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-30 02:00:48 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     2103630 : BgpProtoPrefix::BgpProtoPrefix() : prefixlen(0), type(0) {
      13     2103620 : }
      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      135729 : uint32_t BgpProtoPrefix::ReadLabel(size_t label_offset, bool is_vni) const {
      20      135729 :     assert((label_offset + kLabelSize) <= prefix.size());
      21      135729 :     if (is_vni)
      22         133 :         return get_value(&prefix[label_offset], kLabelSize);
      23      135596 :     uint32_t label = (prefix[label_offset] << 16 |
      24      135596 :         prefix[label_offset + 1] << 8 |
      25      135595 :         prefix[label_offset + 2]) >> 4;
      26      135595 :     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      160547 : void BgpProtoPrefix::WriteLabel(size_t label_offset, uint32_t label,
      34             :     bool is_vni) {
      35      160547 :     assert((label_offset + kLabelSize) <= prefix.size());
      36      160549 :     if (is_vni) {
      37         165 :         put_value(&prefix[label_offset], kLabelSize, label);
      38         165 :         return;
      39             :     }
      40      160384 :     uint32_t tmp = (label << 4 | 0x1);
      41      641526 :     for (size_t idx = 0; idx < kLabelSize; ++idx) {
      42      481142 :         int offset = (kLabelSize - (idx + 1)) * 8;
      43      481142 :         prefix[label_offset + idx] = ((tmp >> offset) & 0xff);
      44             :     }
      45             : }
      46             : 
      47      490633 : int BgpAttribute::CompareTo(const BgpAttribute &rhs) const {
      48      490633 :     KEY_COMPARE(code, rhs.code);
      49      490633 :     KEY_COMPARE(subcode, rhs.subcode);
      50      490633 :     KEY_COMPARE(flags & ~ExtendedLength, rhs.flags & ~ExtendedLength);
      51      490633 :     return 0;
      52             : }
      53             : 
      54      750372 : size_t BgpAttribute::EncodeLength() const {
      55      750372 :     return 0;
      56             : }
      57             : 
      58     1996504 : uint8_t BgpAttribute::GetEncodeFlags() const {
      59     1996504 :     uint8_t value = flags;
      60     1996504 :     if (EncodeLength() >= sizeof(uint8_t) << 8) {
      61       70946 :         value |= BgpAttribute::ExtendedLength;
      62             :     }
      63     1996485 :     return value;
      64             : }
      65             : 
      66      160621 : std::string BgpAttribute::ToString() const {
      67             :     char repr[80];
      68      160621 :     snprintf(repr, sizeof(repr), "<code: %d, flags: %02x>", code, flags);
      69      160621 :     return std::string(repr);
      70             : }

Generated by: LCOV version 1.14