Skip to content
Snippets Groups Projects
Commit 15982261 authored by Shudong Zhou's avatar Shudong Zhou
Browse files

Revised PacketParsingException class

parent b7f0b0b6
No related branches found
No related tags found
No related merge requests found
...@@ -233,18 +233,14 @@ public class ARP extends BasePacket { ...@@ -233,18 +233,14 @@ public class ARP extends BasePacket {
this.hardwareAddressLength = bb.get(); this.hardwareAddressLength = bb.get();
this.protocolAddressLength = bb.get(); this.protocolAddressLength = bb.get();
if (this.hardwareAddressLength != 6) { if (this.hardwareAddressLength != 6) {
if (log.isTraceEnabled()) { String msg = "Incorrect ARP hardware address length: " +
log.trace("Incorrect ARP hardware address length: {}", hardwareAddressLength;
hardwareAddressLength); throw new PacketParsingException(msg);
}
throw new PacketParsingException();
} }
if (this.protocolAddressLength != 4) { if (this.protocolAddressLength != 4) {
if (log.isTraceEnabled()) { String msg = "Incorrect ARP protocol address length: " +
log.trace("Incorrect ARP protocol address length: {}", protocolAddressLength;
protocolAddressLength); throw new PacketParsingException(msg);
}
throw new PacketParsingException();
} }
this.opCode = bb.getShort(); this.opCode = bb.getShort();
this.senderHardwareAddress = new byte[0xff & this.hardwareAddressLength]; this.senderHardwareAddress = new byte[0xff & this.hardwareAddressLength];
......
...@@ -102,13 +102,13 @@ public class BSN extends BasePacket { ...@@ -102,13 +102,13 @@ public class BSN extends BasePacket {
int magic = bb.getInt(); int magic = bb.getInt();
if (magic != BSN_MAGIC) { if (magic != BSN_MAGIC) {
throw new RuntimeException("Invalid BSN magic " + magic); throw new PacketParsingException("Invalid BSN magic " + magic);
} }
this.type = bb.getShort(); this.type = bb.getShort();
this.version = bb.getShort(); this.version = bb.getShort();
if (this.version != BSN_VERSION_CURRENT) { if (this.version != BSN_VERSION_CURRENT) {
throw new RuntimeException( throw new PacketParsingException(
"Invalid BSN packet version " + this.version + ", should be " "Invalid BSN packet version " + this.version + ", should be "
+ BSN_VERSION_CURRENT); + BSN_VERSION_CURRENT);
} }
......
...@@ -362,7 +362,8 @@ public class IPv4 extends BasePacket { ...@@ -362,7 +362,8 @@ public class IPv4 extends BasePacket {
this.headerLength = (byte) (this.version & 0xf); this.headerLength = (byte) (this.version & 0xf);
this.version = (byte) ((this.version >> 4) & 0xf); this.version = (byte) ((this.version >> 4) & 0xf);
if (this.version != 4) { if (this.version != 4) {
throw new RuntimeException("Invalid version for IPv4 packet: " + throw new PacketParsingException(
"Invalid version for IPv4 packet: " +
this.version); this.version);
} }
this.diffServ = bb.get(); this.diffServ = bb.get();
......
...@@ -18,6 +18,10 @@ package net.floodlightcontroller.packet; ...@@ -18,6 +18,10 @@ package net.floodlightcontroller.packet;
public class PacketParsingException extends Exception { public class PacketParsingException extends Exception {
public PacketParsingException(String msg) {
super(msg);
}
private static final long serialVersionUID = -1177841297678875573L; private static final long serialVersionUID = -1177841297678875573L;
} }
\ No newline at end of file
...@@ -268,7 +268,7 @@ public class TCP extends BasePacket { ...@@ -268,7 +268,7 @@ public class TCP extends BasePacket {
this.flags = bb.getShort(); this.flags = bb.getShort();
this.dataOffset = (byte) ((this.flags >> 12) & 0xf); this.dataOffset = (byte) ((this.flags >> 12) & 0xf);
if (this.dataOffset < 5) { if (this.dataOffset < 5) {
throw new RuntimeException("Invalid tcp header length < 20"); throw new PacketParsingException("Invalid tcp header length < 20");
} }
this.flags = (short) (this.flags & 0x1ff); this.flags = (short) (this.flags & 0x1ff);
this.windowSize = bb.getShort(); this.windowSize = bb.getShort();
......
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