Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.devicemanager; |
| 2 | |
| 3 | import static org.easymock.EasyMock.anyObject; |
| 4 | import static org.easymock.EasyMock.createMock; |
| 5 | import static org.easymock.EasyMock.createNiceMock; |
| 6 | import static org.easymock.EasyMock.eq; |
| 7 | import static org.easymock.EasyMock.expect; |
| 8 | import static org.easymock.EasyMock.expectLastCall; |
| 9 | import static org.easymock.EasyMock.replay; |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 10 | |
| 11 | import java.util.Date; |
| 12 | |
| 13 | import net.floodlightcontroller.core.IFloodlightProviderService; |
| 14 | import net.floodlightcontroller.core.IListener.Command; |
| 15 | import net.floodlightcontroller.core.IOFSwitch; |
| 16 | import net.floodlightcontroller.core.IUpdate; |
| 17 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 18 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 19 | import net.floodlightcontroller.test.FloodlightTestCase; |
| 20 | import net.floodlightcontroller.util.MACAddress; |
| 21 | import net.onrc.onos.core.datagrid.IDatagridService; |
| 22 | import net.onrc.onos.core.datagrid.IEventChannel; |
| 23 | import net.onrc.onos.core.datagrid.IEventChannelListener; |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 24 | import net.onrc.onos.core.packet.ARP; |
| 25 | import net.onrc.onos.core.packet.DHCP; |
| 26 | import net.onrc.onos.core.packet.Data; |
| 27 | import net.onrc.onos.core.packet.Ethernet; |
| 28 | import net.onrc.onos.core.packet.IPacket; |
| 29 | import net.onrc.onos.core.packet.IPv4; |
| 30 | import net.onrc.onos.core.packet.UDP; |
| 31 | import net.onrc.onos.core.registry.IControllerRegistryService; |
| 32 | import net.onrc.onos.core.topology.ITopologyListener; |
| 33 | import net.onrc.onos.core.topology.ITopologyService; |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 34 | import net.onrc.onos.core.topology.MockTopology; |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 35 | |
| 36 | import org.easymock.EasyMock; |
| 37 | import org.junit.After; |
| 38 | import org.junit.Before; |
| 39 | import org.junit.Test; |
| 40 | import org.openflow.protocol.OFPacketIn; |
| 41 | import org.openflow.protocol.OFType; |
| 42 | |
| 43 | /** |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 44 | * Unit tests for the Device Manager module (OnosDeviceManger). |
| 45 | * These test cases check the result of add/delete device and |
| 46 | * verify the result of processPacketIn through inject faked packets |
| 47 | * floodLightProvider, datagridService, networkGraphService, |
| 48 | * controllerRegistryService, eventChannel are mocked out. |
| 49 | */ |
| 50 | public class OnosDeviceManagerTest extends FloodlightTestCase { |
| 51 | private IPacket pkt0, pkt1, pkt2, pkt3, pkt4; |
| 52 | private IOFSwitch sw1; |
| 53 | private long sw1Dpid; |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 54 | private long sw1DevPort, sw1DevPort2; |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 55 | private OnosDeviceManager odm; |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 56 | private OFPacketIn pktIn, pktIn2; |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 57 | private FloodlightModuleContext modContext; |
| 58 | private ITopologyService networkGraphService; |
| 59 | private IEventChannel<Long, OnosDevice> eventChannel; |
| 60 | private IFloodlightProviderService floodLightProvider; |
| 61 | private Date lastSeenTimestamp; |
| 62 | |
| 63 | @Override |
| 64 | @Before |
Ray Milkey | ff73514 | 2014-05-22 19:06:02 -0700 | [diff] [blame] | 65 | @SuppressWarnings("unchecked") |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 66 | public void setUp() throws Exception { |
| 67 | super.setUp(); |
| 68 | MockTopology topology = new MockTopology(); |
| 69 | IDatagridService datagridService; |
| 70 | IControllerRegistryService controllerRegistryService; |
| 71 | |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 72 | topology.createSampleTopology2(); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 73 | modContext = new FloodlightModuleContext(); |
| 74 | |
| 75 | floodLightProvider = createMock(IFloodlightProviderService.class); |
| 76 | datagridService = createMock(IDatagridService.class); |
| 77 | networkGraphService = createMock(ITopologyService.class); |
| 78 | controllerRegistryService = createMock(IControllerRegistryService.class); |
| 79 | eventChannel = createMock(IEventChannel.class); |
| 80 | expect(networkGraphService.getTopology()).andReturn(topology).anyTimes(); |
| 81 | networkGraphService.registerTopologyListener(anyObject(ITopologyListener.class)); |
| 82 | expectLastCall(); |
| 83 | |
| 84 | expect(datagridService.createChannel("onos.device", Long.class, OnosDevice.class)) |
| 85 | .andReturn(eventChannel).once(); |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 86 | expect(topology.getOutgoingLink(1L, 100L)).andReturn(null).anyTimes(); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 87 | expect(datagridService.addListener( |
| 88 | eq("onos.device"), |
| 89 | anyObject(IEventChannelListener.class), |
| 90 | eq(Long.class), |
| 91 | eq(OnosDevice.class))) |
| 92 | .andReturn(eventChannel).once(); |
| 93 | |
| 94 | replay(datagridService); |
| 95 | replay(networkGraphService); |
| 96 | replay(controllerRegistryService); |
| 97 | |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 98 | modContext.addService(IDatagridService.class, datagridService); |
| 99 | modContext.addService(ITopologyService.class, networkGraphService); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 100 | modContext.addService(IFloodlightProviderService.class, floodLightProvider); |
| 101 | modContext.getServiceImpl(IFloodlightProviderService.class); |
| 102 | sw1Dpid = 1L; |
| 103 | sw1 = createMockSwitch(sw1Dpid); |
| 104 | replay(sw1); |
| 105 | |
| 106 | sw1DevPort = 100; |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 107 | sw1DevPort2 = 12L; |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 108 | |
| 109 | odm = new OnosDeviceManager(); |
| 110 | /* |
Jonathan Hart | 7ab7161 | 2014-05-27 13:37:31 -0700 | [diff] [blame] | 111 | * Broadcast source address |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 112 | */ |
| 113 | this.pkt0 = new Ethernet() |
Jonathan Hart | 7ab7161 | 2014-05-27 13:37:31 -0700 | [diff] [blame] | 114 | .setDestinationMACAddress("00:44:33:22:11:33") |
| 115 | .setSourceMACAddress("FF:FF:FF:FF:FF:FF") |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 116 | .setEtherType(Ethernet.TYPE_IPV4) |
| 117 | .setPayload( |
| 118 | new IPv4() |
| 119 | .setTtl((byte) 128) |
| 120 | .setSourceAddress("192.168.10.1") |
| 121 | .setDestinationAddress("192.168.255.255") |
| 122 | .setPayload(new UDP() |
| 123 | .setSourcePort((short) 5000) |
| 124 | .setDestinationPort((short) 5001) |
| 125 | .setPayload(new Data(new byte[]{0x01})))); |
| 126 | /* |
| 127 | * Normal IPv4 packet |
| 128 | */ |
| 129 | this.pkt1 = new Ethernet() |
| 130 | .setDestinationMACAddress("00:11:22:33:44:55") |
| 131 | .setSourceMACAddress("00:44:33:22:11:00") |
| 132 | .setEtherType(Ethernet.TYPE_IPV4) |
| 133 | .setPayload( |
| 134 | new IPv4() |
| 135 | .setTtl((byte) 128) |
| 136 | .setSourceAddress("192.168.1.1") |
| 137 | .setDestinationAddress("192.168.1.2") |
| 138 | .setPayload(new UDP() |
| 139 | .setSourcePort((short) 5000) |
| 140 | .setDestinationPort((short) 5001) |
| 141 | .setPayload(new Data(new byte[]{0x01})))); |
| 142 | /* |
| 143 | * Same MAC header as pkt1,but not IP address set |
| 144 | */ |
| 145 | this.pkt2 = new Ethernet() |
| 146 | .setSourceMACAddress("00:44:33:22:11:01") |
| 147 | .setDestinationMACAddress("00:11:22:33:44:55") |
| 148 | .setEtherType(Ethernet.TYPE_IPV4) |
| 149 | .setPayload( |
| 150 | new IPv4() |
| 151 | .setTtl((byte) 128) |
| 152 | .setPayload(new UDP() |
| 153 | .setSourcePort((short) 5000) |
| 154 | .setDestinationPort((short) 5001) |
| 155 | .setPayload(new Data(new byte[]{0x01})))); |
| 156 | /* |
| 157 | * DHCP packet |
| 158 | */ |
| 159 | this.pkt3 = new Ethernet() |
| 160 | .setSourceMACAddress("00:44:33:22:11:01") |
| 161 | .setDestinationMACAddress("00:11:22:33:44:55") |
| 162 | .setEtherType(Ethernet.TYPE_IPV4) |
| 163 | .setPayload( |
| 164 | new IPv4() |
| 165 | .setTtl((byte) 128) |
| 166 | .setSourceAddress("192.168.1.1") |
| 167 | .setDestinationAddress("192.168.1.2") |
| 168 | .setPayload(new UDP() |
| 169 | .setSourcePort((short) 5000) |
| 170 | .setDestinationPort((short) 5001) |
| 171 | .setChecksum((short) 0) |
| 172 | .setPayload( |
| 173 | new DHCP() |
| 174 | .setOpCode(DHCP.OPCODE_REPLY) |
| 175 | .setHardwareType(DHCP.HWTYPE_ETHERNET) |
| 176 | .setHardwareAddressLength((byte) 6) |
| 177 | .setHops((byte) 0) |
| 178 | .setTransactionId(0x00003d1d) |
| 179 | .setSeconds((short) 0) |
| 180 | .setFlags((short) 0) |
| 181 | .setClientIPAddress(0) |
| 182 | .setYourIPAddress(0) |
| 183 | .setServerIPAddress(0) |
| 184 | .setGatewayIPAddress(0)))); |
| 185 | /* |
| 186 | * ARP packet |
| 187 | */ |
| 188 | this.pkt4 = new Ethernet() |
| 189 | .setSourceMACAddress("00:44:33:22:11:01") |
| 190 | .setDestinationMACAddress("00:11:22:33:44:55") |
| 191 | .setEtherType(Ethernet.TYPE_ARP) |
| 192 | .setPayload( |
| 193 | new ARP() |
| 194 | .setHardwareType(ARP.HW_TYPE_ETHERNET) |
| 195 | .setProtocolType(ARP.PROTO_TYPE_IP) |
| 196 | .setHardwareAddressLength((byte) 6) |
| 197 | .setProtocolAddressLength((byte) 4) |
| 198 | .setOpCode(ARP.OP_REPLY) |
| 199 | .setSenderHardwareAddress(Ethernet.toMACAddress("00:44:33:22:11:01")) |
| 200 | .setSenderProtocolAddress(IPv4.toIPv4AddressBytes("192.168.1.1")) |
| 201 | .setTargetHardwareAddress(Ethernet.toMACAddress("00:11:22:33:44:55")) |
| 202 | .setTargetProtocolAddress(IPv4.toIPv4AddressBytes("192.168.1.2"))); |
| 203 | |
| 204 | |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 205 | this.pktIn = new OFPacketIn().setInPort((short) sw1DevPort); |
| 206 | |
| 207 | this.pktIn2 = new OFPacketIn().setInPort((short) sw1DevPort2); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 208 | |
| 209 | lastSeenTimestamp = new Date(1); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | @Override |
| 213 | @After |
| 214 | public void tearDown() throws Exception { |
| 215 | } |
| 216 | |
| 217 | public IOFSwitch createMockSwitch(Long id) { |
| 218 | IOFSwitch mockSwitch = createNiceMock(IOFSwitch.class); |
| 219 | expect(mockSwitch.getId()).andReturn(id).anyTimes(); |
| 220 | return mockSwitch; |
| 221 | } |
| 222 | |
| 223 | /** |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 224 | * Test set operation on lastSeenTimstamp field in OnosDevice. |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 225 | */ |
| 226 | @Test |
| 227 | public void testSetLastSeenTimestamp() { |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 228 | Ethernet eth = (Ethernet) pkt1; |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 229 | OnosDevice srcDevice = odm.getSourceDeviceFromPacket(eth, sw1Dpid, sw1DevPort); |
| 230 | |
| 231 | floodLightProvider.addOFMessageListener(EasyMock.eq(OFType.PACKET_IN), EasyMock.isA(OnosDeviceManager.class)); |
| 232 | srcDevice.setLastSeenTimestamp(lastSeenTimestamp); |
| 233 | assertEquals(lastSeenTimestamp, srcDevice.getLastSeenTimestamp()); |
| 234 | } |
| 235 | /** |
| 236 | * test the functionality to get the source device from Packet header |
| 237 | * information. |
| 238 | */ |
| 239 | @Test |
| 240 | public void testGetSourceDeviceFromPacket() { |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 241 | byte[] address = new byte[] {0x00, 0x44, 0x33, 0x22, 0x11, 0x01}; |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 242 | MACAddress srcMac = new MACAddress(address); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 243 | OnosDevice dev1 = new OnosDevice(srcMac, |
| 244 | null, |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 245 | sw1Dpid, |
| 246 | sw1DevPort, |
| 247 | null); |
| 248 | |
| 249 | /* |
| 250 | * test DHCP packet case |
| 251 | */ |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 252 | Ethernet eth = (Ethernet) pkt3; |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 253 | OnosDevice dev2 = odm.getSourceDeviceFromPacket(eth, sw1Dpid, sw1DevPort); |
| 254 | assertEquals(dev1, dev2); |
| 255 | |
| 256 | /* |
| 257 | * test ARP packet case |
| 258 | */ |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 259 | eth = (Ethernet) pkt4; |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 260 | dev2 = odm.getSourceDeviceFromPacket(eth, sw1Dpid, sw1DevPort); |
| 261 | assertEquals(dev1, dev2); |
| 262 | } |
| 263 | |
| 264 | /** |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 265 | * This test will invoke addOnosDevice to add a new device through Packet pkt1. |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 266 | * @throws FloodlightModuleException |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 267 | */ |
| 268 | @Test |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 269 | public void testProcessPacketInAddNewDevice() throws FloodlightModuleException { |
| 270 | floodLightProvider.addOFMessageListener(EasyMock.eq(OFType.PACKET_IN), |
| 271 | EasyMock.isA(OnosDeviceManager.class)); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 272 | EasyMock.expectLastCall(); |
| 273 | floodLightProvider.publishUpdate(EasyMock.isA(IUpdate.class)); |
| 274 | EasyMock.expectLastCall(); |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 275 | replay(floodLightProvider); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 276 | |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 277 | odm.init(modContext); |
| 278 | odm.startUp(modContext); |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 279 | Command cmd = odm.processPacketIn(sw1, pktIn, (Ethernet) pkt1); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 280 | assertEquals(Command.CONTINUE, cmd); |
| 281 | |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 282 | EasyMock.verify(floodLightProvider); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | /** |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 286 | * Test ProcessPacket function. |
| 287 | * @throws FloodlightModuleException |
| 288 | */ |
| 289 | @Test |
| 290 | public void testProcessPacketInHasLink() throws FloodlightModuleException { |
| 291 | floodLightProvider.addOFMessageListener(EasyMock.eq(OFType.PACKET_IN), |
| 292 | EasyMock.isA(OnosDeviceManager.class)); |
| 293 | EasyMock.expectLastCall(); |
| 294 | replay(floodLightProvider); |
| 295 | |
| 296 | odm.init(modContext); |
| 297 | odm.startUp(modContext); |
| 298 | Command cmd = odm.processPacketIn(sw1, pktIn2, (Ethernet) pkt1); |
| 299 | assertEquals(Command.CONTINUE, cmd); |
| 300 | |
| 301 | EasyMock.verify(floodLightProvider); |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * Test return Command.STOP path in processPacketIn method by injecting a broadcast packet. |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 306 | */ |
| 307 | @Test |
| 308 | public void testProcessPacketInStop() { |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 309 | Command cmd = odm.processPacketIn(sw1, pktIn, (Ethernet) pkt0); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 310 | assertEquals(Command.STOP, cmd); |
| 311 | } |
| 312 | |
| 313 | /** |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 314 | * Test add a device from the information from packet. |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 315 | * @throws FloodlightModuleException |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 316 | */ |
| 317 | @Test |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 318 | public void testAddOnosDevice() throws FloodlightModuleException { |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 319 | Ethernet eth = (Ethernet) pkt1; |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 320 | Long longmac = eth.getSourceMAC().toLong(); |
| 321 | OnosDevice srcDevice = odm.getSourceDeviceFromPacket(eth, sw1Dpid, sw1DevPort); |
| 322 | |
| 323 | floodLightProvider.addOFMessageListener(EasyMock.eq(OFType.PACKET_IN), EasyMock.isA(OnosDeviceManager.class)); |
| 324 | EasyMock.expectLastCall(); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 325 | floodLightProvider.publishUpdate(EasyMock.isA(IUpdate.class)); |
| 326 | EasyMock.expectLastCall(); |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 327 | replay(floodLightProvider); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 328 | |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 329 | odm.init(modContext); |
| 330 | odm.startUp(modContext); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 331 | odm.addOnosDevice(longmac, srcDevice); |
| 332 | |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 333 | EasyMock.verify(floodLightProvider); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | /** |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 337 | * Test delete a device. |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 338 | * @throws FloodlightModuleException |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 339 | */ |
| 340 | @Test |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 341 | public void testDeleteOnosDevice() throws FloodlightModuleException { |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 342 | Ethernet eth = (Ethernet) pkt1; |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 343 | OnosDevice srcDevice = odm.getSourceDeviceFromPacket(eth, sw1Dpid, sw1DevPort); |
| 344 | |
| 345 | floodLightProvider.addOFMessageListener(EasyMock.eq(OFType.PACKET_IN), EasyMock.isA(OnosDeviceManager.class)); |
| 346 | EasyMock.expectLastCall(); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 347 | floodLightProvider.publishUpdate(EasyMock.isA(IUpdate.class)); |
| 348 | EasyMock.expectLastCall(); |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 349 | replay(floodLightProvider); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 350 | |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 351 | odm.init(modContext); |
| 352 | odm.startUp(modContext); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 353 | odm.deleteOnosDevice(srcDevice); |
| 354 | |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 355 | EasyMock.verify(floodLightProvider); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | /** |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 359 | * Test delete a device by using its source mac address. |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 360 | * @throws FloodlightModuleException |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 361 | */ |
| 362 | @Test |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 363 | public void testDeleteOnosDeviceByMac() throws FloodlightModuleException { |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 364 | Ethernet eth = (Ethernet) pkt1; |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 365 | MACAddress mac = eth.getSourceMAC(); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 366 | |
| 367 | floodLightProvider.addOFMessageListener(EasyMock.eq(OFType.PACKET_IN), EasyMock.isA(OnosDeviceManager.class)); |
| 368 | EasyMock.expectLastCall(); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 369 | floodLightProvider.publishUpdate(EasyMock.isA(IUpdate.class)); |
| 370 | EasyMock.expectLastCall(); |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 371 | replay(floodLightProvider); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 372 | |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 373 | odm.init(modContext); |
| 374 | odm.startUp(modContext); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 375 | odm.deleteOnosDeviceByMac(mac); |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame^] | 376 | |
| 377 | EasyMock.verify(floodLightProvider); |
Patrick Liu | ab1e606 | 2014-05-05 11:12:13 -0700 | [diff] [blame] | 378 | } |
| 379 | } |