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-06-08 02:02:55 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             :  */
       4             : 
       5             : #include "bgp/extended-community/etree.h"
       6             : 
       7             : #include <stdio.h>
       8             : 
       9             : #include <algorithm>
      10             : #include <string>
      11             : 
      12             : 
      13             : using std::copy;
      14             : using std::string;
      15             : 
      16        4376 : ETree::ETree(bool leaf, int label) {
      17        4376 :     data_[0] = BgpExtendedCommunityType::Evpn;
      18        4376 :     data_[1] = BgpExtendedCommunityEvpnSubType::ETree;
      19        4376 :     data_[2] = leaf ? 0x01 : 0x0;  // Leaf Indication
      20        4376 :     data_[3] = 0x00;  // Reserved
      21        4376 :     data_[4] = 0x00;  // Reserved
      22        4376 :     put_value(&data_[5], 3, (label<<4)); // leaf label
      23        4376 : }
      24             : 
      25       82641 : ETree::ETree(const bytes_type &data) {
      26       82641 :     copy(data.begin(), data.end(), data_.begin());
      27       82639 : }
      28             : 
      29       82642 : bool ETree::leaf() const {
      30       82642 :     return (data_[2] & 0x1);
      31             : }
      32             : 
      33           8 : int ETree::label() const {
      34             :     uint8_t data[ETree::kSize];
      35           8 :     copy(data_.begin(), data_.end(), &data[0]);
      36           8 :     if (data[0] == BgpExtendedCommunityType::Evpn &&
      37           8 :         data[1] == BgpExtendedCommunityEvpnSubType::ETree) {
      38           8 :         uint32_t value = get_value(data + 5, 3);
      39           8 :         return value >> 4;
      40             :     }
      41           0 :     return false;
      42             : }
      43             : 
      44           8 : std::string ETree::ToString() {
      45             :     char temp[50];
      46          16 :     snprintf(temp, sizeof(temp), "etree:%s:%d",
      47           8 :              (leaf() ? "leaf":"root"), label());
      48           8 :     return string(temp);
      49             : }

Generated by: LCOV version 1.14