introduced LocationResolver 57/38957/4
authorMatej Perina <matej.perina@pantheon.sk>
Wed, 18 May 2016 17:23:46 +0000 (19:23 +0200)
committerMatej Perina <matej.perina@pantheon.sk>
Wed, 18 May 2016 17:23:46 +0000 (19:23 +0200)
LocationResolver collects data from all location providers
and union them to EndpointLocations

Change-Id: I60308ba59ab0f17085f3a85ec7d99e2ee2b4307b
Signed-off-by: Matej Perina <matej.perina@pantheon.sk>
groupbasedpolicy/pom.xml
groupbasedpolicy/src/main/java/org/opendaylight/controller/config/yang/config/groupbasedpolicy/GroupbasedpolicyModule.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/location/resolver/LocationResolver.java [new file with mode: 0644]
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/util/IidFactory.java
groupbasedpolicy/src/main/yang/model/endpoint-location-provider.yang
groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/location/resolver/LocationResolverTest.java [new file with mode: 0644]
groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/util/IidFactoryTest.java
location-providers/ne-location-provider/src/main/java/org/opendaylight/groupbasedpolicy/ne/location/provider/NeLocationProvider.java

index d4db9198546f631fea2bbb3dbaef3207abe43a19..f18597d715214c85344b76deef436120cde2bb83 100755 (executable)
       <type>test-jar</type>
       <scope>test</scope>
     </dependency>
+    <dependency>
+        <groupId>org.opendaylight.controller.model</groupId>
+        <artifactId>model-inventory</artifactId>
+        <scope>test</scope>
+    </dependency>
   </dependencies>
 
 <!-- project build -->
index d8bb3b796b959419170d3150fed017bf9ee98357..779a5afe70ce34743c5df8d84cca00bad32ffcf5 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.controller.config.yang.config.groupbasedpolicy;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.groupbasedpolicy.api.PolicyValidatorRegistry;
+import org.opendaylight.groupbasedpolicy.location.resolver.LocationResolver;
 import org.opendaylight.groupbasedpolicy.sf.SubjectFeatureDefinitionProvider;
 import org.opendaylight.groupbasedpolicy.sf.SupportedActionDefinitionListener;
 import org.opendaylight.groupbasedpolicy.sf.SupportedClassifierDefinitionListener;
@@ -60,11 +61,13 @@ public class GroupbasedpolicyModule extends org.opendaylight.controller.config.y
         private final SubjectFeatureDefinitionProvider sfdp;
         private final SupportedClassifierDefinitionListener supportedClassifierDefinitionListener;
         private final SupportedActionDefinitionListener supportedActionDefinitionListener;
+        private final LocationResolver locationResolver;
 
         Instance(DataBroker dataProvider, PolicyValidatorRegistry validatorRegistry) throws TransactionCommitFailedException {
             sfdp = new SubjectFeatureDefinitionProvider(dataProvider);
             supportedClassifierDefinitionListener = new SupportedClassifierDefinitionListener(dataProvider, validatorRegistry);
             supportedActionDefinitionListener = new SupportedActionDefinitionListener(dataProvider);
+            locationResolver = new LocationResolver(dataProvider);
         }
 
         @Override
@@ -72,6 +75,7 @@ public class GroupbasedpolicyModule extends org.opendaylight.controller.config.y
             sfdp.close();
             supportedClassifierDefinitionListener.close();
             supportedActionDefinitionListener.close();
+            locationResolver.close();
         }
     }
 
