blob: fe51f95970c06ab812fc27a3ed520ce5be3f1bdb [file] [log] [blame]
Teruab4b01a2013-06-20 10:09:57 -07001package net.onrc.onos.ofcontroller.core.internal;
2
Jonathan Hart26bfe5c2013-11-04 12:19:51 -08003import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertTrue;
Teruab4b01a2013-06-20 10:09:57 -07005import net.floodlightcontroller.core.internal.TestDatabaseManager;
Pankaj Berde38646d62013-06-21 11:34:04 -07006import net.onrc.onos.graph.GraphDBConnection;
7import net.onrc.onos.graph.GraphDBOperation;
Teruab4b01a2013-06-20 10:09:57 -07008import net.onrc.onos.ofcontroller.core.INetMapStorage;
9import net.onrc.onos.ofcontroller.core.INetMapStorage.DM_OPERATION;
10import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
11import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
Jonathan Hart26bfe5c2013-11-04 12:19:51 -080012import net.onrc.onos.ofcontroller.core.ISwitchStorage;
13import net.onrc.onos.ofcontroller.core.ISwitchStorage.SwitchState;
14
Teruab4b01a2013-06-20 10:09:57 -070015import org.easymock.EasyMock;
16import org.junit.After;
17import org.junit.Before;
Jonathan Hart26bfe5c2013-11-04 12:19:51 -080018import org.junit.Ignore;
Teruab4b01a2013-06-20 10:09:57 -070019import org.junit.Test;
20import org.junit.runner.RunWith;
21import org.openflow.protocol.OFPhysicalPort;
22import org.openflow.protocol.OFPhysicalPort.OFPortState;
23import org.powermock.api.easymock.PowerMock;
24import org.powermock.core.classloader.annotations.PrepareForTest;
25import org.powermock.modules.junit4.PowerMockRunner;
26import org.slf4j.LoggerFactory;
27
28import com.thinkaurelius.titan.core.TitanFactory;
29import com.thinkaurelius.titan.core.TitanGraph;
30
Jonathan Hart26bfe5c2013-11-04 12:19:51 -080031/*
32 * Jono, 11/4/2013
33 * These tests are being ignored because they don't work because they
34 * rely on test functionality that was written ages ago and hasn't been
35 * updated as the database schema has evolved.
36 * These tests work by getting an in-memory Titan database and testing
37 * the SwitchStorageImpl on top of that. In this regard they're not really
38 * unit tests as they test the entire DB stack (i.e. GraphDBOperation and
39 * GraphDBConnection), not just SwitchStorageImpl.
40 * I've left them here as we may wish to resurrect this kind of
41 * integration testing of the DB layers in the future.
42 */
43@Ignore
Teruab4b01a2013-06-20 10:09:57 -070044//Add Powermock preparation
45@RunWith(PowerMockRunner.class)
46@PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, SwitchStorageImpl.class})
47public class SwitchStorageImplTestBB {
48
49 protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
50
51 String conf;
yoshi2fd4c7e2013-11-22 15:47:55 -080052 String dbStore;
Teruab4b01a2013-06-20 10:09:57 -070053 private GraphDBConnection conn = null;
54 private GraphDBOperation ope = null;
55 private TitanGraph titanGraph = null;
56 ISwitchStorage swSt = null;
57
58 @Before
59 public void setUp() throws Exception {
60
61 swSt = new SwitchStorageImpl();
62 conf = "/dummy/path/to/db";
yoshi2fd4c7e2013-11-22 15:47:55 -080063 dbStore ="dummyStore";
Teruab4b01a2013-06-20 10:09:57 -070064
65 // Make mock cassandra DB
66 // Replace TitanFactory.open() to return mock DB
67 titanGraph = TestDatabaseManager.getTestDatabase();
68 TestDatabaseManager.populateTestData(titanGraph);
69 PowerMock.mockStatic(TitanFactory.class);
70 EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph);
71 PowerMock.replay(TitanFactory.class);
72
73 conn = GraphDBConnection.getInstance(conf);
74 ope = new GraphDBOperation(conn);
75
yoshi2fd4c7e2013-11-22 15:47:55 -080076 swSt.init(dbStore, conf);
Teruab4b01a2013-06-20 10:09:57 -070077 }
78
79 @After
80 public void tearDown() throws Exception {
81
82 titanGraph.shutdown();
83 TestDatabaseManager.deleteTestDatabase();
84
85 swSt.close();
86 swSt = null;
87 }
88
89 /**
90 * Desc:
91 * Test method for addSwitch method.
92 * Condition:
93 * Normal
94 * Expect:
95 * 1. Switch should be generated.
96 * 2. The status of switch should be ACTIVE
97 */
98 //@Ignore
99 @Test
100 public void testAddSwitch() {
101 String dpid = "00:00:00:00:00:00:0a:07";
102
103 ISwitchObject sw = ope.searchSwitch(dpid);
104 assertTrue(sw == null);
105 swSt.addSwitch(dpid);
106 ISwitchObject sw2 = ope.searchSwitch(dpid);
107 assertTrue(sw2 != null);
108 assertEquals(sw2.getState(), "ACTIVE");
109 }
110
111 /**
112 * Desc:
113 * Test method for addSwitch method.
114 * Condition:
Teru4fd58642013-06-21 07:54:49 -0700115 * The existing switch status is INACTIVE.
116 * The switch is already existing.
Teruab4b01a2013-06-20 10:09:57 -0700117 * Expect:
Teru4fd58642013-06-21 07:54:49 -0700118 * 1. After add the same switch, the status of switch should be ACTIVE
Teruab4b01a2013-06-20 10:09:57 -0700119 */
120 //@Ignore
121 @Test
122 public void testAddSwitchExisting() {
123 String dpid = "00:00:00:00:00:00:0a:06";
124
Naoki Shiota987a5722013-10-23 11:59:36 -0700125 swSt.updateSwitch(dpid, SwitchState.INACTIVE, DM_OPERATION.UPDATE);
Teruab4b01a2013-06-20 10:09:57 -0700126 ISwitchObject sw = ope.searchSwitch(dpid);
127 assertTrue(sw != null);
128 assertEquals(sw.getState(), SwitchState.INACTIVE.toString());
129 swSt.addSwitch(dpid);
130 ISwitchObject sw2 = ope.searchSwitch(dpid);
131 assertTrue(sw2 != null);
132 assertEquals(sw2.getState(), SwitchState.ACTIVE.toString());
133 }
134
135 /**
136 * Desc:
137 * Test method for testUpdate method.
138 * Condition:
Teru4fd58642013-06-21 07:54:49 -0700139 * The switch is not existing.
140 * The status of added switch is INACTIVE.
141 * DM_OPERATION is CREATE.
Teruab4b01a2013-06-20 10:09:57 -0700142 * Expect:
143 * 1. Switch should be created.
144 * 2. The status of switch should be INACTIVE.
145 */
146 //@Ignore
147 @Test
148 public void testUpdate() {
149 String dpid = "00:00:00:00:00:00:0a:07";
150 SwitchState state = ISwitchStorage.SwitchState.INACTIVE;
151 DM_OPERATION dmope = INetMapStorage.DM_OPERATION.CREATE;
152
153 ISwitchObject sw = ope.searchSwitch(dpid);
154 assertTrue(sw == null);
Naoki Shiota987a5722013-10-23 11:59:36 -0700155 swSt.updateSwitch(dpid, state, dmope);
Teruab4b01a2013-06-20 10:09:57 -0700156 ISwitchObject sw2 = ope.searchSwitch(dpid);
157 assertTrue(sw2 != null);
158 assertEquals(sw2.getState(), state.toString());
159 }
160
161 /**
162 * Desc:
163 * Test method for testUpdate method.
164 * Condition:
165 * The switch is existing.
Teru4fd58642013-06-21 07:54:49 -0700166 * The status of added switch is ACTIVE.
167 * DM_OPERATION is DELETE.
Teruab4b01a2013-06-20 10:09:57 -0700168 * Expect:
169 * 1. Switch should be deleted.
170 */
171 //@Ignore
172 @Test
173 public void testUpdateWithDELETE() {
174 String dpid = "00:00:00:00:00:00:0a:06";
175 SwitchState state = ISwitchStorage.SwitchState.ACTIVE;
176 DM_OPERATION dmope = INetMapStorage.DM_OPERATION.DELETE;
177
178 ISwitchObject sw = ope.searchSwitch(dpid);
179 assertTrue(sw != null);
Naoki Shiota987a5722013-10-23 11:59:36 -0700180 swSt.updateSwitch(dpid, state, dmope);
Teruab4b01a2013-06-20 10:09:57 -0700181 ISwitchObject sw2 = ope.searchSwitch(dpid);
182 assertTrue(sw2 == null);
183 }
184
185 /**
186 * Desc:
187 * Test method for delete switch method.
188 * Condition:
189 * The switch is existing.
190 * Expect:
191 * 1. Switch should be deleted.
192 */
193 //@Ignore
194 @Test
195 public void testDeleteSwitch() {
196 String dpid = "00:00:00:00:00:00:0a:06";
197
198 ISwitchObject sw = ope.searchSwitch(dpid);
199 assertTrue(sw != null);
200 swSt.deleteSwitch(dpid);
201 ISwitchObject sw2 = ope.searchSwitch(dpid);
202 assertTrue(sw2 == null);
203 }
204
205 /**
206 * Desc:
207 * Test method for delete switch method.
208 * Condition:
209 * The switch is not existing.
210 * Expect:
Teru4fd58642013-06-21 07:54:49 -0700211 * Nothing happens.
Teruab4b01a2013-06-20 10:09:57 -0700212 */
213 //@Ignore
214 @Test
215 public void testDeleteNonExistingSwitch() {
216 String dpid = "00:00:00:00:00:00:0a:07";
217
218 ISwitchObject sw = ope.searchSwitch(dpid);
219 assertTrue(sw == null);
220 swSt.deleteSwitch(dpid);
221 ISwitchObject sw2 = ope.searchSwitch(dpid);
222 assertTrue(sw2 == null);
223 }
224
225 /**
226 * Desc:
227 * Test method for delete port method.
228 * Condition:
229 * The port is existing.
230 * Expect:
Teru4fd58642013-06-21 07:54:49 -0700231 * Deleted the port.
Teruab4b01a2013-06-20 10:09:57 -0700232 */
233 //@Ignore
234 @Test
235 public void testDeletePort() {
236 String dpid = "00:00:00:00:00:00:0a:06";
237 short portNumber = 3;
238
239 IPortObject portObj1 = ope.searchPort(dpid, portNumber);
240 assertTrue(portObj1 != null);
241 swSt.deletePort(dpid, portNumber);
242 IPortObject portObj2 = ope.searchPort(dpid, portNumber);
243 assertTrue(portObj2 == null);
244 }
245
246 /**
247 * Desc:
248 * Test method for delete port method.
249 * Condition:
250 * The port is not existing.
251 * Expect:
252 * Nothing happens.
253 */
254 //@Ignore
255 @Test
256 public void testDeleteNonExistingPort() {
257 String dpid = "00:00:00:00:00:00:0a:06";
258 short portNumber = 4;
259
260 IPortObject portObj1 = ope.searchPort(dpid, portNumber);
261 assertTrue(portObj1 == null);
262 swSt.deletePort(dpid, portNumber);
263 IPortObject portObj2 = ope.searchPort(dpid, portNumber);
264 assertTrue(portObj2 == null);
265 }
266
267 /**
268 * Desc:
Teru4fd58642013-06-21 07:54:49 -0700269 * Test method for add port method.
Teruab4b01a2013-06-20 10:09:57 -0700270 * Condition:
271 * The port is not existing.
272 * Expect:
273 * The port should be added.
Teru4fd58642013-06-21 07:54:49 -0700274 * The desc of IPortObject is the same as the name of OFPhysicalPort.
Teruab4b01a2013-06-20 10:09:57 -0700275 */
276 //@Ignore
277 @Test
278 public void testAddPort() {
279 String dpid = "00:00:00:00:00:00:0a:06";
280 short portNumber = 4;
281 String name = "port 4 at ATL Switch";
282 int state = OFPortState.OFPPS_STP_FORWARD.getValue();
283 OFPhysicalPort port = new OFPhysicalPort();
284 port.setPortNumber(portNumber);
285 port.setName(name);
286 port.setState(state);
287
288 ISwitchObject sw = ope.searchSwitch(dpid);
289 assertTrue(sw != null);
290 swSt.addPort(dpid, port);
291 IPortObject portObj = ope.searchPort(dpid, portNumber);
292 assertTrue(portObj != null);
Teru4fd58642013-06-21 07:54:49 -0700293 assertEquals(portObj.getDesc(), name);
Teruab4b01a2013-06-20 10:09:57 -0700294 }
295
296 /**
297 * Desc:
298 * Test method for add method.
299 * Condition:
300 * The port is existing.
301 * Expect:
302 * Nothing happens.
303 */
304 //@Ignore
305 @Test
306 public void testAddExistingPort() {
307 String dpid = "00:00:00:00:00:00:0a:06";
308 short portNumber = 3;
Teru4fd58642013-06-21 07:54:49 -0700309 String name = "xxx";
Teruab4b01a2013-06-20 10:09:57 -0700310 int state = OFPortState.OFPPS_STP_FORWARD.getValue();
311 OFPhysicalPort port = new OFPhysicalPort();
312 port.setPortNumber(portNumber);
313 port.setName(name);
314 port.setState(state);
315
316 ISwitchObject sw = ope.searchSwitch(dpid);
317 assertTrue(sw != null);
318 swSt.addPort(dpid, port);
319 IPortObject portObj = ope.searchPort(dpid, portNumber);
320 assertTrue(portObj != null);
321 }
322
323 /**
324 * Desc:
325 * Test method for add method.
326 * Condition:
327 * The port status is down.
328 * Expect:
329 * Delete the port.
330 */
331 //@Ignore
332 @Test
333 public void testAddDownPort() {
334 String dpid = "00:00:00:00:00:00:0a:06";
335 short portNumber = 3;
336 String name = "port 3 at ATL Switch";
337 int state = OFPortState.OFPPS_LINK_DOWN.getValue();
338 OFPhysicalPort port = new OFPhysicalPort();
339 port.setPortNumber(portNumber);
340 port.setName(name);
341 port.setState(state);
342
343 ISwitchObject sw = ope.searchSwitch(dpid);
344 assertTrue(sw != null);
345 swSt.addPort(dpid, port);
346 IPortObject portObj = ope.searchPort(dpid, portNumber);
347 assertTrue(portObj == null);
348 }
349}