Merge "ios-xe-renderer node manager update"
authorMartin Sunal <msunal@cisco.com>
Thu, 2 Jun 2016 16:46:25 +0000 (16:46 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 2 Jun 2016 16:46:25 +0000 (16:46 +0000)
84 files changed:
artifacts/pom.xml
domain-extensions/l2-l3/pom.xml [new file with mode: 0644]
domain-extensions/l2-l3/src/main/config/default-config.xml [new file with mode: 0644]
domain-extensions/l2-l3/src/main/java/org/opendaylight/controller/config/yang/config/domain_extension/l2_l3/impl/L2L3DomainExtensionModule.java [new file with mode: 0644]
domain-extensions/l2-l3/src/main/java/org/opendaylight/controller/config/yang/config/domain_extension/l2_l3/impl/L2L3DomainExtensionModuleFactory.java [new file with mode: 0644]
domain-extensions/l2-l3/src/main/java/org/opendaylight/groupbasedpolicy/domain_extension/l2_l3/L2L3NetworkDomainAugmentor.java [new file with mode: 0644]
domain-extensions/l2-l3/src/main/java/org/opendaylight/groupbasedpolicy/domain_extension/l2_l3/util/L2L3IidFactory.java [new file with mode: 0644]
domain-extensions/l2-l3/src/main/yang/l2-l3-domain-extension-cfg.yang [new file with mode: 0644]
domain-extensions/l2-l3/src/main/yang/l2-l3-forwarding.yang [moved from groupbasedpolicy/src/main/yang/model/l2-l3-forwarding.yang with 100% similarity]
domain-extensions/l2-l3/src/test/java/org/opendaylight/groupbasedpolicy/domain_extension/l2_l3/L2L3NetworkDomainAugmentorTest.java [new file with mode: 0644]
domain-extensions/l2-l3/src/test/java/org/opendaylight/groupbasedpolicy/domain_extension/l2_l3/util/L2L3IidFactoryTest.java [new file with mode: 0644]
domain-extensions/pom.xml [new file with mode: 0644]
features/pom.xml
features/src/main/features/features.xml
groupbasedpolicy/src/main/java/org/opendaylight/controller/config/yang/config/groupbasedpolicy/DomainSpecificRegistryModule.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/api/EndpointAugmentor.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/api/NetworkDomainAugmentor.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/forwarding/NetworkDomainAugmentorRegistryImpl.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/location/resolver/LocationResolver.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/renderer/RendererConfigurationBuilder.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/renderer/RendererManager.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/renderer/RendererUtils.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/resolver/ForwardingResolver.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/util/IidFactory.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/util/NetUtils.java
groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/base_endpoint/BaseEndpointServiceImplTest.java
groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/location/resolver/LocationResolverTest.java
groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/renderer/RendererManagerDataBrokerTest.java
groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/renderer/RendererManagerTest.java
groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/renderer/TestDataFactory.java
groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/util/IidFactoryTest.java
location-providers/ne-location-provider/pom.xml
location-providers/ne-location-provider/src/main/java/org/opendaylight/groupbasedpolicy/ne/location/provider/NeLocationProvider.java
location-providers/ne-location-provider/src/test/java/org/opendaylight/groupbasedpolicy/ne/location/provider/NeLocationProviderTest.java
neutron-mapper/pom.xml
neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronNetworkAware.java
neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronPortAware.java
neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronRouterAware.java
neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronSubnetAware.java
neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/util/NetworkUtils.java
neutron-vpp-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/vpp/mapper/NeutronVppMapper.java
neutron-vpp-mapper/src/main/yang/neutron-vpp-mapper-impl.yang
pom.xml
renderers/ofoverlay/pom.xml
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/OFStatisticsManager.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/ReadGbpFlowCacheTask.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/ResolvedPolicyClassifierListener.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/SFlowRTConnection.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/util/SFlowQueryParams.java [new file with mode: 0644]
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/arp/ArpTaskerTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/arp/ArpUtilsTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/endpoint/EndpointManagerListenerTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/endpoint/EndpointManagerTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/endpoint/OfOverlayAugTest.java [new file with mode: 0644]
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/endpoint/OfOverlayContextListenerTest.java [new file with mode: 0644]
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/endpoint/OfOverlayL3ContextListenerTest.java [new file with mode: 0644]
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/endpoint/OfOverlayL3NatAugTest.java [new file with mode: 0644]
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/equivalence/BucketsEquivalenceTest.java [new file with mode: 0644]
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/equivalence/GroupEquivalenceTest.java [new file with mode: 0644]
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/JsonRestClientResponseTest.java [new file with mode: 0644]
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/JsonRestClientTest.java [new file with mode: 0644]
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/OFStatisticsManagerTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/ProcessDataTaskTest.java [new file with mode: 0644]
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/ReadGbpFlowCacheTaskTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/ResolvedPolicyClassifierListenerTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/SFlowRTConnectionTest.java [new file with mode: 0644]
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/SflowClientSettingsListenerTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/test/TransactionMockUtils.java [new file with mode: 0644]
renderers/vpp/pom.xml
renderers/vpp/src/main/java/org/opendaylight/controller/config/yang/config/vpp_provider/impl/GbpVppProviderModule.java [moved from renderers/vpp/src/main/java/org/opendaylight/controller/config/yang/config/vpp_provider/impl/VppProviderModule.java with 60% similarity]
renderers/vpp/src/main/java/org/opendaylight/controller/config/yang/config/vpp_provider/impl/GbpVppProviderModuleFactory.java [moved from renderers/vpp/src/main/java/org/opendaylight/controller/config/yang/config/vpp_provider/impl/VppProviderModuleFactory.java with 77% similarity]
renderers/vpp/src/main/java/org/opendaylight/groupbasedpolicy/renderer/vpp/commands/AbstractInterfaceCommand.java [new file with mode: 0644]
renderers/vpp/src/main/java/org/opendaylight/groupbasedpolicy/renderer/vpp/commands/ConfigCommand.java [new file with mode: 0644]
renderers/vpp/src/main/java/org/opendaylight/groupbasedpolicy/renderer/vpp/commands/VhostUserCommand.java [new file with mode: 0644]
renderers/vpp/src/main/java/org/opendaylight/groupbasedpolicy/renderer/vpp/util/General.java [new file with mode: 0644]
renderers/vpp/src/main/java/org/opendaylight/groupbasedpolicy/renderer/vpp/util/VppIidFactory.java [new file with mode: 0644]
renderers/vpp/src/main/yang/vbd/ietf-ip@2014-06-16.yang [new file with mode: 0644]
renderers/vpp/src/main/yang/vbd/v3po@2015-01-05.yang [new file with mode: 0644]
renderers/vpp/src/main/yang/vpp-provider-impl.yang
renderers/vpp/src/main/yang/vpp-renderer.yang
renderers/vpp/src/test/java/org/opendaylight/groupbasedpolicy/renderer/vpp/CustomDataBrokerTest.java [new file with mode: 0644]
renderers/vpp/src/test/java/org/opendaylight/groupbasedpolicy/renderer/vpp/VppRendererDataBrokerTest.java [new file with mode: 0644]
renderers/vpp/src/test/java/org/opendaylight/groupbasedpolicy/renderer/vpp/commands/VhostUserCommandTest.java [new file with mode: 0644]
sxp-mapper/pom.xml

index c8d26b90bcb2eead9c5918921da08a507c87a542..e6d732605682328b74caf012dd78a94f58a3e422 100755 (executable)
         <artifactId>groupbasedpolicy</artifactId>
         <version>${project.version}</version>
       </dependency>
+      <dependency>
+        <groupId>${project.groupId}</groupId>
+        <artifactId>l2-l3-domain-extension</artifactId>
+        <version>${project.version}</version>
+      </dependency>
       <dependency>
         <groupId>${project.groupId}</groupId>
         <artifactId>ofoverlay-renderer</artifactId>
         <type>xml</type>
         <classifier>config</classifier>
       </dependency>
+      <dependency>
+        <groupId>org.opendaylight.groupbasedpolicy</groupId>
+        <artifactId>l2-l3-domain-extension</artifactId>
+        <version>${project.version}</version>
+        <type>xml</type>
+        <classifier>config</classifier>
+      </dependency>
       <dependency>
         <groupId>${project.groupId}</groupId>
         <artifactId>ofoverlay-renderer</artifactId>
diff --git a/domain-extensions/l2-l3/pom.xml b/domain-extensions/l2-l3/pom.xml
new file mode 100644 (file)
index 0000000..61da72d
--- /dev/null
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+  This program and the accompanying materials are made available under the
+  terms of the Eclipse Public License v1.0 which accompanies this distribution,
+  and is available at http://www.eclipse.org/legal/epl-v10.html -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.opendaylight.groupbasedpolicy</groupId>
+    <artifactId>groupbasedpolicy-domain-extensions</artifactId>
+    <version>0.4.0-SNAPSHOT</version>
+    <relativePath>../</relativePath>
+  </parent>
+
+  <artifactId>l2-l3-domain-extension</artifactId>
+  <packaging>bundle</packaging>
+
+  <dependencies>
+    <!-- testing dependencies -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-all</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal-binding-broker-impl</artifactId>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.groupbasedpolicy</groupId>
+      <artifactId>groupbasedpolicy</artifactId>
+      <version>${project.version}</version>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.powermock</groupId>
+      <artifactId>powermock-module-junit4</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.powermock</groupId>
+      <artifactId>powermock-api-mockito</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <!-- project build -->
+  <build>
+    <!-- We use the maven-resources-plugin to copy a class from the groupbasepolicy
+      bundle that we need in order to run some unit tests in the renderer (classes
+      in the test directory aren't packaged in bundles, and instead of keeping
+      separate copies, we just copy the file(s) needed in order to run the test). -->
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Export-Package>
+              org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.*,
+              org.opendaylight.groupbasedpolicy.domain_extension.l2_l3.util
+            </Export-Package>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/domain-extensions/l2-l3/src/main/config/default-config.xml b/domain-extensions/l2-l3/src/main/config/default-config.xml
new file mode 100644 (file)
index 0000000..ffeaa62
--- /dev/null
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+ Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+<snapshot>
+    <configuration>
+        <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
+            <modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
+                <module>
+                    <type xmlns:l2l3="urn:opendaylight:params:xml:ns:yang:controller:config:domain_extension:l2_l3:impl">
+                        l2l3:l2-l3-domain-extension-impl
+                    </type>
+                    <name>l2-l3-domain-extension-impl</name>
+
+                    <domain-specific-registry>
+                        <type xmlns:gbp="urn:opendaylight:params:xml:ns:yang:controller:config:groupbasedpolicy">gbp:domain-specific-registry</type>
+                        <name>domain-specific-registry</name>
+                    </domain-specific-registry>
+                </module>
+            </modules>
+        </data>
+
+    </configuration>
+
+    <required-capabilities>
+        <capability>urn:opendaylight:params:xml:ns:yang:controller:config:domain_extension:l2_l3:impl?module=l2-l3-domain-extension-cfg&amp;revision=2016-05-25</capability>
+    </required-capabilities>
+
+</snapshot>
diff --git a/domain-extensions/l2-l3/src/main/java/org/opendaylight/controller/config/yang/config/domain_extension/l2_l3/impl/L2L3DomainExtensionModule.java b/domain-extensions/l2-l3/src/main/java/org/opendaylight/controller/config/yang/config/domain_extension/l2_l3/impl/L2L3DomainExtensionModule.java
new file mode 100644 (file)
index 0000000..80534ec
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.config.yang.config.domain_extension.l2_l3.impl;
+
+import org.opendaylight.groupbasedpolicy.api.DomainSpecificRegistry;
+import org.opendaylight.groupbasedpolicy.domain_extension.l2_l3.L2L3NetworkDomainAugmentor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+public class L2L3DomainExtensionModule extends org.opendaylight.controller.config.yang.config.domain_extension.l2_l3.impl.AbstractL2L3DomainExtensionModule {
+
+    private static final Logger LOG = LoggerFactory.getLogger(L2L3DomainExtensionModule.class);
+
+    public L2L3DomainExtensionModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+        super(identifier, dependencyResolver);
+    }
+
+    public L2L3DomainExtensionModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.config.domain_extension.l2_l3.impl.L2L3DomainExtensionModule oldModule, java.lang.AutoCloseable oldInstance) {
+        super(identifier, dependencyResolver, oldModule, oldInstance);
+    }
+
+    @Override
+    public void customValidation() {
+        // add custom validation form module attributes here.
+    }
+
+    @Override
+    public java.lang.AutoCloseable createInstance() {
+        DomainSpecificRegistry domainSpecificRegistry = getDomainSpecificRegistryDependency();
+        Preconditions.checkNotNull(domainSpecificRegistry);
+        L2L3NetworkDomainAugmentor l2l3NetworkDomainAugmentor =
+                new L2L3NetworkDomainAugmentor(domainSpecificRegistry.getNetworkDomainAugmentorRegistry());
+        LOG.info("{} successfully started.", L2L3DomainExtensionModule.class.getCanonicalName());
+        return l2l3NetworkDomainAugmentor;
+    }
+
+}
diff --git a/domain-extensions/l2-l3/src/main/java/org/opendaylight/controller/config/yang/config/domain_extension/l2_l3/impl/L2L3DomainExtensionModuleFactory.java b/domain-extensions/l2-l3/src/main/java/org/opendaylight/controller/config/yang/config/domain_extension/l2_l3/impl/L2L3DomainExtensionModuleFactory.java
new file mode 100644 (file)
index 0000000..61bfa02
--- /dev/null
@@ -0,0 +1,12 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.config.yang.config.domain_extension.l2_l3.impl;
+public class L2L3DomainExtensionModuleFactory extends org.opendaylight.controller.config.yang.config.domain_extension.l2_l3.impl.AbstractL2L3DomainExtensionModuleFactory {
+
+}
diff --git a/domain-extensions/l2-l3/src/main/java/org/opendaylight/groupbasedpolicy/domain_extension/l2_l3/L2L3NetworkDomainAugmentor.java b/domain-extensions/l2-l3/src/main/java/org/opendaylight/groupbasedpolicy/domain_extension/l2_l3/L2L3NetworkDomainAugmentor.java
new file mode 100644 (file)
index 0000000..9b8fe27
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * 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.domain_extension.l2_l3;
+
+import java.util.AbstractMap.SimpleImmutableEntry;
+import java.util.Map.Entry;
+
+import org.opendaylight.groupbasedpolicy.api.NetworkDomainAugmentor;
+import org.opendaylight.groupbasedpolicy.api.NetworkDomainAugmentorRegistry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.SubnetAugmentForwarding;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.SubnetAugmentRenderer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.SubnetAugmentRendererBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.forwarding.by.tenant.NetworkDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.forwarding.renderer.forwarding.by.tenant.RendererNetworkDomain;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+
+import com.google.common.base.Preconditions;
+
+public class L2L3NetworkDomainAugmentor implements NetworkDomainAugmentor, AutoCloseable {
+
+    private final NetworkDomainAugmentorRegistry networkDomainAugmentorRegistry;
+
+    public L2L3NetworkDomainAugmentor(NetworkDomainAugmentorRegistry networkDomainAugmentorRegistry) {
+        this.networkDomainAugmentorRegistry = Preconditions.checkNotNull(networkDomainAugmentorRegistry);
+        this.networkDomainAugmentorRegistry.register(this);
+    }
+
+    @Override
+    public Entry<Class<? extends Augmentation<RendererNetworkDomain>>, Augmentation<RendererNetworkDomain>> buildRendererNetworkDomainAugmentation(
+            NetworkDomain input) {
+        SubnetAugmentForwarding subnetForwarding = input.getAugmentation(SubnetAugmentForwarding.class);
+        if (subnetForwarding == null) {
+            return null;
+        }
+        return new SimpleImmutableEntry<>(SubnetAugmentRenderer.class,
+                new SubnetAugmentRendererBuilder(subnetForwarding).build());
+    }
+
+    @Override
+    public void close() throws Exception {
+        networkDomainAugmentorRegistry.unregister(this);
+    }
+
+}
diff --git a/domain-extensions/l2-l3/src/main/java/org/opendaylight/groupbasedpolicy/domain_extension/l2_l3/util/L2L3IidFactory.java b/domain-extensions/l2-l3/src/main/java/org/opendaylight/groupbasedpolicy/domain_extension/l2_l3/util/L2L3IidFactory.java
new file mode 100644 (file)
index 0000000..99f7a59
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * 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.domain_extension.l2_l3.util;
+
+import org.opendaylight.groupbasedpolicy.util.IidFactory;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContextId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.NetworkDomainId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L2BridgeDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L2FloodDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.Subnet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.forwarding.by.tenant.ForwardingContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.forwarding.by.tenant.ForwardingContextKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.forwarding.by.tenant.NetworkDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.forwarding.by.tenant.NetworkDomainKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class L2L3IidFactory {
+
+    public static InstanceIdentifier<NetworkDomain> subnetIid(TenantId tenantId, NetworkDomainId id) {
+        NetworkDomainKey domainKey = new NetworkDomainKey(id, Subnet.class);
+        return IidFactory.forwardingByTenantIid(tenantId).child(NetworkDomain.class, domainKey);
+    }
+
+    public static InstanceIdentifier<ForwardingContext> l2FloodDomainIid(TenantId tenantId, ContextId id) {
+        ForwardingContextKey domainKey = new ForwardingContextKey(id, L2FloodDomain.class);
+        return IidFactory.forwardingByTenantIid(tenantId).child(ForwardingContext.class, domainKey);
+    }
+
+    public static InstanceIdentifier<ForwardingContext> l2BridgeDomainIid(TenantId tenantId, ContextId id) {
+        ForwardingContextKey domainKey = new ForwardingContextKey(id, L2BridgeDomain.class);
+        return IidFactory.forwardingByTenantIid(tenantId).child(ForwardingContext.class, domainKey);
+    }
+
+    public static InstanceIdentifier<ForwardingContext> l3ContextIid(TenantId tenantId, ContextId id) {
+        ForwardingContextKey domainKey = new ForwardingContextKey(id, L3Context.class);
+        return IidFactory.forwardingByTenantIid(tenantId).child(ForwardingContext.class, domainKey);
+    }
+
+}
diff --git a/domain-extensions/l2-l3/src/main/yang/l2-l3-domain-extension-cfg.yang b/domain-extensions/l2-l3/src/main/yang/l2-l3-domain-extension-cfg.yang
new file mode 100644 (file)
index 0000000..548197b
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+module l2-l3-domain-extension-cfg {
+    yang-version 1;
+    namespace "urn:opendaylight:params:xml:ns:yang:controller:config:domain_extension:l2_l3:impl";
+    prefix "gbpcfg";
+
+    import config { prefix config; revision-date 2013-04-05; }
+    import opendaylight-md-sal-binding { prefix mdsal; revision-date 2013-10-28; }
+    import groupbasedpolicy-cfg { prefix gbpcfg; revision-date 2015-11-06; }
+
+    description
+        "This module contains the base YANG definitions for
+          l2-l3 domain exstension implementation.";
+
+    revision "2016-05-25" {
+        description
+            "Initial revision.";
+    }
+
+    identity l2-l3-domain-extension-impl {
+        base "config:module-type";
+
+        config:java-name-prefix L2L3DomainExtension;
+    }
+
+    // Augments the 'configuration' choice node under modules/module.
+    augment "/config:modules/config:module/config:configuration" {
+        case l2-l3-domain-extension-impl {
+            when "/config:modules/config:module/config:type = 'l2-l3-domain-extension-impl'";
+
+            // DomainSpecificRegistry service
+            container domain-specific-registry {
+                uses config:service-ref {
+                    refine type {
+                        config:required-identity gbpcfg:domain-specific-registry;
+                    }
+                }
+            }
+        }
+    }
+}
diff --git a/domain-extensions/l2-l3/src/test/java/org/opendaylight/groupbasedpolicy/domain_extension/l2_l3/L2L3NetworkDomainAugmentorTest.java b/domain-extensions/l2-l3/src/test/java/org/opendaylight/groupbasedpolicy/domain_extension/l2_l3/L2L3NetworkDomainAugmentorTest.java
new file mode 100644 (file)
index 0000000..ba08683
--- /dev/null
@@ -0,0 +1,115 @@
+package org.opendaylight.groupbasedpolicy.domain_extension.l2_l3;
+
+import java.util.Arrays;
+import java.util.Map.Entry;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.groupbasedpolicy.api.NetworkDomainAugmentorRegistry;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.NetworkDomainId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.SubnetAugmentForwarding;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.SubnetAugmentForwardingBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.SubnetAugmentRenderer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.has.subnet.SubnetBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.has.subnet.subnet.Gateways;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.has.subnet.subnet.GatewaysBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.has.subnet.subnet.gateways.PrefixesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.forwarding.by.tenant.NetworkDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.forwarding.by.tenant.NetworkDomainBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.forwarding.renderer.forwarding.by.tenant.RendererNetworkDomain;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+
+@RunWith(MockitoJUnitRunner.class)
+public class L2L3NetworkDomainAugmentorTest {
+
+    private static final IpPrefix IP_PREFIX = new IpPrefix(new Ipv4Prefix("1.1.1.1/24"));
+    private static final IpPrefix IP_PREFIX_2 = new IpPrefix(new Ipv4Prefix("2.2.2.2/24"));
+    private static final IpAddress IP_ADDRESS = new IpAddress(new Ipv4Address("1.1.1.1"));
+    private static final IpAddress IP_ADDRESS_2 = new IpAddress(new Ipv4Address("2.2.2.2"));
+    private static final NetworkDomainId NET_DOMAIN = new NetworkDomainId("netDomain1");
+
+    @Rule
+    public ExpectedException exception = ExpectedException.none();
+    @Mock
+    private NetworkDomainAugmentorRegistry networkDomainAugmentorRegistry;
+
+    private L2L3NetworkDomainAugmentor l2l3Augmentor;
+
+    @Before
+    public void init() {
+        l2l3Augmentor = new L2L3NetworkDomainAugmentor(networkDomainAugmentorRegistry);
+    }
+
+    @Test
+    public void testConstructor() {
+        L2L3NetworkDomainAugmentor l2l3NetworkDomainAugmentor =
+                new L2L3NetworkDomainAugmentor(networkDomainAugmentorRegistry);
+        Mockito.verify(networkDomainAugmentorRegistry).register(Mockito.eq(l2l3NetworkDomainAugmentor));
+    }
+
+    @Test
+    public void testConstructor_npe_exception() {
+        exception.expect(NullPointerException.class);
+        new L2L3NetworkDomainAugmentor(null);
+    }
+
+    @Test
+    public void testClose() throws Exception {
+        l2l3Augmentor.close();
+        Mockito.verify(networkDomainAugmentorRegistry).register(Mockito.eq(l2l3Augmentor));
+    }
+
+    @Test
+    public void testBuildRendererNetworkDomainAugmentation() {
+        Gateways gateways = new GatewaysBuilder().setGateway(IP_ADDRESS)
+            .setPrefixes(Arrays.asList(new PrefixesBuilder().setPrefix(IP_PREFIX_2).build()))
+            .build();
+        SubnetAugmentForwarding subnetAugmentForwarding =
+                new SubnetAugmentForwardingBuilder().setSubnet(new SubnetBuilder().setIpPrefix(IP_PREFIX)
+                    .setGateways(Arrays.asList(gateways))
+                    .setVirtualRouterIp(IP_ADDRESS_2)
+                    .build()).build();
+        NetworkDomain networkDomain = new NetworkDomainBuilder()
+            .setNetworkDomainType(
+                    org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.NetworkDomain.class)
+            .setNetworkDomainId(NET_DOMAIN)
+            .addAugmentation(SubnetAugmentForwarding.class, subnetAugmentForwarding)
+            .build();
+
+        Entry<Class<? extends Augmentation<RendererNetworkDomain>>, Augmentation<RendererNetworkDomain>> rendererNetworkDomainAugmentation =
+                l2l3Augmentor.buildRendererNetworkDomainAugmentation(networkDomain);
+
+        Assert.assertNotNull(rendererNetworkDomainAugmentation);
+        Assert.assertEquals(SubnetAugmentRenderer.class, rendererNetworkDomainAugmentation.getKey());
+        Augmentation<RendererNetworkDomain> rendererNetDomainAug = rendererNetworkDomainAugmentation.getValue();
+        Assert.assertTrue(rendererNetDomainAug instanceof SubnetAugmentRenderer);
+        SubnetAugmentRenderer subnetAugmentRenderer = (SubnetAugmentRenderer) rendererNetDomainAug;
+        Assert.assertEquals(subnetAugmentForwarding.getSubnet(), subnetAugmentRenderer.getSubnet());
+    }
+
+    @Test
+    public void testBuildRendererNetworkDomainAugmentation_nullAugmentation() {
+        NetworkDomain networkDomain = new NetworkDomainBuilder()
+            .setNetworkDomainType(
+                    org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.NetworkDomain.class)
+            .setNetworkDomainId(NET_DOMAIN)
+            .build();
+
+        Entry<Class<? extends Augmentation<RendererNetworkDomain>>, Augmentation<RendererNetworkDomain>> rendererNetworkDomainAugmentation =
+                l2l3Augmentor.buildRendererNetworkDomainAugmentation(networkDomain);
+
+        Assert.assertNull(rendererNetworkDomainAugmentation);
+    }
+
+}
diff --git a/domain-extensions/l2-l3/src/test/java/org/opendaylight/groupbasedpolicy/domain_extension/l2_l3/util/L2L3IidFactoryTest.java b/domain-extensions/l2-l3/src/test/java/org/opendaylight/groupbasedpolicy/domain_extension/l2_l3/util/L2L3IidFactoryTest.java
new file mode 100644 (file)
index 0000000..4edb0f8
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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.domain_extension.l2_l3.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContextId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.ForwardingByTenant;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.forwarding.by.tenant.ForwardingContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.forwarding.by.tenant.NetworkDomain;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class L2L3IidFactoryTest {
+
+    private static final TenantId TENANT_ID = new TenantId("t1");
+    private static final ContextId CONTEXT_ID = new ContextId("ctx1");
+
+    @Test
+    public void testL2FloodDomainIid() {
+        InstanceIdentifier<ForwardingContext> identifier = L2L3IidFactory.l2FloodDomainIid(TENANT_ID, CONTEXT_ID);
+        Assert.assertEquals(CONTEXT_ID, InstanceIdentifier.keyOf(identifier).getContextId());
+        Assert.assertEquals(TENANT_ID, identifier.firstKeyOf(ForwardingByTenant.class).getTenantId());
+    }
+
+    @Test
+    public void testL2BridgeDomainIid() {
+        InstanceIdentifier<ForwardingContext> identifier = L2L3IidFactory.l2BridgeDomainIid(TENANT_ID, CONTEXT_ID);
+        Assert.assertEquals(CONTEXT_ID, InstanceIdentifier.keyOf(identifier).getContextId());
+        Assert.assertEquals(TENANT_ID, identifier.firstKeyOf(ForwardingByTenant.class).getTenantId());
+    }
+
+    @Test
+    public void testL3ContextIid() {
+        InstanceIdentifier<ForwardingContext> identifier = L2L3IidFactory.l3ContextIid(TENANT_ID, CONTEXT_ID);
+        Assert.assertEquals(CONTEXT_ID, InstanceIdentifier.keyOf(identifier).getContextId());
+        Assert.assertEquals(TENANT_ID, identifier.firstKeyOf(ForwardingByTenant.class).getTenantId());
+    }
+
+    @Test
+    public void testSubnetIid() {
+        InstanceIdentifier<NetworkDomain> identifier = L2L3IidFactory.subnetIid(TENANT_ID, CONTEXT_ID);
+        Assert.assertEquals(TENANT_ID, identifier.firstKeyOf(ForwardingByTenant.class).getTenantId());
+        Assert.assertEquals(CONTEXT_ID, identifier.firstKeyOf(NetworkDomain.class).getNetworkDomainId());
+    }
+}
diff --git a/domain-extensions/pom.xml b/domain-extensions/pom.xml
new file mode 100644 (file)
index 0000000..24650ba
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. 
+  This program and the accompanying materials are made available under the 
+  terms of the Eclipse Public License v1.0 which accompanies this distribution, 
+  and is available at http://www.eclipse.org/legal/epl-v10.html -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+    <groupId>org.opendaylight.controller</groupId>
+    <artifactId>config-parent</artifactId>
+    <version>0.5.0-SNAPSHOT</version>
+    <relativePath/>
+  </parent>
+
+  <groupId>org.opendaylight.groupbasedpolicy</groupId>
+  <artifactId>groupbasedpolicy-domain-extensions</artifactId>
+  <version>0.4.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <modules>
+    <module>l2-l3</module>
+  </modules>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.opendaylight.groupbasedpolicy</groupId>
+      <artifactId>groupbasedpolicy</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+  </dependencies>
+</project>
index 72cc9ac6362faa2b299602a608c835c152eaafb7..69aefacff315b54213ffa71086105c57ba0678b6 100755 (executable)
       <groupId>org.opendaylight.groupbasedpolicy</groupId>
       <artifactId>groupbasedpolicy</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.groupbasedpolicy</groupId>
+      <artifactId>l2-l3-domain-extension</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.groupbasedpolicy</groupId>
       <artifactId>ofoverlay-renderer</artifactId>
       <type>xml</type>
       <classifier>config</classifier>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.groupbasedpolicy</groupId>
+      <artifactId>l2-l3-domain-extension</artifactId>
+      <type>xml</type>
+      <classifier>config</classifier>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.groupbasedpolicy</groupId>
       <artifactId>ofoverlay-renderer</artifactId>
index 379b1c9198662cc9848b133645006bd2aa28256d..591ed7fc0df403096139c1955058755327f8a166 100755 (executable)
     <feature name='odl-groupbasedpolicy-neutronmapper' version='${project.version}' description='OpenDaylight :: groupbasedpolicy :: Neutron Mapper mapps neutron APIs to GBP APIs '>
         <feature version="${neutron.version}">odl-neutron-service</feature>
         <feature version="${project.version}">odl-groupbasedpolicy-base</feature>
+        <bundle>mvn:org.opendaylight.groupbasedpolicy/l2-l3-domain-extension/{{VERSION}}</bundle>
         <bundle>mvn:org.opendaylight.neutron/dummyprovider/{{VERSION}}</bundle>
         <bundle>mvn:org.opendaylight.groupbasedpolicy/neutron-mapper/{{VERSION}}</bundle>
+        <configfile finalname="${config.configfile.directory}/15-l2-l3-domain-extension.xml">mvn:org.opendaylight.groupbasedpolicy/l2-l3-domain-extension/{{VERSION}}/xml/config</configfile>
         <configfile finalname="${config.configfile.directory}/15-neutron-mapper.xml">mvn:org.opendaylight.groupbasedpolicy/neutron-mapper/{{VERSION}}/xml/config</configfile>
     </feature>
 
     -->
     <feature name='odl-groupbasedpolicy-vpp' version='${project.version}' description='OpenDaylight :: groupbasedpolicy :: VPP renderer '>
         <feature version="${project.version}">odl-groupbasedpolicy-base</feature>
+        <bundle>mvn:org.opendaylight.groupbasedpolicy/l2-l3-domain-extension/{{VERSION}}</bundle>
         <bundle>mvn:org.opendaylight.groupbasedpolicy/vpp-renderer/{{VERSION}}</bundle>
+        <configfile finalname="${config.configfile.directory}/15-l2-l3-domain-extension.xml">mvn:org.opendaylight.groupbasedpolicy/l2-l3-domain-extension/{{VERSION}}/xml/config</configfile>
         <configfile finalname="${config.configfile.directory}/15-vpp-renderer.xml">mvn:org.opendaylight.groupbasedpolicy/vpp-renderer/{{VERSION}}/xml/config</configfile>
     </feature>
 
     <feature name='odl-groupbasedpolicy-sxp-mapper' version='${project.version}' description='OpenDaylight :: groupbasedpolicy :: sxp-mapper'>
         <feature version="${project.version}">odl-groupbasedpolicy-base</feature>
         <feature version="${sxp.version}">odl-sxp-core</feature>
+        <bundle>mvn:org.opendaylight.groupbasedpolicy/l2-l3-domain-extension/{{VERSION}}</bundle>
         <bundle>mvn:commons-net/commons-net/{{VERSION}}</bundle>
         <bundle>mvn:org.opendaylight.groupbasedpolicy/sxp-mapper/{{VERSION}}</bundle>
+        <configfile finalname="${config.configfile.directory}/15-l2-l3-domain-extension.xml">mvn:org.opendaylight.groupbasedpolicy/l2-l3-domain-extension/{{VERSION}}/xml/config</configfile>
         <configfile finalname="${config.configfile.directory}/15-groupbasedpolicy-sxp-mapper.xml">mvn:org.opendaylight.groupbasedpolicy/sxp-mapper/{{VERSION}}/xml/config</configfile>
     </feature>
 
     -->
     <feature name='odl-groupbasedpolicy-ne-location-provider' version='${project.version}' description='OpenDaylight :: groupbasedpolicy :: NE location provider'>
         <feature version="${project.version}">odl-groupbasedpolicy-base</feature>
+        <bundle>mvn:org.opendaylight.groupbasedpolicy/l2-l3-domain-extension/{{VERSION}}</bundle>
         <bundle>mvn:org.opendaylight.groupbasedpolicy/ne-location-provider/{{VERSION}}</bundle>
+        <configfile finalname="${config.configfile.directory}/15-l2-l3-domain-extension.xml">mvn:org.opendaylight.groupbasedpolicy/l2-l3-domain-extension/{{VERSION}}/xml/config</configfile>
         <configfile finalname="${config.configfile.directory}/15-ne-location-provider.xml">mvn:org.opendaylight.groupbasedpolicy/ne-location-provider/{{VERSION}}/xml/config</configfile>
     </feature>
 
     <!--
        IOS-XE renderer
-   -->
+    -->
     <feature name='odl-groupbasedpolicy-ios-xe' version='${project.version}' description='OpenDaylight :: groupbasedpolicy :: ios-xe renderer'>
         <feature version="${project.version}">odl-groupbasedpolicy-base</feature>
         <feature version="${sfc.version}">odl-sfc-provider</feature>
         <feature version="${sxp.version}">odl-sxp-core</feature>
         <feature version="${netconf.version}">odl-netconf-topology</feature>
+        <bundle>mvn:org.opendaylight.groupbasedpolicy/l2-l3-domain-extension/{{VERSION}}</bundle>
         <bundle>mvn:org.opendaylight.groupbasedpolicy/sxp-mapper/{{VERSION}}</bundle>
         <bundle>mvn:org.opendaylight.groupbasedpolicy/ios-xe-renderer/{{VERSION}}</bundle>
+        <configfile finalname="${config.configfile.directory}/15-l2-l3-domain-extension.xml">mvn:org.opendaylight.groupbasedpolicy/l2-l3-domain-extension/{{VERSION}}/xml/config</configfile>
         <configfile finalname="${config.configfile.directory}/15-groupbasedpolicy-ios-xe-renderer.xml">mvn:org.opendaylight.groupbasedpolicy/ios-xe-renderer/{{VERSION}}/xml/config</configfile>
     </feature>
 </features>
index b237883b130a88c4813d17c1c631b8be871e2bac..aed35222d879e73b715cb21fb64e603ce03f2e01 100644 (file)
@@ -57,7 +57,7 @@ public class DomainSpecificRegistryModule extends org.opendaylight.controller.co
             endpointAugmentorRegistryImpl = new EndpointAugmentorRegistryImpl();
             netDomainAugmentorRegistryImpl = new NetworkDomainAugmentorRegistryImpl();
             baseEndpointServiceImpl = new BaseEndpointServiceImpl(dataProvider, rpcRegistry, endpointAugmentorRegistryImpl);
-            rendererManager = new RendererManager(dataProvider, netDomainAugmentorRegistryImpl);
+            rendererManager = new RendererManager(dataProvider, netDomainAugmentorRegistryImpl, endpointAugmentorRegistryImpl);
         }
 
         @Override
index 3a901cc82e9b8f0e371a5572b8477e8978880162..cc8167fba533c5a02bfe803811c3f7ecbd5793a4 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.ContainmentEndpointWithLocation;
 import org.opendaylight.yangtools.yang.binding.Augmentation;
 
+import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import java.util.Map;
 
@@ -35,7 +36,7 @@ public interface EndpointAugmentor {
      */
     @Nullable
     Map.Entry<Class<? extends Augmentation<AddressEndpoint>>, Augmentation<AddressEndpoint>> buildAddressEndpointAugmentation(
-            AddressEndpointReg input);
+            @Nonnull AddressEndpointReg input);
 
     /**
      * Creates pair of {@link ContainmentEndpoint} augmentation. Augmentation is domain specific.
@@ -48,7 +49,7 @@ public interface EndpointAugmentor {
      */
     @Nullable
     Map.Entry<Class<? extends Augmentation<ContainmentEndpoint>>, Augmentation<ContainmentEndpoint>> buildContainmentEndpointAugmentation(
-            ContainmentEndpointReg input);
+            @Nonnull ContainmentEndpointReg input);
 
     /**
      * Creates pair of {@link AddressEndpointWithLocation} augmentation. Augmentation is domain
@@ -60,7 +61,7 @@ public interface EndpointAugmentor {
      */
     @Nullable
     Map.Entry<Class<? extends Augmentation<AddressEndpointWithLocation>>, Augmentation<AddressEndpointWithLocation>> buildAddressEndpointWithLocationAugmentation(
-            AddressEndpoint input);
+            @Nonnull AddressEndpoint input);
 
     /**
      * Creates pair of {@link ContainmentEndpointWithLocation} augmentation. Augmentation is domain
@@ -72,5 +73,5 @@ public interface EndpointAugmentor {
      */
     @Nullable
     Map.Entry<Class<? extends Augmentation<ContainmentEndpointWithLocation>>, Augmentation<ContainmentEndpointWithLocation>> buildContainmentEndpointWithLocationAugmentation(
-            ContainmentEndpoint input);
+            @Nonnull ContainmentEndpoint input);
 }
