Jian Li
Committed by Gerrit Code Review

[ONOS-3222] Implement toString method for each Packet class

Change-Id: I17d72338d4202117d08b3dca9463be35a87a0c1e
Showing 61 changed files with 815 additions and 124 deletions
...@@ -14,18 +14,17 @@ ...@@ -14,18 +14,17 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -
18 -
19 package org.onlab.packet; 17 package org.onlab.packet;
20 18
21 import java.nio.ByteBuffer; 19 import java.nio.ByteBuffer;
22 import java.util.Arrays; 20 import java.util.Arrays;
23 21
24 -import static org.onlab.packet.PacketUtils.*; 22 +import static com.google.common.base.MoreObjects.toStringHelper;
23 +import static org.onlab.packet.PacketUtils.checkHeaderLength;
24 +import static org.onlab.packet.PacketUtils.checkInput;
25 25
26 /** 26 /**
27 - * 27 + * Representation of an ARP Packet.
28 - *
29 */ 28 */
30 public class ARP extends BasePacket { 29 public class ARP extends BasePacket {
31 public static final short HW_TYPE_ETHERNET = 0x1; 30 public static final short HW_TYPE_ETHERNET = 0x1;
...@@ -341,27 +340,6 @@ public class ARP extends BasePacket { ...@@ -341,27 +340,6 @@ public class ARP extends BasePacket {
341 return true; 340 return true;
342 } 341 }
343 342
344 - /*
345 - * (non-Javadoc)
346 - *
347 - * @see java.lang.Object#toString()
348 - */
349 - @Override
350 - public String toString() {
351 - return "ARP [hardwareType=" + this.hardwareType + ", protocolType="
352 - + this.protocolType + ", hardwareAddressLength="
353 - + this.hardwareAddressLength + ", protocolAddressLength="
354 - + this.protocolAddressLength + ", opCode=" + this.opCode
355 - + ", senderHardwareAddress="
356 - + Arrays.toString(this.senderHardwareAddress)
357 - + ", senderProtocolAddress="
358 - + Arrays.toString(this.senderProtocolAddress)
359 - + ", targetHardwareAddress="
360 - + Arrays.toString(this.targetHardwareAddress)
361 - + ", targetProtocolAddress="
362 - + Arrays.toString(this.targetProtocolAddress) + "]";
363 - }
364 -
365 /** 343 /**
366 * Builds an ARP reply based on a request. 344 * Builds an ARP reply based on a request.
367 * 345 *
...@@ -436,4 +414,18 @@ public class ARP extends BasePacket { ...@@ -436,4 +414,18 @@ public class ARP extends BasePacket {
436 }; 414 };
437 } 415 }
438 416
417 + @Override
418 + public String toString() {
419 + return toStringHelper(getClass())
420 + .add("hardwareType", Short.toString(hardwareType))
421 + .add("protocolType", Short.toString(protocolType))
422 + .add("hardwareAddressLength", Byte.toString(hardwareAddressLength))
423 + .add("protocolAddressLength", Byte.toString(protocolAddressLength))
424 + .add("opCode", Short.toString(opCode))
425 + .add("senderHardwareAddress", Arrays.toString(senderHardwareAddress))
426 + .add("senderProtocolAddress", Arrays.toString(senderProtocolAddress))
427 + .add("targetHardwareAddress", Arrays.toString(targetHardwareAddress))
428 + .add("targetProtocolAddress", Arrays.toString(targetProtocolAddress))
429 + .toString();
430 + }
439 } 431 }
......
...@@ -14,48 +14,32 @@ ...@@ -14,48 +14,32 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -
18 -
19 package org.onlab.packet; 17 package org.onlab.packet;
20 18
21 /** 19 /**
22 - * 20 + * Base packet class.
23 - *
24 */ 21 */
25 public abstract class BasePacket implements IPacket { 22 public abstract class BasePacket implements IPacket {
23 +
26 protected IPacket parent; 24 protected IPacket parent;
27 protected IPacket payload; 25 protected IPacket payload;
28 26
29 - /**
30 - * @return the parent
31 - */
32 @Override 27 @Override
33 public IPacket getParent() { 28 public IPacket getParent() {
34 return this.parent; 29 return this.parent;
35 } 30 }
36 31
37 - /**
38 - * @param parent
39 - * the parent to set
40 - */
41 @Override 32 @Override
42 public IPacket setParent(final IPacket parent) { 33 public IPacket setParent(final IPacket parent) {
43 this.parent = parent; 34 this.parent = parent;
44 return this; 35 return this;
45 } 36 }
46 37
47 - /**
48 - * @return the payload
49 - */
50 @Override 38 @Override
51 public IPacket getPayload() { 39 public IPacket getPayload() {
52 return this.payload; 40 return this.payload;
53 } 41 }
54 42
55 - /**
56 - * @param payload
57 - * the payload to set
58 - */
59 @Override 43 @Override
60 public IPacket setPayload(final IPacket payload) { 44 public IPacket setPayload(final IPacket payload) {
61 this.payload = payload; 45 this.payload = payload;
...@@ -69,11 +53,6 @@ public abstract class BasePacket implements IPacket { ...@@ -69,11 +53,6 @@ public abstract class BasePacket implements IPacket {
69 } 53 }
70 } 54 }
71 55
72 - /*
73 - * (non-Javadoc)
74 - *
75 - * @see java.lang.Object#hashCode()
76 - */
77 @Override 56 @Override
78 public int hashCode() { 57 public int hashCode() {
79 final int prime = 6733; 58 final int prime = 6733;
...@@ -83,11 +62,6 @@ public abstract class BasePacket implements IPacket { ...@@ -83,11 +62,6 @@ public abstract class BasePacket implements IPacket {
83 return result; 62 return result;
84 } 63 }
85 64
86 - /*
87 - * (non-Javadoc)
88 - *
89 - * @see java.lang.Object#equals(java.lang.Object)
90 - */
91 @Override 65 @Override
92 public boolean equals(final Object obj) { 66 public boolean equals(final Object obj) {
93 if (this == obj) { 67 if (this == obj) {
......
...@@ -21,14 +21,16 @@ package org.onlab.packet; ...@@ -21,14 +21,16 @@ package org.onlab.packet;
21 import java.io.UnsupportedEncodingException; 21 import java.io.UnsupportedEncodingException;
22 import java.nio.ByteBuffer; 22 import java.nio.ByteBuffer;
23 import java.util.ArrayList; 23 import java.util.ArrayList;
24 +import java.util.Arrays;
24 import java.util.List; 25 import java.util.List;
25 import java.util.ListIterator; 26 import java.util.ListIterator;
26 27
27 import static com.google.common.base.Preconditions.checkArgument; 28 import static com.google.common.base.Preconditions.checkArgument;
28 import static org.onlab.packet.PacketUtils.checkInput; 29 import static org.onlab.packet.PacketUtils.checkInput;
30 +import static com.google.common.base.MoreObjects.toStringHelper;
29 31
30 /** 32 /**
31 - * 33 + * Representation of an DHCP Packet.
32 */ 34 */
33 public class DHCP extends BasePacket { 35 public class DHCP extends BasePacket {
34 /** 36 /**
...@@ -629,4 +631,25 @@ public class DHCP extends BasePacket { ...@@ -629,4 +631,25 @@ public class DHCP extends BasePacket {
629 return dhcp; 631 return dhcp;
630 }; 632 };
631 } 633 }
634 +
635 + @Override
636 + public String toString() {
637 + return toStringHelper(getClass())
638 + .add("opCode", Byte.toString(opCode))
639 + .add("hardwareType", Byte.toString(hardwareType))
640 + .add("hardwareAddressLength", Byte.toString(hardwareAddressLength))
641 + .add("hops", Byte.toString(hops))
642 + .add("transactionId", Integer.toString(transactionId))
643 + .add("seconds", Short.toString(seconds))
644 + .add("flags", Short.toString(flags))
645 + .add("clientIPAddress", Integer.toString(clientIPAddress))
646 + .add("yourIPAddress", Integer.toString(yourIPAddress))
647 + .add("serverIPAddress", Integer.toString(serverIPAddress))
648 + .add("gatewayIPAddress", Integer.toString(gatewayIPAddress))
649 + .add("clientHardwareAddress", Arrays.toString(clientHardwareAddress))
650 + .add("serverName", serverName)
651 + .add("bootFileName", bootFileName)
652 + .toString();
653 + // TODO: need to handle options
654 + }
632 } 655 }
......
...@@ -14,14 +14,12 @@ ...@@ -14,14 +14,12 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -
18 -
19 package org.onlab.packet; 17 package org.onlab.packet;
20 18
21 import java.util.Arrays; 19 import java.util.Arrays;
22 20
23 /** 21 /**
24 - * 22 + * Representation of DHCPOption field.
25 */ 23 */
26 public class DHCPOption { 24 public class DHCPOption {
27 protected byte code; 25 protected byte code;
...@@ -36,8 +34,7 @@ public class DHCPOption { ...@@ -36,8 +34,7 @@ public class DHCPOption {
36 } 34 }
37 35
38 /** 36 /**
39 - * @param code 37 + * @param code the code to set
40 - * the code to set
41 * @return this 38 * @return this
42 */ 39 */
43 public DHCPOption setCode(final byte code) { 40 public DHCPOption setCode(final byte code) {
...@@ -53,8 +50,7 @@ public class DHCPOption { ...@@ -53,8 +50,7 @@ public class DHCPOption {
53 } 50 }
54 51
55 /** 52 /**
56 - * @param length 53 + * @param length the length to set
57 - * the length to set
58 * @return this 54 * @return this
59 */ 55 */
60 public DHCPOption setLength(final byte length) { 56 public DHCPOption setLength(final byte length) {
...@@ -70,8 +66,7 @@ public class DHCPOption { ...@@ -70,8 +66,7 @@ public class DHCPOption {
70 } 66 }
71 67
72 /** 68 /**
73 - * @param data 69 + * @param data the data to set
74 - * the data to set
75 * @return this 70 * @return this
76 */ 71 */
77 public DHCPOption setData(final byte[] data) { 72 public DHCPOption setData(final byte[] data) {
......
...@@ -20,6 +20,7 @@ package org.onlab.packet; ...@@ -20,6 +20,7 @@ package org.onlab.packet;
20 20
21 import java.util.Arrays; 21 import java.util.Arrays;
22 22
23 +import static com.google.common.base.MoreObjects.toStringHelper;
23 import static org.onlab.packet.PacketUtils.*; 24 import static org.onlab.packet.PacketUtils.*;
24 25
25 /** 26 /**
...@@ -129,4 +130,10 @@ public class Data extends BasePacket { ...@@ -129,4 +130,10 @@ public class Data extends BasePacket {
129 }; 130 };
130 } 131 }
131 132
133 + @Override
134 + public String toString() {
135 + return toStringHelper(getClass())
136 + .add("data", Arrays.toString(data))
137 + .toString();
138 + }
132 } 139 }
......
...@@ -19,7 +19,9 @@ ...@@ -19,7 +19,9 @@
19 package org.onlab.packet; 19 package org.onlab.packet;
20 20
21 import java.nio.ByteBuffer; 21 import java.nio.ByteBuffer;
22 +import java.util.Arrays;
22 23
24 +import static com.google.common.base.MoreObjects.toStringHelper;
23 import static org.onlab.packet.PacketUtils.checkHeaderLength; 25 import static org.onlab.packet.PacketUtils.checkHeaderLength;
24 import static org.onlab.packet.PacketUtils.checkInput; 26 import static org.onlab.packet.PacketUtils.checkInput;
25 27
...@@ -54,7 +56,6 @@ public class EAP extends BasePacket { ...@@ -54,7 +56,6 @@ public class EAP extends BasePacket {
54 protected byte type; 56 protected byte type;
55 protected byte[] data; 57 protected byte[] data;
56 58
57 -
58 /** 59 /**
59 * Gets the EAP code. 60 * Gets the EAP code.
60 * 61 *
...@@ -261,4 +262,15 @@ public class EAP extends BasePacket { ...@@ -261,4 +262,15 @@ public class EAP extends BasePacket {
261 result = prime * result + this.type; 262 result = prime * result + this.type;
262 return result; 263 return result;
263 } 264 }
265 +
266 + @Override
267 + public String toString() {
268 + return toStringHelper(getClass())
269 + .add("code", Byte.toString(code))
270 + .add("identifier", Byte.toString(identifier))
271 + .add("length", Short.toString(length))
272 + .add("type", Byte.toString(type))
273 + .add("data", Arrays.toString(data))
274 + .toString();
275 + }
264 } 276 }
......
...@@ -20,6 +20,7 @@ package org.onlab.packet; ...@@ -20,6 +20,7 @@ package org.onlab.packet;
20 20
21 import java.nio.ByteBuffer; 21 import java.nio.ByteBuffer;
22 22
23 +import static com.google.common.base.MoreObjects.toStringHelper;
23 import static org.onlab.packet.PacketUtils.checkHeaderLength; 24 import static org.onlab.packet.PacketUtils.checkHeaderLength;
24 import static org.onlab.packet.PacketUtils.checkInput; 25 import static org.onlab.packet.PacketUtils.checkInput;
25 26
...@@ -195,5 +196,14 @@ public class EAPOL extends BasePacket { ...@@ -195,5 +196,14 @@ public class EAPOL extends BasePacket {
195 196
196 return this; 197 return this;
197 } 198 }
199 +
200 + @Override
201 + public String toString() {
202 + return toStringHelper(getClass())
203 + .add("version", Byte.toString(version))
204 + .add("eapolType", Byte.toString(eapolType))
205 + .add("packetLength", Short.toString(packetLength))
206 + .toString();
207 + }
198 } 208 }
199 209
......
...@@ -34,7 +34,7 @@ import static org.onlab.packet.PacketUtils.checkHeaderLength; ...@@ -34,7 +34,7 @@ import static org.onlab.packet.PacketUtils.checkHeaderLength;
34 import static org.onlab.packet.PacketUtils.checkInput; 34 import static org.onlab.packet.PacketUtils.checkInput;
35 35
36 /** 36 /**
37 - * 37 + * Ethernet Packet.
38 */ 38 */
39 public class Ethernet extends BasePacket { 39 public class Ethernet extends BasePacket {
40 private static final String HEXES = "0123456789ABCDEF"; 40 private static final String HEXES = "0123456789ABCDEF";
...@@ -714,5 +714,4 @@ public class Ethernet extends BasePacket { ...@@ -714,5 +714,4 @@ public class Ethernet extends BasePacket {
714 return eth; 714 return eth;
715 }; 715 };
716 } 716 }
717 -
718 } 717 }
......
...@@ -15,16 +15,15 @@ ...@@ -15,16 +15,15 @@
15 */ 15 */
16 16
17 17
18 -
19 package org.onlab.packet; 18 package org.onlab.packet;
20 19
21 import java.nio.ByteBuffer; 20 import java.nio.ByteBuffer;
22 21
22 +import static com.google.common.base.MoreObjects.toStringHelper;
23 import static org.onlab.packet.PacketUtils.*; 23 import static org.onlab.packet.PacketUtils.*;
24 24
25 /** 25 /**
26 * Implements ICMP packet format. 26 * Implements ICMP packet format.
27 - *
28 */ 27 */
29 public class ICMP extends BasePacket { 28 public class ICMP extends BasePacket {
30 protected byte icmpType; 29 protected byte icmpType;
...@@ -45,8 +44,7 @@ public class ICMP extends BasePacket { ...@@ -45,8 +44,7 @@ public class ICMP extends BasePacket {
45 } 44 }
46 45
47 /** 46 /**
48 - * @param icmpType 47 + * @param icmpType to set
49 - * to set
50 * @return this 48 * @return this
51 */ 49 */
52 public ICMP setIcmpType(final byte icmpType) { 50 public ICMP setIcmpType(final byte icmpType) {
...@@ -62,8 +60,7 @@ public class ICMP extends BasePacket { ...@@ -62,8 +60,7 @@ public class ICMP extends BasePacket {
62 } 60 }
63 61
64 /** 62 /**
65 - * @param icmpCode 63 + * @param icmpCode code to set
66 - * code to set
67 * @return this 64 * @return this
68 */ 65 */
69 public ICMP setIcmpCode(final byte icmpCode) { 66 public ICMP setIcmpCode(final byte icmpCode) {
...@@ -79,8 +76,7 @@ public class ICMP extends BasePacket { ...@@ -79,8 +76,7 @@ public class ICMP extends BasePacket {
79 } 76 }
80 77
81 /** 78 /**
82 - * @param checksum 79 + * @param checksum the checksum to set
83 - * the checksum to set
84 * @return this 80 * @return this
85 */ 81 */
86 public ICMP setChecksum(final short checksum) { 82 public ICMP setChecksum(final short checksum) {
...@@ -220,4 +216,13 @@ public class ICMP extends BasePacket { ...@@ -220,4 +216,13 @@ public class ICMP extends BasePacket {
220 return icmp; 216 return icmp;
221 }; 217 };
222 } 218 }
219 +
220 + @Override
221 + public String toString() {
222 + return toStringHelper(getClass())
223 + .add("icmpType", Byte.toString(icmpType))
224 + .add("icmpCode", Byte.toString(icmpCode))
225 + .add("checksum", Short.toString(checksum))
226 + .toString();
227 + }
223 } 228 }
......
...@@ -29,6 +29,7 @@ import java.nio.ByteBuffer; ...@@ -29,6 +29,7 @@ import java.nio.ByteBuffer;
29 import java.util.HashMap; 29 import java.util.HashMap;
30 import java.util.Map; 30 import java.util.Map;
31 31
32 +import static com.google.common.base.MoreObjects.toStringHelper;
32 import static org.onlab.packet.PacketUtils.checkInput; 33 import static org.onlab.packet.PacketUtils.checkInput;
33 34
34 /** 35 /**
...@@ -363,4 +364,13 @@ public class ICMP6 extends BasePacket { ...@@ -363,4 +364,13 @@ public class ICMP6 extends BasePacket {
363 return icmp6; 364 return icmp6;
364 }; 365 };
365 } 366 }
367 +
368 + @Override
369 + public String toString() {
370 + return toStringHelper(getClass())
371 + .add("icmpType", Byte.toString(icmpType))
372 + .add("icmpCode", Byte.toString(icmpCode))
373 + .add("checksum", Short.toString(checksum))
374 + .toString();
375 + }
366 } 376 }
......
...@@ -15,16 +15,19 @@ ...@@ -15,16 +15,19 @@
15 */ 15 */
16 package org.onlab.packet; 16 package org.onlab.packet;
17 17
18 +import org.slf4j.Logger;
19 +
18 import java.nio.ByteBuffer; 20 import java.nio.ByteBuffer;
19 import java.util.ArrayList; 21 import java.util.ArrayList;
20 import java.util.HashMap; 22 import java.util.HashMap;
21 import java.util.List; 23 import java.util.List;
22 import java.util.Map; 24 import java.util.Map;
23 -import org.slf4j.Logger; 25 +import java.util.Arrays;
24 26
25 -import static org.slf4j.LoggerFactory.getLogger; 27 +import static com.google.common.base.MoreObjects.toStringHelper;
26 import static com.google.common.base.Preconditions.checkNotNull; 28 import static com.google.common.base.Preconditions.checkNotNull;
27 import static org.onlab.packet.PacketUtils.checkInput; 29 import static org.onlab.packet.PacketUtils.checkInput;
30 +import static org.slf4j.LoggerFactory.getLogger;
28 31
29 32
30 /** 33 /**
...@@ -332,4 +335,15 @@ public class IGMP extends BasePacket { ...@@ -332,4 +335,15 @@ public class IGMP extends BasePacket {
332 result = prime * result + this.groups.hashCode(); 335 result = prime * result + this.groups.hashCode();
333 return result; 336 return result;
334 } 337 }
338 +
339 + @Override
340 + public String toString() {
341 + return toStringHelper(getClass())
342 + .add("igmpType", Byte.toString(igmpType))
343 + .add("resField", Byte.toString(resField))
344 + .add("checksum", Short.toString(checksum))
345 + .add("unsupportTypeData", Arrays.toString(unsupportTypeData))
346 + .toString();
347 + // TODO: need to handle groups
348 + }
335 } 349 }
......
...@@ -95,4 +95,18 @@ public abstract class IGMPGroup { ...@@ -95,4 +95,18 @@ public abstract class IGMPGroup {
95 * @return The serialized message 95 * @return The serialized message
96 */ 96 */
97 public abstract byte[] serialize(ByteBuffer bb); 97 public abstract byte[] serialize(ByteBuffer bb);
98 +
99 + @Override
100 + public String toString() {
101 + StringBuilder sb = new StringBuilder();
102 + sb.append("[");
103 + sb.append("auxInfo= ");
104 + sb.append(auxInfo);
105 + sb.append("gaddr= ");
106 + sb.append(gaddr);
107 + sb.append("sources= ");
108 + sb.append(sources.toString());
109 + sb.append("]");
110 + return sb.toString();
111 + }
98 } 112 }
......
1 /* 1 /*
2 - * Copyright 2014 Open Networking Laboratory 2 + * Copyright 2015 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -14,21 +14,22 @@ ...@@ -14,21 +14,22 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -
18 -
19 package org.onlab.packet; 17 package org.onlab.packet;
20 18
21 /** 19 /**
22 - * 20 + * Packet Interface.
23 */ 21 */
24 public interface IPacket { 22 public interface IPacket {
23 +
25 /** 24 /**
25 + * Obtain the packet payload.
26 * 26 *
27 * @return the payload 27 * @return the payload
28 */ 28 */
29 IPacket getPayload(); 29 IPacket getPayload();
30 30
31 /** 31 /**
32 + * Assign the packet payload.
32 * 33 *
33 * @param packet new payload 34 * @param packet new payload
34 * @return self 35 * @return self
...@@ -36,12 +37,14 @@ public interface IPacket { ...@@ -36,12 +37,14 @@ public interface IPacket {
36 IPacket setPayload(IPacket packet); 37 IPacket setPayload(IPacket packet);
37 38
38 /** 39 /**
40 + * Obtain the parent packet.
39 * 41 *
40 * @return parent packet 42 * @return parent packet
41 */ 43 */
42 IPacket getParent(); 44 IPacket getParent();
43 45
44 /** 46 /**
47 + * Configure a new parent packet.
45 * 48 *
46 * @param packet new parent 49 * @param packet new parent
47 * @return self 50 * @return self
...@@ -49,7 +52,7 @@ public interface IPacket { ...@@ -49,7 +52,7 @@ public interface IPacket {
49 IPacket setParent(IPacket packet); 52 IPacket setParent(IPacket packet);
50 53
51 /** 54 /**
52 - * Reset any checksums as needed, and call resetChecksum on all parents. 55 + * Reset any checksum as needed, and call resetChecksum on all parents.
53 */ 56 */
54 void resetChecksum(); 57 void resetChecksum();
55 58
...@@ -62,7 +65,7 @@ public interface IPacket { ...@@ -62,7 +65,7 @@ public interface IPacket {
62 byte[] serialize(); 65 byte[] serialize();
63 66
64 /** 67 /**
65 - * Deserializes this packet layer and all possible payloads. 68 + * Deserialize this packet layer and all possible payloads.
66 * 69 *
67 * NOTE: This method has been deprecated and will be removed in a future 70 * NOTE: This method has been deprecated and will be removed in a future
68 * release. It is now recommended to use the Deserializer function provided 71 * release. It is now recommended to use the Deserializer function provided
......
...@@ -25,10 +25,11 @@ import java.util.Collection; ...@@ -25,10 +25,11 @@ import java.util.Collection;
25 import java.util.HashMap; 25 import java.util.HashMap;
26 import java.util.Map; 26 import java.util.Map;
27 27
28 +import static com.google.common.base.MoreObjects.toStringHelper;
28 import static org.onlab.packet.PacketUtils.*; 29 import static org.onlab.packet.PacketUtils.*;
29 30
30 /** 31 /**
31 - * 32 + * Implements IPv4 packet format.
32 */ 33 */
33 public class IPv4 extends BasePacket { 34 public class IPv4 extends BasePacket {
34 public static final byte PROTOCOL_ICMP = 0x1; 35 public static final byte PROTOCOL_ICMP = 0x1;
...@@ -730,4 +731,24 @@ s */ ...@@ -730,4 +731,24 @@ s */
730 return ipv4; 731 return ipv4;
731 }; 732 };
732 } 733 }
734 +
735 + @Override
736 + public String toString() {
737 + return toStringHelper(getClass())
738 + .add("version", Byte.toString(version))
739 + .add("headerLength", Byte.toString(headerLength))
740 + .add("diffServ", Byte.toString(diffServ))
741 + .add("totalLength", Short.toString(totalLength))
742 + .add("identification", Short.toString(identification))
743 + .add("flags", Byte.toString(flags))
744 + .add("fragmentOffset", Short.toString(fragmentOffset))
745 + .add("ttl", Byte.toString(ttl))
746 + .add("protocol", Byte.toString(protocol))
747 + .add("checksum", Short.toString(checksum))
748 + .add("sourceAddress", Integer.toString(sourceAddress))
749 + .add("destinationAddress", Integer.toString(destinationAddress))
750 + .add("options", Arrays.toString(options))
751 + .add("isTruncated", Boolean.toString(isTruncated))
752 + .toString();
753 + }
733 } 754 }
......
...@@ -31,6 +31,7 @@ import java.util.Arrays; ...@@ -31,6 +31,7 @@ import java.util.Arrays;
31 import java.util.HashMap; 31 import java.util.HashMap;
32 import java.util.Map; 32 import java.util.Map;
33 33
34 +import static com.google.common.base.MoreObjects.toStringHelper;
34 import static org.onlab.packet.PacketUtils.checkInput; 35 import static org.onlab.packet.PacketUtils.checkInput;
35 36
36 /** 37 /**
...@@ -381,4 +382,18 @@ public class IPv6 extends BasePacket implements IExtensionHeader { ...@@ -381,4 +382,18 @@ public class IPv6 extends BasePacket implements IExtensionHeader {
381 return ipv6; 382 return ipv6;
382 }; 383 };
383 } 384 }
385 +
386 + @Override
387 + public String toString() {
388 + return toStringHelper(getClass())
389 + .add("version", Byte.toString(version))
390 + .add("trafficClass", Byte.toString(trafficClass))
391 + .add("flowLabel", Integer.toString(flowLabel))
392 + .add("payloadLength", Short.toString(payloadLength))
393 + .add("nextHeader", Byte.toString(nextHeader))
394 + .add("hopLimit", Byte.toString(hopLimit))
395 + .add("sourceAddress", Arrays.toString(sourceAddress))
396 + .add("destinationAddress", Arrays.toString(destinationAddress))
397 + .toString();
398 + }
384 } 399 }
......
...@@ -20,13 +20,12 @@ package org.onlab.packet; ...@@ -20,13 +20,12 @@ package org.onlab.packet;
20 20
21 import java.nio.ByteBuffer; 21 import java.nio.ByteBuffer;
22 22
23 +import static com.google.common.base.MoreObjects.toStringHelper;
23 import static org.onlab.packet.PacketUtils.*; 24 import static org.onlab.packet.PacketUtils.*;
24 25
25 /** 26 /**
26 * This class represents an Link Local Control header that is used in Ethernet 27 * This class represents an Link Local Control header that is used in Ethernet
27 * 802.3. 28 * 802.3.
28 - *
29 - *
30 */ 29 */
31 public class LLC extends BasePacket { 30 public class LLC extends BasePacket {
32 31
...@@ -99,4 +98,13 @@ public class LLC extends BasePacket { ...@@ -99,4 +98,13 @@ public class LLC extends BasePacket {
99 return llc; 98 return llc;
100 }; 99 };
101 } 100 }
101 +
102 + @Override
103 + public String toString() {
104 + return toStringHelper(getClass())
105 + .add("dsap", Byte.toString(dsap))
106 + .add("ssap", Byte.toString(ssap))
107 + .add("ctrl", Byte.toString(ctrl))
108 + .toString();
109 + }
102 } 110 }
......
...@@ -20,13 +20,15 @@ ...@@ -20,13 +20,15 @@
20 package org.onlab.packet; 20 package org.onlab.packet;
21 21
22 import java.nio.ByteBuffer; 22 import java.nio.ByteBuffer;
23 +import java.util.Arrays;
23 import java.util.LinkedList; 24 import java.util.LinkedList;
24 import java.util.List; 25 import java.util.List;
25 26
27 +import static com.google.common.base.MoreObjects.toStringHelper;
26 import static org.onlab.packet.PacketUtils.*; 28 import static org.onlab.packet.PacketUtils.*;
27 29
28 /** 30 /**
29 - * 31 + * Representation of an LLDP Packet.
30 */ 32 */
31 public class LLDP extends BasePacket { 33 public class LLDP extends BasePacket {
32 public static final byte CHASSIS_TLV_TYPE = 1; 34 public static final byte CHASSIS_TLV_TYPE = 1;
...@@ -59,8 +61,7 @@ public class LLDP extends BasePacket { ...@@ -59,8 +61,7 @@ public class LLDP extends BasePacket {
59 } 61 }
60 62
61 /** 63 /**
62 - * @param chassis 64 + * @param chassis the chassisId to set
63 - * the chassisId to set
64 * @return this 65 * @return this
65 */ 66 */
66 public LLDP setChassisId(final LLDPTLV chassis) { 67 public LLDP setChassisId(final LLDPTLV chassis) {
...@@ -76,8 +77,7 @@ public class LLDP extends BasePacket { ...@@ -76,8 +77,7 @@ public class LLDP extends BasePacket {
76 } 77 }
77 78
78 /** 79 /**
79 - * @param portId 80 + * @param portId the portId to set
80 - * the portId to set
81 * @return this 81 * @return this
82 */ 82 */
83 public LLDP setPortId(final LLDPTLV portId) { 83 public LLDP setPortId(final LLDPTLV portId) {
...@@ -93,8 +93,7 @@ public class LLDP extends BasePacket { ...@@ -93,8 +93,7 @@ public class LLDP extends BasePacket {
93 } 93 }
94 94
95 /** 95 /**
96 - * @param ttl 96 + * @param ttl the ttl to set
97 - * the ttl to set
98 * @return this 97 * @return this
99 */ 98 */
100 public LLDP setTtl(final LLDPTLV ttl) { 99 public LLDP setTtl(final LLDPTLV ttl) {
...@@ -110,8 +109,7 @@ public class LLDP extends BasePacket { ...@@ -110,8 +109,7 @@ public class LLDP extends BasePacket {
110 } 109 }
111 110
112 /** 111 /**
113 - * @param optionalTLVList 112 + * @param optionalTLVList the optionalTLVList to set
114 - * the optionalTLVList to set
115 * @return this 113 * @return this
116 */ 114 */
117 public LLDP setOptionalTLVList(final List<LLDPTLV> optionalTLVList) { 115 public LLDP setOptionalTLVList(final List<LLDPTLV> optionalTLVList) {
...@@ -297,4 +295,15 @@ public class LLDP extends BasePacket { ...@@ -297,4 +295,15 @@ public class LLDP extends BasePacket {
297 }; 295 };
298 } 296 }
299 297
298 + @Override
299 + public String toString() {
300 + return toStringHelper(getClass())
301 + .add("chassisId", Arrays.toString(chassisId.getValue()))
302 + .add("portId", Arrays.toString(portId.getValue()))
303 + .add("ttl", Arrays.toString(ttl.getValue()))
304 + .add("ethType", Short.toString(ethType))
305 + .toString();
306 +
307 + // TODO: need to handle optionalTLVList
308 + }
300 } 309 }
......
...@@ -30,6 +30,20 @@ public class LLDPTLV { ...@@ -30,6 +30,20 @@ public class LLDPTLV {
30 protected short length; 30 protected short length;
31 protected byte[] value; 31 protected byte[] value;
32 32
33 + @Override
34 + public String toString() {
35 + StringBuilder sb = new StringBuilder();
36 + sb.append("[");
37 + sb.append("type= ");
38 + sb.append(type);
39 + sb.append("length= ");
40 + sb.append(length);
41 + sb.append("value= ");
42 + sb.append(Arrays.toString(value));
43 + sb.append("]");
44 + return sb.toString();
45 + }
46 +
33 /** 47 /**
34 * @return the type 48 * @return the type
35 */ 49 */
......
...@@ -19,8 +19,12 @@ import java.nio.ByteBuffer; ...@@ -19,8 +19,12 @@ import java.nio.ByteBuffer;
19 import java.util.HashMap; 19 import java.util.HashMap;
20 import java.util.Map; 20 import java.util.Map;
21 21
22 +import static com.google.common.base.MoreObjects.toStringHelper;
22 import static org.onlab.packet.PacketUtils.checkInput; 23 import static org.onlab.packet.PacketUtils.checkInput;
23 24
25 +/**
26 + * Representation of an MPLS Packet.
27 + */
24 public class MPLS extends BasePacket { 28 public class MPLS extends BasePacket {
25 public static final int HEADER_LENGTH = 4; 29 public static final int HEADER_LENGTH = 4;
26 30
...@@ -159,4 +163,14 @@ public class MPLS extends BasePacket { ...@@ -159,4 +163,14 @@ public class MPLS extends BasePacket {
159 return mpls; 163 return mpls;
160 }; 164 };
161 } 165 }
166 +
167 + @Override
168 + public String toString() {
169 + return toStringHelper(getClass())
170 + .add("label", Integer.toString(label))
171 + .add("bos", Byte.toString(bos))
172 + .add("ttl", Byte.toString(ttl))
173 + .add("protocol", Byte.toString(protocol))
174 + .toString();
175 + }
162 } 176 }
......
...@@ -177,9 +177,4 @@ public class ONOSLLDP extends LLDP { ...@@ -177,9 +177,4 @@ public class ONOSLLDP extends LLDP {
177 } 177 }
178 return null; 178 return null;
179 } 179 }
180 -
181 -
182 -
183 -
184 -
185 } 180 }
......
...@@ -22,6 +22,7 @@ import java.nio.ByteBuffer; ...@@ -22,6 +22,7 @@ import java.nio.ByteBuffer;
22 import java.util.HashMap; 22 import java.util.HashMap;
23 import java.util.Map; 23 import java.util.Map;
24 24
25 +import static com.google.common.base.MoreObjects.toStringHelper;
25 import static org.onlab.packet.PacketUtils.checkInput; 26 import static org.onlab.packet.PacketUtils.checkInput;
26 27
27 /** 28 /**
...@@ -296,4 +297,14 @@ public class PIM extends BasePacket { ...@@ -296,4 +297,14 @@ public class PIM extends BasePacket {
296 return pim; 297 return pim;
297 }; 298 };
298 } 299 }
300 +
301 + @Override
302 + public String toString() {
303 + return toStringHelper(getClass())
304 + .add("version", Byte.toString(version))
305 + .add("type", Byte.toString(type))
306 + .add("reserved", Byte.toString(reserved))
307 + .add("checksum", Short.toString(reserved))
308 + .toString();
309 + }
299 } 310 }
......
...@@ -30,6 +30,7 @@ import java.util.ArrayList; ...@@ -30,6 +30,7 @@ import java.util.ArrayList;
30 import java.util.Arrays; 30 import java.util.Arrays;
31 import java.util.List; 31 import java.util.List;
32 32
33 +import static com.google.common.base.MoreObjects.toStringHelper;
33 import static org.onlab.packet.PacketUtils.checkHeaderLength; 34 import static org.onlab.packet.PacketUtils.checkHeaderLength;
34 import static org.onlab.packet.PacketUtils.checkInput; 35 import static org.onlab.packet.PacketUtils.checkInput;
35 import static org.slf4j.LoggerFactory.getLogger; 36 import static org.slf4j.LoggerFactory.getLogger;
...@@ -420,4 +421,15 @@ public class RADIUS extends BasePacket { ...@@ -420,4 +421,15 @@ public class RADIUS extends BasePacket {
420 return this; 421 return this;
421 } 422 }
422 423
424 + @Override
425 + public String toString() {
426 + return toStringHelper(getClass())
427 + .add("code", Byte.toString(code))
428 + .add("identifier", Byte.toString(identifier))
429 + .add("length", Short.toString(length))
430 + .add("authenticator", Arrays.toString(authenticator))
431 + .toString();
432 +
433 + // TODO: need to handle attributes
434 + }
423 } 435 }
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
18 18
19 package org.onlab.packet; 19 package org.onlab.packet;
20 20
21 +import java.util.Arrays;
22 +
21 /** 23 /**
22 * An attribute in a RADIUS packet. 24 * An attribute in a RADIUS packet.
23 */ 25 */
...@@ -139,4 +141,17 @@ public class RADIUSAttribute { ...@@ -139,4 +141,17 @@ public class RADIUSAttribute {
139 return this; 141 return this;
140 } 142 }
141 143
144 + @Override
145 + public String toString() {
146 + StringBuilder sb = new StringBuilder();
147 + sb.append("[");
148 + sb.append("type= ");
149 + sb.append(type);
150 + sb.append("length= ");
151 + sb.append(length);
152 + sb.append("value= ");
153 + sb.append(Arrays.toString(value));
154 + sb.append("]");
155 + return sb.toString();
156 + }
142 } 157 }
......
...@@ -21,6 +21,7 @@ package org.onlab.packet; ...@@ -21,6 +21,7 @@ package org.onlab.packet;
21 import java.nio.ByteBuffer; 21 import java.nio.ByteBuffer;
22 import java.util.Arrays; 22 import java.util.Arrays;
23 23
24 +import static com.google.common.base.MoreObjects.toStringHelper;
24 import static org.onlab.packet.PacketUtils.*; 25 import static org.onlab.packet.PacketUtils.*;
25 26
26 /** 27 /**
...@@ -459,4 +460,20 @@ public class TCP extends BasePacket { ...@@ -459,4 +460,20 @@ public class TCP extends BasePacket {
459 return tcp; 460 return tcp;
460 }; 461 };
461 } 462 }
463 +
464 + @Override
465 + public String toString() {
466 + return toStringHelper(getClass())
467 + .add("sourcePort", Integer.toString(sourcePort))
468 + .add("destinationPort", Integer.toString(destinationPort))
469 + .add("sequence", Integer.toString(sequence))
470 + .add("acknowledge", Integer.toString(acknowledge))
471 + .add("dataOffset", Byte.toString(dataOffset))
472 + .add("flags", Short.toString(flags))
473 + .add("windowSize", Short.toString(windowSize))
474 + .add("checksum", Short.toString(checksum))
475 + .add("urgentPointer", Short.toString(urgentPointer))
476 + .add("options", Arrays.toString(options))
477 + .toString();
478 + }
462 } 479 }
......
...@@ -22,6 +22,7 @@ import java.nio.ByteBuffer; ...@@ -22,6 +22,7 @@ import java.nio.ByteBuffer;
22 import java.util.HashMap; 22 import java.util.HashMap;
23 import java.util.Map; 23 import java.util.Map;
24 24
25 +import static com.google.common.base.MoreObjects.toStringHelper;
25 import static org.onlab.packet.PacketUtils.*; 26 import static org.onlab.packet.PacketUtils.*;
26 27
27 /** 28 /**
...@@ -303,4 +304,14 @@ public class UDP extends BasePacket { ...@@ -303,4 +304,14 @@ public class UDP extends BasePacket {
303 return udp; 304 return udp;
304 }; 305 };
305 } 306 }
307 +
308 + @Override
309 + public String toString() {
310 + return toStringHelper(getClass())
311 + .add("sourcePort", Integer.toString(sourcePort))
312 + .add("destinationPort", Integer.toString(destinationPort))
313 + .add("length", Short.toString(length))
314 + .add("checksum", Short.toString(checksum))
315 + .toString();
316 + }
306 } 317 }
......
...@@ -26,6 +26,7 @@ import org.onlab.packet.IPv6; ...@@ -26,6 +26,7 @@ import org.onlab.packet.IPv6;
26 import java.nio.ByteBuffer; 26 import java.nio.ByteBuffer;
27 import java.util.Arrays; 27 import java.util.Arrays;
28 28
29 +import static com.google.common.base.MoreObjects.toStringHelper;
29 import static org.onlab.packet.PacketUtils.checkInput; 30 import static org.onlab.packet.PacketUtils.checkInput;
30 31
31 /** 32 /**
...@@ -297,4 +298,15 @@ public class Authentication extends BasePacket implements IExtensionHeader { ...@@ -297,4 +298,15 @@ public class Authentication extends BasePacket implements IExtensionHeader {
297 return authentication; 298 return authentication;
298 }; 299 };
299 } 300 }
301 +
302 + @Override
303 + public String toString() {
304 + return toStringHelper(getClass())
305 + .add("nextHeader", Byte.toString(nextHeader))
306 + .add("payloadLength", Byte.toString(payloadLength))
307 + .add("securityParamIndex", Integer.toString(securityParamIndex))
308 + .add("sequence", Integer.toString(sequence))
309 + .add("integrityCheck", Arrays.toString(integrityCheck))
310 + .toString();
311 + }
300 } 312 }
......
...@@ -26,6 +26,7 @@ import org.onlab.packet.IPv6; ...@@ -26,6 +26,7 @@ import org.onlab.packet.IPv6;
26 import java.nio.ByteBuffer; 26 import java.nio.ByteBuffer;
27 import java.util.Arrays; 27 import java.util.Arrays;
28 28
29 +import static com.google.common.base.MoreObjects.toStringHelper;
29 import static org.onlab.packet.PacketUtils.checkHeaderLength; 30 import static org.onlab.packet.PacketUtils.checkHeaderLength;
30 import static org.onlab.packet.PacketUtils.checkInput; 31 import static org.onlab.packet.PacketUtils.checkInput;
31 32
...@@ -257,4 +258,14 @@ public class BaseOptions extends BasePacket implements IExtensionHeader { ...@@ -257,4 +258,14 @@ public class BaseOptions extends BasePacket implements IExtensionHeader {
257 return baseOptions; 258 return baseOptions;
258 }; 259 };
259 } 260 }
261 +
262 + @Override
263 + public String toString() {
264 + return toStringHelper(getClass())
265 + .add("nextHeader", Byte.toString(nextHeader))
266 + .add("headerExtLength", Byte.toString(headerExtLength))
267 + .add("options", Arrays.toString(options))
268 + .add("type", Short.toString(type))
269 + .toString();
270 + }
260 } 271 }
......
...@@ -24,6 +24,7 @@ import org.onlab.packet.IPv6; ...@@ -24,6 +24,7 @@ import org.onlab.packet.IPv6;
24 24
25 import java.nio.ByteBuffer; 25 import java.nio.ByteBuffer;
26 26
27 +import static com.google.common.base.MoreObjects.toStringHelper;
27 import static org.onlab.packet.PacketUtils.checkInput; 28 import static org.onlab.packet.PacketUtils.checkInput;
28 29
29 /** 30 /**
...@@ -185,4 +186,12 @@ public class EncapSecurityPayload extends BasePacket { ...@@ -185,4 +186,12 @@ public class EncapSecurityPayload extends BasePacket {
185 return encapSecurityPayload; 186 return encapSecurityPayload;
186 }; 187 };
187 } 188 }
189 +
190 + @Override
191 + public String toString() {
192 + return toStringHelper(getClass())
193 + .add("securityParamIndex", Integer.toString(securityParamIndex))
194 + .add("sequence", Integer.toString(sequence))
195 + .toString();
196 + }
188 } 197 }
......
...@@ -25,6 +25,7 @@ import org.onlab.packet.IPv6; ...@@ -25,6 +25,7 @@ import org.onlab.packet.IPv6;
25 25
26 import java.nio.ByteBuffer; 26 import java.nio.ByteBuffer;
27 27
28 +import static com.google.common.base.MoreObjects.toStringHelper;
28 import static org.onlab.packet.PacketUtils.checkInput; 29 import static org.onlab.packet.PacketUtils.checkInput;
29 30
30 /** 31 /**
...@@ -250,4 +251,14 @@ public class Fragment extends BasePacket implements IExtensionHeader { ...@@ -250,4 +251,14 @@ public class Fragment extends BasePacket implements IExtensionHeader {
250 return fragment; 251 return fragment;
251 }; 252 };
252 } 253 }
254 +
255 + @Override
256 + public String toString() {
257 + return toStringHelper(getClass())
258 + .add("nextHeader", Byte.toString(nextHeader))
259 + .add("fragmentOffset", Short.toString(fragmentOffset))
260 + .add("moreFragment", Byte.toString(moreFragment))
261 + .add("identification", Integer.toString(identification))
262 + .toString();
263 + }
253 } 264 }
......
...@@ -26,6 +26,7 @@ import org.onlab.packet.IPv6; ...@@ -26,6 +26,7 @@ import org.onlab.packet.IPv6;
26 import java.nio.ByteBuffer; 26 import java.nio.ByteBuffer;
27 import java.util.Arrays; 27 import java.util.Arrays;
28 28
29 +import static com.google.common.base.MoreObjects.toStringHelper;
29 import static org.onlab.packet.PacketUtils.checkHeaderLength; 30 import static org.onlab.packet.PacketUtils.checkHeaderLength;
30 import static org.onlab.packet.PacketUtils.checkInput; 31 import static org.onlab.packet.PacketUtils.checkInput;
31 32
...@@ -288,4 +289,15 @@ public class Routing extends BasePacket implements IExtensionHeader { ...@@ -288,4 +289,15 @@ public class Routing extends BasePacket implements IExtensionHeader {
288 return routing; 289 return routing;
289 }; 290 };
290 } 291 }
292 +
293 + @Override
294 + public String toString() {
295 + return toStringHelper(getClass())
296 + .add("nextHeader", Byte.toString(nextHeader))
297 + .add("headerExtLength", Byte.toString(headerExtLength))
298 + .add("routingType", Byte.toString(routingType))
299 + .add("segmentsLeft", Byte.toString(segmentsLeft))
300 + .add("routingData", Arrays.toString(routingData))
301 + .toString();
302 + }
291 } 303 }
......
...@@ -24,6 +24,7 @@ import java.nio.ByteBuffer; ...@@ -24,6 +24,7 @@ import java.nio.ByteBuffer;
24 import java.util.Arrays; 24 import java.util.Arrays;
25 import java.util.List; 25 import java.util.List;
26 26
27 +import static com.google.common.base.MoreObjects.toStringHelper;
27 import static org.onlab.packet.PacketUtils.checkInput; 28 import static org.onlab.packet.PacketUtils.checkInput;
28 29
29 /** 30 /**
...@@ -275,4 +276,14 @@ public class NeighborAdvertisement extends BasePacket { ...@@ -275,4 +276,14 @@ public class NeighborAdvertisement extends BasePacket {
275 return neighborAdvertisement; 276 return neighborAdvertisement;
276 }; 277 };
277 } 278 }
279 +
280 + @Override
281 + public String toString() {
282 + return toStringHelper(getClass())
283 + .add("routerFlag", Byte.toString(routerFlag))
284 + .add("solicitedFlag", Byte.toString(solicitedFlag))
285 + .add("overrideFlag", Byte.toString(overrideFlag))
286 + .add("targetAddress", Arrays.toString(targetAddress))
287 + .toString();
288 + }
278 } 289 }
......
...@@ -25,6 +25,7 @@ import java.util.ArrayList; ...@@ -25,6 +25,7 @@ import java.util.ArrayList;
25 import java.util.Arrays; 25 import java.util.Arrays;
26 import java.util.List; 26 import java.util.List;
27 27
28 +import static com.google.common.base.MoreObjects.toStringHelper;
28 import static org.onlab.packet.PacketUtils.checkInput; 29 import static org.onlab.packet.PacketUtils.checkInput;
29 30
30 /** 31 /**
...@@ -117,6 +118,18 @@ public class NeighborDiscoveryOptions extends BasePacket { ...@@ -117,6 +118,18 @@ public class NeighborDiscoveryOptions extends BasePacket {
117 private int optionWireLength() { 118 private int optionWireLength() {
118 return 8 * optionLengthField(); 119 return 8 * optionLengthField();
119 } 120 }
121 +
122 + @Override
123 + public String toString() {
124 + StringBuilder sb = new StringBuilder();
125 + sb.append("[");
126 + sb.append("type= ");
127 + sb.append(type);
128 + sb.append("data= ");
129 + sb.append(data);
130 + sb.append("]");
131 + return sb.toString();
132 + }
120 } 133 }
121 134
122 /** 135 /**
...@@ -278,4 +291,11 @@ public class NeighborDiscoveryOptions extends BasePacket { ...@@ -278,4 +291,11 @@ public class NeighborDiscoveryOptions extends BasePacket {
278 return ndo; 291 return ndo;
279 }; 292 };
280 } 293 }
294 +
295 + @Override
296 + public String toString() {
297 + return toStringHelper(getClass())
298 + .toString();
299 + // TODO: need to handle options
300 + }
281 } 301 }
......
...@@ -24,6 +24,7 @@ import java.nio.ByteBuffer; ...@@ -24,6 +24,7 @@ import java.nio.ByteBuffer;
24 import java.util.Arrays; 24 import java.util.Arrays;
25 import java.util.List; 25 import java.util.List;
26 26
27 +import static com.google.common.base.MoreObjects.toStringHelper;
27 import static org.onlab.packet.PacketUtils.checkInput; 28 import static org.onlab.packet.PacketUtils.checkInput;
28 29
29 /** 30 /**
...@@ -189,4 +190,12 @@ public class NeighborSolicitation extends BasePacket { ...@@ -189,4 +190,12 @@ public class NeighborSolicitation extends BasePacket {
189 return neighborSolicitation; 190 return neighborSolicitation;
190 }; 191 };
191 } 192 }
193 +
194 + @Override
195 + public String toString() {
196 + return toStringHelper(getClass())
197 + .add("targetAddress", Arrays.toString(targetAddress))
198 + .toString();
199 + // TODO: need to handle options
200 + }
192 } 201 }
......
...@@ -24,6 +24,7 @@ import java.nio.ByteBuffer; ...@@ -24,6 +24,7 @@ import java.nio.ByteBuffer;
24 import java.util.Arrays; 24 import java.util.Arrays;
25 import java.util.List; 25 import java.util.List;
26 26
27 +import static com.google.common.base.MoreObjects.toStringHelper;
27 import static org.onlab.packet.PacketUtils.checkInput; 28 import static org.onlab.packet.PacketUtils.checkInput;
28 29
29 /** 30 /**
...@@ -222,4 +223,12 @@ public class Redirect extends BasePacket { ...@@ -222,4 +223,12 @@ public class Redirect extends BasePacket {
222 return redirect; 223 return redirect;
223 }; 224 };
224 } 225 }
226 +
227 + @Override
228 + public String toString() {
229 + return toStringHelper(getClass())
230 + .add("targetAddress", Arrays.toString(targetAddress))
231 + .add("destinationAddress", Arrays.toString(destinationAddress))
232 + .toString();
233 + }
225 } 234 }
......
...@@ -22,6 +22,7 @@ import org.onlab.packet.IPacket; ...@@ -22,6 +22,7 @@ import org.onlab.packet.IPacket;
22 import java.nio.ByteBuffer; 22 import java.nio.ByteBuffer;
23 import java.util.List; 23 import java.util.List;
24 24
25 +import static com.google.common.base.MoreObjects.toStringHelper;
25 import static org.onlab.packet.PacketUtils.checkInput; 26 import static org.onlab.packet.PacketUtils.checkInput;
26 27
27 /** 28 /**
...@@ -322,4 +323,17 @@ public class RouterAdvertisement extends BasePacket { ...@@ -322,4 +323,17 @@ public class RouterAdvertisement extends BasePacket {
322 return routerAdvertisement; 323 return routerAdvertisement;
323 }; 324 };
324 } 325 }
326 +
327 + @Override
328 + public String toString() {
329 + return toStringHelper(getClass())
330 + .add("currentHopLimit", Byte.toString(currentHopLimit))
331 + .add("mFlag", Byte.toString(mFlag))
332 + .add("oFlag", Byte.toString(oFlag))
333 + .add("routerLifetime", Short.toString(routerLifetime))
334 + .add("reachableTime", Integer.toString(reachableTime))
335 + .add("retransmitTimer", Integer.toString(retransmitTimer))
336 + .toString();
337 + // TODO: need to handle optionis
338 + }
325 } 339 }
......
...@@ -22,6 +22,7 @@ import org.onlab.packet.IPacket; ...@@ -22,6 +22,7 @@ import org.onlab.packet.IPacket;
22 import java.nio.ByteBuffer; 22 import java.nio.ByteBuffer;
23 import java.util.List; 23 import java.util.List;
24 24
25 +import static com.google.common.base.MoreObjects.toStringHelper;
25 import static org.onlab.packet.PacketUtils.checkInput; 26 import static org.onlab.packet.PacketUtils.checkInput;
26 27
27 /** 28 /**
...@@ -152,4 +153,11 @@ public class RouterSolicitation extends BasePacket { ...@@ -152,4 +153,11 @@ public class RouterSolicitation extends BasePacket {
152 return routerSolicitation; 153 return routerSolicitation;
153 }; 154 };
154 } 155 }
156 +
157 + @Override
158 + public String toString() {
159 + return toStringHelper(getClass())
160 + .toString();
161 + // TODO: need to handle options
162 + }
155 } 163 }
......
...@@ -23,6 +23,7 @@ import java.nio.ByteBuffer; ...@@ -23,6 +23,7 @@ import java.nio.ByteBuffer;
23 import java.util.HashMap; 23 import java.util.HashMap;
24 import java.util.Map; 24 import java.util.Map;
25 25
26 +import static com.google.common.base.MoreObjects.toStringHelper;
26 import static org.onlab.packet.PacketUtils.checkInput; 27 import static org.onlab.packet.PacketUtils.checkInput;
27 28
28 public class PIMHello extends BasePacket { 29 public class PIMHello extends BasePacket {
...@@ -115,4 +116,13 @@ public class PIMHello extends BasePacket { ...@@ -115,4 +116,13 @@ public class PIMHello extends BasePacket {
115 return hello; 116 return hello;
116 }; 117 };
117 } 118 }
119 +
120 + @Override
121 + public String toString() {
122 + return toStringHelper(getClass())
123 + .add("nbrIpAddress", nbrIpAddress.toString())
124 + .add("priorityPresent", Boolean.toString(priorityPresent))
125 + .toString();
126 + // TODO: need to handle options
127 + }
118 } 128 }
......
...@@ -23,6 +23,7 @@ import org.onlab.packet.IpPrefix; ...@@ -23,6 +23,7 @@ import org.onlab.packet.IpPrefix;
23 import java.nio.ByteBuffer; 23 import java.nio.ByteBuffer;
24 import java.util.HashMap; 24 import java.util.HashMap;
25 25
26 +import static com.google.common.base.MoreObjects.toStringHelper;
26 import static org.onlab.packet.PacketUtils.checkInput; 27 import static org.onlab.packet.PacketUtils.checkInput;
27 28
28 public class PIMJoinPrune extends BasePacket { 29 public class PIMJoinPrune extends BasePacket {
...@@ -268,4 +269,13 @@ public class PIMJoinPrune extends BasePacket { ...@@ -268,4 +269,13 @@ public class PIMJoinPrune extends BasePacket {
268 return jp; 269 return jp;
269 }; 270 };
270 } 271 }
272 +
273 + @Override
274 + public String toString() {
275 + return toStringHelper(getClass())
276 + .add("upstreamAddr", upstreamAddr.toString())
277 + .add("holdTime", Short.toString(holdTime))
278 + .toString();
279 + // TODO: need to handle joinPrunes
280 + }
271 } 281 }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onlab.packet; 17 package org.onlab.packet;
18 18
19 +import org.apache.commons.lang3.StringUtils;
19 import org.junit.Before; 20 import org.junit.Before;
20 import org.junit.Test; 21 import org.junit.Test;
21 22
...@@ -70,6 +71,9 @@ public class ArpTest { ...@@ -70,6 +71,9 @@ public class ArpTest {
70 PacketTestUtils.testDeserializeTruncated(deserializer, byteHeader); 71 PacketTestUtils.testDeserializeTruncated(deserializer, byteHeader);
71 } 72 }
72 73
74 + /**
75 + * Tests deserialize and getters.
76 + */
73 @Test 77 @Test
74 public void testDeserialize() throws Exception { 78 public void testDeserialize() throws Exception {
75 ARP arp = deserializer.deserialize(byteHeader, 0, byteHeader.length); 79 ARP arp = deserializer.deserialize(byteHeader, 0, byteHeader.length);
...@@ -85,4 +89,19 @@ public class ArpTest { ...@@ -85,4 +89,19 @@ public class ArpTest {
85 assertTrue(Arrays.equals(targetMac.toBytes(), arp.getTargetHardwareAddress())); 89 assertTrue(Arrays.equals(targetMac.toBytes(), arp.getTargetHardwareAddress()));
86 assertTrue(Arrays.equals(targetIp.toOctets(), arp.getTargetProtocolAddress())); 90 assertTrue(Arrays.equals(targetIp.toOctets(), arp.getTargetProtocolAddress()));
87 } 91 }
92 +
93 + /**
94 + * Tests toString.
95 + */
96 + @Test
97 + public void testToStringArp() throws Exception {
98 + ARP arp = deserializer.deserialize(byteHeader, 0, byteHeader.length);
99 + String str = arp.toString();
100 + assertTrue(StringUtils.contains(str, "hardwareAddressLength=" + hwAddressLength));
101 + assertTrue(StringUtils.contains(str, "protocolAddressLength=" + protoAddressLength));
102 + assertTrue(StringUtils.contains(str, "senderHardwareAddress=" + Arrays.toString(srcMac.toBytes())));
103 + assertTrue(StringUtils.contains(str, "senderProtocolAddress=" + Arrays.toString(srcIp.toOctets())));
104 + assertTrue(StringUtils.contains(str, "targetHardwareAddress=" + Arrays.toString(targetMac.toBytes())));
105 + assertTrue(StringUtils.contains(str, "targetProtocolAddress=" + Arrays.toString(targetIp.toOctets())));
106 + }
88 } 107 }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
17 package org.onlab.packet; 17 package org.onlab.packet;
18 18
19 import com.google.common.base.Charsets; 19 import com.google.common.base.Charsets;
20 +import org.apache.commons.lang3.StringUtils;
20 import org.junit.Before; 21 import org.junit.Before;
21 import org.junit.Test; 22 import org.junit.Test;
22 23
...@@ -111,6 +112,9 @@ public class DhcpTest { ...@@ -111,6 +112,9 @@ public class DhcpTest {
111 PacketTestUtils.testDeserializeTruncated(deserializer, byteHeader); 112 PacketTestUtils.testDeserializeTruncated(deserializer, byteHeader);
112 } 113 }
113 114
115 + /**
116 + * Tests deserialize and getters.
117 + */
114 @Test 118 @Test
115 public void testDeserialize() throws Exception { 119 public void testDeserialize() throws Exception {
116 DHCP dhcp = deserializer.deserialize(byteHeader, 0, byteHeader.length); 120 DHCP dhcp = deserializer.deserialize(byteHeader, 0, byteHeader.length);
...@@ -134,4 +138,28 @@ public class DhcpTest { ...@@ -134,4 +138,28 @@ public class DhcpTest {
134 assertEquals(hostNameOption, dhcp.options.get(0)); 138 assertEquals(hostNameOption, dhcp.options.get(0));
135 } 139 }
136 140
141 + /**
142 + * Tests toString.
143 + */
144 + @Test
145 + public void testToStringDhcp() throws Exception {
146 + DHCP dhcp = deserializer.deserialize(byteHeader, 0, byteHeader.length);
147 + String str = dhcp.toString();
148 +
149 + assertTrue(StringUtils.contains(str, "opCode=" + opCode));
150 + assertTrue(StringUtils.contains(str, "hardwareType=" + hardwareType));
151 + assertTrue(StringUtils.contains(str, "hardwareAddressLength=" + hardwareAddressLength));
152 + assertTrue(StringUtils.contains(str, "hops=" + hops));
153 + assertTrue(StringUtils.contains(str, "transactionId=" + transactionId));
154 + assertTrue(StringUtils.contains(str, "seconds=" + seconds));
155 + assertTrue(StringUtils.contains(str, "flags=" + flags));
156 + assertTrue(StringUtils.contains(str, "clientIPAddress=" + clientIpAddress));
157 + assertTrue(StringUtils.contains(str, "yourIPAddress=" + yourIpAddress));
158 + assertTrue(StringUtils.contains(str, "serverIPAddress=" + serverIpAddress));
159 + assertTrue(StringUtils.contains(str, "gatewayIPAddress=" + gatewayIpAddress));
160 + assertTrue(StringUtils.contains(str, "clientHardwareAddress=" + Arrays.toString(clientHardwareAddress)));
161 + assertTrue(StringUtils.contains(str, "serverName=" + serverName));
162 + assertTrue(StringUtils.contains(str, "bootFileName=" + bootFileName));
163 + // TODO: add option unit test
164 + }
137 } 165 }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
18 18
19 package org.onlab.packet; 19 package org.onlab.packet;
20 20
21 +import org.apache.commons.lang3.StringUtils;
21 import org.junit.BeforeClass; 22 import org.junit.BeforeClass;
22 import org.junit.Test; 23 import org.junit.Test;
23 24
...@@ -107,4 +108,17 @@ public class ICMP6Test { ...@@ -107,4 +108,17 @@ public class ICMP6Test {
107 assertTrue(icmp61.equals(icmp61)); 108 assertTrue(icmp61.equals(icmp61));
108 assertFalse(icmp61.equals(icmp62)); 109 assertFalse(icmp61.equals(icmp62));
109 } 110 }
111 +
112 + /**
113 + * Tests toString.
114 + */
115 + @Test
116 + public void testToStringIcmp6() throws Exception {
117 + ICMP6 icmp6 = ICMP6.deserializer().deserialize(bytePacket, 0, bytePacket.length);
118 + String str = icmp6.toString();
119 +
120 + assertTrue(StringUtils.contains(str, "icmpType=" + ICMP6.ECHO_REQUEST));
121 + assertTrue(StringUtils.contains(str, "icmpCode=" + (byte) 0x00));
122 + assertTrue(StringUtils.contains(str, "checksum=" + (short) 0x82bc));
123 + }
110 } 124 }
......
...@@ -16,12 +16,14 @@ ...@@ -16,12 +16,14 @@
16 16
17 package org.onlab.packet; 17 package org.onlab.packet;
18 18
19 +import org.apache.commons.lang3.StringUtils;
19 import org.junit.Before; 20 import org.junit.Before;
20 import org.junit.Test; 21 import org.junit.Test;
21 22
22 import java.nio.ByteBuffer; 23 import java.nio.ByteBuffer;
23 24
24 import static org.junit.Assert.assertEquals; 25 import static org.junit.Assert.assertEquals;
26 +import static org.junit.Assert.assertTrue;
25 27
26 /** 28 /**
27 * Unit tests for the ICMP class. 29 * Unit tests for the ICMP class.
...@@ -59,6 +61,9 @@ public class ICMPTest { ...@@ -59,6 +61,9 @@ public class ICMPTest {
59 PacketTestUtils.testDeserializeTruncated(deserializer, headerBytes); 61 PacketTestUtils.testDeserializeTruncated(deserializer, headerBytes);
60 } 62 }
61 63
64 + /**
65 + * Tests deserialize and getters.
66 + */
62 @Test 67 @Test
63 public void testDeserialize() throws Exception { 68 public void testDeserialize() throws Exception {
64 ICMP icmp = deserializer.deserialize(headerBytes, 0, headerBytes.length); 69 ICMP icmp = deserializer.deserialize(headerBytes, 0, headerBytes.length);
...@@ -67,4 +72,17 @@ public class ICMPTest { ...@@ -67,4 +72,17 @@ public class ICMPTest {
67 assertEquals(icmpCode, icmp.getIcmpCode()); 72 assertEquals(icmpCode, icmp.getIcmpCode());
68 assertEquals(checksum, icmp.getChecksum()); 73 assertEquals(checksum, icmp.getChecksum());
69 } 74 }
75 +
76 + /**
77 + * Tests toString.
78 + */
79 + @Test
80 + public void testToStringIcmp() throws Exception {
81 + ICMP icmp = deserializer.deserialize(headerBytes, 0, headerBytes.length);
82 + String str = icmp.toString();
83 +
84 + assertTrue(StringUtils.contains(str, "icmpType=" + icmpType));
85 + assertTrue(StringUtils.contains(str, "icmpCode=" + icmpCode));
86 + assertTrue(StringUtils.contains(str, "checksum=" + checksum));
87 + }
70 } 88 }
......
...@@ -93,4 +93,12 @@ public class IGMPTest { ...@@ -93,4 +93,12 @@ public class IGMPTest {
93 IGMP igmp = deserializer.deserialize(data, 0, data.length); 93 IGMP igmp = deserializer.deserialize(data, 0, data.length);
94 assertTrue(igmp.equals(igmpMembership)); 94 assertTrue(igmp.equals(igmpMembership));
95 } 95 }
96 +
97 + /**
98 + * Tests toString.
99 + */
100 + @Test
101 + public void testToStringIgmp() throws Exception {
102 + // TODO: add toString unit test
103 + }
96 } 104 }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onlab.packet; 17 package org.onlab.packet;
18 18
19 +import org.apache.commons.lang3.StringUtils;
19 import org.junit.Before; 20 import org.junit.Before;
20 import org.junit.Test; 21 import org.junit.Test;
21 22
...@@ -78,6 +79,9 @@ public class IPv4Test { ...@@ -78,6 +79,9 @@ public class IPv4Test {
78 PacketTestUtils.testDeserializeTruncated(deserializer, headerBytes); 79 PacketTestUtils.testDeserializeTruncated(deserializer, headerBytes);
79 } 80 }
80 81
82 + /**
83 + * Tests deserialize and getters.
84 + */
81 @Test 85 @Test
82 public void testDeserialize() throws Exception { 86 public void testDeserialize() throws Exception {
83 IPv4 ipv4 = deserializer.deserialize(headerBytes, 0, headerBytes.length); 87 IPv4 ipv4 = deserializer.deserialize(headerBytes, 0, headerBytes.length);
...@@ -96,4 +100,26 @@ public class IPv4Test { ...@@ -96,4 +100,26 @@ public class IPv4Test {
96 assertEquals(destinationAddress, ipv4.getDestinationAddress()); 100 assertEquals(destinationAddress, ipv4.getDestinationAddress());
97 assertTrue(ipv4.isTruncated()); 101 assertTrue(ipv4.isTruncated());
98 } 102 }
103 +
104 + /**
105 + * Tests toString.
106 + */
107 + @Test
108 + public void testToStringIPv4() throws Exception {
109 + IPv4 ipv4 = deserializer.deserialize(headerBytes, 0, headerBytes.length);
110 + String str = ipv4.toString();
111 +
112 + assertTrue(StringUtils.contains(str, "version=" + version));
113 + assertTrue(StringUtils.contains(str, "headerLength=" + headerLength));
114 + assertTrue(StringUtils.contains(str, "diffServ=" + diffServ));
115 + assertTrue(StringUtils.contains(str, "totalLength=" + totalLength));
116 + assertTrue(StringUtils.contains(str, "identification=" + identification));
117 + assertTrue(StringUtils.contains(str, "flags=" + flags));
118 + assertTrue(StringUtils.contains(str, "fragmentOffset=" + fragmentOffset));
119 + assertTrue(StringUtils.contains(str, "ttl=" + ttl));
120 + assertTrue(StringUtils.contains(str, "protocol=" + protocol));
121 + assertTrue(StringUtils.contains(str, "checksum=" + checksum));
122 + assertTrue(StringUtils.contains(str, "sourceAddress=" + sourceAddress));
123 + assertTrue(StringUtils.contains(str, "destinationAddress=" + destinationAddress));
124 + }
99 } 125 }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
18 18
19 package org.onlab.packet; 19 package org.onlab.packet;
20 20
21 +import org.apache.commons.lang3.StringUtils;
21 import org.junit.Before; 22 import org.junit.Before;
22 import org.junit.BeforeClass; 23 import org.junit.BeforeClass;
23 import org.junit.Test; 24 import org.junit.Test;
...@@ -151,4 +152,20 @@ public class IPv6Test { ...@@ -151,4 +152,20 @@ public class IPv6Test {
151 assertTrue(packet1.equals(packet1)); 152 assertTrue(packet1.equals(packet1));
152 assertFalse(packet1.equals(packet2)); 153 assertFalse(packet1.equals(packet2));
153 } 154 }
155 +
156 + /**
157 + * Tests toString.
158 + */
159 + @Test
160 + public void testToStringIPv6() throws Exception {
161 + IPv6 ipv6 = deserializer.deserialize(bytePacket, 0, bytePacket.length);
162 + String str = ipv6.toString();
163 +
164 + assertTrue(StringUtils.contains(str, "version=" + (byte) 6));
165 + assertTrue(StringUtils.contains(str, "trafficClass=" + (byte) 0x93));
166 + assertTrue(StringUtils.contains(str, "flowLabel=" + 0x13579));
167 + assertTrue(StringUtils.contains(str, "nextHeader=" + IPv6.PROTOCOL_UDP));
168 + assertTrue(StringUtils.contains(str, "hopLimit=" + (byte) 32));
169 + // TODO: test IPv6 source and destination address
170 + }
154 } 171 }
......
...@@ -16,12 +16,14 @@ ...@@ -16,12 +16,14 @@
16 16
17 package org.onlab.packet; 17 package org.onlab.packet;
18 18
19 +import org.apache.commons.lang3.StringUtils;
19 import org.junit.Before; 20 import org.junit.Before;
20 import org.junit.Test; 21 import org.junit.Test;
21 22
22 import java.nio.ByteBuffer; 23 import java.nio.ByteBuffer;
23 24
24 import static org.junit.Assert.assertEquals; 25 import static org.junit.Assert.assertEquals;
26 +import static org.junit.Assert.assertTrue;
25 27
26 /** 28 /**
27 * Unit tests for LLC class. 29 * Unit tests for LLC class.
...@@ -59,6 +61,9 @@ public class LLCTest { ...@@ -59,6 +61,9 @@ public class LLCTest {
59 PacketTestUtils.testDeserializeTruncated(deserializer, bytes); 61 PacketTestUtils.testDeserializeTruncated(deserializer, bytes);
60 } 62 }
61 63
64 + /**
65 + * Tests deserialize and getters.
66 + */
62 @Test 67 @Test
63 public void testDeserialize() throws Exception { 68 public void testDeserialize() throws Exception {
64 LLC llc = deserializer.deserialize(bytes, 0, bytes.length); 69 LLC llc = deserializer.deserialize(bytes, 0, bytes.length);
...@@ -67,4 +72,17 @@ public class LLCTest { ...@@ -67,4 +72,17 @@ public class LLCTest {
67 assertEquals(ssap, llc.getSsap()); 72 assertEquals(ssap, llc.getSsap());
68 assertEquals(ctrl, llc.getCtrl()); 73 assertEquals(ctrl, llc.getCtrl());
69 } 74 }
75 +
76 + /**
77 + * Tests toString.
78 + */
79 + @Test
80 + public void testToStringLLC() throws Exception {
81 + LLC llc = deserializer.deserialize(bytes, 0, bytes.length);
82 + String str = llc.toString();
83 +
84 + assertTrue(StringUtils.contains(str, "dsap=" + dsap));
85 + assertTrue(StringUtils.contains(str, "ssap=" + ssap));
86 + assertTrue(StringUtils.contains(str, "ctrl=" + ctrl));
87 + }
70 } 88 }
......
...@@ -89,6 +89,9 @@ public class LLDPTest { ...@@ -89,6 +89,9 @@ public class LLDPTest {
89 PacketTestUtils.testDeserializeTruncated(deserializer, bytes); 89 PacketTestUtils.testDeserializeTruncated(deserializer, bytes);
90 } 90 }
91 91
92 + /**
93 + * Tests deserialize and getters.
94 + */
92 @Test 95 @Test
93 public void testDeserialize() throws Exception { 96 public void testDeserialize() throws Exception {
94 LLDP lldp = deserializer.deserialize(bytes, 0, bytes.length); 97 LLDP lldp = deserializer.deserialize(bytes, 0, bytes.length);
...@@ -112,4 +115,15 @@ public class LLDPTest { ...@@ -112,4 +115,15 @@ public class LLDPTest {
112 assertEquals(optionalTlvSize, optionalTlv.getLength()); 115 assertEquals(optionalTlvSize, optionalTlv.getLength());
113 assertTrue(Arrays.equals(optionalTlvValue, optionalTlv.getValue())); 116 assertTrue(Arrays.equals(optionalTlvValue, optionalTlv.getValue()));
114 } 117 }
118 +
119 + /**
120 + * Tests toString.
121 + */
122 + @Test
123 + public void testToStringLLDP() throws Exception {
124 + LLDP lldp = deserializer.deserialize(bytes, 0, bytes.length);
125 + String str = lldp.toString();
126 +
127 + // TODO: need to add LLDP toString unit test
128 + }
115 } 129 }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onlab.packet; 17 package org.onlab.packet;
18 18
19 +import org.apache.commons.lang3.StringUtils;
19 import org.junit.Before; 20 import org.junit.Before;
20 import org.junit.Test; 21 import org.junit.Test;
21 22
...@@ -23,6 +24,7 @@ import java.nio.ByteBuffer; ...@@ -23,6 +24,7 @@ import java.nio.ByteBuffer;
23 import java.util.HashMap; 24 import java.util.HashMap;
24 25
25 import static org.junit.Assert.assertEquals; 26 import static org.junit.Assert.assertEquals;
27 +import static org.junit.Assert.assertTrue;
26 28
27 /** 29 /**
28 * Unit tests for MPLS class. 30 * Unit tests for MPLS class.
...@@ -62,6 +64,9 @@ public class MplsTest { ...@@ -62,6 +64,9 @@ public class MplsTest {
62 PacketTestUtils.testDeserializeTruncated(deserializer, bytes); 64 PacketTestUtils.testDeserializeTruncated(deserializer, bytes);
63 } 65 }
64 66
67 + /**
68 + * Tests deserialize and getters.
69 + */
65 @Test 70 @Test
66 public void testDeserialize() throws Exception { 71 public void testDeserialize() throws Exception {
67 MPLS mpls = deserializer.deserialize(bytes, 0, bytes.length); 72 MPLS mpls = deserializer.deserialize(bytes, 0, bytes.length);
...@@ -71,4 +76,18 @@ public class MplsTest { ...@@ -71,4 +76,18 @@ public class MplsTest {
71 assertEquals(ttl, mpls.ttl); 76 assertEquals(ttl, mpls.ttl);
72 assertEquals(protocol, mpls.protocol); 77 assertEquals(protocol, mpls.protocol);
73 } 78 }
79 +
80 + /**
81 + * Tests toString.
82 + */
83 + @Test
84 + public void testToStringMpls() throws Exception {
85 + MPLS mpls = deserializer.deserialize(bytes, 0, bytes.length);
86 + String str = mpls.toString();
87 +
88 + assertTrue(StringUtils.contains(str, "label=" + label));
89 + assertTrue(StringUtils.contains(str, "bos=" + bos));
90 + assertTrue(StringUtils.contains(str, "ttl=" + ttl));
91 + assertTrue(StringUtils.contains(str, "protocol=" + protocol));
92 + }
74 } 93 }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
18 18
19 package org.onlab.packet; 19 package org.onlab.packet;
20 20
21 +import org.apache.commons.lang3.StringUtils;
21 import org.junit.BeforeClass; 22 import org.junit.BeforeClass;
22 import org.junit.Test; 23 import org.junit.Test;
23 24
...@@ -160,4 +161,23 @@ public class TCPTest { ...@@ -160,4 +161,23 @@ public class TCPTest {
160 assertTrue(tcp1.equals(tcp1)); 161 assertTrue(tcp1.equals(tcp1));
161 assertFalse(tcp1.equals(tcp2)); 162 assertFalse(tcp1.equals(tcp2));
162 } 163 }
164 +
165 + /**
166 + * Tests toString.
167 + */
168 + @Test
169 + public void testToStringTcp() throws Exception {
170 + TCP tcp = deserializer.deserialize(bytePacketTCP4, 0, bytePacketTCP4.length);
171 + String str = tcp.toString();
172 +
173 + assertTrue(StringUtils.contains(str, "sourcePort=" + 0x50));
174 + assertTrue(StringUtils.contains(str, "destinationPort=" + 0x60));
175 + assertTrue(StringUtils.contains(str, "sequence=" + 0x10));
176 + assertTrue(StringUtils.contains(str, "acknowledge=" + 0x20));
177 + assertTrue(StringUtils.contains(str, "dataOffset=" + (byte) 0x5));
178 + assertTrue(StringUtils.contains(str, "flags=" + (short) 0x2));
179 + assertTrue(StringUtils.contains(str, "windowSize=" + (short) 0x1000));
180 + assertTrue(StringUtils.contains(str, "checksum=" + (short) 0x1bae));
181 + assertTrue(StringUtils.contains(str, "urgentPointer=" + (short) 0x1));
182 + }
163 } 183 }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
18 18
19 package org.onlab.packet; 19 package org.onlab.packet;
20 20
21 +import org.apache.commons.lang3.StringUtils;
21 import org.junit.BeforeClass; 22 import org.junit.BeforeClass;
22 import org.junit.Test; 23 import org.junit.Test;
23 24
...@@ -131,4 +132,18 @@ public class UDPTest { ...@@ -131,4 +132,18 @@ public class UDPTest {
131 assertTrue(udp1.equals(udp1)); 132 assertTrue(udp1.equals(udp1));
132 assertFalse(udp1.equals(udp2)); 133 assertFalse(udp1.equals(udp2));
133 } 134 }
135 +
136 + /**
137 + * Tests toString.
138 + */
139 + @Test
140 + public void testToStringUdp() throws Exception {
141 + UDP udp = deserializer.deserialize(bytePacketUDP4, 0, bytePacketUDP4.length);
142 + String str = udp.toString();
143 +
144 + assertTrue(StringUtils.contains(str, "sourcePort=" + 0x50));
145 + assertTrue(StringUtils.contains(str, "destinationPort=" + 0x60));
146 + assertTrue(StringUtils.contains(str, "length=" + (short) 8));
147 + assertTrue(StringUtils.contains(str, "checksum=" + (short) 0x7bda));
148 + }
134 } 149 }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onlab.packet.ipv6; 17 package org.onlab.packet.ipv6;
18 18
19 +import org.apache.commons.lang3.StringUtils;
19 import org.junit.Before; 20 import org.junit.Before;
20 import org.junit.BeforeClass; 21 import org.junit.BeforeClass;
21 import org.junit.Test; 22 import org.junit.Test;
...@@ -23,11 +24,10 @@ import org.onlab.packet.Data; ...@@ -23,11 +24,10 @@ import org.onlab.packet.Data;
23 import org.onlab.packet.Deserializer; 24 import org.onlab.packet.Deserializer;
24 import org.onlab.packet.UDP; 25 import org.onlab.packet.UDP;
25 26
27 +import java.util.Arrays;
28 +
26 import static org.hamcrest.Matchers.is; 29 import static org.hamcrest.Matchers.is;
27 -import static org.junit.Assert.assertArrayEquals; 30 +import static org.junit.Assert.*;
28 -import static org.junit.Assert.assertFalse;
29 -import static org.junit.Assert.assertThat;
30 -import static org.junit.Assert.assertTrue;
31 31
32 /** 32 /**
33 * Tests for class {@link Authentication}. 33 * Tests for class {@link Authentication}.
...@@ -118,4 +118,19 @@ public class AuthenticationTest { ...@@ -118,4 +118,19 @@ public class AuthenticationTest {
118 assertTrue(auth1.equals(auth1)); 118 assertTrue(auth1.equals(auth1));
119 assertFalse(auth1.equals(auth2)); 119 assertFalse(auth1.equals(auth2));
120 } 120 }
121 +
122 + /**
123 + * Tests toString.
124 + */
125 + @Test
126 + public void testToStringAuthentication() throws Exception {
127 + Authentication auth = deserializer.deserialize(bytePacket, 0, bytePacket.length);
128 + String str = auth.toString();
129 +
130 + assertTrue(StringUtils.contains(str, "nextHeader=" + (byte) 0x11));
131 + assertTrue(StringUtils.contains(str, "payloadLength=" + (byte) 0x02));
132 + assertTrue(StringUtils.contains(str, "securityParamIndex=" + 0x13572468));
133 + assertTrue(StringUtils.contains(str, "sequence=" + 0xffff00));
134 + assertTrue(StringUtils.contains(str, "integrityCheck=" + Arrays.toString(icv)));
135 + }
121 } 136 }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onlab.packet.ipv6; 17 package org.onlab.packet.ipv6;
18 18
19 +import org.apache.commons.lang3.StringUtils;
19 import org.junit.Before; 20 import org.junit.Before;
20 import org.junit.BeforeClass; 21 import org.junit.BeforeClass;
21 import org.junit.Test; 22 import org.junit.Test;
...@@ -24,11 +25,10 @@ import org.onlab.packet.Deserializer; ...@@ -24,11 +25,10 @@ import org.onlab.packet.Deserializer;
24 import org.onlab.packet.IPv6; 25 import org.onlab.packet.IPv6;
25 import org.onlab.packet.UDP; 26 import org.onlab.packet.UDP;
26 27
28 +import java.util.Arrays;
29 +
27 import static org.hamcrest.Matchers.is; 30 import static org.hamcrest.Matchers.is;
28 -import static org.junit.Assert.assertArrayEquals; 31 +import static org.junit.Assert.*;
29 -import static org.junit.Assert.assertFalse;
30 -import static org.junit.Assert.assertThat;
31 -import static org.junit.Assert.assertTrue;
32 32
33 /** 33 /**
34 * Tests for class {@link BaseOptions}. 34 * Tests for class {@link BaseOptions}.
...@@ -112,4 +112,17 @@ public class BaseOptionsTest { ...@@ -112,4 +112,17 @@ public class BaseOptionsTest {
112 assertTrue(baseopt1.equals(baseopt1)); 112 assertTrue(baseopt1.equals(baseopt1));
113 assertFalse(baseopt1.equals(baseopt2)); 113 assertFalse(baseopt1.equals(baseopt2));
114 } 114 }
115 +
116 + /**
117 + * Tests toString.
118 + */
119 + @Test
120 + public void testToStringBaseOptions() throws Exception {
121 + BaseOptions baseopt = deserializer.deserialize(bytePacket, 0, bytePacket.length);
122 + String str = baseopt.toString();
123 +
124 + assertTrue(StringUtils.contains(str, "nextHeader=" + (byte) 0x11));
125 + assertTrue(StringUtils.contains(str, "headerExtLength=" + (byte) 0x00));
126 + assertTrue(StringUtils.contains(str, "options=" + Arrays.toString(options)));
127 + }
115 } 128 }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onlab.packet.ipv6; 17 package org.onlab.packet.ipv6;
18 18
19 +import org.apache.commons.lang3.StringUtils;
19 import org.junit.Before; 20 import org.junit.Before;
20 import org.junit.BeforeClass; 21 import org.junit.BeforeClass;
21 import org.junit.Test; 22 import org.junit.Test;
...@@ -101,4 +102,16 @@ public class EncapSecurityPayloadTest { ...@@ -101,4 +102,16 @@ public class EncapSecurityPayloadTest {
101 assertTrue(esp1.equals(esp1)); 102 assertTrue(esp1.equals(esp1));
102 assertFalse(esp1.equals(esp2)); 103 assertFalse(esp1.equals(esp2));
103 } 104 }
105 +
106 + /**
107 + * Tests toString.
108 + */
109 + @Test
110 + public void testToStringESP() throws Exception {
111 + EncapSecurityPayload esp = deserializer.deserialize(bytePacket, 0, bytePacket.length);
112 + String str = esp.toString();
113 +
114 + assertTrue(StringUtils.contains(str, "securityParamIndex=" + 0x13572468));
115 + assertTrue(StringUtils.contains(str, "sequence=" + 0xffff00));
116 + }
104 } 117 }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onlab.packet.ipv6; 17 package org.onlab.packet.ipv6;
18 18
19 +import org.apache.commons.lang3.StringUtils;
19 import org.junit.Before; 20 import org.junit.Before;
20 import org.junit.BeforeClass; 21 import org.junit.BeforeClass;
21 import org.junit.Test; 22 import org.junit.Test;
...@@ -110,4 +111,18 @@ public class FragmentTest { ...@@ -110,4 +111,18 @@ public class FragmentTest {
110 assertTrue(frag1.equals(frag1)); 111 assertTrue(frag1.equals(frag1));
111 assertFalse(frag1.equals(frag2)); 112 assertFalse(frag1.equals(frag2));
112 } 113 }
114 +
115 + /**
116 + * Tests toString.
117 + */
118 + @Test
119 + public void testToStringFragment() throws Exception {
120 + Fragment frag = deserializer.deserialize(bytePacket, 0, bytePacket.length);
121 + String str = frag.toString();
122 +
123 + assertTrue(StringUtils.contains(str, "nextHeader=" + (byte) 0x11));
124 + assertTrue(StringUtils.contains(str, "fragmentOffset=" + (short) 0x1f));
125 + assertTrue(StringUtils.contains(str, "moreFragment=" + (byte) 1));
126 + assertTrue(StringUtils.contains(str, "identification=" + 0x1357));
127 + }
113 } 128 }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onlab.packet.ipv6; 17 package org.onlab.packet.ipv6;
18 18
19 +import org.apache.commons.lang3.StringUtils;
19 import org.junit.Before; 20 import org.junit.Before;
20 import org.junit.BeforeClass; 21 import org.junit.BeforeClass;
21 import org.junit.Test; 22 import org.junit.Test;
...@@ -24,11 +25,10 @@ import org.onlab.packet.DeserializationException; ...@@ -24,11 +25,10 @@ import org.onlab.packet.DeserializationException;
24 import org.onlab.packet.Deserializer; 25 import org.onlab.packet.Deserializer;
25 import org.onlab.packet.UDP; 26 import org.onlab.packet.UDP;
26 27
28 +import java.util.Arrays;
29 +
27 import static org.hamcrest.Matchers.is; 30 import static org.hamcrest.Matchers.is;
28 -import static org.junit.Assert.assertArrayEquals; 31 +import static org.junit.Assert.*;
29 -import static org.junit.Assert.assertFalse;
30 -import static org.junit.Assert.assertThat;
31 -import static org.junit.Assert.assertTrue;
32 32
33 /** 33 /**
34 * Tests for class {@link Routing}. 34 * Tests for class {@link Routing}.
...@@ -125,4 +125,19 @@ public class RoutingTest { ...@@ -125,4 +125,19 @@ public class RoutingTest {
125 assertTrue(routing1.equals(routing1)); 125 assertTrue(routing1.equals(routing1));
126 assertFalse(routing1.equals(routing2)); 126 assertFalse(routing1.equals(routing2));
127 } 127 }
128 +
129 + /**
130 + * Tests toString.
131 + */
132 + @Test
133 + public void testToStringRouting() throws Exception {
134 + Routing routing = deserializer.deserialize(bytePacket, 0, bytePacket.length);
135 + String str = routing.toString();
136 +
137 + assertTrue(StringUtils.contains(str, "nextHeader=" + (byte) 0x11));
138 + assertTrue(StringUtils.contains(str, "headerExtLength=" + (byte) 0x02));
139 + assertTrue(StringUtils.contains(str, "routingType=" + (byte) 0x00));
140 + assertTrue(StringUtils.contains(str, "segmentsLeft=" + (byte) 0x03));
141 + assertTrue(StringUtils.contains(str, "routingData=" + Arrays.toString(routingData)));
142 + }
128 } 143 }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onlab.packet.ndp; 16 package org.onlab.packet.ndp;
17 17
18 +import org.apache.commons.lang3.StringUtils;
18 import org.junit.BeforeClass; 19 import org.junit.BeforeClass;
19 import org.junit.Test; 20 import org.junit.Test;
20 import org.onlab.packet.DeserializationException; 21 import org.onlab.packet.DeserializationException;
...@@ -25,10 +26,7 @@ import org.onlab.packet.PacketTestUtils; ...@@ -25,10 +26,7 @@ import org.onlab.packet.PacketTestUtils;
25 import java.nio.ByteBuffer; 26 import java.nio.ByteBuffer;
26 27
27 import static org.hamcrest.Matchers.is; 28 import static org.hamcrest.Matchers.is;
28 -import static org.junit.Assert.assertArrayEquals; 29 +import static org.junit.Assert.*;
29 -import static org.junit.Assert.assertFalse;
30 -import static org.junit.Assert.assertThat;
31 -import static org.junit.Assert.assertTrue;
32 30
33 /** 31 /**
34 * Tests for class {@link NeighborAdvertisement}. 32 * Tests for class {@link NeighborAdvertisement}.
...@@ -137,4 +135,18 @@ public class NeighborAdvertisementTest { ...@@ -137,4 +135,18 @@ public class NeighborAdvertisementTest {
137 assertTrue(na1.equals(na1)); 135 assertTrue(na1.equals(na1));
138 assertFalse(na1.equals(na2)); 136 assertFalse(na1.equals(na2));
139 } 137 }
138 +
139 + /**
140 + * Tests toString.
141 + */
142 + @Test
143 + public void testToStringNA() throws Exception {
144 + NeighborAdvertisement na = deserializer.deserialize(bytePacket, 0, bytePacket.length);
145 + String str = na.toString();
146 +
147 + assertTrue(StringUtils.contains(str, "routerFlag=" + (byte) 1));
148 + assertTrue(StringUtils.contains(str, "solicitedFlag=" + (byte) 1));
149 + assertTrue(StringUtils.contains(str, "overrideFlag=" + (byte) 1));
150 + // TODO: need to handle TARGET_ADDRESS
151 + }
140 } 152 }
......
...@@ -25,10 +25,7 @@ import org.onlab.packet.PacketTestUtils; ...@@ -25,10 +25,7 @@ import org.onlab.packet.PacketTestUtils;
25 import java.nio.ByteBuffer; 25 import java.nio.ByteBuffer;
26 26
27 import static org.hamcrest.Matchers.is; 27 import static org.hamcrest.Matchers.is;
28 -import static org.junit.Assert.assertArrayEquals; 28 +import static org.junit.Assert.*;
29 -import static org.junit.Assert.assertFalse;
30 -import static org.junit.Assert.assertThat;
31 -import static org.junit.Assert.assertTrue;
32 29
33 /** 30 /**
34 * Tests for class {@link NeighborSolicitation}. 31 * Tests for class {@link NeighborSolicitation}.
...@@ -131,4 +128,15 @@ public class NeighborSolicitationTest { ...@@ -131,4 +128,15 @@ public class NeighborSolicitationTest {
131 assertTrue(ns1.equals(ns1)); 128 assertTrue(ns1.equals(ns1));
132 assertFalse(ns1.equals(ns2)); 129 assertFalse(ns1.equals(ns2));
133 } 130 }
131 +
132 + /**
133 + * Tests toString.
134 + */
135 + @Test
136 + public void testToStringNS() throws Exception {
137 + NeighborSolicitation ns = deserializer.deserialize(bytePacket, 0, bytePacket.length);
138 + String str = ns.toString();
139 +
140 + // TODO: need to handle TARGET_ADDRESS and Options
141 + }
134 } 142 }
......
...@@ -144,4 +144,15 @@ public class RedirectTest { ...@@ -144,4 +144,15 @@ public class RedirectTest {
144 assertTrue(rd1.equals(rd1)); 144 assertTrue(rd1.equals(rd1));
145 assertFalse(rd1.equals(rd2)); 145 assertFalse(rd1.equals(rd2));
146 } 146 }
147 +
148 + /**
149 + * Tests toString.
150 + */
151 + @Test
152 + public void testToStringRedirect() throws Exception {
153 + Redirect rd = deserializer.deserialize(bytePacket, 0, bytePacket.length);
154 + String str = rd.toString();
155 +
156 + // TODO: need to handle TARGET_ADDRESS and DESTINATION_ADDRESS
157 + }
147 } 158 }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onlab.packet.ndp; 16 package org.onlab.packet.ndp;
17 17
18 +import org.apache.commons.lang3.StringUtils;
18 import org.junit.BeforeClass; 19 import org.junit.BeforeClass;
19 import org.junit.Test; 20 import org.junit.Test;
20 import org.onlab.packet.DeserializationException; 21 import org.onlab.packet.DeserializationException;
...@@ -137,4 +138,22 @@ public class RouterAdvertisementTest { ...@@ -137,4 +138,22 @@ public class RouterAdvertisementTest {
137 assertTrue(ra1.equals(ra1)); 138 assertTrue(ra1.equals(ra1));
138 assertFalse(ra1.equals(ra2)); 139 assertFalse(ra1.equals(ra2));
139 } 140 }
141 +
142 + /**
143 + * Tests toString.
144 + */
145 + @Test
146 + public void testToStringRA() throws Exception {
147 + RouterAdvertisement ra = deserializer.deserialize(bytePacket, 0, bytePacket.length);
148 + String str = ra.toString();
149 +
150 + assertTrue(StringUtils.contains(str, "currentHopLimit=" + (byte) 3));
151 + assertTrue(StringUtils.contains(str, "mFlag=" + (byte) 1));
152 + assertTrue(StringUtils.contains(str, "oFlag=" + (byte) 1));
153 + assertTrue(StringUtils.contains(str, "routerLifetime=" + (short) 0x258));
154 + assertTrue(StringUtils.contains(str, "reachableTime=" + 0x3e8));
155 + assertTrue(StringUtils.contains(str, "retransmitTimer=" + 0x1f4));
156 +
157 + // TODO: need to handle options
158 + }
140 } 159 }
......
...@@ -24,10 +24,7 @@ import org.onlab.packet.PacketTestUtils; ...@@ -24,10 +24,7 @@ import org.onlab.packet.PacketTestUtils;
24 import java.nio.ByteBuffer; 24 import java.nio.ByteBuffer;
25 25
26 import static org.hamcrest.Matchers.is; 26 import static org.hamcrest.Matchers.is;
27 -import static org.junit.Assert.assertArrayEquals; 27 +import static org.junit.Assert.*;
28 -import static org.junit.Assert.assertFalse;
29 -import static org.junit.Assert.assertThat;
30 -import static org.junit.Assert.assertTrue;
31 28
32 /** 29 /**
33 * Tests for class {@link RouterSolicitation}. 30 * Tests for class {@link RouterSolicitation}.
...@@ -111,4 +108,15 @@ public class RouterSolicitationTest { ...@@ -111,4 +108,15 @@ public class RouterSolicitationTest {
111 assertTrue(rs1.equals(rs1)); 108 assertTrue(rs1.equals(rs1));
112 assertFalse(rs1.equals(rs2)); 109 assertFalse(rs1.equals(rs2));
113 } 110 }
111 +
112 + /**
113 + * Tests toString.
114 + */
115 + @Test
116 + public void testToStringRS() throws Exception {
117 + RouterSolicitation rs = deserializer.deserialize(bytePacket, 0, bytePacket.length);
118 + String str = rs.toString();
119 +
120 + // TODO: need to handle Options
121 + }
114 } 122 }
......