Search in sources :

Example 6 with Notify

use of org.oasis_open.docs.wsn.b_2.Notify in project bgpcep by opendaylight.

the class BGPSessionImplTest method testHandleOpenMsg.

@Test
public void testHandleOpenMsg() throws BGPDocumentedException {
    this.bgpSession.handleMessage(this.classicOpen);
    Assert.assertEquals(State.IDLE, this.bgpSession.getState());
    Assert.assertEquals(1, this.receivedMsgs.size());
    Assert.assertTrue(this.receivedMsgs.get(0) instanceof Notify);
    final Notify error = (Notify) this.receivedMsgs.get(0);
    Assert.assertEquals(BGPError.FSM_ERROR.getCode(), error.getErrorCode().shortValue());
    Assert.assertEquals(BGPError.FSM_ERROR.getSubcode(), error.getErrorSubcode().shortValue());
    Mockito.verify(this.speakerListener).close();
}
Also used : Notify(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Notify) Test(org.junit.Test)

Example 7 with Notify

use of org.oasis_open.docs.wsn.b_2.Notify 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 8 with Notify

use of org.oasis_open.docs.wsn.b_2.Notify in project bgpcep by opendaylight.

the class BGPSessionImpl method handleMessage.

/**
 * Handles incoming message based on their type.
 *
 * @param msg incoming message
 */
synchronized void handleMessage(final Notification msg) {
    if (this.state == State.IDLE) {
        return;
    }
    try {
        // Update last reception time
        this.lastMessageReceivedAt = System.nanoTime();
        if (msg instanceof Open) {
            // Open messages should not be present here
            this.terminate(new BGPDocumentedException(null, BGPError.FSM_ERROR));
        } else if (msg instanceof Notify) {
            final Notify notify = (Notify) msg;
            // Notifications are handled internally
            LOG.info("Session closed because Notification message received: {} / {}, data={}", notify.getErrorCode(), notify.getErrorSubcode(), notify.getData() != null ? ByteBufUtil.hexDump(notify.getData()) : null);
            notifyTerminationReasonAndCloseWithoutMessage(notify.getErrorCode(), notify.getErrorSubcode());
        } else if (msg instanceof Keepalive) {
            // Keepalives are handled internally
            LOG.trace("Received KeepAlive message.");
            this.kaCounter++;
            if (this.kaCounter >= 2) {
                this.sync.kaReceived();
            }
        } else if (msg instanceof RouteRefresh) {
            this.listener.onMessage(this, msg);
        } else if (msg instanceof Update) {
            this.listener.onMessage(this, msg);
            this.sync.updReceived((Update) msg);
        } else {
            LOG.warn("Ignoring unhandled message: {}.", msg.getClass());
        }
        this.sessionState.messageReceived(msg);
    } catch (final BGPDocumentedException e) {
        this.terminate(e);
    }
}
Also used : Notify(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Notify) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) RouteRefresh(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.RouteRefresh) Keepalive(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Keepalive) Update(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Open)

Example 9 with Notify

use of org.oasis_open.docs.wsn.b_2.Notify in project bgpcep by opendaylight.

the class ParserTest method testNotificationMsg.

