Search in sources :

Example 6 with FlowRegistryKey

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

the class SalFlowServiceImpl method addFlow.

@Override
public Future<RpcResult<AddFlowOutput>> addFlow(final AddFlowInput input) {
    final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(deviceContext.getDeviceInfo().getVersion(), input);
    final ListenableFuture<RpcResult<AddFlowOutput>> future;
    if (flowAddMessage.canUseSingleLayerSerialization()) {
        future = flowAddMessage.handleServiceCall(input);
        Futures.addCallback(future, new AddFlowCallback(input, flowRegistryKey), MoreExecutors.directExecutor());
    } else {
        future = flowAdd.processFlowModInputBuilders(flowAdd.toFlowModInputs(input));
        Futures.addCallback(future, new AddFlowCallback(input, flowRegistryKey), MoreExecutors.directExecutor());
    }
    return future;
}
Also used : FlowRegistryKey(org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult)

Example 7 with FlowRegistryKey

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

the class FlowStatsMultipartWriter method storeStatistics.

@Override
public void storeStatistics(final FlowAndStatisticsMapList statistics, final boolean withParents) {
    statistics.getFlowAndStatisticsMapList().forEach(stat -> {
        final FlowBuilder flow = new FlowBuilder(stat).addAugmentation(FlowStatisticsData.class, new FlowStatisticsDataBuilder().setFlowStatistics(new FlowStatisticsBuilder(stat).build()).build());
        final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(version, flow.build());
        registry.getDeviceFlowRegistry().store(flowRegistryKey);
        final FlowDescriptor flowDescriptor = registry.getDeviceFlowRegistry().retrieveDescriptor(flowRegistryKey);
        if (Objects.nonNull(flowDescriptor)) {
            final FlowKey key = new FlowKey(flowDescriptor.getFlowId());
            writeToTransaction(getInstanceIdentifier().augmentation(FlowCapableNode.class).child(Table.class, new TableKey(stat.getTableId())).child(Flow.class, key), flow.setId(key.getId()).setKey(key).build(), withParents);
        }
    });
}
Also used : FlowStatisticsDataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsDataBuilder) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) FlowStatisticsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.statistics.FlowStatisticsBuilder) 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) 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)

Example 8 with FlowRegistryKey

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

the class AbstractFlowDirectStatisticsService method generateFlowId.

/**
 * Get flow ID from #{@link org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry} or
 * create alien ID.
 * @param flowStatistics flow statistics
 * @return generated flow ID
 */
protected FlowId generateFlowId(FlowAndStatisticsMapList flowStatistics) {
    final FlowStatisticsDataBuilder flowStatisticsDataBld = new FlowStatisticsDataBuilder().setFlowStatistics(new FlowStatisticsBuilder(flowStatistics).build());
    final FlowBuilder flowBuilder = new FlowBuilder(flowStatistics).addAugmentation(FlowStatisticsData.class, flowStatisticsDataBld.build());
    final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(getVersion(), flowBuilder.build());
    getDeviceRegistry().getDeviceFlowRegistry().store(flowRegistryKey);
    return getDeviceRegistry().getDeviceFlowRegistry().retrieveDescriptor(flowRegistryKey).getFlowId();
}
Also used : FlowStatisticsDataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsDataBuilder) FlowStatisticsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.statistics.FlowStatisticsBuilder) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) FlowRegistryKey(org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey)

Example 9 with FlowRegistryKey

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

the class DeviceFlowRegistryImplTest method testStoreIfNecessary.

@Test
public void testStoreIfNecessary() throws Exception {
    FlowId newFlowId;
    // store existing key
    deviceFlowRegistry.store(key);
    newFlowId = deviceFlowRegistry.retrieveDescriptor(key).getFlowId();
    Assert.assertEquals(1, deviceFlowRegistry.getAllFlowDescriptors().size());
    Assert.assertEquals(descriptor, deviceFlowRegistry.retrieveDescriptor(key));
    Assert.assertEquals(descriptor.getFlowId(), newFlowId);
    // store new key
    final String alienPrefix = "#UF$TABLE*2-";
    final FlowRegistryKey key2 = FlowRegistryKeyFactory.create(OFConstants.OFP_VERSION_1_3, TestFlowHelper.createFlowAndStatisticsMapListBuilder(2).build());
    deviceFlowRegistry.store(key2);
    newFlowId = deviceFlowRegistry.retrieveDescriptor(key2).getFlowId();
    Assert.assertTrue(newFlowId.getValue().startsWith(alienPrefix));
    Assert.assertTrue(deviceFlowRegistry.retrieveDescriptor(key2).getFlowId().getValue().startsWith(alienPrefix));
    Assert.assertEquals(2, deviceFlowRegistry.getAllFlowDescriptors().size());
}
Also used : FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) FlowRegistryKey(org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey) Test(org.junit.Test)

Example 10 with FlowRegistryKey

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

the class FlowRegistryKeyFactoryTest method testEquals.

@Test
public void testEquals() throws Exception {
    FlowsStatisticsUpdate flowStats = FLOWS_STATISTICS_UPDATE_BUILDER.build();
    HashSet<FlowRegistryKey> flowRegistryKeys = new HashSet<>();
    for (FlowAndStatisticsMapList item : flowStats.getFlowAndStatisticsMapList()) {
        final FlowRegistryKey key1 = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), item);
        final FlowRegistryKey key2 = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), item);
        flowRegistryKeys.add(key1);
        flowRegistryKeys.add(key1);
        flowRegistryKeys.add(key2);
    }
    assertEquals(3, flowRegistryKeys.size());
}
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) HashSet(java.util.HashSet) 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