LCOV - code coverage report
Current view: top level - bgp - bgp_attr_base.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 34 34 100.0 %
Date: 2026-06-04 02:06:09 Functions: 7 7 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #include "bgp/bgp_attr_base.h"
       6             : 
       7             : #include <cstdio>
       8             : 
       9             : const size_t BgpProtoPrefix::kLabelSize = 3;
      10             : 
      11     2101693 : BgpProtoPrefix::BgpProtoPrefix() : prefixlen(0), type(0) {
      12     2101682 : }
      13             : 
      14             : //
      15             : // Extract the label from the BgpProtorefix.
      16             : // EVPN extensions for VXLAN use the label to convey a 24-bit VNI.
      17             : //
      18      135438 : uint32_t BgpProtoPrefix::ReadLabel(size_t label_offset, bool is_vni) const {
      19      135438 :     assert((label_offset + kLabelSize) <= prefix.size());
      20      135438 :     if (is_vni)
      21         133 :         return get_value(&prefix[label_offset], kLabelSize);
      22      135305 :     uint32_t label = (prefix[label_offset] << 16 |
      23      135305 :         prefix[label_offset + 1] << 8 |
      24      135305 :         prefix[label_offset + 2]) >> 4;
      25      135305 :     return label;
      26             : }
      27             : 
      28             : //
      29             : // Write the label to the BgpProtorefix.
      30             : // EVPN extensions for VXLAN use the label to convey a 24-bit VNI.
      31             : //
      32      159859 : void BgpProtoPrefix::WriteLabel(size_t label_offset, uint32_t label,
      33             :     bool is_vni) {
      34      159859 :     assert((label_offset + kLabelSize) <= prefix.size());
      35      159859 :     if (is_vni) {
      36         165 :         put_value(&prefix[label_offset], kLabelSize, label);
      37         165 :         return;
      38             :     }
      39      159694 :     uint32_t tmp = (label << 4 | 0x1);
      40      638759 :     for (size_t idx = 0; idx < kLabelSize; ++idx) {
      41      479064 :         int offset = (kLabelSize - (idx + 1)) * 8;
      42      479064 :         prefix[label_offset + idx] = ((tmp >> offset) & 0xff);
      43             :     }
      44             : }
      45             : 
      46      525337 : int BgpAttribute::CompareTo(const BgpAttribute &rhs) const {
      47      525337 :     KEY_COMPARE(code, rhs.code);
      48      525337 :     KEY_COMPARE(subcode, rhs.subcode);
      49      525337 :     KEY_COMPARE(flags & ~ExtendedLength, rhs.flags & ~ExtendedLength);
      50      525337 :     return 0;
      51             : }
      52             : 
      53      744464 : size_t BgpAttribute::EncodeLength() const {
      54      744464 :     return 0;
      55             : }
      56             : 
      57     1980632 : uint8_t BgpAttribute::GetEncodeFlags() const {
      58     1980632 :     uint8_t value = flags;
      59     1980632 :     if (EncodeLength() >= sizeof(uint8_t) << 8) {
      60       69614 :         value |= BgpAttribute::ExtendedLength;
      61             :     }
      62     1980625 :     return value;
      63             : }
      64             : 
      65      158016 : std::string BgpAttribute::ToString() const {
      66             :     char repr[80];
      67      158016 :     snprintf(repr, sizeof(repr), "<code: %d, flags: %02x>", code, flags);
      68      158016 :     return std::string(repr);
      69             : }

Generated by: LCOV version 1.14