Line data Source code
1 : /*
2 : * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
3 : */
4 :
5 : #include <boost/uuid/uuid_io.hpp>
6 : #include <boost/scoped_ptr.hpp>
7 : #include <vnc_cfg_types.h>
8 : #include <base/util.h>
9 : #include <db/db_partition.h>
10 :
11 : #include <ifmap/ifmap_node.h>
12 : #include <ifmap/ifmap_link.h>
13 : #include <ifmap/ifmap_agent_table.h>
14 : #include <cmn/agent_cmn.h>
15 : #include <oper/operdb_init.h>
16 : #include <oper/ifmap_dependency_manager.h>
17 : #include <oper/config_manager.h>
18 :
19 : #include <oper/interface_common.h>
20 : #include <oper/health_check.h>
21 : #include <oper/physical_device.h>
22 : #include <oper/physical_device_vn.h>
23 : #include <oper/vn.h>
24 : #include <oper/vrf.h>
25 : #include <oper/sg.h>
26 : #include <oper/tag.h>
27 : #include <oper/vm.h>
28 : #include <oper/interface_common.h>
29 : #include <oper/global_qos_config.h>
30 : #include <oper/global_system_config.h>
31 : #include <oper/qos_config.h>
32 : #include <oper/vrouter.h>
33 : #include <oper/global_vrouter.h>
34 : #include <oper/bgp_router.h>
35 : #include <oper/forwarding_class.h>
36 : #include<oper/qos_queue.h>
37 : #include <oper/bridge_domain.h>
38 : #include <oper/security_logging_object.h>
39 : #include <oper/multicast_policy.h>
40 : #include <filter/policy_set.h>
41 : #include <vector>
42 : #include <string>
43 :
44 : using std::string;
45 :
46 1 : ConfigHelper::ConfigHelper(const ConfigManager *mgr,
47 1 : const Agent *agent) :
48 1 : mgr_(mgr), link_table_(NULL), agent_(agent) {
49 1 : }
50 :
51 0 : IFMapNode *ConfigHelper::GetOtherAdjacentNode(IFMapLink *link,
52 : IFMapNode *node) {
53 0 : if (link->left() == node) return link->right();
54 0 : if (link->right() == node) return link->left();
55 0 : return NULL;
56 : }
57 :
58 : //Note: FindLink here checks for many-to-one node.
59 0 : IFMapNode *ConfigHelper::FindLink(const char *type,
60 : IFMapNode *node) {
61 0 : IFMapLink *link = NULL;
62 0 : if (!link_table_) {
63 0 : link_table_ = static_cast<IFMapAgentLinkTable *>(agent_->db()->
64 0 : FindTable(IFMAP_AGENT_LINK_DB_NAME));
65 : }
66 :
67 0 : std::ostringstream key_with_node_in_right;
68 0 : key_with_node_in_right << type << ",," << node->ToString();
69 0 : link = link_table_->FindNextLink(key_with_node_in_right.str());
70 0 : if (link && (strcmp(link->metadata().c_str(), type) == 0))
71 0 : return GetOtherAdjacentNode(link, node);
72 :
73 0 : std::ostringstream key_with_node_in_left;
74 0 : key_with_node_in_left << type << "," << node->ToString() << ",";
75 0 : link = link_table_->FindNextLink(key_with_node_in_left.str());
76 0 : if (link && (strcmp(link->metadata().c_str(), type) == 0))
77 0 : return GetOtherAdjacentNode(link, node);
78 :
79 0 : return NULL;
80 0 : }
81 :
82 : class ConfigManagerNodeList {
83 : public:
84 : struct Node {
85 411 : Node(IFMapDependencyManager::IFMapNodePtr state) : state_(state) { }
86 662 : ~Node() { }
87 :
88 : IFMapDependencyManager::IFMapNodePtr state_;
89 : };
90 :
91 : struct NodeCmp {
92 360 : bool operator() (const Node &lhs, const Node &rhs) const {
93 360 : return lhs.state_.get() < rhs.state_.get();
94 : }
95 : };
96 : typedef std::set<Node, NodeCmp> NodeList;
97 : typedef NodeList::iterator NodeListIterator;
98 :
99 17 : ConfigManagerNodeList(AgentDBTable *table) :
100 34 : table_(table), oper_ifmap_table_(NULL), enqueue_count_(0),
101 17 : process_count_(0) {
102 17 : }
103 :
104 7 : ConfigManagerNodeList(OperIFMapTable *table) :
105 14 : table_(NULL), oper_ifmap_table_(table), enqueue_count_(0),
106 7 : process_count_(0) {
107 7 : }
108 :
109 24 : ~ConfigManagerNodeList() {
110 24 : assert(list_.size() == 0);
111 24 : }
112 :
113 411 : bool Add(Agent *agent, ConfigManager *mgr, IFMapNode *node) {
114 411 : IFMapDependencyManager *dep = agent->oper_db()->dependency_manager();
115 411 : Node n(dep->SetState(node));
116 411 : list_.insert(n);
117 411 : enqueue_count_++;
118 411 : mgr->Start();
119 411 : return true;
120 411 : }
121 :
122 : bool Delete(Agent *agent, ConfigManager *mgr, IFMapNode *node) {
123 : IFMapDependencyManager *dep = agent->oper_db()->dependency_manager();
124 : IFMapNodeState *state = dep->IFMapNodeGet(node);
125 : if (state == NULL)
126 : return false;
127 : Node n(state);
128 : list_.erase(n);
129 : return true;
130 : }
131 :
132 3480 : uint32_t Process(uint32_t weight) {
133 3480 : uint32_t count = 0;
134 3480 : NodeListIterator it = list_.begin();
135 3731 : while (weight && (it != list_.end())) {
136 251 : NodeListIterator prev = it++;
137 251 : IFMapNodeState *state = prev->state_.get();
138 251 : IFMapNode *node = state->node();
139 :
140 251 : DBRequest req;
141 251 : boost::uuids::uuid id = state->uuid();
142 251 : if (table_) {
143 240 : if (table_->ProcessConfig(node, req, id)) {
144 120 : table_->Enqueue(&req);
145 : }
146 : }
147 :
148 251 : if (oper_ifmap_table_) {
149 11 : oper_ifmap_table_->ProcessConfig(node);
150 : }
151 :
152 251 : list_.erase(prev);
153 251 : weight--;
154 251 : count++;
155 251 : process_count_++;
156 251 : }
157 :
158 3480 : return count;
159 : }
160 :
161 3045 : uint32_t Size() const { return list_.size(); }
162 0 : uint32_t enqueue_count() const { return enqueue_count_; }
163 0 : uint32_t process_count() const { return process_count_; }
164 :
165 : private:
166 : AgentDBTable *table_;
167 : OperIFMapTable *oper_ifmap_table_;
168 : NodeList list_;
169 : uint32_t enqueue_count_;
170 : uint32_t process_count_;
171 : DISALLOW_COPY_AND_ASSIGN(ConfigManagerNodeList);
172 : };
173 :
174 : class ConfigManagerDeviceVnList {
175 : public:
176 : struct DeviceVnEntry {
177 5 : DeviceVnEntry(const boost::uuids::uuid &dev,
178 5 : const boost::uuids::uuid &vn) : dev_(dev), vn_(vn) {
179 5 : }
180 :
181 9 : ~DeviceVnEntry() { }
182 :
183 : boost::uuids::uuid dev_;
184 : boost::uuids::uuid vn_;
185 : };
186 :
187 : struct DeviceVnEntryCmp {
188 0 : bool operator() (const DeviceVnEntry &lhs, const DeviceVnEntry &rhs) const {
189 0 : if (lhs.dev_ != rhs.dev_)
190 0 : return lhs.dev_ < rhs.dev_;
191 :
192 0 : return lhs.vn_ < rhs.vn_;
193 : }
194 : };
195 :
196 : typedef std::set<DeviceVnEntry, DeviceVnEntryCmp> DeviceVnList;
197 : typedef DeviceVnList::iterator DeviceVnIterator;
198 :
199 1 : ConfigManagerDeviceVnList(PhysicalDeviceVnTable *table) :
200 1 : table_(table), enqueue_count_(0), process_count_(0) {
201 1 : }
202 :
203 1 : ~ConfigManagerDeviceVnList() {
204 1 : assert(list_.size() == 0);
205 1 : }
206 :
207 4 : bool Add(Agent *agent, ConfigManager *mgr, const boost::uuids::uuid &dev,
208 : const boost::uuids::uuid &vn) {
209 4 : list_.insert(DeviceVnEntry(dev, vn));
210 4 : enqueue_count_++;
211 4 : mgr->Start();
212 4 : return true;
213 : }
214 :
215 1 : bool Delete(Agent *agent, ConfigManager *mgr, const boost::uuids::uuid &dev,
216 : const boost::uuids::uuid &vn) {
217 1 : list_.erase(DeviceVnEntry(dev, vn));
218 1 : return true;
219 : }
220 :
221 145 : uint32_t Process(uint32_t weight) {
222 145 : uint32_t count = 0;
223 145 : DeviceVnIterator it = list_.begin();
224 149 : while (weight && (it != list_.end())) {
225 4 : DeviceVnIterator prev = it++;
226 4 : DBRequest req;
227 4 : table_->ProcessConfig(prev->dev_, prev->vn_);
228 4 : list_.erase(prev);
229 4 : weight--;
230 4 : count++;
231 4 : }
232 145 : return count;
233 : }
234 :
235 145 : uint32_t Size() const { return list_.size(); }
236 : uint32_t enqueue_count() const { return enqueue_count_; }
237 0 : uint32_t process_count() const { return process_count_; }
238 :
239 : private:
240 : PhysicalDeviceVnTable *table_;
241 : DeviceVnList list_;
242 : uint32_t enqueue_count_;
243 : uint32_t process_count_;
244 : DISALLOW_COPY_AND_ASSIGN(ConfigManagerDeviceVnList);
245 : };
246 :
247 1 : ConfigManager::ConfigManager(Agent *agent) :
248 1 : agent_(agent), trigger_(), timer_(NULL), timeout_(kMinTimeout) {
249 :
250 1 : int task_id = TaskScheduler::GetInstance()->GetTaskId("db::DBTable");
251 : trigger_.reset
252 2 : (new TaskTrigger(boost::bind(&ConfigManager::TriggerRun, this),
253 1 : task_id, 0));
254 1 : timer_ = TimerManager::CreateTimer(*(agent->event_manager()->io_service()),
255 : "Config Manager", task_id, 0);
256 11 : for (uint32_t i = 0; i < kMaxTimeout; i++) {
257 10 : process_config_count_[i] = 0;
258 : }
259 1 : helper_.reset(new ConfigHelper(this, agent_));
260 1 : }
261 :
262 2 : ConfigManager::~ConfigManager() {
263 1 : timer_->Cancel();
264 1 : TimerManager::DeleteTimer(timer_);
265 2 : }
266 :
267 1 : void ConfigManager::Init() {
268 1 : AgentDBTable *intf_table = agent_->interface_table();
269 1 : vmi_list_.reset(new ConfigManagerNodeList(intf_table));
270 1 : physical_interface_list_.reset(new ConfigManagerNodeList(intf_table));
271 1 : logical_interface_list_.reset(new ConfigManagerNodeList(intf_table));
272 :
273 1 : device_list_.reset(new ConfigManagerNodeList
274 1 : (agent_->physical_device_table()));
275 1 : sg_list_.reset(new ConfigManagerNodeList(agent_->sg_table()));
276 1 : tag_list_.reset(new ConfigManagerNodeList(agent_->tag_table()));
277 1 : vn_list_.reset(new ConfigManagerNodeList(agent_->vn_table()));
278 1 : vrf_list_.reset(new ConfigManagerNodeList(agent_->vrf_table()));
279 1 : vm_list_.reset(new ConfigManagerNodeList(agent_->vm_table()));
280 1 : hc_list_.reset(new ConfigManagerNodeList
281 1 : (agent_->health_check_table()));
282 1 : bridge_domain_list_.reset(new ConfigManagerNodeList(
283 1 : agent_->bridge_domain_table()));
284 1 : policy_set_list_.reset(new ConfigManagerNodeList(
285 1 : agent_->policy_set_table()));
286 1 : qos_config_list_.reset(new ConfigManagerNodeList(agent_->qos_config_table()));
287 1 : device_vn_list_.reset(new ConfigManagerDeviceVnList
288 1 : (agent_->physical_device_vn_table()));
289 1 : qos_queue_list_.reset(new ConfigManagerNodeList(agent_->qos_queue_table()));
290 1 : forwarding_class_list_.reset(new
291 1 : ConfigManagerNodeList(agent_->forwarding_class_table()));
292 1 : slo_list_.reset(new
293 1 : ConfigManagerNodeList(agent_->slo_table()));
294 1 : mp_list_.reset(new ConfigManagerNodeList(agent_->mp_table()));
295 :
296 1 : OperDB *oper_db = agent()->oper_db();
297 : global_vrouter_list_.reset
298 1 : (new ConfigManagerNodeList(oper_db->global_vrouter()));
299 : bgp_router_config_list_.reset
300 1 : (new ConfigManagerNodeList(oper_db->bgp_router_config()));
301 : virtual_router_list_.reset
302 1 : (new ConfigManagerNodeList(oper_db->vrouter()));
303 : global_qos_config_list_.reset
304 1 : (new ConfigManagerNodeList(oper_db->global_qos_config()));
305 : global_system_config_list_.reset
306 1 : (new ConfigManagerNodeList(oper_db->global_system_config()));
307 : network_ipam_list_.reset
308 1 : (new ConfigManagerNodeList(oper_db->network_ipam()));
309 1 : virtual_dns_list_.reset(new ConfigManagerNodeList(oper_db->virtual_dns()));
310 1 : }
311 :
312 145 : uint32_t ConfigManager::Size() const {
313 : return
314 145 : global_vrouter_list_->Size() +
315 145 : bgp_router_config_list_->Size() +
316 145 : virtual_router_list_->Size() +
317 145 : global_qos_config_list_->Size() +
318 145 : global_system_config_list_->Size() +
319 145 : network_ipam_list_->Size() + + +
320 145 : virtual_dns_list_->Size() +
321 145 : vmi_list_->Size() +
322 145 : physical_interface_list_->Size() +
323 145 : logical_interface_list_->Size() +
324 145 : device_list_->Size() +
325 145 : sg_list_->Size() +
326 145 : tag_list_->Size() +
327 145 : vn_list_->Size() +
328 145 : vrf_list_->Size() +
329 145 : vm_list_->Size() +
330 145 : hc_list_->Size() +
331 145 : device_vn_list_->Size() +
332 145 : qos_config_list_->Size() +
333 145 : bridge_domain_list_->Size() +
334 145 : policy_set_list_->Size() +
335 145 : mp_list_->Size();
336 : }
337 :
338 0 : uint32_t ConfigManager::ProcessCount() const {
339 : return
340 0 : global_vrouter_list_->process_count() +
341 0 : bgp_router_config_list_->process_count() +
342 0 : virtual_router_list_->process_count() +
343 0 : global_qos_config_list_->process_count() +
344 0 : global_system_config_list_->process_count() +
345 0 : network_ipam_list_->process_count() +
346 0 : virtual_dns_list_->process_count() +
347 0 : vmi_list_->process_count() +
348 0 : physical_interface_list_->process_count() +
349 0 : logical_interface_list_->process_count() +
350 0 : device_list_->process_count() +
351 0 : sg_list_->process_count() +
352 0 : tag_list_->process_count() +
353 0 : vn_list_->process_count() +
354 0 : vrf_list_->process_count() +
355 0 : vm_list_->process_count() +
356 0 : hc_list_->process_count() +
357 0 : device_vn_list_->process_count() +
358 0 : qos_config_list_->process_count() +
359 0 : policy_set_list_->process_count() +
360 0 : mp_list_->process_count();
361 : }
362 :
363 416 : void ConfigManager::Start() {
364 416 : if (agent_->ResourceManagerReady() == false) {
365 0 : return;
366 : }
367 :
368 416 : if (agent_->test_mode()) {
369 416 : trigger_->Set();
370 : } else {
371 0 : timeout_++;
372 0 : if (timeout_ > kMaxTimeout)
373 0 : timeout_ = kMaxTimeout;
374 0 : if (timer_->Idle())
375 0 : timer_->Start(timeout_, boost::bind(&ConfigManager::TimerRun,
376 : this));
377 : }
378 : }
379 :
380 0 : bool ConfigManager::TimerRun() {
381 0 : int count = Run();
382 0 : process_config_count_[timeout_] += count;
383 :
384 0 : if (Size() == 0) {
385 0 : timeout_ = kMinTimeout;
386 0 : return false;
387 : }
388 :
389 0 : timeout_--;
390 0 : if (timeout_ <= kMinTimeout)
391 0 : timeout_ = kMinTimeout;
392 0 : timer_->Reschedule(timeout_);
393 0 : return true;
394 : }
395 :
396 145 : bool ConfigManager::TriggerRun() {
397 145 : Run();
398 145 : return (Size() == 0);
399 : }
400 :
401 : // Run the change-list
402 145 : int ConfigManager::Run() {
403 145 : uint32_t max_count = kIterationCount;
404 145 : uint32_t count = 0;
405 :
406 145 : count += global_vrouter_list_->Process(max_count - count);
407 145 : count += bgp_router_config_list_->Process(max_count - count);
408 145 : count += virtual_router_list_->Process(max_count - count);
409 145 : count += global_qos_config_list_->Process(max_count - count);
410 145 : count += global_system_config_list_->Process(max_count - count);
411 145 : count += network_ipam_list_->Process(max_count - count);
412 145 : count += virtual_dns_list_->Process(max_count - count);
413 145 : count += sg_list_->Process(max_count - count);
414 145 : count += tag_list_->Process(max_count - count);
415 145 : count += physical_interface_list_->Process(max_count - count);
416 145 : count += qos_queue_list_->Process(max_count - count);
417 145 : count += forwarding_class_list_->Process(max_count - count);
418 145 : count += qos_config_list_->Process(max_count - count);
419 145 : count += vn_list_->Process(max_count - count);
420 145 : count += vm_list_->Process(max_count - count);
421 145 : count += vrf_list_->Process(max_count - count);
422 145 : count += bridge_domain_list_->Process(max_count - count);
423 145 : count += policy_set_list_->Process(max_count - count);
424 145 : count += logical_interface_list_->Process(max_count - count);
425 145 : count += hc_list_->Process(max_count - count);
426 145 : count += vmi_list_->Process(max_count - count);
427 145 : count += device_list_->Process(max_count - count);
428 145 : count += device_vn_list_->Process(max_count - count);
429 145 : count += slo_list_->Process(max_count - count);
430 145 : count += mp_list_->Process(max_count - count);
431 145 : return count;
432 : }
433 :
434 174 : void ConfigManager::AddVmiNode(IFMapNode *node) {
435 174 : vmi_list_->Add(agent_, this, node);
436 174 : }
437 :
438 0 : uint32_t ConfigManager::VmiNodeCount() const {
439 0 : return vmi_list_->Size();
440 : }
441 :
442 18 : void ConfigManager::AddLogicalInterfaceNode(IFMapNode *node) {
443 18 : logical_interface_list_->Add(agent_, this, node);
444 18 : }
445 :
446 0 : uint32_t ConfigManager::LogicalInterfaceNodeCount() const {
447 0 : return logical_interface_list_->Size();
448 : }
449 :
450 5 : void ConfigManager::AddPhysicalDeviceNode(IFMapNode *node) {
451 5 : device_list_->Add(agent_, this, node);
452 5 : }
453 :
454 0 : void ConfigManager::AddHealthCheckServiceNode(IFMapNode *node) {
455 0 : hc_list_->Add(agent_, this, node);
456 0 : }
457 :
458 0 : void ConfigManager::AddBridgeDomainNode(IFMapNode *node) {
459 0 : bridge_domain_list_->Add(agent_, this, node);
460 0 : }
461 :
462 0 : void ConfigManager::AddPolicySetNode(IFMapNode *node) {
463 0 : policy_set_list_->Add(agent_, this, node);
464 0 : }
465 :
466 18 : void ConfigManager::AddSgNode(IFMapNode *node) {
467 18 : sg_list_->Add(agent_, this, node);
468 18 : }
469 :
470 0 : void ConfigManager::AddTagNode(IFMapNode *node) {
471 0 : tag_list_->Add(agent_, this, node);
472 0 : }
473 :
474 65 : void ConfigManager::AddVnNode(IFMapNode *node) {
475 65 : vn_list_->Add(agent_, this, node);
476 65 : }
477 :
478 56 : void ConfigManager::AddVrfNode(IFMapNode *node) {
479 56 : vrf_list_->Add(agent_, this, node);
480 56 : }
481 :
482 50 : void ConfigManager::AddVmNode(IFMapNode *node) {
483 50 : vm_list_->Add(agent_, this, node);
484 50 : }
485 :
486 7 : void ConfigManager::AddPhysicalInterfaceNode(IFMapNode *node) {
487 7 : physical_interface_list_->Add(agent_, this, node);
488 7 : }
489 :
490 0 : void ConfigManager::AddQosConfigNode(IFMapNode *node) {
491 0 : qos_config_list_->Add(agent_, this, node);
492 0 : }
493 :
494 0 : void ConfigManager::AddForwardingClassNode(IFMapNode *node) {
495 0 : forwarding_class_list_->Add(agent_, this, node);
496 0 : }
497 :
498 0 : void ConfigManager::AddSecurityLoggingObjectNode(IFMapNode *node) {
499 0 : slo_list_->Add(agent_, this, node);
500 0 : }
501 :
502 0 : void ConfigManager::AddMulticastPolicyNode(IFMapNode *node) {
503 0 : mp_list_->Add(agent_, this, node);
504 0 : }
505 :
506 0 : void ConfigManager::AddQosQueueNode(IFMapNode *node) {
507 0 : qos_queue_list_->Add(agent_, this, node);
508 0 : }
509 :
510 4 : void ConfigManager::AddPhysicalDeviceVn(const boost::uuids::uuid &dev,
511 : const boost::uuids::uuid &vn) {
512 4 : device_vn_list_->Add(agent_, this, dev, vn);
513 4 : }
514 :
515 1 : void ConfigManager::DelPhysicalDeviceVn(const boost::uuids::uuid &dev,
516 : const boost::uuids::uuid &vn) {
517 1 : device_vn_list_->Delete(agent_, this, dev, vn);
518 1 : }
519 0 : uint32_t ConfigManager::PhysicalDeviceVnCount() const {
520 0 : return device_vn_list_->Size();
521 : }
522 :
523 0 : void ConfigManager::AddGlobalQosConfigNode(IFMapNode *node) {
524 0 : global_qos_config_list_->Add(agent_, this, node);
525 0 : }
526 :
527 0 : void ConfigManager::AddGlobalSystemConfigNode(IFMapNode *node) {
528 0 : global_system_config_list_->Add(agent_, this, node);
529 0 : }
530 :
531 17 : void ConfigManager::AddNetworkIpamNode(IFMapNode *node) {
532 17 : network_ipam_list_->Add(agent_, this, node);
533 17 : }
534 :
535 0 : void ConfigManager::AddVirtualDnsNode(IFMapNode *node) {
536 0 : virtual_dns_list_->Add(agent_, this, node);
537 0 : }
538 :
539 1 : void ConfigManager::AddGlobalVrouterNode(IFMapNode *node) {
540 1 : global_vrouter_list_->Add(agent_, this, node);
541 1 : }
542 :
543 0 : void ConfigManager::AddBgpRouterConfigNode(IFMapNode *node) {
544 0 : bgp_router_config_list_->Add(agent_, this, node);
545 0 : }
546 :
547 0 : void ConfigManager::AddVirtualRouterNode(IFMapNode *node) {
548 0 : virtual_router_list_->Add(agent_, this, node);
549 0 : }
550 :
551 0 : string ConfigManager::ProfileInfo() const {
552 : using std::setw;
553 : using std::endl;
554 :
555 0 : std::stringstream str;
556 : str << setw(16) << "CfgMgr"
557 0 : << " Queue" << setw(8) << Size()
558 0 : << " Timeout " << setw(8) << timeout()
559 0 : << " Process" << setw(8) << ProcessCount() << endl;
560 : str << setw(22)
561 0 : << " VMI-Q " << setw(8) << vmi_list_->Size()
562 0 : << " Enqueue " << setw(8) << vmi_list_->enqueue_count()
563 0 : << " Process" << setw(8) << vmi_list_->process_count() << endl;
564 : str << setw(22)
565 0 : << " LI-Q " << setw(8) << logical_interface_list_->Size()
566 0 : << " Enqueue " << setw(8) << logical_interface_list_->enqueue_count()
567 0 : << " Process" << setw(8) << logical_interface_list_->process_count() << endl;
568 0 : return str.str();
569 0 : }
570 :
571 : // When traversing graph, check if an IFMapNode can be used. Conditions are,
572 : // - The node is not in deleted state
573 : // - The node was notified earlier
574 687 : bool ConfigManager::CanUseNode(IFMapNode *node) {
575 687 : if (node->IsDeleted()) {
576 0 : return false;
577 : }
578 :
579 : IFMapDependencyManager *dep =
580 687 : agent()->oper_db()->dependency_manager();
581 :
582 : // Table not managed by dependency manager. Node can be used
583 687 : if (dep->IsRegistered(node) == false)
584 181 : return true;
585 :
586 506 : IFMapNodeState *state = dep->IFMapNodeGet(node);
587 506 : if (state == NULL) {
588 : // State not set. Means, IFMapDependency manager manages the node
589 : // and has not seen the node yet. Node cannot be used.
590 11 : return false;
591 : }
592 :
593 990 : if (state->notify() == false ||
594 495 : state->oper_db_request_enqueued() == false) {
595 0 : return false;
596 : }
597 :
598 495 : return true;
599 : }
600 :
601 : // When traversing graph, check if an IFMapNode can be used. Conditions are,
602 : // - The node is not in deleted state
603 : // - The node was notified earlier
604 : // - The node is an entry in IFMapAgentTable specified
605 626 : bool ConfigManager::CanUseNode(IFMapNode *node, IFMapAgentTable *table) {
606 626 : if (table != static_cast<IFMapAgentTable *>(node->table())) {
607 572 : return false;
608 : }
609 :
610 54 : return CanUseNode(node);
611 : }
612 :
613 633 : bool ConfigManager::SkipNode(IFMapNode *node) {
614 633 : return !CanUseNode(node);
615 : }
616 :
617 388 : bool ConfigManager::SkipNode(IFMapNode *node, IFMapAgentTable *table) {
618 388 : return !CanUseNode(node, table);
619 : }
620 :
621 :
622 113 : IFMapNode *ConfigManager::FindAdjacentIFMapNode(IFMapNode *node,
623 : const char *type) {
624 113 : IFMapAgentTable *table = static_cast<IFMapAgentTable *>(node->table());
625 113 : DBGraph *graph = table->GetGraph();
626 113 : assert(node->IsVertexValid());
627 113 : for (DBGraphVertex::adjacency_iterator iter = node->begin(graph);
628 362 : iter != node->end(graph); ++iter) {
629 278 : IFMapNode *adj_node = static_cast<IFMapNode *>(iter.operator->());
630 278 : if (SkipNode(adj_node)) {
631 0 : continue;
632 : }
633 278 : if (strcmp(adj_node->table()->Typename(), type) == 0) {
634 29 : return adj_node;
635 : }
636 : }
637 :
638 84 : return NULL;
639 : }
640 :
641 0 : void ConfigManager::NodeResync(IFMapNode *node) {
642 0 : IFMapDependencyManager *dep = agent_->oper_db()->dependency_manager();
643 0 : dep->PropogateNodeAndLinkChange(node);
644 0 : }
|