Search in sources :

Example 1 with CParameters1

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1 in project bgpcep by opendaylight.

the class PeerTest method mockSession.

private void mockSession() {
    final EventLoop eventLoop = mock(EventLoop.class);
    final Channel channel = mock(Channel.class);
    final ChannelPipeline pipeline = mock(ChannelPipeline.class);
    doReturn(null).when(eventLoop).schedule(any(Runnable.class), any(long.class), any(TimeUnit.class));
    doReturn(eventLoop).when(channel).eventLoop();
    doReturn(Boolean.TRUE).when(channel).isWritable();
    doReturn(null).when(channel).close();
    doReturn(pipeline).when(channel).pipeline();
    doCallRealMethod().when(channel).toString();
    doReturn(pipeline).when(pipeline).addLast(any(ChannelHandler.class));
    doReturn(new DefaultChannelPromise(channel)).when(channel).writeAndFlush(any(Notification.class));
    doReturn(new InetSocketAddress("localhost", 12345)).when(channel).remoteAddress();
    doReturn(new InetSocketAddress("localhost", 12345)).when(channel).localAddress();
    final List<BgpParameters> params = Lists.newArrayList(new BgpParametersBuilder().setOptionalCapabilities(Lists.newArrayList(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build()).build()).build()).build())).build());
    final Open openObj = new OpenBuilder().setBgpIdentifier(new Ipv4Address("1.1.1.1")).setHoldTimer(50).setMyAsNumber(72).setBgpParameters(params).build();
    this.session = new BGPSessionImpl(this.classic, channel, openObj, 30, null);
    this.session.setChannelExtMsgCoder(openObj);
}
Also used : OptionalCapabilitiesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.OptionalCapabilitiesBuilder) MultiprotocolCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.MultiprotocolCapabilityBuilder) OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.OpenBuilder) InetSocketAddress(java.net.InetSocketAddress) Channel(io.netty.channel.Channel) ChannelHandler(io.netty.channel.ChannelHandler) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters) BgpParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParametersBuilder) CParameters1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1) ChannelPipeline(io.netty.channel.ChannelPipeline) Notification(org.opendaylight.yangtools.yang.binding.Notification) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Open) CParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParametersBuilder) CParameters1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1Builder) EventLoop(io.netty.channel.EventLoop) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) TimeUnit(java.util.concurrent.TimeUnit) UnicastSubsequentAddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Example 2 with CParameters1

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1 in project bgpcep by opendaylight.

the class EventBusRegistration method sendMessage.

private static void sendMessage(final BGPSessionListener listener, final Notification message) {
    if (BGPMock.CONNECTION_LOST_MAGIC_MSG.equals(message)) {
        listener.onSessionTerminated(null, new BGPTerminationReason(BGPError.CEASE));
    } else if (message instanceof Open) {
        final Set<BgpTableType> tts = Sets.newHashSet();
        final List<AddressFamilies> addPathCapabilitiesList = Lists.newArrayList();
        for (final BgpParameters param : ((Open) message).getBgpParameters()) {
            for (final OptionalCapabilities capa : param.getOptionalCapabilities()) {
                final CParameters cParam = capa.getCParameters();
                if (cParam.getAugmentation(CParameters1.class) == null) {
                    continue;
                }
                if (cParam.getAugmentation(CParameters1.class).getMultiprotocolCapability() != null) {
                    final MultiprotocolCapability p = cParam.getAugmentation(CParameters1.class).getMultiprotocolCapability();
                    LOG.debug("Adding open parameter {}", p);
                    final BgpTableType type = new BgpTableTypeImpl(p.getAfi(), p.getSafi());
                    tts.add(type);
                } else if (cParam.getAugmentation(CParameters1.class).getAddPathCapability() != null) {
                    final AddPathCapability addPathCap = cParam.getAugmentation(CParameters1.class).getAddPathCapability();
                    addPathCapabilitiesList.addAll(addPathCap.getAddressFamilies());
                }
            }
        }
        listener.onSessionUp(new MockBGPSession(tts));
    } else if (!(message instanceof Keepalive)) {
        try {
            listener.onMessage(new MockBGPSession(), message);
        } catch (BGPDocumentedException e) {
            LOG.warn("Exception encountered while handling message", e);
        }
    }
}
Also used : BgpTableType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType) Set(java.util.Set) Keepalive(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Keepalive) CParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParameters) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters) CParameters1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Open) OptionalCapabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.OptionalCapabilities) BGPTerminationReason(org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason) MultiprotocolCapability(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.MultiprotocolCapability) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) AddPathCapability(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.AddPathCapability) List(java.util.List) BgpTableTypeImpl(org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl)

Example 3 with CParameters1

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1 in project bgpcep by opendaylight.

the class BGPSessionStateImpl method advertizeCapabilities.

