LCOV - code coverage report
Current view: top level - ifmap - ifmap_node.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 72 86 83.7 %
Date: 2026-11-16 02:06:09 Functions: 16 18 88.9 %
Legend: Lines: hit not hit

          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_node.h"
       7             : 
       8             : #include <iostream>
       9             : 
      10             : #include <pugixml/pugixml.hpp>
      11             : 
      12             : #include "ifmap/ifmap_table.h"
      13             : 
      14             : using namespace std;
      15             : using pugi::xml_node;
      16             : 
      17             : 
      18     1085120 : IFMapNode::IFMapNode(IFMapTable *table)
      19     1085120 :     : table_(table) {
      20     1085120 : }
      21             : 
      22             : struct IFMapObjectDeleter {
      23      107074 :     void operator()(IFMapObject *obj) const {
      24      107074 :         intrusive_ptr_release(obj);
      25      107074 :     }
      26             : };
      27             : 
      28     2170240 : IFMapNode::~IFMapNode() {
      29     1085120 :     list_.clear_and_dispose(IFMapObjectDeleter());
      30     2170240 : }
      31             : 
      32     2117619 : string IFMapNode::ToString() const {
      33     2117619 :     string repr(table_->Typename());
      34     2117619 :     repr += ":";
      35     2117619 :     repr += name_;
      36     2117619 :     return repr;
      37           0 : }
      38             : 
      39      139517 : IFMapObject *IFMapNode::Find(IFMapOrigin origin) {
      40      279400 :     for (ObjectList::iterator iter = list_.begin(); iter != list_.end();
      41             :          ++iter) {
      42       39992 :         IFMapObject *object = iter.operator->();
      43       39992 :         if (object->origin() == origin) {
      44       39809 :             return object;
      45             :         }
      46             :     }
      47       99708 :     return NULL;
      48             : }
      49             : 
      50      135021 : void IFMapNode::Insert(IFMapObject *obj) {
      51      135021 :     intrusive_ptr_add_ref(obj);
      52      135021 :     if (obj->origin().IsOriginXmpp()) {
      53          80 :         list_.push_back(*obj);
      54             :     } else {
      55      134941 :         list_.push_front(*obj);
      56             :     }
      57      135021 : }
      58             : 
      59       27947 : void IFMapNode::Remove(IFMapObject *obj) {
      60       55894 :     list_.erase(list_.iterator_to(*obj));
      61       27947 :     intrusive_ptr_release(obj);
      62       27947 : }
      63             : 
      64     2019921 : IFMapObject *IFMapNode::GetObject() {
      65     2019921 :     if (list_.empty()) {
      66      191834 :         return NULL;
      67             :     }
      68     1828087 :     return &list_.front();
      69             : }
      70             : 
      71       51885 : const IFMapObject *IFMapNode::GetObject() const {
      72       51885 :     if (list_.empty()) {
      73          24 :         return NULL;
      74             :     }
      75       51861 :     return &list_.front();
      76             : }
      77             : 
      78        3551 : IFMapNode::crc32type IFMapNode::GetConfigCrc() {
      79        3551 :     IFMapNode::crc32type crc = 0;
      80        3551 :     IFMapObject *object = Find(IFMapOrigin(IFMapOrigin::CASSANDRA));
      81        3551 :     if (object) {
      82        3060 :         crc = object->CalculateCrc();
      83        3060 :         if (crc == 0) {
      84         510 :             crc = 0xffffffff;
      85             :         }
      86             :     }
      87             : 
      88        3551 :     return crc;
      89             : }
      90             : 
      91           0 : void IFMapNode::PrintAllObjects() {
      92           0 :     cout << name_ << ": " << list_.size() << " objects" << endl;
      93           0 :     for (ObjectList::iterator iter = list_.begin(); iter != list_.end();
      94             :          ++iter) {
      95           0 :         IFMapObject *object = iter.operator->();
      96           0 :         cout << "\t" << object->origin().ToString() << endl;
      97             :     }
      98           0 : }
      99             : 
     100         443 : void IFMapNode::EncodeNodeDetail(pugi::xml_node *parent) const {
     101         443 :     xml_node node = parent->append_child("node");
     102         443 :     node.append_attribute("type") = table_->Typename();
     103         443 :     node.append_child("name").text().set(name_.c_str());
     104         443 :     const IFMapObject *object = GetObject();
     105         443 :     if (object != NULL) {
     106         419 :         object->EncodeUpdate(&node);
     107             :     }
     108         443 : }
     109             : 
     110           0 : void IFMapNode::EncodeNode(xml_node *parent) const {
     111           0 :     xml_node node = parent->append_child("node");
     112           0 :     node.append_attribute("type") = table_->Typename();
     113           0 :     node.append_child("name").text().set(name_.c_str());
     114           0 : }
     115             : 
     116         916 : void IFMapNode::EncodeNode(const Descriptor &descriptor, xml_node *parent) {
     117         916 :     xml_node node = parent->append_child("node");
     118         916 :     node.append_attribute("type") = descriptor.first.c_str();
     119         916 :     node.append_child("name").text().set(descriptor.second.c_str());
     120         916 : }
     121             : 
     122        1761 : DBEntryBase::KeyPtr IFMapNode::GetDBRequestKey() const {
     123        1761 :     IFMapTable::RequestKey *keyptr = new IFMapTable::RequestKey();
     124        1761 :     keyptr->id_name = name_;
     125        1761 :     return KeyPtr(keyptr);
     126             : }
     127             : 
     128     1085120 : void IFMapNode::SetKey(const DBRequestKey *genkey) {
     129     1085120 :     const IFMapTable::RequestKey *keyptr =
     130             :     static_cast<const IFMapTable::RequestKey *>(genkey);
     131     1085120 :     name_ = keyptr->id_name;
     132     1085120 : }
     133             : 
     134      131932 : IFMapNode *IFMapNode::DescriptorLookup(
     135             :         DB *db, const IFMapNode::Descriptor &descriptor) {
     136      131932 :     if (db == NULL) {
     137           0 :         return NULL;
     138             :     }
     139      131932 :     IFMapTable *table = IFMapTable::FindTable(db, descriptor.first);
     140      131932 :     if (table == NULL) {
     141           0 :         return NULL;
     142             :     }
     143      131932 :     return table->FindNode(descriptor.second);
     144             : }

Generated by: LCOV version 1.14