Search in sources :

Example 1 with BmpDeserializationException

use of org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException in project bgpcep by opendaylight.

the class PeerUpHandler method parseMessageBody.

@Override
public Notification parseMessageBody(final ByteBuf bytes) throws BmpDeserializationException {
    final PeerUpNotificationBuilder peerUpNot = new PeerUpNotificationBuilder().setPeerHeader(parsePerPeerHeader(bytes));
    if (peerUpNot.getPeerHeader().isIpv4()) {
        bytes.skipBytes(Ipv6Util.IPV6_LENGTH - Ipv4Util.IP4_LENGTH);
        peerUpNot.setLocalAddress(new IpAddress(Ipv4Util.addressForByteBuf(bytes)));
    } else {
        peerUpNot.setLocalAddress(new IpAddress(Ipv6Util.addressForByteBuf(bytes)));
    }
    peerUpNot.setLocalPort(new PortNumber(bytes.readUnsignedShort()));
    peerUpNot.setRemotePort(new PortNumber(bytes.readUnsignedShort()));
    try {
        final Notification opSent = this.msgRegistry.parseMessage(bytes.readSlice(getBgpMessageLength(bytes)), null);
        requireNonNull(opSent, "Error on parse Sent OPEN Message, Sent OPEN Message is null");
        Preconditions.checkArgument(opSent instanceof OpenMessage, "An instance of OpenMessage notification is required");
        final OpenMessage sent = (OpenMessage) opSent;
        final Notification opRec = this.msgRegistry.parseMessage(bytes.readSlice(getBgpMessageLength(bytes)), null);
        requireNonNull(opRec, "Error on parse Received  OPEN Message, Received  OPEN Message is null");
        Preconditions.checkArgument(opRec instanceof OpenMessage, "An instance of OpenMessage notification is required");
        final OpenMessage received = (OpenMessage) opRec;
        peerUpNot.setSentOpen(new SentOpenBuilder(sent).build());
        peerUpNot.setReceivedOpen(new ReceivedOpenBuilder(received).build());
        final InformationBuilder infos = new InformationBuilder();
        if (bytes.isReadable()) {
            parseTlvs(infos, bytes);
            peerUpNot.setInformation(infos.build());
        }
    } catch (final BGPDocumentedException | BGPParsingException e) {
        throw new BmpDeserializationException("Error while parsing BGP Open Message.", e);
    }
    return peerUpNot.build();
}
Also used : ReceivedOpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.up.ReceivedOpenBuilder) StringInformationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.string.informations.StringInformationBuilder) InformationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.up.InformationBuilder) OpenMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.OpenMessage) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) SentOpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.up.SentOpenBuilder) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) BGPParsingException(org.opendaylight.protocol.bgp.parser.BGPParsingException) BmpDeserializationException(org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber) PeerUpNotification(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerUpNotification) Notification(org.opendaylight.yangtools.yang.binding.Notification) PeerUpNotificationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerUpNotificationBuilder)

Example 2 with BmpDeserializationException

use of org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException in project bgpcep by opendaylight.

the class RouteMonitoringMessageHandler method parseMessageBody.

@Override
public Notification parseMessageBody(final ByteBuf bytes) throws BmpDeserializationException {
    final RouteMonitoringMessageBuilder routeMonitor = new RouteMonitoringMessageBuilder().setPeerHeader(parsePerPeerHeader(bytes));
    try {
        final Notification message = this.msgRegistry.parseMessage(bytes, null);
        requireNonNull(message, "UpdateMessage may not be null");
        Preconditions.checkArgument(message instanceof UpdateMessage, "An instance of UpdateMessage is required");
        final UpdateMessage updateMessage = (UpdateMessage) message;
        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.route.monitoring.message.Update update = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.route.monitoring.message.UpdateBuilder(updateMessage).build();
        routeMonitor.setUpdate(update);
    } catch (final BGPDocumentedException | BGPParsingException e) {
        throw new BmpDeserializationException("Error while parsing Update Message.", e);
    }
    return routeMonitor.build();
}
Also used : UpdateMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.UpdateMessage) BGPParsingException(org.opendaylight.protocol.bgp.parser.BGPParsingException) RouteMonitoringMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.RouteMonitoringMessageBuilder) Notification(org.opendaylight.yangtools.yang.binding.Notification) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) BmpDeserializationException(org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException)

