Search in sources :

Example 1 with Notifications

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.pcntf.message.Notifications in project openflowplugin by opendaylight.

the class Activator method onSessionInitialized.

/**
 * Invoked when consumer is registered to the MD-SAL.
 */
@Override
public void onSessionInitialized(ConsumerContext session) {
    LOG.info("inSessionInitialized() passing");
    /**
     * We create instance of our LearningSwitchManager
     * and set all required dependencies,
     *
     * which are
     *   Data Broker (data storage service) - for configuring flows and reading stored switch state
     *   PacketProcessingService - for sending out packets
     *   NotificationService - for receiving notifications such as packet in.
     */
    learningSwitch = new LearningSwitchManagerMultiImpl();
    learningSwitch.setDataBroker(session.getSALService(DataBroker.class));
    learningSwitch.setPacketProcessingService(session.getRpcService(PacketProcessingService.class));
    learningSwitch.setNotificationService(session.getSALService(NotificationService.class));
    learningSwitch.start();
}
Also used : LearningSwitchManagerMultiImpl(org.opendaylight.openflowplugin.learningswitch.multi.LearningSwitchManagerMultiImpl) NotificationService(org.opendaylight.controller.sal.binding.api.NotificationService) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) PacketProcessingService(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService)

Example 2 with Notifications

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.pcntf.message.Notifications in project openflowplugin by opendaylight.

the class ConnectionAdapterImplTest method testConsume.

/**
 * Tests {@link ConnectionAdapterImpl#consume(DataObject)} with notifications.
 */
@Test
public void testConsume() {
    DataObject message = new EchoRequestMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onEchoRequestMessage((EchoRequestMessage) message);
    message = new ErrorMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onErrorMessage((ErrorMessage) message);
    message = new ExperimenterMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onExperimenterMessage((ExperimenterMessage) message);
    message = new FlowRemovedMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onFlowRemovedMessage((FlowRemovedMessage) message);
    message = new HelloMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onHelloMessage((HelloMessage) message);
    message = new MultipartReplyMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onMultipartReplyMessage((MultipartReplyMessage) message);
    message = new PacketInMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onPacketInMessage((PacketInMessage) message);
    message = new PortStatusMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onPortStatusMessage((PortStatusMessage) message);
    message = new SwitchIdleEventBuilder().build();
    adapter.consume(message);
    verify(systemListener, times(1)).onSwitchIdleEvent((SwitchIdleEvent) message);
    message = new DisconnectEventBuilder().build();
    adapter.consume(message);
    verify(systemListener, times(1)).onDisconnectEvent((DisconnectEvent) message);
    message = new EchoRequestMessageBuilder().build();
    adapter.consume(message);
    verify(messageListener, times(1)).onEchoRequestMessage((EchoRequestMessage) message);
}
Also used : ErrorMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder) DisconnectEventBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEventBuilder) ExperimenterMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessageBuilder) PacketInMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) SwitchIdleEventBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEventBuilder) PortStatusMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder) HelloMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder) MultipartReplyMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder) FlowRemovedMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder) EchoRequestMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessageBuilder) Test(org.junit.Test)

Example 3 with Notifications

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.pcntf.message.Notifications in project netvirt by opendaylight.

the class Ipv6ServiceInterfaceEventListener method remove.

@Override
public void remove(InstanceIdentifier<Interface> key, Interface del) {
    LOG.debug("Port removed {}, {}", key, del);
    if (!L2vlan.class.equals(del.getType())) {
        return;
    }
    // In ipv6service, we are only interested in the notification for NeutronPort, so we skip other notifications
    List<String> ofportIds = del.getLowerLayerIf();
    if (ofportIds == null || ofportIds.isEmpty() || !isNeutronPort(del.getName())) {
        return;
    }
    if (!ipv6ServiceEosHandler.isClusterOwner()) {
        LOG.trace("Not a cluster Owner, skipping further IPv6 processing on this node.");
        return;
    }
    Uuid portId = new Uuid(del.getName());
    VirtualPort port = ifMgr.obtainV6Interface(portId);
    if (port == null) {
        LOG.info("Port {} does not include IPv6Address, skipping.", portId);
        return;
    }
    String jobKey = Ipv6ServiceUtils.buildIpv6MonitorJobKey(portId.getValue());
    jobCoordinator.enqueueJob(jobKey, () -> {
        if (port.getServiceBindingStatus()) {
            // Unbind Service
            ipv6ServiceUtils.unbindIpv6Service(portId.getValue());
            port.setServiceBindingStatus(false);
            VirtualNetwork vnet = ifMgr.getNetwork(port.getNetworkID());
            if (null != vnet) {
                Uint64 dpId = port.getDpId();
                vnet.updateDpnPortInfo(dpId, port.getOfPort(), portId, Ipv6ServiceConstants.DEL_ENTRY);
            }
        }
        VirtualPort routerPort = ifMgr.getRouterV6InterfaceForNetwork(port.getNetworkID());
        ifMgr.handleInterfaceStateEvent(port, ipv6ServiceUtils.getDpIdFromInterfaceState(del), routerPort, del.getIfIndex(), Ipv6ServiceConstants.DEL_FLOW);
        return Collections.emptyList();
    }, SystemPropertyReader.getDataStoreJobCoordinatorMaxRetries());
}
Also used : L2vlan(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev170119.L2vlan) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 4 with Notifications

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.pcntf.message.Notifications in project controller by opendaylight.

