</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <configuration>
+ <failOnError>true</failOnError>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
<scm>
<connection>scm:git:ssh://git.opendaylight.org:29418/bgpcep.git</connection>
<developerConnection>scm:git:ssh://git.opendaylight.org:29418/bgpcep.git</developerConnection>
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <configuration>
+ <failOnError>true</failOnError>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
<scm>
<connection>scm:git:ssh://git.opendaylight.org:29418/bgpcep.git</connection>
<developerConnection>scm:git:ssh://git.opendaylight.org:29418/bgpcep.git</developerConnection>
import org.slf4j.LoggerFactory;
/**
- * There are several errors documented in RFC4271 or in draft, that have specific meaning for the BGP. This exception is
- * used, when any of those errors occurs.
+ * There are several errors documented in RFC4271 or in draft, that have specific meaning for the BGP.
+ * This exception is used, when any of those errors occurs.
*/
public final class BGPDocumentedException extends Exception {
* @param data data associated with the error
* @param cause cause for the error
*/
- public BGPDocumentedException(final String message, final BGPError error, final byte[] data, final Exception cause) {
+ public BGPDocumentedException(final String message, final BGPError error, final byte[] data,
+ final Exception cause) {
super(message, cause);
this.error = error;
this.data = data == null ? null : Arrays.copyOf(data, data.length);
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
+import java.io.Serializable;
import java.util.Map;
/**
- * Possible errors from implemented RFCs and drafts. Each error consists of error code and error subcode (code/subcode
- * in comments).
+ * Possible errors from implemented RFCs and drafts. Each error consists of error code and error subcode
+ * (code/subcode in comments).
*
* @see <a href="http://tools.ietf.org/html/rfc4271#section-4.5">BGP Notification Message</a>
*/
*/
OUT_OF_RESOURCES((short) 6, (short) 8),
/**
- * Unsupported Capability 2/7
+ * Unsupported Capability. 2/7
*/
UNSUPPORTED_CAPABILITY((short) 2, (short) 7);
this.errorId = new BGPErrorIdentifier(code, subcode);
}
+ public static BGPError forValue(final int code, final int subcode) {
+ final BGPError e = VALUE_MAP.get(new BGPErrorIdentifier((short) code, (short) subcode));
+ Preconditions.checkArgument(e != null, "BGP Error code %s and subcode %s not recognized.",
+ code, subcode);
+ return e;
+ }
+
public short getCode() {
- return this.errorId.getCode();
+ return this.errorId.code;
}
public short getSubcode() {
- return this.errorId.getSubCode();
+ return this.errorId.subcode;
}
private BGPErrorIdentifier getErrorIdentifier() {
return this.errorId;
}
- public static BGPError forValue(final int code, final int subcode) {
- final BGPError e = VALUE_MAP.get(new BGPErrorIdentifier((short) code, (short) subcode));
- Preconditions.checkArgument(e != null, "BGP Error code %s and subcode %s not recognized.", code, subcode);
- return e;
+ /**
+ * Caret for combination of Error-type and Error-value.
+ */
+ private static class BGPErrorIdentifier implements Serializable {
+ private static final long serialVersionUID = 5722575354944165734L;
+ final short code;
+ final short subcode;
+
+ BGPErrorIdentifier(final short code, final short subcode) {
+ this.code = code;
+ this.subcode = subcode;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + this.code;
+ result = prime * result + this.subcode;
+ return result;
+ }
+
+ @Override
+ public boolean equals(final java.lang.Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || this.getClass() != obj.getClass()) {
+ return false;
+ }
+ final BGPErrorIdentifier other = (BGPErrorIdentifier) obj;
+ return this.code == other.code && this.subcode == other.subcode;
+ }
+
+ @Override
+ public String toString() {
+ return "type " + this.code + " value " + this.subcode;
+ }
}
}
+++ /dev/null
-/*
- * Copyright (c) 2014 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.parser;
-
-import java.io.Serializable;
-
-/**
- * Caret for combination of Error-type and Error-value
- */
-final class BGPErrorIdentifier implements Serializable {
- private static final long serialVersionUID = 5722575354944165734L;
- private final short code;
- private final short subcode;
-
- BGPErrorIdentifier(final short code, final short subcode) {
- this.code = code;
- this.subcode = subcode;
- }
-
- public short getCode() {
- return this.code;
- }
-
- public short getSubCode() {
- return this.subcode;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + this.code;
- result = prime * result + this.subcode;
- return result;
- }
-
- @Override
- public boolean equals(final java.lang.Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null || this.getClass() != obj.getClass()) {
- return false;
- }
- final BGPErrorIdentifier other = (BGPErrorIdentifier) obj;
- if (this.code != other.code || this.subcode != other.subcode) {
- return false;
- }
- return true;
- }
-
- @Override
- public String toString() {
- return "type " + this.code + " value " + this.subcode;
- }
-}
package org.opendaylight.protocol.bgp.parser;
/**
- *
* Used when something occurs during the parsing to get Update Message.
- *
*/
public class BGPParsingException extends Exception {
private static final long serialVersionUID = 1L;
* Creates new BGPParsingException with specific message and cause.
*
* @param message exception message
- * @param cause primary exception
+ * @param cause primary exception
*/
public BGPParsingException(final String message, final Exception cause) {
super(message, cause);
public final class BgpExtendedMessageUtil {
public static final CParameters EXTENDED_MESSAGE_CAPABILITY =
- new CParametersBuilder().setBgpExtendedMessageCapability(new BgpExtendedMessageCapabilityBuilder().build()).build();
+ new CParametersBuilder().setBgpExtendedMessageCapability(new BgpExtendedMessageCapabilityBuilder()
+ .build()).build();
private BgpExtendedMessageUtil() {
throw new UnsupportedOperationException();
* @param afi Address Family Identifier
* @param safi Subsequent Address Family Identifier
*/
- public BgpTableTypeImpl(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) {
+ public BgpTableTypeImpl(final Class<? extends AddressFamily> afi,
+ final Class<? extends SubsequentAddressFamily> safi) {
this.afi = requireNonNull(afi, "Address family may not be null");
this.safi = requireNonNull(safi, "Subsequent address family may not be null");
}
import static org.junit.Assert.assertEquals;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
public void testAsNumberUtil() {
final List<BgpParameters> params = new ArrayList<>();
final List<OptionalCapabilities> capas = new ArrayList<>();
- capas.add(new OptionalCapabilitiesBuilder().setCParameters( new CParametersBuilder().addAugmentation(
- CParameters1.class, new CParameters1Builder().setMultiprotocolCapability( new MultiprotocolCapabilityBuilder()
- .build()).build()).build()).build());
+ capas.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(
+ CParameters1.class, new CParameters1Builder().setMultiprotocolCapability(
+ new MultiprotocolCapabilityBuilder().build()).build()).build()).build());
capas.add(new OptionalCapabilitiesBuilder().setCParameters(
- new CParametersBuilder().setAs4BytesCapability( new As4BytesCapabilityBuilder().setAsNumber(
- new AsNumber(35L)).build()).build()).build());
+ new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(
+ new AsNumber(35L)).build()).build()).build());
params.add(new BgpParametersBuilder().setOptionalCapabilities(capas).build());
final Open open1 = new OpenBuilder().setBgpParameters(params).build();
assertEquals(35L, AsNumberUtil.advertizedAsNumber(open1).getValue().longValue());
public void testBgpExtendedMessageUtil() {
final List<BgpParameters> params = new ArrayList<>();
final List<OptionalCapabilities> capas = new ArrayList<>();
- capas.add(new OptionalCapabilitiesBuilder().setCParameters( new CParametersBuilder().addAugmentation(
- CParameters1.class, new CParameters1Builder().setMultiprotocolCapability( new MultiprotocolCapabilityBuilder()
- .build()).build()).build()).build());
+ capas.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(
+ CParameters1.class, new CParameters1Builder()
+ .setMultiprotocolCapability(new MultiprotocolCapabilityBuilder()
+ .build()).build()).build()).build());
capas.add(new OptionalCapabilitiesBuilder().setCParameters(
BgpExtendedMessageUtil.EXTENDED_MESSAGE_CAPABILITY).build());
params.add(new BgpParametersBuilder().setOptionalCapabilities(capas).build());
final Open open1 = new OpenBuilder().setBgpParameters(params).build();
assertEquals(true, BgpExtendedMessageUtil.advertizedBgpExtendedMessageCapability(open1));
}
-
- @Test(expected=UnsupportedOperationException.class)
- public void testAsNumberUtilPrivateConstructor() throws Throwable {
- final Constructor<AsNumberUtil> c = AsNumberUtil.class.getDeclaredConstructor();
- c.setAccessible(true);
- try {
- c.newInstance();
- } catch (final InvocationTargetException e) {
- throw e.getCause();
- }
- }
}
@Test
public void testTableTypes() {
- final BgpTableType tt1 = new BgpTableTypeImpl(Ipv4AddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class);
- final BgpTableType tt2 = new BgpTableTypeImpl(Ipv6AddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class);
+ final BgpTableType tt1 = new BgpTableTypeImpl(Ipv4AddressFamily.class,
+ MplsLabeledVpnSubsequentAddressFamily.class);
+ final BgpTableType tt2 = new BgpTableTypeImpl(Ipv6AddressFamily.class,
+ MplsLabeledVpnSubsequentAddressFamily.class);
try {
new BgpTableTypeImpl(null, MplsLabeledVpnSubsequentAddressFamily.class);
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <configuration>
+ <failOnError>true</failOnError>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
<scm>
<connection>scm:git:ssh://git.opendaylight.org:29418/bgpcep.git</connection>
<developerConnection>scm:git:ssh://git.opendaylight.org:29418/bgpcep.git</developerConnection>
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.RibKey;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-/**
- *
- */
public class DefaultRibReference implements RibReference {
private final KeyedInstanceIdentifier<Rib, RibKey> instanceIdentifier;
import java.util.Set;
import java.util.concurrent.atomic.LongAdder;
import javax.annotation.Nonnull;
+import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.NotThreadSafe;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener;
private static final Logger LOG = LoggerFactory.getLogger(LocRibWriter.class);
- private static final LeafNode<Boolean> ATTRIBUTES_UPTODATE_TRUE = ImmutableNodes.leafNode(QName.create(Attributes.QNAME, "uptodate"), Boolean.TRUE);
+ private static final LeafNode<Boolean> ATTRIBUTES_UPTODATE_TRUE = ImmutableNodes
+ .leafNode(QName.create(Attributes.QNAME, "uptodate"), Boolean.TRUE);
private final Map<PathArgument, RouteEntry> routeEntries = new HashMap<>();
private final YangInstanceIdentifier locRibTarget;
private final NodeIdentifierWithPredicates tableKey;
- private DOMTransactionChain chain;
private final ExportPolicyPeerTracker exportPolicyPeerTracker;
private final NodeIdentifier attributesIdentifier;
private final Long ourAs;
private final TablesKey localTablesKey;
private final YangInstanceIdentifier target;
private final DOMDataTreeChangeService service;
- private ListenerRegistration<LocRibWriter> reg;
private final PathSelectionMode pathSelectionMode;
private final LongAdder totalPathsCounter = new LongAdder();
private final LongAdder totalPrefixesCounter = new LongAdder();
+ private DOMTransactionChain chain;
+ @GuardedBy("this")
+ private ListenerRegistration<LocRibWriter> reg;
private LocRibWriter(final RIBSupportContextRegistry registry, final DOMTransactionChain chain,
final YangInstanceIdentifier target, final Long ourAs, final DOMDataTreeChangeService service,
this.reg = this.service.registerDataTreeChangeListener(wildcard, this);
}
- public static LocRibWriter create(@Nonnull final RIBSupportContextRegistry registry, @Nonnull final TablesKey tablesKey,
- @Nonnull final DOMTransactionChain chain,
- @Nonnull final YangInstanceIdentifier target, @Nonnull final AsNumber ourAs, @Nonnull final DOMDataTreeChangeService service,
- @Nonnull final ExportPolicyPeerTracker ep, @Nonnull final PathSelectionMode pathSelectionStrategy) {
+ public static LocRibWriter create(@Nonnull final RIBSupportContextRegistry registry,
+ @Nonnull final TablesKey tablesKey,
+ @Nonnull final DOMTransactionChain chain,
+ @Nonnull final YangInstanceIdentifier target,
+ @Nonnull final AsNumber ourAs,
+ @Nonnull final DOMDataTreeChangeService service,
+ @Nonnull final ExportPolicyPeerTracker ep,
+ @Nonnull final PathSelectionMode pathSelectionStrategy) {
return new LocRibWriter(registry, chain, target, ourAs.getValue(), service, ep, tablesKey,
- pathSelectionStrategy);
+ pathSelectionStrategy);
}
/**
}
@Override
- public void close() {
- this.reg.close();
- this.reg = null;
+ public synchronized void close() {
+ if (this.reg != null) {
+ this.reg.close();
+ this.reg = null;
+ }
this.chain.close();
}
}
}
- private Map<RouteUpdateKey, RouteEntry> update(final DOMDataWriteTransaction tx, final Collection<DataTreeCandidate> changes) {
+ private Map<RouteUpdateKey, RouteEntry> update(final DOMDataWriteTransaction tx,
+ final Collection<DataTreeCandidate> changes) {
final Map<RouteUpdateKey, RouteEntry> ret = new HashMap<>();
changes.forEach(tc -> {
final DataTreeCandidateNode table = tc.getRootNode();
return ret;
}
- private void initializeTableWithExistentRoutes(final DataTreeCandidateNode table, final PeerId peerIdOfNewPeer, final YangInstanceIdentifier rootPath,
+ private void initializeTableWithExistentRoutes(final DataTreeCandidateNode table, final PeerId peerIdOfNewPeer,
+ final YangInstanceIdentifier rootPath,
final DOMDataWriteTransaction tx) {
if (!table.getDataBefore().isPresent() && this.exportPolicyPeerTracker.isTableSupported(peerIdOfNewPeer)) {
this.exportPolicyPeerTracker.registerPeerAsInitialized(peerIdOfNewPeer);
if (child.getDataAfter().isPresent()) {
// putting uptodate attribute in
LOG.trace("Uptodate found for {}", child.getDataAfter());
- tx.put(LogicalDatastoreType.OPERATIONAL, this.locRibTarget.node(child.getIdentifier()), child.getDataAfter().get());
+ tx.put(LogicalDatastoreType.OPERATIONAL, this.locRibTarget.node(child.getIdentifier()),
+ child.getDataAfter().get());
}
continue;
}
}
}
- private void updateRoutesEntries(final DataTreeCandidateNode child, final PeerId peerId, final Map<RouteUpdateKey, RouteEntry> routes) {
+ private void updateRoutesEntries(final DataTreeCandidateNode child, final PeerId peerId,
+ final Map<RouteUpdateKey, RouteEntry> routes) {
final UnsignedInteger routerId = RouterIds.routerIdForPeerId(peerId);
final Collection<DataTreeCandidateNode> modifiedRoutes = this.ribSupport.changedRoutes(child);
for (final DataTreeCandidateNode route : modifiedRoutes) {
if (entry == null) {
entry = createEntry(routeId);
}
- entry.addRoute(routerId, this.ribSupport.extractPathId(maybeData.get()), this.attributesIdentifier, maybeData.get());
+ entry.addRoute(routerId, this.ribSupport.extractPathId(maybeData.get()),
+ this.attributesIdentifier, maybeData.get());
this.totalPathsCounter.increment();
} else if (entry != null) {
this.totalPathsCounter.decrement();
}
}
- private void walkThrough(final DOMDataWriteTransaction tx, final Set<Map.Entry<RouteUpdateKey, RouteEntry>> toUpdate) {
+ private void walkThrough(final DOMDataWriteTransaction tx,
+ final Set<Map.Entry<RouteUpdateKey, RouteEntry>> toUpdate) {
for (final Map.Entry<RouteUpdateKey, RouteEntry> e : toUpdate) {
LOG.trace("Walking through {}", e);
final RouteEntry entry = e.getValue();
LOG.trace("Best path has not changed, continuing");
continue;
}
- entry.updateRoute(this.localTablesKey, this.exportPolicyPeerTracker, this.locRibTarget, this.ribSupport, tx, e.getKey().getRouteId());
+ entry.updateRoute(this.localTablesKey, this.exportPolicyPeerTracker, this.locRibTarget,
+ this.ribSupport, tx, e.getKey().getRouteId());
}
}
private final YangInstanceIdentifier yangRibId;
private final RIBSupportContextRegistryImpl ribContextRegistry;
private final CodecsRegistryImpl codecsRegistry;
+ @GuardedBy("this")
private ClusterSingletonServiceRegistration registration;
private final DOMDataBrokerExtension service;
private final Map<TransactionChain<?, ?>, LocRibWriter> txChainToLocRibWriter = new HashMap<>();
* @param retryTimer Retry timer
* @return Future promising a client session
*/
+ @Deprecated
Future<? extends BGPSession> createClient(InetSocketAddress remoteAddress, int retryTimer);
/**
<build>
<plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <configuration>
+ <failOnError>true</failOnError>
+ </configuration>
+ </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
private static final int INITIAL_HOLD_TIME = 90;
private static final String LOG_LEVEL = "log_level";
private static final String REMOTE_ADDRESS_PARAMETER = "remoteAddress";
- private static final String REMOTE_ADDRESS_PARAMETER_HELP = "IP address of remote BGP peer, which the tool can accept or initiate connect to that " +
- "address (based on the mode)";
+ private static final String REMOTE_ADDRESS_PARAMETER_HELP = "IP address of remote BGP peer, which the tool"
+ + " can accept or initiate connect to that address (based on the mode)";
private static final String LOCAL_ADDRESS_PARAMETER = "localAddress";
private static final String LOCAL_ADDRESS_PARAMETER_HELP = "IP address of BGP speakers which the tools simulates";
private static final String EXTENDED_COMMUNITIES_PARAMETER = "extended_communities";
- private static final String EXTENDED_COMMUNITIES_PARAMETER_HELP = "Extended communities to be send. Format: x,x,x where x is each extended " +
- "community from bgp-types.yang as as-4-generic-spec-extended-community, link-bandwidth-extended-community, ...";
+ private static final String EXTENDED_COMMUNITIES_PARAMETER_HELP = "Extended communities to be send. "
+ + "Format: x,x,x where x is each extended community from bgp-types.yang as "
+ + "as-4-generic-spec-extended-community, link-bandwidth-extended-community, ...";
private static final String ACTIVE_CONNECTION_PARAMETER = "active";
private static final String ACTIVE_CONNECTION_HELP = "Active initialization of the connection, by default false";
private static final String HOLD_TIMER_PARAMETER = "holdtimer";
- private static final String INITIAL_HOLD_TIME_HELP = "In seconds, value of the desired holdtimer. According to RFC4271, recommended value for " +
- "deadtimer is 90 seconds(set by default)";
+ private static final String INITIAL_HOLD_TIME_HELP = "In seconds, value of the desired holdtimer."
+ + " According to RFC4271, recommended value for deadtimer is 90 seconds(set by default)";
private static final String PREFIXES_PARAMETER = "prefixes";
private static final String PREFIXES_PARAMETER_HELP = "Number of prefixes to be sent";
private static final String MULTIPATH_PARAMETER = "multiPathSupport";
private static final String AS_PARAMETER = "as";
private static final String AS_PARAMETER_HELP = "Value of AS in the initial open message";
private static final String SPEAKERS_COUNT = "speakersCount";
- private static final String SPEAKERS_COUNT_HELP = "Number of simulated BGP speakers, when creating each speaker, use incremented " +
- "local-address for binding";
+ private static final String SPEAKERS_COUNT_HELP = "Number of simulated BGP speakers, when creating each speaker,"
+ + " use incremented local-address for binding";
private static final ArgumentParser ARGUMENT_PARSER = initializeArgumentParser();
private final Namespace parseArgs;
private static ArgumentParser initializeArgumentParser() {
final ArgumentParser parser = ArgumentParsers.newArgumentParser(PROGRAM_NAME);
- parser.addArgument("-i", toArgName(ACTIVE_CONNECTION_PARAMETER)).type(Boolean.class).setDefault(false).help(ACTIVE_CONNECTION_HELP);
- parser.addArgument("-ho", toArgName(HOLD_TIMER_PARAMETER)).type(Integer.class).setDefault(INITIAL_HOLD_TIME).help(INITIAL_HOLD_TIME_HELP);
- parser.addArgument("-pr", toArgName(PREFIXES_PARAMETER)).type(Integer.class).setDefault(0).help(PREFIXES_PARAMETER_HELP);
- parser.addArgument("-sc", toArgName(SPEAKERS_COUNT)).type(Integer.class).setDefault(0).help(SPEAKERS_COUNT_HELP);
- parser.addArgument("-mp", toArgName(MULTIPATH_PARAMETER)).type(Boolean.class).setDefault(false).help(MULTIPATH_PARAMETER_HELP);
- parser.addArgument("-" + AS_PARAMETER, toArgName(AS_PARAMETER)).type((ArgumentTypeTool<AsNumber>) as -> new AsNumber(Long.valueOf(as)))
- .setDefault(new AsNumber(64496L)).help(AS_PARAMETER_HELP);
- parser.addArgument("-ec", toArgName(EXTENDED_COMMUNITIES_PARAMETER)).type((ArgumentTypeTool<List<String>>) extComInput ->
- Arrays.asList(extComInput.split(","))).setDefault(Collections.emptyList()).help(EXTENDED_COMMUNITIES_PARAMETER_HELP);
- parser.addArgument("-ll", toArgName(LOG_LEVEL)).type((ArgumentTypeTool<Level>) Level::toLevel).setDefault(Level.INFO).help("log levels");
- parser.addArgument("-ra", toArgName(REMOTE_ADDRESS_PARAMETER)).type((ArgumentTypeTool<List<InetSocketAddress>>) input ->
- InetSocketAddressUtil.parseAddresses(input, DEFAULT_REMOTE_PORT)).setDefault(Collections.singletonList(REMOTE_ADDRESS))
- .help(REMOTE_ADDRESS_PARAMETER_HELP);
- parser.addArgument("-la", toArgName(LOCAL_ADDRESS_PARAMETER)).type((ArgumentTypeTool<InetSocketAddress>) input ->
- getInetSocketAddress(input, DEFAULT_LOCAL_PORT)).setDefault(LOCAL_ADDRESS).help(LOCAL_ADDRESS_PARAMETER_HELP);
+ parser.addArgument("-i", toArgName(ACTIVE_CONNECTION_PARAMETER)).type(Boolean.class)
+ .setDefault(false).help(ACTIVE_CONNECTION_HELP);
+ parser.addArgument("-ho", toArgName(HOLD_TIMER_PARAMETER)).type(Integer.class)
+ .setDefault(INITIAL_HOLD_TIME).help(INITIAL_HOLD_TIME_HELP);
+ parser.addArgument("-pr", toArgName(PREFIXES_PARAMETER)).type(Integer.class)
+ .setDefault(0).help(PREFIXES_PARAMETER_HELP);
+ parser.addArgument("-sc", toArgName(SPEAKERS_COUNT)).type(Integer.class)
+ .setDefault(0).help(SPEAKERS_COUNT_HELP);
+ parser.addArgument("-mp", toArgName(MULTIPATH_PARAMETER)).type(Boolean.class)
+ .setDefault(false).help(MULTIPATH_PARAMETER_HELP);
+ parser.addArgument("-" + AS_PARAMETER, toArgName(AS_PARAMETER))
+ .type((ArgumentTypeTool<AsNumber>) as -> new AsNumber(Long.valueOf(as)))
+ .setDefault(new AsNumber(64496L)).help(AS_PARAMETER_HELP);
+ parser.addArgument("-ec", toArgName(EXTENDED_COMMUNITIES_PARAMETER))
+ .type((ArgumentTypeTool<List<String>>) extComInput ->
+ Arrays.asList(extComInput.split(","))).setDefault(Collections.emptyList())
+ .help(EXTENDED_COMMUNITIES_PARAMETER_HELP);
+ parser.addArgument("-ll", toArgName(LOG_LEVEL))
+ .type((ArgumentTypeTool<Level>) Level::toLevel).setDefault(Level.INFO).help("log levels");
+ parser.addArgument("-ra", toArgName(REMOTE_ADDRESS_PARAMETER))
+ .type((ArgumentTypeTool<List<InetSocketAddress>>) input ->
+ InetSocketAddressUtil.parseAddresses(input, DEFAULT_REMOTE_PORT))
+ .setDefault(Collections.singletonList(REMOTE_ADDRESS))
+ .help(REMOTE_ADDRESS_PARAMETER_HELP);
+ parser.addArgument("-la", toArgName(LOCAL_ADDRESS_PARAMETER))
+ .type((ArgumentTypeTool<InetSocketAddress>) input ->
+ getInetSocketAddress(input, DEFAULT_LOCAL_PORT))
+ .setDefault(LOCAL_ADDRESS).help(LOCAL_ADDRESS_PARAMETER_HELP);
return parser;
}
}
static void createPeer(final BGPDispatcher dispatcher, final Arguments arguments,
- final InetSocketAddress localAddress, final BGPSessionListener sessionListener,
- final BgpParameters bgpParameters) {
+ final InetSocketAddress localAddress, final BGPSessionListener sessionListener,
+ final BgpParameters bgpParameters) {
final AsNumber as = arguments.getAs();
final BGPSessionPreferences proposal = new BGPSessionPreferences(as, arguments.getHoldTimer(),
- new BgpId(localAddress.getAddress().getHostAddress()), as, Collections.singletonList(bgpParameters),
- Optional.absent());
+ new BgpId(localAddress.getAddress().getHostAddress()), as, Collections.singletonList(bgpParameters),
+ Optional.absent());
final BGPPeerRegistry strictBGPPeerRegistry = dispatcher.getBGPPeerRegistry();
if (arguments.getInitiateConnection()) {
for (final InetSocketAddress remoteAddress : arguments.getRemoteAddresses()) {
strictBGPPeerRegistry.addPeer(StrictBGPPeerRegistry.getIpAddress(remoteAddress), sessionListener,
- proposal);
+ proposal);
addFutureListener(localAddress, ((BGPDispatcherImpl) dispatcher).createClient(localAddress,
- remoteAddress, RETRY_TIMER, true));
+ remoteAddress, RETRY_TIMER, true));
}
} else {
for (final InetSocketAddress remoteAddress : arguments.getRemoteAddresses()) {
strictBGPPeerRegistry.addPeer(StrictBGPPeerRegistry.getIpAddress(remoteAddress), sessionListener,
- proposal);
+ proposal);
}
addFutureListener(localAddress, dispatcher.createServer(localAddress));
}
private static <T> void addFutureListener(final InetSocketAddress localAddress, final Future<T> future) {
future.addListener(future1 -> Preconditions.checkArgument(future1.isSuccess(),
- "Unable to start bgp session on %s", localAddress, future1.cause()));
+ "Unable to start bgp session on %s", localAddress, future1.cause()));
}
}
void start(final Arguments arguments) {
final BGPDispatcher dispatcher = initializeActivator();
- final ArrayList<OptionalCapabilities> optCap = Lists.newArrayList(createMPCapability(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class),
- createMPCapability(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class), createAs4BytesMPCapability(arguments.getAs()));
+ final ArrayList<OptionalCapabilities> optCap = Lists.newArrayList(createMPCapability(Ipv4AddressFamily.class,
+ UnicastSubsequentAddressFamily.class),
+ createMPCapability(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class),
+ createAs4BytesMPCapability(arguments.getAs()));
if (arguments.getMultiPathSupport()) {
optCap.add(createAddPathCapability());
}
InetAddress address = localAddress.getAddress();
int numberOfSpeakers = arguments.getSpeakerCount();
do {
- final BGPSessionListener sessionListener = new TestingListener(arguments.getNumberOfPrefixes(), arguments.getExtendedCommunities(),
+ final BGPSessionListener sessionListener = new TestingListener(arguments.getNumberOfPrefixes(),
+ arguments.getExtendedCommunities(),
arguments.getMultiPathSupport());
this.listeners.put(address.getHostAddress(), sessionListener);
createPeer(dispatcher, arguments, new InetSocketAddress(address, port), sessionListener, bgpParameters);
final BGPExtensionProviderContext ctx = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance();
activator.start(ctx);
- final org.opendaylight.protocol.bgp.inet.BGPActivator inetActivator = new org.opendaylight.protocol.bgp.inet.BGPActivator();
+ final org.opendaylight.protocol.bgp.inet.BGPActivator inetActivator
+ = new org.opendaylight.protocol.bgp.inet.BGPActivator();
inetActivator.start(ctx);
- final org.opendaylight.protocol.bgp.evpn.impl.BGPActivator evpnActivator = new org.opendaylight.protocol.bgp.evpn.impl.BGPActivator();
+ final org.opendaylight.protocol.bgp.evpn.impl.BGPActivator evpnActivator = new org.opendaylight.protocol.bgp
+ .evpn.impl.BGPActivator();
evpnActivator.start(ctx);
final SimpleFlowspecExtensionProviderContext fsContext = new SimpleFlowspecExtensionProviderContext();
final FlowspecActivator flowspecActivator = new FlowspecActivator(fsContext);
- final org.opendaylight.protocol.bgp.flowspec.BGPActivator flowspecBGPActivator = new org.opendaylight.protocol.bgp.flowspec.BGPActivator(flowspecActivator);
+ final org.opendaylight.protocol.bgp.flowspec.BGPActivator flowspecBGPActivator
+ = new org.opendaylight.protocol.bgp.flowspec.BGPActivator(flowspecActivator);
flowspecBGPActivator.start(ctx);
- final org.opendaylight.protocol.bgp.labeled.unicast.BGPActivator labeledActivator = new org.opendaylight.protocol.bgp.labeled.unicast.BGPActivator();
+ final org.opendaylight.protocol.bgp.labeled.unicast.BGPActivator labeledActivator
+ = new org.opendaylight.protocol.bgp.labeled.unicast.BGPActivator();
labeledActivator.start(ctx);
- final org.opendaylight.protocol.bgp.l3vpn.ipv4.BgpIpv4Activator bgpIpv4Activator = new org.opendaylight.protocol.bgp.l3vpn.ipv4.BgpIpv4Activator();
+ final org.opendaylight.protocol.bgp.l3vpn.ipv4.BgpIpv4Activator bgpIpv4Activator
+ = new org.opendaylight.protocol.bgp.l3vpn.ipv4.BgpIpv4Activator();
bgpIpv4Activator.start(ctx);
- final org.opendaylight.protocol.bgp.l3vpn.ipv6.BgpIpv6Activator bgpIpv6Activator = new org.opendaylight.protocol.bgp.l3vpn.ipv6.BgpIpv6Activator();
+ final org.opendaylight.protocol.bgp.l3vpn.ipv6.BgpIpv6Activator bgpIpv6Activator
+ = new org.opendaylight.protocol.bgp.l3vpn.ipv6.BgpIpv6Activator();
bgpIpv6Activator.start(ctx);
return new BGPDispatcherImpl(ctx.getMessageRegistry(), new NioEventLoopGroup(), new NioEventLoopGroup(),
new StrictBGPPeerRegistry());
}
- private static OptionalCapabilities createMPCapability(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) {
- return new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder()
- .setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(afi).setSafi(safi).build()).build()).build()).build();
+ private static OptionalCapabilities createMPCapability(final Class<? extends AddressFamily> afi,
+ final Class<? extends SubsequentAddressFamily> safi) {
+ return new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder()
+ .addAugmentation(CParameters1.class, new CParameters1Builder()
+ .setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(afi)
+ .setSafi(safi).build()).build()).build()).build();
}
private static OptionalCapabilities createAs4BytesMPCapability(final AsNumber as) {
}
private static OptionalCapabilities createAddPathCapability() {
- return new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder()
- .setAddPathCapability(new AddPathCapabilityBuilder().setAddressFamilies(Lists.newArrayList(new AddressFamiliesBuilder()
- .setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).setSendReceive(SendReceive.Both).build()
- )).build()).build()).build()).build();
+ return new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder()
+ .addAugmentation(CParameters1.class, new CParameters1Builder()
+ .setAddPathCapability(new AddPathCapabilityBuilder()
+ .setAddressFamilies(Lists.newArrayList(new AddressFamiliesBuilder()
+ .setAfi(Ipv4AddressFamily.class)
+ .setSafi(UnicastSubsequentAddressFamily.class)
+ .setSendReceive(SendReceive.Both).build())).build()).build()).build()).build();
}
void printCount(final String localAddress) {
final class CommunitiesBuilder {
private static final Logger LOG = LoggerFactory.getLogger(CommunitiesBuilder.class);
- private static final As4SpecificCommon AS_4_COMMON = new As4SpecificCommonBuilder().setAsNumber(new AsNumber(20L)).setLocalAdministrator(100).build();
+ private static final As4SpecificCommon AS_4_COMMON = new As4SpecificCommonBuilder()
+ .setAsNumber(new AsNumber(20L)).setLocalAdministrator(100).build();
private static final Ipv4Address IPV4 = new Ipv4Address("192.168.1.0");
private static final byte[] BYTE = new byte[]{(byte) 0x4f, (byte) 0x70, (byte) 0x00, (byte) 0x00};
private static final int LA = 4660;
for (String ec : extCom) {
ExtendedCommunity community = null;
switch (ec) {
- case "as-4-generic-spec-extended-community":
- community = CommunitiesBuilder.as4GenSpecBuild();
- break;
- case "as-4-route-target-extended-community":
- community = CommunitiesBuilder.as4RTBuild();
- break;
- case "as-4-route-origin-extended-community":
- community = CommunitiesBuilder.as4ROBuild();
- break;
- case "route-origin":
- community = CommunitiesBuilder.rOBuild();
- break;
- case "route-target":
- community = CommunitiesBuilder.rTBuild();
- break;
- case "route-origin-extended-community":
- community = CommunitiesBuilder.rOECBuild();
- break;
- case "route-target-extended-community":
- community = CommunitiesBuilder.rTECBuild();
- break;
- case "link-bandwidth-extended-community":
- community = CommunitiesBuilder.linkBandBuild();
- break;
- case "opaque-extended-community":
- community = CommunitiesBuilder.opaqueBuild();
- break;
- case "inet4-specific-extended-community":
- community = CommunitiesBuilder.inet4Build();
- break;
- case "as-specific-extended-community":
- community = CommunitiesBuilder.asSpecBuild();
- break;
- default:
- LOG.debug("Not recognized Extended Community {}", ec);
- break;
+ case "as-4-generic-spec-extended-community":
+ community = CommunitiesBuilder.as4GenSpecBuild();
+ break;
+ case "as-4-route-target-extended-community":
+ community = CommunitiesBuilder.as4RTBuild();
+ break;
+ case "as-4-route-origin-extended-community":
+ community = CommunitiesBuilder.as4ROBuild();
+ break;
+ case "route-origin":
+ community = CommunitiesBuilder.rOBuild();
+ break;
+ case "route-target":
+ community = CommunitiesBuilder.rTBuild();
+ break;
+ case "route-origin-extended-community":
+ community = CommunitiesBuilder.rOECBuild();
+ break;
+ case "route-target-extended-community":
+ community = CommunitiesBuilder.rTECBuild();
+ break;
+ case "link-bandwidth-extended-community":
+ community = CommunitiesBuilder.linkBandBuild();
+ break;
+ case "opaque-extended-community":
+ community = CommunitiesBuilder.opaqueBuild();
+ break;
+ case "inet4-specific-extended-community":
+ community = CommunitiesBuilder.inet4Build();
+ break;
+ case "as-specific-extended-community":
+ community = CommunitiesBuilder.asSpecBuild();
+ break;
+ default:
+ LOG.debug("Not recognized Extended Community {}", ec);
+ break;
}
- extendedCommunities.add(new ExtendedCommunitiesBuilder().setTransitive(true).setExtendedCommunity(community).build());
+ extendedCommunities.add(new ExtendedCommunitiesBuilder()
+ .setTransitive(true).setExtendedCommunity(community).build());
}
return extendedCommunities;
}
private static ExtendedCommunity as4GenSpecBuild() {
return new As4GenericSpecExtendedCommunityCaseBuilder()
- .setAs4GenericSpecExtendedCommunity(new As4GenericSpecExtendedCommunityBuilder()
- .setAs4SpecificCommon(AS_4_COMMON).build()).build();
+ .setAs4GenericSpecExtendedCommunity(new As4GenericSpecExtendedCommunityBuilder()
+ .setAs4SpecificCommon(AS_4_COMMON).build()).build();
}
private static ExtendedCommunity as4RTBuild() {
return new As4RouteTargetExtendedCommunityCaseBuilder().setAs4RouteTargetExtendedCommunity(
- new As4RouteTargetExtendedCommunityBuilder().setAs4SpecificCommon(AS_4_COMMON).build()).build();
+ new As4RouteTargetExtendedCommunityBuilder().setAs4SpecificCommon(AS_4_COMMON).build()).build();
}
private static ExtendedCommunity as4ROBuild() {
return new As4RouteOriginExtendedCommunityCaseBuilder().setAs4RouteOriginExtendedCommunity(
- new As4RouteOriginExtendedCommunityBuilder().setAs4SpecificCommon(AS_4_COMMON).build()).build();
+ new As4RouteOriginExtendedCommunityBuilder().setAs4SpecificCommon(AS_4_COMMON).build()).build();
}
private static ExtendedCommunity rTBuild() {
return new RouteTargetIpv4CaseBuilder().setRouteTargetIpv4(
- new RouteTargetIpv4Builder().setGlobalAdministrator(IPV4).setLocalAdministrator(LA).build()).build();
+ new RouteTargetIpv4Builder().setGlobalAdministrator(IPV4).setLocalAdministrator(LA).build()).build();
}
private static ExtendedCommunity rOBuild() {
return new RouteOriginIpv4CaseBuilder().setRouteOriginIpv4(
- new RouteOriginIpv4Builder().setGlobalAdministrator(IPV4).setLocalAdministrator(LA).build()).build();
+ new RouteOriginIpv4Builder().setGlobalAdministrator(IPV4).setLocalAdministrator(LA).build()).build();
}
private static ExtendedCommunity linkBandBuild() {
- return new LinkBandwidthCaseBuilder().setLinkBandwidthExtendedCommunity(new LinkBandwidthExtendedCommunityBuilder()
- .setBandwidth(new Bandwidth(new Float32(BYTE))).build()).build();
+ return new LinkBandwidthCaseBuilder()
+ .setLinkBandwidthExtendedCommunity(new LinkBandwidthExtendedCommunityBuilder()
+ .setBandwidth(new Bandwidth(new Float32(BYTE))).build()).build();
}
private static ExtendedCommunity rOECBuild() {
return new RouteOriginExtendedCommunityCaseBuilder().setRouteOriginExtendedCommunity(
- new RouteOriginExtendedCommunityBuilder().setGlobalAdministrator(SHORT_AS).setLocalAdministrator(BYTE).build()).build();
+ new RouteOriginExtendedCommunityBuilder().setGlobalAdministrator(SHORT_AS)
+ .setLocalAdministrator(BYTE).build()).build();
}
private static ExtendedCommunity rTECBuild() {
return new RouteTargetExtendedCommunityCaseBuilder().setRouteTargetExtendedCommunity(
- new RouteTargetExtendedCommunityBuilder().setGlobalAdministrator(SHORT_AS).setLocalAdministrator(BYTE).build()).build();
+ new RouteTargetExtendedCommunityBuilder().setGlobalAdministrator(SHORT_AS)
+ .setLocalAdministrator(BYTE).build()).build();
}
private static ExtendedCommunity opaqueBuild() {
return new OpaqueExtendedCommunityCaseBuilder().setOpaqueExtendedCommunity(
- new OpaqueExtendedCommunityBuilder().setValue(BYTE).build()).build();
+ new OpaqueExtendedCommunityBuilder().setValue(BYTE).build()).build();
}
private static ExtendedCommunity inet4Build() {
return new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
- new Inet4SpecificExtendedCommunityBuilder().setGlobalAdministrator(IPV4).setLocalAdministrator(BYTE).build()).build();
+ new Inet4SpecificExtendedCommunityBuilder().setGlobalAdministrator(IPV4)
+ .setLocalAdministrator(BYTE).build()).build();
}
private static ExtendedCommunity asSpecBuild() {
return new AsSpecificExtendedCommunityCaseBuilder().setAsSpecificExtendedCommunity(
- new AsSpecificExtendedCommunityBuilder().setGlobalAdministrator(SHORT_AS).setLocalAdministrator(BYTE).build()).build();
+ new AsSpecificExtendedCommunityBuilder().setGlobalAdministrator(SHORT_AS)
+ .setLocalAdministrator(BYTE).build()).build();
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
import org.opendaylight.protocol.util.LoggerUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
LoggerUtil.initiateLogger(arguments);
final BGPTestTool bgpTestTool = new BGPTestTool();
- final InputStreamReader isr = new InputStreamReader(System.in);
+ final InputStreamReader isr = new InputStreamReader(System.in, StandardCharsets.UTF_8);
final BufferedReader br = new BufferedReader(isr);
bgpTestTool.start(arguments);
for (;;) {
private static final Ipv4NextHopCase NEXT_HOP;
static {
- NEXT_HOP = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("127.1.1.1")).build()).build();
+ NEXT_HOP = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder()
+ .setGlobal(new Ipv4Address("127.1.1.1")).build()).build();
}
private PrefixesBuilder() {
throw new UnsupportedOperationException();
}
- static void advertiseIpv4Prefixes(final ChannelOutputLimiter session, final int nPrefixes, final List<String> extCom, final boolean multipartSupport) {
+ static void advertiseIpv4Prefixes(final ChannelOutputLimiter session, final int nprefixes,
+ final List<String> extCom, final boolean multipartSupport) {
Ipv4Prefix addressPrefix = new Ipv4Prefix("1.1.1.1/31");
- for (int i = 0; i < nPrefixes; i++) {
+ for (int i = 0; i < nprefixes; i++) {
buildAndSend(session, addressPrefix, extCom, multipartSupport);
addressPrefix = incrementIpv4Prefix(addressPrefix);
}
}
- private static void buildAndSend(final ChannelOutputLimiter session, final Ipv4Prefix addressPrefix, final List<String> extCom,
- final boolean multipartSupport) {
+ private static void buildAndSend(final ChannelOutputLimiter session, final Ipv4Prefix addressPrefix,
+ final List<String> extCom, final boolean multipartSupport) {
final Update upd = new UpdateBuilder().setAttributes(createAttributes(extCom, multipartSupport, addressPrefix))
.build();
session.write(upd);
session.flush();
}
- private static Attributes createAttributes(final List<String> extCom, final boolean multiPathSupport, final Ipv4Prefix addressPrefix) {
+ private static Attributes createAttributes(final List<String> extCom, final boolean multiPathSupport,
+ final Ipv4Prefix addressPrefix) {
final AttributesBuilder attBuilder = new AttributesBuilder();
attBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build());
attBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.emptyList()).build());
prefixes.setPathId(new PathId(5L));
}
attBuilder.addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(
- new MpReachNlriBuilder().setCNextHop(NEXT_HOP).setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class)
- .setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationIpv4CaseBuilder().setDestinationIpv4(new DestinationIpv4Builder()
- .setIpv4Prefixes(Collections.singletonList(prefixes.build())).build()).build()).build()).build()).build());
+ new MpReachNlriBuilder().setCNextHop(NEXT_HOP).setAfi(Ipv4AddressFamily.class)
+ .setSafi(UnicastSubsequentAddressFamily.class)
+ .setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
+ new DestinationIpv4CaseBuilder().setDestinationIpv4(new DestinationIpv4Builder()
+ .setIpv4Prefixes(Collections.singletonList(prefixes.build())).build())
+ .build()).build()).build()).build());
return attBuilder.build();
}
*/
final class TestingListener implements BGPSessionListener {
private static final Logger LOG = LoggerFactory.getLogger(TestingListener.class);
- private final int nPrefixes;
+ private final int nprefixes;
private final List<String> extCom;
private final boolean multiPathSupport;
private LongAdder messageCounter = new LongAdder();
- TestingListener(final int nPrefixes, final List<String> extCom, final boolean multiPathSupport) {
- this.nPrefixes = nPrefixes;
+ TestingListener(final int nprefixes, final List<String> extCom, final boolean multiPathSupport) {
+ this.nprefixes = nprefixes;
this.extCom = extCom;
this.multiPathSupport = multiPathSupport;
}
@Override
public void onSessionUp(final BGPSession session) {
LOG.info("Client Listener: Session Up.");
- if (this.nPrefixes > 0) {
- PrefixesBuilder.advertiseIpv4Prefixes(((BGPSessionImpl) session).getLimiter(), this.nPrefixes, this.extCom, this.multiPathSupport);
+ if (this.nprefixes > 0) {
+ PrefixesBuilder.advertiseIpv4Prefixes(((BGPSessionImpl) session).getLimiter(), this.nprefixes, this.extCom,
+ this.multiPathSupport);
}
}
@Override
- public void onSessionDown(final BGPSession session, final Exception e) {
+ @SuppressWarnings("checkstyle:IllegalCatch")
+ public void onSessionDown(final BGPSession session, final Exception exc) {
LOG.info("Client Listener: Connection lost.");
try {
session.close();
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <configuration>
+ <failOnError>true</failOnError>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
<scm>
<connection>scm:git:ssh://git.opendaylight.org:29418/bgpcep.git</connection>
<developerConnection>scm:git:ssh://git.opendaylight.org:29418/bgpcep.git</developerConnection>
// Parse length
final int length = ByteArray.bytesToInt(new byte[]{ byteArray[j], byteArray[j + 1] });
- Preconditions.checkArgument(length >= MINIMAL_LENGTH, "Invalid message at index " + start
+ Preconditions.checkArgument(length >= MINIMAL_LENGTH,
+ "Invalid message at index " + start
+ ", length atribute is lower than " + MINIMAL_LENGTH);
final byte[] message = Arrays.copyOfRange(byteArray, start, start + length);
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
+import java.util.Locale;
import javax.annotation.concurrent.Immutable;
import org.opendaylight.protocol.util.ByteArray;
import org.slf4j.Logger;
}
}
- public static List<byte[]> parseMessages(final String c) {
- final String content = clearWhiteSpaceToUpper(c);
+ public static List<byte[]> parseMessages(final String stringMessage) {
+ final String content = clearWhiteSpaceToUpper(stringMessage);
final int sixteen = 16;
final int four = 4;
// search for 16 FFs
// Assert that message is longer than minimum 19(header.length == 19)
// If length in BGP message would be 0, loop would never end
- Preconditions.checkArgument(length >= MINIMAL_LENGTH, "Invalid message at index " + idx + ", length atribute is lower than "
- + MINIMAL_LENGTH);
+ Preconditions.checkArgument(length >= MINIMAL_LENGTH, "Invalid message at index "
+ + idx + ", length atribute is lower than " + MINIMAL_LENGTH);
final String hexMessage = content.substring(idx, messageEndIdx);
final byte[] message = BaseEncoding.base16().decode(hexMessage);
@VisibleForTesting
static String clearWhiteSpaceToUpper(final String line) {
- return line.replaceAll("\\s", "").toUpperCase();
+ return line.replaceAll("\\s", "").toUpperCase(Locale.ENGLISH);
}
}
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
import java.util.List;
import org.junit.Test;
public class BGPBinaryFileParserTest {
- private final byte ff = (byte) 255;
+ private static final byte FF = (byte) 255;
+
+ private static List<byte[]> extractFromFile(final String fileName) throws IOException {
+ final InputStream is = BGPBinaryFileParserTest.class.getResourceAsStream(fileName);
+ if (is == null) {
+ throw new IOException("Failed to get resource " + fileName);
+ }
+
+ final ByteArrayOutputStream bis = new ByteArrayOutputStream();
+ final byte[] data = new byte[1000];
+ int nread;
+ while ((nread = is.read(data, 0, data.length)) != -1) {
+ bis.write(data, 0, nread);
+ }
+ bis.flush();
+ return BinaryBGPDumpFileParser.parseMessages(bis.toByteArray());
+ }
@Test
public void testCorrectExtraction() throws IOException {
}
- private static List<byte[]> extractFromFile(final String fileName) throws IOException {
- final InputStream is = BGPBinaryFileParserTest.class.getResourceAsStream(fileName);
- assertNotNull("File not found - " + fileName);
- if (is == null) {
- throw new IOException("Failed to get resource " + fileName);
- }
-
- final ByteArrayOutputStream bis = new ByteArrayOutputStream();
- final byte[] data = new byte[1000];
- int nRead = 0;
- while ((nRead = is.read(data, 0, data.length)) != -1) {
- bis.write(data, 0, nRead);
- }
- bis.flush();
- return BinaryBGPDumpFileParser.parseMessages(bis.toByteArray());
- }
-
private void checkMarker(final List<byte[]> parsedMessages) {
for (int i = 0; i < 16; i++) {
- assertThat(parsedMessages.get(0)[i], is(this.ff));
+ assertThat(parsedMessages.get(0)[i], is(FF));
}
}
/**
- * In BgpMessages_wrong_header file, first FF sequence is corrupted
- *
- * @throws IOException
+ * In BgpMessages_wrong_header file, first FF sequence is corrupted.
*/
@Test
public void testCorruptedHeader() throws IOException {
final List<byte[]> parsedMessages = extractFromFile("/BgpMessages_wrong_header.bin");
assertEquals(42, parsedMessages.size());
}
-
- @Test(expected=UnsupportedOperationException.class)
- public void testPrivateConstructor() throws Throwable {
- final Constructor<BinaryBGPDumpFileParser> c = BinaryBGPDumpFileParser.class.getDeclaredConstructor();
- c.setAccessible(true);
- try {
- c.newInstance();
- } catch (InvocationTargetException e) {
- throw e.getCause();
- }
- }
-
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
+
import java.io.File;
import java.io.FileNotFoundException;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
import java.util.List;
import org.junit.Test;
public class BGPHexFileParserTest {
- public static final String hexDumpFileName = "bgp_hex.txt";
- private static final String fileNameInvalid = "BgpMessage_Hex_InvalidLength.bin";
- private static final int expectedSize = 25;
+ private static final String HEX_DUMP_FILE_NAME = "bgp_hex.txt";
+ private static final String BGP_MESSAGE_HEX_INVALID_LENGTH_BIN = "BgpMessage_Hex_InvalidLength.bin";
+ private static final int EXPECTED_SIZE = 25;
@Test
public void testCleanWhiteSpace() {
@Test
public void testParsing() throws Exception {
- final List<byte[]> result = HexDumpBGPFileParser.parseMessages(getClass().getClassLoader().getResourceAsStream(
- BGPHexFileParserTest.hexDumpFileName));
- assertEquals(expectedSize, result.size());
+ final List<byte[]> result = HexDumpBGPFileParser.parseMessages(getClass().getClassLoader()
+ .getResourceAsStream(BGPHexFileParserTest.HEX_DUMP_FILE_NAME));
+ assertEquals(EXPECTED_SIZE, result.size());
}
@Test
public void testParsingInvalidMessage() throws Exception {
try {
- HexDumpBGPFileParser.parseMessages(getClass().getClassLoader().getResourceAsStream(fileNameInvalid));
+ HexDumpBGPFileParser.parseMessages(getClass().getClassLoader()
+ .getResourceAsStream(BGP_MESSAGE_HEX_INVALID_LENGTH_BIN));
fail("Exception should have occured.");
} catch (final IllegalArgumentException e) {
- assertThat(e.getMessage(), containsString("Invalid message at index 0, length atribute is lower than 19"));
+ assertThat(e.getMessage(), containsString("Invalid message at index 0, "
+ + "length atribute is lower than 19"));
}
}
assertThat(e.getMessage(), containsString("bad file name"));
}
}
-
- @Test(expected=UnsupportedOperationException.class)
- public void testPrivateConstructor() throws Throwable {
- final Constructor<HexDumpBGPFileParser> c = HexDumpBGPFileParser.class.getDeclaredConstructor();
- c.setAccessible(true);
- try {
- c.newInstance();
- } catch (InvocationTargetException e) {
- throw e.getCause();
- }
- }
-
}