Search in sources :

Example 1 with FlowRegistryKey

use of org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey in project openflowplugin by opendaylight.

the class DeviceContextImplTest method testProcessFlowRemovedMessage.

@Test
public void testProcessFlowRemovedMessage() throws Exception {
    // prepare translation result
    final FlowRemovedBuilder flowRemovedMdsalBld = new FlowRemovedBuilder().setTableId((short) 0).setPriority(42).setCookie(new FlowCookie(BigInteger.ONE)).setMatch(new MatchBuilder().build());
    final NotificationPublishService mockedNotificationPublishService = mock(NotificationPublishService.class);
    Mockito.when(messageTranslatorFlowRemoved.translate(any(Object.class), any(DeviceInfo.class), any(Object.class))).thenReturn(flowRemovedMdsalBld.build());
    // insert flow+flowId into local registry
    final FlowRegistryKey flowRegKey = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), flowRemovedMdsalBld.build());
    final FlowDescriptor flowDescriptor = FlowDescriptorFactory.create((short) 0, new FlowId("ut-ofp:f456"));
    deviceContext.getDeviceFlowRegistry().storeDescriptor(flowRegKey, flowDescriptor);
    // prepare empty input message
    final FlowRemovedMessageBuilder flowRemovedBld = new FlowRemovedMessageBuilder();
    // prepare path to flow to be removed
    final KeyedInstanceIdentifier<Flow, FlowKey> flowToBeRemovedPath = nodeKeyIdent.augmentation(FlowCapableNode.class).child(Table.class, new TableKey((short) 0)).child(Flow.class, new FlowKey(new FlowId("ut-ofp:f456")));
    deviceContext.setNotificationPublishService(mockedNotificationPublishService);
    deviceContext.processFlowRemovedMessage(flowRemovedBld.build());
}
Also used : FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) Table(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table) FlowRegistryKey(org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey) FlowDescriptor(org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor) FlowRemovedBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) DeviceInfo(org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo) FlowRemovedMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) NotificationPublishService(org.opendaylight.controller.md.sal.binding.api.NotificationPublishService) Test(org.junit.Test)

Example 2 with FlowRegistryKey

use of org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey in project openflowplugin by opendaylight.

the class DeviceFlowRegistryImplTest method testStore.

@Test
public void testStore() throws Exception {
    // store the same key with different value
    final FlowDescriptor descriptor2 = FlowDescriptorFactory.create(key.getTableId(), new FlowId("ut:2"));
    deviceFlowRegistry.storeDescriptor(key, descriptor2);
    Assert.assertEquals(1, deviceFlowRegistry.getAllFlowDescriptors().size());
    Assert.assertEquals("ut:2", deviceFlowRegistry.retrieveDescriptor(key).getFlowId().getValue());
    // store new key with old value
    final FlowAndStatisticsMapList flowStats = TestFlowHelper.createFlowAndStatisticsMapListBuilder(2).build();
    final FlowRegistryKey key2 = FlowRegistryKeyFactory.create(OFConstants.OFP_VERSION_1_3, flowStats);
    deviceFlowRegistry.storeDescriptor(key2, descriptor);
    Assert.assertEquals(2, deviceFlowRegistry.getAllFlowDescriptors().size());
    Assert.assertEquals("ut:1", deviceFlowRegistry.retrieveDescriptor(key2).getFlowId().getValue());
}
Also used : FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) FlowRegistryKey(org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey) FlowDescriptor(org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor) FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList) Test(org.junit.Test)

Example 3 with FlowRegistryKey

use of org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey in project openflowplugin by opendaylight.

the class DeviceFlowRegistryImplTest method testFill.