diff --git a/groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/location/resolver/LocationResolver.java b/groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/location/resolver/LocationResolver.java
new file mode 100644 (file)
index 0000000..dfbf4d0
--- /dev/null
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 2016 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.groupbasedpolicy.location.resolver;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Nullable;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.util.IidFactory;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoint.locations.AddressEndpointLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoint.locations.AddressEndpointLocationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoint.locations.AddressEndpointLocationKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoint.locations.ContainmentEndpointLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoint.locations.ContainmentEndpointLocationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoint.locations.ContainmentEndpointLocationKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.AbsoluteLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.relative.location.relative.locations.ExternalLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.relative.location.relative.locations.InternalLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.LocationProviders;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.LocationProvider;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.location.provider.ProviderAddressEndpointLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.location.provider.ProviderAddressEndpointLocationKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.location.provider.ProviderContainmentEndpointLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.location.provider.ProviderContainmentEndpointLocationKey;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LocationResolver implements DataTreeChangeListener<LocationProvider>, AutoCloseable {
+
+    private static final Logger LOG = LoggerFactory.getLogger(LocationResolver.class);
+    private Map<AddressEndpointLocationKey, Map<Long, AbsoluteLocation>> realLocations;
+    private DataBroker dataBroker;
+    private ListenerRegistration<LocationResolver> listenerRegistation;
+
+    public LocationResolver(DataBroker dataBroker) {
+        this.dataBroker = dataBroker;
+        this.realLocations = new HashMap<>();
+        this.listenerRegistation = dataBroker.registerDataTreeChangeListener(
+                new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
+                        InstanceIdentifier.builder(LocationProviders.class).child(LocationProvider.class).build()),
+                this);
+    }
+
+    @Override
+    public synchronized void onDataTreeChanged(Collection<DataTreeModification<LocationProvider>> changes) {
+        for (DataTreeModification<LocationProvider> change : changes) {
+            WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
+            switch (change.getRootNode().getModificationType()) {
+                case DELETE: {
+                    processRemovedLocationProviderData(change.getRootNode().getDataBefore(), wtx);
+                    LOG.debug("Data from location provider {} has been removed",
+                            change.getRootNode().getDataBefore().getProvider().getValue());
+                    break;
+                }
+                case WRITE: {
+                    if (change.getRootNode().getDataBefore() != null) {
+                        processRemovedLocationProviderData(change.getRootNode().getDataBefore(), wtx);
+                    }
+                    processCreatedLocationProviderData(change.getRootNode().getDataAfter(), wtx);
+                    LOG.debug("Data from location provider {} has been created",
+                            change.getRootNode().getDataAfter().getProvider().getValue());
+                    break;
+                }
+                case SUBTREE_MODIFIED: {
+                    processRemovedLocationProviderData(change.getRootNode().getDataBefore(), wtx);
+                    processCreatedLocationProviderData(change.getRootNode().getDataAfter(), wtx);
+                    LOG.debug("Data from location provider {} has been changed",
+                            change.getRootNode().getDataAfter().getProvider().getValue());
+                    break;
+                }
+            }
+            wtx.submit();
+        }
+    }
+
+    private void processRemovedLocationProviderData(LocationProvider provider, WriteTransaction wtx) {
+        for (ProviderAddressEndpointLocation addressEndpointLocation : nullToEmpty(
+                provider.getProviderAddressEndpointLocation())) {
+            AddressEndpointLocationKey epKey = createAddressEndpointLocationKey(addressEndpointLocation.getKey());
+            long priority;
+            if (provider.getPriority() == null) {
+                priority = 0;
+                LOG.debug("{} provider doesn't provide priority. Using 0 as priority instead.",
+                        provider.getProvider().getValue());
+            } else {
+                priority = provider.getPriority();
+            }
+            realLocations.get(epKey).remove(priority);
+            AbsoluteLocation newAbsoluteLocation = getBestAbsoluteLocation(epKey);
+            if (newAbsoluteLocation == null) {
+                InstanceIdentifier<AbsoluteLocation> iid = IidFactory.absoluteLocationIid(epKey);
+                wtx.delete(LogicalDatastoreType.OPERATIONAL, iid);
+            } else {
+                AddressEndpointLocationBuilder newEP =
+                        new AddressEndpointLocationBuilder().setKey(epKey).setAbsoluteLocation(newAbsoluteLocation);
+                InstanceIdentifier<AddressEndpointLocation> iid = IidFactory.addressEndpointLocationIid(newEP.getKey());
+                wtx.merge(LogicalDatastoreType.OPERATIONAL, iid, newEP.build(), true);
+            }
+            if (addressEndpointLocation.getRelativeLocations() != null) {
+                for (InternalLocation location : nullToEmpty(
+                        addressEndpointLocation.getRelativeLocations().getInternalLocation())) {
+                    InstanceIdentifier<InternalLocation> iid = IidFactory.internalLocationIid(epKey, location.getKey());
+                    wtx.delete(LogicalDatastoreType.OPERATIONAL, iid);
+                }
+                for (ExternalLocation location : nullToEmpty(
+                        addressEndpointLocation.getRelativeLocations().getExternalLocation())) {
+                    InstanceIdentifier<ExternalLocation> iid = IidFactory.externalLocationIid(epKey, location.getKey());
+                    wtx.delete(LogicalDatastoreType.OPERATIONAL, iid);
+                }
+            }
+        }
+        for (ProviderContainmentEndpointLocation containmentEndpoint : nullToEmpty(
+                provider.getProviderContainmentEndpointLocation())) {
+            ContainmentEndpointLocationKey epKey = createContainmentEndpointLocationKey(containmentEndpoint.getKey());
+            if (containmentEndpoint.getRelativeLocations() != null) {
+                for (InternalLocation location : nullToEmpty(
+                        containmentEndpoint.getRelativeLocations().getInternalLocation())) {
+                    InstanceIdentifier<InternalLocation> iid = IidFactory.internalLocationIid(epKey, location.getKey());
+                    wtx.delete(LogicalDatastoreType.OPERATIONAL, iid);
+                }
+                for (ExternalLocation location : nullToEmpty(
+                        containmentEndpoint.getRelativeLocations().getExternalLocation())) {
+                    InstanceIdentifier<ExternalLocation> iid = IidFactory.externalLocationIid(epKey, location.getKey());
+                    wtx.delete(LogicalDatastoreType.OPERATIONAL, iid);
+                }
+            }
+        }
+    }
+
+    private void processCreatedLocationProviderData(LocationProvider provider, WriteTransaction wtx) {
+        for (ProviderAddressEndpointLocation addressEndpointLocation : nullToEmpty(
+                provider.getProviderAddressEndpointLocation())) {
+            AddressEndpointLocationKey epKey = createAddressEndpointLocationKey(addressEndpointLocation.getKey());
+            AddressEndpointLocationBuilder newEP = new AddressEndpointLocationBuilder().setKey(epKey);
+            if (addressEndpointLocation.getAbsoluteLocation() != null) {
+                if (realLocations.get(epKey) == null) {
+                    realLocations.put(epKey, new HashMap<>());
+                }
+                long priority;
+                if (provider.getPriority() == null) {
+                    priority = 0;
+                    LOG.debug("{} provider doesnt provide priority. Using 0 as priority instead.",
+                            provider.getProvider().getValue());
+                } else {
+                    priority = provider.getPriority();
+                }
+                realLocations.get(epKey).put(priority, addressEndpointLocation.getAbsoluteLocation());
+            }
+            AbsoluteLocation bestLocation = getBestAbsoluteLocation(epKey);
+            if (bestLocation != null) {
+                newEP.setAbsoluteLocation(bestLocation);
+            }
+            if (addressEndpointLocation.getRelativeLocations() != null) {
+                newEP.setRelativeLocations(addressEndpointLocation.getRelativeLocations());
+            }
+            InstanceIdentifier<AddressEndpointLocation> iid = IidFactory.addressEndpointLocationIid(newEP.getKey());
+            wtx.merge(LogicalDatastoreType.OPERATIONAL, iid, newEP.build(), true);
+        }
+        for (ProviderContainmentEndpointLocation containmentEndpointLocation : nullToEmpty(
+                provider.getProviderContainmentEndpointLocation())) {
+            if (containmentEndpointLocation.getRelativeLocations() != null) {
+                ContainmentEndpointLocationKey key =
+                        createContainmentEndpointLocationKey(containmentEndpointLocation.getKey());
+                ContainmentEndpointLocationBuilder newEP = new ContainmentEndpointLocationBuilder().setKey(key);
+                newEP.setRelativeLocations(containmentEndpointLocation.getRelativeLocations());
+                InstanceIdentifier<ContainmentEndpointLocation> iid =
+                        IidFactory.containmentEndpointLocationIid(newEP.getKey());
+                wtx.merge(LogicalDatastoreType.OPERATIONAL, iid, newEP.build(), true);
+            }
+        }
+    }
+
+    private AbsoluteLocation getBestAbsoluteLocation(AddressEndpointLocationKey epKey) {
+        if (realLocations.get(epKey) == null) {
+            return null;
+        }
+        long bestPriority = -1;
+        for (long priority : realLocations.get(epKey).keySet()) {
+            bestPriority = bestPriority > priority ? bestPriority : priority;
+        };
+        if (bestPriority == -1) {
+            return null;
+        }
+        return (realLocations.get(epKey).get(new Long(bestPriority)));
+    }
+
+    private AddressEndpointLocationKey createAddressEndpointLocationKey(ProviderAddressEndpointLocationKey key) {
+        return new AddressEndpointLocationKey(key.getAddress(), key.getAddressType(), key.getContextId(),
+                key.getContextType());
+    }
+
+    private ContainmentEndpointLocationKey createContainmentEndpointLocationKey(
+            ProviderContainmentEndpointLocationKey key) {
+        return new ContainmentEndpointLocationKey(key.getContextId(), key.getContextType());
+    }
+
+    private <T> List<T> nullToEmpty(@Nullable List<T> list) {
+        return list == null ? Collections.emptyList() : list;
+    }
+
+    @Override
+    public void close() throws Exception {
+        listenerRegistation.close();
+    }
+}
index a9f9e6c6b66c85135632f9bb2be74fc93c0be825..4e1835cb143c73827a04d3a05d5130ab81e9339f 100644 (file)
@@ -11,6 +11,11 @@ package org.opendaylight.groupbasedpolicy.util;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.EndpointLocations;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoint.locations.AddressEndpointLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoint.locations.AddressEndpointLocationKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoint.locations.ContainmentEndpointLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoint.locations.ContainmentEndpointLocationKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.AddressEndpoints;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.ContainmentEndpoints;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.address.endpoints.AddressEndpoint;
@@ -19,6 +24,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpo
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.containment.endpoints.ContainmentEndpointKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.parent.child.endpoints.parent.endpoint.choice.parent.containment.endpoint._case.ParentContainmentEndpoint;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.parent.child.endpoints.parent.endpoint.choice.parent.containment.endpoint._case.ParentContainmentEndpointKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.AbsoluteLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.relative.location.RelativeLocations;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.relative.location.relative.locations.ExternalLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.relative.location.relative.locations.ExternalLocationKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.relative.location.relative.locations.InternalLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.relative.location.relative.locations.InternalLocationKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ActionDefinitionId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ActionName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierDefinitionId;
@@ -108,7 +119,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.statistics
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.statistics.store.rev151215.statistics.store.StatisticRecord;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.statistics.store.rev151215.statistics.store.StatisticRecordKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
 
 public class IidFactory {
 
@@ -406,11 +416,67 @@ public class IidFactory {
             .build();
     }
 
-    public static InstanceIdentifierBuilder<ProviderAddressEndpointLocation> providerAddressEndpointLocationIid(String provider,
+    public static InstanceIdentifier<AddressEndpointLocation> addressEndpointLocationIid(AddressEndpointLocationKey addrEndpointLocationKey) {
+        return InstanceIdentifier.builder(EndpointLocations.class)
+                .child(AddressEndpointLocation.class, addrEndpointLocationKey)
+                .build();
+    }
+
+    public static InstanceIdentifier<ContainmentEndpointLocation> containmentEndpointLocationIid(ContainmentEndpointLocationKey addrEndpointLocationKey) {
+        return InstanceIdentifier.builder(EndpointLocations.class)
+                .child(ContainmentEndpointLocation.class, addrEndpointLocationKey)
+                .build();
+    }
+
+    public static InstanceIdentifier<InternalLocation> internalLocationIid(AddressEndpointLocationKey addrEndpointLocationKey,
+            InternalLocationKey internalLocationKey) {
+        return InstanceIdentifier.builder(EndpointLocations.class)
+                .child(AddressEndpointLocation.class, addrEndpointLocationKey)
+                .child(RelativeLocations.class)
+                .child(InternalLocation.class, internalLocationKey)
+                .build();
+    }
+
+    public static InstanceIdentifier<InternalLocation> internalLocationIid(ContainmentEndpointLocationKey contEndpointLocationKey,
+            InternalLocationKey internalLocationKey) {
+        return InstanceIdentifier.builder(EndpointLocations.class)
+                .child(ContainmentEndpointLocation.class, contEndpointLocationKey)
+                .child(RelativeLocations.class)
+                .child(InternalLocation.class, internalLocationKey)
+                .build();
+    }
+
+    public static InstanceIdentifier<ExternalLocation> externalLocationIid(AddressEndpointLocationKey addrEndpointLocationKey,
+            ExternalLocationKey externalLocationKey) {
+        return InstanceIdentifier.builder(EndpointLocations.class)
+                .child(AddressEndpointLocation.class, addrEndpointLocationKey)
+                .child(RelativeLocations.class)
+                .child(ExternalLocation.class, externalLocationKey)
+                .build();
+    }
+
+    public static InstanceIdentifier<ExternalLocation> externalLocationIid(ContainmentEndpointLocationKey contEndpointLocationKey,
+            ExternalLocationKey externalLocationKey) {
+        return InstanceIdentifier.builder(EndpointLocations.class)
+                .child(ContainmentEndpointLocation.class, contEndpointLocationKey)
+                .child(RelativeLocations.class)
+                .child(ExternalLocation.class, externalLocationKey)
+                .build();
+    }
+
+    public static InstanceIdentifier<AbsoluteLocation> absoluteLocationIid(AddressEndpointLocationKey addrEndpointLocationKey) {
+        return InstanceIdentifier.builder(EndpointLocations.class)
+                .child(AddressEndpointLocation.class, addrEndpointLocationKey)
+                .child(AbsoluteLocation.class)
+                .build();
+    }
+
+    public static InstanceIdentifier<ProviderAddressEndpointLocation> providerAddressEndpointLocationIid(String provider,
             Class<? extends AddressType> addrType, String addr, Class<? extends ContextType> cType,
             ContextId containment) {
         return InstanceIdentifier.builder(LocationProviders.class)
                 .child(LocationProvider.class, new LocationProviderKey(new ProviderName(provider)))
-            .child(ProviderAddressEndpointLocation.class, new ProviderAddressEndpointLocationKey(addr, addrType, containment, cType));
+            .child(ProviderAddressEndpointLocation.class, new ProviderAddressEndpointLocationKey(addr, addrType, containment, cType))
+            .build();
     }
 }
index 5519d5e645a62b9456724b71d20903969a599b28..7af2d7d94688baf0c806b392dfa98250246701c8 100644 (file)
@@ -33,6 +33,9 @@ module endpoint-location-provider {
             leaf provider {\r
                 type provider-name;\r
             }\r
+            leaf priority {\r
+                type uint32;\r
+            }\r
             list provider-address-endpoint-location {\r
                 key "context-type context-id address-type address";\r
                 uses base-endpoint:address-endpoint-key;\r
diff --git a/groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/location/resolver/LocationResolverTest.java b/groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/location/resolver/LocationResolverTest.java
new file mode 100644 (file)
index 0000000..7e8c5ef
--- /dev/null
@@ -0,0 +1,247 @@
+/*
+ * Copyright (c) 2016 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.groupbasedpolicy.location.resolver;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.test.CustomDataBrokerTest;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.EndpointLocations;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoint.locations.AddressEndpointLocationKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoint.locations.ContainmentEndpointLocationKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.AbsoluteLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.AbsoluteLocationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.absolute.location.location.type.InternalLocationCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.relative.location.RelativeLocations;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.relative.location.RelativeLocationsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.relative.location.relative.locations.InternalLocationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContextId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.LocationProviders;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.ProviderName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.LocationProvider;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.LocationProviderBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.LocationProviderKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.location.provider.ProviderAddressEndpointLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.location.provider.ProviderAddressEndpointLocationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.location.provider.ProviderAddressEndpointLocationKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.location.provider.ProviderContainmentEndpointLocationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.IpPrefixType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
+
+public class LocationResolverTest extends CustomDataBrokerTest {
+
+    private final String PROVIDER_NAME = "location-provider";
+    private final String ADDRESS = "192.168.50.20/24";
+    private final String NODE_1 = "node1";
+    private final String NODE_2 = "node2";
+    private final String NODE_CONNNECTOR = "connector";
+    private final ContextId contextId = new ContextId("context");
+
+    private InstanceIdentifier<Node> nodeIid1 =
+            InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(new NodeId(NODE_1))).build();
+    private InstanceIdentifier<Node> nodeIid2 =
+            InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(new NodeId(NODE_2))).build();
+    private InstanceIdentifier<NodeConnector> connectorIid = InstanceIdentifier.builder(Nodes.class)
+        .child(Node.class, new NodeKey(new NodeId(NODE_1)))
+        .child(NodeConnector.class, new NodeConnectorKey(new NodeConnectorId(NODE_CONNNECTOR)))
+        .build();
+    private DataBroker dataBroker;
+    private LocationResolver resolver;
+
+    @Before
+    public void init() {
+        dataBroker = getDataBroker();
+        resolver = new LocationResolver(dataBroker);
+    }
+
+    @Override
+    public Collection<Class<?>> getClassesFromModules() {
+        return ImmutableList.<Class<?>>of(LocationProvider.class, Nodes.class, L3Context.class,
+                EndpointLocations.class);
+    }
+
+    @Test
+    public void test_LocationProviderWrite() throws Exception {
+        AbsoluteLocation absoluteLocation =
+                new AbsoluteLocationBuilder().setLocationType(new InternalLocationCaseBuilder()
+                    .setInternalNode(nodeIid1).setInternalNodeConnector(connectorIid).build()).build();
+        RelativeLocations relativeLocations = new RelativeLocationsBuilder()
+            .setInternalLocation(Collections.singletonList(new InternalLocationBuilder().setInternalNode(nodeIid1)
+                .setInternalNodeConnector(connectorIid)
+                .build()))
+            .build();
+        LocationProvider provider = new LocationProviderBuilder().setProvider(new ProviderName(PROVIDER_NAME))
+            .setProviderAddressEndpointLocation(
+                    Collections.singletonList(new ProviderAddressEndpointLocationBuilder()
+                        .setKey(new ProviderAddressEndpointLocationKey(ADDRESS, IpPrefixType.class, contextId,
+                                L3Context.class))
+                        .setAbsoluteLocation(absoluteLocation)
+                        .setRelativeLocations(relativeLocations)
+                        .build()))
+            .setProviderContainmentEndpointLocation(
+                    Collections.singletonList(new ProviderContainmentEndpointLocationBuilder().setContextId(contextId)
+                        .setContextType(L3Context.class)
+                        .setRelativeLocations(relativeLocations)
+                        .build()))
+            .build();
+        InstanceIdentifier<LocationProvider> iid = InstanceIdentifier.builder(LocationProviders.class)
+            .child(LocationProvider.class, provider.getKey())
+            .build();
+        WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
+        wtx.put(LogicalDatastoreType.OPERATIONAL, iid, provider);
+        wtx.submit().get();
+
+        ReadOnlyTransaction rtx = dataBroker.newReadOnlyTransaction();
+        InstanceIdentifier<EndpointLocations> readIid = InstanceIdentifier.builder(EndpointLocations.class).build();
+        Optional<EndpointLocations> read = rtx.read(LogicalDatastoreType.OPERATIONAL, readIid).get();
+        assertTrue(read.isPresent());
+        EndpointLocations readLocations = read.get();
+        assertNotNull(readLocations.getAddressEndpointLocation());
+        assertEquals(1, readLocations.getAddressEndpointLocation().size());
+        assertEquals(new AddressEndpointLocationKey(ADDRESS, IpPrefixType.class, contextId, L3Context.class),
+                readLocations.getAddressEndpointLocation().get(0).getKey());
+        assertEquals(absoluteLocation, readLocations.getAddressEndpointLocation().get(0).getAbsoluteLocation());
+        assertNotNull(readLocations.getContainmentEndpointLocation());
+        assertEquals(1, readLocations.getContainmentEndpointLocation().size());
+        assertEquals(new ContainmentEndpointLocationKey(contextId, L3Context.class),
+                readLocations.getContainmentEndpointLocation().get(0).getKey());
+        assertEquals(relativeLocations, readLocations.getContainmentEndpointLocation().get(0).getRelativeLocations());
+    }
+
+    @Test
+    public void test_LocationProviderOverWrite() throws Exception {
+        test_LocationProviderWrite();
+        AbsoluteLocation absoluteLocation =
+                new AbsoluteLocationBuilder().setLocationType(new InternalLocationCaseBuilder()
+                    .setInternalNode(nodeIid2).setInternalNodeConnector(connectorIid).build()).build();
+        RelativeLocations relativeLocations = new RelativeLocationsBuilder()
+            .setInternalLocation(Collections.singletonList(new InternalLocationBuilder().setInternalNode(nodeIid2)
+                .setInternalNodeConnector(connectorIid)
+                .build()))
+            .build();
+        LocationProvider provider = new LocationProviderBuilder().setProvider(new ProviderName(PROVIDER_NAME))
+            .setProviderAddressEndpointLocation(
+                    Collections.singletonList(new ProviderAddressEndpointLocationBuilder()
+                        .setKey(new ProviderAddressEndpointLocationKey(ADDRESS, IpPrefixType.class, contextId,
+                                L3Context.class))
+                        .setAbsoluteLocation(absoluteLocation)
+                        .setRelativeLocations(relativeLocations)
+                        .build()))
+            .setProviderContainmentEndpointLocation(
+                    Collections.singletonList(new ProviderContainmentEndpointLocationBuilder().setContextId(contextId)
+                        .setContextType(L3Context.class)
+                        .setRelativeLocations(relativeLocations)
+                        .build()))
+            .build();
+        InstanceIdentifier<LocationProvider> iid = InstanceIdentifier.builder(LocationProviders.class)
+            .child(LocationProvider.class, provider.getKey())
+            .build();
+        WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
+        wtx.put(LogicalDatastoreType.OPERATIONAL, iid, provider);
+        wtx.submit().get();
+
+        ReadOnlyTransaction rtx = dataBroker.newReadOnlyTransaction();
+        InstanceIdentifier<EndpointLocations> readIid = InstanceIdentifier.builder(EndpointLocations.class).build();
+        Optional<EndpointLocations> read = rtx.read(LogicalDatastoreType.OPERATIONAL, readIid).get();
+        assertTrue(read.isPresent());
+        EndpointLocations readLocations = read.get();
+        assertNotNull(readLocations.getAddressEndpointLocation());
+        assertEquals(1, readLocations.getAddressEndpointLocation().size());
+        assertEquals(new AddressEndpointLocationKey(ADDRESS, IpPrefixType.class, contextId, L3Context.class),
+                readLocations.getAddressEndpointLocation().get(0).getKey());
+        assertEquals(absoluteLocation, readLocations.getAddressEndpointLocation().get(0).getAbsoluteLocation());
+        assertNotNull(readLocations.getContainmentEndpointLocation());
+        assertEquals(1, readLocations.getContainmentEndpointLocation().size());
+        assertEquals(new ContainmentEndpointLocationKey(contextId, L3Context.class),
+                readLocations.getContainmentEndpointLocation().get(0).getKey());
+        assertEquals(relativeLocations, readLocations.getContainmentEndpointLocation().get(0).getRelativeLocations());
+    }
+
+    @Test
+    public void test_LocationProviderDelete() throws Exception {
+        test_LocationProviderWrite();
+        InstanceIdentifier<LocationProvider> iid = InstanceIdentifier.builder(LocationProviders.class)
+            .child(LocationProvider.class, new LocationProviderKey(new ProviderName(PROVIDER_NAME)))
+            .build();
+        WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
+        wtx.delete(LogicalDatastoreType.OPERATIONAL, iid);
+        wtx.submit().get();
+
+        ReadOnlyTransaction rtx = dataBroker.newReadOnlyTransaction();
+        InstanceIdentifier<EndpointLocations> readIid = InstanceIdentifier.builder(EndpointLocations.class).build();
+        Optional<EndpointLocations> read = rtx.read(LogicalDatastoreType.OPERATIONAL, readIid).get();
+        assertTrue(read.isPresent());
+        EndpointLocations readLocations = read.get();
+        assertEquals(1, readLocations.getAddressEndpointLocation().size());
+        assertNull(readLocations.getAddressEndpointLocation().get(0).getAbsoluteLocation());
+        assertTrue(readLocations.getAddressEndpointLocation()
+            .get(0)
+            .getRelativeLocations()
+            .getInternalLocation()
+            .isEmpty());
+        assertNull(readLocations.getAddressEndpointLocation().get(0).getRelativeLocations().getExternalLocation());
+        assertEquals(1, readLocations.getContainmentEndpointLocation().size());
+        assertTrue(readLocations.getAddressEndpointLocation()
+            .get(0)
+            .getRelativeLocations()
+            .getInternalLocation()
+            .isEmpty());
+        assertNull(readLocations.getAddressEndpointLocation().get(0).getRelativeLocations().getExternalLocation());
+    }
+
+    @Test
+    public void test_LocationProviderModify() throws Exception {
+        test_LocationProviderWrite();
+        AbsoluteLocation absoluteLocation =
+                new AbsoluteLocationBuilder().setLocationType(new InternalLocationCaseBuilder()
+                    .setInternalNode(nodeIid2).setInternalNodeConnector(connectorIid).build()).build();
+        InstanceIdentifier<AbsoluteLocation> iid = InstanceIdentifier.builder(LocationProviders.class)
+            .child(LocationProvider.class, new LocationProviderKey(new ProviderName(PROVIDER_NAME)))
+            .child(ProviderAddressEndpointLocation.class,
+                    new ProviderAddressEndpointLocationKey(ADDRESS, IpPrefixType.class, contextId, L3Context.class))
+            .child(AbsoluteLocation.class)
+            .build();
+        WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
+        wtx.put(LogicalDatastoreType.OPERATIONAL, iid, absoluteLocation);
+        wtx.submit().get();
+
+        ReadOnlyTransaction rtx = dataBroker.newReadOnlyTransaction();
+        InstanceIdentifier<EndpointLocations> readIid = InstanceIdentifier.builder(EndpointLocations.class).build();
+        Optional<EndpointLocations> read = rtx.read(LogicalDatastoreType.OPERATIONAL, readIid).get();
+        assertTrue(read.isPresent());
+        EndpointLocations readLocations = read.get();
+        assertNotNull(readLocations.getAddressEndpointLocation());
+        assertEquals(1, readLocations.getAddressEndpointLocation().size());
+        assertEquals(new AddressEndpointLocationKey(ADDRESS, IpPrefixType.class, contextId, L3Context.class),
+                readLocations.getAddressEndpointLocation().get(0).getKey());
+        assertEquals(absoluteLocation, readLocations.getAddressEndpointLocation().get(0).getAbsoluteLocation());
+    }
+}
index 30222acf0b8dfcf0199a342e64e7ab4eb769c22d..a168b8fc2f08c5a3f4f0ce4454a4a99471744f17 100755 (executable)
@@ -16,8 +16,17 @@ import org.junit.Test;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoint.locations.AddressEndpointLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoint.locations.AddressEndpointLocationKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoint.locations.ContainmentEndpointLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoint.locations.ContainmentEndpointLocationKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.address.endpoints.AddressEndpoint;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.address.endpoints.AddressEndpointKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.AbsoluteLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.relative.location.relative.locations.ExternalLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.relative.location.relative.locations.ExternalLocationKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.relative.location.relative.locations.InternalLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.relative.location.relative.locations.InternalLocationKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ActionDefinitionId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ActionName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierDefinitionId;
@@ -67,6 +76,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.SupportedClassifierDefinition;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.interests.followed.tenants.FollowedTenant;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.interests.followed.tenants.followed.tenant.FollowedEndpointGroup;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 public class IidFactoryTest {
@@ -75,6 +91,7 @@ public class IidFactoryTest {
     private final String IP_ADDRESS = "192.68.50.71";
     private final String IP_PREFIX = "192.168.50.0/24";
     private final String L3_CONTEXT_ID = "l3Context";
+    private final String CONNECTOR = "connector";
 
     private TenantId tenantId;
     private EndpointGroupId epgId;
@@ -83,6 +100,13 @@ public class IidFactoryTest {
     private RuleName ruleName;
     private RendererName rendererName;
 
+    private InstanceIdentifier<Node> nodeIid = InstanceIdentifier.builder(Nodes.class)
+            .child(Node.class, new NodeKey(new NodeId("node"))).build();
+    private InstanceIdentifier<NodeConnector> connectorIid = InstanceIdentifier.builder(Nodes.class)
+            .child(Node.class, new NodeKey(new NodeId("node")))
+            .child(NodeConnector.class, new NodeConnectorKey(new NodeConnectorId("connector")))
+            .build();
+
     @Before
     public void initialise() {
         tenantId = mock(TenantId.class);
@@ -346,8 +370,7 @@ public class IidFactoryTest {
         InstanceIdentifier<ProviderAddressEndpointLocation> identifier = IidFactory
             .providerAddressEndpointLocationIid(LOCATION_PROVIDER_NAME, IpPrefixType.class, IP_ADDRESS,
                     org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class,
-                    l3Context)
-            .build();
+                    l3Context);
         Assert.assertEquals(LOCATION_PROVIDER_NAME,
                 identifier.firstKeyOf(LocationProvider.class).getProvider().getValue());
         Assert.assertEquals(IP_ADDRESS, identifier.firstKeyOf(ProviderAddressEndpointLocation.class).getAddress());
@@ -358,7 +381,7 @@ public class IidFactoryTest {
     public void testAddressEndpointIid() {
         ContextId l3Context = new ContextId(L3_CONTEXT_ID);
         InstanceIdentifier<AddressEndpoint> identifier =
-                IidFactory.addressEndpointIid(new AddressEndpointKey(IP_ADDRESS, IpPrefixType.class, new ContextId(l3Context),
+                IidFactory.addressEndpointIid(new AddressEndpointKey(IP_ADDRESS, IpPrefixType.class, l3Context,
                         org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class
                         ));
         Assert.assertEquals(IpPrefixType.class, identifier.firstKeyOf(AddressEndpoint.class).getAddressType());
@@ -368,4 +391,115 @@ public class IidFactoryTest {
                 identifier.firstKeyOf(AddressEndpoint.class).getContextType());
         Assert.assertEquals(l3Context, identifier.firstKeyOf(AddressEndpoint.class).getContextId());
     }
+
+    @Test
+    public void testAddressEndpointLocationIid() {
+        ContextId l3Context = new ContextId(L3_CONTEXT_ID);
+        AddressEndpointLocationKey addrEndpointLocationKey =
+                new AddressEndpointLocationKey(IP_ADDRESS, IpPrefixType.class, l3Context,
+                        org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class);
+        InstanceIdentifier<AddressEndpointLocation> iid = IidFactory.addressEndpointLocationIid(addrEndpointLocationKey);
+        Assert.assertEquals(IpPrefixType.class, iid.firstKeyOf(AddressEndpointLocation.class).getAddressType());
+        Assert.assertEquals(IP_ADDRESS, iid.firstKeyOf(AddressEndpointLocation.class).getAddress());
+        Assert.assertEquals(
+                org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class,
+                iid.firstKeyOf(AddressEndpointLocation.class).getContextType());
+        Assert.assertEquals(l3Context, iid.firstKeyOf(AddressEndpointLocation.class).getContextId());
+    }
+
+    @Test
+    public void testContainmentEndpointLocationIid() {
+        ContextId l3Context = new ContextId(L3_CONTEXT_ID);
+        ContainmentEndpointLocationKey contEndpointLocationKey =
+                new ContainmentEndpointLocationKey(l3Context,
+                        org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class);
+        InstanceIdentifier<ContainmentEndpointLocation> iid = IidFactory.containmentEndpointLocationIid(contEndpointLocationKey);
+        Assert.assertEquals(
+                org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class,
+                iid.firstKeyOf(ContainmentEndpointLocation.class).getContextType());
+        Assert.assertEquals(l3Context, iid.firstKeyOf(ContainmentEndpointLocation.class).getContextId());
+    }
+
+    @Test
+    public void internalLocationIid_AddrEndpoint() {
+        ContextId l3Context = new ContextId(L3_CONTEXT_ID);
+        AddressEndpointLocationKey addrEndpointLocationKey =
+                new AddressEndpointLocationKey(IP_ADDRESS, IpPrefixType.class, l3Context,
+                        org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class);
+        InternalLocationKey internalLocationKey = new InternalLocationKey(nodeIid, connectorIid);
+        InstanceIdentifier<InternalLocation> iid = IidFactory.internalLocationIid(addrEndpointLocationKey, internalLocationKey);
+        Assert.assertEquals(IpPrefixType.class, iid.firstKeyOf(AddressEndpointLocation.class).getAddressType());
+        Assert.assertEquals(IP_ADDRESS, iid.firstKeyOf(AddressEndpointLocation.class).getAddress());
+        Assert.assertEquals(
+                org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class,
+                iid.firstKeyOf(AddressEndpointLocation.class).getContextType());
+        Assert.assertEquals(l3Context, iid.firstKeyOf(AddressEndpointLocation.class).getContextId());
+        Assert.assertEquals(nodeIid, iid.firstKeyOf(InternalLocation.class).getInternalNode());
+        Assert.assertEquals(connectorIid, iid.firstKeyOf(InternalLocation.class).getInternalNodeConnector());
+    }
+
+    @Test
+    public void internalLocationIid_ContEndpoint() {
+        ContextId l3Context = new ContextId(L3_CONTEXT_ID);
+        ContainmentEndpointLocationKey contEndpointLocationKey =
+                new ContainmentEndpointLocationKey(l3Context,
+                        org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class);
+        InternalLocationKey internalLocationKey = new InternalLocationKey(nodeIid, connectorIid);
+        InstanceIdentifier<InternalLocation> iid = IidFactory.internalLocationIid(contEndpointLocationKey, internalLocationKey);
+        Assert.assertEquals(
+                org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class,
+                iid.firstKeyOf(ContainmentEndpointLocation.class).getContextType());
+        Assert.assertEquals(l3Context, iid.firstKeyOf(ContainmentEndpointLocation.class).getContextId());
+        Assert.assertEquals(nodeIid, iid.firstKeyOf(InternalLocation.class).getInternalNode());
+        Assert.assertEquals(connectorIid, iid.firstKeyOf(InternalLocation.class).getInternalNodeConnector());
+    }
+
+    @Test
+    public void externalLocationIid_AddrEndpoint() {
+        ContextId l3Context = new ContextId(L3_CONTEXT_ID);
+        AddressEndpointLocationKey addrEndpointLocationKey =
+                new AddressEndpointLocationKey(IP_ADDRESS, IpPrefixType.class, l3Context,
+                        org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class);
+        ExternalLocationKey externalLocationKey = new ExternalLocationKey(CONNECTOR, nodeIid);
+        InstanceIdentifier<ExternalLocation> iid = IidFactory.externalLocationIid(addrEndpointLocationKey, externalLocationKey);
+        Assert.assertEquals(IpPrefixType.class, iid.firstKeyOf(AddressEndpointLocation.class).getAddressType());
+        Assert.assertEquals(IP_ADDRESS, iid.firstKeyOf(AddressEndpointLocation.class).getAddress());
+        Assert.assertEquals(
+                org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class,
+                iid.firstKeyOf(AddressEndpointLocation.class).getContextType());
+        Assert.assertEquals(l3Context, iid.firstKeyOf(AddressEndpointLocation.class).getContextId());
+        Assert.assertEquals(CONNECTOR, iid.firstKeyOf(ExternalLocation.class).getExternalNodeConnector());
+        Assert.assertEquals(nodeIid, iid.firstKeyOf(ExternalLocation.class).getExternalNodeMountPoint());
+    }
+
+    @Test
+    public void externalLocationIid_ContEndpoint() {
+        ContextId l3Context = new ContextId(L3_CONTEXT_ID);
+        ContainmentEndpointLocationKey addrEndpointLocationKey =
+                new ContainmentEndpointLocationKey(l3Context,
+                        org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class);
+        ExternalLocationKey externalLocationKey = new ExternalLocationKey(CONNECTOR, nodeIid);
+        InstanceIdentifier<ExternalLocation> iid = IidFactory.externalLocationIid(addrEndpointLocationKey, externalLocationKey);
+        Assert.assertEquals(
+                org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class,
+                iid.firstKeyOf(ContainmentEndpointLocation.class).getContextType());
+        Assert.assertEquals(l3Context, iid.firstKeyOf(ContainmentEndpointLocation.class).getContextId());
+        Assert.assertEquals(CONNECTOR, iid.firstKeyOf(ExternalLocation.class).getExternalNodeConnector());
+        Assert.assertEquals(nodeIid, iid.firstKeyOf(ExternalLocation.class).getExternalNodeMountPoint());
+    }
+
+    @Test
+    public void absoluteLocationIid() {
+        ContextId l3Context = new ContextId(L3_CONTEXT_ID);
+        AddressEndpointLocationKey addrEndpointLocationKey =
+                new AddressEndpointLocationKey(IP_ADDRESS, IpPrefixType.class, l3Context,
+                        org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class);
+        InstanceIdentifier<AbsoluteLocation> iid = IidFactory.absoluteLocationIid(addrEndpointLocationKey);
+        Assert.assertEquals(IpPrefixType.class, iid.firstKeyOf(AddressEndpointLocation.class).getAddressType());
+        Assert.assertEquals(IP_ADDRESS, iid.firstKeyOf(AddressEndpointLocation.class).getAddress());
+        Assert.assertEquals(
+                org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class,
+                iid.firstKeyOf(AddressEndpointLocation.class).getContextType());
+        Assert.assertEquals(l3Context, iid.firstKeyOf(AddressEndpointLocation.class).getContextId());
+    }
 }
index 99325e0896c77271169fd912475b952fcacf8722..e20046df8dca04e571fe7e3858c088fecc3719dd 100644 (file)
@@ -114,8 +114,7 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
                         InstanceIdentifier<AbsoluteLocation> iid = IidFactory
                             .providerAddressEndpointLocationIid(NE_LOCATION_PROVIDER_NAME, IpPrefixType.class,
                                     endpoint.getAddress(), endpoint.getContextType(), endpoint.getContextId())
-                            .child(AbsoluteLocation.class)
-                            .build();
+                            .child(AbsoluteLocation.class);
                         wtx.put(LogicalDatastoreType.OPERATIONAL, iid, createRealLocation(ne.getIid(), iface.getIid()),
                                 true);
                         wtx.submit();
@@ -139,8 +138,7 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
                         InstanceIdentifier<AbsoluteLocation> iid = IidFactory
                             .providerAddressEndpointLocationIid(NE_LOCATION_PROVIDER_NAME, IpPrefixType.class,
                                     endpoint.getAddress(), endpoint.getContextType(), endpoint.getContextId())
-                            .child(AbsoluteLocation.class)
-                            .build();
+                            .child(AbsoluteLocation.class);
                         wtx.delete(LogicalDatastoreType.OPERATIONAL, iid);
                         wtx.submit();
                         LOG.debug("Location deleted for endpoint {}", endpoint);
@@ -382,8 +380,7 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
                 InstanceIdentifier<AbsoluteLocation> iid = IidFactory
                     .providerAddressEndpointLocationIid(NE_LOCATION_PROVIDER_NAME, IpPrefixType.class,
                             endpoint.getAddress(), endpoint.getContextType(), endpoint.getContextId())
-                    .child(AbsoluteLocation.class)
-                    .build();
+                    .child(AbsoluteLocation.class);
                 wtx.put(LogicalDatastoreType.OPERATIONAL, iid, createRealLocation(nodeIID, connectorIID), true);
                 wtx.submit();
                 LOG.debug("New location created for endpoint {}", endpoint);
@@ -402,8 +399,7 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
                 InstanceIdentifier<AbsoluteLocation> iid = IidFactory
                     .providerAddressEndpointLocationIid(NE_LOCATION_PROVIDER_NAME, IpPrefixType.class,
                             endpoint.getAddress(), endpoint.getContextType(), endpoint.getContextId())
-                    .child(AbsoluteLocation.class)
-                    .build();
+                    .child(AbsoluteLocation.class);
                 wtx.delete(LogicalDatastoreType.OPERATIONAL, iid);
                 wtx.submit();
                 LOG.debug("Location deleted for endpoint {}", endpoint);