blob: f85cc4f10e4cb7d7805651d76244179dfb7f731f [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
Pankaj Berde38646d62013-06-21 11:34:04 -070012import net.onrc.onos.graph.GraphDBOperation;
Toshio Koide880f4c72013-06-17 14:43:11 -070013import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IDeviceObject;
14import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
15import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
16import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
Toshio Koideb29b9b32013-06-13 14:37:46 -070017import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
18import net.onrc.onos.ofcontroller.core.ISwitchStorage.SwitchState;
HIGUCHI Yuta08137932013-06-17 14:11:50 -070019import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager;
Toshio Koide880f4c72013-06-17 14:43:11 -070020import net.onrc.onos.ofcontroller.util.FlowEntryId;
21import net.onrc.onos.ofcontroller.util.FlowId;
Toshio Koide9d8856e2013-06-12 16:48:11 -070022
23import org.easymock.EasyMock;
24import org.junit.After;
25import org.junit.AfterClass;
26import org.junit.Before;
27import org.junit.BeforeClass;
28import org.junit.Test;
29import org.junit.runner.RunWith;
30import org.powermock.api.easymock.PowerMock;
31import org.powermock.core.classloader.annotations.PrepareForTest;
32import org.powermock.modules.junit4.PowerMockRunner;
33
34import com.thinkaurelius.titan.core.TitanFactory;
35import com.thinkaurelius.titan.core.TitanGraph;
Toshio Koide3c460e12013-06-13 11:55:12 -070036import com.tinkerpop.blueprints.Vertex;
Toshio Koide9d8856e2013-06-12 16:48:11 -070037
38/**
39 * @author Toshio Koide
40 *
41 */
Toshio Koide880f4c72013-06-17 14:43:11 -070042
Toshio Koide9d8856e2013-06-12 16:48:11 -070043@RunWith(PowerMockRunner.class)
44@PrepareForTest({TitanFactory.class})
Toshio Koide880f4c72013-06-17 14:43:11 -070045public class GraphDBOperationTest extends TestCase {
Toshio Koide3c460e12013-06-13 11:55:12 -070046 private static TitanGraph testdb;
Toshio Koide9d8856e2013-06-12 16:48:11 -070047 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 Koidebfe9b922013-06-18 10:56:05 -070078 op = new GraphDBOperation(dummyPath);
Toshio Koide9d8856e2013-06-12 16:48:11 -070079 }
80
81 /**
82 * @throws java.lang.Exception
83 */
84 @After
85 public void tearDown() throws Exception {
Toshio Koidebfe9b922013-06-18 10:56:05 -070086 op.close();
Toshio Koide3c460e12013-06-13 11:55:12 -070087 testdb.shutdown();
Toshio Koide880f4c72013-06-17 14:43:11 -070088 PowerMock.verifyAll();
Toshio Koide9d8856e2013-06-12 16:48:11 -070089 }
90
91 /**
Pankaj Berde38646d62013-06-21 11:34:04 -070092 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#newSwitch(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -070093 */
94 @Test
95 public final void testNewSwitch() {
Toshio Koide880f4c72013-06-17 14:43:11 -070096 assertNull(op.searchSwitch("123"));
Toshio Koide9d8856e2013-06-12 16:48:11 -070097
Toshio Koide880f4c72013-06-17 14:43:11 -070098 op.newSwitch("123");
Toshio Koidea9a03002013-06-13 13:10:48 -070099 op.commit();
Toshio Koide9d8856e2013-06-12 16:48:11 -0700100
Toshio Koide880f4c72013-06-17 14:43:11 -0700101 ISwitchObject sw = op.searchSwitch("123");
102 assertNotNull(op);
103 assertEquals("123", sw.getDPID());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700104 }
105
106 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700107 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#searchSwitch(net.onrc.onos.graph.GraphDBConnection, java.lang.String)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700108 */
109 @Test
110 public final void testSearchSwitch() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700111 op.newSwitch("123");
112 op.newSwitch("456");
Toshio Koidea9a03002013-06-13 13:10:48 -0700113 op.commit();
Toshio Koide880f4c72013-06-17 14:43:11 -0700114
115 ISwitchObject sw = op.searchSwitch("123");
Toshio Koide3c460e12013-06-13 11:55:12 -0700116 assertNotNull(sw);
117 assertEquals("123", sw.getDPID());
Toshio Koide880f4c72013-06-17 14:43:11 -0700118
119 sw = op.searchSwitch("789");
120 assertNull(sw);
Toshio Koide3c460e12013-06-13 11:55:12 -0700121 }
122
123 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700124 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#searchActiveSwitch(net.onrc.onos.graph.GraphDBConnection, java.lang.String)}.
Toshio Koide3c460e12013-06-13 11:55:12 -0700125 */
126 @Test
127 public final void testSearchActiveSwitch() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700128 op.newSwitch("111").setState(SwitchState.ACTIVE.toString());
129 op.newSwitch("222").setState(SwitchState.INACTIVE.toString());
Toshio Koidea9a03002013-06-13 13:10:48 -0700130 op.commit();
131
Toshio Koide880f4c72013-06-17 14:43:11 -0700132 ISwitchObject sw = op.searchActiveSwitch("111");
Toshio Koide3c460e12013-06-13 11:55:12 -0700133 assertNotNull(sw);
134 assertEquals("111", sw.getDPID());
135
136 sw = op.searchActiveSwitch("222");
137 assertNull(sw);
138 }
139
140 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700141 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getActiveSwitches(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide3c460e12013-06-13 11:55:12 -0700142 */
143 @Test
144 public final void testGetActiveSwitches() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700145 op.newSwitch("111").setState(SwitchState.ACTIVE.toString());
146 op.newSwitch("222").setState(SwitchState.INACTIVE.toString());
Toshio Koidea9a03002013-06-13 13:10:48 -0700147 op.commit();
Toshio Koide3c460e12013-06-13 11:55:12 -0700148
149 Iterator<ISwitchObject> i = op.getActiveSwitches().iterator();
Toshio Koide880f4c72013-06-17 14:43:11 -0700150
Toshio Koide3c460e12013-06-13 11:55:12 -0700151 assertTrue(i.hasNext());
152 assertEquals("111", i.next().getDPID());
Toshio Koide880f4c72013-06-17 14:43:11 -0700153 assertFalse(i.hasNext());
154 }
155
156 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700157 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getAllSwitches(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide880f4c72013-06-17 14:43:11 -0700158 */
159 @Test
160 public final void testGetAllSwitches() {
161 List<String> dpids = Arrays.asList("111", "222", "333");
162 Collections.sort(dpids);
163
164 for (String dpid: dpids) op.newSwitch(dpid);
165 op.commit();
166
167 List<String> actual_ids = new ArrayList<String>();
168 for (ISwitchObject switchObj: op.getAllSwitches()) actual_ids.add(switchObj.getDPID());
169 Collections.sort(actual_ids);
170
171 assertArrayEquals(dpids.toArray(), actual_ids.toArray());
172 }
173
174 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700175 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getInactiveSwitches(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide880f4c72013-06-17 14:43:11 -0700176 */
177 @Test
178 public final void testGetInactiveSwitches() {
179 op.newSwitch("111").setState(SwitchState.ACTIVE.toString());
180 op.newSwitch("222").setState(SwitchState.INACTIVE.toString());
181 op.commit();
182
183 Iterator<ISwitchObject> i = op.getInactiveSwitches().iterator();
184
185 assertTrue(i.hasNext());
186 assertEquals("222", i.next().getDPID());
187 assertFalse(i.hasNext());
188 }
189
190 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700191 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getAllSwitchNotUpdatedFlowEntries(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide880f4c72013-06-17 14:43:11 -0700192 */
193 @Test
194 public final void testGetAllSwitchNotUpdatedFlowEntries() {
195 FlowEntryId flowEntryId10 = new FlowEntryId(10);
196 FlowEntryId flowEntryId20 = new FlowEntryId(20);
197 IFlowEntry flowEntry10 = op.newFlowEntry();
198 IFlowEntry flowEntry20 = op.newFlowEntry();
199 flowEntry10.setFlowEntryId(flowEntryId10.toString());
200 flowEntry20.setFlowEntryId(flowEntryId20.toString());
201 flowEntry10.setSwitchState("FE_SWITCH_NOT_UPDATED");
202 flowEntry20.setSwitchState("FE_SWITCH_UPDATED");
203 op.commit();
204
205 Iterator<IFlowEntry> flowEntries = op.getAllSwitchNotUpdatedFlowEntries().iterator();
206 assertNotNull(flowEntries);
207 assertTrue(flowEntries.hasNext());
208 assertEquals(flowEntryId10.toString(), flowEntries.next().getFlowEntryId());
209 assertFalse(flowEntries.hasNext());
Toshio Koide3c460e12013-06-13 11:55:12 -0700210 }
211
212 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700213 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#removeSwitch(net.onrc.onos.graph.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject)}.
Toshio Koide3c460e12013-06-13 11:55:12 -0700214 */
215 @Test
216 public final void testRemoveSwitch() {
217 ISwitchObject sw = op.newSwitch("123");
Toshio Koidea9a03002013-06-13 13:10:48 -0700218 op.commit();
Toshio Koide3c460e12013-06-13 11:55:12 -0700219 sw = op.searchSwitch("123");
Toshio Koide880f4c72013-06-17 14:43:11 -0700220 assertNotNull(sw);
221
Toshio Koide3c460e12013-06-13 11:55:12 -0700222 op.removeSwitch(sw);
Toshio Koide880f4c72013-06-17 14:43:11 -0700223 op.commit();
224
225 assertNull(op.searchSwitch("123"));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700226 }
227
228 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700229 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#newPort(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700230 */
231 @Test
232 public final void testNewPort() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700233 assertFalse(testdb.getVertices("type", "port").iterator().hasNext());
234
235 IPortObject port = op.newPort((short) 10);
236 assertTrue(port.getNumber() == 10);
237 op.commit();
238
239 Iterator<Vertex> vertices = testdb.getVertices("type", "port").iterator();
240 assertTrue(vertices.hasNext());
241 assertEquals(vertices.next().getProperty("number").toString(), "10");
Toshio Koide9d8856e2013-06-12 16:48:11 -0700242 }
243
244 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700245 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#searchPort(net.onrc.onos.graph.GraphDBConnection, java.lang.String, short)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700246 */
247 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700248 public final void testSearchPort() {
249 ISwitchObject sw;
250 IPortObject port;
251
252 sw = op.newSwitch("1");
253 sw.addPort(op.newPort((short) 1));
254 sw.addPort(op.newPort((short) 2));
255
256 sw = op.newSwitch("2");
257 sw.addPort(op.newPort((short) 1));
258 sw.addPort(op.newPort((short) 2));
259
260 op.commit();
261
262 assertNull(op.searchPort("3", (short) 1));
263 assertNull(op.searchPort("1", (short) 3));
264
265 port = op.searchPort("1", (short) 1);
266 assertNotNull(port);
267 assertTrue(port.getNumber() == 1);
268 sw = port.getSwitch();
269 assertNotNull(sw);
270 assertEquals("1", sw.getDPID());
271
272 port = op.searchPort("1", (short) 2);
273 assertNotNull(port);
274 assertTrue(port.getNumber() == 2);
275 sw = port.getSwitch();
276 assertNotNull(sw);
277 assertEquals("1", sw.getDPID());
278
279 port = op.searchPort("2", (short) 1);
280 assertNotNull(port);
281 assertTrue(port.getNumber() == 1);
282 sw = port.getSwitch();
283 assertNotNull(sw);
284 assertEquals("2", sw.getDPID());
285
286 port = op.searchPort("2", (short) 2);
287 assertNotNull(port);
288 assertTrue(port.getNumber() == 2);
289 sw = port.getSwitch();
290 assertNotNull(sw);
291 assertEquals("2", sw.getDPID());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700292 }
293
294 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700295 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#removePort(net.onrc.onos.graph.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IPortObject)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700296 */
297 @Test
298 public final void testRemovePort() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700299 ISwitchObject sw;
300 IPortObject port;
301
302 sw = op.newSwitch("1");
303 sw.addPort(op.newPort((short) 1));
304 sw.addPort(op.newPort((short) 2));
305
306 op.commit();
307
308 port = op.searchPort("1", (short) 1);
309 assertNotNull(port);
310 assertNotNull(op.searchPort("1", (short) 2));
311 assertNull(op.searchPort("1", (short) 3));
312
313 op.removePort(port);
314 op.commit();
315
316 assertNull(op.searchPort("1", (short) 1));
317 port = op.searchPort("1", (short) 2);
318 assertNotNull(port);
319
320 op.removePort(port);
321 op.commit();
322
323 assertNull(op.searchPort("1", (short) 1));
324 assertNull(op.searchPort("1", (short) 2));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700325 }
326
327 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700328 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#newDevice(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700329 */
330 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700331 public final void testNewDevice() {
332 assertFalse(testdb.getVertices("type", "device").iterator().hasNext());
333
334 IDeviceObject device = op.newDevice();
335 device.setMACAddress("11:22:33:44:55:66");
336 device.setIPAddress("192.168.1.1");
337 op.commit();
338
339 Iterator<Vertex> vertices = testdb.getVertices("type", "device").iterator();
340 assertTrue(vertices.hasNext());
341 Vertex v = vertices.next();
342 assertEquals("11:22:33:44:55:66", v.getProperty("dl_addr").toString());
343 assertEquals("192.168.1.1", v.getProperty("nw_addr").toString());
344 }
345
346 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700347 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#searchDevice(net.onrc.onos.graph.GraphDBConnection, java.lang.String)}.
Toshio Koide880f4c72013-06-17 14:43:11 -0700348 */
349 @Test
350 public final void testSearchDevice() {
351 assertNull(op.searchDevice("11:22:33:44:55:66"));
352 assertNull(op.searchDevice("66:55:44:33:22:11"));
353
354 op.newDevice().setMACAddress("11:22:33:44:55:66");
355 op.commit();
356
357 IDeviceObject device = op.searchDevice("11:22:33:44:55:66");
358 assertNotNull(device);
359 assertEquals("11:22:33:44:55:66", device.getMACAddress());
360
361 assertNull(op.searchDevice("66:55:44:33:22:11"));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700362 }
363
364 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700365 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getDevices(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700366 */
367 @Test
368 public final void testGetDevices() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700369 List<String> original_macs = Arrays.asList(
370 "11:11:11:11:11:11",
371 "22:22:22:22:22:22",
372 "33:33:33:33:33:33"
373 );
374
375 for (String mac: original_macs) op.newDevice().setMACAddress(mac);
376 op.commit();
377
378 Iterable<IDeviceObject> devices = op.getDevices();
379 List<String> macs = new ArrayList<String>();
380 for (IDeviceObject device: devices) macs.add(device.getMACAddress());
381 Collections.sort(macs);
382 assertArrayEquals(original_macs.toArray(), macs.toArray());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700383 }
384
385 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700386 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#removeDevice(net.onrc.onos.graph.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IDeviceObject)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700387 */
388 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700389 public final void testRemoveDevice() {
390 op.newDevice().setMACAddress("11:22:33:44:55:66");
391 op.commit();
392
393 op.removeDevice(op.searchDevice("11:22:33:44:55:66"));
394 op.commit();
395 assertNull(op.searchDevice("11:22:33:44:55:66"));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700396 }
397
398 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700399 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#newFlowPath(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700400 */
401 @Test
402 public final void testNewFlowPath() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700403 FlowId flowId = new FlowId(10);
404 IFlowPath flowPath = op.newFlowPath();
405 flowPath.setFlowId(flowId.toString());
406 op.commit();
407
408 Iterator<IFlowPath> flows = op.getAllFlowPaths().iterator();
409 assertTrue(flows.hasNext());
410 assertEquals(flowId.toString(), flows.next().getFlowId());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700411 }
412
413 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700414 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#searchFlowPath(net.onrc.onos.graph.GraphDBConnection, net.floodlightcontroller.util.FlowId)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700415 */
416 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700417 public final void testSearchFlowPath() {
418 FlowId flowId = new FlowId(20);
419 assertNull(op.searchFlowPath(flowId));
420
421 op.newFlowPath().setFlowId(flowId.toString());
422 op.commit();
423
424 IFlowPath flowPath = op.searchFlowPath(flowId);
425 assertNotNull(flowPath);
426 assertEquals(flowId.toString(), flowPath.getFlowId());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700427 }
428
429 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700430 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getFlowPathByFlowEntry(net.onrc.onos.graph.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700431 */
432 @Test
433 public final void testGetFlowPathByFlowEntry() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700434 FlowId flowId10 = new FlowId(10);
435 FlowId flowId20 = new FlowId(20);
436 IFlowPath flowPath10 = op.newFlowPath();
437 IFlowPath flowPath20 = op.newFlowPath();
438 IFlowEntry flowEntry10 = op.newFlowEntry();
439 IFlowEntry flowEntry20 = op.newFlowEntry();
440 IFlowEntry flowEntry30 = op.newFlowEntry();
441 FlowEntryId flowEntryId10 = new FlowEntryId(10);
442 FlowEntryId flowEntryId20 = new FlowEntryId(20);
443 FlowEntryId flowEntryId30 = new FlowEntryId(30);
444 flowEntry10.setFlowEntryId(flowEntryId10.toString());
445 flowEntry20.setFlowEntryId(flowEntryId20.toString());
446 flowEntry30.setFlowEntryId(flowEntryId30.toString());
447 flowPath10.setFlowId(flowId10.toString());
448 flowPath10.addFlowEntry(flowEntry10);
449 flowPath20.setFlowId(flowId20.toString());
450 flowPath20.addFlowEntry(flowEntry20);
451 op.commit();
452
453 flowEntry10 = op.searchFlowEntry(flowEntryId10);
454 IFlowPath obtainedFlowPath = op.getFlowPathByFlowEntry(flowEntry10);
455 assertNotNull(obtainedFlowPath);
456 assertEquals(flowId10.toString(), obtainedFlowPath.getFlowId());
457
458 flowEntry20 = op.searchFlowEntry(flowEntryId20);
459 obtainedFlowPath = op.getFlowPathByFlowEntry(flowEntry20);
460 assertNotNull(obtainedFlowPath);
461 assertEquals(flowId20.toString(), obtainedFlowPath.getFlowId());
462
463 flowEntry30 = op.searchFlowEntry(flowEntryId30);
464 obtainedFlowPath = op.getFlowPathByFlowEntry(flowEntry30);
465 assertNull(obtainedFlowPath);
Toshio Koide9d8856e2013-06-12 16:48:11 -0700466 }
467
468 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700469 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getAllFlowPaths(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700470 */
471 @Test
472 public final void testGetAllFlowPaths() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700473 List<FlowId> flowids = Arrays.asList(
474 new FlowId(10), new FlowId(20), new FlowId(30)
475 );
476
477 for (FlowId flowId: flowids)
478 op.newFlowPath().setFlowId(flowId.toString());
479 op.commit();
480
481 List<String> actual_ids = new ArrayList<String>();
482 for (IFlowPath flowPath: op.getAllFlowPaths()) actual_ids.add(flowPath.getFlowId());
483 Collections.sort(actual_ids);
484
485 List<String> expected_ids = new ArrayList<String>();
486 for (FlowId flowid: flowids) expected_ids.add(flowid.toString());
487 Collections.sort(expected_ids);
488
489 assertArrayEquals(expected_ids.toArray(), actual_ids.toArray());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700490 }
491
492 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700493 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#removeFlowPath(net.onrc.onos.graph.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700494 */
495 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700496 public final void testRemoveFlowPath() {
497 FlowId flowId10 = new FlowId(10);
498 FlowId flowId20 = new FlowId(20);
499 op.newFlowPath().setFlowId(flowId10.toString());
500 op.newFlowPath().setFlowId(flowId20.toString());
501 op.commit();
502
503 IFlowPath flowPath = op.searchFlowPath(flowId10);
504 assertNotNull(flowPath);
505 op.removeFlowPath(flowPath);
506 op.commit();
507
508 assertNull(op.searchFlowPath(flowId10));
509 assertNotNull(op.searchFlowPath(flowId20));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700510 }
511
512 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700513 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#newFlowEntry(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700514 */
515 @Test
516 public final void testNewFlowEntry() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700517 IFlowEntry flowEntry = op.newFlowEntry();
518 FlowEntryId flowEntryId = new FlowEntryId();
519 flowEntryId.setValue(12345);
520 flowEntry.setFlowEntryId(flowEntryId.toString());
521 op.commit();
522
523 flowEntry = op.searchFlowEntry(flowEntryId);
524 assertNotNull(flowEntry);
525 assertEquals(flowEntry.getFlowEntryId(), flowEntryId.toString());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700526 }
527
528 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700529 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#searchFlowEntry(net.onrc.onos.graph.GraphDBConnection, net.floodlightcontroller.util.FlowEntryId)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700530 */
531 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700532 public final void testSearchFlowEntry() {
533 FlowEntryId flowEntryId10 = new FlowEntryId();
534 flowEntryId10.setValue(10);
535 FlowEntryId flowEntryId20 = new FlowEntryId();
536 flowEntryId20.setValue(20);
537 FlowEntryId flowEntryId30 = new FlowEntryId();
538 flowEntryId30.setValue(30);
539
540 op.newFlowEntry().setFlowEntryId(flowEntryId10.toString());
541 op.newFlowEntry().setFlowEntryId(flowEntryId20.toString());
542 op.commit();
543
544 assertNull(op.searchFlowEntry(flowEntryId30));
545 IFlowEntry flowEntry = op.searchFlowEntry(flowEntryId10);
546 assertEquals(flowEntry.getFlowEntryId(), flowEntryId10.toString());
547 flowEntry = op.searchFlowEntry(flowEntryId20);
548 assertEquals(flowEntry.getFlowEntryId(), flowEntryId20.toString());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700549 }
550
551 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700552 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getAllFlowEntries(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700553 */
554 @Test
555 public final void testGetAllFlowEntries() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700556 List<FlowEntryId> flowEntryIds = Arrays.asList(
557 new FlowEntryId(10), new FlowEntryId(20), new FlowEntryId(30)
558 );
559
560 for (FlowEntryId flowEntryId: flowEntryIds)
561 op.newFlowEntry().setFlowEntryId(flowEntryId.toString());
562 op.commit();
563
564 List<String> actual_ids = new ArrayList<String>();
565 for (IFlowEntry flowEntry: op.getAllFlowEntries()) actual_ids.add(flowEntry.getFlowEntryId());
566 Collections.sort(actual_ids);
567
568 List<String> expected_ids = new ArrayList<String>();
569 for (FlowEntryId flowEntryId: flowEntryIds) expected_ids.add(flowEntryId.toString());
570 Collections.sort(expected_ids);
571
572 assertArrayEquals(expected_ids.toArray(), actual_ids.toArray());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700573 }
574
575 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700576 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#removeFlowEntry(net.onrc.onos.graph.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700577 */
578 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700579 public final void testRemoveFlowEntry() {
580 FlowEntryId flowEntryId10 = new FlowEntryId(10);
581 FlowEntryId flowEntryId20 = new FlowEntryId(20);
582 op.newFlowEntry().setFlowEntryId(flowEntryId10.toString());
583 op.newFlowEntry().setFlowEntryId(flowEntryId20.toString());
584 op.commit();
585
586 IFlowEntry flowEntry = op.searchFlowEntry(flowEntryId10);
587 assertNotNull(flowEntry);
588 op.removeFlowEntry(flowEntry);
589 op.commit();
590
591 assertNull(op.searchFlowEntry(flowEntryId10));
592 assertNotNull(op.searchFlowEntry(flowEntryId20));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700593 }
594
Toshio Koide9d8856e2013-06-12 16:48:11 -0700595}