OpenSDN source code
ifmap_table.cc
Go to the documentation of this file.
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 IFMapTable::IFMapTable(DB *db, const std::string &name, DBGraph *graph)
21  : DBGraphTable(db, name, graph) {
22 }
23 
24 IFMapNode *IFMapTable::FindNode(const std::string &name) {
25  DBTablePartition *partition =
26  static_cast<DBTablePartition *>(GetTablePartition(0));
28  reqkey.id_name = name;
29  return static_cast<IFMapNode *>(partition->Find(&reqkey));
30 }
31 
32 IFMapNode *IFMapTable::FindNextNode(const std::string &name) {
33  DBTablePartition *partition =
34  static_cast<DBTablePartition *>(GetTablePartition(0));
36  reqkey.id_name = name;
37  return static_cast<IFMapNode *>(partition->FindNext(&reqkey));
38 }
39 
40 IFMapTable *IFMapTable::FindTable(DB *db, const std::string &element_type) {
41  string idtype = element_type;
42  std::replace(idtype.begin(), idtype.end(), '-', '_');
43  string name = "__ifmap__." + idtype + ".0";
44  return static_cast<IFMapTable *>(db->FindTable(name));
45 }
46 
48  for (DB::iterator iter = db->lower_bound("__ifmap__.");
49  iter != db->end(); ++iter) {
50  if (iter->first.find("__ifmap__.") != 0) {
51  break;
52  }
53  IFMapTable *table = static_cast<IFMapTable *>(iter->second);
54  table->Clear();
55  }
56 }
57 
59  std::vector<IFMapNodeTableListShowEntry> *table_list) {
60  for (DB::const_iterator iter = db->const_lower_bound("__ifmap__");
61  iter != db->end(); ++iter) {
62  DBTable *table = static_cast<DBTable *>(iter->second);
63  if (table->name().compare("__ifmap_metadata__.0") == 0) {
64  // Ignore the link-table in this api
65  continue;
66  }
67  if (!table->Size())
68  continue;
69  // Create a name that can be passed to IFMapTable::FindTable()
70  size_t first = table->name().find_first_of(".");
71  size_t second = table->name().find_first_of(".", first + 1);
72  std::string name = table->name().substr(first + 1, second - first - 1);
73  std::replace(name.begin(), name.end(), '_', '-');
74 
75  IFMapNodeTableListShowEntry entry;
76  entry.table_name = name;
77  entry.size = table->Size();
78 
79  table_list->push_back(entry);
80  if (table->name().find("__ifmap__") != 0) {
81  break;
82  }
83  }
84 }
const std::string & name() const
Definition: db_table.h:111
DBEntry * FindNext(const DBRequestKey *key)
DBEntry * Find(const DBEntry *entry)
virtual size_t Size() const
Definition: db_table.cc:534
virtual DBTablePartBase * GetTablePartition(const DBRequestKey *key)
Definition: db_table.cc:463
Definition: db.h:25
iterator lower_bound(const std::string &name)
Definition: db.h:71
const_iterator const_lower_bound(const std::string &name)
Definition: db.h:76
iterator end()
Definition: db.h:70
TableMap::iterator iterator
Definition: db.h:30
TableMap::const_iterator const_iterator
Definition: db.h:31
DBTableBase * FindTable(const std::string &name)
Definition: db.cc:68
static IFMapTable * FindTable(DB *db, const std::string &element_type)
Definition: ifmap_table.cc:40
IFMapNode * FindNode(const std::string &name)
Definition: ifmap_table.cc:24
virtual void Clear()=0
static void FillNodeTableList(DB *db, std::vector< IFMapNodeTableListShowEntry > *table_list)
Definition: ifmap_table.cc:58
IFMapTable(DB *db, const std::string &name, DBGraph *graph)
Definition: ifmap_table.cc:20
static void ClearTables(DB *db)
Definition: ifmap_table.cc:47
IFMapNode * FindNextNode(const std::string &name)
Definition: ifmap_table.cc:32