*/
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;
/**
*/
@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());
*/
@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);
}
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;
* 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;
*/
@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();
msgBody.writeByte(paramsBuffer.writerIndex());
msgBody.writeBytes(paramsBuffer);
- if (LOG.isTraceEnabled()) {
- LOG.trace("Open message serialized to: {}", ByteBufUtil.hexDump(msgBody));
- }
MessageUtil.formatMessage(TYPE, msgBody, bytes);
}
*/
@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);
}
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));
}
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);
}
}
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;
* @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);
}
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();
messageBody.writeBytes(Ipv4Util.bytesForPrefixBegin(prefix));
}
}
- LOG.trace("Update message serialized to {}", ByteBufUtil.hexDump(messageBody));
MessageUtil.formatMessage(TYPE, messageBody, bytes);
}
}