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: 40 55 72.7 %
Date: 2026-06-08 02:02:55 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             :  */
       4             : 
       5             : #include "bgp/extended-community/types.h"
       6             : #include "bgp/security_group/security_group.h"
       7             : 
       8             : #include <stdio.h>
       9             : 
      10             : #include <algorithm>
      11             : 
      12             : 
      13             : using std::copy;
      14             : using std::string;
      15             : 
      16       27682 : SecurityGroup::SecurityGroup(as2_t asn, uint32_t sgid) {
      17       27682 :     data_[0] = BgpExtendedCommunityType::Experimental;
      18       27682 :     data_[1] = BgpExtendedCommunityExperimentalSubType::SgId;
      19       27682 :     put_value(&data_[2], 2, asn);
      20       27682 :     put_value(&data_[4], 4, sgid);
      21       27682 : }
      22             : 
      23      433240 : SecurityGroup::SecurityGroup(const bytes_type &data) {
      24      433240 :     copy(data.begin(), data.end(), data_.begin());
      25      433239 : }
      26             : 
      27      235447 : as2_t SecurityGroup::as_number() const {
      28      470888 :     if (data_[0] == BgpExtendedCommunityType::Experimental &&
      29      235445 :             data_[1] == BgpExtendedCommunityExperimentalSubType::SgId) {
      30      235441 :         as2_t as_number = get_value(&data_[2], 2);
      31      235442 :         return as_number;
      32             :     }
      33           0 :     return 0;
      34             : }
      35             : 
      36      570015 : uint32_t SecurityGroup::security_group_id() const {
      37     1140027 :     if (data_[0] == BgpExtendedCommunityType::Experimental &&
      38      570014 :             data_[1] == BgpExtendedCommunityExperimentalSubType::SgId) {
      39      570012 :         uint32_t num = get_value(&data_[4], 4);
      40      570040 :         return num;
      41             :     }
      42           0 :     return 0;
      43             : }
      44             : 
      45      136807 : bool SecurityGroup::IsGlobal() const {
      46      136807 :     uint32_t sgid = security_group_id();
      47      136819 :     return (sgid >= kMinGlobalId && sgid <= kMaxGlobalId);
      48             : }
      49             : 
      50          19 : string SecurityGroup::ToString() {
      51             :     char temp[50];
      52          19 :     snprintf(temp, sizeof(temp), "secgroup:%u:%u",
      53          19 :         as_number(), security_group_id());
      54          19 :     return string(temp);
      55             : }
      56             : 
      57           6 : SecurityGroup4ByteAs::SecurityGroup4ByteAs(as_t asn, uint32_t sgid) {
      58           6 :     data_[0] = BgpExtendedCommunityType::Experimental4ByteAs;
      59           6 :     data_[1] = BgpExtendedCommunityExperimentalSubType::SgId;
      60           6 :     put_value(&data_[2], 4, asn);
      61           6 :     put_value(&data_[6], 2, sgid);
      62           6 : }
      63             : 
      64      196608 : SecurityGroup4ByteAs::SecurityGroup4ByteAs(const bytes_type &data) {
      65      196608 :     copy(data.begin(), data.end(), data_.begin());
      66      196608 : }
      67             : 
      68      196608 : as_t SecurityGroup4ByteAs::as_number() const {
      69      393216 :     if (data_[0] == BgpExtendedCommunityType::Experimental4ByteAs &&
      70      196608 :             data_[1] == BgpExtendedCommunityExperimentalSubType::SgId) {
      71      196608 :         as_t as_number = get_value(&data_[2], 4);
      72      196608 :         return as_number;
      73             :     }
      74           0 :     return 0;
      75             : }
      76             : 
      77           0 : uint32_t SecurityGroup4ByteAs::security_group_id() const {
      78           0 :     if (data_[0] == BgpExtendedCommunityType::Experimental4ByteAs &&
      79           0 :             data_[1] == BgpExtendedCommunityExperimentalSubType::SgId) {
      80           0 :         uint32_t num = get_value(&data_[6], 2);
      81           0 :         return num;
      82             :     }
      83           0 :     return 0;
      84             : }
      85             : 
      86           0 : bool SecurityGroup4ByteAs::IsGlobal() const {
      87           0 :     uint32_t sgid = security_group_id();
      88           0 :     return (sgid >= kMinGlobalId && sgid <= kMaxGlobalId);
      89             : }
      90             : 
      91           0 : string SecurityGroup4ByteAs::ToString() {
      92             :     char temp[50];
      93           0 :     snprintf(temp, sizeof(temp), "secgroup:%u:%u",
      94             :         as_number(), security_group_id());
      95           0 :     return string(temp);
      96             : }

Generated by: LCOV version 1.14