BUG-2304 Fix leafref/instanceIdentifier processing in restconf -> netconf pipeline 24/12524/11
authorMaros Marsalek <mmarsale@cisco.com>
Wed, 5 Nov 2014 15:46:01 +0000 (16:46 +0100)
committerMaros Marsalek <mmarsale@cisco.com>
Wed, 19 Nov 2014 14:48:26 +0000 (14:48 +0000)
Resolve the leafref type based on type being referenced by the xpath.
Fix tests testing wrong instance identifier behavior
Fix subtree filtering in netconf northbound when identityrefs are involved

Change-Id: I561e0c92550dd6639a9f9fbd1909695041c378e4
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
18 files changed:
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/schema/mapping/NetconfMessageTransformer.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestCodec.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonLeafrefType.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/json/to/cnsn/test/JsonLeafrefToCnSnTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/XmlAndJsonToCnSnLeafRefTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/xml/to/cnsn/test/XmlToCnSnTest.java
opendaylight/md-sal/sal-rest-connector/src/test/resources/cnsn-to-json/leafref/cont-augment-module.yang
opendaylight/md-sal/sal-rest-connector/src/test/resources/cnsn-to-json/leafref/xml/data_ref_to_not_leaf.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/leafref/json/jsondata.json
opendaylight/md-sal/sal-rest-connector/src/test/resources/leafref/xml/xmldata.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/xml-to-cnsn/leafref/leafref-module
opendaylight/md-sal/sal-rest-connector/src/test/resources/xml-to-cnsn/leafref/xml/data.xml
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/SubtreeFilter.java
opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/SubtreeFilterTest.java
opendaylight/netconf/netconf-impl/src/test/resources/subtree/10/post-filter.xml [new file with mode: 0644]
opendaylight/netconf/netconf-impl/src/test/resources/subtree/10/pre-filter.xml [new file with mode: 0644]
opendaylight/netconf/netconf-impl/src/test/resources/subtree/10/request.xml [new file with mode: 0644]

