6 #ifndef SRC_BGP_BGP_ATTR_BASE_H_
7 #define SRC_BGP_BGP_ATTR_BASE_H_
9 #include <boost/functional/hash.hpp>
10 #include <boost/scoped_array.hpp>
83 virtual std::string
ToString()
const;
104 uint32_t
ReadLabel(
size_t label_offset,
bool is_vni =
false)
const;
105 void WriteLabel(
size_t label_offset, uint32_t label,
bool is_vni =
false);
122 template <
class Type,
class TypePtr,
class TypeSpec,
typename TypeCompare,
136 std::scoped_lock lock(
mutex_[i]);
137 size +=
set_[i].size();
145 std::scoped_lock lock(
mutex_[hash]);
146 assert(
set_[hash].erase(attr));
156 Type *attr =
new Type(
static_cast<TypeDB *
>(
this), spec);
165 boost::hash_combine(hash, *attr);
170 char *str = getenv(
"BGP_PATH_ATTRIBUTE_DB_HASH_SIZE");
174 return strtoul(str, NULL, 0);
187 std::scoped_lock lock(
mutex_[hash]);
188 std::pair<typename Set::iterator, bool> ret;
191 ret =
set_[hash].insert(attr);
201 TypePtr ptr = TypePtr(*ret.first);
222 TypePtr ptr = TypePtr(*ret.first);
240 typedef std::set<Type *, TypeCompare>
Set;
int intrusive_ptr_del_ref(const AsPath *cpath)
int intrusive_ptr_add_ref(const AsPath *cpath)
virtual void ToCanonical(BgpAttr *attr)
BgpAttribute(uint8_t code, uint8_t subcode, uint8_t flags)
virtual int CompareTo(const BgpAttribute &rhs) const
uint8_t GetEncodeFlags() const
static const uint8_t FLAG_MASK
BgpAttribute(uint8_t code, uint8_t flags)
virtual size_t EncodeLength() const
virtual std::string ToString() const
boost::scoped_array< std::mutex > mutex_
std::set< Type *, TypeCompare > Set
TypePtr Locate(Type *attr)
boost::scoped_array< Set > set_
static size_t GetHashSize()
TypePtr LocateInternal(Type *attr)
TypePtr Locate(const TypeSpec &spec)
BgpPathAttributeDB(int hash_size=GetHashSize())
const size_t HashCompute(Type *attr) const
void WriteLabel(size_t label_offset, uint32_t label, bool is_vni=false)
uint32_t ReadLabel(size_t label_offset, bool is_vni=false) const
static const size_t kLabelSize
std::vector< uint8_t > prefix