Don't use exceptions for commonly-used logic
+ javadocs Change-Id: Ib4d886e10996273855ab5784dc4a0d86f5b11103
Showing
3 changed files
with
37 additions
and
7 deletions
... | @@ -15,13 +15,15 @@ | ... | @@ -15,13 +15,15 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.packet; | 16 | package org.onosproject.net.packet; |
17 | 17 | ||
18 | -import java.util.concurrent.atomic.AtomicBoolean; | ||
19 | - | ||
20 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 18 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
21 | import org.onosproject.net.flow.TrafficTreatment; | 19 | import org.onosproject.net.flow.TrafficTreatment; |
22 | import org.onosproject.net.flow.TrafficTreatment.Builder; | 20 | import org.onosproject.net.flow.TrafficTreatment.Builder; |
23 | 21 | ||
22 | +import java.util.concurrent.atomic.AtomicBoolean; | ||
24 | 23 | ||
24 | +/** | ||
25 | + * Default implementation of a packet context. | ||
26 | + */ | ||
25 | public abstract class DefaultPacketContext implements PacketContext { | 27 | public abstract class DefaultPacketContext implements PacketContext { |
26 | 28 | ||
27 | private final long time; | 29 | private final long time; |
... | @@ -31,7 +33,14 @@ public abstract class DefaultPacketContext implements PacketContext { | ... | @@ -31,7 +33,14 @@ public abstract class DefaultPacketContext implements PacketContext { |
31 | 33 | ||
32 | private final AtomicBoolean block; | 34 | private final AtomicBoolean block; |
33 | 35 | ||
34 | - | 36 | + /** |
37 | + * Creates a new packet context. | ||
38 | + * | ||
39 | + * @param time creation time | ||
40 | + * @param inPkt inbound packet | ||
41 | + * @param outPkt outbound packet | ||
42 | + * @param block whether the context is blocked or not | ||
43 | + */ | ||
35 | protected DefaultPacketContext(long time, InboundPacket inPkt, | 44 | protected DefaultPacketContext(long time, InboundPacket inPkt, |
36 | OutboundPacket outPkt, boolean block) { | 45 | OutboundPacket outPkt, boolean block) { |
37 | super(); | 46 | super(); | ... | ... |
... | @@ -19,6 +19,7 @@ package org.onosproject.openflow.controller; | ... | @@ -19,6 +19,7 @@ package org.onosproject.openflow.controller; |
19 | import org.onlab.packet.Ethernet; | 19 | import org.onlab.packet.Ethernet; |
20 | import org.projectfloodlight.openflow.protocol.OFPacketIn; | 20 | import org.projectfloodlight.openflow.protocol.OFPacketIn; |
21 | import org.projectfloodlight.openflow.protocol.OFPacketOut; | 21 | import org.projectfloodlight.openflow.protocol.OFPacketOut; |
22 | +import org.projectfloodlight.openflow.protocol.OFVersion; | ||
22 | import org.projectfloodlight.openflow.protocol.action.OFAction; | 23 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
23 | import org.projectfloodlight.openflow.protocol.action.OFActionOutput; | 24 | import org.projectfloodlight.openflow.protocol.action.OFActionOutput; |
24 | import org.projectfloodlight.openflow.protocol.match.MatchField; | 25 | import org.projectfloodlight.openflow.protocol.match.MatchField; |
... | @@ -29,6 +30,9 @@ import java.nio.BufferUnderflowException; | ... | @@ -29,6 +30,9 @@ import java.nio.BufferUnderflowException; |
29 | import java.util.Collections; | 30 | import java.util.Collections; |
30 | import java.util.concurrent.atomic.AtomicBoolean; | 31 | import java.util.concurrent.atomic.AtomicBoolean; |
31 | 32 | ||
33 | +/** | ||
34 | + * Default implementation of an OpenFlowPacketContext. | ||
35 | + */ | ||
32 | public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext { | 36 | public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext { |
33 | 37 | ||
34 | private final AtomicBoolean free = new AtomicBoolean(true); | 38 | private final AtomicBoolean free = new AtomicBoolean(true); |
... | @@ -99,6 +103,13 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext | ... | @@ -99,6 +103,13 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext |
99 | return new Dpid(sw.getId()); | 103 | return new Dpid(sw.getId()); |
100 | } | 104 | } |
101 | 105 | ||
106 | + /** | ||
107 | + * Creates an OpenFlow packet context based on a packet-in. | ||
108 | + * | ||
109 | + * @param s OpenFlow switch | ||
110 | + * @param pkt OpenFlow packet-in | ||
111 | + * @return the OpenFlow packet context | ||
112 | + */ | ||
102 | public static OpenFlowPacketContext packetContextFromPacketIn(OpenFlowSwitch s, | 113 | public static OpenFlowPacketContext packetContextFromPacketIn(OpenFlowSwitch s, |
103 | OFPacketIn pkt) { | 114 | OFPacketIn pkt) { |
104 | return new DefaultOpenFlowPacketContext(s, pkt); | 115 | return new DefaultOpenFlowPacketContext(s, pkt); |
... | @@ -110,12 +121,10 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext | ... | @@ -110,12 +121,10 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext |
110 | } | 121 | } |
111 | 122 | ||
112 | private OFPort pktinInPort() { | 123 | private OFPort pktinInPort() { |
113 | - //FIXME: this has to change in loxi | 124 | + if (pktin.getVersion() == OFVersion.OF_10) { |
114 | - try { | ||
115 | return pktin.getInPort(); | 125 | return pktin.getInPort(); |
116 | - } catch (UnsupportedOperationException e) { | ||
117 | - return pktin.getMatch().get(MatchField.IN_PORT); | ||
118 | } | 126 | } |
127 | + return pktin.getMatch().get(MatchField.IN_PORT); | ||
119 | } | 128 | } |
120 | 129 | ||
121 | @Override | 130 | @Override | ... | ... |
... | @@ -28,10 +28,22 @@ import org.projectfloodlight.openflow.types.OFPort; | ... | @@ -28,10 +28,22 @@ import org.projectfloodlight.openflow.types.OFPort; |
28 | 28 | ||
29 | import java.util.List; | 29 | import java.util.List; |
30 | 30 | ||
31 | +/** | ||
32 | + * Packet context used with the OpenFlow providers. | ||
33 | + */ | ||
31 | public class OpenFlowCorePacketContext extends DefaultPacketContext { | 34 | public class OpenFlowCorePacketContext extends DefaultPacketContext { |
32 | 35 | ||
33 | private final OpenFlowPacketContext ofPktCtx; | 36 | private final OpenFlowPacketContext ofPktCtx; |
34 | 37 | ||
38 | + /** | ||
39 | + * Creates a new OpenFlow core packet context. | ||
40 | + * | ||
41 | + * @param time creation time | ||
42 | + * @param inPkt inbound packet | ||
43 | + * @param outPkt outbound packet | ||
44 | + * @param block whether the context is blocked or not | ||
45 | + * @param ofPktCtx OpenFlow packet context | ||
46 | + */ | ||
35 | protected OpenFlowCorePacketContext(long time, InboundPacket inPkt, | 47 | protected OpenFlowCorePacketContext(long time, InboundPacket inPkt, |
36 | OutboundPacket outPkt, boolean block, | 48 | OutboundPacket outPkt, boolean block, |
37 | OpenFlowPacketContext ofPktCtx) { | 49 | OpenFlowPacketContext ofPktCtx) { | ... | ... |
-
Please register or login to post a comment