LCOV - code coverage report
Current view: top level - bgp/l3vpn - inetvpn_route.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 52 54 96.3 %
Date: 2026-06-18 01:51:13 Functions: 9 9 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             : #include "bgp/l3vpn/inetvpn_route.h"
       6             : 
       7             : #include <algorithm>
       8             : 
       9             : #include "bgp/l3vpn/inetvpn_table.h"
      10             : 
      11             : using std::copy;
      12             : using std::string;
      13             : using std::vector;
      14             : 
      15      241249 : InetVpnRoute::InetVpnRoute(const InetVpnPrefix &prefix)
      16      241249 :     : prefix_(prefix) {
      17      241212 : }
      18             : 
      19     2031057 : int InetVpnRoute::CompareTo(const Route &rhs) const {
      20     2031057 :     const InetVpnRoute &other = static_cast<const InetVpnRoute &>(rhs);
      21     2031057 :     int res = prefix_.route_distinguisher().CompareTo(
      22             :         other.prefix_.route_distinguisher());
      23     2031145 :     if (res != 0) {
      24      794895 :         return res;
      25             :     }
      26     1236250 :     Ip4Address laddr = prefix_.addr();
      27     1236256 :     Ip4Address raddr = other.prefix_.addr();
      28     1236229 :     if (laddr < raddr) {
      29      511294 :         return -1;
      30             :     }
      31      725026 :     if (laddr > raddr) {
      32      445552 :         return 1;
      33             :     }
      34      279457 :     if (prefix_.prefixlen() < other.prefix_.prefixlen()) {
      35          20 :         return -1;
      36             :     }
      37      279475 :     if (prefix_.prefixlen() > other.prefix_.prefixlen()) {
      38          11 :         return 1;
      39             :     }
      40      279461 :     return 0;
      41             : }
      42             : 
      43      448084 : string InetVpnRoute::ToString() const {
      44      448084 :     string repr = prefix_.route_distinguisher().ToString() + ":";
      45      448100 :     repr += prefix_.addr().to_string();
      46             :     char strplen[4];
      47      448097 :     snprintf(strplen, sizeof(strplen), "/%d", prefix_.prefixlen());
      48      448095 :     repr.append(strplen);
      49             : 
      50      896210 :     return repr;
      51           0 : }
      52             : 
      53           2 : void InetVpnRoute::SetKey(const DBRequestKey *reqkey) {
      54           2 :     const InetVpnTable::RequestKey *key =
      55             :         static_cast<const InetVpnTable::RequestKey *>(reqkey);
      56           2 :     prefix_ = key->prefix;
      57           2 : }
      58             : 
      59       74273 : void InetVpnRoute::BuildProtoPrefix(BgpProtoPrefix *prefix,
      60             :                                     const BgpAttr *attr,
      61             :                                     uint32_t label,
      62             :                                     uint32_t l3_label) const {
      63       74273 :     prefix_.BuildProtoPrefix(label, prefix, attr);
      64       74262 : }
      65             : 
      66       43084 : void InetVpnRoute::BuildBgpProtoNextHop(vector<uint8_t> &nh,
      67             :                                         IpAddress nexthop) const {
      68       43084 :     nh.resize(4+RouteDistinguisher::kSize);
      69       43086 :     const Ip4Address::bytes_type &addr_bytes = nexthop.to_v4().to_bytes();
      70       43086 :     copy(addr_bytes.begin(), addr_bytes.end(),
      71       43086 :         nh.begin() + RouteDistinguisher::kSize);
      72       43086 : }
      73             : 
      74       58903 : DBEntryBase::KeyPtr InetVpnRoute::GetDBRequestKey() const {
      75             :     InetVpnTable::RequestKey *key =
      76       58903 :         new InetVpnTable::RequestKey(GetPrefix(), NULL);
      77       58891 :     return KeyPtr(key);
      78             : }
      79             : 
      80             : // Check whether 'this' is more specific than rhs.
      81          25 : bool InetVpnRoute::IsMoreSpecific(const string &match) const {
      82          25 :     boost::system::error_code ec;
      83             : 
      84          25 :     InetVpnPrefix prefix = InetVpnPrefix::FromString(match, &ec);
      85          25 :     if (!ec) {
      86          22 :         return GetPrefix().IsMoreSpecific(prefix);
      87             :     }
      88             : 
      89           3 :     return false;
      90             : }
      91             : 
      92             : // Check whether 'this' is less specific than rhs.
      93          18 : bool InetVpnRoute::IsLessSpecific(const string &match) const {
      94          18 :     boost::system::error_code ec;
      95             : 
      96          18 :     InetVpnPrefix prefix = InetVpnPrefix::FromString(match, &ec);
      97          18 :     if (!ec) {
      98          18 :         return prefix.IsMoreSpecific(GetPrefix());
      99             :     }
     100             : 
     101           0 :     return false;
     102             : }

Generated by: LCOV version 1.14