Removed PolicyListener and PolicyResolver methods 12/30512/10
authorMartin Sunal <msunal@cisco.com>
Wed, 2 Dec 2015 21:58:58 +0000 (22:58 +0100)
committerMartin Sunal <msunal@cisco.com>
Thu, 3 Dec 2015 15:38:06 +0000 (16:38 +0100)
- renderer should listen on resolved-policy from resolved-policy.yang
- removed public methods from PolicyResolver

Change-Id: Ife1e165b7264910a5be2f859b72f2b454dd04027
Signed-off-by: Martin Sunal <msunal@cisco.com>
45 files changed:
groupbasedpolicy/pom.xml
groupbasedpolicy/src/main/java/org/opendaylight/controller/config/yang/config/groupbasedpolicy/impl/GroupbasedpolicyModule.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/dto/ConsEpgKey.java [new file with mode: 0644]
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/dto/EpgKey.java [new file with mode: 0644]
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/dto/EpgKeyDto.java [new file with mode: 0644]
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/dto/ProvEpgKey.java [new file with mode: 0644]
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/resolver/EgKey.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/resolver/FollowedTenantListener.java [new file with mode: 0644]
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/resolver/PolicyInfo.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/resolver/PolicyListener.java [deleted file]
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/resolver/PolicyResolver.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/resolver/PolicyResolverUtils.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/resolver/PolicyScope.java [deleted file]
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/util/IidFactory.java
groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/resolver/MockPolicyResolver.java [deleted file]
groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/resolver/PolicyResolverTest.java
groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/resolver/PolicyScopeTest.java [deleted file]
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/OFOverlayRenderer.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/OfContext.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/PolicyManager.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/DestinationMapper.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/EgressNatMapper.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/ExternalMapper.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/FlowTable.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/GroupTable.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/IngressNatMapper.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/OfTable.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/OrdinalFactory.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/PolicyEnforcer.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/PortSecurity.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/SourceMapper.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/sf/ActionDefinitionListener.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/sf/ClassifierDefinitionListener.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/MockOfContext.java [new file with mode: 0644]
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/MockPolicyManager.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/PolicyManagerTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/DestinationMapperTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/EgressNatMapperTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/ExternalMapperTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/FlowTableTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/GroupTableTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/IngressNatMapperTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/OfTableTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/PolicyEnforcerTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/SourceMapperTest.java

index 03e91496d75ae0d9ee5cd3f910b2a3854de22545..b22a9aebc6c325712422855acf31eabd55f04537 100755 (executable)
@@ -61,6 +61,7 @@
             <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.*,
index adc2ec9210dd32c2bdb866c3cc371be21de5852f..9c99e1a38983df15f3c3e7d3863755aec5ccd220 100755 (executable)
@@ -12,6 +12,8 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 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;
@@ -65,6 +67,8 @@ public class GroupbasedpolicyModule extends
                         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 {
@@ -72,6 +76,8 @@ public class GroupbasedpolicyModule extends
                     epRpcRegistry.close();
                     supportedClassifierDefinitionListener.close();
                     supportedActionDefinitionListener.close();
+                    policyResolver.close();
+                    followedTenantListener.close();
                 }
             };
         } catch (TransactionCommitFailedException e) {
diff --git a/groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/dto/ConsEpgKey.java b/groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/dto/ConsEpgKey.java
new file mode 100644 (file)
index 0000000..bddfc4d
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * 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 {
+
+}
diff --git a/groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/dto/EpgKey.java b/groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/dto/EpgKey.java
new file mode 100644 (file)
index 0000000..880d2d7
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * 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();
+
+}
diff --git a/groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/dto/EpgKeyDto.java b/groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/dto/EpgKeyDto.java
new file mode 100644 (file)
index 0000000..bf4f3a5
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * 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;
+    }
+
+}
diff --git a/groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/dto/ProvEpgKey.java b/groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/dto/ProvEpgKey.java
new file mode 100644 (file)
index 0000000..5236a77
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * 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 {
+
+}
index 238db2a42c77929dc7cb06016e3999aa464ddda4..5f67ce0eec74669dd1c71a6f5147ec20061339b9 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.groupbasedpolicy.resolver;
 
 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;
 
