LCOV - code coverage report
Current view: top level - bfd - bfd_common.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 33 33 100.0 %
Date: 2026-06-08 02:02:55 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2014 CodiLime, Inc. All rights reserved.
       3             :  */
       4             : #ifndef SRC_BFD_BFD_COMMON_H_
       5             : #define SRC_BFD_BFD_COMMON_H_
       6             : 
       7             : #include <ostream>
       8             : #include <string>
       9             : #include <boost/asio.hpp>
      10             : #include <boost/optional.hpp>
      11             : #include <boost/date_time.hpp>
      12             : #include <boost/random/taus88.hpp>
      13             : 
      14             : #include "base/util.h"
      15             : 
      16             : namespace BFD {
      17             : typedef uint32_t Discriminator;
      18             : typedef boost::posix_time::time_duration TimeInterval;
      19             : typedef uint32_t ClientId;
      20             : 
      21             : enum BFDState {
      22             :     kAdminDown, kDown, kInit, kUp
      23             : };
      24             : 
      25             : enum Port {
      26             :     kSingleHop = 3784,
      27             :     kMultiHop = 4784,
      28             :     kSendPortMin = 49152,
      29             :     kSendPortMax = 65535,
      30             : };
      31             : 
      32             : enum AuthType {
      33             :     kReserved,
      34             :     kSimplePassword,
      35             :     kKeyedMD5,
      36             :     kMeticulousKeyedMD5,
      37             :     kKeyedSHA1,
      38             :     kMeticulousKeyedSHA1,
      39             : };
      40             : 
      41             : enum ResultCode {
      42             :     kResultCode_Ok,
      43             :     kResultCode_UnknownSession,
      44             :     kResultCode_Error,
      45             :     kResultCode_InvalidPacket,
      46             :     kResultCode_NotImplemented,
      47             : };
      48             : 
      49             : enum Diagnostic {
      50             :     kNoDiagnostic,
      51             :     kControlDetectionTimeExpired,
      52             :     kEchoFunctionFailed,
      53             :     kNeighborSignaledSessionDown,
      54             :     kForwardingPlaneReset,
      55             :     kPathDown,
      56             :     kConcatenatedPathDown,
      57             :     kAdministrativelyDown,
      58             :     kReverseConcatenatedPathDown,
      59             :     kDiagnosticFirstInvalid
      60             : };
      61             : 
      62             : std::ostream &operator<<(std::ostream &, enum BFDState);
      63             : boost::optional<BFDState> BFDStateFromString(const std::string& s);
      64             : 
      65             : struct SessionIndex {
      66             : public:
      67         610 :     SessionIndex(uint32_t if_index = 0, uint32_t vrf_index = 0) :
      68         610 :             if_index(if_index), vrf_index(vrf_index) { }
      69       45262 :     bool operator<(const SessionIndex &other) const {
      70       45262 :         BOOL_KEY_COMPARE(if_index, other.if_index);
      71       44433 :         BOOL_KEY_COMPARE(vrf_index, other.vrf_index);
      72       43588 :         return false;
      73             :     }
      74             : 
      75          29 :     const std::string to_string() const {
      76          29 :         std::ostringstream os;
      77          29 :         os << "if_index:" << if_index << ", vrf_index: " << vrf_index;
      78          58 :         return os.str();
      79          29 :     }
      80             : 
      81             :     uint32_t if_index;
      82             :     uint32_t vrf_index;
      83             : };
      84             : 
      85             : struct SessionKey {
      86             : public:
      87          54 :     SessionKey(const boost::asio::ip::address &remote_address,
      88             :                const SessionIndex &session_index = SessionIndex(),
      89             :                uint16_t remote_port = kSingleHop,
      90             :                const boost::asio::ip::address &local_address =
      91          54 :                    boost::asio::ip::address()) :
      92          54 :             local_address(local_address),
      93          54 :             remote_address(remote_address), index(session_index),
      94          54 :             remote_port(remote_port) {
      95          54 :     }
      96             : 
      97         139 :     SessionKey() : remote_port(kSingleHop) { }
      98             : 
      99       23984 :     bool operator<(const SessionKey &other) const {
     100       23984 :         BOOL_KEY_COMPARE(local_address, other.local_address);
     101       23562 :         BOOL_KEY_COMPARE(remote_address, other.remote_address);
     102       23196 :         BOOL_KEY_COMPARE(remote_port, other.remote_port);
     103       23196 :         BOOL_KEY_COMPARE(index, other.index);
     104       21564 :         return false;
     105             :     }
     106             : 
     107          29 :     const std::string to_string() const {
     108          29 :         std::ostringstream os;
     109          29 :         os << local_address << ":" << remote_address << ":";
     110          29 :         os << index.to_string() << ":" << ":" << remote_port;
     111          58 :         return os.str();
     112          29 :     }
     113             : 
     114             :     boost::asio::ip::address local_address;
     115             :     boost::asio::ip::address remote_address;
     116             :     SessionIndex index; // InterfaceIndex or VrfIndex
     117             :     uint16_t remote_port;
     118             : };
     119             : 
     120             : struct SessionConfig {
     121         186 :     SessionConfig() : desiredMinTxInterval(boost::posix_time::seconds(1)),
     122         186 :         requiredMinRxInterval(boost::posix_time::seconds(0)),
     123         186 :         detectionTimeMultiplier(1) {}
     124             : 
     125             :     TimeInterval desiredMinTxInterval;  // delay
     126             :     TimeInterval requiredMinRxInterval; // timeout
     127             :     int detectionTimeMultiplier;        // max-retries ?
     128             : };
     129             : 
     130             : typedef boost::function<void(const SessionKey &key,
     131             :                              const BFD::BFDState &state)> ChangeCb;
     132             : extern const int kMinimalPacketLength;
     133             : extern const TimeInterval kIdleTxInterval;
     134             : extern boost::random::taus88 randomGen;
     135             : }  // namespace BFD
     136             : 
     137             : #endif  // SRC_BFD_BFD_COMMON_H_

Generated by: LCOV version 1.14