LCOV - code coverage report
Current view: top level - vnsw/agent/oper - vrf_assign.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 3 30 10.0 %
Date: 2026-11-09 02:10:49 Functions: 4 27 14.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_vrf_assign_hpp
       7             : #define vnsw_agent_vrf_assign_hpp
       8             : 
       9             : #include <cmn/agent_cmn.h>
      10             : #include <cmn/agent.h>
      11             : 
      12             : /////////////////////////////////////////////////////////////////////////////
      13             : // Base class for VRF Assignment table. Implementation of specific types must
      14             : // derive from this class
      15             : /////////////////////////////////////////////////////////////////////////////
      16             : 
      17             : class VrfAssign : AgentRefCount<VrfAssign>, public AgentDBEntry {
      18             : public:
      19             :     enum Type {
      20             :         INVALID,
      21             :         VLAN
      22             :     };
      23             : 
      24             :     struct VrfAssignKey : public AgentKey {
      25           0 :         VrfAssignKey() : type_(INVALID) { };
      26           0 :         virtual ~VrfAssignKey() { };
      27             : 
      28             :         VrfAssign::Type type_;
      29             :         boost::uuids::uuid intf_uuid_;
      30             :         uint16_t vlan_tag_;
      31             : 
      32           0 :         void VlanInit(const boost::uuids::uuid intf_uuid, uint16_t vlan_tag) {
      33           0 :             type_ = VLAN;
      34           0 :             intf_uuid_ = intf_uuid;
      35           0 :             vlan_tag_ = vlan_tag;
      36           0 :         };
      37             :     };
      38             : 
      39             :     struct VrfAssignData : public AgentData {
      40           0 :         VrfAssignData(const std::string vrf_name) :
      41           0 :             AgentData(), vrf_name_(vrf_name) { };
      42           0 :         virtual ~VrfAssignData() { };
      43             : 
      44             :         const std::string vrf_name_;
      45             :     };
      46             : 
      47           0 :     VrfAssign(Type type, Interface *intrface)
      48           0 :         : type_(type), interface_(intrface), vrf_(NULL, this) { };
      49           0 :     virtual ~VrfAssign() { };
      50             : 
      51           0 :     uint32_t GetRefCount() const {
      52           0 :         return AgentRefCount<VrfAssign>::GetRefCount();
      53             :     };
      54             :     bool IsLess(const DBEntry &rhs) const;
      55             :     bool Change(const DBRequest *req);
      56             : 
      57             :     virtual bool VrfAssignIsLess(const VrfAssign &rhs) const = 0;
      58           0 :     virtual bool VrfAssignChange(const DBRequest *req) {return false;};
      59             : 
      60           0 :     const Type GetType() const {return type_;};
      61           0 :     const Interface *GetInterface() const {return interface_.get();};
      62           0 :     const VrfEntry *GetVrf() const {return vrf_.get();};
      63             : 
      64             : protected:
      65             :     friend class VrfAssignTable;
      66             :     void SetVrf(VrfEntry *vrf) {vrf_ = vrf;};
      67             :     Type type_;
      68             :     InterfaceRef interface_;
      69             :     VrfEntryRef vrf_;
      70             : private:
      71             :     DISALLOW_COPY_AND_ASSIGN(VrfAssign);
      72             : };
      73             : 
      74             : /////////////////////////////////////////////////////////////////////////////
      75             : // Data for VLAN based VRF Assignment
      76             : /////////////////////////////////////////////////////////////////////////////
      77             : class VlanVrfAssign : public VrfAssign {
      78             : public:
      79           0 :     VlanVrfAssign(Interface *intrface, uint16_t vlan_tag):
      80           0 :         VrfAssign(VLAN, intrface), vlan_tag_(vlan_tag), nh_(NULL) {}
      81           0 :     virtual ~VlanVrfAssign() {}
      82             :     bool VrfAssignIsLess(const VrfAssign &rhs) const;
      83             : 
      84           0 :     virtual std::string ToString() const {return "VlanVrfAssign";};
      85             : 
      86          10 :     const uint32_t GetVlanTag() const {return vlan_tag_;};
      87           0 :     const NextHop *nh() const {return nh_.get();}
      88             :     bool DBEntrySandesh(Sandesh *sresp, std::string &name) const;
      89             :     KeyPtr GetDBRequestKey() const;
      90             :     void SetKey(const DBRequestKey *key);
      91             :     virtual bool VrfAssignChange(const DBRequest *req);
      92             : 
      93             : private:
      94             :     uint16_t vlan_tag_;
      95             :     NextHopConstRef nh_;
      96             :     DISALLOW_COPY_AND_ASSIGN(VlanVrfAssign);
      97             : };
      98             : 
      99             : /////////////////////////////////////////////////////////////////////////////
     100             : // VRF Assignment table definition
     101             : /////////////////////////////////////////////////////////////////////////////
     102             : class VrfAssignTable : public AgentDBTable {
     103             : public:
     104           2 :     VrfAssignTable(DB *db, const std::string &name) : AgentDBTable(db, name) {}
     105           4 :     virtual ~VrfAssignTable() { }
     106             : 
     107           0 :     virtual size_t Hash(const DBEntry *entry) const {return 0;};
     108           0 :     virtual size_t Hash(const DBRequestKey *key) const {return 0;};
     109             : 
     110             :     virtual std::unique_ptr<DBEntry> AllocEntry(const DBRequestKey *k) const;
     111             :     virtual DBEntry *Add(const DBRequest *req);
     112             :     virtual bool OnChange(DBEntry *entry, const DBRequest *req);
     113             :     virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args,
     114             :                                             const std::string &context);
     115             : 
     116             :     static DBTableBase *CreateTable(DB *db, const std::string &name);
     117           0 :     static VrfAssignTable *GetInstance() {return vrf_assign_table_;};
     118             : 
     119             :     static Interface *FindInterface(const boost::uuids::uuid &intf_uuid);
     120             :     static VrfEntry *FindVrf(const std::string &name);
     121             : 
     122             :     static void CreateVlanReq(const boost::uuids::uuid &intf_uuid,
     123             :             const std::string &vrf_name, uint16_t vlan_tag);
     124             :     static void DeleteVlanReq(const boost::uuids::uuid &intf_uuid,
     125             :                               uint16_t vlan_tag);
     126             :     static void CreateVlan(const boost::uuids::uuid &intf_uuid,
     127             :             const std::string &vrf_name, uint16_t vlan_tag);
     128             :     static void DeleteVlan(const boost::uuids::uuid &intf_uuid,
     129             :                            uint16_t vlan_tag);
     130             :     static VrfAssign *FindVlanReq(const boost::uuids::uuid &intf_uuid,
     131             :                                   uint16_t vlan_tag);
     132             : 
     133             : private:
     134             :     static VrfAssignTable *vrf_assign_table_;
     135             :     VrfAssign *AllocWithKey(const DBRequestKey *k) const;
     136             :     DISALLOW_COPY_AND_ASSIGN(VrfAssignTable);
     137             : };
     138             : 
     139             : #endif // vnsw_agent_vrf_assign_hpp

Generated by: LCOV version 1.14