LCOV - code coverage report
Current view: top level - bgp/evpn - evpn_route.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 25 25 100.0 %
Date: 2026-06-22 02:21:21 Functions: 18 18 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #ifndef SRC_BGP_EVPN_EVPN_ROUTE_H_
       6             : #define SRC_BGP_EVPN_EVPN_ROUTE_H_
       7             : 
       8             : #include <boost/system/error_code.hpp>
       9             : 
      10             : #include <string>
      11             : #include <vector>
      12             : 
      13             : #include "bgp/bgp_route.h"
      14             : #include "bgp/inet/inet_route.h"
      15             : #include "bgp/inet6/inet6_route.h"
      16             : #include "base/address.h"
      17             : #include "net/bgp_af.h"
      18             : #include "net/esi.h"
      19             : #include "net/mac_address.h"
      20             : #include "net/rd.h"
      21             : 
      22             : class BgpServer;
      23             : 
      24             : class EvpnPrefix {
      25             : public:
      26             :     static const EvpnPrefix kNullPrefix;
      27             :     static const uint32_t kInvalidLabel;
      28             :     static const uint32_t kNullTag;
      29             :     static const uint32_t kMaxTag;
      30             :     static const uint32_t kMaxVni;
      31             :     static const int32_t kMaxVniSigned;
      32             : 
      33             :     static const size_t kRdSize;
      34             :     static const size_t kEsiSize;
      35             :     static const size_t kTagSize;
      36             :     static const size_t kIp4AddrSize;
      37             :     static const size_t kIp6AddrSize;
      38             :     static const size_t kMacSize;
      39             :     static const size_t kLabelSize;
      40             :     static const size_t kMinAutoDiscoveryRouteSize;
      41             :     static const size_t kMinMacAdvertisementRouteSize;
      42             :     static const size_t kMinInclusiveMulticastRouteSize;
      43             :     static const size_t kMinSelectiveMulticastRouteSize;
      44             :     static const size_t kMinSegmentRouteSize;
      45             :     static const size_t kMinInetPrefixRouteSize;
      46             :     static const size_t kMinInet6PrefixRouteSize;
      47             : 
      48             :     enum RouteType {
      49             :         Unspecified = 0,
      50             :         AutoDiscoveryRoute = 1,
      51             :         MacAdvertisementRoute = 2,
      52             :         InclusiveMulticastRoute = 3,
      53             :         SegmentRoute = 4,
      54             :         IpPrefixRoute = 5,
      55             :         SelectiveMulticastRoute = 6
      56             :     };
      57             : 
      58             :     EvpnPrefix();
      59             :     EvpnPrefix(const RouteDistinguisher &rd, const EthernetSegmentId &esi,
      60             :         uint32_t tag);
      61             :     EvpnPrefix(const RouteDistinguisher &rd,
      62             :         const MacAddress &mac_addr, const IpAddress &ip_address);
      63             :     EvpnPrefix(const RouteDistinguisher &rd, uint32_t tag,
      64             :         const MacAddress &mac_addr, const IpAddress &ip_address);
      65             :     EvpnPrefix(const RouteDistinguisher &rd, uint32_t tag,
      66             :         const IpAddress &ip_address);
      67             :     EvpnPrefix(const RouteDistinguisher &rd, const EthernetSegmentId &esi,
      68             :         const IpAddress &ip_address);
      69             :     EvpnPrefix(const RouteDistinguisher &rd,
      70             :         const IpAddress &ip_address, uint8_t ip_prefixlen);
      71             :     EvpnPrefix(const RouteDistinguisher &rd, uint32_t tag,
      72             :         const IpAddress &source, const IpAddress &group,
      73             :         const IpAddress &originator);
      74             : 
      75             :     void BuildProtoPrefix(BgpProtoPrefix *proto_prefix,
      76             :         const BgpAttr *attr, uint32_t label, uint32_t l3_label = 0) const;
      77             : 
      78             :     static int FromProtoPrefix(BgpServer *server,
      79             :         const BgpProtoPrefix &proto_prefix, const BgpAttr *attr,
      80             :         const Address::Family family, EvpnPrefix *evpn_prefix,
      81             :         BgpAttrPtr *new_attr, uint32_t *label, uint32_t *l3_label = NULL);
      82             :     static EvpnPrefix FromString(const std::string &str,
      83             :         boost::system::error_code *errorp = NULL);
      84             :     std::string ToString() const;
      85             :     std::string ToXmppIdString() const;
      86             : 
      87             :     int CompareTo(const EvpnPrefix &rhs) const;
      88       21516 :     bool operator==(const EvpnPrefix &rhs) const {
      89       21516 :         return CompareTo(rhs) == 0;
      90             :     }
      91             :     bool operator!=(const EvpnPrefix &rhs) const {
      92             :         return CompareTo(rhs) != 0;
      93             :     }
      94        4820 :     bool operator<(const EvpnPrefix &rhs) const {
      95        4820 :         return (CompareTo(rhs) < 0);
      96             :     }
      97             :     bool operator>(const EvpnPrefix &rhs) const {
      98             :         return (CompareTo(rhs) > 0);
      99             :     }
     100     2879582 :     uint8_t type() const { return type_; }
     101      107348 :     const RouteDistinguisher &route_distinguisher() const { return rd_; }
     102         185 :     const EthernetSegmentId &esi() const { return esi_; }
     103       56428 :     uint32_t tag() const { return tag_; }
     104     1810556 :     const MacAddress &mac_addr() const { return mac_addr_; }
     105       40845 :     Address::Family family() const { return family_; }
     106       27797 :     const IpAddress& addr() const { return ip_address_; }
     107      390193 :     IpAddress ip_address() const { return ip_address_; }
     108       75153 :     IpAddress group() const { return group_; }
     109       54352 :     IpAddress source() const { return source_; }
     110             :     uint8_t ip_address_length() const;
     111        9391 :     uint8_t prefixlen() const { return ip_prefixlen_; }
     112             :     const Ip4Address ip4_addr() const { return ip_address_.to_v4(); }
     113             :     const Ip6Address ip6_addr() const { return ip_address_.to_v6(); }
     114      229871 :     Ip4Prefix inet_prefix() const {
     115      229871 :         return Ip4Prefix(ip_address_.to_v4(), ip_prefixlen_);
     116             :     }
     117      213523 :     Inet6Prefix inet6_prefix() const {
     118      213523 :         return Inet6Prefix(ip_address_.to_v6(), ip_prefixlen_);
     119             :     }
     120       44136 :     void set_route_distinguisher(const RouteDistinguisher &rd) { rd_ = rd; }
     121             : 
     122             :     // Check whether 'this' is more specific than rhs.
     123             :     bool IsMoreSpecific(const EvpnPrefix &rhs) const;
     124             : 
     125             : private:
     126             :     uint8_t type_;
     127             :     RouteDistinguisher rd_;
     128             :     EthernetSegmentId esi_;
     129             :     uint32_t tag_;
     130             :     MacAddress mac_addr_;
     131             :     Address::Family family_;
     132             :     IpAddress ip_address_;
     133             :     IpAddress source_;
     134             :     IpAddress group_;
     135             :     uint8_t ip_prefixlen_;
     136             :     uint8_t flags_;
     137             : 
     138             :     size_t GetIpAddressSize() const;
     139             :     void ReadIpAddress(const BgpProtoPrefix &proto_prefix,
     140             :         size_t ip_offset, size_t ip_size, size_t ip_psize);
     141             :     void ReadSource(const BgpProtoPrefix &proto_prefix,
     142             :                     size_t ip_offset, size_t ip_size);
     143             :     void ReadGroup(const BgpProtoPrefix &proto_prefix,
     144             :                    size_t ip_offset, size_t ip_size);
     145             :     void WriteIpAddress(BgpProtoPrefix *proto_prefix, size_t ip_offset) const;
     146             :     void WriteSource(BgpProtoPrefix *proto_prefix, size_t ip_offset) const;
     147             :     void WriteGroup(BgpProtoPrefix *proto_prefix, size_t ip_offset) const;
     148             :     static bool GetSourceFromString(EvpnPrefix *prefix, const std::string &str,
     149             :         size_t pos1, size_t *pos2, boost::system::error_code *errorp);
     150             :     static bool GetGroupFromString(EvpnPrefix *prefix, const std::string &str,
     151             :         size_t pos1, size_t *pos2, boost::system::error_code *errorp);
     152             : };
     153             : 
     154             : class EvpnRoute : public BgpRoute {
     155             : public:
     156             :     explicit EvpnRoute(const EvpnPrefix &prefix);
     157             :     virtual int CompareTo(const Route &rhs) const;
     158             :     virtual std::string ToString() const;
     159             :     virtual std::string ToXmppIdString() const;
     160             :     virtual bool IsValid() const;
     161             : 
     162     2125819 :     const EvpnPrefix &GetPrefix() const { return prefix_; }
     163             : 
     164             :     virtual KeyPtr GetDBRequestKey() const;
     165             :     virtual void SetKey(const DBRequestKey *reqkey);
     166             : 
     167             :     virtual void BuildProtoPrefix(BgpProtoPrefix *proto_prefix,
     168             :         const BgpAttr *attr = NULL, uint32_t label = 0,
     169             :         uint32_t l3_label = 0) const;
     170             :     virtual void BuildBgpProtoNextHop(std::vector<uint8_t> &nh,
     171             :         IpAddress nexthop) const;
     172             : 
     173     2706957 :     virtual bool IsLess(const DBEntry &genrhs) const {
     174     2706957 :         const EvpnRoute &rhs = static_cast<const EvpnRoute &>(genrhs);
     175     2706957 :         int cmp = CompareTo(rhs);
     176     2704980 :         return (cmp < 0);
     177             :     }
     178             : 
     179             : private:
     180             :     EvpnPrefix prefix_;
     181             :     mutable std::string xmpp_id_str_;
     182             : 
     183             :     DISALLOW_COPY_AND_ASSIGN(EvpnRoute);
     184             : };
     185             : 
     186             : #endif  // SRC_BGP_EVPN_EVPN_ROUTE_H_

Generated by: LCOV version 1.14