small fixes to ethtype pattern
Change-Id: Ic58c426821952f66aa21bc828d36fd4f83d8da0d
diff --git a/src/main/java/org/onosproject/aaa/packet/EAPEthernet.java b/src/main/java/org/onosproject/aaa/packet/EAPEthernet.java
index be2dae4..f975c15 100644
--- a/src/main/java/org/onosproject/aaa/packet/EAPEthernet.java
+++ b/src/main/java/org/onosproject/aaa/packet/EAPEthernet.java
@@ -16,11 +16,13 @@
package org.onosproject.aaa.packet;
-import org.onlab.packet.ARP;
+import org.onlab.packet.Deserializer;
+import org.onlab.packet.EthType;
import org.onlab.packet.Ethernet;
-import org.onlab.packet.IPv4;
-import org.onlab.packet.IPv6;
-import org.onlab.packet.LLDP;
+import org.onlab.packet.IPacket;
+
+import java.util.HashMap;
+import java.util.Map;
/**
* Created by jono on 5/19/15.
@@ -29,17 +31,21 @@
public static final short TYPE_PAE = (short) 0x888e;
+ private static final Map<Short, Deserializer<? extends IPacket>> ETHERTYPE_DESERIALIZER_MAP =
+ new HashMap<>();
+
private EAPEthernet() {
}
static {
- Ethernet.ETHER_TYPE_CLASS_MAP.put(org.onlab.packet.Ethernet.TYPE_ARP, ARP.class);
- org.onlab.packet.Ethernet.ETHER_TYPE_CLASS_MAP.put(org.onlab.packet.Ethernet.TYPE_RARP, ARP.class);
- org.onlab.packet.Ethernet.ETHER_TYPE_CLASS_MAP.put(org.onlab.packet.Ethernet.TYPE_IPV4, IPv4.class);
- org.onlab.packet.Ethernet.ETHER_TYPE_CLASS_MAP.put(org.onlab.packet.Ethernet.TYPE_IPV6, IPv6.class);
- org.onlab.packet.Ethernet.ETHER_TYPE_CLASS_MAP.put(org.onlab.packet.Ethernet.TYPE_LLDP, LLDP.class);
- org.onlab.packet.Ethernet.ETHER_TYPE_CLASS_MAP.put(org.onlab.packet.Ethernet.TYPE_BSN, LLDP.class);
- org.onlab.packet.Ethernet.ETHER_TYPE_CLASS_MAP.put(TYPE_PAE, EAPOL.class);
+ for (EthType.EtherType ethType : EthType.EtherType.values()) {
+ if (ethType.deserializer() != null) {
+ ETHERTYPE_DESERIALIZER_MAP.put(ethType.ethType().toShort(),
+ ethType.deserializer());
+ }
+ }
+ ETHERTYPE_DESERIALIZER_MAP.put((short) 0x888e, EAPOL.deserializer());
}
+
}
diff --git a/src/main/java/org/onosproject/aaa/packet/EAPOL.java b/src/main/java/org/onosproject/aaa/packet/EAPOL.java
index 3179e28..ac11dcc 100644
--- a/src/main/java/org/onosproject/aaa/packet/EAPOL.java
+++ b/src/main/java/org/onosproject/aaa/packet/EAPOL.java
@@ -19,12 +19,15 @@
package org.onosproject.aaa.packet;
import org.onlab.packet.BasePacket;
+import org.onlab.packet.Deserializer;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IPacket;
import org.onlab.packet.MacAddress;
import java.nio.ByteBuffer;
+import static org.onlab.packet.PacketUtils.checkInput;
+
/**
*
*/
@@ -133,29 +136,8 @@
return data;
}
- @Override
- public IPacket deserialize(final byte[] data, final int offset,
- final int length) {
- final ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
- //deserialize the EAPOL header
- this.version = bb.get();
- this.eapolType = bb.get();
- this.packetLength = bb.getShort();
-
- if (this.packetLength > 0) {
- //deserialize the EAP Payload
- this.payload = new EAP();
-
- this.payload = this.payload.deserialize(data, bb.position(), length - 4);
- this.payload.setParent(this);
- }
-
-
- return this;
- }
-
@Override
public int hashCode() {
final int prime = 3889;
@@ -196,5 +178,51 @@
eth.setPad(true);
return eth;
}
+
+ public static Deserializer<EAPOL> deserializer() {
+ return (data, offset, length) -> {
+ checkInput(data, offset, length, 0);
+
+ EAPOL eapol = new EAPOL();
+ final ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
+ eapol.setVersion(bb.get());
+ eapol.setEapolType(bb.get());
+ eapol.setPacketLength(bb.getShort());
+
+ if (eapol.packetLength > 0) {
+ //deserialize the EAP Payload
+ eapol.payload = new EAP();
+
+ eapol.payload = eapol.payload.deserialize(data, bb.position(), length - 4);
+ eapol.payload.setParent(eapol);
+ }
+ return eapol;
+ };
+ }
+
+ @Override
+ public IPacket deserialize(final byte[] data, final int offset,
+ final int length) {
+ final ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
+
+
+ //deserialize the EAPOL header
+ this.version = bb.get();
+ this.eapolType = bb.get();
+ this.packetLength = bb.getShort();
+
+ if (this.packetLength > 0) {
+ //deserialize the EAP Payload
+ this.payload = new EAP();
+
+ this.payload = this.payload.deserialize(data, bb.position(), length - 4);
+ this.payload.setParent(this);
+ }
+
+
+ return this;
+ }
+
+
}