Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.linkdiscovery.internal; |
| 2 | |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 3 | import static org.junit.Assert.assertEquals; |
| 4 | import static org.junit.Assert.assertFalse; |
| 5 | import static org.junit.Assert.assertTrue; |
| 6 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 7 | import java.util.ArrayList; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 8 | import java.util.Iterator; |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 9 | import java.util.List; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 10 | |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 11 | import net.floodlightcontroller.core.INetMapStorage.DM_OPERATION; |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 12 | import net.floodlightcontroller.core.internal.TestDatabaseManager; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 13 | import net.floodlightcontroller.linkdiscovery.ILinkStorage; |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 14 | import net.floodlightcontroller.linkdiscovery.LinkInfo; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 15 | import net.floodlightcontroller.routing.Link; |
| 16 | |
mininet | 37dc589 | 2013-06-04 10:58:44 -0700 | [diff] [blame] | 17 | import org.easymock.EasyMock; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 18 | import org.junit.After; |
| 19 | import org.junit.Before; |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 20 | import org.junit.Ignore; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 21 | import org.junit.Test; |
mininet | 37dc589 | 2013-06-04 10:58:44 -0700 | [diff] [blame] | 22 | import org.junit.runner.RunWith; |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 23 | import org.openflow.util.HexString; |
mininet | 37dc589 | 2013-06-04 10:58:44 -0700 | [diff] [blame] | 24 | import org.powermock.api.easymock.PowerMock; |
| 25 | import org.powermock.core.classloader.annotations.PrepareForTest; |
| 26 | import org.powermock.modules.junit4.PowerMockRunner; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 27 | |
mininet | 37dc589 | 2013-06-04 10:58:44 -0700 | [diff] [blame] | 28 | import com.thinkaurelius.titan.core.TitanFactory; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 29 | import com.thinkaurelius.titan.core.TitanGraph; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 30 | import com.tinkerpop.blueprints.Vertex; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 31 | import com.tinkerpop.gremlin.java.GremlinPipeline; |
| 32 | |
mininet | 37dc589 | 2013-06-04 10:58:44 -0700 | [diff] [blame] | 33 | @RunWith(PowerMockRunner.class) |
| 34 | @PrepareForTest({TitanFactory.class}) |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 35 | public class LinkStorageImplTest { |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 36 | private static ILinkStorage linkStorage; |
| 37 | private static TitanGraph titanGraph; |
| 38 | |
mininet | 37dc589 | 2013-06-04 10:58:44 -0700 | [diff] [blame] | 39 | //private static IController |
| 40 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 41 | /** |
| 42 | * Setup code called before each tests. |
| 43 | * Read test graph data and replace DB access by test graph data. |
| 44 | * @throws Exception |
| 45 | */ |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 46 | @Before |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 47 | public void setUp() throws Exception{ |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 48 | TestDatabaseManager.deleteTestDatabase(); |
| 49 | |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 50 | titanGraph = TestDatabaseManager.getTestDatabase(); |
| 51 | TestDatabaseManager.populateTestData(titanGraph); |
mininet | 37dc589 | 2013-06-04 10:58:44 -0700 | [diff] [blame] | 52 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 53 | // replace return value of TitanFactory.open() to dummy DB created above |
mininet | 37dc589 | 2013-06-04 10:58:44 -0700 | [diff] [blame] | 54 | PowerMock.mockStatic(TitanFactory.class); |
| 55 | EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph); |
| 56 | PowerMock.replay(TitanFactory.class); |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 57 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 58 | linkStorage = new LinkStorageImpl(); |
| 59 | |
| 60 | // initialize with dummy string |
mininet | 37dc589 | 2013-06-04 10:58:44 -0700 | [diff] [blame] | 61 | linkStorage.init("/dummy/path/to/db"); |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 62 | } |
| 63 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 64 | /** |
| 65 | * Closing code called after each tests. |
| 66 | * Discard test graph data. |
| 67 | * @throws Exception |
| 68 | */ |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 69 | @After |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 70 | public void tearDown() throws Exception { |
| 71 | // finish code |
| 72 | linkStorage.close(); |
| 73 | |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 74 | titanGraph.shutdown(); |
mininet | 37dc589 | 2013-06-04 10:58:44 -0700 | [diff] [blame] | 75 | TestDatabaseManager.deleteTestDatabase(); |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 76 | } |
| 77 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 78 | // TODO: remove @Ignore after UPDATE method will be implemented |
| 79 | @Ignore @Test |
| 80 | public void testUpdate_UpdateSingleLink() { |
| 81 | Link linkToUpdate= createExistingLink(); |
| 82 | LinkInfo infoToUpdate = new LinkInfo( |
| 83 | System.currentTimeMillis(), |
| 84 | System.currentTimeMillis(), |
| 85 | System.currentTimeMillis(), |
| 86 | 0, 0); |
| 87 | |
| 88 | linkStorage.update(linkToUpdate, infoToUpdate, ILinkStorage.DM_OPERATION.UPDATE); |
| 89 | |
| 90 | // TODO: get LinkInfo from titanGraph and verify |
| 91 | } |
| 92 | |
| 93 | @Test |
| 94 | public void testUpdate_CreateSingleLink() { |
| 95 | Link linkToCreate = createFeasibleLink(); |
| 96 | Link linkToVerify = createFeasibleLink(); |
| 97 | |
| 98 | //Use the link storage API to add the link |
| 99 | linkStorage.update(linkToCreate, ILinkStorage.DM_OPERATION.CREATE); |
| 100 | doTestLinkIsInGraph(linkToVerify); |
| 101 | |
| 102 | // Add same link |
| 103 | Link linkToCreateTwice = createFeasibleLink(); |
| 104 | linkStorage.update(linkToCreateTwice, ILinkStorage.DM_OPERATION.CREATE); |
| 105 | |
| 106 | // this occurs assertion failure if there are two links in titanGraph |
| 107 | doTestLinkIsInGraph(linkToVerify); |
| 108 | } |
| 109 | |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 110 | @Test |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 111 | public void testUpdate_InsertSingleLink(){ |
| 112 | Link linkToInsert = createFeasibleLink(); |
| 113 | Link linkToVerify = createFeasibleLink(); |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 114 | |
| 115 | //Use the link storage API to add the link |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 116 | linkStorage.update(linkToInsert, ILinkStorage.DM_OPERATION.INSERT); |
| 117 | |
| 118 | doTestLinkIsInGraph(linkToVerify); |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 119 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 120 | // Add same link |
| 121 | Link linkToInsertTwice = createFeasibleLink(); |
| 122 | linkStorage.update(linkToInsertTwice, ILinkStorage.DM_OPERATION.INSERT); |
| 123 | |
| 124 | // this occurs assertion failure if there are two links in titanGraph |
| 125 | doTestLinkIsInGraph(linkToVerify); |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 126 | } |
| 127 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 128 | @Test |
| 129 | public void testUpdate_DeleteSingleLink(){ |
| 130 | Link linkToDelete = createExistingLink(); |
| 131 | Link linkToVerify = createExistingLink(); |
| 132 | |
| 133 | // Test deletion of existing link |
| 134 | linkStorage.update(linkToDelete, DM_OPERATION.DELETE); |
| 135 | doTestLinkIsNotInGraph(linkToVerify); |
| 136 | |
| 137 | linkToDelete = createFeasibleLink(); |
| 138 | linkToVerify = createFeasibleLink(); |
| 139 | |
| 140 | // Test deletion of not-existing link |
| 141 | linkStorage.update(linkToDelete, DM_OPERATION.DELETE); |
| 142 | doTestLinkIsNotInGraph(linkToVerify); |
| 143 | } |
| 144 | |
| 145 | // TODO: remove @Ignore after UPDATE method will be implemented |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 146 | @Ignore @Test |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 147 | public void testUpdate_UpdateLinks(){ |
| 148 | List<Link> linksToUpdate= createExistingLinks(); |
| 149 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 150 | // TODO: Who calls update method like this way? Remove this test if unneeded. |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 151 | linkStorage.update(linksToUpdate, ILinkStorage.DM_OPERATION.UPDATE); |
| 152 | |
| 153 | // TODO: verification of update result |
| 154 | } |
| 155 | |
| 156 | @Test |
| 157 | public void testUpdate_CreateLinks(){ |
| 158 | List<Link> linksToCreate = createFeasibleLinks(); |
| 159 | List<Link> linksToVerify = createFeasibleLinks(); |
| 160 | |
| 161 | // Test creation of new links |
| 162 | linkStorage.update(linksToCreate, ILinkStorage.DM_OPERATION.CREATE); |
| 163 | for(Link l : linksToVerify) { |
| 164 | doTestLinkIsInGraph(l); |
| 165 | } |
| 166 | |
| 167 | // Test creation of existing links |
| 168 | linksToCreate = createFeasibleLinks(); |
| 169 | linkStorage.update(linksToCreate, ILinkStorage.DM_OPERATION.CREATE); |
| 170 | for(Link l : linksToVerify) { |
| 171 | doTestLinkIsInGraph(l); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | @Test |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 176 | public void testUpdate_CreateLinks_Mixuture(){ |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 177 | List<Link> linksToCreate = new ArrayList<Link>(); |
| 178 | linksToCreate.add(createFeasibleLink()); |
| 179 | linksToCreate.add(createExistingLink()); |
| 180 | |
| 181 | // Test creation of mixture of new/existing links |
| 182 | linkStorage.update(linksToCreate, ILinkStorage.DM_OPERATION.CREATE); |
| 183 | doTestLinkIsInGraph(createFeasibleLink()); |
| 184 | doTestLinkIsInGraph(createExistingLink()); |
| 185 | } |
| 186 | |
| 187 | @Test |
| 188 | public void testUpdate_InsertLinks(){ |
| 189 | List<Link> linksToInsert = createFeasibleLinks(); |
| 190 | List<Link> linksToVerify = createFeasibleLinks(); |
| 191 | |
| 192 | // Test insertion of new links |
| 193 | linkStorage.update(linksToInsert, ILinkStorage.DM_OPERATION.INSERT); |
| 194 | for(Link l : linksToVerify) { |
| 195 | doTestLinkIsInGraph(l); |
| 196 | } |
| 197 | |
| 198 | // Test insertion of existing links |
| 199 | linksToInsert = createFeasibleLinks(); |
| 200 | linkStorage.update(linksToInsert, ILinkStorage.DM_OPERATION.INSERT); |
| 201 | for(Link l : linksToVerify) { |
| 202 | doTestLinkIsInGraph(l); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | @Test |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 207 | public void testUpdate_InsertLinks_Mixuture(){ |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 208 | List<Link> linksToInsert = new ArrayList<Link>(); |
| 209 | linksToInsert.add(createFeasibleLink()); |
| 210 | linksToInsert.add(createExistingLink()); |
| 211 | |
| 212 | // Test insertion of mixture of new/existing links |
| 213 | linkStorage.update(linksToInsert, ILinkStorage.DM_OPERATION.INSERT); |
| 214 | doTestLinkIsInGraph(createFeasibleLink()); |
| 215 | doTestLinkIsInGraph(createExistingLink()); |
| 216 | } |
| 217 | |
| 218 | |
| 219 | @Test |
| 220 | public void testUpdate_DeleteLinks(){ |
| 221 | List<Link> linksToDelete = createExistingLinks(); |
| 222 | List<Link> linksToVerify = createExistingLinks(); |
| 223 | |
| 224 | // Test deletion of existing links |
| 225 | linkStorage.update(linksToDelete, ILinkStorage.DM_OPERATION.DELETE); |
| 226 | for(Link l : linksToVerify) { |
| 227 | doTestLinkIsNotInGraph(l); |
| 228 | } |
| 229 | |
| 230 | // Test deletion of not-existing links |
| 231 | linksToDelete = createExistingLinks(); |
| 232 | linkStorage.update(linksToDelete, ILinkStorage.DM_OPERATION.DELETE); |
| 233 | for(Link l : linksToVerify) { |
| 234 | doTestLinkIsNotInGraph(l); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | @Test |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 239 | public void testUpdate_DeleteLinks_Mixuture(){ |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 240 | List<Link> linksToDelete = new ArrayList<Link>(); |
| 241 | linksToDelete.add(createFeasibleLink()); |
| 242 | linksToDelete.add(createExistingLink()); |
| 243 | |
| 244 | // Test deletion of mixture of new/existing links |
| 245 | linkStorage.update(linksToDelete, ILinkStorage.DM_OPERATION.DELETE); |
| 246 | doTestLinkIsNotInGraph(createFeasibleLink()); |
| 247 | doTestLinkIsNotInGraph(createExistingLink()); |
| 248 | } |
| 249 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 250 | @Ignore @Test |
| 251 | public void testAddOrUpdateLink_Update() { |
| 252 | Link linkToUpdate= createExistingLink(); |
| 253 | LinkInfo infoToUpdate = new LinkInfo( |
| 254 | System.currentTimeMillis(), |
| 255 | System.currentTimeMillis(), |
| 256 | System.currentTimeMillis(), |
| 257 | 0, 0); |
| 258 | |
| 259 | linkStorage.addOrUpdateLink(linkToUpdate, infoToUpdate, ILinkStorage.DM_OPERATION.UPDATE); |
| 260 | |
| 261 | // TODO: get LinkInfo from titanGraph and verify |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 262 | |
| 263 | } |
| 264 | |
| 265 | @Test |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 266 | public void testAddOrUpdateLink_Create() { |
| 267 | Link linkToCreate = createFeasibleLink(); |
| 268 | Link linkToVerify = createFeasibleLink(); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 269 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 270 | //Use the link storage API to add the link |
| 271 | linkStorage.addOrUpdateLink(linkToCreate, null, ILinkStorage.DM_OPERATION.CREATE); |
| 272 | doTestLinkIsInGraph(linkToVerify); |
| 273 | |
| 274 | // Add same link |
| 275 | Link linkToCreateTwice = createFeasibleLink(); |
| 276 | linkStorage.addOrUpdateLink(linkToCreateTwice, null, ILinkStorage.DM_OPERATION.CREATE); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 277 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 278 | // this occurs assertion failure if there are two links in titanGraph |
| 279 | doTestLinkIsInGraph(linkToVerify); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | @Test |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 283 | public void testAddOrUpdateLink_Insert() { |
| 284 | Link linkToInsert = createFeasibleLink(); |
| 285 | Link linkToVerify = createFeasibleLink(); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 286 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 287 | //Use the link storage API to add the link |
| 288 | linkStorage.addOrUpdateLink(linkToInsert, null, ILinkStorage.DM_OPERATION.INSERT); |
| 289 | |
| 290 | doTestLinkIsInGraph(linkToVerify); |
| 291 | |
| 292 | // Add same link |
| 293 | Link linkToInsertTwice = createFeasibleLink(); |
| 294 | linkStorage.addOrUpdateLink(linkToInsertTwice, null, ILinkStorage.DM_OPERATION.INSERT); |
| 295 | |
| 296 | // this occurs assertion failure if there are two links in titanGraph |
| 297 | doTestLinkIsInGraph(linkToVerify); |
| 298 | } |
| 299 | |
| 300 | // TODO: Check if addOrUpdateLink() should accept DELETE operation. If not, remove this test. |
| 301 | @Ignore @Test |
| 302 | public void testAddOrUpdateLink_Delete() { |
| 303 | Link linkToDelete = createExistingLink(); |
| 304 | Link linkToVerify = createExistingLink(); |
| 305 | |
| 306 | // Test deletion of existing link |
| 307 | linkStorage.addOrUpdateLink(linkToDelete, null, DM_OPERATION.DELETE); |
| 308 | doTestLinkIsNotInGraph(linkToVerify); |
| 309 | |
| 310 | linkToDelete = createFeasibleLink(); |
| 311 | linkToVerify = createFeasibleLink(); |
| 312 | |
| 313 | // Test deletion of not-existing link |
| 314 | linkStorage.addOrUpdateLink(linkToDelete, null, DM_OPERATION.DELETE); |
| 315 | doTestLinkIsNotInGraph(linkToVerify); |
| 316 | } |
| 317 | |
| 318 | @Test |
| 319 | public void testGetLinks_ByDpidPort(){ |
| 320 | Link linkToVerify = createExistingLink(); |
| 321 | Long dpid = linkToVerify.getSrc(); |
| 322 | short port = (short)linkToVerify.getSrcPort(); |
| 323 | |
| 324 | List<Link> list = linkStorage.getLinks(dpid, port); |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 325 | |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 326 | assertEquals(list.size(), 1); |
| 327 | |
| 328 | Link l = list.get(0); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 329 | assertEquals(l.getSrc(), linkToVerify.getSrc()); |
| 330 | assertEquals(l.getSrcPort(), linkToVerify.getSrcPort()); |
| 331 | assertEquals(l.getDst(), linkToVerify.getDst()); |
| 332 | assertEquals(l.getDstPort(), linkToVerify.getDstPort()); |
| 333 | |
| 334 | Link linkToVerifyNot = createFeasibleLink(); |
| 335 | |
| 336 | List<Link> list2 = linkStorage.getLinks(linkToVerifyNot.getSrc(), (short)linkToVerifyNot.getSrcPort()); |
| 337 | |
| 338 | assertEquals(list2.size(), 0); |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 339 | } |
| 340 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 341 | @Test |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 342 | public void testGetLinks_ByString() { |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 343 | Link linkToVeryfy = createExistingLink(); |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 344 | String dpid = HexString.toHexString(linkToVeryfy.getSrc()); |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 345 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 346 | List<Link> links = linkStorage.getLinks(dpid); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 347 | assertTrue(links.contains(linkToVeryfy)); |
| 348 | |
| 349 | Link linkToVerifyNot = createFeasibleLink(); |
| 350 | assertFalse(links.contains(linkToVerifyNot)); |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 351 | } |
| 352 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 353 | @Test |
| 354 | public void testDeleteLink() { |
| 355 | // Deletion of existing link |
| 356 | Link linkToDelete = createExistingLink(); |
| 357 | Link linkToVerify = createExistingLink(); |
| 358 | |
| 359 | linkStorage.deleteLink(linkToDelete); |
| 360 | doTestLinkIsNotInGraph(linkToVerify); |
| 361 | |
| 362 | // Deletion of not existing link |
| 363 | linkToDelete = createFeasibleLink(); |
| 364 | linkToVerify = createFeasibleLink(); |
| 365 | |
| 366 | linkStorage.deleteLink(linkToDelete); |
| 367 | doTestLinkIsNotInGraph(linkToVerify); |
| 368 | } |
| 369 | |
| 370 | @Test |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 371 | public void testDeleteLinks(){ |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 372 | List<Link> linksToDelete = createExistingLinks(); |
| 373 | List<Link> linksToVerify = createExistingLinks(); |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 374 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 375 | linkStorage.deleteLinks(linksToDelete); |
| 376 | for(Link l : linksToVerify) { |
| 377 | doTestLinkIsNotInGraph(l); |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | @Test |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 382 | public void testDeleteLinks_Mixture(){ |
| 383 | List<Link> linksToDelete = new ArrayList<Link>(); |
| 384 | linksToDelete.add(createFeasibleLink()); |
| 385 | linksToDelete.add(createExistingLink()); |
| 386 | |
| 387 | // Test deletion of mixture of new/existing links |
| 388 | linkStorage.deleteLinks(linksToDelete); |
| 389 | doTestLinkIsNotInGraph(createFeasibleLink()); |
| 390 | doTestLinkIsNotInGraph(createExistingLink()); |
| 391 | } |
| 392 | |
| 393 | @Test |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 394 | public void testGetActiveLinks() { |
| 395 | Link existingLink = createExistingLink(); |
| 396 | Link notExistingLink = createFeasibleLink(); |
| 397 | |
| 398 | List<Link> links = linkStorage.getActiveLinks(); |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 399 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 400 | assertTrue(links.contains(existingLink)); |
| 401 | assertFalse(links.contains(notExistingLink)); |
| 402 | } |
| 403 | |
| 404 | @Test |
| 405 | public void testDeleteLinksOnPort() { |
| 406 | Link linkToDelete = createExistingLink(); |
| 407 | Link linkToVerify = createExistingLink(); |
| 408 | |
| 409 | linkStorage.deleteLinksOnPort(linkToDelete.getSrc(), linkToDelete.getSrcPort()); |
| 410 | |
| 411 | doTestLinkIsNotInGraph(linkToVerify); |
| 412 | } |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 413 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 414 | /** |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 415 | * Test if titanGraph has specific link |
| 416 | * @param link |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 417 | */ |
| 418 | private void doTestLinkIsInGraph(Link link) { |
| 419 | String src_dpid = HexString.toHexString(link.getSrc()); |
| 420 | String dst_dpid = HexString.toHexString(link.getDst()); |
| 421 | short src_port = link.getSrcPort(); |
| 422 | short dst_port = link.getDstPort(); |
| 423 | |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 424 | GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>(); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 425 | Iterator<Vertex> it = titanGraph.getVertices("dpid", src_dpid).iterator(); |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 426 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 427 | // Test if just one switch is found in the graph |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 428 | assertTrue(it.hasNext()); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 429 | Vertex sw = it.next(); |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 430 | assertFalse(it.hasNext()); |
| 431 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 432 | pipe.start(sw).out("on").has("number", src_port).out("link").has("number", dst_port).in("on").has("dpid", dst_dpid); |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 433 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 434 | // Test if just one link is found in the graph |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 435 | assertTrue(pipe.hasNext()); |
| 436 | pipe.next(); |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 437 | assertFalse(pipe.hasNext()); |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 438 | } |
| 439 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 440 | /** |
| 441 | * Test if titanGraph doesn't have specific link |
| 442 | * @param link |
| 443 | */ |
| 444 | private void doTestLinkIsNotInGraph(Link link) { |
| 445 | String src_dpid = HexString.toHexString(link.getSrc()); |
| 446 | String dst_dpid = HexString.toHexString(link.getDst()); |
| 447 | short src_port = link.getSrcPort(); |
| 448 | short dst_port = link.getDstPort(); |
| 449 | |
| 450 | GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>(); |
| 451 | Iterator<Vertex> it = titanGraph.getVertices("dpid", src_dpid).iterator(); |
| 452 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 453 | // Test if just one switch is found in the graph |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 454 | assertTrue(it.hasNext()); |
| 455 | Vertex sw = it.next(); |
| 456 | assertFalse(it.hasNext()); |
| 457 | |
| 458 | pipe.start(sw).out("on").has("number", src_port).out("link").has("number", dst_port).in("on").has("dpid", dst_dpid); |
| 459 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 460 | // Test if no link is found in the graph |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 461 | assertFalse(pipe.hasNext()); |
| 462 | } |
| 463 | |
| 464 | //----------------- Creation of test data ----------------------- |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 465 | /** |
| 466 | * Returns new Link object which has information of existing link in titanGraph |
| 467 | * @return new Link object |
| 468 | */ |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 469 | private Link createExistingLink() { |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 470 | // Link from SEA switch port 2 to CHI switch port 1 |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 471 | return new Link(Long.decode("0x0000000000000a01"), 2, Long.decode("0x0000000000000a03"), 1); |
| 472 | } |
| 473 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 474 | /** |
| 475 | * Returns new Link object which has information of not-existing but feasible link in titanGraph |
| 476 | * @return new Link object |
| 477 | */ |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 478 | private Link createFeasibleLink() { |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 479 | // Link from SEA switch port 1 to LAX switch port 1 |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 480 | return new Link(Long.decode("0x0000000000000a01"), 4, Long.decode("0x0000000000000a02"), 1); |
| 481 | } |
| 482 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 483 | // make NO sense while test-network data doesn't define physical network (i.e. any link is feasible) |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 484 | @SuppressWarnings("unused") |
| 485 | private Link createInfeasibleLink() { |
| 486 | return new Link(Long.decode("0x0000000000000a01"), 1, Long.decode("0x0000000000000a02"), 1); |
| 487 | } |
| 488 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 489 | /** |
| 490 | * Returns list of Link objects which all has information of existing link in titanGraph |
| 491 | * @return ArrayList of new Link objects |
| 492 | */ |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 493 | private List<Link> createExistingLinks() { |
| 494 | List<Link> links = new ArrayList<Link>(); |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 495 | // Link from SEA switch port 2 to CHI switch port 1 |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 496 | links.add(new Link(Long.decode("0x0000000000000a01"), 2, Long.decode("0x0000000000000a03"), 1)); |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 497 | // Link from LAX switch port 1 to SEA switch port 3 |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 498 | links.add(new Link(Long.decode("0x0000000000000a02"), 1, Long.decode("0x0000000000000a01"), 3)); |
| 499 | return links; |
| 500 | } |
| 501 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 502 | /** |
| 503 | * Returns list of Link objects which all has information of not-existing but feasible link |
| 504 | * @return ArrayList of new Link objects |
| 505 | */ |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 506 | private List<Link> createFeasibleLinks() { |
| 507 | List<Link> links = new ArrayList<Link>(); |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 508 | // Link from CHI switch port 4 to NYC switch port 3 |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 509 | links.add(new Link(Long.decode("0x0000000000000a03"), 4, Long.decode("0x0000000000000a05"), 3)); |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame^] | 510 | // Link from SEA switch port 4 to LAX switch port 1 |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 511 | links.add(new Link(Long.decode("0x0000000000000a01"), 4, Long.decode("0x0000000000000a02"), 1)); |
| 512 | return links; |
| 513 | } |
| 514 | //--------------------------------------------------------------- |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 515 | } |