blob: 5334d54ec3604b8d86aadece027edba3634baa20 [file] [log] [blame]
Charles M.C. Chanea5aa472015-01-03 13:40:39 +08001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18
19package org.onlab.packet.ndp;
20
21import org.onlab.packet.BasePacket;
22import org.onlab.packet.Data;
23import org.onlab.packet.IPacket;
24
25import java.nio.ByteBuffer;
26
27/**
28 * Implements ICMPv6 Router Solicitation packet format. (RFC 4861)
29 */
30public class RouterSolicitation extends BasePacket {
31 public static final byte HEADER_LENGTH = 4; // bytes
32
33 @Override
34 public byte[] serialize() {
35 byte[] payloadData = null;
36 if (this.payload != null) {
37 this.payload.setParent(this);
38 payloadData = this.payload.serialize();
39 }
40
41 int payloadLength = payloadData == null ? 0 : (short) payloadData.length;
42
43 final byte[] data = new byte[HEADER_LENGTH + payloadLength];
44 final ByteBuffer bb = ByteBuffer.wrap(data);
45
46 bb.putInt(0);
47
48 if (payloadData != null) {
49 bb.put(payloadData);
50 }
51
52 return data;
53 }
54
55 @Override
56 public IPacket deserialize(byte[] data, int offset, int length) {
57 final ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
58
59 bb.getInt();
60
61 this.payload = new Data();
62 this.payload = this.payload.deserialize(data, bb.position(), bb.limit()
63 - bb.position());
64 this.payload.setParent(this);
65
66 return this;
67 }
68
69 /*
70 * (non-Javadoc)
71 *
72 * @see java.lang.Object#hashCode()
73 */
74 @Override
75 public int hashCode() {
76 return super.hashCode();
77 }
78
79 /*
80 * (non-Javadoc)
81 *
82 * @see java.lang.Object#equals(java.lang.Object)
83 */
84 @Override
85 public boolean equals(final Object obj) {
86 if (this == obj) {
87 return true;
88 }
89 if (!super.equals(obj)) {
90 return false;
91 }
92 if (!(obj instanceof RouterSolicitation)) {
93 return false;
94 }
95 return true;
96 }
97}