LCOV - code coverage report
Current view: top level - bgp/extended-community - etree.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 23 24 95.8 %
Date: 2026-11-09 02:10:49 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #include "bgp/extended-community/etree.h"
       7             : 
       8             : #include <stdio.h>
       9             : 
      10             : #include <algorithm>
      11             : #include <string>
      12             : 
      13             : 
      14             : using std::copy;
      15             : using std::string;
      16             : 
      17        4374 : ETree::ETree(bool leaf, int label) {
      18        4374 :     data_[0] = BgpExtendedCommunityType::Evpn;
      19        4374 :     data_[1] = BgpExtendedCommunityEvpnSubType::ETree;
      20        4374 :     data_[2] = leaf ? 0x01 : 0x0;  // Leaf Indication
      21        4374 :     data_[3] = 0x00;  // Reserved
      22        4374 :     data_[4] = 0x00;  // Reserved
      23        4374 :     put_value(&data_[5], 3, (label<<4)); // leaf label
      24        4374 : }
      25             : 
      26       83186 : ETree::ETree(const bytes_type &data) {
      27       83186 :     copy(data.begin(), data.end(), data_.begin());
      28       83187 : }
      29             : 
      30       83190 : bool ETree::leaf() const {
      31       83190 :     return (data_[2] & 0x1);
      32             : }
      33             : 
      34           8 : int ETree::label() const {
      35             :     uint8_t data[ETree::kSize];
      36           8 :     copy(data_.begin(), data_.end(), &data[0]);
      37           8 :     if (data[0] == BgpExtendedCommunityType::Evpn &&
      38           8 :         data[1] == BgpExtendedCommunityEvpnSubType::ETree) {
      39           8 :         uint32_t value = get_value(data + 5, 3);
      40           8 :         return value >> 4;
      41             :     }
      42           0 :     return false;
      43             : }
      44             : 
      45           8 : std::string ETree::ToString() {
      46             :     char temp[50];
      47          16 :     snprintf(temp, sizeof(temp), "etree:%s:%d",
      48           8 :              (leaf() ? "leaf":"root"), label());
      49           8 :     return string(temp);
      50             : }

Generated by: LCOV version 1.14