OpenSDN source code
prouter_uve_table.h
Go to the documentation of this file.
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 
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
31  public:
32  typedef std::set<std::string> InterfaceSet;
34  const std::string name_;
35  uint16_t vlan_;
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>
47  typedef std::map<boost::uuids::uuid, LogicalInterfaceUveEntryPtr>
49  typedef std::pair<boost::uuids::uuid, LogicalInterfaceUveEntryPtr>
51 
52  struct PhysicalDeviceState : public DBState {
53  };
54 
55  struct ProuterInterfaceState : public DBState {
57  std::string physical_interface_;
58  ProuterInterfaceState() : physical_device_(boost::uuids::nil_uuid()),
60  }
61  };
62 
63  struct VmInterfaceState : public DBState {
65  VmInterfaceState() : logical_interface_(boost::uuids::nil_uuid()) {
66  }
67  };
68 
69  typedef std::set<boost::uuids::uuid> LogicalInterfaceSet;
70  struct ProuterUveEntry {
71  explicit ProuterUveEntry(const PhysicalDevice *p);
73  void AddPhysicalInterface(const Interface *itf);
74  void DeletePhysicalInterface(const Interface *itf);
75  void AddLogicalInterface(const LogicalInterface *itf);
77  void Reset();
78 
79  std::string name_;
83  bool changed_;
84  bool deleted_;
85  bool renewed_;
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 
93  explicit PhyInterfaceUveEntry(const Interface *pintf);
94  void Update(const Interface *pintf);
95  void FillLogicalInterfaceList(std::vector<std::string> &list) const;
96 
99  bool changed_;
100  bool deleted_;
101  bool renewed_;
102  };
103  typedef boost::shared_ptr<PhyInterfaceUveEntry> PhyInterfaceUveEntryPtr;
104  typedef std::map<std::string, PhyInterfaceUveEntryPtr>
106  typedef std::pair<std::string, PhyInterfaceUveEntryPtr>
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:
127 
128  private:
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;
136  bool SendProuterMsg(ProuterUveEntry *entry);
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);
145  void DeleteHandler(const PhysicalDevice *p);
146  void AddLogicalToPhysical(const Interface *p, const LogicalInterface *i);
148  void MarkDeletedLogical(const LogicalInterface *pintf);
149  void DeleteLogicalFromPhysical(const std::string &name,
150  const LogicalInterface *i);
152  const LogicalInterface *intf);
154  const LogicalInterface *intf);
155  const PhysicalDevice *InterfaceToProuter(const Interface *intf);
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);
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);
171  LogicalInterfaceUveEntry *entry);
172 
176  // Last visited Prouter by timer
179 
182 
186 };
187 
188 #endif // _ROOT_PROUTER_UVE_TABLE_H_
Definition: agent.h:361
int ListenerId
Definition: db_table.h:63
void DeleteHandler(const PhysicalDevice *p)
boost::shared_ptr< PhyInterfaceUveEntry > PhyInterfaceUveEntryPtr
const PhysicalDevice * InterfaceToProuter(const Interface *intf)
boost::uuids::uuid pr_timer_last_visited_
ProuterUveEntry * AddHandler(const PhysicalDevice *p)
void MarkChanged(const boost::uuids::uuid &li)
void FrameProuterMsg(ProuterUveEntry *entry, ProuterData *uve) const
void MarkDeletedPhysical(const Interface *pintf)
ProuterUveEntry * PDEntryToProuterUveEntry(const boost::uuids::uuid &u) const
void AddProuterLogicalInterface(const PhysicalDevice *p, const LogicalInterface *intf)
std::pair< boost::uuids::uuid, ProuterUveEntryPtr > UveProuterPair
bool SendProuterMsg(ProuterUveEntry *entry)
DBTableBase::ListenerId interface_listener_id_
boost::uuids::uuid li_timer_last_visited_
std::pair< std::string, PhyInterfaceUveEntryPtr > UvePhyInterfacePair
void InterfaceNotify(DBTablePartBase *partition, DBEntryBase *e)
UveProuterMap uve_prouter_map_
LogicalInterfaceMap uve_logical_interface_map_
std::map< boost::uuids::uuid, ProuterUveEntryPtr > UveProuterMap
void VmInterfaceHandler(DBTablePartBase *partition, DBEntryBase *e)
void AddUpdateLogicalInterface(const LogicalInterface *i)
boost::shared_ptr< LogicalInterfaceUveEntry > LogicalInterfaceUveEntryPtr
void SendProuterDeleteMsg(ProuterUveEntry *e)
void set_expiry_time(int time, Timer *timer)
std::map< boost::uuids::uuid, LogicalInterfaceUveEntryPtr > LogicalInterfaceMap
static const uint16_t kInvalidVlanId
DBTableBase::ListenerId physical_device_listener_id_
void MarkDeletedLogical(const LogicalInterface *pintf)
ProuterUveTable(Agent *agent, uint32_t default_intvl)
boost::shared_ptr< ProuterUveEntry > ProuterUveEntryPtr
void SendLogicalInterfaceDeleteMsg(const std::string &config_name)
void SendPhysicalInterfaceMsg(const std::string &name, PhyInterfaceUveEntry *entry)
void MarkPhysicalDeviceChanged(const PhysicalDevice *pde)
virtual ~ProuterUveTable()
virtual void DispatchProuterMsg(const ProuterData &uve)
void AddLogicalToPhysical(const Interface *p, const LogicalInterface *i)
std::set< std::string > InterfaceSet
void TimerCleanup(Timer *timer)
void PhysicalDeviceNotify(DBTablePartBase *partition, DBEntryBase *e)
ProuterUveEntryPtr Allocate(const PhysicalDevice *pr)
void UpdateMastership(const boost::uuids::uuid &u, bool value)
PhyInterfaceUveEntry * NameToPhyInterfaceUveEntry(const std::string &name) const
void DeletePhysicalFromProuter(const Interface *i, const boost::uuids::uuid &u)
virtual void DispatchPhysicalInterfaceMsg(const UvePhysicalInterfaceAgent &uve)
std::pair< boost::uuids::uuid, LogicalInterfaceUveEntryPtr > LogicalInterfacePair
virtual void DispatchLogicalInterfaceMsg(const UveLogicalInterfaceAgent &u)
void SendProuterVrouterAssociation()
void SendLogicalInterfaceMsg(const boost::uuids::uuid &u, LogicalInterfaceUveEntry *entry)
std::string pi_timer_last_visited_
void VMInterfaceAdd(const VmInterface *vmi)
std::map< std::string, PhyInterfaceUveEntryPtr > UvePhyInterfaceMap
void DeleteLogicalFromPhysical(const std::string &name, const LogicalInterface *i)
void DeleteProuterLogicalInterface(const boost::uuids::uuid &u, const LogicalInterface *intf)
void SendProuterMsgFromPhyInterface(const Interface *pi)
UvePhyInterfaceMap uve_phy_interface_map_
void SendPhysicalInterfaceDeleteMsg(const std::string &cfg_name)
DISALLOW_COPY_AND_ASSIGN(ProuterUveTable)
void PhysicalInterfaceHandler(const Interface *i, const boost::uuids::uuid &u)
const Interface * NameToInterface(const std::string &name) const
void VMInterfaceRemove(const boost::uuids::uuid &li, const VmInterface *vmi)
std::set< boost::uuids::uuid > LogicalInterfaceSet
void AddUpdatePhysicalInterface(const Interface *intf)
Definition: timer.h:58
SandeshTraceBufferPtr ProuterUveTraceBuf
boost::shared_ptr< TraceBuffer< SandeshTrace > > SandeshTraceBufferPtr
Definition: sandesh_trace.h:19
void FillVmInterfaceList(std::vector< std::string > &vmi_list) const
void Update(const LogicalInterface *li)
LogicalInterfaceUveEntry(const LogicalInterface *li)
void Update(const Interface *pintf)
PhyInterfaceUveEntry(const Interface *pintf)
void FillLogicalInterfaceList(std::vector< std::string > &list) const
bool DeleteLogicalInterface(const LogicalInterface *itf)
void AddPhysicalInterface(const Interface *itf)
ProuterUveEntry(const PhysicalDevice *p)
void AddLogicalInterface(const LogicalInterface *itf)
void DeletePhysicalInterface(const Interface *itf)
LogicalInterfaceSet logical_interface_set_
boost::uuids::uuid uuid