Search in sources :

Example 86 with Table

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table 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 87 with Table

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

the class ResubmitCodecTest method getSubTypeTest2.

/**
 * If table != null or table != OFP_TABLE_ALL
 * SUBTYPE should be set to NXAST_RESUBMIT_TABLE_SUBTYPE.
 */
@Test
public void getSubTypeTest2() {
    Byte table = new Byte((byte) 1);
    action = createAction(null, table);
    ActionResubmit actionResubmit = (ActionResubmit) action.getActionChoice();
    byte result = resubmitCodec.getSubType(actionResubmit);
    assertEquals(NXAST_RESUBMIT_TABLE_SUBTYPE, result);
}
Also used : ActionResubmit(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionResubmit) Test(org.junit.Test)

Example 88 with Table

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

the class FlowModInputMessageFactoryTest method test.

@Test
public void test() throws Exception {
    ByteBuf bb = BufferHelper.buildBuffer("ff 01 04 01 06 00 07 01 ff 05 00 00 09 30 00 30 41 02 00 0c 00 00 00 7e 00 " + "00 00 02 00 00 11 46 00 00 00 62 00 0b 00 00 00 01 00 11 80 00 02 04 00 00 00 2a 80 00 12 01 04 00 " + "00 00 00 00 00 00 00 01 00 08 2b 00 00 00 00 02 00 18 00 00 00 00 ff 01 04 01 06 00 07 01 ff 05 00 00 " + "09 30 00 30 00 04 00 18 00 00 00 00 00 00 00 10 00 00 00 2a 00 34 00 00 00 00 00 00");
    FlowModInput deserializedMessage = BufferHelper.deserialize(flowFactory, bb);
    BufferHelper.checkHeaderV13(deserializedMessage);
    byte[] cookie = new byte[] { (byte) 0xFF, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01 };
    Assert.assertEquals("Wrong cookie", new BigInteger(1, cookie), deserializedMessage.getCookie());
    byte[] cookieMask = new byte[] { (byte) 0xFF, 0x05, 0x00, 0x00, 0x09, 0x30, 0x00, 0x30 };
    Assert.assertEquals("Wrong cookie mask", new BigInteger(1, cookieMask), deserializedMessage.getCookieMask());
    Assert.assertEquals("Wrong table id", new TableId(65L), deserializedMessage.getTableId());
    Assert.assertEquals("Wrong command", FlowModCommand.forValue(2), deserializedMessage.getCommand());
    Assert.assertEquals("Wrong idle timeout", 12, deserializedMessage.getIdleTimeout().intValue());
    Assert.assertEquals("Wrong hard timeout", 0, deserializedMessage.getHardTimeout().intValue());
    Assert.assertEquals("Wrong priority", 126, deserializedMessage.getPriority().intValue());
    Assert.assertEquals("Wrong buffer id ", 2L, deserializedMessage.getBufferId().longValue());
    Assert.assertEquals("Wrong out port", new PortNumber(4422L), deserializedMessage.getOutPort());
    Assert.assertEquals("Wrong out group", 98L, deserializedMessage.getOutGroup().longValue());
    Assert.assertEquals("Wrong flags", new FlowModFlags(true, false, true, false, true), deserializedMessage.getFlags());
    Assert.assertEquals("Wrong match", createMatch(), deserializedMessage.getMatch());
    Assert.assertEquals("Wrong instructions", createInstructions(), deserializedMessage.getInstruction());
}
Also used : TableId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId) FlowModFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags) FlowModInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput) BigInteger(java.math.BigInteger) ByteBuf(io.netty.buffer.ByteBuf) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) Test(org.junit.Test)

Example 89 with Table

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

the class DeviceFlowRegistryImpl method fillFromDatastore.

private CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> fillFromDatastore(final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier<FlowCapableNode> path) {
    // Create new read-only transaction
    final ReadOnlyTransaction transaction = dataBroker.newReadOnlyTransaction();
    // Bail out early if transaction is null
    if (transaction == null) {
        return Futures.immediateFailedCheckedFuture(new ReadFailedException("Read transaction is null"));
    }
    // Prepare read operation from datastore for path
    final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> future = transaction.read(logicalDatastoreType, path);
    // Bail out early if future is null
    if (future == null) {
        return Futures.immediateFailedCheckedFuture(new ReadFailedException("Future from read transaction is null"));
    }
    Futures.addCallback(future, new FutureCallback<Optional<FlowCapableNode>>() {

        @Override
        public void onSuccess(@Nonnull Optional<FlowCapableNode> result) {
            result.asSet().stream().filter(Objects::nonNull).filter(flowCapableNode -> Objects.nonNull(flowCapableNode.getTable())).flatMap(flowCapableNode -> flowCapableNode.getTable().stream()).filter(Objects::nonNull).filter(table -> Objects.nonNull(table.getFlow())).flatMap(table -> table.getFlow().stream()).filter(Objects::nonNull).filter(flow -> Objects.nonNull(flow.getId())).forEach(flowConsumer);
            // After we are done with reading from datastore, close the transaction
            transaction.close();
        }

        @Override
        public void onFailure(Throwable throwable) {
            // Even when read operation failed, close the transaction
            transaction.close();
        }
    }, MoreExecutors.directExecutor());
    return future;
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) Arrays(java.util.Arrays) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) DeviceFlowRegistry(org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry) LoggerFactory(org.slf4j.LoggerFactory) CheckedFuture(com.google.common.util.concurrent.CheckedFuture) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) ArrayList(java.util.ArrayList) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) Optional(com.google.common.base.Optional) Map(java.util.Map) FlowDescriptor(org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor) Nonnull(javax.annotation.Nonnull) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) FlowRegistryKey(org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey) BiMap(com.google.common.collect.BiMap) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) ThreadSafe(javax.annotation.concurrent.ThreadSafe) Maps(com.google.common.collect.Maps) FutureCallback(com.google.common.util.concurrent.FutureCallback) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) Objects(java.util.Objects) Consumer(java.util.function.Consumer) GeneralAugMatchNodesNodeTableFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlow) HashBiMap(com.google.common.collect.HashBiMap) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Optional(com.google.common.base.Optional) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) Objects(java.util.Objects)

Example 90 with Table

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

the class AbstractTableMultipartService method storeStatistics.

/**
 * Stores table features to operational datastore.
 */
protected void storeStatistics(List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures> result) {
    multipartWriterProvider.lookup(MultipartType.OFPMPTABLEFEATURES).ifPresent(writer -> {
        writer.write(new TableUpdatedBuilder().setTableFeatures(result).build(), false);
        getTxFacade().submitTransaction();
    });
}
Also used : TableUpdatedBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.TableUpdatedBuilder)

Aggregations

ArrayList (java.util.ArrayList)71 BigInteger (java.math.BigInteger)63 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)51 Test (org.junit.Test)38 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)27 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)27 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)26 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)25 List (java.util.List)25 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)25 Table (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table)23 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)22 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)22 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)20 ByteBuf (io.netty.buffer.ByteBuf)18 FlowBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder)18 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)17 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)17 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)17 FlowKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey)17