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