@@ -18,9 +19,11 @@ import com.google.common.collect.Ordering;
 
 /**
  * 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;
diff --git a/groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/resolver/FollowedTenantListener.java b/groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/resolver/FollowedTenantListener.java
new file mode 100644 (file)
index 0000000..ef4cc89
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * 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();
+    }
+
+}
index c0e7e76b8a134f5d82aa2636b65f5460981263a8..66ab3f56bda8191d4411bf63eff1e05759d48ae6 100644 (file)
@@ -38,6 +38,7 @@ public class PolicyInfo {
         this.policyMap = policyMap;
         this.egConditions = egConditions;
     }
+
     public Table<EgKey, EgKey, Policy> getPolicyMap() {
         return policyMap;
     }
diff --git a/groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/resolver/PolicyListener.java b/groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/resolver/PolicyListener.java
deleted file mode 100644 (file)
index 2d1afe8..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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);
-    
-}
index 0123fba6e3fad7cc82642aeda315617eaf2fec49..2c5f9ad8a840709c0d034eff536234220ba95638 100755 (executable)
@@ -15,8 +15,6 @@ import java.util.Map;
 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;
@@ -31,15 +29,16 @@ import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
 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;
@@ -47,19 +46,14 @@ import org.slf4j.Logger;
 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.
@@ -83,22 +77,9 @@ public class PolicyResolver implements AutoCloseable {
     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
      *
@@ -106,12 +87,8 @@ public class PolicyResolver implements AutoCloseable {
     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");
     }
@@ -131,29 +108,6 @@ public class PolicyResolver implements AutoCloseable {
     // *************************
     // 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) {
@@ -175,91 +129,6 @@ public class PolicyResolver implements AutoCloseable {
         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
@@ -299,6 +168,7 @@ public class PolicyResolver implements AutoCloseable {
                             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
@@ -331,7 +201,7 @@ public class PolicyResolver implements AutoCloseable {
                     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) {
@@ -357,7 +227,7 @@ public class PolicyResolver implements AutoCloseable {
             public void onFailure(Throwable t) {
                 LOG.error("Count not get tenant {}", tenantId, t);
             }
-        }, executor);
+        });
     }
 
     private void deleteOperTenantIfExists(final InstanceIdentifier<Tenant> tiid, final TenantId tenantId) {
@@ -381,8 +251,7 @@ public class PolicyResolver implements AutoCloseable {
                 LOG.error("Failed to read operational datastore: {}", t);
                 rwTx.cancel();
             }
-        }, executor);
-
+        });
     }
 
     protected void updatePolicy() {
@@ -390,10 +259,7 @@ public class PolicyResolver implements AutoCloseable {
             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);
         }
@@ -416,6 +282,7 @@ public class PolicyResolver implements AutoCloseable {
             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) {
index 5ed1f29b5dccbf5e03ca55a1ceed17964fe475ea..817cbca616055313a53320f6ceac1ddf06fb637d 100644 (file)
@@ -42,7 +42,7 @@ public class PolicyResolverUtils {
      * (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);
diff --git a/groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/resolver/PolicyScope.java b/groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/resolver/PolicyScope.java
deleted file mode 100644 (file)
index 1f7d91b..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * 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;
-    }
-}
index 30365bcf8ce5360d8848b88957ecf56b4b1c6187..4f417f1042ab6e0e7cfd009542b2a94fa9c84312 100644 (file)
@@ -70,6 +70,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev
 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 {
@@ -248,5 +258,15 @@ 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();
+    }
 
 }
diff --git a/groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/resolver/MockPolicyResolver.java b/groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/resolver/MockPolicyResolver.java
deleted file mode 100644 (file)
index 5aa46c0..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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();
-    }
-}
index 9a23c477d7ce0c60cd364cd67135ef774e68d247..73c19d9277f3a7abc0c2f0211bfd3033ef6af00b 100644 (file)
@@ -14,16 +14,13 @@ import static org.junit.Assert.assertTrue;
 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;
@@ -102,7 +99,6 @@ import org.opendaylight.yangtools.concepts.ListenerRegistration;
 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;
@@ -112,66 +108,20 @@ public class PolicyResolverTest {
 
     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));
 
     }
 
@@ -334,29 +284,14 @@ public class PolicyResolverTest {
 
     @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());
diff --git a/groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/resolver/PolicyScopeTest.java b/groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/resolver/PolicyScopeTest.java
deleted file mode 100644 (file)
index e1f8234..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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));
-    }
-}
index deaf2ad9a085aeab9bd605364400f68e17074f74..11897955c001814a47c52b802ce254e4811233f7 100644 (file)
@@ -36,6 +36,7 @@ import org.opendaylight.groupbasedpolicy.resolver.PolicyResolver;
 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;
@@ -54,7 +55,7 @@ import com.google.common.util.concurrent.ListenableFuture;
 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;
@@ -87,13 +88,14 @@ public class OFOverlayRenderer implements AutoCloseable, DataChangeListener {
         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,
@@ -128,6 +130,7 @@ public class OFOverlayRenderer implements AutoCloseable, DataChangeListener {
         if (actionDefinitionListener != null) actionDefinitionListener.close();
         if (ofOverlayAug != null) ofOverlayAug.close();
         if (ofOverlayL3NatAug != null) ofOverlayL3NatAug.close();
+        if (policyManager != null) policyManager.close();
     }
 
     // ******************
index c2fd12b18a28302d570c3f7b5e0480db9d2e1b23..767945298c9d2852eec5f69da8a410f392fd07dd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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() {
@@ -56,16 +116,22 @@ public class OfContext {
         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() {
index 901210372728fd5dd2a7f9eecaa1a0c8f9be7f0d..48ee3b85fc6dc99fd5e01b16256e8778f386c68e 100755 (executable)
@@ -8,10 +8,11 @@
 
 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;
@@ -19,14 +20,12 @@ import java.util.concurrent.ExecutorCompletionService;
 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;
@@ -43,30 +42,37 @@ import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.PortSecurity;
 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);
 
@@ -80,18 +86,13 @@ public class PolicyManager
     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
@@ -100,7 +101,6 @@ public class PolicyManager
     private final static int FLOW_UPDATE_DELAY = 250;
 
     public PolicyManager(DataBroker dataBroker,
-                         PolicyResolver policyResolver,
                          SwitchManager switchManager,
                          EndpointManager endpointManager,
                          RpcProviderRegistry rpcRegistry,
@@ -109,7 +109,6 @@ public class PolicyManager
         super();
         this.switchManager = switchManager;
         this.executor = executor;
-        this.policyResolver = policyResolver;
         this.dataBroker = dataBroker;
         this.tableOffset = tableOffset;
         try {
@@ -120,19 +119,19 @@ public class PolicyManager
                     + "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());
@@ -141,7 +140,7 @@ public class PolicyManager
         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.
@@ -177,7 +176,6 @@ public class PolicyManager
 
             @Override
             public Void apply(Void tablesRemoved) {
-                flowPipeline = createFlowPipeline();
                 scheduleUpdate();
                 return null;
             }
@@ -306,16 +304,25 @@ public class PolicyManager
 
     @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();
     }
 
@@ -346,22 +353,22 @@ public class PolicyManager
      * 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);
@@ -403,8 +410,11 @@ public class PolicyManager
         }
     }
 
-
-
-
+    @Override
+    public void close() throws IOException {
+        if (registerDataTreeChangeListener != null)
+            registerDataTreeChangeListener.close();
+        // TODO unregister classifier and action instance validators
+    }
 
 }
index dcda8f7f8ad142f0bbefd4a67a5ca12d63836c5e..3a2d4391f8a23c6b7ae97ca66e6589b4ab1c757f 100755 (executable)
@@ -55,7 +55,6 @@ import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.RegMa
 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;
@@ -145,7 +144,7 @@ public class DestinationMapper extends FlowTable {
     }
 
     @Override
-    public void sync(NodeId nodeId, PolicyInfo policyInfo, OfWriter ofWriter) throws Exception {
+    public void sync(NodeId nodeId, OfWriter ofWriter) throws Exception {
 
         TenantId currentTenant = null;
 
@@ -163,7 +162,7 @@ public class DestinationMapper extends FlowTable {
 
             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();
@@ -174,11 +173,11 @@ public class DestinationMapper extends FlowTable {
                         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);
@@ -228,7 +227,7 @@ public class DestinationMapper extends FlowTable {
                     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");
@@ -241,7 +240,7 @@ public class DestinationMapper extends FlowTable {
     // 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" ?
@@ -275,7 +274,7 @@ public class DestinationMapper extends FlowTable {
             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;
@@ -464,7 +463,7 @@ public class DestinationMapper extends FlowTable {
     }
 
     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;
@@ -577,23 +576,23 @@ public class DestinationMapper extends FlowTable {
         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;
@@ -1109,8 +1108,7 @@ public class DestinationMapper extends FlowTable {
              * 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();
         }
index efedab591ac65633108c003b0ddc29cd7b6d9dda..7e1cdea3008fbf810ffe615fc1d39427ffba1a35 100755 (executable)
@@ -19,10 +19,9 @@ import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtil
 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;
@@ -65,7 +64,7 @@ public class EgressNatMapper extends FlowTable {
     }
 
     @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();
index bcd73bcc916c282acaf6f744412f080e083db564..03e37a0e5e3959966f7c3b893bf3ee7907087259 100755 (executable)
@@ -14,7 +14,6 @@ import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtil
 
 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;
@@ -43,7 +42,7 @@ public class ExternalMapper extends FlowTable {
     }
 
     @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);
index ce55b582f6f5189e2d743a9f542572eb2c6bfebd..0ceff85f9337e5d1c519740fe0fe8bdf03bbfc96 100755 (executable)
@@ -8,15 +8,12 @@
 
 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;
 
@@ -32,32 +29,6 @@ public abstract class FlowTable extends OfTable {
         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
      *
index 3bed5c02cda56589b6d94575b6417c52af9dae7f..7b54fb09675be3bcf7ab37c9ef04ad1517548810 100644 (file)
@@ -18,15 +18,12 @@ import java.util.HashSet;
 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;
@@ -43,6 +40,8 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Optional;
+
 /**
  * Manage the group tables for handling broadcast/multicast
  */
