OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ifmap_node.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include "ifmap_node.h"
6 
7 #include <iostream>
8 
9 #include <pugixml/pugixml.hpp>
10 
11 #include "ifmap/ifmap_table.h"
12 
13 using namespace std;
14 using pugi::xml_node;
15 
16 
18  : table_(table) {
19 }
20 
22  void operator()(IFMapObject *obj) const {
24  }
25 };
26 
28  list_.clear_and_dispose(IFMapObjectDeleter());
29 }
30 
31 string IFMapNode::ToString() const {
32  string repr(table_->Typename());
33  repr += ":";
34  repr += name_;
35  return repr;
36 }
37 
39  for (ObjectList::iterator iter = list_.begin(); iter != list_.end();
40  ++iter) {
41  IFMapObject *object = iter.operator->();
42  if (object->origin() == origin) {
43  return object;
44  }
45  }
46  return NULL;
47 }
48 
51  if (obj->origin().IsOriginXmpp()) {
52  list_.push_back(*obj);
53  } else {
54  list_.push_front(*obj);
55  }
56 }
57 
59  list_.erase(list_.iterator_to(*obj));
61 }
62 
64  if (list_.empty()) {
65  return NULL;
66  }
67  return &list_.front();
68 }
69 
71  if (list_.empty()) {
72  return NULL;
73  }
74  return &list_.front();
75 }
76 
78  IFMapNode::crc32type crc = 0;
80  if (object) {
81  crc = object->CalculateCrc();
82  if (crc == 0) {
83  crc = 0xffffffff;
84  }
85  }
86 
87  return crc;
88 }
89 
91  cout << name_ << ": " << list_.size() << " objects" << endl;
92  for (ObjectList::iterator iter = list_.begin(); iter != list_.end();
93  ++iter) {
94  IFMapObject *object = iter.operator->();
95  cout << "\t" << object->origin().ToString() << endl;
96  }
97 }
98 
99 void IFMapNode::EncodeNodeDetail(pugi::xml_node *parent) const {
100  xml_node node = parent->append_child("node");
101  node.append_attribute("type") = table_->Typename();
102  node.append_child("name").text().set(name_.c_str());
103  const IFMapObject *object = GetObject();
104  if (object != NULL) {
105  object->EncodeUpdate(&node);
106  }
107 }
108 
109 void IFMapNode::EncodeNode(xml_node *parent) const {
110  xml_node node = parent->append_child("node");
111  node.append_attribute("type") = table_->Typename();
112  node.append_child("name").text().set(name_.c_str());
113 }
114 
115 void IFMapNode::EncodeNode(const Descriptor &descriptor, xml_node *parent) {
116  xml_node node = parent->append_child("node");
117  node.append_attribute("type") = descriptor.first.c_str();
118  node.append_child("name").text().set(descriptor.second.c_str());
119 }
120 
123  keyptr->id_name = name_;
124  return KeyPtr(keyptr);
125 }
126 
127 void IFMapNode::SetKey(const DBRequestKey *genkey) {
128  const IFMapTable::RequestKey *keyptr =
129  static_cast<const IFMapTable::RequestKey *>(genkey);
130  name_ = keyptr->id_name;
131 }
132 
134  DB *db, const IFMapNode::Descriptor &descriptor) {
135  if (db == NULL) {
136  return NULL;
137  }
138  IFMapTable *table = IFMapTable::FindTable(db, descriptor.first);
139  if (table == NULL) {
140  return NULL;
141  }
142  return table->FindNode(descriptor.second);
143 }
int intrusive_ptr_add_ref(const AsPath *cpath)
Definition: bgp_aspath.h:147
ObjectList list_
Definition: ifmap_node.h:64
void EncodeNode(pugi::xml_node *parent) const
IFMapTable * table_
Definition: ifmap_node.h:62
virtual std::string ToString() const
Definition: ifmap_node.cc:31
void Remove(IFMapObject *obj)
Definition: ifmap_node.cc:58
IFMapOrigin origin() const
Definition: ifmap_object.h:38
virtual const char * Typename() const =0
IFMapTable * table()
Definition: ifmap_node.h:29
std::unique_ptr< DBRequestKey > KeyPtr
Definition: db_entry.h:25
void EncodeNodeDetail(pugi::xml_node *parent) const
Definition: ifmap_node.cc:99
static IFMapNode * DescriptorLookup(DB *db, const Descriptor &descriptor)
Definition: ifmap_node.cc:133
Definition: db.h:24
void operator()(IFMapObject *obj) const
Definition: ifmap_node.cc:22
crc32type GetConfigCrc()
Definition: ifmap_node.cc:77
IFMapNode * FindNode(const std::string &name)
Definition: ifmap_table.cc:23
std::string name_
Definition: ifmap_node.h:63
boost::crc_32_type::value_type crc32type
Definition: ifmap_node.h:16
void Insert(IFMapObject *obj)
Definition: ifmap_node.cc:49
IFMapObject * Find(IFMapOrigin origin)
Definition: ifmap_node.cc:38
IFMapObject * GetObject()
Definition: ifmap_node.cc:63
void PrintAllObjects()
Definition: ifmap_node.cc:90
std::pair< std::string, std::string > Descriptor
Definition: ifmap_node.h:22
static IFMapTable * FindTable(DB *db, const std::string &element_type)
Definition: ifmap_table.cc:39
virtual KeyPtr GetDBRequestKey() const
Definition: ifmap_node.cc:121
void intrusive_ptr_release(const AsPath *cpath)
Definition: bgp_aspath.h:155
std::string ToString() const
Definition: ifmap_origin.h:22
virtual ~IFMapNode()
Definition: ifmap_node.cc:27
virtual void SetKey(const DBRequestKey *genkey)
Definition: ifmap_node.cc:127
IFMapNode(IFMapTable *table)
Definition: ifmap_node.cc:17
bool IsOriginXmpp() const
Definition: ifmap_origin.h:37