blob: bb0dbbfb8cd14516e857a4128df913beccb23fc8 [file] [log] [blame]
Teru68076a42013-06-27 14:57:49 -07001package net.onrc.onos.ofcontroller.core;
2
3import static org.junit.Assert.*;
4
5import java.util.ArrayList;
6import java.util.HashMap;
7
8import net.onrc.onos.graph.GraphDBConnection;
9import net.onrc.onos.graph.GraphDBOperation;
10import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
11import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
12import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
13import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
14import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager;
15import org.easymock.EasyMock;
16import org.junit.After;
17import org.junit.Before;
18import org.junit.Test;
19import org.junit.runner.RunWith;
20import org.powermock.api.easymock.PowerMock;
21import org.powermock.core.classloader.annotations.PrepareForTest;
22import org.slf4j.LoggerFactory;
23import org.powermock.modules.junit4.PowerMockRunner;
24
25import com.thinkaurelius.titan.core.TitanFactory;
26import com.thinkaurelius.titan.core.TitanGraph;
27
28//Add Powermock preparation
29@RunWith(PowerMockRunner.class)
30@PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, SwitchStorageImpl.class})
31public class INetMapTopologyObjectsIFlowPathTest {
32
33 //The test network is ./titan/schema/test-network.xml
34
35 protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
36
37 String conf;
38 private GraphDBConnection conn = null;
39 private GraphDBOperation ope = null;
40 private TitanGraph titanGraph = null;
41 private IFlowPath flowPath = null;
42 private IFlowEntry flowEntry = null;
43
44 @Before
45 public void setUp() throws Exception {
46 conf = "/dummy/path/to/db";
47
48 // Make mock cassandra DB
49 // Replace TitanFactory.open() to return mock DB
50 TestDatabaseManager.deleteTestDatabase();
51 titanGraph = TestDatabaseManager.getTestDatabase();
52 //TestDatabaseManager.populateTestData(titanGraph);
53 PowerMock.mockStatic(TitanFactory.class);
54 EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph);
55 PowerMock.replay(TitanFactory.class);
56
57 conn = GraphDBConnection.getInstance(conf);
58 ope = new GraphDBOperation(conn);
59
60 flowPath = ope.newFlowPath();
61 flowEntry = ope.newFlowEntry();
62 flowEntry.setState("zz");
63 }
64
65 @After
66 public void tearDown() throws Exception {
67 titanGraph.shutdown();
68 TestDatabaseManager.deleteTestDatabase();
69 }
70
71 /**
72 * Desc:
73 * Test method for get and set FlowId method.
74 * Condition:
75 * N/A
76 * Expect:
77 * 1. Should set the flow id.
78 * 2. Should get the flow id.
79 */
80 @Test
81 public void testSetGetFlowId() {
82 String flowId = "xx";
83 flowPath.setFlowId(flowId);
84 assertEquals(flowPath.getFlowId(), flowId);
85 }
86
87 /**
88 * Desc:
89 * Test method for get and set InstallerId method.
90 * Condition:
91 * N/A
92 * Expect:
93 * 1. Should set the installer id.
94 * 2. Should get the installer id.
95 */
96 @Test
97 public void testSetGetInstallerId() {
98 String flowId = "xx";
99 String installerId = "yy";
100 flowPath.setFlowId(flowId);
101 flowPath.setInstallerId(installerId);
102 assertEquals(flowPath.getInstallerId(), installerId);
103 }
104
105 /**
106 * Desc:
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700107 * Test method for get and set FlowPathFlags method.
108 * Condition:
109 * N/A
110 * Expect:
111 * 1. Should set the Flow Path Flags.
112 * 2. Should get the Flow Path Flags.
113 */
114 @Test
115 public void testSetGetFlowPathFlags() {
116 String flowId = "xx";
117 Long flowPathFlags = new Long(0x3);
118 flowPath.setFlowId(flowId);
119 flowPath.setFlowPathFlags(flowPathFlags);
120 assertEquals(flowPath.getFlowPathFlags(), flowPathFlags);
121 }
122
123 /**
124 * Desc:
Teru68076a42013-06-27 14:57:49 -0700125 * Test method for get and set SourceSwitch method.
126 * Condition:
127 * N/A
128 * Expect:
129 * 1. Should set the source switch.
130 * 2. Should get the source switch.
131 */
132 @Test
133 public void testSetGetSourceSwitch() {
134 String flowId = "xx";
135 String sourceSwitch = "aa";
136 flowPath.setFlowId(flowId);
137 flowPath.setSrcSwitch(sourceSwitch);
138 assertEquals(flowPath.getSrcSwitch(), sourceSwitch);
139 }
140
141 /**
142 * Desc:
143 * Test method for get and set SourcePort method.
144 * Condition:
145 * N/A
146 * Expect:
147 * 1. Should set the source port.
148 * 2. Should get the source port.
149 */
150 @Test
151 public void testSetGetSourcePort() {
152 String flowId = "xx";
153 Short sourcePort = 1;
154 flowPath.setFlowId(flowId);
155 flowPath.setSrcPort(sourcePort);
156 assertEquals(flowPath.getSrcPort(), sourcePort);
157 }
158
159 /**
160 * Desc:
161 * Test method for get and set DestSwitch method.
162 * Condition:
163 * N/A
164 * Expect:
165 * 1. Should set the dest switch.
166 * 2. Should get the dest switch.
167 */
168 @Test
169 public void testSetGetDestSwitch() {
170 String flowId = "xx";
171 String destSwitch = "bb";
172 flowPath.setFlowId(flowId);
173 flowPath.setDstSwitch(destSwitch);
174 assertEquals(flowPath.getDstSwitch(), destSwitch);
175 }
176
177 /**
178 * Desc:
179 * Test method for get and set DestPort method.
180 * Condition:
181 * N/A
182 * Expect:
183 * 1. Should set the source dest port.
184 * 2. Should get the source dest port.
185 */
186 @Test
187 public void testSetGetDstPort() {
188 String flowId = "xx";
189 Short dstPort = 2;
190 flowPath.setFlowId(flowId);
191 flowPath.setDstPort(dstPort);
192 assertEquals(flowPath.getDstPort(), dstPort);
193 }
194
195 /**
196 * Desc:
197 * Test method for get and set DataPathSummary method.
198 * Condition:
199 * N/A
200 * Expect:
201 * 1. Should set the data path summary.
202 * 2. Should get the data path summary.
203 */
204 @Test
205 public void testSetGetDataPathSummary() {
206 String flowId = "xx";
207 String dataPathSummary = "yy";
208 flowPath.setFlowId(flowId);
209 flowPath.setInstallerId(dataPathSummary);
210 assertEquals(flowPath.getInstallerId(), dataPathSummary);
211 }
212
213 public boolean testIFlowEntry(IFlowPath fp, IFlowEntry fe)
214 {
215 ArrayList<IFlowEntry> flowEntryList = new ArrayList<IFlowEntry>();
216 for(IFlowEntry inFlowEntry : fp.getFlowEntries())
217 {
218 flowEntryList.add(inFlowEntry);
219 }
220 return flowEntryList.contains(fe);
221 }
222
223 /**
224 * Desc:
225 * Test method for addFlowEntry and getFlorEntries method.
226 * Condition:
227 * N/A
228 * Expect:
229 * 1. Should add the FlowEntry.
230 * 2. Should get the FlowEntries. It is tested in the testIFlowEntry method.
231 */
232 @Test
233 public void testAddFlowEntryAndGetFlowEntries() {
234 String flowId = "xx";
235 flowPath.setFlowId(flowId);
236 flowPath.addFlowEntry(flowEntry);
237 IFlowEntry flowEntry2 = ope.newFlowEntry();
238 flowPath.addFlowEntry(flowEntry2);
239 assertTrue(testIFlowEntry(flowPath, flowEntry));
240 assertTrue(testIFlowEntry(flowPath, flowEntry2));
241 }
242
243 /**
244 * Desc:
245 * Test method for remove FlowEntry.
246 * Condition:
247 * N/A
248 * Expect:
249 * 1. Should remove FlowEntry.
250 */
251 @Test
252 public void testRemoveFlowEntry() {
253 String flowId = "xx";
254 flowPath.setFlowId(flowId);
255 flowPath.addFlowEntry(flowEntry);
256 flowPath.removeFlowEntry(flowEntry);
257 assertTrue(!testIFlowEntry(flowPath, flowEntry));
258 }
259
260 /**
261 * Desc:
Teru68076a42013-06-27 14:57:49 -0700262 * Test method for set and get MatchSrcMac
263 * Condition:
264 * N/A
265 * Expect:
266 * 1. Should set MatchSrcMac.
267 * 2. Should get MatchSrcMac.
268 */
269 @Test
270 public void testSetGetMatchSrcMac() {
271 String flowId = "xx";
272 String matchSrcMac = "00:00:00:00:00:11";
273 flowPath.setFlowId(flowId);
274 flowPath.setMatchSrcMac(matchSrcMac);
275 assertEquals(flowPath.getMatchSrcMac(), matchSrcMac);
276 }
277
278 /**
279 * Desc:
280 * Test method for set and get MatchDstMac.
281 * Condition:
282 * N/A
283 * Expect:
284 * 1. Should set MatchDstMac.
285 * 2. Should get MatchDstMac.
286 */
287 @Test
288 public void testSetGetMatchDstMac() {
289 String flowId = "xx";
290 String matchDstMac = "00:00:00:00:00:11";
291 flowPath.setFlowId(flowId);
292 flowPath.setMatchDstMac(matchDstMac);
293 assertEquals(flowPath.getMatchDstMac(), matchDstMac);
294 }
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700295
Teru68076a42013-06-27 14:57:49 -0700296 /**
297 * Desc:
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700298 * Test method for set and get MatchEthernetFrameType
Teru68076a42013-06-27 14:57:49 -0700299 * Condition:
300 * N/A
301 * Expect:
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700302 * 1. Should set MatchEthernetFrameType.
303 * 2. Should get MatchEthernetFrameType.
304 */
305 @Test
306 public void testSetGetMatchEthernetFrameType() {
307 String flowId = "xx";
308 Short matchEthernetFrameType = 1;
309 flowPath.setFlowId(flowId);
310 flowPath.setMatchEthernetFrameType(matchEthernetFrameType);
311 assertEquals(flowPath.getMatchEthernetFrameType(), matchEthernetFrameType);
312 }
313
314 /**
315 * Desc:
316 * Test method for set and get MatchVlanId
317 * Condition:
318 * N/A
319 * Expect:
320 * 1. Should set MatchVlanId.
321 * 2. Should get MatchVlanId.
322 */
323 @Test
324 public void testSetGetMatchVlanId() {
325 String flowId = "xx";
326 Short matchVlanId = 10;
327 flowPath.setFlowId(flowId);
328 flowPath.setMatchVlanId(matchVlanId);
329 assertEquals(flowPath.getMatchVlanId(), matchVlanId);
330 }
331
332 /**
333 * Desc:
334 * Test method for set and get MatchVlanPriority
335 * Condition:
336 * N/A
337 * Expect:
338 * 1. Should set MatchVlanPriority.
339 * 2. Should get MatchVlanPriority.
340 */
341 @Test
342 public void testSetGetMatchVlanPriority() {
343 String flowId = "xx";
344 Byte matchVlanPriority = 20;
345 flowPath.setFlowId(flowId);
346 flowPath.setMatchVlanPriority(matchVlanPriority);
347 assertEquals(flowPath.getMatchVlanPriority(), matchVlanPriority);
348 }
349
350 /**
351 * Desc:
352 * Test method for set and get MatchSrcIPv4Net.
353 * Condition:
354 * N/A
355 * Expect:
356 * 1. Should set MatchSrcIPv4Net.
357 * 2. Should get MatchSrcIPv4Net.
Teru68076a42013-06-27 14:57:49 -0700358 */
359 @Test
360 public void testSetGetMatchSrcIPv4Net() {
361 String flowId = "xx";
362 String ip = "192.168.0.1";
363 flowPath.setFlowId(flowId);
364 flowPath.setMatchSrcIPv4Net(ip);
365 assertEquals(flowPath.getMatchSrcIPv4Net(), ip);
366 }
367
368 /**
369 * Desc:
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700370 * Test method for set and get MatchDstIPv4Net.
Teru68076a42013-06-27 14:57:49 -0700371 * Condition:
372 * N/A
373 * Expect:
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700374 * 1. Should set MatchDstIPv4Net.
375 * 2. Should get MatchDstIPv4Net.
Teru68076a42013-06-27 14:57:49 -0700376 */
377 @Test
378 public void testSetGetMatchDstIPv4Net() {
379 String flowId = "xx";
380 String ip = "192.168.0.1";
381 flowPath.setFlowId(flowId);
382 flowPath.setMatchDstIPv4Net(ip);
383 assertEquals(flowPath.getMatchDstIPv4Net(), ip);
384 }
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700385
386 /**
387 * Desc:
388 * Test method for set and get MatchIpProto
389 * Condition:
390 * N/A
391 * Expect:
392 * 1. Should set MatchIpProto.
393 * 2. Should get MatchIpProto.
394 */
395 @Test
396 public void testSetGetMatchIpProto() {
397 String flowId = "xx";
398 Byte matchIpProto = 20;
399 flowPath.setFlowId(flowId);
400 flowPath.setMatchIpProto(matchIpProto);
401 assertEquals(flowPath.getMatchIpProto(), matchIpProto);
402 }
403
404 /**
405 * Desc:
406 * Test method for set and get MatchIpToS
407 * Condition:
408 * N/A
409 * Expect:
410 * 1. Should set MatchIpToS.
411 * 2. Should get MatchIpToS.
412 */
413 @Test
414 public void testSetGetMatchIpToS() {
415 String flowId = "xx";
416 Byte matchIpToS = 20;
417 flowPath.setFlowId(flowId);
418 flowPath.setMatchIpToS(matchIpToS);
419 assertEquals(flowPath.getMatchIpToS(), matchIpToS);
420 }
421
422 /**
423 * Desc:
424 * Test method for set and get MatchSrcTcpUdpPort.
425 * Condition:
426 * N/A
427 * Expect:
428 * 1. Should set MatchSrcTcpUdpPort.
429 * 2. Should get MatchSrcTcpUdpPort.
430 */
431 @Test
432 public void testSetGetMatchSrcTcpUdpPort() {
433 String flowId = "xx";
434 Short srcTcpUdpPort = (short)65535;
435 flowPath.setFlowId(flowId);
436 flowPath.setMatchSrcTcpUdpPort(srcTcpUdpPort);
437 assertEquals(flowPath.getMatchSrcTcpUdpPort(), srcTcpUdpPort);
438 }
439
440 /**
441 * Desc:
442 * Test method for set and get MatchDstTcpUdpPort.
443 * Condition:
444 * N/A
445 * Expect:
446 * 1. Should set MatchDstTcpUdpPort.
447 * 2. Should get MatchDstTcpUdpPort.
448 */
449 @Test
450 public void testSetGetMatchDstTcpUdpPort() {
451 String flowId = "xx";
452 Short dstTcpUdpPort = (short)65535;
453 flowPath.setFlowId(flowId);
454 flowPath.setMatchDstTcpUdpPort(dstTcpUdpPort);
455 assertEquals(flowPath.getMatchDstTcpUdpPort(), dstTcpUdpPort);
456 }
457
Teru68076a42013-06-27 14:57:49 -0700458 /**
459 * Desc:
460 * Test method for set and get UserState.
461 * Condition:
462 * N/A
463 * Expect:
464 * 1. Should set UserState.
465 * 2. Should get UserState.
466 */
467 @Test
468 public void testSetGetUserState() {
469 String flowId = "xx";
470 String userStatus = "Good";
471 flowPath.setFlowId(flowId);
472 flowPath.setUserState(userStatus);
473 assertEquals(flowPath.getUserState(), userStatus);
474 }
475
476 /**
477 * Desc:
478 * Test method for get Switches.
479 * Condition:
480 * N/A
481 * Expect:
482 * 1. Should get switches.
483 */
484 @Test
485 public void testGetSwitches() {
486 String flowId = "xx";
487 String dpid = "1";
488 flowPath.setFlowId(flowId);
489 ISwitchObject sw = ope.newSwitch(dpid);
490 flowEntry.setSwitch(sw);
491 flowPath.addFlowEntry(flowEntry);
492
493 HashMap<String, ISwitchObject> swList = new HashMap<String, ISwitchObject>();
494 for(ISwitchObject insw : flowPath.getSwitches()){
495 swList.put(sw.getDPID(), insw);
496 }
497
498 assertTrue(swList.containsKey(dpid));
499 }
500
501 //TODO Dont know how to set the state property.
502 @Test
503 public void testGetState() {
504 String status = null;
505 assertEquals(flowPath.getState(), status);
506 }
507
508
509}