<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 -->
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;
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
sfdp.close();
supportedClassifierDefinitionListener.close();
supportedActionDefinitionListener.close();
+ locationResolver.close();
}
}
--- /dev/null
+/*
+ * 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();
+ }
+}
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;
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;
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 {
.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();
}
}
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
--- /dev/null
+/*
+ * 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());
+ }
+}
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;
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 {
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;
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);
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());
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());
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());
+ }
}
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();
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);
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);
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);