Line data Source code
1 : /*
2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3 : */
4 :
5 : #ifndef __AGENT_MIRROR_CFG_H__
6 : #define __AGENT_MIRROR_CFG_H__
7 :
8 : #include <map>
9 : #include <cmn/agent_cmn.h>
10 : #include <cmn/agent.h>
11 : #include <agent_types.h>
12 :
13 : class MirrorCfgDisplayResp;
14 : struct MirrorCfgKey {
15 : std::string handle;
16 : };
17 :
18 : struct MirrorCfgData {
19 0 : MirrorCfgData() :
20 0 : apply_vn(), src_vn(), src_ip_prefix(), src_ip_prefix_len(0),
21 0 : dst_vn(), dst_ip_prefix(), dst_ip_prefix_len(0), start_src_port(0),
22 0 : end_src_port(0), start_dst_port(0), end_dst_port(0), protocol(0),
23 0 : ip(), udp_port(0), time_period(60) {};
24 0 : ~MirrorCfgData() {};
25 :
26 : std::string apply_vn;
27 : std::string src_vn;
28 : std::string src_ip_prefix;
29 : int src_ip_prefix_len;
30 :
31 : // Destination
32 : std::string dst_vn;
33 : std::string dst_ip_prefix;
34 : int dst_ip_prefix_len;
35 :
36 : // -1 on both start and end means any
37 : // if there is no end_src_port, end_src_port will be same as start_src_port
38 : int start_src_port;
39 : int end_src_port;
40 :
41 : // Dest port, -1 means any
42 : // if there is no end_dst_port, end_dst_port will be same as start_dst_port
43 : int start_dst_port;
44 : int end_dst_port;
45 :
46 : // Protocol, -1 means any
47 : int protocol;
48 :
49 : // Mirror destination
50 : std::string ip;
51 : int udp_port;
52 : // Time period for mirroring in seconds
53 : int time_period;
54 : std::string mirror_vrf;
55 : };
56 :
57 : struct AceInfo {
58 0 : AceInfo() : acl_id(boost::uuids::nil_uuid()), id(0) {}
59 :
60 : boost::uuids::uuid acl_id;
61 : int id;
62 : };
63 :
64 : struct MirrorCfgEntry {
65 : MirrorCfgKey key;
66 : MirrorCfgData data;
67 : AceInfo ace_info;
68 : };
69 :
70 : struct MirrorCfgKeyCmp {
71 0 : bool operator()(const MirrorCfgKey &lhs, const MirrorCfgKey &rhs) const {
72 0 : return lhs.handle < rhs.handle;
73 : }
74 : };
75 :
76 : struct AclIdInfo {
77 0 : AclIdInfo() :
78 0 : id(boost::uuids::nil_uuid()), num_of_entries(0), ace_id_latest(0) {}
79 :
80 : boost::uuids::uuid id;
81 : int num_of_entries;
82 : int ace_id_latest;
83 : };
84 :
85 : class MirrorCfgTable {
86 : public:
87 : typedef std::string VnIdStr;
88 : typedef boost::uuids::uuid AclUuid;
89 : // Config Tree
90 : typedef std::map<MirrorCfgKey, MirrorCfgEntry *, MirrorCfgKeyCmp> MirrorCfgTree;
91 : typedef std::map<VnIdStr, AclIdInfo> VnAclMap;
92 :
93 3 : MirrorCfgTable(AgentConfig *cfg) :
94 3 : agent_cfg_(cfg), mc_tree_(), vn_acl_map_() {};
95 3 : ~MirrorCfgTable() {};
96 :
97 : void Shutdown();
98 : void Init();
99 : void SetMirrorCfgSandeshData(std::string &handle,
100 : MirrorCfgDisplayResp &resp);
101 : void SetMirrorCfgVnSandeshData(std::string &vn_name,
102 : MirrorCfgVnInfoResp &resp);
103 : const boost::uuids::uuid GetMirrorUuid(const std::string &vn_name) const;
104 :
105 : const char *Add(const MirrorCreateReq &cfg);
106 : void Delete(MirrorCfgKey &key);
107 : private:
108 : AgentConfig *agent_cfg_;
109 : MirrorCfgTree mc_tree_;
110 : VnAclMap vn_acl_map_;
111 :
112 : const char *UpdateAclEntry(AclUuid &id, bool create, MirrorCfgEntry *e,
113 : int ace_id);
114 :
115 : DISALLOW_COPY_AND_ASSIGN(MirrorCfgTable);
116 : };
117 :
118 : struct MirrorDestination {
119 : std::string handle;
120 : IpAddress sip;
121 : uint16_t sport;
122 : // Mirror destination
123 : IpAddress dip;
124 : uint16_t dport;
125 : // Time period for mirroring in seconds
126 : int time_period;
127 : std::string mirror_vrf;
128 : };
129 :
130 : struct IntfMirrorCfgData {
131 0 : IntfMirrorCfgData() : intf_id(boost::uuids::nil_uuid()) {}
132 :
133 : boost::uuids::uuid intf_id;
134 : std::string intf_name;
135 : MirrorDestination mirror_dest;
136 : };
137 :
138 : struct IntfMirrorCfgEntry {
139 : MirrorCfgKey key;
140 : IntfMirrorCfgData data;
141 : };
142 :
143 : class IntfMirrorCfgTable {
144 : public:
145 3 : IntfMirrorCfgTable(AgentConfig *cfg) : agent_cfg_(cfg) {};
146 3 : ~IntfMirrorCfgTable() {};
147 : typedef std::map<MirrorCfgKey, IntfMirrorCfgEntry *, MirrorCfgKeyCmp> IntfMirrorCfgTree;
148 : const char *Add(const IntfMirrorCreateReq &cfg);
149 : void Delete(MirrorCfgKey &key);
150 : IntfMirrorCfgTable *CreateIntfMirrorCfgTable();
151 : void Init();
152 : void Shutdown();
153 : void SetIntfMirrorCfgSandeshData(std::string &handle,
154 : IntfMirrorCfgDisplayResp &resp);
155 : private:
156 : AgentConfig *agent_cfg_;
157 : IntfMirrorCfgTree intf_mc_tree_;
158 : DISALLOW_COPY_AND_ASSIGN(IntfMirrorCfgTable);
159 : };
160 :
161 : #endif // __AGENT_MIRROR_CFG_H__
|