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