Search in sources :

Example 1 with FlowAdded

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAdded 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 2 with FlowAdded

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAdded in project openflowplugin by opendaylight.

the class FlowNotificationSupplierImplTest method testCreate.

@Test
public void testCreate() {
    final FlowAdded notification = notifSupplierImpl.createNotification(createTestFlow(), createTestFlowPath());
    assertNotNull(notification);
    assertEquals(FLOW_ID, notification.getFlowRef().getValue().firstKeyOf(Flow.class, FlowKey.class).getId().getValue());
    assertEquals(FLOW_TABLE_ID, notification.getFlowRef().getValue().firstKeyOf(Table.class, TableKey.class).getId());
    assertEquals(FLOW_NODE_ID, notification.getNode().getValue().firstKeyOf(Node.class, NodeKey.class).getId().getValue());
}
Also used : FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) FlowAdded(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAdded) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) Test(org.junit.Test)

Example 3 with FlowAdded

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAdded in project openflowplugin by opendaylight.

the class FlowNotificationSupplierImpl method createNotification.

@Override
public FlowAdded createNotification(final Flow dataTreeItemObject, final InstanceIdentifier<Flow> path) {
    Preconditions.checkArgument(dataTreeItemObject != null);
    Preconditions.checkArgument(path != null);
    final FlowAddedBuilder builder = new FlowAddedBuilder(dataTreeItemObject);
    builder.setFlowRef(new FlowRef(path));
    builder.setNode(createNodeRef(path));
    return builder.build();
}
Also used : FlowAddedBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAddedBuilder) FlowRef(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef)

Aggregations

Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 ProviderContext (org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext)1 BindingAwareConsumer (org.opendaylight.controller.sal.binding.api.BindingAwareConsumer)1 BindingAwareProvider (org.opendaylight.controller.sal.binding.api.BindingAwareProvider)1 NotificationProviderService (org.opendaylight.controller.sal.binding.api.NotificationProviderService)1 NotificationService (org.opendaylight.controller.sal.binding.api.NotificationService)1 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)1 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)1 FlowKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey)1 FlowAdded (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAdded)1 FlowAddedBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAddedBuilder)1 FlowRef (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef)1 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)1 NodeKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)1 OpendaylightTestNotificationListener (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.notification.rev150205.OpendaylightTestNotificationListener)1 OutOfPixieDustNotification (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.notification.rev150205.OutOfPixieDustNotification)1