@Test
public void testPacketInBasic() throws Exception {
byte[] deviceMac =
((Ethernet)this.testARPReplyPacket_1).getSourceMACAddress();
OFPacketIn packetIn = testARPReplyPacketIn_1;
Integer ipaddr = IPv4.toIPv4Address("192.168.1.1");
// Mock up our expected behavior
ITopologyService mockTopology = createMock(ITopologyService.class);
deviceManager.topology = mockTopology;
mockTopologyForPacketInTests(mockTopology);
replay(mockTopology);
FloodlightContext cntx = new FloodlightContext();
Command cmd = dispatchPacketIn(1L, packetIn, cntx);
verify(mockTopology);
assertEquals(Command.CONTINUE, cmd);
// Verify the device
Device rdevice = (Device)
deviceManager.findDevice(Ethernet.toLong(deviceMac),
(short)5, null, null, null);
verifyDevice(rdevice, Ethernet.toLong(deviceMac),
(short)5, ipaddr, 1L, 1);
IDevice cntxSrcDev = IDeviceService.fcStore.get(cntx,
IDeviceService.CONTEXT_SRC_DEVICE);
assertEquals(rdevice, cntxSrcDev);
IDevice cntxDstDev = IDeviceService.fcStore.get(cntx,
IDeviceService.CONTEXT_DST_DEVICE);
assertNull(cntxDstDev);
Device result = null;
Iterator<? extends IDevice> dstiter =
deviceManager.queryDevices(null, null, ipaddr,
null, null);
if (dstiter.hasNext()) {
result = (Device)dstiter.next();
}
assertFalse("There shouldn't be more than 1 device", dstiter.hasNext());
assertEquals(rdevice, result);
//-----------------
// Test packetIn again with a different source port. Should be
// the same device
reset(mockTopology);
mockTopologyForPacketInTests(mockTopology);
replay(mockTopology);
// trigger the packet in
cntx = new FloodlightContext();
packetIn.setInPort((short)2);
cmd = dispatchPacketIn(5L, packetIn, cntx);
verify(mockTopology);
// Verify the replay matched our expectations
assertEquals(Command.CONTINUE, cmd);