blob: 4bfcf144f2b790b95878da715d5d1e0755df3751 [file] [log] [blame]
Toshio Koide9d8856e2013-06-12 16:48:11 -07001/**
2 *
3 */
4package net.onrc.onos.util;
5
6import static org.junit.Assert.*;
7
Toshio Koide880f4c72013-06-17 14:43:11 -07008import java.util.*;
Toshio Koide3c460e12013-06-13 11:55:12 -07009
Toshio Koide880f4c72013-06-17 14:43:11 -070010import junit.framework.TestCase;
11
12import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IDeviceObject;
13import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
14import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
15import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
Toshio Koideb29b9b32013-06-13 14:37:46 -070016import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
17import net.onrc.onos.ofcontroller.core.ISwitchStorage.SwitchState;
Toshio Koide880f4c72013-06-17 14:43:11 -070018import net.onrc.onos.ofcontroller.util.FlowEntryId;
19import net.onrc.onos.ofcontroller.util.FlowId;
Toshio Koide9d8856e2013-06-12 16:48:11 -070020import net.floodlightcontroller.core.internal.TestDatabaseManager;
Toshio Koide9d8856e2013-06-12 16:48:11 -070021
22import org.easymock.EasyMock;
23import org.junit.After;
24import org.junit.AfterClass;
25import org.junit.Before;
26import org.junit.BeforeClass;
27import org.junit.Test;
28import org.junit.runner.RunWith;
29import org.powermock.api.easymock.PowerMock;
30import org.powermock.core.classloader.annotations.PrepareForTest;
31import org.powermock.modules.junit4.PowerMockRunner;
32
33import com.thinkaurelius.titan.core.TitanFactory;
34import com.thinkaurelius.titan.core.TitanGraph;
Toshio Koide3c460e12013-06-13 11:55:12 -070035import com.tinkerpop.blueprints.Vertex;
Toshio Koide9d8856e2013-06-12 16:48:11 -070036
37/**
38 * @author Toshio Koide
39 *
40 */
Toshio Koide880f4c72013-06-17 14:43:11 -070041
Toshio Koide9d8856e2013-06-12 16:48:11 -070042@RunWith(PowerMockRunner.class)
43@PrepareForTest({TitanFactory.class})
Toshio Koide880f4c72013-06-17 14:43:11 -070044public class GraphDBOperationTest extends TestCase {
Toshio Koide3c460e12013-06-13 11:55:12 -070045 private static TitanGraph testdb;
Toshio Koide9d8856e2013-06-12 16:48:11 -070046 private static GraphDBConnection conn;
47 private static GraphDBOperation op;
48
49 /**
50 * @throws java.lang.Exception
51 */
52 @BeforeClass
53 public static void setUpBeforeClass() throws Exception {
54 }
55
56 /**
57 * @throws java.lang.Exception
58 */
59 @AfterClass
60 public static void tearDownAfterClass() throws Exception {
61 }
62
63 /**
64 * @throws java.lang.Exception
65 */
66 @Before
67 public void setUp() throws Exception {
68 TestDatabaseManager.deleteTestDatabase();
Toshio Koide3c460e12013-06-13 11:55:12 -070069 testdb = TestDatabaseManager.getTestDatabase();
Toshio Koide9d8856e2013-06-12 16:48:11 -070070// TestDatabaseManager.populateTestData(titanGraph);
Toshio Koide880f4c72013-06-17 14:43:11 -070071
72 String dummyPath = "/dummy/to/conf";
Toshio Koide9d8856e2013-06-12 16:48:11 -070073 // replace return value of TitanFactory.open() to dummy DB created above
74 PowerMock.mockStatic(TitanFactory.class);
Toshio Koide880f4c72013-06-17 14:43:11 -070075 EasyMock.expect(TitanFactory.open(dummyPath)).andReturn(testdb);
Toshio Koide9d8856e2013-06-12 16:48:11 -070076 PowerMock.replay(TitanFactory.class);
77
Toshio Koide880f4c72013-06-17 14:43:11 -070078 conn = GraphDBConnection.getInstance(dummyPath);
Toshio Koide9d8856e2013-06-12 16:48:11 -070079 op = new GraphDBOperation(conn);
80 }
81
82 /**
83 * @throws java.lang.Exception
84 */
85 @After
86 public void tearDown() throws Exception {
87 conn.close();
Toshio Koide3c460e12013-06-13 11:55:12 -070088 testdb.shutdown();
Toshio Koide880f4c72013-06-17 14:43:11 -070089 PowerMock.verifyAll();
Toshio Koide9d8856e2013-06-12 16:48:11 -070090 }
91
92 /**
93 * Test method for {@link net.onrc.onos.util.GraphDBOperation#newSwitch(net.onrc.onos.util.GraphDBConnection)}.
94 */
95 @Test
96 public final void testNewSwitch() {
Toshio Koide880f4c72013-06-17 14:43:11 -070097 assertNull(op.searchSwitch("123"));
Toshio Koide9d8856e2013-06-12 16:48:11 -070098
Toshio Koide880f4c72013-06-17 14:43:11 -070099 op.newSwitch("123");
Toshio Koidea9a03002013-06-13 13:10:48 -0700100 op.commit();
Toshio Koide9d8856e2013-06-12 16:48:11 -0700101
Toshio Koide880f4c72013-06-17 14:43:11 -0700102 ISwitchObject sw = op.searchSwitch("123");
103 assertNotNull(op);
104 assertEquals("123", sw.getDPID());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700105 }
106
107 /**
108 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchSwitch(net.onrc.onos.util.GraphDBConnection, java.lang.String)}.
109 */
110 @Test
111 public final void testSearchSwitch() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700112 op.newSwitch("123");
113 op.newSwitch("456");
Toshio Koidea9a03002013-06-13 13:10:48 -0700114 op.commit();
Toshio Koide880f4c72013-06-17 14:43:11 -0700115
116 ISwitchObject sw = op.searchSwitch("123");
Toshio Koide3c460e12013-06-13 11:55:12 -0700117 assertNotNull(sw);
118 assertEquals("123", sw.getDPID());
Toshio Koide880f4c72013-06-17 14:43:11 -0700119
120 sw = op.searchSwitch("789");
121 assertNull(sw);
Toshio Koide3c460e12013-06-13 11:55:12 -0700122 }
123
124 /**
125 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchActiveSwitch(net.onrc.onos.util.GraphDBConnection, java.lang.String)}.
126 */
127 @Test
128 public final void testSearchActiveSwitch() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700129 op.newSwitch("111").setState(SwitchState.ACTIVE.toString());
130 op.newSwitch("222").setState(SwitchState.INACTIVE.toString());
Toshio Koidea9a03002013-06-13 13:10:48 -0700131 op.commit();
132
Toshio Koide880f4c72013-06-17 14:43:11 -0700133 ISwitchObject sw = op.searchActiveSwitch("111");
Toshio Koide3c460e12013-06-13 11:55:12 -0700134 assertNotNull(sw);
135 assertEquals("111", sw.getDPID());
136
137 sw = op.searchActiveSwitch("222");
138 assertNull(sw);
139 }
140
141 /**
142 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getActiveSwitches(net.onrc.onos.util.GraphDBConnection)}.
143 */
144 @Test
145 public final void testGetActiveSwitches() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700146 op.newSwitch("111").setState(SwitchState.ACTIVE.toString());
147 op.newSwitch("222").setState(SwitchState.INACTIVE.toString());
Toshio Koidea9a03002013-06-13 13:10:48 -0700148 op.commit();
Toshio Koide3c460e12013-06-13 11:55:12 -0700149
150 Iterator<ISwitchObject> i = op.getActiveSwitches().iterator();
Toshio Koide880f4c72013-06-17 14:43:11 -0700151
Toshio Koide3c460e12013-06-13 11:55:12 -0700152 assertTrue(i.hasNext());
153 assertEquals("111", i.next().getDPID());
Toshio Koide880f4c72013-06-17 14:43:11 -0700154 assertFalse(i.hasNext());
155 }
156
157 /**
158 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllSwitches(net.onrc.onos.util.GraphDBConnection)}.
159 */
160 @Test
161 public final void testGetAllSwitches() {
162 List<String> dpids = Arrays.asList("111", "222", "333");
163 Collections.sort(dpids);
164
165 for (String dpid: dpids) op.newSwitch(dpid);
166 op.commit();
167
168 List<String> actual_ids = new ArrayList<String>();
169 for (ISwitchObject switchObj: op.getAllSwitches()) actual_ids.add(switchObj.getDPID());
170 Collections.sort(actual_ids);
171
172 assertArrayEquals(dpids.toArray(), actual_ids.toArray());
173 }
174
175 /**
176 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getInactiveSwitches(net.onrc.onos.util.GraphDBConnection)}.
177 */
178 @Test
179 public final void testGetInactiveSwitches() {
180 op.newSwitch("111").setState(SwitchState.ACTIVE.toString());
181 op.newSwitch("222").setState(SwitchState.INACTIVE.toString());
182 op.commit();
183
184 Iterator<ISwitchObject> i = op.getInactiveSwitches().iterator();
185
186 assertTrue(i.hasNext());
187 assertEquals("222", i.next().getDPID());
188 assertFalse(i.hasNext());
189 }
190
191 /**
192 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllSwitchNotUpdatedFlowEntries(net.onrc.onos.util.GraphDBConnection)}.
193 */
194 @Test
195 public final void testGetAllSwitchNotUpdatedFlowEntries() {
196 FlowEntryId flowEntryId10 = new FlowEntryId(10);
197 FlowEntryId flowEntryId20 = new FlowEntryId(20);
198 IFlowEntry flowEntry10 = op.newFlowEntry();
199 IFlowEntry flowEntry20 = op.newFlowEntry();
200 flowEntry10.setFlowEntryId(flowEntryId10.toString());
201 flowEntry20.setFlowEntryId(flowEntryId20.toString());
202 flowEntry10.setSwitchState("FE_SWITCH_NOT_UPDATED");
203 flowEntry20.setSwitchState("FE_SWITCH_UPDATED");
204 op.commit();
205
206 Iterator<IFlowEntry> flowEntries = op.getAllSwitchNotUpdatedFlowEntries().iterator();
207 assertNotNull(flowEntries);
208 assertTrue(flowEntries.hasNext());
209 assertEquals(flowEntryId10.toString(), flowEntries.next().getFlowEntryId());
210 assertFalse(flowEntries.hasNext());
Toshio Koide3c460e12013-06-13 11:55:12 -0700211 }
212
213 /**
214 * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeSwitch(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject)}.
215 */
216 @Test
217 public final void testRemoveSwitch() {
218 ISwitchObject sw = op.newSwitch("123");
Toshio Koidea9a03002013-06-13 13:10:48 -0700219 op.commit();
Toshio Koide3c460e12013-06-13 11:55:12 -0700220 sw = op.searchSwitch("123");
Toshio Koide880f4c72013-06-17 14:43:11 -0700221 assertNotNull(sw);
222
Toshio Koide3c460e12013-06-13 11:55:12 -0700223 op.removeSwitch(sw);
Toshio Koide880f4c72013-06-17 14:43:11 -0700224 op.commit();
225
226 assertNull(op.searchSwitch("123"));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700227 }
228
229 /**
230 * Test method for {@link net.onrc.onos.util.GraphDBOperation#newPort(net.onrc.onos.util.GraphDBConnection)}.
231 */
232 @Test
233 public final void testNewPort() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700234 assertFalse(testdb.getVertices("type", "port").iterator().hasNext());
235
236 IPortObject port = op.newPort((short) 10);
237 assertTrue(port.getNumber() == 10);
238 op.commit();
239
240 Iterator<Vertex> vertices = testdb.getVertices("type", "port").iterator();
241 assertTrue(vertices.hasNext());
242 assertEquals(vertices.next().getProperty("number").toString(), "10");
Toshio Koide9d8856e2013-06-12 16:48:11 -0700243 }
244
245 /**
Toshio Koide880f4c72013-06-17 14:43:11 -0700246 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchPort(net.onrc.onos.util.GraphDBConnection, java.lang.String, short)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700247 */
248 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700249 public final void testSearchPort() {
250 ISwitchObject sw;
251 IPortObject port;
252
253 sw = op.newSwitch("1");
254 sw.addPort(op.newPort((short) 1));
255 sw.addPort(op.newPort((short) 2));
256
257 sw = op.newSwitch("2");
258 sw.addPort(op.newPort((short) 1));
259 sw.addPort(op.newPort((short) 2));
260
261 op.commit();
262
263 assertNull(op.searchPort("3", (short) 1));
264 assertNull(op.searchPort("1", (short) 3));
265
266 port = op.searchPort("1", (short) 1);
267 assertNotNull(port);
268 assertTrue(port.getNumber() == 1);
269 sw = port.getSwitch();
270 assertNotNull(sw);
271 assertEquals("1", sw.getDPID());
272
273 port = op.searchPort("1", (short) 2);
274 assertNotNull(port);
275 assertTrue(port.getNumber() == 2);
276 sw = port.getSwitch();
277 assertNotNull(sw);
278 assertEquals("1", sw.getDPID());
279
280 port = op.searchPort("2", (short) 1);
281 assertNotNull(port);
282 assertTrue(port.getNumber() == 1);
283 sw = port.getSwitch();
284 assertNotNull(sw);
285 assertEquals("2", sw.getDPID());
286
287 port = op.searchPort("2", (short) 2);
288 assertNotNull(port);
289 assertTrue(port.getNumber() == 2);
290 sw = port.getSwitch();
291 assertNotNull(sw);
292 assertEquals("2", sw.getDPID());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700293 }
294
295 /**
296 * Test method for {@link net.onrc.onos.util.GraphDBOperation#removePort(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IPortObject)}.
297 */
298 @Test
299 public final void testRemovePort() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700300 ISwitchObject sw;
301 IPortObject port;
302
303 sw = op.newSwitch("1");
304 sw.addPort(op.newPort((short) 1));
305 sw.addPort(op.newPort((short) 2));
306
307 op.commit();
308
309 port = op.searchPort("1", (short) 1);
310 assertNotNull(port);
311 assertNotNull(op.searchPort("1", (short) 2));
312 assertNull(op.searchPort("1", (short) 3));
313
314 op.removePort(port);
315 op.commit();
316
317 assertNull(op.searchPort("1", (short) 1));
318 port = op.searchPort("1", (short) 2);
319 assertNotNull(port);
320
321 op.removePort(port);
322 op.commit();
323
324 assertNull(op.searchPort("1", (short) 1));
325 assertNull(op.searchPort("1", (short) 2));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700326 }
327
328 /**
Toshio Koide880f4c72013-06-17 14:43:11 -0700329 * Test method for {@link net.onrc.onos.util.GraphDBOperation#newDevice(net.onrc.onos.util.GraphDBConnection)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700330 */
331 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700332 public final void testNewDevice() {
333 assertFalse(testdb.getVertices("type", "device").iterator().hasNext());
334
335 IDeviceObject device = op.newDevice();
336 device.setMACAddress("11:22:33:44:55:66");
337 device.setIPAddress("192.168.1.1");
338 op.commit();
339
340 Iterator<Vertex> vertices = testdb.getVertices("type", "device").iterator();
341 assertTrue(vertices.hasNext());
342 Vertex v = vertices.next();
343 assertEquals("11:22:33:44:55:66", v.getProperty("dl_addr").toString());
344 assertEquals("192.168.1.1", v.getProperty("nw_addr").toString());
345 }
346
347 /**
348 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchDevice(net.onrc.onos.util.GraphDBConnection, java.lang.String)}.
349 */
350 @Test
351 public final void testSearchDevice() {
352 assertNull(op.searchDevice("11:22:33:44:55:66"));
353 assertNull(op.searchDevice("66:55:44:33:22:11"));
354
355 op.newDevice().setMACAddress("11:22:33:44:55:66");
356 op.commit();
357
358 IDeviceObject device = op.searchDevice("11:22:33:44:55:66");
359 assertNotNull(device);
360 assertEquals("11:22:33:44:55:66", device.getMACAddress());
361
362 assertNull(op.searchDevice("66:55:44:33:22:11"));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700363 }
364
365 /**
366 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getDevices(net.onrc.onos.util.GraphDBConnection)}.
367 */
368 @Test
369 public final void testGetDevices() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700370 List<String> original_macs = Arrays.asList(
371 "11:11:11:11:11:11",
372 "22:22:22:22:22:22",
373 "33:33:33:33:33:33"
374 );
375
376 for (String mac: original_macs) op.newDevice().setMACAddress(mac);
377 op.commit();
378
379 Iterable<IDeviceObject> devices = op.getDevices();
380 List<String> macs = new ArrayList<String>();
381 for (IDeviceObject device: devices) macs.add(device.getMACAddress());
382 Collections.sort(macs);
383 assertArrayEquals(original_macs.toArray(), macs.toArray());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700384 }
385
386 /**
Toshio Koide880f4c72013-06-17 14:43:11 -0700387 * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeDevice(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IDeviceObject)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700388 */
389 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700390 public final void testRemoveDevice() {
391 op.newDevice().setMACAddress("11:22:33:44:55:66");
392 op.commit();
393
394 op.removeDevice(op.searchDevice("11:22:33:44:55:66"));
395 op.commit();
396 assertNull(op.searchDevice("11:22:33:44:55:66"));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700397 }
398
399 /**
400 * Test method for {@link net.onrc.onos.util.GraphDBOperation#newFlowPath(net.onrc.onos.util.GraphDBConnection)}.
401 */
402 @Test
403 public final void testNewFlowPath() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700404 FlowId flowId = new FlowId(10);
405 IFlowPath flowPath = op.newFlowPath();
406 flowPath.setFlowId(flowId.toString());
407 op.commit();
408
409 Iterator<IFlowPath> flows = op.getAllFlowPaths().iterator();
410 assertTrue(flows.hasNext());
411 assertEquals(flowId.toString(), flows.next().getFlowId());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700412 }
413
414 /**
Toshio Koide880f4c72013-06-17 14:43:11 -0700415 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchFlowPath(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.util.FlowId)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700416 */
417 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700418 public final void testSearchFlowPath() {
419 FlowId flowId = new FlowId(20);
420 assertNull(op.searchFlowPath(flowId));
421
422 op.newFlowPath().setFlowId(flowId.toString());
423 op.commit();
424
425 IFlowPath flowPath = op.searchFlowPath(flowId);
426 assertNotNull(flowPath);
427 assertEquals(flowId.toString(), flowPath.getFlowId());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700428 }
429
430 /**
431 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getFlowPathByFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry)}.
432 */
433 @Test
434 public final void testGetFlowPathByFlowEntry() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700435 FlowId flowId10 = new FlowId(10);
436 FlowId flowId20 = new FlowId(20);
437 IFlowPath flowPath10 = op.newFlowPath();
438 IFlowPath flowPath20 = op.newFlowPath();
439 IFlowEntry flowEntry10 = op.newFlowEntry();
440 IFlowEntry flowEntry20 = op.newFlowEntry();
441 IFlowEntry flowEntry30 = op.newFlowEntry();
442 FlowEntryId flowEntryId10 = new FlowEntryId(10);
443 FlowEntryId flowEntryId20 = new FlowEntryId(20);
444 FlowEntryId flowEntryId30 = new FlowEntryId(30);
445 flowEntry10.setFlowEntryId(flowEntryId10.toString());
446 flowEntry20.setFlowEntryId(flowEntryId20.toString());
447 flowEntry30.setFlowEntryId(flowEntryId30.toString());
448 flowPath10.setFlowId(flowId10.toString());
449 flowPath10.addFlowEntry(flowEntry10);
450 flowPath20.setFlowId(flowId20.toString());
451 flowPath20.addFlowEntry(flowEntry20);
452 op.commit();
453
454 flowEntry10 = op.searchFlowEntry(flowEntryId10);
455 IFlowPath obtainedFlowPath = op.getFlowPathByFlowEntry(flowEntry10);
456 assertNotNull(obtainedFlowPath);
457 assertEquals(flowId10.toString(), obtainedFlowPath.getFlowId());
458
459 flowEntry20 = op.searchFlowEntry(flowEntryId20);
460 obtainedFlowPath = op.getFlowPathByFlowEntry(flowEntry20);
461 assertNotNull(obtainedFlowPath);
462 assertEquals(flowId20.toString(), obtainedFlowPath.getFlowId());
463
464 flowEntry30 = op.searchFlowEntry(flowEntryId30);
465 obtainedFlowPath = op.getFlowPathByFlowEntry(flowEntry30);
466 assertNull(obtainedFlowPath);
Toshio Koide9d8856e2013-06-12 16:48:11 -0700467 }
468
469 /**
470 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllFlowPaths(net.onrc.onos.util.GraphDBConnection)}.
471 */
472 @Test
473 public final void testGetAllFlowPaths() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700474 List<FlowId> flowids = Arrays.asList(
475 new FlowId(10), new FlowId(20), new FlowId(30)
476 );
477
478 for (FlowId flowId: flowids)
479 op.newFlowPath().setFlowId(flowId.toString());
480 op.commit();
481
482 List<String> actual_ids = new ArrayList<String>();
483 for (IFlowPath flowPath: op.getAllFlowPaths()) actual_ids.add(flowPath.getFlowId());
484 Collections.sort(actual_ids);
485
486 List<String> expected_ids = new ArrayList<String>();
487 for (FlowId flowid: flowids) expected_ids.add(flowid.toString());
488 Collections.sort(expected_ids);
489
490 assertArrayEquals(expected_ids.toArray(), actual_ids.toArray());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700491 }
492
493 /**
Toshio Koide880f4c72013-06-17 14:43:11 -0700494 * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeFlowPath(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700495 */
496 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700497 public final void testRemoveFlowPath() {
498 FlowId flowId10 = new FlowId(10);
499 FlowId flowId20 = new FlowId(20);
500 op.newFlowPath().setFlowId(flowId10.toString());
501 op.newFlowPath().setFlowId(flowId20.toString());
502 op.commit();
503
504 IFlowPath flowPath = op.searchFlowPath(flowId10);
505 assertNotNull(flowPath);
506 op.removeFlowPath(flowPath);
507 op.commit();
508
509 assertNull(op.searchFlowPath(flowId10));
510 assertNotNull(op.searchFlowPath(flowId20));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700511 }
512
513 /**
514 * Test method for {@link net.onrc.onos.util.GraphDBOperation#newFlowEntry(net.onrc.onos.util.GraphDBConnection)}.
515 */
516 @Test
517 public final void testNewFlowEntry() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700518 IFlowEntry flowEntry = op.newFlowEntry();
519 FlowEntryId flowEntryId = new FlowEntryId();
520 flowEntryId.setValue(12345);
521 flowEntry.setFlowEntryId(flowEntryId.toString());
522 op.commit();
523
524 flowEntry = op.searchFlowEntry(flowEntryId);
525 assertNotNull(flowEntry);
526 assertEquals(flowEntry.getFlowEntryId(), flowEntryId.toString());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700527 }
528
529 /**
Toshio Koide880f4c72013-06-17 14:43:11 -0700530 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.util.FlowEntryId)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700531 */
532 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700533 public final void testSearchFlowEntry() {
534 FlowEntryId flowEntryId10 = new FlowEntryId();
535 flowEntryId10.setValue(10);
536 FlowEntryId flowEntryId20 = new FlowEntryId();
537 flowEntryId20.setValue(20);
538 FlowEntryId flowEntryId30 = new FlowEntryId();
539 flowEntryId30.setValue(30);
540
541 op.newFlowEntry().setFlowEntryId(flowEntryId10.toString());
542 op.newFlowEntry().setFlowEntryId(flowEntryId20.toString());
543 op.commit();
544
545 assertNull(op.searchFlowEntry(flowEntryId30));
546 IFlowEntry flowEntry = op.searchFlowEntry(flowEntryId10);
547 assertEquals(flowEntry.getFlowEntryId(), flowEntryId10.toString());
548 flowEntry = op.searchFlowEntry(flowEntryId20);
549 assertEquals(flowEntry.getFlowEntryId(), flowEntryId20.toString());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700550 }
551
552 /**
553 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllFlowEntries(net.onrc.onos.util.GraphDBConnection)}.
554 */
555 @Test
556 public final void testGetAllFlowEntries() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700557 List<FlowEntryId> flowEntryIds = Arrays.asList(
558 new FlowEntryId(10), new FlowEntryId(20), new FlowEntryId(30)
559 );
560
561 for (FlowEntryId flowEntryId: flowEntryIds)
562 op.newFlowEntry().setFlowEntryId(flowEntryId.toString());
563 op.commit();
564
565 List<String> actual_ids = new ArrayList<String>();
566 for (IFlowEntry flowEntry: op.getAllFlowEntries()) actual_ids.add(flowEntry.getFlowEntryId());
567 Collections.sort(actual_ids);
568
569 List<String> expected_ids = new ArrayList<String>();
570 for (FlowEntryId flowEntryId: flowEntryIds) expected_ids.add(flowEntryId.toString());
571 Collections.sort(expected_ids);
572
573 assertArrayEquals(expected_ids.toArray(), actual_ids.toArray());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700574 }
575
576 /**
Toshio Koide880f4c72013-06-17 14:43:11 -0700577 * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700578 */
579 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700580 public final void testRemoveFlowEntry() {
581 FlowEntryId flowEntryId10 = new FlowEntryId(10);
582 FlowEntryId flowEntryId20 = new FlowEntryId(20);
583 op.newFlowEntry().setFlowEntryId(flowEntryId10.toString());
584 op.newFlowEntry().setFlowEntryId(flowEntryId20.toString());
585 op.commit();
586
587 IFlowEntry flowEntry = op.searchFlowEntry(flowEntryId10);
588 assertNotNull(flowEntry);
589 op.removeFlowEntry(flowEntry);
590 op.commit();
591
592 assertNull(op.searchFlowEntry(flowEntryId10));
593 assertNotNull(op.searchFlowEntry(flowEntryId20));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700594 }
595
Toshio Koide9d8856e2013-06-12 16:48:11 -0700596}