LCOV - code coverage report
Current view: top level - bgp/ermvpn - ermvpn_route.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 11 11 100.0 %
Date: 2026-06-08 02:02:55 Functions: 8 8 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_ERMVPN_ERMVPN_ROUTE_H_
       6             : #define SRC_BGP_ERMVPN_ERMVPN_ROUTE_H_
       7             : 
       8             : #include <boost/system/error_code.hpp>
       9             : 
      10             : #include <set>
      11             : #include <string>
      12             : #include <vector>
      13             : 
      14             : #include "base/util.h"
      15             : #include "base/address.h"
      16             : #include "bgp/bgp_attr.h"
      17             : #include "bgp/bgp_attr_base.h"
      18             : #include "bgp/bgp_route.h"
      19             : #include "net/bgp_af.h"
      20             : #include "net/rd.h"
      21             : 
      22             : class ErmVpnPrefix {
      23             : public:
      24             :     enum RouteType {
      25             :         NativeRoute = 0,
      26             :         LocalTreeRoute = 1,
      27             :         GlobalTreeRoute = 2,
      28             :         Invalid = 255,
      29             :     };
      30             : 
      31             :     ErmVpnPrefix();
      32             :     ErmVpnPrefix(uint8_t type, const RouteDistinguisher &rd,
      33             :                  const Ip4Address &group, const Ip4Address &source);
      34             :     ErmVpnPrefix(uint8_t type, const RouteDistinguisher &rd,
      35             :                  const Ip4Address &router_id,
      36             :                  const Ip4Address &group, const Ip4Address &source);
      37             :     const std::string GetType() const;
      38             : 
      39             :     static int FromProtoPrefix(const BgpProtoPrefix &proto_prefix,
      40             :                                ErmVpnPrefix *prefix);
      41             :     static int FromProtoPrefix(BgpServer *server,
      42             :                                const BgpProtoPrefix &proto_prefix,
      43             :                                const BgpAttr *attr,
      44             :                                const Address::Family family,
      45             :                                ErmVpnPrefix *prefix, BgpAttrPtr *new_attr,
      46             :                                uint32_t *label, uint32_t *l3_label);
      47             :     static ErmVpnPrefix FromString(const std::string &str,
      48             :                                    boost::system::error_code *errorp = NULL);
      49             : 
      50             :     std::string ToString() const;
      51             :     std::string ToXmppIdString() const;
      52             :     static bool IsValidForBgp(uint8_t type);
      53             :     static bool IsValid(uint8_t type);
      54             :     bool operator==(const ErmVpnPrefix &rhs) const;
      55             : 
      56      621147 :     uint8_t type() const { return type_; }
      57      412285 :     const RouteDistinguisher &route_distinguisher() const { return rd_; }
      58      315750 :     Ip4Address router_id() const { return router_id_; }
      59     1158196 :     Ip4Address group() const { return group_; }
      60     1041329 :     Ip4Address source() const { return source_; }
      61       10495 :     void set_route_distinguisher(const RouteDistinguisher &rd) { rd_ = rd; }
      62             : 
      63             :     void BuildProtoPrefix(BgpProtoPrefix *prefix) const;
      64             : 
      65             : private:
      66             :     uint8_t type_;
      67             :     RouteDistinguisher rd_;
      68             :     Ip4Address router_id_;
      69             :     Ip4Address group_;
      70             :     Ip4Address source_;
      71             : };
      72             : 
      73             : class ErmVpnRoute : public BgpRoute {
      74             : public:
      75             :     explicit ErmVpnRoute(const ErmVpnPrefix &prefix);
      76             :     virtual int CompareTo(const Route &rhs) const;
      77             :     virtual std::string ToString() const;
      78             :     virtual std::string ToXmppIdString() const;
      79             :     virtual bool IsValid() const;
      80             : 
      81      520582 :     const ErmVpnPrefix &GetPrefix() const { return prefix_; }
      82             : 
      83             :     virtual KeyPtr GetDBRequestKey() const;
      84             :     virtual void SetKey(const DBRequestKey *reqkey);
      85             :     virtual void BuildProtoPrefix(BgpProtoPrefix *prefix,
      86             :                                   const BgpAttr *attr = NULL,
      87             :                                   uint32_t label = 0,
      88             :                                   uint32_t l3_label = 0) const;
      89             :     virtual void BuildBgpProtoNextHop(std::vector<uint8_t> &nh,
      90             :                                       IpAddress nexthop) const;
      91             : 
      92      245703 :     virtual bool IsLess(const DBEntry &genrhs) const {
      93      245703 :         const ErmVpnRoute &rhs = static_cast<const ErmVpnRoute &>(genrhs);
      94      245703 :         int cmp = CompareTo(rhs);
      95      245698 :         return (cmp < 0);
      96             :     }
      97             : 
      98             :     const std::string GetType() const;
      99             : 
     100             : private:
     101             :     ErmVpnPrefix prefix_;
     102             :     mutable std::string xmpp_id_str_;
     103             : 
     104             :     DISALLOW_COPY_AND_ASSIGN(ErmVpnRoute);
     105             : };
     106             : 
     107             : #endif  // SRC_BGP_ERMVPN_ERMVPN_ROUTE_H_

Generated by: LCOV version 1.14