<Export-Package>
org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.*,
org.opendaylight.controller.config.yang.config.endpoint_provider,
+ org.opendaylight.groupbasedpolicy.dto,
org.opendaylight.groupbasedpolicy.endpoint,
org.opendaylight.groupbasedpolicy.resolver.*,
org.opendaylight.groupbasedpolicy.sf.actions.*,
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.groupbasedpolicy.endpoint.EndpointRpcRegistry;
+import org.opendaylight.groupbasedpolicy.resolver.FollowedTenantListener;
+import org.opendaylight.groupbasedpolicy.resolver.PolicyResolver;
import org.opendaylight.groupbasedpolicy.sf.SubjectFeatureDefinitionProvider;
import org.opendaylight.groupbasedpolicy.sf.SupportedActionDefinitionListener;
import org.opendaylight.groupbasedpolicy.sf.SupportedClassifierDefinitionListener;
new SupportedClassifierDefinitionListener(dataProvider);
SupportedActionDefinitionListener supportedActionDefinitionListener =
new SupportedActionDefinitionListener(dataProvider);
+ PolicyResolver policyResolver = new PolicyResolver(dataProvider);
+ FollowedTenantListener followedTenantListener = new FollowedTenantListener(dataProvider, policyResolver);
@Override
public void close() throws Exception {
epRpcRegistry.close();
supportedClassifierDefinitionListener.close();
supportedActionDefinitionListener.close();
+ policyResolver.close();
+ followedTenantListener.close();
}
};
} catch (TransactionCommitFailedException e) {
--- /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.dto;
+
+
+/**
+ * Marker interface representing consumer endpoint-group key
+ */
+public interface ConsEpgKey extends EpgKey {
+
+}
--- /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.dto;
+
+import javax.annotation.Nonnull;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+
+public interface EpgKey {
+
+ /**
+ * @return ID of the endpoint-group; cannot be {@code null}
+ */
+ @Nonnull
+ EndpointGroupId getEpgId();
+
+ /**
+ * @return Tenant ID where is endpoint-group located; cannot be {@code null}
+ */
+ @Nonnull
+ TenantId getTenantId();
+
+}
--- /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.dto;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import javax.annotation.Nonnull;
+import javax.annotation.concurrent.Immutable;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+
+/**
+ * Represents provider endpoint-group key composed from ID and Tenant ID
+ */
+@Immutable
+public final class EpgKeyDto implements ConsEpgKey, ProvEpgKey {
+
+ private final EndpointGroupId epgId;
+ private final TenantId tenantId;
+
+ /**
+ * @param epgId endpoint-group ID
+ * @param tenantId tenant ID where EPG is located
+ * @throws NullPointerException if {@code epgId} or {@code tenantId} is null
+ */
+ public EpgKeyDto(@Nonnull EndpointGroupId epgId, @Nonnull TenantId tenantId) {
+ this.epgId = checkNotNull(epgId);
+ this.tenantId = checkNotNull(tenantId);
+ }
+
+ @Override
+ public EndpointGroupId getEpgId() {
+ return epgId;
+ }
+
+ @Override
+ public TenantId getTenantId() {
+ return tenantId;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((epgId == null) ? 0 : epgId.hashCode());
+ result = prime * result + ((tenantId == null) ? 0 : tenantId.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ EpgKeyDto other = (EpgKeyDto) obj;
+ if (epgId == null) {
+ if (other.epgId != null)
+ return false;
+ } else if (!epgId.equals(other.epgId))
+ return false;
+ if (tenantId == null) {
+ if (other.tenantId != null)
+ return false;
+ } else if (!tenantId.equals(other.tenantId))
+ return false;
+ return true;
+ }
+
+}
--- /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.dto;
+
+/**
+ * Marker interface representing provider endpoint-group key
+ */
+public interface ProvEpgKey extends EpgKey {
+
+}
import javax.annotation.concurrent.Immutable;
+import org.opendaylight.groupbasedpolicy.dto.EpgKeyDto;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
/**
* A tuple referencing an endpoint group and its enclosing tenant
+ * @deprecated use {@link EpgKeyDto}
* @author readams
*/
@Immutable
+@Deprecated
public class EgKey implements Comparable<EgKey> {
private final TenantId tenantId;
private final EndpointGroupId egId;
--- /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.resolver;
+
+import java.io.Closeable;
+import java.io.IOException;
+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.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+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;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.Interests;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.interests.FollowedTenants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.interests.followed.tenants.FollowedTenant;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+import com.google.common.collect.HashMultiset;
+import com.google.common.collect.Multiset;
+
+public class FollowedTenantListener implements DataTreeChangeListener<FollowedTenant>, Closeable {
+
+ private final PolicyResolver policyResolver;
+ private final ListenerRegistration<FollowedTenantListener> listenerRegistration;
+ private final Multiset<TenantId> countedFollowedTenants = HashMultiset.create();
+
+ public FollowedTenantListener(DataBroker dataProvider, PolicyResolver policyResolver) {
+ this.policyResolver = policyResolver;
+ listenerRegistration = dataProvider.registerDataTreeChangeListener(
+ new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
+ InstanceIdentifier.builder(Renderers.class)
+ .child(Renderer.class)
+ .child(Interests.class)
+ .child(FollowedTenants.class)
+ .child(FollowedTenant.class)
+ .build()),
+ this);
+ }
+
+ @Override
+ public void onDataTreeChanged(Collection<DataTreeModification<FollowedTenant>> changes) {
+ for (DataTreeModification<FollowedTenant> change : changes) {
+ DataObjectModification<FollowedTenant> rootNode = change.getRootNode();
+ TenantId tenantId = change.getRootPath().getRootIdentifier().firstKeyOf(FollowedTenant.class).getId();
+ switch (rootNode.getModificationType()) {
+ case WRITE:
+ policyResolver.subscribeTenant(tenantId);
+ countedFollowedTenants.add(tenantId);
+ break;
+ case DELETE:
+ countedFollowedTenants.remove(tenantId);
+ if (countedFollowedTenants.count(tenantId) == 0) {
+ policyResolver.unsubscribeTenant(tenantId);
+ }
+ break;
+ case SUBTREE_MODIFIED:
+ // NOOP
+ break;
+ }
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ if (listenerRegistration != null)
+ listenerRegistration.close();
+ }
+
+}
this.policyMap = policyMap;
this.egConditions = egConditions;
}
+
public Table<EgKey, EgKey, Policy> getPolicyMap() {
return policyMap;
}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.groupbasedpolicy.resolver;
-
-import java.util.Set;
-
-/**
- * An interface for an object that can listen for events related to group-based
- * policy resolution.
- * @author readams
- */
-public interface PolicyListener {
-
- /**
- * Indicates that the policy related to the set of endpoint groups
- * has changed
- * @param updatedGroups the set of endpoint groups involved
- * in a contract whose policy has changed
- */
- public void policyUpdated(Set<EgKey> updatedGroups);
-
-}
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.concurrent.Immutable;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.groupbasedpolicy.resolver.validator.ValidationResult;
import org.opendaylight.groupbasedpolicy.resolver.validator.Validator;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ActionDefinitionId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierDefinitionId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.Tenant;
-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.ResolvedPoliciesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.SubjectFeatureInstances;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.subject.feature.instances.ActionInstance;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.subject.feature.instances.ClassifierInstance;
+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.ResolvedPoliciesBuilder;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.LoggerFactory;
import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimaps;
import com.google.common.collect.SetMultimap;
-import com.google.common.collect.Sets;
import com.google.common.collect.Table;
-import com.google.common.collect.Table.Cell;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
-import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
-
/**
* The policy resolver is a utility for renderers to help in resolving
* group-based policy into a form that is easier to apply to the actual network.
private static final Logger LOG = LoggerFactory.getLogger(PolicyResolver.class);
private final DataBroker dataProvider;
- private final ScheduledExecutorService executor;
-
- /**
- * Keep track of the current relevant policy scopes.
- */
- protected CopyOnWriteArrayList<PolicyScope> policyListenerScopes;
protected ConcurrentMap<TenantId, TenantContext> resolvedTenants;
- /**
- * Store a policy object for each endpoint group pair. The table is stored
- * with the key as (consumer, provider). Two endpoints could appear in both
- * roles at the same time, in which case both policies would apply.
- */
- AtomicReference<PolicyInfo> policy = new AtomicReference<>();
-
/*
* Store validators for ActionDefinitions from Renderers
*
protected SetMultimap<ActionDefinitionId, Validator<ActionInstance>> actionInstanceValidatorsByDefinition = Multimaps.synchronizedSetMultimap(HashMultimap.<ActionDefinitionId, Validator<ActionInstance>>create());
protected SetMultimap<ClassifierDefinitionId, Validator<ClassifierInstance>> classifierInstanceValidatorsByDefinition = Multimaps.synchronizedSetMultimap(HashMultimap.<ClassifierDefinitionId, Validator<ClassifierInstance>>create());
- public PolicyResolver(DataBroker dataProvider,
- ScheduledExecutorService executor) {
- super();
+ public PolicyResolver(DataBroker dataProvider) {
this.dataProvider = dataProvider;
- this.executor = executor;
- policyListenerScopes = new CopyOnWriteArrayList<>();
resolvedTenants = new ConcurrentHashMap<>();
LOG.debug("Initialized renderer common policy resolver");
}
// *************************
// PolicyResolver public API
// *************************
- /**
- * Get a snapshot of the current policy
- *
- * @return the {@link PolicyInfo} object representing an immutable snapshot
- * of the policy state
- */
- public PolicyInfo getCurrentPolicy() {
- return policy.get();
- }
-
- /**
- * Get the normalized tenant for the given ID
- *
- * @param tenant the tenant ID
- * @return the {@link Tenant}
- */
- public IndexedTenant getTenant(TenantId tenant) {
- TenantContext tc = resolvedTenants.get(tenant);
- if (tc == null) {
- return null;
- }
- return tc.tenant.get();
- }
public void registerActionInstanceValidators(ActionDefinitionId actionDefinitionId,
Validator<ActionInstance> validator) {
classifierInstanceValidatorsByDefinition.remove(classifierDefinitionId, validator);
}
- /**
- * Register a listener to receive update events.
- *
- * @param listener the {@link PolicyListener} object to receive the update
- * events
- */
- public PolicyScope registerListener(PolicyListener listener) {
- PolicyScope ps = new PolicyScope(this, listener);
- policyListenerScopes.add(ps);
-
- return ps;
- }
-
- /**
- * Remove the listener registered for the given {@link PolicyScope}.
- *
- * @param scope the scope to remove
- * @see PolicyResolver#registerListener(PolicyListener)
- */
- public void removeListener(PolicyScope scope) {
- policyListenerScopes.remove(scope);
- }
-
- // **************
- // Implementation
- // **************
- /**
- * Atomically update the active policy and notify policy listeners of
- * relevant changes
- *
- * @param policyMap the new policy to set
- * @param egConditions the map of endpoint groups to relevant condition sets
- * @return the set of groups with updated policy
- */
- protected Set<EgKey> updatePolicy(Table<EgKey, EgKey, Policy> policyMap,
- Map<EgKey, Set<ConditionSet>> egConditions,
- List<PolicyScope> policyListenerScopes) {
- PolicyInfo newPolicy = new PolicyInfo(policyMap, egConditions);
- PolicyInfo oldPolicy = policy.getAndSet(newPolicy);
-
- HashSet<EgKey> notifySet = new HashSet<>();
-
- for (Cell<EgKey, EgKey, Policy> cell : newPolicy.getPolicyMap().cellSet()) {
- Policy newp = cell.getValue();
- Policy oldp = null;
- if (oldPolicy != null) {
- oldp = oldPolicy.getPolicyMap().get(cell.getRowKey(),
- cell.getColumnKey());
- }
- if (oldp == null || !newp.equals(oldp)) {
- notifySet.add(cell.getRowKey());
- notifySet.add(cell.getColumnKey());
- }
- }
- if (oldPolicy != null) {
- for (Cell<EgKey, EgKey, Policy> cell : oldPolicy.getPolicyMap().cellSet()) {
- if (!newPolicy.getPolicyMap().contains(cell.getRowKey(),
- cell.getColumnKey())) {
- notifySet.add(cell.getRowKey());
- notifySet.add(cell.getColumnKey());
- }
- }
- }
- return notifySet;
- }
-
- /**
- * Notify the policy listeners about a set of updated groups
- */
- private void notifyListeners(Set<EgKey> updatedGroups) {
- for (final PolicyScope scope : policyListenerScopes) {
- Set<EgKey> filtered
- = Sets.filter(updatedGroups, new Predicate<EgKey>() {
- @Override
- public boolean apply(EgKey input) {
- return scope.contains(input.getTenantId(),
- input.getEgId());
- }
- });
- if (!filtered.isEmpty()) {
- scope.getListener().policyUpdated(filtered);
- }
- }
- }
-
/**
* Subscribe the resolver to updates related to a particular tenant Make
* sure that this can't be called concurrently with subscribe
TenantUtils.tenantIid(tenantId),
new PolicyChangeListener(tenantId),
DataChangeScope.SUBTREE);
+ LOG.debug("Data change listener for tenant {} in CONF DS is registered.", tenantId.getValue());
context = new TenantContext(registration);
TenantContext oldContext
deleteOperTenantIfExists(tiid, tenantId);
return;
}
-
+ LOG.debug("Resolving of tenant inheritance and policy triggered by a change in tenant {}", tenantId);
Tenant t = InheritanceUtils.resolveTenant(result.get());
SubjectFeatureInstances subjectFeatureInstances = t.getSubjectFeatureInstances();
if (subjectFeatureInstances != null) {
public void onFailure(Throwable t) {
LOG.error("Count not get tenant {}", tenantId, t);
}
- }, executor);
+ });
}
private void deleteOperTenantIfExists(final InstanceIdentifier<Tenant> tiid, final TenantId tenantId) {
LOG.error("Failed to read operational datastore: {}", t);
rwTx.cancel();
}
- }, executor);
-
+ });
}
protected void updatePolicy() {
Map<EgKey, Set<ConditionSet>> egConditions = new HashMap<>();
Set<IndexedTenant> indexedTenants = getIndexedTenants(resolvedTenants.values());
Table<EgKey, EgKey, Policy> policyMap = PolicyResolverUtils.resolvePolicy(indexedTenants, egConditions);
- Set<EgKey> updatedGroups = updatePolicy(policyMap, egConditions, policyListenerScopes);
updatePolicyInDataStore(policyMap);
- //TODO the following will be removed when the policyInfo datastore is completed
- notifyListeners(updatedGroups);
} catch (Exception e) {
LOG.error("Failed to update policy", e);
}
LOG.error("Failed to write resolved policies to Datastore.");
}
}
+
private Set<IndexedTenant> getIndexedTenants(Collection<TenantContext> tenantCtxs) {
Set<IndexedTenant> result = new HashSet<>();
for (TenantContext tenant : tenantCtxs) {
* (3) resolve the set of in-scope contracts into a list of subjects that apply for each pair of
* endpoint groups and the conditions that can apply for for each endpoint in those groups.
*/
- protected static Table<EgKey, EgKey, Policy> resolvePolicy(Set<IndexedTenant> tenants,
+ public static Table<EgKey, EgKey, Policy> resolvePolicy(Set<IndexedTenant> tenants,
Map<EgKey, Set<ConditionSet>> egConditions) {
Preconditions.checkNotNull(tenants);
Preconditions.checkNotNull(egConditions);
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.groupbasedpolicy.resolver;
-
-import java.util.Collections;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
-
-/**
- * The policy scope object represents a scope for policy-related information.
- * A renderer that addresses a particular scope can express this as a
- * {@link PolicyScope} with an associates {@link PolicyListener} that can
- * receive relevant updates.
- * @see PolicyResolver
- * @author readams
- */
-public class PolicyScope {
-
- /**
- * The parent policy resolver
- */
- private final PolicyResolver resolver;
-
- /**
- * The listener for this policy scope
- */
- private final PolicyListener listener;
-
- /**
- * The set of policy scope elements that we want to listen to.
- */
- private Set<EgKey> scopeElements;
-
- public PolicyScope(PolicyResolver resolver,
- PolicyListener listener) {
- super();
- this.resolver = resolver;
- this.listener = listener;
- Map<EgKey,Boolean> smap = new ConcurrentHashMap<>();
- scopeElements = Collections.newSetFromMap(smap);
- }
-
- // ***********
- // PolicyScope
- // ***********
-
- /**
- * Add the endpoint group from the given tenant and endpoint group to the
- * scope of updates
- * @param tenant the tenant for the endpoint group
- * @param endpointGroup the endpoint group to add. This is the consumer
- * of the contract
- */
- public void addToScope(TenantId tenant, EndpointGroupId endpointGroup) {
- synchronized (this) {
- scopeElements.add(new EgKey(tenant, endpointGroup));
- resolver.subscribeTenant(tenant);
- }
- }
-
- /**
- * Add all endpoint groups in the given tenant to the scope of updates
- * @param tenant the tenant to add.
- */
- public void addToScope(TenantId tenant) {
- addToScope(tenant, null);
- }
-
- /**
- * Remove an endpoint group from the given tenant and endpoint group from
- * the scope of updates
- * @param tenant the tenant for the endpoint group
- * @param endpointGroup the endpoint group to remove. This is the consumer
- * of the contract
- */
- public void removeFromScope(TenantId tenant,
- EndpointGroupId endpointGroup) {
- synchronized (this) {
- boolean canUnsubscribe = true;
- scopeElements.remove(new EgKey(tenant, endpointGroup));
- for (EgKey element : scopeElements) {
- if (element.getTenantId().equals(tenant)) {
- canUnsubscribe = false;
- break;
- }
- }
- if (canUnsubscribe) {
- resolver.unsubscribeTenant(tenant);
- }
- }
- }
-
- /**
- * Remove an endpoint group from the given tenant from
- * the scope of updates
- * @param tenant the tenant for the endpoint group
- */
- public void removeFromScope(TenantId tenant) {
- removeFromScope(tenant, null);
- }
-
- /**
- * Check whether the policy scope applies to the given tenant and endpoint
- * group
- * @param tenant the tenant to look up
- * @param endpointGroup the endpoint group to look up. May be null,
- * in which case will only check if the policy scope applies to the entire
- * tenant
- * @return <code>true</code> if the policy scope applies to the given
- * tenant and endpoint group.
- */
- public boolean contains(TenantId tenant, EndpointGroupId endpointGroup) {
- EgKey pse = new EgKey(tenant, endpointGroup);
- if (scopeElements.contains(pse)) return true;
- pse = new EgKey(tenant, null);
- return scopeElements.contains(pse);
-
- }
-
- /**
- * Get the policy listener for this scope
- * @return the policy listener
- */
- public PolicyListener getListener() {
- return listener;
- }
-}
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.subject.feature.instances.ActionInstanceKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.subject.feature.instances.ClassifierInstance;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.subject.feature.instances.ClassifierInstanceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.RendererName;
+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;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.RendererKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.Interests;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.interests.FollowedTenants;
+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.FollowedTenantKey;
+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.FollowedEndpointGroupKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
public class IidFactory {
.build();
}
+ public static InstanceIdentifier<FollowedEndpointGroup> followedEndpointgroupIid(RendererName rendererName,
+ TenantId tenantId, EndpointGroupId epgId) {
+ return InstanceIdentifier.builder(Renderers.class)
+ .child(Renderer.class, new RendererKey(rendererName))
+ .child(Interests.class)
+ .child(FollowedTenants.class)
+ .child(FollowedTenant.class, new FollowedTenantKey(tenantId))
+ .child(FollowedEndpointGroup.class, new FollowedEndpointGroupKey(epgId))
+ .build();
+ }
}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.groupbasedpolicy.resolver;
-
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.Tenant;
-
-
-/**
- * Mock version of policy resolver useful for tests
- * @author readams
- */
-public class MockPolicyResolver extends PolicyResolver {
-
- public MockPolicyResolver() {
- super(null, null);
- }
-
- public void addTenant(Tenant unresolvedTenant) {
- TenantContext context = new TenantContext(null);
- Tenant t = InheritanceUtils.resolveTenant(unresolvedTenant);
- IndexedTenant it = new IndexedTenant(t);
- context.tenant.set(it);
- resolvedTenants.put(unresolvedTenant.getId(), context);
-
- updatePolicy();
- }
-}
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.ScheduledExecutorService;
import org.junit.Assert;
import org.junit.Before;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import com.google.common.base.Optional;
-import com.google.common.collect.HashBasedTable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Table;
private PolicyResolver policyResolver;
private DataBroker dataProvider;
- private ScheduledExecutorService executor;
- private PolicyListener policyListener;
private ReadOnlyTransaction readTransaction;
private CheckedFuture<Optional<Tenant>, ReadFailedException> unresolved;
- private Table<EgKey, EgKey, Policy> policyMap;
- private Map<EgKey, Set<ConditionSet>> egConditions;
- private List<PolicyScope> policyListenerScopes;
-
@SuppressWarnings("unchecked")
@Before
public void initialisePolicyResolver() {
dataProvider = mock(DataBroker.class);
- executor = mock(ScheduledExecutorService.class);
readTransaction = mock(ReadOnlyTransaction.class);
when(dataProvider.newReadOnlyTransaction()).thenReturn(readTransaction);
unresolved = mock(CheckedFuture.class);
when(readTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(
unresolved);
- policyResolver = spy(new PolicyResolver(dataProvider, executor));
-
- policyMap = HashBasedTable.create();
- egConditions = new HashMap<EgKey, Set<ConditionSet>>();
- policyListenerScopes = new ArrayList<PolicyScope>();
- policyListener = mock(PolicyListener.class);
- policyResolver.registerListener(policyListener);
- }
-
- @Test
- public void updatePolicyTest() {
- EgKey oldRowKey = mock(EgKey.class);
- EgKey oldColumnKey = mock(EgKey.class);
- Policy oldPolicy = mock(Policy.class);
- policyMap.put(oldRowKey, oldColumnKey, oldPolicy);
-
- Set<EgKey> notifySet;
- notifySet = policyResolver.updatePolicy(policyMap, egConditions, policyListenerScopes);
- Assert.assertTrue(notifySet.contains(oldRowKey));
- Assert.assertTrue(notifySet.contains(oldColumnKey));
-
- EgKey newRowKey = mock(EgKey.class);
- EgKey newColumnKey = mock(EgKey.class);
- Policy newPolicy = mock(Policy.class);
-
- policyMap = HashBasedTable.create();
- policyMap.put(newRowKey, newColumnKey, newPolicy);
-
- notifySet = policyResolver.updatePolicy(policyMap, egConditions, policyListenerScopes);
- Assert.assertTrue(notifySet.contains(oldRowKey));
- Assert.assertTrue(notifySet.contains(oldColumnKey));
- Assert.assertTrue(notifySet.contains(newRowKey));
- Assert.assertTrue(notifySet.contains(newColumnKey));
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void updatePolicy2Test() {
- policyResolver.updatePolicy();
- verify(policyResolver).updatePolicy(any(Table.class), any(Map.class), any(List.class));
+ policyResolver = spy(new PolicyResolver(dataProvider));
}
@Before
public void setup() throws Exception {
- resolver = new PolicyResolver(null, null);
- }
-
- @Test
- public void listenerTest() {
- PolicyScope policyScope;
- PolicyListener policyListener = mock(PolicyListener.class);
- Assert.assertTrue(resolver.policyListenerScopes.isEmpty());
-
- policyScope = resolver.registerListener(policyListener);
- Assert.assertNotNull(policyScope);
- Assert.assertFalse(resolver.policyListenerScopes.isEmpty());
-
- resolver.removeListener(policyScope);
- Assert.assertTrue(resolver.policyListenerScopes.isEmpty());
+ resolver = new PolicyResolver(null);
}
@SuppressWarnings({"unchecked", "rawtypes"})
@Test
public void tenantTest() {
DataBroker dataProvider = mock(DataBroker.class);
- ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
- resolver = new PolicyResolver(dataProvider, executor);
+ resolver = new PolicyResolver(dataProvider);
TenantId tenantId = mock(TenantId.class);
Assert.assertTrue(resolver.resolvedTenants.isEmpty());
+++ /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.resolver;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
-
-public class PolicyScopeTest {
-
- private PolicyScope policyScope;
- private PolicyResolver resolver;
- private PolicyListener listener;
-
- @Before
- public void initialisation() {
- resolver = mock(PolicyResolver.class);
- listener = mock(PolicyListener.class);
- policyScope = new PolicyScope(resolver, listener);
- }
-
- @Test
- public void constructorTest() {
- Assert.assertEquals(listener, policyScope.getListener());
- }
-
- @Test
- public void tenantTest() {
- TenantId tenantId = mock(TenantId.class);
-
- policyScope.addToScope(tenantId);
- verify(resolver).subscribeTenant(tenantId);
- Assert.assertTrue(policyScope.contains(tenantId, null));
-
- policyScope.removeFromScope(tenantId);
- verify(resolver).unsubscribeTenant(tenantId);
- Assert.assertFalse(policyScope.contains(tenantId, null));
- }
-
- @Test
- public void TenantEndpointGroupTest() {
- TenantId tenantId = mock(TenantId.class);
- EndpointGroupId endpointGroupId = mock(EndpointGroupId.class);
-
- policyScope.addToScope(tenantId, endpointGroupId);
- verify(resolver).subscribeTenant(tenantId);
- Assert.assertTrue(policyScope.contains(tenantId, endpointGroupId));
-
- policyScope.removeFromScope(tenantId, endpointGroupId);
- verify(resolver).unsubscribeTenant(tenantId);
- Assert.assertFalse(policyScope.contains(tenantId, endpointGroupId));
- }
-
- @Test
- public void removeFromScopeTestUnsubscribeFalse() {
- TenantId tenantId = mock(TenantId.class);
- EndpointGroupId endpointGroupId1 = mock(EndpointGroupId.class);
- EndpointGroupId endpointGroupId2 = mock(EndpointGroupId.class);
-
- policyScope.addToScope(tenantId, endpointGroupId1);
- policyScope.addToScope(tenantId, endpointGroupId2);
- verify(resolver, times(2)).subscribeTenant(tenantId);
- Assert.assertTrue(policyScope.contains(tenantId, endpointGroupId1));
- Assert.assertTrue(policyScope.contains(tenantId, endpointGroupId2));
-
- policyScope.removeFromScope(tenantId, endpointGroupId1);
- verify(resolver, never()).unsubscribeTenant(tenantId);
- Assert.assertFalse(policyScope.contains(tenantId, endpointGroupId1));
- Assert.assertTrue(policyScope.contains(tenantId, endpointGroupId2));
- }
-}
import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayConfig;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayConfigBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.RendererName;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
public class OFOverlayRenderer implements AutoCloseable, DataChangeListener {
private static final Logger LOG =
LoggerFactory.getLogger(OFOverlayRenderer.class);
- public static final String RENDERER_NAME = "OFOverlay";
+ public static final RendererName RENDERER_NAME = new RendererName("OFOverlay");
private final DataBroker dataBroker;
private final PolicyResolver policyResolver;
switchManager = new SwitchManager(dataProvider);
endpointManager = new EndpointManager(dataProvider, rpcRegistry, notificationService,
executor, switchManager);
- policyResolver = new PolicyResolver(dataProvider, executor);
+ policyResolver = new PolicyResolver(dataProvider);
classifierDefinitionListener = new ClassifierDefinitionListener(dataBroker);
actionDefinitionListener = new ActionDefinitionListener(dataProvider);
+ // TODO we need register action/classifier validators to gpb-base
+
policyManager = new PolicyManager(dataProvider,
- policyResolver,
switchManager,
endpointManager,
rpcRegistry,
if (actionDefinitionListener != null) actionDefinitionListener.close();
if (ofOverlayAug != null) ofOverlayAug.close();
if (ofOverlayL3NatAug != null) ofOverlayL3NatAug.close();
+ if (policyManager != null) policyManager.close();
}
// ******************
/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ * 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,
package org.opendaylight.groupbasedpolicy.renderer.ofoverlay;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ScheduledExecutorService;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.EndpointManager;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyResolver;
+import org.opendaylight.groupbasedpolicy.resolver.ConditionSet;
+import org.opendaylight.groupbasedpolicy.resolver.EgKey;
+import org.opendaylight.groupbasedpolicy.resolver.IndexedTenant;
+import org.opendaylight.groupbasedpolicy.resolver.InheritanceUtils;
+import org.opendaylight.groupbasedpolicy.resolver.Policy;
+import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
+import org.opendaylight.groupbasedpolicy.resolver.PolicyResolverUtils;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.Tenants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.Tenant;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Optional;
+import com.google.common.collect.Table;
public class OfContext {
- private final DataBroker dataBroker;
- private final RpcProviderRegistry rpcRegistry;
+ private static final Logger LOG = LoggerFactory.getLogger(OfContext.class);
+ private static final InstanceIdentifier<Tenants> TENANTS_IID = InstanceIdentifier.builder(Tenants.class).build();
+ private final DataBroker dataBroker;
private final PolicyManager policyManager;
private final SwitchManager switchManager;
private final EndpointManager epManager;
-
- private final PolicyResolver policyResolver;
+ private final Map<TenantId, IndexedTenant> resolvedTenants = new HashMap<>();
+ private PolicyInfo policyInfo;
private final ScheduledExecutorService executor;
- public OfContext(DataBroker dataBroker,
- RpcProviderRegistry rpcRegistry,
- PolicyManager policyManager,
- PolicyResolver policyResolver,
- SwitchManager switchManager,
- EndpointManager endpointManager,
- ScheduledExecutorService executor) {
+ public OfContext(DataBroker dataBroker, PolicyManager policyManager, SwitchManager switchManager,
+ EndpointManager endpointManager, ScheduledExecutorService executor) {
this.dataBroker = dataBroker;
- this.rpcRegistry = rpcRegistry;
this.policyManager = policyManager;
this.switchManager = switchManager;
this.epManager = endpointManager;
- this.policyResolver = policyResolver;
this.executor = executor;
+ if (dataBroker == null) {
+ LOG.error("DataBroker is null. Cannot read resolved tenants and resolved policy from DS.");
+ } else {
+ ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();
+ Optional<Tenants> potentialTenants =
+ DataStoreHelper.readFromDs(LogicalDatastoreType.OPERATIONAL, TENANTS_IID, rTx);
+ if (potentialTenants.isPresent() && potentialTenants.get().getTenant() != null) {
+ for (Tenant tenant : potentialTenants.get().getTenant()) {
+ resolvedTenants.put(tenant.getId(), new IndexedTenant(tenant));
+ }
+ // TODO we should read resolved-policy from DS instead of this
+ policyInfo = resolvePolicy(resolvedTenants);
+ }
+ rTx.close();
+ }
+ }
+
+ @VisibleForTesting
+ void addTenantAndResolvePolicy(Tenant unresolvedTenant) {
+ Tenant t = InheritanceUtils.resolveTenant(unresolvedTenant);
+ IndexedTenant it = new IndexedTenant(t);
+ resolvedTenants.put(unresolvedTenant.getId(), it);
+ policyInfo = resolvePolicy(resolvedTenants);
+ }
+
+ private static PolicyInfo resolvePolicy(Map<TenantId, IndexedTenant> resolvedTenants) {
+ if (resolvedTenants.isEmpty()) {
+ return null;
+ }
+ Map<EgKey, Set<ConditionSet>> egConditions = new HashMap<>();
+ Table<EgKey, EgKey, Policy> resolvePolicy =
+ PolicyResolverUtils.resolvePolicy(getIndexedTenants(resolvedTenants.values()), egConditions);
+ return new PolicyInfo(resolvePolicy, egConditions);
+ }
+
+ private static Set<IndexedTenant> getIndexedTenants(Collection<IndexedTenant> tenants) {
+ Set<IndexedTenant> result = new HashSet<>();
+ for (IndexedTenant t : tenants) {
+ if (t != null) {
+ result.add(t);
+ }
+ }
+ return result;
}
public PolicyManager getPolicyManager() {
return this.epManager;
}
- public PolicyResolver getPolicyResolver() {
- return this.policyResolver;
- }
-
public DataBroker getDataBroker() {
return this.dataBroker;
}
- public RpcProviderRegistry getRpcRegistry() {
- return this.rpcRegistry;
+ public IndexedTenant getTenant(TenantId tenant) {
+ return resolvedTenants.get(tenant);
+ }
+
+ /**
+ * Get a snapshot of the current policy
+ *
+ * @return the {@link PolicyInfo} object representing an immutable snapshot
+ * of the policy state
+ */
+ public PolicyInfo getCurrentPolicy() {
+ return policyInfo;
}
public ScheduledExecutorService getExecutor() {
package org.opendaylight.groupbasedpolicy.renderer.ofoverlay;
+import java.io.Closeable;
+import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
-import java.util.Map.Entry;
-import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableList;
-import com.google.common.util.concurrent.AsyncFunction;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
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.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.groupbasedpolicy.endpoint.EpKey;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.SourceMapper;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchListener;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.Action;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.SubjectFeatures;
import org.opendaylight.groupbasedpolicy.resolver.EgKey;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyListener;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyResolver;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyScope;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+import org.opendaylight.groupbasedpolicy.util.IidFactory;
import org.opendaylight.groupbasedpolicy.util.SingletonTask;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ActionDefinitionId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayConfig.LearningMode;
+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.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
+import com.google.common.util.concurrent.AsyncFunction;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+
/**
* Manage policies on switches by subscribing to updates from the
* policy resolver and information about endpoints from the endpoint
* registry
*/
public class PolicyManager
- implements SwitchListener, PolicyListener, EndpointListener {
+ implements SwitchListener, EndpointListener, DataTreeChangeListener<ResolvedPolicy>, Closeable {
private static final Logger LOG =
LoggerFactory.getLogger(PolicyManager.class);
private static final short TABLEID_EXTERNAL_MAPPER = 6;
private final SwitchManager switchManager;
- private final PolicyResolver policyResolver;
+ private final EndpointManager endpointManager;
- private final PolicyScope policyScope;
+ private final ListenerRegistration<PolicyManager> registerDataTreeChangeListener;
private final ScheduledExecutorService executor;
private final SingletonTask flowUpdateTask;
private final DataBroker dataBroker;
- private final OfContext ofCtx;
- /**
- * The flow tables that make up the processing pipeline
- */
- private List<? extends OfTable> flowPipeline;
/**
* The delay before triggering the flow update task in response to an
private final static int FLOW_UPDATE_DELAY = 250;
public PolicyManager(DataBroker dataBroker,
- PolicyResolver policyResolver,
SwitchManager switchManager,
EndpointManager endpointManager,
RpcProviderRegistry rpcRegistry,
super();
this.switchManager = switchManager;
this.executor = executor;
- this.policyResolver = policyResolver;
this.dataBroker = dataBroker;
this.tableOffset = tableOffset;
try {
+ "Max. table ID would be out of range. Check config-subsystem.\n{}", e);
}
- for(Entry<ActionDefinitionId, Action> entry : SubjectFeatures.getActions().entrySet()) {
- policyResolver.registerActionInstanceValidators(entry.getKey(), entry.getValue());
+ if (dataBroker != null) {
+ registerDataTreeChangeListener = dataBroker.registerDataTreeChangeListener(
+ new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
+ InstanceIdentifier.builder(ResolvedPolicies.class).child(ResolvedPolicy.class).build()),
+ this);
+ } else {
+ registerDataTreeChangeListener = null;
+ LOG.error("DataBroker is null. Listener for {} was not registered.",
+ ResolvedPolicy.class.getCanonicalName());
}
-
- ofCtx = new OfContext(dataBroker, rpcRegistry,
- this, policyResolver, switchManager,
- endpointManager, executor);
-
- flowPipeline = createFlowPipeline();
-
- policyScope = policyResolver.registerListener(this);
if (switchManager != null)
switchManager.registerListener(this);
+ this.endpointManager = endpointManager;
endpointManager.registerListener(this);
flowUpdateTask = new SingletonTask(executor, new FlowUpdateTask());
LOG.debug("Initialized OFOverlay policy manager");
}
- private List<? extends OfTable> createFlowPipeline() {
+ private List<? extends OfTable> createFlowPipeline(OfContext ofCtx) {
// TODO - PORTSECURITY is kept in table 0.
// According to openflow spec,processing on vSwitch always starts from table 0.
// Packets will be droped if table 0 is empty.
@Override
public Void apply(Void tablesRemoved) {
- flowPipeline = createFlowPipeline();
scheduleUpdate();
return null;
}
@Override
public void groupEndpointUpdated(EgKey egKey, EpKey epKey) {
- policyScope.addToScope(egKey.getTenantId(), egKey.getEgId());
+ // 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(egKey.getEgId()).build();
+ wTx.put(LogicalDatastoreType.OPERATIONAL, IidFactory.followedEndpointgroupIid(OFOverlayRenderer.RENDERER_NAME,
+ egKey.getTenantId(), egKey.getEgId()), followedEpg, true);
+ DataStoreHelper.submitToDs(wTx);
scheduleUpdate();
}
// **************
- // PolicyListener
+ // DataTreeChangeListener<ResolvedPolicy>
// **************
@Override
- public void policyUpdated(Set<EgKey> updatedConsumers) {
+ public void onDataTreeChanged(Collection<DataTreeModification<ResolvedPolicy>> changes) {
scheduleUpdate();
}
* Update the flows on a particular switch
*/
private class SwitchFlowUpdateTask implements Callable<Void> {
- private OfWriter ofWriter;
+ private final OfWriter ofWriter;
public SwitchFlowUpdateTask(OfWriter ofWriter) {
- super();
this.ofWriter = ofWriter;
}
@Override
public Void call() throws Exception {
+ OfContext ofCtx = new OfContext(dataBroker, PolicyManager.this, switchManager, endpointManager, executor);
+ if (ofCtx.getCurrentPolicy() == null)
+ return null;
+ List<? extends OfTable> flowPipeline = createFlowPipeline(ofCtx);
for (NodeId node : switchManager.getReadySwitches()) {
- PolicyInfo info = policyResolver.getCurrentPolicy();
- if (info == null)
- return null;
for (OfTable table : flowPipeline) {
try {
- table.update(node, info, ofWriter);
+ table.sync(node, ofWriter);
} catch (Exception e) {
LOG.error("Failed to write Openflow table {}",
table.getClass().getSimpleName(), e);
}
}
-
-
-
+ @Override
+ public void close() throws IOException {
+ if (registerDataTreeChangeListener != null)
+ registerDataTreeChangeListener.close();
+ // TODO unregister classifier and action instance validators
+ }
}
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.OrdinalFactory.EndpointFwdCtxOrdinals;
import org.opendaylight.groupbasedpolicy.resolver.EgKey;
import org.opendaylight.groupbasedpolicy.resolver.IndexedTenant;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
import org.opendaylight.groupbasedpolicy.resolver.TenantUtils;
import org.opendaylight.groupbasedpolicy.util.IidFactory;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
}
@Override
- public void sync(NodeId nodeId, PolicyInfo policyInfo, OfWriter ofWriter) throws Exception {
+ public void sync(NodeId nodeId, OfWriter ofWriter) throws Exception {
TenantId currentTenant = null;
for (EndpointGroupId epgId : srcEpgIds) {
EgKey epg = new EgKey(srcEp.getTenant(), epgId);
- Set<EgKey> peers = Sets.union(Collections.singleton(epg), policyInfo.getPeers(epg));
+ Set<EgKey> peers = Sets.union(Collections.singleton(epg), ctx.getCurrentPolicy().getPeers(epg));
for (EgKey peer : peers) {
for (Endpoint peerEp : ctx.getEndpointManager().getEndpointsForGroup(peer)) {
currentTenant = peerEp.getTenant();
if (visitedEps.get(srcEpKey) != null && visitedEps.get(srcEpKey).contains(peerEpKey)) {
continue;
}
- syncEP(ofWriter, nodeId, policyInfo, srcEp, peerEp);
+ syncEP(ofWriter, nodeId, srcEp, peerEp);
visitedEps.put(srcEpKey, peerEpKey);
// Process subnets and flood-domains for epPeer
- EndpointFwdCtxOrdinals epOrds = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, policyInfo,
+ EndpointFwdCtxOrdinals epOrds = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx,
peerEp);
if (epOrds == null) {
LOG.debug("getEndpointFwdCtxOrdinals is null for EP {}", peerEp);
continue;
}
for (Subnet localSubnet: localSubnets) {
- Flow prefixFlow = createL3PrefixFlow(prefixEp, policyInfo, nodeId, localSubnet);
+ Flow prefixFlow = createL3PrefixFlow(prefixEp, nodeId, localSubnet);
if (prefixFlow != null) {
ofWriter.writeFlow(nodeId, TABLE_ID, prefixFlow);
LOG.trace("Wrote L3Prefix flow");
// set up next-hop destinations for all the endpoints in the endpoint
// group on the node
- private Flow createL3PrefixFlow(EndpointL3Prefix prefixEp, PolicyInfo policyInfo, NodeId nodeId, Subnet subnet) throws Exception {
+ private Flow createL3PrefixFlow(EndpointL3Prefix prefixEp, NodeId nodeId, Subnet subnet) throws Exception {
/*
* Priority: 100+lengthprefix
* Match: prefix, l3c, "mac address of router" ?
return null;
}
Endpoint l2Ep = optL2Ep.get();
- EndpointFwdCtxOrdinals epFwdCtxOrds = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, policyInfo, l2Ep);
+ EndpointFwdCtxOrdinals epFwdCtxOrds = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, l2Ep);
if (epFwdCtxOrds == null) {
LOG.debug("getEndpointFwdCtxOrdinals is null for EP {}", l2Ep);
return null;
}
private L3Context getL3ContextForSubnet(TenantId tenantId, Subnet sn) {
- IndexedTenant indexedTenant = ctx.getPolicyResolver().getTenant(tenantId);
+ IndexedTenant indexedTenant = ctx.getTenant(tenantId);
if (indexedTenant == null) {
LOG.debug("Tenant {} is null, cannot get L3 context", tenantId);
return null;
return flowb.build();
}
- private void syncEP(OfWriter ofWriter, NodeId nodeId, PolicyInfo policyInfo, Endpoint srcEp, Endpoint destEp)
+ private void syncEP(OfWriter ofWriter, NodeId nodeId, Endpoint srcEp, Endpoint destEp)
throws Exception {
- if (ctx.getPolicyResolver().getTenant(srcEp.getTenant()) == null
- || ctx.getPolicyResolver().getTenant(destEp.getTenant()) == null) {
+ if (ctx.getTenant(srcEp.getTenant()) == null
+ || ctx.getTenant(destEp.getTenant()) == null) {
LOG.debug("Source or destination EP references empty tenant srcEp:{} destEp:{}", srcEp, destEp);
return;
}
// TODO: Conditions messed up, but for now, send policyInfo until this
// is fixed.
- EndpointFwdCtxOrdinals destEpFwdCtxOrds = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, policyInfo, destEp);
+ EndpointFwdCtxOrdinals destEpFwdCtxOrds = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, destEp);
if (destEpFwdCtxOrds == null) {
LOG.debug("getEndpointFwdCtxOrdinals is null for EP {}", destEp);
return;
}
- EndpointFwdCtxOrdinals srcEpFwdCtxOrds = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, policyInfo, srcEp);
+ EndpointFwdCtxOrdinals srcEpFwdCtxOrds = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, srcEp);
if (srcEpFwdCtxOrds == null) {
LOG.debug("getEndpointFwdCtxOrdinals is null for EP {}", srcEp);
return;
* which we can't do because of the backwards way endpoints were
* "architected".
*/
- return ctx.getPolicyResolver()
- .getTenant(endpoint.getTenant())
+ return ctx.getTenant(endpoint.getTenant())
.getEndpointGroup(endpoint.getEndpointGroup())
.getNetworkDomain();
}
import java.util.Collection;
import java.util.List;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.RegMatch;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
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.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
}
@Override
- public void sync(NodeId nodeId, PolicyInfo policyInfo, OfWriter ofWriter) throws Exception {
+ public void sync(NodeId nodeId, OfWriter ofWriter) throws Exception {
ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(1), null, TABLE_ID));
Collection<EndpointL3> l3Endpoints = ctx.getEndpointManager().getL3EndpointsWithNat();
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
}
@Override
- public void sync(NodeId nodeId, PolicyInfo policyInfo, OfWriter ofWriter) throws Exception {
+ public void sync(NodeId nodeId, OfWriter ofWriter) throws Exception {
if (ctx.getSwitchManager().getExternalPorts(nodeId) == null) {
LOG.trace("No external ports found for node: {}", nodeId);
package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
super(ctx);
}
- // *******
- // OfTable
- // *******
-
- @Override
- public void update(NodeId nodeId, PolicyInfo policyInfo,
- OfWriter ofWriter) throws Exception {
-
- sync(nodeId, policyInfo, ofWriter);
-
- }
-
- // *********
- // FlowTable
- // *********
-
- /**
- * Sync flow state using the flow map
- *
- * @param nodeId the node id
- * @param policyInfo the current policy snapshot
- * @param ofWriter the {@link OfWriter}
- * @throws Exception throws all exception
- */
- public abstract void sync(NodeId nodeId, PolicyInfo policyInfo, OfWriter ofWriter) throws Exception;
-
/**
* Get the table ID being manipulated
*
import java.util.Set;
import java.util.concurrent.ExecutionException;
-import com.google.common.base.Optional;
-
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.OrdinalFactory.EndpointFwdCtxOrdinals;
import org.opendaylight.groupbasedpolicy.resolver.EgKey;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
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.action.types.rev131112.action.Action;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.Optional;
+
/**
* Manage the group tables for handling broadcast/multicast
*/
}
@Override
- public void update(NodeId nodeId, PolicyInfo policyInfo, OfWriter ofWriter) throws Exception {
+ public void sync(NodeId nodeId, OfWriter ofWriter) throws Exception {
// there appears to be no way of getting only the existing group
// tables unfortunately, so we have to get the whole goddamned node.
// Since this is happening concurrently with other things that are
if (fcn == null)
return;
- sync(nodeId, policyInfo, ofWriter);
- }
-
- public void sync(NodeId nodeId, PolicyInfo policyInfo, OfWriter ofWriter) throws Exception {
-
for (Endpoint localEp : ctx.getEndpointManager().getEndpointsForNode(nodeId)) {
EndpointFwdCtxOrdinals localEpFwdCtxOrds =
- OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, policyInfo, localEp);
+ OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, localEp);
if (localEpFwdCtxOrds == null) {
LOG.debug("getEndpointFwdCtxOrdinals is null for EP {}", localEp);
continue;
// we'll use the fdId with the high bit set for remote bucket
// and just the local port number for local bucket
- for (NodeId destNode : findPeerNodesForGroup(policyInfo, epg)) {
+ for (NodeId destNode : findPeerNodesForGroup(epg)) {
if (nodeId.equals(destNode))
continue;
- if(isFloodDomainOnNode(localEpFwdCtxOrds.getFdId(), destNode, policyInfo)) {
+ if(isFloodDomainOnNode(localEpFwdCtxOrds.getFdId(), destNode)) {
long bucketId = OrdinalFactory.getContextOrdinal(destNode);
bucketId |= 1L << 31;
}
/**
- * @param policyInfo to read peer groups for a group
* @param sourceEpgKey a key of source group
* @return all the nodes on which endpoints are either in groups that have policy with source
* group, or are in the source group
*/
- private Set<NodeId> findPeerNodesForGroup(PolicyInfo policyInfo, EgKey sourceEpgKey) {
+ private Set<NodeId> findPeerNodesForGroup(EgKey sourceEpgKey) {
Set<NodeId> nodes = new HashSet<NodeId>();
nodes.addAll(ctx.getEndpointManager().getNodesForGroup(sourceEpgKey));
- for (EgKey dstEpgs : policyInfo.getPeers(sourceEpgKey)) {
+ for (EgKey dstEpgs : ctx.getCurrentPolicy().getPeers(sourceEpgKey)) {
nodes.addAll(ctx.getEndpointManager().getNodesForGroup(dstEpgs));
}
return nodes;
}
- private boolean isFloodDomainOnNode(int fdId, NodeId node, PolicyInfo policyInfo) throws Exception {
+ private boolean isFloodDomainOnNode(int fdId, NodeId node) throws Exception {
for (Endpoint ep : ctx.getEndpointManager().getEndpointsForNode(node)) {
- int epFdId = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, policyInfo, ep).getFdId();
+ int epFdId = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, ep).getFdId();
if (fdId == epFdId) {
return true;
}
import java.util.List;
import org.opendaylight.groupbasedpolicy.endpoint.EpKey;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.OrdinalFactory.EndpointFwdCtxOrdinals;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
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.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
}
@Override
- public void sync(NodeId nodeId, PolicyInfo policyInfo, OfWriter ofWriter) throws Exception {
+ public void sync(NodeId nodeId, OfWriter ofWriter) throws Exception {
ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(1), null, TABLE_ID));
if (l3Ep.getL2Context() != null && l3Ep.getMacAddress() !=null ) {
Endpoint ep = ctx.getEndpointManager().getEndpoint(new EpKey(l3Ep.getL2Context(), l3Ep.getMacAddress()));
if (endpointsForNode.contains(ep)) {
- createNatFlow(l3Ep, nodeId, ofWriter, policyInfo);
+ createNatFlow(l3Ep, nodeId, ofWriter);
}
}
}
}
- private void createNatFlow(EndpointL3 l3Ep, NodeId nodeId, OfWriter ofWriter, PolicyInfo policyInfo) throws Exception {
+ private void createNatFlow(EndpointL3 l3Ep, NodeId nodeId, OfWriter ofWriter) throws Exception {
List<NaptTranslation> naptAugL3Endpoint = ctx.getEndpointManager().getNaptAugL3Endpoint(l3Ep);
// Match on L3 Nat Augmentation in Destination, set to IPAddress/Mac, send to SourceMapper
if (naptAugL3Endpoint == null) {
Flow flow = null;
for (NaptTranslation nat : naptAugL3Endpoint) {
Endpoint ep = ctx.getEndpointManager().getEndpoint(new EpKey(l3Ep.getL2Context(), l3Ep.getMacAddress()));
- EndpointFwdCtxOrdinals epFwdCtxOrds = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, policyInfo, ep);
+ EndpointFwdCtxOrdinals epFwdCtxOrds = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, ep);
if (epFwdCtxOrds == null) {
LOG.debug("getEndpointFwdCtxOrdinals is null for EP {}", ep);
continue;
package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @author readams
*/
public abstract class OfTable {
- protected static final Logger LOG =
- LoggerFactory.getLogger(OfTable.class);
+
+ protected static final Logger LOG = LoggerFactory.getLogger(OfTable.class);
protected final OfContext ctx;
public OfTable(OfContext ctx) {
- super();
this.ctx = ctx;
}
-
- // *******
- // OfTable
- // *******
-
/**
* Update the relevant flow table for the node
+ *
* @param nodeId the node to update
- * @param policyInfo the current policy snapshot
* @param ofWriter the {@link OfWriter}
* @throws Exception throws all exception
*/
- public abstract void update(NodeId nodeId,
- PolicyInfo policyInfo,
- OfWriter ofWriter) throws Exception;
+ public abstract void sync(NodeId nodeId, OfWriter ofWriter)
+ throws Exception;
}
import org.opendaylight.groupbasedpolicy.resolver.ConditionGroup;
import org.opendaylight.groupbasedpolicy.resolver.EgKey;
import org.opendaylight.groupbasedpolicy.resolver.IndexedTenant;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ConditionName;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.NetworkDomainId;
return ord.intValue();
}
- public static final EndpointFwdCtxOrdinals getEndpointFwdCtxOrdinals(OfContext ctx, PolicyInfo policyInfo,
+ public static final EndpointFwdCtxOrdinals getEndpointFwdCtxOrdinals(OfContext ctx,
Endpoint ep) throws Exception {
- IndexedTenant tenant = ctx.getPolicyResolver().getTenant(ep.getTenant());
+ IndexedTenant tenant = ctx.getTenant(ep.getTenant());
if (tenant == null) {
LOG.debug("Tenant {} is null", ep.getTenant());
return null;
}
- return new EndpointFwdCtxOrdinals(ep, policyInfo, ctx);
+ return new EndpointFwdCtxOrdinals(ep, ctx);
}
// TODO alagalah Li: Move to either OrdinalFactory or EndpointManager
private EpKey ep;
private int epgId = 0, bdId = 0, fdId = 0, l3Id = 0, cgId = 0, tunnelId = 0;
- private EndpointFwdCtxOrdinals(Endpoint ep, PolicyInfo policyInfo, OfContext ctx) throws Exception {
+ private EndpointFwdCtxOrdinals(Endpoint ep, OfContext ctx) throws Exception {
this.ep = new EpKey(ep.getL2Context(), ep.getMacAddress());
- IndexedTenant tenant = ctx.getPolicyResolver().getTenant(ep.getTenant());
+ IndexedTenant tenant = ctx.getTenant(ep.getTenant());
// Set network containment either from ep, or from primary EPG
if (ep.getNetworkContainment() != null) {
// conditions, but
// out of scope until broader bugs with conditions are fixed.
List<ConditionName> conds = ctx.getEndpointManager().getConditionsForEndpoint(ep);
- ConditionGroup cg = policyInfo.getEgCondGroup(new EgKey(ep.getTenant(), ep.getEndpointGroup()), conds);
+ ConditionGroup cg = ctx.getCurrentPolicy().getEgCondGroup(new EgKey(ep.getTenant(), ep.getEndpointGroup()), conds);
this.cgId = getCondGroupOrdinal(cg);
// Based on network containment, determine components of
import javax.annotation.concurrent.Immutable;
-import org.opendaylight.groupbasedpolicy.sf.actions.AllowActionDefinition;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.RegMatch;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.OrdinalFactory.EndpointFwdCtxOrdinals;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.Action;
import org.opendaylight.groupbasedpolicy.resolver.EndpointConstraint;
import org.opendaylight.groupbasedpolicy.resolver.IndexedTenant;
import org.opendaylight.groupbasedpolicy.resolver.Policy;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
import org.opendaylight.groupbasedpolicy.resolver.RuleGroup;
+import org.opendaylight.groupbasedpolicy.sf.actions.AllowActionDefinition;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
}
@Override
- public void sync(NodeId nodeId, PolicyInfo policyInfo, OfWriter ofWriter) throws Exception {
+ public void sync(NodeId nodeId, OfWriter ofWriter) throws Exception {
ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(1), null, TABLE_ID));
for (Endpoint srcEp : ctx.getEndpointManager().getEndpointsForNode(nodeId)) {
for (EgKey srcEpgKey : ctx.getEndpointManager().getEgKeysForEndpoint(srcEp)) {
- Set<EgKey> peers = policyInfo.getPeers(srcEpgKey);
+ Set<EgKey> peers = ctx.getCurrentPolicy().getPeers(srcEpgKey);
for (EgKey dstEpgKey : peers) {
Set<Endpoint> dstEndpoints = new HashSet<>();
dstEndpoints.addAll(ctx.getEndpointManager().getEndpointsForGroup(dstEpgKey));
dstEndpoints.addAll(ctx.getEndpointManager().getExtEpsNoLocForGroup(dstEpgKey));
for (Endpoint dstEp : dstEndpoints) {
- EndpointFwdCtxOrdinals srcEpFwdCxtOrds = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx,
- policyInfo, srcEp);
+ EndpointFwdCtxOrdinals srcEpFwdCxtOrds = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, srcEp);
if (srcEpFwdCxtOrds == null) {
LOG.debug("getEndpointFwdCtxOrdinals is null for EP {}", srcEp);
continue;
}
- EndpointFwdCtxOrdinals dstEpFwdCxtOrds = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx,
- policyInfo, dstEp);
+ EndpointFwdCtxOrdinals dstEpFwdCxtOrds = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, dstEp);
if (dstEpFwdCxtOrds == null) {
LOG.debug("getEndpointFwdCtxOrdinals is null for EP {}", dstEp);
continue;
int sepgId = srcEpFwdCxtOrds.getEpgId();
fdIds.add(srcEpFwdCxtOrds.getFdId());
- NetworkElements netElements = new NetworkElements(srcEp, dstEp, nodeId, ctx, policyInfo);
+ NetworkElements netElements = new NetworkElements(srcEp, dstEp, nodeId, ctx);
- Policy policy = policyInfo.getPolicy(dstEpgKey, srcEpgKey);
+ Policy policy = ctx.getCurrentPolicy().getPolicy(dstEpgKey, srcEpgKey);
for (Cell<EndpointConstraint, EndpointConstraint, List<RuleGroup>> activeRulesByConstraints : getActiveRulesBetweenEps(
policy, dstEp, srcEp)) {
Set<IpPrefix> sIpPrefixes = Policy.getIpPrefixesFrom(activeRulesByConstraints.getRowKey()
}
// Reverse
- policy = policyInfo.getPolicy(srcEpgKey, dstEpgKey);
+ policy = ctx.getCurrentPolicy().getPolicy(srcEpgKey, dstEpgKey);
for (Cell<EndpointConstraint, EndpointConstraint, List<RuleGroup>> activeRulesByConstraints : getActiveRulesBetweenEps(
policy, srcEp, dstEp)) {
Set<IpPrefix> sIpPrefixes = Policy.getIpPrefixesFrom(activeRulesByConstraints.getRowKey()
for (Endpoint srcEp : ctx.getEndpointManager().getEndpointsForNode(nodeId)) {
for (EgKey srcEpgKey : ctx.getEndpointManager().getEgKeysForEndpoint(srcEp)) {
- IndexedTenant tenant = ctx.getPolicyResolver().getTenant(srcEpgKey.getTenantId());
+ IndexedTenant tenant = ctx.getTenant(srcEpgKey.getTenantId());
if (tenant != null) {
EndpointGroup group = tenant.getEndpointGroup(srcEpgKey.getEgId());
if (group == null) {
if (igp == null || igp.equals(IntraGroupPolicy.Allow)) {
for (Endpoint dstEp : ctx.getEndpointManager().getEndpointsForGroup(srcEpgKey)) {
EndpointFwdCtxOrdinals srcEpFwdCxtOrds =
- OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, policyInfo, srcEp);
+ OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, srcEp);
if (srcEpFwdCxtOrds == null) {
LOG.debug("getEndpointFwdCtxOrdinals is null for EP {}", srcEp);
continue;
}
EndpointFwdCtxOrdinals dstEpFwdCxtOrds =
- OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, policyInfo, dstEp);
+ OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, dstEp);
if (dstEpFwdCxtOrds == null) {
LOG.debug("getEndpointFwdCtxOrdinals is null for EP {}", dstEp);
continue;
int priority = 65000;
for (RuleGroup rg : rgs) {
TenantId tenantId = rg.getContractTenant().getId();
- IndexedTenant tenant = ctx.getPolicyResolver().getTenant(tenantId);
+ IndexedTenant tenant = ctx.getTenant(tenantId);
for (Rule r : rg.getRules()) {
syncDirection(ofWriter, netElements, tenant, policyPair, r, Direction.In, priority);
syncDirection(ofWriter, netElements, tenant, policyPair, r, Direction.Out, priority);
private EndpointFwdCtxOrdinals srcEpOrds;
private EndpointFwdCtxOrdinals dstEpOrds;
- public NetworkElements(Endpoint srcEp, Endpoint dstEp, NodeId nodeId, OfContext ctx, PolicyInfo policyInfo)
+ public NetworkElements(Endpoint srcEp, Endpoint dstEp, NodeId nodeId, OfContext ctx)
throws Exception {
Preconditions.checkArgument(srcEp.getAugmentation(OfOverlayContext.class) != null);
Preconditions.checkArgument(dstEp.getAugmentation(OfOverlayContext.class) != null);
this.srcEp = srcEp;
this.dstEp = dstEp;
this.localNodeId = nodeId;
- this.srcEpOrds = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, policyInfo, srcEp);
+ this.srcEpOrds = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, srcEp);
if (this.srcEpOrds == null) {
LOG.debug("getEndpointFwdCtxOrdinals is null for EP {}", srcEp);
return;
}
- this.dstEpOrds = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, policyInfo, dstEp);
+ this.dstEpOrds = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, dstEp);
if (this.dstEpOrds == null) {
LOG.debug("getEndpointFwdCtxOrdinals is null for EP {}", dstEp);
return;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
}
@Override
- public void sync(NodeId nodeId, PolicyInfo policyInfo, OfWriter ofWriter) {
+ public void sync(NodeId nodeId, OfWriter ofWriter) {
// Allow traffic from tunnel ports
NodeConnectorId tunnelIf = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlan.class);
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.OrdinalFactory.EndpointFwdCtxOrdinals;
import org.opendaylight.groupbasedpolicy.resolver.EgKey;
import org.opendaylight.groupbasedpolicy.resolver.IndexedTenant;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
}
@Override
- public void sync(NodeId nodeId, PolicyInfo policyInfo, OfWriter ofWriter) throws Exception {
+ public void sync(NodeId nodeId, OfWriter ofWriter) throws Exception {
ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(1), null, TABLE_ID));
for (Endpoint ep : ctx.getEndpointManager().getEndpointsForNode(nodeId)) {
OfOverlayContext ofc = ep.getAugmentation(OfOverlayContext.class);
- IndexedTenant tenant = ctx.getPolicyResolver().getTenant(ep.getTenant());
+ IndexedTenant tenant = ctx.getTenant(ep.getTenant());
if (tenant == null)
continue;
- EndpointFwdCtxOrdinals epFwdCtxOrds = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, policyInfo, ep);
+ EndpointFwdCtxOrdinals epFwdCtxOrds = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, ep);
if (epFwdCtxOrds == null) {
LOG.debug("getEndpointFwdCtxOrdinals is null for EP {}", ep);
continue;
}
- createRemoteTunnels(ofWriter, nodeId, ep, policyInfo, epFwdCtxOrds);
+ createRemoteTunnels(ofWriter, nodeId, ep, epFwdCtxOrds);
if (ep.getTenant() == null || (ep.getEndpointGroup() == null && ep.getEndpointGroups() == null)) {
continue;
}
}
- private void createRemoteTunnels(OfWriter ofWriter, NodeId nodeId, Endpoint ep, PolicyInfo policyInfo,
- EndpointFwdCtxOrdinals epFwdCtxOrds) throws Exception {
+ private void createRemoteTunnels(OfWriter ofWriter, NodeId nodeId, Endpoint ep, EndpointFwdCtxOrdinals epFwdCtxOrds)
+ throws Exception {
Set<EgKey> epgs = new HashSet<>();
// Get EPGs and add to Set to remove duplicates
// Create tunnels on remote Nodes that may talk to us.
for (EgKey epg : epgs) {
- Set<EgKey> peers = Sets.union(Collections.singleton(epg), policyInfo.getPeers(epg));
+ Set<EgKey> peers = Sets.union(Collections.singleton(epg), ctx.getCurrentPolicy().getPeers(epg));
for (EgKey peer : peers) {
for (NodeId remoteNodeId : ctx.getEndpointManager().getNodesForGroup(peer)) {
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OFOverlayRenderer;
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.RendererName;
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;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.RendererKey;
private static final Logger LOG = LoggerFactory.getLogger(ActionDefinitionListener.class);
private static final InstanceIdentifier<Capabilities> CAPABILITIES_IID = InstanceIdentifier.builder(Renderers.class)
- .child(Renderer.class, new RendererKey(new RendererName(OFOverlayRenderer.RENDERER_NAME)))
+ .child(Renderer.class, new RendererKey(OFOverlayRenderer.RENDERER_NAME))
.child(Capabilities.class)
.build();
private static String PUT = "stored";
@Override
public void onSuccess(Void result) {
- LOG.debug("Capability of renerer {} was {}: {}", OFOverlayRenderer.RENDERER_NAME, putOrDeleted,
- supportedActionDefinitionKey);
+ LOG.debug("Capability of renerer {} was {}: {}", OFOverlayRenderer.RENDERER_NAME.getValue(),
+ putOrDeleted, supportedActionDefinitionKey);
}
@Override
public void onFailure(Throwable t) {
- LOG.error("Capability of renderer {} was NOT {}: {}", OFOverlayRenderer.RENDERER_NAME, putOrDeleted,
- supportedActionDefinitionKey, t);
+ LOG.error("Capability of renderer {} was NOT {}: {}", OFOverlayRenderer.RENDERER_NAME.getValue(),
+ putOrDeleted, supportedActionDefinitionKey, t);
}
};
}
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OFOverlayRenderer;
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.RendererName;
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;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.RendererKey;
private static final Logger LOG = LoggerFactory.getLogger(ClassifierDefinitionListener.class);
private static final InstanceIdentifier<Capabilities> CAPABILITIES_IID = InstanceIdentifier.builder(Renderers.class)
- .child(Renderer.class, new RendererKey(new RendererName(OFOverlayRenderer.RENDERER_NAME)))
+ .child(Renderer.class, new RendererKey(OFOverlayRenderer.RENDERER_NAME))
.child(Capabilities.class)
.build();
private static String PUT = "stored";
@Override
public void onSuccess(Void result) {
- LOG.debug("Capability of renerer {} was {}: {}", OFOverlayRenderer.RENDERER_NAME, putOrDeleted,
- supportedClassifierDefinitionKey);
+ LOG.debug("Capability of renerer {} was {}: {}", OFOverlayRenderer.RENDERER_NAME.getValue(),
+ putOrDeleted, supportedClassifierDefinitionKey);
}
@Override
public void onFailure(Throwable t) {
- LOG.error("Capability of renderer {} was NOT {}: {}", OFOverlayRenderer.RENDERER_NAME, putOrDeleted,
- supportedClassifierDefinitionKey, t);
+ LOG.error("Capability of renderer {} was NOT {}: {}", OFOverlayRenderer.RENDERER_NAME.getValue(),
+ putOrDeleted, supportedClassifierDefinitionKey, t);
}
};
}
--- /dev/null
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay;
+
+import java.util.concurrent.ScheduledExecutorService;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.EndpointManager;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.Tenant;
+
+public class MockOfContext extends OfContext {
+
+ public MockOfContext(DataBroker dataBroker, PolicyManager policyManager, SwitchManager switchManager,
+ EndpointManager endpointManager, ScheduledExecutorService executor) {
+ super(dataBroker, policyManager, switchManager, endpointManager, executor);
+ }
+
+ public void addTenant(Tenant unresolvedTenant) {
+ addTenantAndResolvePolicy(unresolvedTenant);
+ }
+
+}
package org.opendaylight.groupbasedpolicy.renderer.ofoverlay;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.EndpointManager;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyResolver;
public class MockPolicyManager extends PolicyManager {
private static short offSet = 0;
- public MockPolicyManager(PolicyResolver policyResolver,
- EndpointManager endpointManager) {
- super(null, policyResolver, null, endpointManager, null, null, offSet);
+ public MockPolicyManager(EndpointManager endpointManager) {
+ super(null, null, endpointManager, null, null, offSet);
}
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.atLeastOnce;
-import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.EndpointManager;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;
import org.opendaylight.groupbasedpolicy.resolver.EgKey;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyResolver;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyScope;
-import org.opendaylight.groupbasedpolicy.resolver.validator.Validator;
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.flow.inventory.rev130819.tables.Table;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
-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.L2ContextId;
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.inventory.rev130819.NodeId;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
private PolicyManager manager;
private DataBroker dataBroker;
- private PolicyResolver policyResolver;
private SwitchManager switchManager;
private EndpointManager endpointManager;
private RpcProviderRegistry rpcRegistry;
private short tableId;
private Flow flow;
- private PolicyScope policyScope;
-
@Before
public void setUp() {
dataBroker = mock(DataBroker.class);
- policyResolver = mock(PolicyResolver.class);
switchManager = mock(SwitchManager.class);
endpointManager = mock(EndpointManager.class);
rpcRegistry = mock(RpcProviderRegistry.class);
executor = mock(ScheduledExecutorService.class);
tableOffset = 5;
- policyScope = mock(PolicyScope.class);
- when(policyResolver.registerListener(any(PolicyManager.class))).thenReturn(policyScope);
-
writeTransaction = mock(WriteTransaction.class);
when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
readWriteTransaction = mock(ReadWriteTransaction.class);
when(dataBroker.newReadWriteTransaction()).thenReturn(readWriteTransaction);
- manager = new PolicyManager(dataBroker, policyResolver, switchManager,
+ manager = new PolicyManager(dataBroker, switchManager,
endpointManager, rpcRegistry, executor, tableOffset);
nodeId = mock(NodeId.class);
flow = mock(Flow.class);
}
- @SuppressWarnings("unchecked")
- @Test
- public void constructorTest() {
- WriteTransaction ctorWriteTransaction = mock(WriteTransaction.class);
- when(dataBroker.newWriteOnlyTransaction()).thenReturn(ctorWriteTransaction);
- PolicyResolver ctorPolicyResolver = mock(PolicyResolver.class);
- PolicyManager ctorPolicyManager = new PolicyManager(dataBroker, ctorPolicyResolver,
- switchManager, endpointManager, rpcRegistry, executor, tableOffset);
- verify(ctorPolicyResolver, atLeastOnce()).registerActionInstanceValidators(any(ActionDefinitionId.class),
- any(Validator.class));
- }
-
@SuppressWarnings("unchecked")
@Test
public void flowMapTestAddition() throws Exception {
EpKey epKey = new EpKey(
new L2ContextId("10fdfde9-c0f2-412d-822d-59d38711bde8"),
new MacAddress("24:77:03:D8:E9:B4"));
- doNothing().when(policyScope).addToScope(eq(egKey.getTenantId()), eq(egKey.getEgId()));
- manager.groupEndpointUpdated(egKey, epKey);
- verify(policyScope).addToScope(eq(egKey.getTenantId()), eq(egKey.getEgId()));
+ // TODO finish this test
}
@Test
endpointManager.addEndpoint(remoteEp);\r
\r
\r
- policyResolver.addTenant(baseTenant().setContract(\r
+ ctx.addTenant(baseTenant().setContract(\r
ImmutableList.<Contract> of(baseContract(null).build())).build());\r
verifyDMap(remoteEp, localEp);\r
}\r
.build();\r
endpointManager.addEndpoint(remoteEp);\r
\r
- policyResolver.addTenant(baseTenant().setContract(\r
+ ctx.addTenant(baseTenant().setContract(\r
ImmutableList.<Contract> of(baseContract(null).build())).build());\r
verifyDMap(remoteEp, localEp);\r
}\r
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.EndpointManager;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyResolver;
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;
private EgressNatMapper mapper;
private NodeId nodeId;
- private PolicyInfo policyInfo;
private OfWriter ofWriter;
private IpAddress ipAddressNapt;
when(ctx.getPolicyManager()).thenReturn(policyManager);
when(policyManager.getTABLEID_DESTINATION_MAPPER()).thenReturn(TABLE_ID);
- // EndpointFwdCtxOrdinals
- PolicyResolver policyResolver = mock(PolicyResolver.class);
- when(ctx.getPolicyResolver()).thenReturn(policyResolver);
-
nodeId = mock(NodeId.class);
- policyInfo = mock(PolicyInfo.class);
ofWriter = mock(OfWriter.class);
mapper = new EgressNatMapper(ctx, TABLE_ID);
@Test
public void syncTestIpv4() throws Exception {
- mapper.sync(nodeId, policyInfo, ofWriter);
+ mapper.sync(nodeId, ofWriter);
verify(ofWriter, times(2)).writeFlow(any(NodeId.class), any(Short.class), any(Flow.class));
}
@Test
public void syncTestIpv6() throws Exception {
when(ipAddressNapt.getIpv4Address()).thenReturn(null);
- mapper.sync(nodeId, policyInfo, ofWriter);
+ mapper.sync(nodeId, ofWriter);
verify(ofWriter, times(2)).writeFlow(any(NodeId.class), any(Short.class), any(Flow.class));
}
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
private OfContext ctx;
private short tableId;
private NodeId nodeId;
- private PolicyInfo policyInfo;
private OfWriter ofWriter;
private SwitchManager switchManager;
ctx = mock(OfContext.class);
tableId = 5;
nodeId = mock(NodeId.class);
- policyInfo = mock(PolicyInfo.class);
ofWriter = mock(OfWriter.class);
switchManager = mock(SwitchManager.class);
when(ctx.getSwitchManager()).thenReturn(switchManager);
Set<NodeConnectorId> externalPorts = new HashSet<NodeConnectorId>(Arrays.asList(nodeConnectorId));
when(switchManager.getExternalPorts(nodeId)).thenReturn(externalPorts);
- mapper.sync(nodeId, policyInfo, ofWriter);
+ mapper.sync(nodeId, ofWriter);
verify(ofWriter, times(2)).writeFlow(any(NodeId.class), any(Short.class), any(Flow.class));
}
public void syncTestNoExternalPorts() throws Exception {
when(switchManager.getExternalPorts(nodeId)).thenReturn(null);
- mapper.sync(nodeId, policyInfo, ofWriter);
+ mapper.sync(nodeId, ofWriter);
verify(ofWriter, never()).writeFlow(any(NodeId.class), any(Short.class), any(Flow.class));
}
}
}\r
}\r
}\r
- table.sync(nodeId, policyResolver.getCurrentPolicy(), ofWriter);\r
+ table.sync(nodeId, ofWriter);\r
return ofWriter;\r
}\r
}\r
package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow;
import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import java.util.HashSet;
import java.util.List;
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
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.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.EndpointManager;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.EndpointManager;
import org.opendaylight.groupbasedpolicy.resolver.EgKey;
import org.opendaylight.groupbasedpolicy.resolver.IndexedTenant;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyResolver;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.EndpointGroup;
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.Node;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+
public class GroupTableTest {
private GroupTable groupTable;
private CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> checkedFutureFCNRead;
private CheckedFuture<Void, TransactionCommitFailedException> checkedFutureWrite;
- private Optional<Node> optionalNode;
private Optional<FlowCapableNode> optionalFlowCapableNode;
- private Node node;
private FlowCapableNode flowCapableNode;
private Group group;
private List<Group> groups;
private Buckets buckets;
private Bucket bucket;
private NodeId nodeId;
- private PolicyInfo policyInfo;
private OfWriter ofWriter;
- private GroupId groupId;
private Bucket bucketOther;
private EndpointManager endpointManager;
private Endpoint localEp;
dataBroker = mock(DataBroker.class);
when(ofContext.getDataBroker()).thenReturn(dataBroker);
- node = mock(Node.class);
checkedFutureFCNRead = mock(CheckedFuture.class);
optionalFlowCapableNode = mock(Optional.class);
flowCapableNode = mock(FlowCapableNode.class);
bucketOther = mock(Bucket.class);
when(bucketOther.getAction()).thenReturn(Collections.singletonList(mock(Action.class)));
- groupId = mock(GroupId.class);
nodeId = mock(NodeId.class);
- policyInfo = mock(PolicyInfo.class);
ofWriter = mock(OfWriter.class);
endpointManager = mock(EndpointManager.class);
localEp = mock(Endpoint.class);
when(endpointManager.getEndpointsForNode(nodeId)).thenReturn(Collections.singletonList(
localEp));
- PolicyResolver policyResolver = mock(PolicyResolver.class);
- when(ofContext.getPolicyResolver()).thenReturn(policyResolver);
IndexedTenant indexedTenant = mock(IndexedTenant.class);
- when(policyResolver.getTenant(any(TenantId.class))).thenReturn(indexedTenant);
+ when(ofContext.getTenant(any(TenantId.class))).thenReturn(indexedTenant);
EndpointGroup epg = mock(EndpointGroup.class);
when(indexedTenant.getEndpointGroup(any(EndpointGroupId.class))).thenReturn(epg);
egKey = mock(EgKey.class);
@Test
public void updateTest() throws Exception {
- doNothing().when(groupTable).sync(nodeId, policyInfo, ofWriter);
+ doNothing().when(groupTable).sync(nodeId, ofWriter);
- groupTable.update(nodeId, policyInfo, ofWriter);
- verify(groupTable).sync(any(NodeId.class), any(PolicyInfo.class), any(OfWriter.class));
+ groupTable.sync(nodeId, ofWriter);
+ verify(groupTable).sync(any(NodeId.class), any(OfWriter.class));
}
@Test
public void updateTestNoFCN() throws Exception {
doReturn(null).when(groupTable).getFCNodeFromDatastore(any(NodeId.class));
- groupTable.update(nodeId, policyInfo, ofWriter);
- verify(groupTable, never()).sync(any(NodeId.class), any(PolicyInfo.class), any(OfWriter.class));
+ groupTable.sync(nodeId, ofWriter);
+ verify(ofWriter, never()).writeBucket(any(NodeId.class), any(GroupId.class), any(Bucket.class));;
+ verify(ofWriter, never()).writeFlow(any(NodeId.class), any(Short.class), any(Flow.class));
+ verify(ofWriter, never()).writeGroup(any(NodeId.class), any(GroupId.class), any(GroupTypes.class),
+ any(String.class), any(String.class), any(Boolean.class));
}
@Test
when(endpointManager.getGroupsForNode(any(NodeId.class))).thenReturn(
Collections.<EgKey>emptySet());
- groupTable.update(nodeId, policyInfo, ofWriter);
+ groupTable.sync(nodeId, ofWriter);
verify(ofWriter).writeGroup(any(NodeId.class), any(GroupId.class));
}
when(endpointManager.getGroupsForNode(any(NodeId.class))).thenReturn(
Collections.<EgKey>emptySet());
- groupTable.update(nodeId, policyInfo, ofWriter);
+ groupTable.sync(nodeId, ofWriter);
verify(ofWriter, never()).writeGroup(any(NodeId.class), any(GroupId.class));
}
}
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.groupbasedpolicy.endpoint.EpKey;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.EndpointManager;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyResolver;
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;
private IngressNatMapper mapper;
private NodeId nodeId;
- private PolicyInfo policyInfo;
private OfWriter ofWriter;
private IpAddress ipAddressNapt;
when(ctx.getPolicyManager()).thenReturn(policyManager);
when(policyManager.getTABLEID_DESTINATION_MAPPER()).thenReturn(TABLE_ID);
- // EndpointFwdCtxOrdinals
- PolicyResolver policyResolver = mock(PolicyResolver.class);
- when(ctx.getPolicyResolver()).thenReturn(policyResolver);
-
nodeId = mock(NodeId.class);
- policyInfo = mock(PolicyInfo.class);
ofWriter = mock(OfWriter.class);
mapper = new IngressNatMapper(ctx, TABLE_ID);
@Test
public void syncTestIpv4() throws Exception {
- mapper.sync(nodeId, policyInfo, ofWriter);
+ mapper.sync(nodeId, ofWriter);
verify(ofWriter).writeFlow(any(NodeId.class), any(Short.class), any(Flow.class));
}
@Test
public void syncTestIpv6() throws Exception {
when(ipAddressL3Ep.getIpv4Address()).thenReturn(null);
- mapper.sync(nodeId, policyInfo, ofWriter);
+ mapper.sync(nodeId, ofWriter);
verify(ofWriter).writeFlow(any(NodeId.class), any(Short.class), any(Flow.class));
}
import java.util.List;\r
import java.util.Map;\r
\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.MockOfContext;\r
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.MockPolicyManager;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;\r
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.MockEndpointManager;\r
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.MockSwitchManager;\r
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.AllowAction;\r
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.Classifier;\r
-import org.opendaylight.groupbasedpolicy.resolver.MockPolicyResolver;\r
import org.opendaylight.groupbasedpolicy.sf.classifiers.L4ClassifierDefinition;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;\r
import com.google.common.collect.ImmutableList;\r
\r
public class OfTableTest {\r
- OfContext ctx;\r
+ MockOfContext ctx;\r
\r
MockEndpointManager endpointManager;\r
- MockPolicyResolver policyResolver;\r
MockPolicyManager policyManager;\r
MockSwitchManager switchManager;\r
NodeId nodeId = new NodeId("openflow:1");\r
\r
protected void initCtx() {\r
endpointManager = new MockEndpointManager();\r
- policyResolver = new MockPolicyResolver();\r
- policyManager = new MockPolicyManager(policyResolver, endpointManager);\r
+ policyManager = new MockPolicyManager(endpointManager);\r
switchManager = new MockSwitchManager();\r
- ctx = new OfContext(null,\r
- null,\r
+ ctx = new MockOfContext(null,\r
policyManager,\r
- policyResolver,\r
switchManager,\r
endpointManager,\r
null);\r
endpointManager.addEndpoint(ep1);
Endpoint ep2 = localEP().setMacAddress(new MacAddress("00:00:00:00:00:02")).build();
endpointManager.addEndpoint(ep2);
- policyResolver.addTenant(baseTenant().setContract(ImmutableList.<Contract>of(baseContract(null).build()))
+ ctx.addTenant(baseTenant().setContract(ImmutableList.<Contract>of(baseContract(null).build()))
.build());
OfWriter fm = dosync(null);
endpointManager.addEndpoint(ep1);
Endpoint ep2 = localEP().setMacAddress(new MacAddress("00:00:00:00:00:02")).setEndpointGroup(eg2).build();
endpointManager.addEndpoint(ep2);
- policyResolver.addTenant(baseTenant().setContract(ImmutableList.<Contract>of(baseContract(subjects).build()))
+ ctx.addTenant(baseTenant().setContract(ImmutableList.<Contract>of(baseContract(subjects).build()))
.build());
OfWriter fm = dosync(null);
.build())).build())
.build()))
.build()));
- policyResolver.addTenant(tb.build());
+ ctx.addTenant(tb.build());
- PolicyInfo policy = policyResolver.getCurrentPolicy();
+ PolicyInfo policy = ctx.getCurrentPolicy();
List<ConditionName> ep1c = endpointManager.getConditionsForEndpoint(ep1);
ConditionGroup cg1 = policy.getEgCondGroup(new EgKey(tb.getId(), ep1.getEndpointGroup()), ep1c);
List<ConditionName> ep2c = endpointManager.getConditionsForEndpoint(ep2);
FlowUtils.addNxRegMatch(mb, RegMatch.of(NxmNxReg0.class, Long.valueOf(eg1Id)),
RegMatch.of(NxmNxReg1.class, Long.valueOf(cg1Id)), RegMatch.of(NxmNxReg2.class, Long.valueOf(eg2Id)),
RegMatch.of(NxmNxReg3.class, Long.valueOf(cg2Id)));
- GeneralAugMatchNodesNodeTableFlow m1 = mb.getAugmentation(GeneralAugMatchNodesNodeTableFlow.class);
- FlowUtils.addNxRegMatch(mb, RegMatch.of(NxmNxReg0.class, Long.valueOf(eg2Id)),
- RegMatch.of(NxmNxReg1.class, Long.valueOf(cg2Id)), RegMatch.of(NxmNxReg2.class, Long.valueOf(eg1Id)),
- RegMatch.of(NxmNxReg3.class, Long.valueOf(cg1Id)));
- GeneralAugMatchNodesNodeTableFlow m2 = mb.getAugmentation(GeneralAugMatchNodesNodeTableFlow.class);
int count = 0;
OfWriter fm = dosync(null);
assertEquals(7, fm.getTableForNode(nodeId, ctx.getPolicyManager().getTABLEID_POLICY_ENFORCER())
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.EndpointManager;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;
import org.opendaylight.groupbasedpolicy.resolver.EgKey;
import org.opendaylight.groupbasedpolicy.resolver.IndexedTenant;
import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
-import org.opendaylight.groupbasedpolicy.resolver.PolicyResolver;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
private Endpoint endpoint;
private EndpointManager endpointManager;
private IndexedTenant tenant;
- private PolicyResolver policyResolver;
private TenantId tenantId;
private PolicyManager policyManager;
private OfOverlayContext ofOverlayContext;
ctx = mock(OfContext.class);
tableId = 5;
nodeId = mock(NodeId.class);
- policyInfo = mock(PolicyInfo.class);
ofWriter = mock(OfWriter.class);
mapper = new SourceMapper(ctx, tableId);
tenantId = mock(TenantId.class);
when(endpoint.getTenant()).thenReturn(tenantId);
- policyResolver = mock(PolicyResolver.class);
- when(ctx.getPolicyResolver()).thenReturn(policyResolver);
tenant = mock(IndexedTenant.class);
- when(policyResolver.getTenant(tenantId)).thenReturn(tenant);
+ when(ctx.getTenant(tenantId)).thenReturn(tenant);
policyManager = mock(PolicyManager.class);
when(ctx.getPolicyManager()).thenReturn(policyManager);
+ policyInfo = mock(PolicyInfo.class);
+ when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
endpointGroup = mock(EndpointGroup.class);
when(tenant.getEndpointGroup(any(EndpointGroupId.class))).thenReturn(endpointGroup);
when(endpoint.getEndpointGroup()).thenReturn(endpointGroupIdSingle);
when(endpoint.getEndpointGroups()).thenReturn(null);
- mapper.sync(nodeId, policyInfo, ofWriter);
+ mapper.sync(nodeId, ofWriter);
verify(ofWriter, times(4)).writeFlow(any(NodeId.class), any(Short.class), any(Flow.class));
}
List<EndpointGroupId> endpointGroups = Arrays.asList(endpointGroupIdList);
when(endpoint.getEndpointGroups()).thenReturn(endpointGroups);
- mapper.sync(nodeId, policyInfo, ofWriter);
+ mapper.sync(nodeId, ofWriter);
verify(ofWriter, times(4)).writeFlow(any(NodeId.class), any(Short.class), any(Flow.class));
}
when(endpoint.getEndpointGroup()).thenReturn(endpointGroupIdSingle);
when(endpoint.getEndpointGroups()).thenReturn(null);
- mapper.sync(nodeId, policyInfo, ofWriter);
+ mapper.sync(nodeId, ofWriter);
verify(ofWriter, times(4)).writeFlow(any(NodeId.class), any(Short.class), any(Flow.class));
}
when(endpoint.getEndpointGroups()).thenReturn(null);
when(switchManager.getTunnelPort(nodeId, TunnelTypeVxlan.class)).thenReturn(null);
- mapper.sync(nodeId, policyInfo, ofWriter);
+ mapper.sync(nodeId, ofWriter);
verify(ofWriter, times(2)).writeFlow(any(NodeId.class), any(Short.class), any(Flow.class));
}
@Test
public void syncTestTenantNull() throws Exception {
- when(policyResolver.getTenant(tenantId)).thenReturn(null);
+ when(ctx.getTenant(tenantId)).thenReturn(null);
- mapper.sync(nodeId, policyInfo, ofWriter);
+ mapper.sync(nodeId, ofWriter);
verify(ofWriter, times(1)).writeFlow(any(NodeId.class), any(Short.class), any(Flow.class));
}
}