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