Line data Source code
1 : /* 2 : * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : 6 : #ifndef _ROOT_PROUTER_UVE_TABLE_H_ 7 : #define _ROOT_PROUTER_UVE_TABLE_H_ 8 : 9 : #include <boost/scoped_ptr.hpp> 10 : #include <boost/shared_ptr.hpp> 11 : #include <boost/uuid/uuid_io.hpp> 12 : #include <prouter_types.h> 13 : #include <oper/interface_common.h> 14 : #include <oper/physical_device.h> 15 : #include <cmn/index_vector.h> 16 : #include <string> 17 : #include <vector> 18 : #include <set> 19 : #include <map> 20 : 21 : extern SandeshTraceBufferPtr ProuterUveTraceBuf; 22 : #define PROUTER_UVE_TRACE(...)\ 23 : do {\ 24 : ProuterUveTrace::TraceMsg(ProuterUveTraceBuf, __FILE__, __LINE__, __VA_ARGS__);\ 25 : } while (false) 26 : 27 : // The container class for objects representing Prouter UVEs 28 : // Defines routines for storing and managing (add, delete, change and send) 29 : // Prouter UVEs 30 : class ProuterUveTable { 31 : public: 32 : typedef std::set<std::string> InterfaceSet; 33 : struct LogicalInterfaceUveEntry { 34 : const std::string name_; 35 : uint16_t vlan_; 36 : InterfaceSet vmi_list_; 37 : bool changed_; 38 : bool deleted_; 39 : bool renewed_; 40 : 41 : explicit LogicalInterfaceUveEntry(const LogicalInterface *li); 42 : void Update(const LogicalInterface *li); 43 : void FillVmInterfaceList(std::vector<std::string> &vmi_list) const; 44 : }; 45 : typedef boost::shared_ptr<LogicalInterfaceUveEntry> 46 : LogicalInterfaceUveEntryPtr; 47 : typedef std::map<boost::uuids::uuid, LogicalInterfaceUveEntryPtr> 48 : LogicalInterfaceMap; 49 : typedef std::pair<boost::uuids::uuid, LogicalInterfaceUveEntryPtr> 50 : LogicalInterfacePair; 51 : 52 : struct PhysicalDeviceState : public DBState { 53 : }; 54 : 55 : struct ProuterInterfaceState : public DBState { 56 : boost::uuids::uuid physical_device_; 57 : std::string physical_interface_; 58 4 : ProuterInterfaceState() : physical_device_(boost::uuids::nil_uuid()), 59 2 : physical_interface_() { 60 2 : } 61 : }; 62 : 63 : struct VmInterfaceState : public DBState { 64 : boost::uuids::uuid logical_interface_; 65 169 : VmInterfaceState() : logical_interface_(boost::uuids::nil_uuid()) { 66 169 : } 67 : }; 68 : 69 : typedef std::set<boost::uuids::uuid> LogicalInterfaceSet; 70 : struct ProuterUveEntry { 71 : explicit ProuterUveEntry(const PhysicalDevice *p); 72 : ~ProuterUveEntry(); 73 : void AddPhysicalInterface(const Interface *itf); 74 : void DeletePhysicalInterface(const Interface *itf); 75 : void AddLogicalInterface(const LogicalInterface *itf); 76 : bool DeleteLogicalInterface(const LogicalInterface *itf); 77 : void Reset(); 78 : 79 : std::string name_; 80 : boost::uuids::uuid uuid_; 81 : InterfaceSet physical_interface_set_; 82 : LogicalInterfaceSet logical_interface_set_; 83 : bool changed_; 84 : bool deleted_; 85 : bool renewed_; 86 : bool mastership_; 87 : }; 88 : typedef boost::shared_ptr<ProuterUveEntry> ProuterUveEntryPtr; 89 : typedef std::map<boost::uuids::uuid, ProuterUveEntryPtr> UveProuterMap; 90 : typedef std::pair<boost::uuids::uuid, ProuterUveEntryPtr> UveProuterPair; 91 : 92 : struct PhyInterfaceUveEntry { 93 : explicit PhyInterfaceUveEntry(const Interface *pintf); 94 : void Update(const Interface *pintf); 95 : void FillLogicalInterfaceList(std::vector<std::string> &list) const; 96 : 97 : boost::uuids::uuid uuid_; 98 : LogicalInterfaceSet logical_interface_set_; 99 : bool changed_; 100 : bool deleted_; 101 : bool renewed_; 102 : }; 103 : typedef boost::shared_ptr<PhyInterfaceUveEntry> PhyInterfaceUveEntryPtr; 104 : typedef std::map<std::string, PhyInterfaceUveEntryPtr> 105 : UvePhyInterfaceMap; 106 : typedef std::pair<std::string, PhyInterfaceUveEntryPtr> 107 : UvePhyInterfacePair; 108 : 109 : static const uint16_t kInvalidVlanId = 0xFFFF; 110 : explicit ProuterUveTable(Agent *agent, uint32_t default_intvl); 111 : virtual ~ProuterUveTable(); 112 : void RegisterDBClients(); 113 : void Shutdown(void); 114 : virtual void DispatchProuterMsg(const ProuterData &uve); 115 : virtual void DispatchLogicalInterfaceMsg(const UveLogicalInterfaceAgent &u); 116 : virtual void DispatchPhysicalInterfaceMsg 117 : (const UvePhysicalInterfaceAgent &uve); 118 : bool TimerExpiry(); 119 : bool PITimerExpiry(); 120 : bool LITimerExpiry(); 121 : void UpdateMastership(const boost::uuids::uuid &u, bool value); 122 : 123 : protected: 124 : UveProuterMap uve_prouter_map_; 125 : UvePhyInterfaceMap uve_phy_interface_map_; 126 : LogicalInterfaceMap uve_logical_interface_map_; 127 : 128 : private: 129 : ProuterUveEntryPtr Allocate(const PhysicalDevice *pr); 130 : ProuterUveEntry *PDEntryToProuterUveEntry(const boost::uuids::uuid &u) const; 131 : PhyInterfaceUveEntry *NameToPhyInterfaceUveEntry(const std::string &name) 132 : const; 133 : const Interface *NameToInterface(const std::string &name) const; 134 : void FrameProuterMsg(ProuterUveEntry *entry, ProuterData *uve) const; 135 : void SendProuterDeleteMsg(ProuterUveEntry *e); 136 : bool SendProuterMsg(ProuterUveEntry *entry); 137 : void SendProuterMsgFromPhyInterface(const Interface *pi); 138 : void PhysicalDeviceNotify(DBTablePartBase *partition, DBEntryBase *e); 139 : void PhysicalInterfaceHandler(const Interface *i, const boost::uuids::uuid &u); 140 : void MarkDeletedPhysical(const Interface *pintf); 141 : void DeletePhysicalFromProuter(const Interface *i, 142 : const boost::uuids::uuid &u); 143 : void InterfaceNotify(DBTablePartBase *partition, DBEntryBase *e); 144 : ProuterUveEntry* AddHandler(const PhysicalDevice *p); 145 : void DeleteHandler(const PhysicalDevice *p); 146 : void AddLogicalToPhysical(const Interface *p, const LogicalInterface *i); 147 : void AddUpdateLogicalInterface(const LogicalInterface *i); 148 : void MarkDeletedLogical(const LogicalInterface *pintf); 149 : void DeleteLogicalFromPhysical(const std::string &name, 150 : const LogicalInterface *i); 151 : void AddProuterLogicalInterface(const PhysicalDevice *p, 152 : const LogicalInterface *intf); 153 : void DeleteProuterLogicalInterface(const boost::uuids::uuid &u, 154 : const LogicalInterface *intf); 155 : const PhysicalDevice *InterfaceToProuter(const Interface *intf); 156 : void SendProuterVrouterAssociation(); 157 : void set_expiry_time(int time, Timer *timer); 158 : void TimerCleanup(Timer *timer); 159 : void VmInterfaceHandler(DBTablePartBase *partition, DBEntryBase *e); 160 : void VMInterfaceAdd(const VmInterface *vmi); 161 : void VMInterfaceRemove(const boost::uuids::uuid &li, 162 : const VmInterface *vmi); 163 : void MarkPhysicalDeviceChanged(const PhysicalDevice *pde); 164 : void MarkChanged(const boost::uuids::uuid &li); 165 : void AddUpdatePhysicalInterface(const Interface *intf); 166 : void SendPhysicalInterfaceDeleteMsg(const std::string &cfg_name); 167 : void SendPhysicalInterfaceMsg(const std::string &name, 168 : PhyInterfaceUveEntry *entry); 169 : void SendLogicalInterfaceDeleteMsg(const std::string &config_name); 170 : void SendLogicalInterfaceMsg(const boost::uuids::uuid &u, 171 : LogicalInterfaceUveEntry *entry); 172 : 173 : Agent *agent_; 174 : DBTableBase::ListenerId physical_device_listener_id_; 175 : DBTableBase::ListenerId interface_listener_id_; 176 : // Last visited Prouter by timer 177 : boost::uuids::uuid pr_timer_last_visited_; 178 : Timer *pr_timer_; 179 : 180 : std::string pi_timer_last_visited_; 181 : Timer *pi_timer_; 182 : 183 : boost::uuids::uuid li_timer_last_visited_; 184 : Timer *li_timer_; 185 : DISALLOW_COPY_AND_ASSIGN(ProuterUveTable); 186 : }; 187 : 188 : #endif // _ROOT_PROUTER_UVE_TABLE_H_