Line data Source code
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 : 31 99080 : void set_origin(IFMapOrigin origin) { origin_ = origin; } 32 : 33 49941 : uint64_t sequence_number() { return sequence_number_; } 34 0 : const uint64_t sequence_number() const { return sequence_number_; } 35 65969 : void set_sequence_number(uint64_t sequence_number) { 36 65969 : sequence_number_ = sequence_number; 37 65969 : } 38 173259 : 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_; 54 : IFMapOrigin origin_; 55 : DISALLOW_COPY_AND_ASSIGN(IFMapObject); 56 : }; 57 : 58 : typedef boost::intrusive_ptr<IFMapObject> IFMapObjectRef; 59 353679 : inline void intrusive_ptr_add_ref(IFMapObject *object) { 60 353679 : if (object == NULL) { 61 0 : return; 62 : } 63 353679 : object->refcount_++; 64 : } 65 353679 : inline void intrusive_ptr_release(IFMapObject *object) { 66 353679 : if (object == NULL) { 67 0 : return; 68 : } 69 353679 : if (--object->refcount_ == 0) { 70 129690 : IFMapObject::Release(object); 71 : } 72 : } 73 32032 : inline void intrusive_ptr_add_ref(const IFMapObject *object) { 74 32032 : object->refcount_++; 75 32032 : } 76 32032 : inline void intrusive_ptr_release(const IFMapObject *object) { 77 32032 : if (--object->refcount_ == 0) { 78 11622 : IFMapObject::Release(const_cast<IFMapObject *>(object)); 79 : } 80 32032 : } 81 : 82 : // Base class for entries that correspond to IF-MAP identifiers 83 : class IFMapIdentifier : public IFMapObject { 84 : public: 85 : IFMapIdentifier(); 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 0 : virtual bool empty() const { 94 0 : return true; 95 : } 96 : 97 : void TransferPropertyToOldProperty(); 98 : bool ResolveStalePropertiesAndResetOld(); 99 114 : 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: 107 : DISALLOW_COPY_AND_ASSIGN(IFMapIdentifier); 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: 118 : DISALLOW_COPY_AND_ASSIGN(IFMapLinkAttr); 119 : }; 120 : 121 : #endif