16 package org.openkilda.floodlight.pathverification;
19 import static org.easymock.EasyMock.anyObject;
20 import static org.easymock.EasyMock.expect;
21 import static org.easymock.EasyMock.replay;
22 import static org.easymock.EasyMock.reset;
23 import static org.easymock.EasyMock.verify;
24 import static org.junit.Assert.assertEquals;
26 import junit.framework.AssertionFailedError;
27 import net.floodlightcontroller.core.FloodlightContext;
28 import net.floodlightcontroller.core.IFloodlightProviderService;
29 import net.floodlightcontroller.core.IListener.Command;
30 import net.floodlightcontroller.core.IOFSwitch;
31 import net.floodlightcontroller.core.module.FloodlightModuleException;
32 import net.floodlightcontroller.packet.Ethernet;
33 import net.floodlightcontroller.packet.IPacket;
34 import net.floodlightcontroller.packet.PacketParsingException;
35 import org.apache.kafka.clients.producer.KafkaProducer;
36 import org.easymock.EasyMock;
37 import org.easymock.EasyMockRunner;
38 import org.easymock.Mock;
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.junit.runner.RunWith;
42 import org.projectfloodlight.openflow.protocol.OFPacketIn;
43 import org.projectfloodlight.openflow.protocol.OFPacketOut;
44 import org.projectfloodlight.openflow.protocol.OFType;
45 import org.projectfloodlight.openflow.protocol.match.Match;
46 import org.projectfloodlight.openflow.protocol.match.MatchField;
47 import org.projectfloodlight.openflow.types.DatapathId;
48 import org.projectfloodlight.openflow.types.OFPort;
50 import java.util.HashMap;
52 @RunWith(EasyMockRunner.class)
55 private OFPacketIn ofPacketIn;
56 private FloodlightContext context;
59 private KafkaProducer<String, String>
producer;
62 public void setUp() throws Exception {
66 OFPacketOut packetOut = pvs.generateVerificationPacket(sw1, OFPort.of(1));
68 ofPacketIn = EasyMock.createMock(OFPacketIn.class);
70 context =
new FloodlightContext();
72 expect(ofPacketIn.getType()).andReturn(OFType.PACKET_IN).anyTimes();
73 expect(ofPacketIn.getXid()).andReturn(0L).anyTimes();
74 expect(ofPacketIn.getVersion()).andReturn(packetOut.getVersion()).anyTimes();
76 Match match = EasyMock.createMock(Match.class);
77 expect(match.get(MatchField.IN_PORT)).andReturn(OFPort.of(1)).anyTimes();
79 expect(ofPacketIn.getMatch()).andReturn(match).anyTimes();
82 IPacket expected =
new Ethernet().deserialize(packetOut.getData(), 0,
83 packetOut.getData().length);
85 context.getStorage().put(IFloodlightProviderService.CONTEXT_PI_PAYLOAD, expected);
87 HashMap<DatapathId, IOFSwitch> switches =
new HashMap<>();
88 switches.put(sw1.getId(), sw1);
89 switches.put(sw2.getId(), sw2);
90 mockSwitchManager.setSwitches(switches);
99 expect(
producer.send(anyObject())).andReturn(null).once();
101 assertEquals(Command.STOP, pvs.receive(sw2, ofPacketIn, context));
107 OFPacketOut noSignPacket = pvs.generateVerificationPacket(sw1, OFPort.of(1), null,
false);
108 IPacket noSignPacketData =
new Ethernet().deserialize(noSignPacket.getData(), 0,
109 noSignPacket.getData().length);
110 context.getStorage().put(IFloodlightProviderService.CONTEXT_PI_PAYLOAD, noSignPacketData);
111 expect(
producer.send(anyObject())).andThrow(
new AssertionFailedError()).anyTimes();
113 assertEquals(Command.STOP, pvs.receive(sw2, ofPacketIn, context));
119 expect(
producer.send(anyObject())).andThrow(
new AssertionFailedError()).anyTimes();
121 pvs.initAlgorithm(
"secret2");
122 assertEquals(Command.STOP, pvs.receive(sw2, ofPacketIn, context));
void testSignPacketInvalidSign()
void testSignPacketMissedSign()
void testSignPacketPositive()