@Test
public void testNotificationMsg() throws BGPParsingException, BGPDocumentedException {
    Notification notMsg = new NotifyBuilder().setErrorCode(BGPError.OPT_PARAM_NOT_SUPPORTED.getCode()).setErrorSubcode(BGPError.OPT_PARAM_NOT_SUPPORTED.getSubcode()).setData(new byte[] { 4, 9 }).build();
    final ByteBuf bytes = Unpooled.buffer();
    ParserTest.reg.serializeMessage(notMsg, bytes);
    assertArrayEquals(notificationBMsg, ByteArray.subByte(bytes.array(), 0, bytes.writerIndex()));
    Notification m = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
    assertTrue(m instanceof Notify);
    assertEquals(BGPError.OPT_PARAM_NOT_SUPPORTED, BGPError.forValue(((Notify) m).getErrorCode(), ((Notify) m).getErrorSubcode()));
    assertArrayEquals(new byte[] { 4, 9 }, ((Notify) m).getData());
    notMsg = new NotifyBuilder().setErrorCode(BGPError.CONNECTION_NOT_SYNC.getCode()).setErrorSubcode(BGPError.CONNECTION_NOT_SYNC.getSubcode()).build();
    bytes.clear();
    ParserTest.reg.serializeMessage(notMsg, bytes);
    m = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes), null);
    assertTrue(m instanceof Notify);
    assertEquals(BGPError.CONNECTION_NOT_SYNC, BGPError.forValue(((Notify) m).getErrorCode(), ((Notify) m).getErrorSubcode()));
    assertNull(((Notify) m).getData());
}
Also used : NotifyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.NotifyBuilder) Notify(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Notify) ByteBuf(io.netty.buffer.ByteBuf) Notification(org.opendaylight.yangtools.yang.binding.Notification) Test(org.junit.Test)

Example 10 with Notify

use of org.oasis_open.docs.wsn.b_2.Notify in project bgpcep by opendaylight.

the class AbstractBGPSessionNegotiator method handleMessage.

protected synchronized void handleMessage(final Notification msg) {
    LOG.debug("Channel {} handling message in state {}, msg: {}", this.channel, this.state, msg);
    switch(this.state) {
        case FINISHED:
            sendMessage(buildErrorNotify(BGPError.FSM_ERROR));
            return;
        case IDLE:
            // to avoid race condition when Open message was sent by the peer before startNegotiation could be executed
            if (msg instanceof Open) {
                startNegotiation();
                handleOpen((Open) msg);
                return;
            }
            sendMessage(buildErrorNotify(BGPError.FSM_ERROR));
            break;
        case OPEN_CONFIRM:
            if (msg instanceof Keepalive) {
                negotiationSuccessful(this.session);
                LOG.info("BGP Session with peer {} established successfully.", this.channel);
            } else if (msg instanceof Notify) {
                final Notify ntf = (Notify) msg;
                negotiationFailed(new BGPDocumentedException("Peer refusal", BGPError.forValue(ntf.getErrorCode(), ntf.getErrorSubcode())));
            }
            this.state = State.FINISHED;
            return;
        case OPEN_SENT:
            if (msg instanceof Open) {
                handleOpen((Open) msg);
                return;
            }
            break;
        default:
            break;
    }
    // Catch-all for unexpected message
    LOG.warn("Channel {} state {} unexpected message {}", this.channel, this.state, msg);
    sendMessage(buildErrorNotify(BGPError.FSM_ERROR));
    negotiationFailed(new BGPDocumentedException("Unexpected message channel: " + this.channel + ", state: " + this.state + ", message: " + msg, BGPError.FSM_ERROR));
    this.state = State.FINISHED;
}
Also used : Notify(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Notify) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) Keepalive(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Keepalive) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Open)

Aggregations

Notify (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Notify)11 Test (org.junit.Test)9 NotificationMessageHolderType (org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType)7 JAXBException (javax.xml.bind.JAXBException)6 Notify (org.oasis_open.docs.wsn.b_2.Notify)5 Open (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Open)5 Notification (org.opendaylight.yangtools.yang.binding.Notification)5 JMSException (javax.jms.JMSException)4 OpenBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.OpenBuilder)4 Message (javax.jms.Message)3 TextMessage (javax.jms.TextMessage)3 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)3 ProtocolVersion (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.ProtocolVersion)3 Element (org.w3c.dom.Element)3 ByteBuf (io.netty.buffer.ByteBuf)2 StringReader (java.io.StringReader)2 StringWriter (java.io.StringWriter)2 QName (javax.xml.namespace.QName)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 Consumer (org.apache.cxf.wsn.client.Consumer)2