Removed duplicate logging from message parsers. 79/22979/4
authorDana Kutenicsova <dkutenic@cisco.com>
Fri, 19 Jun 2015 09:47:20 +0000 (11:47 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 22 Jun 2015 09:07:44 +0000 (09:07 +0000)
Message hex dumps are already printed out via Encoder/Decoder
classes, no need to print them in here as well.

Unified log messages and renamed some variables to make
code more readable.

Change-Id: I9bdcfed891ee1175d28ba1b993f1f22c9774da3e
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPNotificationMessageParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPOpenMessageParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPUpdateMessageParser.java

index 199f9c15d324c01282c7d2c1a08e2bdf73489885..bee6fcdbbc6a12c9b9ded2ea5c1c820b3d0d9734 100644 (file)
@@ -29,10 +29,10 @@ import org.slf4j.LoggerFactory;
  */
 public final class BGPNotificationMessageParser implements MessageParser, MessageSerializer {
 
-    public static final int TYPE = 3;
-
     private static final Logger LOG = LoggerFactory.getLogger(BGPNotificationMessageParser.class);
 
+    public static final int TYPE = 3;
+
     private static final int ERROR_SIZE = 2;
 
     /**
@@ -43,9 +43,8 @@ public final class BGPNotificationMessageParser implements MessageParser, Messag
      */
     @Override
     public void serializeMessage(final Notification msg, final ByteBuf bytes) {
-        Preconditions.checkArgument(msg instanceof Notify, "BGP Notification message cannot be null");
+        Preconditions.checkArgument(msg instanceof Notify, "Message needs to be of type Notify");
         final Notify ntf = (Notify) msg;
-        LOG.trace("Started serializing Notification message: {}", ntf);
 
         final ByteBuf msgBody = Unpooled.buffer();
         msgBody.writeByte(ntf.getErrorCode());
@@ -68,8 +67,7 @@ public final class BGPNotificationMessageParser implements MessageParser, Messag
      */
     @Override
     public Notify parseMessageBody(final ByteBuf body, final int messageLength) throws BGPDocumentedException {
-        Preconditions.checkArgument(body != null, "Byte buffer cannot be null.");
-        LOG.trace("Started parsing of notification message: {}", ByteBufUtil.hexDump(body));
+        Preconditions.checkArgument(body != null, "Buffer cannot be null.");
         if (body.readableBytes() < ERROR_SIZE) {
             throw BGPDocumentedException.badMessageLength("Notification message too small.", messageLength);
         }
index 6f2a02c5e30dfd84ba685cd11c09ef3174db4a26..07ca965866ef3c1061628ed55c16de458a2221a6 100644 (file)
@@ -12,7 +12,6 @@ import io.netty.buffer.ByteBuf;
 import io.netty.buffer.ByteBufUtil;
 import io.netty.buffer.Unpooled;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPError;
@@ -36,10 +35,11 @@ import org.slf4j.LoggerFactory;
  * Parser for BGP Open message.
  */
 public final class BGPOpenMessageParser implements MessageParser, MessageSerializer {
-    public static final int TYPE = 1;
 
     private static final Logger LOG = LoggerFactory.getLogger(BGPOpenMessageParser.class);
 
+    public static final int TYPE = 1;
+
     private static final int VERSION_SIZE = 1;
     private static final int AS_SIZE = 2;
     private static final int HOLD_TIME_SIZE = 2;
@@ -66,8 +66,7 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
      */
     @Override
     public void serializeMessage(final Notification msg, final ByteBuf bytes) {
-        Preconditions.checkArgument(msg instanceof Open, "BGP Open message cannot be null");
-        LOG.trace("Started serializing open message: {}", msg);
+        Preconditions.checkArgument(msg instanceof Open, "Message needs to be of type Open");
         final Open open = (Open) msg;
         final ByteBuf msgBody = Unpooled.buffer();
 
@@ -91,9 +90,6 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
         msgBody.writeByte(paramsBuffer.writerIndex());
         msgBody.writeBytes(paramsBuffer);
 
-        if (LOG.isTraceEnabled()) {
-            LOG.trace("Open message serialized to: {}", ByteBufUtil.hexDump(msgBody));
-        }
         MessageUtil.formatMessage(TYPE, msgBody, bytes);
     }
 
@@ -107,10 +103,7 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
      */
     @Override
     public Open parseMessageBody(final ByteBuf body, final int messageLength) throws BGPDocumentedException {
-        Preconditions.checkArgument(body != null, "Byte array cannot be null.");
-        if (LOG.isTraceEnabled()) {
-            LOG.trace("Started parsing of open message: {}", ByteBufUtil.hexDump(body));
-        }
+        Preconditions.checkArgument(body != null, "Buffer cannot be null.");
 
         if (body.readableBytes() < MIN_MSG_LENGTH) {
             throw BGPDocumentedException.badMessageLength("Open message too small.", messageLength);
@@ -142,7 +135,7 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
     }
 
     private void fillParams(final ByteBuf buffer, final List<BgpParameters> params) throws BGPDocumentedException {
-        Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Byte array cannot be null or empty.");
+        Preconditions.checkArgument(buffer != null && buffer.isReadable(), "BUffer cannot be null or empty.");
         if (LOG.isTraceEnabled()) {
             LOG.trace("Started parsing of BGP parameter: {}", ByteBufUtil.hexDump(buffer));
         }
@@ -166,8 +159,6 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
                 LOG.debug("Ignoring BGP Parameter type: {}", paramType);
             }
         }
-        if (LOG.isTraceEnabled()) {
-            LOG.trace("Parsed BGP parameters: {}", Arrays.toString(params.toArray()));
-        }
+        LOG.trace("Parsed BGP parameters: {}", params);
     }
 }
index 093f0cbfc174627528c5f3fb317c6abc01b141ef..582f7acd106936f2660f8eb3c473ce229a9c6079 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.protocol.bgp.parser.impl.message;
 
 import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
-import io.netty.buffer.ByteBufUtil;
 import io.netty.buffer.Unpooled;
 import java.util.List;
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
@@ -40,51 +39,41 @@ import org.slf4j.LoggerFactory;
  * @see <a href="http://tools.ietf.org/html/rfc4271#section-4.3">BGP-4 Update Message Format</a>
  */
 public final class BGPUpdateMessageParser implements MessageParser, MessageSerializer {
-    public static final int TYPE = 2;
 
     private static final Logger LOG = LoggerFactory.getLogger(BGPUpdateMessageParser.class);
 
-    /**
-     * Size of the withdrawn_routes_length field, in bytes.
-     */
-    public static final int WITHDRAWN_ROUTES_LENGTH_SIZE = 2;
-    /**
-     * Size of the total_path_attr_length field, in bytes.
-     */
-    public static final int TOTAL_PATH_ATTR_LENGTH_SIZE = 2;
+    public static final int TYPE = 2;
+
+    private static final int WITHDRAWN_ROUTES_LENGTH_SIZE = 2;
+
+    private static final int TOTAL_PATH_ATTR_LENGTH_SIZE = 2;
 
     private final AttributeRegistry reg;
 
-    // Constructors -------------------------------------------------------
     public BGPUpdateMessageParser(final AttributeRegistry reg) {
         this.reg = Preconditions.checkNotNull(reg);
     }
 
-    // Getters & setters --------------------------------------------------
-
     @Override
     public Update parseMessageBody(final ByteBuf buffer, final int messageLength) throws BGPDocumentedException {
-        Preconditions.checkArgument(buffer != null && buffer.readableBytes() != 0, "Byte array cannot be null or empty.");
-        if (LOG.isTraceEnabled()) {
-            LOG.trace("Started parsing of update message: {}", ByteBufUtil.hexDump(buffer));
-        }
+        Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Buffer cannot be null or empty.");
 
-        final int withdrawnRoutesLength = buffer.readUnsignedShort();
-        final UpdateBuilder eventBuilder = new UpdateBuilder();
+        final UpdateBuilder builder = new UpdateBuilder();
 
+        final int withdrawnRoutesLength = buffer.readUnsignedShort();
         if (withdrawnRoutesLength > 0) {
             final List<Ipv4Prefix> withdrawnRoutes = Ipv4Util.prefixListForBytes(ByteArray.readBytes(buffer, withdrawnRoutesLength));
-            eventBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setWithdrawnRoutes(withdrawnRoutes).build());
+            builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setWithdrawnRoutes(withdrawnRoutes).build());
         }
         final int totalPathAttrLength = buffer.readUnsignedShort();
 
         if (withdrawnRoutesLength == 0 && totalPathAttrLength == 0) {
-            return eventBuilder.build();
+            return builder.build();
         }
         if (totalPathAttrLength > 0) {
             try {
                 final Attributes pathAttributes = this.reg.parseAttributes(buffer.readSlice(totalPathAttrLength));
-                eventBuilder.setAttributes(pathAttributes);
+                builder.setAttributes(pathAttributes);
             } catch (final BGPParsingException | RuntimeException e) {
                 // Catch everything else and turn it into a BGPDocumentedException
                 LOG.warn("Could not parse BGP attributes", e);
@@ -93,17 +82,16 @@ public final class BGPUpdateMessageParser implements MessageParser, MessageSeria
         }
         final List<Ipv4Prefix> nlri = Ipv4Util.prefixListForBytes(ByteArray.readAllBytes(buffer));
         if (nlri != null && !nlri.isEmpty()) {
-            eventBuilder.setNlri(new NlriBuilder().setNlri(nlri).build());
+            builder.setNlri(new NlriBuilder().setNlri(nlri).build());
         }
-        final Update msg = eventBuilder.build();
+        final Update msg = builder.build();
         LOG.debug("BGP Update message was parsed {}.", msg);
         return msg;
     }
 
     @Override
     public void serializeMessage(final Notification message, final ByteBuf bytes) {
-        Preconditions.checkArgument(message instanceof Update, "BGPUpdate message cannot be null");
-        LOG.trace("Started serializing update message: {}", message);
+        Preconditions.checkArgument(message instanceof Update, "Message needs to be of type Update");
         final Update update = (Update) message;
 
         final ByteBuf messageBody = Unpooled.buffer();
@@ -132,7 +120,6 @@ public final class BGPUpdateMessageParser implements MessageParser, MessageSeria
                 messageBody.writeBytes(Ipv4Util.bytesForPrefixBegin(prefix));
             }
         }
-        LOG.trace("Update message serialized to {}", ByteBufUtil.hexDump(messageBody));
         MessageUtil.formatMessage(TYPE, messageBody, bytes);
     }
 }