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>
64 : code(code),
subcode(0), flags(flags) { }
66 : code(code), subcode(subcode), flags(flags) { }
81 virtual std::string
ToString()
const;
102 uint32_t
ReadLabel(
size_t label_offset,
bool is_vni =
false)
const;
103 void WriteLabel(
size_t label_offset, uint32_t label,
bool is_vni =
false);
120 template <
class Type,
class TypePtr,
class TypeSpec,
typename TypeCompare,
127 mutex_(new tbb::mutex[hash_size]) {
134 tbb::mutex::scoped_lock lock(
mutex_[i]);
135 size +=
set_[i].size();
143 tbb::mutex::scoped_lock lock(
mutex_[hash]);
144 assert(
set_[hash].erase(attr));
154 Type *attr =
new Type(static_cast<TypeDB *>(
this), spec);
163 boost::hash_combine(hash, *attr);
168 char *str = getenv(
"BGP_PATH_ATTRIBUTE_DB_HASH_SIZE");
172 return strtoul(str, NULL, 0);
185 tbb::mutex::scoped_lock lock(
mutex_[hash]);
186 std::pair<typename Set::iterator, bool> ret;
189 ret =
set_[hash].insert(attr);
199 TypePtr ptr = TypePtr(*ret.first);
220 TypePtr ptr = TypePtr(*ret.first);
238 typedef std::set<Type *, TypeCompare>
Set;
244 #endif // SRC_BGP_BGP_ATTR_BASE_H_
virtual std::string ToString() const
int intrusive_ptr_add_ref(const AsPath *cpath)
BgpAttribute(uint8_t code, uint8_t flags)
BgpPathAttributeDB(int hash_size=GetHashSize())
TypePtr Locate(Type *attr)
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
boost::scoped_array< tbb::mutex > mutex_
uint8_t GetEncodeFlags() const
TypePtr LocateInternal(Type *attr)
virtual size_t EncodeLength() const
BgpAttribute(uint8_t code, uint8_t subcode, uint8_t flags)
virtual int CompareTo(const BgpAttribute &rhs) const
static const size_t kLabelSize
std::vector< uint8_t > prefix
virtual void ToCanonical(BgpAttr *attr)
const size_t HashCompute(Type *attr) const
int intrusive_ptr_del_ref(const AsPath *cpath)
boost::scoped_array< Set > set_
static const uint8_t FLAG_MASK
static size_t GetHashSize()
TypePtr Locate(const TypeSpec &spec)
std::set< ClusterList *, ClusterListCompare > Set