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

Generated by: LCOV version 1.14