the class NotificationIT method notificationTest.

/**
 * test of delivering of notification
 * @throws Exception
 */
@Test
public void notificationTest() throws Exception {
    LOG.info("The registration of the Provider 1.");
    AbstractTestProvider provider1 = new AbstractTestProvider() {

        @Override
        public void onSessionInitiated(ProviderContext session) {
            notifyProviderService = session.getSALService(NotificationProviderService.class);
        }
    };
    // registerProvider method calls onSessionInitiated method above
    broker.registerProvider(provider1);
    assertNotNull(notifyProviderService);
    LOG.info("The registration of the Consumer 1. It retrieves Notification Service " + "from MD-SAL and registers OpendaylightTestNotificationListener as notification listener");
    BindingAwareConsumer consumer1 = session -> {
        NotificationService notificationService = session.getSALService(NotificationService.class);
        assertNotNull(notificationService);
        listener1Reg = notificationService.registerNotificationListener(listener1);
    };
    // registerConsumer method calls onSessionInitialized method above
    broker.registerConsumer(consumer1);
    assertNotNull(listener1Reg);
    LOG.info("The notification of type FlowAdded with cookie ID 0 is created. The " + "delay 100ms to make sure that the notification was delivered to " + "listener.");
    notifyProviderService.publish(noDustNotification("rainy day", 42));
    Thread.sleep(100);
    /**
     * Check that one notification was delivered and has correct cookie.
     */
    assertEquals(1, listener1.notificationBag.size());
    assertEquals("rainy day", listener1.notificationBag.get(0).getReason());
    assertEquals(42, listener1.notificationBag.get(0).getDaysTillNewDust().intValue());
    LOG.info("The registration of the Consumer 2. SalFlowListener is registered " + "registered as notification listener.");
    BindingAwareProvider provider = session -> listener2Reg = session.getSALService(NotificationProviderService.class).registerNotificationListener(listener2);
    // registerConsumer method calls onSessionInitialized method above
    broker.registerProvider(provider);
    LOG.info("3 notifications are published");
    notifyProviderService.publish(noDustNotification("rainy day", 5));
    notifyProviderService.publish(noDustNotification("rainy day", 10));
    notifyProviderService.publish(noDustNotification("tax collector", 2));
    /**
     * The delay 100ms to make sure that the notifications were delivered to
     * listeners.
     */
    Thread.sleep(100);
    /**
     * Check that 3 notification was delivered to both listeners (first one
     * received 4 in total, second 3 in total).
     */
    assertEquals(4, listener1.notificationBag.size());
    assertEquals(3, listener2.notificationBag.size());
    /**
     * The second listener is closed (unregistered)
     */
    listener2Reg.close();
    LOG.info("The notification 5 is published");
    notifyProviderService.publish(noDustNotification("entomologist hunt", 10));
    /**
     * The delay 100ms to make sure that the notification was delivered to
     * listener.
     */
    Thread.sleep(100);
    /**
     * Check that first consumer received 5 notifications in total, second
     * consumer received only three. Last notification was never received by
     * second consumer because its listener was unregistered.
     */
    assertEquals(5, listener1.notificationBag.size());
    assertEquals(3, listener2.notificationBag.size());
}
Also used : Logger(org.slf4j.Logger) NotificationService(org.opendaylight.controller.sal.binding.api.NotificationService) OutOfPixieDustNotificationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.notification.rev150205.OutOfPixieDustNotificationBuilder) Assert.assertNotNull(org.junit.Assert.assertNotNull) LoggerFactory(org.slf4j.LoggerFactory) Test(org.junit.Test) ProviderContext(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext) NotificationProviderService(org.opendaylight.controller.sal.binding.api.NotificationProviderService) ListenerRegistration(org.opendaylight.yangtools.concepts.ListenerRegistration) ArrayList(java.util.ArrayList) BindingAwareConsumer(org.opendaylight.controller.sal.binding.api.BindingAwareConsumer) OpendaylightTestNotificationListener(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.notification.rev150205.OpendaylightTestNotificationListener) List(java.util.List) BindingAwareProvider(org.opendaylight.controller.sal.binding.api.BindingAwareProvider) OutOfPixieDustNotification(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.notification.rev150205.OutOfPixieDustNotification) NotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener) Assert.assertEquals(org.junit.Assert.assertEquals) ProviderContext(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext) BindingAwareProvider(org.opendaylight.controller.sal.binding.api.BindingAwareProvider) NotificationProviderService(org.opendaylight.controller.sal.binding.api.NotificationProviderService) NotificationService(org.opendaylight.controller.sal.binding.api.NotificationService) BindingAwareConsumer(org.opendaylight.controller.sal.binding.api.BindingAwareConsumer) Test(org.junit.Test)

