LCOV - code coverage report
Current view: top level - bgp/inet - inet_route.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 20 20 100.0 %
Date: 2026-06-08 02:02:55 Functions: 11 11 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_INET_INET_ROUTE_H_
       6             : #define SRC_BGP_INET_INET_ROUTE_H_
       7             : 
       8             : #include <string>
       9             : #include <vector>
      10             : 
      11             : #include "bgp/bgp_attr.h"
      12             : #include "bgp/bgp_route.h"
      13             : #include "base/address.h"
      14             : #include "net/bgp_af.h"
      15             : 
      16             : class Ip4Prefix {
      17             : public:
      18      205487 :     Ip4Prefix() : prefixlen_(0) { }
      19     2306859 :     Ip4Prefix(Ip4Address addr, int prefixlen)
      20     2306859 :         : ip4_addr_(addr), prefixlen_(prefixlen) {
      21     2306701 :     }
      22             :     int CompareTo(const Ip4Prefix &rhs) const;
      23             : 
      24       91728 :     Ip4Address addr() const { return ip4_addr_; }
      25     7081233 :     Ip4Address ip4_addr() const { return ip4_addr_; }
      26             : 
      27     1117690 :     int prefixlen() const { return prefixlen_; }
      28             : 
      29             :     static int FromProtoPrefix(const BgpProtoPrefix &proto_prefix,
      30             :                                Ip4Prefix *prefix);
      31             :     static int FromProtoPrefix(BgpServer *server,
      32             :                                const BgpProtoPrefix &proto_prefix,
      33             :                                const BgpAttr *attr,
      34             :                                const Address::Family family, Ip4Prefix *prefix,
      35             :                                BgpAttrPtr *new_attr, uint32_t *label,
      36             :                                uint32_t *l3_label);
      37             :     static Ip4Prefix FromString(const std::string &str,
      38             :                                 boost::system::error_code *errorp = NULL);
      39             : 
      40             :     std::string ToString() const;
      41             : 
      42       14023 :     bool operator==(const Ip4Prefix &rhs) const {
      43       14023 :         return (CompareTo(rhs) == 0);
      44             :     }
      45        4557 :     bool operator!=(const Ip4Prefix &rhs) const {
      46        4557 :         return (CompareTo(rhs) != 0);
      47             :     }
      48       35013 :     bool operator<(const Ip4Prefix &rhs) const {
      49       35013 :         int cmp = CompareTo(rhs);
      50       35013 :         return (cmp < 0);
      51             :     }
      52             :     bool operator>(const Ip4Prefix &rhs) const {
      53             :         int cmp = CompareTo(rhs);
      54             :         return (cmp > 0);
      55             :     }
      56             : 
      57             :     // Check whether 'this' is more specific than rhs.
      58             :     bool IsMoreSpecific(const Ip4Prefix &rhs) const;
      59             : 
      60             : private:
      61             :     Ip4Address ip4_addr_;
      62             :     int prefixlen_;
      63             : };
      64             : 
      65             : class InetRoute : public BgpRoute {
      66             : public:
      67             :     explicit InetRoute(const Ip4Prefix &prefix);
      68             :     virtual int CompareTo(const Route &rhs) const;
      69     1314014 :     virtual std::string ToString() const { return prefix_str_; }
      70     4430595 :     const Ip4Prefix &GetPrefix() const { return prefix_; }
      71             : 
      72             :     virtual KeyPtr GetDBRequestKey() const;
      73             :     virtual void SetKey(const DBRequestKey *reqkey);
      74             : 
      75             :     virtual void BuildProtoPrefix(BgpProtoPrefix *prefix,
      76             :                                   const BgpAttr *attr = NULL,
      77             :                                   uint32_t label = 0,
      78             :                                   uint32_t l3_label = 0) const;
      79             :     virtual void BuildBgpProtoNextHop(std::vector<uint8_t> &nh,
      80             :                                       IpAddress nexthop) const;
      81             : 
      82     6028445 :     virtual bool IsLess(const DBEntry &genrhs) const {
      83     6028445 :         const InetRoute &rhs = static_cast<const InetRoute &>(genrhs);
      84     6028445 :         int cmp = CompareTo(rhs);
      85     6026260 :         return (cmp < 0);
      86             :     }
      87             : 
      88             :     virtual bool IsMoreSpecific(const std::string &match) const;
      89             :     virtual bool IsLessSpecific(const std::string &match) const;
      90             : 
      91             : private:
      92             :     Ip4Prefix prefix_;
      93             :     std::string prefix_str_;
      94             : 
      95             :     DISALLOW_COPY_AND_ASSIGN(InetRoute);
      96             : };
      97             : 
      98             : #endif  // SRC_BGP_INET_INET_ROUTE_H_

Generated by: LCOV version 1.14