Search in sources :

Example 16 with Notification

use of org.opendaylight.yangtools.yang.binding.Notification in project bgpcep by opendaylight.

the class AbstractAddPathTest method sendNotification.

void sendNotification(final BGPSessionImpl session) {
    final Notification notMsg = new NotifyBuilder().setErrorCode(BGPError.OPT_PARAM_NOT_SUPPORTED.getCode()).setErrorSubcode(BGPError.OPT_PARAM_NOT_SUPPORTED.getSubcode()).setData(new byte[] { 4, 9 }).build();
    waitFutureSuccess(session.writeAndFlush(notMsg));
}
Also used : NotifyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.NotifyBuilder) Notification(org.opendaylight.yangtools.yang.binding.Notification)

Example 17 with Notification

use of org.opendaylight.yangtools.yang.binding.Notification in project bgpcep by opendaylight.

the class FSMTest method sendNotification.

@Test
public void sendNotification() {
    this.clientSession.channelActive(null);
    this.clientSession.handleMessage(this.classicOpen);
    this.clientSession.handleMessage(new KeepaliveBuilder().build());
    assertEquals(this.clientSession.getState(), BGPClientSessionNegotiator.State.FINISHED);
    this.clientSession.handleMessage(new OpenBuilder().setMyAsNumber(30).setHoldTimer(3).setVersion(new ProtocolVersion((short) 4)).build());
    assertEquals(3, this.receivedMsgs.size());
    assertTrue(this.receivedMsgs.get(2) instanceof Notify);
    final Notification m = this.receivedMsgs.get(2);
    assertEquals(BGPError.FSM_ERROR.getCode(), ((Notify) m).getErrorCode().shortValue());
    assertEquals(BGPError.FSM_ERROR.getSubcode(), ((Notify) m).getErrorSubcode().shortValue());
}
Also used : OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.OpenBuilder) Notify(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Notify) KeepaliveBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.KeepaliveBuilder) ProtocolVersion(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.ProtocolVersion) Notification(org.opendaylight.yangtools.yang.binding.Notification) Test(org.junit.Test)

Example 18 with Notification

use of org.opendaylight.yangtools.yang.binding.Notification in project bgpcep by opendaylight.

the class AbstractPCEPSessionTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    this.receivedMsgs = new ArrayList<>();
    doAnswer(invocation -> {
        final Object[] args = invocation.getArguments();
        AbstractPCEPSessionTest.this.receivedMsgs.add((Notification) args[0]);
        return this.channelFuture;
    }).when(this.clientListener).writeAndFlush(any(Notification.class));
    doReturn(null).when(this.channelFuture).addListener(Mockito.any());
    doReturn("TestingChannel").when(this.clientListener).toString();
    doReturn(this.pipeline).when(this.clientListener).pipeline();
    doReturn(this.pipeline).when(this.pipeline).replace(any(ChannelHandler.class), any(String.class), any(ChannelHandler.class));
    doReturn(this.eventLoop).when(this.clientListener).eventLoop();
    doNothing().when(this.statsRegistry).bind(any(), any());
    doNothing().when(this.statsRegistry).unbind(any());
    doReturn(null).when(this.eventLoop).schedule(any(Runnable.class), any(long.class), any(TimeUnit.class));
    doReturn(true).when(this.clientListener).isActive();
    final InetSocketAddress ra = new InetSocketAddress(this.testAddress, 4189);
    doReturn(ra).when(this.clientListener).remoteAddress();
    final InetSocketAddress la = new InetSocketAddress(this.testAddress, InetSocketAddressUtil.getRandomPort());
    doReturn(la).when(this.clientListener).localAddress();
    doReturn(mock(ChannelFuture.class)).when(this.clientListener).close();
    doReturn(getDataBroker()).when(this.topologyDependencies).getDataBroker();
    doReturn(this.statsRegistry).when(this.topologyDependencies).getStateRegistry();
    @SuppressWarnings("unchecked") final T listenerFactory = (T) ((Class) ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments()[0]).newInstance();
    doReturn(new IpAddress(new Ipv4Address(this.testAddress))).when(this.sessionConfig).getListenAddress();
    doReturn(new PortNumber(4189)).when(this.sessionConfig).getListenPort();
    doReturn(RPC_TIMEOUT).when(this.sessionConfig).getRpcTimeout();
    doReturn(TEST_TOPOLOGY_ID).when(this.topology).getTopologyId();
    doReturn(Collections.emptyList()).when(this.topology).getNode();
    final PCEPTopologyConfiguration configDep = new PCEPTopologyConfiguration(this.sessionConfig, this.topology);
    this.manager = new ServerSessionManager(this.topologyDependencies, listenerFactory, configDep);
    startSessionManager();
    this.neg = new DefaultPCEPSessionNegotiator(this.promise, this.clientListener, this.manager.getSessionListener(), (short) 1, 5, this.localPrefs);
    this.topologyRpcs = new TopologyRPCs(this.manager);
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) PCEPTopologyConfiguration(org.opendaylight.bgpcep.pcep.topology.provider.config.PCEPTopologyConfiguration) InetSocketAddress(java.net.InetSocketAddress) ChannelHandler(io.netty.channel.ChannelHandler) Notification(org.opendaylight.yangtools.yang.binding.Notification) TimeUnit(java.util.concurrent.TimeUnit) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) DefaultPCEPSessionNegotiator(org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiator) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Before(org.junit.Before)

