Implemented a mechanism to easily add and access Neighbor Discovery protocol
packet options.

Fixes ONOS-1011

Change-Id: I94daa3f3c1297fb9a7b44901927738a29aff030a
diff --git a/utils/misc/src/main/java/org/onlab/packet/ndp/NeighborAdvertisement.java b/utils/misc/src/main/java/org/onlab/packet/ndp/NeighborAdvertisement.java
index 515dd4e..ccb87e3 100644
--- a/utils/misc/src/main/java/org/onlab/packet/ndp/NeighborAdvertisement.java
+++ b/utils/misc/src/main/java/org/onlab/packet/ndp/NeighborAdvertisement.java
@@ -16,30 +16,27 @@
 package org.onlab.packet.ndp;
 
 import org.onlab.packet.BasePacket;
-import org.onlab.packet.Data;
 import org.onlab.packet.IPacket;
 import org.onlab.packet.Ip6Address;
 
 import java.nio.ByteBuffer;
 import java.util.Arrays;
+import java.util.List;
 
 /**
  * Implements ICMPv6 Neighbor Advertisement packet format (RFC 4861).
  */
 public class NeighborAdvertisement extends BasePacket {
     public static final byte HEADER_LENGTH = 20; // bytes
-    public static final byte OPTION_TYPE_SOURCE_LL_ADDRESS = 1;
-    public static final byte OPTION_TYPE_TARGET_LL_ADDRESS = 2;
-    public static final byte OPTION_TYPE_PREFIX_INFORMATION = 3;
-    public static final byte OPTION_TYPE_REDIRECTED_HEADER = 4;
-    public static final byte OPTION_TYPE_MTU = 5;
-    public static final byte OPTION_LENGTH_IEEE802_ADDRESS = 8;
 
     protected byte routerFlag;
     protected byte solicitedFlag;
     protected byte overrideFlag;
     protected byte[] targetAddress = new byte[Ip6Address.BYTE_LENGTH];
 
+    private final NeighborDiscoveryOptions options =
+        new NeighborDiscoveryOptions();
+
     /**
      * Gets router flag.
      *
@@ -116,30 +113,54 @@
      * @return this
      */
     public NeighborAdvertisement setTargetAddress(final byte[] targetAddress) {
-        this.targetAddress = Arrays.copyOfRange(targetAddress, 0, Ip6Address.BYTE_LENGTH);
+        this.targetAddress =
+            Arrays.copyOfRange(targetAddress, 0, Ip6Address.BYTE_LENGTH);
+        return this;
+    }
+
+    /**
+     * Gets the Neighbor Discovery Protocol packet options.
+     *
+     * @return the Neighbor Discovery Protocol packet options
+     */
+    public List<NeighborDiscoveryOptions.Option> getOptions() {
+        return this.options.options();
+    }
+
+    /**
+     * Adds a Neighbor Discovery Protocol packet option.
+     *
+     * @param type the option type
+     * @param data the option data
+     * @return this
+     */
+    public NeighborAdvertisement addOption(final byte type,
+                                           final byte[] data) {
+        this.options.addOption(type, data);
         return this;
     }
 
     @Override
     public byte[] serialize() {
-        byte[] payloadData = null;
-        if (this.payload != null) {
-            this.payload.setParent(this);
-            payloadData = this.payload.serialize();
+        byte[] optionsData = null;
+        if (this.options.hasOptions()) {
+            optionsData = this.options.serialize();
         }
 
-        int payloadLength = 0;
-        if (payloadData != null) {
-            payloadLength = payloadData.length;
+        int optionsLength = 0;
+        if (optionsData != null) {
+            optionsLength = optionsData.length;
         }
 
-        final byte[] data = new byte[HEADER_LENGTH + payloadLength];
+        final byte[] data = new byte[HEADER_LENGTH + optionsLength];
         final ByteBuffer bb = ByteBuffer.wrap(data);
 
-        bb.putInt((this.routerFlag & 0x1) << 31 | (this.solicitedFlag & 0x1) << 30 | (this.overrideFlag & 0x1) << 29);
+        bb.putInt((this.routerFlag & 0x1) << 31 |
+                  (this.solicitedFlag & 0x1) << 30 |
+                  (this.overrideFlag & 0x1) << 29);
         bb.put(this.targetAddress, 0, Ip6Address.BYTE_LENGTH);
-        if (payloadData != null) {
-            bb.put(payloadData);
+        if (optionsData != null) {
+            bb.put(optionsData);
         }
 
         return data;
@@ -156,10 +177,8 @@
         this.overrideFlag = (byte) (iscratch >> 29 & 0x1);
         bb.get(this.targetAddress, 0, Ip6Address.BYTE_LENGTH);
 
-        this.payload = new Data();
-        this.payload = this.payload.deserialize(data, bb.position(), bb.limit()
-                - bb.position());
-        this.payload.setParent(this);
+        this.options.deserialize(data, bb.position(),
+                                 bb.limit() - bb.position());
 
         return this;
     }
@@ -178,9 +197,10 @@
         result = prime * result + this.solicitedFlag;
         result = prime * result + this.overrideFlag;
         bb = ByteBuffer.wrap(this.targetAddress);
-        for (int i = 0; i < 4; i++) {
+        for (int i = 0; i < this.targetAddress.length / 4; i++) {
             result = prime * result + bb.getInt();
         }
+        result = prime * result + this.options.hashCode();
         return result;
     }
 
@@ -213,6 +233,9 @@
         if (!Arrays.equals(this.targetAddress, other.targetAddress)) {
             return false;
         }
+        if (!this.options.equals(other.options)) {
+            return false;
+        }
         return true;
     }
 }
diff --git a/utils/misc/src/main/java/org/onlab/packet/ndp/NeighborDiscoveryOptions.java b/utils/misc/src/main/java/org/onlab/packet/ndp/NeighborDiscoveryOptions.java
new file mode 100644
index 0000000..b8561b1
--- /dev/null
+++ b/utils/misc/src/main/java/org/onlab/packet/ndp/NeighborDiscoveryOptions.java
@@ -0,0 +1,232 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * 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 org.onlab.packet.ndp;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.onlab.packet.BasePacket;
+import org.onlab.packet.IPacket;
+
+/**
+ * Neighbor Discovery Protocol packet options.
+ */
+public class NeighborDiscoveryOptions extends BasePacket {
+    public static final byte TYPE_SOURCE_LL_ADDRESS = 1;
+    public static final byte TYPE_TARGET_LL_ADDRESS = 2;
+    public static final byte TYPE_PREFIX_INFORMATION = 3;
+    public static final byte TYPE_REDIRECTED_HEADER = 4;
+    public static final byte TYPE_MTU = 5;
+
+    private final List<Option> options = new ArrayList<>();
+
+    /**
+     * Packet option.
+     */
+    public final class Option {
+        private final byte type;
+        private final byte[] data;
+
+        /**
+         * Constructor.
+         *
+         * @param type the option type
+         * @param data the option data
+         */
+        private Option(byte type, byte[] data) {
+            this.type = type;
+            this.data = Arrays.copyOfRange(data, 0, data.length);
+        }
+
+        /**
+         * Gets the option type.
+         *
+         * @return the option type
+         */
+        public byte type() {
+            return this.type;
+        }
+
+        /**
+         * Gets the option data.
+         *
+         * @return the option data
+         */
+        public byte[] data() {
+            return this.data;
+        }
+
+        /**
+         * Gets the option data length (in number of octets).
+         *
+         * @return the option data length (in number of octets)
+         */
+        public int dataLength() {
+            return data.length;
+        }
+
+        /**
+         * Gets the option length (in number of octets), including the type and
+         * length fields (one octet each).
+         *
+         * @return the option length (in number of octets), including the type
+         * and length fields
+         */
+        private int optionLength() {
+            return 2 + dataLength();
+        }
+
+        /**
+         * Gets the option length field value (in units of 8 octets).
+         *
+         * @return the option length field value (in units of 8 octets)
+         */
+        private byte optionLengthField() {
+            return (byte) ((optionLength() + 7) / 8);
+        }
+
+        /**
+         * Gets the option length on the wire (in number of octets).
+         *
+         * @return the option length on the wire (in number of octets)
+         */
+        private int optionWireLength() {
+            return 8 * optionLengthField();
+        }
+    }
+
+    /**
+     * Adds a Neighbor Discovery Protocol packet option.
+     *
+     * @param type the option type
+     * @param data the option data
+     * @return this
+     */
+    public NeighborDiscoveryOptions addOption(byte type, byte[] data) {
+        options.add(new Option(type, data));
+        return this;
+    }
+
+    /**
+     * Gets the Neighbor Discovery Protocol packet options.
+     *
+     * @return the Neighbor Discovery Protocol packet options
+     */
+    public List<NeighborDiscoveryOptions.Option> options() {
+        return this.options;
+    }
+
+    /**
+     * Checks whether any options are included.
+     *
+     * @return true if options are included, otherwise false
+     */
+    public boolean hasOptions() {
+        return !this.options.isEmpty();
+    }
+
+    @Override
+    public byte[] serialize() {
+        // Compute first the total length on the wire for all options
+
+        int wireLength = 0;
+
+        for (Option option : this.options) {
+            wireLength += option.optionWireLength();
+        }
+
+        final byte[] data = new byte[wireLength];
+        final ByteBuffer bb = ByteBuffer.wrap(data);
+
+        //
+        // Serialize all options
+        //
+        for (Option option : this.options) {
+            bb.put(option.type());
+            bb.put(option.optionLengthField());
+            bb.put(option.data());
+            // Add the padding
+            int paddingLength =
+                option.optionWireLength() - option.optionLength();
+            for (int i = 0; i < paddingLength; i++) {
+                bb.put((byte) 0);
+            }
+        }
+
+        return data;
+    }
+
+    @Override
+    public IPacket deserialize(byte[] data, int offset, int length) {
+        final ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
+
+        options.clear();
+
+        //
+        // Deserialize all options
+        //
+        while (bb.hasRemaining()) {
+            byte type = bb.get();
+            if (!bb.hasRemaining()) {
+                break;
+            }
+            byte lengthField = bb.get();
+            int dataLength = lengthField * 8;   // The data length field is in
+                                                // unit of 8 octets
+
+            // Exclude the type and length fields
+            if (dataLength < 2) {
+                break;
+            }
+            dataLength -= 2;
+
+            if (bb.remaining() < dataLength) {
+                break;
+            }
+            byte[] optionData = new byte[dataLength];
+            bb.get(optionData, 0, optionData.length);
+            addOption(type, optionData);
+        }
+
+        return this;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+
+        for (Option option : this.options) {
+            result = prime * result + option.type();
+            result = prime * result + Arrays.hashCode(option.data());
+        }
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof NeighborDiscoveryOptions) {
+            NeighborDiscoveryOptions other = (NeighborDiscoveryOptions) obj;
+            return this.options.equals(other.options);
+        }
+        return false;
+    }
+}
diff --git a/utils/misc/src/main/java/org/onlab/packet/ndp/NeighborSolicitation.java b/utils/misc/src/main/java/org/onlab/packet/ndp/NeighborSolicitation.java
index 878f939..25df3b4 100644
--- a/utils/misc/src/main/java/org/onlab/packet/ndp/NeighborSolicitation.java
+++ b/utils/misc/src/main/java/org/onlab/packet/ndp/NeighborSolicitation.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2014 Open Networking Laboratory
+ * Copyright 2014-2015 Open Networking Laboratory
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -13,18 +13,15 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-
-
 package org.onlab.packet.ndp;
 
 import org.onlab.packet.BasePacket;
-import org.onlab.packet.Data;
 import org.onlab.packet.IPacket;
 import org.onlab.packet.Ip6Address;
 
 import java.nio.ByteBuffer;
 import java.util.Arrays;
+import java.util.List;
 
 /**
  * Implements ICMPv6 Neighbor Solicitation packet format. (RFC 4861)
@@ -34,6 +31,9 @@
 
     protected byte[] targetAddress = new byte[Ip6Address.BYTE_LENGTH];
 
+    private final NeighborDiscoveryOptions options =
+        new NeighborDiscoveryOptions();
+
     /**
      * Gets target address.
      *
@@ -50,30 +50,52 @@
      * @return this
      */
     public NeighborSolicitation setTargetAddress(final byte[] targetAddress) {
-        this.targetAddress = Arrays.copyOfRange(targetAddress, 0, Ip6Address.BYTE_LENGTH);
+        this.targetAddress =
+            Arrays.copyOfRange(targetAddress, 0, Ip6Address.BYTE_LENGTH);
+        return this;
+    }
+
+    /**
+     * Gets the Neighbor Discovery Protocol packet options.
+     *
+     * @return the Neighbor Discovery Protocol packet options
+     */
+    public List<NeighborDiscoveryOptions.Option> getOptions() {
+        return this.options.options();
+    }
+
+    /**
+     * Adds a Neighbor Discovery Protocol packet option.
+     *
+     * @param type the option type
+     * @param data the option data
+     * @return this
+     */
+    public NeighborSolicitation addOption(final byte type,
+                                          final byte[] data) {
+        this.options.addOption(type, data);
         return this;
     }
 
     @Override
     public byte[] serialize() {
-        byte[] payloadData = null;
-        if (this.payload != null) {
-            this.payload.setParent(this);
-            payloadData = this.payload.serialize();
+        byte[] optionsData = null;
+        if (this.options.hasOptions()) {
+            optionsData = this.options.serialize();
         }
 
-        int payloadLength = 0;
-        if (payloadData != null) {
-            payloadLength = payloadData.length;
+        int optionsLength = 0;
+        if (optionsData != null) {
+            optionsLength = optionsData.length;
         }
 
-        final byte[] data = new byte[HEADER_LENGTH + payloadLength];
+        final byte[] data = new byte[HEADER_LENGTH + optionsLength];
         final ByteBuffer bb = ByteBuffer.wrap(data);
 
         bb.putInt(0);
         bb.put(this.targetAddress, 0, Ip6Address.BYTE_LENGTH);
-        if (payloadData != null) {
-            bb.put(payloadData);
+        if (optionsData != null) {
+            bb.put(optionsData);
         }
 
         return data;
@@ -86,10 +108,8 @@
         bb.getInt();
         bb.get(this.targetAddress, 0, Ip6Address.BYTE_LENGTH);
 
-        this.payload = new Data();
-        this.payload = this.payload.deserialize(data, bb.position(), bb.limit()
-                - bb.position());
-        this.payload.setParent(this);
+        this.options.deserialize(data, bb.position(),
+                                 bb.limit() - bb.position());
 
         return this;
     }
@@ -105,9 +125,10 @@
         int result = super.hashCode();
         ByteBuffer bb;
         bb = ByteBuffer.wrap(this.targetAddress);
-        for (int i = 0; i < 4; i++) {
+        for (int i = 0; i < this.targetAddress.length / 4; i++) {
             result = prime * result + bb.getInt();
         }
+        result = prime * result + this.options.hashCode();
         return result;
     }
 
@@ -131,6 +152,9 @@
         if (!Arrays.equals(this.targetAddress, other.targetAddress)) {
             return false;
         }
+        if (!this.options.equals(other.options)) {
+            return false;
+        }
         return true;
     }
 }
diff --git a/utils/misc/src/main/java/org/onlab/packet/ndp/Redirect.java b/utils/misc/src/main/java/org/onlab/packet/ndp/Redirect.java
index a7e7680..0515869 100644
--- a/utils/misc/src/main/java/org/onlab/packet/ndp/Redirect.java
+++ b/utils/misc/src/main/java/org/onlab/packet/ndp/Redirect.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2014 Open Networking Laboratory
+ * Copyright 2014-2015 Open Networking Laboratory
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -13,18 +13,15 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-
-
 package org.onlab.packet.ndp;
 
 import org.onlab.packet.BasePacket;
-import org.onlab.packet.Data;
 import org.onlab.packet.IPacket;
 import org.onlab.packet.Ip6Address;
 
 import java.nio.ByteBuffer;
 import java.util.Arrays;
+import java.util.List;
 
 /**
  * Implements ICMPv6 Redirect packet format. (RFC 4861)
@@ -35,6 +32,9 @@
     protected byte[] targetAddress = new byte[Ip6Address.BYTE_LENGTH];
     protected byte[] destinationAddress = new byte[Ip6Address.BYTE_LENGTH];
 
+    private final NeighborDiscoveryOptions options =
+        new NeighborDiscoveryOptions();
+
     /**
      * Gets target address.
      *
@@ -51,7 +51,8 @@
      * @return this
      */
     public Redirect setTargetAddress(final byte[] targetAddress) {
-        this.targetAddress = Arrays.copyOfRange(targetAddress, 0, Ip6Address.BYTE_LENGTH);
+        this.targetAddress =
+            Arrays.copyOfRange(targetAddress, 0, Ip6Address.BYTE_LENGTH);
         return this;
     }
 
@@ -71,32 +72,52 @@
      * @return this
      */
     public Redirect setDestinationAddress(final byte[] destinationAddress) {
-        this.destinationAddress = Arrays.copyOfRange(destinationAddress, 0, Ip6Address.BYTE_LENGTH);
+        this.destinationAddress =
+            Arrays.copyOfRange(destinationAddress, 0, Ip6Address.BYTE_LENGTH);
+        return this;
+    }
+
+    /**
+     * Gets the Neighbor Discovery Protocol packet options.
+     *
+     * @return the Neighbor Discovery Protocol packet options
+     */
+    public List<NeighborDiscoveryOptions.Option> getOptions() {
+        return this.options.options();
+    }
+
+    /**
+     * Adds a Neighbor Discovery Protocol packet option.
+     *
+     * @param type the option type
+     * @param data the option data
+     * @return this
+     */
+    public Redirect addOption(final byte type, final byte[] data) {
+        this.options.addOption(type, data);
         return this;
     }
 
     @Override
     public byte[] serialize() {
-        byte[] payloadData = null;
-        if (this.payload != null) {
-            this.payload.setParent(this);
-            payloadData = this.payload.serialize();
+        byte[] optionsData = null;
+        if (this.options.hasOptions()) {
+            optionsData = this.options.serialize();
         }
 
-        int payloadLength = 0;
-        if (payloadData != null) {
-            payloadLength = payloadData.length;
+        int optionsLength = 0;
+        if (optionsData != null) {
+            optionsLength = optionsData.length;
         }
 
-        final byte[] data = new byte[HEADER_LENGTH + payloadLength];
+        final byte[] data = new byte[HEADER_LENGTH + optionsLength];
         final ByteBuffer bb = ByteBuffer.wrap(data);
 
         bb.putInt(0);
         bb.put(this.targetAddress, 0, Ip6Address.BYTE_LENGTH);
         bb.put(this.destinationAddress, 0, Ip6Address.BYTE_LENGTH);
-
-        if (payloadData != null) {
-            bb.put(payloadData);
+        if (optionsData != null) {
+            bb.put(optionsData);
         }
 
         return data;
@@ -110,10 +131,8 @@
         bb.get(this.targetAddress, 0, Ip6Address.BYTE_LENGTH);
         bb.get(this.destinationAddress, 0, Ip6Address.BYTE_LENGTH);
 
-        this.payload = new Data();
-        this.payload = this.payload.deserialize(data, bb.position(), bb.limit()
-                - bb.position());
-        this.payload.setParent(this);
+        this.options.deserialize(data, bb.position(),
+                                 bb.limit() - bb.position());
 
         return this;
     }
@@ -129,13 +148,14 @@
         int result = super.hashCode();
         ByteBuffer bb;
         bb = ByteBuffer.wrap(this.targetAddress);
-        for (int i = 0; i < 4; i++) {
+        for (int i = 0; i < this.targetAddress.length / 4; i++) {
             result = prime * result + bb.getInt();
         }
         bb = ByteBuffer.wrap(this.destinationAddress);
-        for (int i = 0; i < 4; i++) {
+        for (int i = 0; i < this.destinationAddress.length / 4; i++) {
             result = prime * result + bb.getInt();
         }
+        result = prime * result + this.options.hashCode();
         return result;
     }
 
@@ -159,7 +179,11 @@
         if (!Arrays.equals(this.targetAddress, other.targetAddress)) {
             return false;
         }
-        if (!Arrays.equals(this.destinationAddress, other.destinationAddress)) {
+        if (!Arrays.equals(this.destinationAddress,
+                           other.destinationAddress)) {
+            return false;
+        }
+        if (!this.options.equals(other.options)) {
             return false;
         }
         return true;
diff --git a/utils/misc/src/main/java/org/onlab/packet/ndp/RouterAdvertisement.java b/utils/misc/src/main/java/org/onlab/packet/ndp/RouterAdvertisement.java
index ce0c13b..1c2f928 100644
--- a/utils/misc/src/main/java/org/onlab/packet/ndp/RouterAdvertisement.java
+++ b/utils/misc/src/main/java/org/onlab/packet/ndp/RouterAdvertisement.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2014 Open Networking Laboratory
+ * Copyright 2014-2015 Open Networking Laboratory
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -13,16 +13,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-
-
 package org.onlab.packet.ndp;
 
 import org.onlab.packet.BasePacket;
-import org.onlab.packet.Data;
 import org.onlab.packet.IPacket;
 
 import java.nio.ByteBuffer;
+import java.util.List;
 
 /**
  * Implements ICMPv6 Router Advertisement packet format. (RFC 4861)
@@ -37,6 +34,9 @@
     protected int reachableTime;
     protected int retransmitTimer;
 
+    private final NeighborDiscoveryOptions options =
+        new NeighborDiscoveryOptions();
+
     /**
      * Gets current hop limit.
      *
@@ -157,20 +157,40 @@
         return this;
     }
 
+    /**
+     * Gets the Neighbor Discovery Protocol packet options.
+     *
+     * @return the Neighbor Discovery Protocol packet options
+     */
+    public List<NeighborDiscoveryOptions.Option> getOptions() {
+        return this.options.options();
+    }
+
+    /**
+     * Adds a Neighbor Discovery Protocol packet option.
+     *
+     * @param type the option type
+     * @param data the option data
+     * @return this
+     */
+    public RouterAdvertisement addOption(final byte type, final byte[] data) {
+        this.options.addOption(type, data);
+        return this;
+    }
+
     @Override
     public byte[] serialize() {
-        byte[] payloadData = null;
-        if (this.payload != null) {
-            this.payload.setParent(this);
-            payloadData = this.payload.serialize();
+        byte[] optionsData = null;
+        if (this.options.hasOptions()) {
+            optionsData = this.options.serialize();
         }
 
-        int payloadLength = 0;
-        if (payloadData != null) {
-            payloadLength = payloadData.length;
+        int optionsLength = 0;
+        if (optionsData != null) {
+            optionsLength = optionsData.length;
         }
 
-        final byte[] data = new byte[HEADER_LENGTH + payloadLength];
+        final byte[] data = new byte[HEADER_LENGTH + optionsLength];
         final ByteBuffer bb = ByteBuffer.wrap(data);
 
         bb.put(this.currentHopLimit);
@@ -179,8 +199,8 @@
         bb.putInt(reachableTime);
         bb.putInt(retransmitTimer);
 
-        if (payloadData != null) {
-            bb.put(payloadData);
+        if (optionsData != null) {
+            bb.put(optionsData);
         }
 
         return data;
@@ -199,10 +219,8 @@
         this.reachableTime = bb.getInt();
         this.retransmitTimer = bb.getInt();
 
-        this.payload = new Data();
-        this.payload = this.payload.deserialize(data, bb.position(), bb.limit()
-                - bb.position());
-        this.payload.setParent(this);
+        this.options.deserialize(data, bb.position(),
+                                 bb.limit() - bb.position());
 
         return this;
     }
@@ -222,6 +240,7 @@
         result = prime * result + this.routerLifetime;
         result = prime * result + this.reachableTime;
         result = prime * result + this.retransmitTimer;
+        result = prime * result + this.options.hashCode();
         return result;
     }
 
@@ -260,6 +279,9 @@
         if (this.retransmitTimer != other.retransmitTimer) {
             return false;
         }
+        if (!this.options.equals(other.options)) {
+            return false;
+        }
         return true;
     }
 }
diff --git a/utils/misc/src/main/java/org/onlab/packet/ndp/RouterSolicitation.java b/utils/misc/src/main/java/org/onlab/packet/ndp/RouterSolicitation.java
index 948b08a..3fddc5e 100644
--- a/utils/misc/src/main/java/org/onlab/packet/ndp/RouterSolicitation.java
+++ b/utils/misc/src/main/java/org/onlab/packet/ndp/RouterSolicitation.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2014 Open Networking Laboratory
+ * Copyright 2014-2015 Open Networking Laboratory
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -13,16 +13,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-
-
 package org.onlab.packet.ndp;
 
 import org.onlab.packet.BasePacket;
-import org.onlab.packet.Data;
 import org.onlab.packet.IPacket;
 
 import java.nio.ByteBuffer;
+import java.util.List;
 
 /**
  * Implements ICMPv6 Router Solicitation packet format. (RFC 4861)
@@ -30,26 +27,49 @@
 public class RouterSolicitation extends BasePacket {
     public static final byte HEADER_LENGTH = 4; // bytes
 
+    private final NeighborDiscoveryOptions options =
+        new NeighborDiscoveryOptions();
+
+    /**
+     * Gets the Neighbor Discovery Protocol packet options.
+     *
+     * @return the Neighbor Discovery Protocol packet options
+     */
+    public List<NeighborDiscoveryOptions.Option> getOptions() {
+        return this.options.options();
+    }
+
+    /**
+     * Adds a Neighbor Discovery Protocol packet option.
+     *
+     * @param type the option type
+     * @param data the option data
+     * @return this
+     */
+    public RouterSolicitation addOption(final byte type, final byte[] data) {
+        this.options.addOption(type, data);
+        return this;
+    }
+
     @Override
     public byte[] serialize() {
-        byte[] payloadData = null;
-        if (this.payload != null) {
-            this.payload.setParent(this);
-            payloadData = this.payload.serialize();
+        byte[] optionsData = null;
+        if (this.options.hasOptions()) {
+            optionsData = this.options.serialize();
         }
 
-        int payloadLength = 0;
-        if (payloadData != null) {
-            payloadLength = payloadData.length;
+        int optionsLength = 0;
+        if (optionsData != null) {
+            optionsLength = optionsData.length;
         }
 
-        final byte[] data = new byte[HEADER_LENGTH + payloadLength];
+        final byte[] data = new byte[HEADER_LENGTH + optionsLength];
         final ByteBuffer bb = ByteBuffer.wrap(data);
 
         bb.putInt(0);
 
-        if (payloadData != null) {
-            bb.put(payloadData);
+        if (optionsData != null) {
+            bb.put(optionsData);
         }
 
         return data;
@@ -61,10 +81,8 @@
 
         bb.getInt();
 
-        this.payload = new Data();
-        this.payload = this.payload.deserialize(data, bb.position(), bb.limit()
-                - bb.position());
-        this.payload.setParent(this);
+        this.options.deserialize(data, bb.position(),
+                                 bb.limit() - bb.position());
 
         return this;
     }
@@ -76,7 +94,10 @@
      */
     @Override
     public int hashCode() {
-        return super.hashCode();
+        final int prime = 5807;
+        int result = super.hashCode();
+        result = prime * result + this.options.hashCode();
+        return result;
     }
 
     /*
@@ -95,6 +116,10 @@
         if (!(obj instanceof RouterSolicitation)) {
             return false;
         }
+        final RouterSolicitation other = (RouterSolicitation) obj;
+        if (!this.options.equals(other.options)) {
+            return false;
+        }
         return true;
     }
 }