blob: b40d2afa4647d01d84fa924014d04964955cca92 [file] [log] [blame]
Toshio Koide9d8856e2013-06-12 16:48:11 -07001/**
2 *
3 */
Toshio Koidee32a4ec2013-06-27 11:51:21 -07004package net.onrc.onos.graph;
Toshio Koide9d8856e2013-06-12 16:48:11 -07005
Jonathan Hart56d15772013-11-03 19:09:59 -08006import static org.junit.Assert.assertArrayEquals;
Toshio Koide9d8856e2013-06-12 16:48:11 -07007
Jonathan Hart56d15772013-11-03 19:09:59 -08008import java.util.ArrayList;
9import java.util.Arrays;
10import java.util.Collections;
11import java.util.Iterator;
12import java.util.List;
Toshio Koide3c460e12013-06-13 11:55:12 -070013
Toshio Koide880f4c72013-06-17 14:43:11 -070014import junit.framework.TestCase;
Toshio Koide880f4c72013-06-17 14:43:11 -070015import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IDeviceObject;
16import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
17import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
Jonathan Hart56d15772013-11-03 19:09:59 -080018import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IIpv4Address;
Toshio Koide880f4c72013-06-17 14:43:11 -070019import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
Toshio Koideb29b9b32013-06-13 14:37:46 -070020import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
21import net.onrc.onos.ofcontroller.core.ISwitchStorage.SwitchState;
HIGUCHI Yuta08137932013-06-17 14:11:50 -070022import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager;
Toshio Koide880f4c72013-06-17 14:43:11 -070023import net.onrc.onos.ofcontroller.util.FlowEntryId;
24import net.onrc.onos.ofcontroller.util.FlowId;
Toshio Koide9d8856e2013-06-12 16:48:11 -070025
26import org.easymock.EasyMock;
27import org.junit.After;
28import org.junit.AfterClass;
29import org.junit.Before;
30import org.junit.BeforeClass;
Jonathan Hart56d15772013-11-03 19:09:59 -080031import org.junit.Ignore;
Toshio Koide9d8856e2013-06-12 16:48:11 -070032import org.junit.Test;
33import org.junit.runner.RunWith;
34import org.powermock.api.easymock.PowerMock;
35import org.powermock.core.classloader.annotations.PrepareForTest;
36import org.powermock.modules.junit4.PowerMockRunner;
37
Jonathan Hart56d15772013-11-03 19:09:59 -080038import com.google.common.net.InetAddresses;
Toshio Koide9d8856e2013-06-12 16:48:11 -070039import com.thinkaurelius.titan.core.TitanFactory;
40import com.thinkaurelius.titan.core.TitanGraph;
Toshio Koide3c460e12013-06-13 11:55:12 -070041import com.tinkerpop.blueprints.Vertex;
Toshio Koide9d8856e2013-06-12 16:48:11 -070042
43/**
44 * @author Toshio Koide
45 *
46 */
Toshio Koide880f4c72013-06-17 14:43:11 -070047
Toshio Koide9d8856e2013-06-12 16:48:11 -070048@RunWith(PowerMockRunner.class)
49@PrepareForTest({TitanFactory.class})
Toshio Koide880f4c72013-06-17 14:43:11 -070050public class GraphDBOperationTest extends TestCase {
Toshio Koide3c460e12013-06-13 11:55:12 -070051 private static TitanGraph testdb;
Toshio Koide9d8856e2013-06-12 16:48:11 -070052 private static GraphDBOperation op;
53
54 /**
55 * @throws java.lang.Exception
56 */
57 @BeforeClass
58 public static void setUpBeforeClass() throws Exception {
59 }
60
61 /**
62 * @throws java.lang.Exception
63 */
64 @AfterClass
65 public static void tearDownAfterClass() throws Exception {
66 }
67
68 /**
69 * @throws java.lang.Exception
70 */
71 @Before
72 public void setUp() throws Exception {
73 TestDatabaseManager.deleteTestDatabase();
Toshio Koide3c460e12013-06-13 11:55:12 -070074 testdb = TestDatabaseManager.getTestDatabase();
Toshio Koide9d8856e2013-06-12 16:48:11 -070075// TestDatabaseManager.populateTestData(titanGraph);
Toshio Koide880f4c72013-06-17 14:43:11 -070076
77 String dummyPath = "/dummy/to/conf";
Toshio Koide9d8856e2013-06-12 16:48:11 -070078 // replace return value of TitanFactory.open() to dummy DB created above
79 PowerMock.mockStatic(TitanFactory.class);
Toshio Koide880f4c72013-06-17 14:43:11 -070080 EasyMock.expect(TitanFactory.open(dummyPath)).andReturn(testdb);
Toshio Koide9d8856e2013-06-12 16:48:11 -070081 PowerMock.replay(TitanFactory.class);
82
Toshio Koidebfe9b922013-06-18 10:56:05 -070083 op = new GraphDBOperation(dummyPath);
Toshio Koide9d8856e2013-06-12 16:48:11 -070084 }
85
86 /**
87 * @throws java.lang.Exception
88 */
89 @After
90 public void tearDown() throws Exception {
Toshio Koidebfe9b922013-06-18 10:56:05 -070091 op.close();
Toshio Koide3c460e12013-06-13 11:55:12 -070092 testdb.shutdown();
Toshio Koide880f4c72013-06-17 14:43:11 -070093 PowerMock.verifyAll();
Toshio Koide9d8856e2013-06-12 16:48:11 -070094 }
95
96 /**
Pankaj Berde38646d62013-06-21 11:34:04 -070097 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#newSwitch(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -070098 */
99 @Test
100 public final void testNewSwitch() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700101 assertNull(op.searchSwitch("123"));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700102
Toshio Koidee32a4ec2013-06-27 11:51:21 -0700103 ISwitchObject sw = op.newSwitch("123");
104 assertEquals(sw.getDPID(), "123");
Toshio Koidea9a03002013-06-13 13:10:48 -0700105 op.commit();
Toshio Koide9d8856e2013-06-12 16:48:11 -0700106
Toshio Koidee32a4ec2013-06-27 11:51:21 -0700107 sw = op.searchSwitch("123");
108 assertNotNull(sw);
Toshio Koide880f4c72013-06-17 14:43:11 -0700109 assertEquals("123", sw.getDPID());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700110 }
111
112 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700113 * 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 -0700114 */
115 @Test
116 public final void testSearchSwitch() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700117 op.newSwitch("123");
118 op.newSwitch("456");
Toshio Koidea9a03002013-06-13 13:10:48 -0700119 op.commit();
Toshio Koide880f4c72013-06-17 14:43:11 -0700120
121 ISwitchObject sw = op.searchSwitch("123");
Toshio Koide3c460e12013-06-13 11:55:12 -0700122 assertNotNull(sw);
123 assertEquals("123", sw.getDPID());
Toshio Koide880f4c72013-06-17 14:43:11 -0700124
125 sw = op.searchSwitch("789");
126 assertNull(sw);
Toshio Koide3c460e12013-06-13 11:55:12 -0700127 }
128
129 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700130 * 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 -0700131 */
132 @Test
133 public final void testSearchActiveSwitch() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700134 op.newSwitch("111").setState(SwitchState.ACTIVE.toString());
135 op.newSwitch("222").setState(SwitchState.INACTIVE.toString());
Toshio Koidea9a03002013-06-13 13:10:48 -0700136 op.commit();
137
Toshio Koide880f4c72013-06-17 14:43:11 -0700138 ISwitchObject sw = op.searchActiveSwitch("111");
Toshio Koide3c460e12013-06-13 11:55:12 -0700139 assertNotNull(sw);
140 assertEquals("111", sw.getDPID());
141
142 sw = op.searchActiveSwitch("222");
143 assertNull(sw);
144 }
145
146 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700147 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getActiveSwitches(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide3c460e12013-06-13 11:55:12 -0700148 */
149 @Test
150 public final void testGetActiveSwitches() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700151 op.newSwitch("111").setState(SwitchState.ACTIVE.toString());
152 op.newSwitch("222").setState(SwitchState.INACTIVE.toString());
Toshio Koidea9a03002013-06-13 13:10:48 -0700153 op.commit();
Toshio Koide3c460e12013-06-13 11:55:12 -0700154
155 Iterator<ISwitchObject> i = op.getActiveSwitches().iterator();
Toshio Koide880f4c72013-06-17 14:43:11 -0700156
Toshio Koide3c460e12013-06-13 11:55:12 -0700157 assertTrue(i.hasNext());
158 assertEquals("111", i.next().getDPID());
Toshio Koide880f4c72013-06-17 14:43:11 -0700159 assertFalse(i.hasNext());
160 }
161
162 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700163 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getAllSwitches(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide880f4c72013-06-17 14:43:11 -0700164 */
165 @Test
166 public final void testGetAllSwitches() {
167 List<String> dpids = Arrays.asList("111", "222", "333");
168 Collections.sort(dpids);
169
170 for (String dpid: dpids) op.newSwitch(dpid);
171 op.commit();
172
173 List<String> actual_ids = new ArrayList<String>();
174 for (ISwitchObject switchObj: op.getAllSwitches()) actual_ids.add(switchObj.getDPID());
175 Collections.sort(actual_ids);
176
177 assertArrayEquals(dpids.toArray(), actual_ids.toArray());
178 }
179
180 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700181 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getInactiveSwitches(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide880f4c72013-06-17 14:43:11 -0700182 */
183 @Test
184 public final void testGetInactiveSwitches() {
185 op.newSwitch("111").setState(SwitchState.ACTIVE.toString());
186 op.newSwitch("222").setState(SwitchState.INACTIVE.toString());
187 op.commit();
188
189 Iterator<ISwitchObject> i = op.getInactiveSwitches().iterator();
190
191 assertTrue(i.hasNext());
192 assertEquals("222", i.next().getDPID());
193 assertFalse(i.hasNext());
194 }
195
196 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700197 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getAllSwitchNotUpdatedFlowEntries(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide880f4c72013-06-17 14:43:11 -0700198 */
199 @Test
200 public final void testGetAllSwitchNotUpdatedFlowEntries() {
201 FlowEntryId flowEntryId10 = new FlowEntryId(10);
202 FlowEntryId flowEntryId20 = new FlowEntryId(20);
203 IFlowEntry flowEntry10 = op.newFlowEntry();
204 IFlowEntry flowEntry20 = op.newFlowEntry();
205 flowEntry10.setFlowEntryId(flowEntryId10.toString());
206 flowEntry20.setFlowEntryId(flowEntryId20.toString());
207 flowEntry10.setSwitchState("FE_SWITCH_NOT_UPDATED");
208 flowEntry20.setSwitchState("FE_SWITCH_UPDATED");
209 op.commit();
210
211 Iterator<IFlowEntry> flowEntries = op.getAllSwitchNotUpdatedFlowEntries().iterator();
212 assertNotNull(flowEntries);
213 assertTrue(flowEntries.hasNext());
214 assertEquals(flowEntryId10.toString(), flowEntries.next().getFlowEntryId());
215 assertFalse(flowEntries.hasNext());
Toshio Koide3c460e12013-06-13 11:55:12 -0700216 }
217
218 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700219 * 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 -0700220 */
221 @Test
222 public final void testRemoveSwitch() {
223 ISwitchObject sw = op.newSwitch("123");
Toshio Koidea9a03002013-06-13 13:10:48 -0700224 op.commit();
Toshio Koide3c460e12013-06-13 11:55:12 -0700225 sw = op.searchSwitch("123");
Toshio Koide880f4c72013-06-17 14:43:11 -0700226 assertNotNull(sw);
227
Toshio Koide3c460e12013-06-13 11:55:12 -0700228 op.removeSwitch(sw);
Toshio Koide880f4c72013-06-17 14:43:11 -0700229 op.commit();
230
231 assertNull(op.searchSwitch("123"));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700232 }
233
234 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700235 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#newPort(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700236 */
237 @Test
238 public final void testNewPort() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700239 assertFalse(testdb.getVertices("type", "port").iterator().hasNext());
240
Toshio Koidee32a4ec2013-06-27 11:51:21 -0700241 IPortObject port = op.newPort("1", (short) 10);
Toshio Koide880f4c72013-06-17 14:43:11 -0700242 assertTrue(port.getNumber() == 10);
243 op.commit();
244
245 Iterator<Vertex> vertices = testdb.getVertices("type", "port").iterator();
246 assertTrue(vertices.hasNext());
247 assertEquals(vertices.next().getProperty("number").toString(), "10");
Toshio Koide9d8856e2013-06-12 16:48:11 -0700248 }
249
250 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700251 * 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 -0700252 */
253 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700254 public final void testSearchPort() {
255 ISwitchObject sw;
256 IPortObject port;
257
258 sw = op.newSwitch("1");
Toshio Koidee32a4ec2013-06-27 11:51:21 -0700259 sw.addPort(op.newPort("1", (short) 1));
260 sw.addPort(op.newPort("1", (short) 2));
Toshio Koide880f4c72013-06-17 14:43:11 -0700261
262 sw = op.newSwitch("2");
Toshio Koidee32a4ec2013-06-27 11:51:21 -0700263 sw.addPort(op.newPort("2", (short) 1));
264 sw.addPort(op.newPort("2", (short) 2));
Toshio Koide880f4c72013-06-17 14:43:11 -0700265
266 op.commit();
267
268 assertNull(op.searchPort("3", (short) 1));
269 assertNull(op.searchPort("1", (short) 3));
270
271 port = op.searchPort("1", (short) 1);
272 assertNotNull(port);
273 assertTrue(port.getNumber() == 1);
274 sw = port.getSwitch();
275 assertNotNull(sw);
276 assertEquals("1", sw.getDPID());
277
278 port = op.searchPort("1", (short) 2);
279 assertNotNull(port);
280 assertTrue(port.getNumber() == 2);
281 sw = port.getSwitch();
282 assertNotNull(sw);
283 assertEquals("1", sw.getDPID());
284
285 port = op.searchPort("2", (short) 1);
286 assertNotNull(port);
287 assertTrue(port.getNumber() == 1);
288 sw = port.getSwitch();
289 assertNotNull(sw);
290 assertEquals("2", sw.getDPID());
291
292 port = op.searchPort("2", (short) 2);
293 assertNotNull(port);
294 assertTrue(port.getNumber() == 2);
295 sw = port.getSwitch();
296 assertNotNull(sw);
297 assertEquals("2", sw.getDPID());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700298 }
299
300 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700301 * 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 -0700302 */
303 @Test
304 public final void testRemovePort() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700305 ISwitchObject sw;
306 IPortObject port;
307
308 sw = op.newSwitch("1");
Toshio Koidee32a4ec2013-06-27 11:51:21 -0700309 sw.addPort(op.newPort("1", (short) 1));
310 sw.addPort(op.newPort("1", (short) 2));
Toshio Koide880f4c72013-06-17 14:43:11 -0700311
312 op.commit();
313
314 port = op.searchPort("1", (short) 1);
315 assertNotNull(port);
316 assertNotNull(op.searchPort("1", (short) 2));
317 assertNull(op.searchPort("1", (short) 3));
318
319 op.removePort(port);
320 op.commit();
321
322 assertNull(op.searchPort("1", (short) 1));
323 port = op.searchPort("1", (short) 2);
324 assertNotNull(port);
325
326 op.removePort(port);
327 op.commit();
328
329 assertNull(op.searchPort("1", (short) 1));
330 assertNull(op.searchPort("1", (short) 2));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700331 }
332
333 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700334 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#newDevice(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700335 */
336 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700337 public final void testNewDevice() {
338 assertFalse(testdb.getVertices("type", "device").iterator().hasNext());
339
340 IDeviceObject device = op.newDevice();
341 device.setMACAddress("11:22:33:44:55:66");
Jonathan Hart56d15772013-11-03 19:09:59 -0800342 //device.setIPAddress("192.168.1.1");
Toshio Koide880f4c72013-06-17 14:43:11 -0700343 op.commit();
344
345 Iterator<Vertex> vertices = testdb.getVertices("type", "device").iterator();
346 assertTrue(vertices.hasNext());
347 Vertex v = vertices.next();
348 assertEquals("11:22:33:44:55:66", v.getProperty("dl_addr").toString());
Jonathan Hart56d15772013-11-03 19:09:59 -0800349 //assertEquals("192.168.1.1", v.getProperty("nw_addr").toString());
Toshio Koide880f4c72013-06-17 14:43:11 -0700350 }
351
352 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700353 * 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 -0700354 */
355 @Test
356 public final void testSearchDevice() {
357 assertNull(op.searchDevice("11:22:33:44:55:66"));
358 assertNull(op.searchDevice("66:55:44:33:22:11"));
359
360 op.newDevice().setMACAddress("11:22:33:44:55:66");
361 op.commit();
362
363 IDeviceObject device = op.searchDevice("11:22:33:44:55:66");
364 assertNotNull(device);
365 assertEquals("11:22:33:44:55:66", device.getMACAddress());
366
367 assertNull(op.searchDevice("66:55:44:33:22:11"));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700368 }
369
370 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700371 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getDevices(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700372 */
373 @Test
374 public final void testGetDevices() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700375 List<String> original_macs = Arrays.asList(
376 "11:11:11:11:11:11",
377 "22:22:22:22:22:22",
378 "33:33:33:33:33:33"
379 );
380
381 for (String mac: original_macs) op.newDevice().setMACAddress(mac);
382 op.commit();
383
384 Iterable<IDeviceObject> devices = op.getDevices();
385 List<String> macs = new ArrayList<String>();
386 for (IDeviceObject device: devices) macs.add(device.getMACAddress());
387 Collections.sort(macs);
388 assertArrayEquals(original_macs.toArray(), macs.toArray());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700389 }
390
391 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700392 * 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 -0700393 */
394 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700395 public final void testRemoveDevice() {
396 op.newDevice().setMACAddress("11:22:33:44:55:66");
397 op.commit();
398
399 op.removeDevice(op.searchDevice("11:22:33:44:55:66"));
400 op.commit();
401 assertNull(op.searchDevice("11:22:33:44:55:66"));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700402 }
Jonathan Hart56d15772013-11-03 19:09:59 -0800403
404 /**
405 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#newIpv4Address(net.onrc.onos.graph.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IIpv4Address)}.
406 */
407 @Test
408 public final void testNewIpv4Address() {
409 int intIpv4Address = InetAddresses.coerceToInteger(InetAddresses.forString("192.168.10.1"));
410
411 assertFalse(testdb.getVertices("type", "ipv4Address").iterator().hasNext());
412
413 IIpv4Address ipv4Address = op.newIpv4Address();
414 ipv4Address.setIpv4Address(intIpv4Address);
415 //device.setIPAddress("192.168.1.1");
416 op.commit();
417
418 Iterator<Vertex> vertices = testdb.getVertices("type", "ipv4Address").iterator();
419 assertTrue(vertices.hasNext());
420 Vertex v = vertices.next();
421 assertEquals(intIpv4Address, ((Integer) v.getProperty("ipv4_address")).intValue());
422 }
423
424 /**
425 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#searchIpv4Address(net.onrc.onos.graph.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IIpv4Address)}.
426 */
427 @Test
428 public final void testSearchIpv4Address() {
429 int addr1 = InetAddresses.coerceToInteger(InetAddresses.forString("192.168.20.1"));
430 int addr2 = InetAddresses.coerceToInteger(InetAddresses.forString("59.203.2.15"));
431
432 assertNull(op.searchIpv4Address(addr1));
433 assertNull(op.searchIpv4Address(addr2));
434
435 op.newIpv4Address().setIpv4Address(addr1);
436 op.commit();
437
438 IIpv4Address ipv4Address = op.searchIpv4Address(addr1);
439 assertNotNull(ipv4Address);
440 assertEquals(addr1, ipv4Address.getIpv4Address());
441
442 assertNull(op.searchIpv4Address(addr2));
443 }
444
445 @Ignore
446 @Test
447 public final void testEnsureIpv4Address() {
448 // TODO not yet implemented
449 }
Toshio Koide9d8856e2013-06-12 16:48:11 -0700450
451 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700452 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#newFlowPath(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700453 */
454 @Test
455 public final void testNewFlowPath() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700456 FlowId flowId = new FlowId(10);
457 IFlowPath flowPath = op.newFlowPath();
458 flowPath.setFlowId(flowId.toString());
459 op.commit();
460
461 Iterator<IFlowPath> flows = op.getAllFlowPaths().iterator();
462 assertTrue(flows.hasNext());
463 assertEquals(flowId.toString(), flows.next().getFlowId());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700464 }
465
466 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700467 * 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 -0700468 */
469 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700470 public final void testSearchFlowPath() {
471 FlowId flowId = new FlowId(20);
472 assertNull(op.searchFlowPath(flowId));
473
474 op.newFlowPath().setFlowId(flowId.toString());
475 op.commit();
476
477 IFlowPath flowPath = op.searchFlowPath(flowId);
478 assertNotNull(flowPath);
479 assertEquals(flowId.toString(), flowPath.getFlowId());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700480 }
481
482 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700483 * 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 -0700484 */
485 @Test
486 public final void testGetFlowPathByFlowEntry() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700487 FlowId flowId10 = new FlowId(10);
488 FlowId flowId20 = new FlowId(20);
489 IFlowPath flowPath10 = op.newFlowPath();
490 IFlowPath flowPath20 = op.newFlowPath();
491 IFlowEntry flowEntry10 = op.newFlowEntry();
492 IFlowEntry flowEntry20 = op.newFlowEntry();
493 IFlowEntry flowEntry30 = op.newFlowEntry();
494 FlowEntryId flowEntryId10 = new FlowEntryId(10);
495 FlowEntryId flowEntryId20 = new FlowEntryId(20);
496 FlowEntryId flowEntryId30 = new FlowEntryId(30);
497 flowEntry10.setFlowEntryId(flowEntryId10.toString());
498 flowEntry20.setFlowEntryId(flowEntryId20.toString());
499 flowEntry30.setFlowEntryId(flowEntryId30.toString());
500 flowPath10.setFlowId(flowId10.toString());
501 flowPath10.addFlowEntry(flowEntry10);
502 flowPath20.setFlowId(flowId20.toString());
503 flowPath20.addFlowEntry(flowEntry20);
504 op.commit();
505
506 flowEntry10 = op.searchFlowEntry(flowEntryId10);
507 IFlowPath obtainedFlowPath = op.getFlowPathByFlowEntry(flowEntry10);
508 assertNotNull(obtainedFlowPath);
509 assertEquals(flowId10.toString(), obtainedFlowPath.getFlowId());
510
511 flowEntry20 = op.searchFlowEntry(flowEntryId20);
512 obtainedFlowPath = op.getFlowPathByFlowEntry(flowEntry20);
513 assertNotNull(obtainedFlowPath);
514 assertEquals(flowId20.toString(), obtainedFlowPath.getFlowId());
515
516 flowEntry30 = op.searchFlowEntry(flowEntryId30);
517 obtainedFlowPath = op.getFlowPathByFlowEntry(flowEntry30);
518 assertNull(obtainedFlowPath);
Toshio Koide9d8856e2013-06-12 16:48:11 -0700519 }
520
521 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700522 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getAllFlowPaths(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700523 */
524 @Test
525 public final void testGetAllFlowPaths() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700526 List<FlowId> flowids = Arrays.asList(
527 new FlowId(10), new FlowId(20), new FlowId(30)
528 );
529
530 for (FlowId flowId: flowids)
531 op.newFlowPath().setFlowId(flowId.toString());
532 op.commit();
533
534 List<String> actual_ids = new ArrayList<String>();
535 for (IFlowPath flowPath: op.getAllFlowPaths()) actual_ids.add(flowPath.getFlowId());
536 Collections.sort(actual_ids);
537
538 List<String> expected_ids = new ArrayList<String>();
539 for (FlowId flowid: flowids) expected_ids.add(flowid.toString());
540 Collections.sort(expected_ids);
541
542 assertArrayEquals(expected_ids.toArray(), actual_ids.toArray());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700543 }
544
545 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700546 * 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 -0700547 */
548 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700549 public final void testRemoveFlowPath() {
550 FlowId flowId10 = new FlowId(10);
551 FlowId flowId20 = new FlowId(20);
552 op.newFlowPath().setFlowId(flowId10.toString());
553 op.newFlowPath().setFlowId(flowId20.toString());
554 op.commit();
555
556 IFlowPath flowPath = op.searchFlowPath(flowId10);
557 assertNotNull(flowPath);
558 op.removeFlowPath(flowPath);
559 op.commit();
560
561 assertNull(op.searchFlowPath(flowId10));
562 assertNotNull(op.searchFlowPath(flowId20));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700563 }
564
565 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700566 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#newFlowEntry(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700567 */
568 @Test
569 public final void testNewFlowEntry() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700570 IFlowEntry flowEntry = op.newFlowEntry();
571 FlowEntryId flowEntryId = new FlowEntryId();
572 flowEntryId.setValue(12345);
573 flowEntry.setFlowEntryId(flowEntryId.toString());
574 op.commit();
575
576 flowEntry = op.searchFlowEntry(flowEntryId);
577 assertNotNull(flowEntry);
578 assertEquals(flowEntry.getFlowEntryId(), flowEntryId.toString());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700579 }
580
581 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700582 * 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 -0700583 */
584 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700585 public final void testSearchFlowEntry() {
586 FlowEntryId flowEntryId10 = new FlowEntryId();
587 flowEntryId10.setValue(10);
588 FlowEntryId flowEntryId20 = new FlowEntryId();
589 flowEntryId20.setValue(20);
590 FlowEntryId flowEntryId30 = new FlowEntryId();
591 flowEntryId30.setValue(30);
592
593 op.newFlowEntry().setFlowEntryId(flowEntryId10.toString());
594 op.newFlowEntry().setFlowEntryId(flowEntryId20.toString());
595 op.commit();
596
597 assertNull(op.searchFlowEntry(flowEntryId30));
598 IFlowEntry flowEntry = op.searchFlowEntry(flowEntryId10);
599 assertEquals(flowEntry.getFlowEntryId(), flowEntryId10.toString());
600 flowEntry = op.searchFlowEntry(flowEntryId20);
601 assertEquals(flowEntry.getFlowEntryId(), flowEntryId20.toString());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700602 }
603
604 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700605 * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getAllFlowEntries(net.onrc.onos.graph.GraphDBConnection)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700606 */
607 @Test
608 public final void testGetAllFlowEntries() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700609 List<FlowEntryId> flowEntryIds = Arrays.asList(
610 new FlowEntryId(10), new FlowEntryId(20), new FlowEntryId(30)
611 );
612
613 for (FlowEntryId flowEntryId: flowEntryIds)
614 op.newFlowEntry().setFlowEntryId(flowEntryId.toString());
615 op.commit();
616
617 List<String> actual_ids = new ArrayList<String>();
618 for (IFlowEntry flowEntry: op.getAllFlowEntries()) actual_ids.add(flowEntry.getFlowEntryId());
619 Collections.sort(actual_ids);
620
621 List<String> expected_ids = new ArrayList<String>();
622 for (FlowEntryId flowEntryId: flowEntryIds) expected_ids.add(flowEntryId.toString());
623 Collections.sort(expected_ids);
624
625 assertArrayEquals(expected_ids.toArray(), actual_ids.toArray());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700626 }
627
628 /**
Pankaj Berde38646d62013-06-21 11:34:04 -0700629 * 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 -0700630 */
631 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700632 public final void testRemoveFlowEntry() {
633 FlowEntryId flowEntryId10 = new FlowEntryId(10);
634 FlowEntryId flowEntryId20 = new FlowEntryId(20);
635 op.newFlowEntry().setFlowEntryId(flowEntryId10.toString());
636 op.newFlowEntry().setFlowEntryId(flowEntryId20.toString());
637 op.commit();
638
639 IFlowEntry flowEntry = op.searchFlowEntry(flowEntryId10);
640 assertNotNull(flowEntry);
641 op.removeFlowEntry(flowEntry);
642 op.commit();
643
644 assertNull(op.searchFlowEntry(flowEntryId10));
645 assertNotNull(op.searchFlowEntry(flowEntryId20));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700646 }
647
Toshio Koide9d8856e2013-06-12 16:48:11 -0700648}