From 15982261aa85ed746c014bc28aa57ecd100df781 Mon Sep 17 00:00:00 2001 From: Shudong Zhou <shudongzhou@gmail.com> Date: Tue, 25 Jun 2013 15:09:01 -0700 Subject: [PATCH] Revised PacketParsingException class --- .../net/floodlightcontroller/packet/ARP.java | 16 ++++++---------- .../net/floodlightcontroller/packet/BSN.java | 4 ++-- .../net/floodlightcontroller/packet/IPv4.java | 3 ++- .../packet/PacketParsingException.java | 6 +++++- .../net/floodlightcontroller/packet/TCP.java | 2 +- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/floodlightcontroller/packet/ARP.java b/src/main/java/net/floodlightcontroller/packet/ARP.java index e6a19ef2b..bf3f49385 100644 --- a/src/main/java/net/floodlightcontroller/packet/ARP.java +++ b/src/main/java/net/floodlightcontroller/packet/ARP.java @@ -233,18 +233,14 @@ public class ARP extends BasePacket { this.hardwareAddressLength = bb.get(); this.protocolAddressLength = bb.get(); if (this.hardwareAddressLength != 6) { - if (log.isTraceEnabled()) { - log.trace("Incorrect ARP hardware address length: {}", - hardwareAddressLength); - } - throw new PacketParsingException(); + String msg = "Incorrect ARP hardware address length: " + + hardwareAddressLength; + throw new PacketParsingException(msg); } if (this.protocolAddressLength != 4) { - if (log.isTraceEnabled()) { - log.trace("Incorrect ARP protocol address length: {}", - protocolAddressLength); - } - throw new PacketParsingException(); + String msg = "Incorrect ARP protocol address length: " + + protocolAddressLength; + throw new PacketParsingException(msg); } this.opCode = bb.getShort(); this.senderHardwareAddress = new byte[0xff & this.hardwareAddressLength]; diff --git a/src/main/java/net/floodlightcontroller/packet/BSN.java b/src/main/java/net/floodlightcontroller/packet/BSN.java index 489e4bc3c..676f54d48 100644 --- a/src/main/java/net/floodlightcontroller/packet/BSN.java +++ b/src/main/java/net/floodlightcontroller/packet/BSN.java @@ -102,13 +102,13 @@ public class BSN extends BasePacket { int magic = bb.getInt(); if (magic != BSN_MAGIC) { - throw new RuntimeException("Invalid BSN magic " + magic); + throw new PacketParsingException("Invalid BSN magic " + magic); } this.type = bb.getShort(); this.version = bb.getShort(); if (this.version != BSN_VERSION_CURRENT) { - throw new RuntimeException( + throw new PacketParsingException( "Invalid BSN packet version " + this.version + ", should be " + BSN_VERSION_CURRENT); } diff --git a/src/main/java/net/floodlightcontroller/packet/IPv4.java b/src/main/java/net/floodlightcontroller/packet/IPv4.java index 064ad31e8..61d9730ba 100644 --- a/src/main/java/net/floodlightcontroller/packet/IPv4.java +++ b/src/main/java/net/floodlightcontroller/packet/IPv4.java @@ -362,7 +362,8 @@ public class IPv4 extends BasePacket { this.headerLength = (byte) (this.version & 0xf); this.version = (byte) ((this.version >> 4) & 0xf); if (this.version != 4) { - throw new RuntimeException("Invalid version for IPv4 packet: " + + throw new PacketParsingException( + "Invalid version for IPv4 packet: " + this.version); } this.diffServ = bb.get(); diff --git a/src/main/java/net/floodlightcontroller/packet/PacketParsingException.java b/src/main/java/net/floodlightcontroller/packet/PacketParsingException.java index 63e6410cb..f27629de8 100644 --- a/src/main/java/net/floodlightcontroller/packet/PacketParsingException.java +++ b/src/main/java/net/floodlightcontroller/packet/PacketParsingException.java @@ -18,6 +18,10 @@ package net.floodlightcontroller.packet; public class PacketParsingException extends Exception { + public PacketParsingException(String msg) { + super(msg); + } + private static final long serialVersionUID = -1177841297678875573L; -} +} \ No newline at end of file diff --git a/src/main/java/net/floodlightcontroller/packet/TCP.java b/src/main/java/net/floodlightcontroller/packet/TCP.java index 215337885..6af5932a5 100644 --- a/src/main/java/net/floodlightcontroller/packet/TCP.java +++ b/src/main/java/net/floodlightcontroller/packet/TCP.java @@ -268,7 +268,7 @@ public class TCP extends BasePacket { this.flags = bb.getShort(); this.dataOffset = (byte) ((this.flags >> 12) & 0xf); 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.windowSize = bb.getShort(); -- GitLab