16 package org.openkilda.floodlight.pathverification;
18 import static org.easymock.EasyMock.expect;
19 import static org.easymock.EasyMock.replay;
20 import static org.junit.Assert.assertArrayEquals;
26 import net.floodlightcontroller.core.FloodlightContext;
27 import net.floodlightcontroller.core.IFloodlightProviderService;
28 import net.floodlightcontroller.core.IOFSwitch;
29 import net.floodlightcontroller.core.internal.IOFSwitchService;
30 import net.floodlightcontroller.core.module.FloodlightModuleContext;
31 import net.floodlightcontroller.packet.Data;
32 import net.floodlightcontroller.packet.Ethernet;
33 import net.floodlightcontroller.packet.IPacket;
34 import net.floodlightcontroller.packet.IPv4;
35 import net.floodlightcontroller.packet.LLDPTLV;
36 import net.floodlightcontroller.packet.UDP;
37 import org.apache.commons.codec.binary.Hex;
38 import org.easymock.EasyMock;
39 import org.junit.After;
40 import org.junit.Before;
41 import org.junit.Test;
42 import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
43 import org.projectfloodlight.openflow.protocol.OFPacketIn;
44 import org.projectfloodlight.openflow.protocol.OFPacketInReason;
45 import org.projectfloodlight.openflow.protocol.OFPortDesc;
46 import org.projectfloodlight.openflow.protocol.OFVersion;
47 import org.projectfloodlight.openflow.protocol.match.MatchField;
48 import org.projectfloodlight.openflow.types.EthType;
49 import org.projectfloodlight.openflow.types.IpProtocol;
50 import org.projectfloodlight.openflow.types.MacAddress;
51 import org.projectfloodlight.openflow.types.OFPort;
52 import org.projectfloodlight.openflow.types.TransportPort;
54 import java.net.InetSocketAddress;
58 protected FloodlightContext
cntx;
62 protected IOFSwitch
sw1, sw2;
65 protected InetSocketAddress
swIp =
new InetSocketAddress(
"192.168.10.1", 200);
67 private byte[] pkt = {(byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD, (byte) 0xEE, (byte) 0xFF,
68 0x11, 0x22, 0x33, 0x44, 0x55, 0x66,
78 (byte) 0xC0, (byte) 0xA8, 0x00, 0x01,
79 (byte) 0xC0, (byte) 0xA8, 0x00, (byte) 0xFF,
87 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
103 .
setChassisId(
new LLDPTLV().setType((byte) 1).setLength((
short) 7)
104 .setValue(
new byte[] {0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}))
105 .
setPortId(
new LLDPTLV().setType((byte) 2).setLength((
short) 3)
106 .setValue(
new byte[] {0x02, 0x00, 0x01}))
107 .
setTtl(
new LLDPTLV().setType((byte) 3).setLength((
short) 2)
108 .setValue(
new byte[] {0x00, 0x78}));
110 udp.setPayload(
new Data(verificationPacket.
serialize()));
113 .setSourceAddress(
"192.168.0.1")
115 .setProtocol(IpProtocol.UDP);
117 Ethernet eth =
new Ethernet()
118 .setDestinationMACAddress(
"AA:BB:CC:DD:EE:FF")
119 .setSourceMACAddress(
"11:22:33:44:55:66")
120 .setEtherType(EthType.IPv4);
129 public void setUp() throws Exception {
133 cntx =
new FloodlightContext();
138 FloodlightModuleContext fmc =
new FloodlightModuleContext();
143 OFPacketIn.Builder packetInBuilder =
factory.buildPacketIn();
145 .setMatch(
factory.buildMatch().setExact(MatchField.IN_PORT, OFPort.of(1)).
build())
147 .setReason(OFPacketInReason.NO_MATCH);
148 pktIn = packetInBuilder.build();
149 System.out.print(Hex.encodeHexString(
pktIn.getData()));
153 fmc.addConfigParam(
pvs,
"isl_bandwidth_quotient",
"0.0");
154 fmc.addConfigParam(
pvs,
"hmac256-secret",
"secret");
155 fmc.addConfigParam(
pvs,
"bootstrap-servers",
"");
160 pvs.initConfiguration(topicsConfig, serviceConfig);
161 pvs.initServices(fmc);
163 srcIpTarget =
new InetSocketAddress(
"192.168.10.1", 200);
164 dstIpTarget =
new InetSocketAddress(
"192.168.10.101", 100);
166 sw2HwAddrTarget =
"AA:BB:CC:DD:EE:FF";
168 OFPortDesc sw1Port1 = EasyMock.createMock(OFPortDesc.class);
169 expect(sw1Port1.getHwAddr()).andReturn(MacAddress.of(
sw1HwAddrTarget)).anyTimes();
170 expect(sw1Port1.getVersion()).andReturn(OFVersion.OF_12).anyTimes();
171 expect(sw1Port1.getCurrSpeed()).andReturn(100000L).anyTimes();
173 OFPortDesc sw2Port1 = EasyMock.createMock(OFPortDesc.class);
174 expect(sw2Port1.getHwAddr()).andReturn(MacAddress.of(sw2HwAddrTarget)).anyTimes();
175 expect(sw2Port1.getVersion()).andReturn(OFVersion.OF_12).anyTimes();
176 expect(sw2Port1.getCurrSpeed()).andReturn(100000L).anyTimes();
192 Ethernet ethernet = (Ethernet)
new Ethernet().deserialize(pkt, 0, pkt.length);
193 assertArrayEquals(pkt, ethernet.serialize());
196 assertArrayEquals(expected.serialize(), ethernet.serialize());
PathVerificationService pvs
OFDescStatsReply swDescription
InetSocketAddress srcIpTarget
static final int VERIFICATION_PACKET_UDP_PORT
VerificationPacket setTtl(LLDPTLV ttl)
OFFeaturesReply swFeatures
VerificationPacket setPortId(LLDPTLV portId)
VerificationPacket setChassisId(LLDPTLV chassisId)
static ConfigurationProvider of(FloodlightModuleContext moduleContext, IFloodlightModule module)
static final String VERIFICATION_PACKET_IP_DST
IOFSwitch buildMockIOFSwitch(Long id, OFPortDesc portDesc, OFFactory factory, OFDescStatsReply swDesc, InetSocketAddress inetAddr)
MockFloodlightProvider getMockFloodlightProvider()
MockFloodlightProvider mockFloodlightProvider
MockSwitchManager getMockSwitchService()