Skip to content
Snippets Groups Projects
Commit ee7e37e4 authored by Wilson Ng's avatar Wilson Ng
Browse files

Initial check-in of VRS traceroute support [BVS-356]

parent 8936db01
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,8 @@
package net.floodlightcontroller.packet;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
/**
* Implements ICMP packet format
......@@ -28,8 +30,23 @@ public class ICMP extends BasePacket {
protected byte icmpCode;
protected short checksum;
// The value is the number of bytes of padding
public static final Map<Byte, Short> paddingMap;
public static final byte ECHO_REPLY = 0x0;
public static final byte ECHO_REQUEST = 0x8;
public static final byte TIME_EXCEEDED = 0xB;
public static final byte DESTINATION_UNREACHABLE = 0x3;
public static final byte CODE_PORT_UNREACHABLE = 0x3;
static {
paddingMap = new HashMap<Byte, Short>();
ICMP.paddingMap.put(ICMP.ECHO_REPLY, (short) 0);
ICMP.paddingMap.put(ICMP.ECHO_REQUEST, (short) 0);
ICMP.paddingMap.put(ICMP.TIME_EXCEEDED, (short) 4);
ICMP.paddingMap.put(ICMP.DESTINATION_UNREACHABLE, (short) 4);
}
/**
* @return the icmpType
......@@ -84,7 +101,11 @@ public class ICMP extends BasePacket {
*/
@Override
public byte[] serialize() {
int length = 4;
short padding = 0;
if (paddingMap.containsKey(this.icmpType))
padding = paddingMap.get(this.icmpType);
int length = 4 + padding;
byte[] payloadData = null;
if (payload != null) {
payload.setParent(this);
......@@ -98,6 +119,9 @@ public class ICMP extends BasePacket {
bb.put(this.icmpType);
bb.put(this.icmpCode);
bb.putShort(this.checksum);
for (int i = 0; i < padding; i++)
bb.put((byte) 0);
if (payloadData != null)
bb.put(payloadData);
......@@ -166,6 +190,12 @@ public class ICMP extends BasePacket {
this.icmpCode = bb.get();
this.checksum = bb.getShort();
short padding = 0;
if (paddingMap.containsKey(this.icmpType))
padding = paddingMap.get(this.icmpType);
bb.position(bb.position() + padding);
this.payload = new Data();
this.payload = payload.deserialize(data, bb.position(), bb.limit()-bb.position());
this.payload.setParent(this);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment