package org.opendaylight.protocol.bgp.linkstate;
import com.google.common.base.Charsets;
+import com.google.common.base.Preconditions;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
final BitSet flags = BitSet.valueOf(ByteArray.readAllBytes(value));
builder.setNodeFlags(new NodeFlagBits(flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT), flags.get(EXTERNAL_BIT), flags.get(ABBR_BIT)));
LOG.debug("Parsed Overload bit: {}, attached bit: {}, external bit: {}, area border router: {}.",
- flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT), flags.get(EXTERNAL_BIT), flags.get(ABBR_BIT));
+ flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT), flags.get(EXTERNAL_BIT), flags.get(ABBR_BIT));
break;
case TlvCode.NODE_OPAQUE:
LOG.debug("Ignoring opaque value: {}.", ByteBufUtil.hexDump(value));
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
final PathAttributes1 pathAttributes1 = ((PathAttributes) attribute).getAugmentation(PathAttributes1.class);
if (pathAttributes1 == null) {
return;
writeTLV(TlvCode.SHARED_RISK_LINK_GROUP, sharedRLGBuf, byteAggregator);
}
if (linkAttributes.getLinkName() != null) {
- writeTLV(TlvCode.LINK_NAME, Unpooled.wrappedBuffer(linkAttributes.getLinkName().getBytes()), byteAggregator);
+ writeTLV(TlvCode.LINK_NAME, Unpooled.wrappedBuffer(Charsets.UTF_8.encode(linkAttributes.getLinkName())), byteAggregator);
}
LOG.trace("Finished serializing Link Attributes");
}
}
serializeNodeFlagBits(nodeAttributes.getNodeFlags(), byteAggregator);
if (nodeAttributes.getDynamicHostname() != null) {
- writeTLV(TlvCode.DYNAMIC_HOSTNAME, Unpooled.wrappedBuffer(nodeAttributes.getDynamicHostname().getBytes()), byteAggregator);
+ writeTLV(TlvCode.DYNAMIC_HOSTNAME, Unpooled.wrappedBuffer(Charsets.UTF_8.encode(nodeAttributes.getDynamicHostname())), byteAggregator);
}
final List<IsisAreaIdentifier> isisList = nodeAttributes.getIsisAreaId();
if (isisList != null && !isisList.isEmpty()) {
*/
package org.opendaylight.protocol.bgp.linkstate;
+import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.primitives.UnsignedBytes;
import com.google.common.primitives.UnsignedInteger;
private static final int TYPE_LENGTH = 2;
private static final int LENGTH_SIZE = 2;
- protected static final int TOPOLOGY_ID_OFFSET = 0x3fff;
+ static final int TOPOLOGY_ID_OFFSET = 0x3fff;
private final boolean isVpn;
final int restLength = length - (this.isVpn ? ROUTE_DISTINGUISHER_LENGTH : 0) - PROTOCOL_ID_LENGTH - IDENTIFIER_LENGTH
- TYPE_LENGTH - LENGTH_SIZE - locallength;
LOG.trace("Restlength {}", restLength);
- ByteBuf rest = nlri.slice(nlri.readerIndex(), restLength);
+ final ByteBuf rest = nlri.slice(nlri.readerIndex(), restLength);
switch (type) {
case Link:
parseLink(builder, rest);
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
final PathAttributes pathAttributes = (PathAttributes) attribute;
final PathAttributes1 pathAttributes1 = pathAttributes.getAugmentation(PathAttributes1.class);
final PathAttributes2 pathAttributes2 = pathAttributes.getAugmentation(PathAttributes2.class);
}
}
} else if (pathAttributes2 != null) {
- MpUnreachNlri mpUnreachNlri = pathAttributes2.getMpUnreachNlri();
+ final MpUnreachNlri mpUnreachNlri = pathAttributes2.getMpUnreachNlri();
if (mpUnreachNlri.getWithdrawnRoutes() != null && mpUnreachNlri.getWithdrawnRoutes().getDestinationType() instanceof DestinationLinkstateCase) {
- DestinationLinkstateCase linkstateCase = (DestinationLinkstateCase) mpUnreachNlri.getWithdrawnRoutes().getDestinationType();
- for (CLinkstateDestination cLinkstateDestination : linkstateCase.getDestinationLinkstate().getCLinkstateDestination()) {
+ final DestinationLinkstateCase linkstateCase = (DestinationLinkstateCase) mpUnreachNlri.getWithdrawnRoutes().getDestinationType();
+ for (final CLinkstateDestination cLinkstateDestination : linkstateCase.getDestinationLinkstate().getCLinkstateDestination()) {
serializeNlri(cLinkstateDestination, byteAggregator);
}
}
assertEquals("42.42.42.42", ls.getLocalIpv4RouterId().getValue());
assertEquals("43.43.43.43", ls.getRemoteIpv4RouterId().getValue());
- assertEquals(new Long(0), ls.getAdminGroup().getValue());
+ assertEquals(Long.valueOf(0L), ls.getAdminGroup().getValue());
assertArrayEquals(new byte[] { (byte) 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80 }, ls.getMaxLinkBandwidth().getValue());
assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 }, ls.getMaxReservableBandwidth().getValue());
assertNotNull(ls.getUnreservedBandwidth());
import com.google.common.base.Preconditions;
import com.google.common.primitives.UnsignedBytes;
-
import java.util.Arrays;
-
import org.opendaylight.protocol.util.Values;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @return byte array data
*/
public byte[] getData() {
- return this.data;
+ return (this.data != null) ? Arrays.copyOf(this.data, this.data.length) : new byte[0];
}
public static BGPDocumentedException badMessageLength(final String message, final int length) {
package org.opendaylight.protocol.bgp.parser;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
import java.util.ArrayList;
import java.util.List;
-
import org.junit.Test;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
final BGPDocumentedException de = new BGPDocumentedException("Some message", BGPError.BAD_BGP_ID);
assertEquals("Some message", de.getMessage());
assertEquals(BGPError.BAD_BGP_ID, de.getError());
- assertNull(de.getData());
+ assertEquals(0, de.getData().length);
final BGPDocumentedException doc = BGPDocumentedException.badMessageLength("Wrong length", 5000);
assertEquals(5000, ByteArray.bytesToInt(doc.getData()));
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.Arrays;
-
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPError;
import org.opendaylight.protocol.bgp.parser.spi.MessageParser;
*/
@Override
public void serializeMessage(final Notification msg, final ByteBuf bytes) {
- Preconditions.checkArgument(msg != null, "BGP Notification message cannot be null");
+ Preconditions.checkArgument(msg != null && msg instanceof Notify, "BGP Notification message cannot be null");
final Notify ntf = (Notify) msg;
LOG.trace("Started serializing Notification message: {}", ntf);
- byte[] data = ntf.getData();
+ final byte[] data = ntf.getData();
final ByteBuf msgBody = Unpooled.buffer();
msgBody.writeByte(ntf.getErrorCode());
msgBody.writeByte(ntf.getErrorSubcode());
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.ArrayList;
import java.util.Arrays;
import java.util.List;
-
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPError;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
*/
@Override
public void serializeMessage(final Notification msg, final ByteBuf bytes) {
- Preconditions.checkArgument(msg != null, "BGP Open message cannot be null");
+ Preconditions.checkArgument(msg != null && msg instanceof Open, "BGP Open message cannot be null");
LOG.trace("Started serializing open message: {}", msg);
final Open open = (Open) msg;
final ByteBuf msgBody = Unpooled.buffer();
if (body.readableBytes() < MIN_MSG_LENGTH) {
throw BGPDocumentedException.badMessageLength("Open message too small.", messageLength);
}
- int version = body.readUnsignedByte();
+ final int version = body.readUnsignedByte();
if (version != BGP_VERSION) {
throw new BGPDocumentedException("BGP Protocol version " + version + " not supported.", BGPError.VERSION_NOT_SUPPORTED);
}
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;
import org.opendaylight.protocol.bgp.parser.BGPError;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
if (nlri != null && !nlri.isEmpty()) {
eventBuilder.setNlri(new NlriBuilder().setNlri(nlri).build());
}
- Update msg = eventBuilder.build();
+ final Update msg = eventBuilder.build();
LOG.debug("BGP Update message was parsed {}.", msg);
return msg;
}
@Override
public void serializeMessage(final Notification message, final ByteBuf bytes) {
- Preconditions.checkArgument(message != null, "BGPUpdate message cannot be null");
+ Preconditions.checkArgument(message != null && message instanceof Update, "BGPUpdate message cannot be null");
LOG.trace("Started serializing update message: {}", message);
final Update update = (Update) message;
*/
package org.opendaylight.protocol.bgp.parser.impl.message.open;
+import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
import org.opendaylight.protocol.bgp.parser.spi.CapabilityParser;
}
@Override
- public void serializeCapability(final CParameters capability, ByteBuf bytes) {
+ public void serializeCapability(final CParameters capability, final ByteBuf bytes) {
+ Preconditions.checkArgument(capability instanceof As4BytesCase);
CapabilityUtil.formatCapability(CODE, putAS4BytesParameterValue((As4BytesCase) capability),bytes);
}
}
@Override
- public void serializeCapability(final CParameters capability, ByteBuf byteAggregator) {
+ public void serializeCapability(final CParameters capability, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(capability instanceof GracefulRestartCase);
final GracefulRestartCapability grace = ((GracefulRestartCase) capability).getGracefulRestartCapability();
final List<Tables> tables = grace.getTables();
package org.opendaylight.protocol.bgp.parser.impl.message.open;
import com.google.common.base.Preconditions;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
}
@Override
- public void serializeCapability(final CParameters capability, ByteBuf byteAggregator) {
+ public void serializeCapability(final CParameters capability, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(capability instanceof MultiprotocolCase);
final MultiprotocolCase mp = (MultiprotocolCase) capability;
final ByteBuf capBuffer = Unpooled.buffer();
final Class<? extends AddressFamily> afi = mp.getMultiprotocolCapability().getAfi();
*/
package org.opendaylight.protocol.bgp.parser.impl.message.update;
+import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
-
import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.protocol.util.Ipv6Util;
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
final PathAttributes1 pathAttributes1 = ((PathAttributes) attribute).getAugmentation(PathAttributes1.class);
if (pathAttributes1 == null) {
return;
if (mpReachNlri == null) {
return;
}
- AdvertizedRoutes routes = mpReachNlri.getAdvertizedRoutes();
+ final AdvertizedRoutes routes = mpReachNlri.getAdvertizedRoutes();
if (routes.getDestinationType() instanceof DestinationIpv4Case) {
final DestinationIpv4Case destinationIpv4Case = (DestinationIpv4Case) routes.getDestinationType();
for (final Ipv4Prefix ipv4Prefix : destinationIpv4Case.getDestinationIpv4().getIpv4Prefixes()) {
package org.opendaylight.protocol.bgp.parser.impl.message.update;
import com.google.common.base.Preconditions;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
final PathAttributes pathAttributes = (PathAttributes) attribute;
final Aggregator aggregator = pathAttributes.getAggregator();
if (aggregator == null) {
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.primitives.UnsignedBytes;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import java.util.List;
-
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPError;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
if (segmentType == SegmentType.AS_SEQUENCE) {
final List<AsSequence> numbers = AsPathSegmentParser.parseAsSequence(refCache, count, buffer.slice(buffer.readerIndex(),
- count * AsPathSegmentParser.AS_NUMBER_LENGTH));
+ count * AsPathSegmentParser.AS_NUMBER_LENGTH));
ases.add(new SegmentsBuilder().setCSegment(
- new AListCaseBuilder().setAList(new AListBuilder().setAsSequence(numbers).build()).build()).build());
+ new AListCaseBuilder().setAList(new AListBuilder().setAsSequence(numbers).build()).build()).build());
isSequence = true;
} else {
final List<AsNumber> list = AsPathSegmentParser.parseAsSet(refCache, count, buffer.slice(buffer.readerIndex(), count
- * AsPathSegmentParser.AS_NUMBER_LENGTH));
+ * AsPathSegmentParser.AS_NUMBER_LENGTH));
ases.add(new SegmentsBuilder().setCSegment(new ASetCaseBuilder().setASet(new ASetBuilder().setAsSet(list).build()).build()).build());
}
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
final PathAttributes pathAttributes = (PathAttributes) attribute;
final AsPath asPath = pathAttributes.getAsPath();
if (asPath == null) {
return;
}
final ByteBuf segmentsBuffer = Unpooled.buffer();
- if (asPath.getSegments().size()>0) {
- for (Segments segments : asPath.getSegments()) {
+ if (asPath.getSegments() != null) {
+ for (final Segments segments : asPath.getSegments()) {
if (segments.getCSegment() instanceof AListCase) {
- AListCase listCase = (AListCase) segments.getCSegment();
+ final AListCase listCase = (AListCase) segments.getCSegment();
AsPathSegmentParser.serializeAsSequence(listCase, segmentsBuffer);
} else if (segments.getCSegment() instanceof ASetCase) {
- ASetCase set = (ASetCase) segments.getCSegment();
+ final ASetCase set = (ASetCase) segments.getCSegment();
AsPathSegmentParser.serializeAsSet(set, segmentsBuffer);
} else {
LOG.warn("Segment class is neither AListCase nor ASetCase.");
*/
package org.opendaylight.protocol.bgp.parser.impl.message.update;
+import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
final PathAttributes pathAttributes = (PathAttributes) attribute;
if (pathAttributes.getAtomicAggregate() == null) {
return;
*/
package org.opendaylight.protocol.bgp.parser.impl.message.update;
+import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import java.util.List;
-
import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
public final class ClusterIdAttributeParser implements AttributeParser, AttributeSerializer {
public static final int TYPE = 10;
- public static final int ATTR_LENGTH = 4;
@Override
public void parseAttribute(final ByteBuf buffer, final PathAttributesBuilder builder) {
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
final ClusterId cid = ((PathAttributes) attribute).getClusterId();
if (cid == null) {
return;
public final class CommunitiesAttributeParser implements AttributeParser, AttributeSerializer {
public static final int TYPE = 8;
- public static final int ATTR_LENGTH = 4;
private final ReferenceCache refCache;
final List<Communities> set = Lists.newArrayList();
while (buffer.isReadable()) {
set.add((Communities) CommunitiesParser.parseCommunity(this.refCache, buffer.slice(buffer.readerIndex(),
- CommunitiesParser.COMMUNITY_LENGTH)));
+ CommunitiesParser.COMMUNITY_LENGTH)));
buffer.skipBytes(CommunitiesParser.COMMUNITY_LENGTH);
}
builder.setCommunities(set);
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
final PathAttributes pathAttributes = (PathAttributes) attribute;
final List<Communities> communities = pathAttributes.getCommunities();
if (communities == null || communities.isEmpty()) {
*/
public final class CommunitiesParser {
- protected static final int EXTENDED_COMMUNITY_LENGTH = 8;
-
- protected static final int COMMUNITY_LENGTH = 4;
+ public static final int COMMUNITY_LENGTH = 4;
private static final int AS_LOCAL_ADMIN_LENGTH = 4;
private static final int INET_LOCAL_ADMIN_LENGTH = 2;
- protected static final short AS_TYPE_TRANS = 0;
+ private static final short AS_TYPE_TRANS = 0;
- protected static final short AS_TYPE_NON_TRANS = 40;
+ private static final short AS_TYPE_NON_TRANS = 40;
- protected static final short INET_TYPE_TRANS = 1;
+ private static final short INET_TYPE_TRANS = 1;
- protected static final short INET_TYPE_NON_TRANS = 41;
+ private static final short INET_TYPE_NON_TRANS = 41;
- protected static final short OPAQUE_TYPE_TRANS = 3;
+ private static final short OPAQUE_TYPE_TRANS = 3;
- protected static final short OPAQUE_TYPE_NON_TRANS = 43;
+ private static final short OPAQUE_TYPE_NON_TRANS = 43;
- protected static final short ROUTE_TYPE_ONLY = 2;
+ private static final short ROUTE_TYPE_ONLY = 2;
- protected static final short ROUTE_TARGET_SUBTYPE = 2;
+ private static final short ROUTE_TARGET_SUBTYPE = 2;
- protected static final short ROUTE_ORIGIN_SUBTYPE = 3;
+ private static final short ROUTE_ORIGIN_SUBTYPE = 3;
private static final byte[] NO_EXPORT = new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x01 };
if (buffer.readableBytes() != COMMUNITY_LENGTH) {
throw new BGPDocumentedException("Community with wrong length: " + buffer.readableBytes(), BGPError.OPT_ATTR_ERROR);
}
- byte[] body = ByteArray.getBytes(buffer, COMMUNITY_LENGTH);
+ final byte[] body = ByteArray.getBytes(buffer, COMMUNITY_LENGTH);
if (Arrays.equals(body, NO_EXPORT)) {
return CommunityUtil.NO_EXPORT;
} else if (Arrays.equals(body, NO_ADVERTISE)) {
package org.opendaylight.protocol.bgp.parser.impl.message.update;
import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
+import java.util.ArrayList;
import java.util.List;
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
public static final int TYPE = 16;
+ private static final int EXTENDED_COMMUNITY_LENGTH = 8;
+
private final ReferenceCache refCache;
public ExtendedCommunitiesAttributeParser(final ReferenceCache refCache) {
@Override
public void parseAttribute(final ByteBuf buffer, final PathAttributesBuilder builder) throws BGPDocumentedException {
- final List<ExtendedCommunities> set = Lists.newArrayList();
+ final List<ExtendedCommunities> set = new ArrayList<>();
while (buffer.isReadable()) {
- final ExtendedCommunities comm = CommunitiesParser.parseExtendedCommunity(this.refCache, buffer.slice(buffer.readerIndex(), CommunitiesParser.EXTENDED_COMMUNITY_LENGTH));
- buffer.skipBytes(CommunitiesParser.EXTENDED_COMMUNITY_LENGTH);
+ final ExtendedCommunities comm = CommunitiesParser.parseExtendedCommunity(this.refCache, buffer.slice(buffer.readerIndex(), EXTENDED_COMMUNITY_LENGTH));
+ buffer.skipBytes(EXTENDED_COMMUNITY_LENGTH);
set.add(comm);
}
builder.setExtendedCommunities(set);
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
final PathAttributes pathAttributes = (PathAttributes) attribute;
final List<ExtendedCommunities> communitiesList = pathAttributes.getExtendedCommunities();
if (communitiesList == null || communitiesList.isEmpty()) {
*/
package org.opendaylight.protocol.bgp.parser.impl.message.update;
+import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
-
import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.Nlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.destination.type.DestinationIpv4Case;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.destination.type.DestinationIpv4CaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.destination.type.destination.ipv4._case.DestinationIpv4Builder;
@Override
protected DestinationIpv4Case parseNlri(final ByteBuf nlri) {
return new DestinationIpv4CaseBuilder().setDestinationIpv4(
- new DestinationIpv4Builder().setIpv4Prefixes(Ipv4Util.prefixListForBytes(ByteArray.readAllBytes(nlri))).build()).build();
+ new DestinationIpv4Builder().setIpv4Prefixes(Ipv4Util.prefixListForBytes(ByteArray.readAllBytes(nlri))).build()).build();
}
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
final Nlri nlri = (Nlri) attribute;
for (final Ipv4Prefix ipv4Prefix : nlri.getNlri()) {
byteAggregator.writeBytes(Ipv4Util.bytesForPrefix(ipv4Prefix));
*/
package org.opendaylight.protocol.bgp.parser.impl.message.update;
+import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
public final class LocalPreferenceAttributeParser implements AttributeParser,AttributeSerializer {
public static final int TYPE = 5;
- public static final int LOCAL_PREFS_LENGTH = 4;
@Override
public void parseAttribute(final ByteBuf buffer, final PathAttributesBuilder builder) {
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
final LocalPref lp = ((PathAttributes) attribute).getLocalPref();
if (lp == null) {
return;
package org.opendaylight.protocol.bgp.parser.impl.message.update;
import com.google.common.base.Preconditions;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPError;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
public final class MPReachAttributeParser implements AttributeParser, AttributeSerializer {
public static final int TYPE = 14;
- public static final int ATTR_LENGTH = 2;
+
private final NlriRegistry reg;
public MPReachAttributeParser(final NlriRegistry reg) {
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
final PathAttributes pathAttributes = (PathAttributes) attribute;
final PathAttributes1 pathAttributes1 = pathAttributes.getAugmentation(PathAttributes1.class);
if (pathAttributes1 == null) {
package org.opendaylight.protocol.bgp.parser.impl.message.update;
import com.google.common.base.Preconditions;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPError;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
public final class MPUnreachAttributeParser implements AttributeParser, AttributeSerializer {
public static final int TYPE = 15;
- public static final int MAX_ATTR_LENGTH_FOR_SINGLE_BYTE = 127;
private final NlriRegistry reg;
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
final PathAttributes pathAttributes = (PathAttributes) attribute;
final PathAttributes2 pathAttributes2 = pathAttributes.getAugmentation(PathAttributes2.class);
if (pathAttributes2 == null) {
*/
package org.opendaylight.protocol.bgp.parser.impl.message.update;
+import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
final MultiExitDisc multiExitDisc = ((PathAttributes) attribute).getMultiExitDisc();
if (multiExitDisc == null) {
return;
package org.opendaylight.protocol.bgp.parser.impl.message.update;
import com.google.common.base.Preconditions;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import org.opendaylight.bgp.concepts.NextHopUtil;
import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
final CNextHop cNextHop = ((PathAttributes) attribute).getCNextHop();
if (cNextHop == null) {
return;
*/
package org.opendaylight.protocol.bgp.parser.impl.message.update;
+import com.google.common.base.Preconditions;
import com.google.common.primitives.UnsignedBytes;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPError;
import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
public final class OriginAttributeParser implements AttributeParser, AttributeSerializer {
public static final int TYPE = 1;
- public static final int ATTR_LENGTH = 1;
@Override
public void parseAttribute(final ByteBuf buffer, final PathAttributesBuilder builder) throws BGPDocumentedException {
- byte rawOrigin = buffer.readByte();
+ final byte rawOrigin = buffer.readByte();
final BgpOrigin borigin = BgpOrigin.forValue(UnsignedBytes.toInt(rawOrigin));
if (borigin == null) {
throw new BGPDocumentedException("Unknown Origin type.", BGPError.ORIGIN_ATTR_NOT_VALID, new byte[] { (byte) 0x01, (byte) 0x01, rawOrigin} );
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
final Origin origin = ((PathAttributes) attribute).getOrigin();
if (origin == null) {
return;
package org.opendaylight.protocol.bgp.parser.impl.message.update;
import com.google.common.base.Preconditions;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
final OriginatorId originator = ((PathAttributes) attribute).getOriginatorId();
if (originator == null) {
return;
*/
package org.opendaylight.protocol.bgp.parser.impl.message.update;
+import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
-
import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.protocol.util.Ipv6Util;
public class WithdrawnRoutesSerializer implements NlriSerializer {
@Override
- public void serializeAttribute(DataObject attribute, ByteBuf byteAggregator) {
- PathAttributes2 pathAttributes2 = ((PathAttributes) attribute).getAugmentation(PathAttributes2.class);
+ public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
+ final PathAttributes2 pathAttributes2 = ((PathAttributes) attribute).getAugmentation(PathAttributes2.class);
if (pathAttributes2 == null) {
return;
}
- MpUnreachNlri mpUnreachNlri = pathAttributes2.getMpUnreachNlri();
+ final MpUnreachNlri mpUnreachNlri = pathAttributes2.getMpUnreachNlri();
if (mpUnreachNlri == null) {
return;
}
- WithdrawnRoutes routes = mpUnreachNlri.getWithdrawnRoutes();
+ final WithdrawnRoutes routes = mpUnreachNlri.getWithdrawnRoutes();
if (routes != null) {
if (routes.getDestinationType() instanceof DestinationIpv4Case) {
final DestinationIpv4Case destinationIpv4Case = (DestinationIpv4Case)routes.getDestinationType();
@BeforeClass
public static void setUp() throws Exception {
updateParser = new BGPUpdateMessageParser(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry());
-
for (int i = 1; i <= COUNTER; i++) {
final String name = "/up" + i + ".bin";
- final InputStream is = BGPParserTest.class.getResourceAsStream(name);
- if (is == null) {
- throw new IOException("Failed to get resource " + name);
- }
-
- final ByteArrayOutputStream bis = new ByteArrayOutputStream();
- final byte[] data = new byte[MAX_SIZE];
- int nRead = 0;
- while ((nRead = is.read(data, 0, data.length)) != -1) {
- bis.write(data, 0, nRead);
+ try (final InputStream is = BGPParserTest.class.getResourceAsStream(name)){
+ if (is == null) {
+ throw new IOException("Failed to get resource " + name);
+ }
+ final ByteArrayOutputStream bis = new ByteArrayOutputStream();
+ final byte[] data = new byte[MAX_SIZE];
+ int nRead = 0;
+ while ((nRead = is.read(data, 0, data.length)) != -1) {
+ bis.write(data, 0, nRead);
+ }
+ bis.flush();
+
+ inputBytes.add(bis.toByteArray());
+ is.close();
}
- bis.flush();
-
- inputBytes.add(bis.toByteArray());
}
}
+
@Test
public void testResource() {
assertNotNull(inputBytes);
final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65002L)).build());
final List<Segments> asPath = Lists.newArrayList();
asPath.add(new SegmentsBuilder().setCSegment(
- new AListCaseBuilder().setAList(new AListBuilder().setAsSequence(asnums).build()).build()).build());
+ new AListCaseBuilder().setAList(new AListBuilder().setAsSequence(asnums).build()).build()).build());
final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
- new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build();
+ new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build();
final List<Communities> comms = Lists.newArrayList();
comms.add((Communities) CommunityUtil.NO_EXPORT);
final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65001L)).build());
final List<Segments> asPath = Lists.newArrayList();
asPath.add(new SegmentsBuilder().setCSegment(
- new AListCaseBuilder().setAList(new AListBuilder().setAsSequence(asnums).build()).build()).build());
+ new AListCaseBuilder().setAList(new AListBuilder().setAsSequence(asnums).build()).build()).build());
final Ipv6NextHopCase nextHop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(
- new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
+ new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
final List<ClusterIdentifier> clusters = Lists.newArrayList(new ClusterIdentifier(new Ipv4Address("1.2.3.4")),
- new ClusterIdentifier(new Ipv4Address("5.6.7.8")));
+ new ClusterIdentifier(new Ipv4Address("5.6.7.8")));
// check path attributes
mpBuilder.setSafi(UnicastSubsequentAddressFamily.class);
mpBuilder.setCNextHop(nextHop);
mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(prefs).build()).build()).build());
+ new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(prefs).build()).build()).build());
paBuilder.addAugmentation(PathAttributes1.class, new PathAttributes1Builder().setMpReachNlri(mpBuilder.build()).build());
assertEquals(paBuilder.getAugmentation(PathAttributes1.class).getMpReachNlri(),
- attrs.getAugmentation(PathAttributes1.class).getMpReachNlri());
+ attrs.getAugmentation(PathAttributes1.class).getMpReachNlri());
// check API message
final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(30L)).build());
final List<Segments> asPath = Lists.newArrayList();
asPath.add(new SegmentsBuilder().setCSegment(
- new AListCaseBuilder().setAList(new AListBuilder().setAsSequence(asnums).build()).build()).build());
+ new AListCaseBuilder().setAList(new AListBuilder().setAsSequence(asnums).build()).build()).build());
asPath.add(new SegmentsBuilder().setCSegment(
- new ASetCaseBuilder().setASet(new ASetBuilder().setAsSet(Lists.newArrayList(new AsNumber(10L), new AsNumber(20L))).build()).build()).build());
+ new ASetCaseBuilder().setASet(new ASetBuilder().setAsSet(Lists.newArrayList(new AsNumber(10L), new AsNumber(20L))).build()).build()).build());
final Aggregator aggregator = new AggregatorBuilder().setAsNumber(new AsNumber((long) 30)).setNetworkAddress(
- new Ipv4Address("10.0.0.9")).build();
+ new Ipv4Address("10.0.0.9")).build();
final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
- new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.9")).build()).build();
+ new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.9")).build()).build();
// check path attributes
final PathAttributes attrs = message.getPathAttributes();
// attributes
final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
- new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("3.3.3.3")).build()).build();
+ new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("3.3.3.3")).build()).build();
final List<ExtendedCommunities> comms = Lists.newArrayList();
comms.add(new ExtendedCommunitiesBuilder().setCommType((short) 1).setExtendedCommunity(
- new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
- new Inet4SpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(
- new Ipv4Address("192.168.1.0")).setLocalAdministrator(new byte[] { 0x12, 0x34 }).build()).build()).build());
+ new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
+ new Inet4SpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(
+ new Ipv4Address("192.168.1.0")).setLocalAdministrator(new byte[] { 0x12, 0x34 }).build()).build()).build());
final List<Segments> asPath = Lists.newArrayList();
// check API message
final Update expectedMessage = new UpdateBuilder().setWithdrawnRoutes(
- new WithdrawnRoutesBuilder().setWithdrawnRoutes(prefs).build()).build();
+ new WithdrawnRoutesBuilder().setWithdrawnRoutes(prefs).build()).build();
assertEquals(expectedMessage.getWithdrawnRoutes(), message.getWithdrawnRoutes());
assertNull(message.getWithdrawnRoutes());
final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
- new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
+ new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
final List<Segments> asPath = Lists.newArrayList();
final LocalNodeDescriptorsBuilder lndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
- new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
+ new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
final RemoteNodeDescriptorsBuilder rndBuilder = new RemoteNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
- new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
+ new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
final List<CLinkstateDestination> linkstates = Lists.newArrayList();
clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
- new OspfPseudonodeCaseBuilder().setOspfPseudonode(
- new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
+ new OspfPseudonodeCaseBuilder().setOspfPseudonode(
+ new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
- new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x03030304L).build()).build()).build());
+ new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x03030304L).build()).build()).build());
clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
- new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.3"))).build());
+ new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.3"))).build());
linkstates.add(clBuilder.build());
clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
- new OspfPseudonodeCaseBuilder().setOspfPseudonode(
- new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
+ new OspfPseudonodeCaseBuilder().setOspfPseudonode(
+ new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
- new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
+ new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
- new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
+ new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
linkstates.add(clBuilder.build());
clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
- new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
+ new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
- new OspfPseudonodeCaseBuilder().setOspfPseudonode(
- new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
+ new OspfPseudonodeCaseBuilder().setOspfPseudonode(
+ new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
- new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
+ new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
linkstates.add(clBuilder.build());
lsBuilder.setMpReachNlri(mpBuilder.build());
dBuilder.setCLinkstateDestination(linkstates);
mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
+ new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
lsBuilder.setMpReachNlri(mpBuilder.build());
paBuilder.addAugmentation(PathAttributes1.class, lsBuilder.build());
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1Builder lsAttrBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1Builder();
lsAttrBuilder.setLinkstatePathAttribute(new LinkstatePathAttributeBuilder().setLinkStateAttribute(
- new LinkAttributesCaseBuilder().setLinkAttributes(new LinkAttributesBuilder().setMetric(new Metric(1L)).build()).build()).build());
+ new LinkAttributesCaseBuilder().setLinkAttributes(new LinkAttributesBuilder().setMetric(new Metric(1L)).build()).build()).build());
paBuilder.addAugmentation(
- org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1.class,
- lsAttrBuilder.build());
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1.class,
+ lsAttrBuilder.build());
assertEquals(
- lsAttrBuilder.build().getLinkstatePathAttribute(),
- attrs.getAugmentation(
- org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1.class).getLinkstatePathAttribute());
+ lsAttrBuilder.build().getLinkstatePathAttribute(),
+ attrs.getAugmentation(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1.class).getLinkstatePathAttribute());
final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mp.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
// attributes
final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
- new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
+ new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
final LocalNodeDescriptorsBuilder lndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
- new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
+ new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
final List<CLinkstateDestination> linkstates = Lists.newArrayList();
clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
- new OspfPseudonodeCaseBuilder().setOspfPseudonode(
- new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
+ new OspfPseudonodeCaseBuilder().setOspfPseudonode(
+ new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
linkstates.add(clBuilder.build());
clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
- new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x03030304L).build()).build()).build());
+ new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x03030304L).build()).build()).build());
linkstates.add(clBuilder.build());
clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
- new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
+ new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
linkstates.add(clBuilder.build());
final PathAttributes1Builder lsBuilder = new PathAttributes1Builder();
dBuilder.setCLinkstateDestination(linkstates);
mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
+ new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
lsBuilder.setMpReachNlri(mpBuilder.build());
final List<Segments> asPath = Lists.newArrayList();
public class ParserTest {
- public static final byte[] openBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ private static final byte[] openBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4,
(byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
- public static final byte[] keepAliveBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ private static final byte[] keepAliveBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0x00, (byte) 0x13, (byte) 0x04 };
- public static final byte[] notificationBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ private static final byte[] notificationBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x17, (byte) 0x03, (byte) 0x02, (byte) 0x04, (byte) 0x04, (byte) 0x09 };
- public static final byte[] openWithCpblt1 = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ private static final byte[] openWithCpblt1 = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0x00, (byte) 0x2d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x48, (byte) 0x00, (byte) 0xb4,
(byte) 0xac, (byte) 0x14, (byte) 0xa0, (byte) 0xaa, (byte) 0x10, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04,
(byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, (byte) 0x40,
(byte) 0x04, (byte) 0x00, (byte) 0x47 };
- public static final byte[] openWithCpblt2 = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ private static final byte[] openWithCpblt2 = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0x00, (byte) 0x2d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x48, (byte) 0x00, (byte) 0xb4,
(byte) 0xac, (byte) 0x14, (byte) 0xa0, (byte) 0xaa, (byte) 0x10, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04,
(byte) 0x40, (byte) 0x04, (byte) 0x00, (byte) 0x47, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, (byte) 0x00,
(byte) 0x01, (byte) 0x00, (byte) 0x01 };
- public static final byte[] updateMsg = {
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, 0x51, 0x02, 0x00, 0x00, 0x00, 0x36, 0x40, 0x01, 0x01, 0x00, 0x40, 0x02,
- 0x1a, 0x02, 0x06, 0x00, 0x00, (byte) 0xfe, 0x55, 0x00, 0x00, (byte) 0xfc, 0x12, 0x00, 0x00, 0x00, 0x6d, 0x00, 0x00, 0x02, (byte) 0xbd, 0x00, 0x00, 0x0d, 0x1c, 0x00, 0x00, 0x6a, 0x74, 0x40, 0x03,
- 0x04, 0x0a, 0x20, 0x00, (byte) 0xfe, (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x04, 0x00, 0x00, 0x00, 0x64, 0x18, (byte) 0xa8, (byte) 0xa1, (byte) 0xf7
- };
-
static MessageRegistry reg;
@BeforeClass
@Test
public void testKeepAliveMsg() throws BGPParsingException, BGPDocumentedException {
final Notification keepAlive = new KeepaliveBuilder().build();
- ByteBuf buffer = Unpooled.buffer();
+ final ByteBuf buffer = Unpooled.buffer();
ParserTest.reg.serializeMessage(keepAlive, buffer);
assertArrayEquals(keepAliveBMsg, ByteArray.getAllBytes(buffer));
@Test
public void testOpenMessage() throws UnknownHostException, BGPParsingException, BGPDocumentedException {
final Notification open = new OpenBuilder().setMyAsNumber(100).setHoldTimer(180).setBgpIdentifier(new Ipv4Address("20.20.20.20")).setVersion(
- new ProtocolVersion((short) 4)).build();
- ByteBuf bytes = Unpooled.buffer();
+ new ProtocolVersion((short) 4)).build();
+ final ByteBuf bytes = Unpooled.buffer();
ParserTest.reg.serializeMessage(open, bytes);
assertArrayEquals(openBMsg, ByteArray.getAllBytes(bytes));
@Test
public void testNotificationMsg() throws BGPParsingException, BGPDocumentedException {
Notification notMsg = new NotifyBuilder().setErrorCode(BGPError.OPT_PARAM_NOT_SUPPORTED.getCode()).setErrorSubcode(
- BGPError.OPT_PARAM_NOT_SUPPORTED.getSubcode()).setData(new byte[] { 4, 9 }).build();
- ByteBuf bytes = Unpooled.buffer();
+ BGPError.OPT_PARAM_NOT_SUPPORTED.getSubcode()).setData(new byte[] { 4, 9 }).build();
+ final ByteBuf bytes = Unpooled.buffer();
ParserTest.reg.serializeMessage(notMsg, bytes);
assertArrayEquals(notificationBMsg, ByteArray.subByte(bytes.array(),0,bytes.writerIndex()));
final Open open = new OpenBuilder().setMyAsNumber(72).setHoldTimer(180).setBgpIdentifier(new Ipv4Address("172.20.160.170")).setVersion(
new ProtocolVersion((short) 4)).setBgpParameters(tlvs).build();
- ByteBuf result = Unpooled.buffer();
+ final ByteBuf result = Unpooled.buffer();
ParserTest.reg.serializeMessage(open, result);
// the capabilities can be swapped.
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Set;
-
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
* @param fileNumber parameter to distinguish between files from which bytes are read
*/
private byte[] fillInputBytes(final int fileNumber) throws Exception {
-
- final InputStream is = this.getClass().getResourceAsStream("/up" + fileNumber + ".bin");
final ByteArrayOutputStream bis = new ByteArrayOutputStream();
final byte[] data = new byte[60];
int nRead = 0;
- while ((nRead = is.read(data, 0, data.length)) != -1) {
- bis.write(data, 0, nRead);
+ try (final InputStream is = this.getClass().getResourceAsStream("/up" + fileNumber + ".bin")) {
+ while ((nRead = is.read(data, 0, data.length)) != -1) {
+ bis.write(data, 0, nRead);
+ }
+ bis.flush();
+ is.close();
}
- bis.flush();
return bis.toByteArray();
}
final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(asn)).build());
final List<Segments> asPath = Lists.newArrayList();
asPath.add(new SegmentsBuilder().setCSegment(
- new AListCaseBuilder().setAList(new AListBuilder().setAsSequence(asnums).build()).build()).build());
+ new AListCaseBuilder().setAList(new AListBuilder().setAsSequence(asnums).build()).build()).build());
final CNextHop nextHop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(
- new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
+ new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
final Ipv6Prefix pref1 = new Ipv6Prefix("2001:db8:1:2::/64");
final Ipv6Prefix pref2 = new Ipv6Prefix("2001:db8:1:1::/64");
mpReachBuilder.setSafi(UnicastSubsequentAddressFamily.class);
mpReachBuilder.setCNextHop(nextHop);
mpReachBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationIpv6CaseBuilder().setDestinationIpv6(
- new DestinationIpv6Builder().setIpv6Prefixes(Lists.newArrayList(pref1, pref2, pref3)).build()).build()).build());
+ new DestinationIpv6CaseBuilder().setDestinationIpv6(
+ new DestinationIpv6Builder().setIpv6Prefixes(Lists.newArrayList(pref1, pref2, pref3)).build()).build()).build());
paBuilder.addAugmentation(PathAttributes1.class, new PathAttributes1Builder().setMpReachNlri(mpReachBuilder.build()).build());
final List<BgpParameters> params = Lists.newArrayList();
final CParameters par = new MultiprotocolCaseBuilder().setMultiprotocolCapability(
- new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class).setSafi(MplsLabeledVpnSubsequentAddressFamily.class).build()).build();
+ new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class).setSafi(MplsLabeledVpnSubsequentAddressFamily.class).build()).build();
params.add(new BgpParametersBuilder().setCParameters(par).build());
final byte[] input = new byte[] { 5, 8, 13, 21 };
openMap.put(Unpooled.copiedBuffer(input), new OpenBuilder().setMyAsNumber(30).setHoldTimer(30).setBgpParameters(params).setVersion(
- new ProtocolVersion((short) 4)).build());
+ new ProtocolVersion((short) 4)).build());
final BGPMessageParserMock mockParser = new BGPMessageParserMock(openMap);
public final class BaseBGPParserModule extends org.opendaylight.controller.config.yang.bgp.rib.impl.AbstractBaseBGPParserModule {
public BaseBGPParserModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
- final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+ final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
super(identifier, dependencyResolver);
}
public BaseBGPParserModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
- final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final BaseBGPParserModule oldModule,
- final java.lang.AutoCloseable oldInstance) {
+ final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final BaseBGPParserModule oldModule,
+ final java.lang.AutoCloseable oldInstance) {
super(identifier, dependencyResolver, oldModule, oldInstance);
}
- @Override
- public void validate() {
- super.validate();
- // Add custom validation for module attributes here.
- }
-
@Override
public java.lang.AutoCloseable createInstance() {
return new BGPActivator();
import io.netty.channel.socket.SocketChannel;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.Promise;
-
import java.net.InetSocketAddress;
-
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
-import org.opendaylight.protocol.bgp.rib.impl.spi.BGPServerDispatcher;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionValidator;
import org.opendaylight.protocol.framework.AbstractDispatcher;
import org.opendaylight.protocol.framework.ReconnectStrategy;
/**
* Implementation of BGPDispatcher.
*/
-public final class BGPDispatcherImpl extends AbstractDispatcher<BGPSessionImpl, BGPSessionListener> implements BGPDispatcher, BGPServerDispatcher, AutoCloseable {
+public final class BGPDispatcherImpl extends AbstractDispatcher<BGPSessionImpl, BGPSessionListener> implements BGPDispatcher, AutoCloseable {
private final MD5ServerChannelFactory<?> scf;
private final MD5ChannelFactory<?> cf;
private final BGPHandlerFactory hf;
@Override
public synchronized Future<BGPSessionImpl> createClient(final InetSocketAddress address,
- final AsNumber remoteAs, final BGPPeerRegistry listener, final ReconnectStrategy strategy) {
+ final AsNumber remoteAs, final BGPPeerRegistry listener, final ReconnectStrategy strategy) {
final BGPClientSessionNegotiatorFactory snf = new BGPClientSessionNegotiatorFactory(remoteAs, listener);
return super.createClient(address, strategy, new PipelineInitializer<BGPSessionImpl>() {
@Override
@Override
public Future<Void> createReconnectingClient(final InetSocketAddress address,
- final AsNumber remoteAs, final BGPPeerRegistry listener, final ReconnectStrategyFactory connectStrategyFactory,
- final ReconnectStrategyFactory reestablishStrategyFactory) {
+ final AsNumber remoteAs, final BGPPeerRegistry listener, final ReconnectStrategyFactory connectStrategyFactory,
+ final ReconnectStrategyFactory reestablishStrategyFactory) {
return this.createReconnectingClient(address, remoteAs, listener, connectStrategyFactory, reestablishStrategyFactory,
- null);
+ null);
}
@Override
@Override
public synchronized Future<Void> createReconnectingClient(final InetSocketAddress address,
- final AsNumber remoteAs, final BGPPeerRegistry peerRegistry, final ReconnectStrategyFactory connectStrategyFactory,
- final ReconnectStrategyFactory reestablishStrategyFactory, final KeyMapping keys) {
+ final AsNumber remoteAs, final BGPPeerRegistry peerRegistry, final ReconnectStrategyFactory connectStrategyFactory,
+ final ReconnectStrategyFactory reestablishStrategyFactory, final KeyMapping keys) {
final BGPClientSessionNegotiatorFactory snf = new BGPClientSessionNegotiatorFactory(remoteAs, peerRegistry);
this.keys = keys;
@Override
protected void customizeBootstrap(final Bootstrap b) {
- if (keys != null && !keys.isEmpty()) {
- if (cf == null) {
+ if (this.keys != null && !this.keys.isEmpty()) {
+ if (this.cf == null) {
throw new UnsupportedOperationException("No key access instance available, cannot use key mapping");
}
- b.channelFactory(cf);
- b.option(MD5ChannelOption.TCP_MD5SIG, keys);
+ b.channelFactory(this.cf);
+ b.option(MD5ChannelOption.TCP_MD5SIG, this.keys);
}
}
@Override
protected void customizeBootstrap(final ServerBootstrap b) {
- if (keys != null && !keys.isEmpty()) {
- if (scf == null) {
+ if (this.keys != null && !this.keys.isEmpty()) {
+ if (this.scf == null) {
throw new UnsupportedOperationException("No key access instance available, cannot use key mapping");
}
- b.channelFactory(scf);
- b.option(MD5ChannelOption.TCP_MD5SIG, keys);
+ b.channelFactory(this.scf);
+ b.option(MD5ChannelOption.TCP_MD5SIG, this.keys);
}
}
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.net.InetAddresses;
-
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
-
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathAttributes;
// 2. prefer path with higher LOCAL_PREF
if ((o1.getLocalPref() != null || o2.getLocalPref() != null)
- && (o1.getLocalPref() != null && !o1.getLocalPref().equals(o2.getLocalPref()))) {
+ && (o1.getLocalPref() != null && !o1.getLocalPref().equals(o2.getLocalPref()))) {
return o1.getLocalPref().getPref().compareTo(o2.getLocalPref().getPref());
}
// 6. prefer the path with the lowest multi-exit discriminator (MED)
if ((o1.getMultiExitDisc() != null || o2.getMultiExitDisc() != null)
- && (o1.getMultiExitDisc() != null && !o1.getMultiExitDisc().equals(o2.getMultiExitDisc()))) {
+ && (o1.getMultiExitDisc() != null && !o1.getMultiExitDisc().equals(o2.getMultiExitDisc()))) {
return o2.getMultiExitDisc().getMed().compareTo(o1.getMultiExitDisc().getMed());
}
final AsNumber first = getPeerAs(o1.getAsPath().getSegments());
final AsNumber second = getPeerAs(o2.getAsPath().getSegments());
if ((first != null || second != null) && (first != null && !first.equals(second))) {
- if (first == null || first.equals(this.ourAS)) {
+ if (first.equals(this.ourAS)) {
return -1;
}
if (second == null || second.equals(this.ourAS)) {
LOG.info("Session with peer {} went up with tables: {}", this.name, session.getAdvertisedTableTypes());
this.session = session;
- this.comparator = new BGPObjectComparator(this.rib.getLocalAs(), rib.getBgpIdentifier(), session.getBgpId());
+ this.comparator = new BGPObjectComparator(this.rib.getLocalAs(), this.rib.getBgpIdentifier(), session.getBgpId());
for (final BgpTableType t : session.getAdvertisedTableTypes()) {
final TablesKey key = new TablesKey(t.getAfi(), t.getSafi());
}
@Override
- public Comparator<PathAttributes> getComparator() {
+ public synchronized Comparator<PathAttributes> getComparator() {
return this.comparator;
}
protected RIB getRib() {
- return rib;
+ return this.rib;
}
@Override
* @param msg incoming message
*/
@Override
- public void handleMessage(final Notification msg) {
+ public synchronized void handleMessage(final Notification msg) {
// Update last reception time
this.lastMessageReceivedAt = System.nanoTime();
} else if (msg instanceof Notify) {
// Notifications are handled internally
LOG.info("Session closed because Notification message received: {} / {}", ((Notify) msg).getErrorCode(),
- ((Notify) msg).getErrorSubcode());
+ ((Notify) msg).getErrorSubcode());
this.closeWithoutMessage();
this.listener.onSessionTerminated(this, new BGPTerminationReason(BGPError.forValue(((Notify) msg).getErrorCode(),
- ((Notify) msg).getErrorSubcode())));
+ ((Notify) msg).getErrorSubcode())));
} else if (msg instanceof Keepalive) {
// Keepalives are handled internally
LOG.trace("Received KeepAlive messsage.");
}
}
- void sendMessage(final Notification msg) {
+ synchronized void sendMessage(final Notification msg) {
try {
this.channel.writeAndFlush(msg);
this.lastMessageSentAt = System.nanoTime();
return new Ipv6RouteBuilder().setKey(InstanceIdentifier.keyOf(id)).setAttributes(new AttributesBuilder(attributes).build()).build();
}
};
-
+ Preconditions.checkArgument(nlri.getAdvertizedRoutes().getDestinationType() instanceof DestinationIpv6);
for (final Ipv6Prefix id : ((DestinationIpv6) nlri.getAdvertizedRoutes().getDestinationType()).getIpv6Prefixes()) {
super.add(trans, peer, id, data);
}
package org.opendaylight.protocol.bgp.rib.impl;
+import com.google.common.base.CharMatcher;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
private static final Logger LOG = LoggerFactory.getLogger(StrictBGPPeerRegistry.class);
+ private static final CharMatcher NONDIGIT = CharMatcher.inRange('0', '9').negate();
+
// TODO remove backwards compatibility
public static final StrictBGPPeerRegistry GLOBAL = new StrictBGPPeerRegistry();
@Override
public synchronized void addPeer(final IpAddress ip, final ReusableBGPPeer peer, final BGPSessionPreferences preferences) {
Preconditions.checkNotNull(ip);
- Preconditions.checkArgument(!peers.containsKey(ip), "Peer for %s already present", ip);
- peers.put(ip, Preconditions.checkNotNull(peer));
- peerPreferences.put(ip, Preconditions.checkNotNull(preferences));
+ Preconditions.checkArgument(!this.peers.containsKey(ip), "Peer for %s already present", ip);
+ this.peers.put(ip, Preconditions.checkNotNull(peer));
+ this.peerPreferences.put(ip, Preconditions.checkNotNull(preferences));
}
@Override
public synchronized void removePeer(final IpAddress ip) {
Preconditions.checkNotNull(ip);
- peers.remove(ip);
+ this.peers.remove(ip);
}
@Override
public boolean isPeerConfigured(final IpAddress ip) {
Preconditions.checkNotNull(ip);
- return peers.containsKey(ip);
+ return this.peers.containsKey(ip);
}
private void checkPeerConfigured(final IpAddress ip) {
- Preconditions.checkState(isPeerConfigured(ip), "BGP peer with ip: %s not configured, configured peers are: %s", ip, peers.keySet());
+ Preconditions.checkState(isPeerConfigured(ip), "BGP peer with ip: %s not configured, configured peers are: %s", ip, this.peers.keySet());
}
@Override
public synchronized BGPSessionListener getPeer(final IpAddress ip,
- final Ipv4Address sourceId, final Ipv4Address remoteId)
+ final Ipv4Address sourceId, final Ipv4Address remoteId)
throws BGPDocumentedException {
Preconditions.checkNotNull(ip);
Preconditions.checkNotNull(sourceId);
final BGPSessionId currentConnection = new BGPSessionId(sourceId, remoteId);
- if (sessionIds.containsKey(ip)) {
+ if (this.sessionIds.containsKey(ip)) {
LOG.warn("Duplicate BGP session established with {}", ip);
- final BGPSessionId previousConnection = sessionIds.get(ip);
+ final BGPSessionId previousConnection = this.sessionIds.get(ip);
// Session reestablished with different ids
if (!previousConnection.equals(currentConnection)) {
LOG.warn("BGP session with {} {} has to be dropped. Same session already present {}", ip, currentConnection, previousConnection);
throw new BGPDocumentedException(
- String.format("BGP session with %s %s has to be dropped. Same session already present %s",
- ip, currentConnection, previousConnection),
+ String.format("BGP session with %s %s has to be dropped. Same session already present %s",
+ ip, currentConnection, previousConnection),
BGPError.CEASE);
- // Session reestablished with lower source bgp id, dropping current
+ // Session reestablished with lower source bgp id, dropping current
} else if (previousConnection.isHigherDirection(currentConnection)) {
LOG.warn("BGP session with {} {} has to be dropped. Opposite session already present", ip, currentConnection);
throw new BGPDocumentedException(
- String.format("BGP session with %s initiated %s has to be dropped. Opposite session already present",
- ip, currentConnection),
+ String.format("BGP session with %s initiated %s has to be dropped. Opposite session already present",
+ ip, currentConnection),
BGPError.CEASE);
- // Session reestablished with higher source bgp id, dropping previous
+ // Session reestablished with higher source bgp id, dropping previous
} else if (currentConnection.isHigherDirection(previousConnection)) {
LOG.warn("BGP session with {} {} released. Replaced by opposite session", ip, previousConnection);
- peers.get(ip).releaseConnection();
- return peers.get(ip);
+ this.peers.get(ip).releaseConnection();
+ return this.peers.get(ip);
- // Session reestablished with same source bgp id, dropping current as duplicate
+ // Session reestablished with same source bgp id, dropping current as duplicate
} else {
LOG.warn("BGP session with %s initiated from %s to %s has to be dropped. Same session already present", ip, sourceId, remoteId);
throw new BGPDocumentedException(
- String.format("BGP session with %s initiated %s has to be dropped. Same session already present",
- ip, currentConnection),
+ String.format("BGP session with %s initiated %s has to be dropped. Same session already present",
+ ip, currentConnection),
BGPError.CEASE);
}
}
// Map session id to peer IP address
- sessionIds.put(ip, currentConnection);
- return peers.get(ip);
+ this.sessionIds.put(ip, currentConnection);
+ return this.peers.get(ip);
}
@Override
public BGPSessionPreferences getPeerPreferences(final IpAddress ip) {
Preconditions.checkNotNull(ip);
checkPeerConfigured(ip);
- return peerPreferences.get(ip);
+ return this.peerPreferences.get(ip);
}
/**
@Override
public synchronized void close() {
- peers.clear();
- sessionIds.clear();
+ this.peers.clear();
+ this.sessionIds.clear();
}
@Override
public String toString() {
return Objects.toStringHelper(this)
- .add("peers", peers.keySet())
- .toString();
+ .add("peers", this.peers.keySet())
+ .toString();
}
/**
final BGPSessionId bGPSessionId = (BGPSessionId) o;
- if (!from.equals(bGPSessionId.from) && !from.equals(bGPSessionId.to)) {
+ if (!this.from.equals(bGPSessionId.from) && !this.from.equals(bGPSessionId.to)) {
return false;
}
- if (!to.equals(bGPSessionId.to) && !to.equals(bGPSessionId.from)) {
+ if (!this.to.equals(bGPSessionId.to) && !this.to.equals(bGPSessionId.from)) {
return false;
}
@Override
public int hashCode() {
final int prime = 31;
- int result = from.hashCode() + to.hashCode();
+ int result = this.from.hashCode() + this.to.hashCode();
result = prime * result;
return result;
}
*/
boolean isHigherDirection(final BGPSessionId other) {
Preconditions.checkState(!this.isSameDirection(other), "Equal sessions with same direction");
- return toLong(from) > toLong(other.from);
+ return toLong(this.from) > toLong(other.from);
}
private long toLong(final Ipv4Address from) {
- return Long.valueOf(from.getValue().replaceAll("[^0-9]", ""));
+ return Long.parseLong(NONDIGIT.removeFrom(from.getValue()));
}
/**
*/
boolean isSameDirection(final BGPSessionId other) {
Preconditions.checkState(this.equals(other), "Only equal sessions can be compared");
- return from.equals(other.from);
+ return this.from.equals(other.from);
}
@Override
public String toString() {
return Objects.toStringHelper(this)
- .add("from", from)
- .add("to", to)
- .toString();
+ .add("from", this.from)
+ .add("to", this.to)
+ .toString();
}
}
}
private static final Logger LOG = LoggerFactory.getLogger(Main.class);
private static final String USAGE = "DESCRIPTION:\n"
- + "\tCreates a server with given parameters. As long as it runs, it accepts connections " + "from PCCs.\n" + "USAGE:\n"
- + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n"
- + "\t\tFormat: x.x.x.x:y where y is port number.\n\n"
- + "\t\tThis IP address will appear in BGP Open message as BGP Identifier of the server.\n" +
+ + "\tCreates a server with given parameters. As long as it runs, it accepts connections " + "from PCCs.\n" + "USAGE:\n"
+ + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n"
+ + "\t\tFormat: x.x.x.x:y where y is port number.\n\n"
+ + "\t\tThis IP address will appear in BGP Open message as BGP Identifier of the server.\n" +
"\t-as\n" + "\t\t value of AS in the initial open message\n\n" +
private static final int RECONNECT_MILLIS = 5000;
private Main() throws Exception {
- BGPActivator bgpActivator = new BGPActivator();
+ final BGPActivator bgpActivator = new BGPActivator();
bgpActivator.start(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance());
this.dispatcher = new BGPDispatcherImpl(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry(), new NioEventLoopGroup(), new NioEventLoopGroup());
}
while (i < args.length) {
if (args[i].equalsIgnoreCase("-a") || args[i].equalsIgnoreCase("--address")) {
final String[] ip = args[i + 1].split(":");
- address = new InetSocketAddress(InetAddress.getByName(ip[0]), Integer.valueOf(ip[1]));
+ address = new InetSocketAddress(InetAddress.getByName(ip[0]), Integer.parseInt(ip[1]));
i++;
} else if (args[i].equalsIgnoreCase("-h") || args[i].equalsIgnoreCase("--holdtimer")) {
holdTimerValue = Short.valueOf(args[i + 1]);
strictBGPPeerRegistry.addPeer(StrictBGPPeerRegistry.getIpAddress(address), sessionListener, proposal);
m.dispatcher.createClient(addr, as, strictBGPPeerRegistry,
- new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, RECONNECT_MILLIS));
+ new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, RECONNECT_MILLIS));
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;
-
import org.junit.Test;
public class BGPHexFileParserTest {
public static final String hexDumpFileName = "bgp_hex.txt";
- private final String fileNameInvalid = "BgpMessage_Hex_InvalidLength.bin";
- private final int expectedSize = 25;
+ private static final String fileNameInvalid = "BgpMessage_Hex_InvalidLength.bin";
+ private static final int expectedSize = 25;
@Test
public void testCleanWhiteSpace() {
@Test
public void testParsing() throws Exception {
final List<byte[]> result = HexDumpBGPFileParser.parseMessages(getClass().getClassLoader().getResourceAsStream(
- BGPHexFileParserTest.hexDumpFileName));
- assertEquals(this.expectedSize, result.size());
+ BGPHexFileParserTest.hexDumpFileName));
+ assertEquals(expectedSize, result.size());
}
@Test
public void testParsingInvalidMessage() throws Exception {
try {
- HexDumpBGPFileParser.parseMessages(getClass().getClassLoader().getResourceAsStream(this.fileNameInvalid));
+ HexDumpBGPFileParser.parseMessages(getClass().getClassLoader().getResourceAsStream(fileNameInvalid));
fail("Exception should have occured.");
} catch (final IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("Invalid message at index 0, length atribute is lower than 19"));