Search in sources :

Example 46 with TableKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey in project openflowplugin by opendaylight.

the class StatisticsGatheringUtilsTest method testGatherStatistics_flow.

@Test
public void testGatherStatistics_flow() throws Exception {
    final short tableId = 0;
    final MultipartType type = MultipartType.OFPMPFLOW;
    final InstanceIdentifier<FlowCapableNode> nodePath = deviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
    final TableBuilder tableDataBld = new TableBuilder();
    tableDataBld.setId(tableId);
    final FlowCapableNodeBuilder flowNodeBuilder = new FlowCapableNodeBuilder();
    flowNodeBuilder.setTable(Collections.singletonList(tableDataBld.build()));
    final Optional<FlowCapableNode> flowNodeOpt = Optional.of(flowNodeBuilder.build());
    final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> flowNodeFuture = Futures.immediateCheckedFuture(flowNodeOpt);
    when(readTx.read(LogicalDatastoreType.OPERATIONAL, nodePath)).thenReturn(flowNodeFuture);
    when(flowDescriptor.getFlowId()).thenReturn(flowId);
    final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder matchBld = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder().setMatchEntry(Collections.<MatchEntry>emptyList());
    final FlowStatsBuilder flowStatsBld = new FlowStatsBuilder().setByteCount(BigInteger.valueOf(55L)).setPacketCount(BigInteger.valueOf(56L)).setDurationSec(57L).setDurationNsec(58L).setTableId((short) 0).setMatch(matchBld.build()).setFlags(new FlowModFlags(true, false, false, false, true));
    final MultipartReplyFlowBuilder mpReplyFlowBld = new MultipartReplyFlowBuilder();
    mpReplyFlowBld.setFlowStats(Lists.newArrayList(flowStatsBld.build()));
    final MultipartReplyFlowCaseBuilder mpReplyFlowCaseBld = new MultipartReplyFlowCaseBuilder();
    mpReplyFlowCaseBld.setMultipartReplyFlow(mpReplyFlowBld.build());
    final MultipartReply flowStatsUpdated = assembleMPReplyMessage(type, mpReplyFlowCaseBld.build());
    final List<MultipartReply> statsData = Collections.singletonList(flowStatsUpdated);
    fireAndCheck(type, statsData);
    final FlowBuilder flowBld = new FlowBuilder().setTableId((short) 0).setMatch(new MatchBuilder().build());
    final KeyedInstanceIdentifier<Table, TableKey> tablePath = dummyNodePath.augmentation(FlowCapableNode.class).child(Table.class, new TableKey((short) 0));
    final KeyedInstanceIdentifier<Flow, FlowKey> flowPath = tablePath.child(Flow.class, new FlowKey(flowId));
    verify(deviceContext, Mockito.never()).addDeleteToTxChain(Matchers.eq(LogicalDatastoreType.OPERATIONAL), Matchers.<InstanceIdentifier<?>>any());
    final InOrder inOrder = Mockito.inOrder(deviceContext);
    inOrder.verify(deviceContext).writeToTransaction(Matchers.eq(LogicalDatastoreType.OPERATIONAL), Matchers.any(), Matchers.any());
}
Also used : MultipartReply(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply) FlowCapableNodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder) MultipartReplyTableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTableBuilder) TableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder) MultipartReplyFlowCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCaseBuilder) FlowStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStatsBuilder) MultipartReplyFlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlowBuilder) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) 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) InOrder(org.mockito.InOrder) Optional(com.google.common.base.Optional) FlowModFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags) MultipartType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType) 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) MultipartReplyFlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlowBuilder) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) Test(org.junit.Test)

Example 47 with TableKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey in project openflowplugin by opendaylight.

the class OpenflowpluginStatsTestCommandProvider method _tableStats.

