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