Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | */ |
| 4 | package net.onrc.onos.util; |
| 5 | |
| 6 | import static org.junit.Assert.*; |
| 7 | |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 8 | import java.util.*; |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 9 | |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 10 | import junit.framework.TestCase; |
| 11 | |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 12 | import net.onrc.onos.graph.GraphDBOperation; |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 13 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IDeviceObject; |
| 14 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry; |
| 15 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath; |
| 16 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject; |
Toshio Koide | b29b9b3 | 2013-06-13 14:37:46 -0700 | [diff] [blame] | 17 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject; |
| 18 | import net.onrc.onos.ofcontroller.core.ISwitchStorage.SwitchState; |
HIGUCHI Yuta | 0813793 | 2013-06-17 14:11:50 -0700 | [diff] [blame] | 19 | import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager; |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 20 | import net.onrc.onos.ofcontroller.util.FlowEntryId; |
| 21 | import net.onrc.onos.ofcontroller.util.FlowId; |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 22 | |
| 23 | import org.easymock.EasyMock; |
| 24 | import org.junit.After; |
| 25 | import org.junit.AfterClass; |
| 26 | import org.junit.Before; |
| 27 | import org.junit.BeforeClass; |
| 28 | import org.junit.Test; |
| 29 | import org.junit.runner.RunWith; |
| 30 | import org.powermock.api.easymock.PowerMock; |
| 31 | import org.powermock.core.classloader.annotations.PrepareForTest; |
| 32 | import org.powermock.modules.junit4.PowerMockRunner; |
| 33 | |
| 34 | import com.thinkaurelius.titan.core.TitanFactory; |
| 35 | import com.thinkaurelius.titan.core.TitanGraph; |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 36 | import com.tinkerpop.blueprints.Vertex; |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * @author Toshio Koide |
| 40 | * |
| 41 | */ |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 42 | |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 43 | @RunWith(PowerMockRunner.class) |
| 44 | @PrepareForTest({TitanFactory.class}) |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 45 | public class GraphDBOperationTest extends TestCase { |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 46 | private static TitanGraph testdb; |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 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 Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 69 | testdb = TestDatabaseManager.getTestDatabase(); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 70 | // TestDatabaseManager.populateTestData(titanGraph); |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 71 | |
| 72 | String dummyPath = "/dummy/to/conf"; |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 73 | // replace return value of TitanFactory.open() to dummy DB created above |
| 74 | PowerMock.mockStatic(TitanFactory.class); |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 75 | EasyMock.expect(TitanFactory.open(dummyPath)).andReturn(testdb); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 76 | PowerMock.replay(TitanFactory.class); |
| 77 | |
Toshio Koide | bfe9b92 | 2013-06-18 10:56:05 -0700 | [diff] [blame] | 78 | op = new GraphDBOperation(dummyPath); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /** |
| 82 | * @throws java.lang.Exception |
| 83 | */ |
| 84 | @After |
| 85 | public void tearDown() throws Exception { |
Toshio Koide | bfe9b92 | 2013-06-18 10:56:05 -0700 | [diff] [blame] | 86 | op.close(); |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 87 | testdb.shutdown(); |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 88 | PowerMock.verifyAll(); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 92 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#newSwitch(net.onrc.onos.graph.GraphDBConnection)}. |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 93 | */ |
| 94 | @Test |
| 95 | public final void testNewSwitch() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 96 | assertNull(op.searchSwitch("123")); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 97 | |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 98 | op.newSwitch("123"); |
Toshio Koide | a9a0300 | 2013-06-13 13:10:48 -0700 | [diff] [blame] | 99 | op.commit(); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 100 | |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 101 | ISwitchObject sw = op.searchSwitch("123"); |
| 102 | assertNotNull(op); |
| 103 | assertEquals("123", sw.getDPID()); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 107 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#searchSwitch(net.onrc.onos.graph.GraphDBConnection, java.lang.String)}. |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 108 | */ |
| 109 | @Test |
| 110 | public final void testSearchSwitch() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 111 | op.newSwitch("123"); |
| 112 | op.newSwitch("456"); |
Toshio Koide | a9a0300 | 2013-06-13 13:10:48 -0700 | [diff] [blame] | 113 | op.commit(); |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 114 | |
| 115 | ISwitchObject sw = op.searchSwitch("123"); |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 116 | assertNotNull(sw); |
| 117 | assertEquals("123", sw.getDPID()); |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 118 | |
| 119 | sw = op.searchSwitch("789"); |
| 120 | assertNull(sw); |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 124 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#searchActiveSwitch(net.onrc.onos.graph.GraphDBConnection, java.lang.String)}. |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 125 | */ |
| 126 | @Test |
| 127 | public final void testSearchActiveSwitch() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 128 | op.newSwitch("111").setState(SwitchState.ACTIVE.toString()); |
| 129 | op.newSwitch("222").setState(SwitchState.INACTIVE.toString()); |
Toshio Koide | a9a0300 | 2013-06-13 13:10:48 -0700 | [diff] [blame] | 130 | op.commit(); |
| 131 | |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 132 | ISwitchObject sw = op.searchActiveSwitch("111"); |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 133 | assertNotNull(sw); |
| 134 | assertEquals("111", sw.getDPID()); |
| 135 | |
| 136 | sw = op.searchActiveSwitch("222"); |
| 137 | assertNull(sw); |
| 138 | } |
| 139 | |
| 140 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 141 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getActiveSwitches(net.onrc.onos.graph.GraphDBConnection)}. |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 142 | */ |
| 143 | @Test |
| 144 | public final void testGetActiveSwitches() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 145 | op.newSwitch("111").setState(SwitchState.ACTIVE.toString()); |
| 146 | op.newSwitch("222").setState(SwitchState.INACTIVE.toString()); |
Toshio Koide | a9a0300 | 2013-06-13 13:10:48 -0700 | [diff] [blame] | 147 | op.commit(); |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 148 | |
| 149 | Iterator<ISwitchObject> i = op.getActiveSwitches().iterator(); |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 150 | |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 151 | assertTrue(i.hasNext()); |
| 152 | assertEquals("111", i.next().getDPID()); |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 153 | assertFalse(i.hasNext()); |
| 154 | } |
| 155 | |
| 156 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 157 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getAllSwitches(net.onrc.onos.graph.GraphDBConnection)}. |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 158 | */ |
| 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 Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 175 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getInactiveSwitches(net.onrc.onos.graph.GraphDBConnection)}. |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 176 | */ |
| 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 Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 191 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getAllSwitchNotUpdatedFlowEntries(net.onrc.onos.graph.GraphDBConnection)}. |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 192 | */ |
| 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 Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 213 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#removeSwitch(net.onrc.onos.graph.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject)}. |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 214 | */ |
| 215 | @Test |
| 216 | public final void testRemoveSwitch() { |
| 217 | ISwitchObject sw = op.newSwitch("123"); |
Toshio Koide | a9a0300 | 2013-06-13 13:10:48 -0700 | [diff] [blame] | 218 | op.commit(); |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 219 | sw = op.searchSwitch("123"); |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 220 | assertNotNull(sw); |
| 221 | |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 222 | op.removeSwitch(sw); |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 223 | op.commit(); |
| 224 | |
| 225 | assertNull(op.searchSwitch("123")); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 229 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#newPort(net.onrc.onos.graph.GraphDBConnection)}. |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 230 | */ |
| 231 | @Test |
| 232 | public final void testNewPort() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 233 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 245 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#searchPort(net.onrc.onos.graph.GraphDBConnection, java.lang.String, short)}. |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 246 | */ |
| 247 | @Test |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 248 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 295 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#removePort(net.onrc.onos.graph.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IPortObject)}. |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 296 | */ |
| 297 | @Test |
| 298 | public final void testRemovePort() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 299 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 328 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#newDevice(net.onrc.onos.graph.GraphDBConnection)}. |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 329 | */ |
| 330 | @Test |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 331 | 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 Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 347 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#searchDevice(net.onrc.onos.graph.GraphDBConnection, java.lang.String)}. |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 348 | */ |
| 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 365 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getDevices(net.onrc.onos.graph.GraphDBConnection)}. |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 366 | */ |
| 367 | @Test |
| 368 | public final void testGetDevices() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 369 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 386 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#removeDevice(net.onrc.onos.graph.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IDeviceObject)}. |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 387 | */ |
| 388 | @Test |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 389 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 399 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#newFlowPath(net.onrc.onos.graph.GraphDBConnection)}. |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 400 | */ |
| 401 | @Test |
| 402 | public final void testNewFlowPath() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 403 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 414 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#searchFlowPath(net.onrc.onos.graph.GraphDBConnection, net.floodlightcontroller.util.FlowId)}. |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 415 | */ |
| 416 | @Test |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 417 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 430 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getFlowPathByFlowEntry(net.onrc.onos.graph.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry)}. |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 431 | */ |
| 432 | @Test |
| 433 | public final void testGetFlowPathByFlowEntry() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 434 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 469 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getAllFlowPaths(net.onrc.onos.graph.GraphDBConnection)}. |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 470 | */ |
| 471 | @Test |
| 472 | public final void testGetAllFlowPaths() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 473 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 493 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#removeFlowPath(net.onrc.onos.graph.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath)}. |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 494 | */ |
| 495 | @Test |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 496 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 513 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#newFlowEntry(net.onrc.onos.graph.GraphDBConnection)}. |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 514 | */ |
| 515 | @Test |
| 516 | public final void testNewFlowEntry() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 517 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 529 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#searchFlowEntry(net.onrc.onos.graph.GraphDBConnection, net.floodlightcontroller.util.FlowEntryId)}. |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 530 | */ |
| 531 | @Test |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 532 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 552 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#getAllFlowEntries(net.onrc.onos.graph.GraphDBConnection)}. |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 553 | */ |
| 554 | @Test |
| 555 | public final void testGetAllFlowEntries() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 556 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 576 | * Test method for {@link net.onrc.onos.graph.GraphDBOperation#removeFlowEntry(net.onrc.onos.graph.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry)}. |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 577 | */ |
| 578 | @Test |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 579 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 593 | } |
| 594 | |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 595 | } |