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();
}
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();
}
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());
}
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();
}
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();
}
Aggregations