Example 5 with Notifications

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.pcntf.message.Notifications in project lispflowmapping by opendaylight.

the class MappingDataListener method onDataTreeChanged.

@Override
public void onDataTreeChanged(Collection<DataTreeModification<Mapping>> changes) {
    for (DataTreeModification<Mapping> change : changes) {
        final DataObjectModification<Mapping> mod = change.getRootNode();
        if (ModificationType.DELETE == mod.getModificationType()) {
            // Process deleted mappings
            final Mapping mapping = mod.getDataBefore();
            // before being persisted, except for cluster slaves
            if (mapping.getOrigin() == MappingOrigin.Southbound && mapSystem.isMaster()) {
                continue;
            }
            LOG.trace("Received deleted data");
            LOG.trace("Key: {}", change.getRootPath().getRootIdentifier());
            LOG.trace("Value: {}", mapping);
            final Mapping convertedMapping = convertToBinaryIfNecessary(mapping);
            mapSystem.removeMapping(convertedMapping.getOrigin(), convertedMapping.getMappingRecord().getEid());
        } else if (ModificationType.SUBTREE_MODIFIED == mod.getModificationType() || ModificationType.WRITE == mod.getModificationType()) {
            final Mapping mapping = mod.getDataAfter();
            // SB notifications
            if (mapping.getOrigin() == MappingOrigin.Southbound && mapSystem.isMaster()) {
                continue;
            }
            final Mapping convertedMapping = convertToBinaryIfNecessary(mapping);
            Eid convertedEid = convertedMapping.getMappingRecord().getEid();
            if (ModificationType.SUBTREE_MODIFIED == mod.getModificationType()) {
                LOG.trace("Received update data");
                LOG.trace("Key: {}", change.getRootPath().getRootIdentifier());
                LOG.trace("Value: {}", mapping);
                mapSystem.updateMapping(convertedMapping.getOrigin(), convertedEid, new MappingData(convertedMapping.getMappingRecord()));
            } else {
                LOG.trace("Received write data");
                LOG.trace("Key: {}", change.getRootPath().getRootIdentifier());
                LOG.trace("Value: {}", mapping);
                mapSystem.addMapping(convertedMapping.getOrigin(), convertedEid, new MappingData(convertedMapping.getMappingRecord()));
            }
        } else {
            LOG.warn("Ignoring unhandled modification type {}", mod.getModificationType());
        }
    }
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) Mapping(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.Mapping)

Aggregations

ArrayList (java.util.ArrayList)6 ExecutionException (java.util.concurrent.ExecutionException)4 TimeoutException (java.util.concurrent.TimeoutException)4 Optional (com.google.common.base.Optional)3 Test (org.junit.Test)3 Notifications (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.pcntf.message.Notifications)3 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 FutureCallback (com.google.common.util.concurrent.FutureCallback)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ByteBuf (io.netty.buffer.ByteBuf)2 Semaphore (java.util.concurrent.Semaphore)2 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)2 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)2 NotificationService (org.opendaylight.controller.sal.binding.api.NotificationService)2 PCEPDeserializerException (org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)2 UnsubscribeDtclOutput (org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.UnsubscribeDtclOutput)2 UnsubscribeDtclOutputBuilder (org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.UnsubscribeDtclOutputBuilder)2 L2vlan (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev170119.L2vlan)2 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)2 MonitoringState (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringState)2