LCOV - code coverage report
Current view: top level - ifmap - ifmap_update.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 83 97 85.6 %
Date: 2026-09-28 02:13:17 Functions: 24 29 82.8 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14