Skip to content
Snippets Groups Projects
Commit c75c9099 authored by Jacob Chappell's avatar Jacob Chappell
Browse files

Add SPUD decoding to UDP.

parent 21c2fd72
No related branches found
No related tags found
No related merge requests found
/**
* Copyright 2011, Big Switch Networks, Inc.
* Copyright 2011, Big Switch Networks, Inc.
* Originally created by David Erickson, Stanford University
*
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
......@@ -18,6 +18,7 @@
package net.floodlightcontroller.packet;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
......@@ -39,7 +40,7 @@ public class UDP extends BasePacket {
*/
UDP.decodeMap.put(DHCP_CLIENT_PORT, DHCP.class);
UDP.decodeMap.put(DHCP_SERVER_PORT, DHCP.class);
}
protected TransportPort sourcePort;
......@@ -61,7 +62,7 @@ public class UDP extends BasePacket {
this.sourcePort = sourcePort;
return this;
}
/**
* @param sourcePort the sourcePort to set
*/
......@@ -84,7 +85,7 @@ public class UDP extends BasePacket {
this.destinationPort = destinationPort;
return this;
}
/**
* @param destinationPort the destinationPort to set
*/
......@@ -227,6 +228,14 @@ public class UDP extends BasePacket {
this.destinationPort = TransportPort.of((int) (bb.getShort() & 0xffff)); // convert range 0 to 65534, not -32768 to 32767
this.length = bb.getShort();
this.checksum = bb.getShort();
// Grab a snapshot of the first four bytes of the UDP payload.
// We will use these to see if the payload is SPUD, without
// disturbing the existing byte buffer's offsets.
ByteBuffer bb_spud = bb.slice();
byte[] maybe_spud_bytes = new byte[SPUD.MAGIC_CONSTANT.length];
if (bb_spud.remaining() >= SPUD.MAGIC_CONSTANT.length) {
bb_spud.get(maybe_spud_bytes, 0, SPUD.MAGIC_CONSTANT.length);
}
if (UDP.decodeMap.containsKey(this.destinationPort)) {
try {
......@@ -240,6 +249,8 @@ public class UDP extends BasePacket {
} catch (Exception e) {
throw new RuntimeException("Failure instantiating class", e);
}
} else if (Arrays.equals(maybe_spud_bytes, SPUD.MAGIC_CONSTANT)) {
this.payload = new SPUD();
} else {
this.payload = new Data();
}
......
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