Merge "CodeGenerator update."
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / packet / IPv4.java
index b1fef8f1a5ad23256f77a6eee5253f3fef89f1d5..d547e2c905ecae0d5397a053d9c784a3f64a2aea 100644 (file)
@@ -24,6 +24,8 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
 import org.opendaylight.controller.sal.utils.IPProtocols;
 import org.opendaylight.controller.sal.utils.NetUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Class that represents the IPv4  packet objects
@@ -32,6 +34,8 @@ import org.opendaylight.controller.sal.utils.NetUtils;
  */
 
 public class IPv4 extends Packet {
+    protected static final Logger logger = LoggerFactory
+    .getLogger(IPv4.class);
     private static final String VERSION = "Version";
     private static final String HEADERLENGTH = "HeaderLength";
     private static final String DIFFSERV = "DiffServ";
@@ -47,7 +51,7 @@ public class IPv4 extends Packet {
     private static final String DIP = "DestinationIPAddress";
     private static final String OPTIONS = "Options";
 
-    public static Map<Byte, Class<? extends Packet>> protocolClassMap;
+    public static final Map<Byte, Class<? extends Packet>> protocolClassMap;
     static {
         protocolClassMap = new HashMap<Byte, Class<? extends Packet>>();
         protocolClassMap.put(IPProtocols.ICMP.byteValue(), ICMP.class);
@@ -501,17 +505,20 @@ public class IPv4 extends Packet {
      * Method to perform post serialization - like computation of checksum of serialized header
      * @param serializedBytes
      * @return void
-     * @Exception throws exception
+     * @Exception throws PacketException
      */
     protected void postSerializeCustomOperation(byte[] serializedBytes)
-            throws Exception {
+            throws PacketException {
         int startOffset = this.getfieldOffset(CHECKSUM);
         int numBits = this.getfieldnumBits(CHECKSUM);
         byte[] checkSum = BitBufferHelper.toByteArray(computeChecksum(
                 serializedBytes, serializedBytes.length));
-        BitBufferHelper.setBytes(serializedBytes, checkSum, startOffset,
-                numBits);
-        return;
+        try {
+            BitBufferHelper.setBytes(serializedBytes, checkSum, startOffset,
+                    numBits);
+        } catch (BufferException e) {
+            throw new PacketException(e.getMessage());
+        }
     }
 
     @Override
@@ -530,8 +537,8 @@ public class IPv4 extends Packet {
         int payloadLength = 0;
         try {
             payloadLength = payload.serialize().length;
-        } catch (Exception e) {
-            e.printStackTrace();
+        } catch (PacketException e) {
+            logger.error("", e);
         }
         this.setTotalLength((short) (this.getHeaderLen() + payloadLength));
     }
@@ -545,7 +552,8 @@ public class IPv4 extends Packet {
         int endByteOffset = endBitOffset / NetUtils.NumBitsInAByte;
         int computedChecksum = computeChecksum(data, endByteOffset);
         int actualChecksum = BitBufferHelper.getInt(fieldValues.get(CHECKSUM));
-        if (computedChecksum != actualChecksum)
+        if (computedChecksum != actualChecksum) {
             corrupted = true;
+        }
     }
 }