blob: 06d8522b495838a1528e4b2ace0ee9171c82899f [file] [log] [blame]
Teru68076a42013-06-27 14:57:49 -07001package net.onrc.onos.ofcontroller.core;
2
3import static org.junit.Assert.*;
4
5import net.onrc.onos.graph.GraphDBConnection;
6import net.onrc.onos.graph.GraphDBOperation;
7import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
8import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
9import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
10import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
11import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
12import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager;
13import org.easymock.EasyMock;
14import org.junit.After;
15import org.junit.Before;
16import org.junit.Test;
17import org.junit.runner.RunWith;
18import org.powermock.api.easymock.PowerMock;
19import org.powermock.core.classloader.annotations.PrepareForTest;
20import org.slf4j.LoggerFactory;
21import org.powermock.modules.junit4.PowerMockRunner;
22
23import com.thinkaurelius.titan.core.TitanFactory;
24import com.thinkaurelius.titan.core.TitanGraph;
25
26//Add Powermock preparation
27@RunWith(PowerMockRunner.class)
28@PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, SwitchStorageImpl.class})
29public class INetMapTopologyObjectsIFlowEntryTest {
30
31 //The test network is ./titan/schema/test-network.xml
32
33 protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
34
35 String conf;
36 private GraphDBConnection conn = null;
37 private GraphDBOperation ope = null;
38 private TitanGraph titanGraph = null;
39 private IFlowEntry flowEntry = null;
40
41 @Before
42 public void setUp() throws Exception {
43 conf = "/dummy/path/to/db";
44
45 // Make mock cassandra DB
46 // Replace TitanFactory.open() to return mock DB
47 TestDatabaseManager.deleteTestDatabase();
48 titanGraph = TestDatabaseManager.getTestDatabase();
49 //TestDatabaseManager.populateTestData(titanGraph);
50 PowerMock.mockStatic(TitanFactory.class);
51 EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph);
52 PowerMock.replay(TitanFactory.class);
53
54 conn = GraphDBConnection.getInstance(conf);
55 ope = new GraphDBOperation(conn);
56
57 flowEntry = ope.newFlowEntry();
58 }
59
60 @After
61 public void tearDown() throws Exception {
62 titanGraph.shutdown();
63 TestDatabaseManager.deleteTestDatabase();
64 }
65
66 /**
67 * Desc:
68 * Test method for set and get FlowEntryId.
69 * Condition:
70 * N/A
71 * Expect:
72 * 1. Should set FlowEntryId.
73 * 2. Should get FlowEntryId.
74 */
75 @Test
76 public void testSetGetFlowEntryId() {
77 String flowEntryId = "xx";
78 flowEntry.setFlowEntryId(flowEntryId);
79 assertEquals(flowEntry.getFlowEntryId(), flowEntryId);
80 }
81
82 /**
83 * Desc:
84 * Test method for set and get SwitchDpid.
85 * Condition:
86 * N/A
87 * Expect:
88 * 1. Should set SwitchDpid.
89 * 2. Should get SwitchDpid.
90 */
91 @Test
92 public void testSetGetSwitchDpid() {
93 String switchDpid = "00:00:00:00:00:11";
94 flowEntry.setSwitchDpid(switchDpid);
95 assertEquals(flowEntry.getSwitchDpid(), switchDpid);
96 }
97
98 /**
99 * Desc:
100 * Test method for set and get UserState.
101 * Condition:
102 * N/A
103 * Expect:
104 * 1. Should set UserState.
105 * 2. Should get UserState.
106 */
107 @Test
108 public void testSetGetUserState() {
109 String userStete = "good";
110 flowEntry.setUserState(userStete);
111 assertEquals(flowEntry.getUserState(), userStete);
112 }
113
114 /**
115 * Desc:
116 * Test method for set and get SwitchState.
117 * Condition:
118 * N/A
119 * Expect:
120 * 1. Should set SwitchState.
121 * 2. Should get SwitchState.
122 */
123 @Test
124 public void testSetGetSwitchState() {
125 String switchStete = "ACTIVE";
126 flowEntry.setSwitchState(switchStete);
127 assertEquals(flowEntry.getSwitchState(), switchStete);
128 }
129
130 /**
131 * Desc:
132 * Test method for set and get ErrorStateType.
133 * Condition:
134 * N/A
135 * Expect:
136 * 1. Should set ErrorStateType.
137 * 2. Should get ErrorStateType.
138 */
139 @Test
140 public void testSetGetErrorStateType() {
141 String errorSteteType = "error";
142 flowEntry.setErrorStateType(errorSteteType);
143 assertEquals(flowEntry.getErrorStateType(), errorSteteType);
144 }
145
146 /**
147 * Desc:
148 * Test method for set and get ErrorStateCode.
149 * Condition:
150 * N/A
151 * Expect:
152 * 1. Should set ErrorStateCode.
153 * 2. Should get ErrorStateCode.
154 */
155 @Test
156 public void testSetGetErrorStateCode() {
157 String errorSteteCode = "error";
158 flowEntry.setErrorStateCode(errorSteteCode);
159 assertEquals(flowEntry.getErrorStateCode(), errorSteteCode);
160 }
161
162 /**
163 * Desc:
164 * Test method for set and get MatchInPort.
165 * Condition:
166 * N/A
167 * Expect:
168 * 1. Should set MatchInPort.
169 * 2. Should get MatchInPort.
170 */
171 @Test
172 public void testSetGetMatchInPort() {
173 Short inPort = 1;
174 flowEntry.setMatchInPort(inPort);
175 assertEquals(flowEntry.getMatchInPort(), inPort);
176 }
177
178 /**
179 * Desc:
Teru68076a42013-06-27 14:57:49 -0700180 * Test method for set and get MatchSrcMac.
181 * Condition:
182 * N/A
183 * Expect:
184 * 1. Should set MatchSrcMac.
185 * 2. Should get MatchSrcMac.
186 */
187 @Test
188 public void testSetGetMatchSrcMac() {
189 String matchSrcMac = "00:00:00:00:00:11";
190 flowEntry.setMatchSrcMac(matchSrcMac);
191 assertEquals(flowEntry.getMatchSrcMac(), matchSrcMac);
192 }
193
194 /**
195 * Desc:
196 * Test method for set and get MatchDstMac.
197 * Condition:
198 * N/A
199 * Expect:
200 * 1. Should set MatchDstMac.
201 * 2. Should get MatchDstMac.
202 */
203 @Test
204 public void testSetGetMatchDstMac() {
205 String matchDstMac = "00:00:00:00:00:11";
206 flowEntry.setMatchDstMac(matchDstMac);
207 assertEquals(flowEntry.getMatchDstMac(), matchDstMac);
208 }
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700209
210 /**
211 * Desc:
212 * Test method for set and get MatchEthernetFrameType.
213 * Condition:
214 * N/A
215 * Expect:
216 * 1. Should set MatchEthernetFrameType.
217 * 2. Should get MatchEthernetFrameType.
218 */
219 @Test
220 public void testSetGetMatchEthernetFrameType() {
221 Short matchEthernetFrameType = 1;
222 flowEntry.setMatchEthernetFrameType(matchEthernetFrameType);
223 assertEquals(flowEntry.getMatchEthernetFrameType(), matchEthernetFrameType);
224 }
225
226 /**
227 * Desc:
228 * Test method for set and get MatchVlanId.
229 * Condition:
230 * N/A
231 * Expect:
232 * 1. Should set MatchVlanId.
233 * 2. Should get MatchVlanId.
234 */
235 @Test
236 public void testSetGetMatchVlanId() {
237 Short matchVlanId = 10;
238 flowEntry.setMatchVlanId(matchVlanId);
239 assertEquals(flowEntry.getMatchVlanId(), matchVlanId);
240 }
241
242 /**
243 * Desc:
244 * Test method for set and get MatchVlanPriority.
245 * Condition:
246 * N/A
247 * Expect:
248 * 1. Should set MatchVlanPriority.
249 * 2. Should get MatchVlanPriority.
250 */
251 @Test
252 public void testSetGetMatchVlanPriority() {
253 Byte matchVlanPriority = 10;
254 flowEntry.setMatchVlanPriority(matchVlanPriority);
255 assertEquals(flowEntry.getMatchVlanPriority(), matchVlanPriority);
256 }
Teru68076a42013-06-27 14:57:49 -0700257
258 /**
259 * Desc:
260 * Test method for set and get SrcIPv4Net.
261 * Condition:
262 * N/A
263 * Expect:
264 * 1. Should set SrcIPv4Net.
265 * 2. Should get SrcIPv4Net.
266 */
267 @Test
268 public void testSetGetMatchSrcIPv4Net() {
269 String srcIPv4Net = "192.168.0.1";
270 flowEntry.setMatchSrcIPv4Net(srcIPv4Net);
271 assertEquals(flowEntry.getMatchSrcIPv4Net(), srcIPv4Net);
272 }
273
274 /**
275 * Desc:
276 * Test method for set and get MatchDstIPv4Net.
277 * Condition:
278 * N/A
279 * Expect:
280 * 1. Should set MatchDstIPv4Net.
281 * 2. Should get MatchDstIPv4Net.
282 */
283 @Test
284 public void testSetGetMatchDstIPv4Net() {
285 String dstIPv4Net = "192.168.0.1";
286 flowEntry.setMatchDstIPv4Net(dstIPv4Net);
287 assertEquals(flowEntry.getMatchDstIPv4Net(), dstIPv4Net);
288 }
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700289
290 /**
291 * Desc:
292 * Test method for set and get MatchIpProto.
293 * Condition:
294 * N/A
295 * Expect:
296 * 1. Should set MatchIpProto.
297 * 2. Should get MatchIpProto.
298 */
299 @Test
300 public void testSetGetMatchIpProto() {
301 Byte matchIpProto = 20;
302 flowEntry.setMatchIpProto(matchIpProto);
303 assertEquals(flowEntry.getMatchIpProto(), matchIpProto);
304 }
305
306 /**
307 * Desc:
308 * Test method for set and get MatchIpToS.
309 * Condition:
310 * N/A
311 * Expect:
312 * 1. Should set MatchIpToS.
313 * 2. Should get MatchIpToS.
314 */
315 @Test
316 public void testSetGetMatchIpToS() {
317 Byte matchIpToS = 20;
318 flowEntry.setMatchIpToS(matchIpToS);
319 assertEquals(flowEntry.getMatchIpToS(), matchIpToS);
320 }
321
322 /**
323 * Desc:
324 * Test method for set and get MatchSrcTcpUdpPort.
325 * Condition:
326 * N/A
327 * Expect:
328 * 1. Should set MatchSrcTcpUdpPort.
329 * 2. Should get MatchSrcTcpUdpPort.
330 */
331 @Test
332 public void testSetGetMatchSrcTcpUdpPort() {
333 Short srcTcpUdpPort = (short)65535;
334 flowEntry.setMatchSrcTcpUdpPort(srcTcpUdpPort);
335 assertEquals(flowEntry.getMatchSrcTcpUdpPort(), srcTcpUdpPort);
336 }
337
338 /**
339 * Desc:
340 * Test method for set and get MatchDstTcpUdpPort.
341 * Condition:
342 * N/A
343 * Expect:
344 * 1. Should set MatchDstTcpUdpPort.
345 * 2. Should get MatchDstTcpUdpPort.
346 */
347 @Test
348 public void testSetGetMatchDstTcpUdpPort() {
349 Short dstTcpUdpPort = (short)65535;
350 flowEntry.setMatchDstTcpUdpPort(dstTcpUdpPort);
351 assertEquals(flowEntry.getMatchDstTcpUdpPort(), dstTcpUdpPort);
352 }
Teru68076a42013-06-27 14:57:49 -0700353
354 /**
355 * Desc:
Pavlin Radoslavovc1bafd12013-07-12 17:00:35 -0700356 * Test method for set and get ActionOutputPort.
Teru68076a42013-06-27 14:57:49 -0700357 * Condition:
358 * N/A
359 * Expect:
Pavlin Radoslavovc1bafd12013-07-12 17:00:35 -0700360 * 1. Should set ActionOutputPort.
361 * 2. Should get ActionOutputPort.
Teru68076a42013-06-27 14:57:49 -0700362 */
363 @Test
Pavlin Radoslavovc1bafd12013-07-12 17:00:35 -0700364 public void testSetGetActionOutputPort() {
365 Short actionOutputPort = 1;
366 flowEntry.setActionOutputPort(actionOutputPort);
367 assertEquals(flowEntry.getActionOutputPort(), actionOutputPort);
Teru68076a42013-06-27 14:57:49 -0700368 }
369
370 /**
371 * Desc:
372 * Test method for set and get FlowPath.
373 * Condition:
374 * N/A
375 * Expect:
376 * 1. Should set FlowPath.
377 * 2. Should get FlowPath.
378 */
379 @Test
380 public void testSetGetFlowPath() {
381 IFlowPath fp = ope.newFlowPath();
382 String flowId = "xx";
383 fp.setFlowId(flowId);
384 flowEntry.setFlow(fp);
385 IFlowPath fp2 = flowEntry.getFlow();
386 assertEquals(fp2.getFlowId(), flowId);
387 }
388
389 /**
390 * Desc:
391 * Test method for set and get Switch.
392 * Condition:
393 * N/A
394 * Expect:
395 * 1. Should set Switch.
396 * 2. Should get Switch.
397 */
398 @Test
399 public void testSetGetSwitch() {
400 String dpid = "00:00:00:00:00:22";
401 ISwitchObject sw1 = ope.newSwitch(dpid);
402 flowEntry.setSwitch(sw1);
403 ISwitchObject sw2 = flowEntry.getSwitch();
404 assertEquals(sw2, sw1);
405 }
406
407 /**
408 * Desc:
409 * Test method for set and get InPort.
410 * Condition:
411 * N/A
412 * Expect:
413 * 1. Should set InPort.
414 * 2. Should get InPort.
415 */
416 @Test
417 public void testSetGetInPort() {
418 String dpid = "00:00:00:00:00:22";
419 Short portNum = 4;
420 IPortObject port1 = ope.newPort(dpid, portNum);
421 flowEntry.setInPort(port1);
422 IPortObject port2 = flowEntry.getInPort();
423 assertEquals(port2, port1);
424 }
425
426 /**
427 * Desc:
428 * Test method for set and get OutPort.
429 * Condition:
430 * N/A
431 * Expect:
432 * 1. Should set OutPort.
433 * 2. Should get OutPort.
434 */
435 @Test
436 public void testSetGetOutPort() {
437 String dpid = "00:00:00:00:00:22";
438 Short portNum = 4;
439 IPortObject port1 = ope.newPort(dpid, portNum);
440 flowEntry.setOutPort(port1);
441 IPortObject port2 = flowEntry.getOutPort();
442 assertEquals(port2, port1);
443 }
444}