index 02819c15c78b4408c91ff56a725e013017a0b55b..2971865a70fb50f65e7c032295bf5bf5963a33df 100644 (file)
@@ -67,18 +67,18 @@ public class NetconfMessageTransformer implements MessageTransformer<NetconfMess
             if(schemaContext.isPresent()) {
                 if (NetconfMessageTransformUtil.isDataEditOperation(rpc)) {
                     final DataNodeContainer schemaForEdit = NetconfMessageTransformUtil.createSchemaForEdit(schemaContext.get());
             if(schemaContext.isPresent()) {
                 if (NetconfMessageTransformUtil.isDataEditOperation(rpc)) {
                     final DataNodeContainer schemaForEdit = NetconfMessageTransformUtil.createSchemaForEdit(schemaContext.get());
-                    w3cPayload = XmlDocumentUtils.toDocument(rpcPayload, schemaForEdit, codecProvider);
+                    w3cPayload = XmlDocumentUtils.toDocument(rpcPayload, schemaContext.get(), schemaForEdit, codecProvider);
                 } else if (NetconfMessageTransformUtil.isGetOperation(rpc)) {
                     final DataNodeContainer schemaForGet = NetconfMessageTransformUtil.createSchemaForGet(schemaContext.get());
                 } else if (NetconfMessageTransformUtil.isGetOperation(rpc)) {
                     final DataNodeContainer schemaForGet = NetconfMessageTransformUtil.createSchemaForGet(schemaContext.get());
-                    w3cPayload = XmlDocumentUtils.toDocument(rpcPayload, schemaForGet, codecProvider);
+                    w3cPayload = XmlDocumentUtils.toDocument(rpcPayload, schemaContext.get(), schemaForGet, codecProvider);
                 } else if (NetconfMessageTransformUtil.isGetConfigOperation(rpc)) {
                     final DataNodeContainer schemaForGetConfig = NetconfMessageTransformUtil.createSchemaForGetConfig(schemaContext.get());
                 } else if (NetconfMessageTransformUtil.isGetConfigOperation(rpc)) {
                     final DataNodeContainer schemaForGetConfig = NetconfMessageTransformUtil.createSchemaForGetConfig(schemaContext.get());
-                    w3cPayload = XmlDocumentUtils.toDocument(rpcPayload, schemaForGetConfig, codecProvider);
+                    w3cPayload = XmlDocumentUtils.toDocument(rpcPayload, schemaContext.get(), schemaForGetConfig, codecProvider);
                 } else {
                     final Optional<RpcDefinition> schemaForRpc = NetconfMessageTransformUtil.findSchemaForRpc(rpc, schemaContext.get());
                     if(schemaForRpc.isPresent()) {
                         final DataNodeContainer schemaForGetConfig = NetconfMessageTransformUtil.createSchemaForRpc(schemaForRpc.get());
                 } else {
                     final Optional<RpcDefinition> schemaForRpc = NetconfMessageTransformUtil.findSchemaForRpc(rpc, schemaContext.get());
                     if(schemaForRpc.isPresent()) {
                         final DataNodeContainer schemaForGetConfig = NetconfMessageTransformUtil.createSchemaForRpc(schemaForRpc.get());
-                        w3cPayload = XmlDocumentUtils.toDocument(rpcPayload, schemaForGetConfig, codecProvider);
+                        w3cPayload = XmlDocumentUtils.toDocument(rpcPayload, schemaContext.get(), schemaForGetConfig, codecProvider);
                     } else {
                         w3cPayload = toRpcRequestWithoutSchema(rpcPayload, codecProvider);
                     }
                     } else {
                         w3cPayload = toRpcRequestWithoutSchema(rpcPayload, codecProvider);
                     }
index 665fafacc893b7b05235daaa34f8e709d6f2702f..ceac03e3d97eccabca05633652179ce1bb3acb1c 100644 (file)
@@ -88,11 +88,6 @@ public class RestCodec {
                             "Value is not instance of IdentityrefTypeDefinition but is {}. Therefore NULL is used as translation of  - {}",
                             input == null ? "null" : input.getClass(), String.valueOf(input));
                     return null;
                             "Value is not instance of IdentityrefTypeDefinition but is {}. Therefore NULL is used as translation of  - {}",
                             input == null ? "null" : input.getClass(), String.valueOf(input));
                     return null;
-                } else if (type instanceof LeafrefTypeDefinition) {
-                    if (input instanceof IdentityValuesDTO) {
-                        return LEAFREF_DEFAULT_CODEC.deserialize(((IdentityValuesDTO) input).getOriginValue());
-                    }
-                    return LEAFREF_DEFAULT_CODEC.deserialize(input);
                 } else if (type instanceof InstanceIdentifierTypeDefinition) {
                     if (input instanceof IdentityValuesDTO) {
                         return instanceIdentifier.deserialize(input);
                 } else if (type instanceof InstanceIdentifierTypeDefinition) {
                     if (input instanceof IdentityValuesDTO) {
                         return instanceIdentifier.deserialize(input);
@@ -232,7 +227,7 @@ public class RestCodec {
             IdentityValue valueWithNamespace = data.getValuesWithNamespaces().get(0);
             Module module = getModuleByNamespace(valueWithNamespace.getNamespace(), mountPoint);
             if (module == null) {
             IdentityValue valueWithNamespace = data.getValuesWithNamespaces().get(0);
             Module module = getModuleByNamespace(valueWithNamespace.getNamespace(), mountPoint);
             if (module == null) {
-                logger.info("Module by namespace '{}' of first node in instance-identiefier was not found.",
+                logger.info("Module by namespace '{}' of first node in instance-identifier was not found.",
                         valueWithNamespace.getNamespace());
                 logger.info("Instance-identifier will be translated as NULL for data - {}",
                         String.valueOf(valueWithNamespace.getValue()));
                         valueWithNamespace.getNamespace());
                 logger.info("Instance-identifier will be translated as NULL for data - {}",
                         String.valueOf(valueWithNamespace.getValue()));
index cd860efab75073e13cf0cd2cfd93e12fd7200a5e..ded398a33d0f0390beab6f8e723412182a8172ce 100644 (file)
@@ -84,7 +84,9 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
 import org.opendaylight.yangtools.yang.model.util.EmptyType;
 import org.opendaylight.yangtools.yang.model.util.EmptyType;
+import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
 import org.opendaylight.yangtools.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder;
 import org.slf4j.Logger;
 import org.opendaylight.yangtools.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder;
 import org.slf4j.Logger;
@@ -1241,7 +1243,9 @@ public class RestconfImpl implements RestconfService {
                 try {
                     this.normalizeNode(nodeWrap, schema, null, mountPoint);
                 } catch (IllegalArgumentException e) {
                 try {
                     this.normalizeNode(nodeWrap, schema, null, mountPoint);
                 } catch (IllegalArgumentException e) {
-                    throw new RestconfDocumentedException(e.getMessage(), ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
+                    RestconfDocumentedException restconfDocumentedException = new RestconfDocumentedException(e.getMessage(), ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
+                    restconfDocumentedException.addSuppressed(e);
+                    throw restconfDocumentedException;
                 }
                 if (nodeWrap instanceof CompositeNodeWrapper) {
                     return ((CompositeNodeWrapper) nodeWrap).unwrap();
                 }
                 if (nodeWrap instanceof CompositeNodeWrapper) {
                     return ((CompositeNodeWrapper) nodeWrap).unwrap();
@@ -1319,11 +1323,14 @@ public class RestconfImpl implements RestconfService {
         final Object value = simpleNode.getValue();
         Object inputValue = value;
         TypeDefinition<? extends Object> typeDefinition = this.typeDefinition(schema);
         final Object value = simpleNode.getValue();
         Object inputValue = value;
         TypeDefinition<? extends Object> typeDefinition = this.typeDefinition(schema);
-        if ((typeDefinition instanceof IdentityrefTypeDefinition)) {
-            if ((value instanceof String)) {
-                inputValue = new IdentityValuesDTO(simpleNode.getNamespace().toString(), (String) value, null,
-                        (String) value);
-            } // else value is already instance of IdentityValuesDTO
+
+        // For leafrefs, extract the type it is pointing to
+        if(typeDefinition instanceof LeafrefTypeDefinition) {
+            typeDefinition = SchemaContextUtil.getBaseTypeForLeafRef(((LeafrefTypeDefinition) typeDefinition), mountPoint == null ? this.controllerContext.getGlobalSchema() : mountPoint.getSchemaContext(), schema);
+        }
+
+        if (typeDefinition instanceof IdentityrefTypeDefinition) {
+            inputValue = parseToIdentityValuesDTO(simpleNode, value, inputValue);
         }
 
         Object outputValue = inputValue;
         }
 
         Object outputValue = inputValue;
@@ -1336,6 +1343,14 @@ public class RestconfImpl implements RestconfService {
         simpleNode.setValue(outputValue);
     }
 
         simpleNode.setValue(outputValue);
     }
 
+    private Object parseToIdentityValuesDTO(final SimpleNodeWrapper simpleNode, final Object value, Object inputValue) {
+        if ((value instanceof String)) {
+            inputValue = new IdentityValuesDTO(simpleNode.getNamespace().toString(), (String) value, null,
+                    (String) value);
+        } // else value is already instance of IdentityValuesDTO
+        return inputValue;
+    }
+
     private void normalizeCompositeNode(final CompositeNodeWrapper compositeNodeBuilder,
             final DataNodeContainer schema, final DOMMountPoint mountPoint, final QName currentAugment) {
         final List<NodeWrapper<?>> children = compositeNodeBuilder.getValues();
     private void normalizeCompositeNode(final CompositeNodeWrapper compositeNodeBuilder,
             final DataNodeContainer schema, final DOMMountPoint mountPoint, final QName currentAugment) {
         final List<NodeWrapper<?>> children = compositeNodeBuilder.getValues();
index b5d3528e95857cd95c9956522bf633f99edc6763..fa79fb7677d264969a6473ef8dfcc5d37c317a32 100644 (file)
@@ -63,7 +63,7 @@ public class CnSnToJsonLeafrefType extends YangAndXmlAndDataSchemaLoader {
     @Test
     public void leafrefToNotLeafTest() {
         String json = toJson("/cnsn-to-json/leafref/xml/data_ref_to_not_leaf.xml");
     @Test
     public void leafrefToNotLeafTest() {
         String json = toJson("/cnsn-to-json/leafref/xml/data_ref_to_not_leaf.xml");
-        validateJson(".*\"cont-augment-module\\p{Blank}*:\\p{Blank}*lf6\":\\p{Blank}*\"44.33\".*", json);
+        validateJson(".*\"cont-augment-module\\p{Blank}*:\\p{Blank}*lf6\":\\p{Blank}*\"44\".*", json);
     }
 
     /**
     }
 
     /**
index 59696bc534803935ab5c0c0126d0a43fc2c75fa5..bdd74e8f9617a634235814304f21a3362eefeb6f 100644 (file)
@@ -51,9 +51,7 @@ public class JsonLeafrefToCnSnTest extends YangAndXmlAndDataSchemaLoader {
         }
 
         assertNotNull(lf2);
         }
 
         assertNotNull(lf2);
-        assertTrue(lf2.getValue() instanceof String);
-        assertEquals("121", lf2.getValue());
-
+        assertEquals(121, lf2.getValue());
     }
 
 }
     }
 
 }
index 1c8e53e69ff5091d9a9013947d09cb6381d5723a..7b216ef1ba54f276628349a534871f4694852c00 100644 (file)
@@ -12,17 +12,27 @@ import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
 import java.net.URISyntaxException;
 
 import java.io.IOException;
 import java.net.URISyntaxException;
+
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.WebApplicationException;
+
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider;
 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider;
 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.Node;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
 public class XmlAndJsonToCnSnLeafRefTest extends YangAndXmlAndDataSchemaLoader {
 
 
 public class XmlAndJsonToCnSnLeafRefTest extends YangAndXmlAndDataSchemaLoader {
 
+    final QName refContQName = QName.create("referenced:module", "2014-04-17", "cont");
+    final QName refLf1QName = QName.create(refContQName, "lf1");
+    final QName contQName = QName.create("leafref:module", "2014-04-17", "cont");
+    final QName lf1QName = QName.create(contQName, "lf1");
+    final QName lf2QName = QName.create(contQName, "lf2");
+    final QName lf3QName = QName.create(contQName, "lf3");
+
     @BeforeClass
     public static void initialize() {
         dataLoad("/leafref/yang", 2, "leafref-module", "cont");
     @BeforeClass
     public static void initialize() {
         dataLoad("/leafref/yang", 2, "leafref-module", "cont");
@@ -36,7 +46,11 @@ public class XmlAndJsonToCnSnLeafRefTest extends YangAndXmlAndDataSchemaLoader {
         CompositeNode cnSn = (CompositeNode)node;
 
         TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath);
         CompositeNode cnSn = (CompositeNode)node;
 
         TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath);
-        verifyContPredicate(cnSn, "/ns:cont/ns:lf1", "/cont/lf1", "/ns:cont/ns:lf1", "../lf1");
+
+        verifyContPredicate(cnSn, "lf4", YangInstanceIdentifier.builder().node(refContQName).node(refLf1QName).build());
+        verifyContPredicate(cnSn, "lf2", YangInstanceIdentifier.builder().node(contQName).node(lf1QName).build());
+        verifyContPredicate(cnSn, "lf3", YangInstanceIdentifier.builder().node(contQName).node(lf2QName).build());
+        verifyContPredicate(cnSn, "lf5", YangInstanceIdentifier.builder().node(contQName).node(lf3QName).build());
     }
 
     @Test
     }
 
     @Test
@@ -47,31 +61,23 @@ public class XmlAndJsonToCnSnLeafRefTest extends YangAndXmlAndDataSchemaLoader {
         CompositeNode cnSn = (CompositeNode)node;
 
         TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath);
         CompositeNode cnSn = (CompositeNode)node;
 
         TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath);
-        verifyContPredicate(cnSn, "/leafref-module:cont/leafref-module:lf1", "/leafref-module:cont/leafref-module:lf1",
-                "/referenced-module:cont/referenced-module:lf1", "/leafref-module:cont/leafref-module:lf1");
+
+        verifyContPredicate(cnSn, "lf4", YangInstanceIdentifier.builder().node(refContQName).node(refLf1QName).build());
+        verifyContPredicate(cnSn, "lf2", YangInstanceIdentifier.builder().node(contQName).node(lf1QName).build());
+        verifyContPredicate(cnSn, "lf3", YangInstanceIdentifier.builder().node(contQName).node(lf2QName).build());
+        verifyContPredicate(cnSn, "lf5", YangInstanceIdentifier.builder().node(contQName).node(lf3QName).build());
     }
 
     }
 
-    private void verifyContPredicate(CompositeNode cnSn, String... values) throws URISyntaxException {
-        Object lf2Value = null;
-        Object lf3Value = null;
-        Object lf4Value = null;
-        Object lf5Value = null;
-
-        for (Node<?> node : cnSn.getValue()) {
-            if (node.getNodeType().getLocalName().equals("lf2")) {
-                lf2Value = ((SimpleNode<?>) node).getValue();
-            } else if (node.getNodeType().getLocalName().equals("lf3")) {
-                lf3Value = ((SimpleNode<?>) node).getValue();
-            } else if (node.getNodeType().getLocalName().equals("lf4")) {
-                lf4Value = ((SimpleNode<?>) node).getValue();
-            } else if (node.getNodeType().getLocalName().equals("lf5")) {
-                lf5Value = ((SimpleNode<?>) node).getValue();
+    private void verifyContPredicate(CompositeNode cnSn, String leafName, Object value) throws URISyntaxException {
+        Object parsed = null;
+
+        for (final Node<?> node : cnSn.getValue()) {
+            if (node.getNodeType().getLocalName().equals(leafName)) {
+                parsed = node.getValue();
             }
         }
             }
         }
-        assertEquals(values[0], lf2Value);
-        assertEquals(values[1], lf3Value);
-        assertEquals(values[2], lf4Value);
-        assertEquals(values[3], lf5Value);
+
+        assertEquals(value, parsed);
     }
 
 }
     }
 
 }
index d0af29e913fa633381c176ff1796a2fbd3f41c29..64568da769cad13132806df5bb551edd51bcaf20 100644 (file)
@@ -54,8 +54,7 @@ public class XmlToCnSnTest extends YangAndXmlAndDataSchemaLoader {
         }
 
         assertNotNull(lf2);
         }
 
         assertNotNull(lf2);
-        assertTrue(lf2.getValue() instanceof String);
-        assertEquals("121", lf2.getValue());
+        assertEquals(121, lf2.getValue());
     }
 
     @Test
     }
 
     @Test
index afc23b7946cf93b4e73b4c1c31255986562db1da..27b2dae2434dc63e1fb464de0cb62ea88b9157cc 100644 (file)
@@ -1,42 +1,42 @@
 module cont-augment-module {
 module cont-augment-module {
-  namespace "cont:augment:module";  
+  namespace "cont:augment:module";
 
   prefix "cntaugmod";
 
   prefix "cntaugmod";
-  
+
   import main-module {prefix mamo; revision-date 2013-12-2;}
   import main-module {prefix mamo; revision-date 2013-12-2;}
-         
+
   revision 2013-12-2 {
   revision 2013-12-2 {
-  
+
   }
   }
-  
+
   augment "/mamo:cont" {
        leaf-list lflst1 {
                type leafref {
   augment "/mamo:cont" {
        leaf-list lflst1 {
                type leafref {
-                       path "../lf1";
+                       path "../mamo:lf1";
                }
                }
-       }       
-       
+       }
+
        leaf lf4 {
                type leafref {
        leaf lf4 {
                type leafref {
-                       path "../lf1";
+                       path "../mamo:lf1";
                }
        }
                }
        }
-       
+
        /* reference to not leaf element */
        leaf lf6 {
                type leafref {
                        path "../lflst1";
                }
        }
        /* reference to not leaf element */
        leaf lf6 {
                type leafref {
                        path "../lflst1";
                }
        }
-       
+
        leaf lf7 {
                type leafref {
                        path "../lf4";
                }
        }
   }
        leaf lf7 {
                type leafref {
                        path "../lf4";
                }
        }
   }
-       
 
 
-         
+
+
+
 }
\ No newline at end of file
 }
\ No newline at end of file
index 10632a44af44f682237b200f295de98a235927b9..b72d438c289831076bddf321c0b0bbf337cb7e3a 100644 (file)
@@ -1,3 +1,3 @@
 <cont>
 <cont>
-    <lf6>44.33</lf6>
+    <lf6>44</lf6>
 </cont>
\ No newline at end of file
 </cont>
\ No newline at end of file
index cbe455b33b09beaa3b152d76edaefff716e87dbe..f4a435e3bf6b94e8e70ff46d08adf2f9fa4456e6 100644 (file)
@@ -2,7 +2,7 @@
     "leafref-module:cont" : {
         "lf4" : "/referenced-module:cont/referenced-module:lf1",
         "lf2" : "/leafref-module:cont/leafref-module:lf1",
     "leafref-module:cont" : {
         "lf4" : "/referenced-module:cont/referenced-module:lf1",
         "lf2" : "/leafref-module:cont/leafref-module:lf1",
-        "lf3" : "/leafref-module:cont/leafref-module:lf1",
-        "lf5" : "/leafref-module:cont/leafref-module:lf1"
+        "lf3" : "/leafref-module:cont/leafref-module:lf2",
+        "lf5" : "/leafref-module:cont/leafref-module:lf3"
     }
 }
\ No newline at end of file
     }
 }
\ No newline at end of file
index 01bf092d27f005605def37d43dda00f2c4450e72..1b5ce835fc0e9a44e94311df8f6c9f9d65827922 100644 (file)
@@ -1,6 +1,6 @@
-<cont xmlns="leafref:module">
-    <lf4 xmlns:ns="referenced:module">/ns:cont/ns:lf1</lf4>
-    <lf2 xmlns:ns="leafref:module">/ns:cont/ns:lf1</lf2>
-    <lf3 xmlns:ns="leafref:module">/cont/lf1</lf3>
-    <lf5 xmlns:ns="leafref:module">../lf1</lf5>
+<cont xmlnsa="leafref:module">
+    <lf4 xmlns:nsa="referenced:module">/nsa:cont/nsa:lf1</lf4>
+    <lf2 xmlns:nsa="leafref:module">/nsa:cont/nsa:lf1</lf2>
+    <lf3 xmlns:ns="leafref:module">/ns:cont/ns:lf2</lf3>
+    <lf5 xmlns:nsa="leafref:module">/nsa:cont/nsa:lf3</lf5>
 </cont>
 </cont>
index 8ca9f090968fa8ed25d4f69b5243f011f1f709c5..6fe770b40baebc9bdef35be75504c0c731461e87 100644 (file)
@@ -1,19 +1,61 @@
 module leafref-module {
 module leafref-module {
-  namespace "leafref:module";  
+  namespace "leafref:module";
 
   prefix "lfrfmo";
 
   prefix "lfrfmo";
-  revision 2013-11-18 {    
+  revision 2013-11-18 {
   }
 
   }
 
+  identity base {}
+
     container cont {
         leaf lf1 {
             type int32;
         }
         leaf lf2 {
             type leafref {
     container cont {
         leaf lf1 {
             type int32;
         }
         leaf lf2 {
             type leafref {
-                path "/cont/lf1"; 
+                path "/cont/lf1";
+            }
+        }
+
+        leaf lf-ident {
+            type identityref {
+                base "lfrfmo:base";
             }
         }
             }
         }
+
+        leaf lf-ident-ref {
+            type leafref {
+                path "/cont/lf-ident";
+            }
+        }
+
+        leaf lf-ident-ref-relative {
+            type leafref {
+                path "../lf-ident";
+            }
+        }
+
+        leaf lf-ident-ref-relative-cnd {
+            type leafref {
+                path "/lfrfmo:cont/lfrfmo:lis[lfrfmo:id='abc']/lf-ident-ref";
+            }
+        }
+
+
+        list lis {
+            key "id";
+
+            leaf id {
+                type string;
+            }
+
+            leaf lf-ident-ref {
+                type leafref {
+                    path "/cont/lf-ident";
+                }
+            }
+        }
+
     }
     }
-  
+
 }
\ No newline at end of file
 }
\ No newline at end of file
index 06200a69b577088d98fe9252ee5252931e62672b..c3071e5610bcacbafe0863ccc6c5f34766661781 100644 (file)
@@ -1,4 +1,8 @@
 <cont>
     <lf1>121</lf1>
     <lf2>121</lf2>
 <cont>
     <lf1>121</lf1>
     <lf2>121</lf2>
+    <lf-ident xmlns:a="leafref:module">a:base</lf-ident>
+    <lf-ident-ref xmlns:a="leafref:module">a:base</lf-ident-ref>
+    <lf-ident-ref-relative xmlns:a="leafref:module">a:base</lf-ident-ref-relative>
+    <lf-ident-ref-relative-cnd xmlns:a="leafref:module">a:base</lf-ident-ref-relative-cnd>
 </cont>
\ No newline at end of file
 </cont>
\ No newline at end of file
index 42a8bae4484b93a3ed4689223cbf34a9aacbd986..8b2ca86010a06aa5c1b509bd617a08de72fd684a 100644 (file)
@@ -178,10 +178,10 @@ public class SubtreeFilter {
             return false;
         }
 
             return false;
         }
 
-        final String unprefixedFilterContent = filter.getTextContent().substring(prefix.length());
-        final String unprefixedSrcCOntnet = src.getTextContent().substring(prefix.length());
+        final String unprefixedFilterContent = filter.getTextContent().substring(prefixToNamespaceOfFilter.getKey().length() + 1);
+        final String unprefixedSrcContnet = src.getTextContent().substring(prefixToNamespaceOfSrc.getKey().length() + 1);
         // Finally compare unprefixed content
         // Finally compare unprefixed content
-        return unprefixedFilterContent.equals(unprefixedSrcCOntnet);
+        return unprefixedFilterContent.equals(unprefixedSrcContnet);
     }
 
     enum MatchingResult {
     }
 
     enum MatchingResult {
index 5d9470750e54053423b8bb871192fafedf9bf53b..51dfa4b1a8df3ed9a785c468ec38b8ddfc5136f7 100644 (file)
@@ -36,7 +36,7 @@ public class SubtreeFilterTest {
     @Parameters
     public static Collection<Object[]> data() {
         List<Object[]> result = new ArrayList<>();
     @Parameters
     public static Collection<Object[]> data() {
         List<Object[]> result = new ArrayList<>();
-        for (int i = 0; i <= 9; i++) {
+        for (int i = 0; i <= 10; i++) {
             result.add(new Object[]{i});
         }
         return result;
             result.add(new Object[]{i});
         }
         return result;
diff --git a/opendaylight/netconf/netconf-impl/src/test/resources/subtree/10/post-filter.xml b/opendaylight/netconf/netconf-impl/src/test/resources/subtree/10/post-filter.xml
new file mode 100644 (file)
index 0000000..3331cb8
--- /dev/null
@@ -0,0 +1,47 @@
+<!--
+  ~ 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
+  -->
+
+<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="m-10">
+    <data>
+        <modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
+            <module>
+                <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">prefix:sal-netconf-connector</type>
+                <name>controller-config</name>
+                <port xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">1830</port>
+                <connection-timeout-millis xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">20000</connection-timeout-millis>
+                <between-attempts-timeout-millis xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">2000</between-attempts-timeout-millis>
+                <sleep-factor xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">1.5</sleep-factor>
+                <password xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">admin</password>
+                <dom-registry xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
+                    <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom">prefix:dom-broker-osgi-registry</type>
+                    <name>dom-broker</name>
+                </dom-registry>
+                <client-dispatcher xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
+                    <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:config:netconf">prefix:netconf-client-dispatcher</type>
+                    <name>global-netconf-dispatcher</name>
+                </client-dispatcher>
+                <username xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">admin</username>
+                <address xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">127.0.0.1</address>
+                <processing-executor xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
+                    <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:threadpool">prefix:threadpool</type>
+                    <name>global-netconf-processing-executor</name>
+                </processing-executor>
+                <tcp-only xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">false</tcp-only>
+                <binding-registry xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
+                    <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">prefix:binding-broker-osgi-registry</type>
+                    <name>binding-osgi-broker</name>
+                </binding-registry>
+                <max-connection-attempts xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">0</max-connection-attempts>
+                <event-executor xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
+                    <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:netty">prefix:netty-event-executor</type>
+                    <name>global-event-executor</name>
+                </event-executor>
+            </module>
+        </modules>
+    </data>
+</rpc-reply>
\ No newline at end of file
diff --git a/opendaylight/netconf/netconf-impl/src/test/resources/subtree/10/pre-filter.xml b/opendaylight/netconf/netconf-impl/src/test/resources/subtree/10/pre-filter.xml
new file mode 100644 (file)
index 0000000..f2620bb
--- /dev/null
@@ -0,0 +1,52 @@
+<!--
+  ~ 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
+  -->
+
+<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="m-10">
+    <data>
+        <modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
+            <module>
+                <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">prefix:sal-netconf-connector</type>
+                <name>controller-config</name>
+                <port xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">1830</port>
+                <connection-timeout-millis xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">20000</connection-timeout-millis>
+                <between-attempts-timeout-millis xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">2000</between-attempts-timeout-millis>
+                <sleep-factor xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">1.5</sleep-factor>
+                <password xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">admin</password>
+                <dom-registry xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
+                    <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom">prefix:dom-broker-osgi-registry</type>
+                    <name>dom-broker</name>
+                </dom-registry>
+                <client-dispatcher xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
+                    <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:config:netconf">prefix:netconf-client-dispatcher</type>
+                    <name>global-netconf-dispatcher</name>
+                </client-dispatcher>
+                <username xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">admin</username>
+                <address xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">127.0.0.1</address>
+                <processing-executor xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
+                    <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:threadpool">prefix:threadpool</type>
+                    <name>global-netconf-processing-executor</name>
+                </processing-executor>
+                <tcp-only xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">false</tcp-only>
+                <binding-registry xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
+                    <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">prefix:binding-broker-osgi-registry</type>
+                    <name>binding-osgi-broker</name>
+                </binding-registry>
+                <max-connection-attempts xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">0</max-connection-attempts>
+                <event-executor xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
+                    <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:netty">prefix:netty-event-executor</type>
+                    <name>global-event-executor</name>
+                </event-executor>
+            </module>
+            <module>
+                <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:shutdown:impl">prefix:shutdown</type>
+                <name>shutdown</name>
+                <secret xmlns="urn:opendaylight:params:xml:ns:yang:controller:shutdown:impl"/>
+            </module>
+        </modules>
+    </data>
+</rpc-reply>
\ No newline at end of file
diff --git a/opendaylight/netconf/netconf-impl/src/test/resources/subtree/10/request.xml b/opendaylight/netconf/netconf-impl/src/test/resources/subtree/10/request.xml
new file mode 100644 (file)
index 0000000..259b123
--- /dev/null
@@ -0,0 +1,15 @@
+<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="m-9">
+    <get-config>
+        <source>
+            <running/>
+        </source>
+        <filter xmlns:a="urn:ietf:params:xml:ns:netconf:base:1.0" a:type="subtree">
+            <modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
+                <module>
+                    <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">x:sal-netconf-connector</type>
+                    <name>controller-config</name>
+                </module>
+            </modules>
+        </filter>
+    </get-config>
+</rpc>