</dependency>
<!-- testing dependencies -->
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-binding-broker-impl</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
import java.util.Map.Entry;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.groupbasedpolicy.api.EpRendererAugmentationRegistry;
import org.opendaylight.groupbasedpolicy.api.PolicyValidatorRegistry;
-import org.opendaylight.groupbasedpolicy.dto.EpKey;
+import org.opendaylight.groupbasedpolicy.renderer.iovisor.endpoint.EndpointListener;
import org.opendaylight.groupbasedpolicy.renderer.iovisor.endpoint.EndpointManager;
-import org.opendaylight.groupbasedpolicy.renderer.iovisor.module.IovisorModuleManager;
import org.opendaylight.groupbasedpolicy.renderer.iovisor.sf.Action;
import org.opendaylight.groupbasedpolicy.renderer.iovisor.sf.ActionDefinitionListener;
import org.opendaylight.groupbasedpolicy.renderer.iovisor.sf.ClassifierDefinitionListener;
import org.opendaylight.groupbasedpolicy.renderer.iovisor.sf.SubjectFeatures;
-import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
-import org.opendaylight.groupbasedpolicy.util.IidFactory;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ActionDefinitionId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.SubjectFeatureDefinitions;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinition;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinition;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.RendererName;
-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.groupbasedpolicy.renderer.rev151103.renderers.renderer.interests.followed.tenants.followed.tenant.FollowedEndpointGroupBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.ResolvedPolicies;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.resolved.policies.ResolvedPolicy;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOG = LoggerFactory.getLogger(IovisorRenderer.class);
- private EndpointManager endPointManager;
- private IovisorModuleManager iovisorModuleManager;
public static final RendererName RENDERER_NAME = new RendererName("IOVisor");
+
private final ClassifierDefinitionListener classifierDefinitionListener;
+ private EndpointManager endpointManager;
+ private EndpointListener endpointListener;
+ private final IovisorResolvedEndpointListener resolvedEndpointListener;
private ActionDefinitionListener actionDefinitionListener;
private ResolvedPolicyListener resolvedPolicyListener;
+
private DataBroker dataBroker;
- public IovisorRenderer(DataBroker dataBroker, EpRendererAugmentationRegistry epRendererAugmentationRegistry,
+ public IovisorRenderer(DataBroker passedDataBroker, EpRendererAugmentationRegistry epRendererAugmentationRegistry,
PolicyValidatorRegistry policyValidatorRegistry) {
- if (dataBroker != null)
- this.dataBroker = dataBroker;
- this.endPointManager = new EndpointManager(dataBroker, epRendererAugmentationRegistry);
- this.iovisorModuleManager = new IovisorModuleManager(dataBroker);
- this.resolvedPolicyListener =
- new ResolvedPolicyListener(dataBroker, new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
- InstanceIdentifier.builder(ResolvedPolicies.class).child(ResolvedPolicy.class).build()));
- classifierDefinitionListener = new ClassifierDefinitionListener(dataBroker, new DataTreeIdentifier<>(
- LogicalDatastoreType.CONFIGURATION,
- InstanceIdentifier.builder(SubjectFeatureDefinitions.class).child(ClassifierDefinition.class).build()));
- actionDefinitionListener = new ActionDefinitionListener(dataBroker, new DataTreeIdentifier<>(
- LogicalDatastoreType.CONFIGURATION,
- InstanceIdentifier.builder(SubjectFeatureDefinitions.class).child(ActionDefinition.class).build()));
+ if (passedDataBroker != null)
+ dataBroker = passedDataBroker;
+ endpointManager = new EndpointManager(dataBroker, epRendererAugmentationRegistry);
+ endpointListener = new EndpointListener(dataBroker, endpointManager);
+ this.resolvedPolicyListener = new ResolvedPolicyListener(dataBroker);
+ this.resolvedEndpointListener = new IovisorResolvedEndpointListener(dataBroker);
+ classifierDefinitionListener = new ClassifierDefinitionListener(dataBroker);
+ actionDefinitionListener = new ActionDefinitionListener(dataBroker);
for (Entry<ActionDefinitionId, Action> entry : SubjectFeatures.getActions().entrySet()) {
policyValidatorRegistry.register(entry.getKey(), entry.getValue());
}
- // TODO PUNT THIS....
- public void endpointPolicyUpdated(TenantId tenantId, EndpointGroupId epgId, EpKey epKey) {
- // TODO a renderer should remove followed-EPG and followed-tenant at some point
- if (dataBroker == null) {
- LOG.error("DataBroker is null. Cannot write followed-epg {}", epKey);
- return;
- }
- WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
- FollowedEndpointGroup followedEpg = new FollowedEndpointGroupBuilder().setId(epgId).build();
- wTx.put(LogicalDatastoreType.OPERATIONAL, IidFactory.followedEndpointgroupIid(RENDERER_NAME, tenantId, epgId),
- followedEpg, true);
- DataStoreHelper.submitToDs(wTx);
+ public IovisorResolvedEndpointListener getResolvedEndpointListener() {
+ return resolvedEndpointListener;
+ }
+
+ public EndpointManager getEndPointManager() {
+ return endpointManager;
}
@Override
public void close() throws Exception {
- if (endPointManager != null) {
- endPointManager.close();
- }
+ if (endpointManager != null)
+ endpointManager.close();
+ if (endpointListener != null)
+ endpointListener.close();
if (classifierDefinitionListener != null)
classifierDefinitionListener.close();
if (actionDefinitionListener != null)
actionDefinitionListener.close();
- if (iovisorModuleManager != null) {
- iovisorModuleManager.close();
- if (resolvedPolicyListener != null)
- resolvedPolicyListener.close();
- }
+ if (resolvedPolicyListener != null)
+ resolvedPolicyListener.close();
+ if (resolvedEndpointListener != null)
+ resolvedEndpointListener.close();
+
}
}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.renderer.iovisor;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.renderer.iovisor.utils.IovisorIidFactory;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+import org.opendaylight.groupbasedpolicy.util.DataTreeChangeHandler;
+import org.opendaylight.groupbasedpolicy.util.IidFactory;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.IovisorResolvedEndpointsByTenantByEndpointgroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.resolved.endpoints.by.tenant.by.endpointgroup.id.IovisorResolvedEndpointByTenantByEndpointgroupId;
+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.groupbasedpolicy.renderer.rev151103.renderers.renderer.interests.followed.tenants.followed.tenant.FollowedEndpointGroupBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.VisibleForTesting;
+
+public class IovisorResolvedEndpointListener
+ extends DataTreeChangeHandler<IovisorResolvedEndpointsByTenantByEndpointgroupId> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(IovisorResolvedEndpointListener.class);
+
+ protected IovisorResolvedEndpointListener(DataBroker dataprovider) {
+ super(dataprovider, new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
+ IovisorIidFactory.iovisorResolvedEndpointsByTenantIdByEndpointGroupIdWildCardIid()));
+ }
+
+ @Override
+ protected void onWrite(DataObjectModification<IovisorResolvedEndpointsByTenantByEndpointgroupId> rootNode,
+ InstanceIdentifier<IovisorResolvedEndpointsByTenantByEndpointgroupId> rootIdentifier) {
+ onSubtreeModified(rootNode, rootIdentifier);
+ }
+
+ @Override
+ protected void onDelete(DataObjectModification<IovisorResolvedEndpointsByTenantByEndpointgroupId> rootNode,
+ InstanceIdentifier<IovisorResolvedEndpointsByTenantByEndpointgroupId> rootIdentifier) {
+ throw new UnsupportedOperationException("Not implemented yet.");
+
+ }
+
+ @Override
+ protected void onSubtreeModified(DataObjectModification<IovisorResolvedEndpointsByTenantByEndpointgroupId> rootNode,
+ InstanceIdentifier<IovisorResolvedEndpointsByTenantByEndpointgroupId> rootIdentifier) {
+ for (IovisorResolvedEndpointByTenantByEndpointgroupId element : rootNode.getDataAfter()
+ .getIovisorResolvedEndpointByTenantByEndpointgroupId()) {
+ endpointPolicyUpdated(element.getTenantId(), element.getEndpointgroupId(),
+ this.dataProvider.newWriteOnlyTransaction());
+ }
+ }
+
+ @VisibleForTesting
+ void endpointPolicyUpdated(TenantId tenantId, EndpointGroupId epgId, WriteTransaction wTx) {
+ // TODO a renderer should remove followed-EPG and followed-tenant at some point
+ FollowedEndpointGroup followedEpg = new FollowedEndpointGroupBuilder().setId(epgId).build();
+ wTx.put(LogicalDatastoreType.OPERATIONAL,
+ IidFactory.followedEndpointgroupIid(IovisorRenderer.RENDERER_NAME, tenantId, epgId), followedEpg, true);
+ if (DataStoreHelper.submitToDs(wTx)) {
+ LOG.info("IovisorRenderer following Tenant {} EndpointGroup {}", tenantId.getValue(), epgId.getValue());
+ return;
+ } else {
+ LOG.error("IovisorRenderer could not follow Tenant {} EndpointGroup {}", tenantId.getValue(),
+ epgId.getValue());
+ return;
+ }
+ }
+
+}
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.groupbasedpolicy.util.DataTreeChangeHandler;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.ResolvedPolicies;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.resolved.policies.ResolvedPolicy;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public class ResolvedPolicyListener extends DataTreeChangeHandler<ResolvedPolicy> {
- protected ResolvedPolicyListener(DataBroker dataProvider, DataTreeIdentifier<ResolvedPolicy> pointOfInterest) {
- super(dataProvider, pointOfInterest);
- LOG.info("Initialised ResolvedPolicyListener");
+ public ResolvedPolicyListener(DataBroker dataBroker) {
+ super(dataBroker, new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
+ InstanceIdentifier.builder(ResolvedPolicies.class).child(ResolvedPolicy.class).build()));
}
- private static final Logger LOG = LoggerFactory.getLogger(ResolvedPolicyListener.class);
-
@Override
protected void onWrite(DataObjectModification<ResolvedPolicy> rootNode,
InstanceIdentifier<ResolvedPolicy> rootIdentifier) {
- LOG.info("Not implemented yet");
-
+ throw new UnsupportedOperationException("Not implemented yet.");
}
@Override
protected void onDelete(DataObjectModification<ResolvedPolicy> rootNode,
InstanceIdentifier<ResolvedPolicy> rootIdentifier) {
- LOG.info("Not implemented yet");
-
+ throw new UnsupportedOperationException("Not implemented yet.");
}
@Override
protected void onSubtreeModified(DataObjectModification<ResolvedPolicy> rootNode,
InstanceIdentifier<ResolvedPolicy> rootIdentifier) {
- LOG.info("Not implemented yet");
-
+ throw new UnsupportedOperationException("Not implemented yet.");
}
}
package org.opendaylight.groupbasedpolicy.renderer.iovisor.endpoint;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.util.Collection;
-
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
-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.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.util.DataTreeChangeHandler;
import org.opendaylight.groupbasedpolicy.util.IidFactory;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.IovisorModuleAugmentation;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class EndpointListener implements DataTreeChangeListener<EndpointL3>, AutoCloseable {
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
- private static final Logger LOG = LoggerFactory.getLogger(EndpointListener.class);
+public class EndpointListener extends DataTreeChangeHandler<EndpointL3> {
- private final DataBroker dataProvider;
- private final ListenerRegistration<EndpointListener> registration;
private final EndpointManager endpointManager;
public EndpointListener(DataBroker dataProvider, EndpointManager endpointManager) {
- this.dataProvider = checkNotNull(dataProvider);
- registration = dataProvider.registerDataTreeChangeListener(
- new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, IidFactory.l3EndpointsIidWildcard()), this);
+ super(dataProvider,
+ new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, IidFactory.l3EndpointsIidWildcard()));
this.endpointManager = endpointManager;
}
@Override
- public void onDataTreeChanged(Collection<DataTreeModification<EndpointL3>> changes) {
- for (DataTreeModification<EndpointL3> change : changes) {
- DataObjectModification<EndpointL3> rootNode = change.getRootNode();
- switch (rootNode.getModificationType()) {
- case WRITE:
- case SUBTREE_MODIFIED:
- LOG.info("Received Endpoint {}", rootNode.getDataAfter().getIpAddress());
- if (rootNode.getDataAfter().getAugmentation(IovisorModuleAugmentation.class) != null) {
- endpointManager.processEndpoint(rootNode.getDataAfter());
- } else {
- LOG.info("Endpoint did not have IOVisor Module Augmentation (Location URI). Ignoring");
- }
- break;
- case DELETE:
- LOG.warn("Received Endpoint {} but DELETE not implemented yet",
- rootNode.getDataAfter().getIpAddress());
- }
- }
+ protected void onWrite(DataObjectModification<EndpointL3> rootNode, InstanceIdentifier<EndpointL3> rootIdentifier) {
+ onSubtreeModified(rootNode, rootIdentifier);
}
@Override
- public void close() throws Exception {
- registration.close();
+ protected void onDelete(DataObjectModification<EndpointL3> rootNode,
+ InstanceIdentifier<EndpointL3> rootIdentifier) {
+ throw new UnsupportedOperationException("Not implemented yet.");
}
+ @Override
+ protected void onSubtreeModified(DataObjectModification<EndpointL3> rootNode,
+ InstanceIdentifier<EndpointL3> rootIdentifier) {
+ endpointManager.processEndpoint(rootNode.getDataAfter());
+ }
}
package org.opendaylight.groupbasedpolicy.renderer.iovisor.endpoint;
+import java.util.ArrayList;
+import java.util.List;
+
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.groupbasedpolicy.api.EpRendererAugmentationRegistry;
+import org.opendaylight.groupbasedpolicy.renderer.iovisor.module.IovisorModuleListener;
+import org.opendaylight.groupbasedpolicy.renderer.iovisor.module.IovisorModuleManager;
+import org.opendaylight.groupbasedpolicy.renderer.iovisor.utils.IovisorIidFactory;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.IovisorModuleAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.IovisorModuleId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.module.instances.IovisorModuleInstance;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.module.instances.IovisorModuleInstanceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.resolved.endpoints.IovisorResolvedEndpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.resolved.endpoints.IovisorResolvedEndpointBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.resolved.endpoints.by.tenant.by.endpointgroup.id.IovisorResolvedEndpointByTenantByEndpointgroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.resolved.endpoints.by.tenant.by.endpointgroup.id.IovisorResolvedEndpointByTenantByEndpointgroupIdBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.resolved.endpoints.by.tenant.by.endpointgroup.id.iovisor.resolved.endpoint.by.tenant.by.endpointgroup.id.IovisorEndpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.resolved.endpoints.by.tenant.by.endpointgroup.id.iovisor.resolved.endpoint.by.tenant.by.endpointgroup.id.IovisorEndpointBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
public class EndpointManager implements AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(EndpointManager.class);
-
+ private final DataBroker dataBroker;
private EndpointListener endpointListener;
private final IovisorEndpointAug iovisorEndpointAug;
+ private IovisorModuleManager iovisorModuleManager;
+ private IovisorModuleListener iovisorModuleListener;
- public EndpointManager(DataBroker dataBroker, EpRendererAugmentationRegistry epRendererAugmentationRegistry) {
- Preconditions.checkNotNull(dataBroker, "DataBroker instance must not be null");
+ public EndpointManager(DataBroker passedDataBroker, EpRendererAugmentationRegistry epRendererAugmentationRegistry) {
+ Preconditions.checkNotNull(passedDataBroker, "DataBroker instance must not be null");
+ dataBroker = passedDataBroker;
iovisorEndpointAug = new IovisorEndpointAug(epRendererAugmentationRegistry);
- endpointListener = new EndpointListener(dataBroker, this);
+ iovisorModuleManager = new IovisorModuleManager(dataBroker);
+ iovisorModuleListener = new IovisorModuleListener(dataBroker);
LOG.info("Initialized IOVisor EndpointManager");
}
+ @VisibleForTesting
+ IovisorModuleManager getIovisorModuleManager() {
+ return iovisorModuleManager;
+ }
+
public void processEndpoint(EndpointL3 endpoint) {
- /*
- * Is Augmentation valid?
- * - IPAddress or a name that can be resolved to an IPAddress
- */
-
- /*
- * IOVisorModule registered?
- * - In this rev, we will register the IOVisorModule (agent)
- */
-
- /*
- * Validate there is a resolved policy for tenant/EPGs.
- * - If so, add to resolved policy endpoint map thing
- * - If not, wait until there is (listener)
- * .... not real sure on this one... chicken and egg.
- */
-
- /*
- * Validate there is a valid forwarding model
- *
- */
-
- LOG.info("Processed Endpoint {}", endpoint);
+
+ IovisorModuleAugmentation iomAug = endpoint.getAugmentation(IovisorModuleAugmentation.class);
+ IovisorModuleId iovisorModuleId = new IovisorModuleId(iomAug.getUri().getValue());
+
+ // See if IovisorModule already exists in OPERATIONAL datastore. If not, for now we will
+ // register it.
+ IovisorModuleInstance iovisorModuleInstance = iovisorModuleManager.getActiveIovisorModule(iovisorModuleId);
+
+ if (iovisorModuleInstance == null) {
+ // In this iteration we will provision the IovisorModule (ie add it to CONF) then
+ // activate it (add it to OPER)
+ iovisorModuleInstance =
+ new IovisorModuleInstanceBuilder().setId(iovisorModuleId).setUri(iomAug.getUri()).build();
+ if (iovisorModuleManager.addProvisionedIovisorModule(iovisorModuleInstance)) {
+ LOG.info("Provisioned IovisorModule {}}", iovisorModuleInstance.getId());
+ } else {
+ LOG.error(
+ "Error provisioning IovisorModule {} as part of processing Endpoint Tenant: {} L3C: {} IPAddress: {}",
+ iovisorModuleInstance.getId(), endpoint.getTenant(), endpoint.getL3Context(),
+ endpoint.getIpAddress());
+ return;
+ }
+ // This could be under the successful if test above but end goal with remote Agent is
+ // that it registers so top test should go away
+ if (iovisorModuleManager.addActiveIovisorModule(iovisorModuleInstance.getId())) {
+ LOG.info("Activated IovisorModule {} as part of processing Endpoint Tenant: {} L3C: {} IPAddress: {}",
+ iovisorModuleInstance.getId().getValue(), endpoint.getTenant().getValue(),
+ endpoint.getL3Context().getValue(), endpoint.getIpAddress().getValue());
+ } else {
+ LOG.error(
+ "Error provisioning IovisorModule {} as part of processing Endpoint Tenant: {} L3C: {} IPAddress: {}",
+ iovisorModuleInstance.getId().getValue(), endpoint.getTenant().getValue(),
+ endpoint.getL3Context().getValue(), endpoint.getIpAddress().getValue());
+ return;
+ }
+ }
+
+ if (addIovisorResolvedEndpoint(endpoint)) {
+ LOG.info("Processed Endpoint Tenant {} L3Context: {} 1st IP Address: {}", endpoint.getTenant().getValue(),
+ endpoint.getL3Context().getValue(), endpoint.getIpAddress().getValue());
+ return;
+ } else {
+ LOG.error(
+ "Could not add to IovisorResolvedEndpoint store following Endpoint Tenant {} L3Context: {} 1st IP Address: {}",
+ endpoint.getTenant().getValue(), endpoint.getL3Context().getValue(),
+ endpoint.getIpAddress().getValue());
+ return;
+ }
+ }
+
+ @VisibleForTesting
+ boolean addIovisorResolvedEndpoint(EndpointL3 endpoint) {
+ WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
+ IovisorResolvedEndpoint iovisorResolvedEndpoint = new IovisorResolvedEndpointBuilder()
+ .setIpAddress(endpoint.getIpAddress()).setL3Context(endpoint.getL3Context()).build();
+ wTx.put(LogicalDatastoreType.OPERATIONAL,
+ IovisorIidFactory.iovisorResolvedEndpointIid(endpoint.getL3Context(), endpoint.getIpAddress()),
+ iovisorResolvedEndpoint, true);
+
+ IovisorEndpoint iovisorEndpoint = new IovisorEndpointBuilder().setIpAddress(endpoint.getIpAddress())
+ .setL3Context(endpoint.getL3Context())
+ .build();
+ List<IovisorEndpoint> iovisorEndpoints = new ArrayList<>();
+ iovisorEndpoints.add(iovisorEndpoint);
+
+ IovisorResolvedEndpointByTenantByEndpointgroupId iovisorResolvedEndpointbyTenantByEndpointgroupId;
+ if (endpoint.getEndpointGroup() != null) {
+ iovisorResolvedEndpointbyTenantByEndpointgroupId =
+ new IovisorResolvedEndpointByTenantByEndpointgroupIdBuilder().setTenantId(endpoint.getTenant())
+ .setEndpointgroupId(endpoint.getEndpointGroup())
+ .setIovisorEndpoint(iovisorEndpoints)
+ .build();
+ wTx.merge(LogicalDatastoreType.OPERATIONAL,
+ IovisorIidFactory.iovisorResolvedEndpointByTenantIdByEndpointGroupIdIid(endpoint.getTenant(),
+ endpoint.getEndpointGroup()),
+ iovisorResolvedEndpointbyTenantByEndpointgroupId, true);
+ LOG.trace("Added endpoint via endpointGroup to ResolvedEndpoints for {} {}",
+ endpoint.getTenant().getValue(), endpoint.getEndpointGroup().getValue());
+ }
+ if (endpoint.getEndpointGroups() != null) {
+ for (EndpointGroupId epg : endpoint.getEndpointGroups()) {
+ iovisorResolvedEndpointbyTenantByEndpointgroupId =
+ new IovisorResolvedEndpointByTenantByEndpointgroupIdBuilder().setTenantId(endpoint.getTenant())
+ .setEndpointgroupId(epg)
+ .setIovisorEndpoint(iovisorEndpoints)
+ .build();
+ wTx.merge(
+ LogicalDatastoreType.OPERATIONAL, IovisorIidFactory
+ .iovisorResolvedEndpointByTenantIdByEndpointGroupIdIid(endpoint.getTenant(), epg),
+ iovisorResolvedEndpointbyTenantByEndpointgroupId, true);
+ LOG.trace("Added endpoint via endpoingGroups() to ResolvedEndpoints for {} {}",
+ endpoint.getTenant().getValue(), epg.getValue());
+ }
+ }
+ return DataStoreHelper.submitToDs(wTx);
+
}
@Override
public void close() throws Exception {
if (iovisorEndpointAug != null)
iovisorEndpointAug.close();
+ if (iovisorModuleListener != null)
+ iovisorModuleListener.close();
if (endpointListener != null)
endpointListener.close();
/*
- * Copyright (c) 2015 Inocybe Technologies and others. All rights reserved.
+ * Copyright (c) 2015 Inocybe Technologies 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,
package org.opendaylight.groupbasedpolicy.renderer.iovisor.module;
-import java.util.Map;
-import java.util.Map.Entry;
-
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.groupbasedpolicy.renderer.iovisor.utils.IovisorIidFactory;
+import org.opendaylight.groupbasedpolicy.util.DataTreeChangeHandler;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.module.instances.IovisorModuleInstance;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.module.instances.IovisorModuleInstanceBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.module.instances.IovisorModuleInstanceKey;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class IovisorModuleListener implements DataChangeListener, AutoCloseable {
-
- private static final Logger LOG = LoggerFactory.getLogger(IovisorModuleListener.class);
-
- private final ListenerRegistration<DataChangeListener> registerListener;
-
- public IovisorModuleListener(DataBroker dataBroker) {
- this.registerListener = dataBroker.registerDataChangeListener(
- LogicalDatastoreType.OPERATIONAL,
- IovisorIidFactory.iovisorModuleInstancesIid().child(IovisorModuleInstance.class),
- this,
- AsyncDataBroker.DataChangeScope.SUBTREE);
- }
-
- @Override
- public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes) {
- created(changes.getCreatedData());
- updated(changes.getUpdatedData());
- removed(changes);
- }
+public class IovisorModuleListener extends DataTreeChangeHandler<IovisorModuleInstance> {
- /**
- * Process created events.
- *
- * @param created
- * Created data
- */
- private void created(Map<InstanceIdentifier<?>, DataObject> created) {
- for (Entry<InstanceIdentifier<?>, DataObject> newEndpoint : created.entrySet()) {
- IovisorModuleInstance iovisorModuleInstance = fromMd(newEndpoint.getKey(), (IovisorModuleInstance) newEndpoint.getValue());
- LOG.debug("IovisorModuleInstance CREATED {}", iovisorModuleInstance);
- //TODO process created event
- }
+ public IovisorModuleListener(DataBroker dataProvider) {
+ super(dataProvider, new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
+ IovisorIidFactory.iovisorModuleInstanceWildCardIid().child(IovisorModuleInstance.class)));
}
- /**
- * Process updated events.
- *
- * @param updated
- * updated data
- */
- private void updated(Map<InstanceIdentifier<?>, DataObject> updated) {
- for (Entry<InstanceIdentifier<?>, DataObject> updatedEndpoint : updated.entrySet()) {
- IovisorModuleInstance iovisorModuleInstance = fromMd(updatedEndpoint.getKey(), (IovisorModuleInstance) updatedEndpoint.getValue());
- LOG.debug("IovisorModuleInstance UPDATED {}", iovisorModuleInstance);
- //TODO process updated event
-
- }
- }
+ private static final Logger LOG = LoggerFactory.getLogger(IovisorModuleListener.class);
- /**
- * Process REMOVED data.
- *
- * @param changes
- * Changes data
- */
- private void removed(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes) {
- for (InstanceIdentifier<?> deletedEndpointPath : changes.getRemovedPaths()) {
- IovisorModuleInstance iovisorModuleInstance = fromMd(deletedEndpointPath, (IovisorModuleInstance) changes.getOriginalData().get(deletedEndpointPath));
- LOG.debug("IovisorModuleInstance REMOVED {}", iovisorModuleInstance);
- // TODO process removed event
- }
+ @Override
+ protected void onWrite(DataObjectModification<IovisorModuleInstance> rootNode,
+ InstanceIdentifier<IovisorModuleInstance> rootIdentifier) {
+ onSubtreeModified(rootNode, rootIdentifier);
}
- /**
- * Get the object from MD-SAL based on the instance identifier.
- *
- * @param iid
- * {@link InstanceIdentifier} of the related event
- * @param iovisorModuleInstance
- * {@link IovisorModuleInstance} from the related event
- * @return IovisorModuleInstance constructed from the one gathered in the related event
- */
- private IovisorModuleInstance fromMd(InstanceIdentifier<?> iid, IovisorModuleInstance iovisorModuleInstance) {
- IovisorModuleInstanceBuilder result = new IovisorModuleInstanceBuilder();
-
- final IovisorModuleInstanceKey key = iid.firstKeyOf(IovisorModuleInstance.class);
- if (key != null) {
- result.setKey(key);
- }
-
- result.setUri(iovisorModuleInstance.getUri());
+ @Override
+ protected void onDelete(DataObjectModification<IovisorModuleInstance> rootNode,
+ InstanceIdentifier<IovisorModuleInstance> rootIdentifier) {
+ LOG.debug("IovisorModuleInstance DELETED {}", rootNode.getDataAfter().getUri().getValue());
- return result.build();
}
@Override
- public void close() throws Exception {
- if (registerListener != null)
- registerListener.close();
+ protected void onSubtreeModified(DataObjectModification<IovisorModuleInstance> rootNode,
+ InstanceIdentifier<IovisorModuleInstance> rootIdentifier) {
+ LOG.debug("IovisorModuleInstance CREATED/MODIFIED {}", rootNode.getDataAfter().getUri().getValue());
+
}
}
package org.opendaylight.groupbasedpolicy.renderer.iovisor.module;
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.renderer.iovisor.utils.IovisorIidFactory;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.IovisorModuleId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.IovisorModuleInstances;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.module.instances.IovisorModuleInstance;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.module.instances.IovisorModuleInstanceKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import com.google.common.net.HostSpecifier;
public class IovisorModuleManager implements AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(IovisorModuleManager.class);
+ private DataBroker dataBroker;
- private IovisorModuleListener iovisorModuleListener;
+ public IovisorModuleManager(DataBroker passedDataBroker) {
+ Preconditions.checkNotNull(passedDataBroker, "DataBroker instance must not be null");
+ dataBroker = passedDataBroker;
+ LOG.info("Initialized IOVisor IovisorModuleManager");
+ }
- public IovisorModuleManager(DataBroker dataBroker) {
- Preconditions.checkNotNull(dataBroker, "DataBroker instance must not be null");
+ public boolean addProvisionedIovisorModule(IovisorModuleInstance iovisorModuleInstance) {
+ return addIovisorModule(iovisorModuleInstance, LogicalDatastoreType.CONFIGURATION);
+ }
- this.iovisorModuleListener = new IovisorModuleListener(dataBroker);
- LOG.info("Initialized IOVisor IovisorModuleManager");
+ public boolean addActiveIovisorModule(IovisorModuleId iovisorModuleId) {
+ IovisorModuleInstance iovisorModuleInstance = getProvisionedIovisorModule(iovisorModuleId);
+ if (iovisorModuleInstance == null) {
+ LOG.error("Cannot Activate IovisorModule {}, no provisioned IovisorModule found.",
+ iovisorModuleId.getValue());
+ return false;
+ }
+ return addIovisorModule(iovisorModuleInstance, LogicalDatastoreType.OPERATIONAL);
}
- @Override
- public void close() throws Exception {
- if (iovisorModuleListener != null) {
- iovisorModuleListener.close();
+ public boolean addIovisorModule(IovisorModuleInstance iovisorModuleInstance, LogicalDatastoreType dataStoreType) {
+ if (!isValidIovisorModuleInstance(iovisorModuleInstance))
+ return false;
+ WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
+ wTx.put(dataStoreType,
+ IovisorIidFactory.iovisorModuleInstanceIid(new IovisorModuleInstanceKey(iovisorModuleInstance.getId())),
+ iovisorModuleInstance);
+ return DataStoreHelper.submitToDs(wTx);
+ }
+
+ public IovisorModuleInstance getActiveIovisorModule(IovisorModuleId iovisorModuleId) {
+ if (!isValidIovisorModuleId(iovisorModuleId))
+ return null;
+ return getIovisorModule(iovisorModuleId, LogicalDatastoreType.OPERATIONAL);
+ }
+
+ public IovisorModuleInstance getProvisionedIovisorModule(IovisorModuleId iovisorModuleId) {
+ return getIovisorModule(iovisorModuleId, LogicalDatastoreType.CONFIGURATION);
+ }
+
+ private IovisorModuleInstance getIovisorModule(IovisorModuleId iovisorModuleId,
+ LogicalDatastoreType dataStoreType) {
+ ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();
+ Optional<IovisorModuleInstance> readFromDs = DataStoreHelper.readFromDs(dataStoreType,
+ IovisorIidFactory.iovisorModuleInstanceIid(new IovisorModuleInstanceKey(iovisorModuleId)), rTx);
+ if (readFromDs.isPresent()) {
+ return readFromDs.get();
}
+ return null;
}
+
+ public IovisorModuleInstances getIovisorModules(ReadOnlyTransaction rTx, LogicalDatastoreType dataStoreType) {
+ Optional<IovisorModuleInstances> readFromDs =
+ DataStoreHelper.readFromDs(dataStoreType, IovisorIidFactory.iovisorModuleInstanceWildCardIid(), rTx);
+ if (readFromDs.isPresent()) {
+ return readFromDs.get();
+ }
+ return null;
+ }
+
+ private boolean isValidIovisorModuleInstance(IovisorModuleInstance iovisorModuleInstance) {
+ if (iovisorModuleInstance == null || iovisorModuleInstance.getId() == null
+ || iovisorModuleInstance.getUri() == null) {
+ LOG.info("IovisorModuleInstance was not valid. {} contained null.", iovisorModuleInstance.toString());
+ return false;
+ }
+ if (!isValidIovisorModuleId(iovisorModuleInstance.getId())) {
+ return false;
+ }
+ if (!isValidIovisorModuleUri(iovisorModuleInstance.getUri())) {
+ return false;
+ }
+ return true;
+ }
+
+ private boolean isValidIovisorModuleUri(Uri uri) {
+ /*
+ * TODO Still deciding if want to take IovisorModuleId in host:port form and if host
+ * is form name.something.org:port convert to IpAddress:port for putting in Uri. For now
+ * assuming Id==Uri
+ */
+ IovisorModuleId idFromUri = new IovisorModuleId(uri.getValue());
+ if (!isValidIovisorModuleId(idFromUri)) {
+ LOG.error("IovisorModule Uri is not of form host-specifier:port {}", uri.getValue());
+ return false;
+ }
+ return true;
+ }
+
+ private boolean isValidIovisorModuleId(IovisorModuleId id) {
+ String[] idParts = id.getValue().split(":");
+ if (idParts.length != 2) {
+ LOG.error("IovisorModuleId is not of form host-specifier:port {}", id.getValue());
+ return false;
+ }
+ String nameOrIp = idParts[0];
+ if (!HostSpecifier.isValid(nameOrIp)) {
+ LOG.error("IovisorModuleId host specifier is incorrect format: {}", nameOrIp);
+ return false;
+ }
+ Integer port = Integer.valueOf(idParts[1]);
+ if (port < 0 || port > 65535) {
+ LOG.error("IovisorModuleId port specifier is incorrect format: {}", port);
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void close() throws Exception {}
+
}
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.groupbasedpolicy.renderer.iovisor.IovisorRenderer;
import org.opendaylight.groupbasedpolicy.util.DataTreeChangeHandler;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.SubjectFeatureDefinitions;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinition;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.Renderers;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.Renderer;
private static String PUT = "stored";
private static String DELETED = "removed";
- public ActionDefinitionListener(DataBroker dataProvider, DataTreeIdentifier<ActionDefinition> pointOfInterest) {
- super(dataProvider, pointOfInterest);
+ public ActionDefinitionListener(DataBroker dataBroker) {
+ super(dataBroker, new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
+ InstanceIdentifier.builder(SubjectFeatureDefinitions.class).child(ActionDefinition.class).build()));
}
private SupportedActionDefinition createSupportedActionDefinition(Action action) {
@Override
public void onSuccess(Void result) {
LOG.debug("Capability of renerer {} was {}: {}", IovisorRenderer.RENDERER_NAME.getValue(), putOrDeleted,
- supportedActionDefinitionKey);
+ supportedActionDefinitionKey.getActionDefinitionId().getValue());
}
@Override
public void onFailure(Throwable t) {
LOG.error("Capability of renderer {} was NOT {}: {}", IovisorRenderer.RENDERER_NAME.getValue(),
- putOrDeleted, supportedActionDefinitionKey, t);
+ putOrDeleted, supportedActionDefinitionKey.getActionDefinitionId().getValue(), t);
}
};
}
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.groupbasedpolicy.renderer.iovisor.IovisorRenderer;
import org.opendaylight.groupbasedpolicy.util.DataTreeChangeHandler;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.SubjectFeatureDefinitions;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinition;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.Renderers;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.Renderer;
private static final String PUT = "stored";
private static final String DELETED = "removed";
+
private static final InstanceIdentifier<Capabilities> CAPABILITIES_IID = InstanceIdentifier.builder(Renderers.class)
.child(Renderer.class, new RendererKey(IovisorRenderer.RENDERER_NAME))
.child(Capabilities.class)
.build();
- public ClassifierDefinitionListener(DataBroker dataBroker,
- DataTreeIdentifier<ClassifierDefinition> pointOfInterest) {
- super(dataBroker, pointOfInterest);
+ public ClassifierDefinitionListener(DataBroker dataBroker) {
+ super(dataBroker, new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
+ InstanceIdentifier.builder(SubjectFeatureDefinitions.class).child(ClassifierDefinition.class).build()));
}
private SupportedClassifierDefinition createSupportedClassifierDefinition(Classifier classifier) {
@Override
public void onSuccess(Void result) {
LOG.debug("Capability of renerer {} was {}: {}", IovisorRenderer.RENDERER_NAME.getValue(), putOrDeleted,
- supportedClassifierDefinitionKey);
+ supportedClassifierDefinitionKey.getClassifierDefinitionId().getValue());
}
@Override
public void onFailure(Throwable t) {
LOG.error("Capability of renderer {} was NOT {}: {}", IovisorRenderer.RENDERER_NAME.getValue(),
- putOrDeleted, supportedClassifierDefinitionKey, t);
+ putOrDeleted, supportedClassifierDefinitionKey.getClassifierDefinitionId().getValue(), t);
}
};
}
SupportedClassifierDefinitionKey supportedClassifierDefinitionKey =
new SupportedClassifierDefinitionKey(ourClassifier.getId());
WriteTransaction wTx = dataProvider.newWriteOnlyTransaction();
+
wTx.delete(LogicalDatastoreType.OPERATIONAL,
CAPABILITIES_IID.child(SupportedClassifierDefinition.class, supportedClassifierDefinitionKey));
Futures.addCallback(wTx.submit(), logDebugResult(supportedClassifierDefinitionKey, DELETED));
/*
- * Copyright (c) 2015 Inocybe Technologies and others. All rights reserved.
+ * Copyright (c) 2015 Inocybe Technologies 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,
package org.opendaylight.groupbasedpolicy.renderer.iovisor.utils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L3ContextId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.IovisorModuleInstances;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.IovisorResolvedEndpoints;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.IovisorResolvedEndpointsByTenantByEndpointgroupId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.module.instances.IovisorModuleInstance;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.module.instances.IovisorModuleInstanceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.resolved.endpoints.IovisorResolvedEndpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.resolved.endpoints.IovisorResolvedEndpointKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.resolved.endpoints.by.tenant.by.endpointgroup.id.IovisorResolvedEndpointByTenantByEndpointgroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.resolved.endpoints.by.tenant.by.endpointgroup.id.IovisorResolvedEndpointByTenantByEndpointgroupIdKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
public class IovisorIidFactory {
- private IovisorIidFactory() {
- }
+ private IovisorIidFactory() {}
- private static final InstanceIdentifier<IovisorModuleInstances> IOVISOR_MODULE_INSTANCES_IID = InstanceIdentifier.builder(IovisorModuleInstances.class).build();
+ private static final InstanceIdentifier<IovisorModuleInstances> IOVISOR_MODULE_INSTANCES_IID =
+ InstanceIdentifier.builder(IovisorModuleInstances.class).build();
/**
* @return The {@link InstanceIdentifier} of the {@link IovisorModuleInstances}
*/
- public static InstanceIdentifier<IovisorModuleInstances> iovisorModuleInstancesIid() {
+ public static InstanceIdentifier<IovisorModuleInstances> iovisorModuleInstanceWildCardIid() {
return IOVISOR_MODULE_INSTANCES_IID;
}
/**
* Return the InstanceIdentifier for a specific IovisorModuleInstance.
- * @param iovisorModuleInstanceKey The key of the {@link IovisorModuleInstance} we want to retrieve.
+ *
+ * @param iovisorModuleInstanceKey The key of the {@link IovisorModuleInstance} we want to
+ * retrieve.
* @return The {@link InstanceIdentifier} of the {@link IovisorModuleInstance}
*/
- public static InstanceIdentifier<IovisorModuleInstance> iovisorModuleInstanceIid(IovisorModuleInstanceKey iovisorModuleInstanceKey) {
+ public static InstanceIdentifier<IovisorModuleInstance> iovisorModuleInstanceIid(
+ IovisorModuleInstanceKey iovisorModuleInstanceKey) {
return IOVISOR_MODULE_INSTANCES_IID.child(IovisorModuleInstance.class, iovisorModuleInstanceKey);
}
+
+ public static InstanceIdentifier<IovisorResolvedEndpoints> iovisorResolvedEndpointWildcardIid() {
+ return InstanceIdentifier.builder(IovisorResolvedEndpoints.class).build();
+ }
+
+ public static InstanceIdentifier<IovisorResolvedEndpoint> iovisorResolvedEndpointIid(L3ContextId l3Context,
+ IpAddress ipAddress) {
+ return iovisorResolvedEndpointIid(new IovisorResolvedEndpointKey(ipAddress, l3Context));
+ }
+
+ public static InstanceIdentifier<IovisorResolvedEndpoint> iovisorResolvedEndpointIid(
+ IovisorResolvedEndpointKey iovisorResolvedEndpointKey) {
+ return InstanceIdentifier.builder(IovisorResolvedEndpoints.class)
+ .child(IovisorResolvedEndpoint.class, iovisorResolvedEndpointKey)
+ .build();
+ }
+
+ public static InstanceIdentifier<IovisorResolvedEndpointsByTenantByEndpointgroupId> iovisorResolvedEndpointsByTenantIdByEndpointGroupIdWildCardIid() {
+ return InstanceIdentifier.builder(IovisorResolvedEndpointsByTenantByEndpointgroupId.class).build();
+ }
+
+ public static InstanceIdentifier<IovisorResolvedEndpointByTenantByEndpointgroupId> iovisorResolvedEndpointByTenantIdByEndpointGroupIdIid(
+ TenantId tenantId, EndpointGroupId epgId) {
+ return iovisorResolvedEndpointByTenantIdByEndpointGroupIdIid(
+ new IovisorResolvedEndpointByTenantByEndpointgroupIdKey(epgId, tenantId));
+ }
+
+ public static InstanceIdentifier<IovisorResolvedEndpointByTenantByEndpointgroupId> iovisorResolvedEndpointByTenantIdByEndpointGroupIdIid(
+ IovisorResolvedEndpointByTenantByEndpointgroupIdKey key) {
+ return InstanceIdentifier.builder(IovisorResolvedEndpointsByTenantByEndpointgroupId.class)
+ .child(IovisorResolvedEndpointByTenantByEndpointgroupId.class, key)
+ .build();
+ }
}
*/
public static boolean validateIovisorModuleInstance(DataBroker dataBroker, Uri iovisorModuleUri) {
Optional<IovisorModuleInstances> res = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
- IovisorIidFactory.iovisorModuleInstancesIid(),
+ IovisorIidFactory.iovisorModuleInstanceWildCardIid(),
dataBroker.newReadOnlyTransaction());
if (res.isPresent()) {
for (IovisorModuleInstance instance : res.get().getIovisorModuleInstance()) {
import yang-ext {prefix ext; revision-date "2013-07-09";}
import ietf-inet-types { prefix inet; revision-date 2010-09-24; }
import endpoint { prefix endpoint; }
+ import gbp-common { prefix gbp-common; }
description
"This module defines the group-based policy iovisor renderer model.";
}
typedef iovisor-module-id {
+ /*
+ * TODO Either convert this to URI or allow String but expect name:port where name will
+ * resolved into ip:port (see iovisor-module grouping)
+ */
description "Uniquely identifies the IOVisor module";
type string;
}
grouping iovisor-module {
+ /*
+ * TODO Convert this to leafs of IP(v4|v6) and port - easier to validate
+ * For now assuming format "ip:port"
+ */
leaf uri {
type inet:uri;
description "IOVisor module uniform resource identifier.";
}
}
+ container iovisor-resolved-endpoints {
+ description "IOvisor validated Endpoints";
+ config false;
+ list iovisor-resolved-endpoint {
+ key "l3-context ip-address";
+ uses endpoint:l3-key;
+ }
+ }
+
+ container iovisor-resolved-endpoints-by-tenant-by-endpointgroup-id {
+ config false;
+ list iovisor-resolved-endpoint-by-tenant-by-endpointgroup-id {
+ key "tenant-id endpointgroup-id";
+ leaf tenant-id {
+ type gbp-common:tenant-id;
+ }
+ leaf endpointgroup-id {
+ type gbp-common:endpoint-group-id;
+ }
+ list iovisor-endpoint {
+ key "l3-context ip-address";
+ uses endpoint:l3-key;
+ }
+ }
+ }
+
augment "/endpoint:endpoints/endpoint:endpoint-l3" {
description "Augmentation adding the IOVisor module location";
ext:augment-identifier "iovisor-module-augmentation";
package org.opendaylight.groupbasedpolicy.renderer.iovisor;
-import org.junit.Test;
+import static org.mockito.Mockito.mock;
-public class IovisorRendererTest {
+import org.junit.Before;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.groupbasedpolicy.api.EpRendererAugmentationRegistry;
+import org.opendaylight.groupbasedpolicy.api.PolicyValidatorRegistry;
+import org.opendaylight.groupbasedpolicy.renderer.iovisor.test.GbpIovisorDataBrokerTest;
- @Test
- public void IovisorRendererClassTest() {
- // TODO Implement me
- }
+public class IovisorRendererTest extends GbpIovisorDataBrokerTest {
+
+ private DataBroker dataBroker;
+ private EpRendererAugmentationRegistry epRendererAugReg;
+ private IovisorRenderer iovisorRenderer;
+ private PolicyValidatorRegistry policyValidatorRegistry;
+
+ @Before
+ public void iovisorInit() {
+ dataBroker = getDataBroker();
+ epRendererAugReg = mock(EpRendererAugmentationRegistry.class);
+ policyValidatorRegistry = mock(PolicyValidatorRegistry.class);
+ iovisorRenderer = new IovisorRenderer(dataBroker, epRendererAugReg, policyValidatorRegistry);
- @Test
- public void endpointPolicyUpdatedTest() {
- // TODO implement me
}
}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems. 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.renderer.iovisor;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.renderer.iovisor.test.GbpIovisorDataBrokerTest;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+import org.opendaylight.groupbasedpolicy.util.IidFactory;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.interests.followed.tenants.followed.tenant.FollowedEndpointGroup;
+
+import com.google.common.base.Optional;
+
+public class IovisorResolvedEndpointListenerTest extends GbpIovisorDataBrokerTest {
+
+ private DataBroker dataBroker;
+ private IovisorResolvedEndpointListener iovisorResolvedEndpointListener;
+ private final TenantId tenant1 = new TenantId("tenant1");
+ private final EndpointGroupId epg1 = new EndpointGroupId("client");
+
+ @Before
+ public void iovisorInit() {
+ dataBroker = getDataBroker();
+ iovisorResolvedEndpointListener = new IovisorResolvedEndpointListener(dataBroker);
+
+ }
+
+ @Test
+ public void endpointPolicyUpdatedTest() {
+ iovisorResolvedEndpointListener.endpointPolicyUpdated(tenant1, epg1, dataBroker.newWriteOnlyTransaction());
+ Optional<FollowedEndpointGroup> readFromDs = DataStoreHelper.readFromDs(LogicalDatastoreType.OPERATIONAL,
+ IidFactory.followedEndpointgroupIid(IovisorRenderer.RENDERER_NAME, tenant1, epg1),
+ dataBroker.newReadOnlyTransaction());
+ Assert.assertTrue(readFromDs.isPresent());
+ Assert.assertEquals(epg1, readFromDs.get().getId());
+ }
+}
package org.opendaylight.groupbasedpolicy.renderer.iovisor.endpoint;
-public class EndpointManagerTest {
+import static org.mockito.Mockito.mock;
- // Nothing to test
-}
\ No newline at end of file
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.api.EpRendererAugmentationRegistry;
+import org.opendaylight.groupbasedpolicy.renderer.iovisor.module.IovisorModuleManager;
+import org.opendaylight.groupbasedpolicy.renderer.iovisor.test.GbpIovisorDataBrokerTest;
+import org.opendaylight.groupbasedpolicy.renderer.iovisor.utils.IovisorIidFactory;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+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.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L3ContextId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3AddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Key;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.IovisorModuleAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.IovisorModuleAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.IovisorModuleId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.module.instances.IovisorModuleInstance;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.resolved.endpoints.by.tenant.by.endpointgroup.id.IovisorResolvedEndpointByTenantByEndpointgroupId;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
+
+public class EndpointManagerTest extends GbpIovisorDataBrokerTest {
+
+ private final TenantId tenant1 = new TenantId("tenant1");
+ private final L3ContextId l3c1 = new L3ContextId("l3c1");
+ private final IpAddress ipv41 = new IpAddress(new Ipv4Address("10.1.1.10"));
+
+ private final EndpointL3Key ipv41Key = new EndpointL3Key(ipv41, l3c1);
+
+ private final IpAddress ipv61 = new IpAddress(new Ipv6Address("2001:db8::2"));
+
+ List<EndpointGroupId> epgs = ImmutableList.of(new EndpointGroupId("client1"));
+
+ private final List<L3Address> l3Address1 =
+ ImmutableList.of(new L3AddressBuilder().setIpAddress(ipv41).setL3Context(l3c1).build(),
+ new L3AddressBuilder().setIpAddress(ipv61).setL3Context(l3c1).build());
+
+ private DataBroker dataBroker;
+ private EndpointManager endpointManager;
+ private static IovisorModuleManager iovisorModuleManager;
+ private EpRendererAugmentationRegistry epRAR;
+ private EndpointL3 endpoint1;
+ private IovisorModuleAugmentation iomAug1;
+
+ @Before
+ public void initialisation() throws Exception {
+ dataBroker = getDataBroker();
+ epRAR = mock(EpRendererAugmentationRegistry.class);
+ endpointManager = new EndpointManager(dataBroker, epRAR);
+ iovisorModuleManager = endpointManager.getIovisorModuleManager();
+
+ // Endpoint Setup
+ iomAug1 = new IovisorModuleAugmentationBuilder().setUri(new Uri("10.10.10.10:10000")).build();
+ endpoint1 = new EndpointL3Builder().setTenant(tenant1)
+ .setL3Context(l3c1)
+ .setIpAddress(ipv41)
+ .setKey(ipv41Key)
+ .setEndpointGroups(epgs)
+ .setL3Address(l3Address1)
+ .addAugmentation(IovisorModuleAugmentation.class, iomAug1)
+ .build();
+
+ }
+
+ @Test
+ public void processEndpointTest() {
+ // Test if endpoint IovisorModule URI Augmentation does not already exist in datastore
+ IovisorModuleId iovisorModuleId =
+ new IovisorModuleId(endpoint1.getAugmentation(IovisorModuleAugmentation.class).getUri().getValue());
+ IovisorModuleInstance iovisorModule = iovisorModuleManager.getActiveIovisorModule(iovisorModuleId);
+ Assert.assertNull(iovisorModule);
+ endpointManager.processEndpoint(endpoint1);
+ iovisorModule = iovisorModuleManager.getActiveIovisorModule(iovisorModuleId);;
+ Assert.assertEquals(iovisorModuleId, iovisorModule.getId());
+ }
+
+ @Test
+ public void addIovisorResolvedEndpointTest() {
+ endpointManager.addIovisorResolvedEndpoint(endpoint1);
+ Optional<IovisorResolvedEndpointByTenantByEndpointgroupId> readFromDs =
+ DataStoreHelper
+ .readFromDs(LogicalDatastoreType.OPERATIONAL,
+ IovisorIidFactory.iovisorResolvedEndpointByTenantIdByEndpointGroupIdIid(
+ endpoint1.getTenant(), endpoint1.getEndpointGroups().get(0)),
+ dataBroker.newReadOnlyTransaction());
+ IovisorResolvedEndpointByTenantByEndpointgroupId iovisorResolvedEndpointByTenantByEndpointgroupId;
+ if (readFromDs.isPresent()) {
+ iovisorResolvedEndpointByTenantByEndpointgroupId = readFromDs.get();
+ } else {
+ iovisorResolvedEndpointByTenantByEndpointgroupId = null;
+ }
+ Assert.assertNotNull(iovisorResolvedEndpointByTenantByEndpointgroupId);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Inocybe Technologies 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.renderer.iovisor.module;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.renderer.iovisor.test.GbpIovisorDataBrokerTest;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.IovisorModuleId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.module.instances.IovisorModuleInstance;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.module.instances.IovisorModuleInstanceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.iovisor.module.instances.IovisorModuleInstanceKey;
+
+public class IovisorModuleManagerTest extends GbpIovisorDataBrokerTest {
+
+ private DataBroker dataBroker;
+ private IovisorModuleManager iovisorModuleManager;
+ IovisorModuleInstance iovisorModuleInstance1;
+ IovisorModuleInstance iovisorModuleInstance2;
+ IovisorModuleInstance badIovisorModuleInstance1;
+
+ @Before
+ public void initialisation() throws Exception {
+ dataBroker = getDataBroker();
+ iovisorModuleManager = new IovisorModuleManager(dataBroker);
+
+ String iom1 = "10.10.10.10:10000";
+ IovisorModuleId iom1Id = new IovisorModuleId(iom1);
+ String iom2 = "iom1.groupbasedpolicy.org:10000";
+ IovisorModuleId iom2Id = new IovisorModuleId(iom2);
+
+ String badIom1 = "10.10.10.10";
+ IovisorModuleId badIom1Id = new IovisorModuleId(badIom1);
+
+ iovisorModuleInstance1 = new IovisorModuleInstanceBuilder().setId(iom1Id)
+ .setKey(new IovisorModuleInstanceKey(iom1Id))
+ .setUri(new Uri(iom1))
+ .build();
+
+ iovisorModuleInstance2 = new IovisorModuleInstanceBuilder().setId(iom2Id)
+ .setKey(new IovisorModuleInstanceKey(iom2Id))
+ .setUri(new Uri(iom2))
+ .build();
+
+ badIovisorModuleInstance1 = new IovisorModuleInstanceBuilder().setId(badIom1Id)
+ .setKey(new IovisorModuleInstanceKey(badIom1Id))
+ .setUri(new Uri(badIom1))
+ .build();
+ }
+
+ @Test
+ public void addActiveIovisorModuleTest() {
+ Assert.assertFalse(iovisorModuleManager.addActiveIovisorModule(iovisorModuleInstance1.getId()));
+ Assert.assertTrue(iovisorModuleManager.addProvisionedIovisorModule(iovisorModuleInstance1));
+ Assert.assertTrue(iovisorModuleManager.addActiveIovisorModule(iovisorModuleInstance1.getId()));
+ }
+
+ @Test
+ public void addProvisionedIovisorModuleTest() {
+ Assert.assertTrue(iovisorModuleManager.addProvisionedIovisorModule(iovisorModuleInstance1));
+ Assert.assertFalse(iovisorModuleManager.addProvisionedIovisorModule(badIovisorModuleInstance1));
+ }
+
+ @Test
+ public void addIovisorInstanceTest() {
+ Assert.assertTrue(
+ iovisorModuleManager.addIovisorModule(iovisorModuleInstance1, LogicalDatastoreType.CONFIGURATION));
+ Assert.assertTrue(
+ iovisorModuleManager.addIovisorModule(iovisorModuleInstance1, LogicalDatastoreType.OPERATIONAL));
+
+ Assert.assertFalse(
+ iovisorModuleManager.addIovisorModule(badIovisorModuleInstance1, LogicalDatastoreType.CONFIGURATION));
+ Assert.assertFalse(
+ iovisorModuleManager.addIovisorModule(badIovisorModuleInstance1, LogicalDatastoreType.OPERATIONAL));
+ }
+
+ @Test
+ public void getActiveIovisorModuleTest() {
+ // Prepare a provisioned IOM
+ Assert.assertTrue(iovisorModuleManager.addProvisionedIovisorModule(iovisorModuleInstance1));
+ IovisorModuleInstance fetchedIom =
+ iovisorModuleManager.getProvisionedIovisorModule(iovisorModuleInstance1.getId());
+ Assert.assertEquals(iovisorModuleInstance1, fetchedIom);
+ // Its not Active yet
+ Assert.assertNull(iovisorModuleManager.getActiveIovisorModule(iovisorModuleInstance1.getId()));
+ Assert.assertTrue(iovisorModuleManager.addActiveIovisorModule(iovisorModuleInstance1.getId()));
+ Assert.assertEquals(iovisorModuleInstance1,
+ iovisorModuleManager.getActiveIovisorModule(iovisorModuleInstance1.getId()));
+
+ }
+
+ @Test
+ public void getProvisionedIovisorModuleTest() {
+ Assert.assertTrue(iovisorModuleManager.addProvisionedIovisorModule(iovisorModuleInstance1));
+ Assert.assertEquals(iovisorModuleInstance1,
+ iovisorModuleManager.getProvisionedIovisorModule(iovisorModuleInstance1.getId()));
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.renderer.iovisor.test;
+
+import static com.google.common.base.Preconditions.checkState;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import javax.annotation.Nonnull;
+
+import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
+import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
+import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSet.Builder;
+
+/**
+ * Loads only modules of GBP and it's dependencies for data broker.
+ * <br>
+ * Therefore this implementation is faster than {@link AbstractDataBrokerTest}
+ */
+public abstract class CustomDataBrokerTest extends AbstractDataBrokerTest {
+
+ @Override
+ protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
+ Builder<YangModuleInfo> moduleInfoSet = ImmutableSet.<YangModuleInfo>builder();
+ for (Class<?> clazz : getClassesFromModules()) {
+ loadModuleInfos(clazz, moduleInfoSet);
+ }
+ return moduleInfoSet.build();
+ }
+
+ /**
+ * @return a class from every yang module which needs to be loaded. Cannot return {@code null}
+ * or empty collection.
+ */
+ public abstract @Nonnull Collection<Class<?>> getClassesFromModules();
+
+ public static void loadModuleInfos(Class<?> clazzFromModule, Builder<YangModuleInfo> moduleInfoSet)
+ throws Exception {
+ YangModuleInfo moduleInfo = BindingReflections.getModuleInfo(clazzFromModule);
+ checkState(moduleInfo != null, "Module Info for %s is not available.", clazzFromModule);
+ collectYangModuleInfo(moduleInfo, moduleInfoSet);
+ }
+
+ private static void collectYangModuleInfo(final YangModuleInfo moduleInfo,
+ final Builder<YangModuleInfo> moduleInfoSet) throws IOException {
+ moduleInfoSet.add(moduleInfo);
+ for (YangModuleInfo dependency : moduleInfo.getImportedModules()) {
+ collectYangModuleInfo(dependency, moduleInfoSet);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.renderer.iovisor.test;
+
+import java.util.Collection;
+
+import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.Endpoints;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.IovisorModuleInstances;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.Tenants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.Renderers;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.ResolvedPolicies;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * Loads only modules of GBP and it's dependencies for data broker.
+ * <br>
+ * Therefore this implementation is faster than {@link AbstractDataBrokerTest}
+ */
+public class GbpIovisorDataBrokerTest extends CustomDataBrokerTest {
+
+ @Override
+ public Collection<Class<?>> getClassesFromModules() {
+ return ImmutableList.<Class<?>>of(Renderers.class, Tenants.class, Endpoints.class, ResolvedPolicies.class,
+ IovisorModuleInstances.class);
+ }
+
+}