Skip to content

Commit

Permalink
Support for IFmap Config Stats in Agent
Browse files Browse the repository at this point in the history
Currently there are no statistics for Config messages received from
control node. Following statistics are added now. Node updates, node
deletes, link updates, link deletes, node parsing update errors, node
parsing delete errors, link parsing update errors, link parsing delete
errors. These statistics are reset every time a new config sequence
number is generated. In addition to these, the number of config xmpp
messages received is also updated. This is part of agent stats and is
not reset when xmpp channel is reset.

Change-Id: Ib5fea7a60d9eeb10bea7caf71071a0247f32a07d
closes-bug: #1572462
  • Loading branch information
divakardhar committed Jul 20, 2016
1 parent 32db0ff commit 98f5cea
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 5 deletions.
17 changes: 17 additions & 0 deletions src/ifmap/ifmap_agent.sandesh
Expand Up @@ -29,6 +29,23 @@ response sandesh ShowIFMapAgentDefLinkResp {
1: list<IFMapAgentDefLink> def_list;
}


//Show IFMap statistics
request sandesh ShowIFMapAgentStatsReq {
}

response sandesh ShowIFMapAgentStatsResp {
1: u64 node_updates_processed;
2: u64 node_deletes_processed;
3: u64 link_updates_processed;
4: u64 link_deletes_processed;
5: u64 node_update_parse_errors;
6: u64 link_update_parse_errors;
7: u64 node_delete_parse_errors;
8: u64 link_delete_parse_errors;
}


