Skip to content
Snippets Groups Projects
Commit 05022ac9 authored by Ryan Izard's avatar Ryan Izard
Browse files

Merge pull request #554 from AndreMantas/AndreMantas-writePacketOutForPacketIn

Update OFMessageUtils.java
parents 31bf08a3 d26cf996
No related branches found
No related tags found
No related merge requests found
package net.floodlightcontroller.util;
import java.util.ArrayList;
import java.util.List;
import net.floodlightcontroller.core.IOFSwitch;
import org.projectfloodlight.openflow.protocol.OFMessage;
import org.projectfloodlight.openflow.protocol.OFPacketIn;
import org.projectfloodlight.openflow.protocol.OFPacketOut;
import org.projectfloodlight.openflow.protocol.OFVersion;
import org.projectfloodlight.openflow.protocol.action.OFAction;
import org.projectfloodlight.openflow.protocol.match.MatchField;
import org.projectfloodlight.openflow.types.OFBufferId;
import org.projectfloodlight.openflow.types.OFPort;
/**
* Tools to help work with OFMessages.
......@@ -37,4 +50,41 @@ public class OFMessageUtils {
OFMessage.Builder mb = b.createBuilder().setXid(a.getXid());
return a.equals(mb.build());
}
/**
* Writes an OFPacketOut message to a switch.
*
* @param sw
* The switch to write the PacketOut to.
* @param packetInMessage
* The corresponding PacketIn.
* @param egressPort
* The switchport to output the PacketOut.
*/
public static void writePacketOutForPacketIn(IOFSwitch sw,
OFPacketIn packetInMessage, OFPort egressPort) {
OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();
// Set buffer_id, in_port, actions_len
pob.setBufferId(packetInMessage.getBufferId());
pob.setInPort(packetInMessage.getVersion().compareTo(OFVersion.OF_12) < 0 ? packetInMessage
.getInPort() : packetInMessage.getMatch().get(
MatchField.IN_PORT));
// set actions
List<OFAction> actions = new ArrayList<OFAction>(1);
actions.add(sw.getOFFactory().actions().buildOutput()
.setPort(egressPort).setMaxLen(0xffFFffFF).build());
pob.setActions(actions);
// set data - only if buffer_id == -1
if (packetInMessage.getBufferId() == OFBufferId.NO_BUFFER) {
byte[] packetData = packetInMessage.getData();
pob.setData(packetData);
}
// and write it out
sw.write(pob.build());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment