From 48620de04f8faaa6ffc1f7acfbe41b12adbf416f Mon Sep 17 00:00:00 2001 From: Prasanna Huddar Date: Wed, 4 Dec 2013 15:35:51 +0530 Subject: [PATCH] Added validation Signed-off-by: Prasanna Huddar --- .../factories/GroupModInputMessageFactory.java | 15 ++++++++++++--- .../protocol/impl/util/ActionsSerializer.java | 12 ++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactory.java index b60a7c29..26ca0d46 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactory.java @@ -63,9 +63,18 @@ public class GroupModInputMessageFactory implements OFSerializer if (buckets != null) { for (BucketsList currentBucket : buckets) { outBuffer.writeShort(computeLengthOfBucket(currentBucket)); - outBuffer.writeShort(currentBucket.getWeight().shortValue()); - outBuffer.writeInt(currentBucket.getWatchPort().getValue().intValue()); - outBuffer.writeInt(currentBucket.getWatchGroup().intValue()); + + if (null != currentBucket.getWeight()) { + outBuffer.writeShort(currentBucket.getWeight().shortValue()); + } + + if (null != currentBucket.getWatchPort()) { + outBuffer.writeInt(currentBucket.getWatchPort().getValue().intValue()); + } + + if (null != currentBucket.getWatchGroup()) { + outBuffer.writeInt(currentBucket.getWatchGroup().intValue()); + } ByteBufUtils.padBuffer(PADDING_IN_BUCKET, outBuffer); ActionsSerializer.encodeActions(currentBucket.getActionsList(), outBuffer); } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java index c7e07ee7..e99d204c 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java @@ -237,11 +237,15 @@ public abstract class ActionsSerializer { private static void encodeCommonEthertype(Action action, ByteBuf outBuffer) { final byte LENGTH_OF_ETHERTYPE_ACTION = 8; - final byte ETHERTYPE_ACTION_PADDING = 2; - outBuffer.writeShort(LENGTH_OF_ETHERTYPE_ACTION); + final byte ETHERTYPE_ACTION_PADDING = 2; EthertypeAction ethertype = action.getAugmentation(EthertypeAction.class); - outBuffer.writeShort(ethertype.getEthertype().getValue()); - ByteBufUtils.padBuffer(ETHERTYPE_ACTION_PADDING, outBuffer); + + if (null != ethertype && null != ethertype.getEthertype()) { + outBuffer.writeShort(LENGTH_OF_ETHERTYPE_ACTION); + + outBuffer.writeShort(ethertype.getEthertype().getValue()); + ByteBufUtils.padBuffer(ETHERTYPE_ACTION_PADDING, outBuffer); + } } /** -- 2.36.6