blob: b0e83cc115fbc7293be6ec70dae7a78dbd325a3e [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
2* Copyright 2011, Big Switch Networks, Inc.
3* Originally created by David Erickson, Stanford University
4*
5* Licensed under the Apache License, Version 2.0 (the "License"); you may
6* not use this file except in compliance with the License. You may obtain
7* a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14* License for the specific language governing permissions and limitations
15* under the License.
16**/
17
18package net.floodlightcontroller.test;
19
20import junit.framework.TestCase;
21import net.floodlightcontroller.core.FloodlightContext;
22import net.floodlightcontroller.core.IFloodlightProviderService;
23import net.floodlightcontroller.core.test.MockFloodlightProvider;
24import net.floodlightcontroller.devicemanager.IDevice;
25import net.floodlightcontroller.devicemanager.IDeviceService;
26import net.floodlightcontroller.packet.Ethernet;
27
28import org.junit.Test;
29import org.openflow.protocol.OFMessage;
30import org.openflow.protocol.OFPacketIn;
31import org.openflow.protocol.OFType;
32
33/**
34 * This class gets a handle on the application context which is used to
35 * retrieve Spring beans from during tests
36 *
37 * @author David Erickson (daviderickson@cs.stanford.edu)
38 */
39public class FloodlightTestCase extends TestCase {
40 protected MockFloodlightProvider mockFloodlightProvider;
41
42 public MockFloodlightProvider getMockFloodlightProvider() {
43 return mockFloodlightProvider;
44 }
45
46 public void setMockFloodlightProvider(MockFloodlightProvider mockFloodlightProvider) {
47 this.mockFloodlightProvider = mockFloodlightProvider;
48 }
49
50 public FloodlightContext parseAndAnnotate(OFMessage m,
51 IDevice srcDevice,
52 IDevice dstDevice) {
53 FloodlightContext bc = new FloodlightContext();
54 return parseAndAnnotate(bc, m, srcDevice, dstDevice);
55 }
56
57 public FloodlightContext parseAndAnnotate(OFMessage m) {
58 return parseAndAnnotate(m, null, null);
59 }
60
61 public FloodlightContext parseAndAnnotate(FloodlightContext bc,
62 OFMessage m,
63 IDevice srcDevice,
64 IDevice dstDevice) {
65 if (OFType.PACKET_IN.equals(m.getType())) {
66 OFPacketIn pi = (OFPacketIn)m;
67 Ethernet eth = new Ethernet();
68 eth.deserialize(pi.getPacketData(), 0, pi.getPacketData().length);
69 IFloodlightProviderService.bcStore.put(bc,
70 IFloodlightProviderService.CONTEXT_PI_PAYLOAD,
71 eth);
72 }
73 if (srcDevice != null) {
74 IDeviceService.fcStore.put(bc,
75 IDeviceService.CONTEXT_SRC_DEVICE,
76 srcDevice);
77 }
78 if (dstDevice != null) {
79 IDeviceService.fcStore.put(bc,
80 IDeviceService.CONTEXT_DST_DEVICE,
81 dstDevice);
82 }
83 return bc;
84 }
85
86 @Override
87 public void setUp() throws Exception {
88 mockFloodlightProvider = new MockFloodlightProvider();
89 }
90
91 @Test
92 public void testSanity() throws Exception {
93 assertTrue(true);
94 }
95}