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);
// Verify the device
rdevice = (Device)
deviceManager.findDevice(Ethernet.toLong(deviceMac),
(short)5, null, null, null);
verifyDevice(rdevice, Ethernet.toLong(deviceMac),
(short)5, ipaddr, 5L, 2);
cntxSrcDev = IDeviceService.fcStore.get(cntx,
IDeviceService.CONTEXT_SRC_DEVICE);
assertEquals(rdevice, cntxSrcDev);
cntxDstDev = IDeviceService.fcStore.get(cntx,
IDeviceService.CONTEXT_DST_DEVICE);
assertNull(cntxDstDev);
// There can be only one device
assertEquals(1, deviceManager.getAllDevices().size());
//----------------------------
// Test packetIn with a different packet going the reverse direction.
// We should now get source and dest device in the context
//==> The destination device in this step has been learned just before
long srcMac = Ethernet.toLong(testUDPPacket.getSourceMACAddress());
long dstMac = Ethernet.toLong(deviceMac);
reset(mockTopology);
mockTopologyForPacketInTests(mockTopology);
replay(mockTopology);
// trigger the packet in
cntx = new FloodlightContext();
cmd = dispatchPacketIn(1L, testUDPPacketIn, cntx);
verify(mockTopology);
assertEquals(Command.CONTINUE, cmd);
IDevice srcDev =
deviceManager.findDevice(srcMac, (short)5, null, null, null);
verifyDevice(srcDev, srcMac, (short)5, null,
1L, testUDPPacketIn.getInPort());
IDevice dstDev =
deviceManager.findDevice(dstMac, (short)5, null, null, null);
verifyDevice(dstDev, dstMac, (short)5, ipaddr, 5L, 2);
cntxSrcDev = IDeviceService.fcStore.get(cntx,
IDeviceService.CONTEXT_SRC_DEVICE);