Jonathan Hart

Don't use exceptions for commonly-used logic

 + javadocs

Change-Id: Ib4d886e10996273855ab5784dc4a0d86f5b11103
......@@ -15,13 +15,15 @@
*/
package org.onosproject.net.packet;
import java.util.concurrent.atomic.AtomicBoolean;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.flow.TrafficTreatment.Builder;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* Default implementation of a packet context.
*/
public abstract class DefaultPacketContext implements PacketContext {
private final long time;
......@@ -31,7 +33,14 @@ public abstract class DefaultPacketContext implements PacketContext {
private final AtomicBoolean block;
/**
* Creates a new packet context.
*
* @param time creation time
* @param inPkt inbound packet
* @param outPkt outbound packet
* @param block whether the context is blocked or not
*/
protected DefaultPacketContext(long time, InboundPacket inPkt,
OutboundPacket outPkt, boolean block) {
super();
......
......@@ -19,6 +19,7 @@ package org.onosproject.openflow.controller;
import org.onlab.packet.Ethernet;
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.action.OFActionOutput;
import org.projectfloodlight.openflow.protocol.match.MatchField;
......@@ -29,6 +30,9 @@ import java.nio.BufferUnderflowException;
import java.util.Collections;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* Default implementation of an OpenFlowPacketContext.
*/
public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext {
private final AtomicBoolean free = new AtomicBoolean(true);
......@@ -99,6 +103,13 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext
return new Dpid(sw.getId());
}
/**
* Creates an OpenFlow packet context based on a packet-in.
*
* @param s OpenFlow switch
* @param pkt OpenFlow packet-in
* @return the OpenFlow packet context
*/
public static OpenFlowPacketContext packetContextFromPacketIn(OpenFlowSwitch s,
OFPacketIn pkt) {
return new DefaultOpenFlowPacketContext(s, pkt);
......@@ -110,12 +121,10 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext
}
private OFPort pktinInPort() {
//FIXME: this has to change in loxi
try {
if (pktin.getVersion() == OFVersion.OF_10) {
return pktin.getInPort();
} catch (UnsupportedOperationException e) {
return pktin.getMatch().get(MatchField.IN_PORT);
}
return pktin.getMatch().get(MatchField.IN_PORT);
}
@Override
......
......@@ -28,10 +28,22 @@ import org.projectfloodlight.openflow.types.OFPort;
import java.util.List;
/**
* Packet context used with the OpenFlow providers.
*/
public class OpenFlowCorePacketContext extends DefaultPacketContext {
private final OpenFlowPacketContext ofPktCtx;
/**
* Creates a new OpenFlow core packet context.
*
* @param time creation time
* @param inPkt inbound packet
* @param outPkt outbound packet
* @param block whether the context is blocked or not
* @param ofPktCtx OpenFlow packet context
*/
protected OpenFlowCorePacketContext(long time, InboundPacket inPkt,
OutboundPacket outPkt, boolean block,
OpenFlowPacketContext ofPktCtx) {
......