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-11-09 02:10:49 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             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #ifndef SRC_BGP_INET_INET_ROUTE_H_
       7             : #define SRC_BGP_INET_INET_ROUTE_H_
       8             : 
       9             : #include <string>
      10             : #include <vector>
      11             : 
      12             : #include "bgp/bgp_attr.h"
      13             : #include "bgp/bgp_route.h"
      14             : #include "base/address.h"
      15             : #include "net/bgp_af.h"
      16             : 
      17             : class Ip4Prefix {
      18             : public:
      19      205575 :     Ip4Prefix() : prefixlen_(0) { }
      20     2350627 :     Ip4Prefix(Ip4Address addr, int prefixlen)
      21     2350627 :         : ip4_addr_(addr), prefixlen_(prefixlen) {
      22     2350413 :     }
      23             :     int CompareTo(const Ip4Prefix &rhs) const;
      24             : 
      25       91730 :     Ip4Address addr() const { return ip4_addr_; }
      26     7108238 :     Ip4Address ip4_addr() const { return ip4_addr_; }
      27             : 
      28     1122136 :     int prefixlen() const { return prefixlen_; }
      29             : 
      30             :     static int FromProtoPrefix(const BgpProtoPrefix &proto_prefix,
      31             :                                Ip4Prefix *prefix);
      32             :     static int FromProtoPrefix(BgpServer *server,
      33             :                                const BgpProtoPrefix &proto_prefix,
      34             :                                const BgpAttr *attr,
      35             :                                const Address::Family family, Ip4Prefix *prefix,
      36             :                                BgpAttrPtr *new_attr, uint32_t *label,
      37             :                                uint32_t *l3_label);
      38             :     static Ip4Prefix FromString(const std::string &str,
      39             :                                 boost::system::error_code *errorp = NULL);
      40             : 
      41             :     std::string ToString() const;
      42             : 
      43       13952 :     bool operator==(const Ip4Prefix &rhs) const {
      44       13952 :         return (CompareTo(rhs) == 0);
      45             :     }
      46        4489 :     bool operator!=(const Ip4Prefix &rhs) const {
      47        4489 :         return (CompareTo(rhs) != 0);
      48             :     }
      49       35827 :     bool operator<(const Ip4Prefix &rhs) const {
      50       35827 :         int cmp = CompareTo(rhs);
      51       35826 :         return (cmp < 0);
      52             :     }
      53             :     bool operator>(const Ip4Prefix &rhs) const {
      54             :         int cmp = CompareTo(rhs);
      55             :         return (cmp > 0);
      56             :     }
      57             : 
      58             :     // Check whether 'this' is more specific than rhs.
      59             :     bool IsMoreSpecific(const Ip4Prefix &rhs) const;
      60             : 
      61             : private:
      62             :     Ip4Address ip4_addr_;
      63             :     int prefixlen_;
      64             : };
      65             : 
      66             : class InetRoute : public BgpRoute {
      67             : public:
      68             :     explicit InetRoute(const Ip4Prefix &prefix);
      69             :     virtual int CompareTo(const Route &rhs) const;
      70     1320621 :     virtual std::string ToString() const { return prefix_str_; }
      71     4416969 :     const Ip4Prefix &GetPrefix() const { return prefix_; }
      72             : 
      73             :     virtual KeyPtr GetDBRequestKey() const;
      74             :     virtual void SetKey(const DBRequestKey *reqkey);
      75             : 
      76             :     virtual void BuildProtoPrefix(BgpProtoPrefix *prefix,
      77             :                                   const BgpAttr *attr = NULL,
      78             :                                   uint32_t label = 0,
      79             :                                   uint32_t l3_label = 0) const;
      80             :     virtual void BuildBgpProtoNextHop(std::vector<uint8_t> &nh,
      81             :                                       IpAddress nexthop) const;
      82             : 
      83     6030099 :     virtual bool IsLess(const DBEntry &genrhs) const {
      84     6030099 :         const InetRoute &rhs = static_cast<const InetRoute &>(genrhs);
      85     6030099 :         int cmp = CompareTo(rhs);
      86     6027773 :         return (cmp < 0);
      87             :     }
      88             : 
      89             :     virtual bool IsMoreSpecific(const std::string &match) const;
      90             :     virtual bool IsLessSpecific(const std::string &match) const;
      91             : 
      92             : private:
      93             :     Ip4Prefix prefix_;
      94             :     std::string prefix_str_;
      95             : 
      96             :     DISALLOW_COPY_AND_ASSIGN(InetRoute);
      97             : };
      98             : 
      99             : #endif  // SRC_BGP_INET_INET_ROUTE_H_

Generated by: LCOV version 1.14