OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ifmap_update.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include "ifmap/ifmap_update.h"
6 
7 #include "base/time_util.h"
8 #include "ifmap/ifmap_node.h"
9 
11  : type(NIL) {
12  u.ptr = NULL;
13 }
14 
16  : type(NODE) {
17  u.node = node;
18 }
19 
21  : type(LINK) {
22  u.link = link;
23 }
24 
27 }
28 
31 }
32 
33 IFMapUpdate::IFMapUpdate(IFMapNode *node, bool positive)
34  : IFMapListEntry(positive ? UPDATE : DEL),
35  data_(node) {
36 }
37 
38 IFMapUpdate::IFMapUpdate(IFMapLink *link, bool positive)
39  : IFMapListEntry(positive ? UPDATE : DEL),
40  data_(link) {
41 }
42 
43 std::string IFMapUpdate::ConfigName() {
44  std::string name;
45  if (data().type == IFMapObjectPtr::NODE) {
46  IFMapNode *node = data().u.node;
47  name = node->ToString();
48  } else if (data().type == IFMapObjectPtr::LINK) {
49  IFMapLink *link = data().u.link;
50  name = link->ToString();
51  }
52  return name;
53 }
54 
55 std::string IFMapUpdate::ToString() {
56  return TypeToString() + ":" + ConfigName();
57 }
58 
60  advertise_.Reset(set);
61 }
62 
63 void IFMapUpdate::AdvertiseOr(const BitSet &set) {
64  advertise_ |= set;
65 }
66 
68  advertise_ = set;
69 }
70 
72  : IFMapListEntry(MARKER) {
73 }
74 
75 std::string IFMapMarker::ToString() {
76  return std::string("Marker:") + mask.ToNumberedString();
77 }
78 
80  : sig_(kInvalidSig), data_(node), crc_(0) {
81 }
82 
84  : sig_(kInvalidSig), data_(link), crc_(0) {
85 }
86 
88  assert(update_list_.empty());
89 }
90 
92  for (UpdateList::iterator iter = update_list_.begin();
93  iter != update_list_.end(); ++iter) {
94  IFMapUpdate *update = iter.operator->();
95  if (update->type == type) {
96  return update;
97  }
98  }
99  return NULL;
100 }
101 
103  update_list_.push_front(*update);
104 }
105 
107  update_list_.erase(update_list_.s_iterator_to(*update));
108 }
109 
111  if (data_.IsNode()) {
112  return data_.u.node;
113  } else {
114  return NULL;
115  }
116 }
117 
119  if (data_.IsLink()) {
120  return data_.u.link;
121  } else {
122  return NULL;
123  }
124 }
125 
127  : IFMapState(node) {
128 }
129 
131  return !dependents_.empty();
132 }
133 
135  : IFMapState(link), left_(link), right_(link) {
136 }
137 
139  IFMapNodeState *second) {
140  left_.reset(first);
141  right_.reset(second);
142 }
143 
145  left_.clear();
146  right_.clear();
147 }
148 
150  return left_.get() != NULL;
151 }
152 
void Remove(IFMapUpdate *update)
IFMapNodeState(IFMapNode *node)
bool HasDependency() const
boost::intrusive::list_member_hook node
Definition: ifmap_update.h:56
IFMapState(IFMapNode *node)
Definition: ifmap_update.cc:79
void clear()
Definition: dependency.h:42
BitSet advertise_
Definition: ifmap_update.h:106
void AdvertiseOr(const BitSet &set)
Definition: ifmap_update.cc:63
void SetAdvertise(const BitSet &set)
Definition: ifmap_update.cc:67
virtual std::string ToString() const
Definition: ifmap_node.cc:31
uint64_t queue_insert_at
Definition: ifmap_update.h:58
void Reset(const BitSet &rhs)
Definition: bitset.cc:470
IFMapUpdate(IFMapNode *node, bool positive)
Definition: ifmap_update.cc:33
ObjectType * get() const
Definition: dependency.h:49
void AdvertiseReset(const BitSet &set)
Definition: ifmap_update.cc:59
bool HasDependents() const
IFMapObjectPtr data_
Definition: ifmap_update.h:165
virtual std::string ToString()
Definition: ifmap_update.cc:55
bool IsNode() const
Definition: ifmap_update.h:36
bool IsLink() const
Definition: ifmap_update.h:37
void RemoveDependency()
void SetDependency(IFMapNodeState *first, IFMapNodeState *second)
uint8_t type
Definition: load_balance.h:109
UpdateList update_list_
Definition: ifmap_update.h:172
std::string TypeToString()
Definition: ifmap_update.h:67
IFMapLink * link
Definition: ifmap_update.h:42
static const std::string duration_usecs_to_string(const uint64_t usecs)
Definition: time_util.h:62
void Insert(IFMapUpdate *update)
IFMapUpdate * GetUpdate(IFMapListEntry::EntryType type)
Definition: ifmap_update.cc:91
const IFMapObjectPtr & data() const
Definition: ifmap_update.h:96
IFMapNode * node
Definition: ifmap_update.h:41
IFMapNode * GetIFMapNode() const
std::string ConfigName()
Definition: ifmap_update.cc:43
Definition: bitset.h:17
IFMapLinkState(IFMapLink *link)
DependencyRef< IFMapLink, IFMapNodeState > right_
Definition: ifmap_update.h:223
static uint64_t UTCTimestampUsec()
Definition: time_util.h:13
virtual std::string ToString()
Definition: ifmap_update.cc:75
union IFMapObjectPtr::@5 u
std::string queue_insert_ago_str()
Definition: ifmap_update.cc:29
std::string ToNumberedString() const
Definition: bitset.cc:593
EntryType type
Definition: ifmap_update.h:57
void set_queue_insert_at_to_now()
Definition: ifmap_update.cc:25
void reset(ObjectType *ptr)
Definition: dependency.h:32
virtual ~IFMapState()
Definition: ifmap_update.cc:87
IFMapLink * GetIFMapLink() const
DependencyRef< IFMapLink, IFMapNodeState > left_
Definition: ifmap_update.h:222