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-06-11 01:56:02 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     1224935 : IFMapTable::IFMapTable(DB *db, const std::string &name, DBGraph *graph)
      20     1224935 :     : DBGraphTable(db, name, graph) {
      21     1224935 : }
      22             : 
      23      273384 : IFMapNode *IFMapTable::FindNode(const std::string &name) {
      24             :     DBTablePartition *partition =
      25      273384 :         static_cast<DBTablePartition *>(GetTablePartition(0));
      26      273384 :     IFMapTable::RequestKey reqkey;
      27      273384 :     reqkey.id_name = name;
      28      546768 :     return static_cast<IFMapNode *>(partition->Find(&reqkey));
      29      273384 : }
      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      534272 : IFMapTable *IFMapTable::FindTable(DB *db, const std::string &element_type) {
      40      534272 :     string idtype = element_type;
      41      534267 :     std::replace(idtype.begin(), idtype.end(), '-', '_');
      42      534269 :     string name = "__ifmap__." + idtype + ".0";
      43     1068544 :     return static_cast<IFMapTable *>(db->FindTable(name));
      44      534266 : }
      45             : 
      46        8216 : void IFMapTable::ClearTables(DB *db) {
      47        8216 :     for (DB::iterator iter = db->lower_bound("__ifmap__.");
      48     1230431 :          iter != db->end(); ++iter) {
      49     1230431 :         if (iter->first.find("__ifmap__.") != 0) {
      50        8216 :             break;
      51             :         }
      52     1222215 :         IFMapTable *table = static_cast<IFMapTable *>(iter->second);
      53     1222215 :         table->Clear();
      54             :     }
      55        8216 : }
      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