OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ifmap_exporter.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef __DB_IFMAP_EXPORTER_H__
6 #define __DB_IFMAP_EXPORTER_H__
7 
8 #include <list>
9 #include <memory>
10 #include <map>
11 #include <string>
12 #include <boost/crc.hpp> // for boost::crc_32_type
13 #include <boost/scoped_ptr.hpp>
14 #include <boost/unordered_set.hpp>
15 
16 #include "db/db_table.h"
17 
18 class BitSet;
19 
20 class IFMapClient;
21 class IFMapGraphWalker;
22 class IFMapLink;
23 class IFMapLinkState;
24 class IFMapNode;
25 class IFMapNodeState;
26 class IFMapServer;
27 class IFMapState;
28 class IFMapTable;
29 class IFMapUpdate;
30 class IFMapUpdateQueue;
31 class IFMapUpdateSender;
32 
34 
35 // The IFMapExporter makes sure that the right entries are added to the update
36 // queue. It uses the GraphWalker to calculate the 'interest' set for each node
37 // and then ensures that all clients see the necessary information. It also
38 // enforces ordering. All link add/change operations must come after the nodes
39 // they refer to have been advertised to the client. Add node delete operations
40 // must come after the links that refer to the node have been deleted.
42 public:
43  enum TrackerType {
47  };
48  typedef boost::unordered_set<IFMapState *> ConfigSet;
49  typedef ConfigSet::size_type CsSz_t;
50  typedef ConfigSet::const_iterator Cs_citer;
51  typedef std::vector<ConfigSet *> ClientConfigTracker;
52  typedef boost::crc_32_type::value_type crc32type;
53  explicit IFMapExporter(IFMapServer *server);
55 
56  void Initialize(DB *db);
57  void Shutdown();
58 
59  void StateUpdateOnDequeue(IFMapUpdate *update, const BitSet &dequeue_set,
60  bool is_delete);
61 
62  // GraphWalker API
63  DBTable::ListenerId TableListenerId(const DBTable *table) const;
64 
68 
70  IFMapServer *server() { return server_; }
71 
72  bool FilterNeighbor(IFMapNode *lnode, IFMapLink *link);
73 
74  void AddClientConfigTracker(int index);
75  void DeleteClientConfigTracker(int index);
76  void UpdateClientConfigTracker(IFMapState *state, const BitSet& client_bits,
77  bool add, TrackerType tracker_type);
78  void CleanupClientConfigTrackedEntries(int index);
79  bool ClientHasConfigTracker(TrackerType tracker_type, int index);
80  bool ClientConfigTrackerHasState(TrackerType tracker_type, int index,
81  IFMapState *state);
82  bool ClientConfigTrackerEmpty(TrackerType tracker_type, int index);
83  size_t ClientConfigTrackerSize(TrackerType tracker_type, int index);
84  Cs_citer ClientConfigTrackerBegin(TrackerType tracker_type, int index) const;
85  Cs_citer ClientConfigTrackerEnd(TrackerType tracker_type, int index) const;
86 
87  void StateInterestSet(IFMapState *state, const BitSet& interest_bits);
88  void StateInterestOr(IFMapState *state, const BitSet& interest_bits);
89  void StateInterestReset(IFMapState *state, const BitSet& interest_bits);
90  void StateAdvertisedOr(IFMapState *state, const BitSet& interest_bits);
91  void StateAdvertisedReset(IFMapState *state, const BitSet& interest_bits);
92 
94  void ResetLinkDeleteClients(const BitSet &bset);
95 
96 private:
97  friend class XmppIfmapTest;
98  class TableInfo;
99  typedef std::map<DBTable *, TableInfo *> TableMap;
100 
101  // Database listener for IFMap identifier (and link attr) tables.
102  void NodeTableExport(DBTablePartBase *partition, DBEntryBase *entry);
103  // Database listener for the IFMapLink DB Table.
104  void LinkTableExport(DBTablePartBase *partition, DBEntryBase *entry);
105 
106  template <class ObjectType>
107  bool UpdateAddChange(ObjectType *obj, IFMapState *state,
108  const BitSet &add_set, const BitSet &rm_set,
109  bool change);
110  template <class ObjectType>
111  bool UpdateRemove(ObjectType *obj, IFMapState *state,
112  const BitSet &rm_set);
113  template <class ObjectType>
114  void EnqueueDelete(ObjectType *obj, IFMapState *state);
115 
116  void MoveDependentLinks(IFMapNodeState *state);
117  void RemoveDependentLinks(IFMapNodeState *state, const BitSet &rm_set);
118  void MoveAdjacentNode(IFMapNodeState *state);
119  void ProcessAdjacentNode(IFMapNode *node, const BitSet &add_set,
120  IFMapNodeState *state, bool force_process=false);
121 
122  bool IsFeasible(const IFMapNode *node);
123 
124  const BitSet *MergeClientInterest(IFMapNode *node, IFMapNodeState *state,
125  std::unique_ptr<BitSet> *ptr);
126 
127  const TableInfo *Find(const DBTable *table) const;
128 
129  void TableStateClear(DBTable *table, DBTable::ListenerId tsid);
130  bool ConfigChanged(IFMapNode *node);
131  void DeleteStateIfAppropriate(DBTable *table, DBEntryBase *entry,
132  IFMapState *state);
133 
136 
138  boost::scoped_ptr<IFMapGraphWalker> walker_;
140 
143 };
144 
145 #endif
IFMapUpdateQueue * queue()
void MoveDependentLinks(IFMapNodeState *state)
bool ClientConfigTrackerEmpty(TrackerType tracker_type, int index)
void DeleteStateIfAppropriate(DBTable *table, DBEntryBase *entry, IFMapState *state)
bool IsFeasible(const IFMapNode *node)
const TableInfo * Find(const DBTable *table) const
void UpdateClientConfigTracker(IFMapState *state, const BitSet &client_bits, bool add, TrackerType tracker_type)
void RemoveDependentLinks(IFMapNodeState *state, const BitSet &rm_set)
bool ConfigChanged(IFMapNode *node)
IFMapUpdateSender * sender()
boost::scoped_ptr< IFMapGraphWalker > walker_
const BitSet * MergeClientInterest(IFMapNode *node, IFMapNodeState *state, std::unique_ptr< BitSet > *ptr)
DBTable * link_table_
TableMap table_map_
void ProcessAdjacentNode(IFMapNode *node, const BitSet &add_set, IFMapNodeState *state, bool force_process=false)
void NodeTableExport(DBTablePartBase *partition, DBEntryBase *entry)
void StateInterestReset(IFMapState *state, const BitSet &interest_bits)
boost::crc_32_type::value_type crc32type
DBTable * link_table()
friend class XmppIfmapTest
int ListenerId
Definition: db_table.h:62
void AddClientConfigTracker(int index)
void StateInterestSet(IFMapState *state, const BitSet &interest_bits)
void StateAdvertisedReset(IFMapState *state, const BitSet &interest_bits)
const IFMapTypenameWhiteList & get_traversal_white_list() const
IFMapServer * server()
void LinkTableExport(DBTablePartBase *partition, DBEntryBase *entry)
void EnqueueDelete(ObjectType *obj, IFMapState *state)
Cs_citer ClientConfigTrackerEnd(TrackerType tracker_type, int index) const
Cs_citer ClientConfigTrackerBegin(TrackerType tracker_type, int index) const
DBTable::ListenerId TableListenerId(const DBTable *table) const
bool ClientHasConfigTracker(TrackerType tracker_type, int index)
Definition: db.h:24
IFMapNodeState * NodeStateLocate(IFMapNode *node)
void TableStateClear(DBTable *table, DBTable::ListenerId tsid)
bool UpdateRemove(ObjectType *obj, IFMapState *state, const BitSet &rm_set)
bool ClientConfigTrackerHasState(TrackerType tracker_type, int index, IFMapState *state)
IFMapNodeState * NodeStateLookup(IFMapNode *node)
void StateInterestOr(IFMapState *state, const BitSet &interest_bits)
ConfigSet::const_iterator Cs_citer
boost::unordered_set< IFMapState * > ConfigSet
void StateAdvertisedOr(IFMapState *state, const BitSet &interest_bits)
void CleanupClientConfigTrackedEntries(int index)
std::map< DBTable *, TableInfo * > TableMap
IFMapServer * server_
Definition: bitset.h:17
std::vector< ConfigSet * > ClientConfigTracker
void StateUpdateOnDequeue(IFMapUpdate *update, const BitSet &dequeue_set, bool is_delete)
size_t ClientConfigTrackerSize(TrackerType tracker_type, int index)
void MoveAdjacentNode(IFMapNodeState *state)
IFMapExporter(IFMapServer *server)
bool UpdateAddChange(ObjectType *obj, IFMapState *state, const BitSet &add_set, const BitSet &rm_set, bool change)
ConfigSet::size_type CsSz_t
void Initialize(DB *db)
void ResetLinkDeleteClients(const BitSet &bset)
IFMapLinkState * LinkStateLookup(IFMapLink *link)
bool FilterNeighbor(IFMapNode *lnode, IFMapLink *link)
void DeleteClientConfigTracker(int index)
ClientConfigTracker client_config_tracker_[TT_END]