OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ifmap_object.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef ctrlplane_ifmap_entry_h
6 #define ctrlplane_ifmap_entry_h
7 
8 #include <boost/crc.hpp>
9 #include <boost/intrusive_ptr.hpp>
10 #include <boost/intrusive/list.hpp>
11 #include <boost/dynamic_bitset.hpp>
12 
13 #include "base/util.h"
14 #include "ifmap/ifmap_origin.h"
15 
16 namespace pugi {
17 class xml_node;
18 }
19 
20 struct AutogenProperty;
21 class IFMapTable;
22 
23 class IFMapObject {
24 public:
25  IFMapObject();
26  virtual ~IFMapObject();
27  virtual std::string ToString() const = 0;
28 
29  virtual void EncodeUpdate(pugi::xml_node *parent) const = 0;
30 
32 
33  uint64_t sequence_number() { return sequence_number_; }
34  const uint64_t sequence_number() const { return sequence_number_; }
37  }
38  IFMapOrigin origin() const { return origin_; }
39  virtual bool ResolveStaleness() = 0; // return true if something was stale
40  virtual boost::crc_32_type::value_type CalculateCrc() const = 0;
41 
42 private:
43  friend class IFMapNode;
44  friend void intrusive_ptr_add_ref(IFMapObject *object);
45  friend void intrusive_ptr_release(IFMapObject *object);
46  friend void intrusive_ptr_add_ref(const IFMapObject *object);
47  friend void intrusive_ptr_release(const IFMapObject *object);
48 
49  static void Release(IFMapObject *object);
50 
51  boost::intrusive::list_member_hook<> node_;
52  mutable int refcount_;
53  uint64_t sequence_number_;
56 };
57 
58 typedef boost::intrusive_ptr<IFMapObject> IFMapObjectRef;
59 inline void intrusive_ptr_add_ref(IFMapObject *object) {
60  if (object == NULL) {
61  return;
62  }
63  object->refcount_++;
64 }
65 inline void intrusive_ptr_release(IFMapObject *object) {
66  if (object == NULL) {
67  return;
68  }
69  if (--object->refcount_ == 0) {
70  IFMapObject::Release(object);
71  }
72 }
73 inline void intrusive_ptr_add_ref(const IFMapObject *object) {
74  object->refcount_++;
75 }
76 inline void intrusive_ptr_release(const IFMapObject *object) {
77  if (--object->refcount_ == 0) {
78  IFMapObject::Release(const_cast<IFMapObject *>(object));
79  }
80 }
81 
82 // Base class for entries that correspond to IF-MAP identifiers
83 class IFMapIdentifier : public IFMapObject {
84 public:
86  explicit IFMapIdentifier(int property_count);
87 
88  virtual bool SetProperty(const std::string &attr_key,
89  AutogenProperty *data) = 0;
90  virtual void ClearProperty(const std::string &attr_key) = 0;
91 
92  // Return true if any properties are set.
93  virtual bool empty() const {
94  return true;
95  }
96 
99  bool IsPropertySet(int id) const {return property_set_.test(id);};
100  virtual bool ResolveStaleness();
101 
102 protected:
103  boost::dynamic_bitset<> property_set_;
104  boost::dynamic_bitset<> old_property_set_;
105 
106 private:
108 };
109 
110 // Base class for entries that correspond to meta-data with attributes
111 class IFMapLinkAttr : public IFMapObject {
112 public:
113  IFMapLinkAttr();
114  virtual bool SetData(const AutogenProperty *data) = 0;
115  virtual bool ResolveStaleness();
116 
117 private:
119 };
120 
121 #endif
int intrusive_ptr_add_ref(const AsPath *cpath)
Definition: bgp_aspath.h:147
void set_origin(IFMapOrigin origin)
Definition: ifmap_object.h:31
boost::dynamic_bitset old_property_set_
Definition: ifmap_object.h:104
DISALLOW_COPY_AND_ASSIGN(IFMapObject)
DISALLOW_COPY_AND_ASSIGN(IFMapLinkAttr)
bool IsPropertySet(int id) const
Definition: ifmap_object.h:99
virtual bool empty() const
Definition: ifmap_object.h:93
IFMapOrigin origin() const
Definition: ifmap_object.h:38
virtual ~IFMapObject()
Definition: ifmap_object.cc:11
friend void intrusive_ptr_release(IFMapObject *object)
Definition: ifmap_object.h:65
boost::intrusive_ptr< IFMapObject > IFMapObjectRef
Definition: ifmap_object.h:58
virtual bool ResolveStaleness()
Definition: ifmap_object.cc:46
boost::intrusive::list_member_hook node_
Definition: ifmap_object.h:51
uint64_t sequence_number()
Definition: ifmap_object.h:33
friend void intrusive_ptr_add_ref(IFMapObject *object)
Definition: ifmap_object.h:59
virtual bool SetData(const AutogenProperty *data)=0
virtual bool ResolveStaleness()
Definition: ifmap_object.cc:38
void set_sequence_number(uint64_t sequence_number)
Definition: ifmap_object.h:35
const uint64_t sequence_number() const
Definition: ifmap_object.h:34
DISALLOW_COPY_AND_ASSIGN(IFMapIdentifier)
IFMapOrigin origin_
Definition: ifmap_object.h:54
bool ResolveStalePropertiesAndResetOld()
Definition: ifmap_object.cc:32
virtual boost::crc_32_type::value_type CalculateCrc() const =0
virtual bool SetProperty(const std::string &attr_key, AutogenProperty *data)=0
void intrusive_ptr_release(const AsPath *cpath)
Definition: bgp_aspath.h:155
static void Release(IFMapObject *object)
Definition: ifmap_object.cc:14
void TransferPropertyToOldProperty()
Definition: ifmap_object.cc:27
virtual std::string ToString() const =0
virtual void EncodeUpdate(pugi::xml_node *parent) const =0
boost::dynamic_bitset property_set_
Definition: ifmap_object.h:103
virtual bool ResolveStaleness()=0
uint64_t sequence_number_
Definition: ifmap_object.h:53
virtual void ClearProperty(const std::string &attr_key)=0