16 package org.openkilda.floodlight.command.flow;
30 import com.auth0.jwt.JWT;
31 import com.google.common.collect.ImmutableList;
32 import net.floodlightcontroller.core.IOFSwitch;
33 import net.floodlightcontroller.core.internal.IOFSwitchService;
34 import net.floodlightcontroller.core.module.FloodlightModuleContext;
35 import net.floodlightcontroller.packet.Data;
36 import net.floodlightcontroller.packet.Ethernet;
37 import net.floodlightcontroller.packet.IPv4;
38 import net.floodlightcontroller.packet.UDP;
39 import net.floodlightcontroller.util.OFMessageUtils;
40 import org.projectfloodlight.openflow.protocol.OFFactory;
41 import org.projectfloodlight.openflow.protocol.OFMessage;
42 import org.projectfloodlight.openflow.protocol.OFPacketOut;
43 import org.projectfloodlight.openflow.protocol.action.OFAction;
44 import org.projectfloodlight.openflow.types.DatapathId;
45 import org.projectfloodlight.openflow.types.EthType;
46 import org.projectfloodlight.openflow.types.MacAddress;
47 import org.projectfloodlight.openflow.types.OFPort;
48 import org.projectfloodlight.openflow.types.TransportPort;
50 import java.util.ArrayList;
51 import java.util.List;
54 private static final String NET_L3_ADDRESS =
"127.0.0.2";
61 super(context, verificationRequest);
64 this.ioService = moduleContext.getServiceImpl(
OfBatchService.class);
65 this.switchUtils =
new SwitchUtils(moduleContext.getServiceImpl(IOFSwitchService.class));
72 DatapathId sourceDpId = DatapathId.of(verificationRequest.getSourceSwitchId().toLong());
76 data.setSenderLatency(sw.getLatency().getValue());
78 Ethernet netPacket = wrapData(
data);
79 OFMessage message = makePacketOut(sw, netPacket.serialize());
89 public void ioComplete(List<OfPendingMessage> payload,
boolean isError) {
98 Data l7 =
new Data(signature.
sign(
data.toJwt(JWT.create())));
105 IPv4 l3 =
new IPv4();
107 l3.setSourceAddress(NET_L3_ADDRESS);
108 l3.setDestinationAddress(NET_L3_ADDRESS);
110 Ethernet l2 =
new Ethernet();
112 l2.setEtherType(EthType.IPv4);
115 l2.setSourceMACAddress(switchUtils.
dpIdToMac(
116 DatapathId.of(verificationRequest.getSourceSwitchId().toLong())));
117 l2.setDestinationMACAddress(switchUtils.
dpIdToMac(
118 DatapathId.of(verificationRequest.getDestSwitchId().toLong())));
119 if (0 != verificationRequest.getVlanId()) {
120 l2.setVlanID((
short) verificationRequest.getVlanId());
130 public static byte[]
unwrapData(MacAddress targetL2Address, Ethernet packet) {
131 if (!packet.getDestinationMACAddress().equals(targetL2Address)) {
135 if (!(packet.getPayload() instanceof IPv4)) {
138 IPv4 ip = (IPv4) packet.getPayload();
140 if (!NET_L3_ADDRESS.equals(ip.getSourceAddress().toString())) {
143 if (!NET_L3_ADDRESS.equals(ip.getDestinationAddress().toString())) {
147 if (!(ip.getPayload() instanceof UDP)) {
150 UDP udp = (UDP) ip.getPayload();
159 return ((Data) udp.getPayload()).getData();
162 private OFMessage makePacketOut(IOFSwitch sw, byte[]
data) {
163 OFFactory ofFactory = sw.getOFFactory();
164 OFPacketOut.Builder pktOut = ofFactory.buildPacketOut();
166 pktOut.setData(
data);
168 List<OFAction> actions =
new ArrayList<>(2);
169 actions.add(ofFactory.actions().buildOutput().setPort(OFPort.TABLE).build());
170 pktOut.setActions(actions);
172 OFMessageUtils.setInPort(pktOut, OFPort.of(getVerificationRequest().getSourcePort()));
174 return pktOut.build();
MacAddress dpIdToMac(final IOFSwitch sw)
CommandContext getContext()
static byte [] unwrapData(MacAddress targetL2Address, Ethernet packet)
static final int VERIFICATION_PACKET_UDP_PORT
static VerificationData of(DecodedJWT token)
IOFSwitch lookupSwitch(DatapathId dpId)
byte [] sign(JWTCreator.Builder token)
VerificationSendCommand(CommandContext context, UniFlowVerificationRequest verificationRequest)
FloodlightModuleContext getModuleContext()
synchronized void push(org.openkilda.floodlight.command.Command initiator, List< OfPendingMessage > payload)
void ioComplete(List< OfPendingMessage > payload, boolean isError)