LCOV - code coverage report
Current view: top level - bgp/large-community - tag.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 6 7 85.7 %
Date: 2026-11-09 02:10:49 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2017 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #ifndef SRC_BGP_LARGE_COMMUNITY_TAG_H_
       7             : #define SRC_BGP_LARGE_COMMUNITY_TAG_H_
       8             : 
       9             : #include <boost/array.hpp>
      10             : #include <stdint.h>
      11             : #include <string>
      12             : 
      13             : #include "base/parse_object.h"
      14             : #include "bgp/bgp_common.h"
      15             : 
      16             : /// @brief Represents a single BGP Large Community tag.
      17             : class TagLC {
      18             : public:
      19             :     /// Fixed size (in bytes) of a BGP Large Community value.
      20             :     static const int kSize = 12;
      21             :     /// Minimum tag id to belong to a global community.
      22             :     static const int kMinGlobalId = 8000000;
      23             :     /// Raw 12-byte type representing the community on the wire.
      24             :     typedef boost::array<uint8_t, kSize> bytes_type;
      25             : 
      26             :     /// Construct from a raw 12-byte value.
      27             :     explicit TagLC(const bytes_type &data);
      28             :     /// Construct from AS number and tag value.
      29             :     explicit TagLC(as_t asn, uint64_t tag);
      30             :     /// Returns a string representation.
      31             :     std::string ToString() const;
      32             : 
      33             :     /// Returns true if this tag belongs to a global community.
      34             :     bool IsGlobal() const;
      35             :     /// Returns the AS number.
      36             :     as_t as_number() const;
      37             :     /// Returns the tag id.
      38             :     uint64_t tag() const;
      39             : 
      40             :     /// Returns the community value as a vector of 3 32-bit integers.
      41          80 :     const std::vector<uint32_t> GetLargeCommunityValue() const {
      42          80 :         std::vector<uint32_t> lc_val;
      43         320 :         for (int i =0; i < 3; i++) {
      44         240 :             uint32_t value = get_value(data_.begin() + 4*i, 4);
      45         240 :             lc_val.push_back(value);
      46             :         }
      47          80 :         return lc_val;
      48           0 :     }
      49             : 
      50             : private:
      51             :     /// Raw 12-byte encoded Large Community value.
      52             :     bytes_type data_;
      53             : };
      54             : 
      55             : #endif  // SRC_BGP_LARGE_COMMUNITY_TAG_H_

Generated by: LCOV version 1.14