LCOV - code coverage report
Current view: top level - bgp/tunnel_encap - tunnel_encap.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 31 32 96.9 %
Date: 2026-11-09 02:10:49 Functions: 6 6 100.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/tunnel_encap/tunnel_encap.h"
       7             : 
       8             : 
       9             : #include <algorithm>
      10             : #include <sstream>
      11             : 
      12             : 
      13             : using std::copy;
      14             : using std::fill;
      15             : using std::string;
      16             : 
      17       61121 : TunnelEncap::TunnelEncap(string encap) {
      18       61121 :     fill(data_.begin(), data_.end(), 0);
      19       61119 :     TunnelEncapType::Encap id = TunnelEncapType::TunnelEncapFromString(encap);
      20       61118 :     if (id == TunnelEncapType::UNSPEC) return;
      21       61117 :     data_[0] = 0x03;
      22       61117 :     data_[1] = 0x0C;
      23             :     // Reserved
      24       61117 :     put_value(&data_[2], 4, 0);
      25       61118 :     put_value(&data_[6], 2, id);
      26             : }
      27             : 
      28        4843 : TunnelEncap::TunnelEncap(TunnelEncapType::Encap tunnel_encap) {
      29        4843 :     fill(data_.begin(), data_.end(), 0);
      30        4842 :     data_[0] = 0x03;
      31        4842 :     data_[1] = 0x0C;
      32             :     // Reserved
      33        4842 :     put_value(&data_[2], 4, 0);
      34        4843 :     put_value(&data_[6], 2, tunnel_encap);
      35        4843 : }
      36             : 
      37      652533 : TunnelEncap::TunnelEncap(const bytes_type &data) {
      38      652533 :     copy(data.begin(), data.end(), data_.begin());
      39      652588 : }
      40             : 
      41     1160796 : TunnelEncapType::Encap TunnelEncap::tunnel_encap() const {
      42     1160796 :     if (data_[0] != 0x03 || data_[1] != 0x0c)
      43           3 :         return TunnelEncapType::UNSPEC;
      44     1160789 :     uint16_t value = get_value(&data_[6], 2);
      45     1160841 :     if (TunnelEncapType::TunnelEncapIsValid(value)) {
      46     1160618 :         return static_cast<TunnelEncapType::Encap>(value);
      47             :     } else {
      48           3 :         return TunnelEncapType::UNSPEC;
      49             :     }
      50             : }
      51             : 
      52        4266 : string TunnelEncap::ToString() {
      53        4266 :     string str("encapsulation:");
      54        4266 :     str += TunnelEncapType::TunnelEncapToString(tunnel_encap());
      55        4266 :     return str;
      56           0 : }
      57             : 
      58      476716 : string TunnelEncap::ToXmppString() {
      59      476716 :     return TunnelEncapType::TunnelEncapToXmppString(tunnel_encap());
      60             : }

Generated by: LCOV version 1.14