LCOV - code coverage report
Current view: top level - vnsw/agent/oper - ifmap_dependency_manager.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 418 490 85.3 %
Date: 2026-11-09 02:10:49 Functions: 27 33 81.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #include <cmn/agent_cmn.h>
       7             : #include <vnc_cfg_types.h>
       8             : #include <agent_types.h>
       9             : 
      10             : #include "oper/oper_db.h"
      11             : #include "oper/ifmap_dependency_manager.h"
      12             : #include "oper/vn.h"
      13             : #include "oper/sg.h"
      14             : #include "oper/tag.h"
      15             : #include "oper/interface_common.h"
      16             : #include "oper/health_check.h"
      17             : #include "oper/vrf.h"
      18             : #include "oper/vm.h"
      19             : #include "oper/physical_device.h"
      20             : #include "filter/acl.h"
      21             : #include "oper/qos_queue.h"
      22             : #include "oper/forwarding_class.h"
      23             : #include "oper/qos_config.h"
      24             : #include "oper/config_manager.h"
      25             : #include "oper/vrouter.h"
      26             : #include "oper/bgp_router.h"
      27             : #include "oper/global_qos_config.h"
      28             : #include "oper/global_system_config.h"
      29             : #include "oper/global_vrouter.h"
      30             : #include "oper/bridge_domain.h"
      31             : #include "filter/policy_set.h"
      32             : #include "cfg/cfg_init.h"
      33             : #include "oper/security_logging_object.h"
      34             : #include "oper/multicast_policy.h"
      35             : 
      36             : #include <boost/assign/list_of.hpp>
      37             : #include <boost/bind/bind.hpp>
      38             : 
      39             : #include "base/task.h"
      40             : #include "base/task_trigger.h"
      41             : #include "db/db.h"
      42             : #include "db/db_table_partition.h"
      43             : #include "db/db_entry.h"
      44             : #include "ifmap/ifmap_agent_table.h"
      45             : #include "ifmap/ifmap_dependency_tracker.h"
      46             : #include "ifmap/ifmap_link.h"
      47             : #include "ifmap/ifmap_node.h"
      48             : #include "ifmap/ifmap_table.h"
      49             : 
      50             : using namespace boost::assign;
      51             : using namespace std;
      52             : using namespace boost::placeholders;
      53             : 
      54             : typedef IFMapDependencyTracker::ReactionMap ReactionMap;
      55             : typedef IFMapDependencyTracker::NodeEventPolicy NodeEventPolicy;
      56             : typedef IFMapDependencyTracker::PropagateList PropagateList;
      57             : 
      58       25710 : void intrusive_ptr_add_ref(IFMapNodeState *state) {
      59       25710 :     ++state->refcount_;
      60       25710 : }
      61             : 
      62       25710 : void intrusive_ptr_release(IFMapNodeState *state) {
      63       25710 :     if (--state->refcount_ ==  0) {
      64        1021 :         assert(state->object_ == NULL);
      65        1021 :         state->manager_->IFMapNodeReset(state->node_);
      66        1021 :         delete state;
      67             :     }
      68       25710 : }
      69             : 
      70           2 : IFMapDependencyManager::IFMapDependencyManager(DB *database, DBGraph *graph)
      71           2 :         : database_(database),
      72           2 :           graph_(graph) {
      73           4 :     tracker_.reset(
      74             :         new IFMapDependencyTracker(
      75             :             database, graph,
      76           2 :             boost::bind(&IFMapDependencyManager::ChangeListAdd, this, _1)));
      77           2 :     int task_id = TaskScheduler::GetInstance()->GetTaskId("db::DBTable");
      78           4 :     trigger_.reset(
      79             :         new TaskTrigger(
      80             :             boost::bind(&IFMapDependencyManager::ProcessChangeList, this),
      81           2 :             task_id, 0));
      82           2 : }
      83             : 
      84           4 : IFMapDependencyManager::~IFMapDependencyManager() {
      85             :     // TODO: Unregister from all tables.
      86           4 : }
      87             : 
      88           2 : void IFMapDependencyManager::Initialize(Agent *agent) {
      89           2 :     agent_ = agent;
      90             :     static const char *ifmap_types[] = {
      91             :         "access-control-list",
      92             :         "address-group",
      93             :         "alias-ip",
      94             :         "alias-ip-pool",
      95             :         "application-policy-set",
      96             :         "application-policy-set-firewall-policy",
      97             :         "bgp-as-a-service",
      98             :         "bgpaas-control-node-zone",
      99             :         "bgp-router",
     100             :         "control-node-zone",
     101             :         "firewall-policy",
     102             :         "firewall-rule",
     103             :         "floating-ip",
     104             :         "floating-ip-pool",
     105             :         "forwarding-class",
     106             :         "global-qos-config",
     107             :         "global-system-config",
     108             :         "instance-ip",
     109             :         "logical-interface",
     110             :         "logical-router",
     111             :         "network-ipam",
     112             :         "physical-interface",
     113             :         "physical-router",
     114             :         "policy-management",
     115             :         "project",
     116             :         "qos-config",
     117             :         "qos-queue",
     118             :         "routing-instance",
     119             :         "security-group",
     120             :         "security-logging-object",
     121             :         "service-group",
     122             :         "service-health-check",
     123             :         "service-instance",
     124             :         "service-template",
     125             :         "subnet",
     126             :         "sub-cluster",
     127             :         "tag",
     128             :         "virtual-ip",
     129             :         "virtual-machine",
     130             :         "virtual-machine-interface",
     131             :         "virtual-machine-interface-routing-instance",
     132             :         "virtual-network",
     133             :         "virtual-network-network-ipam",
     134             :         "virtual-port-group",
     135             :         "virtual-port-group-physical-interface",
     136             :         "virtual-DNS",
     137             :         "global-vrouter-config",
     138             :         "virtual-router",
     139             :         "interface-route-table",
     140             :         "bridge-domain",
     141             :         "virtual-machine-interface-bridge-domain",
     142             :         "firewall-policy-firewall-rule",
     143             :         "port-tuple",
     144             :         "multicast-policy"
     145             :     };
     146             : 
     147             :     // Link table
     148             :     DBTable *link_table = static_cast<DBTable *>(
     149           2 :         database_->FindTable(IFMAP_AGENT_LINK_DB_NAME));
     150           2 :     assert(link_table != NULL);
     151             : 
     152           4 :     DBTable::ListenerId id = link_table->Register(
     153           2 :         boost::bind(&IFMapDependencyManager::LinkObserver, this, _1, _2));
     154           2 :     table_map_.insert(make_pair(link_table->name(), id));
     155             : 
     156             :     // Identifier tables
     157           2 :     const int n_types = sizeof(ifmap_types) / sizeof(const char *);
     158         110 :     for (int i = 0; i < n_types; i++) {
     159         108 :         const char *id_typename = ifmap_types[i];
     160         108 :         IFMapTable *table = IFMapTable::FindTable(database_, id_typename);
     161         108 :         assert(table);
     162         216 :         DBTable::ListenerId id = table->Register(
     163         108 :             boost::bind(&IFMapDependencyManager::NodeObserver, this, _1, _2));
     164         108 :         table_map_.insert(make_pair(table->name(), id));
     165             :     }
     166             : 
     167             :     // Policy definition
     168           2 :     IFMapDependencyTracker::NodeEventPolicy *policy = tracker_->policy_map();
     169             : 
     170             :     ReactionMap react_si = map_list_of<string, PropagateList>
     171           6 :             ("service-instance-service-template", list_of("self")
     172           4 :                 .convert_to_container<PropagateList>())
     173           6 :             ("virtual-machine-service-instance", list_of("self")
     174           4 :                 .convert_to_container<PropagateList>())
     175           4 :             ("self", list_of("self").convert_to_container<PropagateList>());
     176           2 :     policy->insert(make_pair("service-instance", react_si));
     177             : 
     178             :     ReactionMap react_tmpl = map_list_of<string, PropagateList>
     179           4 :             ("self", list_of("service-instance-service-template"));
     180           2 :     policy->insert(make_pair("service-template", react_tmpl));
     181             : 
     182             :     ReactionMap react_vm = map_list_of<string, PropagateList>
     183           6 :             ("self", list_of("virtual-machine-service-instance")
     184           4 :                 .convert_to_container<PropagateList>())
     185           2 :             ("virtual-machine-virtual-machine-interface",
     186           4 :              list_of("virtual-machine-service-instance")
     187           4 :                  .convert_to_container<PropagateList>())
     188           2 :             ("virtual-machine-interface-virtual-machine",
     189           4 :              list_of("virtual-machine-service-instance")
     190           6 :                  .convert_to_container<PropagateList>());
     191           2 :     policy->insert(make_pair("virtual-machine", react_vm));
     192             : 
     193             :     ReactionMap react_vmi = map_list_of<string, PropagateList>
     194           6 :             ("self", list_of("virtual-machine-interface-virtual-machine")
     195           2 :                             ("logical-interface-virtual-machine-interface")
     196           4 :                                 .convert_to_container<PropagateList>())
     197           2 :             ("instance-ip-virtual-machine-interface",
     198           4 :              list_of("virtual-machine-interface-virtual-machine")
     199           4 :                  .convert_to_container<PropagateList>())
     200           2 :             ("virtual-machine-interface-virtual-network",
     201           4 :              list_of("virtual-machine-interface-virtual-machine")
     202           2 :                     ("logical-interface-virtual-machine-interface")
     203           6 :                         .convert_to_container<PropagateList>());
     204           2 :     policy->insert(make_pair("virtual-machine-interface", react_vmi));
     205             : 
     206             :     ReactionMap react_ip = map_list_of<string, PropagateList>
     207           4 :             ("self", list_of("instance-ip-virtual-machine-interface"));
     208           2 :     policy->insert(make_pair("instance-ip", react_ip));
     209             : 
     210             :     ReactionMap react_subnet = map_list_of<string, PropagateList>
     211           6 :             ("self", list_of("virtual-network-network-ipam")
     212           4 :                 .convert_to_container<PropagateList>())
     213           6 :             ("virtual-network-network-ipam", list_of("nil")
     214           6 :                 .convert_to_container<PropagateList>());
     215           2 :     policy->insert(make_pair("virtual-network-network-ipam", react_subnet));
     216             : 
     217             :     ReactionMap react_ipam = map_list_of<string, PropagateList>
     218           4 :             ("virtual-network-network-ipam", list_of("nil"));
     219           2 :     policy->insert(make_pair("network-ipam", react_ipam));
     220             : 
     221             :     ReactionMap react_bgpaas = map_list_of<string, PropagateList>
     222           4 :             ("bgpaas-control-node-zone",
     223           4 :             list_of("bgpaas-virtual-machine-interface"));
     224           2 :     policy->insert(make_pair("bgp-as-a-service", react_bgpaas));
     225             : 
     226           2 :     InitializeDependencyRules(agent);
     227           2 : }
     228             : 
     229           0 : void IFMapDependencyManager::RegisterReactionMap
     230             : (const char *node_name, const IFMapDependencyTracker::ReactionMap &react) {
     231             :     // Register to the IFMap table
     232           0 :     IFMapTable *table = IFMapTable::FindTable(database_, node_name);
     233           0 :     assert(table);
     234             :     DBTable::ListenerId id = table->Register
     235           0 :         (boost::bind(&IFMapDependencyManager::NodeObserver, this, _1, _2));
     236           0 :     table_map_.insert(make_pair(table->name(), id));
     237             : 
     238             :     // Add Policy
     239           0 :     tracker_->policy_map()->insert(make_pair(node_name, react));
     240           0 : }
     241             : 
     242           2 : void IFMapDependencyManager::Terminate() {
     243           2 :     for (TableMap::iterator iter = table_map_.begin();
     244         112 :          iter != table_map_.end(); ++iter) {
     245             :         DBTable *table = static_cast<DBTable *>(
     246         110 :             database_->FindTable(iter->first));
     247         110 :         table->Unregister(iter->second);
     248             :     }
     249           2 :     table_map_.clear();
     250           2 :     event_map_.clear();
     251           2 : }
     252             : 
     253        1314 : bool IFMapDependencyManager::ProcessChangeList() {
     254        1314 :     tracker_->PropagateChanges();
     255        1314 :     tracker_->Clear();
     256             : 
     257        1314 :     for (ChangeList::iterator iter = change_list_.begin();
     258        8144 :          iter != change_list_.end(); ++iter) {
     259        6830 :         IFMapNodeState *state = iter->get();
     260        6830 :         IFMapTable *table = state->node()->table();
     261        6830 :         EventMap::iterator loc = event_map_.find(table->Typename());
     262        6830 :         if (loc == event_map_.end()) {
     263         470 :             continue;
     264             :         }
     265             : 
     266        6360 :         if (state->notify() == true) {
     267        6360 :             loc->second(state->node(), state->object());
     268             :         }
     269             :     }
     270        1314 :     change_list_.clear();
     271        1314 :     return true;
     272             : }
     273             : 
     274        2150 : void IFMapDependencyManager::NodeObserver(
     275             :     DBTablePartBase *root, DBEntryBase *db_entry) {
     276             : 
     277        2150 :     IFMapNode *node = static_cast<IFMapNode *>(db_entry);
     278        2150 :     tracker_->NodeEvent(node);
     279        2150 :     trigger_->Set();
     280        2150 : }
     281             : 
     282         131 : void IFMapDependencyManager::PropogateNodeChange(IFMapNode *node) {
     283         131 :     tracker_->NodeEvent(node, false);
     284         131 :     trigger_->Set();
     285         131 : }
     286             : 
     287           0 : void IFMapDependencyManager::PropogateNodeAndLinkChange(IFMapNode *node) {
     288             : 
     289           0 :     tracker_->NodeEvent(node);
     290             : 
     291           0 :     for (DBGraphVertex::edge_iterator iter = node->edge_list_begin(graph_);
     292           0 :                                 iter != node->edge_list_end(graph_); ++iter) {
     293           0 :         IFMapLink *link = static_cast<IFMapLink *>(iter.operator->());
     294           0 :         IFMapNode *target = static_cast<IFMapNode *>(iter.target());
     295           0 :         tracker_->LinkEvent(link->metadata(), node, target);
     296             :     }
     297             : 
     298           0 :     trigger_->Set();
     299           0 : }
     300             : 
     301        2468 : void IFMapDependencyManager::LinkObserver(
     302             :     DBTablePartBase *root, DBEntryBase *db_entry) {
     303        2468 :     IFMapLink *link = static_cast<IFMapLink *>(db_entry);
     304        2468 :     IFMapNode *left = link->LeftNode(database_);
     305        2468 :     IFMapNode *right = link->RightNode(database_);
     306        2468 :     bool set = false;
     307        2468 :     if (left) {
     308        2468 :         EventMap::iterator loc = event_map_.find(left->table()->Typename());
     309        2468 :         if (loc != event_map_.end()) {
     310        1496 :             ChangeListAdd(left);
     311        1496 :             set = true;
     312             :         }
     313             :     }
     314             : 
     315        2468 :     if (right) {
     316        2468 :         EventMap::iterator loc = event_map_.find(right->table()->Typename());
     317        2468 :         if (loc != event_map_.end()) {
     318        1724 :             ChangeListAdd(right);
     319        1724 :             set = true;
     320             :         }
     321             :     }
     322             : 
     323        2468 :     set |= tracker_->LinkEvent(link->metadata(), left, right);
     324        2468 :     if (set) {
     325        2428 :         trigger_->Set();
     326             :     }
     327        2468 : }
     328             : 
     329        7957 : void IFMapDependencyManager::ChangeListAdd(IFMapNode *node) {
     330        7957 :     IFMapNodeState *state = IFMapNodeGet(node);
     331        7957 :     if (state == NULL) {
     332        2148 :         if (node->IsDeleted() == false)
     333        1021 :             change_list_.push_back(SetState(node));
     334             :     } else {
     335        5809 :         change_list_.push_back(IFMapNodePtr(state));
     336             :     }
     337        7957 : }
     338             : 
     339             : IFMapNodeState *
     340       25185 : IFMapDependencyManager::IFMapNodeGet(IFMapNode *node) {
     341       25185 :     IFMapTable *table = node->table();
     342       25185 :     TableMap::const_iterator loc = table_map_.find(table->name());
     343       25185 :     if (loc == table_map_.end()) {
     344           0 :         return NULL;
     345             :     }
     346             :     IFMapNodeState *state =
     347       25185 :             static_cast<IFMapNodeState *>(node->GetState(table, loc->second));
     348       25185 :     return state;
     349             : }
     350             : 
     351        1021 : void IFMapDependencyManager::IFMapNodeReset(IFMapNode *node) {
     352        1021 :     IFMapTable *table = node->table();
     353        1021 :     TableMap::const_iterator loc = table_map_.find(table->name());
     354        1021 :     assert(loc != table_map_.end());
     355        1021 :     node->ClearState(node->table(), loc->second);
     356        1021 : }
     357             : 
     358             : /*
     359             :  * Associate an IFMapNode with an object in the operational database.
     360             :  *
     361             :  * IFMapNodes that do not have an object mapping do not receive notifications.
     362             :  * This method checks whether the DBState exists and delegates the
     363             :  * responsibility to create a new mapping to IFMapNodeSet (private).
     364             :  */
     365         962 : void IFMapDependencyManager::SetObject(IFMapNode *node, DBEntry *entry) {
     366             : 
     367         962 :     IFMapNodeState *state = IFMapNodeGet(node);
     368         962 :     assert(state);
     369             : 
     370         962 :     DBEntry *old_entry = state->object();
     371             : 
     372         962 :     if (old_entry)
     373         481 :         state->clear_object();
     374             : 
     375         962 :     if (entry) {
     376         481 :         state->set_object(entry);
     377         481 :         tracker_->NodeEvent(node);
     378         481 :         trigger_->Set();
     379             :     }
     380         962 : }
     381             : 
     382         140 : void IFMapDependencyManager::SetNotify(IFMapNode *node, bool notify_flag) {
     383             : 
     384         140 :     IFMapNodeState *state = IFMapNodeGet(node);
     385         140 :     assert(state);
     386             : 
     387         140 :     state->set_notify(notify_flag);
     388         140 : }
     389             : 
     390           0 : void IFMapDependencyManager::SetRequestEnqueued(IFMapNode *node,
     391             :         bool oper_db_request_enqueued) {
     392             : 
     393           0 :     IFMapNodeState *state = IFMapNodeGet(node);
     394           0 :     assert(state);
     395             : 
     396           0 :     state->set_oper_db_request_enqueued(oper_db_request_enqueued);
     397           0 : }
     398             : 
     399             : IFMapDependencyManager::IFMapNodePtr
     400       10564 : IFMapDependencyManager::SetState(IFMapNode *node) {
     401       10564 :     IFMapTable *table = node->table();
     402       10564 :     TableMap::const_iterator loc = table_map_.find(table->name());
     403       10564 :     if (loc == table_map_.end())
     404           0 :         return NULL;
     405             : 
     406             :     IFMapNodeState *state =
     407       10564 :             static_cast<IFMapNodeState *>(node->GetState(table, loc->second));
     408             : 
     409       10564 :     if (!state) {
     410        1021 :         state = new IFMapNodeState(this, node);
     411        1021 :         node->SetState(table, loc->second, state);
     412             :     }
     413       10564 :     return IFMapNodePtr(state);
     414             : }
     415             : 
     416           0 : DBEntry *IFMapDependencyManager::GetObject(IFMapNode *node) {
     417           0 :     IFMapTable *table = node->table();
     418           0 :     TableMap::const_iterator loc = table_map_.find(table->name());
     419           0 :     if (loc == table_map_.end())
     420           0 :         return NULL;
     421             : 
     422             :     IFMapNodeState *state =
     423           0 :         static_cast<IFMapNodeState *>(node->GetState(table, loc->second));
     424           0 :     if (state == NULL)
     425           0 :         return NULL;
     426             : 
     427           0 :     return state->object();
     428             : }
     429             : 
     430             : /*
     431             :  * Register a notification callback.
     432             :  */
     433          54 : void IFMapDependencyManager::Register(
     434             :     const string &type, ChangeEventHandler handler) {
     435          54 :     event_map_.insert(std::make_pair(type, handler));
     436          54 : }
     437             : 
     438             : /*
     439             :  * Unregister a notification callback.
     440             :  */
     441           0 : void IFMapDependencyManager::Unregister(const string &type) {
     442           0 :     event_map_.erase(type);
     443           0 : }
     444             : 
     445             : // Check if a IFMapNode type is registerd with dependency manager
     446       12284 : bool IFMapDependencyManager::IsRegistered(const IFMapNode *node) {
     447       12284 :     EventMap::iterator it = event_map_.find(node->table()->Typename());
     448       12284 :     return (it != event_map_.end());
     449             : }
     450             : 
     451        4604 : bool IFMapDependencyManager::IsNodeIdentifiedByUuid(const IFMapNode *node) {
     452        4604 :     return (strcmp(node->table()->Typename(), "routing-instance") != 0);
     453             : }
     454             : 
     455         120 : IFMapDependencyManager::Path MakePath
     456             : (const char *link1,        const char *node1,        bool interest1,
     457             :  const char *link2 = NULL, const char *node2 = NULL, bool interest2 = false,
     458             :  const char *link3 = NULL, const char *node3 = NULL, bool interest3 = false,
     459             :  const char *link4 = NULL, const char *node4 = NULL, bool interest4 = false,
     460             :  const char *link5 = NULL, const char *node5 = NULL, bool interest5 = false,
     461             :  const char *link6 = NULL, const char *node6 = NULL, bool interest6 = false) {
     462         120 :     if (link2) assert(node2);
     463         120 :     if (link3) assert(node3);
     464         120 :     if (link4) assert(node4);
     465         120 :     if (link5) assert(node5);
     466         120 :     if (link6) assert(node6);
     467             : 
     468         120 :     IFMapDependencyManager::Path path;
     469         120 :     path.push_back(IFMapDependencyManager::Link(link1, node1, interest1));
     470         120 :     if (link2)
     471          72 :         path.push_back(IFMapDependencyManager::Link(link2, node2, interest2));
     472         120 :     if (link3)
     473          36 :         path.push_back(IFMapDependencyManager::Link(link3, node3, interest3));
     474         120 :     if (link4)
     475          18 :         path.push_back(IFMapDependencyManager::Link(link4, node4, interest4));
     476         120 :     if (link5)
     477          10 :         path.push_back(IFMapDependencyManager::Link(link5, node5, interest5));
     478         120 :     if (link6)
     479           2 :         path.push_back(IFMapDependencyManager::Link(link6, node6, interest6));
     480         120 :     return path;
     481           0 : }
     482             : 
     483         378 : static NodeEventPolicy::iterator LocateNodeEventPolicy(NodeEventPolicy *policy,
     484             :                                                        const string &node) {
     485         378 :     NodeEventPolicy::iterator it = policy->find(node);
     486         378 :     if (it != policy->end()) {
     487         290 :         return it;
     488             :     }
     489             :     ReactionMap react = map_list_of<string, PropagateList>
     490         176 :         ("self", PropagateList());
     491          88 :     policy->insert(make_pair(node, react));
     492          88 :     return policy->find(node);
     493          88 : }
     494             : 
     495         606 : static ReactionMap::iterator LocateReactionMap(ReactionMap *react,
     496             :                                                const string &event) {
     497         606 :     ReactionMap::iterator it = react->find(event);
     498         606 :     if (it != react->end()) {
     499         388 :         return it;
     500             :     }
     501         218 :     react->insert(make_pair(event, PropagateList()));
     502         218 :     return react->find(event);
     503             : }
     504             : 
     505             : ////////////////////////////////////////////////////////////////////////
     506             : // The IFMap dependency tracker accepts rules in the form or "Reactor Map"
     507             : // Reactor map is not natural way of defining references between IFMap nodes
     508             : // in agent.
     509             : //
     510             : // When agent builds data for an oper-db entry, the IFNodeToReq API will keep
     511             : // the IFMapNode for oper-db entry as starting node and traverses the graph
     512             : // to build all realvent data for the entry. So, it is more natural in agent
     513             : // to specify relation between nodes in a way IFMapNodeToReq traverses the
     514             : // graph
     515             : //
     516             : // The routine AddDependencyPath takes the graph path between two vertices
     517             : // and then creates "Reactor Map" for them.
     518             : //
     519             : // The API takes IFMapNode for object being built as "node" and then a graph
     520             : // path to reach another IFMapNode of interest.
     521             : //
     522             : // Example: VMI refers to RI with following path to support floating-ip
     523             : //     VMI <----> FIP <----> FIP-POOL <----> VN <----> RI
     524             : //
     525             : //     node is specified as "virtual-machine-interface"
     526             : //     path is specified as,
     527             : //          <string(link-metadata), string(vertex), bool(vertex-attr-interest)>
     528             : //
     529             : //          vertex specifies name of the adjacent node in the path
     530             : //          link-metadata specifies metadata of the link connecting the vertex
     531             : //          vertex-attr-interest
     532             : //               If "node" is interested in any attribute of vertex, this value
     533             : //               is set to TRUE else its set to FALSE
     534             : //               When value is set to TRUE, it will generate an event of type
     535             : //               "self" in the reactor-map
     536             : //
     537             : //          The path from virtual-machine-interface to "routing-instance" above
     538             : //          is given as below,
     539             : //
     540             : //          <"virtual-machine-interface-floating-ip", "floating-ip", true>
     541             : //          <"floating-ip-floating-ip-pool", "floating-ip-pool", false>
     542             : //          <"floating-ip-pool-virtual-network", "virtual-network", true>
     543             : //          <"virtual-network-routing-instance", "routing-instance", true>
     544             : //
     545             : // AddDependencyPath will "APPEND" following Reactor rules,
     546             : //      node(virtual-machine-interface)
     547             : //             event(virtual-machine-floating-ip) => Rectors(self)
     548             : //
     549             : //      node(routing-instance)
     550             : //             event(self) => Reactors(virtual-network-routing-instance)
     551             : //
     552             : //      node(virtual-network)
     553             : //             event(virtual-network-routing-instance) => Reactors(floating-ip-pool-virtual-network)
     554             : //
     555             : //      node(floating-ip-pool)
     556             : //             event(self) => Reactors(virtual-machine-interface-virtual-network)
     557             : //             event(floating-ip-pool-virtual-network) => Reactors(floating-ip-floating-ip-pool)
     558             : //
     559             : //      node(floating-ip)
     560             : //             event(self) => Reactors(virtual-machine-interface-floating-ip)
     561             : //             event(floating-ip-floating-ip-pool) => Reactors(virtual-machine-interface-floating-ip)
     562             : //
     563             : ////////////////////////////////////////////////////////////////////////
     564         120 : void IFMapDependencyManager::AddDependencyPath(const std::string &node,
     565             :                                                Path path) {
     566         120 :     NodeEventPolicy *policy = tracker_->policy_map();
     567         120 :     assert(policy);
     568             : 
     569         120 :     NodeEventPolicy::iterator node_it;
     570         120 :     node_it = LocateNodeEventPolicy(policy, node);
     571         120 :     ReactionMap::iterator react_it = LocateReactionMap(&node_it->second,
     572         120 :                                                        path[0].edge_);
     573         120 :     LOG(DEBUG, "Updating dependency tacker rules for " << node);
     574         120 :     react_it->second.insert("self");
     575         120 :     LOG(DEBUG, "Adding ReactorMap " << node_it->first << " : " <<
     576             :                 react_it->first << " -> " << "self");
     577             : 
     578         378 :     for (size_t i = 0; i < path.size(); i++) {
     579         258 :         node_it = LocateNodeEventPolicy(policy, path[i].vertex_);
     580         258 :         if (path[i].vertex_interest_) {
     581         228 :             react_it = LocateReactionMap(&node_it->second, "self");
     582         228 :             react_it->second.insert(path[i].edge_);
     583         228 :             LOG(DEBUG, "Adding ReactorMap " << node_it->first << " : " <<
     584             :                 react_it->first << " -> " << path[i].edge_);
     585             :         }
     586             : 
     587         258 :         if (i < (path.size() - 1)) {
     588         138 :             react_it = LocateReactionMap(&node_it->second, path[i+1].edge_);
     589         138 :             react_it->second.insert(path[i].edge_);
     590         138 :             LOG(DEBUG, "Adding ReactorMap " << node_it->first << " : " <<
     591             :                 react_it->first << " -> " << path[i].edge_);
     592             :         } else {
     593         120 :             react_it = LocateReactionMap(&node_it->second, path[i].edge_);
     594         120 :             react_it->second.insert("nil");
     595         120 :             LOG(DEBUG, "Adding ReactorMap " << node_it->first << " : " <<
     596             :                 react_it->first << " -> " << "nil");
     597             :         }
     598             :     }
     599             : 
     600         240 :     return;
     601             : }
     602             : 
     603             : // Register callback for ifmap node not having corresponding oper-dbtable
     604          14 : static void RegisterConfigHandler(IFMapDependencyManager *dep,
     605             :                                   const char *name, OperIFMapTable *table) {
     606          14 :     if (table)
     607          14 :         dep->Register(name, boost::bind(&OperIFMapTable::ConfigEventHandler,
     608             :                                         table, _1, _2));
     609          14 : }
     610             : 
     611          38 : static void RegisterConfigHandler(IFMapDependencyManager *dep,
     612             :                                   const char *name, AgentOperDBTable *table) {
     613          38 :     if (table)
     614          38 :         dep->Register(name, boost::bind(&AgentOperDBTable::ConfigEventHandler,
     615             :                                         table, _1, _2));
     616          38 : }
     617             : 
     618           2 : void IFMapDependencyManager::InitializeDependencyRules(Agent *agent) {
     619             : 
     620           4 :     RegisterConfigHandler(this, "virtual-machine",
     621           2 :                           agent ? agent->vm_table() : NULL);
     622             : 
     623           4 :     RegisterConfigHandler(this, "access-control-list",
     624           2 :                           agent ? agent->acl_table() : NULL);
     625             : 
     626           4 :     RegisterConfigHandler(this, "multicast-policy",
     627           2 :                           agent ? agent->mp_table() : NULL);
     628             : 
     629             :     ////////////////////////////////////////////////////////////////////////
     630             :     // VN <----> RI
     631             :     //    <----> ACL
     632             :     //    <----> VN-IPAM <----> IPAM
     633             :     //    <----> SecurityLoggingObject
     634             :     //    <----> Multicast Policy
     635             :     ////////////////////////////////////////////////////////////////////////
     636           2 :     AddDependencyPath("virtual-network",
     637           4 :                       MakePath("virtual-network-routing-instance",
     638             :                                "routing-instance", true));
     639           2 :     AddDependencyPath("virtual-network",
     640           4 :                       MakePath("virtual-network-access-control-list",
     641             :                                "access-control-list", true));
     642           2 :     AddDependencyPath("virtual-network",
     643           4 :                       MakePath("virtual-network-network-ipam",
     644             :                                "virtual-network-network-ipam", true,
     645             :                                "virtual-network-network-ipam",
     646             :                                "network-ipam", false));
     647           2 :     AddDependencyPath("virtual-network",
     648           4 :                       MakePath("virtual-network-qos-config",
     649             :                                "qos-config", true));
     650           2 :     AddDependencyPath("virtual-network",
     651           4 :                       MakePath("virtual-network-security-logging-object",
     652             :                                "security-logging-object", true));
     653           2 :     AddDependencyPath("virtual-network",
     654           4 :                       MakePath("logical-router-virtual-network",
     655             :                                "logical-router-virtual-network", true,
     656             :                                "logical-router-virtual-network",
     657             :                                "logical-router", true));
     658           2 :     AddDependencyPath("virtual-network",
     659           4 :                       MakePath("virtual-network-multicast-policy",
     660             :                                "multicast-policy", true));
     661           4 :     RegisterConfigHandler(this, "virtual-network",
     662           2 :                           agent ? agent->vn_table() : NULL);
     663             : 
     664             :     ////////////////////////////////////////////////////////////////////////
     665             :     // RI <----> VN
     666             :     ////////////////////////////////////////////////////////////////////////
     667           2 :     AddDependencyPath("routing-instance",
     668           4 :                       MakePath("virtual-network-routing-instance",
     669             :                                "virtual-network", true,
     670             :                                "virtual-network-provider-network",
     671             :                                "virtual-network", true));
     672           4 :     RegisterConfigHandler(this, "routing-instance",
     673           2 :                           agent ? agent->vrf_table() : NULL);
     674             : 
     675             :     ////////////////////////////////////////////////////////////////////////
     676             :     // SG <----> ACL
     677             :     ////////////////////////////////////////////////////////////////////////
     678           2 :     AddDependencyPath("security-group",
     679           4 :                       MakePath("security-group-access-control-list",
     680             :                                "access-control-list", true));
     681           4 :     RegisterConfigHandler(this, "security-group",
     682           2 :                          agent ? agent->sg_table() : NULL);
     683             : 
     684           4 :     RegisterConfigHandler(this, "tag",
     685           2 :                          agent ? agent->tag_table() : NULL);
     686           2 :     AddDependencyPath("tag",
     687           4 :                       MakePath("application-policy-set-tag",
     688             :                                "application-policy-set", true,
     689             :                                "policy-management-application-policy-set",
     690             :                                "policy-management", false));
     691             :     ////////////////////////////////////////////////////////////////////////
     692             :     // VMI <----> VN
     693             :     //     <----> VM
     694             :     //     <----> VMI-RI <----> RI
     695             :     //     <----> SG
     696             :     //     //<----> FIP <----> FIP-POOL <----> VN <----> RI
     697             :     //     <----> FIP <----> FIP-POOL <----> VN
     698             :     //     <----> FIP <----> Instance-IP <----> VN
     699             :     //     <----> Instance-IP
     700             :     //     <----> interface-route-table
     701             :     //     <----> subnet
     702             :     //     //<----> vn <----> VN-IPAM <----> IPAM
     703             :     //     <----> LI <----> physical-interface <----> physical-router
     704             :     //     <----> SecurityLoggingObject
     705             :     ////////////////////////////////////////////////////////////////////////
     706           2 :     AddDependencyPath("virtual-machine-interface",
     707           4 :                       MakePath("virtual-machine-interface-virtual-network",
     708             :                                "virtual-network", true,
     709             :                                "virtual-network-network-ipam",
     710             :                                "virtual-network-network-ipam", true));
     711           2 :     AddDependencyPath("virtual-machine-interface",
     712           4 :                       MakePath("virtual-machine-interface-virtual-machine",
     713             :                                "virtual-machine", true));
     714           2 :     AddDependencyPath("virtual-machine-interface",
     715           4 :                       MakePath("virtual-machine-interface-sub-interface",
     716             :                                "virtual-machine-interface", true));
     717             : 
     718           2 :     AddDependencyPath("virtual-machine-interface",
     719           4 :                       MakePath("virtual-machine-interface-virtual-network",
     720             :                                "virtual-network", true,
     721             :                                "virtual-network-provider-network",
     722             :                                "virtual-network", true));
     723             : 
     724           2 :     AddDependencyPath("virtual-machine-interface",
     725           4 :                       MakePath("virtual-machine-interface-routing-instance",
     726             :                                "virtual-machine-interface-routing-instance",
     727             :                                true,
     728             :                                "virtual-machine-interface-routing-instance",
     729             :                                "routing-instance", true));
     730             : 
     731           2 :     AddDependencyPath("virtual-machine-interface",
     732           4 :                       MakePath("virtual-machine-interface-security-group",
     733             :                                "security-group", true));
     734           2 :     AddDependencyPath("virtual-machine-interface",
     735           4 :                       MakePath("alias-ip-virtual-machine-interface",
     736             :                                "alias-ip", true,
     737             :                                "alias-ip-pool-alias-ip",
     738             :                                "alias-ip-pool", false,
     739             :                                "virtual-network-alias-ip-pool",
     740             :                                "virtual-network", true));
     741           2 :     AddDependencyPath("virtual-machine-interface",
     742           4 :                       MakePath("floating-ip-virtual-machine-interface",
     743             :                                "floating-ip", true,
     744             :                                "floating-ip-pool-floating-ip",
     745             :                                "floating-ip-pool", false,
     746             :                                "virtual-network-floating-ip-pool",
     747             :                                "virtual-network", true,
     748             :                                "virtual-network-provider-network",
     749             :                                "virtual-network", true));
     750           2 :     AddDependencyPath("virtual-machine-interface",
     751           4 :                       MakePath("floating-ip-virtual-machine-interface",
     752             :                                "floating-ip", true,
     753             :                                "floating-ip-pool-floating-ip",
     754             :                                "floating-ip-pool", false,
     755             :                                "virtual-network-floating-ip-pool",
     756             :                                "virtual-network", true,
     757             :                                "virtual-network-routing-instance",
     758             :                                "routing-instance", true));
     759           2 :      AddDependencyPath("virtual-machine-interface",
     760           4 :                        MakePath("floating-ip-virtual-machine-interface",
     761             :                                 "floating-ip", true,
     762             :                                 "instance-ip-floating-ip",
     763             :                                 "instance-ip", false,
     764             :                                 "instance-ip-virtual-network",
     765             :                                 "virtual-network", true));
     766           2 :     AddDependencyPath("virtual-machine-interface",
     767           4 :                       MakePath("instance-ip-virtual-machine-interface",
     768             :                                "instance-ip", true));
     769           2 :     AddDependencyPath("virtual-machine-interface",
     770           4 :                       MakePath("virtual-machine-interface-route-table",
     771             :                                "interface-route-table", true));
     772           2 :     AddDependencyPath("virtual-machine-interface",
     773           4 :                       MakePath("subnet-virtual-machine-interface",
     774             :                                "subnet", true));
     775           2 :     AddDependencyPath("virtual-machine-interface",
     776           4 :                       MakePath("logical-interface-virtual-machine-interface",
     777             :                                "logical-interface", false,
     778             :                                "physical-interface-logical-interface",
     779             :                                "physical-interface", false,
     780             :                                "physical-router-physical-interface",
     781             :                                "physical-router", true));
     782           2 :     AddDependencyPath("virtual-machine-interface",
     783           4 :                       MakePath("virtual-port-group-virtual-machine-interface",
     784             :                                "virtual-port-group", false,
     785             :                                "virtual-port-group-physical-interface",
     786             :                                "physical-interface", false,
     787             :                                "physical-router-physical-interface",
     788             :                                "physical-router", true));
     789           2 :     AddDependencyPath("virtual-machine-interface",
     790           4 :                       MakePath("bgpaas-virtual-machine-interface",
     791             :                                "bgp-as-a-service", true,
     792             :                                "bgpaas-bgp-router",
     793             :                                "bgp-router", true,
     794             :                                "instance-bgp-router",
     795             :                                "routing-instance", true));
     796           2 :     AddDependencyPath("virtual-machine-interface",
     797           4 :                       MakePath("bgpaas-virtual-machine-interface",
     798             :                                "bgp-as-a-service", true,
     799             :                                "bgpaas-health-check",
     800             :                                "service-health-check", true));
     801           2 :     AddDependencyPath("virtual-machine-interface",
     802           4 :                       MakePath("virtual-machine-interface-qos-config",
     803             :                           "qos-config", true));
     804           2 :     AddDependencyPath("virtual-machine-interface",
     805           4 :                    MakePath("virtual-machine-interface-security-logging-object",
     806             :                             "security-logging-object", true));
     807             : 
     808           2 :     AddDependencyPath("virtual-machine-interface",
     809           4 :                       MakePath("virtual-machine-interface-bridge-domain",
     810             :                                "virtual-machine-interface-bridge-domain",
     811             :                                true,
     812             :                                "virtual-machine-interface-bridge-domain",
     813             :                                "bridge-domain", true,
     814             :                                "virtual-network-bridge-domain",
     815             :                                "virtual-network", true));
     816             :     //Above rule should suffice for VMI to act on bridge domain
     817             :     //"virtual-machine-interface-bridge-domain" link is used to
     818             :     //link both VMI and bridge domain, so this link could notify
     819             :     //bridge-domain which doesnt have any reaction list as bridge-domain
     820             :     //is not intererested in "virtual-machine-interface-bridge-domain".
     821             :     //VMI ---> VMI-BD Link ---> VMI-BD node ----> VMI-BD link ---> BD
     822             :     //Note that link name is same in above graph
     823             :     //Add the below dummy rule so that VMI-BD link triggers
     824             :     //bridge-domain evaluation its ignored and avoids assert
     825           2 :     AddDependencyPath("virtual-machine-interface",
     826           4 :                       MakePath("virtual-machine-interface-bridge-domain",
     827             :                                "virtual-machine-interface-bridge-domain",
     828             :                                true,
     829             :                                "virtual-machine-interface-bridge-domain",
     830             :                                "bridge-domain", true));
     831             : 
     832           2 :     AddDependencyPath("virtual-machine-interface",
     833           4 :                       MakePath("virtual-machine-interface-tag",
     834             :                                "tag", true,
     835             :                                "application-policy-set-tag",
     836             :                                "application-policy-set", true,
     837             :                                "application-policy-set-firewall-policy",
     838             :                                "application-policy-set-firewall-policy", true,
     839             :                                "application-policy-set-firewall-policy",
     840             :                                "firewall-policy", true));
     841             : 
     842           2 :     AddDependencyPath("virtual-machine-interface",
     843           4 :                       MakePath("virtual-machine-interface-virtual-network",
     844             :                                "virtual-network", true,
     845             :                                "virtual-network-tag", "tag", true,
     846             :                                "application-policy-set-tag",
     847             :                                "application-policy-set", true,
     848             :                                "application-policy-set-firewall-policy",
     849             :                                "application-policy-set-firewall-policy", true,
     850             :                                "application-policy-set-firewall-policy",
     851             :                                "firewall-policy", true));
     852             : 
     853             : 
     854           2 :     AddDependencyPath("virtual-machine-interface",
     855           4 :                       MakePath("virtual-machine-interface-virtual-machine",
     856             :                                "virtual-machine", true,
     857             :                                "virtual-machine-tag", "tag", true,
     858             :                                "application-policy-set-tag",
     859             :                                "application-policy-set", true,
     860             :                                "application-policy-set-firewall-policy",
     861             :                                "application-policy-set-firewall-policy", true,
     862             :                                "application-policy-set-firewall-policy",
     863             :                                "firewall-policy", true));
     864             : 
     865           2 :     AddDependencyPath("virtual-machine-interface",
     866           4 :                       MakePath("virtual-machine-interface-sub-interface",
     867             :                                "virtual-machine-interface", true,
     868             :                                "virtual-machine-interface-virtual-machine",
     869             :                                "virtual-machine", true,
     870             :                                "virtual-machine-tag", "tag", true,
     871             :                                "application-policy-set-tag",
     872             :                                "application-policy-set", true,
     873             :                                "application-policy-set-firewall-policy",
     874             :                                "application-policy-set-firewall-policy", true,
     875             :                                "application-policy-set-firewall-policy",
     876             :                                "firewall-policy", true));
     877             : 
     878           2 :     AddDependencyPath("virtual-machine-interface",
     879           4 :                       MakePath("project-virtual-machine-interface",
     880             :                                "project", true,
     881             :                                "project-tag", "tag", true,
     882             :                                "application-policy-set-tag",
     883             :                                "application-policy-set", true,
     884             :                                "application-policy-set-firewall-policy",
     885             :                                "application-policy-set-firewall-policy", true,
     886             :                                "application-policy-set-firewall-policy",
     887             :                                "firewall-policy", true));
     888             : 
     889             :     /* Trigger change on virtual-machine-interface, if there is change in
     890             :      * port-tuple configuration */
     891           2 :     AddDependencyPath("virtual-machine-interface",
     892           4 :                       MakePath("port-tuple-interface",
     893             :                                "port-tuple", true,
     894             :                                "port-tuple-interface",
     895             :                                "virtual-machine-interface", true));
     896           2 :     AddDependencyPath("virtual-machine-interface",
     897           4 :                       MakePath("logical-router-interface",
     898             :                                "logical-router", true));
     899             : 
     900           4 :     RegisterConfigHandler(this, "virtual-machine-interface",
     901           2 :                           agent ? agent->interface_table() : NULL);
     902             :     ////////////////////////////////////////////////////////////////////////
     903             :     // physical-interface <----> physical-router
     904             :     ////////////////////////////////////////////////////////////////////////
     905           2 :     AddDependencyPath("physical-interface",
     906           4 :                       MakePath("physical-router-physical-interface",
     907             :                                "physical-router", true));
     908             :     ////////////////////////////////////////////////////////////////////////
     909             :     // physical-interface <----> virtual-port-group
     910             :     ////////////////////////////////////////////////////////////////////////
     911           2 :     AddDependencyPath("physical-interface",
     912           4 :                     MakePath("virtual-port-group-physical-interface",
     913             :                              "virtual-port-group-physical-interface", true,
     914             :                              "virtual-port-group-physical-interface",
     915             :                              "virtual-port-group", true));
     916           4 :     RegisterConfigHandler(this, "physical-interface",
     917           2 :                           agent ? agent->interface_table() : NULL);
     918             : 
     919             :     ////////////////////////////////////////////////////////////////////////
     920             :     // logical-interface <----> physical-interface <----> physical-router
     921             :     //                   <----> virtual-machine-interface <---> virtual-network
     922             :     //
     923             :     ////////////////////////////////////////////////////////////////////////
     924           2 :     AddDependencyPath("logical-interface",
     925           4 :                       MakePath("physical-interface-logical-interface",
     926             :                                "physical-interface", true,
     927             :                                "physical-router-physical-interface",
     928             :                                "physical-router", true));
     929           2 :     AddDependencyPath("logical-interface",
     930           4 :                       MakePath("logical-interface-virtual-machine-interface",
     931             :                                "virtual-machine-interface", true));
     932           2 :     AddDependencyPath("logical-interface",
     933           4 :                       MakePath("physical-router-logical-interface",
     934             :                                "physical-router", true));
     935           4 :     RegisterConfigHandler(this, "logical-interface",
     936           2 :                           agent ? agent->interface_table() : NULL);
     937             : 
     938             :     ////////////////////////////////////////////////////////////////////////
     939             :     // physical-router <----> physical-interface
     940             :     ////////////////////////////////////////////////////////////////////////
     941           2 :     AddDependencyPath("physical-router",
     942           4 :                       MakePath("physical-router-physical-interface",
     943             :                                "physical-interface", true));
     944           4 :     RegisterConfigHandler(this, "physical-router",
     945           2 :                           agent ? agent->physical_device_table() : NULL);
     946             : 
     947             :     ////////////////////////////////////////////////////////////////////////
     948             :     // virtual-machine-interface <----> service-health-check
     949             :     ////////////////////////////////////////////////////////////////////////
     950           2 :     AddDependencyPath("service-health-check",
     951           4 :                       MakePath("service-port-health-check",
     952             :                                "virtual-machine-interface", true,
     953             :                                "virtual-machine-interface-virtual-network",
     954             :                                "virtual-network", false,
     955             :                                "virtual-network-network-ipam",
     956             :                                "virtual-network-network-ipam", true));
     957           2 :     AddDependencyPath("service-health-check",
     958           4 :                       MakePath("service-port-health-check",
     959             :                                "virtual-machine-interface", true,
     960             :                                "port-tuple-interface",
     961             :                                "port-tuple", true,
     962             :                                "port-tuple-interface",
     963             :                                "virtual-machine-interface", true,
     964             :                                "virtual-machine-interface-virtual-network",
     965             :                                "virtual-network", false,
     966             :                                "virtual-network-network-ipam",
     967             :                                "virtual-network-network-ipam", true));
     968           4 :     RegisterConfigHandler(this, "service-health-check",
     969           2 :                           agent ? agent->health_check_table() : NULL);
     970             : 
     971           2 :     AddDependencyPath("qos-config",
     972           4 :                        MakePath("global-qos-config-qos-config",
     973             :                                 "global-qos-config", false));
     974           4 :     RegisterConfigHandler(this, "qos-config",
     975           2 :                           agent ? agent->qos_config_table() : NULL);
     976             : 
     977           4 :     RegisterConfigHandler(this, "qos-queue",
     978           2 :                           agent ? agent->qos_queue_table() : NULL);
     979             : 
     980           2 :     AddDependencyPath("forwarding-class",
     981           4 :                        MakePath("forwarding-class-qos-queue",
     982             :                                 "qos-queue", true));
     983           4 :     RegisterConfigHandler(this, "forwarding-class",
     984           2 :                           agent ? agent->forwarding_class_table() : NULL);
     985             : 
     986             :     ////////////////////////////////////////////////////////////////////////
     987             :     // security-logging-object <----> network-policy
     988             :     //                         <----> security-group
     989             :     ////////////////////////////////////////////////////////////////////////
     990           2 :     AddDependencyPath("security-logging-object",
     991           4 :                        MakePath("security-logging-object-network-policy",
     992             :                                 "network-policy", true));
     993           2 :     AddDependencyPath("security-logging-object",
     994           4 :                        MakePath("security-logging-object-security-group",
     995             :                                 "security-group", true));
     996           2 :     AddDependencyPath("security-logging-object",
     997           4 :                       MakePath("firewall-policy-security-logging-object",
     998             :                                "firewall-policy-security-logging-object", true,
     999             :                                "firewall-policy-security-logging-object",
    1000             :                                 "firewall-policy", false));
    1001           2 :     AddDependencyPath("security-logging-object",
    1002           4 :                        MakePath("firewall-rule-security-logging-object",
    1003             :                                 "firewall-rule-security-logging-object", true,
    1004             :                                 "firewall-rule-security-logging-object",
    1005             :                                 "firewall-rule", false));
    1006           4 :     RegisterConfigHandler(this, "security-logging-object",
    1007           2 :                           agent ? agent->slo_table() : NULL);
    1008             : 
    1009             :     ////////////////////////////////////////////////////////////////////////
    1010             :     // VR <----> Subcluster <----> bgp-router
    1011             :     ////////////////////////////////////////////////////////////////////////
    1012           2 :     AddDependencyPath("virtual-router",
    1013           4 :                        MakePath("virtual-router-sub-cluster",
    1014             :                                 "sub-cluster", true,
    1015             :                                 "bgp-router-sub-cluster",
    1016             :                                 "bgp-router", true));
    1017             : 
    1018             :     // Register callback for ifmap node not having corresponding oper-dbtable
    1019           2 :     RegisterConfigHandler(this, "virtual-router", agent->oper_db()->vrouter());
    1020           2 :     RegisterConfigHandler(this, "global-qos-config",
    1021           2 :                           agent->oper_db()->global_qos_config());
    1022           2 :     RegisterConfigHandler(this, "global-system-config",
    1023           2 :                           agent->oper_db()->global_system_config());
    1024           2 :     RegisterConfigHandler(this, "network-ipam",
    1025           2 :                           agent->oper_db()->network_ipam());
    1026           2 :     RegisterConfigHandler(this, "virtual-DNS",
    1027           2 :                           agent->oper_db()->virtual_dns());
    1028           2 :     RegisterConfigHandler(this, "global-vrouter-config",
    1029           2 :                           agent->oper_db()->global_vrouter());
    1030           2 :     RegisterConfigHandler(this, "bgp-router",
    1031           2 :                           agent->oper_db()->bgp_router_config());
    1032           2 :     AddDependencyPath("bridge-domain",
    1033           4 :                       MakePath("virtual-network-bridge-domain",
    1034             :                                "virtual-network", true,
    1035             :                                "virtual-network-routing-instance",
    1036             :                                "routing-instance", true));
    1037           2 :     AddDependencyPath("bridge-domain",
    1038           4 :                       MakePath("virtual-network-bridge-domain",
    1039             :                       "virtual-network", true));
    1040             : 
    1041           4 :     RegisterConfigHandler(this, "bridge-domain",
    1042           2 :                           agent ? agent->bridge_domain_table() : NULL);
    1043             : 
    1044           2 :     AddDependencyPath("application-policy-set",
    1045           4 :                       MakePath("application-policy-set-firewall-policy",
    1046             :                                "application-policy-set-firewall-policy", true,
    1047             :                                "application-policy-set-firewall-policy",
    1048             :                                "firewall-policy", true));
    1049           4 :     RegisterConfigHandler(this, "application-policy-set",
    1050           2 :                           agent ? agent->policy_set_table() : NULL);
    1051             : 
    1052           2 :     AddDependencyPath("firewall-policy",
    1053           4 :                       MakePath("firewall-policy-firewall-rule",
    1054             :                                "firewall-policy-firewall-rule", true,
    1055             :                                "firewall-policy-firewall-rule",
    1056             :                                "firewall-rule", true,
    1057             :                                "firewall-rule-service-group",
    1058             :                                "service-group", true));
    1059           2 :     AddDependencyPath("firewall-policy",
    1060           4 :                       MakePath("firewall-policy-firewall-rule",
    1061             :                                "firewall-policy-firewall-rule", true,
    1062             :                                "firewall-policy-firewall-rule",
    1063             :                                 "firewall-rule", true,
    1064             :                                 "firewall-rule-address-group",
    1065             :                                 "address-group", true,
    1066             :                                 "address-group-tag", "tag", "true"));
    1067             : 
    1068           2 :     AddDependencyPath("firewall-policy",
    1069           4 :                       MakePath("firewall-policy-firewall-rule",
    1070             :                                "firewall-policy-firewall-rule", true,
    1071             :                                "firewall-policy-firewall-rule",
    1072             :                                "firewall-rule", true,
    1073             :                                "firewall-rule-tag",
    1074             :                                "tag", true));
    1075             : 
    1076           2 :     AddDependencyPath("firewall-policy",
    1077           4 :                       MakePath("firewall-policy-firewall-rule",
    1078             :                                "firewall-policy-firewall-rule", true,
    1079             :                                "firewall-policy-firewall-rule",
    1080             :                                "firewall-rule", true));
    1081             : 
    1082           4 :     RegisterConfigHandler(this, "firewall-policy",
    1083           2 :                           agent ? agent->acl_table() : NULL);
    1084           2 : }
    1085             : 
    1086           0 : void IFMapNodePolicyReq::HandleRequest() const {
    1087           0 :     Agent *agent = Agent::GetInstance();
    1088           0 :     IFMapNodePolicyResp *resp = new IFMapNodePolicyResp();
    1089             : 
    1090             :     IFMapDependencyTracker::NodeEventPolicy *policy_list =
    1091           0 :         agent->oper_db()->dependency_manager()->tracker()->policy_map();
    1092           0 :     NodeEventPolicy::iterator it1 = policy_list->begin();
    1093           0 :     std::vector<IFMapNodePolicy> resp_policy_list;
    1094           0 :     while (it1 != policy_list->end()) {
    1095           0 :         if (it1->first.find(get_node()) == string::npos) {
    1096           0 :             it1++;
    1097           0 :             continue;
    1098             :         }
    1099             : 
    1100           0 :         ReactionMap::iterator it2 = it1->second.begin();
    1101           0 :         vector<IFMapReactEvent> resp_event_list;
    1102           0 :         while(it2 != it1->second.end()) {
    1103           0 :             IFMapReactEvent resp_event;
    1104           0 :             vector<string> resp_reactor_list;
    1105           0 :             PropagateList::iterator it3 = it2->second.begin();
    1106           0 :             while (it3 != it2->second.end()) {
    1107           0 :                 resp_reactor_list.push_back((*it3));
    1108           0 :                 it3++;
    1109             :             }
    1110           0 :             resp_event.set_event(it2->first);
    1111           0 :             resp_event.set_reactors(resp_reactor_list);
    1112           0 :             resp_event_list.push_back(resp_event);
    1113           0 :             it2++;
    1114           0 :         }
    1115             : 
    1116           0 :         IFMapNodePolicy policy;
    1117           0 :         policy.set_node(it1->first);
    1118           0 :         policy.set_events(resp_event_list);
    1119           0 :         resp_policy_list.push_back(policy);
    1120           0 :         it1++;
    1121           0 :     }
    1122             : 
    1123           0 :     resp->set_policies(resp_policy_list);
    1124           0 :     resp->set_context(context());
    1125           0 :     resp->set_more(false);
    1126           0 :     resp->Response();
    1127           0 :     return;
    1128           0 : }

Generated by: LCOV version 1.14