This brings the number of violations below 60.
Change-Id: I177545b21da1f965a6db936341223a732560d4d0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
// 4 minutes recommended in http://tools.ietf.org/html/rfc4271#section-8.2.2
private static final int INITIAL_HOLDTIMER = 4;
- /**
- * @see <a href="http://tools.ietf.org/html/rfc6793">BGP Support for 4-Octet AS Number Space</a>
- */
+ // <a href="http://tools.ietf.org/html/rfc6793">BGP Support for 4-Octet AS Number Space</a>
private static final int AS_TRANS = 23456;
private static final Logger LOG = LoggerFactory.getLogger(AbstractBGPSessionNegotiator.class);
private final BGPPeerRegistry registry;
}
/**
+ * Get destination identifier.
+ *
* @param openMsg Open message received from remote BGP speaker
* @param preferences Local BGP speaker preferences
* @return BGP Id of device that accepted the connection
protected abstract Ipv4Address getDestinationId(Open openMsg, BGPSessionPreferences preferences);
/**
+ * Get source identifier.
+ *
* @param openMsg Open message received from remote BGP speaker
* @param preferences Local BGP speaker preferences
* @return BGP Id of device that accepted the connection
* method returns, the old instance must not be reasonably used.
*
* @param newPeerId new peer BGP identifier
- * @param peerPath
+ * @param peerPath path of the peer in the datastore
* @param registry RIB extension registry
* @param tableTypes New tables, must not be null
- * @param addPathTablesType
+ * @param addPathTablesType supported add path tables
* @return New writer
*/
AdjRibInWriter transform(final PeerId newPeerId, final YangInstanceIdentifier peerPath,
}
/**
- * Create new table instances, potentially creating their empty entries
+ * Create new table instances, potentially creating their empty entries.
*/
private static ImmutableMap<TablesKey, TableContext> createNewTableInstances(
final YangInstanceIdentifier newPeerPath, final RIBSupportContextRegistry registry,
LOG.warn("Failed to store stale routes for table {}", tablesKey, throwable);
latch.countDown();
}
- }, MoreExecutors.directExecutor());
+ }, MoreExecutors.directExecutor());
}
}
* Application Peer is a special case of BGP peer. It serves as an interface
* for user to advertise user routes to ODL and through ODL to other BGP peers.
*
+ * <p>
* This peer has it's own RIB, where it stores all user routes. This RIB is
* located in configurational datastore. Routes are added through RESTCONF.
*
+ * <p>
* They are then processed as routes from any other peer, through AdjRib,
* EffectiveRib,LocRib and if they are advertised further, through AdjRibOut.
*
+ * <p>
* For purposed of import policies such as Best Path Selection, application
* peer needs to have a BGP-ID that is configurable.
*/
// No-op
break;
case SUBTREE_MODIFIED:
- //For be ables to use DELETE when we remove specific routes as we do when we remove the whole routes,
- // we need to go deeper three levels
+ // For be ables to use DELETE when we remove specific routes as we do when we remove the whole
+ // routes, we need to go deeper three levels
if (!routeTableIdentifier.equals(childIdentifier.getParent().getParent().getParent())) {
processRoutesTable(child, childIdentifier, tx, routeTableIdentifier);
break;
@Override
public synchronized ChannelFuture createServer(final InetSocketAddress serverAddress) {
final BGPServerSessionNegotiatorFactory snf = new BGPServerSessionNegotiatorFactory(this.bgpPeerRegistry);
- final ChannelPipelineInitializer<?> initializer = BGPChannel.
- createChannelPipelineInitializer(this.handlerFactory, snf);
+ final ChannelPipelineInitializer<?> initializer = BGPChannel.createChannelPipelineInitializer(
+ this.handlerFactory, snf);
final ServerBootstrap serverBootstrap = createServerBootstrap(initializer);
final ChannelFuture channelFuture = serverBootstrap.bind(serverAddress);
LOG.debug("Initiated server {} at {}.", channelFuture, serverAddress);
}
static <S extends BGPSession, T extends BGPSessionNegotiatorFactory<S>> ChannelPipelineInitializer<S>
- createChannelPipelineInitializer(final BGPHandlerFactory hf, final T snf) {
+ createChannelPipelineInitializer(final BGPHandlerFactory hf, final T snf) {
return (channel, promise) -> {
channel.pipeline().addLast(hf.getDecoders());
channel.pipeline().addLast(NEGOTIATOR, snf.getSessionNegotiator(channel, promise));
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
/**
+ * Decoder for BGP message headers.
* @see <a href="http://tools.ietf.org/html/rfc4271#section-4.1">BGP Message Header</a>
*/
final class BGPMessageHeaderDecoder extends LengthFieldBasedFrameDecoder {
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- *
- */
@Sharable
final class BGPMessageToByteEncoder extends MessageToByteEncoder<Notification> {
private static final Logger LOG = LoggerFactory.getLogger(BGPMessageToByteEncoder.class);
*/
public class BGPPeer extends AbstractPeer implements BGPSessionListener {
private static final Logger LOG = LoggerFactory.getLogger(BGPPeer.class);
- private static final TablesKey IPV4_UCAST_TABLE_KEY = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+ private static final TablesKey IPV4_UCAST_TABLE_KEY = new TablesKey(Ipv4AddressFamily.class,
+ UnicastSubsequentAddressFamily.class);
private Set<TablesKey> tables = Collections.emptySet();
private final RIB rib;
}
final GracefulRestartCapability advertisedGracefulRestartCapability =
session.getAdvertisedGracefulRestartCapability();
- final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.graceful.restart.capability.Tables> advertisedTables =
- advertisedGracefulRestartCapability.getTables();
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp
+ .capabilities.graceful.restart.capability.Tables> advertisedTables =
+ advertisedGracefulRestartCapability.getTables();
final List<AddressFamilies> addPathTablesType = session.getAdvertisedAddPathTableTypes();
final Set<BgpTableType> advertizedTableTypes = session.getAdvertisedTableTypes();
LOG.info("Session with peer {} went up with tables {} and Add Path tables {}", this.name,
new BgpPeerRpc(this, session, this.tables));
final KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib
.rev180329.bgp.rib.rib.Peer, PeerKey> path = this.rib.getInstanceIdentifier()
- .child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib
- .rib.Peer.class, new PeerKey(this.peerId));
+ .child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp
+ .rib.rib.Peer.class, new PeerKey(this.peerId));
this.rpcRegistration.registerPath(PeerContext.class, path);
}
} else {
private long lastMessageSentAt;
/**
- * System.nanoTime value about when was received the last message
+ * System.nanoTime value about when was received the last message.
*/
private long lastMessageReceivedAt;
* message arrived already in the channel buffer. Thus #AbstractBGPSessionNegotiator.handleMessage(..)
* gets invoked again and a deadlock is caused. A BGP final state machine error will happen as BGP
* negotiator is still in OPEN_SENT state as the session constructor hasn't returned yet.
- *
- * @param remoteOpen
*/
public synchronized void setChannelExtMsgCoder(final Open remoteOpen) {
final boolean enableExMess = BgpExtendedMessageUtil.advertizedBgpExtendedMessageCapability(remoteOpen);
/**
* Implementation of the BGP import policy. Listens on peer's Adj-RIB-In, inspects all inbound
* routes in the context of the advertising peer's role and applies the inbound policy.
+ *
* <p>
* Inbound policy is applied as follows:
+ *
* <p>
* 1) if the peer is an eBGP peer, perform attribute replacement and filtering
* 2) check if a route is admissible based on attributes attached to it, as well as the
case DELETE:
final Tables removeTable = table.getDataBefore();
final TablesKey tableKey = removeTable.key();
- final KeyedInstanceIdentifier<Tables, TablesKey> effectiveTablePath
- = this.effRibTables.child(Tables.class, tableKey);
- LOG.debug("Delete Effective Table {} modification type {}, "
- , effectiveTablePath, modificationType);
+ final KeyedInstanceIdentifier<Tables, TablesKey> effectiveTablePath = this.effRibTables
+ .child(Tables.class, tableKey);
+ LOG.debug("Delete Effective Table {} modification type {}, ", effectiveTablePath, modificationType);
tx.delete(LogicalDatastoreType.OPERATIONAL, effectiveTablePath);
CountersUtil.decrement(this.prefixesInstalled.get(tableKey), tableKey);
break;
final R route, final WriteTransaction tx) {
final Optional<RouteTarget> rtMembership = RouteTargetMembeshipUtil.getRT(route);
if (rtMembership.isPresent()) {
- if(PeerRole.Ebgp != this.peerImportParameters.getFromPeerRole()) {
+ if (PeerRole.Ebgp != this.peerImportParameters.getFromPeerRole()) {
this.rtCache.uncacheRoute(route);
}
this.rtMemberships.remove(rtMembership.get());
this.ribPolicies = requireNonNull(ribPolicies);
this.codecsRegistry = codecsRegistry;
this.ribContextRegistry = RIBSupportContextRegistryImpl.create(extensions, this.codecsRegistry);
- final InstanceIdentifierBuilder yangRibIdBuilder = YangInstanceIdentifier.builder().node(BgpRib.QNAME).node(Rib.QNAME);
+ final InstanceIdentifierBuilder yangRibIdBuilder = YangInstanceIdentifier.builder().node(BgpRib.QNAME)
+ .node(Rib.QNAME);
this.yangRibId = yangRibIdBuilder.nodeWithKey(Rib.QNAME, RIB_ID_QNAME, ribId.getValue()).build();
this.bestPathSelectionStrategies = requireNonNull(bestPathSelectionStrategies);
this.ribId = ribId;
.addChild(ImmutableNodes.mapNodeBuilder(Tables.QNAME).build())
.build()).build();
-
final DOMDataWriteTransaction trans = this.domChain.newWriteOnlyTransaction();
// merge empty BgpRib + Rib, to make sure the top-level parent structure is present
- trans.merge(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.builder().node(BgpRib.QNAME).build(), bgpRib);
+ trans.merge(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.builder().node(BgpRib.QNAME).build(),
+ bgpRib);
trans.put(LogicalDatastoreType.OPERATIONAL, this.yangRibId, ribInstance);
try {
/**
* Session identifier that contains (source Bgp Id) -> (destination Bgp Id) AsNumber is the remoteAs coming from
- * remote Open message
+ * remote Open message.
*/
private static final class BGPSessionId {
}
/**
- * Equals does not take direction of connection into account id1 -> id2 and id2 -> id1 are equal
+ * Equals does not take direction of connection into account id1 -> id2 and id2 -> id1 are equal.
*/
@Override
public boolean equals(final Object obj) {
}
/**
- * Check if this connection is equal to other and if it contains higher source bgp id
+ * Check if this connection is equal to other and if it contains higher source bgp id.
*/
boolean isHigherDirection(final BGPSessionId other) {
return toLong(this.from) > toLong(other.from);
return rootIdentifier.firstKeyOf(Protocol.class).getName();
}
- @Nullable
- private static Integer getHoldTimer(final Timers timers) {
- if (timers == null) {
- return null;
- }
- final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.timers
- .Config config = timers.getConfig();
- if (config != null && config.getHoldTime() != null) {
- return config.getHoldTime().intValue();
- }
- return null;
- }
-
- @Nullable
- private static AsNumber getRemotePeerAs(final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp
- .rev151009.bgp.neighbor.group.Config config) {
- if (config != null) {
- final AsNumber peerAs = config.getPeerAs();
- if (peerAs != null) {
- return peerAs;
- }
- }
- return null;
- }
-
- @Nullable
- private static Integer getRetryTimer(final Timers timers) {
- if (timers == null) {
- return null;
- }
- final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.timers
- .Config config = timers.getConfig();
- if (config != null && config.getConnectRetry() != null) {
- return config.getConnectRetry().intValue();
- }
- return null;
- }
-
static KeyMapping getNeighborKey(final Neighbor neighbor) {
if (neighbor.getConfig() != null) {
final String authPassword = neighbor.getConfig().getAuthPassword();
return Ipv4Util.toStringIP(rootIdentifier.firstKeyOf(Neighbor.class).getNeighborAddress());
}
- @Nullable
- private static <T extends TransportConfig & Augmentation<Config>> PortNumber getPort(
- @Nullable final Transport transport, final Class<T> augment) {
- if (transport != null) {
- final Config config = transport.getConfig();
- if (config != null) {
- final T peerTc = config.augmentation(augment);
- if (peerTc != null) {
- return peerTc.getRemotePort();
- }
- }
- }
- return null;
- }
-
//make sure IPv4 Unicast (RFC 4271) when required
static List<AfiSafi> getAfiSafiWithDefault(
final BgpCommonAfiSafiList afiSAfis, final boolean setDeafultIPv4) {
return hold;
}
+ @Nullable
+ private static Integer getHoldTimer(final Timers timers) {
+ if (timers == null) {
+ return null;
+ }
+ final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.timers
+ .Config config = timers.getConfig();
+ if (config != null && config.getHoldTime() != null) {
+ return config.getHoldTime().intValue();
+ }
+ return null;
+ }
+
static int getGracefulRestartTimer(final Neighbor neighbor, final PeerGroup peerGroup, final int holdTimer) {
Integer timer = null;
if (peerGroup != null) {
return neighborAs;
}
+ @Nullable
+ private static AsNumber getRemotePeerAs(final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp
+ .rev151009.bgp.neighbor.group.Config config) {
+ return config == null ? null : config.getPeerAs();
+ }
+
@Nonnull
static AsNumber getLocalPeerAs(@Nullable final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp
.rev151009.bgp.neighbor.group.Config config, @Nonnull final AsNumber globalAs) {
return retryTimer;
}
+ @Nullable
+ private static Integer getRetryTimer(final Timers timers) {
+ if (timers == null) {
+ return null;
+ }
+ final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.timers
+ .Config config = timers.getConfig();
+ if (config != null && config.getConnectRetry() != null) {
+ return config.getConnectRetry().intValue();
+ }
+ return null;
+ }
+
@Nonnull
static PortNumber getPort(final Neighbor neighbor, final PeerGroup peerGroup) {
PortNumber port = null;
return port;
}
+ @Nullable
+ private static <T extends TransportConfig & Augmentation<Config>> PortNumber getPort(
+ @Nullable final Transport transport, final Class<T> augment) {
+ if (transport != null) {
+ final Config config = transport.getConfig();
+ if (config != null) {
+ final T peerTc = config.augmentation(augment);
+ if (peerTc != null) {
+ return peerTc.getRemotePort();
+ }
+ }
+ }
+ return null;
+ }
+
@Nullable
static IpAddress getLocalAddress(@Nullable final Transport transport) {
if (transport != null && transport.getConfig() != null) {
import org.opendaylight.yangtools.yang.binding.Notification;
/**
- * BGP Operational Messages Listener State
+ * BGP Operational Messages Listener State.
*/
public interface BGPMessagesListener {
/**
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.bgp.rib.impl.spi;
import javax.annotation.Nonnull;
throws BGPDocumentedException;
/**
+ * Get preferences for a remote peer.
+ *
* @param ip address of remote peer
* @return BGP session preferences for configured peer
- *
- * @throws java.lang.IllegalStateException if there is no peer configured for provided ip address
+ * @throws IllegalStateException if there is no peer configured for provided ip address
*/
BGPSessionPreferences getPeerPreferences(IpAddress ip);
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
/**
- *
* {@link RIBSupport} wrapper which provides additional functionality
* such as logic to update / remove routes using Binding DTOs
* for BGP messages.
- *
*/
public abstract class RIBSupportContext {
-
/**
- *
* Create specified Rib table structure using supplied transaction.
*
* @param tx Transaction to to be used
public abstract void deleteRoutes(DOMDataWriteTransaction tx, YangInstanceIdentifier tableId, MpUnreachNlri nlri);
/**
- *
* Writes supplied routes and attributes to RIB table using supplied transaction.
*
- *
* @param tx Transaction to be used
* @param tableId Instance Identifier of table to be updated
* @param nlri ReachNlri which contains routes to be written.
@Override
public final synchronized boolean isAfiSafiSupported(final TablesKey tablesKey) {
- return this.prefixesReceived != null && this.prefixesReceived.isSupported(tablesKey) &&
- this.afiSafisAdvertized.contains(tablesKey);
+ return this.prefixesReceived != null && this.prefixesReceived.isSupported(tablesKey)
+ && this.afiSafisAdvertized.contains(tablesKey);
}
@Override
return this.peerRestarting;
}
- public synchronized final void setAfiSafiGracefulRestartState(final int peerRestartTime,
+ public final synchronized void setAfiSafiGracefulRestartState(final int peerRestartTime,
final boolean peerRestarting, final boolean localRestarting) {
this.peerRestartTime = peerRestartTime;
this.peerRestarting = peerRestarting;
}
@Override
- public final synchronized int getLlGracefulRestartTimer(@Nonnull TablesKey tablesKey) {
- final int timerAdvertised = isLlGracefulRestartAdvertised(tablesKey) ?
- this.afiSafisLlGracefulAdvertised.get(tablesKey) : 0;
- final int timerReceived = isLlGracefulRestartReceived(tablesKey) ?
- this.afiSafisLlGracefulReceived.get(tablesKey) : 0;
+ public final synchronized int getLlGracefulRestartTimer(@Nonnull final TablesKey tablesKey) {
+ final int timerAdvertised = isLlGracefulRestartAdvertised(tablesKey)
+ ? this.afiSafisLlGracefulAdvertised.get(tablesKey) : 0;
+ final int timerReceived = isLlGracefulRestartReceived(tablesKey)
+ ? this.afiSafisLlGracefulReceived.get(tablesKey) : 0;
return Integer.min(timerAdvertised, timerReceived);
}
}
return connectPeer(peer, clientDispatcher);
}
- static BGPPeer configurePeer(final BGPTableTypeRegistryConsumer tableRegistry,
- final Ipv4Address peerAddress, final RIBImpl ribImpl, final BgpParameters bgpParameters,
- final PeerRole peerRole, final BGPPeerRegistry bgpPeerRegistry) {
+ static BGPPeer configurePeer(final BGPTableTypeRegistryConsumer tableRegistry, final Ipv4Address peerAddress,
+ final RIBImpl ribImpl, final BgpParameters bgpParameters, final PeerRole peerRole,
+ final BGPPeerRegistry bgpPeerRegistry) {
return configurePeer(tableRegistry, peerAddress, ribImpl, bgpParameters, peerRole, bgpPeerRegistry,
AFI_SAFIS_ADVERTIZED, Collections.emptySet());
}
afiSafiAdvertised, gracefulAfiSafiAdvertised, bgpPeer);
}
- static BGPPeer configurePeer(final BGPTableTypeRegistryConsumer tableRegistry,
- final Ipv4Address peerAddress, final RIBImpl ribImpl, final BgpParameters bgpParameters,
- final PeerRole peerRole, final BGPPeerRegistry bgpPeerRegistry,
- final Set<TablesKey> afiSafiAdvertised, final Set<TablesKey> gracefulAfiSafiAdvertised,
- final BgpPeer peer) {
+ static BGPPeer configurePeer(final BGPTableTypeRegistryConsumer tableRegistry, final Ipv4Address peerAddress,
+ final RIBImpl ribImpl, final BgpParameters bgpParameters, final PeerRole peerRole,
+ final BGPPeerRegistry bgpPeerRegistry, final Set<TablesKey> afiSafiAdvertised,
+ final Set<TablesKey> gracefulAfiSafiAdvertised, final BgpPeer peer) {
final IpAddress ipAddress = new IpAddress(peerAddress);
final BGPPeer bgpPeer = new BGPPeer(tableRegistry, new IpAddress(peerAddress), null, ribImpl, peerRole,
final BGPSessionImpl session1 = createPeerSession(PEER1, nonAddPathParams, new SimpleSessionListener());
configurePeer(this.tableRegistry, PEER2, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
- final BGPSessionImpl session2 = createPeerSession(PEER2, nonAddPathParams, new SimpleSessionListener());
+ final BGPSessionImpl session2 = createPeerSession(PEER2, nonAddPathParams, new SimpleSessionListener());
configurePeer(this.tableRegistry, PEER3, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
final BGPSessionImpl session3 = createPeerSession(PEER3, nonAddPathParams, new SimpleSessionListener());
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.doReturn;
assertEquals(3, this.routes.size());
//create new peer so that it gets advertized routes from RIB
- final BGPPeer testingPeer = AbstractAddPathTest.configurePeer(this.tableRegistry, this.neighborAddress.getIpv4Address(),
- getRib(), null, PeerRole.Ibgp, new StrictBGPPeerRegistry());
+ final BGPPeer testingPeer = AbstractAddPathTest.configurePeer(this.tableRegistry,
+ this.neighborAddress.getIpv4Address(), getRib(), null, PeerRole.Ibgp, new StrictBGPPeerRegistry());
testingPeer.instantiateServiceInstance();
testingPeer.onSessionUp(this.session);
assertEquals(3, this.routes.size());