-
Notifications
You must be signed in to change notification settings - Fork 390
/
ifmap_update.cc
152 lines (121 loc) · 3.31 KB
/
ifmap_update.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include "ifmap/ifmap_update.h"
#include "base/time_util.h"
#include "ifmap/ifmap_node.h"
IFMapObjectPtr::IFMapObjectPtr()
: type(NIL) {
u.ptr = NULL;
}
IFMapObjectPtr::IFMapObjectPtr(IFMapNode *node)
: type(NODE) {
u.node = node;
}
IFMapObjectPtr::IFMapObjectPtr(IFMapLink *link)
: type(LINK) {
u.link = link;
}
void IFMapListEntry::set_queue_insert_at_to_now() {
queue_insert_at = UTCTimestampUsec();
}
std::string IFMapListEntry::queue_insert_ago_str() {
return duration_usecs_to_string(UTCTimestampUsec() - queue_insert_at);
}
IFMapUpdate::IFMapUpdate(IFMapNode *node, bool positive)
: IFMapListEntry(positive ? UPDATE : DELETE),
data_(node) {
}
IFMapUpdate::IFMapUpdate(IFMapLink *link, bool positive)
: IFMapListEntry(positive ? UPDATE : DELETE),
data_(link) {
}
std::string IFMapUpdate::ConfigName() {
std::string name;
if (data().type == IFMapObjectPtr::NODE) {
IFMapNode *node = data().u.node;
name = node->ToString();
} else if (data().type == IFMapObjectPtr::LINK) {
IFMapLink *link = data().u.link;
name = link->ToString();
}
return name;
}
std::string IFMapUpdate::ToString() {
return TypeToString() + ":" + ConfigName();
}
void IFMapUpdate::AdvertiseReset(const BitSet &set) {
advertise_.Reset(set);
}
void IFMapUpdate::AdvertiseOr(const BitSet &set) {
advertise_ |= set;
}
void IFMapUpdate::SetAdvertise(const BitSet &set) {
advertise_ = set;
}
IFMapMarker::IFMapMarker()
: IFMapListEntry(MARKER) {
}
std::string IFMapMarker::ToString() {
return std::string("Marker:") + mask.ToNumberedString();
}
IFMapState::IFMapState(IFMapNode *node)
: sig_(kInvalidSig), data_(node), crc_(0) {
}
IFMapState::IFMapState(IFMapLink *link)
: sig_(kInvalidSig), data_(link), crc_(0) {
}
IFMapState::~IFMapState() {
assert(update_list_.empty());
}
IFMapUpdate *IFMapState::GetUpdate(IFMapListEntry::EntryType type) {
for (UpdateList::iterator iter = update_list_.begin();
iter != update_list_.end(); ++iter) {
IFMapUpdate *update = iter.operator->();
if (update->type == type) {
return update;
}
}
return NULL;
}
void IFMapState::Insert(IFMapUpdate *update) {
update_list_.push_front(*update);
}
void IFMapState::Remove(IFMapUpdate *update) {
update_list_.erase(update_list_.s_iterator_to(*update));
}
IFMapNode *IFMapState::GetIFMapNode() const {
if (data_.IsNode()) {
return data_.u.node;
} else {
return NULL;
}
}
IFMapLink *IFMapState::GetIFMapLink() const {
if (data_.IsLink()) {
return data_.u.link;
} else {
return NULL;
}
}
IFMapNodeState::IFMapNodeState(IFMapNode *node)
: IFMapState(node) {
}
bool IFMapNodeState::HasDependents() const {
return !dependents_.empty();
}
IFMapLinkState::IFMapLinkState(IFMapLink *link)
: IFMapState(link), left_(link), right_(link) {
}
void IFMapLinkState::SetDependency(IFMapNodeState *first,
IFMapNodeState *second) {
left_.reset(first);
right_.reset(second);
}
void IFMapLinkState::RemoveDependency() {
left_.clear();
right_.clear();
}
bool IFMapLinkState::HasDependency() const {
return left_.get() != NULL;
}