Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.core.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 | import static org.junit.Assert.fail; |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 7 | |
| 8 | import java.util.Iterator; |
| 9 | |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 10 | import net.floodlightcontroller.core.ISwitchStorage; |
| 11 | import net.floodlightcontroller.core.ISwitchStorage.SwitchState; |
| 12 | |
| 13 | import org.junit.After; |
| 14 | import org.junit.Before; |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 15 | import org.junit.Ignore; |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 16 | import org.junit.Test; |
| 17 | import org.openflow.protocol.OFPhysicalPort; |
| 18 | |
| 19 | import com.thinkaurelius.titan.core.TitanGraph; |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 20 | import com.tinkerpop.blueprints.Vertex; |
| 21 | import com.tinkerpop.gremlin.java.GremlinPipeline; |
| 22 | |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 23 | public class SwitchStorageImplTest { |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 24 | |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 25 | private ISwitchStorage switchStorage; |
| 26 | private TitanGraph titanGraph; |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 27 | |
| 28 | @Before |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 29 | public void setUp() throws Exception { |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 30 | titanGraph = TestDatabaseManager.getTestDatabase(); |
| 31 | TestDatabaseManager.populateTestData(titanGraph); |
| 32 | |
| 33 | switchStorage = new TestableSwitchStorageImpl(titanGraph); |
| 34 | } |
| 35 | |
| 36 | @After |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 37 | public void tearDown() throws Exception { |
| 38 | titanGraph.shutdown(); |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 39 | } |
| 40 | |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 41 | @Ignore @Test |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 42 | public void testUpdate() { |
| 43 | fail("Not yet implemented"); |
| 44 | } |
| 45 | |
| 46 | @Test |
| 47 | public void testAddPort() { |
| 48 | |
| 49 | String dpid = "00:00:00:00:00:00:0a:01"; |
| 50 | short portNumber = 5; |
| 51 | |
| 52 | OFPhysicalPort portToAdd = new OFPhysicalPort(); |
| 53 | portToAdd.setName("port 5 at SEA switch"); |
| 54 | portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue()); |
| 55 | portToAdd.setPortNumber(portNumber); |
| 56 | |
| 57 | switchStorage.addPort(dpid, portToAdd); |
| 58 | |
| 59 | Vertex sw = titanGraph.getVertices("dpid", dpid).iterator().next(); |
| 60 | |
| 61 | GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>(); |
| 62 | pipe.start(sw).out("on").has("number", portNumber); |
| 63 | |
| 64 | assertTrue(pipe.hasNext()); |
| 65 | Vertex addedPort = pipe.next(); |
| 66 | assertFalse(pipe.hasNext()); |
| 67 | |
| 68 | assertEquals(addedPort.getProperty("number"), portNumber); |
| 69 | } |
| 70 | |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 71 | @Ignore @Test |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 72 | public void testGetPorts() { |
| 73 | fail("Not yet implemented"); |
| 74 | } |
| 75 | |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 76 | @Ignore @Test |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 77 | public void testGetPortStringShort() { |
| 78 | fail("Not yet implemented"); |
| 79 | } |
| 80 | |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 81 | @Ignore @Test |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 82 | public void testGetPortStringString() { |
| 83 | fail("Not yet implemented"); |
| 84 | } |
| 85 | |
| 86 | @Test |
| 87 | public void testAddSwitch() { |
| 88 | String dpid = "00:00:00:00:00:00:0a:07"; |
| 89 | |
| 90 | switchStorage.addSwitch(dpid); |
| 91 | |
| 92 | Iterator<Vertex> it = titanGraph.getVertices("dpid", dpid).iterator(); |
| 93 | assertTrue(it.hasNext()); |
| 94 | Vertex addedSwitch = it.next(); |
| 95 | assertFalse(it.hasNext()); |
| 96 | |
| 97 | assertEquals(addedSwitch.getProperty("type"), "switch"); |
| 98 | assertEquals(addedSwitch.getProperty("dpid"), dpid); |
| 99 | assertEquals(addedSwitch.getProperty("state"), SwitchState.ACTIVE.toString()); |
| 100 | } |
| 101 | |
| 102 | |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 103 | @Test |
| 104 | public void testDeleteSwitch() { |
| 105 | String dpid = "00:00:00:00:00:00:0a:01"; |
| 106 | |
| 107 | switchStorage.deleteSwitch(dpid); |
| 108 | |
| 109 | Iterator<Vertex> it = titanGraph.getVertices("dpid", dpid).iterator(); |
| 110 | assertFalse(it.hasNext()); |
| 111 | } |
| 112 | |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 113 | @Test |
| 114 | public void testDeletePortByPortNum() { |
| 115 | //FIXME fails because query for the port is wrong in SwitchStorageImpl |
| 116 | |
| 117 | String dpid = "00:00:00:00:00:00:0a:01"; |
| 118 | short portNum = 3; |
| 119 | |
| 120 | switchStorage.deletePort(dpid, portNum); |
| 121 | |
| 122 | Vertex sw = titanGraph.getVertices("dpid", dpid).iterator().next(); |
| 123 | |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 124 | /* |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 125 | Iterator<Vertex> it = sw.getVertices(Direction.OUT, "on").iterator(); |
| 126 | |
| 127 | while (it.hasNext()){ |
| 128 | System.out.println(it.next()); |
| 129 | } |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 130 | */ |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 131 | |
| 132 | GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>(); |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 133 | pipe.start(sw).out("on").has("number", portNum); |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 134 | assertFalse(pipe.hasNext()); |
| 135 | } |
| 136 | |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 137 | @Ignore @Test |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 138 | public void testDeletePortStringString() { |
| 139 | fail("Not yet implemented"); |
| 140 | } |
| 141 | |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 142 | @Ignore @Test |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 143 | public void testGetActiveSwitches() { |
| 144 | fail("Not yet implemented"); |
| 145 | } |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 146 | } |