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

Generated by: LCOV version 1.14