traceobject sandesh IFMapAgentTrace{
1: i64 seq;
2: string event;
Expand Down
27 changes: 27 additions & 0 deletions src/ifmap/ifmap_agent_parser.cc
Expand Up @@ -26,16 +26,23 @@ void IFMapAgentParser::NodeClear() {
void IFMapAgentParser::NodeParse(xml_node &node, DBRequest::DBOperation oper, uint64_t seq) {

const char *name = node.attribute("type").value();
int msg_type;
if (oper == DBRequest::DB_ENTRY_ADD_CHANGE)
msg_type = UPDATE;
else
msg_type = DELETE;

IFMapTable *table;
table = IFMapTable::FindTable(db_, name);
if(!table) {
node_parse_errors_[msg_type]++;
return;
}

// Locate the decode function using id_name
NodeParseMap::const_iterator loc = node_map_.find(name);
if (loc == node_map_.end()) {
node_parse_errors_[msg_type]++;
return;
}

Expand All @@ -47,6 +54,7 @@ void IFMapAgentParser::NodeParse(xml_node &node, DBRequest::DBOperation oper, ui
req_key->id_seq_num = seq;
obj = loc->second(node, db_, &req_key->id_name);
if (!obj) {
node_parse_errors_[msg_type]++;
delete req_key;
return;
}
Expand All @@ -72,6 +80,12 @@ void IFMapAgentParser::LinkParse(xml_node &link, DBRequest::DBOperation oper, ui
IFMapTable *table;
IFMapAgentLinkTable *link_table;

int msg_type;
if (oper == DBRequest::DB_ENTRY_ADD_CHANGE)
msg_type = UPDATE;
else
msg_type = DELETE;

link_table = static_cast<IFMapAgentLinkTable *>(
db_->FindTable(IFMAP_AGENT_LINK_DB_NAME));

Expand All @@ -80,42 +94,50 @@ void IFMapAgentParser::LinkParse(xml_node &link, DBRequest::DBOperation oper, ui
// Get both first and second node and its corresponding tables
first_node = link.first_child();
if (!first_node) {
link_parse_errors_[msg_type]++;
return;
}

second_node = first_node.next_sibling();
if (!second_node) {
link_parse_errors_[msg_type]++;
return;
}

name1 = first_node.attribute("type").value();
table = IFMapTable::FindTable(db_, name1);
if(!table) {
link_parse_errors_[msg_type]++;
return;
}

name2 = second_node.attribute("type").value();
table = IFMapTable::FindTable(db_, name2);
if(!table) {
link_parse_errors_[msg_type]++;
return;
}

// Get id_name of both the nodes
name_node1 = first_node.first_child();
if (!name_node1) {
link_parse_errors_[msg_type]++;
return;
}

if (strcmp(name_node1.name(), "name") != 0) {
link_parse_errors_[msg_type]++;
return;
}

name_node2 = second_node.first_child();
if (!name_node2) {
link_parse_errors_[msg_type]++;
return;
}

if (strcmp(name_node2.name(), "name") != 0) {
link_parse_errors_[msg_type]++;
return;
}

Expand Down Expand Up @@ -148,10 +170,13 @@ void IFMapAgentParser::ConfigParse(const xml_node config, const uint64_t seq) {
for (xml_node node = config.first_child(); node;
node = node.next_sibling()) {

int msg_type;
if (strcmp(node.name(), "update") == 0) {
oper = DBRequest::DB_ENTRY_ADD_CHANGE;
msg_type = UPDATE;
} else if (strcmp(node.name(), "delete") == 0) {
oper = DBRequest::DB_ENTRY_DELETE;
msg_type = DELETE;
} else {
continue;
}
Expand All @@ -160,11 +185,13 @@ void IFMapAgentParser::ConfigParse(const xml_node config, const uint64_t seq) {

// Handle the links between the nodes
if (strcmp(chld.name(), "link") == 0) {
links_processed_[msg_type]++;
LinkParse(chld, oper, seq);
continue;
}

if (strcmp(chld.name(), "node") == 0) {
nodes_processed_[msg_type]++;
NodeParse(chld, oper, seq);
}
}
Expand Down
31 changes: 30 additions & 1 deletion src/ifmap/ifmap_agent_parser.h
Expand Up @@ -19,17 +19,46 @@ class xml_node;

class IFMapAgentParser {
public:
IFMapAgentParser(DB *db) : db_(db) {} ;

enum ConfigMsgType {
UPDATE,
DELETE,
MAX
};

IFMapAgentParser(DB *db) : db_(db) { reset_statistics(); } ;

typedef boost::function< IFMapObject *(const pugi::xml_node, DB *,
std::string *id_name) > NodeParseFn;
typedef std::map<std::string, NodeParseFn> NodeParseMap;
void NodeRegister(const std::string &node, NodeParseFn parser);
void NodeClear();
void ConfigParse(const pugi::xml_node config, uint64_t seq);
uint64_t node_updates() { return nodes_processed_[UPDATE]; }
uint64_t node_deletes() { return nodes_processed_[DELETE]; }
uint64_t link_updates() { return links_processed_[UPDATE]; }
uint64_t link_deletes() { return links_processed_[DELETE]; }
uint64_t node_update_parse_errors() { return node_parse_errors_[UPDATE]; }
uint64_t node_delete_parse_errors() { return node_parse_errors_[DELETE]; }
uint64_t link_update_parse_errors() { return link_parse_errors_[UPDATE]; }
uint64_t link_delete_parse_errors() { return link_parse_errors_[DELETE]; }
void reset_statistics() {
nodes_processed_[UPDATE] = 0;
nodes_processed_[DELETE] = 0;
links_processed_[UPDATE] = 0;
links_processed_[DELETE] = 0;
node_parse_errors_[UPDATE] = 0;
node_parse_errors_[DELETE] = 0;
link_parse_errors_[UPDATE] = 0;
link_parse_errors_[DELETE] = 0;
}
private:
DB *db_;
NodeParseMap node_map_;
uint64_t nodes_processed_[MAX];
uint64_t links_processed_[MAX];
uint64_t node_parse_errors_[MAX];
uint64_t link_parse_errors_[MAX];
void NodeParse(pugi::xml_node &node, DBRequest::DBOperation oper, uint64_t seq);
void LinkParse(pugi::xml_node &node, DBRequest::DBOperation oper, uint64_t seq);
};
Expand Down
30 changes: 29 additions & 1 deletion src/ifmap/ifmap_agent_sandesh.cc
Expand Up @@ -21,6 +21,7 @@
#include <ifmap/ifmap_agent_table.h>
#include <ifmap/ifmap_node.h>
#include <ifmap/ifmap_agent_types.h>
#include <ifmap/ifmap_agent_parser.h>
#include <pugixml/pugixml.hpp>

using namespace boost::assign;
Expand All @@ -29,6 +30,7 @@ using namespace std;
class ShowIFMapAgentTable {
public:
static DB *db_;
static IFMapAgentParser *parser_;
struct ShowData : public RequestPipeline::InstData {
vector<string> send_buffer;
};
Expand Down Expand Up @@ -56,6 +58,7 @@ class ShowIFMapAgentTable {
};

DB* ShowIFMapAgentTable::db_;
IFMapAgentParser* ShowIFMapAgentTable::parser_;

static inline void to_uuid(uint64_t ms_long, uint64_t ls_long,
boost::uuids::uuid &u) {
Expand Down Expand Up @@ -356,6 +359,31 @@ void ShowIFMapAgentDefLinkReq::HandleRequest() const {
return;
}

void IFMapAgentSandeshInit(DB *db) {
void ShowIFMapAgentStatsReq::HandleRequest() const {

IFMapAgentParser *parser = ShowIFMapAgentTable::parser_;

if (!parser)
return;

ShowIFMapAgentStatsResp *resp;
resp = new ShowIFMapAgentStatsResp();

resp->set_node_updates_processed(parser->node_updates());
resp->set_node_deletes_processed(parser->node_deletes());
resp->set_link_updates_processed(parser->link_updates());
resp->set_link_deletes_processed(parser->link_deletes());
resp->set_node_update_parse_errors(parser->node_update_parse_errors());
resp->set_link_update_parse_errors(parser->link_update_parse_errors());
resp->set_node_delete_parse_errors(parser->node_delete_parse_errors());
resp->set_link_delete_parse_errors(parser->link_delete_parse_errors());

resp->set_context(context());
resp->Response();
return;
}

void IFMapAgentSandeshInit(DB *db, IFMapAgentParser *parser) {
ShowIFMapAgentTable::db_ = db;
ShowIFMapAgentTable::parser_ = parser;
}
4 changes: 2 additions & 2 deletions src/vnsw/agent/cfg/cfg_init.cc
Expand Up @@ -41,7 +41,7 @@ using namespace boost::property_tree;
using namespace boost::uuids;
using boost::optional;

void IFMapAgentSandeshInit(DB *db);
void IFMapAgentSandeshInit(DB *, IFMapAgentParser *);

SandeshTraceBufferPtr CfgTraceBuf(SandeshTraceBufferCreate("Config", 2000));

Expand Down Expand Up @@ -93,7 +93,7 @@ void AgentConfig::CreateDBTables(DB *db) {
new IFMapAgentStaleCleaner(db, cfg_graph_.get());
agent_->set_ifmap_stale_cleaner(cl);

IFMapAgentSandeshInit(db);
IFMapAgentSandeshInit(db, cfg_parser_.get());
}

void AgentConfig::Register(const char *node_name, AgentDBTable *table,
Expand Down
1 change: 1 addition & 0 deletions src/vnsw/agent/cmn/agent_stats.cc
Expand Up @@ -93,6 +93,7 @@ void AgentStatsReq::HandleRequest() const {
peer.set_reconnect(stats->xmpp_reconnects(count));
peer.set_in_msgs(stats->xmpp_in_msgs(count));
peer.set_out_msgs(stats->xmpp_out_msgs(count));
peer.set_config_in_msgs(stats->xmpp_config_in_msgs(count));
list.push_back(peer);
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/vnsw/agent/cmn/agent_stats.h
Expand Up @@ -16,7 +16,8 @@ class AgentStats {
static const uint64_t kInvalidFlowCount = 0xFFFFFFFFFFFFFFFF;
AgentStats(Agent *agent)
: agent_(agent), xmpp_reconnect_(), xmpp_in_msgs_(), xmpp_out_msgs_(),
sandesh_reconnects_(0U), sandesh_in_msgs_(0U), sandesh_out_msgs_(0U),
xmpp_config_in_msgs_(), sandesh_reconnects_(0U),
sandesh_in_msgs_(0U), sandesh_out_msgs_(0U),
sandesh_http_sessions_(0U), nh_count_(0U), pkt_exceptions_(0U),
pkt_invalid_agent_hdr_(0U), pkt_invalid_interface_(0U),
pkt_no_handler_(0U), pkt_fragments_dropped_(0U), pkt_dropped_(0U),
Expand Down Expand Up @@ -52,6 +53,11 @@ class AgentStats {
void incr_xmpp_out_msgs(uint8_t idx) {xmpp_out_msgs_[idx]++;}
uint64_t xmpp_out_msgs(uint8_t idx) const {return xmpp_out_msgs_[idx];}

void incr_xmpp_config_in_msgs(uint8_t idx) {xmpp_config_in_msgs_[idx]++;}
uint64_t xmpp_config_in_msgs(uint8_t idx) const {
return xmpp_config_in_msgs_[idx];
}

void incr_sandesh_reconnects() {sandesh_reconnects_++;}
uint32_t sandesh_reconnects() const {return sandesh_reconnects_;}

Expand Down Expand Up @@ -181,6 +187,7 @@ class AgentStats {
uint32_t xmpp_reconnect_[MAX_XMPP_SERVERS];
uint64_t xmpp_in_msgs_[MAX_XMPP_SERVERS];
uint64_t xmpp_out_msgs_[MAX_XMPP_SERVERS];
uint64_t xmpp_config_in_msgs_[MAX_XMPP_SERVERS];

uint32_t sandesh_reconnects_;
uint64_t sandesh_in_msgs_;
Expand Down
1 change: 1 addition & 0 deletions src/vnsw/agent/cmn/stats.sandesh
Expand Up @@ -63,6 +63,7 @@ struct XmppStatsInfo {
2: u64 in_msgs;
3: u64 out_msgs;
4: u16 reconnect;
5: u64 config_in_msgs;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/vnsw/agent/controller/controller_ifmap.cc
Expand Up @@ -16,6 +16,7 @@
#include <sandesh/sandesh_types.h>

#include <cmn/agent_cmn.h>
#include <cmn/agent_stats.h>
#include <cfg/cfg_interface.h>

#include <controller/controller_init.h>
Expand Down Expand Up @@ -88,6 +89,8 @@ void AgentIfMapXmppChannel::ReceiveConfigMessage(std::auto_ptr<XmlBase> impl) {
}

void AgentIfMapXmppChannel::ReceiveInternal(const XmppStanza::XmppMessage *msg) {
if (agent_->stats())
agent_->stats()->incr_xmpp_config_in_msgs(GetXmppServerIdx());
ReceiveUpdate(msg);
}

Expand Down
2 changes: 2 additions & 0 deletions src/vnsw/agent/controller/controller_peer.cc
Expand Up @@ -1368,6 +1368,7 @@ bool AgentXmppChannel::SetConfigPeer(AgentXmppChannel *peer) {
peer->GetXmppServerIdx());
//Generate a new sequence number for the configuration
AgentIfMapXmppChannel::NewSeqNumber();
agent->ifmap_parser()->reset_statistics();
agent->controller()->agent_ifmap_vm_export()->NotifyAll(peer);
return true;
}
Expand Down Expand Up @@ -1566,6 +1567,7 @@ void AgentXmppChannel::HandleAgentXmppClientChannelEvent(AgentXmppChannel *peer,
// For old config peer increment sequence number and remove
// entries
AgentIfMapXmppChannel::NewSeqNumber();
agent->ifmap_parser()->reset_statistics();
AgentXmppChannel::CleanConfigStale(peer);
}
}
Expand Down

0 comments on commit 98f5cea

Please sign in to comment.