/*
 * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.protocol.bgp.rib.impl;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
import org.opendaylight.yangtools.yang.binding.Notification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Preconditions;

/**
 *
 */
@Sharable
final class BGPMessageToByteEncoder extends MessageToByteEncoder<Notification> {
	private static final Logger LOG = LoggerFactory.getLogger(BGPMessageToByteEncoder.class);
	private final MessageRegistry registry;

	BGPMessageToByteEncoder(final MessageRegistry registry) {
		this.registry = Preconditions.checkNotNull(registry);
	}

	@Override
	protected void encode(final ChannelHandlerContext ctx, final Notification msg, final ByteBuf out) throws Exception {
		LOG.debug("Sent to encode : {}", msg);
		out.writeBytes(this.registry.serializeMessage(msg));
	}
}

@@ -596,16 +596,65 @@
 gistry;%0A
+import org.opendaylight.protocol.util.ByteArray;%0A
 import o
@@ -1303,30 +1303,31 @@
 LOG.
-debug(%22Sent to encode 
+trace(%22Encoding message
 : %7B%7D
@@ -1341,23 +1341,29 @@
 ;%0A%09%09
-out.writeB
+final byte%5B%5D b
 ytes
-(
+ = 
 this
@@ -1393,16 +1393,159 @@
 age(msg)
+;%0A%09%09LOG.trace(%22Encoded message: %7B%7D%22, ByteArray.bytesToHexString(bytes));%0A%09%09out.writeBytes(bytes);%0A%09%09LOG.debug(%22Message sent to output: %7B%7D%22, msg
 );%0A%09%7D%0A%7D%0A

Add more detailed traces about BGP encoding process