LCOV - code coverage report
Current view: top level - vnsw/agent/oper - tunnel_nh.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 14 60 23.3 %
Date: 2026-11-09 02:10:49 Functions: 12 39 30.8 %
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             : #ifndef vnsw_agent_tunnel_nh_hpp
       7             : #define vnsw_agent_tunnel_nh_hpp
       8             : 
       9             : #include <base/dependency.h>
      10             : #include <cmn/agent_cmn.h>
      11             : #include <cmn/agent.h>
      12             : #include <oper/nexthop.h>
      13             : #include <oper/agent_route.h>
      14             : 
      15             : class TunnelNH : public NextHop {
      16             : public:
      17             :     TunnelNH(VrfEntry *vrf, const Ip4Address &sip, const Ip4Address &dip,
      18             :              bool policy, TunnelType type, const MacAddress &rewrite_dmac);
      19             :     virtual ~TunnelNH();
      20             : 
      21           0 :     virtual std::string ToString() const {
      22           0 :         return "Tunnel to " + dip_.to_string() +
      23           0 :             " rewrite mac " + rewrite_dmac_.ToString();
      24             :     }
      25             :     virtual bool NextHopIsLess(const DBEntry &rhs) const;
      26         566 :     virtual bool TunnelNextHopIsLess(const DBEntry &rhs) const {
      27         566 :         return false;
      28             :     }
      29             :     virtual void SetKey(const DBRequestKey *key);
      30             :     virtual bool ChangeEntry(const DBRequest *req);
      31             :     virtual void Delete(const DBRequest *req);
      32             :     virtual KeyPtr GetDBRequestKey() const;
      33             :     virtual bool CanAdd() const;
      34             : 
      35             :     const uint32_t vrf_id() const;
      36         429 :     const VrfEntry *GetVrf() const {return vrf_.get();};
      37         354 :     const Ip4Address *GetSip() const {return &sip_;};
      38         615 :     const Ip4Address *GetDip() const {return &dip_;};
      39           0 :     const AgentRoute *GetRt() const {return tunnel_dst_rt_;};
      40           0 :     const MacAddress *GetDmac() const {return &(encap_list_[0]->dmac_);}
      41           0 :     const bool &IsEncapValid(const uint32_t &i) const {return encap_list_[i]->valid_;}
      42         215 :     const MacAddress &rewrite_dmac() const {return rewrite_dmac_;}
      43         313 :     const TunnelType &GetTunnelType() const {return tunnel_type_;};
      44         215 :     const Interface *GetCryptInterface() const {return crypt_interface_.get();};
      45         215 :     bool GetCrypt() const {return crypt_;};
      46         215 :     bool GetCryptTunnelAvailable() const {return crypt_tunnel_available_;};
      47             :     virtual void SendObjectLog(const NextHopTable *table,
      48             :                                AgentLogEvent::type event) const;
      49          48 :     virtual bool DeleteOnZeroRefCount() const {
      50          48 :         return true;
      51             :     }
      52             : 
      53           0 :     virtual bool MatchEgressData(const NextHop *nh) const {
      54           0 :         const TunnelNH *tun_nh = dynamic_cast<const TunnelNH *>(nh);
      55           0 :         if (tun_nh && vrf_ == tun_nh->vrf_ && dip_ == tun_nh->dip_) {
      56           0 :             return true;
      57             :         }
      58           0 :         return false;
      59             :     }
      60          91 :     virtual bool NeedMplsLabel() { return false; }
      61             : 
      62             :     struct EncapData {
      63         283 :         EncapData(NextHop *nh, InterfaceConstRef intf) : arp_rt_(nh), interface_(intf), valid_(false) {}
      64             :         DependencyRef<NextHop, AgentRoute> arp_rt_;
      65             :         InterfaceConstRef interface_;
      66             :         MacAddress dmac_;
      67             :         bool valid_;
      68             :     };
      69             :     typedef boost::shared_ptr<EncapData> EncapDataPtr;
      70             :     typedef std::vector<EncapDataPtr> EncapDataList;
      71           0 :     const EncapDataList GetEncapDataList() const { return encap_list_; };
      72             : protected:
      73             :     VrfEntryRef vrf_;
      74             :     Ip4Address sip_;
      75             :     Ip4Address dip_;
      76             :     TunnelType tunnel_type_;
      77             :     AgentRoute* tunnel_dst_rt_;
      78             :     EncapDataList encap_list_;
      79             :     bool crypt_;
      80             :     bool crypt_tunnel_available_;
      81             :     InterfaceConstRef crypt_interface_;
      82             :     MacAddress rewrite_dmac_;
      83             : private:
      84             :     DISALLOW_COPY_AND_ASSIGN(TunnelNH);
      85             : };
      86             : 
      87             : class LabelledTunnelNH : public TunnelNH {
      88             : public:
      89             :     LabelledTunnelNH(VrfEntry *vrf, const Ip4Address &sip,
      90             :             const Ip4Address &dip, bool policy, TunnelType type,
      91             :             const MacAddress &rewrite_dmac, uint32_t label);
      92             :     virtual ~LabelledTunnelNH();
      93             : 
      94           0 :     virtual std::string ToString() const {
      95           0 :         return "Tunnel to " + GetDip()->to_string() +
      96           0 :             " rewrite mac " + rewrite_dmac().ToString();
      97             :     }
      98             :     virtual bool TunnelNextHopIsLess(const DBEntry &rhs) const;
      99             :     virtual bool ChangeEntry(const DBRequest *req);
     100             :     virtual KeyPtr GetDBRequestKey() const;
     101           0 :     uint32_t const GetTransportLabel() const { return transport_mpls_label_;};
     102             : 
     103             :     virtual void SendObjectLog(const NextHopTable *table,
     104             :                              AgentLogEvent::type event) const;
     105           0 :     virtual bool DeleteOnZeroRefCount() const {
     106           0 :         return true;
     107             :     }
     108             : 
     109           0 :     virtual bool NeedMplsLabel() { return false; }
     110           0 :     TunnelType::Type const GetTransportTunnelType() const  {
     111           0 :                 return transport_tunnel_type_;}
     112             :     void SetTransportTunnelType() {
     113             :         transport_tunnel_type_ = TunnelType::ComputeType(
     114             :                             TunnelType::MplsType());
     115             :     }
     116             : private:
     117             :     uint32_t transport_mpls_label_;
     118             :     TunnelType::Type transport_tunnel_type_;
     119             :     DISALLOW_COPY_AND_ASSIGN(LabelledTunnelNH);
     120             : };
     121             : /////////////////////////////////////////////////////////////////////////////
     122             : // Mirror NH definition
     123             : /////////////////////////////////////////////////////////////////////////////
     124             : class MirrorNHKey : public NextHopKey {
     125             : public:
     126           0 :     MirrorNHKey(const string &vrf_name, const IpAddress &sip,
     127             :                 const uint16_t sport, const IpAddress &dip,
     128           0 :                 const uint16_t dport) :
     129           0 :         NextHopKey(NextHop::MIRROR, false), vrf_key_(vrf_name), sip_(sip),
     130           0 :         dip_(dip), sport_(sport), dport_(dport){
     131           0 :     };
     132           0 :     virtual ~MirrorNHKey() { };
     133             : 
     134             :     virtual NextHop *AllocEntry() const;
     135           0 :     virtual NextHopKey *Clone() const {
     136           0 :         return new MirrorNHKey(vrf_key_.name_, sip_, sport_, dip_, dport_);
     137             :     }
     138             : private:
     139             :     friend class MirrorNH;
     140             :     VrfKey vrf_key_;
     141             :     IpAddress sip_;
     142             :     IpAddress dip_;
     143             :     uint16_t sport_;
     144             :     uint16_t dport_;
     145             :     DISALLOW_COPY_AND_ASSIGN(MirrorNHKey);
     146             : };
     147             : 
     148             : class MirrorNHData : public NextHopData {
     149             : public:
     150             :     MirrorNHData() : NextHopData() {};
     151             :     virtual ~MirrorNHData() { };
     152             : private:
     153             :     friend class MirrorNH;
     154             :     DISALLOW_COPY_AND_ASSIGN(MirrorNHData);
     155             : };
     156             : 
     157             : class MirrorNH : public NextHop {
     158             : public:
     159             :     MirrorNH(const VrfKey &vkey, const IpAddress &sip, uint16_t sport,
     160             :              const IpAddress &dip, uint16_t dport);
     161           0 :     virtual ~MirrorNH() { }
     162             : 
     163             :     virtual bool NextHopIsLess(const DBEntry &rhs) const;
     164             :     virtual void SetKey(const DBRequestKey *key);
     165             :     virtual bool ChangeEntry(const DBRequest *req);
     166             :     virtual void Delete(const DBRequest *req);
     167             :     virtual KeyPtr GetDBRequestKey() const;
     168             :     virtual bool CanAdd() const;
     169             : 
     170             :     const uint32_t vrf_id() const;
     171           0 :     const VrfEntry *GetVrf() const {return vrf_.get();}
     172           0 :     const IpAddress *GetSip() const {return &sip_;}
     173           0 :     const uint16_t GetSPort() const {return sport_;}
     174           0 :     const IpAddress *GetDip() const {return &dip_;}
     175           0 :     const uint16_t GetDPort() const {return dport_;}
     176           0 :     const AgentRoute *GetRt() const {return arp_rt_.get();}
     177           0 :     virtual std::string ToString() const {
     178           0 :         return "Mirror to " + dip_.to_string();
     179             :     }
     180             :     virtual void SendObjectLog(const NextHopTable *table,
     181             :                                AgentLogEvent::type event) const;
     182           0 :     virtual bool DeleteOnZeroRefCount() const {
     183           0 :         return true;
     184             :     }
     185           0 :     virtual bool MatchEgressData(const NextHop *nh) const {
     186           0 :         const MirrorNH *mir_nh = dynamic_cast<const MirrorNH *>(nh);
     187           0 :         if (mir_nh && vrf_ == mir_nh->vrf_ && dip_ == mir_nh->dip_) {
     188           0 :             return true;
     189             :         }
     190           0 :         return false;
     191             :     }
     192           0 :     virtual bool NeedMplsLabel() { return false; }
     193             : private:
     194             :     InetUnicastAgentRouteTable *GetRouteTable();
     195             :     std::string vrf_name_;
     196             :     VrfEntryRef vrf_;
     197             :     IpAddress sip_;
     198             :     uint16_t sport_;
     199             :     IpAddress dip_;
     200             :     uint16_t dport_;
     201             :     DependencyRef<NextHop, AgentRoute> arp_rt_;
     202             :     InterfaceConstRef interface_;
     203             :     MacAddress dmac_;
     204             :     DISALLOW_COPY_AND_ASSIGN(MirrorNH);
     205             : };
     206             : #endif

Generated by: LCOV version 1.14