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-16 02:06:09 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       31892 : IFMapTable::IFMapTable(DB *db, const std::string &name, DBGraph *graph)
      21       31892 :     : DBGraphTable(db, name, graph) {
      22       31892 : }
      23             : 
      24        9827 : IFMapNode *IFMapTable::FindNode(const std::string &name) {
      25             :     DBTablePartition *partition =
      26        9827 :         static_cast<DBTablePartition *>(GetTablePartition(0));
      27        9827 :     IFMapTable::RequestKey reqkey;
      28        9827 :     reqkey.id_name = name;
      29       19654 :     return static_cast<IFMapNode *>(partition->Find(&reqkey));
      30        9827 : }
      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       32910 : IFMapTable *IFMapTable::FindTable(DB *db, const std::string &element_type) {
      41       32910 :     string idtype = element_type;
      42       32913 :     std::replace(idtype.begin(), idtype.end(), '-', '_');
      43       32864 :     string name = "__ifmap__." + idtype + ".0";
      44       65736 :     return static_cast<IFMapTable *>(db->FindTable(name));
      45       32849 : }
      46             : 
      47         209 : void IFMapTable::ClearTables(DB *db) {
      48         209 :     for (DB::iterator iter = db->lower_bound("__ifmap__.");
      49       29381 :          iter != db->end(); ++iter) {
      50       29381 :         if (iter->first.find("__ifmap__.") != 0) {
      51         209 :             break;
      52             :         }
      53       29172 :         IFMapTable *table = static_cast<IFMapTable *>(iter->second);
      54       29172 :         table->Clear();
      55             :     }
      56         209 : }
      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