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 __RULEENG_H__
7 : #define __RULEENG_H__
8 :
9 : #include "viz_message.h"
10 : #include "ruleparser/t_ruleparser.h"
11 : #include "base/task.h"
12 : #include "gendb_if.h"
13 :
14 : class DbHandler;
15 : class OpServerProxy;
16 :
17 : class Ruleeng {
18 : public:
19 : static int RuleBuilderID;
20 : static int RuleWorkerID;
21 :
22 : Ruleeng(DbHandlerPtr, OpServerProxy *);
23 : virtual ~Ruleeng();
24 :
25 : void Init();
26 : bool Buildrules(const std::string& rulesrc, const std::string& rulebuf);
27 : bool Parserules(char *, size_t len);
28 : bool Parserules(const char *, int len);
29 :
30 0 : void add_rulesrc(const std::string& rulesrc) {
31 0 : rulesrc_.push_back(rulesrc);
32 0 : }
33 :
34 : bool rule_present(const VizMsg *vmsgp);
35 :
36 : bool rule_execute(const VizMsg *vmsgp, bool uveproc, DbHandler *db,
37 : GenDb::GenDbIf::DbAddColumnCb db_cb);
38 :
39 : void print(std::ostream& os) {
40 : rulelist_->print(os);
41 : }
42 :
43 : OpServerProxy * GetOSP() { return osp_; }
44 : private:
45 : DbHandlerPtr db_handler_;
46 : OpServerProxy *osp_;
47 : t_rulelist *rulelist_;
48 : std::vector<std::string> rulesrc_;
49 :
50 : bool handle_uve_publish(const pugi::xml_node& parent,
51 : const VizMsg *rmsg, DbHandler *db, const SandeshHeader &header,
52 : GenDb::GenDbIf::DbAddColumnCb db_cb);
53 :
54 : bool handle_uve_statistics(const pugi::xml_node& parent,
55 : const VizMsg *rmsg, DbHandler *db, const SandeshHeader &header,
56 : GenDb::GenDbIf::DbAddColumnCb db_cb);
57 :
58 : bool handle_flow_object(const pugi::xml_node& parent, DbHandler *db,
59 : const SandeshHeader &header, GenDb::GenDbIf::DbAddColumnCb db_cb);
60 :
61 : bool handle_session_object(const pugi::xml_node& parent, DbHandler *db,
62 : const SandeshHeader &header, GenDb::GenDbIf::DbAddColumnCb db_cb);
63 :
64 : void handle_object_log(const pugi::xml_node& parent,
65 : const VizMsg *rmsg, DbHandler *db, const SandeshHeader &header,
66 : DbHandler::ObjectNamesVec *object_names,
67 : GenDb::GenDbIf::DbAddColumnCb db_cb);
68 :
69 : void remove_identifier(const pugi::xml_node& parent);
70 : };
71 :
72 : class Builder : public Task {
73 : public:
74 0 : Builder(Ruleeng *re, const std::string& rulesrc, const std::string& rulebuf) : Task(Ruleeng::RuleBuilderID), re_(re), rulesrc_(rulesrc), rulebuf_(rulebuf) { }
75 0 : ~Builder() { }
76 :
77 0 : virtual bool Run() {
78 0 : re_->add_rulesrc(rulesrc_);
79 0 : re_->Parserules(rulebuf_.c_str(), rulebuf_.size());
80 0 : return true;
81 : }
82 0 : std::string Description() const { return "Builder"; }
83 :
84 : private:
85 : Ruleeng *re_;
86 : std::string rulesrc_;
87 : std::string rulebuf_;
88 : };
89 :
90 :
91 :
92 : #endif
|