LCOV - code coverage report
Current view: top level - bgp/security_group - security_group.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 41 55 74.5 %
Date: 2026-11-09 02:10:49 Functions: 9 12 75.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #include "bgp/extended-community/types.h"
       7             : #include "bgp/security_group/security_group.h"
       8             : 
       9             : #include <stdio.h>
      10             : 
      11             : #include <algorithm>
      12             : 
      13             : 
      14             : using std::copy;
      15             : using std::string;
      16             : 
      17       27680 : SecurityGroup::SecurityGroup(as2_t asn, uint32_t sgid) {
      18       27680 :     data_[0] = BgpExtendedCommunityType::Experimental;
      19       27680 :     data_[1] = BgpExtendedCommunityExperimentalSubType::SgId;
      20       27680 :     put_value(&data_[2], 2, asn);
      21       27680 :     put_value(&data_[4], 4, sgid);
      22       27681 : }
      23             : 
      24      433055 : SecurityGroup::SecurityGroup(const bytes_type &data) {
      25      433055 :     copy(data.begin(), data.end(), data_.begin());
      26      433053 : }
      27             : 
      28      235258 : as2_t SecurityGroup::as_number() const {
      29      470520 :     if (data_[0] == BgpExtendedCommunityType::Experimental &&
      30      235263 :             data_[1] == BgpExtendedCommunityExperimentalSubType::SgId) {
      31      235262 :         as2_t as_number = get_value(&data_[2], 2);
      32      235266 :         return as_number;
      33             :     }
      34           0 :     return 0;
      35             : }
      36             : 
      37      569810 : uint32_t SecurityGroup::security_group_id() const {
      38     1139615 :     if (data_[0] == BgpExtendedCommunityType::Experimental &&
      39      569803 :             data_[1] == BgpExtendedCommunityExperimentalSubType::SgId) {
      40      569804 :         uint32_t num = get_value(&data_[4], 4);
      41      569826 :         return num;
      42             :     }
      43           1 :     return 0;
      44             : }
      45             : 
      46      136786 : bool SecurityGroup::IsGlobal() const {
      47      136786 :     uint32_t sgid = security_group_id();
      48      136803 :     return (sgid >= kMinGlobalId && sgid <= kMaxGlobalId);
      49             : }
      50             : 
      51          19 : string SecurityGroup::ToString() {
      52             :     char temp[50];
      53          19 :     snprintf(temp, sizeof(temp), "secgroup:%u:%u",
      54          19 :         as_number(), security_group_id());
      55          19 :     return string(temp);
      56             : }
      57             : 
      58           6 : SecurityGroup4ByteAs::SecurityGroup4ByteAs(as_t asn, uint32_t sgid) {
      59           6 :     data_[0] = BgpExtendedCommunityType::Experimental4ByteAs;
      60           6 :     data_[1] = BgpExtendedCommunityExperimentalSubType::SgId;
      61           6 :     put_value(&data_[2], 4, asn);
      62           6 :     put_value(&data_[6], 2, sgid);
      63           6 : }
      64             : 
      65      196608 : SecurityGroup4ByteAs::SecurityGroup4ByteAs(const bytes_type &data) {
      66      196608 :     copy(data.begin(), data.end(), data_.begin());
      67      196608 : }
      68             : 
      69      196608 : as_t SecurityGroup4ByteAs::as_number() const {
      70      393216 :     if (data_[0] == BgpExtendedCommunityType::Experimental4ByteAs &&
      71      196608 :             data_[1] == BgpExtendedCommunityExperimentalSubType::SgId) {
      72      196608 :         as_t as_number = get_value(&data_[2], 4);
      73      196608 :         return as_number;
      74             :     }
      75           0 :     return 0;
      76             : }
      77             : 
      78           0 : uint32_t SecurityGroup4ByteAs::security_group_id() const {
      79           0 :     if (data_[0] == BgpExtendedCommunityType::Experimental4ByteAs &&
      80           0 :             data_[1] == BgpExtendedCommunityExperimentalSubType::SgId) {
      81           0 :         uint32_t num = get_value(&data_[6], 2);
      82           0 :         return num;
      83             :     }
      84           0 :     return 0;
      85             : }
      86             : 
      87           0 : bool SecurityGroup4ByteAs::IsGlobal() const {
      88           0 :     uint32_t sgid = security_group_id();
      89           0 :     return (sgid >= kMinGlobalId && sgid <= kMaxGlobalId);
      90             : }
      91             : 
      92           0 : string SecurityGroup4ByteAs::ToString() {
      93             :     char temp[50];
      94           0 :     snprintf(temp, sizeof(temp), "secgroup:%u:%u",
      95             :         as_number(), security_group_id());
      96           0 :     return string(temp);
      97             : }

Generated by: LCOV version 1.14