Line data Source code
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 : 11 0 : IFMapObjectPtr::IFMapObjectPtr() 12 0 : : type(NIL) { 13 0 : u.ptr = NULL; 14 0 : } 15 : 16 3034 : IFMapObjectPtr::IFMapObjectPtr(IFMapNode *node) 17 3034 : : type(NODE) { 18 3034 : u.node = node; 19 3034 : } 20 : 21 3329 : IFMapObjectPtr::IFMapObjectPtr(IFMapLink *link) 22 3329 : : type(LINK) { 23 3329 : u.link = link; 24 3329 : } 25 : 26 1581 : void IFMapListEntry::set_queue_insert_at_to_now() { 27 1581 : queue_insert_at = UTCTimestampUsec(); 28 1581 : } 29 : 30 0 : std::string IFMapListEntry::queue_insert_ago_str() { 31 0 : return duration_usecs_to_string(UTCTimestampUsec() - queue_insert_at); 32 : } 33 : 34 631 : IFMapUpdate::IFMapUpdate(IFMapNode *node, bool positive) 35 : : IFMapListEntry(positive ? UPDATE : DEL), 36 631 : data_(node) { 37 631 : } 38 : 39 589 : IFMapUpdate::IFMapUpdate(IFMapLink *link, bool positive) 40 : : IFMapListEntry(positive ? UPDATE : DEL), 41 589 : data_(link) { 42 589 : } 43 : 44 891 : std::string IFMapUpdate::ConfigName() { 45 891 : std::string name; 46 891 : if (data().type == IFMapObjectPtr::NODE) { 47 433 : IFMapNode *node = data().u.node; 48 433 : name = node->ToString(); 49 458 : } else if (data().type == IFMapObjectPtr::LINK) { 50 458 : IFMapLink *link = data().u.link; 51 458 : name = link->ToString(); 52 : } 53 891 : return name; 54 0 : } 55 : 56 0 : std::string IFMapUpdate::ToString() { 57 0 : return TypeToString() + ":" + ConfigName(); 58 : } 59 : 60 1801 : void IFMapUpdate::AdvertiseReset(const BitSet &set) { 61 1801 : advertise_.Reset(set); 62 1801 : } 63 : 64 1108 : void IFMapUpdate::AdvertiseOr(const BitSet &set) { 65 1108 : advertise_ |= set; 66 1108 : } 67 : 68 167 : void IFMapUpdate::SetAdvertise(const BitSet &set) { 69 167 : advertise_ = set; 70 167 : } 71 : 72 217 : IFMapMarker::IFMapMarker() 73 217 : : IFMapListEntry(MARKER) { 74 217 : } 75 : 76 51 : std::string IFMapMarker::ToString() { 77 102 : return std::string("Marker:") + mask.ToNumberedString(); 78 : } 79 : 80 2403 : IFMapState::IFMapState(IFMapNode *node) 81 2403 : : sig_(kInvalidSig), data_(node), crc_(0) { 82 2403 : } 83 : 84 2740 : IFMapState::IFMapState(IFMapLink *link) 85 2740 : : sig_(kInvalidSig), data_(link), crc_(0) { 86 2740 : } 87 : 88 5143 : IFMapState::~IFMapState() { 89 5143 : assert(update_list_.empty()); 90 5143 : } 91 : 92 15216 : IFMapUpdate *IFMapState::GetUpdate(IFMapListEntry::EntryType type) { 93 15216 : for (UpdateList::iterator iter = update_list_.begin(); 94 33878 : iter != update_list_.end(); ++iter) { 95 3058 : IFMapUpdate *update = iter.operator->(); 96 3058 : if (update->type == type) { 97 1335 : return update; 98 : } 99 : } 100 13881 : return NULL; 101 : } 102 : 103 1178 : void IFMapState::Insert(IFMapUpdate *update) { 104 1178 : update_list_.push_front(*update); 105 1178 : } 106 : 107 1144 : void IFMapState::Remove(IFMapUpdate *update) { 108 2288 : update_list_.erase(update_list_.s_iterator_to(*update)); 109 1144 : } 110 : 111 70 : IFMapNode *IFMapState::GetIFMapNode() const { 112 70 : if (data_.IsNode()) { 113 70 : return data_.u.node; 114 : } else { 115 0 : return NULL; 116 : } 117 : } 118 : 119 0 : IFMapLink *IFMapState::GetIFMapLink() const { 120 0 : if (data_.IsLink()) { 121 0 : return data_.u.link; 122 : } else { 123 0 : return NULL; 124 : } 125 : } 126 : 127 2403 : IFMapNodeState::IFMapNodeState(IFMapNode *node) 128 2403 : : IFMapState(node) { 129 2403 : } 130 : 131 93 : bool IFMapNodeState::HasDependents() const { 132 93 : return !dependents_.empty(); 133 : } 134 : 135 2740 : IFMapLinkState::IFMapLinkState(IFMapLink *link) 136 2740 : : IFMapState(link), left_(link), right_(link) { 137 2740 : } 138 : 139 2743 : void IFMapLinkState::SetDependency(IFMapNodeState *first, 140 : IFMapNodeState *second) { 141 2743 : left_.reset(first); 142 2743 : right_.reset(second); 143 2743 : } 144 : 145 36 : void IFMapLinkState::RemoveDependency() { 146 36 : left_.clear(); 147 36 : right_.clear(); 148 36 : } 149 : 150 634 : bool IFMapLinkState::HasDependency() const { 151 634 : return left_.get() != NULL; 152 : } 153 :