LCOV - code coverage report
Current view: top level - bgp/mvpn - mvpn_route.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 13 13 100.0 %
Date: 2026-06-11 01:56:02 Functions: 10 10 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2017 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #ifndef SRC_BGP_MVPN_MVPN_ROUTE_H_
       6             : #define SRC_BGP_MVPN_MVPN_ROUTE_H_
       7             : 
       8             : 
       9             : #include <set>
      10             : #include <string>
      11             : #include <vector>
      12             : 
      13             : #include <boost/system/error_code.hpp>
      14             : 
      15             : #include "base/util.h"
      16             : #include "base/address.h"
      17             : #include "bgp/bgp_attr.h"
      18             : #include "bgp/bgp_attr_base.h"
      19             : #include "bgp/bgp_route.h"
      20             : #include "net/bgp_af.h"
      21             : #include "net/rd.h"
      22             : 
      23             : class MvpnPrefix {
      24             : public:
      25             : 
      26             :     static const size_t kRdSize;
      27             :     static const size_t kIp4AddrSize;
      28             :     static const size_t kIp4AddrBitSize;
      29             :     static const size_t kAsnSize;
      30             :     static const size_t kPrefixBytes;
      31             :     static const size_t kIntraASPMSIADRouteSize;
      32             :     static const size_t kInterASPMSIADRouteSize;
      33             :     static const size_t kSPMSIADRouteSize;
      34             :     static const size_t kLeafADRouteSize;
      35             :     static const size_t kSourceActiveADRouteSize;
      36             :     static const size_t kSourceTreeJoinRouteSize;
      37             : 
      38             :     enum RouteType {
      39             :         Unspecified = 0,
      40             :         IntraASPMSIADRoute = 1,
      41             :         InterASPMSIADRoute = 2,
      42             :         SPMSIADRoute = 3,
      43             :         LeafADRoute = 4,
      44             :         SourceActiveADRoute = 5,
      45             :         SharedTreeJoinRoute = 6,
      46             :         SourceTreeJoinRoute = 7,
      47             :     };
      48             : 
      49             :     MvpnPrefix();
      50             :     MvpnPrefix(uint8_t type, const RouteDistinguisher &rd,
      51             :                const Ip4Address &originator);
      52             :     MvpnPrefix(uint8_t type, const RouteDistinguisher &rd,
      53             :                const uint32_t asn);
      54             :     MvpnPrefix(uint8_t type, const RouteDistinguisher &rd,
      55             :                const Ip4Address &group, const Ip4Address &source);
      56             :     MvpnPrefix(uint8_t type, const Ip4Address &originator);
      57             :     MvpnPrefix(uint8_t type, const RouteDistinguisher &rd,
      58             :                const Ip4Address &originator,
      59             :                const Ip4Address &group, const Ip4Address &source);
      60             :     MvpnPrefix(uint8_t type, const RouteDistinguisher &rd, const uint32_t asn,
      61             :                const Ip4Address &group, const Ip4Address &source);
      62             : 
      63             :     Ip4Address GetType3OriginatorFromType4Route() const;
      64             :     void SetLeafADPrefixFromSPMSIPrefix(const MvpnPrefix &prefix);
      65             :     void SetSPMSIPrefixFromLeafADPrefix(const MvpnPrefix &prefix);
      66             : 
      67             :     std::string ToString() const;
      68             :     std::string ToXmppIdString() const;
      69             :     bool operator==(const MvpnPrefix &rhs) const;
      70             :     int CompareTo(const MvpnPrefix &rhs) const;
      71             : 
      72     4292053 :     uint8_t type() const { return type_; }
      73      229985 :     const RouteDistinguisher &route_distinguisher() const { return rd_; }
      74     1117830 :     Ip4Address group() const { return group_; }
      75      577366 :     Ip4Address source() const { return source_; }
      76     1324014 :     Ip4Address originator() const { return originator_; }
      77       29422 :     IpAddress groupIpAddress() const { return IpAddress(group_); }
      78       29422 :     IpAddress sourceIpAddress() const { return IpAddress(source_); }
      79             :     IpAddress originatorIpAddress() const { return IpAddress(originator_); }
      80             :     void set_originator(const Ip4Address &originator);
      81          15 :     uint32_t asn() const { return asn_; }
      82             :     void set_route_distinguisher(const RouteDistinguisher &rd) { rd_ = rd; }
      83             :     uint8_t ip_prefix_length() const { return ip_prefixlen_; }
      84             :     void BuildProtoPrefix(BgpProtoPrefix *prefix) const;
      85             :     const std::string GetType() const;
      86             : 
      87             :     static int FromProtoPrefix(const BgpProtoPrefix &proto_prefix,
      88             :                                MvpnPrefix *prefix);
      89             :     static int FromProtoPrefix(BgpServer *server,
      90             :                                const BgpProtoPrefix &proto_prefix,
      91             :                                const BgpAttr *attr,
      92             :                                const Address::Family family,
      93             :                                MvpnPrefix *prefix,
      94             :                                BgpAttrPtr *new_attr, uint32_t *label,
      95             :                                uint32_t *l3_label);
      96             :     static MvpnPrefix FromString(const std::string &str,
      97             :                                  boost::system::error_code *errorp = NULL);
      98             :     static bool IsValid(uint8_t type);
      99             : 
     100             : private:
     101             :     static bool GetTypeFromString(MvpnPrefix *prefix,
     102             :             const std::string &str, boost::system::error_code *errorp,
     103             :             size_t *pos1);
     104             :     static bool GetRDFromString(MvpnPrefix *prefix,
     105             :             const std::string &str, size_t pos1, size_t *pos2,
     106             :             boost::system::error_code *ec);
     107             :     static bool GetOriginatorFromString(MvpnPrefix *prefix,
     108             :             const std::string &str, size_t pos1,
     109             :             boost::system::error_code *errorp);
     110             :     static bool GetAsnFromString(MvpnPrefix *prefix,
     111             :             const std::string &str, size_t pos1, size_t *pos2,
     112             :             boost::system::error_code *ec);
     113             :     static bool GetSourceFromString(MvpnPrefix *prefix,
     114             :             const std::string &str, size_t pos1, size_t *pos2,
     115             :             boost::system::error_code *ec);
     116             :     static bool GetGroupFromString(MvpnPrefix *prefix,
     117             :             const std::string &str, size_t pos1, size_t *pos2,
     118             :             boost::system::error_code *ec, bool last = false);
     119             :     static int SpmsiAdRouteFromProtoPrefix(const BgpProtoPrefix &proto_prefix,
     120             :                                MvpnPrefix *prefix, size_t rd_offset);
     121             :     uint8_t type_;
     122             :     RouteDistinguisher rd_;
     123             :     Ip4Address originator_;
     124             :     Ip4Address group_;
     125             :     Ip4Address source_;
     126             :     uint8_t ip_prefixlen_;
     127             :     uint32_t asn_;
     128             :     std::vector<uint8_t> rt_key_;
     129             : };
     130             : 
     131             : class MvpnRoute : public BgpRoute {
     132             : public:
     133             :     explicit MvpnRoute(const MvpnPrefix &prefix);
     134             :     virtual int CompareTo(const Route &rhs) const;
     135             :     virtual std::string ToString() const;
     136             :     virtual std::string ToXmppIdString() const;
     137             :     virtual bool IsValid() const;
     138             : 
     139     5342614 :     const MvpnPrefix &GetPrefix() const { return prefix_; }
     140             : 
     141             :     virtual KeyPtr GetDBRequestKey() const;
     142             :     virtual void SetKey(const DBRequestKey *reqkey);
     143             :     virtual void BuildProtoPrefix(BgpProtoPrefix *prefix,
     144             :                                   const BgpAttr *attr = NULL,
     145             :                                   uint32_t label = 0,
     146             :                                   uint32_t l3_label = 0) const;
     147             :     virtual void BuildBgpProtoNextHop(std::vector<uint8_t> &nh,
     148             :                                       IpAddress nexthop) const;
     149             : 
     150     2855271 :     virtual bool IsLess(const DBEntry &genrhs) const {
     151     2855271 :         const MvpnRoute &rhs = static_cast<const MvpnRoute &>(genrhs);
     152     2855271 :         int cmp = CompareTo(rhs);
     153     2855270 :         return (cmp < 0);
     154             :     }
     155             : 
     156             :     const std::string GetType() const;
     157             : 
     158             : private:
     159             :     MvpnPrefix prefix_;
     160             :     mutable std::string xmpp_id_str_;
     161             : 
     162             :     DISALLOW_COPY_AND_ASSIGN(MvpnRoute);
     163             : };
     164             : 
     165             : #endif  // SRC_BGP_MVPN_MVPN_ROUTE_H_

Generated by: LCOV version 1.14