-
Notifications
You must be signed in to change notification settings - Fork 390
/
bgp_origin_vn_path.cc
96 lines (80 loc) · 2.4 KB
/
bgp_origin_vn_path.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include "bgp/bgp_origin_vn_path.h"
#include <boost/foreach.hpp>
#include <algorithm>
#include <string>
#include "bgp/bgp_proto.h"
using std::string;
using std::vector;
string OriginVnPathSpec::ToString() const {
char repr[80];
snprintf(repr, sizeof(repr), "OriginVnPath <code: %d, flags: %02x> : %lu",
code, flags, origin_vns.size());
return string(repr);
}
int OriginVnPathSpec::CompareTo(const BgpAttribute &rhs) const {
int ret = BgpAttribute::CompareTo(rhs);
if (ret != 0)
return ret;
KEY_COMPARE(origin_vns,
static_cast<const OriginVnPathSpec &>(rhs).origin_vns);
return 0;
}
void OriginVnPathSpec::ToCanonical(BgpAttr *attr) {
attr->set_origin_vn_path(this);
}
OriginVnPath::OriginVnPath(OriginVnPathDB *ovnpath_db,
const OriginVnPathSpec spec)
: ovnpath_db_(ovnpath_db) {
refcount_ = 0;
for (vector<uint64_t>::const_iterator it = spec.origin_vns.begin();
it < spec.origin_vns.end(); ++it) {
OriginVnValue value;
put_value(value.data(), value.size(), *it);
origin_vns_.push_back(value);
}
}
void OriginVnPath::Remove() {
ovnpath_db_->Delete(this);
}
void OriginVnPath::Prepend(const OriginVnValue &value) {
OriginVnList::iterator it = origin_vns_.begin();
origin_vns_.insert(it, value);
}
bool OriginVnPath::Contains(const OriginVnValue &val) const {
for (OriginVnList::const_iterator it = origin_vns_.begin();
it != origin_vns_.end(); ++it) {
if (*it == val)
return true;
}
return false;
}
int OriginVnPath::CompareTo(const OriginVnPath &rhs) const {
KEY_COMPARE(origin_vns_.size(), rhs.origin_vns_.size());
OriginVnList::const_iterator it1, it2;
for (it1 = origin_vns_.begin(), it2 = rhs.origin_vns_.begin();
it1 < origin_vns_.end(); ++it1, ++it2) {
if (*it1 < *it2) {
return -1;
}
if (*it1 > *it2) {
return 1;
}
}
return 0;
}
OriginVnPathDB::OriginVnPathDB(BgpServer *server) {
}
OriginVnPathPtr OriginVnPathDB::PrependAndLocate(const OriginVnPath *ovnpath,
const OriginVnPath::OriginVnValue &value) {
OriginVnPath *clone;
if (ovnpath) {
clone = new OriginVnPath(*ovnpath);
} else {
clone = new OriginVnPath(this);
}
clone->Prepend(value);
return Locate(clone);
}