15 using boost::system::errc::invalid_argument;
16 using boost::system::error_code;
30 kRdSize + 2 * (1 + kIp4AddrSize) + kIp4AddrSize;
32 kRdSize + 2 * (1 + kIp4AddrSize);
34 kRdSize + kAsnSize + 2 * (1 + kIp4AddrSize);
42 : type_(
type), rd_(rd), ip_prefixlen_(0), asn_(asn) {
48 : type_(
type), originator_(originator), ip_prefixlen_(0), asn_(0) {
55 : type_(
type), rd_(rd), originator_(originator), ip_prefixlen_(0),
63 : type_(
type), rd_(rd), group_(group), source_(source),
64 ip_prefixlen_(0), asn_(0) {
72 : type_(
type), rd_(rd), originator_(originator),
73 group_(group), source_(source), ip_prefixlen_(0), asn_(0) {
80 : type_(
type), rd_(rd), group_(group), source_(source), ip_prefixlen_(0),
95 size_t source_offset = rd_offset +
kRdSize;
114 size_t nlri_size = proto_prefix.
prefix.size();
117 switch (prefix->
type_) {
120 if (nlri_size != expected_nlri_size)
122 size_t rd_offset = 0;
124 size_t originator_offset = rd_offset +
kRdSize;
131 if (nlri_size != expected_nlri_size)
133 size_t rd_offset = 0;
135 size_t asn_offset = rd_offset +
kRdSize;
141 if (nlri_size != expected_nlri_size)
148 size_t expected_nlri_size;
158 if (nlri_size != expected_nlri_size)
171 prefix->
rt_key_.resize(originator_offset);
172 copy(proto_prefix.
prefix.begin(), proto_prefix.
prefix.begin() +
173 originator_offset, prefix->
rt_key_.begin());
180 if (nlri_size != expected_nlri_size)
182 size_t rd_offset = 0;
184 size_t source_offset = rd_offset +
kRdSize;
200 if (nlri_size != expected_nlri_size)
202 size_t rd_offset = 0;
204 size_t asn_offset = rd_offset +
kRdSize;
207 size_t source_offset = asn_offset +
kAsnSize;
238 uint32_t *l3_label) {
244 proto_prefix->
prefix.clear();
250 proto_prefix->
prefix.resize(nlri_size, 0);
252 size_t rd_offset = 0;
254 proto_prefix->
prefix.begin() + rd_offset);
255 size_t originator_offset = rd_offset +
kRdSize;
256 const Ip4Address::bytes_type &source_bytes =
originator_.to_bytes();
257 copy(source_bytes.begin(), source_bytes.begin() +
kIp4AddrSize,
258 proto_prefix->
prefix.begin() + originator_offset);
264 proto_prefix->
prefix.resize(nlri_size, 0);
266 size_t rd_offset = 0;
268 proto_prefix->
prefix.begin() + rd_offset);
269 size_t asn_offset = rd_offset +
kRdSize;
276 proto_prefix->
prefix.resize(nlri_size, 0);
278 size_t rd_offset = 0;
280 proto_prefix->
prefix.begin() + rd_offset);
281 size_t source_offset = rd_offset +
kRdSize;
283 const Ip4Address::bytes_type &source_bytes =
source_.to_bytes();
284 copy(source_bytes.begin(), source_bytes.begin() +
kIp4AddrSize,
285 proto_prefix->
prefix.begin() + source_offset);
289 const Ip4Address::bytes_type &group_bytes =
group_.to_bytes();
290 copy(group_bytes.begin(), group_bytes.begin() +
kIp4AddrSize,
291 proto_prefix->
prefix.begin() + group_offset);
294 const Ip4Address::bytes_type &originator_bytes =
originator_.to_bytes();
295 copy(originator_bytes.begin(), originator_bytes.begin() +
301 size_t keySize =
rt_key_.size();
304 proto_prefix->
prefix.resize(nlri_size, 0);
307 proto_prefix->
prefix.begin());
309 const Ip4Address::bytes_type &originator_bytes =
originator_.to_bytes();
310 copy(originator_bytes.begin(), originator_bytes.begin() +
317 proto_prefix->
prefix.resize(nlri_size, 0);
319 size_t rd_offset = 0;
321 proto_prefix->
prefix.begin() + rd_offset);
322 size_t source_offset = rd_offset +
kRdSize;
324 const Ip4Address::bytes_type &source_bytes =
source_.to_bytes();
325 copy(source_bytes.begin(), source_bytes.begin() +
kIp4AddrSize,
326 proto_prefix->
prefix.begin() + source_offset);
330 const Ip4Address::bytes_type &group_bytes =
group_.to_bytes();
331 copy(group_bytes.begin(), group_bytes.begin() +
kIp4AddrSize,
332 proto_prefix->
prefix.begin() + group_offset);
339 proto_prefix->
prefix.resize(nlri_size, 0);
341 size_t rd_offset = 0;
343 proto_prefix->
prefix.begin() + rd_offset);
344 size_t asn_offset = rd_offset +
kRdSize;
346 size_t source_offset = asn_offset +
kAsnSize;
348 const Ip4Address::bytes_type &source_bytes =
source_.to_bytes();
349 copy(source_bytes.begin(), source_bytes.begin() +
kIp4AddrSize,
350 proto_prefix->
prefix.begin() + source_offset);
354 const Ip4Address::bytes_type &group_bytes =
group_.to_bytes();
355 copy(group_bytes.begin(), group_bytes.begin() +
kIp4AddrSize,
356 proto_prefix->
prefix.begin() + group_offset);
367 error_code *errorp,
size_t *pos1) {
368 *pos1 = str.find(
'-');
369 if (*pos1 == string::npos) {
370 if (errorp != NULL) {
371 *errorp = make_error_code(invalid_argument);
375 string temp_str = str.substr(0, *pos1);
378 if (errorp != NULL) {
379 *errorp = make_error_code(invalid_argument);
387 size_t pos1,
size_t *pos2, error_code *errorp) {
388 *pos2 = str.find(
',', pos1 + 1);
389 if (*pos2 == string::npos) {
390 if (errorp != NULL) {
391 *errorp = make_error_code(invalid_argument);
395 string temp_str = str.substr(pos1 + 1, *pos2 - pos1 - 1);
398 if (rd_err.failed()) {
399 if (errorp != NULL) {
408 const string &str,
size_t pos1, error_code *errorp) {
409 string temp_str = str.substr(pos1 + 1, string::npos);
410 error_code originator_err;
411 prefix->
originator_ = Ip4Address::from_string(temp_str, originator_err);
412 if (originator_err.failed()) {
413 if (errorp != NULL) {
414 *errorp = originator_err;
422 size_t pos1,
size_t *pos2, error_code *errorp) {
423 *pos2 = str.find(
',', pos1 + 1);
424 if (*pos2 == string::npos) {
425 if (errorp != NULL) {
426 *errorp = make_error_code(invalid_argument);
430 string temp_str = str.substr(pos1 + 1, *pos2 - pos1 - 1);
431 error_code source_err;
432 prefix->
source_ = Ip4Address::from_string(temp_str, source_err);
433 if (source_err.failed()) {
434 if (errorp != NULL) {
435 *errorp = source_err;
443 size_t pos1,
size_t *pos2, error_code *errorp,
445 *pos2 = str.find(
',', pos1 + 1);
446 if (!last && *pos2 == string::npos) {
447 if (errorp != NULL) {
448 *errorp = make_error_code(invalid_argument);
454 temp_str = str.substr(pos1 + 1, string::npos);
456 temp_str = str.substr(pos1 + 1, *pos2 - pos1 - 1);
457 error_code group_err;
458 prefix->
group_ = Ip4Address::from_string(temp_str, group_err);
459 if (group_err.failed()) {
460 if (errorp != NULL) {
469 size_t pos1,
size_t *pos2, error_code *errorp) {
470 *pos2 = str.find(
',', pos1 + 1);
471 if (*pos2 == string::npos) {
472 if (errorp != NULL) {
473 *errorp = make_error_code(invalid_argument);
477 string temp_str = str.substr(pos1 + 1, *pos2 - pos1 - 1);
493 switch (prefix.
type_) {
510 temp_str = str.substr(pos2 + 1, string::npos);
538 size_t pos_last = str.find_last_of(
',');
539 if (pos_last == string::npos) {
540 if (errorp != NULL) {
541 *errorp = make_error_code(invalid_argument);
547 temp_str = str.substr(pos1 + 1, string::npos);
552 uint8_t src_rt_type = prefix.
type_;
557 prefix.
rt_key_.resize(key_size);
562 prefix.
rt_key_.resize(key_size);
566 size_t key_offset = 2;
569 pos2 = pos1 + 1 + pos2;
573 prefix.
rt_key_.begin() + key_offset);
581 size_t asn_size =
sizeof(prefix.
asn_);
587 const Ip4Address::bytes_type &source_bytes = prefix.
source_.to_bytes();
589 copy(source_bytes.begin(), source_bytes.begin() +
597 const Ip4Address::bytes_type &group_bytes = prefix.
group_.to_bytes();
599 copy(group_bytes.begin(), group_bytes.begin() +
604 size_t pos6 = str.find(
',', pos5 + 1);
605 if (pos6 == string::npos) {
606 if (errorp != NULL) {
607 *errorp = make_error_code(invalid_argument);
611 temp_str = str.substr(pos5 + 1, pos6 - pos5 - 1);
612 error_code originator_err;
613 Ip4Address ip = Ip4Address::from_string(temp_str, originator_err);
614 if (originator_err.failed()) {
615 if (errorp != NULL) {
616 *errorp = originator_err;
620 const Ip4Address::bytes_type &originator_bytes = ip.to_bytes();
621 copy(originator_bytes.begin(), originator_bytes.begin() +
680 repr +=
"," +
source_.to_string();
681 repr +=
"," +
group_.to_string();
694 repr +=
"," + ip.to_string();
698 repr +=
"," + ip.to_string();
700 repr +=
"," + ip.to_string();
713 repr +=
"," +
source_.to_string();
714 repr +=
"," +
group_.to_string();
720 repr +=
"," +
source_.to_string();
721 repr +=
"," +
group_.to_string();
773 size_t key_offset = 0;
779 size_t source_offset = key_offset+
kRdSize;
783 const Ip4Address::bytes_type &source_bytes = prefix.
source().to_bytes();
784 copy(source_bytes.begin(), source_bytes.begin() +
kIp4AddrSize,
785 rt_key_.begin() + source_offset);
789 const Ip4Address::bytes_type &group_bytes = prefix.
group().to_bytes();
790 copy(group_bytes.begin(), group_bytes.begin() +
794 const Ip4Address::bytes_type &originator_bytes =
796 copy(originator_bytes.begin(), originator_bytes.begin() +
812 repr +=
":" +
group_.to_string();
813 repr +=
"," +
source_.to_string();
870 const BgpAttr *attr, uint32_t label, uint32_t l3_label)
const {
875 vector<uint8_t> &nh,
IpAddress nexthop)
const {
877 const Ip4Address::bytes_type &addr_bytes = nexthop.to_v4().to_bytes();
878 copy(addr_bytes.begin(), addr_bytes.end(), nh.begin());
890 return "Unspecified";
892 return "IntraASPMSIADRoute";
894 return "InterASPMSIADRoute";
896 return "SPMSIADRoute";
898 return "LeafADRoute";
900 return "SourceActiveADRoute";
902 return "SharedTreeJoinRoute";
904 return "SourceTreeJoinRoute";
boost::asio::ip::address IpAddress
boost::asio::ip::address_v4 Ip4Address
boost::intrusive_ptr< const BgpAttr > BgpAttrPtr
static const uint8_t kMaxV4PrefixLen
static const uint8_t kMaxV4Bytes
virtual bool IsValid() const
std::unique_ptr< DBRequestKey > KeyPtr
void SetLeafADPrefixFromSPMSIPrefix(const MvpnPrefix &prefix)
std::string ToString() const
void SetSPMSIPrefixFromLeafADPrefix(const MvpnPrefix &prefix)
static const size_t kIntraASPMSIADRouteSize
bool operator==(const MvpnPrefix &rhs) const
static bool GetAsnFromString(MvpnPrefix *prefix, const std::string &str, size_t pos1, size_t *pos2, boost::system::error_code *ec)
static const size_t kSourceActiveADRouteSize
static const size_t kPrefixBytes
static int SpmsiAdRouteFromProtoPrefix(const BgpProtoPrefix &proto_prefix, MvpnPrefix *prefix, size_t rd_offset)
const std::string GetType() const
static bool GetSourceFromString(MvpnPrefix *prefix, const std::string &str, size_t pos1, size_t *pos2, boost::system::error_code *ec)
static int FromProtoPrefix(const BgpProtoPrefix &proto_prefix, MvpnPrefix *prefix)
std::vector< uint8_t > rt_key_
static const size_t kInterASPMSIADRouteSize
Ip4Address source() const
void set_originator(const Ip4Address &originator)
std::string ToXmppIdString() const
static const size_t kSPMSIADRouteSize
static bool GetOriginatorFromString(MvpnPrefix *prefix, const std::string &str, size_t pos1, boost::system::error_code *errorp)
static bool GetRDFromString(MvpnPrefix *prefix, const std::string &str, size_t pos1, size_t *pos2, boost::system::error_code *ec)
static const size_t kAsnSize
static const size_t kIp4AddrBitSize
static bool GetTypeFromString(MvpnPrefix *prefix, const std::string &str, boost::system::error_code *errorp, size_t *pos1)
static const size_t kSourceTreeJoinRouteSize
static MvpnPrefix FromString(const std::string &str, boost::system::error_code *errorp=NULL)
static bool IsValid(uint8_t type)
int CompareTo(const MvpnPrefix &rhs) const
Ip4Address GetType3OriginatorFromType4Route() const
static bool GetGroupFromString(MvpnPrefix *prefix, const std::string &str, size_t pos1, size_t *pos2, boost::system::error_code *ec, bool last=false)
Ip4Address originator() const
const RouteDistinguisher & route_distinguisher() const
void BuildProtoPrefix(BgpProtoPrefix *prefix) const
static const size_t kIp4AddrSize
static const size_t kRdSize
virtual int CompareTo(const Route &rhs) const
virtual std::string ToString() const
virtual std::string ToXmppIdString() const
virtual void SetKey(const DBRequestKey *reqkey)
MvpnRoute(const MvpnPrefix &prefix)
const std::string GetType() const
virtual bool IsValid() const
const MvpnPrefix & GetPrefix() const
virtual KeyPtr GetDBRequestKey() const
virtual void BuildProtoPrefix(BgpProtoPrefix *prefix, const BgpAttr *attr=NULL, uint32_t label=0, uint32_t l3_label=0) const
virtual void BuildBgpProtoNextHop(std::vector< uint8_t > &nh, IpAddress nexthop) const
static RouteDistinguisher FromString(const std::string &str, boost::system::error_code *error=NULL)
static const size_t kSize
const uint8_t * GetData() const
std::string ToString() const
static void put_value(uint8_t *data, int size, uint64_t value)
static uint64_t get_value(const uint8_t *data, int size)
bool stringToInteger(const std::string &str, NumberType &num)
static const std::string integerToString(const NumberType &num)
std::vector< uint8_t > prefix
#define KEY_COMPARE(x, y)