index 0c7931616596e06fa9e0a9230af1aaf21cbcd147..86febdad1c0782b0cee8d7a71a105647fd362c27 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.groupbasedpolicy.api;
 
 import java.util.Map;
 
+import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.forwarding.by.tenant.NetworkDomain;
@@ -31,6 +32,6 @@ public interface NetworkDomainAugmentor {
      */
     @Nullable
     Map.Entry<Class<? extends Augmentation<RendererNetworkDomain>>, Augmentation<RendererNetworkDomain>> buildRendererNetworkDomainAugmentation(
-            NetworkDomain input);
+            @Nonnull NetworkDomain input);
 
 }
index 9c9cf04a4d68c9e7bc1c9ed986310f4e8b5a11ba..5e38d7e99d14a31b82a89e83cc1ba8ee03e0642c 100644 (file)
@@ -36,7 +36,7 @@ public class NetworkDomainAugmentorRegistryImpl implements NetworkDomainAugmento
         }
     }
 
-    public Set<NetworkDomainAugmentor> getEndpointAugmentors() {
+    public Set<NetworkDomainAugmentor> getNetworkDomainAugmentors() {
         return augmentors;
     }
 
index dfbf4d0678238af6ec101c9afc6b74e18a300585..e4b00dc8b14b245b3a6476ff227685e9fe939d60 100644 (file)
@@ -22,6 +22,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
 import org.opendaylight.groupbasedpolicy.util.IidFactory;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoint.locations.AddressEndpointLocation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoint.locations.AddressEndpointLocationBuilder;
@@ -87,7 +88,8 @@ public class LocationResolver implements DataTreeChangeListener<LocationProvider
                     break;
                 }
             }
-            wtx.submit();
+            LOG.debug("Writing endpoint location changes to DS");
+            DataStoreHelper.submitToDs(wtx);
         }
     }
 
index f23160eeb864877a6d8141fbf4e29044b0f5cf95..33908b4b1422bb399939d032d11f0ca1e73dcadd 100644 (file)
@@ -20,6 +20,7 @@ import java.util.Set;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
+import org.opendaylight.groupbasedpolicy.api.EndpointAugmentor;
 import org.opendaylight.groupbasedpolicy.api.NetworkDomainAugmentor;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoint.locations.AddressEndpointLocation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoint.locations.ContainmentEndpointLocation;
