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