Pulled packet libraries into the ONOS namespace
Change-Id: Id16d1a8f4cae5de7b6aaa4536f2ba37a878d8d48
diff --git a/src/test/java/net/onrc/onos/packet/BSNTest.java b/src/test/java/net/onrc/onos/packet/BSNTest.java
new file mode 100644
index 0000000..a72caef
--- /dev/null
+++ b/src/test/java/net/onrc/onos/packet/BSNTest.java
@@ -0,0 +1,84 @@
+/**
+* Copyright 2011, Big Switch Networks, Inc.
+* Originally created by David Erickson, Stanford University
+*
+* Licensed under the Apache License, Version 2.0 (the "License"); you may
+* not use this file except in compliance with the License. You may obtain
+* a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+* License for the specific language governing permissions and limitations
+* under the License.
+**/
+
+/**
+ *
+ */
+package net.onrc.onos.packet;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+
+import net.onrc.onos.packet.BSN;
+import net.onrc.onos.packet.BSNPROBE;
+import net.onrc.onos.packet.Ethernet;
+
+import org.junit.Test;
+
+/**
+ *
+ * @author David Erickson (daviderickson@cs.stanford.edu)
+ *
+ */
+public class BSNTest {
+ protected byte[] probePkt = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, // src mac
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, // dst mac
+ (byte) 0x89, 0x42, // BSN type
+ 0x20, 0x00, 0x06, 0x04, 0x00, 0x01, 0x00, 0x00, // BSN header
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // controller id
+ 0x00, 0x00, 0x00, 0x03, // sequence id
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, // src mac
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, // dst mac
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, // switch dpid
+ 0x00, 0x00, 0x00, 0x01 // port number
+ };
+
+ protected Ethernet getProbePacket() {
+ return (Ethernet) new Ethernet()
+ .setSourceMACAddress("00:00:00:00:00:04")
+ .setDestinationMACAddress("00:00:00:00:00:01")
+ .setEtherType(Ethernet.TYPE_BSN)
+ .setPayload(new BSN(BSN.BSN_TYPE_PROBE)
+ .setPayload(new BSNPROBE()
+ .setSequenceId(3)
+ .setSrcMac(new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x01})
+ .setDstMac(new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x04})
+ .setSrcSwDpid(0x06)
+ .setSrcPortNo(0x01)
+ )
+ );
+ }
+
+ @Test
+ public void testSerialize() throws Exception {
+ Ethernet pkt = getProbePacket();
+ byte[] serialized = pkt.serialize();
+ assertTrue(Arrays.equals(probePkt, serialized));
+ }
+
+ @Test
+ public void testDeserialize() throws Exception {
+ Ethernet pkt = (Ethernet) new Ethernet().deserialize(probePkt, 0, probePkt.length);
+ assertTrue(Arrays.equals(probePkt, pkt.serialize()));
+
+ Ethernet expected = getProbePacket();
+ assertEquals(expected, pkt);
+ }
+}
diff --git a/src/test/java/net/onrc/onos/packet/DHCPTest.java b/src/test/java/net/onrc/onos/packet/DHCPTest.java
new file mode 100644
index 0000000..cc15bd1
--- /dev/null
+++ b/src/test/java/net/onrc/onos/packet/DHCPTest.java
@@ -0,0 +1,600 @@
+/**
+* Copyright 2011, Big Switch Networks, Inc.
+* Originally created by David Erickson, Stanford University
+*
+* Licensed under the Apache License, Version 2.0 (the "License"); you may
+* not use this file except in compliance with the License. You may obtain
+* a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+* License for the specific language governing permissions and limitations
+* under the License.
+**/
+
+/**
+ *
+ */
+package net.onrc.onos.packet;
+
+
+
+import java.util.Arrays;
+import java.util.ListIterator;
+
+import net.onrc.onos.packet.DHCP;
+import net.onrc.onos.packet.DHCPOption;
+import net.onrc.onos.packet.Ethernet;
+import net.onrc.onos.packet.IPv4;
+import net.onrc.onos.packet.UDP;
+import junit.framework.TestCase;
+
+
+/**
+ * @author David Erickson (daviderickson@cs.stanford.edu)
+ *
+ */
+public class DHCPTest extends TestCase {
+ public byte[] dhcpPacket = new byte[] {
+ (byte) 0x01, (byte) 0x01,
+ (byte) 0x06, (byte) 0x00, (byte) 0x66, (byte) 0xf2, (byte) 0x8a,
+ (byte) 0x11, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0xc0, (byte) 0x9f, (byte) 0x9f,
+ (byte) 0xfe, (byte) 0xd8, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x63,
+ (byte) 0x82, (byte) 0x53, (byte) 0x63, (byte) 0x35, (byte) 0x01,
+ (byte) 0x01, (byte) 0x37, (byte) 0x0a, (byte) 0x01, (byte) 0x1c,
+ (byte) 0x02, (byte) 0x03, (byte) 0x0f, (byte) 0x06, (byte) 0x0c,
+ (byte) 0x28, (byte) 0x29, (byte) 0x2a, (byte) 0xff, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00
+ };
+
+ public byte[] dhcpPacket2 = new byte[] { (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00,
+ (byte) 0xc0, (byte) 0x9f, (byte) 0x9e, (byte) 0x11, (byte) 0x84,
+ (byte) 0x08, (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x02,
+ (byte) 0x40, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00,
+ (byte) 0x14, (byte) 0x11, (byte) 0xa4, (byte) 0xaa, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x44, (byte) 0x00,
+ (byte) 0x43, (byte) 0x02, (byte) 0x2c, (byte) 0xdd, (byte) 0x9d,
+ (byte) 0x01, (byte) 0x01, (byte) 0x06, (byte) 0x00, (byte) 0xa4,
+ (byte) 0x9e, (byte) 0x11, (byte) 0x84, (byte) 0x00, (byte) 0x40,
+ (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xc0,
+ (byte) 0x9f, (byte) 0x9e, (byte) 0x11, (byte) 0x84, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x63, (byte) 0x82, (byte) 0x53, (byte) 0x63,
+ (byte) 0x35, (byte) 0x01, (byte) 0x01, (byte) 0x37, (byte) 0x18,
+ (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x05, (byte) 0x06,
+ (byte) 0x0b, (byte) 0x0c, (byte) 0x0d, (byte) 0x0f, (byte) 0x10,
+ (byte) 0x11, (byte) 0x12, (byte) 0x2b, (byte) 0x36, (byte) 0x3c,
+ (byte) 0x43, (byte) 0x80, (byte) 0x81, (byte) 0x82, (byte) 0x83,
+ (byte) 0x84, (byte) 0x85, (byte) 0x86, (byte) 0x87, (byte) 0x39,
+ (byte) 0x02, (byte) 0x04, (byte) 0xec, (byte) 0x61, (byte) 0x11,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x5d, (byte) 0x02, (byte) 0x00,
+ (byte) 0x00, (byte) 0x5e, (byte) 0x03, (byte) 0x01, (byte) 0x02,
+ (byte) 0x01, (byte) 0x3c, (byte) 0x20, (byte) 0x50, (byte) 0x58,
+ (byte) 0x45, (byte) 0x43, (byte) 0x6c, (byte) 0x69, (byte) 0x65,
+ (byte) 0x6e, (byte) 0x74, (byte) 0x3a, (byte) 0x41, (byte) 0x72,
+ (byte) 0x63, (byte) 0x68, (byte) 0x3a, (byte) 0x30, (byte) 0x30,
+ (byte) 0x30, (byte) 0x30, (byte) 0x30, (byte) 0x3a, (byte) 0x55,
+ (byte) 0x4e, (byte) 0x44, (byte) 0x49, (byte) 0x3a, (byte) 0x30,
+ (byte) 0x30, (byte) 0x32, (byte) 0x30, (byte) 0x30, (byte) 0x31,
+ (byte) 0xff, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00 };
+
+ public byte[] dhcpPacket3 = new byte[] {
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0x74, (byte) 0x44, (byte) 0x01, (byte) 0x72,
+ (byte) 0xd8, (byte) 0x41, (byte) 0x08, (byte) 0x00, (byte) 0x45,
+ (byte) 0x00, (byte) 0x01, (byte) 0x1f, (byte) 0x48, (byte) 0xcd,
+ (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x11, (byte) 0x6f,
+ (byte) 0x6a, (byte) 0xc0, (byte) 0xa8, (byte) 0x00, (byte) 0xef,
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00,
+ (byte) 0x44, (byte) 0x00, (byte) 0x43, (byte) 0x01, (byte) 0x0b,
+ (byte) 0xb3, (byte) 0x0f, (byte) 0x01, (byte) 0x01, (byte) 0x06,
+ (byte) 0x00, (byte) 0x82, (byte) 0x88, (byte) 0xa6, (byte) 0xc9,
+ (byte) 0x00, (byte) 0x00, (byte) 0x80, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x74, (byte) 0x44, (byte) 0x01, (byte) 0x72, (byte) 0xd8,
+ (byte) 0x41, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x63, (byte) 0x82,
+ (byte) 0x53, (byte) 0x63, (byte) 0x35, (byte) 0x01, (byte) 0x01,
+ (byte) 0x32, (byte) 0x04, (byte) 0xc0, (byte) 0xa8, (byte) 0x0a,
+ (byte) 0xa9, (byte) 0x39, (byte) 0x02, (byte) 0x02, (byte) 0x40,
+ (byte) 0x37, (byte) 0x03, (byte) 0x01, (byte) 0x03, (byte) 0x06,
+ (byte) 0xff
+ };
+
+ public byte[] dhcpPacketPXE = new byte[] { (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00,
+ (byte) 0x19, (byte) 0xb9, (byte) 0xb0, (byte) 0x01, (byte) 0x44,
+ (byte) 0x08, (byte) 0x00, (byte) 0x45, (byte) 0x10, (byte) 0x01,
+ (byte) 0x48, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x80, (byte) 0x11, (byte) 0x2c, (byte) 0x98, (byte) 0x0a,
+ (byte) 0x00, (byte) 0x02, (byte) 0xfe, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x43, (byte) 0x00,
+ (byte) 0x44, (byte) 0x01, (byte) 0x34, (byte) 0xa6, (byte) 0xf0,
+ (byte) 0x02, (byte) 0x01, (byte) 0x06, (byte) 0x00, (byte) 0xa0,
+ (byte) 0x9e, (byte) 0x0c, (byte) 0x13, (byte) 0x00, (byte) 0x04,
+ (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x0a, (byte) 0x00, (byte) 0x02, (byte) 0x14,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xc0,
+ (byte) 0x9f, (byte) 0x9e, (byte) 0x0c, (byte) 0x13, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x78, (byte) 0x65,
+ (byte) 0x6e, (byte) 0x73, (byte) 0x65, (byte) 0x72, (byte) 0x76,
+ (byte) 0x65, (byte) 0x72, (byte) 0x5f, (byte) 0x35, (byte) 0x2e,
+ (byte) 0x36, (byte) 0x2f, (byte) 0x70, (byte) 0x78, (byte) 0x65,
+ (byte) 0x6c, (byte) 0x69, (byte) 0x6e, (byte) 0x75, (byte) 0x78,
+ (byte) 0x2e, (byte) 0x30, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x63, (byte) 0x82, (byte) 0x53, (byte) 0x63,
+ (byte) 0x35, (byte) 0x01, (byte) 0x02, (byte) 0x36, (byte) 0x04,
+ (byte) 0x0a, (byte) 0x00, (byte) 0x02, (byte) 0xfe, (byte) 0x33,
+ (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0xa8, (byte) 0xc0,
+ (byte) 0x01, (byte) 0x04, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0x00, (byte) 0x03, (byte) 0x04, (byte) 0x0a, (byte) 0x00,
+ (byte) 0x02, (byte) 0xfe, (byte) 0x0c, (byte) 0x0d, (byte) 0x64,
+ (byte) 0x6e, (byte) 0x72, (byte) 0x63, (byte) 0x2d, (byte) 0x68,
+ (byte) 0x6f, (byte) 0x73, (byte) 0x74, (byte) 0x30, (byte) 0x30,
+ (byte) 0x32, (byte) 0x30, (byte) 0xff, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
+ };
+
+ public byte[] dhcpPacketBadOption1 = new byte[] { (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00,
+ (byte) 0x19, (byte) 0xb9, (byte) 0xb0, (byte) 0x01, (byte) 0x44,
+ (byte) 0x08, (byte) 0x00, (byte) 0x45, (byte) 0x10, (byte) 0x01,
+ (byte) 0x48, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x80, (byte) 0x11, (byte) 0x2c, (byte) 0x98, (byte) 0x0a,
+ (byte) 0x00, (byte) 0x02, (byte) 0xfe, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x44, (byte) 0x00,
+ (byte) 0x43, (byte) 0x01, (byte) 0x34, (byte) 0xa6, (byte) 0xf0,
+ (byte) 0x02, (byte) 0x01, (byte) 0x06, (byte) 0x00, (byte) 0xa0,
+ (byte) 0x9e, (byte) 0x0c, (byte) 0x13, (byte) 0x00, (byte) 0x04,
+ (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x0a, (byte) 0x00, (byte) 0x02, (byte) 0x14,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xc0,
+ (byte) 0x9f, (byte) 0x9e, (byte) 0x0c, (byte) 0x13, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x78, (byte) 0x65,
+ (byte) 0x6e, (byte) 0x73, (byte) 0x65, (byte) 0x72, (byte) 0x76,
+ (byte) 0x65, (byte) 0x72, (byte) 0x5f, (byte) 0x35, (byte) 0x2e,
+ (byte) 0x36, (byte) 0x2f, (byte) 0x70, (byte) 0x78, (byte) 0x65,
+ (byte) 0x6c, (byte) 0x69, (byte) 0x6e, (byte) 0x75, (byte) 0x78,
+ (byte) 0x2e, (byte) 0x30, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x63, (byte) 0x82, (byte) 0x53, (byte) 0x63,
+ (byte) 0x35, (byte) 0x01, (byte) 0x01, (byte) 0x36, (byte) 0x04,
+ (byte) 0x0a, (byte) 0x00, (byte) 0x02, (byte) 0xfe, (byte) 0x33,
+ (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0xa8, (byte) 0xc0,
+ (byte) 0x01, (byte) 0x04, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0x00, (byte) 0x03, (byte) 0x04, (byte) 0x0a, (byte) 0x00,
+ (byte) 0x02, (byte) 0xfe, (byte) 0x0c, (byte) 0x30, (byte) 0x64,
+ (byte) 0x6e, (byte) 0x72, (byte) 0x63, (byte) 0x2d, (byte) 0x68,
+ (byte) 0x6f, (byte) 0x73, (byte) 0x74, (byte) 0x30, (byte) 0x30,
+ (byte) 0x32, (byte) 0x30, (byte) 0xff, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
+ };
+
+ public byte[] dhcpPacketBadHeader = new byte[] { (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00,
+ (byte) 0x19, (byte) 0xb9, (byte) 0xb0, (byte) 0x01, (byte) 0x44,
+ (byte) 0x08, (byte) 0x00, (byte) 0x45, (byte) 0x10, (byte) 0x01,
+ (byte) 0x48, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x80, (byte) 0x11, (byte) 0x2c, (byte) 0x98, (byte) 0x0a,
+ (byte) 0x00, (byte) 0x02, (byte) 0xfe, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x44, (byte) 0x00,
+ (byte) 0x43, (byte) 0x01, (byte) 0x34, (byte) 0xa6, (byte) 0xf0,
+ (byte) 0x02, (byte) 0x01, (byte) 0x06, (byte) 0x00, (byte) 0xa0,
+ (byte) 0x9e, (byte) 0x0c, (byte) 0x13, (byte) 0x00, (byte) 0x04,
+ (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x0a, (byte) 0x00, (byte) 0x02, (byte) 0x14,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xc0,
+ (byte) 0x9f, (byte) 0x9e, (byte) 0x0c, (byte) 0x13, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x78, (byte) 0x65,
+ (byte) 0x6e, (byte) 0x73, (byte) 0x65, (byte) 0x72, (byte) 0x76,
+ (byte) 0x65, (byte) 0x72, (byte) 0x5f, (byte) 0x35, (byte) 0x2e,
+ (byte) 0x36, (byte) 0x2f, (byte) 0x70, (byte) 0x78, (byte) 0x65,
+ (byte) 0x6c, (byte) 0x69, (byte) 0x6e, (byte) 0x75, (byte) 0x78,
+ (byte) 0x2e, (byte) 0x30, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
+ };
+
+ private void resetChecksumsAndLengths(IPv4 ipv4, UDP udp) {
+ ipv4.setChecksum((short)0);
+ udp.setChecksum((short)0);
+ }
+
+ public void testSerialize() {
+ DHCP dhcp = new DHCP();
+ dhcp.deserialize(dhcpPacket, 0, dhcpPacket.length);
+ byte[] result = dhcp.serialize();
+ assertTrue(Arrays.equals(this.dhcpPacket, result));
+ }
+
+ public void testDeSerialize() {
+ Ethernet eth = new Ethernet();
+ eth.deserialize(dhcpPacket2, 0, dhcpPacket2.length);
+ assertTrue(eth.getPayload() instanceof IPv4);
+ IPv4 ipv4 = (IPv4) eth.getPayload();
+ assertTrue(ipv4.getPayload() instanceof UDP);
+ UDP udp = (UDP) ipv4.getPayload();
+ assertTrue(udp.getPayload() instanceof DHCP);
+ DHCP dhcp = (DHCP) udp.getPayload();
+ /** The invalid option in DHCP packet is dropped. Reset checksums and
+ * length field so that the serialize() function can re-compute them
+ */
+ resetChecksumsAndLengths(ipv4, udp);
+ assertEquals(DHCP.OPCODE_REQUEST, dhcp.getOpCode());
+ }
+
+ public void testDeSerializeReSerialize() {
+ Ethernet eth = new Ethernet();
+ eth.deserialize(dhcpPacket3, 0, dhcpPacket3.length);
+ assertTrue(eth.getPayload() instanceof IPv4);
+ IPv4 ipv4 = (IPv4) eth.getPayload();
+ assertTrue(ipv4.getPayload() instanceof UDP);
+
+ byte[] serializedPacket = eth.serialize();
+ Ethernet eth2 = new Ethernet();
+ eth2.deserialize(serializedPacket, 0, serializedPacket.length);
+ IPv4 ipv42 = (IPv4) eth2.getPayload();
+
+ short ipchecksum = ipv42.getChecksum();
+ ipv42.setChecksum((short) 0);
+ eth2.serialize();
+ assertEquals(ipchecksum, ipv42.getChecksum());
+ }
+
+ public void testDeSerializePXE() {
+ Ethernet eth = new Ethernet();
+ eth.deserialize(dhcpPacketPXE, 0, dhcpPacketPXE.length);
+ assertTrue(eth.getPayload() instanceof IPv4);
+ IPv4 ipv4 = (IPv4) eth.getPayload();
+ assertTrue(ipv4.getPayload() instanceof UDP);
+ UDP udp = (UDP) ipv4.getPayload();
+ assertTrue(udp.getPayload() instanceof DHCP);
+ DHCP dhcp = (DHCP) udp.getPayload();
+ /** The invalid option in DHCP packet is dropped. Reset checksums and
+ * length field so that the serialize() function can re-compute them
+ */
+ resetChecksumsAndLengths(ipv4, udp);
+
+ assertEquals(DHCP.OPCODE_REPLY, dhcp.getOpCode());
+ assertEquals("xenserver_5.6/pxelinux.0", dhcp.getBootFileName());
+
+ byte[] result = eth.serialize();
+ assertTrue(Arrays.equals(this.dhcpPacketPXE, result));
+ }
+
+ public void testDeSerializeBad1() {
+ Ethernet eth = new Ethernet();
+ eth.deserialize(dhcpPacketBadOption1, 0, dhcpPacketBadOption1.length);
+ assertTrue(eth.getPayload() instanceof IPv4);
+ IPv4 ipv4 = (IPv4) eth.getPayload();
+ assertTrue(ipv4.getPayload() instanceof UDP);
+ UDP udp = (UDP) ipv4.getPayload();
+ assertTrue(udp.getPayload() instanceof DHCP);
+ DHCP dhcp = (DHCP) udp.getPayload();
+ /** The invalid option in DHCP packet is dropped. Reset checksums and
+ * length field so that the serialize() function can re-compute them
+ */
+ resetChecksumsAndLengths(ipv4, udp);
+
+ assertEquals(DHCP.OPCODE_REPLY, dhcp.getOpCode());
+ ListIterator<DHCPOption> lit = dhcp.getOptions().listIterator();
+ // Expect 5 correct options and an END option.
+ assertEquals(dhcp.getOptions().size(), 6);
+ while (lit.hasNext()) {
+ DHCPOption option = lit.next();
+ assertFalse(option.code == (byte)0x0c);
+ }
+
+ byte[] result = eth.serialize();
+ // Since one option is badly formated, the result is different.
+ assertFalse(Arrays.equals(this.dhcpPacketPXE, result));
+ }
+
+ public void testDeSerializeBadHeader() {
+ Ethernet eth = new Ethernet();
+ eth.deserialize(dhcpPacketBadHeader, 0, dhcpPacketBadHeader.length);
+ assertTrue(eth.getPayload() instanceof IPv4);
+ IPv4 ipv4 = (IPv4) eth.getPayload();
+ assertTrue(ipv4.getPayload() instanceof UDP);
+ UDP udp = (UDP) ipv4.getPayload();
+ assertTrue(udp.getPayload() instanceof DHCP);
+ DHCP dhcp = (DHCP) udp.getPayload();
+
+ assertEquals(UDP.DHCP_CLIENT_PORT, udp.getSourcePort());
+ assertEquals(UDP.DHCP_SERVER_PORT, udp.getDestinationPort());
+
+ // should get invalid opCode of 0
+ assertEquals(0, dhcp.getOpCode());
+ }
+}
diff --git a/src/test/java/net/onrc/onos/packet/EthernetTest.java b/src/test/java/net/onrc/onos/packet/EthernetTest.java
new file mode 100644
index 0000000..b22c779
--- /dev/null
+++ b/src/test/java/net/onrc/onos/packet/EthernetTest.java
@@ -0,0 +1,77 @@
+/**
+* Copyright 2011, Big Switch Networks, Inc.
+* Originally created by David Erickson, Stanford University
+*
+* Licensed under the Apache License, Version 2.0 (the "License"); you may
+* not use this file except in compliance with the License. You may obtain
+* a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+* License for the specific language governing permissions and limitations
+* under the License.
+**/
+
+/**
+ *
+ */
+package net.onrc.onos.packet;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+
+import net.onrc.onos.packet.Ethernet;
+
+import org.junit.Test;
+
+/**
+ * @author David Erickson (daviderickson@cs.stanford.edu)
+ *
+ */
+public class EthernetTest {
+ @Test
+ public void testToMACAddress() {
+ byte[] address = new byte[] { 0x0, 0x11, 0x22, (byte) 0xff,
+ (byte) 0xee, (byte) 0xdd};
+ assertTrue(Arrays.equals(address, Ethernet
+ .toMACAddress("00:11:22:ff:ee:dd")));
+ assertTrue(Arrays.equals(address, Ethernet
+ .toMACAddress("00:11:22:FF:EE:DD")));
+ }
+
+ @Test
+ public void testSerialize() {
+ Ethernet ethernet = new Ethernet()
+ .setDestinationMACAddress("de:ad:be:ef:de:ad")
+ .setSourceMACAddress("be:ef:de:ad:be:ef")
+ .setEtherType((short) 0);
+ byte[] expected = new byte[] { (byte) 0xde, (byte) 0xad, (byte) 0xbe,
+ (byte) 0xef, (byte) 0xde, (byte) 0xad, (byte) 0xbe,
+ (byte) 0xef, (byte) 0xde, (byte) 0xad, (byte) 0xbe,
+ (byte) 0xef, 0x0, 0x0 };
+ assertTrue(Arrays.equals(expected, ethernet.serialize()));
+ }
+
+ @Test
+ public void testToLong() {
+ assertEquals(
+ 281474976710655L,
+ Ethernet.toLong(new byte[] { (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff }));
+
+ assertEquals(
+ 1103823438081L,
+ Ethernet.toLong(new byte[] { (byte) 0x01, (byte) 0x01,
+ (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01 }));
+
+ assertEquals(
+ 141289400074368L,
+ Ethernet.toLong(new byte[] { (byte) 0x80, (byte) 0x80,
+ (byte) 0x80, (byte) 0x80, (byte) 0x80, (byte) 0x80 }));
+ }
+}
diff --git a/src/test/java/net/onrc/onos/packet/ICMPTest.java b/src/test/java/net/onrc/onos/packet/ICMPTest.java
new file mode 100644
index 0000000..73e9cff
--- /dev/null
+++ b/src/test/java/net/onrc/onos/packet/ICMPTest.java
@@ -0,0 +1,72 @@
+/**
+* Copyright 2011, Big Switch Networks, Inc.
+* Originally created by David Erickson, Stanford University
+*
+* Licensed under the Apache License, Version 2.0 (the "License"); you may
+* not use this file except in compliance with the License. You may obtain
+* a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+* License for the specific language governing permissions and limitations
+* under the License.
+**/
+
+/**
+ *
+ */
+package net.onrc.onos.packet;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+
+import net.onrc.onos.packet.Data;
+import net.onrc.onos.packet.ICMP;
+import net.onrc.onos.packet.IPacket;
+import net.onrc.onos.packet.IPv4;
+
+import org.junit.Test;
+
+/**
+ * @author shudong.zhou@bigswitch.com
+ */
+public class ICMPTest {
+ private byte[] pktSerialized = new byte[] {
+ // (byte) 0xc8, 0x2a, 0x14, 0x2d, 0x35, (byte) 0xf1,
+ // 0x00, 0x0c, 0x29, 0x3b, (byte) 0x95, (byte) 0xf2, 0x08, 0x0,
+ 0x45, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x40, 0x00, 0x40, 0x01,
+ (byte) 0xa3, (byte) 0xcb,
+ (byte) 0xc0, (byte) 0xa8, (byte) 0x0a, (byte) 0xe7,
+ (byte) 0xc0, (byte) 0xa8, (byte) 0x0a, (byte) 0xdb,
+ 0x08, 0x00, 0x7f, 0x0a, 0x76, (byte) 0xf2, 0x00, 0x02,
+ 0x01, 0x01, 0x01 };
+ @Test
+ public void testSerialize() {
+ IPacket packet = new IPv4()
+ .setIdentification((short) 0)
+ .setFlags((byte) 0x02)
+ .setTtl((byte) 64)
+ .setSourceAddress("192.168.10.231")
+ .setDestinationAddress("192.168.10.219")
+ .setPayload(new ICMP()
+ .setIcmpType((byte) 8)
+ .setIcmpCode((byte) 0)
+ .setPayload(new Data(new byte[]
+ {0x76, (byte) 0xf2, 0x0, 0x2, 0x1, 0x1, 0x1}))
+ );
+ byte[] actual = packet.serialize();
+ assertTrue(Arrays.equals(pktSerialized, actual));
+ }
+
+ @Test
+ public void testDeserialize() {
+ IPacket packet = new IPv4();
+ packet.deserialize(pktSerialized, 0, pktSerialized.length);
+ byte[] pktSerialized1 = packet.serialize();
+ assertTrue(Arrays.equals(pktSerialized, pktSerialized1));
+ }
+}
diff --git a/src/test/java/net/onrc/onos/packet/IPv4Test.java b/src/test/java/net/onrc/onos/packet/IPv4Test.java
new file mode 100644
index 0000000..b81be6f
--- /dev/null
+++ b/src/test/java/net/onrc/onos/packet/IPv4Test.java
@@ -0,0 +1,90 @@
+/**
+* Copyright 2011, Big Switch Networks, Inc.
+* Originally created by David Erickson, Stanford University
+*
+* Licensed under the Apache License, Version 2.0 (the "License"); you may
+* not use this file except in compliance with the License. You may obtain
+* a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+* License for the specific language governing permissions and limitations
+* under the License.
+**/
+
+/**
+ *
+ */
+package net.onrc.onos.packet;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+
+import net.onrc.onos.packet.IPv4;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author David Erickson (daviderickson@cs.stanford.edu)
+ *
+ */
+public class IPv4Test {
+ @Test
+ public void testToIPv4Address() {
+ int intIp = 0xc0a80001;
+ String stringIp = "192.168.0.1";
+ byte[] byteIp = new byte[] {(byte)192, (byte)168, (byte)0, (byte)1};
+ assertEquals(intIp, IPv4.toIPv4Address(stringIp));
+ assertEquals(intIp, IPv4.toIPv4Address(byteIp));
+ assertTrue(Arrays.equals(byteIp, IPv4.toIPv4AddressBytes(intIp)));
+ assertTrue(Arrays.equals(byteIp, IPv4.toIPv4AddressBytes(stringIp)));
+ }
+
+ @Test
+ public void testToIPv4AddressBytes() {
+ byte[] expected = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff};
+ Assert.assertArrayEquals(expected, IPv4.toIPv4AddressBytes("255.255.255.255"));
+ expected = new byte[] {(byte) 0x80, (byte) 0x80, (byte) 0x80, (byte) 0x80};
+ Assert.assertArrayEquals(expected, IPv4.toIPv4AddressBytes("128.128.128.128"));
+ expected = new byte[] {0x7f,0x7f,0x7f,0x7f};
+ Assert.assertArrayEquals(expected, IPv4.toIPv4AddressBytes("127.127.127.127"));
+ }
+
+ @Test
+ public void testSerialize() {
+ byte[] expected = new byte[] { 0x45, 0x00, 0x00, 0x14, 0x5e, 0x4e,
+ 0x00, 0x00, 0x3f, 0x06, 0x31, 0x2e, (byte) 0xac, 0x18,
+ 0x4a, (byte) 0xdf, (byte) 0xab, 0x40, 0x4a, 0x30 };
+ IPv4 packet = new IPv4()
+ .setIdentification((short) 24142)
+ .setTtl((byte) 63)
+ .setProtocol((byte) 0x06)
+ .setSourceAddress("172.24.74.223")
+ .setDestinationAddress("171.64.74.48");
+ byte[] actual = packet.serialize();
+ assertTrue(Arrays.equals(expected, actual));
+ }
+
+ @Test
+ public void testDeserialize() {
+ // A real TLSv1 packet
+ byte[] pktSerialized = new byte[] { 0x45, 0x00,
+ 0x00, 0x2e, 0x41, (byte) 0xbe, 0x40, 0x00, 0x40, 0x06,
+ (byte) 0xd4, (byte) 0xf0, (byte) 0xc0, (byte) 0xa8, 0x02, (byte) 0xdb, (byte) 0xd0, 0x55,
+ (byte) 0x90, 0x42, (byte) 0xd5, 0x48, 0x01, (byte) 0xbb, (byte) 0xe3, 0x50,
+ (byte) 0xb2, 0x2f, (byte) 0xfc, (byte) 0xf8, (byte) 0xa8, 0x2c, 0x50, 0x18,
+ (byte) 0xff, (byte) 0xff, 0x24, 0x3c, 0x00, 0x00, 0x14, 0x03,
+ 0x01, 0x00, 0x01, 0x01
+ };
+ IPv4 packet = new IPv4();
+ packet.deserialize(pktSerialized, 0, pktSerialized.length);
+ byte[] pktSerialized1 = packet.serialize();
+ assertTrue(Arrays.equals(pktSerialized, pktSerialized1));
+ }
+}
diff --git a/src/test/java/net/onrc/onos/packet/LLDPOrganizationalTLVTest.java b/src/test/java/net/onrc/onos/packet/LLDPOrganizationalTLVTest.java
new file mode 100644
index 0000000..1a8367c
--- /dev/null
+++ b/src/test/java/net/onrc/onos/packet/LLDPOrganizationalTLVTest.java
@@ -0,0 +1,97 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License. You may obtain
+ * a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ **/
+
+package net.onrc.onos.packet;
+
+import net.onrc.onos.packet.LLDPOrganizationalTLV;
+
+import org.junit.Test;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class LLDPOrganizationalTLVTest {
+ private final byte[] expected = new byte[] {
+ // Type: 127, Length: 13
+ (byte) 254, 13,
+ // OpenFlow OUI: 00-26-E1
+ 0x0, 0x26, (byte)0xe1,
+ // SubType: 12
+ 0xc,
+ // Bytes in "ExtraInfo"
+ 0x45, 0x78, 0x74, 0x72, 0x61, 0x49, 0x6e, 0x66, 0x6f
+ };
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testShortOUI() {
+ LLDPOrganizationalTLV tlv = new LLDPOrganizationalTLV();
+ tlv.setOUI(new byte[2]);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testLongOUI() {
+ LLDPOrganizationalTLV tlv = new LLDPOrganizationalTLV();
+ tlv.setOUI(new byte[4]);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testLongInfoString() {
+ LLDPOrganizationalTLV tlv = new LLDPOrganizationalTLV();
+ tlv.setInfoString(new byte[LLDPOrganizationalTLV.MAX_INFOSTRING_LENGTH + 1]);
+ }
+
+ @Test
+ public void testMaxInfoString() {
+ LLDPOrganizationalTLV tlv = new LLDPOrganizationalTLV();
+ tlv.setInfoString(new byte[LLDPOrganizationalTLV.MAX_INFOSTRING_LENGTH]);
+ }
+
+ @Test
+ public void testInfoString() {
+ LLDPOrganizationalTLV tlv = new LLDPOrganizationalTLV();
+ tlv.setInfoString("ExtraInfo");
+ assertThat(tlv.getInfoString(), is("ExtraInfo".getBytes(Charset.forName("UTF-8"))));
+ }
+
+ @Test
+ public void testSerialize() {
+ LLDPOrganizationalTLV tlv = new LLDPOrganizationalTLV();
+ tlv.setLength((short) 13);
+ // OpenFlow OUI is 00-26-E1
+ tlv.setOUI(new byte[] {0x0, 0x26, (byte) 0xe1});
+ tlv.setSubType((byte) 12);
+ tlv.setInfoString("ExtraInfo".getBytes(Charset.forName("UTF-8")));
+
+ assertThat(tlv.getType(), is((byte)127));
+ assertThat(tlv.getLength(), is((short)13));
+ assertThat(tlv.getOUI(), is(new byte[] {0x0, 0x26, (byte) 0xe1}));
+ assertThat(tlv.getSubType(), is((byte)12));
+ assertThat(tlv.serialize(), is(expected));
+ }
+
+ @Test
+ public void testDeserialize() {
+ LLDPOrganizationalTLV tlv = new LLDPOrganizationalTLV();
+ tlv.deserialize(ByteBuffer.wrap(expected));
+
+ assertThat(tlv.getType(), is((byte)127));
+ assertThat(tlv.getLength(), is((short)13));
+ assertThat(tlv.getOUI(), is(new byte[] {0x0, 0x26, (byte) 0xe1}));
+ assertThat(tlv.getSubType(), is((byte)12));
+ assertThat(tlv.getInfoString(), is("ExtraInfo".getBytes(Charset.forName("UTF-8"))));
+ }
+}
diff --git a/src/test/java/net/onrc/onos/packet/LLDPTest.java b/src/test/java/net/onrc/onos/packet/LLDPTest.java
new file mode 100755
index 0000000..c093efb
--- /dev/null
+++ b/src/test/java/net/onrc/onos/packet/LLDPTest.java
@@ -0,0 +1,76 @@
+/**
+* Copyright 2011, Big Switch Networks, Inc.
+* Originally created by David Erickson, Stanford University
+*
+* Licensed under the Apache License, Version 2.0 (the "License"); you may
+* not use this file except in compliance with the License. You may obtain
+* a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+* License for the specific language governing permissions and limitations
+* under the License.
+**/
+
+/**
+ *
+ */
+package net.onrc.onos.packet;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+
+import net.onrc.onos.packet.Ethernet;
+import net.onrc.onos.packet.IPacket;
+import net.onrc.onos.packet.LLDP;
+import net.onrc.onos.packet.LLDPTLV;
+
+import org.junit.Test;
+
+/**
+ *
+ * @author David Erickson (daviderickson@cs.stanford.edu)
+ *
+ */
+public class LLDPTest {
+ protected byte[] pkt = {0x01,0x23,0x20,0x00,0x00,0x01,0x00,0x12,(byte) 0xe2,0x78,0x67,0x78,(byte) 0x88,(byte) 0xcc,0x02,0x07,
+ 0x04,0x00,0x12,(byte) 0xe2,0x78,0x67,0x64,0x04,0x03,0x02,0x00,0x06,0x06,0x02,0x00,0x78,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
+
+ protected IPacket getPacket() {
+ return new Ethernet()
+ .setPad(true)
+ .setDestinationMACAddress("01:23:20:00:00:01")
+ .setSourceMACAddress("00:12:e2:78:67:78")
+ .setEtherType(Ethernet.TYPE_LLDP)
+ .setPayload(
+ new LLDP()
+ .setChassisId(new LLDPTLV().setType((byte) 1).setLength((short) 7).setValue(new byte[] {0x04, 0x00, 0x12, (byte) 0xe2, 0x78, 0x67, 0x64}))
+ .setPortId(new LLDPTLV().setType((byte) 2).setLength((short) 3).setValue(new byte[] {0x02, 0x00, 0x06}))
+ .setTtl(new LLDPTLV().setType((byte) 3).setLength((short) 2).setValue(new byte[] {0x00, 0x78}))
+
+ );
+ }
+
+ @Test
+ public void testSerialize() throws Exception {
+ IPacket ethernet = getPacket();
+ assertTrue(Arrays.equals(pkt, ethernet.serialize()));
+ }
+
+ @Test
+ public void testDeserialize() throws Exception {
+ Ethernet ethernet = (Ethernet) new Ethernet().deserialize(pkt, 0, pkt.length);
+ ethernet.setPad(true);
+ assertTrue(Arrays.equals(pkt, ethernet.serialize()));
+
+ IPacket expected = getPacket();
+ assertEquals(expected, ethernet);
+ }
+}
diff --git a/src/test/java/net/onrc/onos/packet/PacketTest.java b/src/test/java/net/onrc/onos/packet/PacketTest.java
new file mode 100644
index 0000000..f30c12b
--- /dev/null
+++ b/src/test/java/net/onrc/onos/packet/PacketTest.java
@@ -0,0 +1,133 @@
+package net.onrc.onos.packet;
+
+import static org.junit.Assert.*;
+import net.onrc.onos.packet.ARP;
+import net.onrc.onos.packet.Data;
+import net.onrc.onos.packet.Ethernet;
+import net.onrc.onos.packet.IPacket;
+import net.onrc.onos.packet.IPv4;
+import net.onrc.onos.packet.UDP;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class PacketTest {
+ protected IPacket pkt1, pkt2, pkt3, pkt4;
+ protected IPacket dummyPkt;
+ protected IPacket[] packets;
+
+ @Before
+ public void setUp() {
+ this.pkt1 = new Ethernet()
+ .setDestinationMACAddress("00:11:22:33:44:55")
+ .setSourceMACAddress("00:44:33:22:11:00")
+ .setEtherType(Ethernet.TYPE_IPv4)
+ .setPayload(
+ new IPv4()
+ .setTtl((byte) 128)
+ .setSourceAddress("192.168.1.1")
+ .setDestinationAddress("192.168.1.2")
+ .setPayload(new UDP()
+ .setSourcePort((short) 5000)
+ .setDestinationPort((short) 5001)
+ .setPayload(new Data(new byte[] {0x01}))));
+
+ this.pkt2 = new Ethernet()
+ .setSourceMACAddress("00:44:33:22:11:01")
+ .setDestinationMACAddress("00:11:22:33:44:55")
+ .setEtherType(Ethernet.TYPE_ARP)
+ .setVlanID((short)5)
+ .setPayload(
+ new ARP()
+ .setHardwareType(ARP.HW_TYPE_ETHERNET)
+ .setProtocolType(ARP.PROTO_TYPE_IP)
+ .setHardwareAddressLength((byte) 6)
+ .setProtocolAddressLength((byte) 4)
+ .setOpCode(ARP.OP_REPLY)
+ .setSenderHardwareAddress(Ethernet.toMACAddress("00:44:33:22:11:01"))
+ .setSenderProtocolAddress(IPv4.toIPv4AddressBytes("192.168.1.1"))
+ .setTargetHardwareAddress(Ethernet.toMACAddress("00:11:22:33:44:55"))
+ .setTargetProtocolAddress(IPv4.toIPv4AddressBytes("192.168.1.2")));
+
+
+ this.pkt3 = new Ethernet()
+ .setSourceMACAddress("00:44:33:22:11:01")
+ .setDestinationMACAddress("00:11:22:33:44:55")
+ .setEtherType(Ethernet.TYPE_ARP)
+ .setPayload(
+ new ARP()
+ .setHardwareType(ARP.HW_TYPE_ETHERNET)
+ .setProtocolType(ARP.PROTO_TYPE_IP)
+ .setHardwareAddressLength((byte) 6)
+ .setProtocolAddressLength((byte) 4)
+ .setOpCode(ARP.OP_REPLY)
+ .setSenderHardwareAddress(Ethernet.toMACAddress("00:44:33:22:11:01"))
+ .setSenderProtocolAddress(IPv4.toIPv4AddressBytes("192.168.1.1"))
+ .setTargetHardwareAddress(Ethernet.toMACAddress("00:11:22:33:44:55"))
+ .setTargetProtocolAddress(IPv4.toIPv4AddressBytes("192.168.1.2")));
+
+ this.pkt4 = new Ethernet()
+ .setDestinationMACAddress("FF:FF:FF:FF:FF:FF")
+ .setSourceMACAddress("00:11:33:55:77:01")
+ .setEtherType(Ethernet.TYPE_IPv4)
+ .setPayload(
+ new IPv4()
+ .setTtl((byte) 128)
+ .setSourceAddress("192.168.10.1")
+ .setDestinationAddress("192.168.255.255")
+ .setPayload(new UDP()
+ .setSourcePort((short) 5000)
+ .setDestinationPort((short) 5001)
+ .setPayload(new Data(new byte[] {0x01}))));
+
+ this.dummyPkt = new IPv4()
+ .setTtl((byte) 32)
+ .setSourceAddress("1.2.3.4")
+ .setDestinationAddress("5.6.7.8");
+
+ this.packets = new IPacket[] { pkt1, pkt2, pkt3, pkt4 };
+ }
+
+ protected void doTestClone(IPacket pkt) {
+ if (pkt.getPayload() != null)
+ doTestClone(pkt.getPayload());
+ IPacket newPkt = (IPacket)pkt.clone();
+ assertSame(pkt.getClass(), newPkt.getClass());
+ assertNotSame(pkt, newPkt);
+ assertSame(pkt.getParent(), newPkt.getParent());
+ assertEquals(pkt, newPkt);
+ assertEquals(pkt.getPayload(), newPkt.getPayload());
+ if (pkt.getPayload() != null)
+ assertNotSame(pkt.getPayload(), newPkt.getPayload());
+
+ if (pkt instanceof Ethernet) {
+ Ethernet eth = (Ethernet)pkt;
+ Ethernet newEth = (Ethernet)newPkt;
+ newEth.setDestinationMACAddress(new byte[] { 1,2,3,4,5,6});
+ assertEquals(false, newEth.getDestinationMAC()
+ .equals(eth.getDestinationMAC()));
+ assertEquals(false, newPkt.equals(pkt));
+ }
+ if (pkt instanceof ARP) {
+ ARP arp = (ARP)pkt;
+ ARP newArp = (ARP)newPkt;
+ newArp.setSenderProtocolAddress(new byte[] {1,2,3,4});
+ assertEquals(false, newArp.getSenderProtocolAddress()
+ .equals(arp.getSenderProtocolAddress()));
+ assertEquals(false, newPkt.equals(pkt));
+ }
+
+ byte[] dummyData = dummyPkt.serialize().clone();
+ newPkt = (IPacket)pkt.clone();
+ newPkt.deserialize(dummyData, 0, dummyData.length);
+ assertEquals(false, newPkt.equals(pkt));
+ }
+
+ @Test
+ public void testClone() {
+ for (IPacket pkt: packets) {
+ doTestClone(pkt);
+ }
+ }
+
+}
diff --git a/src/test/java/net/onrc/onos/packet/TCPTest.java b/src/test/java/net/onrc/onos/packet/TCPTest.java
new file mode 100644
index 0000000..03ef8b6
--- /dev/null
+++ b/src/test/java/net/onrc/onos/packet/TCPTest.java
@@ -0,0 +1,78 @@
+/**
+* Copyright 2011, Big Switch Networks, Inc.
+* Originally created by David Erickson, Stanford University
+*
+* Licensed under the Apache License, Version 2.0 (the "License"); you may
+* not use this file except in compliance with the License. You may obtain
+* a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+* License for the specific language governing permissions and limitations
+* under the License.
+**/
+
+/**
+ *
+ */
+package net.onrc.onos.packet;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+
+import net.onrc.onos.packet.IPacket;
+import net.onrc.onos.packet.IPv4;
+import net.onrc.onos.packet.TCP;
+
+import org.junit.Test;
+
+/**
+ * @author shudong.zhou@bigswitch.com
+ */
+public class TCPTest {
+ private byte[] pktSerialized = new byte[] { 0x45, 0x20,
+ 0x00, 0x34, 0x1d, (byte) 0x85, 0x00, 0x00, 0x32, 0x06,
+ 0x31, 0x1e, 0x4a, 0x7d, 0x2d, 0x6d, (byte) 0xc0, (byte) 0xa8,
+ 0x01, 0x6f, 0x03, (byte) 0xe1, (byte) 0xc0, 0x32, (byte) 0xe3, (byte) 0xad,
+ (byte) 0xee, (byte) 0x88, (byte) 0xb7, (byte) 0xda, (byte) 0xd8, 0x24, (byte) 0x80, 0x10,
+ 0x01, 0x0b, 0x59, 0x33, 0x00, 0x00, 0x01, 0x01,
+ 0x08, 0x0a, 0x20, (byte) 0x9a, 0x41, 0x04, 0x07, 0x76,
+ 0x53, 0x1f};
+
+ @Test
+ public void testSerialize() {
+ IPacket packet = new IPv4()
+ .setDiffServ((byte) 0x20)
+ .setIdentification((short) 0x1d85)
+ .setFlags((byte) 0x00)
+ .setTtl((byte) 50)
+ .setSourceAddress("74.125.45.109")
+ .setDestinationAddress("192.168.1.111")
+ .setPayload(new TCP()
+ .setSourcePort((short) 993)
+ .setDestinationPort((short) 49202)
+ .setSequence(0xe3adee88)
+ .setAcknowledge(0xb7dad824)
+ .setDataOffset((byte) 8)
+ .setFlags((short) 0x10)
+ .setWindowSize((short) 267)
+ .setOptions(new byte[] {0x01, 0x01, 0x08, 0x0a, 0x20, (byte) 0x9a,
+ 0x41, 0x04, 0x07, 0x76, 0x53, 0x1f})
+ .setPayload(null)
+ );
+ byte[] actual = packet.serialize();
+ assertTrue(Arrays.equals(pktSerialized, actual));
+ }
+
+ @Test
+ public void testDeserialize() {
+ IPacket packet = new IPv4();
+ packet.deserialize(pktSerialized, 0, pktSerialized.length);
+ byte[] pktSerialized1 = packet.serialize();
+ assertTrue(Arrays.equals(pktSerialized, pktSerialized1));
+ }
+}
diff --git a/src/test/java/net/onrc/onos/packet/UDPTest.java b/src/test/java/net/onrc/onos/packet/UDPTest.java
new file mode 100644
index 0000000..c9081e8
--- /dev/null
+++ b/src/test/java/net/onrc/onos/packet/UDPTest.java
@@ -0,0 +1,60 @@
+/**
+* Copyright 2011, Big Switch Networks, Inc.
+* Originally created by David Erickson, Stanford University
+*
+* Licensed under the Apache License, Version 2.0 (the "License"); you may
+* not use this file except in compliance with the License. You may obtain
+* a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+* License for the specific language governing permissions and limitations
+* under the License.
+**/
+
+/**
+ *
+ */
+package net.onrc.onos.packet;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+
+import net.onrc.onos.packet.Data;
+import net.onrc.onos.packet.IPacket;
+import net.onrc.onos.packet.IPv4;
+import net.onrc.onos.packet.UDP;
+
+import org.junit.Test;
+
+/**
+ * @author David Erickson (daviderickson@cs.stanford.edu)
+ *
+ */
+public class UDPTest {
+
+ @Test
+ public void testSerialize() {
+ byte[] expected = new byte[] { 0x45, 0x00, 0x00, 0x1d, 0x56, 0x23,
+ 0x00, 0x00, (byte) 0x80, 0x11, 0x48, 0x7f, (byte) 0xc0,
+ (byte) 0xa8, 0x01, 0x02, 0x0c, (byte) 0x81, (byte) 0xce, 0x02,
+ 0x17, (byte) 0xe1, 0x04, 0x5f, 0x00, 0x09, 0x46, 0x6e,
+ 0x01 };
+ IPacket packet = new IPv4()
+ .setIdentification((short) 22051)
+ .setTtl((byte) 128)
+ .setSourceAddress("192.168.1.2")
+ .setDestinationAddress("12.129.206.2")
+ .setPayload(new UDP()
+ .setSourcePort((short) 6113)
+ .setDestinationPort((short) 1119)
+ .setPayload(new Data(new byte[] {0x01}))
+ );
+ byte[] actual = packet.serialize();
+ assertTrue(Arrays.equals(expected, actual));
+ }
+}