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