5 #ifndef SRC_BGP_BGP_ATTR_BASE_H_
6 #define SRC_BGP_BGP_ATTR_BASE_H_
8 #include <boost/functional/hash.hpp>
9 #include <boost/scoped_array.hpp>
10 #include <tbb/mutex.h>
82 virtual std::string
ToString()
const;
103 uint32_t
ReadLabel(
size_t label_offset,
bool is_vni =
false)
const;
104 void WriteLabel(
size_t label_offset, uint32_t label,
bool is_vni =
false);
121 template <
class Type,
class TypePtr,
class TypeSpec,
typename TypeCompare,
128 mutex_(new tbb::mutex[hash_size]) {
135 tbb::mutex::scoped_lock lock(
mutex_[i]);
136 size +=
set_[i].size();
144 tbb::mutex::scoped_lock lock(
mutex_[hash]);
145 assert(
set_[hash].erase(attr));
155 Type *attr =
new Type(
static_cast<TypeDB *
>(
this), spec);
164 boost::hash_combine(hash, *attr);
169 char *str = getenv(
"BGP_PATH_ATTRIBUTE_DB_HASH_SIZE");
173 return strtoul(str, NULL, 0);
186 tbb::mutex::scoped_lock lock(
mutex_[hash]);
187 std::pair<typename Set::iterator, bool> ret;
190 ret =
set_[hash].insert(attr);
200 TypePtr ptr = TypePtr(*ret.first);
221 TypePtr ptr = TypePtr(*ret.first);
239 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
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)
boost::scoped_array< tbb::mutex > mutex_
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