import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie
public class MDFlowMapping {
hardTimeout = sourceFlow.hardTimeout as int
idleTimeout = sourceFlow.idleTimeout as int
- cookie = BigInteger.valueOf(sourceFlow.id)
+ cookie = new FlowCookie(BigInteger.valueOf(sourceFlow.id))
priority = sourceFlow.priority as int
val sourceActions = sourceFlow.actions;
val it = new FlowBuilder();
hardTimeout = sourceFlow.hardTimeout as int
idleTimeout = sourceFlow.idleTimeout as int
- cookie = BigInteger.valueOf(sourceFlow.id)
+ cookie = new FlowCookie(BigInteger.valueOf(sourceFlow.id))
priority = sourceFlow.priority as int
id = new FlowId(flowId)
hardTimeout = sourceFlow.hardTimeout as int
idleTimeout = sourceFlow.idleTimeout as int
- cookie = BigInteger.valueOf(sourceFlow.id)
+ cookie = new FlowCookie(BigInteger.valueOf(sourceFlow.id))
priority = sourceFlow.priority as int
val sourceActions = sourceFlow.actions;
target.setActions(actionFrom(actions, node));
}
- target.setId(source.getCookie().longValue());
+ target.setId(source.getCookie().getValue().longValue());
return target;
}
}
private void checkOdFlow(NodeFlow odNodeFlow) {
- assertEquals("Cookie is incorrect.", 9223372036854775807L, odNodeFlow.getCookie().longValue());
+ assertEquals("Cookie is incorrect.", 9223372036854775807L, odNodeFlow.getCookie().getValue().longValue());
assertEquals("Hard timeout is incorrect.", 32765, odNodeFlow.getHardTimeout().shortValue());
assertEquals("Iddle timeout is incorrect.", 32766, odNodeFlow.getIdleTimeout().shortValue());
assertEquals("Priority is incorrect.", 32767, odNodeFlow.getPriority().shortValue());
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAddedBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeFlow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
private FlowAddedBuilder prepareOdFlowCommon() {
FlowAddedBuilder odNodeFlowBuilder = new FlowAddedBuilder();
- odNodeFlowBuilder.setCookie(new BigInteger("9223372036854775807"));
+ odNodeFlowBuilder.setCookie(new FlowCookie(new BigInteger("9223372036854775807")));
odNodeFlowBuilder.setHardTimeout(32767);
odNodeFlowBuilder.setIdleTimeout(32767);
odNodeFlowBuilder.setPriority(32767);
type instance-identifier;
}
+ typedef flow-cookie {
+ description "openflow specific type - flow cookie / flow cookie mask";
+ type uint64;
+ }
+
typedef output-port-values {
type enumeration {
enum MAX {
}
leaf cookie {
- type uint64;
+ type flow-cookie;
}
leaf table_id {
}
leaf cookie_mask {
- type uint64;
+ type flow-cookie;
}
leaf buffer_id {
import opendaylight-match-types {prefix match-type;revision-date "2013-10-26";}
import opendaylight-table-types {prefix table-type;revision-date "2013-10-26";}
import opendaylight-action-types {prefix action-type;revision-date "2013-11-12";}
+ import opendaylight-flow-types {prefix flow-type;revision-date "2013-10-26";}
revision "2013-07-09" {
description "";
}
- typedef cookie {
+ typedef connection-cookie {
type uint32;
}
}
notification packet-received {
- leaf cookie {
- type cookie;
+ leaf connection-cookie {
+ type connection-cookie;
+ }
+
+ leaf flow-cookie {
+ type flow-type:flow-cookie;
}
leaf table-id {
input {
uses inv:node-context-ref;
- leaf cookie {
- type cookie;
+ leaf connection-cookie {
+ type connection-cookie;
}
leaf egress {
type inv:node-connector-ref;
}
- leaf buffer-id {
+ leaf buffer-id {
type uint32;
}
return schemaContext;
}
+ public DOMDataBroker getDomAsyncDataBroker() {
+ return newDOMDataBroker;
+ }
+
protected BindingTestContext(final ListeningExecutorService executor, final ClassPool classPool, final boolean startWithSchema) {
this.executor = executor;
this.classPool = classPool;
<type>test-jar</type>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-binding</artifactId>
+ </dependency>
<dependency>
<groupId>org.opendaylight.controller.model</groupId>
<artifactId>model-flow-management</artifactId>
</dependencies>
<build>
<plugins>
- <plugin>
- <groupId>org.eclipse.xtend</groupId>
- <artifactId>xtend-maven-plugin</artifactId>
- </plugin>
+ <plugin>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>generate-sources</goal>
+ </goals>
+ <configuration>
+ <codeGenerators>
+ <generator>
+ <codeGeneratorClass>org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl</codeGeneratorClass>
+ <outputBaseDir>${salGeneratorPath}</outputBaseDir>
+ </generator>
+ </codeGenerators>
+ <inspectDependencies>true</inspectDependencies>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
--- /dev/null
+module opendaylight-sal-test-store {
+ yang-version 1;
+ namespace "urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:store";
+ prefix "binding-impl";
+
+ description
+ "Regression Test model for data store";
+
+ revision "2014-04-22" {
+ description
+ "Initial revision";
+ }
+
+ grouping name-value {
+ leaf name {
+ type string;
+ }
+ leaf value {
+ type string;
+ }
+ }
+
+ container lists {
+ config false;
+ container unordered-container {
+ list unordered-list {
+ key "name";
+ uses name-value;
+ }
+ }
+ container ordered-container {
+ list ordered-list {
+ ordered-by user;
+ key "name";
+ uses name-value;
+ }
+ }
+ container unkeyed-container {
+ /*
+ Following list nodes not specify key, which
+ makes impossible to uniquely identify list items
+ over time.
+ */
+ list unkeyed-list {
+ uses name-value;
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.md.sal.binding.data;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+
+import org.junit.Test;
+import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction;
+import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
+import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.Lists;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.OrderedContainer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.UnkeyedContainer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.UnkeyedContainerBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.UnorderedContainer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.ordered.container.OrderedList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.ordered.container.OrderedListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.ordered.container.OrderedListKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unkeyed.container.UnkeyedList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unkeyed.container.UnkeyedListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedListKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.Node;
+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.OrderedMapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
+import com.google.common.util.concurrent.ListenableFuture;
+
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+public class ListProcessingAndOrderingTest extends AbstractDataServiceTest {
+
+ private static final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier DOM_UNORDERED_LIST_PATH = org.opendaylight.yangtools.yang.data.api.InstanceIdentifier
+ .builder(Lists.QNAME).node(UnorderedContainer.QNAME).node(UnorderedList.QNAME).build();
+
+ private static final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier DOM_ORDERED_LIST_PATH = org.opendaylight.yangtools.yang.data.api.InstanceIdentifier
+ .builder(Lists.QNAME).node(OrderedContainer.QNAME).node(OrderedList.QNAME).build();
+
+
+ private static final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier DOM_UNKEYED_LIST_PATH = org.opendaylight.yangtools.yang.data.api.InstanceIdentifier
+ .builder(Lists.QNAME).node(UnkeyedContainer.QNAME).node(UnkeyedList.QNAME).build();
+
+ private static final InstanceIdentifier<UnorderedContainer> UNORDERED_CONTAINER_PATH = InstanceIdentifier.builder(Lists.class).child(UnorderedContainer.class).build();
+ private static final InstanceIdentifier<OrderedContainer> ORDERED_CONTAINER_PATH = InstanceIdentifier.builder(Lists.class).child(OrderedContainer.class).build();
+ private static final InstanceIdentifier<UnkeyedContainer> UNKEYED_CONTAINER_PATH = InstanceIdentifier.builder(Lists.class).child(UnkeyedContainer.class).build();
+
+ private static final UnorderedListKey UNORDERED_FOO_KEY = new UnorderedListKey("foo");
+ private static final UnorderedListKey UNORDERED_BAR_KEY = new UnorderedListKey("bar");
+
+ private static final InstanceIdentifier<UnorderedList> UNORDERED_FOO_PATH = InstanceIdentifier.builder(UNORDERED_CONTAINER_PATH).child(UnorderedList.class,UNORDERED_FOO_KEY).build();
+ private static final InstanceIdentifier<UnorderedList> UNORDERED_BAR_PATH = InstanceIdentifier.builder(UNORDERED_CONTAINER_PATH).child(UnorderedList.class,UNORDERED_BAR_KEY).build();
+
+ private static final OrderedListKey ORDERED_FOO_KEY = new OrderedListKey("foo");
+ private static final OrderedListKey ORDERED_BAR_KEY = new OrderedListKey("bar");
+ private static final InstanceIdentifier<OrderedList> ORDERED_FOO_PATH = InstanceIdentifier.builder(ORDERED_CONTAINER_PATH).child(OrderedList.class,ORDERED_FOO_KEY).build();
+ private static final InstanceIdentifier<OrderedList> ORDERED_BAR_PATH = InstanceIdentifier.builder(ORDERED_CONTAINER_PATH).child(OrderedList.class,ORDERED_BAR_KEY).build();
+
+
+ @Test
+ public void unorderedListReadWriteTest() throws InterruptedException, ExecutionException {
+ DataModificationTransaction tx = baDataService.beginTransaction();
+
+ tx.putOperationalData(UNORDERED_FOO_PATH, createUnordered("foo"));
+ tx.putOperationalData(UNORDERED_BAR_PATH, createUnordered("bar"));
+ assertedCommit(tx);
+
+ NormalizedNode<?, ?> data = resolveDataAsserted(DOM_UNORDERED_LIST_PATH);
+ assertTrue(data instanceof MapNode);
+ assertFalse(data instanceof OrderedMapNode);
+
+ assertXmlRepresentation(UNORDERED_CONTAINER_PATH, "foo","bar");
+ }
+
+
+
+ @Test
+ public void orderedListReadWriteTest() throws InterruptedException, ExecutionException {
+ DataModificationTransaction tx = baDataService.beginTransaction();
+
+ tx.putOperationalData(ORDERED_FOO_PATH, createOrdered("foo"));
+ tx.putOperationalData(ORDERED_BAR_PATH, createOrdered("bar"));
+ assertedCommit(tx);
+ NormalizedNode<?, ?> data = resolveDataAsserted(DOM_ORDERED_LIST_PATH);
+ assertTrue(data instanceof MapNode);
+ assertTrue(data instanceof OrderedMapNode);
+
+ assertXmlRepresentation(ORDERED_CONTAINER_PATH, "foo","bar");
+
+ }
+
+
+
+ @Test
+ public void unkeyedListReadWriteTest() throws InterruptedException, ExecutionException {
+ DataModificationTransaction tx = baDataService.beginTransaction();
+
+ ImmutableList<UnkeyedList> unkeyedItems= ImmutableList.<UnkeyedList>builder()
+ .add(createUnkeyed("foo"))
+ .add(createUnkeyed("bar"))
+ .build();
+
+ tx.putOperationalData(UNKEYED_CONTAINER_PATH, new UnkeyedContainerBuilder().setUnkeyedList(unkeyedItems).build());
+ assertedCommit(tx);
+ NormalizedNode<?, ?> data = resolveDataAsserted(DOM_UNKEYED_LIST_PATH);
+ assertFalse(data instanceof MapNode);
+ assertTrue(data instanceof UnkeyedListNode);
+
+ assertXmlRepresentation(UNKEYED_CONTAINER_PATH, "foo","bar");
+ }
+
+ private NormalizedNode<?, ?> resolveDataAsserted(
+ final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier domPath) {
+
+ try (DOMDataReadTransaction readTx = testContext.getDomAsyncDataBroker().newReadOnlyTransaction()){
+ ListenableFuture<Optional<NormalizedNode<?, ?>>> data = readTx.read(LogicalDatastoreType.OPERATIONAL, domPath);
+ Optional<NormalizedNode<?, ?>> potential = data.get();
+ assertTrue(potential.isPresent());
+ return potential.get();
+ } catch (InterruptedException | ExecutionException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static UnorderedList createUnordered(final String name) {
+ return new UnorderedListBuilder().setName(name).setValue(createValue(name)).build();
+ }
+
+ private static OrderedList createOrdered(final String name) {
+ return new OrderedListBuilder().setName(name).setValue(createValue(name)).build();
+ }
+
+ private static UnkeyedList createUnkeyed(final String name) {
+ return new UnkeyedListBuilder().setName(name).setValue(createValue(name)).build();
+ }
+
+ private static String createValue(final String name) {
+ return name + "-" + name.hashCode();
+ }
+
+ private static void assertedCommit(final DataModificationTransaction tx) throws InterruptedException, ExecutionException {
+ RpcResult<TransactionStatus> result = tx.commit().get();
+ assertTrue(result.isSuccessful());
+ assertEquals(TransactionStatus.COMMITED,result.getResult());
+ }
+
+ @SuppressWarnings("deprecation")
+ private void assertXmlRepresentation(final InstanceIdentifier<?> containerPath, final String... childNameValues) {
+
+ org.opendaylight.yangtools.yang.data.api.InstanceIdentifier domPath = testContext.getBindingToDomMappingService().toDataDom(containerPath);
+ CompositeNode compositeNode = testContext.getDomDataBroker().readOperationalData(domPath);
+ assertNotNull(compositeNode);
+
+ Set<String> childValues = new HashSet<>();
+ Collections.addAll(childValues, childNameValues);
+
+ for(Node<?> child : compositeNode.getChildren()) {
+ assertTrue(child instanceof CompositeNode);
+ CompositeNode compChild = (CompositeNode) child;
+ String nameLeafValue = (String) compChild.getSimpleNodesByName("name").get(0).getValue();
+ String valueLeafValue = (String) compChild.getSimpleNodesByName("value").get(0).getValue();
+
+ assertEquals(createValue(nameLeafValue), valueLeafValue);
+ childValues.remove(nameLeafValue);
+ }
+ assertTrue(childValues.isEmpty());
+ }
+
+}
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeExperimenterErrorNotification;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowListener;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SwitchFlowRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.binding.NotificationListener;
import org.opendaylight.yangtools.yang.binding.RpcService;
*
*/
assertEquals(1, listener1.addedFlows.size());
- assertEquals(0, listener1.addedFlows.get(0).getCookie().intValue());
+ assertEquals(0, listener1.addedFlows.get(0).getCookie().getValue().intValue());
/**
* The registration of the Consumer 2. SalFlowListener is registered
*/
public static FlowAdded flowAdded(int i) {
FlowAddedBuilder ret = new FlowAddedBuilder();
- ret.setCookie(BigInteger.valueOf(i));
+ ret.setCookie(new FlowCookie(BigInteger.valueOf(i)));
return ret.build();
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
static AddFlowInput createSampleAddFlow(NodeRef node, int cookie) {
AddFlowInputBuilder ret = new AddFlowInputBuilder();
ret.setNode(node);
- ret.setCookie(BigInteger.valueOf(cookie));
+ ret.setCookie(new FlowCookie(BigInteger.valueOf(cookie)));
return ret.build();
}
}
import org.opendaylight.yangtools.yang.data.api.SimpleNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
@Override
public NormalizedNode<?, ?> createDefault(final PathArgument currentArg) {
- // TODO Auto-generated method stub
return null;
}
}
}
- private static abstract class CompositeNodeNormalizationOpertation<T extends PathArgument> extends
+ private static abstract class CompositeNodeNormalizationOperation<T extends PathArgument> extends
DataNormalizationOperation<T> {
- protected CompositeNodeNormalizationOpertation(final T identifier) {
+ protected CompositeNodeNormalizationOperation(final T identifier) {
super(identifier);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
- public final NormalizedNodeContainer<?, ?, ?> normalize(final Node<?> legacyData) {
+ public final NormalizedNode<?, ?> normalize(final Node<?> legacyData) {
checkArgument(legacyData != null);
if (!isMixin() && getIdentifier().getNodeType() != null) {
checkArgument(getIdentifier().getNodeType().equals(legacyData.getNodeType()),
builder.addChild(childOp.normalize(childLegacy));
}
}
- return (NormalizedNodeContainer<?, ?, ?>) builder.build();
+ return builder.build();
}
@SuppressWarnings("rawtypes")
}
private static abstract class DataContainerNormalizationOperation<T extends PathArgument> extends
- CompositeNodeNormalizationOpertation<T> {
+ CompositeNodeNormalizationOperation<T> {
private final DataNodeContainer schema;
private final Map<QName, DataNormalizationOperation<?>> byQName;
}
}
+ private static final class UnkeyedListItemNormalization extends DataContainerNormalizationOperation<NodeIdentifier> {
+
+ protected UnkeyedListItemNormalization(final ListSchemaNode schema) {
+ super(new NodeIdentifier(schema.getQName()), schema);
+ }
+
+ @Override
+ protected NormalizedNodeContainerBuilder createBuilder(final CompositeNode compositeNode) {
+ return Builders.unkeyedListEntryBuilder().withNodeIdentifier(getIdentifier());
+ }
+
+ @Override
+ public NormalizedNode<?, ?> createDefault(final PathArgument currentArg) {
+ return Builders.unkeyedListEntryBuilder().withNodeIdentifier((NodeIdentifier) currentArg).build();
+ }
+
+ }
+
private static final class ContainerNormalization extends DataContainerNormalizationOperation<NodeIdentifier> {
protected ContainerNormalization(final ContainerSchemaNode schema) {
}
private static abstract class MixinNormalizationOp<T extends PathArgument> extends
- CompositeNodeNormalizationOpertation<T> {
+ CompositeNodeNormalizationOperation<T> {
protected MixinNormalizationOp(final T identifier) {
super(identifier);
}
- private static final class LeafListMixinNormalization extends MixinNormalizationOp<NodeIdentifier> {
+
+ private static final class OrderedLeafListMixinNormalization extends UnorderedLeafListMixinNormalization {
+
+
+ public OrderedLeafListMixinNormalization(final LeafListSchemaNode potential) {
+ super(potential);
+ }
+
+ @Override
+ protected NormalizedNodeContainerBuilder createBuilder(final CompositeNode compositeNode) {
+ return Builders.orderedLeafSetBuilder().withNodeIdentifier(getIdentifier());
+ }
+
+ @Override
+ public NormalizedNode<?, ?> createDefault(final PathArgument currentArg) {
+ return Builders.orderedLeafSetBuilder().withNodeIdentifier(getIdentifier()).build();
+ }
+ }
+
+ private static class UnorderedLeafListMixinNormalization extends MixinNormalizationOp<NodeIdentifier> {
private final DataNormalizationOperation<?> innerOp;
- public LeafListMixinNormalization(final LeafListSchemaNode potential) {
+ public UnorderedLeafListMixinNormalization(final LeafListSchemaNode potential) {
super(new NodeIdentifier(potential.getQName()));
innerOp = new LeafListEntryNormalization(potential);
}
}
- private static final class ListMixinNormalization extends MixinNormalizationOp<NodeIdentifier> {
+ private static class UnorderedMapMixinNormalization extends MixinNormalizationOp<NodeIdentifier> {
private final ListItemNormalization innerNode;
- public ListMixinNormalization(final ListSchemaNode list) {
+ public UnorderedMapMixinNormalization(final ListSchemaNode list) {
super(new NodeIdentifier(list.getQName()));
this.innerNode = new ListItemNormalization(new NodeIdentifierWithPredicates(list.getQName(),
Collections.<QName, Object> emptyMap()), list);
}
+
+ private static class UnkeyedListMixinNormalization extends MixinNormalizationOp<NodeIdentifier> {
+
+ private final UnkeyedListItemNormalization innerNode;
+
+ public UnkeyedListMixinNormalization(final ListSchemaNode list) {
+ super(new NodeIdentifier(list.getQName()));
+ this.innerNode = new UnkeyedListItemNormalization(list);
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ protected NormalizedNodeContainerBuilder createBuilder(final CompositeNode compositeNode) {
+ return Builders.unkeyedListBuilder().withNodeIdentifier(getIdentifier());
+ }
+
+ @Override
+ public NormalizedNode<?, ?> createDefault(final PathArgument currentArg) {
+ return Builders.unkeyedListBuilder().withNodeIdentifier(getIdentifier()).build();
+ }
+
+ @Override
+ public DataNormalizationOperation<?> getChild(final PathArgument child) {
+ if (child.getNodeType().equals(getIdentifier().getNodeType())) {
+ return innerNode;
+ }
+ return null;
+ }
+
+ @Override
+ public DataNormalizationOperation<?> getChild(final QName child) {
+ if (getIdentifier().getNodeType().equals(child)) {
+ return innerNode;
+ }
+ return null;
+ }
+
+ }
+
+ private static final class OrderedMapMixinNormalization extends UnorderedMapMixinNormalization {
+
+ public OrderedMapMixinNormalization(final ListSchemaNode list) {
+ super(list);
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ protected NormalizedNodeContainerBuilder createBuilder(final CompositeNode compositeNode) {
+ return Builders.orderedMapBuilder().withNodeIdentifier(getIdentifier());
+ }
+
+ @Override
+ public NormalizedNode<?, ?> createDefault(final PathArgument currentArg) {
+ return Builders.orderedMapBuilder().withNodeIdentifier(getIdentifier()).build();
+ }
+
+ }
+
private static class ChoiceNodeNormalization extends MixinNormalizationOp<NodeIdentifier> {
private final ImmutableMap<QName, DataNormalizationOperation<?>> byQName;
if (potential instanceof ContainerSchemaNode) {
return new ContainerNormalization((ContainerSchemaNode) potential);
} else if (potential instanceof ListSchemaNode) {
- return new ListMixinNormalization((ListSchemaNode) potential);
+
+ return fromListSchemaNode((ListSchemaNode) potential);
} else if (potential instanceof LeafSchemaNode) {
return new LeafNormalization(new NodeIdentifier(potential.getQName()));
} else if (potential instanceof org.opendaylight.yangtools.yang.model.api.ChoiceNode) {
return new ChoiceNodeNormalization((org.opendaylight.yangtools.yang.model.api.ChoiceNode) potential);
} else if (potential instanceof LeafListSchemaNode) {
- return new LeafListMixinNormalization((LeafListSchemaNode) potential);
+ return fromLeafListSchemaNode((LeafListSchemaNode) potential);
}
return null;
}
+ private static DataNormalizationOperation<?> fromListSchemaNode(final ListSchemaNode potential) {
+ List<QName> keyDefinition = potential.getKeyDefinition();
+ if(keyDefinition == null || keyDefinition.isEmpty()) {
+ return new UnkeyedListMixinNormalization(potential);
+ }
+ if(potential.isUserOrdered()) {
+ return new OrderedMapMixinNormalization(potential);
+ }
+ return new UnorderedMapMixinNormalization(potential);
+ }
+
+ private static DataNormalizationOperation<?> fromLeafListSchemaNode(final LeafListSchemaNode potential) {
+ if(potential.isUserOrdered()) {
+ return new OrderedLeafListMixinNormalization(potential);
+ }
+ return new UnorderedLeafListMixinNormalization(potential);
+ }
+
+
public static DataNormalizationOperation<?> from(final SchemaContext ctx) {
return new ContainerNormalization(ctx);
}
import org.opendaylight.yangtools.yang.data.api.schema.MixinNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
+import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode;
import org.opendaylight.yangtools.yang.data.impl.SimpleNodeTOImpl;
import org.opendaylight.yangtools.yang.data.impl.util.CompositeNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import com.google.common.base.Preconditions;
-import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
for (NormalizedNode<?, ?> child : node.getValue()) {
if (child instanceof MixinNode && child instanceof NormalizedNodeContainer<?, ?, ?>) {
builder.addAll(toLegacyNodesFromMixin((NormalizedNodeContainer) child));
+ } else if( child instanceof UnkeyedListNode) {
+ builder.addAll(toLegacyNodesFromUnkeyedList((UnkeyedListNode) child));
} else {
addToBuilder(builder, toLegacy(child));
}
return builder.toInstance();
}
+ private static Iterable<? extends Node<?>> toLegacyNodesFromUnkeyedList(final UnkeyedListNode mixin) {
+ ArrayList<Node<?>> ret = new ArrayList<>();
+ for (NormalizedNode<?, ?> child : mixin.getValue()) {
+ ret.add(toLegacy(child));
+ }
+ return FluentIterable.from(ret).filter(Predicates.notNull());
+ }
+
private static void addToBuilder(final CompositeNodeBuilder<ImmutableCompositeNode> builder, final Node<?> legacy) {
if (legacy != null) {
builder.add(legacy);
ret.add(toLegacy(child));
}
}
- return FluentIterable.from(ret).filter(new Predicate<Node<?>>() {
-
- @Override
- public boolean apply(final Node<?> input) {
- return input != null;
- }
- });
+ return FluentIterable.from(ret).filter(Predicates.notNull());
}
public DataNormalizationOperation<?> getRootOperation() {
import static com.google.common.base.Preconditions.checkArgument;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import org.opendaylight.controller.md.sal.dom.store.impl.tree.NodeModification;
import org.opendaylight.controller.md.sal.dom.store.impl.tree.StoreMetadataNode;
import org.opendaylight.controller.md.sal.dom.store.impl.tree.StoreNodeCompositeBuilder;
+import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifierWithPredicates;
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.NormalizedNodeContainer;
+import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedMapNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListEntryNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
import org.opendaylight.yangtools.yang.model.api.AugmentationTarget;
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
if (schemaNode instanceof ContainerSchemaNode) {
return new ContainerModificationStrategy((ContainerSchemaNode) schemaNode);
} else if (schemaNode instanceof ListSchemaNode) {
- return new ListMapModificationStrategy((ListSchemaNode) schemaNode);
+ return fromListSchemaNode((ListSchemaNode) schemaNode);
} else if (schemaNode instanceof ChoiceNode) {
return new ChoiceModificationStrategy((ChoiceNode) schemaNode);
} else if (schemaNode instanceof LeafListSchemaNode) {
throw new IllegalArgumentException("Not supported schema node type for " + schemaNode.getClass());
}
+ private static SchemaAwareApplyOperation fromListSchemaNode(final ListSchemaNode schemaNode) {
+ List<QName> keyDefinition = schemaNode.getKeyDefinition();
+ if (keyDefinition == null || keyDefinition.isEmpty()) {
+ return new UnkeyedListModificationStrategy(schemaNode);
+ }
+ if (schemaNode.isUserOrdered()) {
+ return new OrderedMapModificationStrategy(schemaNode);
+ }
+
+ return new UnorderedMapModificationStrategy(schemaNode);
+ }
+
public static SchemaAwareApplyOperation from(final DataNodeContainer resolvedTree,
final AugmentationTarget augSchemas, final AugmentationIdentifier identifier) {
AugmentationSchema augSchema = null;
- allAugments : for (AugmentationSchema potential : augSchemas.getAvailableAugmentations()) {
+ allAugments: for (AugmentationSchema potential : augSchemas.getAvailableAugmentations()) {
boolean containsAll = true;
- for(DataSchemaNode child : potential.getChildNodes()) {
- if(identifier.getPossibleChildNames().contains(child.getQName())) {
+ for (DataSchemaNode child : potential.getChildNodes()) {
+ if (identifier.getPossibleChildNames().contains(child.getQName())) {
augSchema = potential;
break allAugments;
}
}
}
- if(augSchema != null) {
- return new AugmentationModificationStrategy(augSchema,resolvedTree);
+ if (augSchema != null) {
+ return new AugmentationModificationStrategy(augSchema, resolvedTree);
}
return null;
}
-
-
protected final ModificationApplyOperation resolveChildOperation(final PathArgument child) {
Optional<ModificationApplyOperation> potential = getChild(child);
checkArgument(potential.isPresent(), "Operation for child %s is not defined.", child);
switch (modification.getModificationType()) {
case DELETE:
- return modification.storeSnapshot(Optional.<StoreMetadataNode>absent());
+ return modification.storeSnapshot(Optional.<StoreMetadataNode> absent());
case SUBTREE_MODIFIED:
- Preconditions.checkArgument(currentMeta.isPresent(),"Metadata not available for modification",modification);
- return modification.storeSnapshot(Optional.of(applySubtreeChange(modification, currentMeta.get(), subtreeVersion)));
+ Preconditions.checkArgument(currentMeta.isPresent(), "Metadata not available for modification",
+ modification);
+ return modification.storeSnapshot(Optional.of(applySubtreeChange(modification, currentMeta.get(),
+ subtreeVersion)));
case WRITE:
return modification.storeSnapshot(Optional.of(applyWrite(modification, currentMeta, subtreeVersion)));
case UNMODIFIED:
NormalizedNodeContainerModificationStrategy {
private final T schema;
- private final LoadingCache<PathArgument, ModificationApplyOperation> childCache = CacheBuilder.newBuilder().build(
- CacheLoader.from(new Function<PathArgument, ModificationApplyOperation>() {
+ private final LoadingCache<PathArgument, ModificationApplyOperation> childCache = CacheBuilder.newBuilder()
+ .build(CacheLoader.from(new Function<PathArgument, ModificationApplyOperation>() {
@Override
public ModificationApplyOperation apply(final PathArgument identifier) {
}
+ public static class UnkeyedListItemModificationStrategy extends
+ DataNodeContainerModificationStrategy<ListSchemaNode> {
+
+ public UnkeyedListItemModificationStrategy(final ListSchemaNode schemaNode) {
+ super(schemaNode, UnkeyedListEntryNode.class);
+ }
+
+ @Override
+ @SuppressWarnings("rawtypes")
+ protected DataContainerNodeBuilder createBuilder(final PathArgument identifier) {
+ checkArgument(identifier instanceof NodeIdentifier);
+ return ImmutableUnkeyedListEntryNodeBuilder.create().withNodeIdentifier((NodeIdentifier) identifier);
+ }
+
+ }
+
public static class AugmentationModificationStrategy extends
DataNodeContainerModificationStrategy<AugmentationSchema> {
}
-
@Override
protected DataContainerNodeBuilder createBuilder(final PathArgument identifier) {
return Builders.augmentationBuilder().withNodeIdentifier((AugmentationIdentifier) identifier);
public static class ChoiceModificationStrategy extends NormalizedNodeContainerModificationStrategy {
private final ChoiceNode schema;
- private final Map<PathArgument,ModificationApplyOperation> childNodes;
+ private final Map<PathArgument, ModificationApplyOperation> childNodes;
public ChoiceModificationStrategy(final ChoiceNode schemaNode) {
super(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode.class);
this.schema = schemaNode;
ImmutableMap.Builder<PathArgument, ModificationApplyOperation> child = ImmutableMap.builder();
- for(ChoiceCaseNode caze : schemaNode.getCases()) {
- for(DataSchemaNode cazeChild : caze.getChildNodes()) {
+ for (ChoiceCaseNode caze : schemaNode.getCases()) {
+ for (DataSchemaNode cazeChild : caze.getChildNodes()) {
SchemaAwareApplyOperation childNode = from(cazeChild);
- child.put(new NodeIdentifier(cazeChild.getQName()),childNode);
+ child.put(new NodeIdentifier(cazeChild.getQName()), childNode);
}
}
childNodes = child.build();
}
- public static class ListMapModificationStrategy extends NormalizedNodeContainerModificationStrategy {
+ public static class UnkeyedListModificationStrategy extends SchemaAwareApplyOperation {
+
+ private final Optional<ModificationApplyOperation> entryStrategy;
+
+ protected UnkeyedListModificationStrategy(final ListSchemaNode schema) {
+ entryStrategy = Optional.<ModificationApplyOperation> of(new UnkeyedListItemModificationStrategy(schema));
+ }
+
+
+
+ @Override
+ protected StoreMetadataNode applySubtreeChange(final NodeModification modification,
+ final StoreMetadataNode currentMeta, final UnsignedLong subtreeVersion) {
+ throw new UnsupportedOperationException("UnkeyedList does not support subtree change.");
+ }
+
+ @Override
+ protected StoreMetadataNode applyWrite(final NodeModification modification,
+ final Optional<StoreMetadataNode> currentMeta, final UnsignedLong subtreeVersion) {
+ return StoreMetadataNode.createRecursively(modification.getWritenValue(), subtreeVersion);
+ }
+
+ @Override
+ public Optional<ModificationApplyOperation> getChild(final PathArgument child) {
+ if (child instanceof NodeIdentifier) {
+ return entryStrategy;
+ }
+ return Optional.absent();
+ }
+
+ @Override
+ protected void verifyWritenStructure(final NormalizedNode<?, ?> writenValue) {
+
+ }
+
+ @Override
+ protected boolean isSubtreeModificationApplicable(final NodeModification modification,
+ final Optional<StoreMetadataNode> current) {
+ return false;
+ }
+
+ }
+
+ public static class UnorderedMapModificationStrategy extends NormalizedNodeContainerModificationStrategy {
private final Optional<ModificationApplyOperation> entryStrategy;
- protected ListMapModificationStrategy(final ListSchemaNode schema) {
+ protected UnorderedMapModificationStrategy(final ListSchemaNode schema) {
super(MapNode.class);
entryStrategy = Optional.<ModificationApplyOperation> of(new ListEntryModificationStrategy(schema));
}
@Override
public String toString() {
- return "ListMapModificationStrategy [entry=" + entryStrategy + "]";
+ return "UnorderedMapModificationStrategy [entry=" + entryStrategy + "]";
+ }
+ }
+
+ public static class OrderedMapModificationStrategy extends NormalizedNodeContainerModificationStrategy {
+
+ private final Optional<ModificationApplyOperation> entryStrategy;
+
+ protected OrderedMapModificationStrategy(final ListSchemaNode schema) {
+ super(OrderedMapNode.class);
+ entryStrategy = Optional.<ModificationApplyOperation> of(new ListEntryModificationStrategy(schema));
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ protected NormalizedNodeContainerBuilder createBuilder(final PathArgument identifier) {
+ return ImmutableOrderedMapNodeBuilder.create().withNodeIdentifier((NodeIdentifier) identifier);
+ }
+
+ @Override
+ public Optional<ModificationApplyOperation> getChild(final PathArgument identifier) {
+ if (identifier instanceof NodeIdentifierWithPredicates) {
+ return entryStrategy;
+ }
+ return Optional.absent();
+ }
+
+ @Override
+ public String toString() {
+ return "OrderedMapModificationStrategy [entry=" + entryStrategy + "]";
}
}
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
+
import org.opendaylight.controller.sample.l2switch.md.topology.NetworkGraphService;
import org.opendaylight.controller.sample.l2switch.md.util.InstanceIdentifierUtils;
import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
.setBufferId(0L) //
.setHardTimeout(0) //
.setIdleTimeout(0) //
- .setCookie(BigInteger.valueOf(flowCookieInc.getAndIncrement()))
+ .setCookie(new FlowCookie(BigInteger.valueOf(flowCookieInc.getAndIncrement())))
.setFlags(new FlowModFlags(false, false, false, false, false));
return macToMacFlow.build();
return;
}
HostNodeConnector destHost = hostTracker.hostFind(dIP);
+ /*
+ * In cases when incoming and outgoing connectors are in the same node, there is no need
+ * to verify that there is a route. Because of that, we will only need routing.getRoute()
+ * if we know that src and dst nodes are different.
+ */
if (destHost != null
- && (routing == null ||
+ && (incomingNodeConnector.getNode().equals(destHost.getnodeconnectorNode()) ||
+ routing == null ||
routing.getRoute(incomingNodeConnector.getNode(), destHost.getnodeconnectorNode()) != null)) {
log.trace("Host {} is at {}", dIP, destHost.getnodeConnector());
- HostNodePair key = new HostNodePair(destHost, incomingNodeConnector.getNode());
+ HostNodePair key = new HostNodePair(destHost, destHost.getnodeconnectorNode());
// If SimpleForwarding is aware of this host, it will try to install
// a path. Forward packet until it's done.