14 using boost::system::errc::invalid_argument;
15 using boost::system::error_code;
29 kRdSize + 2 * (1 + kIp4AddrSize) + kIp4AddrSize;
31 kRdSize + 2 * (1 + kIp4AddrSize);
33 kRdSize + kAsnSize + 2 * (1 + kIp4AddrSize);
41 : type_(type), rd_(rd), ip_prefixlen_(0), asn_(asn) {
47 : type_(type), originator_(originator), ip_prefixlen_(0), asn_(0) {
54 : type_(type), rd_(rd), originator_(originator), ip_prefixlen_(0),
62 : type_(type), rd_(rd), group_(group), source_(source),
63 ip_prefixlen_(0), asn_(0) {
71 : type_(type), rd_(rd), originator_(originator),
72 group_(group), source_(source), ip_prefixlen_(0), asn_(0) {
79 : type_(type), rd_(rd), group_(group), source_(source), ip_prefixlen_(0),
94 size_t source_offset = rd_offset +
kRdSize;
104 &proto_prefix.
prefix[group_offset], kIp4AddrSize));
107 &proto_prefix.
prefix[originator_offset], kIp4AddrSize));
113 size_t nlri_size = proto_prefix.
prefix.size();
116 switch (prefix->
type_) {
119 if (nlri_size != expected_nlri_size)
121 size_t rd_offset = 0;
123 size_t originator_offset = rd_offset +
kRdSize;
130 if (nlri_size != expected_nlri_size)
132 size_t rd_offset = 0;
134 size_t asn_offset = rd_offset +
kRdSize;
140 if (nlri_size != expected_nlri_size)
147 size_t expected_nlri_size;
157 if (nlri_size != expected_nlri_size)
170 prefix->
rt_key_.resize(originator_offset);
171 copy(proto_prefix.
prefix.begin(), proto_prefix.
prefix.begin() +
172 originator_offset, prefix->
rt_key_.begin());
174 &proto_prefix.
prefix[originator_offset], kIp4AddrSize));
179 if (nlri_size != expected_nlri_size)
181 size_t rd_offset = 0;
183 size_t source_offset = rd_offset +
kRdSize;
193 &proto_prefix.
prefix[group_offset], kIp4AddrSize));
199 if (nlri_size != expected_nlri_size)
201 size_t rd_offset = 0;
203 size_t asn_offset = rd_offset +
kRdSize;
206 size_t source_offset = asn_offset +
kAsnSize;
216 &proto_prefix.
prefix[group_offset], kIp4AddrSize));
237 uint32_t *l3_label) {
243 proto_prefix->
prefix.clear();
249 proto_prefix->
prefix.resize(nlri_size, 0);
251 size_t rd_offset = 0;
253 proto_prefix->
prefix.begin() + rd_offset);
254 size_t originator_offset = rd_offset +
kRdSize;
255 const Ip4Address::bytes_type &source_bytes =
originator_.to_bytes();
256 copy(source_bytes.begin(), source_bytes.begin() +
kIp4AddrSize,
257 proto_prefix->
prefix.begin() + originator_offset);
263 proto_prefix->
prefix.resize(nlri_size, 0);
265 size_t rd_offset = 0;
267 proto_prefix->
prefix.begin() + rd_offset);
268 size_t asn_offset = rd_offset +
kRdSize;
275 proto_prefix->
prefix.resize(nlri_size, 0);
277 size_t rd_offset = 0;
279 proto_prefix->
prefix.begin() + rd_offset);
280 size_t source_offset = rd_offset +
kRdSize;
282 const Ip4Address::bytes_type &source_bytes =
source_.to_bytes();
283 copy(source_bytes.begin(), source_bytes.begin() +
kIp4AddrSize,
284 proto_prefix->
prefix.begin() + source_offset);
288 const Ip4Address::bytes_type &group_bytes =
group_.to_bytes();
289 copy(group_bytes.begin(), group_bytes.begin() +
kIp4AddrSize,
290 proto_prefix->
prefix.begin() + group_offset);
293 const Ip4Address::bytes_type &originator_bytes =
originator_.to_bytes();
294 copy(originator_bytes.begin(), originator_bytes.begin() +
300 size_t keySize =
rt_key_.size();
303 proto_prefix->
prefix.resize(nlri_size, 0);
306 proto_prefix->
prefix.begin());
308 const Ip4Address::bytes_type &originator_bytes =
originator_.to_bytes();
309 copy(originator_bytes.begin(), originator_bytes.begin() +
316 proto_prefix->
prefix.resize(nlri_size, 0);
318 size_t rd_offset = 0;
320 proto_prefix->
prefix.begin() + rd_offset);
321 size_t source_offset = rd_offset +
kRdSize;
323 const Ip4Address::bytes_type &source_bytes =
source_.to_bytes();
324 copy(source_bytes.begin(), source_bytes.begin() +
kIp4AddrSize,
325 proto_prefix->
prefix.begin() + source_offset);
329 const Ip4Address::bytes_type &group_bytes =
group_.to_bytes();
330 copy(group_bytes.begin(), group_bytes.begin() +
kIp4AddrSize,
331 proto_prefix->
prefix.begin() + group_offset);
338 proto_prefix->
prefix.resize(nlri_size, 0);
340 size_t rd_offset = 0;
342 proto_prefix->
prefix.begin() + rd_offset);
343 size_t asn_offset = rd_offset +
kRdSize;
345 size_t source_offset = asn_offset +
kAsnSize;
347 const Ip4Address::bytes_type &source_bytes =
source_.to_bytes();
348 copy(source_bytes.begin(), source_bytes.begin() +
kIp4AddrSize,
349 proto_prefix->
prefix.begin() + source_offset);
353 const Ip4Address::bytes_type &group_bytes =
group_.to_bytes();
354 copy(group_bytes.begin(), group_bytes.begin() +
kIp4AddrSize,
355 proto_prefix->
prefix.begin() + group_offset);
366 error_code *errorp,
size_t *pos1) {
367 *pos1 = str.find(
'-');
368 if (*pos1 == string::npos) {
369 if (errorp != NULL) {
370 *errorp = make_error_code(invalid_argument);
374 string temp_str = str.substr(0, *pos1);
377 if (errorp != NULL) {
378 *errorp = make_error_code(invalid_argument);
386 size_t pos1,
size_t *pos2, error_code *errorp) {
387 *pos2 = str.find(
',', pos1 + 1);
388 if (*pos2 == string::npos) {
389 if (errorp != NULL) {
390 *errorp = make_error_code(invalid_argument);
394 string temp_str = str.substr(pos1 + 1, *pos2 - pos1 - 1);
397 if (rd_err.failed()) {
398 if (errorp != NULL) {
407 const string &str,
size_t pos1, error_code *errorp) {
408 string temp_str = str.substr(pos1 + 1, string::npos);
409 error_code originator_err;
410 prefix->
originator_ = Ip4Address::from_string(temp_str, originator_err);
411 if (originator_err.failed()) {
412 if (errorp != NULL) {
413 *errorp = originator_err;
421 size_t pos1,
size_t *pos2, error_code *errorp) {
422 *pos2 = str.find(
',', pos1 + 1);
423 if (*pos2 == string::npos) {
424 if (errorp != NULL) {
425 *errorp = make_error_code(invalid_argument);
429 string temp_str = str.substr(pos1 + 1, *pos2 - pos1 - 1);
430 error_code source_err;
431 prefix->
source_ = Ip4Address::from_string(temp_str, source_err);
432 if (source_err.failed()) {
433 if (errorp != NULL) {
434 *errorp = source_err;
442 size_t pos1,
size_t *pos2, error_code *errorp,
444 *pos2 = str.find(
',', pos1 + 1);
445 if (!last && *pos2 == string::npos) {
446 if (errorp != NULL) {
447 *errorp = make_error_code(invalid_argument);
453 temp_str = str.substr(pos1 + 1, string::npos);
455 temp_str = str.substr(pos1 + 1, *pos2 - pos1 - 1);
456 error_code group_err;
457 prefix->
group_ = Ip4Address::from_string(temp_str, group_err);
458 if (group_err.failed()) {
459 if (errorp != NULL) {
468 size_t pos1,
size_t *pos2, error_code *errorp) {
469 *pos2 = str.find(
',', pos1 + 1);
470 if (*pos2 == string::npos) {
471 if (errorp != NULL) {
472 *errorp = make_error_code(invalid_argument);
476 string temp_str = str.substr(pos1 + 1, *pos2 - pos1 - 1);
492 switch (prefix.
type_) {
509 temp_str = str.substr(pos2 + 1, string::npos);
537 size_t pos_last = str.find_last_of(
',');
538 if (pos_last == string::npos) {
539 if (errorp != NULL) {
540 *errorp = make_error_code(invalid_argument);
546 temp_str = str.substr(pos1 + 1, string::npos);
551 uint8_t src_rt_type = prefix.
type_;
556 prefix.
rt_key_.resize(key_size);
561 prefix.
rt_key_.resize(key_size);
565 size_t key_offset = 2;
568 pos2 = pos1 + 1 + pos2;
572 prefix.
rt_key_.begin() + key_offset);
580 size_t asn_size =
sizeof(prefix.
asn_);
586 const Ip4Address::bytes_type &source_bytes = prefix.
source_.to_bytes();
588 copy(source_bytes.begin(), source_bytes.begin() +
596 const Ip4Address::bytes_type &group_bytes = prefix.
group_.to_bytes();
598 copy(group_bytes.begin(), group_bytes.begin() +
603 size_t pos6 = str.find(
',', pos5 + 1);
604 if (pos6 == string::npos) {
605 if (errorp != NULL) {
606 *errorp = make_error_code(invalid_argument);
610 temp_str = str.substr(pos5 + 1, pos6 - pos5 - 1);
611 error_code originator_err;
612 Ip4Address ip = Ip4Address::from_string(temp_str, originator_err);
613 if (originator_err.failed()) {
614 if (errorp != NULL) {
615 *errorp = originator_err;
619 const Ip4Address::bytes_type &originator_bytes = ip.to_bytes();
620 copy(originator_bytes.begin(), originator_bytes.begin() +
679 repr +=
"," +
source_.to_string();
680 repr +=
"," +
group_.to_string();
693 repr +=
"," + ip.to_string();
697 repr +=
"," + ip.to_string();
699 repr +=
"," + ip.to_string();
712 repr +=
"," +
source_.to_string();
713 repr +=
"," +
group_.to_string();
719 repr +=
"," +
source_.to_string();
720 repr +=
"," +
group_.to_string();
772 size_t key_offset = 0;
774 rt_key_[key_offset++] = (uint8_t)kSPMSIADRouteSize;
778 size_t source_offset = key_offset+
kRdSize;
782 const Ip4Address::bytes_type &source_bytes = prefix.
source().to_bytes();
783 copy(source_bytes.begin(), source_bytes.begin() +
kIp4AddrSize,
784 rt_key_.begin() + source_offset);
788 const Ip4Address::bytes_type &group_bytes = prefix.
group().to_bytes();
789 copy(group_bytes.begin(), group_bytes.begin() +
793 const Ip4Address::bytes_type &originator_bytes =
795 copy(originator_bytes.begin(), originator_bytes.begin() +
811 repr +=
":" +
group_.to_string();
812 repr +=
"," +
source_.to_string();
869 const BgpAttr *attr, uint32_t label, uint32_t l3_label)
const {
874 vector<uint8_t> &nh,
IpAddress nexthop)
const {
876 const Ip4Address::bytes_type &addr_bytes = nexthop.to_v4().to_bytes();
877 copy(addr_bytes.begin(), addr_bytes.end(), nh.begin());
889 return "Unspecified";
891 return "IntraASPMSIADRoute";
893 return "InterASPMSIADRoute";
895 return "SPMSIADRoute";
897 return "LeafADRoute";
899 return "SourceActiveADRoute";
901 return "SharedTreeJoinRoute";
903 return "SourceTreeJoinRoute";
virtual std::string ToString() const
static bool GetSourceFromString(MvpnPrefix *prefix, const std::string &str, size_t pos1, size_t *pos2, boost::system::error_code *ec)
static const size_t kInterASPMSIADRouteSize
int CompareTo(const MvpnPrefix &rhs) const
static int FromProtoPrefix(const BgpProtoPrefix &proto_prefix, MvpnPrefix *prefix)
virtual bool IsValid() const
static const size_t kSPMSIADRouteSize
static const size_t kPrefixBytes
#define KEY_COMPARE(x, y)
boost::asio::ip::address IpAddress
bool stringToInteger(const std::string &str, NumberType &num)
static const size_t kAsnSize
static RouteDistinguisher FromString(const std::string &str, boost::system::error_code *error=NULL)
virtual void BuildProtoPrefix(BgpProtoPrefix *prefix, const BgpAttr *attr=NULL, uint32_t label=0, uint32_t l3_label=0) const
void SetLeafADPrefixFromSPMSIPrefix(const MvpnPrefix &prefix)
void set_originator(const Ip4Address &originator)
static const uint8_t kMaxV4PrefixLen
static bool GetOriginatorFromString(MvpnPrefix *prefix, const std::string &str, size_t pos1, boost::system::error_code *errorp)
static bool GetAsnFromString(MvpnPrefix *prefix, const std::string &str, size_t pos1, size_t *pos2, boost::system::error_code *ec)
static int SpmsiAdRouteFromProtoPrefix(const BgpProtoPrefix &proto_prefix, MvpnPrefix *prefix, size_t rd_offset)
static const size_t kIp4AddrBitSize
std::unique_ptr< DBRequestKey > KeyPtr
static uint64_t get_value(const uint8_t *data, int size)
std::string ToXmppIdString() const
const std::string GetType() const
static const size_t kSize
virtual std::string ToXmppIdString() const
boost::intrusive_ptr< const BgpAttr > BgpAttrPtr
static const std::string integerToString(const NumberType &num)
static const uint8_t kMaxV4Bytes
std::vector< uint8_t > prefix
virtual KeyPtr GetDBRequestKey() const
bool operator==(const MvpnPrefix &rhs) const
static const size_t kIp4AddrSize
boost::asio::ip::address_v4 Ip4Address
const std::string GetType() const
virtual int CompareTo(const Route &rhs) const
void SetSPMSIPrefixFromLeafADPrefix(const MvpnPrefix &prefix)
std::vector< uint8_t > rt_key_
static const size_t kSourceActiveADRouteSize
static const size_t kSourceTreeJoinRouteSize
std::string ToString() const
static bool IsValid(uint8_t type)
virtual void BuildBgpProtoNextHop(std::vector< uint8_t > &nh, IpAddress nexthop) const
static bool GetGroupFromString(MvpnPrefix *prefix, const std::string &str, size_t pos1, size_t *pos2, boost::system::error_code *ec, bool last=false)
static bool GetTypeFromString(MvpnPrefix *prefix, const std::string &str, boost::system::error_code *errorp, size_t *pos1)
const uint8_t * GetData() const
MvpnRoute(const MvpnPrefix &prefix)
static MvpnPrefix FromString(const std::string &str, boost::system::error_code *errorp=NULL)
Ip4Address source() const
const MvpnPrefix & GetPrefix() const
const RouteDistinguisher & route_distinguisher() const
static const size_t kRdSize
Ip4Address originator() const
virtual void SetKey(const DBRequestKey *reqkey)
static const size_t kIntraASPMSIADRouteSize
void BuildProtoPrefix(BgpProtoPrefix *prefix) const
Ip4Address GetType3OriginatorFromType4Route() const
std::string ToString() const
virtual bool IsValid() const
static bool GetRDFromString(MvpnPrefix *prefix, const std::string &str, size_t pos1, size_t *pos2, boost::system::error_code *ec)
static void put_value(uint8_t *data, int size, uint64_t value)