5 #include <sandesh/request_pipeline.h>
7 #include <boost/bind.hpp>
8 #include <boost/assign/list_of.hpp>
9 #include <boost/uuid/uuid_io.hpp>
10 #include <boost/algorithm/string/trim.hpp>
21 #include <ifmap/ifmap_agent_types.h>
23 #include <pugixml/pugixml.hpp>
25 using namespace boost::assign;
40 void MakeNode(
const string &name_sub_string,
41 const string &link_type_sub_string,
42 const string &link_node_sub_string,
49 void TableToBuffer(
const ShowIFMapAgentReq *request,
IFMapTable *table,
61 static inline void to_uuid(uint64_t ms_long, uint64_t ls_long,
63 for (
int i = 0; i < 8; i++) {
64 u.data[7 - i] = ms_long & 0xFF;
65 ms_long = ms_long >> 8;
68 for (
int i = 0; i < 8; i++) {
69 u.data[15 - i] = ls_long & 0xFF;
70 ls_long = ls_long >> 8;
75 void xml_parse(pugi::xml_node &node,
string &s,
int n) {
80 static uint64_t uuid_ms;
81 static uint64_t uuid_ls;
82 static int ls_set = 0;
83 static int ms_set = 0;
86 case pugi::node_element:
88 for(chld = node.first_child(); chld; chld = chld.next_sibling()) {
93 if (strlen(node.child_value()) == 0) {
97 if ((child == 1) && (fchld.type() == pugi::node_pcdata) && (strlen(fchld.child_value()) == 0)) {
102 if (strcmp(node.name(),
"uuid-mslong") == 0) {
103 string value(node.child_value());
105 uuid_ms = strtoull(value.c_str(), NULL, 10);
109 if (strcmp(node.name(),
"uuid-lslong") == 0) {
110 string value(node.child_value());
112 uuid_ls = strtoull(value.c_str(), NULL, 10);
116 if (strcmp(node.name(),
"config") && strcmp(node.name(),
"node")) {
118 if (strlen(node.child_value())) {
119 s = s + t + node.name() +
":" + node.child_value() +
"\n";
121 s = s + t + node.name() +
"\n";
125 if (ms_set && ls_set) {
129 s = s + t +
"Uuid : " + tmp +
"\n";
133 for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) {
134 s = s + t + ait->name() +
":" + ait->value() +
"\n";
137 for(pugi::xml_node chld = node.first_child(); chld; chld = chld.next_sibling()) {
142 case pugi::node_pcdata:
143 s = s + node.child_value() +
"\n";
151 const string &link_node_sub_string,
152 const string &link_type_sub_string,
155 pugi::xml_document doc;
156 pugi::xml_node config;
158 if (name_sub_string.empty() ==
false) {
159 if (node->
name().find(name_sub_string) == string::npos)
165 config = doc.append_child(
"config");
167 config = doc.append_child(
"Delete Marked config");
178 dst = dst +
"Adjacencies:\n";
185 if (link_type_sub_string.empty() ==
false) {
188 link_type_sub_string.c_str()) == NULL)
192 if (link_node_sub_string.empty() ==
false) {
194 if (adj_node->
name().find(link_node_sub_string) == string::npos)
199 adj_node->
name() +
"\n";
211 MakeNode(request->get_node_sub_string(),
212 request->get_link_node_sub_string(),
213 request->get_link_type_sub_string(),
215 if (dst.empty() ==
false)
224 const ShowIFMapAgentReq *request =
225 static_cast<const ShowIFMapAgentReq *
>(ps.
snhRequest_.get());
229 LOG(DEBUG,
"Invalid table name: " << request->get_table_name());
233 if (table->
name().find(
"__ifmap__.") != 0) {
234 LOG(DEBUG,
"Invalid table name: " << request->get_table_name());
239 TableToBuffer(request, table, show_data);
246 const ShowIFMapAgentReq *request =
247 static_cast<const ShowIFMapAgentReq *
>(ps.
snhRequest_.get());
248 for (
DB::iterator iter = db_->lower_bound(
"__ifmap__.");
249 iter != db_->end(); ++iter) {
250 if (iter->first.find(
"__ifmap__.") != 0) {
255 TableToBuffer(request, table, show_data);
263 int stage,
int instNum,
266 const ShowIFMapAgentReq *request =
267 static_cast<const ShowIFMapAgentReq *
>(ps.
snhRequest_.get());
269 if (request->get_table_name().length()) {
270 return BufferSomeTables(ps, data);
272 return BufferAllTables(ps, data);
278 int stage,
int instNum,
283 const ShowIFMapAgentReq *request =
284 static_cast<const ShowIFMapAgentReq *
>(ps.
snhRequest_.get());
285 ShowIFMapAgentResp *response =
new ShowIFMapAgentResp();
287 response->set_context(request->context());
288 response->set_more(
false);
289 response->Response();
293 void ShowIFMapAgentReq::HandleRequest()
const {
315 ps.stages_= list_of(s0)(s1)
316 .convert_to_container<vector<RequestPipeline::StageSpec> >();
320 void ShowIFMapAgentDefLinkReq::HandleRequest()
const {
321 ShowIFMapAgentDefLinkResp *resp;
322 resp =
new ShowIFMapAgentDefLinkResp();
328 IFMapAgentLinkTable::LinkDefMap::const_iterator dlist_it;
329 std::list<IFMapAgentLinkTable::DeferredNode> *ent;
330 std::list<IFMapAgentLinkTable::DeferredNode>::iterator it;
336 std::vector<IFMapAgentDefLink> &list =
337 const_cast<std::vector<IFMapAgentDefLink>&
>(resp->get_def_list());
340 for(dlist_it = def_list.begin(); dlist_it != def_list.end(); dlist_it++) {
342 ent = dlist_it->second;
345 for(it = ent->begin(); it != ent->end(); it++) {
346 IFMapAgentDefLink data;
347 data.set_seq_num((*it).node_key.id_seq_num);
348 data.set_left_node(temp.
id_type +
":" +
350 data.set_metadata((*it).link_metadata);
351 data.set_right_node((*it).node_key.id_type +
":" +
352 (*it).node_key.id_name);
353 list.push_back(data);
356 resp->set_context(context());
361 void ShowIFMapAgentStatsReq::HandleRequest()
const {
368 ShowIFMapAgentStatsResp *resp;
369 resp =
new ShowIFMapAgentStatsResp();
371 resp->set_node_updates_processed(parser->
node_updates());
372 resp->set_node_deletes_processed(parser->
node_deletes());
373 resp->set_link_updates_processed(parser->
link_updates());
374 resp->set_link_deletes_processed(parser->
link_deletes());
380 resp->set_context(context());
std::vector< int > instances_
bool BufferStage(const Sandesh *sr, const RequestPipeline::PipeSpec ps, int stage, int instNum, RequestPipeline::InstData *data)
virtual DBEntryBase * GetFirst()=0
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
boost::ptr_vector< InstData > StageData
vector< string > send_buffer
static const int kPartitionCount
uint64_t node_update_parse_errors()
uint64_t node_delete_parse_errors()
std::map< IFMapTable::RequestKey, std::list< DeferredNode > *, comp > LinkDefMap
virtual const char * Typename() const =0
virtual DBEntryBase * GetNext(const DBEntryBase *)=0
const LinkDefMap & GetLinkDefMap() const
adjacency_iterator end(DBGraph *graph)
static std::string UuidToString(const boost::uuids::uuid &id)
RequestPipeline::InstData * AllocData(int stage)
void TableToBuffer(const ShowIFMapAgentReq *request, IFMapTable *table, ShowData *show_data)
int GetTaskId(const std::string &name)
void EncodeNodeDetail(pugi::xml_node *parent) const
const DBGraph * GetGraph() const
uint64_t link_delete_parse_errors()
static TaskScheduler * GetInstance()
void xml_parse(pugi::xml_node &node, string &s, int n)
TableMap::iterator iterator
bool SendStage(const Sandesh *sr, const RequestPipeline::PipeSpec ps, int stage, int instNum, RequestPipeline::InstData *data)
static IFMapAgentParser * parser_
const std::string & name() const
bool BufferAllTables(const RequestPipeline::PipeSpec ps, RequestPipeline::InstData *data)
const std::string & name() const
void IFMapAgentSandeshInit(DB *db, IFMapAgentParser *parser)
virtual DBTablePartBase * GetTablePartition(const DBRequestKey *key)
bool BufferSomeTables(const RequestPipeline::PipeSpec ps, RequestPipeline::InstData *data)
static IFMapTable * FindTable(DB *db, const std::string &element_type)
#define IFMAP_AGENT_LINK_DB_NAME
uint64_t link_update_parse_errors()
#define LOG(_Level, _Msg)
boost::shared_ptr< const SandeshRequest > snhRequest_
void MakeNode(const string &name_sub_string, const string &link_type_sub_string, const string &link_node_sub_string, string &dst, DBEntryBase *src)
const StageData * GetStageData(int stage) const
adjacency_iterator begin(DBGraph *graph)
static void to_uuid(uint64_t ms_long, uint64_t ls_long, boost::uuids::uuid &u)
DBTableBase * FindTable(const std::string &name)