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