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

Generated by: LCOV version 1.14