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