@Test
public void testFill() throws Exception {
    final InstanceIdentifier<FlowCapableNode> path = nodeInstanceIdentifier.augmentation(FlowCapableNode.class);
    final Flow flow = new FlowBuilder().setTableId((short) 1).setPriority(10).setCookie(new FlowCookie(BigInteger.TEN)).setId(new FlowId("HELLO")).build();
    final Table table = new TableBuilder().setFlow(Collections.singletonList(flow)).build();
    final FlowCapableNode flowCapableNode = new FlowCapableNodeBuilder().setTable(Collections.singletonList(table)).build();
    final Map<FlowRegistryKey, FlowDescriptor> allFlowDescriptors = fillRegistry(path, flowCapableNode);
    key = FlowRegistryKeyFactory.create(OFConstants.OFP_VERSION_1_3, flow);
    InOrder order = inOrder(dataBroker, readOnlyTransaction);
    order.verify(dataBroker).newReadOnlyTransaction();
    order.verify(readOnlyTransaction).read(LogicalDatastoreType.CONFIGURATION, path);
    order.verify(dataBroker).newReadOnlyTransaction();
    order.verify(readOnlyTransaction).read(LogicalDatastoreType.OPERATIONAL, path);
    assertTrue(allFlowDescriptors.containsKey(key));
    deviceFlowRegistry.addMark(key);
}
Also used : Table(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table) InOrder(org.mockito.InOrder) FlowRegistryKey(org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey) FlowDescriptor(org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) FlowCapableNodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder) TableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) Test(org.junit.Test)

Example 4 with FlowRegistryKey

use of org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey in project openflowplugin by opendaylight.

the class FlowRegistryKeyFactoryTest method testGetHash2.

@Test
public void testGetHash2() throws Exception {
    MatchBuilder match1Builder = new MatchBuilder().setLayer3Match(new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix("10.0.1.157/32")).build());
    FlowBuilder flow1Builder = new FlowBuilder().setCookie(new FlowCookie(BigInteger.valueOf(483))).setMatch(match1Builder.build()).setPriority(2).setTableId((short) 0);
    FlowRegistryKey flow1Hash = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), flow1Builder.build());
    LOG.info("flowHash1: {}", flow1Hash.hashCode());
    MatchBuilder match2Builder = new MatchBuilder().setLayer3Match(new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix("10.0.0.242/32")).build());
    FlowBuilder flow2Builder = new FlowBuilder(flow1Builder.build()).setCookie(new FlowCookie(BigInteger.valueOf(148))).setMatch(match2Builder.build());
    FlowRegistryKey flow2Hash = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), flow2Builder.build());
    LOG.info("flowHash2: {}", flow2Hash.hashCode());
    Assert.assertNotSame(flow1Hash, flow2Hash);
}
Also used : Ipv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) FlowRegistryKey(org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) Ipv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) Test(org.junit.Test)

Example 5 with FlowRegistryKey

use of org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey in project openflowplugin by opendaylight.

the class FlowRegistryKeyFactoryTest method testGetHash.

@Test
public void testGetHash() throws Exception {
    FlowsStatisticsUpdate flowStats = FLOWS_STATISTICS_UPDATE_BUILDER.build();
    for (FlowAndStatisticsMapList item : flowStats.getFlowAndStatisticsMapList()) {
        FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), item);
        FlowRegistryKey lastHash = null;
        if (null != lastHash) {
            assertNotEquals(lastHash, flowRegistryKey);
        } else {
            lastHash = flowRegistryKey;
        }
    }
}
Also used : FlowsStatisticsUpdate(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate) FlowRegistryKey(org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey) FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList) Test(org.junit.Test)

Aggregations

FlowRegistryKey (org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey)12 Test (org.junit.Test)9 FlowBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder)5 FlowDescriptor (org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor)4 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)4 FlowAndStatisticsMapList (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList)4 FlowCookie (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie)4 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)4 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)3 Ipv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder)3 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)2 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)2 Table (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table)2 TableKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)2 FlowKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey)2 FlowStatisticsDataBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsDataBuilder)2 FlowsStatisticsUpdate (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate)2 FlowStatisticsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.statistics.FlowStatisticsBuilder)2 HashSet (java.util.HashSet)1 InOrder (org.mockito.InOrder)1