1 | /** |
---|
2 | * @file CommonTrafficCaptureMessages.h |
---|
3 | * This header file defines simple data message used in communication with the |
---|
4 | * TrafficCapture application. |
---|
5 | * @author Tomas Urban |
---|
6 | * @version 0.3 |
---|
7 | * @date 23/07/2009 |
---|
8 | */ |
---|
9 | #ifndef COMMON_TRAFFIC_CAPTURE_MESSAGES_H |
---|
10 | #define COMMON_TRAFFIC_CAPTURE_MESSAGES_H |
---|
11 | #include "TrafficCaptureMessageId.h" |
---|
12 | #include "TrafficCaptureMessage.h" |
---|
13 | #include <vector> |
---|
14 | |
---|
15 | /** |
---|
16 | * This class describes a request containing command to start message capture. |
---|
17 | */ |
---|
18 | class StartCaptureRequest : public TrafficCaptureMessage |
---|
19 | { |
---|
20 | public: |
---|
21 | StartCaptureRequest() {} |
---|
22 | virtual ~StartCaptureRequest() {} |
---|
23 | virtual unsigned short GetId() const { return START_CAPTURE_REQ; } |
---|
24 | }; |
---|
25 | |
---|
26 | /** |
---|
27 | * This class describes a reply to a request for starting message capture. |
---|
28 | */ |
---|
29 | class StartCaptureReply : public CommonReplyMessage |
---|
30 | { |
---|
31 | public: |
---|
32 | StartCaptureReply() {} |
---|
33 | virtual ~StartCaptureReply() {} |
---|
34 | virtual unsigned short GetId() const { return START_CAPTURE_REP; } |
---|
35 | }; |
---|
36 | |
---|
37 | /** |
---|
38 | * This class describes a request containing command to stop message capture. |
---|
39 | */ |
---|
40 | class StopCaptureRequest : public TrafficCaptureMessage |
---|
41 | { |
---|
42 | public: |
---|
43 | StopCaptureRequest() {} |
---|
44 | virtual ~StopCaptureRequest() {} |
---|
45 | virtual unsigned short GetId() const { return STOP_CAPTURE_REQ; } |
---|
46 | }; |
---|
47 | |
---|
48 | /** |
---|
49 | * This class describes a reply to a request for stopping message capture. |
---|
50 | */ |
---|
51 | class StopCaptureReply : public CommonReplyMessage |
---|
52 | { |
---|
53 | public: |
---|
54 | StopCaptureReply() {} |
---|
55 | virtual ~StopCaptureReply() {} |
---|
56 | virtual unsigned short GetId() const { return STOP_CAPTURE_REP; } |
---|
57 | }; |
---|
58 | |
---|
59 | /** |
---|
60 | * This class describes a request used for initialization of traffic capture. |
---|
61 | */ |
---|
62 | class OpenDeviceRequest : public TrafficCaptureMessage |
---|
63 | { |
---|
64 | private: |
---|
65 | ECaptureType m_captureType; |
---|
66 | ECaptureMode m_captureMode; |
---|
67 | timeval m_timestamp; |
---|
68 | std::string m_sParams; |
---|
69 | std::string m_sCaptureFile; |
---|
70 | protected: |
---|
71 | virtual unsigned int CalculateDataLength(); |
---|
72 | virtual void EncodePayload(unsigned int & nOffset); |
---|
73 | virtual bool DecodePayload(const char * pPayload, unsigned int nPayloadLength, unsigned int & nOffset); |
---|
74 | public: |
---|
75 | OpenDeviceRequest(); |
---|
76 | virtual ~OpenDeviceRequest() {} |
---|
77 | virtual unsigned short GetId() const { return OPEN_DEVICE_REQ; } |
---|
78 | /** |
---|
79 | * Returns the requested capture type. |
---|
80 | * @return Requested capture type |
---|
81 | */ |
---|
82 | ECaptureType GetCaptureType() const { return m_captureType; } |
---|
83 | /** |
---|
84 | * Sets the requested capture type. |
---|
85 | * @param captureType Requested capture type |
---|
86 | */ |
---|
87 | void SetCaptureType(ECaptureType captureType); |
---|
88 | /** |
---|
89 | * Returns the requested capture mode. |
---|
90 | * @return Requested capture mode |
---|
91 | */ |
---|
92 | ECaptureMode GetCaptureMode() const { return m_captureMode; } |
---|
93 | /** |
---|
94 | * Sets the requested capture mode. |
---|
95 | * @param captureMode Requested capture mode |
---|
96 | */ |
---|
97 | void SetCaptureMode(ECaptureMode captureMode); |
---|
98 | /** |
---|
99 | * Returns the requested timestamp for time-based filter. If the returned value is equal to zero, |
---|
100 | * no time-based filtering will occur. |
---|
101 | * @return Timestamp for time-based filter |
---|
102 | */ |
---|
103 | struct timeval GetTimestamp() const { return m_timestamp; } |
---|
104 | /** |
---|
105 | * Sets the timestamp for time-based filter. If the timestamp value is equal to zero, no |
---|
106 | * time-based filtering will occur. |
---|
107 | * @param timestamp Timestamp for time-based filter |
---|
108 | */ |
---|
109 | void SetTimestamp(struct timeval timestamp); |
---|
110 | /** |
---|
111 | * Returns the parameter string used for initializing capturing device. |
---|
112 | * @return Start-up parameters for capturing device |
---|
113 | */ |
---|
114 | std::string GetParameters() const { return m_sParams; } |
---|
115 | /** |
---|
116 | * Sets the parameter string used for initializing capturing devices. The string format |
---|
117 | * is device specific. Please check the documentation of supported devices for more details. |
---|
118 | * @param sParams Start-up parameters for capturing device |
---|
119 | */ |
---|
120 | void SetParameters(const std::string & sParams); |
---|
121 | /** |
---|
122 | * Returns the name of the file into which captured packets should be saved. Only devices |
---|
123 | * using live capture are capable of saving data into files. |
---|
124 | * @return Path to the capture file or empty string if no data should be saved |
---|
125 | */ |
---|
126 | std::string GetCaptureFile() const { return m_sCaptureFile; } |
---|
127 | /** |
---|
128 | * Sets the name of the file into which captured packets should be saved. Only devices |
---|
129 | * using live capture are capable of saving data into files. |
---|
130 | * @param sFile Path to the capture file or empty string if no data should be saved |
---|
131 | */ |
---|
132 | void SetCaptureFile(const std::string & sFile); |
---|
133 | }; |
---|
134 | |
---|
135 | /** |
---|
136 | * This class describes a reply to a traffic capture initialization request. |
---|
137 | */ |
---|
138 | class OpenDeviceReply : public TrafficCaptureMessage |
---|
139 | { |
---|
140 | private: |
---|
141 | ECaptureInitResult m_result; |
---|
142 | protected: |
---|
143 | virtual unsigned int CalculateDataLength(); |
---|
144 | virtual void EncodePayload(unsigned int & nOffset); |
---|
145 | virtual bool DecodePayload(const char * pPayload, unsigned int nPayloadLength, unsigned int & nOffset); |
---|
146 | public: |
---|
147 | OpenDeviceReply(); |
---|
148 | virtual ~OpenDeviceReply() {} |
---|
149 | virtual unsigned short GetId() const { return OPEN_DEVICE_REP; } |
---|
150 | /** |
---|
151 | * The method returns the result of the operation. |
---|
152 | * @return Operation result |
---|
153 | */ |
---|
154 | ECaptureInitResult GetResult() const { return m_result; } |
---|
155 | /** |
---|
156 | * The method sets the result of the operation. The default value is #ECaptureInit_Failed. |
---|
157 | * @param result Operation result |
---|
158 | */ |
---|
159 | void SetResult(ECaptureInitResult result); |
---|
160 | }; |
---|
161 | |
---|
162 | /** |
---|
163 | * This class describes a request used for setting a data filter. |
---|
164 | */ |
---|
165 | class SetFilterRequest : public TrafficCaptureMessage |
---|
166 | { |
---|
167 | private: |
---|
168 | std::string m_sFilter; |
---|
169 | protected: |
---|
170 | virtual unsigned int CalculateDataLength(); |
---|
171 | virtual void EncodePayload(unsigned int & nOffset); |
---|
172 | virtual bool DecodePayload(const char * pPayload, unsigned int nPayloadLength, unsigned int & nOffset); |
---|
173 | public: |
---|
174 | SetFilterRequest() {} |
---|
175 | virtual ~SetFilterRequest() {} |
---|
176 | virtual unsigned short GetId() const { return SET_FILTER_REQ; } |
---|
177 | |
---|
178 | /** |
---|
179 | * Gets requested filter parameters. If the string is empty, no filter shall be applied. |
---|
180 | * @return Filter parameters |
---|
181 | */ |
---|
182 | std::string GetFilter() const { return m_sFilter; } |
---|
183 | /** |
---|
184 | * Sets filter parameters. If no filtering should occur, the string shall be empty. The string format |
---|
185 | * is device specific. Please check the documentation of supported devices for more details. |
---|
186 | * @param sFilter Filter parameters |
---|
187 | */ |
---|
188 | void SetFilter(const std::string & sFilter); |
---|
189 | }; |
---|
190 | |
---|
191 | /** |
---|
192 | * This class describes a reply to a filtering request. |
---|
193 | */ |
---|
194 | class SetFilterReply : public CommonReplyMessage |
---|
195 | { |
---|
196 | public: |
---|
197 | SetFilterReply() {} |
---|
198 | virtual ~SetFilterReply() {} |
---|
199 | virtual unsigned short GetId() const { return SET_FILTER_REP; } |
---|
200 | }; |
---|
201 | |
---|
202 | /** |
---|
203 | * This class describes a merging request. This request is used for merging several pcap files |
---|
204 | * into one. If the operation is successful, the path to the file containing merged data is |
---|
205 | * returned by a subsequent response. |
---|
206 | */ |
---|
207 | class MergePcapFilesRequest : public TrafficCaptureMessage |
---|
208 | { |
---|
209 | private: |
---|
210 | std::string m_sMergePath, m_sMergecapPath; |
---|
211 | std::vector<std::string> m_vsMergeFiles; |
---|
212 | protected: |
---|
213 | virtual unsigned int CalculateDataLength(); |
---|
214 | virtual void EncodePayload(unsigned int & nOffset); |
---|
215 | virtual bool DecodePayload(const char * pPayload, unsigned int nPayloadLength, unsigned int & nOffset); |
---|
216 | public: |
---|
217 | MergePcapFilesRequest() {} |
---|
218 | virtual ~MergePcapFilesRequest() {} |
---|
219 | virtual unsigned short GetId() const { return MERGE_FILES_REQ; } |
---|
220 | /** |
---|
221 | * Sets the path to the directory where the mergecap tool is installed. |
---|
222 | * @param sPath Path to mergecap installation directory |
---|
223 | */ |
---|
224 | void SetMergecapDirectory(const std::string & sPath); |
---|
225 | /** |
---|
226 | * Returns path to the directory where the mergecap tool is installed. |
---|
227 | * @return Path to mergecap installation directory |
---|
228 | */ |
---|
229 | std::string GetMergecapDirectory() {return m_sMergecapPath; } |
---|
230 | /** |
---|
231 | * Sets the source data for the file merging operation. |
---|
232 | * @param sMergePath Path to the directory containing files to merge. This directory |
---|
233 | * is also used for storing the merged file. |
---|
234 | * @param vsMergeFiles Vector containing files to merge |
---|
235 | **/ |
---|
236 | void SetMergeSource(const std::string & sMergePath, const std::vector<std::string> & vsMergeFiles); |
---|
237 | /** |
---|
238 | * Returns the path to the directory containing files to merge. This directory |
---|
239 | * will be also used for storing the merged file. |
---|
240 | * @return Path of files to merge |
---|
241 | */ |
---|
242 | std::string GetMergePath() const { return m_sMergePath; } |
---|
243 | /** |
---|
244 | * Returns a vector containing files to merge. |
---|
245 | * @return Files to merge |
---|
246 | */ |
---|
247 | std::vector<std::string> GetFilesToMerge() const { return m_vsMergeFiles; } |
---|
248 | }; |
---|
249 | |
---|
250 | /** |
---|
251 | * This class describes a reply to a merging request. |
---|
252 | */ |
---|
253 | class MergePcapFilesReply : public CommonReplyMessage |
---|
254 | { |
---|
255 | private: |
---|
256 | std::string m_sMergeFile; |
---|
257 | protected: |
---|
258 | virtual unsigned int CalculateDataLength(); |
---|
259 | virtual void EncodePayload(unsigned int & nOffset); |
---|
260 | virtual bool DecodePayload(const char * pPayload, unsigned int nPayloadLength, unsigned int & nOffset); |
---|
261 | public: |
---|
262 | MergePcapFilesReply() {} |
---|
263 | virtual ~MergePcapFilesReply() {} |
---|
264 | virtual unsigned short GetId() const { return MERGE_FILES_REP; } |
---|
265 | /** |
---|
266 | * Sets a path to the merge file. The path shall be set only in case of successful reply. |
---|
267 | * @param sMergeFile Path to the merge file |
---|
268 | */ |
---|
269 | void SetMergeFile(const std::string & sMergeFile); |
---|
270 | /** |
---|
271 | * Return a path to the merge file. In case of successful reply, this path shall be used as |
---|
272 | * a parameter in a subsequent #OpenDeviceRequest for opening an offline pcap device. Refer to |
---|
273 | * #OpenDeviceRequest::SetParameters() for more details. |
---|
274 | * @return Path to the merge file |
---|
275 | */ |
---|
276 | std::string GetMergeFile() { return m_sMergeFile; } |
---|
277 | }; |
---|
278 | |
---|
279 | #endif |
---|