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 | |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 7 | import java.util.Iterator; |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 8 | import java.util.List; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 9 | |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 10 | import net.floodlightcontroller.core.INetMapStorage.DM_OPERATION; |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 11 | import net.floodlightcontroller.core.internal.TestDatabaseManager; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 12 | import net.floodlightcontroller.linkdiscovery.ILinkStorage; |
| 13 | import net.floodlightcontroller.routing.Link; |
| 14 | |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 15 | import org.junit.After; |
| 16 | import org.junit.Before; |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 17 | import org.junit.Ignore; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 18 | import org.junit.Test; |
| 19 | |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 20 | import com.thinkaurelius.titan.core.TitanGraph; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 21 | import com.tinkerpop.blueprints.Vertex; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 22 | import com.tinkerpop.gremlin.java.GremlinPipeline; |
| 23 | |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 24 | public class LinkStorageImplTest { |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 25 | private static ILinkStorage linkStorage; |
| 26 | private static TitanGraph titanGraph; |
| 27 | |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 28 | //TODO Future ideas: |
| 29 | //Test add links with CREATE and UPDATE |
| 30 | //Test adding existing link again |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 31 | |
| 32 | @Before |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 33 | public void setUp() throws Exception{ |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 34 | titanGraph = TestDatabaseManager.getTestDatabase(); |
| 35 | TestDatabaseManager.populateTestData(titanGraph); |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 36 | |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 37 | linkStorage = new TestableLinkStorageImpl(titanGraph); |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 38 | } |
| 39 | |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 40 | @After |
| 41 | public void tearDown() throws Exception { |
| 42 | titanGraph.shutdown(); |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | /* |
| 46 | * Add a link between port 1.102 and 2.104 |
| 47 | * i.e SEA switch port 3 to LAX switch port 1 |
| 48 | */ |
| 49 | @Test |
| 50 | public void testAddSingleLink(){ |
| 51 | Link linkToAdd = new Link(Long.decode("0x0000000000000a01"), 3, Long.decode("0x0000000000000a02"), 1); |
| 52 | |
| 53 | //Use the link storage API to add the link |
| 54 | linkStorage.update(linkToAdd, ILinkStorage.DM_OPERATION.INSERT); |
| 55 | |
| 56 | //Test if it was added correctly with the Gremlin API |
| 57 | GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>(); |
| 58 | Iterator<Vertex> it = titanGraph.getVertices("dpid", "00:00:00:00:00:00:0a:01").iterator(); |
| 59 | |
| 60 | assertTrue(it.hasNext()); |
| 61 | Vertex sw1 = it.next(); |
| 62 | assertFalse(it.hasNext()); |
| 63 | |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 64 | pipe.start(sw1).out("on").has("number", (short)3).out("link").in("on"); |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 65 | |
| 66 | assertTrue(pipe.hasNext()); |
| 67 | Vertex sw2 = pipe.next(); |
| 68 | assertFalse(pipe.hasNext()); |
| 69 | |
| 70 | //Check we ended up at the right vertex |
| 71 | assertEquals((String)sw2.getProperty("dpid"), "00:00:00:00:00:00:0a:02"); |
| 72 | } |
| 73 | |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 74 | //TODO enable once method is written |
| 75 | @Ignore @Test |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 76 | public void testGetLinks(){ |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 77 | //TODO Make sure this works when the implementation is written |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 78 | List<Link> list = linkStorage.getLinks(Long.decode("0x0000000000000a01"), (short)2); |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 79 | |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 80 | assertEquals(list.size(), 1); |
| 81 | |
| 82 | Link l = list.get(0); |
| 83 | assertEquals(l.getSrc(), 2561L); |
| 84 | assertEquals(l.getSrcPort(), (short)2); |
| 85 | assertEquals(l.getDst(), 2563L); |
| 86 | assertEquals(l.getDstPort(), (short)1); |
| 87 | } |
| 88 | |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 89 | //TODO enable once method is written |
| 90 | @Ignore @Test |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 91 | public void testUpdateDelete(){ |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 92 | Link linkToDelete = new Link(Long.decode("0x0000000000000a01"), 2, Long.decode("0x0000000000000a03"), 1); |
| 93 | |
| 94 | linkStorage.update(linkToDelete, DM_OPERATION.DELETE); |
| 95 | |
| 96 | //Test if it was deleted correctly with the Gremlin API |
| 97 | GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>(); |
| 98 | Iterator<Vertex> it = titanGraph.getVertices("dpid", "00:00:00:00:00:00:0a:01").iterator(); |
| 99 | |
| 100 | assertTrue(it.hasNext()); |
| 101 | Vertex sw1 = it.next(); |
| 102 | assertFalse(it.hasNext()); |
| 103 | |
| 104 | pipe.start(sw1).out("on").has("number", 2).out("link"); |
| 105 | |
| 106 | assertFalse(pipe.hasNext()); |
| 107 | } |
| 108 | |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 109 | //TODO enable once method is written |
| 110 | @Ignore @Test |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 111 | public void testDeleteLinks(){ |
| 112 | //TODO Make sure this works when the implementation is written |
| 113 | |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 114 | linkStorage.deleteLinksOnPort(Long.decode("0x0000000000000a01"), (short)2); |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 115 | |
| 116 | //Test if it was deleted correctly with the Gremlin API |
| 117 | GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>(); |
| 118 | Iterator<Vertex> it = titanGraph.getVertices("dpid", "00:00:00:00:00:00:0a:01").iterator(); |
| 119 | |
| 120 | assertTrue(it.hasNext()); |
| 121 | Vertex sw1 = it.next(); |
| 122 | assertFalse(it.hasNext()); |
| 123 | |
| 124 | pipe.start(sw1).out("on").has("number", 2).out("link"); |
| 125 | |
| 126 | assertFalse(pipe.hasNext()); |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 127 | } |
| 128 | |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 129 | } |