summaryrefslogtreecommitdiffstats
path: root/infra/data-impl/src/main/java/io/fd/honeycomb/v3po/data/impl/ReadableDataTreeDelegator.java
diff options
context:
space:
mode:
authorMaros Marsalek <mmarsale@cisco.com>2016-07-27 11:05:51 +0200
committerMaros Marsalek <mmarsale@cisco.com>2016-07-29 16:32:07 +0200
commit0578156b721fa01c8c645b8f9625ecebdb6449e4 (patch)
tree49d36f24e5d984a8c9f151b1440de88619f8b7de /infra/data-impl/src/main/java/io/fd/honeycomb/v3po/data/impl/ReadableDataTreeDelegator.java
parent007d4542388ca89be409ce1a4a4c7a36ddcb538f (diff)
HONEYCOMB-130: Separate v3po plugin from HC infra
Creating folders: - common/ - infra/ - v3po/ - vpp-common/ Change-Id: I2c39e1b17e39e7c0f0628f44aa5fe08563fa06e4 Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'infra/data-impl/src/main/java/io/fd/honeycomb/v3po/data/impl/ReadableDataTreeDelegator.java')
-rw-r--r--infra/data-impl/src/main/java/io/fd/honeycomb/v3po/data/impl/ReadableDataTreeDelegator.java242
1 files changed, 242 insertions, 0 deletions
diff --git a/infra/data-impl/src/main/java/io/fd/honeycomb/v3po/data/impl/ReadableDataTreeDelegator.java b/infra/data-impl/src/main/java/io/fd/honeycomb/v3po/data/impl/ReadableDataTreeDelegator.java
new file mode 100644
index 000000000..aff023ebc
--- /dev/null
+++ b/infra/data-impl/src/main/java/io/fd/honeycomb/v3po/data/impl/ReadableDataTreeDelegator.java
@@ -0,0 +1,242 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.v3po.data.impl;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.collect.Iterables.getOnlyElement;
+
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Multimap;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.Futures;
+import io.fd.honeycomb.v3po.data.ReadableDataManager;
+import io.fd.honeycomb.v3po.translate.MappingContext;
+import io.fd.honeycomb.v3po.translate.ModificationCache;
+import io.fd.honeycomb.v3po.translate.read.ReadContext;
+import io.fd.honeycomb.v3po.translate.read.ReadFailedException;
+import io.fd.honeycomb.v3po.translate.read.registry.ReaderRegistry;
+import io.fd.honeycomb.v3po.translate.util.TransactionMappingContext;
+import java.util.Collection;
+import java.util.Map;
+import javax.annotation.Nonnull;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ReadableDataTree implementation for operational data.
+ */
+public final class ReadableDataTreeDelegator implements ReadableDataManager {
+ private static final Logger LOG = LoggerFactory.getLogger(ReadableDataTreeDelegator.class);
+
+ private final BindingNormalizedNodeSerializer serializer;
+ private final ReaderRegistry readerRegistry;
+ private final SchemaContext globalContext;
+ private final org.opendaylight.controller.md.sal.binding.api.DataBroker contextBroker;
+
+ /**
+ * Creates operational data tree instance.
+ * @param serializer service for serialization between Java Binding Data representation and NormalizedNode
+ * representation.
+ * @param globalContext service for obtaining top level context data from all yang modules.
+ * @param readerRegistry service responsible for translation between DataObjects and data provider.
+ * @param contextBroker BA broker for context data
+ */
+ public ReadableDataTreeDelegator(@Nonnull BindingNormalizedNodeSerializer serializer,
+ @Nonnull final SchemaContext globalContext,
+ @Nonnull final ReaderRegistry readerRegistry,
+ @Nonnull final org.opendaylight.controller.md.sal.binding.api.DataBroker contextBroker) {
+ this.contextBroker = checkNotNull(contextBroker, "contextBroker should not be null");
+ this.globalContext = checkNotNull(globalContext, "globalContext should not be null");
+ this.serializer = checkNotNull(serializer, "serializer should not be null");
+ this.readerRegistry = checkNotNull(readerRegistry, "reader should not be null");
+ }
+
+ @Override
+ public CheckedFuture<Optional<NormalizedNode<?, ?>>,
+ org.opendaylight.controller.md.sal.common.api.data.ReadFailedException> read(
+ @Nonnull final YangInstanceIdentifier yangInstanceIdentifier) {
+
+ try(TransactionMappingContext mappingContext = new TransactionMappingContext(contextBroker.newReadWriteTransaction());
+ ReadContext ctx = new ReadContextImpl(mappingContext)) {
+
+ final Optional<NormalizedNode<?, ?>> value;
+ if (checkNotNull(yangInstanceIdentifier).equals(YangInstanceIdentifier.EMPTY)) {
+ value = readRoot(ctx);
+ } else {
+ value = readNode(yangInstanceIdentifier, ctx);
+ }
+
+ // Submit context mapping updates
+ final CheckedFuture<Void, TransactionCommitFailedException> contextUpdateResult =
+ ((TransactionMappingContext) ctx.getMappingContext()).submit();
+ // Blocking on context data update
+ contextUpdateResult.checkedGet();
+
+ return Futures.immediateCheckedFuture(value);
+
+ } catch (ReadFailedException e) {
+ return Futures.immediateFailedCheckedFuture(
+ new org.opendaylight.controller.md.sal.common.api.data.ReadFailedException(
+ "Failed to read VPP data", e));
+ } catch (TransactionCommitFailedException e) {
+ // FIXME revert should probably occur when context is not written successfully
+ final String msg = "Error while updating mapping context data";
+ LOG.error(msg, e);
+ return Futures.immediateFailedCheckedFuture(
+ new org.opendaylight.controller.md.sal.common.api.data.ReadFailedException(msg, e)
+ );
+ }
+ }
+
+ private Optional<NormalizedNode<?, ?>> readNode(final YangInstanceIdentifier yangInstanceIdentifier,
+ final ReadContext ctx) throws ReadFailedException {
+ LOG.debug("OperationalDataTree.readNode(), yangInstanceIdentifier={}", yangInstanceIdentifier);
+ final InstanceIdentifier<?> path = serializer.fromYangInstanceIdentifier(yangInstanceIdentifier);
+ checkNotNull(path, "Invalid instance identifier %s. Cannot create BA equivalent.", yangInstanceIdentifier);
+ LOG.debug("OperationalDataTree.readNode(), path={}", path);
+
+ final Optional<? extends DataObject> dataObject;
+
+ dataObject = readerRegistry.read(path, ctx);
+ if (dataObject.isPresent()) {
+ final NormalizedNode<?, ?> value = toNormalizedNodeFunction(path).apply(dataObject.get());
+ return Optional.<NormalizedNode<?, ?>>fromNullable(value);
+ } else {
+ return Optional.absent();
+ }
+ }
+
+ private Optional<NormalizedNode<?, ?>> readRoot(final ReadContext ctx) throws ReadFailedException {
+ LOG.debug("OperationalDataTree.readRoot()");
+
+ final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> dataNodeBuilder =
+ Builders.containerBuilder()
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(SchemaContext.NAME));
+
+ final Multimap<InstanceIdentifier<? extends DataObject>, ? extends DataObject> dataObjects =
+ readerRegistry.readAll(ctx);
+
+ for (final InstanceIdentifier<? extends DataObject> instanceIdentifier : dataObjects.keySet()) {
+ final YangInstanceIdentifier rootElementId = serializer.toYangInstanceIdentifier(instanceIdentifier);
+ final NormalizedNode<?, ?> node =
+ wrapDataObjects(rootElementId, instanceIdentifier, dataObjects.get(instanceIdentifier));
+ dataNodeBuilder.withChild((DataContainerChild<?, ?>) node);
+ }
+ return Optional.<NormalizedNode<?, ?>>of(dataNodeBuilder.build());
+ }
+
+ private NormalizedNode<?, ?> wrapDataObjects(final YangInstanceIdentifier yangInstanceIdentifier,
+ final InstanceIdentifier<? extends DataObject> instanceIdentifier,
+ final Collection<? extends DataObject> dataObjects) {
+ final Collection<NormalizedNode<?, ?>> normalizedRootElements = Collections2
+ .transform(dataObjects, toNormalizedNodeFunction(instanceIdentifier));
+
+ final DataSchemaNode schemaNode =
+ globalContext.getDataChildByName(yangInstanceIdentifier.getLastPathArgument().getNodeType());
+ if (schemaNode instanceof ListSchemaNode) {
+ // In case of a list, wrap all the values in a Mixin parent node
+ final ListSchemaNode listSchema = (ListSchemaNode) schemaNode;
+ return wrapListIntoMixinNode(normalizedRootElements, listSchema);
+ } else {
+ Preconditions.checkState(dataObjects.size() == 1, "Singleton list was expected");
+ return getOnlyElement(normalizedRootElements);
+ }
+ }
+
+ private static DataContainerChild<?, ?> wrapListIntoMixinNode(
+ final Collection<NormalizedNode<?, ?>> normalizedRootElements, final ListSchemaNode listSchema) {
+ if (listSchema.getKeyDefinition().isEmpty()) {
+ final CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> listBuilder =
+ Builders.unkeyedListBuilder();
+ for (NormalizedNode<?, ?> normalizedRootElement : normalizedRootElements) {
+ listBuilder.withChild((UnkeyedListEntryNode) normalizedRootElement);
+ }
+ return listBuilder.build();
+ } else {
+ final CollectionNodeBuilder<MapEntryNode, ? extends MapNode> listBuilder =
+ listSchema.isUserOrdered()
+ ? Builders.orderedMapBuilder()
+ : Builders.mapBuilder();
+
+ for (NormalizedNode<?, ?> normalizedRootElement : normalizedRootElements) {
+ listBuilder.withChild((MapEntryNode) normalizedRootElement);
+ }
+ return listBuilder.build();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private Function<DataObject, NormalizedNode<?, ?>> toNormalizedNodeFunction(final InstanceIdentifier path) {
+ return dataObject -> {
+ LOG.trace("OperationalDataTree.toNormalizedNode(), path={}, dataObject={}", path, dataObject);
+ final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry =
+ serializer.toNormalizedNode(path, dataObject);
+
+ LOG.trace("OperationalDataTree.toNormalizedNode(), normalizedNodeEntry={}", entry);
+ return entry.getValue();
+ };
+ }
+
+ private static final class ReadContextImpl implements ReadContext {
+
+ private final ModificationCache ctx = new ModificationCache();
+ private final MappingContext mappingContext;
+
+ private ReadContextImpl(final MappingContext mappingContext) {
+ this.mappingContext = mappingContext;
+ }
+
+ @Nonnull
+ @Override
+ public ModificationCache getModificationCache() {
+ return ctx;
+ }
+
+ @Nonnull
+ @Override
+ public MappingContext getMappingContext() {
+ return mappingContext;
+ }
+
+ @Override
+ public void close() {
+ // Make sure to clear the storage in case some customizer stored a reference to it to prevent memory leaks
+ ctx.close();
+ }
+ }
+}
class="p">| ... | (flow-group per direction, ${flows_per_dir} flows per flow-group) with\ | ... | all packets containing Ethernet header, IPv4 header with UDP header and\ | ... | static payload. MAC addresses are matching MAC addresses of the TG node\ | ... | interfaces. | ... | *[Ref] Applicable standard specifications:* RFC2544. *** Variables *** | @{plugins_to_enable}= | dpdk_plugin.so | acl_plugin.so | ${osi_layer}= | L2 | ${nic_name}= | Intel-X710 | ${nic_driver}= | vfio-pci | ${overhead}= | ${0} # ACL test setup | ${acl_action}= | permit+reflect | ${acl_apply_type}= | input | ${no_hit_aces_number}= | 1 | ${flows_per_dir}= | 10k # starting points for non-hitting ACLs | ${src_ip_start}= | 30.30.30.1 | ${dst_ip_start}= | 40.40.40.1 | ${ip_step}= | ${1} | ${sport_start}= | ${1000} | ${dport_start}= | ${1000} | ${port_step}= | ${1} | ${trex_stream1_subnet}= | 10.10.10.0/24 | ${trex_stream2_subnet}= | 20.20.20.0/24 # Traffic profile: | ${traffic_profile}= | trex-sl-3n-ethip4udp-10u1000p-conc *** Keywords *** | Local Template | | [Documentation] | | ... | [Cfg] DUT runs L2BD config with ACLs with ${phy_cores} phy | | ... | core(s). | | ... | [Ver] Measure NDR and PDR values using MLRsearch algorithm.\ | | ... | | ... | *Arguments:* | | ... | - frame_size - Framesize in Bytes in integer or string (IMIX_v4_1). | | ... | Type: integer, string | | ... | - phy_cores - Number of physical cores. Type: integer | | ... | - rxq - Number of RX queues, default value: ${None}. Type: integer | | ... | | [Arguments] | ${frame_size} | ${phy_cores} | ${rxq}=${None} | | ... | | Set Test Variable | \${frame_size} | | ... | | Given Add worker threads and rxqueues to all DUTs | ${phy_cores} | ${rxq} | | And Add PCI devices to all DUTs | | And Set Max Rate And Jumbo And Handle Multi Seg | | And Apply startup configuration on all VPP DUTs | | When Initialize layer driver | ${nic_driver} | | And Initialize L2 bridge domain with IPv4 ACLs on DUT1 in 3-node circular topology | | Then Find NDR and PDR intervals using optimized search *** Test Cases *** | tc01-64B-1c-eth-l2bdbasemaclrn-iacl1sf-10kflows-ndrpdr | | [Tags] | 64B | 1C | | frame_size=${64} | phy_cores=${1} | tc02-64B-2c-eth-l2bdbasemaclrn-iacl1sf-10kflows-ndrpdr | | [Tags] | 64B | 2C | | frame_size=${64} | phy_cores=${2} | tc03-64B-4c-eth-l2bdbasemaclrn-iacl1sf-10kflows-ndrpdr | | [Tags] | 64B | 4C | | frame_size=${64} | phy_cores=${4} | tc04-1518B-1c-eth-l2bdbasemaclrn-iacl1sf-10kflows-ndrpdr | | [Tags] | 1518B | 1C | | frame_size=${1518} | phy_cores=${1} | tc05-1518B-2c-eth-l2bdbasemaclrn-iacl1sf-10kflows-ndrpdr | | [Tags] | 1518B | 2C | | frame_size=${1518} | phy_cores=${2} | tc06-1518B-4c-eth-l2bdbasemaclrn-iacl1sf-10kflows-ndrpdr | | [Tags] | 1518B | 4C | | frame_size=${1518} | phy_cores=${4} | tc07-9000B-1c-eth-l2bdbasemaclrn-iacl1sf-10kflows-ndrpdr | | [Tags] | 9000B | 1C | | frame_size=${9000} | phy_cores=${1} | tc08-9000B-2c-eth-l2bdbasemaclrn-iacl1sf-10kflows-ndrpdr | | [Tags] | 9000B | 2C | | frame_size=${9000} | phy_cores=${2} | tc09-9000B-4c-eth-l2bdbasemaclrn-iacl1sf-10kflows-ndrpdr | | [Tags] | 9000B | 4C | | frame_size=${9000} | phy_cores=${4} | tc10-IMIX-1c-eth-l2bdbasemaclrn-iacl1sf-10kflows-ndrpdr | | [Tags] | IMIX | 1C | | frame_size=IMIX_v4_1 | phy_cores=${1} | tc11-IMIX-2c-eth-l2bdbasemaclrn-iacl1sf-10kflows-ndrpdr | | [Tags] | IMIX | 2C | | frame_size=IMIX_v4_1 | phy_cores=${2} | tc12-IMIX-4c-eth-l2bdbasemaclrn-iacl1sf-10kflows-ndrpdr | | [Tags] | IMIX | 4C | | frame_size=IMIX_v4_1 | phy_cores=${4}