Example 19 with Notification

use of org.opendaylight.yangtools.yang.binding.Notification in project bgpcep by opendaylight.

the class FiniteStateMachineTest method testErrorOneTwo.

/**
 * OpenWait timer expired.
 *
 * @throws InterruptedException exception
 */
@Test
public void testErrorOneTwo() throws Exception {
    this.serverSession.channelActive(null);
    assertEquals(1, this.msgsSend.size());
    assertTrue(this.msgsSend.get(0) instanceof OpenMessage);
    checkEquals(() -> {
        for (final Notification m : this.msgsSend) {
            if (m instanceof Pcerr) {
                final Errors obj = ((Pcerr) m).getPcerrMessage().getErrors().get(0);
                assertEquals(new Short((short) 1), obj.getErrorObject().getType());
                assertEquals(new Short((short) 2), obj.getErrorObject().getValue());
            }
        }
    });
}
Also used : Errors(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.Errors) PCEPErrors(org.opendaylight.protocol.pcep.spi.PCEPErrors) OpenMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenMessage) Pcerr(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcerr) Notification(org.opendaylight.yangtools.yang.binding.Notification) Test(org.junit.Test)

Example 20 with Notification

use of org.opendaylight.yangtools.yang.binding.Notification in project bgpcep by opendaylight.

the class BGPSessionImplTest method setUp.

