LCOV - code coverage report
Current view: top level - ifmap - ifmap_table.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 23 49 46.9 %
Date: 2026-09-21 02:11:39 Functions: 4 6 66.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #include <sandesh/request_pipeline.h>
       6             : 
       7             : #include "ifmap/ifmap_table.h"
       8             : 
       9             : #include <boost/algorithm/string.hpp>
      10             : #include "db/db.h"
      11             : #include "db/db_table.h"
      12             : #include "db/db_table_partition.h"
      13             : #include "ifmap/autogen.h"
      14             : #include "ifmap/ifmap_node.h"
      15             : #include "ifmap/ifmap_server_show_types.h"
      16             : 
      17             : using namespace std;
      18             : 
      19       33382 : IFMapTable::IFMapTable(DB *db, const std::string &name, DBGraph *graph)
      20       33382 :     : DBGraphTable(db, name, graph) {
      21       33382 : }
      22             : 
      23        2331 : IFMapNode *IFMapTable::FindNode(const std::string &name) {
      24             :     DBTablePartition *partition =
      25        2331 :         static_cast<DBTablePartition *>(GetTablePartition(0));
      26        2331 :     IFMapTable::RequestKey reqkey;
      27        2331 :     reqkey.id_name = name;
      28        4662 :     return static_cast<IFMapNode *>(partition->Find(&reqkey));
      29        2331 : }
      30             : 
      31           0 : IFMapNode *IFMapTable::FindNextNode(const std::string &name) {
      32             :     DBTablePartition *partition =
      33           0 :         static_cast<DBTablePartition *>(GetTablePartition(0));
      34           0 :     IFMapTable::RequestKey reqkey;
      35           0 :     reqkey.id_name = name;
      36           0 :     return static_cast<IFMapNode *>(partition->FindNext(&reqkey));
      37           0 : }
      38             : 
      39       10185 : IFMapTable *IFMapTable::FindTable(DB *db, const std::string &element_type) {
      40       10185 :     string idtype = element_type;
      41       10185 :     std::replace(idtype.begin(), idtype.end(), '-', '_');
      42       10185 :     string name = "__ifmap__." + idtype + ".0";
      43       20370 :     return static_cast<IFMapTable *>(db->FindTable(name));
      44       10185 : }
      45             : 
      46         219 : void IFMapTable::ClearTables(DB *db) {
      47         219 :     for (DB::iterator iter = db->lower_bound("__ifmap__.");
      48       30881 :          iter != db->end(); ++iter) {
      49       30881 :         if (iter->first.find("__ifmap__.") != 0) {
      50         219 :             break;
      51             :         }
      52       30662 :         IFMapTable *table = static_cast<IFMapTable *>(iter->second);
      53       30662 :         table->Clear();
      54             :     }
      55         219 : }
      56             : 
      57           0 : void IFMapTable::FillNodeTableList(DB *db,
      58             :         std::vector<IFMapNodeTableListShowEntry> *table_list) {
      59           0 :     for (DB::const_iterator iter = db->const_lower_bound("__ifmap__");
      60           0 :          iter != db->end(); ++iter) {
      61           0 :         DBTable *table = static_cast<DBTable *>(iter->second);
      62           0 :         if (table->name().compare("__ifmap_metadata__.0") == 0) {
      63             :             // Ignore the link-table in this api
      64           0 :             continue;
      65             :         }
      66           0 :         if (!table->Size())
      67           0 :             continue;
      68             :         // Create a name that can be passed to IFMapTable::FindTable()
      69           0 :         size_t first = table->name().find_first_of(".");
      70           0 :         size_t second = table->name().find_first_of(".", first + 1);
      71           0 :         std::string name = table->name().substr(first + 1, second - first - 1);
      72           0 :         std::replace(name.begin(), name.end(), '_', '-');
      73             : 
      74           0 :         IFMapNodeTableListShowEntry entry;
      75           0 :         entry.table_name = name;
      76           0 :         entry.size = table->Size();
      77             : 
      78           0 :         table_list->push_back(entry);
      79           0 :         if (table->name().find("__ifmap__") != 0) {
      80           0 :             break;
      81             :         }
      82           0 :     }
      83           0 : }

Generated by: LCOV version 1.14