-
Notifications
You must be signed in to change notification settings - Fork 390
/
ifmap_dependency_manager.cc
779 lines (687 loc) · 30.2 KB
/
ifmap_dependency_manager.cc
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
/*
* Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
*/
#include <cmn/agent_cmn.h>
#include <vnc_cfg_types.h>
#include <agent_types.h>
#include "oper/oper_db.h"
#include "oper/ifmap_dependency_manager.h"
#include "oper/vn.h"
#include "oper/sg.h"
#include "oper/interface_common.h"
#include "oper/health_check.h"
#include "oper/vrf.h"
#include "oper/vm.h"
#include "oper/physical_device.h"
#include "filter/acl.h"
#include "oper/qos_queue.h"
#include "oper/forwarding_class.h"
#include "oper/qos_config.h"
#include <boost/assign/list_of.hpp>
#include <boost/bind.hpp>
#include "base/task.h"
#include "base/task_trigger.h"
#include "db/db.h"
#include "db/db_table_partition.h"
#include "db/db_entry.h"
#include "ifmap/ifmap_agent_table.h"
#include "ifmap/ifmap_dependency_tracker.h"
#include "ifmap/ifmap_link.h"
#include "ifmap/ifmap_node.h"
#include "ifmap/ifmap_table.h"
using namespace boost::assign;
using namespace std;
typedef IFMapDependencyTracker::ReactionMap ReactionMap;
typedef IFMapDependencyTracker::NodeEventPolicy NodeEventPolicy;
typedef IFMapDependencyTracker::PropagateList PropagateList;
void intrusive_ptr_add_ref(IFMapNodeState *state) {
++state->refcount_;
}
void intrusive_ptr_release(IFMapNodeState *state) {
if (--state->refcount_ == 0) {
assert(state->object_ == NULL);
state->manager_->IFMapNodeReset(state->node_);
delete state;
}
}
IFMapDependencyManager::IFMapDependencyManager(DB *database, DBGraph *graph)
: database_(database),
graph_(graph) {
tracker_.reset(
new IFMapDependencyTracker(
database, graph,
boost::bind(&IFMapDependencyManager::ChangeListAdd, this, _1)));
int task_id = TaskScheduler::GetInstance()->GetTaskId("db::DBTable");
trigger_.reset(
new TaskTrigger(
boost::bind(&IFMapDependencyManager::ProcessChangeList, this),
task_id, 0));
}
IFMapDependencyManager::~IFMapDependencyManager() {
// TODO: Unregister from all tables.
}
void IFMapDependencyManager::Initialize(Agent *agent) {
static const char *ifmap_types[] = {
"access-control-list",
"alias-ip",
"alias-ip-pool",
"bgp-as-a-service",
"bgp-router",
"floating-ip",
"floating-ip-pool",
"forwarding-class",
"instance-ip",
"logical-interface",
"network-ipam",
"physical-interface",
"physical-router",
"qos-config",
"qos-queue",
"routing-instance",
"security-group",
"service-health-check",
"service-instance",
"service-template",
"subnet",
"virtual-ip",
"virtual-machine",
"virtual-machine-interface",
"virtual-machine-interface-routing-instance",
"virtual-network",
"virtual-network-network-ipam",
};
// Link table
DBTable *link_table = static_cast<DBTable *>(
database_->FindTable(IFMAP_AGENT_LINK_DB_NAME));
assert(link_table != NULL);
DBTable::ListenerId id = link_table->Register(
boost::bind(&IFMapDependencyManager::LinkObserver, this, _1, _2));
table_map_.insert(make_pair(link_table->name(), id));
// Identifier tables
const int n_types = sizeof(ifmap_types) / sizeof(const char *);
for (int i = 0; i < n_types; i++) {
const char *id_typename = ifmap_types[i];
IFMapTable *table = IFMapTable::FindTable(database_, id_typename);
assert(table);
DBTable::ListenerId id = table->Register(
boost::bind(&IFMapDependencyManager::NodeObserver, this, _1, _2));
table_map_.insert(make_pair(table->name(), id));
}
// Policy definition
IFMapDependencyTracker::NodeEventPolicy *policy = tracker_->policy_map();
ReactionMap react_si = map_list_of<string, PropagateList>
("service-instance-service-template", list_of("self"))
("virtual-machine-service-instance", list_of("self"))
("self", list_of("self"));
policy->insert(make_pair("service-instance", react_si));
ReactionMap react_tmpl = map_list_of<string, PropagateList>
("self", list_of("service-instance-service-template"));
policy->insert(make_pair("service-template", react_tmpl));
ReactionMap react_vm = map_list_of<string, PropagateList>
("self", list_of("virtual-machine-service-instance"))
("virtual-machine-virtual-machine-interface",
list_of("virtual-machine-service-instance"))
("virtual-machine-interface-virtual-machine",
list_of("virtual-machine-service-instance"));
policy->insert(make_pair("virtual-machine", react_vm));
ReactionMap react_vmi = map_list_of<string, PropagateList>
("self", list_of("virtual-machine-interface-virtual-machine")
("logical-interface-virtual-machine-interface"))
("instance-ip-virtual-machine-interface",
list_of("virtual-machine-interface-virtual-machine"))
("virtual-machine-interface-virtual-network",
list_of("virtual-machine-interface-virtual-machine")
("logical-interface-virtual-machine-interface"));
policy->insert(make_pair("virtual-machine-interface", react_vmi));
ReactionMap react_ip = map_list_of<string, PropagateList>
("self", list_of("instance-ip-virtual-machine-interface"));
policy->insert(make_pair("instance-ip", react_ip));
ReactionMap react_subnet = map_list_of<string, PropagateList>
("self", list_of("virtual-network-network-ipam"))
("virtual-network-network-ipam", list_of("nil"));
policy->insert(make_pair("virtual-network-network-ipam", react_subnet));
ReactionMap react_ipam = map_list_of<string, PropagateList>
("virtual-network-network-ipam", list_of("nil"));
policy->insert(make_pair("network-ipam", react_ipam));
InitializeDependencyRules(agent);
}
void IFMapDependencyManager::RegisterReactionMap
(const char *node_name, const IFMapDependencyTracker::ReactionMap &react) {
// Register to the IFMap table
IFMapTable *table = IFMapTable::FindTable(database_, node_name);
assert(table);
DBTable::ListenerId id = table->Register
(boost::bind(&IFMapDependencyManager::NodeObserver, this, _1, _2));
table_map_.insert(make_pair(table->name(), id));
// Add Policy
tracker_->policy_map()->insert(make_pair(node_name, react));
}
void IFMapDependencyManager::Terminate() {
for (TableMap::iterator iter = table_map_.begin();
iter != table_map_.end(); ++iter) {
DBTable *table = static_cast<DBTable *>(
database_->FindTable(iter->first));
table->Unregister(iter->second);
}
table_map_.clear();
event_map_.clear();
}
bool IFMapDependencyManager::ProcessChangeList() {
tracker_->PropagateChanges();
tracker_->Clear();
for (ChangeList::iterator iter = change_list_.begin();
iter != change_list_.end(); ++iter) {
IFMapNodeState *state = iter->get();
IFMapTable *table = state->node()->table();
EventMap::iterator loc = event_map_.find(table->Typename());
if (loc == event_map_.end()) {
continue;
}
if (state->notify() == true) {
loc->second(state->node(), state->object());
}
}
change_list_.clear();
return true;
}
void IFMapDependencyManager::NodeObserver(
DBTablePartBase *root, DBEntryBase *db_entry) {
IFMapNode *node = static_cast<IFMapNode *>(db_entry);
tracker_->NodeEvent(node);
trigger_->Set();
}
void IFMapDependencyManager::PropogateNodeChange(IFMapNode *node) {
tracker_->NodeEvent(node, false);
trigger_->Set();
}
void IFMapDependencyManager::PropogateNodeAndLinkChange(IFMapNode *node) {
tracker_->NodeEvent(node);
for (DBGraphVertex::edge_iterator iter = node->edge_list_begin(graph_);
iter != node->edge_list_end(graph_); ++iter) {
IFMapLink *link = static_cast<IFMapLink *>(iter.operator->());
IFMapNode *target = static_cast<IFMapNode *>(iter.target());
tracker_->LinkEvent(link->metadata(), node, target);
}
trigger_->Set();
}
void IFMapDependencyManager::LinkObserver(
DBTablePartBase *root, DBEntryBase *db_entry) {
IFMapLink *link = static_cast<IFMapLink *>(db_entry);
IFMapNode *left = link->LeftNode(database_);
IFMapNode *right = link->RightNode(database_);
bool set = false;
if (left) {
EventMap::iterator loc = event_map_.find(left->table()->Typename());
if (loc != event_map_.end()) {
ChangeListAdd(left);
set = true;
}
}
if (right) {
EventMap::iterator loc = event_map_.find(right->table()->Typename());
if (loc != event_map_.end()) {
ChangeListAdd(right);
set = true;
}
}
set |= tracker_->LinkEvent(link->metadata(), left, right);
if (set) {
trigger_->Set();
}
}
void IFMapDependencyManager::ChangeListAdd(IFMapNode *node) {
IFMapNodeState *state = IFMapNodeGet(node);
if (state == NULL) {
if (node->IsDeleted() == false)
change_list_.push_back(SetState(node));
} else {
change_list_.push_back(IFMapNodePtr(state));
}
}
IFMapNodeState *
IFMapDependencyManager::IFMapNodeGet(IFMapNode *node) {
IFMapTable *table = node->table();
TableMap::const_iterator loc = table_map_.find(table->name());
if (loc == table_map_.end()) {
return NULL;
}
IFMapNodeState *state =
static_cast<IFMapNodeState *>(node->GetState(table, loc->second));
return state;
}
void IFMapDependencyManager::IFMapNodeReset(IFMapNode *node) {
IFMapTable *table = node->table();
TableMap::const_iterator loc = table_map_.find(table->name());
assert(loc != table_map_.end());
node->ClearState(node->table(), loc->second);
}
/*
* Associate an IFMapNode with an object in the operational database.
*
* IFMapNodes that do not have an object mapping do not receive notifications.
* This method checks whether the DBState exists and delegates the
* responsibility to create a new mapping to IFMapNodeSet (private).
*/
void IFMapDependencyManager::SetObject(IFMapNode *node, DBEntry *entry) {
IFMapNodeState *state = IFMapNodeGet(node);
assert(state);
DBEntry *old_entry = state->object();
if (old_entry)
state->clear_object();
if (entry) {
state->set_object(entry);
tracker_->NodeEvent(node);
trigger_->Set();
}
}
void IFMapDependencyManager::SetNotify(IFMapNode *node, bool notify_flag) {
IFMapNodeState *state = IFMapNodeGet(node);
assert(state);
state->set_notify(notify_flag);
}
void IFMapDependencyManager::SetRequestEnqueued(IFMapNode *node,
bool oper_db_request_enqueued) {
IFMapNodeState *state = IFMapNodeGet(node);
assert(state);
state->set_oper_db_request_enqueued(oper_db_request_enqueued);
}
IFMapDependencyManager::IFMapNodePtr
IFMapDependencyManager::SetState(IFMapNode *node) {
IFMapTable *table = node->table();
TableMap::const_iterator loc = table_map_.find(table->name());
if (loc == table_map_.end())
return NULL;
IFMapNodeState *state =
static_cast<IFMapNodeState *>(node->GetState(table, loc->second));
if (!state) {
state = new IFMapNodeState(this, node);
node->SetState(table, loc->second, state);
}
return IFMapNodePtr(state);
}
DBEntry *IFMapDependencyManager::GetObject(IFMapNode *node) {
IFMapTable *table = node->table();
TableMap::const_iterator loc = table_map_.find(table->name());
if (loc == table_map_.end())
return NULL;
IFMapNodeState *state =
static_cast<IFMapNodeState *>(node->GetState(table, loc->second));
if (state == NULL)
return NULL;
return state->object();
}
/*
* Register a notification callback.
*/
void IFMapDependencyManager::Register(
const string &type, ChangeEventHandler handler) {
event_map_.insert(std::make_pair(type, handler));
}
/*
* Unregister a notification callback.
*/
void IFMapDependencyManager::Unregister(const string &type) {
event_map_.erase(type);
}
// Check if a IFMapNode type is registerd with dependency manager
bool IFMapDependencyManager::IsRegistered(const IFMapNode *node) {
EventMap::iterator it = event_map_.find(node->table()->Typename());
return (it != event_map_.end());
}
bool IFMapDependencyManager::IsNodeIdentifiedByUuid(const IFMapNode *node) {
return (strcmp(node->table()->Typename(), "routing-instance") != 0);
}
IFMapDependencyManager::Path MakePath
(const char *link1, const char *node1, bool interest1,
const char *link2 = NULL, const char *node2 = NULL, bool interest2 = false,
const char *link3 = NULL, const char *node3 = NULL, bool interest3 = false,
const char *link4 = NULL, const char *node4 = NULL, bool interest4 = false,
const char *link5 = NULL, const char *node5 = NULL, bool interest5 = false,
const char *link6 = NULL, const char *node6 = NULL, bool interest6 = false) {
if (link2) assert(node2);
if (link3) assert(node3);
if (link4) assert(node4);
if (link5) assert(node5);
if (link6) assert(node6);
IFMapDependencyManager::Path path;
path.push_back(IFMapDependencyManager::Link(link1, node1, interest1));
if (link2)
path.push_back(IFMapDependencyManager::Link(link2, node2, interest2));
if (link3)
path.push_back(IFMapDependencyManager::Link(link3, node3, interest3));
if (link4)
path.push_back(IFMapDependencyManager::Link(link4, node4, interest4));
if (link5)
path.push_back(IFMapDependencyManager::Link(link5, node5, interest5));
if (link6)
path.push_back(IFMapDependencyManager::Link(link6, node6, interest6));
return path;
}
static NodeEventPolicy::iterator LocateNodeEventPolicy(NodeEventPolicy *policy,
const string &node) {
NodeEventPolicy::iterator it = policy->find(node);
if (it != policy->end()) {
return it;
}
ReactionMap react = map_list_of<string, PropagateList>
("self", PropagateList());
policy->insert(make_pair(node, react));
return policy->find(node);
}
static ReactionMap::iterator LocateReactionMap(ReactionMap *react,
const string &event) {
ReactionMap::iterator it = react->find(event);
if (it != react->end()) {
return it;
}
react->insert(make_pair(event, PropagateList()));
return react->find(event);
}
////////////////////////////////////////////////////////////////////////
// The IFMap dependency tracker accepts rules in the form or "Reactor Map"
// Reactor map is not natural way of defining references between IFMap nodes
// in agent.
//
// When agent builds data for an oper-db entry, the IFNodeToReq API will keep
// the IFMapNode for oper-db entry as starting node and traverses the graph
// to build all realvent data for the entry. So, it is more natural in agent
// to specify relation between nodes in a way IFMapNodeToReq traverses the
// graph
//
// The routine AddDependencyPath takes the graph path between two vertices
// and then creates "Reactor Map" for them.
//
// The API takes IFMapNode for object being built as "node" and then a graph
// path to reach another IFMapNode of interest.
//
// Example: VMI refers to RI with following path to support floating-ip
// VMI <----> FIP <----> FIP-POOL <----> VN <----> RI
//
// node is specified as "virtual-machine-interface"
// path is specified as,
// <string(link-metadata), string(vertex), bool(vertex-attr-interest)>
//
// vertex specifies name of the adjacent node in the path
// link-metadata specifies metadata of the link connecting the vertex
// vertex-attr-interest
// If "node" is interested in any attribute of vertex, this value
// is set to TRUE else its set to FALSE
// When value is set to TRUE, it will generate an event of type
// "self" in the reactor-map
//
// The path from virtual-machine-interface to "routing-instance" above
// is given as below,
//
// <"virtual-machine-interface-floating-ip", "floating-ip", true>
// <"floating-ip-floating-ip-pool", "floating-ip-pool", false>
// <"floating-ip-pool-virtual-network", "virtual-network", true>
// <"virtual-network-routing-instance", "routing-instance", true>
//
// AddDependencyPath will "APPEND" following Reactor rules,
// node(virtual-machine-interface)
// event(virtual-machine-floating-ip) => Rectors(self)
//
// node(routing-instance)
// event(self) => Reactors(virtual-network-routing-instance)
//
// node(virtual-network)
// event(virtual-network-routing-instance) => Reactors(floating-ip-pool-virtual-network)
//
// node(floating-ip-pool)
// event(self) => Reactors(virtual-machine-interface-virtual-network)
// event(floating-ip-pool-virtual-network) => Reactors(floating-ip-floating-ip-pool)
//
// node(floating-ip)
// event(self) => Reactors(virtual-machine-interface-floating-ip)
// event(floating-ip-floating-ip-pool) => Reactors(virtual-machine-interface-floating-ip)
//
////////////////////////////////////////////////////////////////////////
void IFMapDependencyManager::AddDependencyPath(const std::string &node,
Path path) {
NodeEventPolicy *policy = tracker_->policy_map();
assert(policy);
NodeEventPolicy::iterator node_it;
node_it = LocateNodeEventPolicy(policy, node);
ReactionMap::iterator react_it = LocateReactionMap(&node_it->second,
path[0].edge_);
LOG(DEBUG, "Updating dependency tacker rules for " << node);
react_it->second.insert("self");
LOG(DEBUG, "Adding ReactorMap " << node_it->first << " : " <<
react_it->first << " -> " << "self");
for (size_t i = 0; i < path.size(); i++) {
node_it = LocateNodeEventPolicy(policy, path[i].vertex_);
if (path[i].vertex_interest_) {
react_it = LocateReactionMap(&node_it->second, "self");
react_it->second.insert(path[i].edge_);
LOG(DEBUG, "Adding ReactorMap " << node_it->first << " : " <<
react_it->first << " -> " << path[i].edge_);
}
if (i < (path.size() - 1)) {
react_it = LocateReactionMap(&node_it->second, path[i+1].edge_);
react_it->second.insert(path[i].edge_);
LOG(DEBUG, "Adding ReactorMap " << node_it->first << " : " <<
react_it->first << " -> " << path[i].edge_);
} else {
react_it = LocateReactionMap(&node_it->second, path[i].edge_);
react_it->second.insert("nil");
LOG(DEBUG, "Adding ReactorMap " << node_it->first << " : " <<
react_it->first << " -> " << "nil");
}
}
return;
}
static void RegisterConfigHandler(IFMapDependencyManager *dep,
const char *name, AgentOperDBTable *table) {
if (table)
dep->Register(name, boost::bind(&AgentOperDBTable::ConfigEventHandler,
table, _1, _2));
}
void IFMapDependencyManager::InitializeDependencyRules(Agent *agent) {
RegisterConfigHandler(this, "virtual-machine",
agent ? agent->vm_table() : NULL);
RegisterConfigHandler(this, "access-control-list",
agent ? agent->acl_table() : NULL);
////////////////////////////////////////////////////////////////////////
// VN <----> RI
// <----> ACL
// <----> VN-IPAM <----> IPAM
////////////////////////////////////////////////////////////////////////
AddDependencyPath("virtual-network",
MakePath("virtual-network-routing-instance",
"routing-instance", true));
AddDependencyPath("virtual-network",
MakePath("virtual-network-access-control-list",
"access-control-list", true));
AddDependencyPath("virtual-network",
MakePath("virtual-network-network-ipam",
"virtual-network-network-ipam", true,
"virtual-network-network-ipam",
"network-ipam", false));
AddDependencyPath("virtual-network",
MakePath("virtual-network-qos-config",
"qos-config", true));
RegisterConfigHandler(this, "virtual-network",
agent ? agent->vn_table() : NULL);
////////////////////////////////////////////////////////////////////////
// RI <----> VN
////////////////////////////////////////////////////////////////////////
AddDependencyPath("routing-instance",
MakePath("virtual-network-routing-instance",
"virtual-network", true));
RegisterConfigHandler(this, "routing-instance",
agent ? agent->vrf_table() : NULL);
////////////////////////////////////////////////////////////////////////
// SG <----> ACL
////////////////////////////////////////////////////////////////////////
AddDependencyPath("security-group",
MakePath("security-group-access-control-list",
"access-control-list", true));
RegisterConfigHandler(this, "security-group",
agent ? agent->sg_table() : NULL);
////////////////////////////////////////////////////////////////////////
// VMI <----> VN
// <----> VM
// <----> VMI-RI <----> RI
// <----> SG
// //<----> FIP <----> FIP-POOL <----> VN <----> RI
// <----> FIP <----> FIP-POOL <----> VN
// <----> Instance-IP
// <----> interface-route-table
// <----> subnet
// //<----> vn <----> VN-IPAM <----> IPAM
// <----> LI <----> physical-interface <----> physical-router
////////////////////////////////////////////////////////////////////////
AddDependencyPath("virtual-machine-interface",
MakePath("virtual-machine-interface-virtual-network",
"virtual-network", true));
AddDependencyPath("virtual-machine-interface",
MakePath("virtual-machine-interface-virtual-machine",
"virtual-machine", true));
AddDependencyPath("virtual-machine-interface",
MakePath("virtual-machine-interface-sub-interface",
"virtual-machine-interface", true));
AddDependencyPath("virtual-machine-interface",
MakePath("virtual-machine-interface-routing-instance",
"virtual-machine-interface-routing-instance",
true,
"virtual-machine-interface-routing-instance",
"routing-instance", true));
AddDependencyPath("virtual-machine-interface",
MakePath("virtual-machine-interface-security-group",
"security-group", true));
AddDependencyPath("virtual-machine-interface",
MakePath("alias-ip-virtual-machine-interface",
"alias-ip", true,
"alias-ip-pool-alias-ip",
"alias-ip-pool", false,
"virtual-network-alias-ip-pool",
"virtual-network", true));
AddDependencyPath("virtual-machine-interface",
MakePath("floating-ip-virtual-machine-interface",
"floating-ip", true,
"floating-ip-pool-floating-ip",
"floating-ip-pool", false,
"virtual-network-floating-ip-pool",
"virtual-network", true));
AddDependencyPath("virtual-machine-interface",
MakePath("instance-ip-virtual-machine-interface",
"instance-ip", true));
AddDependencyPath("virtual-machine-interface",
MakePath("virtual-machine-interface-route-table",
"interface-route-table", true));
AddDependencyPath("virtual-machine-interface",
MakePath("subnet-virtual-machine-interface",
"subnet", true));
AddDependencyPath("virtual-machine-interface",
MakePath("logical-interface-virtual-machine-interface",
"logical-interface", false,
"physical-interface-logical-interface",
"physical-interface", false,
"physical-router-physical-interface",
"physical-router", true));
AddDependencyPath("virtual-machine-interface",
MakePath("bgpaas-virtual-machine-interface",
"bgp-as-a-service", true,
"bgpaas-bgp-router",
"bgp-router", true,
"instance-bgp-router",
"routing-instance", true));
AddDependencyPath("virtual-machine-interface",
MakePath("virtual-machine-interface-qos-config",
"qos-config", true));
RegisterConfigHandler(this, "virtual-machine-interface",
agent ? agent->interface_table() : NULL);
////////////////////////////////////////////////////////////////////////
// physical-interface <----> physical-router
////////////////////////////////////////////////////////////////////////
AddDependencyPath("physical-interface",
MakePath("physical-router-physical-interface",
"physical-router", true));
RegisterConfigHandler(this, "physical-interface",
agent ? agent->interface_table() : NULL);
////////////////////////////////////////////////////////////////////////
// logical-interface <----> physical-interface <----> physical-router
// <----> virtual-machine-interface <---> virtual-network
//
////////////////////////////////////////////////////////////////////////
AddDependencyPath("logical-interface",
MakePath("physical-interface-logical-interface",
"physical-interface", true,
"physical-interface-physical-router",
"physical-router", true));
AddDependencyPath("logical-interface",
MakePath("logical-interface-virtual-machine-interface",
"virtual-machine-interface", true));
AddDependencyPath("logical-interface",
MakePath("physical-router-logical-interface",
"physical-router", true));
RegisterConfigHandler(this, "logical-interface",
agent ? agent->interface_table() : NULL);
////////////////////////////////////////////////////////////////////////
// physical-router <----> physical-interface
////////////////////////////////////////////////////////////////////////
AddDependencyPath("physical-router",
MakePath("physical-router-physical-interface",
"physical-interface", true));
RegisterConfigHandler(this, "physical-router",
agent ? agent->physical_device_table() : NULL);
////////////////////////////////////////////////////////////////////////
// virtual-machine-interface <----> service-health-check
////////////////////////////////////////////////////////////////////////
AddDependencyPath("service-health-check",
MakePath("service-port-health-check",
"virtual-machine-interface", true));
RegisterConfigHandler(this, "service-health-check",
agent ? agent->health_check_table() : NULL);
AddDependencyPath("qos-config",
MakePath("global-qos-config-qos-config",
"qos-config", true));
RegisterConfigHandler(this, "qos-config",
agent ? agent->qos_config_table() : NULL);
RegisterConfigHandler(this, "qos-queue",
agent ? agent->qos_queue_table() : NULL);
AddDependencyPath("forwarding-class",
MakePath("forwarding-class-qos-queue",
"qos-queue", true));
RegisterConfigHandler(this, "forwarding-class",
agent ? agent->forwarding_class_table() : NULL);
}
void IFMapNodePolicyReq::HandleRequest() const {
Agent *agent = Agent::GetInstance();
IFMapNodePolicyResp *resp = new IFMapNodePolicyResp();
IFMapDependencyTracker::NodeEventPolicy *policy_list =
agent->oper_db()->dependency_manager()->tracker()->policy_map();
NodeEventPolicy::iterator it1 = policy_list->begin();
std::vector<IFMapNodePolicy> resp_policy_list;
while (it1 != policy_list->end()) {
if (it1->first.find(get_node()) == string::npos) {
it1++;
continue;
}
ReactionMap::iterator it2 = it1->second.begin();
vector<IFMapReactEvent> resp_event_list;
while(it2 != it1->second.end()) {
IFMapReactEvent resp_event;
vector<string> resp_reactor_list;
PropagateList::iterator it3 = it2->second.begin();
while (it3 != it2->second.end()) {
resp_reactor_list.push_back((*it3));
it3++;
}
resp_event.set_event(it2->first);
resp_event.set_reactors(resp_reactor_list);
resp_event_list.push_back(resp_event);
it2++;
}
IFMapNodePolicy policy;
policy.set_node(it1->first);
policy.set_events(resp_event_list);
resp_policy_list.push_back(policy);
it1++;
}
resp->set_policies(resp_policy_list);
resp->set_context(context());
resp->set_more(false);
resp->Response();
return;
}