Fix checkstyle whitespace issues - WHITESPACE ONLY
Change-Id: Ic205c1afd639c6008d61d9de95cb764eeb6238ca
diff --git a/src/main/java/net/onrc/onos/core/packet/ARP.java b/src/main/java/net/onrc/onos/core/packet/ARP.java
index a2e25c3..bc61c91 100644
--- a/src/main/java/net/onrc/onos/core/packet/ARP.java
+++ b/src/main/java/net/onrc/onos/core/packet/ARP.java
@@ -1,19 +1,19 @@
/**
-* 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
-*
-* 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.
-**/
+ * 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
+ *
+ * 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 net.onrc.onos.core.packet;
@@ -21,7 +21,6 @@
import java.util.Arrays;
/**
- *
* @author David Erickson (daviderickson@cs.stanford.edu)
*/
public class ARP extends BasePacket {
@@ -148,7 +147,7 @@
this.senderProtocolAddress = senderProtocolAddress;
return this;
}
-
+
public ARP setSenderProtocolAddress(int address) {
this.senderProtocolAddress = ByteBuffer.allocate(4).putInt(address).array();
return this;
@@ -179,9 +178,9 @@
/**
* @return True if gratuitous ARP (SPA = TPA), false otherwise
*/
- public boolean isGratuitous() {
- assert(senderProtocolAddress.length == targetProtocolAddress.length);
-
+ public boolean isGratuitous() {
+ assert (senderProtocolAddress.length == targetProtocolAddress.length);
+
int indx = 0;
while (indx < senderProtocolAddress.length) {
if (senderProtocolAddress[indx] != targetProtocolAddress[indx]) {
@@ -189,10 +188,10 @@
}
indx++;
}
-
+
return true;
}
-
+
/**
* @param targetProtocolAddress the targetProtocolAddress to set
*/
@@ -200,7 +199,7 @@
this.targetProtocolAddress = targetProtocolAddress;
return this;
}
-
+
public ARP setTargetProtocolAddress(int address) {
this.targetProtocolAddress = ByteBuffer.allocate(4).putInt(address).array();
return this;
diff --git a/src/main/java/net/onrc/onos/core/packet/BPDU.java b/src/main/java/net/onrc/onos/core/packet/BPDU.java
index 1dc7296..583eeff 100644
--- a/src/main/java/net/onrc/onos/core/packet/BPDU.java
+++ b/src/main/java/net/onrc/onos/core/packet/BPDU.java
@@ -1,19 +1,19 @@
/**
-* 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
-*
-* 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.
-**/
+ * 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
+ *
+ * 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 net.onrc.onos.core.packet;
@@ -22,6 +22,7 @@
/**
* This class is a Rapid Spanning Tree Protocol
* Bridge Protocol Data Unit
+ *
* @author alexreimers
*/
public class BPDU extends BasePacket {
@@ -29,9 +30,9 @@
CONFIG,
TOPOLOGY_CHANGE;
}
-
+
private final long destMac = 0x0180c2000000L; // 01-80-c2-00-00-00
-
+
// TODO - check this for RSTP
private LLC llcHeader;
private short protocolId = 0;
@@ -46,17 +47,17 @@
private short maxAge; // 256ths of a second
private short helloTime; // 256ths of a second
private short forwardDelay; // 256ths of a second
-
+
public BPDU(BPDUType type) {
rootBridgeId = new byte[8];
senderBridgeId = new byte[8];
-
+
llcHeader = new LLC();
llcHeader.setDsap((byte) 0x42);
llcHeader.setSsap((byte) 0x42);
llcHeader.setCtrl((byte) 0x03);
-
- switch(type) {
+
+ switch (type) {
case CONFIG:
this.type = 0x0;
break;
@@ -68,19 +69,19 @@
break;
}
}
-
+
@Override
public byte[] serialize() {
byte[] data;
// TODO check these
- if (type == 0x0) {
+ if (type == 0x0) {
// config
data = new byte[38];
} else {
// topology change
data = new byte[7]; // LLC + TC notification
}
-
+
ByteBuffer bb = ByteBuffer.wrap(data);
// Serialize the LLC header
byte[] llc = llcHeader.serialize();
@@ -88,7 +89,7 @@
bb.putShort(protocolId);
bb.put(version);
bb.put(type);
-
+
if (type == 0x0) {
bb.put(flags);
bb.put(rootBridgeId, 0, rootBridgeId.length);
@@ -100,21 +101,21 @@
bb.putShort(helloTime);
bb.putShort(forwardDelay);
}
-
+
return data;
}
@Override
public IPacket deserialize(byte[] data, int offset, int length) {
ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
-
+
// LLC header
llcHeader.deserialize(data, offset, 3);
-
+
this.protocolId = bb.getShort();
this.version = bb.get();
this.type = bb.get();
-
+
// These fields only exist if it's a configuration BPDU
if (this.type == 0x0) {
this.flags = bb.get();
@@ -128,7 +129,7 @@
this.forwardDelay = bb.getShort();
}
// TODO should we set other fields to 0?
-
+
return this;
}
diff --git a/src/main/java/net/onrc/onos/core/packet/BSN.java b/src/main/java/net/onrc/onos/core/packet/BSN.java
index fead254..dedabd5 100644
--- a/src/main/java/net/onrc/onos/core/packet/BSN.java
+++ b/src/main/java/net/onrc/onos/core/packet/BSN.java
@@ -1,21 +1,21 @@
/**
-* Copyright 2012, Big Switch Networks, Inc.
-*
-* 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.
-**/
+ * Copyright 2012, Big Switch Networks, Inc.
+ *
+ * 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 net.onrc.onos.core.packet;
@@ -25,72 +25,71 @@
/**
* @author Shudong Zhou (shudong.zhou@bigswitch.com)
- *
*/
public class BSN extends BasePacket {
- public static final int BSN_MAGIC = 0x20000604;
- public static final short BSN_VERSION_CURRENT = 0x0;
- public static final short BSN_TYPE_PROBE = 0x1;
- public static final short BSN_TYPE_BDDP = 0x2;
- public static Map<Short, Class<? extends IPacket>> typeClassMap;
-
+ public static final int BSN_MAGIC = 0x20000604;
+ public static final short BSN_VERSION_CURRENT = 0x0;
+ public static final short BSN_TYPE_PROBE = 0x1;
+ public static final short BSN_TYPE_BDDP = 0x2;
+ public static Map<Short, Class<? extends IPacket>> typeClassMap;
+
static {
typeClassMap = new HashMap<Short, Class<? extends IPacket>>();
typeClassMap.put(BSN_TYPE_PROBE, BSNPROBE.class);
typeClassMap.put(BSN_TYPE_BDDP, LLDP.class);
}
- protected short type;
- protected short version;
+ protected short type;
+ protected short version;
- public BSN() {
- version = BSN_VERSION_CURRENT;
- }
-
+ public BSN() {
+ version = BSN_VERSION_CURRENT;
+ }
+
public BSN(short type) {
- this.type = type;
- version = BSN_VERSION_CURRENT;
+ this.type = type;
+ version = BSN_VERSION_CURRENT;
}
public short getType() {
- return type;
- }
+ return type;
+ }
- public BSN setType(short type) {
- this.type = type;
- return this;
- }
-
+ public BSN setType(short type) {
+ this.type = type;
+ return this;
+ }
+
public short getVersion() {
- return version;
- }
+ return version;
+ }
- public BSN setVersion(short version) {
- this.version = version;
- return this;
- }
+ public BSN setVersion(short version) {
+ this.version = version;
+ return this;
+ }
@Override
public byte[] serialize() {
- short length = 4 /* magic */ + 2 /* type */ + 2 /* version */;
-
- byte[] payloadData = null;
- if (this.payload != null) {
+ short length = 4 /* magic */ + 2 /* type */ + 2 /* version */;
+
+ byte[] payloadData = null;
+ if (this.payload != null) {
payload.setParent(this);
payloadData = payload.serialize();
length += payloadData.length;
}
-
+
byte[] data = new byte[length];
ByteBuffer bb = ByteBuffer.wrap(data);
bb.putInt(BSN_MAGIC);
bb.putShort(this.type);
bb.putShort(this.version);
if (payloadData != null)
- bb.put(payloadData);
+ bb.put(payloadData);
if (this.parent != null && this.parent instanceof Ethernet)
- ((Ethernet)this.parent).setEtherType(Ethernet.TYPE_BSN);
+ ((Ethernet) this.parent).setEtherType(Ethernet.TYPE_BSN);
return data;
}
@@ -98,20 +97,20 @@
@Override
public IPacket deserialize(byte[] data, int offset, int length) {
ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
-
+
int magic = bb.getInt();
if (magic != BSN_MAGIC) {
- throw new RuntimeException("Invalid BSN magic " + magic);
+ throw new RuntimeException("Invalid BSN magic " + magic);
}
-
+
this.type = bb.getShort();
this.version = bb.getShort();
if (this.version != BSN_VERSION_CURRENT) {
- throw new RuntimeException(
- "Invalid BSN packet version " + this.version + ", should be "
- + BSN_VERSION_CURRENT);
+ throw new RuntimeException(
+ "Invalid BSN packet version " + this.version + ", should be "
+ + BSN_VERSION_CURRENT);
}
-
+
IPacket payload;
if (typeClassMap.containsKey(this.type)) {
Class<? extends IPacket> clazz = typeClassMap.get(this.type);
@@ -123,11 +122,11 @@
} else {
payload = new Data();
}
-
+
this.payload = new Data();
this.payload = payload.deserialize(data, bb.position(), bb.limit() - bb.position());
this.payload.setParent(this);
-
+
return this;
}
@@ -156,17 +155,17 @@
return false;
BSN other = (BSN) obj;
return (type == other.type &&
- version == other.version);
+ version == other.version);
}
-
+
public String toString() {
- StringBuffer sb = new StringBuffer("\n");
- sb.append("BSN packet");
+ StringBuffer sb = new StringBuffer("\n");
+ sb.append("BSN packet");
if (typeClassMap.containsKey(this.type))
- sb.append(" type: " + typeClassMap.get(this.type).getCanonicalName());
+ sb.append(" type: " + typeClassMap.get(this.type).getCanonicalName());
else
- sb.append(" type: " + this.type);
-
- return sb.toString();
+ sb.append(" type: " + this.type);
+
+ return sb.toString();
}
}
diff --git a/src/main/java/net/onrc/onos/core/packet/BSNPROBE.java b/src/main/java/net/onrc/onos/core/packet/BSNPROBE.java
index 24dbe90..e411b7e 100644
--- a/src/main/java/net/onrc/onos/core/packet/BSNPROBE.java
+++ b/src/main/java/net/onrc/onos/core/packet/BSNPROBE.java
@@ -1,21 +1,21 @@
/**
-* Copyright 2012, Big Switch Networks, Inc.
-*
-* 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.
-**/
+ * Copyright 2012, Big Switch Networks, Inc.
+ *
+ * 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 net.onrc.onos.core.packet;
@@ -26,15 +26,14 @@
/**
* @author Shudong Zhou (shudong.zhou@bigswitch.com)
- *
*/
-public class BSNPROBE extends BasePacket {
- protected long controllerId;
- protected int sequenceId;
- protected byte[] srcMac;
- protected byte[] dstMac;
- protected long srcSwDpid;
- protected int srcPortNo;
+public class BSNPROBE extends BasePacket {
+ protected long controllerId;
+ protected int sequenceId;
+ protected byte[] srcMac;
+ protected byte[] dstMac;
+ protected long srcSwDpid;
+ protected int srcPortNo;
public BSNPROBE() {
srcMac = new byte[6];
@@ -42,24 +41,24 @@
}
- public long getControllerId() {
- return this.controllerId;
- }
+ public long getControllerId() {
+ return this.controllerId;
+ }
- public BSNPROBE setControllerId(long controllerId) {
- this.controllerId = controllerId;
- return this;
- }
+ public BSNPROBE setControllerId(long controllerId) {
+ this.controllerId = controllerId;
+ return this;
+ }
- public int getSequenceId() {
- return sequenceId;
- }
+ public int getSequenceId() {
+ return sequenceId;
+ }
- public BSNPROBE setSequenceId(int sequenceId) {
- this.sequenceId = sequenceId;
- return this;
- }
-
+ public BSNPROBE setSequenceId(int sequenceId) {
+ this.sequenceId = sequenceId;
+ return this;
+ }
+
public byte[] getSrcMac() {
return this.srcMac;
}
@@ -68,46 +67,46 @@
this.srcMac = srcMac;
return this;
}
-
- public byte[] getDstMac() {
- return dstMac;
- }
- public BSNPROBE setDstMac(byte[] dstMac) {
- this.dstMac = dstMac;
- return this;
- }
+ public byte[] getDstMac() {
+ return dstMac;
+ }
- public long getSrcSwDpid() {
- return srcSwDpid;
- }
+ public BSNPROBE setDstMac(byte[] dstMac) {
+ this.dstMac = dstMac;
+ return this;
+ }
- public BSNPROBE setSrcSwDpid(long srcSwDpid) {
- this.srcSwDpid = srcSwDpid;
- return this;
- }
+ public long getSrcSwDpid() {
+ return srcSwDpid;
+ }
- public int getSrcPortNo() {
- return srcPortNo;
- }
+ public BSNPROBE setSrcSwDpid(long srcSwDpid) {
+ this.srcSwDpid = srcSwDpid;
+ return this;
+ }
- public BSNPROBE setSrcPortNo(int srcPortNo) {
- this.srcPortNo = srcPortNo;
- return this;
- }
+ public int getSrcPortNo() {
+ return srcPortNo;
+ }
+
+ public BSNPROBE setSrcPortNo(int srcPortNo) {
+ this.srcPortNo = srcPortNo;
+ return this;
+ }
@Override
public byte[] serialize() {
- short length = 8 /* controllerId */ + 4 /* seqId */
- + 12 /* srcMac dstMac */ + 8 /* srcSwDpid */ + 4 /* srcPortNo */;
-
- byte[] payloadData = null;
- if (this.payload != null) {
+ short length = 8 /* controllerId */ + 4 /* seqId */
+ + 12 /* srcMac dstMac */ + 8 /* srcSwDpid */ + 4 /* srcPortNo */;
+
+ byte[] payloadData = null;
+ if (this.payload != null) {
payload.setParent(this);
payloadData = payload.serialize();
length += payloadData.length;
}
-
+
byte[] data = new byte[length];
ByteBuffer bb = ByteBuffer.wrap(data);
bb.putLong(this.controllerId);
@@ -117,10 +116,10 @@
bb.putLong(this.srcSwDpid);
bb.putInt(this.srcPortNo);
if (payloadData != null)
- bb.put(payloadData);
+ bb.put(payloadData);
if (this.parent != null && this.parent instanceof BSN)
- ((BSN)this.parent).setType(BSN.BSN_TYPE_PROBE);
+ ((BSN) this.parent).setType(BSN.BSN_TYPE_PROBE);
return data;
}
@@ -128,20 +127,20 @@
@Override
public IPacket deserialize(byte[] data, int offset, int length) {
ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
-
+
controllerId = bb.getLong();
sequenceId = bb.getInt();
bb.get(this.srcMac, 0, 6);
bb.get(this.dstMac, 0, 6);
this.srcSwDpid = bb.getLong();
this.srcPortNo = bb.getInt();
-
+
if (bb.hasRemaining()) {
- this.payload = new Data();
- this.payload = payload.deserialize(data, bb.position(), bb.limit() - bb.position());
- this.payload.setParent(this);
+ this.payload = new Data();
+ this.payload = payload.deserialize(data, bb.position(), bb.limit() - bb.position());
+ this.payload.setParent(this);
}
-
+
return this;
}
@@ -174,25 +173,25 @@
if (!Arrays.equals(srcMac, other.srcMac))
return false;
if (!Arrays.equals(dstMac, other.dstMac))
- return false;
+ return false;
return (sequenceId == other.sequenceId &&
- srcSwDpid == other.srcSwDpid &&
- srcPortNo == other.srcPortNo
- );
+ srcSwDpid == other.srcSwDpid &&
+ srcPortNo == other.srcPortNo
+ );
}
-
+
public String toString() {
- StringBuffer sb = new StringBuffer("\n");
- sb.append("BSN Probe packet");
- sb.append("\nSource Mac: ");
- sb.append(HexString.toHexString(srcMac));
- sb.append("\nDestination Mac: ");
- sb.append(HexString.toHexString(dstMac));
- sb.append("\nSource Switch: ");
- sb.append(HexString.toHexString(srcSwDpid));
- sb.append(" port: " + srcPortNo);
- sb.append("\nSequence No.:" + sequenceId);
-
- return sb.toString();
+ StringBuffer sb = new StringBuffer("\n");
+ sb.append("BSN Probe packet");
+ sb.append("\nSource Mac: ");
+ sb.append(HexString.toHexString(srcMac));
+ sb.append("\nDestination Mac: ");
+ sb.append(HexString.toHexString(dstMac));
+ sb.append("\nSource Switch: ");
+ sb.append(HexString.toHexString(srcSwDpid));
+ sb.append(" port: " + srcPortNo);
+ sb.append("\nSequence No.:" + sequenceId);
+
+ return sb.toString();
}
}
diff --git a/src/main/java/net/onrc/onos/core/packet/BasePacket.java b/src/main/java/net/onrc/onos/core/packet/BasePacket.java
index d3b382b..4f4f478 100644
--- a/src/main/java/net/onrc/onos/core/packet/BasePacket.java
+++ b/src/main/java/net/onrc/onos/core/packet/BasePacket.java
@@ -1,27 +1,26 @@
/**
-* 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
-*
-* 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.
-**/
+ * 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
+ *
+ * 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 net.onrc.onos.core.packet;
/**
-*
-* @author David Erickson (daviderickson@cs.stanford.edu)
-*/
+ * @author David Erickson (daviderickson@cs.stanford.edu)
+ */
public abstract class BasePacket implements IPacket {
protected IPacket parent;
protected IPacket payload;
@@ -59,7 +58,7 @@
this.payload = payload;
return this;
}
-
+
@Override
public void resetChecksum() {
if (this.parent != null)
@@ -96,7 +95,7 @@
return false;
return true;
}
-
+
@Override
public Object clone() {
IPacket pkt;
diff --git a/src/main/java/net/onrc/onos/core/packet/DHCP.java b/src/main/java/net/onrc/onos/core/packet/DHCP.java
index 16cc22f..ee3052b 100644
--- a/src/main/java/net/onrc/onos/core/packet/DHCP.java
+++ b/src/main/java/net/onrc/onos/core/packet/DHCP.java
@@ -1,19 +1,19 @@
/**
-* 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
-*
-* 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.
-**/
+ * 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
+ *
+ * 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 net.onrc.onos.core.packet;
@@ -24,7 +24,6 @@
import java.util.ListIterator;
/**
- *
* @author David Erickson (daviderickson@cs.stanford.edu)
*/
public class DHCP extends BasePacket {
@@ -52,7 +51,6 @@
* ------------------------------------------
* | options (312) |
* ------------------------------------------
- *
*/
// Header + magic without options
public static int MIN_HEADER_LENGTH = 240;
@@ -60,30 +58,30 @@
public static byte OPCODE_REPLY = 0x2;
public static byte HWTYPE_ETHERNET = 0x1;
-
+
public enum DHCPOptionCode {
- OptionCode_SubnetMask ((byte)1),
- OptionCode_RequestedIP ((byte)50),
- OptionCode_LeaseTime ((byte)51),
- OptionCode_MessageType ((byte)53),
- OptionCode_DHCPServerIp ((byte)54),
- OptionCode_RequestedParameters ((byte)55),
- OptionCode_RenewalTime ((byte)58),
- OPtionCode_RebindingTime ((byte)59),
- OptionCode_ClientID ((byte)61),
- OptionCode_END ((byte)255);
-
+ OptionCode_SubnetMask((byte) 1),
+ OptionCode_RequestedIP((byte) 50),
+ OptionCode_LeaseTime((byte) 51),
+ OptionCode_MessageType((byte) 53),
+ OptionCode_DHCPServerIp((byte) 54),
+ OptionCode_RequestedParameters((byte) 55),
+ OptionCode_RenewalTime((byte) 58),
+ OPtionCode_RebindingTime((byte) 59),
+ OptionCode_ClientID((byte) 61),
+ OptionCode_END((byte) 255);
+
protected byte value;
-
+
private DHCPOptionCode(byte value) {
this.value = value;
}
-
+
public byte getValue() {
return value;
}
}
-
+
protected byte opCode;
protected byte hardwareType;
protected byte hardwareAddressLength;
@@ -279,9 +277,10 @@
this.clientHardwareAddress = clientHardwareAddress;
return this;
}
-
+
/**
* Gets a specific DHCP option parameter
+ *
* @param opetionCode The option code to get
* @return The value of the option if it exists, null otherwise
*/
@@ -322,7 +321,7 @@
}
return null;
}
-
+
/**
* @return the serverName
*/
@@ -364,14 +363,14 @@
if (option.getCode() == 0 || option.getCode() == 255) {
optionsLength += 1;
} else {
- optionsLength += 2 + (int)(0xff & option.getLength());
+ optionsLength += 2 + (int) (0xff & option.getLength());
}
}
int optionsPadLength = 0;
if (optionsLength < 60)
optionsPadLength = 60 - optionsLength;
- byte[] data = new byte[240+optionsLength+optionsPadLength];
+ byte[] data = new byte[240 + optionsLength + optionsPadLength];
ByteBuffer bb = ByteBuffer.wrap(data);
bb.put(this.opCode);
bb.put(this.hardwareType);
@@ -417,7 +416,7 @@
} else {
byte[] bytes = null;
try {
- bytes = string.getBytes("ascii");
+ bytes = string.getBytes("ascii");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Failure encoding server name", e);
}
@@ -438,7 +437,7 @@
if (bb.remaining() < MIN_HEADER_LENGTH) {
return this;
}
-
+
this.opCode = bb.get();
this.hardwareType = bb.get();
this.hardwareAddressLength = bb.get();
@@ -483,13 +482,13 @@
} else {
// Skip the invalid option and set the END option
code = 0xff;
- option.setCode((byte)code);
+ option.setCode((byte) code);
option.setLength((byte) 0);
}
} else {
// Skip the invalid option and set the END option
code = 0xff;
- option.setCode((byte)code);
+ option.setCode((byte) code);
option.setLength((byte) 0);
}
}
diff --git a/src/main/java/net/onrc/onos/core/packet/DHCPOption.java b/src/main/java/net/onrc/onos/core/packet/DHCPOption.java
index 4681e0b..7c56a34 100644
--- a/src/main/java/net/onrc/onos/core/packet/DHCPOption.java
+++ b/src/main/java/net/onrc/onos/core/packet/DHCPOption.java
@@ -1,26 +1,25 @@
/**
-* 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
-*
-* 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.
-**/
+ * 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
+ *
+ * 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 net.onrc.onos.core.packet;
import java.util.Arrays;
/**
- *
* @author David Erickson (daviderickson@cs.stanford.edu)
*/
public class DHCPOption {
diff --git a/src/main/java/net/onrc/onos/core/packet/DHCPPacketType.java b/src/main/java/net/onrc/onos/core/packet/DHCPPacketType.java
index d68c22f..9d83c15 100644
--- a/src/main/java/net/onrc/onos/core/packet/DHCPPacketType.java
+++ b/src/main/java/net/onrc/onos/core/packet/DHCPPacketType.java
@@ -1,55 +1,55 @@
/**
-* 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
-*
-* 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.
-**/
+ * 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
+ *
+ * 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 net.onrc.onos.core.packet;
public enum DHCPPacketType {
// From RFC 1533
- DHCPDISCOVER (1),
- DHCPOFFER (2),
- DHCPREQUEST (3),
- DHCPDECLINE (4),
- DHCPACK (5),
- DHCPNAK (6),
- DHCPRELEASE (7),
-
+ DHCPDISCOVER(1),
+ DHCPOFFER(2),
+ DHCPREQUEST(3),
+ DHCPDECLINE(4),
+ DHCPACK(5),
+ DHCPNAK(6),
+ DHCPRELEASE(7),
+
// From RFC2132
- DHCPINFORM (8),
-
+ DHCPINFORM(8),
+
// From RFC3203
- DHCPFORCERENEW (9),
-
+ DHCPFORCERENEW(9),
+
// From RFC4388
- DHCPLEASEQUERY (10),
- DHCPLEASEUNASSIGNED (11),
- DHCPLEASEUNKNOWN (12),
- DHCPLEASEACTIVE (13);
-
+ DHCPLEASEQUERY(10),
+ DHCPLEASEUNASSIGNED(11),
+ DHCPLEASEUNKNOWN(12),
+ DHCPLEASEACTIVE(13);
+
protected int value;
-
+
private DHCPPacketType(int value) {
this.value = value;
}
-
+
public int getValue() {
return value;
}
-
- public String toString(){
+
+ public String toString() {
switch (value) {
case 1:
return "DHCPDISCOVER";
@@ -78,9 +78,10 @@
case 13:
return "DHCPLEASEACTIVE";
}
-
+
return null;
}
+
public static DHCPPacketType getType(int value) {
switch (value) {
case 1:
@@ -110,7 +111,7 @@
case 13:
return DHCPLEASEACTIVE;
}
-
+
return null;
}
}
diff --git a/src/main/java/net/onrc/onos/core/packet/Data.java b/src/main/java/net/onrc/onos/core/packet/Data.java
index e8617ad..f6f9138 100644
--- a/src/main/java/net/onrc/onos/core/packet/Data.java
+++ b/src/main/java/net/onrc/onos/core/packet/Data.java
@@ -1,33 +1,32 @@
/**
-* 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
-*
-* 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.
-**/
+ * 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
+ *
+ * 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 net.onrc.onos.core.packet;
import java.util.Arrays;
/**
- *
* @author David Erickson (daviderickson@cs.stanford.edu)
*/
public class Data extends BasePacket {
protected byte[] data;
/**
- *
+ *
*/
public Data() {
}
diff --git a/src/main/java/net/onrc/onos/core/packet/Ethernet.java b/src/main/java/net/onrc/onos/core/packet/Ethernet.java
index 794b3b7..8a4b0fb 100644
--- a/src/main/java/net/onrc/onos/core/packet/Ethernet.java
+++ b/src/main/java/net/onrc/onos/core/packet/Ethernet.java
@@ -1,19 +1,19 @@
/**
-* 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
-*
-* 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.
-**/
+ * 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
+ *
+ * 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 net.onrc.onos.core.packet;
@@ -27,7 +27,6 @@
import org.openflow.util.HexString;
/**
- *
* @author David Erickson (daviderickson@cs.stanford.edu)
*/
public class Ethernet extends BasePacket {
@@ -37,7 +36,7 @@
public static final short TYPE_IPv4 = 0x0800;
public static final short TYPE_LLDP = (short) 0x88cc;
public static final short TYPE_BSN = (short) 0x8942;
- public static final short VLAN_UNTAGGED = (short)0xffff;
+ public static final short VLAN_UNTAGGED = (short) 0xffff;
public static final short DATALAYER_ADDRESS_LENGTH = 6; // bytes
public static Map<Short, Class<? extends IPacket>> etherTypeClassMap;
@@ -64,14 +63,14 @@
super();
this.vlanID = VLAN_UNTAGGED;
}
-
+
/**
* @return the destination MAC as a byte array
*/
public byte[] getDestinationMACAddress() {
return destinationMACAddress.toBytes();
}
-
+
/**
* @return the destination MAC
*/
@@ -101,7 +100,7 @@
public byte[] getSourceMACAddress() {
return sourceMACAddress.toBytes();
}
-
+
/**
* @return the source MACAddress
*/
@@ -169,23 +168,25 @@
this.etherType = etherType;
return this;
}
-
+
/**
* @return True if the Ethernet frame is broadcast, false otherwise
*/
public boolean isBroadcast() {
- assert(destinationMACAddress.length() == 6);
+ assert (destinationMACAddress.length() == 6);
return destinationMACAddress.isBroadcast();
}
-
+
/**
* @return True is the Ethernet frame is multicast, False otherwise
*/
public boolean isMulticast() {
return destinationMACAddress.isMulticast();
}
+
/**
* Pad this packet to 60 bytes minimum, filling with zeros?
+ *
* @return the pad
*/
public boolean isPad() {
@@ -194,6 +195,7 @@
/**
* Pad this packet to 60 bytes minimum, filling with zeros?
+ *
* @param pad the pad to set
*/
public Ethernet setPad(boolean pad) {
@@ -208,7 +210,7 @@
payloadData = payload.serialize();
}
int length = 14 + ((vlanID == VLAN_UNTAGGED) ? 0 : 4) +
- ((payloadData == null) ? 0 : payloadData.length);
+ ((payloadData == null) ? 0 : payloadData.length);
if (pad && length < 60) {
length = 60;
}
@@ -224,7 +226,7 @@
if (payloadData != null)
bb.put(payloadData);
if (pad) {
- Arrays.fill(data, bb.position(), data.length, (byte)0x0);
+ Arrays.fill(data, bb.position(), data.length, (byte) 0x0);
}
return data;
}
@@ -256,7 +258,7 @@
this.vlanID = VLAN_UNTAGGED;
}
this.etherType = etherType;
-
+
IPacket payload;
if (Ethernet.etherTypeClassMap.containsKey(this.etherType)) {
Class<? extends IPacket> clazz = Ethernet.etherTypeClassMap.get(this.etherType);
@@ -268,13 +270,14 @@
} else {
payload = new Data();
}
- this.payload = payload.deserialize(data, bb.position(), bb.limit()-bb.position());
+ this.payload = payload.deserialize(data, bb.position(), bb.limit() - bb.position());
this.payload.setParent(this);
return this;
}
/**
* Checks to see if a string is a valid MAC address.
+ *
* @param macAddress
* @return True if macAddress is a valid MAC, False otherwise
*/
@@ -283,8 +286,8 @@
if (macBytes.length != 6)
return false;
for (int i = 0; i < 6; ++i) {
- if (HEXES.indexOf(macBytes[i].toUpperCase().charAt(0)) == -1 ||
- HEXES.indexOf(macBytes[i].toUpperCase().charAt(1)) == -1) {
+ if (HEXES.indexOf(macBytes[i].toUpperCase().charAt(0)) == -1 ||
+ HEXES.indexOf(macBytes[i].toUpperCase().charAt(1)) == -1) {
return false;
}
}
@@ -294,8 +297,9 @@
/**
* Accepts a MAC address of the form 00:aa:11:bb:22:cc, case does not
* matter, and returns a corresponding byte[].
+ *
* @param macAddress The MAC address to convert into a bye array
- * @return The macAddress as a byte array
+ * @return The macAddress as a byte array
*/
public static byte[] toMACAddress(String macAddress) {
return MACAddress.valueOf(macAddress).toBytes();
@@ -305,6 +309,7 @@
/**
* Accepts a MAC address and returns the corresponding long, where the
* MAC bytes are set on the lower order bytes of the long.
+ *
* @param macAddress
* @return a long containing the mac address bytes
*/
@@ -314,13 +319,14 @@
/**
* Convert a long MAC address to a byte array
+ *
* @param macAddress
* @return the bytes of the mac address
*/
public static byte[] toByteArray(long macAddress) {
return MACAddress.valueOf(macAddress).toBytes();
}
-
+
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@@ -363,7 +369,7 @@
return false;
return true;
}
-
+
/* (non-Javadoc)
* @see java.lang.Object#toString(java.lang.Object)
*/
@@ -384,7 +390,7 @@
sb.append("ip");
else if (pkt instanceof DHCP)
sb.append("dhcp");
- else sb.append(this.getEtherType());
+ else sb.append(this.getEtherType());
sb.append("\ndl_vlan: ");
if (this.getVlanID() == Ethernet.VLAN_UNTAGGED)
@@ -405,18 +411,15 @@
sb.append(IPv4.fromIPv4Address(IPv4.toIPv4Address(p.getSenderProtocolAddress())));
sb.append("\nnw_dst: ");
sb.append(IPv4.fromIPv4Address(IPv4.toIPv4Address(p.getTargetProtocolAddress())));
- }
- else if (pkt instanceof LLDP) {
+ } else if (pkt instanceof LLDP) {
sb.append("lldp packet");
- }
- else if (pkt instanceof ICMP) {
+ } else if (pkt instanceof ICMP) {
ICMP icmp = (ICMP) pkt;
sb.append("\nicmp_type: ");
sb.append(icmp.getIcmpType());
sb.append("\nicmp_code: ");
sb.append(icmp.getIcmpCode());
- }
- else if (pkt instanceof IPv4) {
+ } else if (pkt instanceof IPv4) {
IPv4 p = (IPv4) pkt;
sb.append("\nnw_src: ");
sb.append(IPv4.fromIPv4Address(p.getSourceAddress()));
@@ -448,20 +451,15 @@
sb.append(icmp.getIcmpCode());
}
- }
- else if (pkt instanceof DHCP) {
+ } else if (pkt instanceof DHCP) {
sb.append("\ndhcp packet");
- }
- else if (pkt instanceof Data) {
+ } else if (pkt instanceof Data) {
sb.append("\ndata packet");
- }
- else if (pkt instanceof LLC) {
+ } else if (pkt instanceof LLC) {
sb.append("\nllc packet");
- }
- else if (pkt instanceof BPDU) {
+ } else if (pkt instanceof BPDU) {
sb.append("\nbpdu packet");
- }
- else sb.append("\nunknwon packet");
+ } else sb.append("\nunknwon packet");
return sb.toString();
}
diff --git a/src/main/java/net/onrc/onos/core/packet/ICMP.java b/src/main/java/net/onrc/onos/core/packet/ICMP.java
index b575878..4b80c94 100644
--- a/src/main/java/net/onrc/onos/core/packet/ICMP.java
+++ b/src/main/java/net/onrc/onos/core/packet/ICMP.java
@@ -1,19 +1,19 @@
/**
-* 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
-*
-* 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.
-**/
+ * 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
+ *
+ * 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 net.onrc.onos.core.packet;
@@ -21,6 +21,7 @@
/**
* Implements ICMP packet format
+ *
* @author shudong.zhou@bigswitch.com
*/
public class ICMP extends BasePacket {
@@ -76,8 +77,8 @@
/**
* Serializes the packet. Will compute and set the following fields if they
* are set to specific values at the time serialize is called:
- * -checksum : 0
- * -length : 0
+ * -checksum : 0
+ * -length : 0
*/
public byte[] serialize() {
int length = 4;
@@ -98,7 +99,7 @@
bb.put(payloadData);
if (this.parent != null && this.parent instanceof IPv4)
- ((IPv4)this.parent).setProtocol(IPv4.PROTOCOL_ICMP);
+ ((IPv4) this.parent).setProtocol(IPv4.PROTOCOL_ICMP);
// compute checksum if needed
if (this.checksum == 0) {
@@ -161,9 +162,9 @@
this.icmpType = bb.get();
this.icmpCode = bb.get();
this.checksum = bb.getShort();
-
+
this.payload = new Data();
- this.payload = payload.deserialize(data, bb.position(), bb.limit()-bb.position());
+ this.payload = payload.deserialize(data, bb.position(), bb.limit() - bb.position());
this.payload.setParent(this);
return this;
}
diff --git a/src/main/java/net/onrc/onos/core/packet/IPacket.java b/src/main/java/net/onrc/onos/core/packet/IPacket.java
index 0cfc51f..8f31960 100644
--- a/src/main/java/net/onrc/onos/core/packet/IPacket.java
+++ b/src/main/java/net/onrc/onos/core/packet/IPacket.java
@@ -1,48 +1,43 @@
/**
-* 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
-*
-* 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.
-**/
+ * 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
+ *
+ * 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 net.onrc.onos.core.packet;
/**
-*
-* @author David Erickson (daviderickson@cs.stanford.edu)
-*/
+ * @author David Erickson (daviderickson@cs.stanford.edu)
+ */
public interface IPacket {
/**
- *
* @return
*/
public IPacket getPayload();
/**
- *
* @param packet
* @return
*/
public IPacket setPayload(IPacket packet);
/**
- *
* @return
*/
public IPacket getParent();
/**
- *
* @param packet
* @return
*/
@@ -52,25 +47,28 @@
* Reset any checksums as needed, and call resetChecksum on all parents
*/
public void resetChecksum();
-
+
/**
- * Sets all payloads parent packet if applicable, then serializes this
+ * Sets all payloads parent packet if applicable, then serializes this
* packet and all payloads
+ *
* @return a byte[] containing this packet and payloads
*/
public byte[] serialize();
/**
* Deserializes this packet layer and all possible payloads
+ *
* @param data
* @param offset offset to start deserializing from
* @param length length of the data to deserialize
* @return the deserialized data
*/
public IPacket deserialize(byte[] data, int offset, int length);
-
- /** Clone this packet and its payload packet but not its parent.
- *
+
+ /**
+ * Clone this packet and its payload packet but not its parent.
+ *
* @return
*/
public Object clone();
diff --git a/src/main/java/net/onrc/onos/core/packet/IPv4.java b/src/main/java/net/onrc/onos/core/packet/IPv4.java
index 7f9db1a..1195c7c 100644
--- a/src/main/java/net/onrc/onos/core/packet/IPv4.java
+++ b/src/main/java/net/onrc/onos/core/packet/IPv4.java
@@ -1,22 +1,22 @@
/**
-* 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
-*
-* 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.
-**/
+ * 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
+ *
+ * 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 net.onrc.onos.core.packet;
@@ -28,10 +28,9 @@
/**
* @author David Erickson (daviderickson@cs.stanford.edu)
- *
*/
public class IPv4 extends BasePacket {
- public static final int ADDRESS_LENGTH = 4;
+ public static final int ADDRESS_LENGTH = 4;
public static final byte PROTOCOL_ICMP = 0x1;
public static final byte PROTOCOL_TCP = 0x6;
public static final byte PROTOCOL_UDP = 0x11;
@@ -210,6 +209,7 @@
this.checksum = checksum;
return this;
}
+
@Override
public void resetChecksum() {
this.checksum = 0;
@@ -283,9 +283,9 @@
/**
* Serializes the packet. Will compute and set the following fields if they
* are set to specific values at the time serialize is called:
- * -checksum : 0
- * -headerLength : 0
- * -totalLength : 0
+ * -checksum : 0
+ * -headerLength : 0
+ * -totalLength : 0
*/
public byte[] serialize() {
byte[] payloadData = null;
@@ -372,7 +372,7 @@
} else {
payload = new Data();
}
- this.payload = payload.deserialize(data, bb.position(), bb.limit()-bb.position());
+ this.payload = payload.deserialize(data, bb.position(), bb.limit() - bb.position());
this.payload.setParent(this);
if (this.totalLength != length)
@@ -386,21 +386,22 @@
/**
* Accepts an IPv4 address of the form xxx.xxx.xxx.xxx, ie 192.168.0.1 and
* returns the corresponding 32 bit integer.
+ *
* @param ipAddress
* @return
*/
public static int toIPv4Address(String ipAddress) {
if (ipAddress == null)
throw new IllegalArgumentException("Specified IPv4 address must" +
- "contain 4 sets of numerical digits separated by periods");
+ "contain 4 sets of numerical digits separated by periods");
String[] octets = ipAddress.split("\\.");
- if (octets.length != 4)
+ if (octets.length != 4)
throw new IllegalArgumentException("Specified IPv4 address must" +
- "contain 4 sets of numerical digits separated by periods");
+ "contain 4 sets of numerical digits separated by periods");
int result = 0;
for (int i = 0; i < 4; ++i) {
- result |= Integer.valueOf(octets[i]) << ((3-i)*8);
+ result |= Integer.valueOf(octets[i]) << ((3 - i) * 8);
}
return result;
}
@@ -408,14 +409,15 @@
/**
* Accepts an IPv4 address in a byte array and returns the corresponding
* 32-bit integer value.
+ *
* @param ipAddress
* @return
*/
public static int toIPv4Address(byte[] ipAddress) {
int ip = 0;
for (int i = 0; i < 4; i++) {
- int t = (ipAddress[i] & 0xff) << ((3-i)*8);
- ip |= t;
+ int t = (ipAddress[i] & 0xff) << ((3 - i) * 8);
+ ip |= t;
}
return ip;
}
@@ -423,7 +425,7 @@
/**
* Accepts an IPv4 address and returns of string of the form xxx.xxx.xxx.xxx
* ie 192.168.0.1
- *
+ *
* @param ipAddress
* @return
*/
@@ -431,7 +433,7 @@
StringBuffer sb = new StringBuffer();
int result = 0;
for (int i = 0; i < 4; ++i) {
- result = (ipAddress >> ((3-i)*8)) & 0xff;
+ result = (ipAddress >> ((3 - i) * 8)) & 0xff;
sb.append(Integer.valueOf(result).toString());
if (i != 3)
sb.append(".");
@@ -443,7 +445,7 @@
* Accepts a collection of IPv4 addresses as integers and returns a single
* String useful in toString method's containing collections of IP
* addresses.
- *
+ *
* @param ipAddresses collection
* @return
*/
@@ -456,21 +458,22 @@
sb.append(fromIPv4Address(ip));
sb.append(",");
}
- sb.replace(sb.length()-1, sb.length(), "]");
+ sb.replace(sb.length() - 1, sb.length(), "]");
return sb.toString();
}
/**
* Accepts an IPv4 address of the form xxx.xxx.xxx.xxx, ie 192.168.0.1 and
* returns the corresponding byte array.
+ *
* @param ipAddress The IP address in the form xx.xxx.xxx.xxx.
* @return The IP address separated into bytes
*/
public static byte[] toIPv4AddressBytes(String ipAddress) {
String[] octets = ipAddress.split("\\.");
- if (octets.length != 4)
+ if (octets.length != 4)
throw new IllegalArgumentException("Specified IPv4 address must" +
- "contain 4 sets of numerical digits separated by periods");
+ "contain 4 sets of numerical digits separated by periods");
byte[] result = new byte[4];
for (int i = 0; i < 4; ++i) {
@@ -478,19 +481,20 @@
}
return result;
}
-
+
/**
* Accepts an IPv4 address in the form of an integer and
* returns the corresponding byte array.
+ *
* @param ipAddress The IP address as an integer.
* @return The IP address separated into bytes.
*/
public static byte[] toIPv4AddressBytes(int ipAddress) {
- return new byte[] {
- (byte)(ipAddress >>> 24),
- (byte)(ipAddress >>> 16),
- (byte)(ipAddress >>> 8),
- (byte)ipAddress};
+ return new byte[]{
+ (byte) (ipAddress >>> 24),
+ (byte) (ipAddress >>> 16),
+ (byte) (ipAddress >>> 8),
+ (byte) ipAddress};
}
/* (non-Javadoc)
diff --git a/src/main/java/net/onrc/onos/core/packet/LLC.java b/src/main/java/net/onrc/onos/core/packet/LLC.java
index c4f0c27..d809f12 100644
--- a/src/main/java/net/onrc/onos/core/packet/LLC.java
+++ b/src/main/java/net/onrc/onos/core/packet/LLC.java
@@ -1,19 +1,19 @@
/**
-* 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
-*
-* 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.
-**/
+ * 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
+ *
+ * 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 net.onrc.onos.core.packet;
@@ -22,14 +22,14 @@
/**
* This class represents an Link Local Control
* header that is used in Ethernet 802.3.
- * @author alexreimers
*
+ * @author alexreimers
*/
public class LLC extends BasePacket {
private byte dsap = 0;
private byte ssap = 0;
private byte ctrl = 0;
-
+
public byte getDsap() {
return dsap;
}
diff --git a/src/main/java/net/onrc/onos/core/packet/LLDP.java b/src/main/java/net/onrc/onos/core/packet/LLDP.java
index 307a052..0b0f9ec 100644
--- a/src/main/java/net/onrc/onos/core/packet/LLDP.java
+++ b/src/main/java/net/onrc/onos/core/packet/LLDP.java
@@ -1,22 +1,22 @@
/**
-* 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
-*
-* 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.
-**/
+ * 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
+ *
+ * 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 net.onrc.onos.core.packet;
@@ -26,7 +26,6 @@
/**
* @author David Erickson (daviderickson@cs.stanford.edu)
- *
*/
public class LLDP extends BasePacket {
protected LLDPTLV chassisId;
@@ -102,8 +101,8 @@
@Override
public byte[] serialize() {
- int length = 2+this.chassisId.getLength() + 2+this.portId.getLength() +
- 2+this.ttl.getLength() + 2;
+ int length = 2 + this.chassisId.getLength() + 2 + this.portId.getLength() +
+ 2 + this.ttl.getLength() + 2;
for (LLDPTLV tlv : this.optionalTLVList) {
length += 2 + tlv.getLength();
}
@@ -119,7 +118,7 @@
bb.putShort((short) 0); // End of LLDPDU
if (this.parent != null && this.parent instanceof Ethernet)
- ((Ethernet)this.parent).setEtherType(ethType);
+ ((Ethernet) this.parent).setEtherType(ethType);
return data;
}
diff --git a/src/main/java/net/onrc/onos/core/packet/LLDPOrganizationalTLV.java b/src/main/java/net/onrc/onos/core/packet/LLDPOrganizationalTLV.java
index f3cd655..beae222 100644
--- a/src/main/java/net/onrc/onos/core/packet/LLDPOrganizationalTLV.java
+++ b/src/main/java/net/onrc/onos/core/packet/LLDPOrganizationalTLV.java
@@ -39,13 +39,14 @@
/**
* Set the value of OUI.
+ *
* @param oui The value of OUI to be set.
* @return This LLDP Organizationally Specific TLV.
*/
public LLDPOrganizationalTLV setOUI(byte[] oui) {
if (oui.length != OUI_LENGTH) {
throw new IllegalArgumentException("The length of OUI must be " + OUI_LENGTH +
- ", but it is " + oui.length);
+ ", but it is " + oui.length);
}
this.oui = Arrays.copyOf(oui, oui.length);
return this;
@@ -53,6 +54,7 @@
/**
* Returns the value of the OUI.
+ *
* @return The value of the OUI .
*/
public byte[] getOUI() {
@@ -61,6 +63,7 @@
/**
* Set the value of sub type.
+ *
* @param subType The value of sub type to be set.
* @return This LLDP Organizationally Specific TLV.
*/
@@ -71,6 +74,7 @@
/**
* Returns the value of the sub type.
+ *
* @return The value of the sub type.
*/
public byte getSubType() {
@@ -79,6 +83,7 @@
/**
* Set the value of information string.
+ *
* @param infoString the byte array of the value of information string.
* @return This LLDP Organizationally Specific TLV.
*/
@@ -93,6 +98,7 @@
/**
* Set the value of information string.
* The String value is automatically converted into byte array with UTF-8 encoding.
+ *
* @param infoString the String value of information string.
* @return This LLDP Organizationally Specific TLV.
*/
@@ -103,6 +109,7 @@
/**
* Returns the value of information string.
+ *
* @return the value of information string.
*/
public byte[] getInfoString() {
@@ -159,7 +166,7 @@
return false;
}
- LLDPOrganizationalTLV other = (LLDPOrganizationalTLV)o;
+ LLDPOrganizationalTLV other = (LLDPOrganizationalTLV) o;
if (this.type != other.type) {
return false;
}
diff --git a/src/main/java/net/onrc/onos/core/packet/LLDPTLV.java b/src/main/java/net/onrc/onos/core/packet/LLDPTLV.java
index d7bcc68..7b852e2 100644
--- a/src/main/java/net/onrc/onos/core/packet/LLDPTLV.java
+++ b/src/main/java/net/onrc/onos/core/packet/LLDPTLV.java
@@ -1,19 +1,19 @@
/**
-* 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
-*
-* 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.
-**/
+ * 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
+ *
+ * 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 net.onrc.onos.core.packet;
@@ -21,8 +21,6 @@
import java.util.Arrays;
/**
- *
- *
* @author David Erickson (daviderickson@cs.stanford.edu)
*/
public class LLDPTLV {
@@ -80,7 +78,7 @@
// info string length 9 bits, each value == byte
// info string
short scratch = (short) (((0x7f & this.type) << 9) | (0x1ff & this.length));
- byte[] data = new byte[2+this.length];
+ byte[] data = new byte[2 + this.length];
ByteBuffer bb = ByteBuffer.wrap(data);
bb.putShort(scratch);
if (this.value != null)
diff --git a/src/main/java/net/onrc/onos/core/packet/TCP.java b/src/main/java/net/onrc/onos/core/packet/TCP.java
index 7eb78bd..ec74f46 100644
--- a/src/main/java/net/onrc/onos/core/packet/TCP.java
+++ b/src/main/java/net/onrc/onos/core/packet/TCP.java
@@ -1,26 +1,25 @@
/**
-* 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
-*
-* 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.
-**/
+ * 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
+ *
+ * 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 net.onrc.onos.core.packet;
import java.nio.ByteBuffer;
/**
- *
* @author shudong.zhou@bigswitch.com
*/
public class TCP extends BasePacket {
@@ -71,71 +70,86 @@
public short getChecksum() {
return checksum;
}
-
+
public int getSequence() {
return this.sequence;
}
+
public TCP setSequence(int seq) {
this.sequence = seq;
return this;
}
+
public int getAcknowledge() {
return this.acknowledge;
}
+
public TCP setAcknowledge(int ack) {
this.acknowledge = ack;
return this;
}
+
public byte getDataOffset() {
return this.dataOffset;
}
+
public TCP setDataOffset(byte offset) {
this.dataOffset = offset;
return this;
}
+
public short getFlags() {
return this.flags;
}
+
public TCP setFlags(short flags) {
this.flags = flags;
return this;
}
+
public short getWindowSize() {
return this.windowSize;
}
+
public TCP setWindowSize(short windowSize) {
this.windowSize = windowSize;
return this;
}
+
public short getTcpChecksum() {
return this.checksum;
}
+
public TCP setTcpChecksum(short checksum) {
this.checksum = checksum;
return this;
}
-
+
@Override
public void resetChecksum() {
this.checksum = 0;
super.resetChecksum();
}
-
+
public short getUrgentPointer(short urgentPointer) {
return this.urgentPointer;
}
+
public TCP setUrgentPointer(short urgentPointer) {
- this.urgentPointer= urgentPointer;
+ this.urgentPointer = urgentPointer;
return this;
}
+
public byte[] getOptions() {
return this.options;
}
+
public TCP setOptions(byte[] options) {
this.options = options;
this.dataOffset = (byte) ((20 + options.length + 3) >> 2);
return this;
}
+
/**
* @param checksum the checksum to set
*/
@@ -147,8 +161,8 @@
/**
* Serializes the packet. Will compute and set the following fields if they
* are set to specific values at the time serialize is called:
- * -checksum : 0
- * -length : 0
+ * -checksum : 0
+ * -length : 0
*/
public byte[] serialize() {
int length;
@@ -184,7 +198,7 @@
bb.put(payloadData);
if (this.parent != null && this.parent instanceof IPv4)
- ((IPv4)this.parent).setProtocol(IPv4.PROTOCOL_TCP);
+ ((IPv4) this.parent).setProtocol(IPv4.PROTOCOL_TCP);
// compute checksum if needed
if (this.checksum == 0) {
@@ -245,15 +259,15 @@
TCP other = (TCP) obj;
// May want to compare fields based on the flags set
return (checksum == other.checksum) &&
- (destinationPort == other.destinationPort) &&
- (sourcePort == other.sourcePort) &&
- (sequence == other.sequence) &&
- (acknowledge == other.acknowledge) &&
- (dataOffset == other.dataOffset) &&
- (flags == other.flags) &&
- (windowSize == other.windowSize) &&
- (urgentPointer == other.urgentPointer) &&
- (dataOffset == 5 || options.equals(other.options));
+ (destinationPort == other.destinationPort) &&
+ (sourcePort == other.sourcePort) &&
+ (sequence == other.sequence) &&
+ (acknowledge == other.acknowledge) &&
+ (dataOffset == other.dataOffset) &&
+ (flags == other.flags) &&
+ (windowSize == other.windowSize) &&
+ (urgentPointer == other.urgentPointer) &&
+ (dataOffset == 5 || options.equals(other.options));
}
@Override
@@ -271,7 +285,7 @@
this.urgentPointer = bb.getShort();
if (this.dataOffset > 5) {
int optLength = (dataOffset << 2) - 20;
- if (bb.limit() < bb.position()+optLength) {
+ if (bb.limit() < bb.position() + optLength) {
optLength = bb.limit() - bb.position();
}
try {
@@ -281,9 +295,9 @@
this.options = null;
}
}
-
+
this.payload = new Data();
- this.payload = payload.deserialize(data, bb.position(), bb.limit()-bb.position());
+ this.payload = payload.deserialize(data, bb.position(), bb.limit() - bb.position());
this.payload.setParent(this);
return this;
}
diff --git a/src/main/java/net/onrc/onos/core/packet/UDP.java b/src/main/java/net/onrc/onos/core/packet/UDP.java
index 950afaf..6b7cee6 100644
--- a/src/main/java/net/onrc/onos/core/packet/UDP.java
+++ b/src/main/java/net/onrc/onos/core/packet/UDP.java
@@ -1,19 +1,19 @@
/**
-* 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
-*
-* 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.
-**/
+ * 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
+ *
+ * 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 net.onrc.onos.core.packet;
@@ -22,13 +22,12 @@
import java.util.Map;
/**
- *
* @author David Erickson (daviderickson@cs.stanford.edu)
*/
public class UDP extends BasePacket {
public static Map<Short, Class<? extends IPacket>> decodeMap;
- public static short DHCP_SERVER_PORT = (short)67;
- public static short DHCP_CLIENT_PORT = (short)68;
+ public static short DHCP_SERVER_PORT = (short) 67;
+ public static short DHCP_CLIENT_PORT = (short) 68;
static {
decodeMap = new HashMap<Short, Class<? extends IPacket>>();
@@ -37,7 +36,7 @@
*/
UDP.decodeMap.put(DHCP_SERVER_PORT, DHCP.class);
UDP.decodeMap.put(DHCP_CLIENT_PORT, DHCP.class);
-
+
}
protected short sourcePort;
@@ -106,8 +105,8 @@
/**
* Serializes the packet. Will compute and set the following fields if they
* are set to specific values at the time serialize is called:
- * -checksum : 0
- * -length : 0
+ * -checksum : 0
+ * -length : 0
*/
public byte[] serialize() {
byte[] payloadData = null;
@@ -130,7 +129,7 @@
bb.put(payloadData);
if (this.parent != null && this.parent instanceof IPv4)
- ((IPv4)this.parent).setProtocol(IPv4.PROTOCOL_UDP);
+ ((IPv4) this.parent).setProtocol(IPv4.PROTOCOL_UDP);
// compute checksum if needed
if (this.checksum == 0) {
@@ -224,7 +223,7 @@
} else {
this.payload = new Data();
}
- this.payload = payload.deserialize(data, bb.position(), bb.limit()-bb.position());
+ this.payload = payload.deserialize(data, bb.position(), bb.limit() - bb.position());
this.payload.setParent(this);
return this;
}