@Override
public synchronized void advertizeCapabilities(final int holdTimerValue, final SocketAddress remoteAddress, final SocketAddress localAddress, final Set<BgpTableType> tableTypes, final List<BgpParameters> bgpParameters) {
    if (bgpParameters != null && !bgpParameters.isEmpty()) {
        for (final BgpParameters parameters : bgpParameters) {
            for (final OptionalCapabilities optionalCapabilities : parameters.getOptionalCapabilities()) {
                final CParameters cParam = optionalCapabilities.getCParameters();
                final CParameters1 capabilities = cParam.getAugmentation(CParameters1.class);
                if (capabilities != null) {
                    final MultiprotocolCapability mc = capabilities.getMultiprotocolCapability();
                    if (mc != null) {
                        this.multiProtocolCapability = true;
                    }
                    if (capabilities.getGracefulRestartCapability() != null) {
                        this.gracefulRestartCapability = true;
                    }
                    if (capabilities.getAddPathCapability() != null) {
                        this.addPathCapability = true;
                    }
                    if (capabilities.getRouteRefreshCapability() != null) {
                        this.routerRefreshCapability = true;
                    }
                }
                if (cParam.getAs4BytesCapability() != null) {
                    this.asn32Capability = true;
                }
            }
        }
    }
    this.holdTimerValue = holdTimerValue;
    this.remoteAddress = StrictBGPPeerRegistry.getIpAddress(remoteAddress);
    this.remotePort = new PortNumber(((InetSocketAddress) remoteAddress).getPort());
    this.localPort = new PortNumber(((InetSocketAddress) localAddress).getPort());
}
Also used : MultiprotocolCapability(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.MultiprotocolCapability) InetSocketAddress(java.net.InetSocketAddress) CParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParameters) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters) CParameters1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber) OptionalCapabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.OptionalCapabilities)

Example 4 with CParameters1

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1 in project bgpcep by opendaylight.

the class BmpRouterPeerImpl method setPeerTables.

private static Set<TablesKey> setPeerTables(final ReceivedOpen open) {
    final Set<TablesKey> tables = Sets.newHashSet(DEFAULT_TABLE);
    for (final BgpParameters param : open.getBgpParameters()) {
        for (final OptionalCapabilities optCapa : param.getOptionalCapabilities()) {
            final CParameters cParam = optCapa.getCParameters();
            if (cParam.getAugmentation(CParameters1.class) == null || cParam.getAugmentation(CParameters1.class).getMultiprotocolCapability() == null) {
                continue;
            }
            final MultiprotocolCapability multi = cParam.getAugmentation(CParameters1.class).getMultiprotocolCapability();
            final TablesKey tt = new TablesKey(multi.getAfi(), multi.getSafi());
            tables.add(tt);
        }
    }
    return tables;
}
Also used : TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey) MultiprotocolCapability(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.MultiprotocolCapability) CParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParameters) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters) CParameters1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1) OptionalCapabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.OptionalCapabilities)

Example 5 with CParameters1

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1 in project bgpcep by opendaylight.

the class APITest method testAsNumberUtil.

@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().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());
    final Open open2 = new OpenBuilder().setMyAsNumber(10).build();
    assertEquals(10, AsNumberUtil.advertizedAsNumber(open2).getValue().intValue());
}
Also used : OptionalCapabilitiesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.OptionalCapabilitiesBuilder) MultiprotocolCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.MultiprotocolCapabilityBuilder) OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.OpenBuilder) ArrayList(java.util.ArrayList) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters) BgpParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParametersBuilder) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) OptionalCapabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.OptionalCapabilities) As4BytesCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapabilityBuilder) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Open) CParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParametersBuilder) CParameters1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1Builder) Test(org.junit.Test)

Aggregations

CParametersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParametersBuilder)33 CParameters1Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1Builder)33 CParameters1 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1)29 Test (org.junit.Test)24 ByteBuf (io.netty.buffer.ByteBuf)22 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters)17 OptionalCapabilities (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.OptionalCapabilities)17 CParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParameters)17 MultiprotocolCapabilityBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.MultiprotocolCapabilityBuilder)17 OptionalCapabilitiesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.OptionalCapabilitiesBuilder)14 BgpParametersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParametersBuilder)13 ArrayList (java.util.ArrayList)11 GracefulRestartCapabilityBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.GracefulRestartCapabilityBuilder)11 OpenBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.OpenBuilder)10 Open (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Open)9 As4BytesCapabilityBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapabilityBuilder)9 AddPathCapabilityBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.AddPathCapabilityBuilder)8 RestartFlags (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.GracefulRestartCapability.RestartFlags)7 MultiprotocolCapability (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.MultiprotocolCapability)7 AddressFamilies (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.add.path.capability.AddressFamilies)7