LCOV - code coverage report
Current view: top level - vnsw/agent/oper - mirror_table.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 16 48 33.3 %
Date: 2026-11-09 02:10:49 Functions: 10 30 33.3 %
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_mirror_table_hpp
       7             : #define vnsw_agent_mirror_table_hpp
       8             : 
       9             : #include <cmn/agent_cmn.h>
      10             : #include <cmn/agent.h>
      11             : #include <agent_types.h>
      12             : 
      13             : struct MirrorEntryKey : public AgentKey {
      14        1327 :     MirrorEntryKey(const std::string analyzer_name)
      15        1327 :             : analyzer_name_(analyzer_name) {
      16        1327 :     }
      17             :     std::string analyzer_name_;
      18             : };
      19             : 
      20             : struct MirrorEntryData : public AgentData {
      21             :     enum MirrorEntryFlags {
      22             :         DynamicNH_With_JuniperHdr = 1,
      23             :         DynamicNH_Without_JuniperHdr = 2,
      24             :         StaticNH_With_JuniperHdr = 3,
      25             :         StaticNH_Without_JuniperHdr = 4
      26             : 
      27             :     };
      28             : 
      29           0 :     MirrorEntryData(const std::string vrf_name, const IpAddress &sip,
      30             :                     const uint16_t sport, const IpAddress &dip,
      31             :                     const uint16_t dport, uint8_t mirror_flags,
      32           0 :                     uint32_t vni, const MacAddress &mac, bool createdvrf):
      33           0 :             vrf_name_(vrf_name), sip_(sip), sport_(sport), dip_(dip),
      34           0 :             dport_(dport), mirror_flags_(mirror_flags), vni_(vni),
      35           0 :             mac_(mac), createdvrf_(createdvrf),
      36           0 :             nic_assisted_mirroring_(false) { }
      37             : 
      38           0 :     MirrorEntryData(bool nic_assisted_mirroring,
      39           0 :             uint16_t nic_assisted_mirroring_vlan):
      40           0 :             nic_assisted_mirroring_(nic_assisted_mirroring),
      41           0 :             nic_assisted_mirroring_vlan_(nic_assisted_mirroring_vlan) {  }
      42             : 
      43             : 
      44             :     std::string vrf_name_;
      45             :     IpAddress sip_;
      46             :     uint16_t sport_;
      47             :     IpAddress dip_;
      48             :     uint16_t dport_;
      49             :     uint8_t mirror_flags_;
      50             :     uint32_t vni_;
      51             :     MacAddress mac_; // can be type of vtep mac or analyzer-mac based on type NH
      52             :     bool createdvrf_;
      53             :     bool nic_assisted_mirroring_;
      54             :     uint16_t nic_assisted_mirroring_vlan_;
      55             : };
      56             : 
      57             : class MirrorEntry : AgentRefCount<MirrorEntry>, public AgentDBEntry {
      58             : public:
      59        1327 :     MirrorEntry(std::string analyzer_name) :
      60        2654 :            analyzer_name_(analyzer_name), vrf_(NULL, this), nh_(NULL),
      61        3981 :            vrf_name_(""), createdvrf_(false) { };
      62        2654 :     virtual ~MirrorEntry() { };
      63             : 
      64             :     virtual bool IsLess(const DBEntry &rhs) const;
      65           0 :     virtual bool Change(const DBRequest *req) {return false;};
      66             : 
      67             :     virtual void SetKey(const DBRequestKey *key);
      68             :     virtual KeyPtr GetDBRequestKey() const;
      69           0 :     virtual std::string ToString() const { return "MirrorEntry";};
      70             : 
      71           0 :     uint32_t GetRefCount() const {
      72           0 :         return AgentRefCount<MirrorEntry>::GetRefCount();
      73             :     }
      74             :     bool DBEntrySandesh(Sandesh *sresp, std::string &name) const;
      75             :     void set_mirror_entrySandeshData(MirrorEntrySandeshData &data) const;
      76             :     uint32_t vrf_id() const;
      77             :     const VrfEntry *GetVrf() const;
      78           0 :     const std::string GetAnalyzerName() const {return analyzer_name_;}
      79           0 :     const IpAddress *GetSip() const {return &sip_;}
      80           0 :     uint16_t GetSPort() const {return sport_;}
      81           0 :     const IpAddress *GetDip() const {return &dip_;}
      82           0 :     uint16_t GetDPort() const {return dport_;}
      83         178 :     const NextHop *GetNH() const {return nh_.get();}
      84           0 :     const std::string vrf_name() const {return vrf_name_;}
      85           0 :     uint32_t GetVni() const {return vni_;}
      86           0 :     uint8_t GetMirrorFlag() const {return mirror_flags_;}
      87           0 :     const MacAddress *GetMac() const { return &mac_;}
      88           0 :     bool GetCreatedVrf() const {return createdvrf_;}
      89          94 :     uint16_t nic_assisted_mirroring_vlan() const {
      90          94 :         return nic_assisted_mirroring_vlan_;}
      91         150 :     bool nic_assisted_mirroring() const {
      92         150 :         return nic_assisted_mirroring_;
      93             :     }
      94           0 :     void set_mirror_index(uint32_t index) {mirror_index_ = index;}
      95           0 :     uint32_t mirror_index() const { return mirror_index_; }
      96             : private:
      97             :     std::string analyzer_name_;
      98             :     VrfEntryRef vrf_;
      99             :     IpAddress sip_;
     100             :     uint16_t sport_;
     101             :     IpAddress dip_;
     102             :     uint16_t dport_;
     103             :     NextHopRef nh_;
     104             :     std::string vrf_name_;
     105             :     uint8_t mirror_flags_;
     106             :     uint32_t vni_;
     107             :     MacAddress mac_; // can be type of vtep mac or analyzer-mac based on type NH
     108             :     // this vrf will be created if this mirror vrf is not known to compute node
     109             :     // add it subscribes for the route information to get down loaded
     110             :     bool createdvrf_;
     111             :     bool nic_assisted_mirroring_;
     112             :     uint16_t nic_assisted_mirroring_vlan_;
     113             :     uint32_t mirror_index_;
     114             :     friend class MirrorTable;
     115             : };
     116             : 
     117             : class MirrorTable : public AgentDBTable {
     118             : public:
     119             :     const static unsigned bufLen = 512;
     120             :     const static uint8_t kInvalidIndex = 0xFF;
     121             :     typedef std::vector<MirrorEntry *> MirrorEntryList;
     122             :     typedef std::map<std::string , MirrorEntryList> VrfMirrorEntryList;
     123             :     typedef std::pair<std::string , MirrorEntryList> VrfMirrorEntry;
     124             : 
     125           2 :     MirrorTable(DB *db, const std::string &name) : AgentDBTable(db, name) {
     126           2 :     }
     127             :     virtual ~MirrorTable();
     128             :     virtual std::unique_ptr<DBEntry> AllocEntry(const DBRequestKey *k) const;
     129           0 :     virtual size_t Hash(const DBEntry *entry) const {return 0;}
     130        1327 :     virtual size_t Hash(const DBRequestKey *key) const {return 0;}
     131             : 
     132             :     virtual DBEntry *Add(const DBRequest *req);
     133             :     virtual bool OnChange(DBEntry *entry, const DBRequest *req);
     134             :     virtual bool Delete(DBEntry *entry, const DBRequest *request);
     135           0 :     virtual bool Resync(DBEntry *entry, const DBRequest *req) {
     136           0 :         bool ret = OnChange(entry, req);
     137           0 :         return ret;
     138             :     }
     139             :     virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args,
     140             :                                             const std::string &context);
     141             :     VrfEntry *FindVrfEntry(const std::string &vrf_name) const;
     142             :     static void AddMirrorEntry(const std::string &analyzer_name,
     143             :                                const std::string &vrf_name,
     144             :                                const IpAddress &sip, uint16_t sport,
     145             :                                const IpAddress &dip, uint16_t dport);
     146             :     static void AddMirrorEntry(const std::string &analyzer_name,
     147             :                                const std::string &vrf_name,
     148             :                                const IpAddress &sip, uint16_t sport,
     149             :                                const IpAddress &dip, uint16_t dport,
     150             :                                uint32_t vni, uint8_t mirror_flag,
     151             :                                const MacAddress &mac);
     152             :     static void AddMirrorEntry(const std::string &analyzer_name,
     153             :                                uint32_t nic_assisted_mirroring_vlan);
     154             :     static void DelMirrorEntry(const std::string &analyzer_name);
     155             :     virtual void OnZeroRefcount(AgentDBEntry *e);
     156             :     static DBTableBase *CreateTable(DB *db, const std::string &name);
     157           2 :     static MirrorTable *GetInstance() {return mirror_table_;}
     158             :     void MirrorSockInit(void);
     159             :     void ReadHandler(const boost::system::error_code& error, size_t bytes);
     160             :     void AddUnresolved(MirrorEntry *entry);
     161             :     void RemoveUnresolved(MirrorEntry *entry);
     162             :     void AddResolvedVrfMirrorEntry(MirrorEntry *entry);
     163             :     void DeleteResolvedVrfMirrorEntry(MirrorEntry *entry);
     164             :     void ResyncMirrorEntry(VrfMirrorEntryList &list, const VrfEntry *vrf);
     165             :     void ResyncResolvedMirrorEntry(const VrfEntry *vrf);
     166             :     void ResyncUnresolvedMirrorEntry(const VrfEntry *vrf);
     167             :     void Add(VrfMirrorEntryList &vrf_entry_map, MirrorEntry *entry);
     168             :     void Delete(VrfMirrorEntryList &vrf_entry_map, MirrorEntry *entry);
     169             :     void VrfListenerInit();
     170             :     void VrfNotify(DBTablePartBase *root, DBEntryBase *entry);
     171             :     void Shutdown();
     172             :     void Initialize();
     173             :     bool OnChange(MirrorEntry *mirror_entry);
     174             :     struct MirrorVrfState : DBState {
     175           0 :         MirrorVrfState() : DBState(), seen_(false),
     176           0 :         bridge_rt_table_listener_id_(DBTableBase::kInvalidId) {}
     177             :         bool seen_;
     178             :         DBTableBase::ListenerId bridge_rt_table_listener_id_;
     179             :     };
     180             :     void BridgeRouteTableNotify(DBTablePartBase *partition, DBEntryBase *e);
     181             :     void UnRegisterBridgeRouteTableListener(const VrfEntry *entry,
     182             :                                             MirrorVrfState *state);
     183             :     bool UnresolvedMirrorVrf(const VrfEntry *vrf, VrfMirrorEntryList &list);
     184             :     MirrorEntry* GetMirrorEntry(VrfEntry *vrf, const MacAddress & mac,
     185             :                                 VrfMirrorEntryList &list);
     186             :     static MirrorEntryData::MirrorEntryFlags
     187             :         DecodeMirrorFlag (const std::string &nh_mode, bool juniper_header);
     188             :     void DeleteMirrorVrf(MirrorEntry *entry, bool del_from_vrf_list);
     189             :     bool IsConfigured();
     190             : private:
     191             :     std::unique_ptr<boost::asio::ip::udp::socket> udp_sock_;
     192             :     static MirrorTable *mirror_table_;
     193             :     char rx_buff_[bufLen];
     194             :     VrfMirrorEntryList unresolved_entry_list_;
     195             :     VrfMirrorEntryList resolved_entry_list_;
     196             :     DBTableBase::ListenerId vrf_listener_id_;
     197             : };
     198             : #endif

Generated by: LCOV version 1.14