/
ifmap_exporter.h
108 lines (84 loc) · 3.39 KB
/
ifmap_exporter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#ifndef __DB_IFMAP_EXPORTER_H__
#define __DB_IFMAP_EXPORTER_H__
#include <list>
#include <memory>
#include <map>
#include <string>
#include <boost/crc.hpp> // for boost::crc_32_type
#include <boost/scoped_ptr.hpp>
#include "db/db_table.h"
class BitSet;
class IFMapClient;
class IFMapGraphWalker;
class IFMapLink;
class IFMapLinkState;
class IFMapNode;
class IFMapNodeState;
class IFMapServer;
class IFMapState;
class IFMapTable;
class IFMapUpdate;
class IFMapUpdateQueue;
class IFMapUpdateSender;
// The IFMapExporter makes sure that the right entries are added to the update
// queue. It uses the GraphWalker to calculate the 'interest' set for each node
// and then ensures that all clients see the necessary information. It also
// enforces ordering. All link add/change operations must come after the nodes
// they refer to have been advertised to the client. Add node delete operations
// must come after the links that refer to the node have been deleted.
class IFMapExporter {
public:
typedef boost::crc_32_type::value_type crc32type;
explicit IFMapExporter(IFMapServer *server);
~IFMapExporter();
void Initialize(DB *db);
void Shutdown();
void StateUpdateOnDequeue(IFMapUpdate *update, const BitSet &dequeue_set,
bool is_delete);
// GraphWalker API
DBTable::ListenerId TableListenerId(const DBTable *table) const;
IFMapNodeState *NodeStateLocate(IFMapNode *node);
IFMapNodeState *NodeStateLookup(IFMapNode *node);
IFMapLinkState *LinkStateLookup(IFMapLink *link);
DBTable *link_table() { return link_table_; }
IFMapServer *server() { return server_; }
bool FilterNeighbor(IFMapNode *lnode, IFMapNode *rnode);
private:
friend class XmppIfmapTest;
class TableInfo;
typedef std::map<DBTable *, TableInfo *> TableMap;
// Database listener for IFMap identifier (and link attr) tables.
void NodeTableExport(DBTablePartBase *partition, DBEntryBase *entry);
// Database listener for the IFMapLink DB Table.
void LinkTableExport(DBTablePartBase *partition, DBEntryBase *entry);
template <class ObjectType>
bool UpdateAddChange(ObjectType *obj, IFMapState *state,
const BitSet &add_set, const BitSet &rm_set,
bool change);
template <class ObjectType>
bool UpdateRemove(ObjectType *obj, IFMapState *state,
const BitSet &rm_set);
template <class ObjectType>
void EnqueueDelete(ObjectType *obj, IFMapState *state);
void MoveDependentLinks(IFMapNodeState *state);
void RemoveDependentLinks(IFMapNodeState *state, const BitSet &rm_set);
void MoveAdjacentNode(IFMapNodeState *state);
void ProcessAdjacentNode(IFMapNode *node, const BitSet &add_set,
IFMapNodeState *state);
bool IsFeasible(const IFMapNode *node);
const BitSet *MergeClientInterest(IFMapNode *node, IFMapNodeState *state,
std::auto_ptr<BitSet> *ptr);
const TableInfo *Find(const DBTable *table) const;
void TableStateClear(DBTable *table, DBTable::ListenerId tsid);
bool ConfigChanged(IFMapNode *node);
IFMapUpdateQueue *queue();
IFMapUpdateSender *sender();
IFMapServer *server_;
boost::scoped_ptr<IFMapGraphWalker> walker_;
TableMap table_map_;
DBTable *link_table_;
};
#endif