blob: 7edc1c53168db8c300e8d75b9e579bd15220b175 [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;
52 private GraphDBConnection conn = null;
53 private GraphDBOperation ope = null;
54 private TitanGraph titanGraph = null;
55 ISwitchStorage swSt = null;
56
57 @Before
58 public void setUp() throws Exception {
59
60 swSt = new SwitchStorageImpl();
61 conf = "/dummy/path/to/db";
62
63 // Make mock cassandra DB
64 // Replace TitanFactory.open() to return mock DB
65 titanGraph = TestDatabaseManager.getTestDatabase();
66 TestDatabaseManager.populateTestData(titanGraph);
67 PowerMock.mockStatic(TitanFactory.class);
68 EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph);
69 PowerMock.replay(TitanFactory.class);
70
71 conn = GraphDBConnection.getInstance(conf);
72 ope = new GraphDBOperation(conn);
73
74 swSt.init(conf);
75 }
76
77 @After
78 public void tearDown() throws Exception {
79
80 titanGraph.shutdown();
81 TestDatabaseManager.deleteTestDatabase();
82
83 swSt.close();
84 swSt = null;
85 }
86
87 /**
88 * Desc:
89 * Test method for addSwitch method.
90 * Condition:
91 * Normal
92 * Expect:
93 * 1. Switch should be generated.
94 * 2. The status of switch should be ACTIVE
95 */
96 //@Ignore
97 @Test
98 public void testAddSwitch() {
99 String dpid = "00:00:00:00:00:00:0a:07";
100
101 ISwitchObject sw = ope.searchSwitch(dpid);
102 assertTrue(sw == null);
103 swSt.addSwitch(dpid);
104 ISwitchObject sw2 = ope.searchSwitch(dpid);
105 assertTrue(sw2 != null);
106 assertEquals(sw2.getState(), "ACTIVE");
107 }
108
109 /**
110 * Desc:
111 * Test method for addSwitch method.
112 * Condition:
Teru4fd58642013-06-21 07:54:49 -0700113 * The existing switch status is INACTIVE.
114 * The switch is already existing.
Teruab4b01a2013-06-20 10:09:57 -0700115 * Expect:
Teru4fd58642013-06-21 07:54:49 -0700116 * 1. After add the same switch, the status of switch should be ACTIVE
Teruab4b01a2013-06-20 10:09:57 -0700117 */
118 //@Ignore
119 @Test
120 public void testAddSwitchExisting() {
121 String dpid = "00:00:00:00:00:00:0a:06";
122
Naoki Shiota987a5722013-10-23 11:59:36 -0700123 swSt.updateSwitch(dpid, SwitchState.INACTIVE, DM_OPERATION.UPDATE);
Teruab4b01a2013-06-20 10:09:57 -0700124 ISwitchObject sw = ope.searchSwitch(dpid);
125 assertTrue(sw != null);
126 assertEquals(sw.getState(), SwitchState.INACTIVE.toString());
127 swSt.addSwitch(dpid);
128 ISwitchObject sw2 = ope.searchSwitch(dpid);
129 assertTrue(sw2 != null);
130 assertEquals(sw2.getState(), SwitchState.ACTIVE.toString());
131 }
132
133 /**
134 * Desc:
135 * Test method for testUpdate method.
136 * Condition:
Teru4fd58642013-06-21 07:54:49 -0700137 * The switch is not existing.
138 * The status of added switch is INACTIVE.
139 * DM_OPERATION is CREATE.
Teruab4b01a2013-06-20 10:09:57 -0700140 * Expect:
141 * 1. Switch should be created.
142 * 2. The status of switch should be INACTIVE.
143 */
144 //@Ignore
145 @Test
146 public void testUpdate() {
147 String dpid = "00:00:00:00:00:00:0a:07";
148 SwitchState state = ISwitchStorage.SwitchState.INACTIVE;
149 DM_OPERATION dmope = INetMapStorage.DM_OPERATION.CREATE;
150
151 ISwitchObject sw = ope.searchSwitch(dpid);
152 assertTrue(sw == null);
Naoki Shiota987a5722013-10-23 11:59:36 -0700153 swSt.updateSwitch(dpid, state, dmope);
Teruab4b01a2013-06-20 10:09:57 -0700154 ISwitchObject sw2 = ope.searchSwitch(dpid);
155 assertTrue(sw2 != null);
156 assertEquals(sw2.getState(), state.toString());
157 }
158
159 /**
160 * Desc:
161 * Test method for testUpdate method.
162 * Condition:
163 * The switch is existing.
Teru4fd58642013-06-21 07:54:49 -0700164 * The status of added switch is ACTIVE.
165 * DM_OPERATION is DELETE.
Teruab4b01a2013-06-20 10:09:57 -0700166 * Expect:
167 * 1. Switch should be deleted.
168 */
169 //@Ignore
170 @Test
171 public void testUpdateWithDELETE() {
172 String dpid = "00:00:00:00:00:00:0a:06";
173 SwitchState state = ISwitchStorage.SwitchState.ACTIVE;
174 DM_OPERATION dmope = INetMapStorage.DM_OPERATION.DELETE;
175
176 ISwitchObject sw = ope.searchSwitch(dpid);
177 assertTrue(sw != null);
Naoki Shiota987a5722013-10-23 11:59:36 -0700178 swSt.updateSwitch(dpid, state, dmope);
Teruab4b01a2013-06-20 10:09:57 -0700179 ISwitchObject sw2 = ope.searchSwitch(dpid);
180 assertTrue(sw2 == null);
181 }
182
183 /**
184 * Desc:
185 * Test method for delete switch method.
186 * Condition:
187 * The switch is existing.
188 * Expect:
189 * 1. Switch should be deleted.
190 */
191 //@Ignore
192 @Test
193 public void testDeleteSwitch() {
194 String dpid = "00:00:00:00:00:00:0a:06";
195
196 ISwitchObject sw = ope.searchSwitch(dpid);
197 assertTrue(sw != null);
198 swSt.deleteSwitch(dpid);
199 ISwitchObject sw2 = ope.searchSwitch(dpid);
200 assertTrue(sw2 == null);
201 }
202
203 /**
204 * Desc:
205 * Test method for delete switch method.
206 * Condition:
207 * The switch is not existing.
208 * Expect:
Teru4fd58642013-06-21 07:54:49 -0700209 * Nothing happens.
Teruab4b01a2013-06-20 10:09:57 -0700210 */
211 //@Ignore
212 @Test
213 public void testDeleteNonExistingSwitch() {
214 String dpid = "00:00:00:00:00:00:0a:07";
215
216 ISwitchObject sw = ope.searchSwitch(dpid);
217 assertTrue(sw == null);
218 swSt.deleteSwitch(dpid);
219 ISwitchObject sw2 = ope.searchSwitch(dpid);
220 assertTrue(sw2 == null);
221 }
222
223 /**
224 * Desc:
225 * Test method for delete port method.
226 * Condition:
227 * The port is existing.
228 * Expect:
Teru4fd58642013-06-21 07:54:49 -0700229 * Deleted the port.
Teruab4b01a2013-06-20 10:09:57 -0700230 */
231 //@Ignore
232 @Test
233 public void testDeletePort() {
234 String dpid = "00:00:00:00:00:00:0a:06";
235 short portNumber = 3;
236
237 IPortObject portObj1 = ope.searchPort(dpid, portNumber);
238 assertTrue(portObj1 != null);
239 swSt.deletePort(dpid, portNumber);
240 IPortObject portObj2 = ope.searchPort(dpid, portNumber);
241 assertTrue(portObj2 == null);
242 }
243
244 /**
245 * Desc:
246 * Test method for delete port method.
247 * Condition:
248 * The port is not existing.
249 * Expect:
250 * Nothing happens.
251 */
252 //@Ignore
253 @Test
254 public void testDeleteNonExistingPort() {
255 String dpid = "00:00:00:00:00:00:0a:06";
256 short portNumber = 4;
257
258 IPortObject portObj1 = ope.searchPort(dpid, portNumber);
259 assertTrue(portObj1 == null);
260 swSt.deletePort(dpid, portNumber);
261 IPortObject portObj2 = ope.searchPort(dpid, portNumber);
262 assertTrue(portObj2 == null);
263 }
264
265 /**
266 * Desc:
Teru4fd58642013-06-21 07:54:49 -0700267 * Test method for add port method.
Teruab4b01a2013-06-20 10:09:57 -0700268 * Condition:
269 * The port is not existing.
270 * Expect:
271 * The port should be added.
Teru4fd58642013-06-21 07:54:49 -0700272 * The desc of IPortObject is the same as the name of OFPhysicalPort.
Teruab4b01a2013-06-20 10:09:57 -0700273 */
274 //@Ignore
275 @Test
276 public void testAddPort() {
277 String dpid = "00:00:00:00:00:00:0a:06";
278 short portNumber = 4;
279 String name = "port 4 at ATL Switch";
280 int state = OFPortState.OFPPS_STP_FORWARD.getValue();
281 OFPhysicalPort port = new OFPhysicalPort();
282 port.setPortNumber(portNumber);
283 port.setName(name);
284 port.setState(state);
285
286 ISwitchObject sw = ope.searchSwitch(dpid);
287 assertTrue(sw != null);
288 swSt.addPort(dpid, port);
289 IPortObject portObj = ope.searchPort(dpid, portNumber);
290 assertTrue(portObj != null);
Teru4fd58642013-06-21 07:54:49 -0700291 assertEquals(portObj.getDesc(), name);
Teruab4b01a2013-06-20 10:09:57 -0700292 }
293
294 /**
295 * Desc:
296 * Test method for add method.
297 * Condition:
298 * The port is existing.
299 * Expect:
300 * Nothing happens.
301 */
302 //@Ignore
303 @Test
304 public void testAddExistingPort() {
305 String dpid = "00:00:00:00:00:00:0a:06";
306 short portNumber = 3;
Teru4fd58642013-06-21 07:54:49 -0700307 String name = "xxx";
Teruab4b01a2013-06-20 10:09:57 -0700308 int state = OFPortState.OFPPS_STP_FORWARD.getValue();
309 OFPhysicalPort port = new OFPhysicalPort();
310 port.setPortNumber(portNumber);
311 port.setName(name);
312 port.setState(state);
313
314 ISwitchObject sw = ope.searchSwitch(dpid);
315 assertTrue(sw != null);
316 swSt.addPort(dpid, port);
317 IPortObject portObj = ope.searchPort(dpid, portNumber);
318 assertTrue(portObj != null);
319 }
320
321 /**
322 * Desc:
323 * Test method for add method.
324 * Condition:
325 * The port status is down.
326 * Expect:
327 * Delete the port.
328 */
329 //@Ignore
330 @Test
331 public void testAddDownPort() {
332 String dpid = "00:00:00:00:00:00:0a:06";
333 short portNumber = 3;
334 String name = "port 3 at ATL Switch";
335 int state = OFPortState.OFPPS_LINK_DOWN.getValue();
336 OFPhysicalPort port = new OFPhysicalPort();
337 port.setPortNumber(portNumber);
338 port.setName(name);
339 port.setState(state);
340
341 ISwitchObject sw = ope.searchSwitch(dpid);
342 assertTrue(sw != null);
343 swSt.addPort(dpid, port);
344 IPortObject portObj = ope.searchPort(dpid, portNumber);
345 assertTrue(portObj == null);
346 }
347}