final List<BgpParameters> tlvs = getTlvs(r);
final AsNumber remoteAs = getAsOrDefault(r);
final String password = getPasswordOrNull();
- final BGPSessionPreferences prefs = new BGPSessionPreferences(r.getLocalAs(), getHoldtimer(), r.getBgpIdentifier(), tlvs);
+ final BGPSessionPreferences prefs = new BGPSessionPreferences(r.getLocalAs(), getHoldtimer(), r.getBgpIdentifier(), remoteAs, tlvs);
final BGPPeer bgpClientPeer;
if (getPeerRole() != null) {
bgpClientPeer = new BGPPeer(peerName(getHostWithoutValue()), r, getPeerRole());
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.IpAddress;
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.Open;
/**
* Registry of BGP peers that allows only one connection per 2 peers
}
@Override
- public BGPSessionListener getPeer(final IpAddress ip, final Ipv4Address sourceId, final Ipv4Address remoteId, final AsNumber asNumber)
+ public BGPSessionListener getPeer(final IpAddress ip, final Ipv4Address sourceId, final Ipv4Address remoteId, final AsNumber asNumber, final Open open)
throws BGPDocumentedException {
- return this.global.getPeer(ip, sourceId, remoteId, asNumber);
+ return this.global.getPeer(ip, sourceId, remoteId, asNumber, open);
}
@Override
}
try {
- final BGPSessionListener peer = this.registry.getPeer(getRemoteIp(), getSourceId(openObj, getPreferences()),
- getDestinationId(openObj, getPreferences()), getAsNumber(openObj, getPreferences()));
- this.sendMessage(new KeepaliveBuilder().build());
+ final BGPSessionListener peer = this.registry.getPeer(getRemoteIp(), getSourceId(openObj, getPreferences()), getDestinationId(openObj, getPreferences()), getAsNumber(openObj, getPreferences()), openObj);
+ sendMessage(new KeepaliveBuilder().build());
this.session = new BGPSessionImpl(peer, this.channel, openObj, getPreferences(), this.registry);
this.state = State.OPEN_CONFIRM;
LOG.debug("Channel {} moved to OpenConfirm state with remote proposal {}", this.channel, openObj);
import io.netty.channel.Channel;
import io.netty.util.concurrent.Promise;
+import org.opendaylight.protocol.bgp.parser.AsNumberUtil;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionValidator;
}
@Override
- protected AsNumber getAsNumber(Open openMsg, BGPSessionPreferences preferences) {
- return preferences.getMyAs();
+ protected AsNumber getAsNumber(final Open openMsg, final BGPSessionPreferences preferences) {
+ return AsNumberUtil.advertizedAsNumber(openMsg);
}
}
}
@Override
- protected AsNumber getAsNumber(Open openMsg, BGPSessionPreferences preferences) {
- return new AsNumber(AsNumberUtil.advertizedAsNumber(openMsg));
+ protected AsNumber getAsNumber(final Open openMsg, final BGPSessionPreferences preferences) {
+ return AsNumberUtil.advertizedAsNumber(openMsg);
}
}
private final BGPSessionPreferences prefs;
+ private final AsNumber remoteAs;
+
public BGPSessionProposalImpl(final short holdTimer, final AsNumber as, final Ipv4Address bgpId,
- final Map<Class<? extends AddressFamily>, Class<? extends SubsequentAddressFamily>> tables) {
+ final Map<Class<? extends AddressFamily>, Class<? extends SubsequentAddressFamily>> tables,
+ final AsNumber remoteAs) {
this.holdTimer = holdTimer;
this.as = as;
this.bgpId = bgpId;
+ this.remoteAs = remoteAs;
final List<OptionalCapabilities> caps = new ArrayList<>();
for (final Entry<Class<? extends AddressFamily>, Class<? extends SubsequentAddressFamily>> e : tables.entrySet()) {
caps.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(
CParameters1.class, new CParameters1Builder().setGracefulRestartCapability(
new GracefulRestartCapabilityBuilder().build()).build()).build()).build());
- this.prefs = new BGPSessionPreferences(as, holdTimer, bgpId, Lists.newArrayList(
+ this.prefs = new BGPSessionPreferences(as, holdTimer, bgpId, remoteAs, Lists.newArrayList(
new BgpParametersBuilder().setOptionalCapabilities(caps).build()));
}
package org.opendaylight.protocol.bgp.rib.impl;
import com.google.common.base.MoreObjects;
+import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
import com.google.common.net.InetAddresses;
import com.google.common.primitives.UnsignedInts;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
+import java.util.List;
import java.util.Map;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;
+import org.opendaylight.protocol.bgp.parser.AsNumberUtil;
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPError;
+import org.opendaylight.protocol.bgp.parser.impl.message.open.As4CapabilityHandler;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
import org.opendaylight.protocol.bgp.rib.impl.spi.ReusableBGPPeer;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Open;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.BgpParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.OptionalCapabilities;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.CParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.CParametersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapability;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Override
public synchronized BGPSessionListener getPeer(final IpAddress ip, final Ipv4Address sourceId,
- final Ipv4Address remoteId, final AsNumber asNumber) throws BGPDocumentedException {
+ final Ipv4Address remoteId, final AsNumber remoteAsNumber, final Open openObj) throws BGPDocumentedException {
Preconditions.checkNotNull(ip);
Preconditions.checkNotNull(sourceId);
Preconditions.checkNotNull(remoteId);
- Preconditions.checkNotNull(asNumber);
+ Preconditions.checkNotNull(remoteAsNumber);
+
+ final BGPSessionPreferences prefs = getPeerPreferences(ip);
checkPeerConfigured(ip);
- final BGPSessionId currentConnection = new BGPSessionId(sourceId, remoteId, asNumber);
+ final BGPSessionId currentConnection = new BGPSessionId(sourceId, remoteId, remoteAsNumber);
final BGPSessionListener p = this.peers.get(ip);
final BGPSessionId previousConnection = this.sessionIds.get(ip);
ip, currentConnection),
BGPError.CEASE);
}
- } else {
- if (!getPeerPreferences(ip).getMyAs().equals(asNumber)) {
- LOG.warn("Unexpected remote AS number. Expecting {}, got {}", getPeerPreferences(ip).getMyAs(), asNumber);
- throw new BGPDocumentedException("Peer AS number mismatch", BGPError.BAD_PEER_AS);
- }
}
+ validateAs(openObj, prefs);
// Map session id to peer IP address
this.sessionIds.put(ip, currentConnection);
return p;
}
+ private void validateAs(final Open openObj, final BGPSessionPreferences localPref) throws BGPDocumentedException {
+ final AsNumber remoteAs = AsNumberUtil.advertizedAsNumber(openObj);
+ if (!remoteAs.equals(localPref.getExpectedRemoteAs())) {
+ LOG.warn("Unexpected remote AS number. Expecting {}, got {}", remoteAs, localPref.getExpectedRemoteAs());
+ throw new BGPDocumentedException("Peer AS number mismatch", BGPError.BAD_PEER_AS);
+ }
+
+ // https://tools.ietf.org/html/rfc6286#section-2.2
+ if (openObj.getBgpIdentifier() != null && openObj.getBgpIdentifier().equals(localPref.getBgpId())) {
+ LOG.warn("Remote and local BGP Identifiers are the same: {}", openObj.getBgpIdentifier());
+ throw new BGPDocumentedException("Remote and local BGP Identifiers are the same.", BGPError.BAD_BGP_ID);
+ }
+ final List<BgpParameters> prefs = openObj.getBgpParameters();
+ if (prefs != null) {
+ if (getAs4BytesCapability(localPref.getParams()).isPresent() && !getAs4BytesCapability(prefs).isPresent()) {
+ throw new BGPDocumentedException("The peer must advertise AS4Bytes capability.", BGPError.UNSUPPORTED_CAPABILITY, serializeAs4BytesCapability(getAs4BytesCapability(localPref.getParams()).get()));
+ }
+ if (!prefs.containsAll(localPref.getParams())) {
+ LOG.info("BGP Open message session parameters differ, session still accepted.");
+ }
+ } else {
+ throw new BGPDocumentedException("Open message unacceptable. Check the configuration of BGP speaker.", BGPError.UNSPECIFIC_OPEN_ERROR);
+ }
+ }
+
+ private static Optional<As4BytesCapability> getAs4BytesCapability(final List<BgpParameters> prefs) {
+ for (final BgpParameters param : prefs) {
+ for (final OptionalCapabilities capa : param.getOptionalCapabilities()) {
+ final CParameters cParam = capa.getCParameters();
+ if (cParam.getAs4BytesCapability() != null) {
+ return Optional.of(cParam.getAs4BytesCapability());
+ }
+ }
+ }
+ return Optional.absent();
+ }
+
+ private static byte[] serializeAs4BytesCapability(final As4BytesCapability as4Capability) {
+ final ByteBuf buffer = Unpooled.buffer(1 /*CODE*/ + 1 /*LENGTH*/ + Integer.SIZE / Byte.SIZE /*4 byte value*/);
+ final As4CapabilityHandler serializer = new As4CapabilityHandler();
+ serializer.serializeCapability(new CParametersBuilder().setAs4BytesCapability(as4Capability).build(), buffer);
+ return buffer.array();
+ }
+
@Override
public BGPSessionPreferences getPeerPreferences(final IpAddress ip) {
Preconditions.checkNotNull(ip);
}
/**
- * Session identifier that contains (source Bgp Id) -> (destination Bgp Id)
+ * Session identifier that contains (source Bgp Id) -> (destination Bgp Id) AsNumber is the remoteAs coming from
+ * remote Open message
*/
private static final class BGPSessionId {
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.IpAddress;
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.Open;
/**
* Registry that contains configured bgp peers ready for when a bgp session is established with remote peer.
* @param sourceId BGP ID of peer that initiated the session (current device or remote peer)
* @param remoteId BGP ID of peer that accepted the session (current device or remote peer)
* @param asNumber remote AS number
+ * @param open remote Open message
* @return BGPSessionListener configured Peer as BGP listener
*
* @throws BGPDocumentedException if session establishment cannot be finished successfully
* @throws java.lang.IllegalStateException if there is no peer configured for provided ip address
*/
- BGPSessionListener getPeer(IpAddress ip, Ipv4Address sourceId, Ipv4Address remoteId, AsNumber asNumber) throws BGPDocumentedException;
+ BGPSessionListener getPeer(IpAddress ip, Ipv4Address sourceId, Ipv4Address remoteId, AsNumber asNumber, Open open) throws BGPDocumentedException;
/**
* @param ip address of remote peer
private final List<BgpParameters> params;
+ private final AsNumber remoteAs;
+
/**
* Creates a new DTO for Open message.
*
* @param as local AS number
* @param hold preferred hold timer value, in seconds
* @param bgpId local BGP Identifier
+ * @param remoteAs expected remote As Number
* @param params list of advertised parameters
*/
- public BGPSessionPreferences(final AsNumber as, final int hold, final Ipv4Address bgpId, final List<BgpParameters> params) {
+ public BGPSessionPreferences(final AsNumber as, final int hold, final Ipv4Address bgpId, final AsNumber remoteAs,
+ final List<BgpParameters> params) {
this.as = as;
this.hold = hold;
this.bgpId = bgpId;
+ this.remoteAs = remoteAs;
this.params = params;
}
return this.bgpId;
}
+ /**
+ * Returns expected remote AS number.
+ *
+ * @return AS number
+ */
+ public AsNumber getExpectedRemoteAs() {
+ return this.remoteAs;
+ }
+
/**
* Gets a list of advertised bgp parameters.
*
final Map<Class<? extends AddressFamily>, Class<? extends SubsequentAddressFamily>> map = new HashMap<>();
map.put(key, value);
- final BGPSessionProposalImpl proposal = new BGPSessionProposalImpl((short) 5, new AsNumber(58L), null, map);
+ final BGPSessionProposalImpl proposal = new BGPSessionProposalImpl((short) 5, new AsNumber(58L), null, map, null);
final BGPSessionPreferences sp = proposal.getProposal();
assertNull(sp.getBgpId());
assertEquals(proposal.getHoldTimer(), sp.getHoldTime());
final ChannelFuture future = this.dispatcher.createServer(this.registry, ADDRESS, new BGPServerSessionValidator());
future.addListener(new GenericFutureListener<Future<Void>>() {
@Override
- public void operationComplete(Future<Void> future) {
+ public void operationComplete(final Future<Void> future) {
if(!future.isSuccess()) {
Assert.fail("Failed to create server.");
}
.setAfi(this.ipv4tt.getAfi()).setSafi(this.ipv4tt.getSafi()).build()).build())
.setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(30L)).build()).build()).build());
tlvs.add(new BgpParametersBuilder().setOptionalCapabilities(capas).build());
- return new BGPSessionPreferences(AS_NUMBER, (short) 4, new Ipv4Address(socketAddress.getAddress().getHostAddress()), tlvs);
+ return new BGPSessionPreferences(AS_NUMBER, (short) 4, new Ipv4Address(socketAddress.getAddress().getHostAddress()), AS_NUMBER, tlvs);
}
}
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
-
import com.google.common.collect.Lists;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
tlvs.add(new BgpParametersBuilder().setOptionalCapabilities(capas).build());
- final BGPSessionPreferences prefs = new BGPSessionPreferences(new AsNumber(30L), (short) 3, new Ipv4Address("1.1.1.1"), tlvs);
+ final BGPSessionPreferences prefs = new BGPSessionPreferences(new AsNumber(30L), (short) 3, new Ipv4Address("1.1.1.1"), new AsNumber(30L), tlvs);
final ChannelFuture f = mock(ChannelFuture.class);
doReturn(null).when(f).addListener(any(GenericFutureListener.class));
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
+import com.google.common.collect.Lists;
import java.net.InetSocketAddress;
import java.util.Collections;
+import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
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.IpAddress;
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.Open;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.OpenBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.BgpParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.BgpParametersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.OptionalCapabilitiesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.CParametersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapabilityBuilder;
public class StrictBGPPeerRegistryTest {
private StrictBGPPeerRegistry droppingBGPSessionRegistry;
private BGPSessionPreferences mockPreferences;
private final AsNumber AS1 = new AsNumber(1234L);
+
+ private Open createOpen(final Ipv4Address bgpId, final AsNumber as) {
+ final List<BgpParameters> params = Lists.newArrayList(new BgpParametersBuilder()
+ .setOptionalCapabilities(Lists.newArrayList(new OptionalCapabilitiesBuilder()
+ .setCParameters(new CParametersBuilder()
+ .setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(as).build()).build()).build())).build());
+ return new OpenBuilder().setBgpIdentifier(bgpId).setBgpParameters(params).build();
+ }
+
@Before
public void setUp() throws Exception {
this.droppingBGPSessionRegistry = new StrictBGPPeerRegistry();
- this.mockPreferences = getMockPreferences();
+ this.mockPreferences = getMockPreferences(this.AS1);
}
@Test
final ReusableBGPPeer session1 = getMockSession();
this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
- this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, AS1);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, this.AS1, createOpen(to, this.AS1));
try {
- this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, AS1);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, this.AS1, createOpen(to, this.AS1));
} catch (final BGPDocumentedException e) {
assertEquals(BGPError.CEASE, e.getError());
return;
final Ipv4Address to = new Ipv4Address("255.255.255.255");
try {
- this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, AS1);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, this.AS1, createOpen(to, this.AS1));
} catch (final IllegalStateException e) {
return;
}
final ReusableBGPPeer session2 = getMockSession();
this.droppingBGPSessionRegistry.addPeer(remoteIp2, session2, this.mockPreferences);
- final BGPSessionListener returnedSession1 = this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, AS1);
+ final BGPSessionListener returnedSession1 = this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, this.AS1, createOpen(to, this.AS1));
assertSame(session1, returnedSession1);
- final BGPSessionListener returnedSession2 = this.droppingBGPSessionRegistry.getPeer(remoteIp2, from, to2, AS1);
+ final BGPSessionListener returnedSession2 = this.droppingBGPSessionRegistry.getPeer(remoteIp2, from, to2, this.AS1, createOpen(to, this.AS1));
assertSame(session2, returnedSession2);
Mockito.verifyZeroInteractions(session1);
final ReusableBGPPeer session1 = getMockSession();
this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
- this.droppingBGPSessionRegistry.getPeer(remoteIp, higher, lower, AS1);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, higher, lower, this.AS1, createOpen(lower, this.AS1));
try {
- this.droppingBGPSessionRegistry.getPeer(remoteIp, lower, higher, AS1);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, lower, higher, this.AS1, createOpen(higher, this.AS1));
} catch (final BGPDocumentedException e) {
assertEquals(BGPError.CEASE, e.getError());
return;
final ReusableBGPPeer session1 = getMockSession();
this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
- this.droppingBGPSessionRegistry.getPeer(remoteIp, lower, higher, AS1);
- this.droppingBGPSessionRegistry.getPeer(remoteIp, higher, lower, AS1);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, lower, higher, this.AS1, createOpen(higher, this.AS1));
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, higher, lower, this.AS1, createOpen(lower, this.AS1));
Mockito.verify(session1).releaseConnection();
}
final ReusableBGPPeer session1 = getMockSession();
this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
- this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, AS1);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, this.AS1, createOpen(to, this.AS1));
try {
- this.droppingBGPSessionRegistry.getPeer(remoteIp, to, to, AS1);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, to, to, this.AS1, createOpen(to, this.AS1));
} catch (final BGPDocumentedException e) {
assertEquals(BGPError.CEASE, e.getError());
return;
final ReusableBGPPeer session1 = getMockSession();
this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
- this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, AS1);
- this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, as2);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, this.AS1, createOpen(to, this.AS1));
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, as2, createOpen(to, as2));
Mockito.verify(session1).releaseConnection();
}
final ReusableBGPPeer session1 = getMockSession();
this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
- this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, AS1);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, this.AS1, createOpen(to, this.AS1));
try {
- this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, as2);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, as2, createOpen(to, as2));
} catch (final BGPDocumentedException e) {
assertEquals(BGPError.CEASE, e.getError());
return;
this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
try {
- this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, as2);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, as2, createOpen(to, as2));
} catch (final BGPDocumentedException e) {
assertEquals(BGPError.BAD_PEER_AS, e.getError());
return;
return mock;
}
- public BGPSessionPreferences getMockPreferences() {
- return new BGPSessionPreferences(AS1, 1, new Ipv4Address("0.0.0.1"), Collections.<BgpParameters>emptyList());
+ public BGPSessionPreferences getMockPreferences(final AsNumber remoteAs) {
+ return new BGPSessionPreferences(this.AS1, 1, new Ipv4Address("0.0.0.1"), remoteAs, Collections.<BgpParameters> emptyList());
}
}
tables.put(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
tables.put(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
- final BGPSessionProposalImpl prop = new BGPSessionProposalImpl(holdTimerValue, as, new Ipv4Address("25.25.25.2"), tables);
+ final BGPSessionProposalImpl prop = new BGPSessionProposalImpl(holdTimerValue, as, new Ipv4Address("25.25.25.2"), tables, as);
final BGPSessionPreferences proposal = prop.getProposal();
private BGPSpeakerMock(final BGPServerSessionNegotiatorFactory negotiatorFactory, final BGPHandlerFactory factory,
final DefaultPromise<BGPSessionImpl> defaultPromise) {
- disp = new BGPDispatcherImpl(null, new NioEventLoopGroup(), new NioEventLoopGroup());
+ this.disp = new BGPDispatcherImpl(null, new NioEventLoopGroup(), new NioEventLoopGroup());
this.negotiatorFactory = Preconditions.checkNotNull(negotiatorFactory);
this.factory = Preconditions.checkNotNull(factory);
- peerRegistry = new BGPPeerRegistry() {
+ this.peerRegistry = new BGPPeerRegistry() {
@Override
public void addPeer(final IpAddress ip, final ReusableBGPPeer peer, final BGPSessionPreferences prefs) {
}
}
@Override
- public BGPSessionListener getPeer(final IpAddress ip, final Ipv4Address sourceId, final Ipv4Address remoteId, final AsNumber asNumber) throws BGPDocumentedException {
+ public BGPSessionListener getPeer(final IpAddress ip, final Ipv4Address sourceId, final Ipv4Address remoteId, final AsNumber asNumber, final Open open) throws BGPDocumentedException {
return new SpeakerSessionListener();
}
@Override
public BGPSessionPreferences getPeerPreferences(final IpAddress ip) {
- return new BGPSessionProposalImpl((short) 90, new AsNumber(72L), new Ipv4Address("127.0.0.2"), tables).getProposal();
+ return new BGPSessionProposalImpl((short) 90, new AsNumber(72L), new Ipv4Address("127.0.0.2"), BGPSpeakerMock.this.tables, new AsNumber(72L)).getProposal();
}
@Override
}
};
- tables = new HashMap<>();
- tables.put(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
- tables.put(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
+ this.tables = new HashMap<>();
+ this.tables.put(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+ this.tables.put(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
}
public void main(final String[] args) {
public void validate(final Open openObj, final BGPSessionPreferences prefs) throws BGPDocumentedException {
// NOOP
}
- }, peerRegistry);
+ }, this.peerRegistry);
final BGPSpeakerMock mock = new BGPSpeakerMock(snf, new BGPHandlerFactory(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry()), new DefaultPromise<BGPSessionImpl>(GlobalEventExecutor.INSTANCE));
}
private void createServer(final InetSocketAddress address) {
- disp.createServer(peerRegistry,address, new BGPSessionValidator() {
+ this.disp.createServer(this.peerRegistry,address, new BGPSessionValidator() {
@Override
public void validate(final Open openObj, final BGPSessionPreferences prefs) throws BGPDocumentedException {
// NOOP