alshabib
Committed by Ray Milkey

adding EthType to secure handling ether types

this will also pretty print ethertypes in flow output

Change-Id: I9363070ad308f3c756735e29b3992c500e503636
Showing 19 changed files with 210 additions and 52 deletions
...@@ -114,7 +114,7 @@ public class SdnIpReactiveRouting { ...@@ -114,7 +114,7 @@ public class SdnIpReactiveRouting {
114 ConnectPoint srcConnectPoint = pkt.receivedFrom(); 114 ConnectPoint srcConnectPoint = pkt.receivedFrom();
115 115
116 switch (ethPkt.getEtherType()) { 116 switch (ethPkt.getEtherType()) {
117 - case Ethernet.TYPE_ARP: 117 + case 0x806:
118 ARP arpPacket = (ARP) ethPkt.getPayload(); 118 ARP arpPacket = (ARP) ethPkt.getPayload();
119 Ip4Address targetIpAddress = Ip4Address 119 Ip4Address targetIpAddress = Ip4Address
120 .valueOf(arpPacket.getTargetProtocolAddress()); 120 .valueOf(arpPacket.getTargetProtocolAddress());
...@@ -141,7 +141,7 @@ public class SdnIpReactiveRouting { ...@@ -141,7 +141,7 @@ public class SdnIpReactiveRouting {
141 ByteBuffer.wrap(eth.serialize()))); 141 ByteBuffer.wrap(eth.serialize())));
142 } 142 }
143 break; 143 break;
144 - case Ethernet.TYPE_IPV4: 144 + case 0x800:
145 // Parse packet 145 // Parse packet
146 IPv4 ipv4Packet = (IPv4) ethPkt.getPayload(); 146 IPv4 ipv4Packet = (IPv4) ethPkt.getPayload();
147 IpAddress dstIp = 147 IpAddress dstIp =
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onosproject.net.flow.criteria; 16 package org.onosproject.net.flow.criteria;
17 17
18 +import org.onlab.packet.EthType;
18 import org.onosproject.net.IndexedLambda; 19 import org.onosproject.net.IndexedLambda;
19 import org.onosproject.net.Lambda; 20 import org.onosproject.net.Lambda;
20 import org.onosproject.net.OchSignal; 21 import org.onosproject.net.OchSignal;
...@@ -101,6 +102,16 @@ public final class Criteria { ...@@ -101,6 +102,16 @@ public final class Criteria {
101 } 102 }
102 103
103 /** 104 /**
105 + * Creates a match on ETH_TYPE field using the specified value.
106 + *
107 + * @param ethType eth type value
108 + * @return match criterion
109 + */
110 + public static Criterion matchEthType(EthType ethType) {
111 + return new EthTypeCriterion(ethType);
112 + }
113 +
114 + /**
104 * Creates a match on VLAN ID field using the specified value. 115 * Creates a match on VLAN ID field using the specified value.
105 * 116 *
106 * @param vlanId vlan id value 117 * @param vlanId vlan id value
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
15 */ 15 */
16 package org.onosproject.net.flow.criteria; 16 package org.onosproject.net.flow.criteria;
17 17
18 +import org.onlab.packet.EthType;
19 +
18 import java.util.Objects; 20 import java.util.Objects;
19 21
20 import static com.google.common.base.MoreObjects.toStringHelper; 22 import static com.google.common.base.MoreObjects.toStringHelper;
...@@ -24,7 +26,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; ...@@ -24,7 +26,7 @@ import static com.google.common.base.MoreObjects.toStringHelper;
24 */ 26 */
25 public final class EthTypeCriterion implements Criterion { 27 public final class EthTypeCriterion implements Criterion {
26 private static final int MASK = 0xffff; 28 private static final int MASK = 0xffff;
27 - private final int ethType; // Ethernet type value: 16 bits 29 + private final EthType ethType; // Ethernet type value: 16 bits
28 30
29 /** 31 /**
30 * Constructor. 32 * Constructor.
...@@ -33,7 +35,16 @@ public final class EthTypeCriterion implements Criterion { ...@@ -33,7 +35,16 @@ public final class EthTypeCriterion implements Criterion {
33 * integer) 35 * integer)
34 */ 36 */
35 EthTypeCriterion(int ethType) { 37 EthTypeCriterion(int ethType) {
36 - this.ethType = ethType & MASK; 38 + this.ethType = new EthType(ethType & MASK);
39 + }
40 +
41 + /**
42 + * Constructor.
43 + *
44 + * @param ethType the Ethernet frame type to match
45 + */
46 + EthTypeCriterion(EthType ethType) {
47 + this.ethType = ethType;
37 } 48 }
38 49
39 @Override 50 @Override
...@@ -46,14 +57,14 @@ public final class EthTypeCriterion implements Criterion { ...@@ -46,14 +57,14 @@ public final class EthTypeCriterion implements Criterion {
46 * 57 *
47 * @return the Ethernet frame type to match (16 bits unsigned integer) 58 * @return the Ethernet frame type to match (16 bits unsigned integer)
48 */ 59 */
49 - public int ethType() { 60 + public EthType ethType() {
50 return ethType; 61 return ethType;
51 } 62 }
52 63
53 @Override 64 @Override
54 public String toString() { 65 public String toString() {
55 return toStringHelper(type().toString()) 66 return toStringHelper(type().toString())
56 - .add("ethType", Long.toHexString(ethType)) 67 + .add("ethType", ethType.toString())
57 .toString(); 68 .toString();
58 } 69 }
59 70
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onosproject.net.flow.criteria; 16 package org.onosproject.net.flow.criteria;
17 17
18 import org.junit.Test; 18 import org.junit.Test;
19 +import org.onlab.packet.EthType;
19 import org.onosproject.net.ChannelSpacing; 20 import org.onosproject.net.ChannelSpacing;
20 import org.onosproject.net.GridType; 21 import org.onosproject.net.GridType;
21 import org.onosproject.net.Lambda; 22 import org.onosproject.net.Lambda;
...@@ -418,8 +419,8 @@ public class CriteriaTest { ...@@ -418,8 +419,8 @@ public class CriteriaTest {
418 */ 419 */
419 @Test 420 @Test
420 public void testMatchEthTypeMethod() { 421 public void testMatchEthTypeMethod() {
421 - int ethType = 12; 422 + EthType ethType = new EthType(12);
422 - Criterion matchEthType = Criteria.matchEthType(ethType); 423 + Criterion matchEthType = Criteria.matchEthType(new EthType(12));
423 EthTypeCriterion ethTypeCriterion = 424 EthTypeCriterion ethTypeCriterion =
424 checkAndConvert(matchEthType, 425 checkAndConvert(matchEthType,
425 Criterion.Type.ETH_TYPE, 426 Criterion.Type.ETH_TYPE,
......
...@@ -165,7 +165,7 @@ public final class EncodeCriterionCodec { ...@@ -165,7 +165,7 @@ public final class EncodeCriterionCodec {
165 public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { 165 public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) {
166 final EthTypeCriterion ethTypeCriterion = 166 final EthTypeCriterion ethTypeCriterion =
167 (EthTypeCriterion) criterion; 167 (EthTypeCriterion) criterion;
168 - return root.put(CriterionCodec.ETH_TYPE, ethTypeCriterion.ethType()); 168 + return root.put(CriterionCodec.ETH_TYPE, ethTypeCriterion.ethType().toShort());
169 } 169 }
170 } 170 }
171 171
......
...@@ -134,7 +134,7 @@ public final class CriterionJsonMatcher extends ...@@ -134,7 +134,7 @@ public final class CriterionJsonMatcher extends
134 * @return true if the JSON matches the criterion, false otherwise. 134 * @return true if the JSON matches the criterion, false otherwise.
135 */ 135 */
136 private boolean matchCriterion(EthTypeCriterion criterion) { 136 private boolean matchCriterion(EthTypeCriterion criterion) {
137 - final int ethType = criterion.ethType(); 137 + final int ethType = criterion.ethType().toShort();
138 final int jsonEthType = jsonCriterion.get("ethType").intValue(); 138 final int jsonEthType = jsonCriterion.get("ethType").intValue();
139 if (ethType != jsonEthType) { 139 if (ethType != jsonEthType) {
140 description.appendText("ethType was " 140 description.appendText("ethType was "
......
...@@ -22,6 +22,7 @@ import java.util.TreeMap; ...@@ -22,6 +22,7 @@ import java.util.TreeMap;
22 22
23 import org.junit.Before; 23 import org.junit.Before;
24 import org.junit.Test; 24 import org.junit.Test;
25 +import org.onlab.packet.EthType;
25 import org.onlab.packet.Ethernet; 26 import org.onlab.packet.Ethernet;
26 import org.onlab.packet.IpAddress; 27 import org.onlab.packet.IpAddress;
27 import org.onlab.packet.IpPrefix; 28 import org.onlab.packet.IpPrefix;
...@@ -148,7 +149,7 @@ public class FlowRuleCodecTest { ...@@ -148,7 +149,7 @@ public class FlowRuleCodecTest {
148 assertThat(rule.selector().criteria().size(), is(1)); 149 assertThat(rule.selector().criteria().size(), is(1));
149 Criterion criterion1 = rule.selector().criteria().iterator().next(); 150 Criterion criterion1 = rule.selector().criteria().iterator().next();
150 assertThat(criterion1.type(), is(Criterion.Type.ETH_TYPE)); 151 assertThat(criterion1.type(), is(Criterion.Type.ETH_TYPE));
151 - assertThat(((EthTypeCriterion) criterion1).ethType(), is(2054)); 152 + assertThat(((EthTypeCriterion) criterion1).ethType(), is(new EthType(2054)));
152 153
153 assertThat(rule.treatment().allInstructions().size(), is(1)); 154 assertThat(rule.treatment().allInstructions().size(), is(1));
154 Instruction instruction1 = rule.treatment().allInstructions().get(0); 155 Instruction instruction1 = rule.treatment().allInstructions().get(0);
...@@ -356,7 +357,7 @@ public class FlowRuleCodecTest { ...@@ -356,7 +357,7 @@ public class FlowRuleCodecTest {
356 Criterion criterion; 357 Criterion criterion;
357 358
358 criterion = getCriterion(Criterion.Type.ETH_TYPE); 359 criterion = getCriterion(Criterion.Type.ETH_TYPE);
359 - assertThat(((EthTypeCriterion) criterion).ethType(), is(2054)); 360 + assertThat(((EthTypeCriterion) criterion).ethType(), is(new EthType(2054)));
360 361
361 criterion = getCriterion(Criterion.Type.ETH_DST); 362 criterion = getCriterion(Criterion.Type.ETH_DST);
362 assertThat(((EthCriterion) criterion).mac(), 363 assertThat(((EthCriterion) criterion).mac(),
......
...@@ -243,7 +243,7 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> { ...@@ -243,7 +243,7 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> {
243 Criterion c = intent.selector().getCriterion(Criterion.Type.ETH_TYPE); 243 Criterion c = intent.selector().getCriterion(Criterion.Type.ETH_TYPE);
244 if (c != null && c instanceof EthTypeCriterion) { 244 if (c != null && c instanceof EthTypeCriterion) {
245 EthTypeCriterion ethertype = (EthTypeCriterion) c; 245 EthTypeCriterion ethertype = (EthTypeCriterion) c;
246 - treat.popMpls((short) ethertype.ethType()); 246 + treat.popMpls(ethertype.ethType().toShort());
247 } else { 247 } else {
248 treat.popMpls(Ethernet.TYPE_IPV4); 248 treat.popMpls(Ethernet.TYPE_IPV4);
249 } 249 }
......
...@@ -20,6 +20,7 @@ import com.google.common.collect.ImmutableMap; ...@@ -20,6 +20,7 @@ import com.google.common.collect.ImmutableMap;
20 import com.google.common.collect.ImmutableSet; 20 import com.google.common.collect.ImmutableSet;
21 21
22 import org.onlab.packet.ChassisId; 22 import org.onlab.packet.ChassisId;
23 +import org.onlab.packet.EthType;
23 import org.onlab.packet.Ip4Address; 24 import org.onlab.packet.Ip4Address;
24 import org.onlab.packet.Ip4Prefix; 25 import org.onlab.packet.Ip4Prefix;
25 import org.onlab.packet.Ip6Address; 26 import org.onlab.packet.Ip6Address;
...@@ -293,6 +294,7 @@ public final class KryoNamespaces { ...@@ -293,6 +294,7 @@ public final class KryoNamespaces {
293 PortCriterion.class, 294 PortCriterion.class,
294 MetadataCriterion.class, 295 MetadataCriterion.class,
295 EthCriterion.class, 296 EthCriterion.class,
297 + EthType.class,
296 EthTypeCriterion.class, 298 EthTypeCriterion.class,
297 VlanIdCriterion.class, 299 VlanIdCriterion.class,
298 VlanPcpCriterion.class, 300 VlanPcpCriterion.class,
......
...@@ -295,7 +295,7 @@ public class CentecV350Pipeline extends AbstractHandlerBehaviour implements Pipe ...@@ -295,7 +295,7 @@ public class CentecV350Pipeline extends AbstractHandlerBehaviour implements Pipe
295 TrafficSelector selector = fwd.selector(); 295 TrafficSelector selector = fwd.selector();
296 EthTypeCriterion ethType = 296 EthTypeCriterion ethType =
297 (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE); 297 (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
298 - if (ethType == null || ethType.ethType() != Ethernet.TYPE_IPV4) { 298 + if (ethType == null || ethType.ethType().toShort() != Ethernet.TYPE_IPV4) {
299 fail(fwd, ObjectiveError.UNSUPPORTED); 299 fail(fwd, ObjectiveError.UNSUPPORTED);
300 return Collections.emptySet(); 300 return Collections.emptySet();
301 } 301 }
......
...@@ -510,7 +510,7 @@ public class OFDPA1Pipeline extends AbstractHandlerBehaviour implements Pipeline ...@@ -510,7 +510,7 @@ public class OFDPA1Pipeline extends AbstractHandlerBehaviour implements Pipeline
510 fail(fwd, ObjectiveError.UNKNOWN); 510 fail(fwd, ObjectiveError.UNKNOWN);
511 return Collections.emptySet(); 511 return Collections.emptySet();
512 } 512 }
513 - if (ethType.ethType() == Ethernet.TYPE_ARP) { 513 + if (ethType.ethType().toShort() == Ethernet.TYPE_ARP) {
514 log.warn("Installing ARP rule to table 60"); 514 log.warn("Installing ARP rule to table 60");
515 515
516 // currently need to punt from ACL table should use: 516 // currently need to punt from ACL table should use:
...@@ -551,7 +551,7 @@ public class OFDPA1Pipeline extends AbstractHandlerBehaviour implements Pipeline ...@@ -551,7 +551,7 @@ public class OFDPA1Pipeline extends AbstractHandlerBehaviour implements Pipeline
551 EthTypeCriterion ethType = 551 EthTypeCriterion ethType =
552 (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE); 552 (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
553 // XXX currently supporting only the L3 unicast table 553 // XXX currently supporting only the L3 unicast table
554 - if (ethType == null || ethType.ethType() != Ethernet.TYPE_IPV4) { 554 + if (ethType == null || ethType.ethType().toShort() != Ethernet.TYPE_IPV4) {
555 fail(fwd, ObjectiveError.UNSUPPORTED); 555 fail(fwd, ObjectiveError.UNSUPPORTED);
556 return Collections.emptySet(); 556 return Collections.emptySet();
557 } 557 }
......
...@@ -257,17 +257,17 @@ public class OVSCorsaPipeline extends AbstractHandlerBehaviour implements Pipeli ...@@ -257,17 +257,17 @@ public class OVSCorsaPipeline extends AbstractHandlerBehaviour implements Pipeli
257 fail(fwd, ObjectiveError.UNKNOWN); 257 fail(fwd, ObjectiveError.UNKNOWN);
258 return Collections.emptySet(); 258 return Collections.emptySet();
259 } 259 }
260 - if (ethType.ethType() == Ethernet.TYPE_ARP) { 260 + if (ethType.ethType().toShort() == Ethernet.TYPE_ARP) {
261 log.warn("Driver automatically handles ARP packets by punting to controller " 261 log.warn("Driver automatically handles ARP packets by punting to controller "
262 + " from ETHER table"); 262 + " from ETHER table");
263 pass(fwd); 263 pass(fwd);
264 return Collections.emptySet(); 264 return Collections.emptySet();
265 - } else if (ethType.ethType() == Ethernet.TYPE_LLDP || 265 + } else if (ethType.ethType().toShort() == Ethernet.TYPE_LLDP ||
266 - ethType.ethType() == Ethernet.TYPE_BSN) { 266 + ethType.ethType().toShort() == Ethernet.TYPE_BSN) {
267 log.warn("Driver currently does not currently handle LLDP packets"); 267 log.warn("Driver currently does not currently handle LLDP packets");
268 fail(fwd, ObjectiveError.UNSUPPORTED); 268 fail(fwd, ObjectiveError.UNSUPPORTED);
269 return Collections.emptySet(); 269 return Collections.emptySet();
270 - } else if (ethType.ethType() == Ethernet.TYPE_IPV4) { 270 + } else if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
271 IPCriterion ipSrc = (IPCriterion) selector 271 IPCriterion ipSrc = (IPCriterion) selector
272 .getCriterion(Criterion.Type.IPV4_SRC); 272 .getCriterion(Criterion.Type.IPV4_SRC);
273 IPCriterion ipDst = (IPCriterion) selector 273 IPCriterion ipDst = (IPCriterion) selector
...@@ -303,7 +303,7 @@ public class OVSCorsaPipeline extends AbstractHandlerBehaviour implements Pipeli ...@@ -303,7 +303,7 @@ public class OVSCorsaPipeline extends AbstractHandlerBehaviour implements Pipeli
303 TrafficSelector selector = fwd.selector(); 303 TrafficSelector selector = fwd.selector();
304 EthTypeCriterion ethType = 304 EthTypeCriterion ethType =
305 (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE); 305 (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
306 - if (ethType == null || ethType.ethType() != Ethernet.TYPE_IPV4) { 306 + if (ethType == null || ethType.ethType().toShort() != Ethernet.TYPE_IPV4) {
307 fail(fwd, ObjectiveError.UNSUPPORTED); 307 fail(fwd, ObjectiveError.UNSUPPORTED);
308 return Collections.emptySet(); 308 return Collections.emptySet();
309 } 309 }
......
...@@ -243,7 +243,7 @@ public class PicaPipeline extends AbstractHandlerBehaviour implements Pipeliner ...@@ -243,7 +243,7 @@ public class PicaPipeline extends AbstractHandlerBehaviour implements Pipeliner
243 return Collections.emptySet(); 243 return Collections.emptySet();
244 } 244 }
245 245
246 - if (ethType.ethType() == Ethernet.TYPE_ARP) { 246 + if (ethType.ethType().toShort() == Ethernet.TYPE_ARP) {
247 if (filters.isEmpty()) { 247 if (filters.isEmpty()) {
248 pendingVersatiles.add(fwd); 248 pendingVersatiles.add(fwd);
249 return Collections.emptySet(); 249 return Collections.emptySet();
...@@ -253,12 +253,12 @@ public class PicaPipeline extends AbstractHandlerBehaviour implements Pipeliner ...@@ -253,12 +253,12 @@ public class PicaPipeline extends AbstractHandlerBehaviour implements Pipeliner
253 flowrules.addAll(processVersatilesWithFilters(filter, fwd)); 253 flowrules.addAll(processVersatilesWithFilters(filter, fwd));
254 } 254 }
255 return flowrules; 255 return flowrules;
256 - } else if (ethType.ethType() == Ethernet.TYPE_LLDP || 256 + } else if (ethType.ethType().toShort() == Ethernet.TYPE_LLDP ||
257 - ethType.ethType() == Ethernet.TYPE_BSN) { 257 + ethType.ethType().toShort() == Ethernet.TYPE_BSN) {
258 log.warn("Driver currently does not currently handle LLDP packets"); 258 log.warn("Driver currently does not currently handle LLDP packets");
259 fail(fwd, ObjectiveError.UNSUPPORTED); 259 fail(fwd, ObjectiveError.UNSUPPORTED);
260 return Collections.emptySet(); 260 return Collections.emptySet();
261 - } else if (ethType.ethType() == Ethernet.TYPE_IPV4) { 261 + } else if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
262 IPCriterion ipSrc = (IPCriterion) selector 262 IPCriterion ipSrc = (IPCriterion) selector
263 .getCriterion(Criterion.Type.IPV4_SRC); 263 .getCriterion(Criterion.Type.IPV4_SRC);
264 IPCriterion ipDst = (IPCriterion) selector 264 IPCriterion ipDst = (IPCriterion) selector
...@@ -339,7 +339,7 @@ public class PicaPipeline extends AbstractHandlerBehaviour implements Pipeliner ...@@ -339,7 +339,7 @@ public class PicaPipeline extends AbstractHandlerBehaviour implements Pipeliner
339 TrafficSelector selector = fwd.selector(); 339 TrafficSelector selector = fwd.selector();
340 EthTypeCriterion ethType = 340 EthTypeCriterion ethType =
341 (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE); 341 (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
342 - if (ethType == null || ethType.ethType() != Ethernet.TYPE_IPV4) { 342 + if (ethType == null || ethType.ethType().toShort() != Ethernet.TYPE_IPV4) {
343 fail(fwd, ObjectiveError.UNSUPPORTED); 343 fail(fwd, ObjectiveError.UNSUPPORTED);
344 return Collections.emptySet(); 344 return Collections.emptySet();
345 } 345 }
......
...@@ -367,7 +367,7 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe ...@@ -367,7 +367,7 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe
367 return Collections.emptySet(); 367 return Collections.emptySet();
368 } 368 }
369 369
370 - if (ethType.ethType() == Ethernet.TYPE_ARP) { 370 + if (ethType.ethType().toShort() == Ethernet.TYPE_ARP) {
371 // need to install ARP request & reply flow rules for each interface filter 371 // need to install ARP request & reply flow rules for each interface filter
372 372
373 // rule for ARP replies 373 // rule for ARP replies
...@@ -425,7 +425,7 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe ...@@ -425,7 +425,7 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe
425 EthTypeCriterion ethType = 425 EthTypeCriterion ethType =
426 (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE); 426 (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
427 // XXX currently supporting only the L3 unicast table 427 // XXX currently supporting only the L3 unicast table
428 - if (ethType == null || ethType.ethType() != Ethernet.TYPE_IPV4) { 428 + if (ethType == null || ethType.ethType().toShort() != Ethernet.TYPE_IPV4) {
429 fail(fwd, ObjectiveError.UNSUPPORTED); 429 fail(fwd, ObjectiveError.UNSUPPORTED);
430 return Collections.emptySet(); 430 return Collections.emptySet();
431 } 431 }
...@@ -474,7 +474,7 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe ...@@ -474,7 +474,7 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe
474 * the dummy group is fetched from the distributed store and the enclosed 474 * the dummy group is fetched from the distributed store and the enclosed
475 * treatment is applied as a flow rule action. 475 * treatment is applied as a flow rule action.
476 * 476 *
477 - * @param nextObjective the next objective of type simple 477 + * @param nextObj the next objective of type simple
478 */ 478 */
479 private void processSimpleNextObjective(NextObjective nextObj) { 479 private void processSimpleNextObjective(NextObjective nextObj) {
480 // Simple next objective has a single treatment (not a collection) 480 // Simple next objective has a single treatment (not a collection)
......
...@@ -440,8 +440,8 @@ public class SpringOpenTTP extends AbstractHandlerBehaviour ...@@ -440,8 +440,8 @@ public class SpringOpenTTP extends AbstractHandlerBehaviour
440 EthTypeCriterion ethType = (EthTypeCriterion) selector 440 EthTypeCriterion ethType = (EthTypeCriterion) selector
441 .getCriterion(Criterion.Type.ETH_TYPE); 441 .getCriterion(Criterion.Type.ETH_TYPE);
442 if ((ethType == null) || 442 if ((ethType == null) ||
443 - ((((short) ethType.ethType()) != Ethernet.TYPE_IPV4) && 443 + (ethType.ethType().toShort() != Ethernet.TYPE_IPV4) &&
444 - (((short) ethType.ethType()) != Ethernet.MPLS_UNICAST))) { 444 + (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST)) {
445 log.warn("processSpecific: Unsupported " 445 log.warn("processSpecific: Unsupported "
446 + "forwarding objective criteraia"); 446 + "forwarding objective criteraia");
447 fail(fwd, ObjectiveError.UNSUPPORTED); 447 fail(fwd, ObjectiveError.UNSUPPORTED);
...@@ -451,7 +451,7 @@ public class SpringOpenTTP extends AbstractHandlerBehaviour ...@@ -451,7 +451,7 @@ public class SpringOpenTTP extends AbstractHandlerBehaviour
451 TrafficSelector.Builder filteredSelectorBuilder = 451 TrafficSelector.Builder filteredSelectorBuilder =
452 DefaultTrafficSelector.builder(); 452 DefaultTrafficSelector.builder();
453 int forTableId = -1; 453 int forTableId = -1;
454 - if (((short) ethType.ethType()) == Ethernet.TYPE_IPV4) { 454 + if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
455 filteredSelectorBuilder = filteredSelectorBuilder 455 filteredSelectorBuilder = filteredSelectorBuilder
456 .matchEthType(Ethernet.TYPE_IPV4) 456 .matchEthType(Ethernet.TYPE_IPV4)
457 .matchIPDst(((IPCriterion) selector 457 .matchIPDst(((IPCriterion) selector
......
...@@ -81,8 +81,8 @@ public class SpringOpenTTPDell extends SpringOpenTTP { ...@@ -81,8 +81,8 @@ public class SpringOpenTTPDell extends SpringOpenTTP {
81 EthTypeCriterion ethType = (EthTypeCriterion) selector 81 EthTypeCriterion ethType = (EthTypeCriterion) selector
82 .getCriterion(Criterion.Type.ETH_TYPE); 82 .getCriterion(Criterion.Type.ETH_TYPE);
83 if ((ethType == null) || 83 if ((ethType == null) ||
84 - ((((short) ethType.ethType()) != Ethernet.TYPE_IPV4) && 84 + (ethType.ethType().toShort() != Ethernet.TYPE_IPV4) &&
85 - (((short) ethType.ethType()) != Ethernet.MPLS_UNICAST))) { 85 + (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST)) {
86 log.debug("processSpecific: Unsupported " 86 log.debug("processSpecific: Unsupported "
87 + "forwarding objective criteraia"); 87 + "forwarding objective criteraia");
88 fail(fwd, ObjectiveError.UNSUPPORTED); 88 fail(fwd, ObjectiveError.UNSUPPORTED);
...@@ -92,7 +92,7 @@ public class SpringOpenTTPDell extends SpringOpenTTP { ...@@ -92,7 +92,7 @@ public class SpringOpenTTPDell extends SpringOpenTTP {
92 TrafficSelector.Builder filteredSelectorBuilder = 92 TrafficSelector.Builder filteredSelectorBuilder =
93 DefaultTrafficSelector.builder(); 93 DefaultTrafficSelector.builder();
94 int forTableId = -1; 94 int forTableId = -1;
95 - if (((short) ethType.ethType()) == Ethernet.TYPE_IPV4) { 95 + if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
96 if (deviceTMac == null) { 96 if (deviceTMac == null) {
97 log.debug("processSpecific: ETH_DST filtering " 97 log.debug("processSpecific: ETH_DST filtering "
98 + "objective is not set which is required " 98 + "objective is not set which is required "
......
...@@ -198,7 +198,7 @@ public abstract class FlowModBuilder { ...@@ -198,7 +198,7 @@ public abstract class FlowModBuilder {
198 break; 198 break;
199 case ETH_TYPE: 199 case ETH_TYPE:
200 EthTypeCriterion ethType = (EthTypeCriterion) c; 200 EthTypeCriterion ethType = (EthTypeCriterion) c;
201 - mBuilder.setExact(MatchField.ETH_TYPE, EthType.of(ethType.ethType())); 201 + mBuilder.setExact(MatchField.ETH_TYPE, EthType.of(ethType.ethType().toShort()));
202 break; 202 break;
203 case VLAN_VID: 203 case VLAN_VID:
204 VlanIdCriterion vid = (VlanIdCriterion) c; 204 VlanIdCriterion vid = (VlanIdCriterion) c;
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onlab.packet;
17 +
18 +import com.google.common.collect.Maps;
19 +
20 +import java.util.Map;
21 +
22 +/**
23 + * Representation of an Ethertype.
24 + */
25 +public class EthType {
26 +
27 + public static final short ARP = EtherType.ARP.ethType.toShort();
28 + public static final short RARP = EtherType.RARP.ethType.toShort();
29 + public static final short VLAN = EtherType.VLAN.ethType.toShort();
30 + public static final short IPV4 = EtherType.IPV4.ethType.toShort();
31 + public static final short IPV6 = EtherType.IPV6.ethType.toShort();
32 + public static final short LLDP = EtherType.LLDP.ethType.toShort();
33 + public static final short BDDP = EtherType.BDDP.ethType.toShort();
34 + public static final short MPLS_MULTICAST = EtherType.MPLS_UNICAST.ethType.toShort();
35 + public static final short MPLS_UNICAST = EtherType.MPLS_UNICAST.ethType.toShort();
36 +
37 + private short etherType;
38 +
39 + /*
40 + * Reverse-lookup map for getting a EtherType enum
41 + */
42 + private static final Map<Short, EtherType> LOOKUP = Maps.newHashMap();
43 +
44 + static {
45 + for (EtherType eth : EtherType.values()) {
46 + LOOKUP.put(eth.ethType().toShort(), eth);
47 + }
48 + }
49 +
50 + public EthType(int etherType) {
51 + this.etherType = (short) (etherType & 0xFFFF);
52 + }
53 +
54 + public EthType(short etherType) {
55 + this.etherType = etherType;
56 + }
57 +
58 + public short toShort() {
59 + return etherType;
60 + }
61 +
62 + public static EtherType lookup(short etherType) {
63 + return LOOKUP.get(etherType);
64 + }
65 +
66 + @Override
67 + public boolean equals(Object o) {
68 + if (this == o) {
69 + return true;
70 + }
71 + if (o == null || getClass() != o.getClass()) {
72 + return false;
73 + }
74 +
75 + EthType ethType = (EthType) o;
76 +
77 + if (etherType != ethType.etherType) {
78 + return false;
79 + }
80 +
81 + return true;
82 + }
83 +
84 + @Override
85 + public int hashCode() {
86 + return (int) etherType;
87 + }
88 +
89 + public String toString() {
90 + EtherType ethType = lookup(this.etherType);
91 + return (ethType == null ? "unknown" : ethType.toString());
92 + }
93 +
94 + public static enum EtherType {
95 +
96 + ARP(0x806, "arp", ARP.class),
97 + RARP(0x8035, "rarp", null),
98 + IPV4(0x800, "ipv4", IPv4.class),
99 + IPV6(0x86dd, "ipv6", IPv6.class),
100 + LLDP(0x88cc, "lldp", LLDP.class),
101 + VLAN(0x8100, "vlan", null),
102 + BDDP(0x8942, "bddp", LLDP.class),
103 + MPLS_UNICAST(0x8847, "mpls_unicast", null),
104 + MPLS_MULTICAST(0x8848, "mpls_unicast", null);
105 +
106 +
107 + private final Class clazz;
108 + private EthType ethType;
109 + private String type;
110 +
111 + EtherType(int ethType, String type, Class clazz) {
112 + this.ethType = new EthType(ethType);
113 + this.type = type;
114 + this.clazz = clazz;
115 + }
116 +
117 + public EthType ethType() {
118 + return ethType;
119 + }
120 +
121 + @Override
122 + public String toString() {
123 + return type;
124 + }
125 +
126 + public Class clazz() {
127 + return clazz;
128 + }
129 +
130 +
131 + }
132 +}
...@@ -31,28 +31,28 @@ import java.util.Map; ...@@ -31,28 +31,28 @@ import java.util.Map;
31 */ 31 */
32 public class Ethernet extends BasePacket { 32 public class Ethernet extends BasePacket {
33 private static final String HEXES = "0123456789ABCDEF"; 33 private static final String HEXES = "0123456789ABCDEF";
34 - public static final short TYPE_ARP = (short) 0x0806; 34 + public static final short TYPE_ARP = EthType.ARP;
35 - public static final short TYPE_RARP = (short) 0x8035; 35 + public static final short TYPE_RARP = EthType.RARP;
36 - public static final short TYPE_IPV4 = (short) 0x0800; 36 + public static final short TYPE_IPV4 = EthType.IPV4;
37 - public static final short TYPE_IPV6 = (short) 0x86dd; 37 + public static final short TYPE_IPV6 = EthType.IPV6;
38 - public static final short TYPE_LLDP = (short) 0x88cc; 38 + public static final short TYPE_LLDP = EthType.LLDP;
39 - public static final short TYPE_VLAN = (short) 0x8100; 39 + public static final short TYPE_VLAN = EthType.VLAN;
40 - public static final short TYPE_BSN = (short) 0x8942; 40 + public static final short TYPE_BSN = EthType.BDDP;
41 - public static final short VLAN_UNTAGGED = (short) 0xffff; 41 +
42 - public static final short MPLS_UNICAST = (short) 0x8847; 42 + public static final short MPLS_UNICAST = EthType.MPLS_UNICAST;
43 - public static final short MPLS_MULTICAST = (short) 0x8848; 43 + public static final short MPLS_MULTICAST = EthType.MPLS_MULTICAST;
44 44
45 + public static final short VLAN_UNTAGGED = (short) 0xffff;
45 public static final short DATALAYER_ADDRESS_LENGTH = 6; // bytes 46 public static final short DATALAYER_ADDRESS_LENGTH = 6; // bytes
46 public static final Map<Short, Class<? extends IPacket>> ETHER_TYPE_CLASS_MAP = 47 public static final Map<Short, Class<? extends IPacket>> ETHER_TYPE_CLASS_MAP =
47 new HashMap<>(); 48 new HashMap<>();
48 49
49 static { 50 static {
50 - Ethernet.ETHER_TYPE_CLASS_MAP.put(Ethernet.TYPE_ARP, ARP.class); 51 + for (EthType.EtherType ethType : EthType.EtherType.values()) {
51 - Ethernet.ETHER_TYPE_CLASS_MAP.put(Ethernet.TYPE_RARP, ARP.class); 52 + if (ethType.clazz() != null) {
52 - Ethernet.ETHER_TYPE_CLASS_MAP.put(Ethernet.TYPE_IPV4, IPv4.class); 53 + ETHER_TYPE_CLASS_MAP.put(ethType.ethType().toShort(), ethType.clazz());
53 - Ethernet.ETHER_TYPE_CLASS_MAP.put(Ethernet.TYPE_IPV6, IPv6.class); 54 + }
54 - Ethernet.ETHER_TYPE_CLASS_MAP.put(Ethernet.TYPE_LLDP, LLDP.class); 55 + }
55 - Ethernet.ETHER_TYPE_CLASS_MAP.put(Ethernet.TYPE_BSN, LLDP.class);
56 } 56 }
57 57
58 protected MacAddress destinationMACAddress; 58 protected MacAddress destinationMACAddress;
......