LCOV - code coverage report
Current view: top level - bgp/extended-community - esi_label.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 20 21 95.2 %
Date: 2026-06-11 01:56:02 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #include "bgp/extended-community/esi_label.h"
       6             : 
       7             : #include <stdio.h>
       8             : 
       9             : #include <algorithm>
      10             : #include <string>
      11             : 
      12             : #include "base/parse_object.h"
      13             : 
      14             : using std::copy;
      15             : using std::fill;
      16             : using std::string;
      17             : 
      18          65 : EsiLabel::EsiLabel(const bytes_type &data) {
      19          65 :     copy(data.begin(), data.end(), data_.begin());
      20          65 : }
      21             : 
      22          48 : EsiLabel::EsiLabel(bool single_active) {
      23          48 :     fill(data_.begin(), data_.end(), 0);
      24          48 :     data_[0] = BgpExtendedCommunityType::Evpn;
      25          48 :     data_[1] = BgpExtendedCommunityEvpnSubType::EsiMplsLabel;
      26          48 :     if (single_active) {
      27           8 :         data_[2] |= 0x01;
      28             :     }
      29          48 : }
      30             : 
      31           6 : string EsiLabel::flags() const {
      32           6 :     return (data_[2] & 0x01) ? string("sa") : string("aa");
      33             : }
      34             : 
      35           6 : int EsiLabel::label() const {
      36          12 :     if (data_[0] == BgpExtendedCommunityType::Evpn &&
      37           6 :         data_[1] == BgpExtendedCommunityEvpnSubType::EsiMplsLabel) {
      38           6 :         int value = get_value(&data_[5], 3);
      39           6 :         return value >> 4;
      40             :     }
      41           0 :     return 0;
      42             : }
      43             : 
      44           6 : string EsiLabel::ToString() const {
      45             :     char temp[50];
      46           6 :     snprintf(temp, sizeof(temp), "esilabel:%s:%d", flags().c_str(), label());
      47           6 :     return string(temp);
      48             : }

Generated by: LCOV version 1.14