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-11-09 02:10:49 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             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #include "bgp/bgp_attr_base.h"
       7             : 
       8             : #include <cstdio>
       9             : 
      10             : const size_t BgpProtoPrefix::kLabelSize = 3;
      11             : 
      12     2102909 : BgpProtoPrefix::BgpProtoPrefix() : prefixlen(0), type(0) {
      13     2102916 : }
      14             : 
      15             : //
      16             : // Extract the label from the BgpProtorefix.
      17             : // EVPN extensions for VXLAN use the label to convey a 24-bit VNI.
      18             : //
      19      135658 : uint32_t BgpProtoPrefix::ReadLabel(size_t label_offset, bool is_vni) const {
      20      135658 :     assert((label_offset + kLabelSize) <= prefix.size());
      21      135658 :     if (is_vni)
      22         133 :         return get_value(&prefix[label_offset], kLabelSize);
      23      135525 :     uint32_t label = (prefix[label_offset] << 16 |
      24      135525 :         prefix[label_offset + 1] << 8 |
      25      135525 :         prefix[label_offset + 2]) >> 4;
      26      135525 :     return label;
      27             : }
      28             : 
      29             : //
      30             : // Write the label to the BgpProtorefix.
      31             : // EVPN extensions for VXLAN use the label to convey a 24-bit VNI.
      32             : //
      33      161075 : void BgpProtoPrefix::WriteLabel(size_t label_offset, uint32_t label,
      34             :     bool is_vni) {
      35      161075 :     assert((label_offset + kLabelSize) <= prefix.size());
      36      161079 :     if (is_vni) {
      37         165 :         put_value(&prefix[label_offset], kLabelSize, label);
      38         165 :         return;
      39             :     }
      40      160914 :     uint32_t tmp = (label << 4 | 0x1);
      41      643624 :     for (size_t idx = 0; idx < kLabelSize; ++idx) {
      42      482705 :         int offset = (kLabelSize - (idx + 1)) * 8;
      43      482705 :         prefix[label_offset + idx] = ((tmp >> offset) & 0xff);
      44             :     }
      45             : }
      46             : 
      47      711481 : int BgpAttribute::CompareTo(const BgpAttribute &rhs) const {
      48      711481 :     KEY_COMPARE(code, rhs.code);
      49      711481 :     KEY_COMPARE(subcode, rhs.subcode);
      50      711481 :     KEY_COMPARE(flags & ~ExtendedLength, rhs.flags & ~ExtendedLength);
      51      711481 :     return 0;
      52             : }
      53             : 
      54      746098 : size_t BgpAttribute::EncodeLength() const {
      55      746098 :     return 0;
      56             : }
      57             : 
      58     1982605 : uint8_t BgpAttribute::GetEncodeFlags() const {
      59     1982605 :     uint8_t value = flags;
      60     1982605 :     if (EncodeLength() >= sizeof(uint8_t) << 8) {
      61       69610 :         value |= BgpAttribute::ExtendedLength;
      62             :     }
      63     1982673 :     return value;
      64             : }
      65             : 
      66      158344 : std::string BgpAttribute::ToString() const {
      67             :     char repr[80];
      68      158344 :     snprintf(repr, sizeof(repr), "<code: %d, flags: %02x>", code, flags);
      69      158344 :     return std::string(repr);
      70             : }

Generated by: LCOV version 1.14