Search in sources :

Example 11 with Notification

use of org.opendaylight.yangtools.yang.binding.Notification 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 12 with Notification

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

the class AbstractBmpPerPeerMessageParserTest method setUp.

@Before
public void setUp() {
    this.ctx = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance();
    final MessageRegistry msgRegistry = this.ctx.getMessageRegistry();
    this.parser = new AbstractBmpPerPeerMessageParser<Builder<?>>(msgRegistry) {

        @Override
        public Notification parseMessageBody(final ByteBuf bytes) {
            return null;
        }

        @Override
        public int getBmpMessageType() {
            return 0;
        }
    };
}
Also used : MessageRegistry(org.opendaylight.protocol.bgp.parser.spi.MessageRegistry) PeerUpNotificationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerUpNotificationBuilder) Builder(org.opendaylight.yangtools.concepts.Builder) PeerHeaderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeaderBuilder) ByteBuf(io.netty.buffer.ByteBuf) PeerUpNotification(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerUpNotification) Notification(org.opendaylight.yangtools.yang.binding.Notification) Before(org.junit.Before)

Example 13 with Notification

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

the class BindingToNormalizedNodeCodec method getNotificationClasses.

@SuppressWarnings("unchecked")
public Set<Class<? extends Notification>> getNotificationClasses(final Set<SchemaPath> interested) {
    final Set<Class<? extends Notification>> result = new HashSet<>();
    final Set<NotificationDefinition> knownNotifications = runtimeContext().getSchemaContext().getNotifications();
    for (final NotificationDefinition notification : knownNotifications) {
        if (interested.contains(notification.getPath())) {
            try {
                result.add((Class<? extends Notification>) runtimeContext().getClassForSchema(notification));
            } catch (final IllegalStateException e) {
                // Ignore
                LOG.warn("Class for {} is currently not known.", notification.getPath(), e);
            }
        }
    }
    return result;
}
Also used : NotificationDefinition(org.opendaylight.yangtools.yang.model.api.NotificationDefinition) Notification(org.opendaylight.yangtools.yang.binding.Notification) HashSet(java.util.HashSet)

Example 14 with Notification

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

the class BindingDOMNotificationListenerAdapter method onNotification.

@Override
public void onNotification(@Nonnull final DOMNotification notification) {
    final Notification baNotification = deserialize(notification);
    final QName notificationQName = notification.getType().getLastComponent();
    getInvoker(notification.getType()).invokeNotification(delegate, notificationQName, baNotification);
}
Also used : QName(org.opendaylight.yangtools.yang.common.QName) Notification(org.opendaylight.yangtools.yang.binding.Notification) DOMNotification(org.opendaylight.controller.md.sal.dom.api.DOMNotification)

Example 15 with Notification

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

the class NotificationInvoker method getNotificationTypes.

@SuppressWarnings("unchecked")
private static Set<Class<? extends Notification>> getNotificationTypes(final Class<? extends org.opendaylight.yangtools.yang.binding.NotificationListener> type) {
    // TODO: Investigate possibility and performance impact if we cache this or expose
    // it from NotificationListenerInvoker
    final Set<Class<? extends Notification>> ret = new HashSet<>();
    for (final Method method : type.getMethods()) {
        if (BindingReflections.isNotificationCallback(method)) {
            final Class<? extends Notification> notification = (Class<? extends Notification>) method.getParameterTypes()[0];
            ret.add(notification);
        }
    }
    return ret;
}
Also used : Method(java.lang.reflect.Method) Notification(org.opendaylight.yangtools.yang.binding.Notification) HashSet(java.util.HashSet)

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