OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cfg_listener.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef vnsw_cfg_listener_h
6 #define vnsw_cfg_listener_h
7 
8 #include <map>
9 
10 class IFMapNode;
11 class AgentDBTable;
12 class DB;
13 
14 class CfgDBState : public DBState {
15 public:
16  CfgDBState() : notify_count_(0), uuid_(boost::uuids::nil_uuid()) { };
17  uint32_t notify_count_;
19 };
20 
21 class CfgListener {
22 public:
23  CfgListener(DB *database);
24  virtual ~CfgListener() { }
25 
26  // Data to register a DBTable listener
30  };
31 
32  // Data to register to non-DBTable listener
33  typedef boost::function<void(IFMapNode *)> NodeListenerCb;
34  struct CfgListenerInfo {
37  };
38 
39  // DBTable to listner-id map
40  typedef std::map<DBTableBase *, DBTableBase::ListenerId> CfgListenerIdMap;
41  // Map of IFNode object name to DBTable
42  typedef std::map<std::string, CfgTableListenerInfo> CfgListenerMap;
43  // Map of IFNode to listener callback info
44  typedef std::map<std::string, CfgListenerInfo> CfgListenerCbMap;
45 
46  void NodeListener(DBTablePartBase *partition, DBEntryBase *dbe);
47  void LinkListener(DBTablePartBase *partition, DBEntryBase *dbe);
48  void NodeCallback(DBTablePartBase *partition, DBEntryBase *dbe);
49  // Regsiter for a IFMap link
50  void LinkRegister(const std::string &link_mdata, AgentDBTable *table);
51  // Register DBTable for a IFMapNode
52  void Register(const std::string &id_type, AgentDBTable *table,
53  int need_property_id);
54  // Register callback function for a IFMapNode
55  void Register(const std::string &id_type, NodeListenerCb callback,
56  int need_property_id);
57  void Unregister(std::string type);
58 
62  void NodeReSync(IFMapNode *node);
63  void Init();
64  void Shutdown();
65 
66  bool CanUseNode(IFMapNode *node);
67  bool CanUseNode(IFMapNode *node, IFMapAgentTable *table);
68  bool SkipNode(IFMapNode *node);
69  bool SkipNode(IFMapNode *node, IFMapAgentTable *table);
70 
72 
73  // Callback invoked for each IFMap neighbor node
74  typedef boost::function<void(const Agent *agent, const char *name,
75  IFMapNode *node, AgentKey *key,
76  AgentData *data)>
78  // Iterate thru all IFMap neighbor nodes and invoke callback for each
79  // neighbor of given type
80  uint32_t ForEachAdjacentIFMapNode(const Agent *agent, IFMapNode *node,
81  const char *name, AgentKey *key,
82  AgentData *data, IFMapNodeCb cb);
83 
84  IFMapNode *FindAdjacentIFMapNode(const Agent *agent, IFMapNode *node,
85  const char *name);
86 private:
87  void UpdateSeenState(DBTableBase *table, DBEntryBase *dbe,
89  void LinkNotify(IFMapLink *link, IFMapNode *node, IFMapNode *peer,
90  const std::string &peer_type, CfgDBState *state,
94 
96 
101  void NodeNotify(AgentDBTable *oper_table, IFMapNode *node);
103 };
104 
105 #endif
void UpdateSeenState(DBTableBase *table, DBEntryBase *dbe, CfgDBState *state, DBTableBase::ListenerId id)
boost::function< void(IFMapNode *)> NodeListenerCb
Definition: cfg_listener.h:33
void NodeNotify(AgentDBTable *oper_table, IFMapNode *node)
void LinkRegister(const std::string &link_mdata, AgentDBTable *table)
uint32_t notify_count_
Definition: cfg_listener.h:16
void Shutdown()
int ListenerId
Definition: db_table.h:62
void Register(const std::string &id_type, AgentDBTable *table, int need_property_id)
boost::uuids::uuid uuid
IFMapNode * FindAdjacentIFMapNode(const Agent *agent, IFMapNode *node, const char *name)
CfgListenerMap cfg_link_listener_map_
Definition: cfg_listener.h:99
bool SkipNode(IFMapNode *node)
void Unregister(std::string type)
std::map< std::string, CfgListenerInfo > CfgListenerCbMap
Definition: cfg_listener.h:44
Definition: db.h:24
std::map< std::string, CfgTableListenerInfo > CfgListenerMap
Definition: cfg_listener.h:42
bool GetCfgDBStateUuid(IFMapNode *node, boost::uuids::uuid &id)
void LinkNotify(IFMapLink *link, IFMapNode *node, IFMapNode *peer, const std::string &peer_type, CfgDBState *state, DBTableBase::ListenerId id)
AgentDBTable * GetLinkOperDBTable(IFMapNode *node)
uint8_t type
Definition: load_balance.h:109
CfgListenerCbMap cfg_listener_cb_map_
Definition: cfg_listener.h:100
Definition: agent.h:358
void NodeReSync(IFMapNode *node)
boost::uuids::uuid uuid_
Definition: cfg_listener.h:18
virtual ~CfgListener()
Definition: cfg_listener.h:24
DB * database_
Definition: cfg_listener.h:95
AgentDBTable * GetOperDBTable(IFMapNode *node)
std::map< DBTableBase *, DBTableBase::ListenerId > CfgListenerIdMap
Definition: cfg_listener.h:40
CfgListenerMap cfg_listener_map_
Definition: cfg_listener.h:98
NodeListenerCb GetCallback(IFMapNode *node)
CfgListener(DB *database)
uint32_t ForEachAdjacentIFMapNode(const Agent *agent, IFMapNode *node, const char *name, AgentKey *key, AgentData *data, IFMapNodeCb cb)
void NodeCallback(DBTablePartBase *partition, DBEntryBase *dbe)
void NodeListener(DBTablePartBase *partition, DBEntryBase *dbe)
CfgDBState * GetCfgDBState(IFMapTable *table, DBEntryBase *dbe, DBTableBase::ListenerId &id)
boost::function< void(const Agent *agent, const char *name, IFMapNode *node, AgentKey *key, AgentData *data)> IFMapNodeCb
Definition: cfg_listener.h:77
DISALLOW_COPY_AND_ASSIGN(CfgListener)
CfgListenerIdMap cfg_listener_id_map_
Definition: cfg_listener.h:97
bool CanUseNode(IFMapNode *node)
void LinkListener(DBTablePartBase *partition, DBEntryBase *dbe)