Line data Source code
1 : /* 2 : * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : 6 : #ifndef SRC_BGP_INET6VPN_INET6VPN_ROUTE_H_ 7 : #define SRC_BGP_INET6VPN_INET6VPN_ROUTE_H_ 8 : 9 : #include <string> 10 : #include <vector> 11 : 12 : #include "base/util.h" 13 : #include "base/address.h" 14 : #include "bgp/bgp_attr.h" 15 : #include "bgp/bgp_attr_base.h" 16 : #include "bgp/bgp_route.h" 17 : #include "net/bgp_af.h" 18 : #include "net/rd.h" 19 : 20 : class Inet6VpnPrefix { 21 : public: 22 : Inet6VpnPrefix(); 23 20389 : Inet6VpnPrefix(const RouteDistinguisher &rd, Ip6Address ip, int prefixlen) 24 20389 : : rd_(rd), addr_(ip), prefixlen_(prefixlen) { 25 20390 : } 26 : 27 : static int FromProtoPrefix(const BgpProtoPrefix &proto_prefix, 28 : Inet6VpnPrefix *prefix, uint32_t *label); 29 : static int FromProtoPrefix(BgpServer *server, 30 : const BgpProtoPrefix &proto_prefix, 31 : const BgpAttr *attr, 32 : const Address::Family family, 33 : Inet6VpnPrefix *prefix, 34 : BgpAttrPtr *new_attr, uint32_t *label, 35 : uint32_t *l3_label); 36 : static Inet6VpnPrefix FromString(const std::string &str, 37 : boost::system::error_code *errorp = NULL); 38 : 39 : std::string ToString() const; 40 : bool IsMoreSpecific(const Inet6VpnPrefix &rhs) const; 41 : int CompareTo(const Inet6VpnPrefix &other) const; 42 : bool operator==(const Inet6VpnPrefix &rhs) const; 43 : 44 3703918 : const RouteDistinguisher &route_distinguisher() const { return rd_; } 45 3282538 : Ip6Address addr() const { return addr_; } 46 2951410 : int prefixlen() const { return prefixlen_; } 47 : void BuildProtoPrefix(uint32_t label, BgpProtoPrefix *prefix) const; 48 : 49 : private: 50 : RouteDistinguisher rd_; 51 : Ip6Address addr_; 52 : int prefixlen_; 53 : }; 54 : 55 : class Inet6VpnRoute : public BgpRoute { 56 : public: 57 : explicit Inet6VpnRoute(const Inet6VpnPrefix &prefix); 58 : virtual int CompareTo(const Route &rhs) const; 59 : 60 : virtual std::string ToString() const; 61 : 62 3639639 : const Inet6VpnPrefix &GetPrefix() const { 63 3639639 : return prefix_; 64 : } 65 0 : virtual RouteDistinguisher GetRouteDistinguisher() const { 66 0 : return prefix_.route_distinguisher(); 67 : } 68 : 69 : virtual KeyPtr GetDBRequestKey() const; 70 : virtual void SetKey(const DBRequestKey *reqkey); 71 : virtual void BuildProtoPrefix(BgpProtoPrefix *prefix, const BgpAttr *attr, 72 : uint32_t label, uint32_t l3_label = 0) const; 73 : virtual void BuildBgpProtoNextHop(std::vector<uint8_t> &nh, 74 : IpAddress nexthop) const; 75 : 76 1499338 : virtual bool IsLess(const DBEntry &genrhs) const { 77 1499338 : const Inet6VpnRoute &rhs = static_cast<const Inet6VpnRoute &>(genrhs); 78 1499338 : int cmp = CompareTo(rhs); 79 1499266 : return (cmp < 0); 80 : } 81 : 82 : virtual bool IsMoreSpecific(const std::string &other) const; 83 : virtual bool IsLessSpecific(const std::string &other) const; 84 : 85 : private: 86 : Inet6VpnPrefix prefix_; 87 : DISALLOW_COPY_AND_ASSIGN(Inet6VpnRoute); 88 : }; 89 : 90 : #endif // SRC_BGP_INET6VPN_INET6VPN_ROUTE_H_