@@ -73,7 +72,7 @@ public class GroupTable extends OfTable {
     }
 
     @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
@@ -82,14 +81,9 @@ public class GroupTable extends OfTable {
         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;
@@ -105,11 +99,11 @@ public class GroupTable extends OfTable {
 
                 // 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;
 
@@ -153,23 +147,22 @@ public class GroupTable extends OfTable {
     }
 
     /**
-     * @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;
             }
index eac99d8ec15e2ac95414e926e9962a4e6ac3fb94..c43f45c7b8a3f1a81422f612cb52af08bb3cefb9 100755 (executable)
@@ -32,10 +32,9 @@ import java.util.Collection;
 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;
@@ -84,7 +83,7 @@ public class IngressNatMapper extends FlowTable {
     }
 
     @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));
 
@@ -96,13 +95,13 @@ public class IngressNatMapper extends FlowTable {
             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) {
@@ -111,7 +110,7 @@ public class IngressNatMapper extends FlowTable {
         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;
index 7b599b1b587366f6056dc7ed1850169e670e4e89..fb08689169c4831511b4aa712d803f6de6826a9f 100755 (executable)
@@ -8,9 +8,8 @@
 
 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;
@@ -22,29 +21,22 @@ 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;
 }
index cbee5ff75356f47ff80634962bf8d615d86b06c6..e78d290b1721fc339458ba18b399c9483b0723eb 100755 (executable)
@@ -19,7 +19,6 @@ import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
 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;
@@ -170,14 +169,14 @@ public class OrdinalFactory {
         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
@@ -187,10 +186,10 @@ public class OrdinalFactory {
         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) {
@@ -210,7 +209,7 @@ public class OrdinalFactory {
             // 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
index 8a6986975434342b1e9d0f4e61aae8a6fbcfd5e1..1c008d77b6324200dcbb3f63c1d8beedac2cc034 100755 (executable)
@@ -25,9 +25,8 @@ import java.util.Set;
 
 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;
@@ -40,8 +39,8 @@ import org.opendaylight.groupbasedpolicy.resolver.EgKey;
 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;
@@ -109,7 +108,7 @@ public class PolicyEnforcer extends FlowTable {
     }
 
     @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));
 
@@ -126,22 +125,20 @@ public class PolicyEnforcer extends FlowTable {
 
         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;
@@ -153,9 +150,9 @@ public class PolicyEnforcer extends FlowTable {
                         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()
@@ -177,7 +174,7 @@ public class PolicyEnforcer extends FlowTable {
                         }
 
                         // 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()
@@ -208,7 +205,7 @@ public class PolicyEnforcer extends FlowTable {
         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) {
@@ -220,14 +217,14 @@ public class PolicyEnforcer extends FlowTable {
                     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;
@@ -301,7 +298,7 @@ public class PolicyEnforcer extends FlowTable {
         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);
@@ -701,7 +698,7 @@ public class PolicyEnforcer extends FlowTable {
         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);
@@ -709,12 +706,12 @@ public class PolicyEnforcer extends FlowTable {
             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;
index d828cbe2f4110f4877caf08a360c2b75a4953b2a..6d8180ba5c5c0578c86618f0f13c384d37fa27fa 100755 (executable)
@@ -12,7 +12,6 @@ import java.util.Set;
 
 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;
@@ -55,7 +54,7 @@ public class PortSecurity extends FlowTable {
     }
 
     @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);
index e3032813b8f7a736f3be1aedee9090a1a8a4a8da..307faf7102992904fc39a36afe26d9fd876758fe 100755 (executable)
@@ -26,7 +26,6 @@ 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.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;
@@ -72,7 +71,7 @@ public class SourceMapper extends FlowTable {
     }
 
     @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));
 
@@ -80,17 +79,17 @@ public class SourceMapper extends FlowTable {
         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;
@@ -106,8 +105,8 @@ public class SourceMapper extends FlowTable {
         }
     }
 
-    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
@@ -123,7 +122,7 @@ public class SourceMapper extends FlowTable {
 
         // 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)) {
 
index 8a2b29f16c3659922f1d5e81dc8c103dd0116caf..f526accbdbfe0c6c816fc27ba25b6efadcbe3589 100644 (file)
@@ -22,7 +22,6 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 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;
@@ -42,7 +41,7 @@ public class ActionDefinitionListener implements DataTreeChangeListener<ActionDe
 
     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";
@@ -109,14 +108,14 @@ public class ActionDefinitionListener implements DataTreeChangeListener<ActionDe
 
             @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);
             }
         };
     }
index f14c6c56e5bdd83084f73e8797cb5aa947aff489..ba60bd86eb65474d1544ccf25f6b70f43554804f 100755 (executable)
@@ -22,7 +22,6 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 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;
@@ -42,7 +41,7 @@ public class ClassifierDefinitionListener implements DataTreeChangeListener<Clas
 
     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";
@@ -115,14 +114,14 @@ public class ClassifierDefinitionListener implements DataTreeChangeListener<Clas
 
             @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);
             }
         };
     }
diff --git a/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/MockOfContext.java b/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/MockOfContext.java
new file mode 100644 (file)
index 0000000..e58ea10
--- /dev/null
@@ -0,0 +1,21 @@
+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);
+    }
+
+}
index af85d27a0bb38c8bfcb4f292c3c07f12e37f25e5..177872747cff25513f81fc7c54f1c9e9004987ec 100644 (file)
@@ -9,14 +9,12 @@
 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);
     }
 
 }
index ec9534e6fc5d2dd0c1c75c29c45efd4b0532b188..a24210e882f9a2ac5d39e9d012d89c8a8915a8ee 100644 (file)
@@ -11,9 +11,6 @@ package org.opendaylight.groupbasedpolicy.renderer.ofoverlay;
 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;
@@ -36,17 +33,12 @@ import org.opendaylight.groupbasedpolicy.endpoint.EpKey;
 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;
 
@@ -68,7 +60,6 @@ public class PolicyManagerTest {
     private PolicyManager manager;
 
     private DataBroker dataBroker;
-    private PolicyResolver policyResolver;
     private SwitchManager switchManager;
     private EndpointManager endpointManager;
     private RpcProviderRegistry rpcRegistry;
@@ -82,28 +73,22 @@ public class PolicyManagerTest {
     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);
@@ -111,18 +96,6 @@ public class PolicyManagerTest {
         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 {
@@ -165,9 +138,7 @@ public class PolicyManagerTest {
         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
index 94cc5bbbf7cf582aa421b801ecc8c21aefd299b6..adba97c38c06759ad9fbe33507d1e0580935399e 100755 (executable)
@@ -289,7 +289,7 @@ public class DestinationMapperTest extends FlowTableTest {
         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
@@ -304,7 +304,7 @@ public class DestinationMapperTest extends FlowTableTest {
                 .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
index d73916bd4aba907ea803e4cd3cb0deeb9df1ec64..11614ea3acb044cb63130b29d37931ebb78f064b 100755 (executable)
@@ -24,8 +24,6 @@ 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;
@@ -42,7 +40,6 @@ public class EgressNatMapperTest {
     private EgressNatMapper mapper;
 
     private NodeId nodeId;
-    private PolicyInfo policyInfo;
     private OfWriter ofWriter;
 
     private IpAddress ipAddressNapt;
@@ -98,12 +95,7 @@ public class EgressNatMapperTest {
         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);
@@ -116,14 +108,14 @@ public class EgressNatMapperTest {
 
     @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));
     }
 
index a386a317960038df56284ef2482f9bad08f4060a..2656f06ed84e2b1bd076e287cc77ec5c7378bd7c 100755 (executable)
@@ -22,10 +22,9 @@ import java.util.Set;
 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;
@@ -37,7 +36,6 @@ public class ExternalMapperTest {
     private OfContext ctx;
     private short tableId;
     private NodeId nodeId;
-    private PolicyInfo policyInfo;
     private OfWriter ofWriter;
     private SwitchManager switchManager;
 
@@ -46,7 +44,6 @@ public class ExternalMapperTest {
         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);
@@ -65,7 +62,7 @@ public class ExternalMapperTest {
         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));
     }
 
@@ -73,7 +70,7 @@ public class ExternalMapperTest {
     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));
     }
 }
index e155c0c9058669893a0ef34a85126a54fd57fe2b..e0695d9a065e2eb310db6d56b07506c50148135f 100755 (executable)
@@ -34,7 +34,7 @@ public class FlowTableTest extends OfTableTest {
                 }\r
             }\r
         }\r
-        table.sync(nodeId, policyResolver.getCurrentPolicy(), ofWriter);\r
+        table.sync(nodeId, ofWriter);\r
         return ofWriter;\r
     }\r
 }\r
index fb6c676a336547c9db7f50e0d78385826f66383d..603c76fd1860f4eb7602fbd65d064bd2315a517e 100755 (executable)
@@ -9,7 +9,6 @@
 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;
@@ -22,8 +21,6 @@ import java.util.Collections;
 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;
@@ -33,16 +30,16 @@ import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 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;
@@ -53,9 +50,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.
 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;
@@ -69,19 +68,15 @@ public class GroupTableTest {
 
     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;
@@ -98,7 +93,6 @@ public class GroupTableTest {
         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);
@@ -136,10 +130,8 @@ public class GroupTableTest {
         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);
@@ -147,10 +139,8 @@ public class GroupTableTest {
         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);
@@ -164,18 +154,21 @@ public class GroupTableTest {
 
     @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
@@ -184,7 +177,7 @@ public class GroupTableTest {
         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));
     }
 
@@ -194,7 +187,7 @@ public class GroupTableTest {
         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));
     }
 }
index 17b02c61471bab84803f1b1f696b15ab602a9edb..28acf1d409c870e087bf7aa694111cfe5b252dfd 100755 (executable)
@@ -19,12 +19,10 @@ import org.junit.Assert;
 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;
@@ -41,7 +39,6 @@ public class IngressNatMapperTest {
     private IngressNatMapper mapper;
 
     private NodeId nodeId;
-    private PolicyInfo policyInfo;
     private OfWriter ofWriter;
 
     private IpAddress ipAddressNapt;
@@ -97,12 +94,7 @@ public class IngressNatMapperTest {
         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);
@@ -115,14 +107,14 @@ public class IngressNatMapperTest {
 
     @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));
     }
 
index 0ccaa7a972cae4f9362baa07c40c45b7d9db114d..e9bae480d43a51f8a00670007bf6f7bd3f54eb71 100755 (executable)
@@ -12,13 +12,12 @@ import java.util.ArrayList;
 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
@@ -69,10 +68,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 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
@@ -96,13 +94,10 @@ public class OfTableTest {
 \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
index e5fc397ce124594c7691a71e8dd9be915bf62a01..e42a5042196e7544d195a5281ae1d466000027ea 100755 (executable)
@@ -121,7 +121,7 @@ public class PolicyEnforcerTest extends FlowTableTest {
         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);
@@ -196,7 +196,7 @@ public class PolicyEnforcerTest extends FlowTableTest {
         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);
@@ -282,9 +282,9 @@ public class PolicyEnforcerTest extends FlowTableTest {
                                                     .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);
@@ -300,11 +300,6 @@ public class PolicyEnforcerTest extends FlowTableTest {
         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())
index 0562e9545a2f0a15d1457309db341be8b7fd4b35..1d831b5c52d6c853babe7687f9dace7f6baef699 100755 (executable)
@@ -22,15 +22,14 @@ import java.util.Set;
 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;
@@ -54,7 +53,6 @@ public class SourceMapperTest {
     private Endpoint endpoint;
     private EndpointManager endpointManager;
     private IndexedTenant tenant;
-    private PolicyResolver policyResolver;
     private TenantId tenantId;
     private PolicyManager policyManager;
     private OfOverlayContext ofOverlayContext;
@@ -69,7 +67,6 @@ public class SourceMapperTest {
         ctx = mock(OfContext.class);
         tableId = 5;
         nodeId = mock(NodeId.class);
-        policyInfo = mock(PolicyInfo.class);
         ofWriter = mock(OfWriter.class);
 
         mapper = new SourceMapper(ctx, tableId);
@@ -88,12 +85,12 @@ public class SourceMapperTest {
 
         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);
@@ -117,7 +114,7 @@ public class SourceMapperTest {
         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));
     }
 
@@ -127,7 +124,7 @@ public class SourceMapperTest {
         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));
     }
 
@@ -137,7 +134,7 @@ public class SourceMapperTest {
         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));
     }
 
@@ -148,15 +145,15 @@ public class SourceMapperTest {
         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));
     }
 }