Example 3 with BmpDeserializationException

use of org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException in project bgpcep by opendaylight.

the class BmpSessionImplTest method testExceptionCaught.

@Test
public void testExceptionCaught() throws Exception {
    this.session.exceptionCaught(this.mockedHandlerContext, new BmpDeserializationException(""));
    assertEquals(this.listener.getListMsg().size(), 0);
    assertFalse(this.listener.isUp());
}
Also used : BmpDeserializationException(org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException) Test(org.junit.Test)

Example 4 with BmpDeserializationException

use of org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException in project bgpcep by opendaylight.

the class InitiationHandler method parseMessageBody.

@Override
public Notification parseMessageBody(final ByteBuf bytes) throws BmpDeserializationException {
    final InitiationMessageBuilder initiationBuilder = new InitiationMessageBuilder();
    final TlvsBuilder tlvsBuilder = new TlvsBuilder();
    tlvsBuilder.setStringInformation(ImmutableList.of());
    parseTlvs(tlvsBuilder, bytes);
    if (tlvsBuilder.getDescriptionTlv() == null || tlvsBuilder.getDescriptionTlv().getDescription() == null) {
        throw new BmpDeserializationException("Inclusion of sysDescr TLV is mandatory.");
    }
    if (tlvsBuilder.getNameTlv() == null || tlvsBuilder.getNameTlv().getName() == null) {
        throw new BmpDeserializationException("Inclusion of sysName TLV is mandatory.");
    }
    return initiationBuilder.setTlvs(tlvsBuilder.build()).build();
}
Also used : TlvsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.initiation.TlvsBuilder) InitiationMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.InitiationMessageBuilder) BmpDeserializationException(org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException)

Example 5 with BmpDeserializationException

use of org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException in project bgpcep by opendaylight.

the class PeerDownHandler method parseBgpNotificationMessage.

private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.Notification parseBgpNotificationMessage(final ByteBuf bytes) throws BmpDeserializationException {
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.NotificationBuilder notificationCBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.NotificationBuilder();
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.notification.NotificationBuilder notificationBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.notification.NotificationBuilder();
    try {
        final Notification not = this.msgRegistry.parseMessage(bytes, null);
        requireNonNull(not, "Notify message may not be null.");
        Preconditions.checkArgument(not instanceof NotifyMessage, "An instance of NotifyMessage is required");
        notificationBuilder.fieldsFrom((NotifyMessage) not);
        notificationCBuilder.setNotification(notificationBuilder.build());
    } catch (final BGPDocumentedException | BGPParsingException e) {
        throw new BmpDeserializationException("Error while parsing BGP Notification message.", e);
    }
    return notificationCBuilder.build();
}
Also used : Preconditions(com.google.common.base.Preconditions) BGPParsingException(org.opendaylight.protocol.bgp.parser.BGPParsingException) PeerDownNotification(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerDownNotification) Notification(org.opendaylight.yangtools.yang.binding.Notification) PeerDownNotificationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerDownNotificationBuilder) NotifyMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.NotifyMessage) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) BmpDeserializationException(org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException)

Aggregations

BmpDeserializationException (org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException)6 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)3 BGPParsingException (org.opendaylight.protocol.bgp.parser.BGPParsingException)3 Notification (org.opendaylight.yangtools.yang.binding.Notification)3 Preconditions (com.google.common.base.Preconditions)1 Test (org.junit.Test)1 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)1 PortNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber)1 NotifyMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.NotifyMessage)1 OpenMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.OpenMessage)1 UpdateMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.UpdateMessage)1 InitiationMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.InitiationMessageBuilder)1 PeerDownNotification (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerDownNotification)1 PeerDownNotificationBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerDownNotificationBuilder)1 PeerUpNotification (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerUpNotification)1 PeerUpNotificationBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerUpNotificationBuilder)1 RouteMonitoringMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.RouteMonitoringMessageBuilder)1 TerminationMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.TerminationMessageBuilder)1 TlvsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.initiation.TlvsBuilder)1 InformationBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.up.InformationBuilder)1