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