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