@@ -271,11 +272,11 @@ public class RendererConfigurationBuilder {
     }
 
     public Endpoints buildEndoints(EndpointInfo epInfo, EndpointLocationInfo epLocInfo,
-            Map<InstanceIdentifier<?>, RendererName> rendererByNode) {
+            Map<InstanceIdentifier<?>, RendererName> rendererByNode, Set<EndpointAugmentor> augmentors) {
         List<AddressEndpointWithLocation> epsWithLoc =
-                resolveEpsWithLoc(getAddressEndpointKeys(), epInfo, epLocInfo, rendererByNode);
+                resolveEpsWithLoc(getAddressEndpointKeys(), epInfo, epLocInfo, rendererByNode, augmentors);
         List<ContainmentEndpointWithLocation> contEpsWithLoc =
-                resolveContEpsWithLoc(getContainmentEndpointKeys(), epInfo, epLocInfo);
+                resolveContEpsWithLoc(getContainmentEndpointKeys(), epInfo, epLocInfo, augmentors);
         return new EndpointsBuilder().setAddressEndpointWithLocation(epsWithLoc)
             .setContainmentEndpointWithLocation(contEpsWithLoc)
             .build();
@@ -283,7 +284,7 @@ public class RendererConfigurationBuilder {
 
     private static List<AddressEndpointWithLocation> resolveEpsWithLoc(Set<AddressEndpointKey> epKeys,
             EndpointInfo epInfo, EndpointLocationInfo epLocInfo,
-            Map<InstanceIdentifier<?>, RendererName> rendererByNode) {
+            Map<InstanceIdentifier<?>, RendererName> rendererByNode, Set<EndpointAugmentor> augmentors) {
         List<AddressEndpointWithLocation> result = new ArrayList<>();
         for (AddressEndpointKey epKey : epKeys) {
             Optional<AddressEndpoint> potentialEp = epInfo.getEndpoint(epKey);
@@ -291,7 +292,7 @@ public class RendererConfigurationBuilder {
             Optional<AddressEndpointLocation> potentionalEpLoc = epLocInfo.getAdressEndpointLocation(epKey);
             Preconditions.checkArgument(potentionalEpLoc.isPresent());
             RendererName rendererName = resolveRendererName(potentionalEpLoc.get(), rendererByNode);
-            result.add(createEpWithLoc(potentialEp.get(), potentionalEpLoc.get(), rendererName));
+            result.add(createEpWithLoc(potentialEp.get(), potentionalEpLoc.get(), rendererName, augmentors));
         }
         return result;
     }
@@ -306,8 +307,9 @@ public class RendererConfigurationBuilder {
     }
 
     private static AddressEndpointWithLocation createEpWithLoc(AddressEndpoint ep, AddressEndpointLocation epLoc,
-            RendererName rendererName) {
-        return new AddressEndpointWithLocationBuilder().setAddress(ep.getAddress())
+            RendererName rendererName, Set<EndpointAugmentor> augmentors) {
+        AddressEndpointWithLocationBuilder addrEpWithLoc = new AddressEndpointWithLocationBuilder()
+            .setAddress(ep.getAddress())
             .setAddressType(ep.getAddressType())
             .setContextId(ep.getContextId())
             .setContextType(ep.getContextType())
@@ -320,12 +322,19 @@ public class RendererConfigurationBuilder {
             .setTimestamp(ep.getTimestamp())
             .setAbsoluteLocation(epLoc.getAbsoluteLocation())
             .setRelativeLocations(epLoc.getRelativeLocations())
-            .setRendererName(rendererName)
-            .build();
+            .setRendererName(rendererName);
+        for (EndpointAugmentor augmentor : augmentors) {
+            Entry<Class<? extends Augmentation<AddressEndpointWithLocation>>, Augmentation<AddressEndpointWithLocation>> addrEpWithLocAug =
+                    augmentor.buildAddressEndpointWithLocationAugmentation(ep);
+            if (addrEpWithLocAug != null) {
+                addrEpWithLoc.addAugmentation(addrEpWithLocAug.getKey(), addrEpWithLocAug.getValue());
+            }
+        }
+        return addrEpWithLoc.build();
     }
 
     private static List<ContainmentEndpointWithLocation> resolveContEpsWithLoc(Set<ContainmentEndpointKey> contEpKeys,
-            EndpointInfo epInfo, EndpointLocationInfo epLocInfo) {
+            EndpointInfo epInfo, EndpointLocationInfo epLocInfo, Set<EndpointAugmentor> augmentors) {
         List<ContainmentEndpointWithLocation> result = new ArrayList<>();
         for (ContainmentEndpointKey contEpKey : contEpKeys) {
             Optional<ContainmentEndpoint> potentialContEp = epInfo.getContainmentEndpoint(contEpKey);
@@ -333,14 +342,15 @@ public class RendererConfigurationBuilder {
             Optional<ContainmentEndpointLocation> potentialContEpLoc =
                     epLocInfo.getContainmentEndpointLocation(contEpKey);
             Preconditions.checkArgument(potentialContEpLoc.isPresent());
-            result.add(createContEpWithLoc(potentialContEp.get(), potentialContEpLoc.get()));
+            result.add(createContEpWithLoc(potentialContEp.get(), potentialContEpLoc.get(), augmentors));
         }
         return result;
     }
 
     private static ContainmentEndpointWithLocation createContEpWithLoc(ContainmentEndpoint contEp,
-            ContainmentEndpointLocation contEpLoc) {
-        return new ContainmentEndpointWithLocationBuilder().setContextId(contEp.getContextId())
+            ContainmentEndpointLocation contEpLoc, Set<EndpointAugmentor> augmentors) {
+        ContainmentEndpointWithLocationBuilder contEpWithLoc = new ContainmentEndpointWithLocationBuilder()
+            .setContextId(contEp.getContextId())
             .setContextType(contEp.getContextType())
             .setTenant(contEp.getTenant())
             .setChildEndpoint(contEp.getChildEndpoint())
@@ -348,8 +358,15 @@ public class RendererConfigurationBuilder {
             .setCondition(contEp.getCondition())
             .setNetworkContainment(contEp.getNetworkContainment())
             .setTimestamp(contEp.getTimestamp())
-            .setRelativeLocations(contEpLoc.getRelativeLocations())
-            .build();
+            .setRelativeLocations(contEpLoc.getRelativeLocations());
+        for (EndpointAugmentor augmentor : augmentors) {
+            Entry<Class<? extends Augmentation<ContainmentEndpointWithLocation>>, Augmentation<ContainmentEndpointWithLocation>> contEpWithLocAug =
+                    augmentor.buildContainmentEndpointWithLocationAugmentation(contEp);
+            if (contEpWithLocAug != null) {
+                contEpWithLoc.addAugmentation(contEpWithLocAug.getKey(), contEpWithLocAug.getValue());
+            }
+        }
+        return contEpWithLoc.build();
     }
 
     public RuleGroups buildRuluGroups(ResolvedPolicyInfo policyInfo) {
index 16b68886cf0c4bd655c39bbae6c313126a82831f..9f79a90a65ac005cb25300e01e1c8f45aad6f8cc 100644 (file)
@@ -23,6 +23,7 @@ import javax.annotation.Nullable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.base_endpoint.EndpointAugmentorRegistryImpl;
 import org.opendaylight.groupbasedpolicy.dto.ConsEpgKey;
 import org.opendaylight.groupbasedpolicy.dto.EpgKeyDto;
 import org.opendaylight.groupbasedpolicy.dto.ProvEpgKey;
@@ -85,12 +86,15 @@ public class RendererManager implements AutoCloseable {
 
     private final DataBroker dataProvider;
     private final NetworkDomainAugmentorRegistryImpl netDomainAugmentorRegistry;
+    private final EndpointAugmentorRegistryImpl epAugmentorRegistry;
     private final Set<RendererName> processingRenderers = new HashSet<>();
     private Map<InstanceIdentifier<?>, RendererName> rendererByNode = new HashMap<>();
     private ResolvedPolicyInfo policyInfo;
     private EndpointInfo epInfo;
     private EndpointLocationInfo epLocInfo;
     private Forwarding forwarding;
+    private boolean changesWaitingToProcess = false;
+    private boolean currentVersionHasConfig = false;
 
     private final EndpointsListener endpointsListener;
     private final EndpointLocationsListener endpointLocationsListener;
@@ -98,9 +102,11 @@ public class RendererManager implements AutoCloseable {
     private final ForwardingListener forwardingListener;
     private final RenderersListener renderersListener;
 
-    public RendererManager(DataBroker dataProvider, NetworkDomainAugmentorRegistryImpl netDomainAugmentorRegistry) {
+    public RendererManager(DataBroker dataProvider, NetworkDomainAugmentorRegistryImpl netDomainAugmentorRegistry,
+            EndpointAugmentorRegistryImpl epAugmentorRegistry) {
         this.dataProvider = checkNotNull(dataProvider);
         this.netDomainAugmentorRegistry = checkNotNull(netDomainAugmentorRegistry);
+        this.epAugmentorRegistry = checkNotNull(epAugmentorRegistry);
         endpointsListener = new EndpointsListener(this, dataProvider);
         endpointLocationsListener = new EndpointLocationsListener(this, dataProvider);
         resolvedPoliciesListener = new ResolvedPoliciesListener(this, dataProvider);
@@ -110,21 +116,25 @@ public class RendererManager implements AutoCloseable {
 
     public synchronized void endpointsUpdated(final Endpoints endpoints) {
         epInfo = new EndpointInfo(endpoints);
+        changesWaitingToProcess = true;
         processState();
     }
 
     public synchronized void endpointLocationsUpdated(final EndpointLocations epLocations) {
         epLocInfo = new EndpointLocationInfo(epLocations);
+        changesWaitingToProcess = true;
         processState();
     }
 
     public synchronized void resolvedPoliciesUpdated(final ResolvedPolicies resolvedPolicies) {
         policyInfo = new ResolvedPolicyInfo(resolvedPolicies);
+        changesWaitingToProcess = true;
         processState();
     }
 
     public synchronized void forwardingUpdated(final Forwarding forwarding) {
         this.forwarding = forwarding;
+        changesWaitingToProcess = true;
         processState();
     }
 
@@ -138,7 +148,7 @@ public class RendererManager implements AutoCloseable {
             rendererByNode.put(nodePath, renderers.asList().get(0));
         }
         if (processingRenderers.isEmpty()) {
-            processState();
+            changesWaitingToProcess = true;
         } else {
             LOG.debug("Waiting for renderers. Version {} needs to be processed by renderers: {}", version,
                     processingRenderers);
@@ -161,6 +171,7 @@ public class RendererManager implements AutoCloseable {
                 }
             }
         }
+        processState();
     }
 
     private void processState() {
@@ -172,44 +183,66 @@ public class RendererManager implements AutoCloseable {
         if (rendererByNode.values().isEmpty()) {
             return;
         }
-
-        version++;
+        if (!changesWaitingToProcess) {
+            return;
+        }
         Map<RendererName, RendererConfigurationBuilder> rendererConfigBuilderByRendererName = createRendererConfigBuilders();
-        List<Renderer> renderers = new ArrayList<>();
         Set<RendererName> rendererNames = new HashSet<>(rendererByNode.values());
+        boolean newVersionHasConfig = false;
+        Map<RendererName, Optional<Configuration>> configsByRendererName = new HashMap<>();
         for (RendererName rendererName : rendererNames) {
             RendererConfigurationBuilder rendererPolicyBuilder = rendererConfigBuilderByRendererName.get(rendererName);
             Optional<Configuration> potentialConfig = createConfiguration(rendererPolicyBuilder);
-            RendererPolicy rendererPolicy = null;
             if (potentialConfig.isPresent()) {
-                LOG.debug("Created configuration for renderer with version {}", rendererName.getValue(), version);
-                rendererPolicy =
-                        new RendererPolicyBuilder().setVersion(version).setConfiguration(potentialConfig.get()).build();
+                newVersionHasConfig = true;
+            }
+            configsByRendererName.put(rendererName, potentialConfig);
+        }
+        if (newVersionHasConfig || currentVersionHasConfig) {
+            version++;
+            if (!writeRenderersConfigs(configsByRendererName)) {
+                LOG.warn("Version {} was not dispatched successfully. Previous version is valid until next update.",
+                        version);
+                for (RendererName rendererName : rendererConfigBuilderByRendererName.keySet()) {
+                    processingRenderers.remove(rendererName);
+                }
+                version--;
+                changesWaitingToProcess = true;
+                return;
+            } else {
+                currentVersionHasConfig = newVersionHasConfig;
+            }
+        }
+        changesWaitingToProcess = false;
+    }
+
+    private boolean writeRenderersConfigs(Map<RendererName, Optional<Configuration>> configsByRendererName) {
+        List<Renderer> renderers = new ArrayList<>();
+        for (RendererName rendererName : configsByRendererName.keySet()) {
+            RendererPolicy rendererPolicy = null;
+            if (configsByRendererName.get(rendererName).isPresent()) {
+                rendererPolicy = new RendererPolicyBuilder().setVersion(version)
+                    .setConfiguration(configsByRendererName.get(rendererName).get())
+                    .build();
+
             } else {
-                rendererPolicy =
-                        new RendererPolicyBuilder().setVersion(version).build();
+                rendererPolicy = new RendererPolicyBuilder().setVersion(version).build();
             }
             renderers.add(new RendererBuilder().setName(rendererName).setRendererPolicy(rendererPolicy).build());
             processingRenderers.add(rendererName);
+            LOG.debug("Created configuration for renderer {} with version {}", rendererName.getValue(), version);
         }
         WriteTransaction wTx = dataProvider.newWriteOnlyTransaction();
         wTx.put(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(Renderers.class),
                 new RenderersBuilder().setRenderer(renderers).build());
-        if (!DataStoreHelper.submitToDs(wTx)) {
-            LOG.warn("Version {} was not dispatched successfully. Previous version is valid till next update.",
-                    version);
-            for (RendererName rendererName : rendererConfigBuilderByRendererName.keySet()) {
-                processingRenderers.remove(rendererName);
-            }
-            version--;
-        }
+        return DataStoreHelper.submitToDs(wTx);
     }
 
     /**
      * Entry is added to the result map only if:<br>
      * 1. There is at least one Address EP with absolute location
      * 2. There is a renderer responsible for that EP
-     * 
+     *
      * @return
      */
     private Map<RendererName, RendererConfigurationBuilder> createRendererConfigBuilders() {
@@ -261,14 +294,14 @@ public class RendererManager implements AutoCloseable {
         configBuilder.setRendererEndpoints(rendererEndpoints);
 
         org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.Endpoints endpoints =
-                rendererPolicyBuilder.buildEndoints(epInfo, epLocInfo, rendererByNode);
+                rendererPolicyBuilder.buildEndoints(epInfo, epLocInfo, rendererByNode, epAugmentorRegistry.getEndpointAugmentors());
         configBuilder.setEndpoints(endpoints);
 
         RuleGroups ruleGroups = rendererPolicyBuilder.buildRuluGroups(policyInfo);
         configBuilder.setRuleGroups(ruleGroups);
 
         RendererForwarding rendererForwarding = rendererPolicyBuilder.buildRendererForwarding(forwarding,
-                netDomainAugmentorRegistry.getEndpointAugmentors());
+                netDomainAugmentorRegistry.getNetworkDomainAugmentors());
         configBuilder.setRendererForwarding(rendererForwarding);
 
         return Optional.of(configBuilder.build());
@@ -355,6 +388,9 @@ public class RendererManager implements AutoCloseable {
             return;
         }
         for (AddressEndpointKey peerAdrEpKey : peerAdrEps) {
+            if (isSameKeys(rendererEpKey, peerAdrEpKey)) {
+                continue;
+            }
             ExternalImplicitGroup eig = policy.getExternalImplicitGroup();
             if (eig != null) {
                 if (!epLocInfo.hasRelativeLocation(peerAdrEpKey)) {
@@ -399,6 +435,16 @@ public class RendererManager implements AutoCloseable {
         return false;
     }
 
+    private boolean isSameKeys(RendererEndpointKey rendererEpKey, AddressEndpointKey peerAdrEpKey) {
+        if (rendererEpKey.getAddress().equals(peerAdrEpKey.getAddress())
+                && rendererEpKey.getAddressType().equals(peerAdrEpKey.getAddressType())
+                && rendererEpKey.getContextId().equals(peerAdrEpKey.getContextId())
+                && rendererEpKey.getContextType().equals(peerAdrEpKey.getContextType())) {
+            return true;
+        }
+        return false;
+    }
+
     private Set<EpgKeyDto> toEpgKeys(List<EndpointGroupId> epgIds, TenantId tenantId) {
         return FluentIterable.from(epgIds).transform(new Function<EndpointGroupId, EpgKeyDto>() {
 
index 08cec8c6e8f14bdb208f6c229a34f6db907a7410..fc24581ed421cb70ad953f7aadcdfcd52899c298 100644 (file)
@@ -32,6 +32,9 @@ public class RendererUtils {
         }
         Builder<InstanceIdentifier<?>, RendererName> renderersByNodeBuilder = ImmutableMultimap.builder();
         for (Renderer renderer : renderers) {
+            if (renderer.getRendererNodes() == null) {
+                continue;
+            }
             List<RendererNode> rendererNodes = renderer.getRendererNodes().getRendererNode();
             if (rendererNodes == null) {
                 continue;
index 4d8877efa9b0de2d4f915e57e01b73e60e050891..08ae9bcce078f0f99956e61fa08e04d01e1c508a 100644 (file)
@@ -10,9 +10,11 @@ package org.opendaylight.groupbasedpolicy.resolver;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.groupbasedpolicy.util.DataTreeChangeHandler;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.Forwarding;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.ForwardingByTenant;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
@@ -23,6 +25,8 @@ public class ForwardingResolver extends DataTreeChangeHandler<ForwardingByTenant
 
     public ForwardingResolver(DataBroker dataProvider) {
         super(dataProvider);
+        registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
+                InstanceIdentifier.builder(Forwarding.class).child(ForwardingByTenant.class).build()));
     }
 
     @Override
index 9faabd823a0f2539e103561468ee57c9b0985686..f04cf411878b634ad68ad2be511f28ed1b5bcba1 100644 (file)
@@ -39,7 +39,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2BridgeDomainId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2FloodDomainId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L3ContextId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.NetworkDomainId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.RuleName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SelectorName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubjectName;
@@ -58,19 +57,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_l
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.LocationProviderKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.location.provider.ProviderAddressEndpointLocation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.location.provider.ProviderAddressEndpointLocationKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L2BridgeDomain;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L2FloodDomain;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.Subnet;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.AddressType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.ContextType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.Forwarding;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.ForwardingByTenant;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.ForwardingByTenantKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.forwarding.by.tenant.ForwardingContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.forwarding.by.tenant.ForwardingContextKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.forwarding.by.tenant.NetworkDomain;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.forwarding.by.tenant.NetworkDomainKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.SubjectFeatureDefinitions;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.Tenants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.classifier.refs.ClassifierRef;
@@ -258,31 +249,6 @@ public class IidFactory {
             .build();
     }
 
-    public static InstanceIdentifier<NetworkDomain> subnetIid(TenantId tenantId, NetworkDomainId id) {
-        NetworkDomainKey domainKey = new NetworkDomainKey(id, Subnet.class);
-        return createForwardingByTenantIidBuilder(tenantId).child(NetworkDomain.class, domainKey).build();
-    }
-
-    public static InstanceIdentifier<ForwardingContext> l2FloodDomainIid(TenantId tenantId, ContextId id) {
-        ForwardingContextKey domainKey = new ForwardingContextKey(id, L2FloodDomain.class);
-        return createForwardingByTenantIidBuilder(tenantId).child(ForwardingContext.class, domainKey).build();
-    }
-
-    public static InstanceIdentifier<ForwardingContext> l2BridgeDomainIid(TenantId tenantId, ContextId id) {
-        ForwardingContextKey domainKey = new ForwardingContextKey(id, L2BridgeDomain.class);
-        return createForwardingByTenantIidBuilder(tenantId).child(ForwardingContext.class, domainKey).build();
-    }
-
-    public static InstanceIdentifier<ForwardingContext> l3ContextIid(TenantId tenantId, ContextId id) {
-        ForwardingContextKey domainKey = new ForwardingContextKey(id, L3Context.class);
-        return createForwardingByTenantIidBuilder(tenantId).child(ForwardingContext.class, domainKey).build();
-    }
-
-    private static InstanceIdentifierBuilder<ForwardingByTenant> createForwardingByTenantIidBuilder(TenantId tenantId) {
-        return InstanceIdentifier.builder(Forwarding.class).child(ForwardingByTenant.class,
-                new ForwardingByTenantKey(tenantId));
-    }
-
     @Deprecated
     public static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2FloodDomain> l2FloodDomainIid(TenantId tenantId,
             L2FloodDomainId l2FloodDomainId) {
index a650f11fbb1a8a66ba203f93effafe43c3875ead..36152ac498dd7cdbb58e66718a614ca3b062ac7b 100644 (file)
@@ -99,8 +99,8 @@ public final class NetUtils {
         if (prefix1.getIpv4Prefix() != null && prefix2.getIpv4Prefix() != null) {
             SubnetUtils fromPrefix1 = new SubnetUtils(prefix1.getIpv4Prefix().getValue());
             SubnetUtils fromPrefix2 = new SubnetUtils(prefix2.getIpv4Prefix().getValue());
-            if (fromPrefix1.getInfo().isInRange(fromPrefix2.getInfo().getHighAddress())
-                    && fromPrefix2.getInfo().isInRange(fromPrefix1.getInfo().getHighAddress())) {
+            if (fromPrefix1.getInfo().getNetworkAddress().equals(fromPrefix2.getInfo().getNetworkAddress())
+                    && fromPrefix1.getInfo().getNetmask().equals(fromPrefix2.getInfo().getNetmask())) {
                 return true;
             }
         } else if (prefix1.getIpv6Prefix() != null && prefix2.getIpv6Prefix() != null) {
index 9e0abe80e6e21eb7246079f1363cfff28564590a..522d149aa8480f5186e8532c7959348480582af5 100644 (file)
@@ -58,11 +58,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpo
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContextId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.NetworkDomainId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.IpPrefixType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L2FloodDomain;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.MacAddressType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.Subnet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.AddressType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.ContextType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.NetworkDomain;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
 import com.google.common.base.Optional;
@@ -77,27 +75,26 @@ public class BaseEndpointServiceImplTest extends CustomDataBrokerTest {
     private static final String CONTEXT_ID = "testContext";
     private static final long timestamp = 1234567890L;
     private static final NetworkDomainContainment networkDomainContainment = new NetworkDomainContainmentBuilder()
-        .setNetworkDomainId(new NetworkDomainId(DOMAIN)).setNetworkDomainType(Subnet.class).build();
+        .setNetworkDomainId(new NetworkDomainId(DOMAIN)).setNetworkDomainType(NetworkDomain.class).build();
     private static final ParentEndpoint BASE_L3_PARENT = new ParentEndpointBuilder().setAddress(IP_ADDRESS)
-        .setAddressType(IpPrefixType.class)
+        .setAddressType(AddressType.class)
         .setContextId(new ContextId(CONTEXT_ID))
-        .setContextType(L3Context.class)
+        .setContextType(ContextType.class)
         .build();
     private static final ChildEndpoint BASE_L2_CHILD = new ChildEndpointBuilder().setAddress(MAC_ADDRESS)
-        .setAddressType(MacAddressType.class)
+        .setAddressType(AddressType.class)
         .setContextId(new ContextId(CONTEXT_ID))
-        .setContextType(L2FloodDomain.class)
+        .setContextType(ContextType.class)
         .build();
     private static final ParentContainmentEndpoint BASE_CONT_PARENT = new ParentContainmentEndpointBuilder()
-        .setContextId(new ContextId(CONTEXT_ID)).setContextType(L2FloodDomain.class).build();
+        .setContextId(new ContextId(CONTEXT_ID)).setContextType(ContextType.class).build();
 
     private DataBroker dataProvider;
     private BaseEndpointServiceImpl baseEndpointRpcRegistry;
 
     @Override
     public Collection<Class<?>> getClassesFromModules() {
-        return ImmutableList.of(Endpoints.class, AddressEndpoints.class, ContainmentEndpoints.class,
-                MacAddressType.class, IpPrefixType.class);
+        return ImmutableList.of(Endpoints.class, AddressEndpoints.class, ContainmentEndpoints.class);
     }
 
     @Before
@@ -410,10 +407,10 @@ public class BaseEndpointServiceImplTest extends CustomDataBrokerTest {
     private AddressEndpointBuilder createBaseL2EpBuilder() {
         return new AddressEndpointBuilder().setTimestamp(timestamp)
             .setContextId(new ContextId(CONTEXT_ID))
-            .setContextType(L2FloodDomain.class)
+            .setContextType(ContextType.class)
             .setTenant(new TenantId(TENANT))
             .setAddress(MAC_ADDRESS)
-            .setAddressType(MacAddressType.class)
+            .setAddressType(AddressType.class)
             .setNetworkContainment(new NetworkContainmentBuilder().setContainment(networkDomainContainment).build())
             .setTimestamp(timestamp);
     }
@@ -421,10 +418,10 @@ public class BaseEndpointServiceImplTest extends CustomDataBrokerTest {
     private AddressEndpointBuilder createBaseL3EpBuilder() {
         return new AddressEndpointBuilder().setTimestamp(timestamp)
             .setContextId(new ContextId(CONTEXT_ID))
-            .setContextType(L3Context.class)
+            .setContextType(ContextType.class)
             .setTenant(new TenantId(TENANT))
             .setAddress(IP_ADDRESS)
-            .setAddressType(IpPrefixType.class)
+            .setAddressType(AddressType.class)
             .setNetworkContainment(new NetworkContainmentBuilder().setContainment(networkDomainContainment).build())
             .setTimestamp(timestamp);
     }
@@ -432,7 +429,7 @@ public class BaseEndpointServiceImplTest extends CustomDataBrokerTest {
     private ContainmentEndpointBuilder createBaseContEpBuilder() {
         return new ContainmentEndpointBuilder().setTimestamp(timestamp)
             .setContextId(new ContextId(CONTEXT_ID))
-            .setContextType(L2FloodDomain.class)
+            .setContextType(ContextType.class)
             .setTenant(new TenantId(TENANT))
             .setNetworkContainment(new NetworkContainmentBuilder().setContainment(networkDomainContainment).build());
     }
index 7e8c5ef351cd38021cb178c855e5c1722ede732f..1e068f558bf49e7cdd85f9144cd34a731b766617 100644 (file)
@@ -42,8 +42,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_l
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.location.provider.ProviderAddressEndpointLocationBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.location.provider.ProviderAddressEndpointLocationKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.location.provider.ProviderContainmentEndpointLocationBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.IpPrefixType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.AddressType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.ContextType;
 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;
@@ -84,12 +84,11 @@ public class LocationResolverTest extends CustomDataBrokerTest {
 
     @Override
     public Collection<Class<?>> getClassesFromModules() {
-        return ImmutableList.<Class<?>>of(LocationProvider.class, Nodes.class, L3Context.class,
-                EndpointLocations.class);
+        return ImmutableList.<Class<?>>of(LocationProvider.class, Nodes.class, EndpointLocations.class);
     }
 
     @Test
-    public void test_LocationProviderWrite() throws Exception {
+    public void testOnDataTreeChanged_write() throws Exception {
         AbsoluteLocation absoluteLocation =
                 new AbsoluteLocationBuilder().setLocationType(new InternalLocationCaseBuilder()
                     .setInternalNode(nodeIid1).setInternalNodeConnector(connectorIid).build()).build();
@@ -101,14 +100,14 @@ public class LocationResolverTest extends CustomDataBrokerTest {
         LocationProvider provider = new LocationProviderBuilder().setProvider(new ProviderName(PROVIDER_NAME))
             .setProviderAddressEndpointLocation(
                     Collections.singletonList(new ProviderAddressEndpointLocationBuilder()
-                        .setKey(new ProviderAddressEndpointLocationKey(ADDRESS, IpPrefixType.class, contextId,
-                                L3Context.class))
+                        .setKey(new ProviderAddressEndpointLocationKey(ADDRESS, AddressType.class, contextId,
+                                ContextType.class))
                         .setAbsoluteLocation(absoluteLocation)
                         .setRelativeLocations(relativeLocations)
                         .build()))
             .setProviderContainmentEndpointLocation(
                     Collections.singletonList(new ProviderContainmentEndpointLocationBuilder().setContextId(contextId)
-                        .setContextType(L3Context.class)
+                        .setContextType(ContextType.class)
                         .setRelativeLocations(relativeLocations)
                         .build()))
             .build();
@@ -126,19 +125,19 @@ public class LocationResolverTest extends CustomDataBrokerTest {
         EndpointLocations readLocations = read.get();
         assertNotNull(readLocations.getAddressEndpointLocation());
         assertEquals(1, readLocations.getAddressEndpointLocation().size());
-        assertEquals(new AddressEndpointLocationKey(ADDRESS, IpPrefixType.class, contextId, L3Context.class),
+        assertEquals(new AddressEndpointLocationKey(ADDRESS, AddressType.class, contextId, ContextType.class),
                 readLocations.getAddressEndpointLocation().get(0).getKey());
         assertEquals(absoluteLocation, readLocations.getAddressEndpointLocation().get(0).getAbsoluteLocation());
         assertNotNull(readLocations.getContainmentEndpointLocation());
         assertEquals(1, readLocations.getContainmentEndpointLocation().size());
-        assertEquals(new ContainmentEndpointLocationKey(contextId, L3Context.class),
+        assertEquals(new ContainmentEndpointLocationKey(contextId, ContextType.class),
                 readLocations.getContainmentEndpointLocation().get(0).getKey());
         assertEquals(relativeLocations, readLocations.getContainmentEndpointLocation().get(0).getRelativeLocations());
     }
 
     @Test
-    public void test_LocationProviderOverWrite() throws Exception {
-        test_LocationProviderWrite();
+    public void testOnDataTreeChanged_overWrite() throws Exception {
+        testOnDataTreeChanged_write();
         AbsoluteLocation absoluteLocation =
                 new AbsoluteLocationBuilder().setLocationType(new InternalLocationCaseBuilder()
                     .setInternalNode(nodeIid2).setInternalNodeConnector(connectorIid).build()).build();
@@ -150,14 +149,14 @@ public class LocationResolverTest extends CustomDataBrokerTest {
         LocationProvider provider = new LocationProviderBuilder().setProvider(new ProviderName(PROVIDER_NAME))
             .setProviderAddressEndpointLocation(
                     Collections.singletonList(new ProviderAddressEndpointLocationBuilder()
-                        .setKey(new ProviderAddressEndpointLocationKey(ADDRESS, IpPrefixType.class, contextId,
-                                L3Context.class))
+                        .setKey(new ProviderAddressEndpointLocationKey(ADDRESS, AddressType.class, contextId,
+                                ContextType.class))
                         .setAbsoluteLocation(absoluteLocation)
                         .setRelativeLocations(relativeLocations)
                         .build()))
             .setProviderContainmentEndpointLocation(
                     Collections.singletonList(new ProviderContainmentEndpointLocationBuilder().setContextId(contextId)
-                        .setContextType(L3Context.class)
+                        .setContextType(ContextType.class)
                         .setRelativeLocations(relativeLocations)
                         .build()))
             .build();
@@ -175,19 +174,19 @@ public class LocationResolverTest extends CustomDataBrokerTest {
         EndpointLocations readLocations = read.get();
         assertNotNull(readLocations.getAddressEndpointLocation());
         assertEquals(1, readLocations.getAddressEndpointLocation().size());
-        assertEquals(new AddressEndpointLocationKey(ADDRESS, IpPrefixType.class, contextId, L3Context.class),
+        assertEquals(new AddressEndpointLocationKey(ADDRESS, AddressType.class, contextId, ContextType.class),
                 readLocations.getAddressEndpointLocation().get(0).getKey());
         assertEquals(absoluteLocation, readLocations.getAddressEndpointLocation().get(0).getAbsoluteLocation());
         assertNotNull(readLocations.getContainmentEndpointLocation());
         assertEquals(1, readLocations.getContainmentEndpointLocation().size());
-        assertEquals(new ContainmentEndpointLocationKey(contextId, L3Context.class),
+        assertEquals(new ContainmentEndpointLocationKey(contextId, ContextType.class),
                 readLocations.getContainmentEndpointLocation().get(0).getKey());
         assertEquals(relativeLocations, readLocations.getContainmentEndpointLocation().get(0).getRelativeLocations());
     }
 
     @Test
-    public void test_LocationProviderDelete() throws Exception {
-        test_LocationProviderWrite();
+    public void testOnDataTreeChanged_delete() throws Exception {
+        testOnDataTreeChanged_write();
         InstanceIdentifier<LocationProvider> iid = InstanceIdentifier.builder(LocationProviders.class)
             .child(LocationProvider.class, new LocationProviderKey(new ProviderName(PROVIDER_NAME)))
             .build();
@@ -218,15 +217,15 @@ public class LocationResolverTest extends CustomDataBrokerTest {
     }
 
     @Test
-    public void test_LocationProviderModify() throws Exception {
-        test_LocationProviderWrite();
+    public void testOnDataTreeChanged_modify() throws Exception {
+        testOnDataTreeChanged_write();
         AbsoluteLocation absoluteLocation =
                 new AbsoluteLocationBuilder().setLocationType(new InternalLocationCaseBuilder()
                     .setInternalNode(nodeIid2).setInternalNodeConnector(connectorIid).build()).build();
         InstanceIdentifier<AbsoluteLocation> iid = InstanceIdentifier.builder(LocationProviders.class)
             .child(LocationProvider.class, new LocationProviderKey(new ProviderName(PROVIDER_NAME)))
             .child(ProviderAddressEndpointLocation.class,
-                    new ProviderAddressEndpointLocationKey(ADDRESS, IpPrefixType.class, contextId, L3Context.class))
+                    new ProviderAddressEndpointLocationKey(ADDRESS, AddressType.class, contextId, ContextType.class))
             .child(AbsoluteLocation.class)
             .build();
         WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
@@ -240,7 +239,7 @@ public class LocationResolverTest extends CustomDataBrokerTest {
         EndpointLocations readLocations = read.get();
         assertNotNull(readLocations.getAddressEndpointLocation());
         assertEquals(1, readLocations.getAddressEndpointLocation().size());
-        assertEquals(new AddressEndpointLocationKey(ADDRESS, IpPrefixType.class, contextId, L3Context.class),
+        assertEquals(new AddressEndpointLocationKey(ADDRESS, AddressType.class, contextId, ContextType.class),
                 readLocations.getAddressEndpointLocation().get(0).getKey());
         assertEquals(absoluteLocation, readLocations.getAddressEndpointLocation().get(0).getAbsoluteLocation());
     }
index 1c6c9b14ec51bacf2187b99334f840732919df5c..c6e209c2e9537d8e2a94ac729e7c257062cbca84 100644 (file)
@@ -23,6 +23,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.groupbasedpolicy.base_endpoint.EndpointAugmentorRegistryImpl;
 import org.opendaylight.groupbasedpolicy.forwarding.NetworkDomainAugmentorRegistryImpl;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.EndpointLocations;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.EndpointLocationsBuilder;
@@ -43,6 +44,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.RuleName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubjectName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.ContextType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.ForwardingBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.ForwardingByTenantBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.forwarding.by.tenant.ForwardingContextBuilder;
@@ -96,6 +98,8 @@ public class RendererManagerDataBrokerTest {
     @Mock
     private NetworkDomainAugmentorRegistryImpl netDomainAugmentorRegistry;
     @Mock
+    private EndpointAugmentorRegistryImpl epAugmentorRegistry;
+    @Mock
     private WriteTransaction wTx;
     @Mock
     private CheckedFuture<Void, TransactionCommitFailedException> submitFuture;
@@ -106,8 +110,9 @@ public class RendererManagerDataBrokerTest {
     public void init() {
         Mockito.when(dataProvider.newWriteOnlyTransaction()).thenReturn(wTx);
         Mockito.when(wTx.submit()).thenReturn(submitFuture);
-        Mockito.when(netDomainAugmentorRegistry.getEndpointAugmentors()).thenReturn(Collections.emptySet());
-        rendererManager = new RendererManager(dataProvider, netDomainAugmentorRegistry);
+        Mockito.when(netDomainAugmentorRegistry.getNetworkDomainAugmentors()).thenReturn(Collections.emptySet());
+        Mockito.when(epAugmentorRegistry.getEndpointAugmentors()).thenReturn(Collections.emptySet());
+        rendererManager = new RendererManager(dataProvider, netDomainAugmentorRegistry, epAugmentorRegistry);
         RendererManager.resetVersion();
     }
 
@@ -143,7 +148,7 @@ public class RendererManagerDataBrokerTest {
                 .setForwardingByTenant(
                         Arrays.asList(new ForwardingByTenantBuilder().setTenantId(TestDataFactory.TENANT_ID)
                             .setForwardingContext(Arrays.asList(new ForwardingContextBuilder()
-                                .setContextType(TestDataFactory.DummyContextType.class)
+                                .setContextType(ContextType.class)
                                 .setContextId(TestDataFactory.CTX_1)
                                 .build()))
                             .build()))
@@ -244,7 +249,7 @@ public class RendererManagerDataBrokerTest {
                 .setForwardingByTenant(
                         Arrays.asList(new ForwardingByTenantBuilder().setTenantId(TestDataFactory.TENANT_ID)
                             .setForwardingContext(Arrays.asList(new ForwardingContextBuilder()
-                                .setContextType(TestDataFactory.DummyContextType.class)
+                                .setContextType(ContextType.class)
                                 .setContextId(TestDataFactory.CTX_1)
                                 .build()))
                             .build()))
@@ -327,7 +332,7 @@ public class RendererManagerDataBrokerTest {
                 .setForwardingByTenant(
                         Arrays.asList(new ForwardingByTenantBuilder().setTenantId(TestDataFactory.TENANT_ID)
                             .setForwardingContext(Arrays.asList(new ForwardingContextBuilder()
-                                .setContextType(TestDataFactory.DummyContextType.class)
+                                .setContextType(ContextType.class)
                                 .setContextId(TestDataFactory.CTX_1)
                                 .build()))
                             .build()))
index 0aa8a2574bd150447d0e11b70cdf08fd8da852b7..84973e308ad827d047e7a2d6c026154976100904 100644 (file)
@@ -22,6 +22,7 @@ import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.groupbasedpolicy.base_endpoint.EndpointAugmentorRegistryImpl;
 import org.opendaylight.groupbasedpolicy.forwarding.NetworkDomainAugmentorRegistryImpl;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.EndpointLocations;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.EndpointLocationsBuilder;
@@ -75,13 +76,16 @@ public class RendererManagerTest {
     private DataBroker dataProvider;
     @Mock
     private NetworkDomainAugmentorRegistryImpl netDomainAugmentorRegistry;
+    @Mock
+    private EndpointAugmentorRegistryImpl epAugmentorRegistry;
 
     private RendererManager rendererManager;
 
     @Before
     public void init() {
-        Mockito.when(netDomainAugmentorRegistry.getEndpointAugmentors()).thenReturn(Collections.emptySet());
-        rendererManager = new RendererManager(dataProvider, netDomainAugmentorRegistry);
+        Mockito.when(netDomainAugmentorRegistry.getNetworkDomainAugmentors()).thenReturn(Collections.emptySet());
+        Mockito.when(epAugmentorRegistry.getEndpointAugmentors()).thenReturn(Collections.emptySet());
+        rendererManager = new RendererManager(dataProvider, netDomainAugmentorRegistry, epAugmentorRegistry);
     }
 
     /**
index b4e88128cf4da14c09e5af77fb4b4449a8e8cff5..2640ae036f14b8e39663fc3d37d0528ffaa30e6f 100644 (file)
@@ -82,25 +82,25 @@ public class TestDataFactory {
     }
 
     public static AddressEndpointBuilder defaultAdrEp(String address, EndpointGroupId... epgs) {
-        return new AddressEndpointBuilder().setContextType(DummyContextType.class)
+        return new AddressEndpointBuilder().setContextType(ContextType.class)
             .setContextId(CTX_1)
-            .setAddressType(DummyAddressType.class)
+            .setAddressType(AddressType.class)
             .setAddress(address)
             .setTenant(TENANT_ID)
             .setEndpointGroup(Arrays.asList(epgs))
             .setNetworkContainment(
                     new NetworkContainmentBuilder().setContainment(new ForwardingContextContainmentBuilder()
-                        .setContextType(DummyContextType.class).setContextId(CTX_1).build()).build());
+                        .setContextType(ContextType.class).setContextId(CTX_1).build()).build());
     }
 
     public static ContainmentEndpointBuilder defaultContEp(EndpointGroupId... epgs) {
-        return new ContainmentEndpointBuilder().setContextType(DummyContextType.class)
+        return new ContainmentEndpointBuilder().setContextType(ContextType.class)
             .setContextId(CTX_1)
             .setTenant(TENANT_ID)
             .setEndpointGroup(Arrays.asList(epgs))
             .setNetworkContainment(
                     new NetworkContainmentBuilder().setContainment(new ForwardingContextContainmentBuilder()
-                        .setContextType(DummyContextType.class).setContextId(CTX_1).build()).build());
+                        .setContextType(ContextType.class).setContextId(CTX_1).build()).build());
     }
 
     public static ResolvedRuleBuilder defaultResolvedRule(RuleName ruleName) {
@@ -135,8 +135,4 @@ public class TestDataFactory {
             .setPolicyRuleGroupWithEndpointConstraints(ImmutableList.of(blueRuleGrpWithoutCons));
     }
 
-    public static abstract class DummyContextType extends ContextType {
-    };
-    public static abstract class DummyAddressType extends AddressType {
-    };
 }
index 8e3a656bb1ee026ab2dc38991a3ec25cad4a36dc..c369767bbbb15f4eaad648ee8771a55f532e9b8a 100755 (executable)
@@ -13,7 +13,6 @@ import static org.mockito.Mockito.mock;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.Mockito;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
@@ -39,13 +38,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2BridgeDomainId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2FloodDomainId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L3ContextId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.NetworkDomainId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.RuleName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SelectorName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubjectName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubnetId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.UniqueId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.Endpoints;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointKey;
@@ -53,10 +50,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.LocationProvider;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.location.provider.ProviderAddressEndpointLocation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.IpPrefixType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.AddressType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.ContextType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.ForwardingByTenant;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.forwarding.by.tenant.ForwardingContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.forwarding.forwarding.by.tenant.NetworkDomain;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.classifier.refs.ClassifierRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinition;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinition;
@@ -95,7 +91,6 @@ public class IidFactoryTest {
 
     private final String LOCATION_PROVIDER_NAME = "location-provider";
     private final String IP_ADDRESS = "192.68.50.71";
-    private final String IP_PREFIX = "192.168.50.0/24";
     private final String L3_CONTEXT_ID = "l3Context";
     private final String CONNECTOR = "connector";
 
@@ -224,14 +219,6 @@ public class IidFactoryTest {
         Assert.assertEquals(tenantId, identifier.firstKeyOf(Tenant.class).getId());
     }
 
-    @Test
-    public void testL2FloodDomainIid() {
-        ContextId id = mock(ContextId.class);
-        InstanceIdentifier<ForwardingContext> identifier = IidFactory.l2FloodDomainIid(tenantId, id);
-        Assert.assertEquals(id, InstanceIdentifier.keyOf(identifier).getContextId());
-        Assert.assertEquals(tenantId, identifier.firstKeyOf(ForwardingByTenant.class).getTenantId());
-    }
-
     @Test
     public void testL2FloodDomainIid_tenantApi() {
         L2FloodDomainId l2FloodDomainId = mock(L2FloodDomainId.class);
@@ -240,14 +227,6 @@ public class IidFactoryTest {
         Assert.assertEquals(tenantId, identifier.firstKeyOf(Tenant.class).getId());
     }
 
-    @Test
-    public void testL2BridgeDomainIid() {
-        ContextId id = mock(ContextId.class);
-        InstanceIdentifier<ForwardingContext> identifier = IidFactory.l2BridgeDomainIid(tenantId, id);
-        Assert.assertEquals(id, InstanceIdentifier.keyOf(identifier).getContextId());
-        Assert.assertEquals(tenantId, identifier.firstKeyOf(ForwardingByTenant.class).getTenantId());
-    }
-
     @Test
     public void testL2BridgeDomainIid_tenantApi() {
         L2BridgeDomainId l2BridgeDomainId = mock(L2BridgeDomainId.class);
@@ -256,14 +235,6 @@ public class IidFactoryTest {
         Assert.assertEquals(tenantId, identifier.firstKeyOf(Tenant.class).getId());
     }
 
-    @Test
-    public void testL3ContextIid() {
-        ContextId id = mock(ContextId.class);
-        InstanceIdentifier<ForwardingContext> identifier = IidFactory.l3ContextIid(tenantId, id);
-        Assert.assertEquals(id, InstanceIdentifier.keyOf(identifier).getContextId());
-        Assert.assertEquals(tenantId, identifier.firstKeyOf(ForwardingByTenant.class).getTenantId());
-    }
-
     @Test
     public void testL3ContextIid_tenantApi() {
         L3ContextId l3ContextId = mock(L3ContextId.class);
@@ -272,6 +243,12 @@ public class IidFactoryTest {
         Assert.assertEquals(tenantId, identifier.firstKeyOf(Tenant.class).getId());
     }
 
+    @Test
+    public void testForwardingByTenantIid() {
+        InstanceIdentifier<ForwardingByTenant> forwardingByTenantIid = IidFactory.forwardingByTenantIid(tenantId);
+        Assert.assertEquals(tenantId, forwardingByTenantIid.firstKeyOf(ForwardingByTenant.class).getTenantId());
+    }
+
     @Test
     public void testEndpointIid() {
         L2BridgeDomainId l2Context = mock(L2BridgeDomainId.class);
@@ -315,14 +292,6 @@ public class IidFactoryTest {
         Assert.assertNotNull(identifier);
     }
 
-    @Test
-    public void testSubnetIid() {
-        NetworkDomainId id = mock(NetworkDomainId.class);
-        InstanceIdentifier<NetworkDomain> identifier = IidFactory.subnetIid(tenantId, id);
-        Assert.assertEquals(tenantId, identifier.firstKeyOf(ForwardingByTenant.class).getTenantId());
-        Assert.assertEquals(id, identifier.firstKeyOf(NetworkDomain.class).getNetworkDomainId());
-    }
-
     @Test
     public void testSubnetIid_tenantApi() {
         SubnetId subnetId = mock(SubnetId.class);
@@ -396,19 +365,16 @@ public class IidFactoryTest {
     }
 
     @Test
-    public void  testeExternalImplicitGroupIid(){
-        InstanceIdentifier<ExternalImplicitGroup>
-                identifier = IidFactory.externalImplicitGroupIid(tenantId, epgId);
+    public void testeExternalImplicitGroupIid() {
+        InstanceIdentifier<ExternalImplicitGroup> identifier = IidFactory.externalImplicitGroupIid(tenantId, epgId);
         Assert.assertEquals(epgId, identifier.firstKeyOf(ExternalImplicitGroup.class).getId());
     }
 
     @Test
     public void testProviderAddressEndpointLocationIid() {
         ContextId l3Context = new ContextId(L3_CONTEXT_ID);
-        InstanceIdentifier<ProviderAddressEndpointLocation> identifier = IidFactory
-            .providerAddressEndpointLocationIid(LOCATION_PROVIDER_NAME, IpPrefixType.class, IP_ADDRESS,
-                    org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class,
-                    l3Context);
+        InstanceIdentifier<ProviderAddressEndpointLocation> identifier = IidFactory.providerAddressEndpointLocationIid(
+                LOCATION_PROVIDER_NAME, AddressType.class, IP_ADDRESS, ContextType.class, l3Context);
         Assert.assertEquals(LOCATION_PROVIDER_NAME,
                 identifier.firstKeyOf(LocationProvider.class).getProvider().getValue());
         Assert.assertEquals(IP_ADDRESS, identifier.firstKeyOf(ProviderAddressEndpointLocation.class).getAddress());
@@ -418,15 +384,11 @@ public class IidFactoryTest {
     @Test
     public void testAddressEndpointIid() {
         ContextId l3Context = new ContextId(L3_CONTEXT_ID);
-        InstanceIdentifier<AddressEndpoint> identifier =
-                IidFactory.addressEndpointIid(new AddressEndpointKey(IP_ADDRESS, IpPrefixType.class, l3Context,
-                        org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class
-                        ));
-        Assert.assertEquals(IpPrefixType.class, identifier.firstKeyOf(AddressEndpoint.class).getAddressType());
+        InstanceIdentifier<AddressEndpoint> identifier = IidFactory.addressEndpointIid(
+                new AddressEndpointKey(IP_ADDRESS, AddressType.class, l3Context, ContextType.class));
+        Assert.assertEquals(AddressType.class, identifier.firstKeyOf(AddressEndpoint.class).getAddressType());
         Assert.assertEquals(IP_ADDRESS, identifier.firstKeyOf(AddressEndpoint.class).getAddress());
-        Assert.assertEquals(
-                org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class,
-                identifier.firstKeyOf(AddressEndpoint.class).getContextType());
+        Assert.assertEquals(ContextType.class, identifier.firstKeyOf(AddressEndpoint.class).getContextType());
         Assert.assertEquals(l3Context, identifier.firstKeyOf(AddressEndpoint.class).getContextId());
     }
 
@@ -434,14 +396,12 @@ public class IidFactoryTest {
     public void testAddressEndpointLocationIid() {
         ContextId l3Context = new ContextId(L3_CONTEXT_ID);
         AddressEndpointLocationKey addrEndpointLocationKey =
-                new AddressEndpointLocationKey(IP_ADDRESS, IpPrefixType.class, l3Context,
-                        org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class);
-        InstanceIdentifier<AddressEndpointLocation> iid = IidFactory.addressEndpointLocationIid(addrEndpointLocationKey);
-        Assert.assertEquals(IpPrefixType.class, iid.firstKeyOf(AddressEndpointLocation.class).getAddressType());
+                new AddressEndpointLocationKey(IP_ADDRESS, AddressType.class, l3Context, ContextType.class);
+        InstanceIdentifier<AddressEndpointLocation> iid =
+                IidFactory.addressEndpointLocationIid(addrEndpointLocationKey);
+        Assert.assertEquals(AddressType.class, iid.firstKeyOf(AddressEndpointLocation.class).getAddressType());
         Assert.assertEquals(IP_ADDRESS, iid.firstKeyOf(AddressEndpointLocation.class).getAddress());
-        Assert.assertEquals(
-                org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class,
-                iid.firstKeyOf(AddressEndpointLocation.class).getContextType());
+        Assert.assertEquals(ContextType.class, iid.firstKeyOf(AddressEndpointLocation.class).getContextType());
         Assert.assertEquals(l3Context, iid.firstKeyOf(AddressEndpointLocation.class).getContextId());
     }
 
@@ -449,12 +409,10 @@ public class IidFactoryTest {
     public void testContainmentEndpointLocationIid() {
         ContextId l3Context = new ContextId(L3_CONTEXT_ID);
         ContainmentEndpointLocationKey contEndpointLocationKey =
-                new ContainmentEndpointLocationKey(l3Context,
-                        org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class);
-        InstanceIdentifier<ContainmentEndpointLocation> iid = IidFactory.containmentEndpointLocationIid(contEndpointLocationKey);
-        Assert.assertEquals(
-                org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class,
-                iid.firstKeyOf(ContainmentEndpointLocation.class).getContextType());
+                new ContainmentEndpointLocationKey(l3Context, ContextType.class);
+        InstanceIdentifier<ContainmentEndpointLocation> iid =
+                IidFactory.containmentEndpointLocationIid(contEndpointLocationKey);
+        Assert.assertEquals(ContextType.class, iid.firstKeyOf(ContainmentEndpointLocation.class).getContextType());
         Assert.assertEquals(l3Context, iid.firstKeyOf(ContainmentEndpointLocation.class).getContextId());
     }
 
@@ -462,15 +420,13 @@ public class IidFactoryTest {
     public void internalLocationIid_AddrEndpoint() {
         ContextId l3Context = new ContextId(L3_CONTEXT_ID);
         AddressEndpointLocationKey addrEndpointLocationKey =
-                new AddressEndpointLocationKey(IP_ADDRESS, IpPrefixType.class, l3Context,
-                        org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class);
+                new AddressEndpointLocationKey(IP_ADDRESS, AddressType.class, l3Context, ContextType.class);
         InternalLocationKey internalLocationKey = new InternalLocationKey(nodeIid, connectorIid);
-        InstanceIdentifier<InternalLocation> iid = IidFactory.internalLocationIid(addrEndpointLocationKey, internalLocationKey);
-        Assert.assertEquals(IpPrefixType.class, iid.firstKeyOf(AddressEndpointLocation.class).getAddressType());
+        InstanceIdentifier<InternalLocation> iid =
+                IidFactory.internalLocationIid(addrEndpointLocationKey, internalLocationKey);
+        Assert.assertEquals(AddressType.class, iid.firstKeyOf(AddressEndpointLocation.class).getAddressType());
         Assert.assertEquals(IP_ADDRESS, iid.firstKeyOf(AddressEndpointLocation.class).getAddress());
-        Assert.assertEquals(
-                org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class,
-                iid.firstKeyOf(AddressEndpointLocation.class).getContextType());
+        Assert.assertEquals(ContextType.class, iid.firstKeyOf(AddressEndpointLocation.class).getContextType());
         Assert.assertEquals(l3Context, iid.firstKeyOf(AddressEndpointLocation.class).getContextId());
         Assert.assertEquals(nodeIid, iid.firstKeyOf(InternalLocation.class).getInternalNode());
         Assert.assertEquals(connectorIid, iid.firstKeyOf(InternalLocation.class).getInternalNodeConnector());
@@ -480,13 +436,11 @@ public class IidFactoryTest {
     public void internalLocationIid_ContEndpoint() {
         ContextId l3Context = new ContextId(L3_CONTEXT_ID);
         ContainmentEndpointLocationKey contEndpointLocationKey =
-                new ContainmentEndpointLocationKey(l3Context,
-                        org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class);
+                new ContainmentEndpointLocationKey(l3Context, ContextType.class);
         InternalLocationKey internalLocationKey = new InternalLocationKey(nodeIid, connectorIid);
-        InstanceIdentifier<InternalLocation> iid = IidFactory.internalLocationIid(contEndpointLocationKey, internalLocationKey);
-        Assert.assertEquals(
-                org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class,
-                iid.firstKeyOf(ContainmentEndpointLocation.class).getContextType());
+        InstanceIdentifier<InternalLocation> iid =
+                IidFactory.internalLocationIid(contEndpointLocationKey, internalLocationKey);
+        Assert.assertEquals(ContextType.class, iid.firstKeyOf(ContainmentEndpointLocation.class).getContextType());
         Assert.assertEquals(l3Context, iid.firstKeyOf(ContainmentEndpointLocation.class).getContextId());
         Assert.assertEquals(nodeIid, iid.firstKeyOf(InternalLocation.class).getInternalNode());
         Assert.assertEquals(connectorIid, iid.firstKeyOf(InternalLocation.class).getInternalNodeConnector());
@@ -496,15 +450,13 @@ public class IidFactoryTest {
     public void externalLocationIid_AddrEndpoint() {
         ContextId l3Context = new ContextId(L3_CONTEXT_ID);
         AddressEndpointLocationKey addrEndpointLocationKey =
-                new AddressEndpointLocationKey(IP_ADDRESS, IpPrefixType.class, l3Context,
-                        org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class);
+                new AddressEndpointLocationKey(IP_ADDRESS, AddressType.class, l3Context, ContextType.class);
         ExternalLocationKey externalLocationKey = new ExternalLocationKey(CONNECTOR, nodeIid);
-        InstanceIdentifier<ExternalLocation> iid = IidFactory.externalLocationIid(addrEndpointLocationKey, externalLocationKey);
-        Assert.assertEquals(IpPrefixType.class, iid.firstKeyOf(AddressEndpointLocation.class).getAddressType());
+        InstanceIdentifier<ExternalLocation> iid =
+                IidFactory.externalLocationIid(addrEndpointLocationKey, externalLocationKey);
+        Assert.assertEquals(AddressType.class, iid.firstKeyOf(AddressEndpointLocation.class).getAddressType());
         Assert.assertEquals(IP_ADDRESS, iid.firstKeyOf(AddressEndpointLocation.class).getAddress());
-        Assert.assertEquals(
-                org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class,
-                iid.firstKeyOf(AddressEndpointLocation.class).getContextType());
+        Assert.assertEquals(ContextType.class, iid.firstKeyOf(AddressEndpointLocation.class).getContextType());
         Assert.assertEquals(l3Context, iid.firstKeyOf(AddressEndpointLocation.class).getContextId());
         Assert.assertEquals(CONNECTOR, iid.firstKeyOf(ExternalLocation.class).getExternalNodeConnector());
         Assert.assertEquals(nodeIid, iid.firstKeyOf(ExternalLocation.class).getExternalNodeMountPoint());
@@ -514,13 +466,11 @@ public class IidFactoryTest {
     public void externalLocationIid_ContEndpoint() {
         ContextId l3Context = new ContextId(L3_CONTEXT_ID);
         ContainmentEndpointLocationKey addrEndpointLocationKey =
-                new ContainmentEndpointLocationKey(l3Context,
-                        org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class);
+                new ContainmentEndpointLocationKey(l3Context, ContextType.class);
         ExternalLocationKey externalLocationKey = new ExternalLocationKey(CONNECTOR, nodeIid);
-        InstanceIdentifier<ExternalLocation> iid = IidFactory.externalLocationIid(addrEndpointLocationKey, externalLocationKey);
-        Assert.assertEquals(
-                org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class,
-                iid.firstKeyOf(ContainmentEndpointLocation.class).getContextType());
+        InstanceIdentifier<ExternalLocation> iid =
+                IidFactory.externalLocationIid(addrEndpointLocationKey, externalLocationKey);
+        Assert.assertEquals(ContextType.class, iid.firstKeyOf(ContainmentEndpointLocation.class).getContextType());
         Assert.assertEquals(l3Context, iid.firstKeyOf(ContainmentEndpointLocation.class).getContextId());
         Assert.assertEquals(CONNECTOR, iid.firstKeyOf(ExternalLocation.class).getExternalNodeConnector());
         Assert.assertEquals(nodeIid, iid.firstKeyOf(ExternalLocation.class).getExternalNodeMountPoint());
@@ -530,14 +480,11 @@ public class IidFactoryTest {
     public void absoluteLocationIid() {
         ContextId l3Context = new ContextId(L3_CONTEXT_ID);
         AddressEndpointLocationKey addrEndpointLocationKey =
-                new AddressEndpointLocationKey(IP_ADDRESS, IpPrefixType.class, l3Context,
-                        org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class);
+                new AddressEndpointLocationKey(IP_ADDRESS, AddressType.class, l3Context, ContextType.class);
         InstanceIdentifier<AbsoluteLocation> iid = IidFactory.absoluteLocationIid(addrEndpointLocationKey);
-        Assert.assertEquals(IpPrefixType.class, iid.firstKeyOf(AddressEndpointLocation.class).getAddressType());
+        Assert.assertEquals(AddressType.class, iid.firstKeyOf(AddressEndpointLocation.class).getAddressType());
         Assert.assertEquals(IP_ADDRESS, iid.firstKeyOf(AddressEndpointLocation.class).getAddress());
-        Assert.assertEquals(
-                org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context.class,
-                iid.firstKeyOf(AddressEndpointLocation.class).getContextType());
+        Assert.assertEquals(ContextType.class, iid.firstKeyOf(AddressEndpointLocation.class).getContextType());
         Assert.assertEquals(l3Context, iid.firstKeyOf(AddressEndpointLocation.class).getContextId());
     }
 }
index befc7a10cb487ab146b757efce741ab8177e4075..7465e0724502f35b9889dfefbc79d37017878f0f 100644 (file)
   <packaging>bundle</packaging>
 
   <dependencies>
+    <dependency>
+      <groupId>org.opendaylight.groupbasedpolicy</groupId>
+      <artifactId>l2-l3-domain-extension</artifactId>
+      <version>${project.version}</version>
+    </dependency>
     <!-- testing dependencies -->
     <dependency>
       <groupId>junit</groupId>
index e20046df8dca04e571fe7e3858c088fecc3719dd..97153e2766bc02535179f55e8cd39835c129c30c 100644 (file)
@@ -22,13 +22,14 @@ import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
 import org.opendaylight.groupbasedpolicy.util.IidFactory;
 import org.opendaylight.groupbasedpolicy.util.NetUtils;
 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.groupbasedpolicy.base_endpoint.rev160427.endpoints.address.endpoints.AddressEndpoint;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.AbsoluteLocation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.AbsoluteLocationBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.absolute.location.location.type.InternalLocationCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.absolute.location.location.type.ExternalLocationCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.network.elements.rev160407.NetworkElements;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.network.elements.rev160407.NetworkElementsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.network.elements.rev160407.network.elements.NetworkElement;
@@ -73,11 +74,12 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
     }
 
     public synchronized void onEndpointsChange(Collection<DataTreeModification<AddressEndpoint>> changes) {
+        WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
         for (DataTreeModification<AddressEndpoint> change : changes) {
             switch (change.getRootNode().getModificationType()) {
                 case DELETE: {
                     AddressEndpoint endpoint = change.getRootNode().getDataBefore();
-                    removeLocationForEndpoint(endpoint);
+                    removeLocationForEndpoint(endpoint, wtx);
                     this.endpoints.remove(endpoint);
                     break;
                 }
@@ -89,7 +91,7 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
                         break;
                     }
                     endpoint = change.getRootNode().getDataAfter();
-                    createLocationForEndpoint(endpoint);
+                    createLocationForEndpoint(endpoint, wtx);
                     this.endpoints.add(endpoint);
                     break;
                 }
@@ -100,9 +102,10 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
                 }
             }
         }
+        DataStoreHelper.submitToDs(wtx);
     }
 
-    private void createLocationForEndpoint(AddressEndpoint endpoint) {
+    private void createLocationForEndpoint(AddressEndpoint endpoint, WriteTransaction wtx) {
         for (NetworkElement ne : nullToEmpty(networkElements.getNetworkElement())) {
             for (Interface iface : nullToEmpty(ne.getInterface())) {
                 for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) {
@@ -110,14 +113,12 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
                             && endpoint.getContextId().equals(en.getL3ContextId())
                             && endpoint.getAddressType().isAssignableFrom(IpPrefixType.class) && NetUtils
                                 .samePrefix(new IpPrefix(endpoint.getAddress().toCharArray()), en.getIpPrefix())) {
-                        WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
                         InstanceIdentifier<AbsoluteLocation> iid = IidFactory
                             .providerAddressEndpointLocationIid(NE_LOCATION_PROVIDER_NAME, IpPrefixType.class,
                                     endpoint.getAddress(), endpoint.getContextType(), endpoint.getContextId())
                             .child(AbsoluteLocation.class);
                         wtx.put(LogicalDatastoreType.OPERATIONAL, iid, createRealLocation(ne.getIid(), iface.getIid()),
                                 true);
-                        wtx.submit();
                         LOG.debug("New location created for endpoint {}", endpoint);
                         return;
                     }
@@ -126,7 +127,7 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
         }
     }
 
-    private void removeLocationForEndpoint(AddressEndpoint endpoint) {
+    private void removeLocationForEndpoint(AddressEndpoint endpoint, WriteTransaction wtx) {
         for (NetworkElement ne : nullToEmpty(networkElements.getNetworkElement())) {
             for (Interface iface : nullToEmpty(ne.getInterface())) {
                 for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) {
@@ -134,13 +135,11 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
                             && endpoint.getContextId().equals(en.getL3ContextId())
                             && endpoint.getAddressType().isAssignableFrom(IpPrefixType.class) && NetUtils
                                 .samePrefix(new IpPrefix(endpoint.getAddress().toCharArray()), en.getIpPrefix())) {
-                        WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
                         InstanceIdentifier<AbsoluteLocation> iid = IidFactory
                             .providerAddressEndpointLocationIid(NE_LOCATION_PROVIDER_NAME, IpPrefixType.class,
                                     endpoint.getAddress(), endpoint.getContextType(), endpoint.getContextId())
                             .child(AbsoluteLocation.class);
                         wtx.delete(LogicalDatastoreType.OPERATIONAL, iid);
-                        wtx.submit();
                         LOG.debug("Location deleted for endpoint {}", endpoint);
                         return;
                     }
@@ -151,6 +150,7 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
 
     @Override
     public synchronized void onDataTreeChanged(Collection<DataTreeModification<NetworkElements>> changes) {
+        WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
         for (DataTreeModification<NetworkElements> change : changes) {
             switch (change.getRootNode().getModificationType()) {
                 case DELETE: {
@@ -158,7 +158,7 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
                     for (NetworkElement ne : nullToEmpty(nes.getNetworkElement())) {
                         for (Interface iface : nullToEmpty(ne.getInterface())) {
                             for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) {
-                                processDeletedEN(en);
+                                processDeletedEN(en, wtx);
                             }
                         }
                     }
@@ -172,7 +172,7 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
                         for (NetworkElement ne : nullToEmpty(nes.getNetworkElement())) {
                             for (Interface iface : nullToEmpty(ne.getInterface())) {
                                 for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) {
-                                    processDeletedEN(en);
+                                    processDeletedEN(en, wtx);
                                 }
                             }
                         }
@@ -181,7 +181,7 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
                     for (NetworkElement ne : nullToEmpty(nes.getNetworkElement())) {
                         for (Interface iface : nullToEmpty(ne.getInterface())) {
                             for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) {
-                                processCreatedEN(en, ne.getIid(), iface.getIid());
+                                processCreatedEN(en, ne.getIid(), iface.getIid(), wtx);
                             }
                         }
                     }
@@ -193,12 +193,13 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
                     List<DataObjectModification<NetworkElement>> modifiedNetworkElements =
                             getModifiedNetworkElements(change.getRootNode());
                     for (DataObjectModification<NetworkElement> netElement : modifiedNetworkElements) {
-                        processNetworkElementChange(netElement);
+                        processNetworkElementChange(netElement, wtx);
                     }
                     break;
                 }
             }
         }
+        DataStoreHelper.submitToDs(wtx);
     }
 
     private List<DataObjectModification<NetworkElement>> getModifiedNetworkElements(
@@ -217,13 +218,13 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
         return nes;
     }
 
-    private void processNetworkElementChange(DataObjectModification<NetworkElement> netElement) {
+    private void processNetworkElementChange(DataObjectModification<NetworkElement> netElement, WriteTransaction wtx) {
         switch (netElement.getModificationType()) {
             case DELETE: {
                 NetworkElement ne = netElement.getDataBefore();
                 for (Interface iface : nullToEmpty(ne.getInterface())) {
                     for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) {
-                        processDeletedEN(en);
+                        processDeletedEN(en, wtx);
                     }
                 }
                 networkElements.getNetworkElement().remove(ne);
@@ -235,7 +236,7 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
                 if (ne != null) {
                     for (Interface iface : nullToEmpty(ne.getInterface())) {
                         for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) {
-                            processDeletedEN(en);
+                            processDeletedEN(en, wtx);
                         }
                     }
                     networkElements.getNetworkElement().remove(ne);
@@ -243,7 +244,7 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
                 ne = netElement.getDataAfter();
                 for (Interface iface : nullToEmpty(ne.getInterface())) {
                     for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) {
-                        processCreatedEN(en, ne.getIid(), iface.getIid());
+                        processCreatedEN(en, ne.getIid(), iface.getIid(), wtx);
                     }
                 }
                 networkElements.getNetworkElement().add(ne);
@@ -253,7 +254,7 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
             case SUBTREE_MODIFIED: {
                 List<DataObjectModification<Interface>> modifiedInterfaces = getModifiedInterfaces(netElement);
                 for (DataObjectModification<Interface> modifiedInterface : modifiedInterfaces) {
-                    processInterfaceChange(modifiedInterface, netElement.getDataBefore());
+                    processInterfaceChange(modifiedInterface, netElement.getDataBefore(), wtx);
                 }
                 break;
             }
@@ -277,12 +278,12 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
     }
 
     private void processInterfaceChange(DataObjectModification<Interface> modifiedInterface,
-            NetworkElement nodeBefore) {
+            NetworkElement nodeBefore, WriteTransaction wtx) {
         switch (modifiedInterface.getModificationType()) {
             case DELETE: {
                 Interface iface = modifiedInterface.getDataBefore();
                 for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) {
-                    processDeletedEN(en);
+                    processDeletedEN(en, wtx);
                 }
                 int nodeIndex = getIndexOf(nodeBefore);
                 networkElements.getNetworkElement().get(nodeIndex).getInterface().remove(iface);
@@ -294,13 +295,13 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
                 int nodeIndex = getIndexOf(nodeBefore);
                 if (iface != null) {
                     for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) {
-                        processDeletedEN(en);
+                        processDeletedEN(en, wtx);
                     }
                     networkElements.getNetworkElement().get(nodeIndex).getInterface().remove(iface);
                 }
                 iface = modifiedInterface.getDataAfter();
                 for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) {
-                    processCreatedEN(en, nodeBefore.getIid(), iface.getIid());
+                    processCreatedEN(en, nodeBefore.getIid(), iface.getIid(), wtx);
                 }
                 networkElements.getNetworkElement().get(nodeIndex).getInterface().add(iface);
                 LOG.debug("Created new Interface {}", modifiedInterface.getDataAfter());
@@ -310,7 +311,7 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
                 List<DataObjectModification<EndpointNetwork>> modifiedENs =
                         getModifiedEndpointNetworks(modifiedInterface);
                 for (DataObjectModification<EndpointNetwork> modifiedEN : modifiedENs) {
-                    processEndpointNetworkChange(modifiedEN, nodeBefore, modifiedInterface.getDataBefore());
+                    processEndpointNetworkChange(modifiedEN, nodeBefore, modifiedInterface.getDataBefore(), wtx);
                 }
                 break;
             }
@@ -334,10 +335,10 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
     }
 
     private void processEndpointNetworkChange(DataObjectModification<EndpointNetwork> modifiedEN,
-            NetworkElement nodeBefore, Interface ifaceBefore) {
+            NetworkElement nodeBefore, Interface ifaceBefore, WriteTransaction wtx) {
         switch (modifiedEN.getModificationType()) {
             case DELETE: {
-                processDeletedEN(modifiedEN.getDataBefore());
+                processDeletedEN(modifiedEN.getDataBefore(), wtx);
                 int nodeIndex = getIndexOf(nodeBefore);
                 int ifaceIndex = getIndexOf(ifaceBefore, nodeIndex);
                 networkElements.getNetworkElement()
@@ -350,7 +351,7 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
                 break;
             }
             case WRITE: {
-                processCreatedEN(modifiedEN.getDataAfter(), nodeBefore.getIid(), ifaceBefore.getIid());
+                processCreatedEN(modifiedEN.getDataAfter(), nodeBefore.getIid(), ifaceBefore.getIid(), wtx);
                 int nodeIndex = getIndexOf(nodeBefore);
                 int ifaceIndex = getIndexOf(ifaceBefore, nodeIndex);
                 networkElements.getNetworkElement()
@@ -370,8 +371,7 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
     }
 
     private void processCreatedEN(EndpointNetwork en, InstanceIdentifier<?> nodeIID,
-            InstanceIdentifier<?> connectorIID) {
-        WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
+            InstanceIdentifier<?> connectorIID, WriteTransaction wtx) {
         for (AddressEndpoint endpoint : endpoints) {
             if (endpoint.getContextType().isAssignableFrom(L3Context.class)
                     && endpoint.getContextId().equals(en.getL3ContextId())
@@ -382,15 +382,13 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
                             endpoint.getAddress(), endpoint.getContextType(), endpoint.getContextId())
                     .child(AbsoluteLocation.class);
                 wtx.put(LogicalDatastoreType.OPERATIONAL, iid, createRealLocation(nodeIID, connectorIID), true);
-                wtx.submit();
                 LOG.debug("New location created for endpoint {}", endpoint);
                 return;
             }
         }
     }
 
-    private void processDeletedEN(EndpointNetwork en) {
-        WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
+    private void processDeletedEN(EndpointNetwork en, WriteTransaction wtx) {
         for (AddressEndpoint endpoint : endpoints) {
             if (endpoint.getContextType().isAssignableFrom(L3Context.class)
                     && endpoint.getContextId().equals(en.getL3ContextId())
@@ -401,7 +399,6 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
                             endpoint.getAddress(), endpoint.getContextType(), endpoint.getContextId())
                     .child(AbsoluteLocation.class);
                 wtx.delete(LogicalDatastoreType.OPERATIONAL, iid);
-                wtx.submit();
                 LOG.debug("Location deleted for endpoint {}", endpoint);
                 return;
             }
@@ -410,7 +407,8 @@ public class NeLocationProvider implements DataTreeChangeListener<NetworkElement
 
     private AbsoluteLocation createRealLocation(InstanceIdentifier<?> node, InstanceIdentifier<?> iface) {
         return new AbsoluteLocationBuilder()
-            .setLocationType(new InternalLocationCaseBuilder().setInternalNode(node).setInternalNodeConnector(iface).build()).build();
+            .setLocationType(new ExternalLocationCaseBuilder().setExternalNodeMountPoint(node)
+                    .setExternalNodeConnector(iface.toString()).build()).build();
     }
 
     private <T> List<T> nullToEmpty(@Nullable List<T> list) {
index 8f61ea2bf088f7f56baf6dfd95aca6927051179c..22ac33844ea08b14fc876cc4939773585fe1ea72 100644 (file)
@@ -35,7 +35,6 @@ import org.opendaylight.groupbasedpolicy.test.CustomDataBrokerTest;
 import org.opendaylight.groupbasedpolicy.util.IidFactory;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.EndpointLocations;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.Endpoints;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.common.endpoint.fields.NetworkContainment;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.common.endpoint.fields.NetworkContainmentBuilder;
@@ -44,6 +43,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpo
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.address.endpoints.AddressEndpoint;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.address.endpoints.AddressEndpointBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.address.endpoints.AddressEndpointKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.AbsoluteLocationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.absolute.location.location.type.ExternalLocationCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContextId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.NetworkDomainId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.network.elements.rev160407.NetworkElements;
@@ -57,6 +58,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.n
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.network.elements.rev160407.network.elements.network.element._interface.EndpointNetwork;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.network.elements.rev160407.network.elements.network.element._interface.EndpointNetworkBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.network.elements.rev160407.network.elements.network.element._interface.EndpointNetworkKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.LocationProviders;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.LocationProvidersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.ProviderName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.LocationProviderBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.location.provider.ProviderAddressEndpointLocationBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.IpPrefixType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.L3Context;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.AddressType;
@@ -80,8 +86,8 @@ public class NeLocationProviderTest extends CustomDataBrokerTest {
     private DataBroker dataBroker;
     private NeLocationProvider neProvider;
     private String L3_CONTEXT_ID = "l3Context";
-    private String IPv4_HOST_ADDRESS_1 = "192.168.50.71";
-    private String IPv4_HOST_ADDRESS_2 = "192.168.50.72";
+    private String IPv4_HOST_ADDRESS_1 = "192.168.50.71/24";
+    private String IPv4_HOST_ADDRESS_2 = "192.168.50.72/24";
     private String IPv4_NETWORK_ADDRESS_1 = "192.168.50.0/24";
     private String IPv4_NETWORK_ADDRESS_2 = "192.168.51.0/24";
     private String NODE_ID_1 = "node1";
@@ -91,7 +97,7 @@ public class NeLocationProviderTest extends CustomDataBrokerTest {
 
     @Override
     public Collection<Class<?>> getClassesFromModules() {
-        return ImmutableList.<Class<?>>of(NetworkElements.class, EndpointLocations.class, Endpoints.class, L3Context.class, Nodes.class);
+        return ImmutableList.<Class<?>>of(NetworkElements.class, LocationProviders.class, Endpoints.class, L3Context.class, Nodes.class);
     }
 
     @Before
@@ -135,8 +141,23 @@ public class NeLocationProviderTest extends CustomDataBrokerTest {
 
     @Test
     public void test_AddressEndpointWrite_NoNE_NoOverwrite() throws Exception {
-        AddressEndpoint endpoint =
-                createAddressEndpoint(IPv4_HOST_ADDRESS_1, IpPrefixType.class, L3_CONTEXT_ID, L3Context.class);
+        AddressEndpoint endpoint = writeBaseAddrEndpoint();
+        List<AddressEndpoint> endpoints = neProvider.getEndpoints();
+        assertEquals(1, endpoints.size());
+        assertEquals(endpoint, endpoints.get(0));
+        verifyEmptyLocations();
+    }
+
+    @Test
+    public void test_AddressEndpointWrite_NoNE_Overwrite() throws Exception {
+        writeBaseAddrEndpoint();
+        NetworkContainment nc = new NetworkContainmentBuilder()
+                .setContainment(new NetworkDomainContainmentBuilder().setNetworkDomainId(new NetworkDomainId(L3_CONTEXT_ID)).build())
+                        .build();
+        AddressEndpoint endpoint = new AddressEndpointBuilder().setKey(
+                new AddressEndpointKey(IPv4_HOST_ADDRESS_1, IpPrefixType.class, new ContextId(L3_CONTEXT_ID), L3Context.class))
+                .setNetworkContainment(nc)
+                .build();
         InstanceIdentifier<AddressEndpoint> iid = IidFactory.addressEndpointIid(endpoint.getKey());
         WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
         wtx.put(LogicalDatastoreType.OPERATIONAL, iid, endpoint, true);
@@ -148,8 +169,8 @@ public class NeLocationProviderTest extends CustomDataBrokerTest {
     }
 
     @Test
-    public void test_AddressEndpointWrite_NoNE_Overwrite() throws Exception {
-        test_AddressEndpointWrite_NoNE_NoOverwrite();
+    public void test_AddressEndpointModified_NoNE() throws Exception {
+        writeBaseAddrEndpoint();
         NetworkContainment nc = new NetworkContainmentBuilder()
         .setContainment(new NetworkDomainContainmentBuilder().setNetworkDomainId(new NetworkDomainId(L3_CONTEXT_ID)).build())
                 .build();
@@ -172,7 +193,7 @@ public class NeLocationProviderTest extends CustomDataBrokerTest {
 
     @Test
     public void test_EndpointsDelete_NoNE() throws Exception {
-        test_AddressEndpointWrite_NoNE_NoOverwrite();
+        writeBaseAddrEndpoint();
         InstanceIdentifier<Endpoints> iid = InstanceIdentifier.builder(Endpoints.class)
                 .build();
         WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
@@ -185,7 +206,7 @@ public class NeLocationProviderTest extends CustomDataBrokerTest {
 
     @Test
     public void test_EndpointsModify_NoNE() throws Exception {
-        test_AddressEndpointWrite_NoNE_NoOverwrite();
+        writeBaseAddrEndpoint();
         InstanceIdentifier<Endpoints> iid = InstanceIdentifier.builder(Endpoints.class)
                 .build();
         WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
@@ -198,11 +219,7 @@ public class NeLocationProviderTest extends CustomDataBrokerTest {
 
     @Test
     public void test_NetworkElementsWrite_NoEP_NoOverwrite() throws Exception {
-        NetworkElements nes = createNetworkElements(NODE_ID_1, CONNECTOR_ID_1, L3_CONTEXT_ID, IPv4_NETWORK_ADDRESS_1);
-        InstanceIdentifier<NetworkElements> iid = InstanceIdentifier.builder(NetworkElements.class).build();
-        WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
-        wtx.put(LogicalDatastoreType.CONFIGURATION, iid, nes);
-        wtx.submit().get();
+        NetworkElements nes = writeBaseNetworkElements();
         NetworkElements networkElements = neProvider.getNetworkElements();
         assertEquals(nes, networkElements);
         verifyEmptyLocations();
@@ -210,7 +227,7 @@ public class NeLocationProviderTest extends CustomDataBrokerTest {
 
     @Test
     public void test_NetworkElementsWrite_NoEP_Overwrite() throws Exception {
-        test_NetworkElementsWrite_NoEP_NoOverwrite();
+        writeBaseNetworkElements();
         NetworkElements nes = createNetworkElements(NODE_ID_2, CONNECTOR_ID_2, L3_CONTEXT_ID, IPv4_NETWORK_ADDRESS_1);
         InstanceIdentifier<NetworkElements> iid = InstanceIdentifier.builder(NetworkElements.class).build();
         WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
@@ -223,7 +240,7 @@ public class NeLocationProviderTest extends CustomDataBrokerTest {
 
     @Test
     public void test_NetworkElementWrite_NoEP_Overwrite() throws Exception {
-        test_NetworkElementsWrite_NoEP_NoOverwrite();
+        writeBaseNetworkElements();
         NetworkElement ne = createNetworkElement(NODE_ID_1, CONNECTOR_ID_1, L3_CONTEXT_ID, IPv4_NETWORK_ADDRESS_2);
         InstanceIdentifier<NetworkElement> iid = InstanceIdentifier.builder(NetworkElements.class)
             .child(NetworkElement.class, new NetworkElementKey(ne.getKey()))
@@ -240,7 +257,7 @@ public class NeLocationProviderTest extends CustomDataBrokerTest {
 
     @Test
     public void test_InterfaceWrite_NoEP_Overwrite() throws Exception {
-        test_NetworkElementsWrite_NoEP_NoOverwrite();
+        writeBaseNetworkElements();
         Interface iface = createInterface(NODE_ID_1, CONNECTOR_ID_1, L3_CONTEXT_ID, IPv4_NETWORK_ADDRESS_2);
         InstanceIdentifier<Interface> iid = InstanceIdentifier.builder(NetworkElements.class)
             .child(NetworkElement.class, new NetworkElementKey(createNetworkElementIid(NODE_ID_1)))
@@ -260,7 +277,7 @@ public class NeLocationProviderTest extends CustomDataBrokerTest {
 
     @Test
     public void test_EndpointNetworkChange_NoEP() throws Exception {
-        test_NetworkElementsWrite_NoEP_NoOverwrite();
+        writeBaseNetworkElements();
         EndpointNetwork en = createEndpointNetwork(L3_CONTEXT_ID, IPv4_NETWORK_ADDRESS_2);
         InstanceIdentifier<EndpointNetwork> iid = InstanceIdentifier.builder(NetworkElements.class)
             .child(NetworkElement.class, new NetworkElementKey(createNetworkElementIid(NODE_ID_1)))
@@ -291,7 +308,7 @@ public class NeLocationProviderTest extends CustomDataBrokerTest {
 
     @Test
     public void test_NetworkElementsDelete() throws Exception {
-        test_NetworkElementsWrite_NoEP_NoOverwrite();
+        writeBaseNetworkElements();
         InstanceIdentifier<NetworkElements> iid = InstanceIdentifier.builder(NetworkElements.class).build();
         WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
         wtx.delete(LogicalDatastoreType.CONFIGURATION, iid);
@@ -303,7 +320,7 @@ public class NeLocationProviderTest extends CustomDataBrokerTest {
 
     @Test
     public void test_NetworkElementDelete() throws Exception {
-        test_NetworkElementsWrite_NoEP_NoOverwrite();
+        writeBaseNetworkElements();
         InstanceIdentifier<NetworkElement> iid = InstanceIdentifier.builder(NetworkElements.class)
             .child(NetworkElement.class, new NetworkElementKey(createNetworkElementIid(NODE_ID_1)))
             .build();
@@ -318,7 +335,7 @@ public class NeLocationProviderTest extends CustomDataBrokerTest {
 
     @Test
     public void test_InterfaceDelete() throws Exception {
-        test_NetworkElementsWrite_NoEP_NoOverwrite();
+        writeBaseNetworkElements();
         InstanceIdentifier<Interface> iid = InstanceIdentifier.builder(NetworkElements.class)
             .child(NetworkElement.class, new NetworkElementKey(createNetworkElementIid(NODE_ID_1)))
             .child(Interface.class, new InterfaceKey(createInterfaceIid(NODE_ID_1, CONNECTOR_ID_1)))
@@ -334,6 +351,158 @@ public class NeLocationProviderTest extends CustomDataBrokerTest {
         verifyEmptyLocations();
     }
 
+    @Test
+    public void test_CreateLocationForAddrEndpoint_EndpointWriteFirst() throws Exception {
+        AddressEndpoint endpoint =
+                createAddressEndpoint(IPv4_HOST_ADDRESS_1, IpPrefixType.class, L3_CONTEXT_ID, L3Context.class);
+        InstanceIdentifier<AddressEndpoint> iid = IidFactory.addressEndpointIid(endpoint.getKey());
+        WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
+        wtx.put(LogicalDatastoreType.OPERATIONAL, iid, endpoint, true);
+        wtx.submit().get();
+
+        NetworkElements nes = createNetworkElements(NODE_ID_1, CONNECTOR_ID_1, L3_CONTEXT_ID, IPv4_NETWORK_ADDRESS_1);
+        InstanceIdentifier<NetworkElements> neIid = InstanceIdentifier.builder(NetworkElements.class).build();
+        wtx = dataBroker.newWriteOnlyTransaction();
+        wtx.put(LogicalDatastoreType.CONFIGURATION, neIid, nes);
+        wtx.submit().get();
+
+        ReadOnlyTransaction rtx = dataBroker.newReadOnlyTransaction();
+        InstanceIdentifier<LocationProviders> locationIid = InstanceIdentifier.builder(LocationProviders.class).build();
+        CheckedFuture<Optional<LocationProviders>, ReadFailedException> read =
+                rtx.read(LogicalDatastoreType.OPERATIONAL, locationIid);
+        assertTrue(read.get().isPresent());
+        rtx.close();
+        LocationProviders locations = read.get().get();
+        LocationProviders locationReference =
+                new LocationProvidersBuilder()
+                    .setLocationProvider(Collections.singletonList(new LocationProviderBuilder()
+                            .setProvider(new ProviderName(NeLocationProvider.NE_LOCATION_PROVIDER_NAME))
+                            .setProviderAddressEndpointLocation(Collections.singletonList(
+                                    new ProviderAddressEndpointLocationBuilder()
+                                    .setAddress(IPv4_HOST_ADDRESS_1)
+                                    .setAddressType(IpPrefixType.class)
+                                    .setContextId(new ContextId(L3_CONTEXT_ID))
+                                    .setContextType(L3Context.class)
+                                    .setAbsoluteLocation(new AbsoluteLocationBuilder()
+                                            .setLocationType(new ExternalLocationCaseBuilder()
+                                                    .setExternalNodeMountPoint(createNetworkElementIid(NODE_ID_1))
+                                                    .setExternalNodeConnector(createInterfaceIid(
+                                                            NODE_ID_1, CONNECTOR_ID_1).toString())
+                                                    .build())
+                                            .build())
+                                    .build()))
+                            .build()))
+                    .build();
+        assertEquals(locationReference, locations);
+    }
+
+    @Test
+    public void test_CreateLocationForAddrEndpoint_NEWriteFirst() throws Exception {
+        NetworkElements nes = createNetworkElements(NODE_ID_1, CONNECTOR_ID_1, L3_CONTEXT_ID, IPv4_NETWORK_ADDRESS_1);
+        InstanceIdentifier<NetworkElements> neIid = InstanceIdentifier.builder(NetworkElements.class).build();
+        WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
+        wtx.put(LogicalDatastoreType.CONFIGURATION, neIid, nes);
+
+        AddressEndpoint endpoint =
+                createAddressEndpoint(IPv4_HOST_ADDRESS_1, IpPrefixType.class, L3_CONTEXT_ID, L3Context.class);
+        InstanceIdentifier<AddressEndpoint> iid = IidFactory.addressEndpointIid(endpoint.getKey());
+        wtx.put(LogicalDatastoreType.OPERATIONAL, iid, endpoint, true);
+        wtx.submit().get();
+
+        ReadOnlyTransaction rtx = dataBroker.newReadOnlyTransaction();
+        InstanceIdentifier<LocationProviders> locationIid = InstanceIdentifier.builder(LocationProviders.class).build();
+        CheckedFuture<Optional<LocationProviders>, ReadFailedException> read =
+                rtx.read(LogicalDatastoreType.OPERATIONAL, locationIid);
+        assertTrue(read.get().isPresent());
+        rtx.close();
+        LocationProviders locations = read.get().get();
+        LocationProviders locationReference =
+                new LocationProvidersBuilder()
+                    .setLocationProvider(Collections.singletonList(new LocationProviderBuilder()
+                            .setProvider(new ProviderName(NeLocationProvider.NE_LOCATION_PROVIDER_NAME))
+                            .setProviderAddressEndpointLocation(Collections.singletonList(
+                                    new ProviderAddressEndpointLocationBuilder()
+                                    .setAddress(IPv4_HOST_ADDRESS_1)
+                                    .setAddressType(IpPrefixType.class)
+                                    .setContextId(new ContextId(L3_CONTEXT_ID))
+                                    .setContextType(L3Context.class)
+                                    .setAbsoluteLocation(new AbsoluteLocationBuilder()
+                                            .setLocationType(new ExternalLocationCaseBuilder()
+                                                    .setExternalNodeMountPoint(createNetworkElementIid(NODE_ID_1))
+                                                    .setExternalNodeConnector(createInterfaceIid(
+                                                            NODE_ID_1, CONNECTOR_ID_1).toString())
+                                                    .build())
+                                            .build())
+                                    .build()))
+                            .build()))
+                    .build();
+        assertEquals(locationReference, locations);
+    }
+
+    @Test
+    public void test_CreateLocationForAddrEndpoint_SimultaneousWrite() throws Exception {
+        NetworkElements nes = createNetworkElements(NODE_ID_1, CONNECTOR_ID_1, L3_CONTEXT_ID, IPv4_NETWORK_ADDRESS_1);
+        InstanceIdentifier<NetworkElements> neIid = InstanceIdentifier.builder(NetworkElements.class).build();
+        WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
+        wtx.put(LogicalDatastoreType.CONFIGURATION, neIid, nes);
+        wtx.submit().get();
+
+        AddressEndpoint endpoint =
+                createAddressEndpoint(IPv4_HOST_ADDRESS_1, IpPrefixType.class, L3_CONTEXT_ID, L3Context.class);
+        InstanceIdentifier<AddressEndpoint> iid = IidFactory.addressEndpointIid(endpoint.getKey());
+        wtx = dataBroker.newWriteOnlyTransaction();
+        wtx.put(LogicalDatastoreType.OPERATIONAL, iid, endpoint, true);
+        wtx.submit().get();
+
+        ReadOnlyTransaction rtx = dataBroker.newReadOnlyTransaction();
+        InstanceIdentifier<LocationProviders> locationIid = InstanceIdentifier.builder(LocationProviders.class).build();
+        CheckedFuture<Optional<LocationProviders>, ReadFailedException> read =
+                rtx.read(LogicalDatastoreType.OPERATIONAL, locationIid);
+        assertTrue(read.get().isPresent());
+        rtx.close();
+        LocationProviders locations = read.get().get();
+        LocationProviders locationReference =
+                new LocationProvidersBuilder()
+                    .setLocationProvider(Collections.singletonList(new LocationProviderBuilder()
+                            .setProvider(new ProviderName(NeLocationProvider.NE_LOCATION_PROVIDER_NAME))
+                            .setProviderAddressEndpointLocation(Collections.singletonList(
+                                    new ProviderAddressEndpointLocationBuilder()
+                                    .setAddress(IPv4_HOST_ADDRESS_1)
+                                    .setAddressType(IpPrefixType.class)
+                                    .setContextId(new ContextId(L3_CONTEXT_ID))
+                                    .setContextType(L3Context.class)
+                                    .setAbsoluteLocation(new AbsoluteLocationBuilder()
+                                            .setLocationType(new ExternalLocationCaseBuilder()
+                                                    .setExternalNodeMountPoint(createNetworkElementIid(NODE_ID_1))
+                                                    .setExternalNodeConnector(createInterfaceIid(
+                                                            NODE_ID_1, CONNECTOR_ID_1).toString())
+                                                    .build())
+                                            .build())
+                                    .build()))
+                            .build()))
+                    .build();
+        assertEquals(locationReference, locations);
+    }
+
+    private AddressEndpoint writeBaseAddrEndpoint () throws Exception {
+        AddressEndpoint endpoint =
+                createAddressEndpoint(IPv4_HOST_ADDRESS_1, IpPrefixType.class, L3_CONTEXT_ID, L3Context.class);
+        InstanceIdentifier<AddressEndpoint> iid = IidFactory.addressEndpointIid(endpoint.getKey());
+        WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
+        wtx.put(LogicalDatastoreType.OPERATIONAL, iid, endpoint, true);
+        wtx.submit().get();
+        return endpoint;
+    }
+
+    private NetworkElements writeBaseNetworkElements () throws Exception {
+        NetworkElements nes = createNetworkElements(NODE_ID_1, CONNECTOR_ID_1, L3_CONTEXT_ID, IPv4_NETWORK_ADDRESS_1);
+        InstanceIdentifier<NetworkElements> iid = InstanceIdentifier.builder(NetworkElements.class).build();
+        WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
+        wtx.put(LogicalDatastoreType.CONFIGURATION, iid, nes);
+        wtx.submit().get();
+        return nes;
+    }
+
     private AddressEndpoint createAddressEndpoint(String ipAddr, Class<? extends AddressType> addrType,
             String context, Class<? extends ContextType> cType) {
         return new AddressEndpointBuilder().setAddress(ipAddr).setAddressType(addrType)
@@ -376,8 +545,8 @@ public class NeLocationProviderTest extends CustomDataBrokerTest {
 
     private void verifyEmptyLocations() throws Exception {
         ReadOnlyTransaction rtx = dataBroker.newReadOnlyTransaction();
-        InstanceIdentifier<EndpointLocations> locationIid = InstanceIdentifier.builder(EndpointLocations.class).build();
-        CheckedFuture<Optional<EndpointLocations>, ReadFailedException> read =
+        InstanceIdentifier<LocationProviders> locationIid = InstanceIdentifier.builder(LocationProviders.class).build();
+        CheckedFuture<Optional<LocationProviders>, ReadFailedException> read =
                 rtx.read(LogicalDatastoreType.OPERATIONAL, locationIid);
         assertFalse(read.get().isPresent());
         rtx.close();
index a0d0e82730a65df208fd22d3db45832c78bc473c..1edec15a499a077297ba1198abf690da4073e119 100644 (file)
@@ -28,8 +28,9 @@
     <!-- project specific dependencies -->
     <dependency>
       <groupId>${project.groupId}</groupId>
-      <artifactId>groupbasedpolicy</artifactId>
+      <artifactId>l2-l3-domain-extension</artifactId>
       <version>${project.version}</version>
+      <type>bundle</type>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.neutron</groupId>
index 045e9624c648d1982d9cf19eac0468c703482823..8c42a7454f0d4ab0dfadea217bba9589d6cc8897 100644 (file)
@@ -16,6 +16,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 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.groupbasedpolicy.domain_extension.l2_l3.util.L2L3IidFactory;
 import org.opendaylight.groupbasedpolicy.neutron.gbp.util.NeutronGbpIidFactory;
 import org.opendaylight.groupbasedpolicy.neutron.mapper.infrastructure.NetworkClient;
 import org.opendaylight.groupbasedpolicy.neutron.mapper.infrastructure.NetworkService;
@@ -93,9 +94,9 @@ public class NeutronNetworkAware implements NeutronAware<Network> {
                 MappingUtils.createParent(ctxId, MappingUtils.L2_BRDIGE_DOMAIN));
         ForwardingContext l2Fd = fwdCtxBuilder.build();
 
-        rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.l3ContextIid(tenantId, ctxId), l3Context, true);
-        rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.l2BridgeDomainIid(tenantId, ctxId), l2Bd, true);
-        rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.l2FloodDomainIid(tenantId, ctxId), l2Fd, true);
+        rwTx.put(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.l3ContextIid(tenantId, ctxId), l3Context, true);
+        rwTx.put(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.l2BridgeDomainIid(tenantId, ctxId), l2Bd, true);
+        rwTx.put(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.l2FloodDomainIid(tenantId, ctxId), l2Fd, true);
 
         createTenantNetworkDomains(network, tenantId, rwTx);
 
@@ -185,19 +186,19 @@ public class NeutronNetworkAware implements NeutronAware<Network> {
         TenantId tenantId = new TenantId(network.getTenantId().getValue());
         ContextId id = new ContextId(network.getUuid().getValue());
         Optional<ForwardingContext> potentialL2Fd = DataStoreHelper.removeIfExists(LogicalDatastoreType.CONFIGURATION,
-                IidFactory.l2FloodDomainIid(tenantId, id), rwTx);
+                L2L3IidFactory.l2FloodDomainIid(tenantId, id), rwTx);
         if (!potentialL2Fd.isPresent()) {
             LOG.warn("Illegal state - l2-flood-domain {} does not exist.", id.getValue());
             return;
         }
         Optional<ForwardingContext> potentialL2Bd = DataStoreHelper.removeIfExists(LogicalDatastoreType.CONFIGURATION,
-                IidFactory.l2BridgeDomainIid(tenantId, id), rwTx);
+                L2L3IidFactory.l2BridgeDomainIid(tenantId, id), rwTx);
         if (!potentialL2Bd.isPresent()) {
             LOG.warn("Illegal state - l2-bridge-domain {} does not exist.", id.getValue());
             return;
         }
         Optional<ForwardingContext> potentialL3Ctx = DataStoreHelper.removeIfExists(LogicalDatastoreType.CONFIGURATION,
-                IidFactory.l3ContextIid(tenantId, id), rwTx);
+                L2L3IidFactory.l3ContextIid(tenantId, id), rwTx);
         if (!potentialL3Ctx.isPresent()) {
             LOG.warn("Illegal state - l3-context {} does not exist.", id.getValue());
             return;
index f7a891d9320dcf3b193289eba7ebf8d5998a612a..03e06b2b8b4bc37a90d3d4706f36e147737b75a8 100644 (file)
@@ -18,6 +18,7 @@ import javax.annotation.Nullable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.domain_extension.l2_l3.util.L2L3IidFactory;
 import org.opendaylight.groupbasedpolicy.neutron.gbp.util.NeutronGbpIidFactory;
 import org.opendaylight.groupbasedpolicy.neutron.mapper.EndpointRegistrator;
 import org.opendaylight.groupbasedpolicy.neutron.mapper.infrastructure.NetworkClient;
@@ -128,11 +129,11 @@ public class NeutronPortAware implements NeutronAware<Port> {
                 .setContextType(MappingUtils.L2_BRDIGE_DOMAIN)
                 .setParent(MappingUtils.createParent(routerL3Context, MappingUtils.L3_CONTEXT))
                 .build();
-            rwTx.merge(LogicalDatastoreType.CONFIGURATION, IidFactory.l2BridgeDomainIid(tenantId, l2BdId), l2Bd);
+            rwTx.merge(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.l2BridgeDomainIid(tenantId, l2BdId), l2Bd);
             // set virtual router IP for subnet
             NetworkDomain subnetDomain = NeutronSubnetAware.createSubnet(
                     routerPortSubnet, portIpWithSubnet.getIpAddress());
-            rwTx.merge(LogicalDatastoreType.CONFIGURATION, IidFactory.subnetIid(tenantId, subnetDomain.getNetworkDomainId()), subnetDomain);
+            rwTx.merge(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.subnetIid(tenantId, subnetDomain.getNetworkDomainId()), subnetDomain);
 
             // does the same for tenant forwarding domains
             processTenantForwarding(routerPortSubnet, routerL3Context, portIpWithSubnet, tenantId, rwTx);
@@ -526,9 +527,9 @@ public class NeutronPortAware implements NeutronAware<Port> {
                 .setParent(MappingUtils.createParent(l3Context, MappingUtils.L3_CONTEXT))
                 .build();
             rwTx.merge(LogicalDatastoreType.CONFIGURATION,
-                    IidFactory.l2BridgeDomainIid(tenantId, fwdCtx.getContextId()), fwdCtx);
+                    L2L3IidFactory.l2BridgeDomainIid(tenantId, fwdCtx.getContextId()), fwdCtx);
             NetworkDomain subnet = NeutronSubnetAware.createSubnet(routerPortSubnet, null);
-            rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.subnetIid(tenantId, subnet.getNetworkDomainId()),
+            rwTx.put(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.subnetIid(tenantId, subnet.getNetworkDomainId()),
                     subnet);
             DataStoreHelper.submitToDs(rwTx);
         } else if (PortUtils.isDhcpPort(port)) {
index 0b0199d9ecd6ea375df98216f309718c020a580f..2227224946b31a4c017a611883b79bb79d3a84a7 100644 (file)
@@ -18,6 +18,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 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.groupbasedpolicy.domain_extension.l2_l3.util.L2L3IidFactory;
 import org.opendaylight.groupbasedpolicy.neutron.gbp.util.NeutronGbpIidFactory;
 import org.opendaylight.groupbasedpolicy.neutron.mapper.EndpointRegistrator;
 import org.opendaylight.groupbasedpolicy.neutron.mapper.util.MappingUtils;
@@ -88,7 +89,7 @@ public class NeutronRouterAware implements NeutronAware<Router> {
 
         ContextId routerl3ContextId = new ContextId(router.getUuid().getValue());
         TenantId tenantId = new TenantId(router.getTenantId().getValue());
-        InstanceIdentifier<ForwardingContext> routerL3CtxIid = IidFactory.l3ContextIid(tenantId, routerl3ContextId);
+        InstanceIdentifier<ForwardingContext> routerL3CtxIid = L2L3IidFactory.l3ContextIid(tenantId, routerl3ContextId);
         ForwardingContextBuilder fwdCtxBuilder = new ForwardingContextBuilder();
         Name routerName = null;
         if (!Strings.isNullOrEmpty(router.getName())) {
@@ -168,11 +169,11 @@ public class NeutronRouterAware implements NeutronAware<Router> {
             addNeutronExtGwGbpMapping(routerL3CtxId, gatewayIp, rwTx);
             NetworkDomain subnetDomain = createSubnetWithVirtualRouterIp(gatewayIp, new NetworkDomainId(ipWithSubnetFromGwPort.getSubnetId()
                 .getValue()));
-            rwTx.merge(LogicalDatastoreType.CONFIGURATION, IidFactory.subnetIid(tenantId, subnetDomain.getNetworkDomainId()),
+            rwTx.merge(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.subnetIid(tenantId, subnetDomain.getNetworkDomainId()),
                     subnetDomain);
             ContextId l2BdId = new ContextId(potentialSubnet.get().getNetworkId().getValue());
             Optional<ForwardingContext> optBd = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
-                    IidFactory.l2BridgeDomainIid(tenantId, l2BdId), rwTx);
+                    L2L3IidFactory.l2BridgeDomainIid(tenantId, l2BdId), rwTx);
             if (!optBd.isPresent()) {
                 LOG.warn(
                         "Could not read L2-Bridge-Domain {} Modifiaction of it's parent to L3-Context of router {} aborted.",
@@ -183,7 +184,7 @@ public class NeutronRouterAware implements NeutronAware<Router> {
             ForwardingContext l2BdWithGw = new ForwardingContextBuilder(optBd.get())
             .setParent(MappingUtils.createParent(routerL3CtxId, MappingUtils.L3_CONTEXT))
             .build();
-            rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.l2BridgeDomainIid(tenantId, l2BdId),
+            rwTx.put(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.l2BridgeDomainIid(tenantId, l2BdId),
                     l2BdWithGw);
         }
         updateTenantForwarding(newNeutron, oldRouter, newRouter, new L3ContextId(routerL3CtxId), tenantId, rwTx);
index adf9442f14e3666e28066637c99b4be39ee8b743..2c3037439cd4914dfd243b9e3c86ae57106d1164 100644 (file)
@@ -12,6 +12,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.domain_extension.l2_l3.util.L2L3IidFactory;
 import org.opendaylight.groupbasedpolicy.neutron.mapper.EndpointRegistrator;
 import org.opendaylight.groupbasedpolicy.neutron.mapper.util.MappingUtils;
 import org.opendaylight.groupbasedpolicy.neutron.mapper.util.NetworkUtils;
@@ -97,7 +98,7 @@ public class NeutronSubnetAware implements
             subnetDomain = createSubnet(neutronSubnet, null);
         }
         processTenantSubnet(neutronSubnet, networkOfSubnet, tenantId, rwTx);
-        rwTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.subnetIid(tenantId, subnetDomain.getNetworkDomainId()), subnetDomain, true);
+        rwTx.put(LogicalDatastoreType.CONFIGURATION, L2L3IidFactory.subnetIid(tenantId, subnetDomain.getNetworkDomainId()), subnetDomain, true);
         DataStoreHelper.submitToDs(rwTx);
     }
 
@@ -186,7 +187,7 @@ public class NeutronSubnetAware implements
         NetworkDomainId subnetId = new NetworkDomainId(neutronSubnet.getUuid().getValue());
         TenantId tenantId = new TenantId(neutronSubnet.getTenantId().getValue());
         Optional<NetworkDomain> potentialSubnetDomain = DataStoreHelper.removeIfExists(LogicalDatastoreType.CONFIGURATION,
-                IidFactory.subnetIid(tenantId, subnetId), rwTx);
+                L2L3IidFactory.subnetIid(tenantId, subnetId), rwTx);
         if (!potentialSubnetDomain.isPresent()) {
             LOG.warn("Illegal state - subnet network domain {} does not exist.", subnetId.getValue());
             rwTx.cancel();
index bbf671ac7708e29bad74d56c92344e14151c6674..237f105d0af7e2698defa2313898aef92bee3772 100644 (file)
@@ -64,7 +64,7 @@ public class NetworkUtils {
         if (external == null) {
             return false;
         }
-        return true;
+        return external;
     }
 
     public static @Nonnull String getPhysicalNetwork(Network network) {
index 70f859f42a5b543ee37e09f664601533bc3dbda2..7321a9babc56f38d101e1abc11f33ea148bdcf66 100644 (file)
@@ -18,6 +18,26 @@ public class NeutronVppMapper implements AutoCloseable {
     NeutronListener neutronListener;\r
     private static final Logger LOG = LoggerFactory.getLogger(NeutronVppMapper.class);\r
 \r
+    private String socketPath;\r
+\r
+    private String socketPrefix;\r
+\r
+    public String getSocketPath() {\r
+        return socketPath;\r
+    }\r
+\r
+    public void setSocketPath(String socketPath) {\r
+        this.socketPath = socketPath;\r
+    }\r
+\r
+    public String getSocketPrefix() {\r
+        return socketPrefix;\r
+    }\r
+\r
+    public void setSocketPrefix(String socketPrefix) {\r
+        this.socketPrefix = socketPrefix;\r
+    }\r
+\r
     public NeutronVppMapper(DataBroker dataBroker) {\r
         neutronListener = new NeutronListener(dataBroker);\r
         LOG.info("Neutron VPP started!");\r
index 86243d32788336cd60c11b78cc10efa64d6b6b15..715d5db392f910a9aee51e9456d8b074937051ca 100644 (file)
@@ -47,6 +47,17 @@ module neutron-vpp-mapper-impl {
                 }
             }
 
+            leaf vhostSocketPath {
+                description "Base system directory path for the vhost user host socket filehandle";
+                type string;
+                default "/tmp/";
+            }
+
+            leaf vhostSocketPrefix {
+                description "Prefix for the vhost user host socket filehandle";
+                type string;
+                default "socket_";
+            }
         }
     }
 }
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 3a306a984e1f2101193283a13fc047c755ae6388..6b9946ef86ee4c7afe86b4f96fade8fb13d7fb56 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -18,6 +18,7 @@
   <modules>
     <module>artifacts</module>
     <module>groupbasedpolicy</module>
+    <module>domain-extensions</module>
     <module>renderers</module>
     <module>location-providers</module>
     <module>neutron-mapper</module>
index d092fbdeb0648dc11948785a6a5cde7c9f55b362..801a90c1649bda481f910d9db6d86866be1476ac 100755 (executable)
       <artifactId>powermock-api-mockito</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>com.sun.jersey.jersey-test-framework</groupId>
+      <artifactId>jersey-test-framework-grizzly2</artifactId>
+      <scope>test</scope>
+    </dependency>
 
   </dependencies>
 
index a17c3159f9aa5daab7dbafdbfd3eda77f4c58e68..e28d119b8e8db5e36af84853a9758dc8bda61e13 100755 (executable)
@@ -49,6 +49,8 @@ public class OFStatisticsManager implements AutoCloseable {
     // key is String (not a full IpAddress) because
     // we will get String from REST query to sFlow
     private static ConcurrentMap<String, EndpointL3> endpointL3ByIpMap = new ConcurrentHashMap<>();
+    private static final int CONNECT_TIMEOUT_MILLISEC = 20000;
+    private static final int READ_TIMEOUT_MILLISEC = 30000;
 
     private static final Logger LOG = LoggerFactory.getLogger(OFStatisticsManager.class);
 
@@ -94,7 +96,8 @@ public class OFStatisticsManager implements AutoCloseable {
         epgsByContractId.put(contractId, Pair.of(consEpgKey, provEpgKey));
         boolean isFlowCacheNew = flowCacheNames.add(flowCacheName);
         if (isFlowCacheNew) {
-            SFlowRTConnection sFlowRTConnection = new SFlowRTConnection(executor, sflowCollectorUri, flowCache);
+            SFlowRTConnection sFlowRTConnection = new SFlowRTConnection(executor, sflowCollectorUri, flowCache, new JsonRestClient(sflowCollectorUri, CONNECT_TIMEOUT_MILLISEC,
+                    READ_TIMEOUT_MILLISEC));
             ScheduledFuture<?> collectStatsTask = this.executor.scheduleWithFixedDelay(new ReadGbpFlowCacheTask(flowCacheName, sFlowRTConnection,
                     statisticsManager, MAX_FLOWS, MIN_VALUE_IN_FLOW, AGG_MODE), 0, delay, TimeUnit.SECONDS);
             collectStatsTasks.add(collectStatsTask);
index bd476cf561ce25301494ad3d8ba20701ea818b87..85db48d242bec9484b9f28fc7d6c846aa620d38b 100755 (executable)
@@ -18,6 +18,7 @@ import javax.ws.rs.core.MultivaluedMap;
 
 import org.opendaylight.groupbasedpolicy.api.StatisticsManager;
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.flowcache.FlowCacheData;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.util.SFlowQueryParams;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -31,9 +32,6 @@ public class ReadGbpFlowCacheTask implements Runnable {
 
     private static final Type LIST_OF_FLOW_CACHE_DATA = new TypeToken<List<FlowCacheData>>() {}.getType();
     private static final Gson GSON = new Gson();
-    private static final String MAX_FLOWS_PARAM = "maxFlows";
-    private static final String MIN_VALUE_PARAM = "minValue";
-    private static final String AGG_MODE_PARAM = "aggMode";
 
     private final SFlowRTConnection sFlowRTConnection;
     private final StatisticsManager statisticsManager;
@@ -55,9 +53,9 @@ public class ReadGbpFlowCacheTask implements Runnable {
     @Override
     public void run() {
         MultivaluedMap<String, String> params = new MultivaluedMapImpl();
-        params.add(MAX_FLOWS_PARAM, maxFlows);
-        params.add(MIN_VALUE_PARAM, minValue);
-        params.add(AGG_MODE_PARAM, aggMode);
+        params.add(SFlowQueryParams.MAX_FLOWS, maxFlows);
+        params.add(SFlowQueryParams.MIN_VALUE, minValue);
+        params.add(SFlowQueryParams.AGG_MODE, aggMode);
         JsonRestClientResponse result = sFlowRTConnection.get(path, params);
 
         if (result != null && result.getJsonResponse() != null) {
index 51ccc0f9122bf6b17f0edacd87bf9801c4baebe3..af9bec18044552c2edba32e7ab7e2dc0f9535d4f 100755 (executable)
@@ -51,9 +51,11 @@ public class ResolvedPolicyClassifierListener extends DataTreeChangeHandler<Reso
         ResolvedPolicy resolvedPolicy = rootNode.getDataAfter();
         Map<InstanceIdentifier<Classifier>, Classifier> classifierByIid =
                 resolveClassifiers(resolvedPolicy, rootIdentifier);
-        for (Entry<InstanceIdentifier<Classifier>, Classifier> classfierEntry : classifierByIid.entrySet()) {
-            LOG.trace("New classifier created: {}\n{}", classfierEntry.getKey(), classfierEntry.getValue());
-            ofStatsManager.pullStatsForClassifier(classfierEntry.getKey(), classfierEntry.getValue());
+        for (Entry<InstanceIdentifier<Classifier>, Classifier> classifierEntry : classifierByIid.entrySet()) {
+            LOG.trace("New classifier created: {}\n{}", classifierEntry.getKey(),
+                    classifierEntry.getValue());
+            ofStatsManager.pullStatsForClassifier(classifierEntry.getKey(),
+                    classifierEntry.getValue());
         }
     }
 
index 9a390fec785292fa77410b6f838107fefb51cd45..7189982c856d72c31d0057ef9a8707f5c5878583 100755 (executable)
@@ -21,25 +21,23 @@ public class SFlowRTConnection {
 
     private static final Logger LOG = LoggerFactory.getLogger(SFlowRTConnection.class);
 
-    private static final int CONNECT_TIMEOUT_MILLISEC = 20000;
-    private static final int READ_TIMEOUT_MILLISEC = 30000;
     private static final String GET = "GET";
     private static final String PUT = "PUT";
     private static final String DELETE = "DELETE";
 
+    static final String EX_MSG_NOT_INITIALIZED = "SFlowRTConnection is not initialized.";
+
     private final FlowCache flowCache;
     private JsonRestClient client;
     private boolean isInitialized = false;
     private final ScheduledExecutorService executor;
     private final String collectorUri;
 
-    public SFlowRTConnection(ScheduledExecutorService executor, String collectorUri, FlowCache flowCache) {
+    public SFlowRTConnection(ScheduledExecutorService executor, String collectorUri, FlowCache flowCache, JsonRestClient client) {
         this.executor = Preconditions.checkNotNull(executor);
         this.collectorUri = Preconditions.checkNotNull(collectorUri);
         this.flowCache = Preconditions.checkNotNull(flowCache);
-
-        this.client = new JsonRestClient(collectorUri, CONNECT_TIMEOUT_MILLISEC,
-                READ_TIMEOUT_MILLISEC);
+        this.client = client;
         initialize();
     }
 
@@ -60,7 +58,7 @@ public class SFlowRTConnection {
     public JsonRestClientResponse get(String path,
             MultivaluedMap<String, String> params) {
         if (!isInitialized()) {
-            throw new IllegalStateException("SFlowRTConnection is not initialized.");
+            throw new IllegalStateException(EX_MSG_NOT_INITIALIZED);
         }
         try {
             JsonRestClientResponse responce = client.get(path, params);
@@ -75,7 +73,7 @@ public class SFlowRTConnection {
     @Nullable
     public JsonRestClientResponse put(String path, String someJson) {
         if (!isInitialized()) {
-            throw new IllegalStateException("SFlowRTConnection is not initialized.");
+            throw new IllegalStateException(EX_MSG_NOT_INITIALIZED);
         }
         return putWithoutInitCheck(path, someJson);
     }
@@ -95,7 +93,7 @@ public class SFlowRTConnection {
 
     public JsonRestClientResponse delete(String path) {
         if (!isInitialized()) {
-            throw new IllegalStateException("SFlowRTConnection is not initialized.");
+            throw new IllegalStateException(EX_MSG_NOT_INITIALIZED);
         }
         try {
             JsonRestClientResponse responce = client.delete(path);
diff --git a/renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/util/SFlowQueryParams.java b/renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/util/SFlowQueryParams.java
new file mode 100644 (file)
index 0000000..8e1b9cf
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.util;
+
+public class SFlowQueryParams {
+
+    public static final String MAX_FLOWS = "maxFlows";
+    public static final String MIN_VALUE = "minValue";
+    public static final String AGG_MODE = "aggMode";
+
+}
index 6d6b1eb7eeda39e25331493b8a937be3864c5fda..15453a0750bb5d2b02710fd95566eb4fafd9babc 100644 (file)
@@ -8,11 +8,21 @@
 
 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.arp;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeNoException;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
 import java.net.InetAddress;
 import java.util.Collections;
 import java.util.concurrent.Future;
 
-import org.junit.Assert;
+import com.google.common.util.concurrent.UncheckedExecutionException;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
@@ -102,11 +112,11 @@ public class ArpTaskerTest extends OfOverlayDataBrokerTest {
     @Before
     public void init() {
 
-        PacketProcessingService packetService = Mockito.mock(PacketProcessingService.class);
-        flowService = Mockito.mock(SalFlowService.class);
-        rpcRegistry = Mockito.mock(RpcProviderRegistry.class);
-        Mockito.when(rpcRegistry.getRpcService(PacketProcessingService.class)).thenReturn(packetService);
-        Mockito.when(rpcRegistry.getRpcService(SalFlowService.class)).thenReturn(flowService);
+        PacketProcessingService packetService = mock(PacketProcessingService.class);
+        flowService = mock(SalFlowService.class);
+        rpcRegistry = mock(RpcProviderRegistry.class);
+        when(rpcRegistry.getRpcService(PacketProcessingService.class)).thenReturn(packetService);
+        when(rpcRegistry.getRpcService(SalFlowService.class)).thenReturn(flowService);
     }
 
     @SuppressWarnings("unchecked")
@@ -147,24 +157,25 @@ public class ArpTaskerTest extends OfOverlayDataBrokerTest {
                     .build()));
 
         // test without key
-        ReadOnlyTransaction rtx = Mockito.mock(ReadOnlyTransaction.class);
-        broker = Mockito.mock(DataBroker.class);
+        ReadOnlyTransaction rtx = mock(ReadOnlyTransaction.class);
+        broker = mock(DataBroker.class);
         arpTasker = new ArpTasker(rpcRegistry, broker);
 
-        epL3.setKey(new EndpointL3Key(Mockito.mock(IpAddress.class), null));
+        epL3.setKey(new EndpointL3Key(mock(IpAddress.class), null));
         arpTasker.addMacForL3EpAndCreateEp(epL3.build());
-        Mockito.verify(broker, Mockito.never()).newReadOnlyTransaction();
+        verify(broker, never()).newReadOnlyTransaction();
 
         // test without node with external interface
         epL3.setKey(key);
-        Mockito.when(broker.newReadOnlyTransaction()).thenReturn(rtx);
+        when(broker.newReadOnlyTransaction()).thenReturn(rtx);
         CheckedFuture<Optional<DataObject>, ReadFailedException> future =
                 Futures.immediateCheckedFuture(Optional.<DataObject>absent());
-        Mockito.when(rtx.read(Matchers.eq(LogicalDatastoreType.CONFIGURATION), Matchers.any(InstanceIdentifier.class)))
+        when(rtx.read(Matchers.eq(LogicalDatastoreType.CONFIGURATION),
+                any(InstanceIdentifier.class)))
             .thenReturn(future);
         arpTasker.addMacForL3EpAndCreateEp(epL3.build());
-        Mockito.verify(broker).newReadOnlyTransaction();
-        Mockito.verify(rtx).close();
+        verify(broker).newReadOnlyTransaction();
+        verify(rtx).close();
 
         // test correct
         broker = getDataBroker();
@@ -177,27 +188,37 @@ public class ArpTaskerTest extends OfOverlayDataBrokerTest {
                 .child(NodeConnector.class, new NodeConnectorKey(connectorId))
                 .build(),
                 connector.build(), true);
-        wtx.put(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(Tenants.class).build(), tenants.build(),
-                true);
+        // ignoring a Windows-specific bug
+        try {
+            wtx.put(LogicalDatastoreType.CONFIGURATION,
+                    InstanceIdentifier.builder(Tenants.class).build(), tenants.build(), true);
+        } catch (UncheckedExecutionException e) {
+            assumeNoException(e);
+        }
         wtx.submit().get();
 
-        Future<RpcResult<AddFlowOutput>> flowFuture = Mockito.mock(Future.class);
-        Mockito.when(flowService.addFlow(Mockito.any(AddFlowInput.class))).thenReturn(flowFuture);
+        Future<RpcResult<AddFlowOutput>> flowFuture = mock(Future.class);
+        when(flowService.addFlow(any(AddFlowInput.class))).thenReturn(flowFuture);
 
         epL3.setNetworkContainment(domainId).setTenant(tenantId);
         arpTasker.addMacForL3EpAndCreateEp(epL3.build());
         ArgumentCaptor<AddFlowInput> argument = ArgumentCaptor.forClass(AddFlowInput.class);
-        Mockito.verify(flowService).addFlow(argument.capture());
+        verify(flowService).addFlow(argument.capture());
         AddFlowInput result = argument.getValue();
-        Assert.assertEquals(EtherTypes.ARP.intValue(),
-                result.getMatch().getEthernetMatch().getEthernetType().getType().getValue().intValue());
+        assertEquals(EtherTypes.ARP.intValue(), result.getMatch()
+                .getEthernetMatch()
+                .getEthernetType()
+                .getType()
+                .getValue()
+                .intValue());
         ArpMatch match = (ArpMatch)result.getMatch().getLayer3Match();
-        Assert.assertEquals(ArpOperation.REPLY.intValue(),match.getArpOp().intValue());
-        Assert.assertEquals("192.168.0.254/32",match.getArpTargetTransportAddress().getValue());
-        Assert.assertEquals("192.168.0.1/32", match.getArpSourceTransportAddress().getValue());
-        Assert.assertEquals(connectorId, result.getMatch().getInPort());
-        Assert.assertEquals(new NodeRef(InstanceIdentifier.builder(Nodes.class)
-                .child(Node.class, node.getKey()).build()), result.getNode());
+        assertEquals(ArpOperation.REPLY.intValue(), match.getArpOp().intValue());
+        assertEquals("192.168.0.254/32", match.getArpTargetTransportAddress().getValue());
+        assertEquals("192.168.0.1/32", match.getArpSourceTransportAddress().getValue());
+        assertEquals(connectorId, result.getMatch().getInPort());
+        assertEquals(new NodeRef(
+                InstanceIdentifier.builder(Nodes.class).child(Node.class, node.getKey()).build()),
+                result.getNode());
 
         // onPacketReceived
         Arp arp = new Arp();
@@ -255,13 +276,14 @@ public class ArpTaskerTest extends OfOverlayDataBrokerTest {
         arpTasker.onPacketReceived(packet);
         rtx = broker.newReadOnlyTransaction();
         Optional<EndpointL3> optional = rtx.read(LogicalDatastoreType.OPERATIONAL, epL3Iid).get();
-        Assert.assertTrue(optional.isPresent());
+        assertTrue(optional.isPresent());
         EndpointL3 epl3 = optional.get();
-        Assert.assertArrayEquals(sha, HexEncode.bytesFromHexString(epl3.getMacAddress().getValue()));
-        Assert.assertEquals(l2domain.getId(), epl3.getL2Context());
+        assertArrayEquals(sha, HexEncode.bytesFromHexString(epl3.getMacAddress().getValue()));
+        assertEquals(l2domain.getId(), epl3.getL2Context());
         Optional<Endpoint> optionalEp = rtx.read(LogicalDatastoreType.OPERATIONAL,
                 IidFactory.endpointIid(l2domainId, new MacAddress("00:00:00:00:00:01"))).get();
-        Assert.assertTrue(optionalEp.isPresent());
-        Assert.assertEquals(new OfOverlayContextBuilder(augment).build(), optionalEp.get().getAugmentation(OfOverlayContext.class));
+        assertTrue(optionalEp.isPresent());
+        assertEquals(new OfOverlayContextBuilder(augment).build(),
+                optionalEp.get().getAugmentation(OfOverlayContext.class));
     }
 }
index 7e46d96217ada5ac18525bfa54187f554e774948..3586f03bbfd68554930e44254ed2b9f786561c28 100644 (file)
@@ -8,6 +8,9 @@
 
 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.arp;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
 import java.net.InetAddress;
 
 import org.junit.Assert;
@@ -67,4 +70,11 @@ public class ArpUtilsTest {
         Assert.assertTrue(
                 result.contains("getTargetProtocolAddress()=" + InetAddress.getByAddress(tpa).getHostAddress()));
     }
+
+    @Test
+    public void testBytesToMac(){
+        byte[] macBytes = {0,1,0,1,0,1};
+        assertEquals(new MacAddress("00:01:00:01:00:01"), ArpUtils.bytesToMac(macBytes));
+        assertNull(ArpUtils.bytesToMac(null));
+    }
 }
index 0f92fac41fc2e1cbaed00225f9bb06f4c7b4b84c..c7dc70c39fff521ed0352f26ff47c53ba993f5b0 100755 (executable)
@@ -31,8 +31,7 @@ public class EndpointManagerListenerTest {
         endpointManager = mock(EndpointManager.class);
         DataBroker dataProvider = mock(DataBroker.class);
 
-        EndpointManagerListener endpointManagerListener =
-                new EndpointManagerListener(dataProvider, endpointManager);
+        EndpointManagerListener endpointManagerListener = new EndpointManagerListener(dataProvider, endpointManager);
         tester = new DataChangeListenerTester(endpointManagerListener);
         tester.setRemovedPath(endpointId);
     }
@@ -45,8 +44,7 @@ public class EndpointManagerListenerTest {
         tester.callOnDataChanged();
 
         verify(endpointManager, times(3)).processEndpoint(any(Endpoint.class), any(Endpoint.class));
-        verify(endpointManager, never()).processL3Endpoint(any(EndpointL3.class),
-                any(EndpointL3.class));
+        verify(endpointManager, never()).processL3Endpoint(any(EndpointL3.class), any(EndpointL3.class));
     }
 
     @Test
@@ -57,8 +55,7 @@ public class EndpointManagerListenerTest {
         tester.callOnDataChanged();
 
         verify(endpointManager, never()).processEndpoint(any(Endpoint.class), any(Endpoint.class));
-        verify(endpointManager, times(3)).processL3Endpoint(any(EndpointL3.class),
-                any(EndpointL3.class));
+        verify(endpointManager, times(3)).processL3Endpoint(any(EndpointL3.class), any(EndpointL3.class));
     }
 
     @Test
@@ -69,8 +66,7 @@ public class EndpointManagerListenerTest {
         tester.callOnDataChanged();
 
         verify(endpointManager, never()).processEndpoint(any(Endpoint.class), any(Endpoint.class));
-        verify(endpointManager, never()).processL3Endpoint(any(EndpointL3.class),
-                any(EndpointL3.class));
+        verify(endpointManager, never()).processL3Endpoint(any(EndpointL3.class), any(EndpointL3.class));
     }
 
 }
index 2b59de46991216dc2bef107c0c4a0252d0836fd0..aa54188d21262eb3b68be8562fd8abc78f73eb84 100644 (file)
@@ -8,6 +8,11 @@
 
 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
@@ -16,17 +21,16 @@ import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import java.lang.reflect.Method;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.UUID;
 import java.util.concurrent.ScheduledExecutorService;
 
-import org.junit.Assert;
+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;
@@ -35,7 +39,6 @@ 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.NotificationService;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-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.AsyncDataBroker.DataChangeScope;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
@@ -67,18 +70,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.l3endpoint.rev151217.NatAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContext;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayL3Context;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.Tenant;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.ForwardingContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2BridgeDomain;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.RpcService;
 
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
-
 public class EndpointManagerTest {
 
     private EndpointManager manager;
@@ -102,6 +99,8 @@ public class EndpointManagerTest {
     private EndpointL3 newL3Ep;
     private Optional<Endpoints> optionalRead;
 
+    // TODO get rid of unnecessary mocks (endpoint1, endpoint2, their parameters)
+
     @SuppressWarnings("unchecked")
     @Before
     public void initialisation() throws Exception {
@@ -114,7 +113,8 @@ public class EndpointManagerTest {
         when(dataProvider.newWriteOnlyTransaction()).thenReturn(writeTransaction);
         CheckedFuture<Void, TransactionCommitFailedException> checkedFutureWrite = mock(CheckedFuture.class);
         when(writeTransaction.submit()).thenReturn(checkedFutureWrite);
-        BindingAwareBroker.RpcRegistration<EndpointService> rpcRegistration = mock(BindingAwareBroker.RpcRegistration.class);
+        BindingAwareBroker.RpcRegistration<EndpointService> rpcRegistration =
+                mock(BindingAwareBroker.RpcRegistration.class);
         listenerReg = mock(ListenerRegistration.class);
         when(dataProvider.registerDataChangeListener(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
                 any(DataChangeListener.class), any(DataChangeScope.class))).thenReturn(listenerReg);
@@ -167,8 +167,8 @@ public class EndpointManagerTest {
         ReadOnlyTransaction readTransaction = mock(ReadOnlyTransaction.class);
         when(dataProvider.newReadOnlyTransaction()).thenReturn(readTransaction);
         CheckedFuture<Optional<Endpoints>, ReadFailedException> checkedFutureRead = mock(CheckedFuture.class);
-        when(readTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(
-                checkedFutureRead);
+        when(readTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)))
+            .thenReturn(checkedFutureRead);
         optionalRead = mock(Optional.class);
         when(checkedFutureRead.checkedGet()).thenReturn(optionalRead);
         when(optionalRead.isPresent()).thenReturn(false);
@@ -181,39 +181,39 @@ public class EndpointManagerTest {
 
     @Test
     public void getGroupsForNodeTest() {
-        Assert.assertTrue(manager.getGroupsForNode(nodeId1).isEmpty());
+        assertTrue(manager.getGroupsForNode(nodeId1).isEmpty());
         manager.processEndpoint(null, endpoint1);
-        Assert.assertFalse(manager.getGroupsForNode(nodeId1).isEmpty());
+        assertFalse(manager.getGroupsForNode(nodeId1).isEmpty());
     }
 
     @Test
     public void getNodesForGroupTest() {
         EgKey egKey = mock(EgKey.class);
         Set<NodeId> nodesForGroup = manager.getNodesForGroup(egKey);
-        Assert.assertNotNull(nodesForGroup);
-        Assert.assertTrue(nodesForGroup.isEmpty());
+        assertNotNull(nodesForGroup);
+        assertTrue(nodesForGroup.isEmpty());
     }
 
     @Test
     public void getEndpointsForNodeTestNodeIdEgKey() {
         EgKey egKey = new EgKey(tenantId, endpointGroupId);
-        Assert.assertTrue(manager.getEndpointsForNode(nodeId1, egKey).isEmpty());
+        assertTrue(manager.getEndpointsForNode(nodeId1, egKey).isEmpty());
         manager.processEndpoint(null, endpoint1);
-        Assert.assertFalse(manager.getEndpointsForNode(nodeId1, egKey).isEmpty());
+        assertFalse(manager.getEndpointsForNode(nodeId1, egKey).isEmpty());
     }
 
     @Test
     public void getEndpointsForNodeTestNodeId() {
-        Assert.assertTrue(manager.getEndpointsForNode(nodeId1).isEmpty());
+        assertTrue(manager.getEndpointsForNode(nodeId1).isEmpty());
         manager.processEndpoint(null, endpoint1);
-        Assert.assertFalse(manager.getEndpointsForNode(nodeId1).isEmpty());
+        assertFalse(manager.getEndpointsForNode(nodeId1).isEmpty());
     }
 
     @Test
     public void getEndpoint() {
         EpKey epKey = new EpKey(endpoint1.getL2Context(), endpoint1.getMacAddress());
         manager.processEndpoint(null, endpoint1);
-        Assert.assertEquals(endpoint1, manager.getEndpoint(epKey));
+        assertEquals(endpoint1, manager.getEndpoint(epKey));
     }
 
     @SuppressWarnings("unchecked")
@@ -222,8 +222,8 @@ public class EndpointManagerTest {
         ReadOnlyTransaction readTransaction = mock(ReadOnlyTransaction.class);
         when(dataProvider.newReadOnlyTransaction()).thenReturn(readTransaction);
         CheckedFuture<Optional<Endpoints>, ReadFailedException> resultFuture = mock(CheckedFuture.class);
-        when(readTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(
-                resultFuture);
+        when(readTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)))
+            .thenReturn(resultFuture);
         Optional<Endpoints> optional = mock(Optional.class);
         when(resultFuture.checkedGet()).thenReturn(optional);
         when(optional.isPresent()).thenReturn(true);
@@ -234,7 +234,7 @@ public class EndpointManagerTest {
         when(endpointL3Prefix.getTenant()).thenReturn(tenantId);
 
         Collection<EndpointL3Prefix> result = manager.getEndpointsL3PrefixForTenant(tenantId);
-        Assert.assertTrue(result.contains(endpointL3Prefix));
+        assertTrue(result.contains(endpointL3Prefix));
     }
 
     @SuppressWarnings("unchecked")
@@ -243,24 +243,25 @@ public class EndpointManagerTest {
         ReadOnlyTransaction transaction = mock(ReadOnlyTransaction.class);
         when(dataProvider.newReadOnlyTransaction()).thenReturn(transaction);
         CheckedFuture<Optional<Endpoints>, ReadFailedException> checkedFuture = mock(CheckedFuture.class);
-        when(transaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(checkedFuture);
+        when(transaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)))
+            .thenReturn(checkedFuture);
         Optional<Endpoints> optional = mock(Optional.class);
         when(checkedFuture.checkedGet()).thenReturn(optional);
         when(optional.isPresent()).thenReturn(false);
-        Assert.assertNull(manager.getEndpointsFromDataStore());
+        assertNull(manager.getEndpointsFromDataStore());
 
         when(optional.isPresent()).thenReturn(true);
         Endpoints endpoints = mock(Endpoints.class);
         when(optional.get()).thenReturn(endpoints);
-        Assert.assertEquals(endpoints, manager.getEndpointsFromDataStore());
+        assertEquals(endpoints, manager.getEndpointsFromDataStore());
 
         manager = new EndpointManager(null, rpcRegistry, notificationService, executor, switchManager);
-        Assert.assertNull(manager.getEndpointsFromDataStore());
+        assertNull(manager.getEndpointsFromDataStore());
     }
 
     @Test
     public void getL3EndpointsTestEndpointsNull() throws Exception {
-        Assert.assertNull(manager.getL3Endpoints());
+        assertNull(manager.getL3Endpoints());
     }
 
     @Test
@@ -270,7 +271,7 @@ public class EndpointManagerTest {
         when(optionalRead.get()).thenReturn(endpoints);
         when(endpoints.getEndpointL3()).thenReturn(null);
 
-        Assert.assertNull(manager.getL3Endpoints());
+        assertNull(manager.getL3Endpoints());
     }
 
     @Test
@@ -281,7 +282,7 @@ public class EndpointManagerTest {
         List<EndpointL3> endpointL3List = Collections.singletonList(mock(EndpointL3.class));
         when(endpoints.getEndpointL3()).thenReturn(endpointL3List);
 
-        Assert.assertEquals(endpointL3List, manager.getL3Endpoints());
+        assertEquals(endpointL3List, manager.getL3Endpoints());
     }
 
     @Test
@@ -301,13 +302,13 @@ public class EndpointManagerTest {
         when(endpointL3.getMacAddress()).thenReturn(mock(MacAddress.class));
 
         Map<EndpointKey, EndpointL3> result = manager.getL3EpWithNatByL2Key();
-        Assert.assertTrue(result.containsValue(endpointL3));
+        assertTrue(result.containsValue(endpointL3));
     }
 
     @Test
     public void getL3EpWithNatByL2KeyTestL3EpsNull() {
         Map<EndpointKey, EndpointL3> result = manager.getL3EpWithNatByL2Key();
-        Assert.assertTrue(result.isEmpty());
+        assertTrue(result.isEmpty());
     }
 
     @Test
@@ -326,7 +327,7 @@ public class EndpointManagerTest {
         when(endpointL3.getMacAddress()).thenReturn(null);
 
         Map<EndpointKey, EndpointL3> result = manager.getL3EpWithNatByL2Key();
-        Assert.assertTrue(result.isEmpty());
+        assertTrue(result.isEmpty());
     }
 
     @Test
@@ -345,26 +346,26 @@ public class EndpointManagerTest {
         when(endpointL3.getMacAddress()).thenReturn(mock(MacAddress.class));
 
         Map<EndpointKey, EndpointL3> result = manager.getL3EpWithNatByL2Key();
-        Assert.assertTrue(result.isEmpty());
+        assertTrue(result.isEmpty());
     }
 
     @Test
     public void getEndpointsForGroupTest() {
         EgKey newEgKey = new EgKey(tenantId, endpointGroupId);
-        Assert.assertTrue(manager.getEndpointsForGroup(newEgKey).isEmpty());
+        assertTrue(manager.getEndpointsForGroup(newEgKey).isEmpty());
         manager.processEndpoint(null, endpoint1);
-        Assert.assertFalse(manager.getEndpointsForGroup(newEgKey).isEmpty());
+        assertFalse(manager.getEndpointsForGroup(newEgKey).isEmpty());
     }
 
     @Test
     public void getConditionsForEndpoint() {
         Endpoint endpoint = mock(Endpoint.class);
         when(endpoint.getCondition()).thenReturn(null);
-        Assert.assertTrue(manager.getConditionsForEndpoint(endpoint).isEmpty());
+        assertTrue(manager.getConditionsForEndpoint(endpoint).isEmpty());
 
         List<ConditionName> conditionNameList = Collections.singletonList(mock(ConditionName.class));
         when(endpoint.getCondition()).thenReturn(conditionNameList);
-        Assert.assertEquals(conditionNameList, manager.getConditionsForEndpoint(endpoint));
+        assertEquals(conditionNameList, manager.getConditionsForEndpoint(endpoint));
     }
 
     @Test
@@ -386,7 +387,7 @@ public class EndpointManagerTest {
         when(endpointL3Key.getIpAddress()).thenReturn(ipAddress);
         when(newL3Ep.getIpAddress()).thenReturn(new IpAddress(new Ipv4Address("1.1.1.1")));
         manager.processL3Endpoint(null, newL3Ep);
-        verify(endpointListener,never()).endpointUpdated(any(EpKey.class));
+        verify(endpointListener, never()).endpointUpdated(any(EpKey.class));
     }
 
     @Test
@@ -407,7 +408,7 @@ public class EndpointManagerTest {
         when(endpointL3Key.getIpAddress()).thenReturn(ipAddress);
         when(newL3Ep.getIpAddress()).thenReturn(new IpAddress(new Ipv4Address("1.1.1.1")));
         manager.processL3Endpoint(null, newL3Ep);
-        verify(endpointListener,never()).endpointUpdated(any(EpKey.class));
+        verify(endpointListener, never()).endpointUpdated(any(EpKey.class));
     }
 
     @Test
@@ -437,7 +438,7 @@ public class EndpointManagerTest {
         when(newL3Ep.getIpAddress()).thenReturn(null);
         when(newL3Ep.getIpAddress()).thenReturn(new IpAddress(new Ipv4Address("1.1.1.1")));
         manager.processL3Endpoint(null, newL3Ep);
-        verify(endpointListener,never()).endpointUpdated(any(EpKey.class));
+        verify(endpointListener, never()).endpointUpdated(any(EpKey.class));
     }
 
     @Test
@@ -447,6 +448,30 @@ public class EndpointManagerTest {
         verify(endpointListener).endpointUpdated(any(EpKey.class));
     }
 
+    @Test
+    public void updateEndpointL3TestUpdate() throws Exception {
+        when(oldL3Ep.getIpAddress()).thenReturn(new IpAddress(new Ipv4Address("1.1.1.1")));
+
+        when(newL3Ep.getTenant()).thenReturn(mock(TenantId.class));
+        when(newL3Ep.getEndpointGroup()).thenReturn(mock(EndpointGroupId.class));
+        when(newL3Ep.getL3Context()).thenReturn(mock(L3ContextId.class));
+        when(newL3Ep.getIpAddress()).thenReturn(mock(IpAddress.class));
+
+        OfOverlayL3Context ofOverlayL3Context = mock(OfOverlayL3Context.class);
+        when(newL3Ep.getAugmentation(OfOverlayL3Context.class)).thenReturn(ofOverlayL3Context);
+
+        when(newL3Ep.getNetworkContainment()).thenReturn(null);
+
+        when(newL3Ep.getL2Context()).thenReturn(mock(L2BridgeDomainId.class));
+        when(newL3Ep.getMacAddress()).thenReturn(mock(MacAddress.class));
+        when(newL3Ep.getIpAddress()).thenReturn(new IpAddress(new Ipv4Address("1.1.1.1")));
+
+        manager.processL3Endpoint(null, oldL3Ep);
+        manager.processL3Endpoint(oldL3Ep, newL3Ep);
+
+        verify(endpointListener).endpointUpdated(any(EpKey.class));
+    }
+
     @Test
     public void updateEndpointTestNewEndpointRemove() {
         Collection<Endpoint> collection;
@@ -454,13 +479,13 @@ public class EndpointManagerTest {
         verify(endpointListener).endpointUpdated(any(EpKey.class));
         verify(endpointListener).nodeEndpointUpdated(any(NodeId.class), any(EpKey.class));
         collection = manager.getEndpointsForGroup(new EgKey(tenantId, endpointGroupId));
-        Assert.assertFalse(collection.isEmpty());
+        assertFalse(collection.isEmpty());
 
         manager.processEndpoint(endpoint2, null);
         verify(endpointListener, times(2)).endpointUpdated(any(EpKey.class));
         verify(endpointListener, times(2)).nodeEndpointUpdated(any(NodeId.class), any(EpKey.class));
         collection = manager.getEndpointsForGroup(new EgKey(tenantId, endpointGroupId));
-        Assert.assertTrue(collection.isEmpty());
+        assertTrue(collection.isEmpty());
     }
 
     @Test
@@ -516,7 +541,7 @@ public class EndpointManagerTest {
         // create: node1, update: node1 -> node2
         verify(endpointListener, times(3)).nodeEndpointUpdated(any(NodeId.class), any(EpKey.class));
         collection = manager.getEndpointsForGroup(new EgKey(tenantId, endpointGroupId));
-        Assert.assertFalse(collection.isEmpty());
+        assertFalse(collection.isEmpty());
     }
 
     /**
@@ -534,9 +559,9 @@ public class EndpointManagerTest {
         verify(endpointListener, times(2)).endpointUpdated(any(EpKey.class));
         verify(endpointListener, times(1)).nodeEndpointUpdated(any(NodeId.class), any(EpKey.class));
         collection = manager.getEndpointsForGroup(new EgKey(tenantId, endpointGroupId));
-        Assert.assertTrue(collection.isEmpty());
+        assertTrue(collection.isEmpty());
         collection = manager.getEndpointsForGroup(new EgKey(tenantId, otherEndpointGroupId));
-        Assert.assertFalse(collection.isEmpty());
+        assertFalse(collection.isEmpty());
     }
 
     /**
@@ -554,9 +579,9 @@ public class EndpointManagerTest {
         // create: node1, update: node1 -> node2
         verify(endpointListener, times(3)).nodeEndpointUpdated(any(NodeId.class), any(EpKey.class));
         collection = manager.getEndpointsForGroup(new EgKey(tenantId, endpointGroupId));
-        Assert.assertTrue(collection.isEmpty());
+        assertTrue(collection.isEmpty());
         collection = manager.getEndpointsForGroup(new EgKey(tenantId, otherEndpointGroupId));
-        Assert.assertFalse(collection.isEmpty());
+        assertFalse(collection.isEmpty());
     }
 
     /**
@@ -573,7 +598,7 @@ public class EndpointManagerTest {
         verify(endpointListener, times(2)).endpointUpdated(any(EpKey.class));
         verify(endpointListener, times(2)).nodeEndpointUpdated(any(NodeId.class), any(EpKey.class));
         collection = manager.getEndpointsForGroup(new EgKey(tenantId, endpointGroupId));
-        Assert.assertTrue(collection.isEmpty());
+        assertTrue(collection.isEmpty());
     }
 
     /**
@@ -590,7 +615,7 @@ public class EndpointManagerTest {
         verify(endpointListener).endpointUpdated(any(EpKey.class));
         verify(endpointListener).nodeEndpointUpdated(any(NodeId.class), any(EpKey.class));
         collection = manager.getEndpointsForGroup(new EgKey(tenantId, endpointGroupId));
-        Assert.assertFalse(collection.isEmpty());
+        assertFalse(collection.isEmpty());
     }
 
     @Test
@@ -599,36 +624,36 @@ public class EndpointManagerTest {
         verify(listenerReg, times(3)).close();
     }
 
-     //**************
-     //Helper Functions
-     //**************
+    // **************
+    // Helper Functions
+    // **************
 
     @Test
     public void getEgKeyTest() {
-        Assert.assertNotNull(manager.getEgKey(endpoint1));
-        Assert.assertNull(manager.getEgKey(null));
+        assertNotNull(manager.getEgKey(endpoint1));
+        assertNull(manager.getEgKey(null));
 
         when(endpoint1.getTenant()).thenReturn(null);
-        Assert.assertNull(manager.getEgKey(endpoint1));
+        assertNull(manager.getEgKey(endpoint1));
 
         when(endpoint1.getTenant()).thenReturn(tenantId);
         when(endpoint1.getEndpointGroup()).thenReturn(null);
-        Assert.assertNull(manager.getEgKey(endpoint1));
+        assertNull(manager.getEgKey(endpoint1));
 
         when(endpoint1.getEndpointGroup()).thenReturn(endpointGroupId);
         when(endpoint1.getEndpointGroups()).thenReturn(null);
-        Assert.assertNotNull(manager.getEgKey(endpoint1));
+        assertNotNull(manager.getEgKey(endpoint1));
 
         when(endpoint1.getEndpointGroup()).thenReturn(null);
-        Assert.assertNull(manager.getEgKey(endpoint1));
+        assertNull(manager.getEgKey(endpoint1));
 
         when(endpoint1.getEndpointGroup()).thenReturn(endpointGroupId);
         when(endpoint1.getL2Context()).thenReturn(null);
-        Assert.assertNull(manager.getEgKey(endpoint1));
+        assertNull(manager.getEgKey(endpoint1));
 
         when(endpoint1.getL2Context()).thenReturn(l2BridgeDomainId);
         when(endpoint1.getMacAddress()).thenReturn(null);
-        Assert.assertNull(manager.getEgKey(endpoint1));
+        assertNull(manager.getEgKey(endpoint1));
     }
 
     @Test
@@ -638,18 +663,18 @@ public class EndpointManagerTest {
 
         when(endpoint.getEndpointGroups()).thenReturn(null);
         egKeys = manager.getEgKeysForEndpoint(endpoint);
-        Assert.assertTrue(egKeys.isEmpty());
+        assertTrue(egKeys.isEmpty());
 
         EndpointGroupId endpointGroupId = mock(EndpointGroupId.class);
         when(endpoint.getEndpointGroup()).thenReturn(endpointGroupId);
         egKeys = manager.getEgKeysForEndpoint(endpoint);
-        Assert.assertEquals(1, egKeys.size());
+        assertEquals(1, egKeys.size());
 
         EndpointGroupId epgId = mock(EndpointGroupId.class);
         List<EndpointGroupId> endpointGroups = Collections.singletonList(epgId);
         when(endpoint.getEndpointGroups()).thenReturn(endpointGroups);
         egKeys = manager.getEgKeysForEndpoint(endpoint);
-        Assert.assertEquals(2, egKeys.size());
+        assertEquals(2, egKeys.size());
     }
 
     @Test
@@ -657,21 +682,42 @@ public class EndpointManagerTest {
         Endpoint endpoint = mock(Endpoint.class);
         when(endpoint.getAugmentation(OfOverlayContext.class)).thenReturn(null);
         // TODO
-//        Assert.assertFalse(manager.isExternal(endpoint));
-//        Assert.assertTrue(manager.isInternal(endpoint));
-//
-//        OfOverlayContext ofc = mock(OfOverlayContext.class);
-//        when(endpoint.getAugmentation(OfOverlayContext.class)).thenReturn(ofc);
-//        when(ofc.getLocationType()).thenReturn(null);
-//        Assert.assertFalse(manager.isExternal(endpoint));
-//        Assert.assertTrue(manager.isInternal(endpoint));
-//
-//        when(ofc.getLocationType()).thenReturn(LocationType.Internal);
-//        Assert.assertFalse(manager.isExternal(endpoint));
-//        Assert.assertTrue(manager.isInternal(endpoint));
-//
-//        when(ofc.getLocationType()).thenReturn(LocationType.External);
-//        Assert.assertTrue(manager.isExternal(endpoint));
-//        Assert.assertFalse(manager.isInternal(endpoint));
+        // assertFalse(manager.isExternal(endpoint));
+        // assertTrue(manager.isInternal(endpoint));
+        //
+        // OfOverlayContext ofc = mock(OfOverlayContext.class);
+        // when(endpoint.getAugmentation(OfOverlayContext.class)).thenReturn(ofc);
+        // when(ofc.getLocationType()).thenReturn(null);
+        // assertFalse(manager.isExternal(endpoint));
+        // assertTrue(manager.isInternal(endpoint));
+        //
+        // when(ofc.getLocationType()).thenReturn(LocationType.Internal);
+        // assertFalse(manager.isExternal(endpoint));
+        // assertTrue(manager.isInternal(endpoint));
+        //
+        // when(ofc.getLocationType()).thenReturn(LocationType.External);
+        // assertTrue(manager.isExternal(endpoint));
+        // assertFalse(manager.isInternal(endpoint));
+    }
+
+    @Test
+    public void testGetL2EndpointFromL3() {
+        when(newL3Ep.getL2Context()).thenReturn(mock(L2BridgeDomainId.class));
+        when(newL3Ep.getMacAddress()).thenReturn(mock(MacAddress.class));
+
+        Endpoint ep = manager.getL2EndpointFromL3(newL3Ep);
+
+        assertNull(ep);
+    }
+
+    @Test
+    public void testGetL2EndpointFromL3_noL2Context_noMacAddr() {
+        when(newL3Ep.getL2Context()).thenReturn(null);
+        when(newL3Ep.getMacAddress()).thenReturn(null);
+
+        Endpoint ep = manager.getL2EndpointFromL3(newL3Ep);
+
+        assertNull(ep);
     }
+
 }
diff --git a/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/endpoint/OfOverlayAugTest.java b/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/endpoint/OfOverlayAugTest.java
new file mode 100644 (file)
index 0000000..ddd3700
--- /dev/null
@@ -0,0 +1,156 @@
+/*\r
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint;\r
+\r
+import static org.junit.Assert.assertNotNull;\r
+import static org.junit.Assert.assertNull;\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.when;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.concurrent.ExecutionException;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;\r
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
+import org.opendaylight.groupbasedpolicy.api.EpRendererAugmentationRegistry;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.test.TransactionMockUtils;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.Name;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInputBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterL3PrefixEndpointInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterL3PrefixEndpointInputBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Prefix;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContextInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContextInputBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodesBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;\r
+import org.opendaylight.yangtools.yang.binding.Augmentation;\r
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
+\r
+public class OfOverlayAugTest {\r
+\r
+    private static final String PORT_NAME = "portName";\r
+    private DataBroker dataProvider;\r
+    private EpRendererAugmentationRegistry epRendererAugmentationRegistry;\r
+    private OfOverlayAug ofOverlayAug;\r
+\r
+    @Before\r
+    public void init() {\r
+        dataProvider = mock(DataBroker.class);\r
+        epRendererAugmentationRegistry = mock(EpRendererAugmentationRegistry.class);\r
+        ofOverlayAug = new OfOverlayAug(dataProvider, epRendererAugmentationRegistry);\r
+    }\r
+\r
+    @Test\r
+    public void testConstructor() throws Exception {\r
+        OfOverlayAug other = new OfOverlayAug(dataProvider, epRendererAugmentationRegistry);\r
+        other.close();\r
+    }\r
+\r
+    @SuppressWarnings("unchecked")\r
+    @Test\r
+    public void testBuildEndpointAugmentation() throws ExecutionException, InterruptedException {\r
+        Nodes nodes = buildNodes();\r
+\r
+        ReadOnlyTransaction roTx = mock(ReadOnlyTransaction.class);\r
+        TransactionMockUtils.setupRoTx(roTx, LogicalDatastoreType.OPERATIONAL,\r
+                InstanceIdentifier.builder(Nodes.class).build(), true, nodes);\r
+        when(dataProvider.newReadOnlyTransaction()).thenReturn(roTx);\r
+\r
+        OfOverlayContextInput contextInput =\r
+                new OfOverlayContextInputBuilder().setPortName(new Name(PORT_NAME)).build();\r
+\r
+        RegisterEndpointInput input =\r
+                new RegisterEndpointInputBuilder().addAugmentation(OfOverlayContextInput.class, contextInput).build();\r
+\r
+        Map.Entry<Class<? extends Augmentation<Endpoint>>, Augmentation<Endpoint>> entry =\r
+                ofOverlayAug.buildEndpointAugmentation(input);\r
+\r
+        assertNotNull(entry);\r
+        assertNotNull(entry.getValue());\r
+    }\r
+\r
+    @Test\r
+    public void testBuildEndpointAugmentation_null() {\r
+        RegisterEndpointInput input = new RegisterEndpointInputBuilder().build();\r
+\r
+        Map.Entry<Class<? extends Augmentation<Endpoint>>, Augmentation<Endpoint>> entry =\r
+                ofOverlayAug.buildEndpointAugmentation(input);\r
+\r
+        assertNull(entry);\r
+    }\r
+\r
+    @SuppressWarnings("unchecked")\r
+    @Test\r
+    public void testBuildEndpointL3Augmentation() throws ExecutionException, InterruptedException {\r
+        Nodes nodes = buildNodes();\r
+\r
+        ReadOnlyTransaction roTx = mock(ReadOnlyTransaction.class);\r
+        TransactionMockUtils.setupRoTx(roTx, LogicalDatastoreType.OPERATIONAL,\r
+                InstanceIdentifier.builder(Nodes.class).build(), true, nodes);\r
+        when(dataProvider.newReadOnlyTransaction()).thenReturn(roTx);\r
+\r
+        OfOverlayContextInput contextInput =\r
+                new OfOverlayContextInputBuilder().setPortName(new Name(PORT_NAME)).build();\r
+\r
+        RegisterEndpointInput input =\r
+                new RegisterEndpointInputBuilder().addAugmentation(OfOverlayContextInput.class, contextInput).build();\r
+\r
+        Map.Entry<Class<? extends Augmentation<EndpointL3>>, Augmentation<EndpointL3>> entry =\r
+                ofOverlayAug.buildEndpointL3Augmentation(input);\r
+\r
+        assertNotNull(entry);\r
+        assertNotNull(entry.getValue());\r
+    }\r
+\r
+    @Test\r
+    public void testBuildEndpointL3Augmentation_null() {\r
+        RegisterEndpointInput input = new RegisterEndpointInputBuilder().build();\r
+\r
+        Map.Entry<Class<? extends Augmentation<EndpointL3>>, Augmentation<EndpointL3>> entry =\r
+                ofOverlayAug.buildEndpointL3Augmentation(input);\r
+\r
+        assertNull(entry);\r
+    }\r
+\r
+    @Test\r
+    public void testBuildL3PrefixEndpointAugmentation() {\r
+        RegisterL3PrefixEndpointInput input = new RegisterL3PrefixEndpointInputBuilder().build();\r
+        Map.Entry<Class<? extends Augmentation<EndpointL3Prefix>>, Augmentation<EndpointL3Prefix>> entry =\r
+                ofOverlayAug.buildL3PrefixEndpointAugmentation(input);\r
+\r
+        // always returns null\r
+        assertNull(entry);\r
+    }\r
+\r
+    private Nodes buildNodes() {\r
+        FlowCapableNodeConnector fcnc = new FlowCapableNodeConnectorBuilder().setName(PORT_NAME).build();\r
+        NodeConnector nc = new NodeConnectorBuilder().addAugmentation(FlowCapableNodeConnector.class, fcnc).build();\r
+        List<NodeConnector> nodeConnectorList = new ArrayList<>();\r
+        nodeConnectorList.add(nc);\r
+        Node node = new NodeBuilder().setNodeConnector(nodeConnectorList).build();\r
+        List<Node> nodeList = new ArrayList<>();\r
+        nodeList.add(node);\r
+        return new NodesBuilder().setNode(nodeList).build();\r
+    }\r
+\r
+}\r
diff --git a/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/endpoint/OfOverlayContextListenerTest.java b/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/endpoint/OfOverlayContextListenerTest.java
new file mode 100644 (file)
index 0000000..3e76591
--- /dev/null
@@ -0,0 +1,204 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Set;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.CheckedFuture;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.Name;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.Endpoints;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContextBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class OfOverlayContextListenerTest {
+
+    private static final Name OLD_PORT_NAME = new Name("oldPort");
+    private static final Name NEW_PORT_NAME = new Name("newPort");
+    private OfOverlayContextListener listener;
+    private DataObjectModification<OfOverlayContext> rootNode;
+    private Set<DataTreeModification<OfOverlayContext>> changes;
+
+    private DataBroker dataProvider;
+    private SwitchManager switchManager;
+
+    private InstanceIdentifier<OfOverlayContext> rootIdentifier;
+    private OfOverlayContext oldContext;
+    private OfOverlayContext newContext;
+    private OfOverlayContext contextNoPortName;
+
+    @SuppressWarnings("unchecked")
+    @Before
+    public void init() {
+
+        dataProvider = mock(DataBroker.class);
+        switchManager = mock(SwitchManager.class);
+
+        NodeKey nodeKey = new NodeKey(new NodeId("nodeId"));
+        NodeConnectorKey nodeConnectorKey = new NodeConnectorKey(new NodeConnectorId("ncId"));
+        InstanceIdentifier<NodeConnector> ncIid = InstanceIdentifier.builder(Nodes.class)
+            .child(Node.class, nodeKey)
+            .child(NodeConnector.class, nodeConnectorKey)
+            .build();
+        when(switchManager.getNodeConnectorIidForPortName(NEW_PORT_NAME)).thenReturn(ncIid);
+
+        listener = spy(new OfOverlayContextListener(dataProvider, switchManager));
+        EndpointKey epKey = mock(EndpointKey.class);
+
+        rootNode = mock(DataObjectModification.class);
+        rootIdentifier = InstanceIdentifier.builder(Endpoints.class)
+            .child(Endpoint.class, epKey)
+            .augmentation(OfOverlayContext.class)
+            .build();
+        DataTreeIdentifier<OfOverlayContext> rootPath =
+                new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, rootIdentifier);
+
+        DataTreeModification<OfOverlayContext> change = mock(DataTreeModification.class);
+
+        when(change.getRootNode()).thenReturn(rootNode);
+        when(change.getRootPath()).thenReturn(rootPath);
+
+        changes = ImmutableSet.of(change);
+
+        oldContext = new OfOverlayContextBuilder().setPortName(OLD_PORT_NAME).build();
+        newContext = new OfOverlayContextBuilder().setPortName(NEW_PORT_NAME).build();
+        contextNoPortName = new OfOverlayContextBuilder().build();
+    }
+
+    @Test
+    public void testOnDataTreeChanged_Write() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);
+        when(rootNode.getDataAfter()).thenReturn(newContext);
+
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(wt).merge(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),
+                any(OfOverlayContext.class));
+    }
+
+    @Test
+    public void testOnDataTreeChanged_SubtreeModified() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+        when(rootNode.getDataBefore()).thenReturn(oldContext);
+        when(rootNode.getDataAfter()).thenReturn(newContext);
+
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(wt).merge(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),
+                any(OfOverlayContext.class));
+    }
+
+    @Test
+    public void testOnDataTreeChanged_SubtreeModified_bothNoPortName() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+        when(rootNode.getDataBefore()).thenReturn(contextNoPortName);
+        when(rootNode.getDataAfter()).thenReturn(contextNoPortName);
+
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(wt, never()).merge(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),
+                any(OfOverlayContext.class));
+    }
+
+    @Test
+    public void testOnDataTreeChanged_SubtreeModified_oneNoPortName() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+        when(rootNode.getDataBefore()).thenReturn(oldContext);
+        when(rootNode.getDataAfter()).thenReturn(contextNoPortName);
+
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(wt, never()).merge(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),
+                any(OfOverlayContext.class));
+    }
+
+    @Test
+    public void testOnDataTreeChanged_SubtreeModified_oneNoPortName1() {
+        when(switchManager.getNodeConnectorIidForPortName(NEW_PORT_NAME)).thenReturn(null);
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+        when(rootNode.getDataBefore()).thenReturn(oldContext);
+        when(rootNode.getDataAfter()).thenReturn(newContext);
+
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(wt, never()).merge(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),
+                any(OfOverlayContext.class));
+    }
+
+    @Test
+    public void testOnDataTreeChanged_SubtreeModified_samePortName() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+        when(rootNode.getDataBefore()).thenReturn(newContext);
+        when(rootNode.getDataAfter()).thenReturn(newContext);
+
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(wt, never()).merge(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),
+                any(OfOverlayContext.class));
+    }
+
+    @Test
+    public void testOnDataTreeChanged_Delete() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);
+
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        // no op
+    }
+
+    private WriteTransaction resetTransaction() {
+        WriteTransaction wt = mock(WriteTransaction.class);
+        CheckedFuture checkedFuture = mock(CheckedFuture.class);
+        when(wt.submit()).thenReturn(checkedFuture);
+        when(dataProvider.newWriteOnlyTransaction()).thenReturn(wt);
+        return wt;
+    }
+
+}
diff --git a/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/endpoint/OfOverlayL3ContextListenerTest.java b/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/endpoint/OfOverlayL3ContextListenerTest.java
new file mode 100644 (file)
index 0000000..78e646a
--- /dev/null
@@ -0,0 +1,205 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Set;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.CheckedFuture;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.Name;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.Endpoints;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Key;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayL3Context;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayL3ContextBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class OfOverlayL3ContextListenerTest {
+
+    private static final Name OLD_PORT_NAME = new Name("oldPort");
+    private static final Name NEW_PORT_NAME = new Name("newPort");
+    private OfOverlayL3ContextListener listener;
+    private DataObjectModification<OfOverlayL3Context> rootNode;
+    private Set<DataTreeModification<OfOverlayL3Context>> changes;
+
+    private DataBroker dataProvider;
+    private SwitchManager switchManager;
+
+    private InstanceIdentifier<OfOverlayL3Context> rootIdentifier;
+    private OfOverlayL3Context oldContext;
+    private OfOverlayL3Context newContext;
+    private OfOverlayL3Context contextNoPortName;
+
+    @SuppressWarnings("unchecked")
+    @Before
+    public void init() {
+
+        dataProvider = mock(DataBroker.class);
+        switchManager = mock(SwitchManager.class);
+
+        NodeKey nodeKey = new NodeKey(new NodeId("nodeId"));
+        NodeConnectorKey nodeConnectorKey = new NodeConnectorKey(new NodeConnectorId("ncId"));
+        InstanceIdentifier<NodeConnector> ncIid = InstanceIdentifier.builder(Nodes.class)
+            .child(Node.class, nodeKey)
+            .child(NodeConnector.class, nodeConnectorKey)
+            .build();
+        when(switchManager.getNodeConnectorIidForPortName(NEW_PORT_NAME)).thenReturn(ncIid);
+
+        listener = spy(new OfOverlayL3ContextListener(dataProvider, switchManager));
+        EndpointL3Key epL3Key = mock(EndpointL3Key.class);
+
+        rootNode = mock(DataObjectModification.class);
+        rootIdentifier = InstanceIdentifier.builder(Endpoints.class)
+            .child(EndpointL3.class, epL3Key)
+            .augmentation(OfOverlayL3Context.class)
+            .build();
+        DataTreeIdentifier<OfOverlayL3Context> rootPath =
+                new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, rootIdentifier);
+
+        DataTreeModification<OfOverlayL3Context> change = mock(DataTreeModification.class);
+
+        when(change.getRootNode()).thenReturn(rootNode);
+        when(change.getRootPath()).thenReturn(rootPath);
+
+        changes = ImmutableSet.of(change);
+
+        oldContext = new OfOverlayL3ContextBuilder().setPortName(OLD_PORT_NAME).build();
+        newContext = new OfOverlayL3ContextBuilder().setPortName(NEW_PORT_NAME).build();
+        contextNoPortName = new OfOverlayL3ContextBuilder().build();
+    }
+
+    @Test
+    public void testOnDataTreeChanged_Write() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);
+        when(rootNode.getDataAfter()).thenReturn(newContext);
+
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(wt).merge(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),
+                any(OfOverlayContext.class));
+    }
+
+    @Test
+    public void testOnDataTreeChanged_SubtreeModified() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+        when(rootNode.getDataBefore()).thenReturn(oldContext);
+        when(rootNode.getDataAfter()).thenReturn(newContext);
+
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(wt).merge(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),
+                any(OfOverlayContext.class));
+    }
+
+    @Test
+    public void testOnDataTreeChanged_SubtreeModified_bothNoPortName() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+        when(rootNode.getDataBefore()).thenReturn(contextNoPortName);
+        when(rootNode.getDataAfter()).thenReturn(contextNoPortName);
+
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(wt, never()).merge(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),
+                any(OfOverlayContext.class));
+    }
+
+    @Test
+    public void testOnDataTreeChanged_SubtreeModified_oneNoPortName() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+        when(rootNode.getDataBefore()).thenReturn(oldContext);
+        when(rootNode.getDataAfter()).thenReturn(contextNoPortName);
+
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(wt, never()).merge(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),
+                any(OfOverlayContext.class));
+    }
+
+    @Test
+    public void testOnDataTreeChanged_SubtreeModified_oneNoPortName1() {
+        when(switchManager.getNodeConnectorIidForPortName(NEW_PORT_NAME)).thenReturn(null);
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+        when(rootNode.getDataBefore()).thenReturn(oldContext);
+        when(rootNode.getDataAfter()).thenReturn(newContext);
+
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(wt, never()).merge(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),
+                any(OfOverlayContext.class));
+    }
+
+    @Test
+    public void testOnDataTreeChanged_SubtreeModified_samePortName() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+        when(rootNode.getDataBefore()).thenReturn(newContext);
+        when(rootNode.getDataAfter()).thenReturn(newContext);
+
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(wt, never()).merge(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),
+                any(OfOverlayContext.class));
+    }
+
+    @Test
+    public void testOnDataTreeChanged_Delete() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);
+
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        // no op
+    }
+
+    private WriteTransaction resetTransaction() {
+        WriteTransaction wt = mock(WriteTransaction.class);
+        CheckedFuture checkedFuture = mock(CheckedFuture.class);
+        when(wt.submit()).thenReturn(checkedFuture);
+        when(dataProvider.newWriteOnlyTransaction()).thenReturn(wt);
+        return wt;
+    }
+
+}
diff --git a/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/endpoint/OfOverlayL3NatAugTest.java b/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/endpoint/OfOverlayL3NatAugTest.java
new file mode 100644 (file)
index 0000000..2d03a12
--- /dev/null
@@ -0,0 +1,80 @@
+/*\r
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint;\r
+\r
+import static org.junit.Assert.assertNotNull;\r
+import static org.junit.Assert.assertNull;\r
+import static org.mockito.Mockito.mock;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.opendaylight.groupbasedpolicy.api.EpRendererAugmentationRegistry;\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.Ipv4Address;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInputBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterL3PrefixEndpointInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterL3PrefixEndpointInputBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.l3endpoint.rev151217.NatAddressInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.l3endpoint.rev151217.NatAddressInputBuilder;\r
+\r
+public class OfOverlayL3NatAugTest {\r
+\r
+    private OfOverlayL3NatAug ofOverlayL3NatAug;\r
+    private EpRendererAugmentationRegistry epRendererAugmentationRegistry;\r
+\r
+    @Before\r
+    public void init() {\r
+        epRendererAugmentationRegistry = mock(EpRendererAugmentationRegistry.class);\r
+        ofOverlayL3NatAug = new OfOverlayL3NatAug(epRendererAugmentationRegistry);\r
+    }\r
+\r
+    @Test\r
+    public void testConstructor() throws Exception {\r
+        OfOverlayL3NatAug other = new OfOverlayL3NatAug(epRendererAugmentationRegistry);\r
+        other.close();\r
+    }\r
+\r
+    @Test\r
+    public void testBuildEndpointAugmentation() {\r
+        RegisterEndpointInput input = new RegisterEndpointInputBuilder().build();\r
+        // no op\r
+        assertNull(ofOverlayL3NatAug.buildEndpointAugmentation(input));\r
+    }\r
+\r
+    @Test\r
+    public void testBuildEndpointL3Augmentation() {\r
+        NatAddressInput natAddressInput = new NatAddressInputBuilder().setNatAddress(\r
+                new IpAddress(new Ipv4Address("10.0.0.2"))).build();\r
+        RegisterEndpointInput input =\r
+                new RegisterEndpointInputBuilder().addAugmentation(NatAddressInput.class,\r
+                        natAddressInput).build();\r
+        assertNotNull(ofOverlayL3NatAug.buildEndpointL3Augmentation(input));\r
+    }\r
+\r
+    @Test\r
+    public void testBuildEndpointL3Augmentation_noAug() {\r
+        RegisterEndpointInput input = new RegisterEndpointInputBuilder().build();\r
+        assertNull(ofOverlayL3NatAug.buildEndpointL3Augmentation(input));\r
+    }\r
+\r
+    @Test\r
+    public void testBuildL3PrefixEndpointAugmentation() {\r
+        RegisterL3PrefixEndpointInput input = new RegisterL3PrefixEndpointInputBuilder().build();\r
+        // no op\r
+\r
+        assertNull(ofOverlayL3NatAug.buildL3PrefixEndpointAugmentation(input));\r
+    }\r
+\r
+    @Test\r
+    public void testClose() {\r
+        //        fail("Not yet implemented");\r
+    }\r
+\r
+}\r
diff --git a/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/equivalence/BucketsEquivalenceTest.java b/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/equivalence/BucketsEquivalenceTest.java
new file mode 100644 (file)
index 0000000..d8b8a18
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.equivalence;
+
+import org.junit.Before;
+import org.junit.Test;
+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.BucketsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder;
+
+public class BucketsEquivalenceTest {
+    BucketsEquivalence eq;
+
+    @Before
+    public void init() {
+        eq = new BucketsEquivalence();
+    }
+
+    @Test
+    public void testDoEquivalent() {
+        Buckets a = new BucketsBuilder().build();
+        Buckets b = new BucketsBuilder().build();
+        eq.doEquivalent(a, b);
+    }
+
+    @Test
+    public void testDoHash() {
+        Buckets a = new BucketsBuilder().build();
+        eq.doHash(a);
+    }
+
+}
diff --git a/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/equivalence/GroupEquivalenceTest.java b/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/equivalence/GroupEquivalenceTest.java
new file mode 100644 (file)
index 0000000..62ea64b
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.equivalence;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder;
+
+public class GroupEquivalenceTest {
+
+    GroupEquivalence eq;
+
+    @Before
+    public void init() {
+        eq = new GroupEquivalence();
+    }
+
+    @Test
+    public void testDoEquivalent() {
+        Group a = new GroupBuilder().build();
+        Group b = new GroupBuilder().build();
+        eq.doEquivalent(a, b);
+    }
+
+    @Test
+    public void testDoHash() {
+
+        Group a = new GroupBuilder().build();
+        eq.doHash(a);
+    }
+
+}
diff --git a/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/JsonRestClientResponseTest.java b/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/JsonRestClientResponseTest.java
new file mode 100644 (file)
index 0000000..cbb15da
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.sun.jersey.api.client.ClientHandlerException;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.UniformInterfaceException;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JsonRestClientResponseTest {
+
+    private static final String STRING_ENTITY = "string entity";
+    private ClientResponse clientResponse;
+
+    @Before
+    public void init() {
+        clientResponse = mock(ClientResponse.class);
+
+    }
+
+    @Test
+    public void testResponse_Ok() {
+        when(clientResponse.getEntity(String.class)).thenReturn(STRING_ENTITY);
+        when(clientResponse.getStatus()).thenReturn(200);
+        JsonRestClientResponse response = new JsonRestClientResponse(clientResponse);
+
+        assertSame(clientResponse, response.getClientResponse());
+        assertEquals(STRING_ENTITY, response.getJsonResponse());
+        assertEquals(200, response.getStatusCode());
+        assertNull(response.getClientHandlerException());
+    }
+
+    @Test
+    public void testResponse_UniformInterfaceException() {
+        UniformInterfaceException ex = new UniformInterfaceException(clientResponse);
+        when(clientResponse.getEntity(String.class)).thenThrow(ex);
+        when(clientResponse.getStatus()).thenReturn(204);
+
+        JsonRestClientResponse response = new JsonRestClientResponse(clientResponse);
+
+        assertNull(response.getJsonResponse());
+        assertEquals(204, response.getStatusCode());
+        assertNull(response.getClientHandlerException());
+    }
+
+    @Test
+    public void testResponse_ClientHandlerException() {
+        ClientHandlerException ex = new ClientHandlerException();
+        when(clientResponse.getEntity(String.class)).thenThrow(ex);
+        when(clientResponse.getStatus()).thenReturn(404);
+
+        JsonRestClientResponse response = new JsonRestClientResponse(clientResponse);
+
+        assertNull(response.getJsonResponse());
+        assertEquals(404, response.getStatusCode());
+        assertSame(ex, response.getClientHandlerException());
+    }
+}
diff --git a/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/JsonRestClientTest.java b/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/JsonRestClientTest.java
new file mode 100644 (file)
index 0000000..2c83548
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics;
+
+import static org.junit.Assert.assertEquals;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+
+import com.google.common.collect.ImmutableList;
+import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory;
+import com.sun.jersey.api.core.ClassNamesResourceConfig;
+import com.sun.jersey.api.core.ResourceConfig;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+import com.sun.jersey.test.framework.AppDescriptor;
+import com.sun.jersey.test.framework.JerseyTest;
+import com.sun.jersey.test.framework.WebAppDescriptor;
+import org.glassfish.grizzly.http.server.HttpServer;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.util.SFlowQueryParams;
+
+public class JsonRestClientTest extends JerseyTest {
+
+    private static final int CONNECT_TIMEOUT_MILLISEC = 20000;
+    private static final int READ_TIMEOUT_MILLISEC = 30000;
+    private static final String SFLOW_HOST = "localhost";
+    private static final int SFLOW_PORT = 1234;
+    private static HttpServer server;
+    private static final String SFLOW_URI = "http://" + SFLOW_HOST + ":" + SFLOW_PORT;
+
+    private JsonRestClient client;
+    private String uri;
+    private static String responseJson =
+            " { \"resolved-policy-uri\" : \"/restconf/operational/resolved-policy:resolved-policies/resolved-policy/tenant-red/client/tenant-red/webserver/\" } ";
+
+    private static HttpServer startServer() throws IOException {
+        final ResourceConfig resourceConfig = new ClassNamesResourceConfig(dumbServer.class);
+        HttpServer httpServer;
+        httpServer = GrizzlyServerFactory.createHttpServer(java.net.URI.create(SFLOW_URI), resourceConfig);
+        return httpServer;
+    }
+
+    @BeforeClass
+    public static void setUpClass() throws IOException {
+        server = startServer();
+    }
+
+    @AfterClass
+    public static void tearDownClass() {
+        if (server != null && server.isStarted())
+            server.stop();
+    }
+
+    @Before
+    public void init() {
+        client = new JsonRestClient(SFLOW_URI, CONNECT_TIMEOUT_MILLISEC, READ_TIMEOUT_MILLISEC);
+    }
+
+    @Test
+    public void testGetHost() {
+        String host = client.getHost();
+
+        assertEquals(SFLOW_HOST, host);
+    }
+
+    @Test
+    public void testGet_coverageOnly() {
+        client.get("/");
+    }
+
+    @Test
+    public void testGet_params_coverageOnly() {
+        MultivaluedMap<String, String> params = new MultivaluedMapImpl();
+        params.add(SFlowQueryParams.MAX_FLOWS, "20");
+        params.add(SFlowQueryParams.MIN_VALUE, "0.1");
+        params.add(SFlowQueryParams.AGG_MODE, "sum");
+
+        client.get("/", params);
+    }
+
+    @Test
+    public void testPost_coverageOnly() {
+        client.post("/", "json");
+    }
+
+    @Test
+    public void testPut_coverageOnly() {
+        client.put("/", "json");
+    }
+
+    @Test
+    public void testDelete_coverageOnly() {
+        client.delete("/");
+    }
+
+    @Override
+    protected AppDescriptor configure() {
+        return new WebAppDescriptor.Builder().build();
+    }
+
+    @Path("/")
+    public static class dumbServer {
+
+        @GET
+        @Produces(MediaType.APPLICATION_JSON)
+        public Response get200() {
+            return Response.status(Response.Status.OK).entity(responseJson).build();
+        }
+
+        @POST
+        @Consumes(MediaType.APPLICATION_JSON)
+        public Response post200(String json) {
+            return Response.status(Response.Status.OK).build();
+        }
+
+    }
+}
index de1f7c2b7a0b745a96bbf2bc4aef96fe0a7d16f0..f819633e312da8fca3c2432d9872542d81f404b2 100755 (executable)
@@ -1,27 +1,85 @@
+/*\r
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics;\r
 \r
 import static org.mockito.Mockito.mock;\r
 \r
+import java.util.Map;\r
 import java.util.concurrent.ScheduledExecutorService;\r
 \r
 import org.junit.Before;\r
 import org.junit.Test;\r
 import org.opendaylight.groupbasedpolicy.api.StatisticsManager;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.test.TestUtils;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierName;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContractId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.RuleName;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubjectName;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.has.classifiers.Classifier;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.has.classifiers.ClassifierBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.resolved.policies.ResolvedPolicy;\r
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
 \r
 public class OFStatisticsManagerTest {\r
 \r
-    ScheduledExecutorService executor;\r
-    StatisticsManager statisticsManager;\r
+    private final EndpointGroupId consumerEpgId = new EndpointGroupId("consumerEpg1");\r
+    private final EndpointGroupId providerEpgId = new EndpointGroupId("providerEpg1");\r
+    private final ContractId contractId = new ContractId("contract1");\r
+    private final TenantId tenantId = new TenantId("tenant1");\r
+    private final ClassifierName classifierName = ClassifierName.getDefaultInstance("classifier1");\r
+    private final SubjectName subjectName = SubjectName.getDefaultInstance("subject1");\r
+    private final RuleName ruleName = new RuleName("rule1");\r
+\r
+    private InstanceIdentifier<ResolvedPolicy> rpIid;\r
+    private ResolvedPolicy resolvedPolicy;\r
+\r
+    private ScheduledExecutorService executor;\r
+    private StatisticsManager statisticsManager;\r
+\r
+    private OFStatisticsManager ofStatisticsManager;\r
+    private Classifier classifier;\r
+    private Map<InstanceIdentifier<Classifier>, Classifier> classifierByIid;\r
 \r
     @Before\r
     public void init() {\r
         executor = mock(ScheduledExecutorService.class);\r
         statisticsManager = mock(StatisticsManager.class);\r
+\r
+        classifier = new ClassifierBuilder()\r
+                .setName(classifierName)\r
+                .build();\r
+        resolvedPolicy = TestUtils.newResolvedPolicy(tenantId, contractId, subjectName, ruleName,\r
+                consumerEpgId, providerEpgId, classifier);\r
+\r
+        rpIid = InstanceIdentifier.create(ResolvedPolicy.class);\r
+\r
+        ofStatisticsManager = new OFStatisticsManager(executor, statisticsManager);\r
+        ofStatisticsManager.setDelay(20L);\r
+        ofStatisticsManager.setSflowCollectorUri("http://localhost:1234");\r
+\r
+        classifierByIid =\r
+                ResolvedPolicyClassifierListener.resolveClassifiers(resolvedPolicy, rpIid);\r
     }\r
 \r
     @Test\r
     public void testConstructor() throws Exception {\r
-        new OFStatisticsManager(executor, statisticsManager);\r
+        OFStatisticsManager other = new OFStatisticsManager(executor, statisticsManager);\r
+        other.close();\r
     }\r
 \r
+    @Test\r
+    public void testTTT(){\r
+        for (Map.Entry<InstanceIdentifier<Classifier>, Classifier> classifierEntry : classifierByIid.entrySet()) {\r
+            ofStatisticsManager.pullStatsForClassifier(classifierEntry.getKey(),\r
+                    classifierEntry.getValue());\r
+        }\r
+    }\r
 }\r
diff --git a/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/ProcessDataTaskTest.java b/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/ProcessDataTaskTest.java
new file mode 100644 (file)
index 0000000..4c82d62
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.lang3.tuple.Pair;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.opendaylight.groupbasedpolicy.api.StatisticsManager;
+import org.opendaylight.groupbasedpolicy.dto.ConsEpgKey;
+import org.opendaylight.groupbasedpolicy.dto.EpgKeyDto;
+import org.opendaylight.groupbasedpolicy.dto.ProvEpgKey;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.flowcache.FlowCache;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.flowcache.FlowCacheData;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.util.FlowCacheCons;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.util.IidSflowNameUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContractId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.HasDirection;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroup;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroupBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.statistics.rev151215.statistic.records.StatRecords;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({OFStatisticsManager.class, IidSflowNameUtil.class, OFStatisticsManager.class})
+public class ProcessDataTaskTest {
+
+    private final String IP_PROTO = "6";
+    private final String SRC_IP = "192.168.35.2";
+    private final String DST_IP = "192.168.36.2";
+    private final TenantId tenantId = new TenantId("tenantId");
+    private final EndpointGroupId srcEpgId = new EndpointGroupId("srcEpgId");
+    private final EndpointGroupId dstEpgId = new EndpointGroupId("dstEpgId");
+    private final ContractId contractId = new ContractId("contractId");
+    private final ClassifierName classifierName = new ClassifierName("classifierName");
+
+    private FlowCache flowCache;
+    private FlowCacheData data;
+    private ProcessDataTask task;
+
+    private EndpointL3 srcEpL3;
+    private EndpointL3 dstEpL3;
+    private EndpointGroup srcEpg;
+    private EndpointGroup dstEpg;
+
+    @Before
+    public void init() {
+        PowerMockito.mockStatic(OFStatisticsManager.class);
+        PowerMockito.mockStatic(IidSflowNameUtil.class);
+        PowerMockito.mockStatic(OFStatisticsManager.class);
+
+        String[] keyNames = {FlowCacheCons.Key.IP_PROTOCOL.get(), FlowCacheCons.Key.IP_SOURCE.get(),
+                FlowCacheCons.Key.IP_DESTINATION.get()};
+        flowCache = mock(FlowCache.class);
+        when(flowCache.getKeyNum()).thenReturn(3);
+        when(flowCache.getKeyNames()).thenReturn(keyNames);
+        when(flowCache.getName()).thenReturn("flowcache1");
+        when(flowCache.getDirection()).thenReturn(HasDirection.Direction.Out);
+        data = mock(FlowCacheData.class);
+        when(data.getKey()).thenReturn(IP_PROTO + "," + SRC_IP + "," + DST_IP);
+        List<FlowCacheData> dataList = new ArrayList<>();
+        dataList.add(data);
+        BigInteger timestamp = BigInteger.ZERO;
+        StatisticsManager statisticsManager = mock(StatisticsManager.class);
+        when(statisticsManager.writeStat(any(StatRecords.class))).thenReturn(true);
+
+        task = new ProcessDataTask(flowCache, dataList, timestamp, statisticsManager);
+
+        srcEpg = new EndpointGroupBuilder().setId(srcEpgId).build();
+        dstEpg = new EndpointGroupBuilder().setId(dstEpgId).build();
+        srcEpL3 = new EndpointL3Builder().setTenant(tenantId).setEndpointGroup(srcEpg.getId()).build();
+        dstEpL3 = new EndpointL3Builder().setTenant(tenantId).setEndpointGroup(dstEpg.getId()).build();
+        ConsEpgKey consEpgKey = new EpgKeyDto(srcEpg.getId(), tenantId);
+        ProvEpgKey provEpgKey = new EpgKeyDto(dstEpg.getId(), tenantId);
+        Pair<ConsEpgKey, ProvEpgKey> pair = Pair.of(consEpgKey, provEpgKey);
+        Set<Pair<ConsEpgKey, ProvEpgKey>> epgsForContract = new HashSet<>();
+        epgsForContract.add(pair);
+
+        when(OFStatisticsManager.getEpgsForContract(contractId)).thenReturn(epgsForContract);
+    }
+
+    @Test
+    public void testRun() {
+        when(OFStatisticsManager.getEndpointL3ForIp(SRC_IP)).thenReturn(srcEpL3);
+        when(OFStatisticsManager.getEndpointL3ForIp(DST_IP)).thenReturn(dstEpL3);
+        when(IidSflowNameUtil.resolveContractIdFromFlowCacheName(flowCache.getName())).thenReturn(contractId);
+        when(IidSflowNameUtil.resolveClassifierNameFromFlowCacheName(flowCache.getName())).thenReturn(classifierName);
+        when(IidSflowNameUtil.resolveFlowCacheValue(flowCache.getName())).thenReturn(FlowCacheCons.Value.BYTES.get());
+
+        task.run();
+    }
+
+    @Test
+    public void testRun_reversedConsProv() {
+        when(OFStatisticsManager.getEndpointL3ForIp(SRC_IP)).thenReturn(srcEpL3);
+        when(OFStatisticsManager.getEndpointL3ForIp(DST_IP)).thenReturn(dstEpL3);
+        when(IidSflowNameUtil.resolveContractIdFromFlowCacheName(flowCache.getName())).thenReturn(contractId);
+        when(IidSflowNameUtil.resolveClassifierNameFromFlowCacheName(flowCache.getName())).thenReturn(classifierName);
+        when(IidSflowNameUtil.resolveFlowCacheValue(flowCache.getName())).thenReturn(FlowCacheCons.Value.FRAMES.get());
+
+        ConsEpgKey consEpgKey = new EpgKeyDto(dstEpg.getId(), tenantId);
+        ProvEpgKey provEpgKey = new EpgKeyDto(srcEpg.getId(), tenantId);
+        Pair<ConsEpgKey, ProvEpgKey> pair = Pair.of(consEpgKey, provEpgKey);
+        Set<Pair<ConsEpgKey, ProvEpgKey>> epgsForContract = new HashSet<>();
+        epgsForContract.add(pair);
+        when(OFStatisticsManager.getEpgsForContract(contractId)).thenReturn(epgsForContract);
+
+        task.run();
+    }
+
+    @Test
+    public void testRun_noConsProv() {
+        when(OFStatisticsManager.getEndpointL3ForIp(SRC_IP)).thenReturn(srcEpL3);
+        when(OFStatisticsManager.getEndpointL3ForIp(DST_IP)).thenReturn(dstEpL3);
+        when(IidSflowNameUtil.resolveContractIdFromFlowCacheName(flowCache.getName())).thenReturn(contractId);
+        when(IidSflowNameUtil.resolveClassifierNameFromFlowCacheName(flowCache.getName())).thenReturn(classifierName);
+        when(IidSflowNameUtil.resolveFlowCacheValue(flowCache.getName())).thenReturn(FlowCacheCons.Value.FRAMES.get());
+
+        Set<Pair<ConsEpgKey, ProvEpgKey>> epgsForContract = new HashSet<>();
+        when(OFStatisticsManager.getEpgsForContract(contractId)).thenReturn(epgsForContract);
+
+        task.run();
+    }
+
+    @Test
+    public void testRun_wrongDataResponse() {
+        when(data.getKey()).thenReturn("1,2");
+        task.run();
+    }
+
+}
index 41bba898d86541aa788dce5b2516774ba7cb510b..873b73dc89840d2032b0a17da941dfdee5f2da51 100755 (executable)
@@ -1,8 +1,14 @@
+/*\r
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics;\r
 \r
 import static org.mockito.Matchers.any;\r
-import static org.mockito.Matchers.anyMap;\r
-import static org.mockito.Matchers.anySet;\r
 import static org.mockito.Matchers.anyString;\r
 import static org.mockito.Mockito.doNothing;\r
 import static org.mockito.Mockito.mock;\r
@@ -10,26 +16,30 @@ import static org.mockito.Mockito.when;
 \r
 import javax.ws.rs.core.MultivaluedMap;\r
 \r
-import java.util.concurrent.ExecutorService;\r
 import java.util.concurrent.ScheduledExecutorService;\r
 \r
+import com.sun.jersey.api.client.ClientResponse;\r
 import org.junit.Before;\r
 import org.junit.Test;\r
+import org.mockito.Mockito;\r
 import org.opendaylight.groupbasedpolicy.api.StatisticsManager;\r
 \r
 public class ReadGbpFlowCacheTaskTest {\r
 \r
     ReadGbpFlowCacheTask task;\r
+    private JsonRestClientResponse response;\r
 \r
     @Before\r
     public void init() {\r
         StatisticsManager statisticsManager = mock(StatisticsManager.class);\r
         ScheduledExecutorService executor = mock(ScheduledExecutorService.class);\r
-        JsonRestClientResponse response = mock(JsonRestClientResponse.class);\r
+        ClientResponse clientResponse = mock(ClientResponse.class);\r
+        response = mock(JsonRestClientResponse.class);\r
         when(response.getJsonResponse()).thenReturn("[{\"one\":1, \"two\":2, \"three\":3}]");\r
         when(response.getStatusCode()).thenReturn(200);\r
+        when(response.getClientResponse()).thenReturn(clientResponse);\r
         SFlowRTConnection connection = mock(SFlowRTConnection.class);\r
-        when(connection.get(anyString(), any(MultivaluedMap.class))).thenReturn(response);\r
+        when(connection.get(anyString(), Mockito.<MultivaluedMap<String, String>>any())).thenReturn(response);\r
         when(connection.getExecutor()).thenReturn(executor);\r
         doNothing().when(executor).execute(any(Runnable.class));\r
 \r
@@ -38,7 +48,18 @@ public class ReadGbpFlowCacheTaskTest {
 \r
     @Test\r
     public void testRun() {\r
+        task.run();\r
+    }\r
+\r
+    @Test\r
+    public void testRun_response300() {\r
+        when(response.getStatusCode()).thenReturn(300);\r
+        task.run();\r
+    }\r
 \r
+    @Test\r
+    public void testRun_response400() {\r
+        when(response.getStatusCode()).thenReturn(400);\r
         task.run();\r
     }\r
 \r
index 14baad9ea04099445cfc82ec441b35a9da6b3b4e..430eb59d2a72672e2e333774ebb2351b6eac3d2a 100755 (executable)
@@ -1,3 +1,11 @@
+/*\r
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics;\r
 \r
 import static org.mockito.Mockito.mock;\r
diff --git a/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/SFlowRTConnectionTest.java b/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/SFlowRTConnectionTest.java
new file mode 100644 (file)
index 0000000..ad3ca90
--- /dev/null
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+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.when;
+
+import javax.ws.rs.core.MultivaluedMap;
+import java.util.concurrent.ScheduledExecutorService;
+
+import com.sun.jersey.api.client.ClientHandlerException;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.Mockito;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.flowcache.FlowCache;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.util.SFlowQueryParams;
+
+public class SFlowRTConnectionTest {
+
+    private static final String PATH = "/";
+    private static final String JSON_STRING = "jsonString";
+    private static final String JSON_RESPONSE = "jsonResponse";
+
+    private ScheduledExecutorService executor;
+    private String collectorUri;
+    private FlowCache flowCache;
+    private JsonRestClient client;
+    private MultivaluedMap<String, String> params;
+    private SFlowRTConnection connection;
+    private JsonRestClientResponse response;
+
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
+
+    @Before
+    public void init() {
+        params = new MultivaluedMapImpl();
+        params.add(SFlowQueryParams.MAX_FLOWS, "20");
+        params.add(SFlowQueryParams.MIN_VALUE, "0.1");
+        params.add(SFlowQueryParams.AGG_MODE, "sum");
+
+        executor = mock(ScheduledExecutorService.class);
+        collectorUri = "";
+        flowCache = mock(FlowCache.class);
+        client = mock(JsonRestClient.class);
+        response = mock(JsonRestClientResponse.class);
+        when(response.getJsonResponse()).thenReturn(JSON_RESPONSE);
+        when(response.getStatusCode()).thenReturn(200);
+        when(client.get(any(String.class), Mockito.<MultivaluedMap<String, String>>any())).thenReturn(response);
+        when(client.put(any(String.class), any(String.class))).thenReturn(response);
+        when(client.delete(any(String.class))).thenReturn(response);
+
+        connection = spy(new SFlowRTConnection(executor, collectorUri, flowCache, client));
+    }
+
+    @Test
+    public void testConstructor() {
+        SFlowRTConnection other = new SFlowRTConnection(executor, collectorUri, flowCache, client);
+
+        assertNotNull(other.getExecutor());
+        assertNotNull(other.getFlowCache());
+    }
+
+    @Test
+    public void testGetJsonResponse() {
+        String res = connection.getJsonResponse(PATH, params);
+
+        assertEquals(JSON_RESPONSE, res);
+    }
+
+    @Test(expected = ClientHandlerException.class)
+    public void testGetJsonResponse_ClientHandlerException_noCause() {
+        ClientHandlerException ex = new ClientHandlerException();
+        when(client.get(any(String.class), Mockito.<MultivaluedMap<String, String>>any())).thenThrow(ex);
+
+        connection.getJsonResponse(PATH, params);
+    }
+
+    @Test(expected = ClientHandlerException.class)
+    public void testGetJsonResponse_ClientHandlerException_caused() {
+        ClientHandlerException ex = new ClientHandlerException();
+        ex.initCause(new java.net.ConnectException());
+        when(client.get(any(String.class), Mockito.<MultivaluedMap<String, String>>any())).thenThrow(ex);
+
+        connection.getJsonResponse(PATH, params);
+    }
+
+    @Test
+    public void testGet() {
+        JsonRestClientResponse res = connection.get(PATH, params);
+
+        assertEquals(response, res);
+    }
+
+    @Test
+    public void testGet_notInitialized() {
+        when(connection.isInitialized()).thenReturn(false);
+
+        thrown.expect(IllegalStateException.class);
+        thrown.expectMessage(SFlowRTConnection.EX_MSG_NOT_INITIALIZED);
+        connection.get(PATH, params);
+    }
+
+    @Test(expected = ClientHandlerException.class)
+    public void testGet_ClientHandlerException_noCause() {
+        ClientHandlerException ex = new ClientHandlerException();
+        when(client.get(any(String.class), Mockito.<MultivaluedMap<String, String>>any())).thenThrow(ex);
+
+        connection.get(PATH, params);
+    }
+
+    @Test(expected = ClientHandlerException.class)
+    public void testGet_ClientHandlerException_caused() {
+        ClientHandlerException ex = new ClientHandlerException();
+        ex.initCause(new java.net.ConnectException());
+        when(client.get(any(String.class), Mockito.<MultivaluedMap<String, String>>any())).thenThrow(ex);
+
+        connection.get(PATH, params);
+    }
+
+    @Test
+    public void testPut() {
+        JsonRestClientResponse res = connection.put(PATH, JSON_STRING);
+
+        assertEquals(response, res);
+    }
+
+    @Test
+    public void testPut_notInitialized() {
+        when(connection.isInitialized()).thenReturn(false);
+
+        thrown.expect(IllegalStateException.class);
+        thrown.expectMessage(SFlowRTConnection.EX_MSG_NOT_INITIALIZED);
+        connection.put(PATH, JSON_STRING);
+    }
+
+    @Test(expected = ClientHandlerException.class)
+    public void testPut_ClientHandlerException_noCause() {
+        ClientHandlerException ex = new ClientHandlerException();
+        when(client.put(any(String.class), any(String.class))).thenThrow(ex);
+
+        connection.put(PATH, JSON_STRING);
+    }
+
+    @Test(expected = ClientHandlerException.class)
+    public void testPut_ClientHandlerException_caused() {
+        ClientHandlerException ex = new ClientHandlerException();
+        ex.initCause(new java.net.ConnectException());
+        when(client.put(any(String.class), any(String.class))).thenThrow(ex);
+
+        connection.put(PATH, JSON_STRING);
+    }
+
+    @Test
+    public void testDelete() {
+        JsonRestClientResponse res = connection.delete(PATH);
+
+        assertEquals(response, res);
+    }
+
+    @Test
+    public void testDelete_notInitialized() {
+        when(connection.isInitialized()).thenReturn(false);
+
+        thrown.expect(IllegalStateException.class);
+        thrown.expectMessage(SFlowRTConnection.EX_MSG_NOT_INITIALIZED);
+        connection.delete(PATH);
+    }
+
+    @Test(expected = ClientHandlerException.class)
+    public void testDelete_ClientHandlerException_noCause() {
+        ClientHandlerException ex = new ClientHandlerException();
+        when(client.delete(any(String.class))).thenThrow(ex);
+
+        connection.delete(PATH);
+    }
+
+    @Test(expected = ClientHandlerException.class)
+    public void testDelete_ClientHandlerException_caused() {
+        ClientHandlerException ex = new ClientHandlerException();
+        ex.initCause(new java.net.ConnectException());
+        when(client.delete(any(String.class))).thenThrow(ex);
+
+        connection.delete(PATH);
+    }
+
+    @Test
+    public void testInitialize() {
+        when(response.getStatusCode()).thenReturn(300);
+        connection.initialize();
+        assertTrue(connection.isInitialized());
+
+        when(response.getStatusCode()).thenReturn(400);
+        connection.initialize();
+        assertTrue(connection.isInitialized());
+    }
+
+    @Test
+    public void testLogStatusCode_coverage() {
+        when(response.getStatusCode()).thenReturn(300);
+        connection.getJsonResponse(PATH, params);
+        connection.delete(PATH);
+
+        when(response.getStatusCode()).thenReturn(400);
+        connection.getJsonResponse(PATH, params);
+        connection.delete(PATH);
+    }
+
+}
index 349532978ae7586b5ec5b321a454a8a241350072..c5e1b2074ce3605f69adc707a5d513aea4881412 100755 (executable)
@@ -1,3 +1,11 @@
+/*\r
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics;\r
 \r
 import static org.mockito.Mockito.mock;\r
diff --git a/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/test/TransactionMockUtils.java b/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/test/TransactionMockUtils.java
new file mode 100644 (file)
index 0000000..96c7744
--- /dev/null
@@ -0,0 +1,47 @@
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.test;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.concurrent.ExecutionException;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class TransactionMockUtils {
+
+    /**
+     * Stubs {@link ReadOnlyTransaction#read(LogicalDatastoreType, InstanceIdentifier)}
+     * to return a given {@link DataObject}
+     *
+     * @param roTx mocked transaction to stub
+     * @param store {@link LogicalDatastoreType}
+     * @param path {@link InstanceIdentifier}
+     * @param isPresent stub {@link Optional#isPresent()}; if {@code true}, stub
+     *        {@link Optional#get()} to return {@code returnObject}
+     * @param returnObject {@link DataObject} to return
+     * @param <T> type of {@code returnObject}
+     * @throws ExecutionException
+     * @throws InterruptedException
+     */
+    @SuppressWarnings("unchecked")
+    public static <T extends DataObject> void setupRoTx(ReadOnlyTransaction roTx, LogicalDatastoreType store,
+            InstanceIdentifier<T> path, boolean isPresent, T returnObject)
+            throws ExecutionException, InterruptedException {
+
+        CheckedFuture<Optional<T>, ReadFailedException> future = mock(CheckedFuture.class);
+        when(roTx.read(store, path)).thenReturn(future);
+        Optional<T> opt = mock(Optional.class);
+        when(future.get()).thenReturn(opt);
+        when(opt.isPresent()).thenReturn(isPresent);
+        if (isPresent) {
+            when(opt.get()).thenReturn(returnObject);
+        }
+    }
+
+}
index 0a1df5f39d30dfbc689dd2772035d764e6ae5f61..3ea402b0ca56eb32419ebcd3824a2f3432276a31 100644 (file)
 
   <dependencies>
     <!-- project specific dependencies -->
+    <dependency>
+      <groupId>org.opendaylight.mdsal.model</groupId>
+      <artifactId>ietf-yang-types-20130715</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.mdsal.model</groupId>
+      <artifactId>ietf-inet-types-2013-07-15</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.mdsal.model</groupId>
+      <artifactId>yang-ext</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.mdsal.model</groupId>
+      <artifactId>iana-if-type-2014-05-08</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.mdsal.model</groupId>
+      <artifactId>ietf-interfaces</artifactId>
+    </dependency>
 
     <!-- testing dependencies -->
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal-binding-broker-impl</artifactId>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
@@ -50,7 +76,7 @@
           <instructions>
             <Export-Package>
               org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.*
-            </Export-Package> -->
+            </Export-Package>
           </instructions>
         </configuration>
       </plugin>
@@ -11,15 +11,15 @@ package org.opendaylight.controller.config.yang.config.vpp_provider.impl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class VppProviderModule extends org.opendaylight.controller.config.yang.config.vpp_provider.impl.AbstractVppProviderModule {
+public class GbpVppProviderModule extends org.opendaylight.controller.config.yang.config.vpp_provider.impl.AbstractGbpVppProviderModule {
 
-    private static final Logger LOG = LoggerFactory.getLogger(VppProviderModule.class);
+    private static final Logger LOG = LoggerFactory.getLogger(GbpVppProviderModule.class);
 
-    public VppProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+    public GbpVppProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
         super(identifier, dependencyResolver);
     }
 
-    public VppProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.config.vpp_provider.impl.VppProviderModule oldModule, java.lang.AutoCloseable oldInstance) {
+    public GbpVppProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.config.vpp_provider.impl.GbpVppProviderModule oldModule, java.lang.AutoCloseable oldInstance) {
         super(identifier, dependencyResolver, oldModule, oldInstance);
     }
 
 *
 * Generated from: yang module name: vpp-provider-impl yang module local name: vpp-provider-impl
 * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
-* Generated at: Thu May 05 09:46:48 CEST 2016
+* Generated at: Wed May 25 17:25:43 CEST 2016
 *
 * Do not modify this file unless it is present under src/main directory
 */
 package org.opendaylight.controller.config.yang.config.vpp_provider.impl;
-public class VppProviderModuleFactory extends org.opendaylight.controller.config.yang.config.vpp_provider.impl.AbstractVppProviderModuleFactory {
+public class GbpVppProviderModuleFactory extends org.opendaylight.controller.config.yang.config.vpp_provider.impl.AbstractGbpVppProviderModuleFactory {
 
 }
diff --git a/renderers/vpp/src/main/java/org/opendaylight/groupbasedpolicy/renderer/vpp/commands/AbstractInterfaceCommand.java b/renderers/vpp/src/main/java/org/opendaylight/groupbasedpolicy/renderer/vpp/commands/AbstractInterfaceCommand.java
new file mode 100644 (file)
index 0000000..0493631
--- /dev/null
@@ -0,0 +1,50 @@
+/*\r
+ * Copyright (c) 2016 Cisco Systems. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.groupbasedpolicy.renderer.vpp.commands;\r
+\r
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;\r
+\r
+public abstract class AbstractInterfaceCommand<T extends AbstractInterfaceCommand<T>> implements ConfigCommand {\r
+\r
+    protected General.Operations operation;\r
+    protected String name;\r
+    protected String description;\r
+    protected Boolean enabled;\r
+\r
+    protected enum linkUpDownTrap {\r
+        ENABLED, DISABLED\r
+    }\r
+\r
+    public General.Operations getOperation() {\r
+        return operation;\r
+    }\r
+\r
+    public String getName() {\r
+        return name;\r
+    }\r
+\r
+    public String getDescription() {\r
+        return description;\r
+    }\r
+\r
+    public AbstractInterfaceCommand<T> setDescription(String description) {\r
+        this.description = description;\r
+        return this;\r
+    }\r
+\r
+    public Boolean getEnabled() {\r
+        return enabled;\r
+    }\r
+\r
+    public AbstractInterfaceCommand<T> setEnabled(Boolean enabled) {\r
+        this.enabled = enabled;\r
+        return this;\r
+    }\r
+\r
+}\r
diff --git a/renderers/vpp/src/main/java/org/opendaylight/groupbasedpolicy/renderer/vpp/commands/ConfigCommand.java b/renderers/vpp/src/main/java/org/opendaylight/groupbasedpolicy/renderer/vpp/commands/ConfigCommand.java
new file mode 100644 (file)
index 0000000..cd8b690
--- /dev/null
@@ -0,0 +1,22 @@
+/*\r
+ * Copyright (c) 2016 Cisco Systems. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.groupbasedpolicy.renderer.vpp.commands;\r
+\r
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;\r
+\r
+public interface ConfigCommand {\r
+\r
+    /**\r
+     * Execute command using a given data modification transaction\r
+     *\r
+     * @param readWriteTransaction Transaction for command execution\r
+     */\r
+    void execute(ReadWriteTransaction readWriteTransaction);\r
+\r
+}\r
diff --git a/renderers/vpp/src/main/java/org/opendaylight/groupbasedpolicy/renderer/vpp/commands/VhostUserCommand.java b/renderers/vpp/src/main/java/org/opendaylight/groupbasedpolicy/renderer/vpp/commands/VhostUserCommand.java
new file mode 100644 (file)
index 0000000..a47d04f
--- /dev/null
@@ -0,0 +1,221 @@
+/*\r
+ * Copyright (c) 2016 Cisco Systems. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.groupbasedpolicy.renderer.vpp.commands;\r
+\r
+import com.google.common.base.Preconditions;\r
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;\r
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;\r
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VhostUserRole;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentation;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentationBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.L2Builder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.VhostUserBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.l2.interconnection.BridgeBasedBuilder;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+public class VhostUserCommand extends AbstractInterfaceCommand {\r
+\r
+    private static final Logger LOG = LoggerFactory.getLogger(VhostUserCommand.class);\r
+    private String socket;\r
+    private VhostUserRole role;\r
+    private String bridgeDomain;\r
+\r
+    private VhostUserCommand(VhostUserCommandBuilder builder) {\r
+        this.name = builder.getName();\r
+        this.operation = builder.getOperation();\r
+        this.socket = builder.getSocket();\r
+        this.role = builder.getRole();\r
+        this.enabled = builder.isEnabled();\r
+        this.description = builder.getDescription();\r
+        this.bridgeDomain = builder.getBridgeDomain();\r
+\r
+    }\r
+\r
+    public static VhostUserCommandBuilder builder() {\r
+        return new VhostUserCommandBuilder();\r
+    }\r
+\r
+    public String getSocket() {\r
+        return socket;\r
+    }\r
+\r
+    public VhostUserRole getRole() {\r
+        return role;\r
+    }\r
+\r
+    public String getBridgeDomain() {\r
+        return bridgeDomain;\r
+    }\r
+\r
+    @Override\r
+    public void execute(ReadWriteTransaction readWriteTransaction) {\r
+        switch (getOperation()) {\r
+\r
+            case PUT:\r
+                LOG.info("Executing Add operation for command: {}", this);\r
+                put(readWriteTransaction);\r
+                break;\r
+            case DELETE:\r
+                LOG.info("Executing Delete operation for command: {}", this);\r
+                delete(readWriteTransaction);\r
+                break;\r
+            case MERGE:\r
+                LOG.info("Executing Update operation for command: {}", this);\r
+                merge(readWriteTransaction);\r
+                break;\r
+            default:\r
+                LOG.error("Execution failed for command: {}", this);\r
+                break;\r
+        }\r
+    }\r
+\r
+    private void put(ReadWriteTransaction readWriteTransaction) {\r
+        Preconditions.checkNotNull(name, "Interface name should not be null");\r
+\r
+        InterfaceBuilder interfaceBuilder = getVhostUserInterfaceBuilder();\r
+\r
+        readWriteTransaction.put(LogicalDatastoreType.CONFIGURATION,\r
+                VppIidFactory.getInterfaceIID(interfaceBuilder.getKey()), interfaceBuilder.build(), true);\r
+    }\r
+\r
+    private void merge(ReadWriteTransaction readWriteTransaction) {\r
+        Preconditions.checkNotNull(name, "Interface name should not be null");\r
+\r
+        InterfaceBuilder interfaceBuilder = getVhostUserInterfaceBuilder();\r
+\r
+            readWriteTransaction.merge(LogicalDatastoreType.CONFIGURATION,\r
+                    VppIidFactory.getInterfaceIID(interfaceBuilder.getKey()), interfaceBuilder.build());\r
+    }\r
+\r
+    private InterfaceBuilder getVhostUserInterfaceBuilder() {\r
+        InterfaceBuilder interfaceBuilder =\r
+                new InterfaceBuilder().setKey(new InterfaceKey(name))\r
+                        .setEnabled(enabled)\r
+                        .setDescription(description)\r
+                        .setType(\r
+                                org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VhostUser.class)\r
+                        .setName(name)\r
+                        .setLinkUpDownTrapEnable(Interface.LinkUpDownTrapEnable.Enabled);\r
+\r
+        // Create the vhost augmentation\r
+        VppInterfaceAugmentation vppAugmentation =\r
+                new VppInterfaceAugmentationBuilder()\r
+                        .setVhostUser(new VhostUserBuilder().setRole(role).setSocket(socket).build())\r
+                        .setL2(new L2Builder()\r
+                                .setInterconnection(new BridgeBasedBuilder().setBridgeDomain(bridgeDomain).build()).build())\r
+                        .build();\r
+\r
+        interfaceBuilder.addAugmentation(VppInterfaceAugmentation.class, vppAugmentation);\r
+        return interfaceBuilder;\r
+    }\r
+\r
+    private void delete(ReadWriteTransaction readWriteTransaction) {\r
+        try {\r
+            readWriteTransaction.delete(LogicalDatastoreType.CONFIGURATION,\r
+                    VppIidFactory.getInterfaceIID(new InterfaceKey(name)));\r
+        } catch (IllegalStateException ex) {\r
+            LOG.debug("Vhost Interface is not present in DS", ex);\r
+        }\r
+\r
+    }\r
+\r
+    public static class VhostUserCommandBuilder {\r
+\r
+        private String name;\r
+        private General.Operations operation;\r
+        private String socket;\r
+        private VhostUserRole role = VhostUserRole.Server;\r
+        private boolean enabled = true;\r
+        private String description;\r
+        private String bridgeDomain;\r
+\r
+        public String getName() {\r
+            return name;\r
+        }\r
+\r
+        public VhostUserCommandBuilder setName(String name) {\r
+            this.name = name;\r
+            return this;\r
+        }\r
+\r
+        public General.Operations getOperation() {\r
+            return operation;\r
+        }\r
+\r
+        public VhostUserCommandBuilder setOperation(General.Operations operation) {\r
+            this.operation = operation;\r
+            return this;\r
+        }\r
+\r
+        public String getSocket() {\r
+            return socket;\r
+        }\r
+\r
+        public VhostUserCommandBuilder setSocket(String socket) {\r
+            this.socket = socket;\r
+            return this;\r
+        }\r
+\r
+        public VhostUserRole getRole() {\r
+            return role;\r
+        }\r
+\r
+        public VhostUserCommandBuilder setRole(VhostUserRole role) {\r
+            this.role = role;\r
+            return this;\r
+        }\r
+\r
+        public boolean isEnabled() {\r
+            return enabled;\r
+        }\r
+\r
+        public VhostUserCommandBuilder setEnabled(boolean enabled) {\r
+            this.enabled = enabled;\r
+            return this;\r
+        }\r
+\r
+        public String getDescription() {\r
+            return description;\r
+        }\r
+\r
+        public VhostUserCommandBuilder setDescription(String description) {\r
+            this.description = description;\r
+            return this;\r
+        }\r
+\r
+        public String getBridgeDomain() {\r
+            return bridgeDomain;\r
+        }\r
+\r
+        public VhostUserCommandBuilder setBridgeDomain(String bridgeDomain) {\r
+            this.bridgeDomain = bridgeDomain;\r
+            return this;\r
+        }\r
+\r
+        /**\r
+         * VhostUserCommand build method.\r
+         *\r
+         * @return VhostUserCommand\r
+         * @throws IllegalArgumentException if name, operation or socket is null.\r
+         */\r
+        public VhostUserCommand build() {\r
+            Preconditions.checkArgument(this.name != null);\r
+            Preconditions.checkArgument(this.operation != null);\r
+            Preconditions.checkArgument(this.socket != null);\r
+\r
+            return new VhostUserCommand(this);\r
+        }\r
+    }\r
+}\r
diff --git a/renderers/vpp/src/main/java/org/opendaylight/groupbasedpolicy/renderer/vpp/util/General.java b/renderers/vpp/src/main/java/org/opendaylight/groupbasedpolicy/renderer/vpp/util/General.java
new file mode 100644 (file)
index 0000000..ab59e4b
--- /dev/null
@@ -0,0 +1,31 @@
+/*\r
+ * Copyright (c) 2016 Cisco Systems. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.groupbasedpolicy.renderer.vpp.util;\r
+\r
+\r
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;\r
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
+import org.opendaylight.yangtools.yang.binding.DataObject;\r
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
+\r
+public class General {\r
+\r
+    /**\r
+     * Operations that can be executed over ConfigCommand. Operation names reflect operations used in WriteTransaction.\r
+     * For more information on these operations, please see the documentation in:\r
+     * <br>\r
+     * {@link WriteTransaction#put(LogicalDatastoreType, InstanceIdentifier, DataObject, boolean)}<br>\r
+     * {@link WriteTransaction#merge(LogicalDatastoreType, InstanceIdentifier, DataObject, boolean)}<br>\r
+     * {@link WriteTransaction#delete(LogicalDatastoreType, InstanceIdentifier)}<br>\r
+     *\r
+     */\r
+    public enum Operations {\r
+        PUT, DELETE, MERGE\r
+    }\r
+}\r
diff --git a/renderers/vpp/src/main/java/org/opendaylight/groupbasedpolicy/renderer/vpp/util/VppIidFactory.java b/renderers/vpp/src/main/java/org/opendaylight/groupbasedpolicy/renderer/vpp/util/VppIidFactory.java
new file mode 100644 (file)
index 0000000..19a672c
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2016 Cisco Systems. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.renderer.vpp.util;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class VppIidFactory {
+
+    public static InstanceIdentifier<Interface> getInterfaceIID(InterfaceKey interfaceKey) {
+        return InstanceIdentifier.create(Interfaces.class).child(Interface.class, interfaceKey);
+    }
+}
diff --git a/renderers/vpp/src/main/yang/vbd/ietf-ip@2014-06-16.yang b/renderers/vpp/src/main/yang/vbd/ietf-ip@2014-06-16.yang
new file mode 100644 (file)
index 0000000..f6c59ed
--- /dev/null
@@ -0,0 +1,742 @@
+module ietf-ip {
+
+  yang-version 1;
+
+  namespace
+    "urn:ietf:params:xml:ns:yang:ietf-ip";
+
+  prefix ip;
+
+  import ietf-interfaces {
+    prefix if;
+  }
+  import ietf-inet-types {
+    prefix inet;
+  }
+  import ietf-yang-types {
+    prefix yang;
+  }
+
+  organization
+    "IETF NETMOD (NETCONF Data Modeling Language) Working Group";
+
+  contact
+    "WG Web:   <http://tools.ietf.org/wg/netmod/>
+  WG List:  <mailto:netmod@ietf.org>
+
+  WG Chair: Thomas Nadeau
+            <mailto:tnadeau@lucidvision.com>
+
+  WG Chair: Juergen Schoenwaelder
+            <mailto:j.schoenwaelder@jacobs-university.de>
+
+  Editor:   Martin Bjorklund
+            <mailto:mbj@tail-f.com>";
+
+  description
+    "This module contains a collection of YANG definitions for
+  configuring IP implementations.
+
+  Copyright (c) 2014 IETF Trust and the persons identified as
+  authors of the code.  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or
+  without modification, is permitted pursuant to, and subject
+  to the license terms contained in, the Simplified BSD License
+  set forth in Section 4.c of the IETF Trust's Legal Provisions
+  Relating to IETF Documents
+  (http://trustee.ietf.org/license-info).
+
+  This version of this YANG module is part of RFC 7277; see
+  the RFC itself for full legal notices.";
+
+  revision "2014-06-16" {
+    description "Initial revision.";
+    reference
+      "RFC 7277: A YANG Data Model for IP Management";
+
+  }
+
+
+  feature ipv4-non-contiguous-netmasks {
+    description
+      "Indicates support for configuring non-contiguous
+    subnet masks.";
+  }
+
+  feature ipv6-privacy-autoconf {
+    description
+      "Indicates support for Privacy Extensions for Stateless Address
+    Autoconfiguration in IPv6.";
+    reference
+      "RFC 4941: Privacy Extensions for Stateless Address
+         Autoconfiguration in IPv6";
+
+  }
+
+  typedef ip-address-origin {
+    type enumeration {
+      enum "other" {
+        value 0;
+        description
+          "None of the following.";
+      }
+      enum "static" {
+        value 1;
+        description
+          "Indicates that the address has been statically
+        configured - for example, using NETCONF or a Command Line
+        Interface.";
+      }
+      enum "dhcp" {
+        value 2;
+        description
+          "Indicates an address that has been assigned to this
+        system by a DHCP server.";
+      }
+      enum "link-layer" {
+        value 3;
+        description
+          "Indicates an address created by IPv6 stateless
+        autoconfiguration that embeds a link-layer address in its
+        interface identifier.";
+      }
+      enum "random" {
+        value 4;
+        description
+          "Indicates an address chosen by the system at
+
+        random, e.g., an IPv4 address within 169.254/16, an
+        RFC 4941 temporary address, or an RFC 7217 semantically
+        opaque address.";
+        reference
+          "RFC 4941: Privacy Extensions for Stateless Address
+                 Autoconfiguration in IPv6
+           RFC 7217: A Method for Generating Semantically Opaque
+                 Interface Identifiers with IPv6 Stateless
+                 Address Autoconfiguration (SLAAC)";
+
+      }
+    }
+    description
+      "The origin of an address.";
+  }
+
+  typedef neighbor-origin {
+    type enumeration {
+      enum "other" {
+        value 0;
+        description
+          "None of the following.";
+      }
+      enum "static" {
+        value 1;
+        description
+          "Indicates that the mapping has been statically
+        configured - for example, using NETCONF or a Command Line
+        Interface.";
+      }
+      enum "dynamic" {
+        value 2;
+        description
+          "Indicates that the mapping has been dynamically resolved
+        using, e.g., IPv4 ARP or the IPv6 Neighbor Discovery
+        protocol.";
+      }
+    }
+    description
+      "The origin of a neighbor entry.";
+  }
+
+  augment /if:interfaces/if:interface {
+    description
+      "Parameters for configuring IP on interfaces.
+
+    If an interface is not capable of running IP, the server
+    must not allow the client to configure these parameters.";
+    container ipv4 {
+      presence
+        "Enables IPv4 unless the 'enabled' leaf
+      (which defaults to 'true') is set to 'false'";
+      description
+        "Parameters for the IPv4 address family.";
+      leaf enabled {
+        type boolean;
+        default 'true';
+        description
+          "Controls whether IPv4 is enabled or disabled on this
+        interface.  When IPv4 is enabled, this interface is
+        connected to an IPv4 stack, and the interface can send
+        and receive IPv4 packets.";
+      }
+
+      leaf forwarding {
+        type boolean;
+        default 'false';
+        description
+          "Controls IPv4 packet forwarding of datagrams received by,
+        but not addressed to, this interface.  IPv4 routers
+        forward datagrams.  IPv4 hosts do not (except those
+        source-routed via the host).";
+      }
+
+      leaf mtu {
+        type uint16 {
+          range "68..max";
+        }
+        units "octets";
+        description
+          "The size, in octets, of the largest IPv4 packet that the
+        interface will send and receive.
+
+        The server may restrict the allowed values for this leaf,
+        depending on the interface's type.
+
+        If this leaf is not configured, the operationally used MTU
+        depends on the interface's type.";
+        reference
+          "RFC 791: Internet Protocol";
+
+      }
+
+      list address {
+        key "ip";
+        description
+          "The list of configured IPv4 addresses on the interface.";
+        leaf ip {
+          type inet:ipv4-address-no-zone;
+          description
+            "The IPv4 address on the interface.";
+        }
+
+        choice subnet {
+          mandatory true;
+          description
+            "The subnet can be specified as a prefix-length, or,
+          if the server supports non-contiguous netmasks, as
+          a netmask.";
+          leaf prefix-length {
+            type uint8 {
+              range "0..32";
+            }
+            description
+              "The length of the subnet prefix.";
+          }
+          leaf netmask {
+            if-feature ipv4-non-contiguous-netmasks;
+            type yang:dotted-quad;
+            description
+              "The subnet specified as a netmask.";
+          }
+        }  // choice subnet
+      }  // list address
+
+      list neighbor {
+        key "ip";
+        description
+          "A list of mappings from IPv4 addresses to
+        link-layer addresses.
+
+        Entries in this list are used as static entries in the
+        ARP Cache.";
+        reference
+          "RFC 826: An Ethernet Address Resolution Protocol";
+
+        leaf ip {
+          type inet:ipv4-address-no-zone;
+          description
+            "The IPv4 address of the neighbor node.";
+        }
+
+        leaf link-layer-address {
+          type yang:phys-address;
+          mandatory true;
+          description
+            "The link-layer address of the neighbor node.";
+        }
+      }  // list neighbor
+    }  // container ipv4
+
+    container ipv6 {
+      presence
+        "Enables IPv6 unless the 'enabled' leaf
+      (which defaults to 'true') is set to 'false'";
+      description
+        "Parameters for the IPv6 address family.";
+      leaf enabled {
+        type boolean;
+        default 'true';
+        description
+          "Controls whether IPv6 is enabled or disabled on this
+        interface.  When IPv6 is enabled, this interface is
+        connected to an IPv6 stack, and the interface can send
+        and receive IPv6 packets.";
+      }
+
+      leaf forwarding {
+        type boolean;
+        default 'false';
+        description
+          "Controls IPv6 packet forwarding of datagrams received by,
+        but not addressed to, this interface.  IPv6 routers
+        forward datagrams.  IPv6 hosts do not (except those
+        source-routed via the host).";
+        reference
+          "RFC 4861: Neighbor Discovery for IP version 6 (IPv6)
+                 Section 6.2.1, IsRouter";
+
+      }
+
+      leaf mtu {
+        type uint32 {
+          range "1280..max";
+        }
+        units "octets";
+        description
+          "The size, in octets, of the largest IPv6 packet that the
+        interface will send and receive.
+
+        The server may restrict the allowed values for this leaf,
+        depending on the interface's type.
+
+        If this leaf is not configured, the operationally used MTU
+        depends on the interface's type.";
+        reference
+          "RFC 2460: Internet Protocol, Version 6 (IPv6) Specification
+                 Section 5";
+
+      }
+
+      list address {
+        key "ip";
+        description
+          "The list of configured IPv6 addresses on the interface.";
+        leaf ip {
+          type inet:ipv6-address-no-zone;
+          description
+            "The IPv6 address on the interface.";
+        }
+
+        leaf prefix-length {
+          type uint8 {
+            range "0..128";
+          }
+          mandatory true;
+          description
+            "The length of the subnet prefix.";
+        }
+      }  // list address
+
+      list neighbor {
+        key "ip";
+        description
+          "A list of mappings from IPv6 addresses to
+        link-layer addresses.
+
+        Entries in this list are used as static entries in the
+        Neighbor Cache.";
+        reference
+          "RFC 4861: Neighbor Discovery for IP version 6 (IPv6)";
+
+        leaf ip {
+          type inet:ipv6-address-no-zone;
+          description
+            "The IPv6 address of the neighbor node.";
+        }
+
+        leaf link-layer-address {
+          type yang:phys-address;
+          mandatory true;
+          description
+            "The link-layer address of the neighbor node.";
+        }
+      }  // list neighbor
+
+      leaf dup-addr-detect-transmits {
+        type uint32;
+        default '1';
+        description
+          "The number of consecutive Neighbor Solicitation messages
+        sent while performing Duplicate Address Detection on a
+        tentative address.  A value of zero indicates that
+        Duplicate Address Detection is not performed on
+        tentative addresses.  A value of one indicates a single
+        transmission with no follow-up retransmissions.";
+        reference
+          "RFC 4862: IPv6 Stateless Address Autoconfiguration";
+
+      }
+
+      container autoconf {
+        description
+          "Parameters to control the autoconfiguration of IPv6
+        addresses, as described in RFC 4862.";
+        reference
+          "RFC 4862: IPv6 Stateless Address Autoconfiguration";
+
+        leaf create-global-addresses {
+          type boolean;
+          default 'true';
+          description
+            "If enabled, the host creates global addresses as
+          described in RFC 4862.";
+          reference
+            "RFC 4862: IPv6 Stateless Address Autoconfiguration
+                 Section 5.5";
+
+        }
+
+        leaf create-temporary-addresses {
+          if-feature ipv6-privacy-autoconf;
+          type boolean;
+          default 'false';
+          description
+            "If enabled, the host creates temporary addresses as
+          described in RFC 4941.";
+          reference
+            "RFC 4941: Privacy Extensions for Stateless Address
+                 Autoconfiguration in IPv6";
+
+        }
+
+        leaf temporary-valid-lifetime {
+          if-feature ipv6-privacy-autoconf;
+          type uint32;
+          units "seconds";
+          default '604800';
+          description
+            "The time period during which the temporary address
+          is valid.";
+          reference
+            "RFC 4941: Privacy Extensions for Stateless Address
+                 Autoconfiguration in IPv6
+                 - TEMP_VALID_LIFETIME";
+
+        }
+
+        leaf temporary-preferred-lifetime {
+          if-feature ipv6-privacy-autoconf;
+          type uint32;
+          units "seconds";
+          default '86400';
+          description
+            "The time period during which the temporary address is
+          preferred.";
+          reference
+            "RFC 4941: Privacy Extensions for Stateless Address
+                 Autoconfiguration in IPv6
+                 - TEMP_PREFERRED_LIFETIME";
+
+        }
+      }  // container autoconf
+    }  // container ipv6
+  }
+
+  augment /if:interfaces-state/if:interface {
+    description
+      "Data nodes for the operational state of IP on interfaces.";
+    container ipv4 {
+      presence
+        "Present if IPv4 is enabled on this interface";
+      config false;
+      description
+        "Interface-specific parameters for the IPv4 address family.";
+      leaf forwarding {
+        type boolean;
+        description
+          "Indicates whether IPv4 packet forwarding is enabled or
+        disabled on this interface.";
+      }
+
+      leaf mtu {
+        type uint16 {
+          range "68..max";
+        }
+        units "octets";
+        description
+          "The size, in octets, of the largest IPv4 packet that the
+        interface will send and receive.";
+        reference
+          "RFC 791: Internet Protocol";
+
+      }
+
+      list address {
+        key "ip";
+        description
+          "The list of IPv4 addresses on the interface.";
+        leaf ip {
+          type inet:ipv4-address-no-zone;
+          description
+            "The IPv4 address on the interface.";
+        }
+
+        choice subnet {
+          description
+            "The subnet can be specified as a prefix-length, or,
+          if the server supports non-contiguous netmasks, as
+          a netmask.";
+          leaf prefix-length {
+            type uint8 {
+              range "0..32";
+            }
+            description
+              "The length of the subnet prefix.";
+          }
+          leaf netmask {
+            if-feature ipv4-non-contiguous-netmasks;
+            type yang:dotted-quad;
+            description
+              "The subnet specified as a netmask.";
+          }
+        }  // choice subnet
+
+        leaf origin {
+          type ip-address-origin;
+          description
+            "The origin of this address.";
+        }
+      }  // list address
+
+      list neighbor {
+        key "ip";
+        description
+          "A list of mappings from IPv4 addresses to
+        link-layer addresses.
+
+        This list represents the ARP Cache.";
+        reference
+          "RFC 826: An Ethernet Address Resolution Protocol";
+
+        leaf ip {
+          type inet:ipv4-address-no-zone;
+          description
+            "The IPv4 address of the neighbor node.";
+        }
+
+        leaf link-layer-address {
+          type yang:phys-address;
+          description
+            "The link-layer address of the neighbor node.";
+        }
+
+        leaf origin {
+          type neighbor-origin;
+          description
+            "The origin of this neighbor entry.";
+        }
+      }  // list neighbor
+    }  // container ipv4
+
+    container ipv6 {
+      presence
+        "Present if IPv6 is enabled on this interface";
+      config false;
+      description
+        "Parameters for the IPv6 address family.";
+      leaf forwarding {
+        type boolean;
+        default 'false';
+        description
+          "Indicates whether IPv6 packet forwarding is enabled or
+        disabled on this interface.";
+        reference
+          "RFC 4861: Neighbor Discovery for IP version 6 (IPv6)
+                 Section 6.2.1, IsRouter";
+
+      }
+
+      leaf mtu {
+        type uint32 {
+          range "1280..max";
+        }
+        units "octets";
+        description
+          "The size, in octets, of the largest IPv6 packet that the
+        interface will send and receive.";
+        reference
+          "RFC 2460: Internet Protocol, Version 6 (IPv6) Specification
+                 Section 5";
+
+      }
+
+      list address {
+        key "ip";
+        description
+          "The list of IPv6 addresses on the interface.";
+        leaf ip {
+          type inet:ipv6-address-no-zone;
+          description
+            "The IPv6 address on the interface.";
+        }
+
+        leaf prefix-length {
+          type uint8 {
+            range "0..128";
+          }
+          mandatory true;
+          description
+            "The length of the subnet prefix.";
+        }
+
+        leaf origin {
+          type ip-address-origin;
+          description
+            "The origin of this address.";
+        }
+
+        leaf status {
+          type enumeration {
+            enum "preferred" {
+              value 0;
+              description
+                "This is a valid address that can appear as the
+              destination or source address of a packet.";
+            }
+            enum "deprecated" {
+              value 1;
+              description
+                "This is a valid but deprecated address that should
+              no longer be used as a source address in new
+              communications, but packets addressed to such an
+              address are processed as expected.";
+            }
+            enum "invalid" {
+              value 2;
+              description
+                "This isn't a valid address, and it shouldn't appear
+              as the destination or source address of a packet.";
+            }
+            enum "inaccessible" {
+              value 3;
+              description
+                "The address is not accessible because the interface
+              to which this address is assigned is not
+              operational.";
+            }
+            enum "unknown" {
+              value 4;
+              description
+                "The status cannot be determined for some reason.";
+            }
+            enum "tentative" {
+              value 5;
+              description
+                "The uniqueness of the address on the link is being
+              verified.  Addresses in this state should not be
+              used for general communication and should only be
+              used to determine the uniqueness of the address.";
+            }
+            enum "duplicate" {
+              value 6;
+              description
+                "The address has been determined to be non-unique on
+              the link and so must not be used.";
+            }
+            enum "optimistic" {
+              value 7;
+              description
+                "The address is available for use, subject to
+              restrictions, while its uniqueness on a link is
+              being verified.";
+            }
+          }
+          description
+            "The status of an address.  Most of the states correspond
+          to states from the IPv6 Stateless Address
+          Autoconfiguration protocol.";
+          reference
+            "RFC 4293: Management Information Base for the
+                 Internet Protocol (IP)
+                 - IpAddressStatusTC
+             RFC 4862: IPv6 Stateless Address Autoconfiguration";
+
+        }
+      }  // list address
+
+      list neighbor {
+        key "ip";
+        description
+          "A list of mappings from IPv6 addresses to
+        link-layer addresses.
+
+        This list represents the Neighbor Cache.";
+        reference
+          "RFC 4861: Neighbor Discovery for IP version 6 (IPv6)";
+
+        leaf ip {
+          type inet:ipv6-address-no-zone;
+          description
+            "The IPv6 address of the neighbor node.";
+        }
+
+        leaf link-layer-address {
+          type yang:phys-address;
+          description
+            "The link-layer address of the neighbor node.";
+        }
+
+        leaf origin {
+          type neighbor-origin;
+          description
+            "The origin of this neighbor entry.";
+        }
+
+        leaf is-router {
+          type empty;
+          description
+            "Indicates that the neighbor node acts as a router.";
+        }
+
+        leaf state {
+          type enumeration {
+            enum "incomplete" {
+              value 0;
+              description
+                "Address resolution is in progress, and the link-layer
+              address of the neighbor has not yet been
+              determined.";
+            }
+            enum "reachable" {
+              value 1;
+              description
+                "Roughly speaking, the neighbor is known to have been
+              reachable recently (within tens of seconds ago).";
+            }
+            enum "stale" {
+              value 2;
+              description
+                "The neighbor is no longer known to be reachable, but
+              until traffic is sent to the neighbor no attempt
+              should be made to verify its reachability.";
+            }
+            enum "delay" {
+              value 3;
+              description
+                "The neighbor is no longer known to be reachable, and
+              traffic has recently been sent to the neighbor.
+              Rather than probe the neighbor immediately, however,
+              delay sending probes for a short while in order to
+              give upper-layer protocols a chance to provide
+              reachability confirmation.";
+            }
+            enum "probe" {
+              value 4;
+              description
+                "The neighbor is no longer known to be reachable, and
+              unicast Neighbor Solicitation probes are being sent
+              to verify reachability.";
+            }
+          }
+          description
+            "The Neighbor Unreachability Detection state of this
+          entry.";
+          reference
+            "RFC 4861: Neighbor Discovery for IP version 6 (IPv6)
+                 Section 7.3.2";
+
+        }
+      }  // list neighbor
+    }  // container ipv6
+  }
+}  // module ietf-ip
diff --git a/renderers/vpp/src/main/yang/vbd/v3po@2015-01-05.yang b/renderers/vpp/src/main/yang/vbd/v3po@2015-01-05.yang
new file mode 100644 (file)
index 0000000..3a71ffd
--- /dev/null
@@ -0,0 +1,573 @@
+module v3po {
+  yang-version 1;
+  namespace "urn:opendaylight:params:xml:ns:yang:v3po";
+  prefix "v3po";
+
+  revision "2015-01-05" {
+    description "Initial revision of v3po model";
+  }
+
+  import iana-if-type {
+    prefix "ianaift";
+  }
+  import ietf-interfaces {
+    prefix "if";
+  }
+  import ietf-yang-types {
+    prefix "yang";
+  }
+  import ietf-inet-types {
+    prefix "inet";
+  }
+  import ietf-ip {
+    prefix "ip";
+  }
+  import yang-ext {
+    prefix "ext";
+  }
+
+  typedef bridge-domain-ref {
+    type leafref {
+      path "/vpp/bridge-domains/bridge-domain/name";
+    }
+    description
+      "This type is used by to reference a bridge domain table";
+  }
+
+  typedef bridged-virtual-interface-ref {
+    type leafref {
+      path "/if:interfaces/if:interface/l2/bridged-virtual-interface";
+    }
+    description
+      "This type is used by to reference a bridged virtual interface";
+  }
+
+  typedef vlan-type {
+    type enumeration {
+      enum 802dot1q;
+      enum 802dot1ad;
+    }
+  }
+
+  typedef tag-rewrite-operation {
+    type enumeration {
+      enum disabled;
+      enum push-1;
+      enum push-2;
+      enum pop-1;
+      enum pop-2;
+      enum translate-1-to-1;
+      enum translate-1-to-2;
+      enum translate-2-to-1;
+      enum translate-2-to-2;
+    }
+  }
+
+  typedef vlan-tag {
+    type uint16 {
+      range "1..4094";
+    }
+  }
+
+  identity vxlan-tunnel {
+    base if:interface-type;
+  }
+
+  identity vhost-user {
+    base if:interface-type;
+  }
+
+  identity tap {
+    base if:interface-type;
+  }
+
+  identity sub-interface {
+    base if:interface-type;
+  }
+
+  typedef vxlan-vni {
+    // FIXME: should be in a vxlan-specific model
+    description "VNI used in a VXLAN tunnel";
+    type uint32 {
+      range "0..16777215";
+    }
+  }
+
+  typedef vhost-user-role {
+    type enumeration {
+      enum "server";
+      enum "client";
+    }
+  }
+
+  grouping bridge-domain-attributes {
+    leaf flood {
+      type boolean;
+      default true;
+      description
+      "Enable/disable L2 flooding.";
+    }
+    leaf forward {
+      type boolean;
+      default true;
+      description
+      "Enable/disable L2 forwarding.";
+    }
+    leaf learn {
+      type boolean;
+      default true;
+      description
+      "Enable/disable L2 learning.";
+    }
+    leaf unknown-unicast-flood {
+      type boolean;
+      default true;
+    }
+    leaf arp-termination {
+      type boolean;
+      default false;
+    }
+  }
+
+  grouping sub-interface-base-attributes {
+    leaf identifier {
+      type uint32;
+    }
+    leaf vlan-type {
+      type vlan-type;
+      default '802dot1q';
+    }
+    leaf number-of-tags {
+      type uint8 {
+        range "0..2";
+      }
+      default 1;
+    }
+    leaf outer-id {
+      type vlan-tag;
+    }
+    leaf inner-id {
+      type vlan-tag;
+    }
+    leaf match-any-outer-id {
+      type empty;
+    }
+    leaf match-any-inner-id {
+      type empty;
+    }
+    leaf exact-match {
+      type empty;
+    }
+    leaf default-subif {
+      type empty;
+    }
+  }
+
+  grouping tap-interface-base-attributes {
+    leaf tap-name {
+      type string;
+    }
+  }
+
+  grouping tap-interface-config-attributes {
+    leaf mac {
+      type yang:phys-address;
+      mandatory false;
+      description "Mac address to be set for the tap interface. Random will be used if not configured";
+    }
+
+    leaf device-instance {
+      type uint32;
+      mandatory false;
+      description "Custom device instance. Autogenerated will be used if not configured";
+    }
+  }
+
+  grouping vhost-user-interface-base-attributes {
+    leaf socket {
+      type string {
+        length 1..255;
+      }
+    }
+    leaf role {
+      type vhost-user-role;
+      default "server";
+    }
+  }
+
+  grouping vhost-user-interface-state-attributes {
+      leaf features {
+        type uint64;
+        config false;
+      }
+      leaf virtio-net-hdr-size {
+        type uint32;
+        config false;
+      }
+      leaf num-memory-regions {
+        type uint32;
+        config false;
+      }
+      leaf connect-error {
+        type string;
+        config false;
+      }
+  }
+
+  grouping vlan-tag-rewrite-attributes {
+    leaf rewrite-operation {
+      type tag-rewrite-operation;
+      default 'disabled';
+    }
+    leaf first-pushed {
+      type vlan-type;
+      default '802dot1q';
+    }
+    leaf tag1 {
+      type vlan-tag;
+    }
+    leaf tag2 {
+      type vlan-tag;
+    }
+  }
+
+  augment /if:interfaces/if:interface {
+    ext:augment-identifier "vpp-interface-augmentation";
+
+    // FIXME using ietf-interfaces model for vpp interfaces makes it hard to implement because:
+    // 1. The link between interface type and this augmentation is unclear
+    // 2. Only this augmentation with combination of ifc type is trigger to do something for vpp, what if user only configures base interface stuff ? + We need to get leaves defined by ietf-interfaces when we are processing this augment
+
+    container sub-interface {
+      when "../if:type = 'v3po:sub-interface'";
+      leaf super-interface {
+        type if:interface-ref;
+      }
+      uses sub-interface-base-attributes;
+    }
+
+    container tap {
+      when "../if:type = 'v3po:tap'";
+      uses tap-interface-base-attributes;
+      uses tap-interface-config-attributes;
+    }
+
+    container ethernet {
+      when "../if:type = 'ianaift:ethernetCsmacd'";
+      leaf mtu {
+        type uint16 {
+          range "64..9216";
+        }
+        units "octets";
+        default 9216;
+        description
+        "The size, in octets, of the largest packet that the
+         hardware interface will send and receive.";
+      }
+    }
+    container routing {
+      leaf vrf-id {
+        type uint32;
+        default 0;
+      }
+    }
+    container vhost-user {
+      when "../if:type = 'v3po:vhost-user'";
+      uses vhost-user-interface-base-attributes;
+      description "vhost-user settings";
+    }
+    container vxlan {
+      // FIXME: this should be in an vxlan-specific extension
+      when "../if:type = 'v3po:vxlan-tunnel'";
+
+      leaf src {
+        /*mandatory true;*/
+        type inet:ip-address;
+      }
+      leaf dst {
+        /*mandatory true;*/
+        type inet:ip-address;
+      }
+      leaf vni {
+        /*mandatory true;*/
+        type vxlan-vni;
+      }
+      leaf encap-vrf-id {
+        type uint32;
+      }
+    }
+    container l2 {
+      description
+      "Parameters for configuring Layer2 features on interfaces.";
+      must "(not (../if:ipv4[if:enabled = 'true']/if:address/if:ip) and " +
+      "not (../if:ipv6[if:enabled = 'true']/if:address/if:ip))";
+
+      choice interconnection {
+        case xconnect-based {
+          leaf xconnect-outgoing-interface {
+            /* Don't allow selection of this interface */
+            must "../../if:name != current()";
+            type if:interface-ref;
+            description
+              "L2 xconnect mode";
+          }
+        }
+        case bridge-based {
+          leaf bridge-domain {
+            type bridge-domain-ref;
+            description
+              "Interfaces in a bridge-domain forward packets to other
+               interfaces in the same bridge-domain based on
+               destination mac address.";
+          }
+          leaf split-horizon-group {
+            when "../bridge-domain";
+            type uint8 {
+              range "0..255";
+            }
+            default 0;
+            description
+              "Interface's split-horizon group. Interfaces in the same
+               bridge-domain and split-horizon group can not forward
+               packets between each other. ";
+          }
+          leaf bridged-virtual-interface {
+            when "../bridge-domain";
+            type boolean;
+            default false;
+            description
+              "Interface forward packets in the bridge-domain
+               associated with the BVI.";
+          }
+        }
+      }
+      container vlan-tag-rewrite {
+        uses vlan-tag-rewrite-attributes;
+      }
+    }
+  }
+
+  container vpp {
+    description
+    "VPP config data";
+
+    container bridge-domains {
+      list bridge-domain {
+        key "name";
+        // TODO: where does this come from?
+        max-elements 1024;
+
+        leaf name {
+          type string;
+        }
+
+        uses bridge-domain-attributes;
+
+        list l2-fib {
+          key "phys-address";
+
+          leaf phys-address {
+            type yang:phys-address;
+          }
+          leaf action {
+            type enumeration {
+              enum "forward";
+              enum "filter";
+            }
+            mandatory true;
+          }
+          leaf outgoing-interface {
+            type if:interface-ref;
+          }
+        }
+      }
+    }
+  }
+
+  augment /if:interfaces-state/if:interface {
+    ext:augment-identifier "vpp-interface-state-augmentation";
+
+    leaf description {
+      type string;
+    }
+
+    container sub-interface {
+      when "../if:type = 'v3po:sub-interface'";
+      leaf super-interface {
+        type if:interface-state-ref;
+      }
+      uses sub-interface-base-attributes;
+    }
+
+    container tap {
+      when "../if:type = 'v3po:tap'";
+      uses tap-interface-base-attributes {
+        refine tap-name {
+            config false;
+        }
+      }
+    }
+
+    container ethernet {
+      when "../if:type = 'ianaift:ethernetCsmacd'";
+      leaf mtu {
+        type uint16;
+      }
+      leaf manufacturer-description {
+        type string;
+      }
+      leaf duplex {
+        type enumeration {
+          enum "half";
+          enum "full";
+        }
+      }
+    }
+    container vhost-user {
+      when "../if:type = 'v3po:vhost-user'";
+      uses vhost-user-interface-base-attributes {
+        refine socket {
+            config false;
+        }
+        refine role {
+            config false;
+        }
+      }
+      uses vhost-user-interface-state-attributes;
+    }
+    container vxlan {
+      when "../if:type = 'v3po:vxlan-tunnel'";
+
+      leaf src {
+        type inet:ip-address;
+      }
+      leaf dst {
+        type inet:ip-address;
+      }
+
+      leaf vni {
+        type uint32;
+      }
+      leaf encap-vrf-id {
+        type uint32;
+      }
+    }
+    container l2 {
+      choice interconnection {
+        case xconnect-based {
+          leaf xconnect-outgoing-interface {
+            type if:interface-ref;
+          }
+        }
+        case bridge-based {
+          leaf bridge-domain {
+            type bridge-domain-ref;
+          }
+          leaf split-horizon-group {
+            type uint8;
+          }
+          leaf bridged-virtual-interface {
+            type boolean;
+          }
+        }
+      }
+      container vlan-tag-rewrite {
+        uses vlan-tag-rewrite-attributes;
+      }
+    }
+  }
+
+  augment /if:interfaces-state/if:interface/if:statistics {
+    ext:augment-identifier "vpp-interface-statistics-augmentation";
+    leaf in-errors-no-buf {
+      type yang:counter64;
+    }
+    leaf in-errors-miss {
+      type yang:counter64;
+    }
+    leaf out-discards-fifo-full {
+      type yang:counter64;
+    }
+  }
+
+  container vpp-state {
+    config false;
+
+    description
+      "VPP operational data";
+
+    container bridge-domains {
+      // FIXME: Should this live in bridge-domain.yang in a modular fashion ?
+      list bridge-domain {
+
+        key "name";
+        leaf name {
+          type string;
+        }
+
+        uses bridge-domain-attributes;
+
+        list interface {
+          key "name";
+
+          leaf name {
+            type if:interface-state-ref;
+          }
+
+          leaf split-horizon-group {
+            type uint8;
+          }
+
+          leaf bridged-virtual-interface {
+            type boolean;
+          }
+        }
+
+        list l2-fib {
+          key "phys-address";
+
+          leaf phys-address {
+            type yang:phys-address;
+          }
+          leaf static-config {
+            type boolean;
+          }
+          leaf outgoing-interface {
+            when "../v3po:action = 'forward'";
+            type if:interface-state-ref;
+          }
+          leaf action {
+            type enumeration {
+              enum "forward";
+              enum "filter";
+            }
+            mandatory true;
+          }
+          leaf bridged-virtual-interface {
+            when "../v3po:action = 'forward'";
+            type boolean;
+          }
+        }
+        description
+          "bridge-domain operational data";
+      }
+    }
+
+    container version {
+      leaf name {
+        type string;
+      }
+      leaf build-directory {
+        type string;
+      }
+      leaf build-date {
+        type string;
+      }
+      leaf branch {
+        type string;
+      }
+      description
+      "vlib version info";
+    }
+  }
+}
index b70d8c97ce343075b9125f4b7023853fcd765a99..7169ca14a95c6b5c06d082f6c4c183d30589b36b 100644 (file)
@@ -29,7 +29,7 @@ module vpp-provider-impl {
     identity vpp-provider-impl {
         base "config:module-type";
 
-        config:java-name-prefix VppProvider;
+        config:java-name-prefix GbpVppProvider;
     }
 
     // Augments the 'configuration' choice node under modules/module.
index 283444aee57b610b97b727502d43cc1750d589fe..e15b1d7a85bfe03ccb28bc208c776628a356c4dd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -12,6 +12,8 @@ module vpp-renderer {
     namespace "urn:opendaylight:groupbasedpolicy:vpp_renderer";
     prefix "vpp-renderer";
 
+    import base-endpoint { prefix base-ep; revision-date 2016-04-27; }
+
     description
         "This module is a baseline for the group-based policy vpp renderer model.";
 
@@ -20,12 +22,25 @@ module vpp-renderer {
             "Initial revision.";
     }
 
-    import base-endpoint { prefix base-ep; revision-date 2016-04-27; }
-
     container config {
         list vpp-endpoint {
+            description "Renderer creates/removes interface on VPP node based on given parameters.";
+
             key "context-type context-id address-type address";
             uses base-ep:address-endpoint-key;
+
+            leaf vpp-node-path {
+                description "Path to a node representing mount-point to VPP instance.";
+                type instance-identifier;
+            }
+            leaf vpp-interface-name {
+                description "Name of interface for the endpoint on VPP";
+                type string;
+            }
+            leaf description {
+                description "Additional description of the vpp-endpoint";
+                type string;
+            }
             choice interface-type-choice {
                 case vhost-user-case {
                     leaf socket {
diff --git a/renderers/vpp/src/test/java/org/opendaylight/groupbasedpolicy/renderer/vpp/CustomDataBrokerTest.java b/renderers/vpp/src/test/java/org/opendaylight/groupbasedpolicy/renderer/vpp/CustomDataBrokerTest.java
new file mode 100644 (file)
index 0000000..1528320
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.renderer.vpp;
+
+import static com.google.common.base.Preconditions.checkState;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import javax.annotation.Nonnull;
+
+import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
+import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
+import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSet.Builder;
+
+/**
+ * Loads only modules of GBP and it's dependencies for data broker.
+ * <br>
+ * Therefore this implementation is faster than {@link AbstractDataBrokerTest}
+ */
+public abstract class CustomDataBrokerTest extends AbstractDataBrokerTest {
+
+    public static void loadModuleInfos(Class<?> clazzFromModule, Builder<YangModuleInfo> moduleInfoSet)
+            throws Exception {
+        YangModuleInfo moduleInfo = BindingReflections.getModuleInfo(clazzFromModule);
+        checkState(moduleInfo != null, "Module Info for %s is not available.", clazzFromModule);
+        collectYangModuleInfo(moduleInfo, moduleInfoSet);
+    }
+
+    private static void collectYangModuleInfo(final YangModuleInfo moduleInfo,
+            final Builder<YangModuleInfo> moduleInfoSet) throws IOException {
+        moduleInfoSet.add(moduleInfo);
+        for (YangModuleInfo dependency : moduleInfo.getImportedModules()) {
+            collectYangModuleInfo(dependency, moduleInfoSet);
+        }
+    }
+
+    @Override
+    protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
+        Builder<YangModuleInfo> moduleInfoSet = ImmutableSet.<YangModuleInfo>builder();
+        for (Class<?> clazz : getClassesFromModules()) {
+            loadModuleInfos(clazz, moduleInfoSet);
+        }
+        return moduleInfoSet.build();
+    }
+
+    /**
+     * @return a class from every yang module which needs to be loaded. Cannot return {@code null}
+     *         or empty collection.
+     */
+    public abstract @Nonnull Collection<Class<?>> getClassesFromModules();
+}
diff --git a/renderers/vpp/src/test/java/org/opendaylight/groupbasedpolicy/renderer/vpp/VppRendererDataBrokerTest.java b/renderers/vpp/src/test/java/org/opendaylight/groupbasedpolicy/renderer/vpp/VppRendererDataBrokerTest.java
new file mode 100644 (file)
index 0000000..8cd7458
--- /dev/null
@@ -0,0 +1,26 @@
+/*\r
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.groupbasedpolicy.renderer.vpp;\r
+\r
+import com.google.common.collect.ImmutableList;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.VhostUser;\r
+\r
+import javax.annotation.Nonnull;\r
+import java.util.Collection;\r
+\r
+public class VppRendererDataBrokerTest extends CustomDataBrokerTest {\r
+\r
+    @Nonnull\r
+    @Override\r
+    public Collection<Class<?>> getClassesFromModules() {\r
+        return ImmutableList.of(Interfaces.class, Interface.class, VhostUser.class);\r
+    }\r
+}\r
diff --git a/renderers/vpp/src/test/java/org/opendaylight/groupbasedpolicy/renderer/vpp/commands/VhostUserCommandTest.java b/renderers/vpp/src/test/java/org/opendaylight/groupbasedpolicy/renderer/vpp/commands/VhostUserCommandTest.java
new file mode 100644 (file)
index 0000000..63dc7b2
--- /dev/null
@@ -0,0 +1,183 @@
+/*\r
+ * Copyright (c) 2016 Cisco Systems. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.groupbasedpolicy.renderer.vpp.commands;\r
+\r
+import com.google.common.base.Optional;\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;\r
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;\r
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
+import org.opendaylight.groupbasedpolicy.renderer.vpp.VppRendererDataBrokerTest;\r
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;\r
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;\r
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VhostUserRole;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentation;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentationBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.L2Builder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.VhostUser;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.VhostUserBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.l2.interconnection.BridgeBased;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.l2.interconnection.BridgeBasedBuilder;\r
+\r
+public class VhostUserCommandTest extends VppRendererDataBrokerTest {\r
+\r
+    private final static String BRIDGE_DOMAIN = "testBD";\r
+    private final static String DESCRIPTION = "used for testing";\r
+    private final static String INTERFACE_NAME = "testInterface";\r
+    private final static String SOCKET_NAME = "soc1";\r
+\r
+    private final static String UPD_BRIDGE_DOMAIN = "testBD2";\r
+    private final static String UPD_DESCRIPTION = "updated description";\r
+    private final static String UPD_SOCKET_NAME = "soc2";\r
+    private final static short SPLIT_HORIZON_GROUP_DEFAULT = 0;\r
+    private final static boolean IS_BRIDGED_DEFAULT = false;\r
+\r
+    private static Interface BASIC_INTERFACE;\r
+\r
+    private DataBroker dataBroker;\r
+\r
+    @Before\r
+    public void init() {\r
+        dataBroker = getDataBroker();\r
+\r
+        VhostUser vhostUser = new VhostUserBuilder().setRole(VhostUserRole.Server).setSocket(SOCKET_NAME).build();\r
+\r
+        VppInterfaceAugmentation vppAugmentation = new VppInterfaceAugmentationBuilder().setVhostUser(vhostUser)\r
+            .setL2(new L2Builder().setInterconnection(new BridgeBasedBuilder().setBridgeDomain(BRIDGE_DOMAIN)\r
+                .setSplitHorizonGroup(SPLIT_HORIZON_GROUP_DEFAULT)\r
+                .setBridgedVirtualInterface(IS_BRIDGED_DEFAULT)\r
+                .build()).build())\r
+            .build();\r
+\r
+        BASIC_INTERFACE =\r
+                new InterfaceBuilder().setDescription(DESCRIPTION)\r
+                    .setEnabled(true)\r
+                    .setKey(new InterfaceKey(INTERFACE_NAME))\r
+                    .setName(INTERFACE_NAME)\r
+                    .setType(\r
+                            org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VhostUser.class)\r
+                    .setLinkUpDownTrapEnable(Interface.LinkUpDownTrapEnable.Enabled)\r
+                    .addAugmentation(VppInterfaceAugmentation.class, vppAugmentation)\r
+                    .build();\r
+    }\r
+\r
+    @Test\r
+    public void AddVhostTest() {\r
+        ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();\r
+        VhostUserCommand addCommand = VhostUserCommand.builder()\r
+            .setOperation(General.Operations.PUT)\r
+            .setName(INTERFACE_NAME)\r
+            .setDescription(DESCRIPTION)\r
+            .setRole(VhostUserRole.Server)\r
+            .setSocket(SOCKET_NAME)\r
+            .setBridgeDomain(BRIDGE_DOMAIN)\r
+            .setEnabled(true)\r
+            .build();\r
+\r
+        addCommand.execute(transaction);\r
+\r
+        transaction.submit();\r
+\r
+        ReadOnlyTransaction readOnlyTransaction = dataBroker.newReadOnlyTransaction();\r
+\r
+        Optional<Interface> optional = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,\r
+                VppIidFactory.getInterfaceIID(new InterfaceKey(INTERFACE_NAME)), readOnlyTransaction);\r
+\r
+        Assert.assertTrue("Interface was not written to DS", optional.isPresent());\r
+\r
+        Interface anInterface = optional.get();\r
+\r
+        Assert.assertEquals(BASIC_INTERFACE, anInterface);\r
+\r
+    }\r
+\r
+    @Test\r
+    public void DeleteVhostTest() {\r
+        ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();\r
+\r
+        transaction.put(LogicalDatastoreType.CONFIGURATION, VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()),\r
+                BASIC_INTERFACE, true);\r
+        transaction.submit();\r
+\r
+        Optional<Interface> optional = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,\r
+                VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()), dataBroker.newReadOnlyTransaction());\r
+\r
+        Assert.assertTrue("Interface was not written to DS", optional.isPresent());\r
+\r
+        VhostUserCommand deleteCommand = VhostUserCommand.builder()\r
+                .setOperation(General.Operations.DELETE)\r
+                .setName(INTERFACE_NAME)\r
+                .setSocket(SOCKET_NAME)\r
+                .build();\r
+\r
+        ReadWriteTransaction deleteTransaction = dataBroker.newReadWriteTransaction();\r
+        deleteCommand.execute(deleteTransaction);\r
+        deleteTransaction.submit();\r
+\r
+        Optional<Interface> optionalDeleted = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,\r
+                VppIidFactory.getInterfaceIID(new InterfaceKey(deleteCommand.getName())),\r
+                dataBroker.newReadOnlyTransaction());\r
+\r
+        Assert.assertFalse("Interface was not deleted from DS", optionalDeleted.isPresent());\r
+    }\r
+\r
+    @Test\r
+    public void UpdateVhostTest() {\r
+        ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();\r
+\r
+        transaction.put(LogicalDatastoreType.CONFIGURATION, VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()),\r
+                BASIC_INTERFACE, true);\r
+        transaction.submit();\r
+\r
+        Optional<Interface> optional = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,\r
+                VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()), dataBroker.newReadOnlyTransaction());\r
+\r
+        Assert.assertTrue("Interface was not written to DS", optional.isPresent());\r
+\r
+        VhostUserCommand updateCommand = VhostUserCommand.builder()\r
+            .setOperation(General.Operations.MERGE)\r
+            .setName(INTERFACE_NAME)\r
+            .setDescription(UPD_DESCRIPTION)\r
+            .setEnabled(false)\r
+            .setRole(VhostUserRole.Client)\r
+            .setSocket(UPD_SOCKET_NAME)\r
+            .setBridgeDomain(UPD_BRIDGE_DOMAIN)\r
+            .build();\r
+\r
+        ReadWriteTransaction deleteTransaction = dataBroker.newReadWriteTransaction();\r
+        updateCommand.execute(deleteTransaction);\r
+        deleteTransaction.submit();\r
+\r
+        Optional<Interface> optionalUpdated = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,\r
+                VppIidFactory.getInterfaceIID(new InterfaceKey(updateCommand.getName())),\r
+                dataBroker.newReadOnlyTransaction());\r
+\r
+        Assert.assertTrue("Interface was not found in DS", optionalUpdated.isPresent());\r
+        Interface updatedInterface = optionalUpdated.get();\r
+\r
+        Assert.assertEquals(UPD_DESCRIPTION, updatedInterface.getDescription());\r
+        Assert.assertFalse(updatedInterface.isEnabled());\r
+        VppInterfaceAugmentation vppInterfaceAugmentation =\r
+                updatedInterface.getAugmentation(VppInterfaceAugmentation.class);\r
+        Assert.assertEquals(VhostUserRole.Client, vppInterfaceAugmentation.getVhostUser().getRole());\r
+        Assert.assertEquals(UPD_SOCKET_NAME, vppInterfaceAugmentation.getVhostUser().getSocket());\r
+\r
+        Assert.assertTrue(vppInterfaceAugmentation.getL2().getInterconnection() instanceof BridgeBased);\r
+\r
+        Assert.assertEquals(UPD_BRIDGE_DOMAIN,\r
+                ((BridgeBased) vppInterfaceAugmentation.getL2().getInterconnection()).getBridgeDomain());\r
+    }\r
+}\r
index 0eac9d76448de4d9f21786a050c62a045493b817..cc720f7ba690371e38a9f2d8d33ab2d1f4b061e0 100755 (executable)
@@ -57,7 +57,7 @@
         </dependency>
         <dependency>
             <groupId>org.opendaylight.groupbasedpolicy</groupId>
-            <artifactId>groupbasedpolicy</artifactId>
+            <artifactId>l2-l3-domain-extension</artifactId>
         </dependency>
 
         <!-- sxp deps -->