IOFSwitch mockSwitch = createMock(IOFSwitch.class);
expect(mockSwitch.getId()).andReturn(1L).anyTimes();
replay(mockSwitch);
/* TEST1: See basic packet flow */
OFPacketIn pi;
pi = createPacketIn(mac1, mac2, srcIp, dstIp, vlan);
FloodlightContext cntx = new FloodlightContext();
Ethernet eth = new Ethernet();
eth.deserialize(pi.getPacketData(), 0, pi.getPacketData().length);
IFloodlightProviderService.bcStore.put(cntx,
IFloodlightProviderService.CONTEXT_PI_PAYLOAD,
eth);
Command ret;
ret = ldm.receive(mockSwitch, pi, cntx);
assertEquals(Command.CONTINUE, ret);
/* TEST2: Add mac1 to the ignore MAC list and see that the packet is
* dropped
*/
ldm.addMACToIgnoreList(HexString.toLong(mac1), 0);
ret = ldm.receive(mockSwitch, pi, cntx);
assertEquals(Command.STOP, ret);
/* Verify that if we send a packet with another MAC it still works */
pi = createPacketIn(mac2, mac3, srcIp, dstIp, vlan);
cntx = new FloodlightContext();
eth = new Ethernet();
eth.deserialize(pi.getPacketData(), 0, pi.getPacketData().length);
IFloodlightProviderService.bcStore.put(cntx,
IFloodlightProviderService.CONTEXT_PI_PAYLOAD,
eth);
ret = ldm.receive(mockSwitch, pi, cntx);
assertEquals(Command.CONTINUE, ret);
/* TEST3: Add a MAC range and see if that is ignored */
ldm.addMACToIgnoreList(HexString.toLong(mac2), 8);
ret = ldm.receive(mockSwitch, pi, cntx);
assertEquals(Command.STOP, ret);
/* Send a packet with source MAC as mac3 and see that that is ignored
* as well.
*/
pi = createPacketIn(mac3, mac1, srcIp, dstIp, vlan);
cntx = new FloodlightContext();
eth = new Ethernet();
eth.deserialize(pi.getPacketData(), 0, pi.getPacketData().length);
IFloodlightProviderService.bcStore.put(cntx,
IFloodlightProviderService.CONTEXT_PI_PAYLOAD,
eth);
ret = ldm.receive(mockSwitch, pi, cntx);
assertEquals(Command.STOP, ret);