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 : #ifndef __DB_IFMAP_AGENT_PARSER_H__ 7 : #define __DB_IFMAP_AGENT_PARSER_H__ 8 : 9 : #include <list> 10 : #include <map> 11 : #include <boost/function.hpp> 12 : #include "db/db.h" 13 : #include "ifmap/ifmap_object.h" 14 : #include "ifmap/ifmap_table.h" 15 : 16 : namespace pugi { 17 : class xml_document; 18 : class xml_node; 19 : } // namespace pugi 20 : 21 : class IFMapAgentParser { 22 : public: 23 : 24 : enum ConfigMsgType { 25 : UPDATE, 26 : DEL, 27 : MAX 28 : }; 29 : 30 17 : IFMapAgentParser(DB *db) : db_(db) { reset_statistics(); } ; 31 : 32 : typedef boost::function< IFMapObject *(const pugi::xml_node, DB *, 33 : std::string *id_name) > NodeParseFn; 34 : typedef std::map<std::string, NodeParseFn> NodeParseMap; 35 : void NodeRegister(const std::string &node, NodeParseFn parser); 36 : void NodeClear(); 37 : void ConfigParse(const pugi::xml_node config, uint64_t seq); 38 0 : uint64_t node_updates() { return nodes_processed_[UPDATE]; } 39 0 : uint64_t node_deletes() { return nodes_processed_[DEL]; } 40 0 : uint64_t link_updates() { return links_processed_[UPDATE]; } 41 0 : uint64_t link_deletes() { return links_processed_[DEL]; } 42 0 : uint64_t node_update_parse_errors() { return node_parse_errors_[UPDATE]; } 43 0 : uint64_t node_delete_parse_errors() { return node_parse_errors_[DEL]; } 44 0 : uint64_t link_update_parse_errors() { return link_parse_errors_[UPDATE]; } 45 0 : uint64_t link_delete_parse_errors() { return link_parse_errors_[DEL]; } 46 36 : void reset_statistics() { 47 36 : nodes_processed_[UPDATE] = 0; 48 36 : nodes_processed_[DEL] = 0; 49 36 : links_processed_[UPDATE] = 0; 50 36 : links_processed_[DEL] = 0; 51 36 : node_parse_errors_[UPDATE] = 0; 52 36 : node_parse_errors_[DEL] = 0; 53 36 : link_parse_errors_[UPDATE] = 0; 54 36 : link_parse_errors_[DEL] = 0; 55 36 : } 56 : private: 57 : DB *db_; 58 : NodeParseMap node_map_; 59 : uint64_t nodes_processed_[MAX]; 60 : uint64_t links_processed_[MAX]; 61 : uint64_t node_parse_errors_[MAX]; 62 : uint64_t link_parse_errors_[MAX]; 63 : void NodeParse(pugi::xml_node &node, DBRequest::DBOperation oper, uint64_t seq); 64 : void LinkParse(pugi::xml_node &node, DBRequest::DBOperation oper, uint64_t seq); 65 : }; 66 : 67 : #endif