summaryrefslogtreecommitdiff
path: root/orktrack/src/net/sf/oreka/orktrack/messages/TapeMessage.java
blob: 0db99d713a15965253d28fa32ed164fb413e2adc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*
 * Oreka -- A media capture and retrieval platform
 * 
 * Copyright (C) 2005, orecx LLC
 *
 * http://www.orecx.com
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License.
 * Please refer to http://www.gnu.org/copyleft/gpl.html
 *
 */

package net.sf.oreka.orktrack.messages;

import net.sf.oreka.Direction;
import net.sf.oreka.OrkException;
import net.sf.oreka.messages.AsyncMessage;
import net.sf.oreka.messages.SimpleResponseMessage;
import net.sf.oreka.messages.SyncMessage;
import net.sf.oreka.orktrack.LogManager;
import net.sf.oreka.orktrack.OrkTrack;
import net.sf.oreka.orktrack.ServiceManager;
import net.sf.oreka.orktrack.TapeManager;
import net.sf.oreka.persistent.Service;
import net.sf.oreka.serializers.OrkSerializer;
import net.sf.oreka.serializers.SingleLineSerializer;

import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.Transaction;

public class TapeMessage extends SyncMessage {

	public enum CaptureStage {START , STOP, COMPLETE, UNKN};
	
	Logger log = null;
	
	CaptureStage stage = CaptureStage.UNKN;
	int timestamp = 0;
	int duration = 0;
	String recId = "";
	String filename = "";
	String captureId = "";
	String capturePort = "";
	String localParty = "";
	String localEntryPoint = "";
	String remoteParty = "";
	Direction direction = Direction.UNKN;
	String loginString = "";
	String service = "";
	String srcIp = "";
	String dstIp = "";
	int srcTcpPort = 0;
	int dstTcpPort = 0;
	String srcMac = "";
	String dstMac = "";
	
	public TapeMessage() {
		log = LogManager.getInstance().getPortLogger();
	}
	
	public String getService() {
		return service;
	}

	public void setService(String service) {
		this.service = service;
	}

	@Override
	public AsyncMessage process() {

		SimpleResponseMessage response = new SimpleResponseMessage();
		Session session = null;
		Transaction tx = null;
		
		try {
			session = OrkTrack.hibernateManager.getSession();
	        tx = session.beginTransaction();
	        
	        SingleLineSerializer ser = new SingleLineSerializer();
	        log.info("Message: " + ser.serialize(this));
	        
			Service service = ServiceManager.retrieveOrCreate(this.service, this.getHostname(), session);
			
			//Port port = PortManager.instance().getAndCreatePort(this.getCapturePort(), session, service);
			//port.notifyTapeMessage(this, session, service);
			TapeManager.instance().notifyTapeMessage(this, session, service);
			
			response.setSuccess(true);
			tx.commit();
		}
		catch (Exception e) {
			log.error("TapeMessage.process: ", e);
			response.setSuccess(false);
			response.setComment(e.getMessage());
		}
		finally {
			if(session != null) {session.close();}
		}
		return response;
	}

	public void define(OrkSerializer serializer) throws OrkException {
		
		defineMessage(serializer);
		
		recId = serializer.stringValue("recid", recId, false);
		stage = (CaptureStage)serializer.enumValue("stage", stage, true);
		timestamp = serializer.intValue("timestamp", timestamp, true);
		duration = serializer.intValue("duration", duration, true);		
		filename = serializer.stringValue("filename", filename, true);
		capturePort = serializer.stringValue("captureport", capturePort, true);
		localParty = serializer.stringValue("localparty", localParty, false);
		localEntryPoint = serializer.stringValue("localentrypoint", localEntryPoint, false);
		remoteParty = serializer.stringValue("remoteparty", remoteParty, false);
		direction = (Direction)serializer.enumValue("direction", direction, false);
		loginString = serializer.stringValue("loginString", loginString, false);
		service = serializer.stringValue("service", service, true);
	}

	public String getOrkClassName() {
		return "tape";
	}

	public void validate() {
		// TODO Auto-generated method stub
		
	}

	public String getCapturePort() {
		return capturePort;
	}

	public void setCapturePort(String capturePort) {
		this.capturePort = capturePort;
	}

	public Direction getDirection() {
		return direction;
	}

	public void setDirection(Direction direction) {
		this.direction = direction;
	}

	public String getFilename() {
		return filename;
	}

	public void setFilename(String filename) {
		this.filename = filename;
	}

	public String getLocalEntryPoint() {
		return localEntryPoint;
	}

	public void setLocalEntryPoint(String localEntryPoint) {
		this.localEntryPoint = localEntryPoint;
	}

	public String getLocalParty() {
		return localParty;
	}

	public void setLocalParty(String localParty) {
		this.localParty = localParty;
	}

	public String getLoginString() {
		return loginString;
	}

	public void setLoginString(String loginString) {
		this.loginString = loginString;
	}

	public String getRemoteParty() {
		return remoteParty;
	}

	public void setRemoteParty(String remoteParty) {
		this.remoteParty = remoteParty;
	}

	public CaptureStage getStage() {
		return stage;
	}

	public void setStage(CaptureStage stage) {
		this.stage = stage;
	}

	public int getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(int timestamp) {
		this.timestamp = timestamp;
	}

	public int getDuration() {
		return duration;
	}

	public void setDuration(int duration) {
		this.duration = duration;
	}

	public String getCaptureId() {
		return captureId;
	}
	

	public void setCaptureId(String captureId) {
		this.captureId = captureId;
	}
	

	public String getDstIp() {
		return dstIp;
	}
	

	public void setDstIp(String dstIp) {
		this.dstIp = dstIp;
	}
	

	public String getDstMac() {
		return dstMac;
	}
	

	public void setDstMac(String dstMac) {
		this.dstMac = dstMac;
	}
	

	public int getDstTcpPort() {
		return dstTcpPort;
	}
	

	public void setDstTcpPort(int dstTcpPort) {
		this.dstTcpPort = dstTcpPort;
	}
	

	public String getSrcIp() {
		return srcIp;
	}
	

	public void setSrcIp(String srcIp) {
		this.srcIp = srcIp;
	}
	

	public String getSrcMac() {
		return srcMac;
	}
	

	public void setSrcMac(String srcMac) {
		this.srcMac = srcMac;
	}
	

	public int getSrcTcpPort() {
		return srcTcpPort;
	}
	

	public void setSrcTcpPort(int srcTcpPort) {
		this.srcTcpPort = srcTcpPort;
	}

	public String getRecId() {
		return recId;
	}
	

	public void setRecId(String recId) {
		this.recId = recId;
	}
	
	

}