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 3050 : IFMapObjectPtr::IFMapObjectPtr(IFMapNode *node) 17 3050 : : type(NODE) { 18 3050 : u.node = node; 19 3050 : } 20 : 21 3338 : IFMapObjectPtr::IFMapObjectPtr(IFMapLink *link) 22 3338 : : type(LINK) { 23 3338 : u.link = link; 24 3338 : } 25 : 26 1579 : void IFMapListEntry::set_queue_insert_at_to_now() { 27 1579 : queue_insert_at = UTCTimestampUsec(); 28 1579 : } 29 : 30 0 : std::string IFMapListEntry::queue_insert_ago_str() { 31 0 : return duration_usecs_to_string(UTCTimestampUsec() - queue_insert_at); 32 : } 33 : 34 634 : IFMapUpdate::IFMapUpdate(IFMapNode *node, bool positive) 35 : : IFMapListEntry(positive ? UPDATE : DEL), 36 634 : data_(node) { 37 634 : } 38 : 39 589 : IFMapUpdate::IFMapUpdate(IFMapLink *link, bool positive) 40 : : IFMapListEntry(positive ? UPDATE : DEL), 41 589 : data_(link) { 42 589 : } 43 : 44 892 : std::string IFMapUpdate::ConfigName() { 45 892 : std::string name; 46 892 : if (data().type == IFMapObjectPtr::NODE) { 47 434 : IFMapNode *node = data().u.node; 48 434 : 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 892 : return name; 54 0 : } 55 : 56 0 : std::string IFMapUpdate::ToString() { 57 0 : return TypeToString() + ":" + ConfigName(); 58 : } 59 : 60 1805 : void IFMapUpdate::AdvertiseReset(const BitSet &set) { 61 1805 : advertise_.Reset(set); 62 1805 : } 63 : 64 1108 : void IFMapUpdate::AdvertiseOr(const BitSet &set) { 65 1108 : advertise_ |= set; 66 1108 : } 67 : 68 169 : void IFMapUpdate::SetAdvertise(const BitSet &set) { 69 169 : advertise_ = set; 70 169 : } 71 : 72 217 : IFMapMarker::IFMapMarker() 73 217 : : IFMapListEntry(MARKER) { 74 217 : } 75 : 76 52 : std::string IFMapMarker::ToString() { 77 104 : return std::string("Marker:") + mask.ToNumberedString(); 78 : } 79 : 80 2416 : IFMapState::IFMapState(IFMapNode *node) 81 2416 : : sig_(kInvalidSig), data_(node), crc_(0) { 82 2416 : } 83 : 84 2749 : IFMapState::IFMapState(IFMapLink *link) 85 2749 : : sig_(kInvalidSig), data_(link), crc_(0) { 86 2749 : } 87 : 88 5165 : IFMapState::~IFMapState() { 89 5165 : assert(update_list_.empty()); 90 5165 : } 91 : 92 15348 : IFMapUpdate *IFMapState::GetUpdate(IFMapListEntry::EntryType type) { 93 15348 : for (UpdateList::iterator iter = update_list_.begin(); 94 34154 : iter != update_list_.end(); ++iter) { 95 3061 : IFMapUpdate *update = iter.operator->(); 96 3061 : if (update->type == type) { 97 1332 : return update; 98 : } 99 : } 100 14016 : return NULL; 101 : } 102 : 103 1181 : void IFMapState::Insert(IFMapUpdate *update) { 104 1181 : update_list_.push_front(*update); 105 1181 : } 106 : 107 1147 : void IFMapState::Remove(IFMapUpdate *update) { 108 2294 : update_list_.erase(update_list_.s_iterator_to(*update)); 109 1147 : } 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 2416 : IFMapNodeState::IFMapNodeState(IFMapNode *node) 128 2416 : : IFMapState(node) { 129 2416 : } 130 : 131 166 : bool IFMapNodeState::HasDependents() const { 132 166 : return !dependents_.empty(); 133 : } 134 : 135 2749 : IFMapLinkState::IFMapLinkState(IFMapLink *link) 136 2749 : : IFMapState(link), left_(link), right_(link) { 137 2749 : } 138 : 139 2752 : void IFMapLinkState::SetDependency(IFMapNodeState *first, 140 : IFMapNodeState *second) { 141 2752 : left_.reset(first); 142 2752 : right_.reset(second); 143 2752 : } 144 : 145 50 : void IFMapLinkState::RemoveDependency() { 146 50 : left_.clear(); 147 50 : right_.clear(); 148 50 : } 149 : 150 640 : bool IFMapLinkState::HasDependency() const { 151 640 : return left_.get() != NULL; 152 : } 153 :