@Before
public void setUp() throws UnknownHostException {
    new EmbeddedChannel();
    MockitoAnnotations.initMocks(this);
    final List<BgpParameters> tlvs = Lists.newArrayList();
    this.classicOpen = new OpenBuilder().setMyAsNumber(AS_NUMBER.getValue().intValue()).setHoldTimer(HOLD_TIMER).setVersion(new ProtocolVersion((short) 4)).setBgpParameters(tlvs).setBgpIdentifier(BGP_ID).build();
    final List<OptionalCapabilities> capa = Lists.newArrayList();
    capa.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(this.ipv4tt.getAfi()).setSafi(this.ipv4tt.getSafi()).build()).setGracefulRestartCapability(new GracefulRestartCapabilityBuilder().build()).build()).setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(AS_NUMBER).build()).build()).build());
    capa.add(new OptionalCapabilitiesBuilder().setCParameters(BgpExtendedMessageUtil.EXTENDED_MESSAGE_CAPABILITY).build());
    tlvs.add(new BgpParametersBuilder().setOptionalCapabilities(capa).build());
    final ChannelFuture f = mock(ChannelFuture.class);
    doReturn(null).when(f).addListener(Mockito.any());
    doAnswer(invocation -> {
        final Object[] args = invocation.getArguments();
        BGPSessionImplTest.this.receivedMsgs.add((Notification) args[0]);
        return f;
    }).when(this.speakerListener).writeAndFlush(Mockito.any(Notification.class));
    doReturn(this.eventLoop).when(this.speakerListener).eventLoop();
    doReturn(true).when(this.speakerListener).isActive();
    doAnswer(invocation -> {
        final Runnable command = (Runnable) invocation.getArguments()[0];
        final long delay = (long) invocation.getArguments()[1];
        final TimeUnit unit = (TimeUnit) invocation.getArguments()[2];
        GlobalEventExecutor.INSTANCE.schedule(command, delay, unit);
        return null;
    }).when(this.eventLoop).schedule(Mockito.any(Runnable.class), Mockito.any(long.class), Mockito.any(TimeUnit.class));
    doReturn("TestingChannel").when(this.speakerListener).toString();
    doReturn(true).when(this.speakerListener).isWritable();
    doReturn(new InetSocketAddress(InetAddress.getByName(BGP_ID.getValue()), 179)).when(this.speakerListener).remoteAddress();
    doReturn(new InetSocketAddress(InetAddress.getByName(LOCAL_IP), LOCAL_PORT)).when(this.speakerListener).localAddress();
    doReturn(this.pipeline).when(this.speakerListener).pipeline();
    doReturn(this.pipeline).when(this.pipeline).replace(Mockito.any(ChannelHandler.class), Mockito.any(String.class), Mockito.any(ChannelHandler.class));
    doReturn(null).when(this.pipeline).replace(Matchers.<Class<ChannelHandler>>any(), Mockito.any(String.class), Mockito.any(ChannelHandler.class));
    doReturn(this.pipeline).when(this.pipeline).addLast(Mockito.any(ChannelHandler.class));
    final ChannelFuture futureChannel = mock(ChannelFuture.class);
    doReturn(null).when(futureChannel).addListener(Mockito.any());
    doReturn(futureChannel).when(this.speakerListener).close();
    this.listener = new SimpleSessionListener();
    this.bgpSession = new BGPSessionImpl(this.listener, this.speakerListener, this.classicOpen, this.classicOpen.getHoldTimer(), null);
    this.bgpSession.setChannelExtMsgCoder(this.classicOpen);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ChannelHandler(io.netty.channel.ChannelHandler) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters) ProtocolVersion(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.ProtocolVersion) CParameters1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1) Notification(org.opendaylight.yangtools.yang.binding.Notification) As4BytesCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapabilityBuilder) CParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParametersBuilder) TimeUnit(java.util.concurrent.TimeUnit) ChannelFuture(io.netty.channel.ChannelFuture) OptionalCapabilitiesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.OptionalCapabilitiesBuilder) OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.OpenBuilder) MultiprotocolCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.MultiprotocolCapabilityBuilder) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) BgpParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParametersBuilder) OptionalCapabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.OptionalCapabilities) CParameters1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1Builder) GracefulRestartCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.GracefulRestartCapabilityBuilder) Before(org.junit.Before)

Aggregations

Notification (org.opendaylight.yangtools.yang.binding.Notification)35 Test (org.junit.Test)18 ByteBuf (io.netty.buffer.ByteBuf)10 OpenBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.OpenBuilder)8 ProtocolVersion (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.ProtocolVersion)7 ChannelFuture (io.netty.channel.ChannelFuture)6 InetSocketAddress (java.net.InetSocketAddress)6 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)6 Open (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Open)6 Before (org.junit.Before)5 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)5 Notify (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Notify)5 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters)5 ChannelHandler (io.netty.channel.ChannelHandler)4 TimeUnit (java.util.concurrent.TimeUnit)4 BGPParsingException (org.opendaylight.protocol.bgp.parser.BGPParsingException)4 BgpParametersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParametersBuilder)4 OptionalCapabilities (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.OptionalCapabilities)4 PCEPErrors (org.opendaylight.protocol.pcep.spi.PCEPErrors)3 OptionalCapabilitiesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.OptionalCapabilitiesBuilder)3