import static org.junit.Assert.fail;
import java.net.InetSocketAddress;
+import java.util.Collections;
+
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.BgpParameters;
public class StrictBGPPeerRegistryTest {
private StrictBGPPeerRegistry droppingBGPSessionRegistry;
private BGPSessionPreferences mockPreferences;
-
+ private final AsNumber AS1 = new AsNumber(1234L);
@Before
public void setUp() throws Exception {
this.droppingBGPSessionRegistry = new StrictBGPPeerRegistry();
final Ipv4Address from = new Ipv4Address("0.0.0.1");
final IpAddress remoteIp = new IpAddress(from);
final Ipv4Address to = new Ipv4Address("255.255.255.255");
- final AsNumber as = new AsNumber(1234L);
final ReusableBGPPeer session1 = getMockSession();
this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
- this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, as);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, AS1);
try {
- this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, as);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, AS1);
} catch (final BGPDocumentedException e) {
assertEquals(BGPError.CEASE, e.getError());
return;
final Ipv4Address from = new Ipv4Address("0.0.0.1");
final IpAddress remoteIp = new IpAddress(from);
final Ipv4Address to = new Ipv4Address("255.255.255.255");
- final AsNumber as = new AsNumber(1234L);
try {
- this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, as);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, AS1);
} catch (final IllegalStateException e) {
return;
}
final IpAddress remoteIp = new IpAddress(to);
final Ipv4Address to2 = new Ipv4Address("255.255.255.254");
final IpAddress remoteIp2 = new IpAddress(to2);
- final AsNumber as = new AsNumber(1234L);
final ReusableBGPPeer session1 = getMockSession();
this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
final ReusableBGPPeer session2 = getMockSession();
this.droppingBGPSessionRegistry.addPeer(remoteIp2, session2, this.mockPreferences);
- final BGPSessionListener returnedSession1 = this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, as);
+ final BGPSessionListener returnedSession1 = this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, AS1);
assertSame(session1, returnedSession1);
- final BGPSessionListener returnedSession2 = this.droppingBGPSessionRegistry.getPeer(remoteIp2, from, to2, as);
+ final BGPSessionListener returnedSession2 = this.droppingBGPSessionRegistry.getPeer(remoteIp2, from, to2, AS1);
assertSame(session2, returnedSession2);
Mockito.verifyZeroInteractions(session1);
final Ipv4Address higher = new Ipv4Address("192.168.200.200");
final Ipv4Address lower = new Ipv4Address("10.10.10.10");
final IpAddress remoteIp = new IpAddress(lower);
- final AsNumber as = new AsNumber(1234L);
final ReusableBGPPeer session1 = getMockSession();
this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
- this.droppingBGPSessionRegistry.getPeer(remoteIp, higher, lower, as);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, higher, lower, AS1);
try {
- this.droppingBGPSessionRegistry.getPeer(remoteIp, lower, higher, as);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, lower, higher, AS1);
} catch (final BGPDocumentedException e) {
assertEquals(BGPError.CEASE, e.getError());
return;
final Ipv4Address higher = new Ipv4Address("123.123.123.123");
final Ipv4Address lower = new Ipv4Address("123.123.123.122");
final IpAddress remoteIp = new IpAddress(lower);
- final AsNumber as = new AsNumber(1234L);
final ReusableBGPPeer session1 = getMockSession();
this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
- this.droppingBGPSessionRegistry.getPeer(remoteIp, lower, higher, as);
- this.droppingBGPSessionRegistry.getPeer(remoteIp, higher, lower, as);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, lower, higher, AS1);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, higher, lower, AS1);
Mockito.verify(session1).releaseConnection();
}
final Ipv4Address from = new Ipv4Address("0.0.0.1");
final IpAddress remoteIp = new IpAddress(from);
final Ipv4Address to = new Ipv4Address("255.255.255.255");
- final AsNumber as = new AsNumber(1234L);
final ReusableBGPPeer session1 = getMockSession();
this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
- this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, as);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, AS1);
try {
- this.droppingBGPSessionRegistry.getPeer(remoteIp, to, to, as);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, to, to, AS1);
} catch (final BGPDocumentedException e) {
assertEquals(BGPError.CEASE, e.getError());
return;
final Ipv4Address from = new Ipv4Address("0.0.0.1");
final IpAddress remoteIp = new IpAddress(from);
final Ipv4Address to = new Ipv4Address("255.255.255.255");
- final AsNumber as1 = new AsNumber(1L);
- final AsNumber as2 = new AsNumber(3L);
+ final AsNumber as2 = new AsNumber(1235L);
final ReusableBGPPeer session1 = getMockSession();
this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
- this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, as1);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, AS1);
this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, as2);
Mockito.verify(session1).releaseConnection();
}
final Ipv4Address from = new Ipv4Address("0.0.0.1");
final IpAddress remoteIp = new IpAddress(from);
final Ipv4Address to = new Ipv4Address("255.255.255.255");
- final AsNumber as1 = new AsNumber(10L);
final AsNumber as2 = new AsNumber(3L);
final ReusableBGPPeer session1 = getMockSession();
this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
- this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, as1);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, AS1);
try {
this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, as2);
} catch (final BGPDocumentedException e) {
fail("Same peer cannot be connected twice");
}
+ @Test
+ public void testAsMismatch() throws Exception {
+ final Ipv4Address from = new Ipv4Address("0.0.0.1");
+ final IpAddress remoteIp = new IpAddress(from);
+ final Ipv4Address to = new Ipv4Address("255.255.255.255");
+ final AsNumber as2 = new AsNumber(3L);
+
+ final ReusableBGPPeer session1 = getMockSession();
+ this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
+
+ try {
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, as2);
+ } catch (final BGPDocumentedException e) {
+ assertEquals(BGPError.BAD_PEER_AS, e.getError());
+ return;
+ }
+
+ fail("Peer AS number mismatch");
+ }
+
private ReusableBGPPeer getMockSession() {
final ReusableBGPPeer mock = Mockito.mock(ReusableBGPPeer.class);
Mockito.doNothing().when(mock).releaseConnection();
}
public BGPSessionPreferences getMockPreferences() {
- return new BGPSessionPreferences(null, 1, null, null);
+ return new BGPSessionPreferences(AS1, 1, new Ipv4Address("0.0.0.1"), Collections.<BgpParameters>emptyList());
}
-}
+}
\ No newline at end of file