blob: 9765af8770b43b3eff03d6f17f390538faa77022 [file] [log] [blame]
Teru68076a42013-06-27 14:57:49 -07001package net.onrc.onos.ofcontroller.core;
2
3import static org.junit.Assert.*;
4
5import java.util.ArrayList;
6import java.util.HashMap;
7
8import net.onrc.onos.graph.GraphDBConnection;
9import net.onrc.onos.graph.GraphDBOperation;
10import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
11import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
12import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
13import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
14import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager;
15import org.easymock.EasyMock;
16import org.junit.After;
17import org.junit.Before;
18import org.junit.Test;
19import org.junit.runner.RunWith;
20import org.powermock.api.easymock.PowerMock;
21import org.powermock.core.classloader.annotations.PrepareForTest;
22import org.slf4j.LoggerFactory;
23import org.powermock.modules.junit4.PowerMockRunner;
24
25import com.thinkaurelius.titan.core.TitanFactory;
26import com.thinkaurelius.titan.core.TitanGraph;
27
28//Add Powermock preparation
29@RunWith(PowerMockRunner.class)
30@PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, SwitchStorageImpl.class})
31public class INetMapTopologyObjectsIFlowPathTest {
32
33 //The test network is ./titan/schema/test-network.xml
34
35 protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
36
37 String conf;
38 private GraphDBConnection conn = null;
39 private GraphDBOperation ope = null;
40 private TitanGraph titanGraph = null;
41 private IFlowPath flowPath = null;
42 private IFlowEntry flowEntry = null;
43
44 @Before
45 public void setUp() throws Exception {
46 conf = "/dummy/path/to/db";
47
48 // Make mock cassandra DB
49 // Replace TitanFactory.open() to return mock DB
50 TestDatabaseManager.deleteTestDatabase();
51 titanGraph = TestDatabaseManager.getTestDatabase();
52 //TestDatabaseManager.populateTestData(titanGraph);
53 PowerMock.mockStatic(TitanFactory.class);
54 EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph);
55 PowerMock.replay(TitanFactory.class);
56
57 conn = GraphDBConnection.getInstance(conf);
58 ope = new GraphDBOperation(conn);
59
60 flowPath = ope.newFlowPath();
61 flowEntry = ope.newFlowEntry();
62 flowEntry.setState("zz");
63 }
64
65 @After
66 public void tearDown() throws Exception {
67 titanGraph.shutdown();
68 TestDatabaseManager.deleteTestDatabase();
69 }
70
71 /**
72 * Desc:
73 * Test method for get and set FlowId method.
74 * Condition:
75 * N/A
76 * Expect:
77 * 1. Should set the flow id.
78 * 2. Should get the flow id.
79 */
80 @Test
81 public void testSetGetFlowId() {
82 String flowId = "xx";
83 flowPath.setFlowId(flowId);
84 assertEquals(flowPath.getFlowId(), flowId);
85 }
86
87 /**
88 * Desc:
89 * Test method for get and set InstallerId method.
90 * Condition:
91 * N/A
92 * Expect:
93 * 1. Should set the installer id.
94 * 2. Should get the installer id.
95 */
96 @Test
97 public void testSetGetInstallerId() {
98 String flowId = "xx";
99 String installerId = "yy";
100 flowPath.setFlowId(flowId);
101 flowPath.setInstallerId(installerId);
102 assertEquals(flowPath.getInstallerId(), installerId);
103 }
104
105 /**
106 * Desc:
107 * Test method for get and set SourceSwitch method.
108 * Condition:
109 * N/A
110 * Expect:
111 * 1. Should set the source switch.
112 * 2. Should get the source switch.
113 */
114 @Test
115 public void testSetGetSourceSwitch() {
116 String flowId = "xx";
117 String sourceSwitch = "aa";
118 flowPath.setFlowId(flowId);
119 flowPath.setSrcSwitch(sourceSwitch);
120 assertEquals(flowPath.getSrcSwitch(), sourceSwitch);
121 }
122
123 /**
124 * Desc:
125 * Test method for get and set SourcePort method.
126 * Condition:
127 * N/A
128 * Expect:
129 * 1. Should set the source port.
130 * 2. Should get the source port.
131 */
132 @Test
133 public void testSetGetSourcePort() {
134 String flowId = "xx";
135 Short sourcePort = 1;
136 flowPath.setFlowId(flowId);
137 flowPath.setSrcPort(sourcePort);
138 assertEquals(flowPath.getSrcPort(), sourcePort);
139 }
140
141 /**
142 * Desc:
143 * Test method for get and set DestSwitch method.
144 * Condition:
145 * N/A
146 * Expect:
147 * 1. Should set the dest switch.
148 * 2. Should get the dest switch.
149 */
150 @Test
151 public void testSetGetDestSwitch() {
152 String flowId = "xx";
153 String destSwitch = "bb";
154 flowPath.setFlowId(flowId);
155 flowPath.setDstSwitch(destSwitch);
156 assertEquals(flowPath.getDstSwitch(), destSwitch);
157 }
158
159 /**
160 * Desc:
161 * Test method for get and set DestPort method.
162 * Condition:
163 * N/A
164 * Expect:
165 * 1. Should set the source dest port.
166 * 2. Should get the source dest port.
167 */
168 @Test
169 public void testSetGetDstPort() {
170 String flowId = "xx";
171 Short dstPort = 2;
172 flowPath.setFlowId(flowId);
173 flowPath.setDstPort(dstPort);
174 assertEquals(flowPath.getDstPort(), dstPort);
175 }
176
177 /**
178 * Desc:
179 * Test method for get and set DataPathSummary method.
180 * Condition:
181 * N/A
182 * Expect:
183 * 1. Should set the data path summary.
184 * 2. Should get the data path summary.
185 */
186 @Test
187 public void testSetGetDataPathSummary() {
188 String flowId = "xx";
189 String dataPathSummary = "yy";
190 flowPath.setFlowId(flowId);
191 flowPath.setInstallerId(dataPathSummary);
192 assertEquals(flowPath.getInstallerId(), dataPathSummary);
193 }
194
195 public boolean testIFlowEntry(IFlowPath fp, IFlowEntry fe)
196 {
197 ArrayList<IFlowEntry> flowEntryList = new ArrayList<IFlowEntry>();
198 for(IFlowEntry inFlowEntry : fp.getFlowEntries())
199 {
200 flowEntryList.add(inFlowEntry);
201 }
202 return flowEntryList.contains(fe);
203 }
204
205 /**
206 * Desc:
207 * Test method for addFlowEntry and getFlorEntries method.
208 * Condition:
209 * N/A
210 * Expect:
211 * 1. Should add the FlowEntry.
212 * 2. Should get the FlowEntries. It is tested in the testIFlowEntry method.
213 */
214 @Test
215 public void testAddFlowEntryAndGetFlowEntries() {
216 String flowId = "xx";
217 flowPath.setFlowId(flowId);
218 flowPath.addFlowEntry(flowEntry);
219 IFlowEntry flowEntry2 = ope.newFlowEntry();
220 flowPath.addFlowEntry(flowEntry2);
221 assertTrue(testIFlowEntry(flowPath, flowEntry));
222 assertTrue(testIFlowEntry(flowPath, flowEntry2));
223 }
224
225 /**
226 * Desc:
227 * Test method for remove FlowEntry.
228 * Condition:
229 * N/A
230 * Expect:
231 * 1. Should remove FlowEntry.
232 */
233 @Test
234 public void testRemoveFlowEntry() {
235 String flowId = "xx";
236 flowPath.setFlowId(flowId);
237 flowPath.addFlowEntry(flowEntry);
238 flowPath.removeFlowEntry(flowEntry);
239 assertTrue(!testIFlowEntry(flowPath, flowEntry));
240 }
241
242 /**
243 * Desc:
244 * Test method for set and get MatchEthernetFrameType
245 * Condition:
246 * N/A
247 * Expect:
248 * 1. Should set MatchEthernetFrameType.
249 * 2. Should get MatchEthernetFrameType.
250 */
251 @Test
252 public void testSetGetMatchEthernetFrameType() {
253 String flowId = "xx";
254 Short matchEthernetFrameTypeShort = 1;
255 flowPath.setFlowId(flowId);
256 flowPath.setMatchEthernetFrameType(matchEthernetFrameTypeShort);
257 assertEquals(flowPath.getMatchEthernetFrameType(), matchEthernetFrameTypeShort);
258 }
259
260 /**
261 * Desc:
262 * Test method for set and get MatchSrcMac
263 * Condition:
264 * N/A
265 * Expect:
266 * 1. Should set MatchSrcMac.
267 * 2. Should get MatchSrcMac.
268 */
269 @Test
270 public void testSetGetMatchSrcMac() {
271 String flowId = "xx";
272 String matchSrcMac = "00:00:00:00:00:11";
273 flowPath.setFlowId(flowId);
274 flowPath.setMatchSrcMac(matchSrcMac);
275 assertEquals(flowPath.getMatchSrcMac(), matchSrcMac);
276 }
277
278 /**
279 * Desc:
280 * Test method for set and get MatchDstMac.
281 * Condition:
282 * N/A
283 * Expect:
284 * 1. Should set MatchDstMac.
285 * 2. Should get MatchDstMac.
286 */
287 @Test
288 public void testSetGetMatchDstMac() {
289 String flowId = "xx";
290 String matchDstMac = "00:00:00:00:00:11";
291 flowPath.setFlowId(flowId);
292 flowPath.setMatchDstMac(matchDstMac);
293 assertEquals(flowPath.getMatchDstMac(), matchDstMac);
294 }
295
296 /**
297 * Desc:
298 * Test method for set and get SrcIPv4Net.
299 * Condition:
300 * N/A
301 * Expect:
302 * 1. Should set SrcIPv4Net.
303 * 2. Should get SrcIPv4Net.
304 */
305 @Test
306 public void testSetGetMatchSrcIPv4Net() {
307 String flowId = "xx";
308 String ip = "192.168.0.1";
309 flowPath.setFlowId(flowId);
310 flowPath.setMatchSrcIPv4Net(ip);
311 assertEquals(flowPath.getMatchSrcIPv4Net(), ip);
312 }
313
314 /**
315 * Desc:
316 * Test method for set and get DstIPv4Net.
317 * Condition:
318 * N/A
319 * Expect:
320 * 1. Should set DstIPv4Net.
321 * 2. Should get DstIPv4Net.
322 */
323 @Test
324 public void testSetGetMatchDstIPv4Net() {
325 String flowId = "xx";
326 String ip = "192.168.0.1";
327 flowPath.setFlowId(flowId);
328 flowPath.setMatchDstIPv4Net(ip);
329 assertEquals(flowPath.getMatchDstIPv4Net(), ip);
330 }
331
332 /**
333 * Desc:
334 * Test method for set and get UserState.
335 * Condition:
336 * N/A
337 * Expect:
338 * 1. Should set UserState.
339 * 2. Should get UserState.
340 */
341 @Test
342 public void testSetGetUserState() {
343 String flowId = "xx";
344 String userStatus = "Good";
345 flowPath.setFlowId(flowId);
346 flowPath.setUserState(userStatus);
347 assertEquals(flowPath.getUserState(), userStatus);
348 }
349
350 /**
351 * Desc:
352 * Test method for get Switches.
353 * Condition:
354 * N/A
355 * Expect:
356 * 1. Should get switches.
357 */
358 @Test
359 public void testGetSwitches() {
360 String flowId = "xx";
361 String dpid = "1";
362 flowPath.setFlowId(flowId);
363 ISwitchObject sw = ope.newSwitch(dpid);
364 flowEntry.setSwitch(sw);
365 flowPath.addFlowEntry(flowEntry);
366
367 HashMap<String, ISwitchObject> swList = new HashMap<String, ISwitchObject>();
368 for(ISwitchObject insw : flowPath.getSwitches()){
369 swList.put(sw.getDPID(), insw);
370 }
371
372 assertTrue(swList.containsKey(dpid));
373 }
374
375 //TODO Dont know how to set the state property.
376 @Test
377 public void testGetState() {
378 String status = null;
379 assertEquals(flowPath.getState(), status);
380 }
381
382
383}