public void _tableStats(CommandInterpreter ci) {
    int tableCount = 0;
    int tableStatsCount = 0;
    List<Node> nodes = getNodes();
    for (Node node2 : nodes) {
        NodeKey nodeKey = node2.getKey();
        InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
        ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
        FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
        if (node != null) {
            List<Table> tables = node.getTable();
            for (Table table2 : tables) {
                tableCount++;
                TableKey tableKey = table2.getKey();
                InstanceIdentifier<Table> tableRef = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).child(Table.class, tableKey);
                Table table = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, tableRef);
                if (table != null) {
                    FlowTableStatisticsData data = table.getAugmentation(FlowTableStatisticsData.class);
                    if (null != data) {
                        tableStatsCount++;
                    }
                }
            }
        }
    }
    if (tableCount == tableStatsCount) {
        LOG.debug("tableStats - Success");
    } else {
        LOG.debug("tableStats - Failed");
        LOG.debug("System fetchs stats data in 50 seconds interval, so pls wait and try again.");
    }
}
Also used : Table(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table) FlowTableStatisticsData(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsData) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) 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) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)

Example 48 with TableKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey in project openflowplugin by opendaylight.

the class OpenflowpluginStatsTestCommandProvider method _aggregateStats.

public void _aggregateStats(CommandInterpreter ci) {
    int aggregateFlowCount = 0;
    int aggerateFlowStatsCount = 0;
    List<Node> nodes = getNodes();
    for (Node node2 : nodes) {
        NodeKey nodeKey = node2.getKey();
        InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
        ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
        FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
        if (node != null) {
            List<Table> tables = node.getTable();
            for (Table table2 : tables) {
                aggregateFlowCount++;
                TableKey tableKey = table2.getKey();
                InstanceIdentifier<Table> tableRef = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).child(Table.class, tableKey);
                Table table = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, tableRef);
                if (table != null) {
                    AggregateFlowStatisticsData data = table.getAugmentation(AggregateFlowStatisticsData.class);
                    if (null != data) {
                        aggerateFlowStatsCount++;
                    }
                }
            }
        }
    }
    if (aggregateFlowCount == aggerateFlowStatsCount) {
        LOG.debug("aggregateStats - Success");
    } else {
        LOG.debug("aggregateStats - Failed");
        LOG.debug("System fetchs stats data in 50 seconds interval, so pls wait and try again.");
    }
}
Also used : Table(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) 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) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) AggregateFlowStatisticsData(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsData)

Example 49 with TableKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey in project openflowplugin by opendaylight.

the class OFPluginFlowTest method writeFlow.

static void writeFlow(FlowBuilder flow, InstanceIdentifier<FlowCapableNode> flowNodeIdent) {
    ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
    final InstanceIdentifier<Flow> path1 = flowNodeIdent.child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.getKey());
    modification.merge(LogicalDatastoreType.CONFIGURATION, path1, flow.build(), true);
    CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
    Futures.addCallback(commitFuture, new FutureCallback<Void>() {

        @Override
        public void onSuccess(Void aVoid) {
            LOG.debug("Write of flow on device succeeded.");
        }

        @Override
        public void onFailure(Throwable throwable) {
            LOG.error("Write of flow on device failed.", throwable);
        }
    }, MoreExecutors.directExecutor());
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) Table(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) 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 50 with TableKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey in project openflowplugin by opendaylight.

the class SalFlowServiceImplTest method mockingFlowRegistryLookup.

private void mockingFlowRegistryLookup() {
    FlowDescriptor mockedFlowDescriptor = mock(FlowDescriptor.class);
    FlowId flowId = new FlowId(DUMMY_FLOW_ID);
    when(mockedFlowDescriptor.getFlowId()).thenReturn(flowId);
    when(mockedFlowDescriptor.getTableKey()).thenReturn(new TableKey(DUMMY_TABLE_ID));
    when(deviceFlowRegistry.retrieveDescriptor(Matchers.any(FlowRegistryKey.class))).thenReturn(mockedFlowDescriptor);
}
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) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)

Aggregations

TableKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)50 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)41 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)37 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)28 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)28 FlowKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey)27 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)23 Table (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table)22 Test (org.junit.Test)13 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)12 ArrayList (java.util.ArrayList)10 FlowBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder)10 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)8 ItemSyncBox (org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox)8 FlowRef (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef)8 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)8 NodeKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)8 TableBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder)7 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)6 StaleFlow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlow)6