Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | */ |
Toshio Koide | e32a4ec | 2013-06-27 11:51:21 -0700 | [diff] [blame] | 4 | package net.onrc.onos.graph; |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 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 | e32a4ec | 2013-06-27 11:51:21 -0700 | [diff] [blame] | 98 | ISwitchObject sw = op.newSwitch("123"); |
| 99 | assertEquals(sw.getDPID(), "123"); |
Toshio Koide | a9a0300 | 2013-06-13 13:10:48 -0700 | [diff] [blame] | 100 | op.commit(); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 101 | |
Toshio Koide | e32a4ec | 2013-06-27 11:51:21 -0700 | [diff] [blame] | 102 | sw = op.searchSwitch("123"); |
| 103 | assertNotNull(sw); |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 104 | assertEquals("123", sw.getDPID()); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 108 | * 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] | 109 | */ |
| 110 | @Test |
| 111 | public final void testSearchSwitch() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 112 | op.newSwitch("123"); |
| 113 | op.newSwitch("456"); |
Toshio Koide | a9a0300 | 2013-06-13 13:10:48 -0700 | [diff] [blame] | 114 | op.commit(); |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 115 | |
| 116 | ISwitchObject sw = op.searchSwitch("123"); |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 117 | assertNotNull(sw); |
| 118 | assertEquals("123", sw.getDPID()); |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 119 | |
| 120 | sw = op.searchSwitch("789"); |
| 121 | assertNull(sw); |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 125 | * 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] | 126 | */ |
| 127 | @Test |
| 128 | public final void testSearchActiveSwitch() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 129 | op.newSwitch("111").setState(SwitchState.ACTIVE.toString()); |
| 130 | op.newSwitch("222").setState(SwitchState.INACTIVE.toString()); |
Toshio Koide | a9a0300 | 2013-06-13 13:10:48 -0700 | [diff] [blame] | 131 | op.commit(); |
| 132 | |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 133 | ISwitchObject sw = op.searchActiveSwitch("111"); |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 134 | assertNotNull(sw); |
| 135 | assertEquals("111", sw.getDPID()); |
| 136 | |
| 137 | sw = op.searchActiveSwitch("222"); |
| 138 | assertNull(sw); |
| 139 | } |
| 140 | |
| 141 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 142 | * 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] | 143 | */ |
| 144 | @Test |
| 145 | public final void testGetActiveSwitches() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 146 | op.newSwitch("111").setState(SwitchState.ACTIVE.toString()); |
| 147 | op.newSwitch("222").setState(SwitchState.INACTIVE.toString()); |
Toshio Koide | a9a0300 | 2013-06-13 13:10:48 -0700 | [diff] [blame] | 148 | op.commit(); |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 149 | |
| 150 | Iterator<ISwitchObject> i = op.getActiveSwitches().iterator(); |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 151 | |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 152 | assertTrue(i.hasNext()); |
| 153 | assertEquals("111", i.next().getDPID()); |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 154 | assertFalse(i.hasNext()); |
| 155 | } |
| 156 | |
| 157 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 158 | * 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] | 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 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 176 | * 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] | 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 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 192 | * 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] | 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 Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 214 | * 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] | 215 | */ |
| 216 | @Test |
| 217 | public final void testRemoveSwitch() { |
| 218 | ISwitchObject sw = op.newSwitch("123"); |
Toshio Koide | a9a0300 | 2013-06-13 13:10:48 -0700 | [diff] [blame] | 219 | op.commit(); |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 220 | sw = op.searchSwitch("123"); |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 221 | assertNotNull(sw); |
| 222 | |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 223 | op.removeSwitch(sw); |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 224 | op.commit(); |
| 225 | |
| 226 | assertNull(op.searchSwitch("123")); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 230 | * 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] | 231 | */ |
| 232 | @Test |
| 233 | public final void testNewPort() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 234 | assertFalse(testdb.getVertices("type", "port").iterator().hasNext()); |
| 235 | |
Toshio Koide | e32a4ec | 2013-06-27 11:51:21 -0700 | [diff] [blame] | 236 | IPortObject port = op.newPort("1", (short) 10); |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 246 | * 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] | 247 | */ |
| 248 | @Test |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 249 | public final void testSearchPort() { |
| 250 | ISwitchObject sw; |
| 251 | IPortObject port; |
| 252 | |
| 253 | sw = op.newSwitch("1"); |
Toshio Koide | e32a4ec | 2013-06-27 11:51:21 -0700 | [diff] [blame] | 254 | sw.addPort(op.newPort("1", (short) 1)); |
| 255 | sw.addPort(op.newPort("1", (short) 2)); |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 256 | |
| 257 | sw = op.newSwitch("2"); |
Toshio Koide | e32a4ec | 2013-06-27 11:51:21 -0700 | [diff] [blame] | 258 | sw.addPort(op.newPort("2", (short) 1)); |
| 259 | sw.addPort(op.newPort("2", (short) 2)); |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 296 | * 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] | 297 | */ |
| 298 | @Test |
| 299 | public final void testRemovePort() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 300 | ISwitchObject sw; |
| 301 | IPortObject port; |
| 302 | |
| 303 | sw = op.newSwitch("1"); |
Toshio Koide | e32a4ec | 2013-06-27 11:51:21 -0700 | [diff] [blame] | 304 | sw.addPort(op.newPort("1", (short) 1)); |
| 305 | sw.addPort(op.newPort("1", (short) 2)); |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 329 | * 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] | 330 | */ |
| 331 | @Test |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 332 | 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 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 348 | * 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] | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 366 | * 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] | 367 | */ |
| 368 | @Test |
| 369 | public final void testGetDevices() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 370 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 387 | * 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] | 388 | */ |
| 389 | @Test |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 390 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 400 | * 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] | 401 | */ |
| 402 | @Test |
| 403 | public final void testNewFlowPath() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 404 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 415 | * 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] | 416 | */ |
| 417 | @Test |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 418 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 431 | * 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] | 432 | */ |
| 433 | @Test |
| 434 | public final void testGetFlowPathByFlowEntry() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 435 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 470 | * 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] | 471 | */ |
| 472 | @Test |
| 473 | public final void testGetAllFlowPaths() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 474 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 494 | * 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] | 495 | */ |
| 496 | @Test |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 497 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 514 | * 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] | 515 | */ |
| 516 | @Test |
| 517 | public final void testNewFlowEntry() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 518 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 530 | * 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] | 531 | */ |
| 532 | @Test |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 533 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 553 | * 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] | 554 | */ |
| 555 | @Test |
| 556 | public final void testGetAllFlowEntries() { |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 557 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | /** |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 577 | * 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] | 578 | */ |
| 579 | @Test |
Toshio Koide | 880f4c7 | 2013-06-17 14:43:11 -0700 | [diff] [blame] | 580 | 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 594 | } |
| 595 | |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 596 | } |