-
Notifications
You must be signed in to change notification settings - Fork 390
/
ifmap_agent_table.h
126 lines (103 loc) · 3.96 KB
/
ifmap_agent_table.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#ifndef ctrlplane_ifmap_agent_table_h
#define ctrlplane_ifmap_agent_table_h
#include "db/db_graph_base.h"
#include "ifmap/ifmap_table.h"
#include "ifmap/ifmap_link_table.h"
#include "ifmap/ifmap_object.h"
#include "boost/asio/io_service.hpp"
#include "base/timer.h"
#include "base/task.h"
#include "sandesh/sandesh_trace.h"
#define IFMAP_AGENT_LINK_DB_NAME "__ifmap_agentlinkdata__.0"
extern SandeshTraceBufferPtr IFMapAgentTraceBuf;
#define IFMAP_AGENT_TRACE(obj, ...) do { \
if (LoggingDisabled()) break; \
IFMapAgent##obj::TraceMsg(IFMapAgentTraceBuf, __FILE__, __LINE__, ##__VA_ARGS__); \
} while (0);
class DBGraph;
class IFMapNode;
class IFMapAgentTable : public IFMapTable {
public:
struct IFMapAgentData : DBRequestData {
std::auto_ptr<IFMapObject>content;
};
typedef boost::function<bool(DBTable *table, IFMapNode *node, DBRequest *req)> PreFilterFn;
IFMapAgentTable(DB *db, const std::string &name, DBGraph *graph);
virtual void Input(DBTablePartition *partition, DBClient *client,
DBRequest *req);
virtual void Clear();
// Allocate an IFMapNode.
virtual std::auto_ptr<DBEntry> AllocEntry(const DBRequestKey *key) const;
static IFMapNode *TableEntryLookup(DB *db, RequestKey *key);
void NotifyNode(IFMapNode *node);
DBGraph *GetGraph() const {return graph_;};
void DeleteNode(IFMapNode *node);
void RegisterPreFilter(PreFilterFn fn) {pre_filter_ = fn;};
private:
IFMapNode *EntryLocate(IFMapNode *node, RequestKey *key);
IFMapNode *EntryLookup(RequestKey *key);
IFMapAgentTable* TableFind(const std::string &node_name);
void HandlePendingLinks(IFMapNode *);
DBGraph *graph_;
PreFilterFn pre_filter_;
};
class IFMapAgentLinkTable : public IFMapLinkTable {
public:
struct RequestKey : DBRequestKey {
IFMapTable::RequestKey left_key;
IFMapTable::RequestKey right_key;
std::string metadata;
};
struct DeferredNode {
IFMapTable::RequestKey node_key;
std::string link_metadata;
};
class comp {
public:
bool operator()(const IFMapTable::RequestKey &left,
const IFMapTable::RequestKey &right) const {
if (left.id_type != right.id_type)
return left.id_type < right.id_type;
return left.id_name < right.id_name;
}
};
IFMapAgentLinkTable(DB *db, const std::string &name, DBGraph *graph);
typedef std::map<IFMapTable::RequestKey, std::list<DeferredNode> *, comp> LinkDefMap;
virtual void Input(DBTablePartition *partition, DBClient *client,
DBRequest *req);
void IFMapAgentLinkTable_Init(DB *db, DBGraph *graph);
static DBTable *CreateTable(DB *db, const std::string &name,
DBGraph *graph);
void EvalDefLink(IFMapTable::RequestKey *key);
bool RemoveDefListEntry(LinkDefMap *map, LinkDefMap::iterator &map_it,
std::list<DeferredNode>::iterator *list_it);
void DestroyDefLink(uint64_t);
const LinkDefMap &GetLinkDefMap() const {
return link_def_map_;
}
void DelLink(IFMapNode *first, IFMapNode *second, DBGraphEdge *edge);
void LinkDefAdd(DBRequest *request);
private:
void AddLink(DBGraphBase::edge_descriptor edge,
IFMapNode *left, IFMapNode *right,
const std::string &metadata, uint64_t seq);
DBGraph *graph_;
LinkDefMap link_def_map_;
};
class IFMapAgentStaleCleaner {
public:
IFMapAgentStaleCleaner(DB *db, DBGraph *graph);
~IFMapAgentStaleCleaner();
class IFMapAgentStaleCleanerWorker;
void Clear();
bool StaleTimeout(uint64_t);
private:
DB *db_;
DBGraph *graph_;
uint64_t seq_;
};
extern void IFMapAgentLinkTable_Init(DB *db, DBGraph *graph);
#endif