Fix fileEncoding violations for checkstyle 92/64692/1
authorMichal Cmarada <mcmarada@cisco.com>
Mon, 2 Oct 2017 17:08:43 +0000 (19:08 +0200)
committerMichal Cmarada <mcmarada@cisco.com>
Wed, 25 Oct 2017 08:09:24 +0000 (10:09 +0200)
Change-Id: I231402a076acdc315ff13166573f5b1200b1c099
Signed-off-by: Michal Cmarada <mcmarada@cisco.com>
58 files changed:
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/dto/ValidationResultBuilder.java
groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/resolver/validator/ValidationResultTest.java
neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/SecRuleEntityDecoder.java
neutron-vpp-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/vpp/mapper/NeutronVppMapper.java
neutron-vpp-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/vpp/mapper/SocketInfo.java
neutron-vpp-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/vpp/mapper/hostconfigs/VppNodeListener.java
neutron-vpp-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/vpp/mapper/processors/MappingProvider.java
neutron-vpp-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/vpp/mapper/processors/NeutronListener.java
neutron-vpp-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/vpp/mapper/processors/PortAware.java
neutron-vpp-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/vpp/mapper/processors/PortHandler.java
neutron-vpp-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/vpp/mapper/util/HostconfigUtil.java
neutron-vpp-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/vpp/mapper/hostconfigs/TestResources.java
neutron-vpp-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/vpp/mapper/hostconfigs/VppNodeListenerTest.java
neutron-vpp-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/vpp/mapper/processors/NetworkAwareTest.java
neutron-vpp-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/vpp/mapper/processors/NeutronListenerTest.java
neutron-vpp-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/vpp/mapper/processors/TestUtils.java
neutron-vpp-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/vpp/mapper/util/HostconfigUtilTest.java
renderers/iovisor/src/test/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/endpoint/EndpointListenerCovrgTest.java
renderers/iovisor/src/test/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/endpoint/IovisorEndpointAugCovrgTest.java
renderers/iovisor/src/test/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/sf/ActionDefinitionListenerTest.java
renderers/iovisor/src/test/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/sf/AllowActionTest.java
renderers/iovisor/src/test/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/sf/ClassificationResultTest.java
renderers/iovisor/src/test/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/sf/ClassifierDefinitionListenerTest.java
renderers/iovisor/src/test/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/sf/EtherTypeClassifierTest.java
renderers/iovisor/src/test/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/sf/IpProtoClassifierTest.java
renderers/iovisor/src/test/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/sf/L4ClassifierTest.java
renderers/iovisor/src/test/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/sf/ParamDerivatorTest.java
renderers/iovisor/src/test/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/sf/SubjectFeaturesTest.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/mapper/policyenforcer/NetworkElements.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/endpoint/OfOverlayAugTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/endpoint/OfOverlayL3NatAugTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/ChainActionFlowsTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/FlowTableTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/OfTableTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/mapper/MapperUtilsTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/sf/ActionDefinitionListenerTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/sf/ClassifierDefinitionListenerTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/OFStatisticsManagerTest.java
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/SflowClientSettingsListenerTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/flowcache/FlowCacheBuilderTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/flowcache/FlowCacheDefinitionBuilderTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/flowcache/FlowCacheDefinitionTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/flowcache/FlowCacheFactoryTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/flowcache/FlowCacheFilterBuilderTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/flowcache/FlowCacheFilterTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/flowcache/FlowCacheKeysBuilderTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/flowcache/FlowCacheKeysTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/flowcache/FlowCacheTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/statistics/util/IidSflowNameUtilTest.java
renderers/vpp/src/main/java/org/opendaylight/groupbasedpolicy/renderer/vpp/nat/NatManager.java
renderers/vpp/src/main/java/org/opendaylight/groupbasedpolicy/renderer/vpp/nat/NatUtil.java
renderers/vpp/src/test/java/org/opendaylight/groupbasedpolicy/renderer/vpp/VppRendererDataBrokerTest.java
renderers/vpp/src/test/java/org/opendaylight/groupbasedpolicy/renderer/vpp/commands/LoopbackCommandTest.java
renderers/vpp/src/test/java/org/opendaylight/groupbasedpolicy/renderer/vpp/commands/TapPortCommandTest.java
renderers/vpp/src/test/java/org/opendaylight/groupbasedpolicy/renderer/vpp/commands/VhostUserCommandTest.java
renderers/vpp/src/test/java/org/opendaylight/groupbasedpolicy/renderer/vpp/sf/L4ClassifierTest.java

index 3e22b658ac751dbfaa01c5ebfd3fcd567dd58477..5704e8bce59db1e132468513b9ffa62b3868e2b5 100755 (executable)
@@ -1,96 +1,96 @@
-/*\r
- * Copyright (c) 2015 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
-package org.opendaylight.groupbasedpolicy.dto;\r
-\r
-import javax.annotation.Nonnull;\r
-\r
-import org.opendaylight.groupbasedpolicy.api.ValidationResult;\r
-import org.opendaylight.yangtools.concepts.Builder;\r
-\r
-public final class ValidationResultBuilder implements Builder<ValidationResult> {\r
-\r
-    public static final String ILLEGAL_ARG_EX_MSG = "Result message cannot be set to NULL!";\r
-\r
-    private static final class ValidationResultImpl implements ValidationResult {\r
-\r
-        private final boolean success;\r
-        private final String message;\r
-\r
-        private ValidationResultImpl(final boolean success, final String message) {\r
-            this.success = success;\r
-            this.message = message;\r
-        }\r
-\r
-        @Override\r
-        public boolean isValid() {\r
-            return success;\r
-        }\r
-\r
-        @Override\r
-        public String getMessage() {\r
-            return message;\r
-        }\r
-\r
-        @Override\r
-        public boolean equals(Object o) {\r
-            if (this == o)\r
-                return true;\r
-            if (o == null || getClass() != o.getClass())\r
-                return false;\r
-\r
-            ValidationResultImpl that = (ValidationResultImpl) o;\r
-\r
-            if (success != that.success)\r
-                return false;\r
-            return message.equals(that.message);\r
-        }\r
-\r
-        @Override\r
-        public int hashCode() {\r
-            int result = (success ? 1 : 0);\r
-            result = 31 * result + message.hashCode();\r
-            return result;\r
-        }\r
-    }\r
-\r
-    private boolean success;\r
-    private String message = "";\r
-\r
-    public ValidationResultBuilder success() {\r
-        this.success = true;\r
-        return this;\r
-    }\r
-\r
-    /**\r
-     * Returns a builder for a failed result.\r
-     */\r
-    public ValidationResultBuilder failed() {\r
-        this.success = false;\r
-        return this;\r
-    }\r
-\r
-    /**\r
-     * Returns a builder for a failed result.\r
-     *\r
-     * @param message brief explanation\r
-     * @throws IllegalArgumentException when message is null\r
-     */\r
-    public ValidationResultBuilder setMessage(@Nonnull String message) {\r
-        if (message == null) {\r
-            throw new IllegalArgumentException(ILLEGAL_ARG_EX_MSG);\r
-        }\r
-        this.message = message;\r
-        return this;\r
-    }\r
-\r
-    @Override\r
-    public ValidationResult build() {\r
-        return new ValidationResultImpl(success, message);\r
-    }\r
-\r
-}\r
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.dto;
+
+import javax.annotation.Nonnull;
+
+import org.opendaylight.groupbasedpolicy.api.ValidationResult;
+import org.opendaylight.yangtools.concepts.Builder;
+
+public final class ValidationResultBuilder implements Builder<ValidationResult> {
+
+    public static final String ILLEGAL_ARG_EX_MSG = "Result message cannot be set to NULL!";
+
+    private static final class ValidationResultImpl implements ValidationResult {
+
+        private final boolean success;
+        private final String message;
+
+        private ValidationResultImpl(final boolean success, final String message) {
+            this.success = success;
+            this.message = message;
+        }
+
+        @Override
+        public boolean isValid() {
+            return success;
+        }
+
+        @Override
+        public String getMessage() {
+            return message;
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o)
+                return true;
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            ValidationResultImpl that = (ValidationResultImpl) o;
+
+            if (success != that.success)
+                return false;
+            return message.equals(that.message);
+        }
+
+        @Override
+        public int hashCode() {
+            int result = (success ? 1 : 0);
+            result = 31 * result + message.hashCode();
+            return result;
+        }
+    }
+
+    private boolean success;
+    private String message = "";
+
+    public ValidationResultBuilder success() {
+        this.success = true;
+        return this;
+    }
+
+    /**
+     * Returns a builder for a failed result.
+     */
+    public ValidationResultBuilder failed() {
+        this.success = false;
+        return this;
+    }
+
+    /**
+     * Returns a builder for a failed result.
+     *
+     * @param message brief explanation
+     * @throws IllegalArgumentException when message is null
+     */
+    public ValidationResultBuilder setMessage(@Nonnull String message) {
+        if (message == null) {
+            throw new IllegalArgumentException(ILLEGAL_ARG_EX_MSG);
+        }
+        this.message = message;
+        return this;
+    }
+
+    @Override
+    public ValidationResult build() {
+        return new ValidationResultImpl(success, message);
+    }
+
+}
index 33ed72c52296a6a0f162a7067e6ff362fa676b87..d9fa859ee2f5de4736034e60df20dd1bf6ba5e5f 100755 (executable)
@@ -1,62 +1,62 @@
-/*\r
- * Copyright (c) 2015 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.resolver.validator;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertTrue;\r
-\r
-import org.junit.Before;\r
-import org.junit.Rule;\r
-import org.junit.Test;\r
-import org.junit.rules.ExpectedException;\r
-import org.opendaylight.groupbasedpolicy.api.ValidationResult;\r
-import org.opendaylight.groupbasedpolicy.dto.ValidationResultBuilder;\r
-\r
-public class ValidationResultTest {\r
-\r
-    @Rule\r
-    public ExpectedException thrown = ExpectedException.none();\r
-\r
-    public static final String VALIDATED = "Validated.";\r
-    public static final String EMPTY_STRING = "";\r
-\r
-    ValidationResultBuilder resultBuilder;\r
-\r
-    @Before\r
-    public void init() {\r
-        resultBuilder = new ValidationResultBuilder();\r
-    }\r
-\r
-    @Test\r
-    public void testBuild_WithSuccess() {\r
-        ValidationResult result = resultBuilder.success().build();\r
-        assertTrue(result.isValid());\r
-        assertEquals(EMPTY_STRING, result.getMessage());\r
-    }\r
-\r
-    @Test\r
-    public void testBuild_WithFailed() {\r
-        ValidationResult result = resultBuilder.failed().build();\r
-        assertFalse(result.isValid());\r
-        assertEquals(EMPTY_STRING, result.getMessage());\r
-    }\r
-\r
-    @Test\r
-    public void testMessage() {\r
-        ValidationResult result = resultBuilder.setMessage(VALIDATED).build();\r
-\r
-        assertEquals(VALIDATED, result.getMessage());\r
-\r
-        thrown.expect(IllegalArgumentException.class);\r
-        thrown.expectMessage(ValidationResultBuilder.ILLEGAL_ARG_EX_MSG);\r
-        resultBuilder.setMessage(null);\r
-    }\r
-\r
-}\r
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.resolver.validator;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.opendaylight.groupbasedpolicy.api.ValidationResult;
+import org.opendaylight.groupbasedpolicy.dto.ValidationResultBuilder;
+
+public class ValidationResultTest {
+
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
+
+    public static final String VALIDATED = "Validated.";
+    public static final String EMPTY_STRING = "";
+
+    ValidationResultBuilder resultBuilder;
+
+    @Before
+    public void init() {
+        resultBuilder = new ValidationResultBuilder();
+    }
+
+    @Test
+    public void testBuild_WithSuccess() {
+        ValidationResult result = resultBuilder.success().build();
+        assertTrue(result.isValid());
+        assertEquals(EMPTY_STRING, result.getMessage());
+    }
+
+    @Test
+    public void testBuild_WithFailed() {
+        ValidationResult result = resultBuilder.failed().build();
+        assertFalse(result.isValid());
+        assertEquals(EMPTY_STRING, result.getMessage());
+    }
+
+    @Test
+    public void testMessage() {
+        ValidationResult result = resultBuilder.setMessage(VALIDATED).build();
+
+        assertEquals(VALIDATED, result.getMessage());
+
+        thrown.expect(IllegalArgumentException.class);
+        thrown.expectMessage(ValidationResultBuilder.ILLEGAL_ARG_EX_MSG);
+        resultBuilder.setMessage(null);
+    }
+
+}
index 47a60adc0ce40e43e69cea13e8ae2f1a80cee171..c5255bbfdad06b18a05f8185d810da2783503081 100755 (executable)
-/*\r
- * Copyright (c) 2014 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.neutron.mapper.mapping.rule;\r
-\r
-import static com.google.common.base.Preconditions.checkNotNull;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.opendaylight.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition;\r
-import org.opendaylight.groupbasedpolicy.api.sf.IpProtoClassifierDefinition;\r
-import org.opendaylight.groupbasedpolicy.api.sf.L4ClassifierDefinition;\r
-import org.opendaylight.groupbasedpolicy.neutron.mapper.util.MappingUtils;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;\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.ParameterName;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubjectName;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.change.action.of.security.group.rules.input.action.ActionChoice;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.change.action.of.security.group.rules.input.action.action.choice.AllowActionCase;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.change.action.of.security.group.rules.input.action.action.choice.SfcActionCase;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.HasDirection.Direction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.action.refs.ActionRef;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.classifier.refs.ClassifierRef;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.classifier.refs.ClassifierRef.ConnectionTracking;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.classifier.refs.ClassifierRefBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.endpoint.identification.constraints.EndpointIdentificationConstraints;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.endpoint.identification.constraints.EndpointIdentificationConstraintsBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.endpoint.identification.constraints.endpoint.identification.constraints.L3EndpointIdentificationConstraintsBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.endpoint.identification.constraints.endpoint.identification.constraints.l3.endpoint.identification.constraints.PrefixConstraint;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.endpoint.identification.constraints.endpoint.identification.constraints.l3.endpoint.identification.constraints.PrefixConstraintBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.parameter.value.RangeValueBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.Clause;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.ClauseBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.clause.ConsumerMatchers;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.clause.ConsumerMatchersBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ClassifierInstance;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ClassifierInstanceBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.DirectionBase;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.DirectionEgress;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.DirectionIngress;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.EthertypeBase;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.EthertypeV4;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.EthertypeV6;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProtocolBase;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProtocolIcmp;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProtocolIcmpV6;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProtocolTcp;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProtocolUdp;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.SecurityRuleAttributes;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.rules.attributes.security.rules.SecurityRule;\r
-\r
-import com.google.common.collect.ImmutableList;\r
-\r
-public class SecRuleEntityDecoder {\r
-\r
-    private SecRuleEntityDecoder() {\r
-        throw new UnsupportedOperationException("Cannot create an instace.");\r
-    }\r
-\r
-    public static ContractId getContractId(SecurityRule secRule) {\r
-        return new ContractId(secRule.getUuid().getValue());\r
-    }\r
-\r
-    public static ClassifierInstance getClassifierInstance(SecurityRule secRule) {\r
-        ClassifierInstanceBuilder classifierBuilder = new ClassifierInstanceBuilder();\r
-        List<ParameterValue> params = new ArrayList<>();\r
-        Integer portMin = secRule.getPortRangeMin();\r
-        Integer portMax = secRule.getPortRangeMax();\r
-        if (portMin != null && portMax != null) {\r
-            classifierBuilder.setClassifierDefinitionId(L4ClassifierDefinition.DEFINITION.getId());\r
-            if (portMin.equals(portMax)) {\r
-                params.add(new ParameterValueBuilder().setName(new ParameterName(L4ClassifierDefinition.DST_PORT_PARAM))\r
-                    .setIntValue(portMin.longValue())\r
-                    .build());\r
-            } else {\r
-                params.add(new ParameterValueBuilder().setName(new ParameterName(L4ClassifierDefinition.DST_PORT_RANGE_PARAM))\r
-                    .setRangeValue(\r
-                            new RangeValueBuilder().setMin(portMin.longValue()).setMax(portMax.longValue()).build())\r
-                    .build());\r
-            }\r
-        }\r
-        Long protocol = getProtocol(secRule);\r
-        if (protocol != null) {\r
-            if (classifierBuilder.getClassifierDefinitionId() == null) {\r
-                classifierBuilder.setClassifierDefinitionId(IpProtoClassifierDefinition.DEFINITION.getId());\r
-            }\r
-            params.add(new ParameterValueBuilder().setName(new ParameterName(IpProtoClassifierDefinition.PROTO_PARAM))\r
-                .setIntValue(protocol)\r
-                .build());\r
-        }\r
-        Long ethertype = getEtherType(secRule);\r
-        if (ethertype != null) {\r
-            if (classifierBuilder.getClassifierDefinitionId() == null) {\r
-                classifierBuilder.setClassifierDefinitionId(EtherTypeClassifierDefinition.DEFINITION.getId());\r
-            }\r
-            params.add(new ParameterValueBuilder().setName(new ParameterName(EtherTypeClassifierDefinition.ETHERTYPE_PARAM))\r
-                .setIntValue(ethertype)\r
-                .build());\r
-        }\r
-        ClassifierName classifierName = SecRuleNameDecoder.getClassifierInstanceName(secRule);\r
-        return classifierBuilder.setParameterValue(params).setName(new ClassifierName(classifierName)).build();\r
-    }\r
-\r
-    public static ActionRef createActionRefFromActionChoice(ActionChoice action) {\r
-        if(action instanceof SfcActionCase){\r
-            return MappingUtils.createSfcActionRef(((SfcActionCase) action).getSfcChainName());\r
-        } else if (action instanceof AllowActionCase) {\r
-            return MappingUtils.ACTION_REF_ALLOW;\r
-        }\r
-        return null;\r
-    }\r
-\r
-    public static ClassifierRef getClassifierRef(SecurityRule secRule) {\r
-        checkNotNull(secRule);\r
-        ClassifierName classifierInstanceName = SecRuleNameDecoder.getClassifierInstanceName(secRule);\r
-        ClassifierRefBuilder classifierRefBuilder = new ClassifierRefBuilder()\r
-            .setConnectionTracking(ConnectionTracking.Reflexive).setInstanceName(classifierInstanceName);\r
-        Direction direction = getDirection(secRule);\r
-        classifierRefBuilder.setDirection(direction);\r
-        ClassifierName classifierRefName = SecRuleNameDecoder.getClassifierRefName(secRule);\r
-        return classifierRefBuilder.setName(classifierRefName).build();\r
-    }\r
-\r
-    /**\r
-     * @param secRule\r
-     * @return direction resolved from {@link SecurityRule#getDirection()}\r
-     * @throws IllegalArgumentException if return value of\r
-     *         {@link SecurityRule#getDirection()} is other than {@link DirectionIngress} or\r
-     *         {@link DirectionEgress}\r
-     */\r
-    public static Direction getDirection(SecurityRule secRule) {\r
-        Class<? extends DirectionBase> direction = secRule.getDirection();\r
-        if (direction == null) {\r
-            throw new IllegalArgumentException("Direction cannot be null.");\r
-        }\r
-        if (direction.isAssignableFrom(DirectionIngress.class)) {\r
-            return Direction.In;\r
-        }\r
-        if (direction.isAssignableFrom(DirectionEgress.class)) {\r
-            return Direction.Out;\r
-        }\r
-        throw new IllegalArgumentException("Direction " + direction + " from security group rule "\r
-                + secRule + " is not supported. Direction can be only 'ingress' or 'egress'.");\r
-    }\r
-\r
-    /**\r
-     * @param secRule {@link SecurityRule#getRemoteIpPrefix()} is used for EIC\r
-     *        and subject selection\r
-     * @return clause with the subject and with a consumer matcher containing EIC\r
-     */\r
-    public static Clause getClause(SecurityRule secRule) {\r
-        checkNotNull(secRule);\r
-        SubjectName subjectName = SecRuleNameDecoder.getSubjectName(secRule);\r
-        ClauseBuilder clauseBuilder =\r
-                new ClauseBuilder().setSubjectRefs(ImmutableList.of(subjectName)).setName(SecRuleNameDecoder.getClauseName(secRule));\r
-        IpPrefix remoteIpPrefix = secRule.getRemoteIpPrefix();\r
-        if (remoteIpPrefix != null) {\r
-            clauseBuilder.setConsumerMatchers(createConsumerMatchersWithEic(remoteIpPrefix));\r
-        }\r
-        return clauseBuilder.build();\r
-    }\r
-\r
-    private static ConsumerMatchers createConsumerMatchersWithEic(IpPrefix ipPrefix) {\r
-        PrefixConstraint consumerPrefixConstraint = new PrefixConstraintBuilder().setIpPrefix(ipPrefix).build();\r
-        EndpointIdentificationConstraints eic =\r
-                new EndpointIdentificationConstraintsBuilder()\r
-                    .setL3EndpointIdentificationConstraints(new L3EndpointIdentificationConstraintsBuilder()\r
-                        .setPrefixConstraint(ImmutableList.<PrefixConstraint>of(consumerPrefixConstraint)).build())\r
-                    .build();\r
-        return new ConsumerMatchersBuilder().setEndpointIdentificationConstraints(eic).build();\r
-    }\r
-\r
-    public static boolean isEtherTypeOfOneWithinTwo(SecurityRule one, SecurityRule two) {\r
-        Long oneEtherType = getEtherType(one);\r
-        Long twoEtherType = getEtherType(two);\r
-        return twoIsNullOrEqualsOne(oneEtherType, twoEtherType);\r
-    }\r
-\r
-    public static boolean isProtocolOfOneWithinTwo(SecurityRule one, SecurityRule two) {\r
-        Long oneProtocol = getProtocol(one);\r
-        Long twoProtocol = getProtocol(two);\r
-        return twoIsNullOrEqualsOne(oneProtocol, twoProtocol);\r
-    }\r
-\r
-    private static <T> boolean twoIsNullOrEqualsOne(T one, T two) {\r
-        if (two == null)\r
-            return true;\r
-        if (two.equals(one))\r
-            return true;\r
-        return false;\r
-    }\r
-\r
-    public static boolean isPortsOfOneWithinTwo(SecurityRule one, SecurityRule two) {\r
-        Integer onePortMin = one.getPortRangeMin();\r
-        Integer onePortMax = one.getPortRangeMax();\r
-        Integer twoPortMin = two.getPortRangeMin();\r
-        Integer twoPortMax = two.getPortRangeMax();\r
-        if (twoPortMin == null && twoPortMax == null) {\r
-            return true;\r
-        }\r
-        if ((onePortMin != null && twoPortMin != null && onePortMin >= twoPortMin)\r
-                && (onePortMax != null && twoPortMax != null && onePortMax <= twoPortMax)) {\r
-            return true;\r
-        }\r
-        return false;\r
-    }\r
-\r
-    /**\r
-     * @param secRule\r
-     * @return {@code null} if {@link SecurityRule#getEthertype()} is null; Otherwise ethertype\r
-     *         number\r
-     * @throws IllegalArgumentException if return value of\r
-     *         {@link SecurityRule#getEthertype()} is other {@link EthertypeV4} or\r
-     *         {@link EthertypeV6}\r
-     */\r
-    public static Long getEtherType(SecurityRule secRule) {\r
-        Class<? extends EthertypeBase> ethertype = secRule.getEthertype();\r
-        if (ethertype == null) {\r
-            return null;\r
-        }\r
-        if (ethertype.isAssignableFrom(EthertypeV4.class)) {\r
-            return EtherTypeClassifierDefinition.IPv4_VALUE;\r
-        }\r
-        if (ethertype.isAssignableFrom(EthertypeV6.class)) {\r
-            return EtherTypeClassifierDefinition.IPv6_VALUE;\r
-        }\r
-        throw new IllegalArgumentException("Ethertype " + ethertype + " is not supported.");\r
-    }\r
-\r
-    /**\r
-     * @param secRule\r
-     * @return {@code null} if {@link SecurityRule#getProtocol()} is null; Otherwise protocol number\r
-     * @throws IllegalArgumentException if return value of\r
-     *         {@link SecurityRule#getProtocol()} is other than {@link ProtocolTcp},\r
-     *         {@link ProtocolUdp}, {@link ProtocolIcmp}, {@link ProtocolIcmpV6}\r
-     */\r
-    public static Long getProtocol(SecurityRule secRule) {\r
-        SecurityRuleAttributes.Protocol protocol = secRule.getProtocol();\r
-        if (protocol == null) {\r
-            return null;\r
-        }\r
-        if (protocol.getUint8() != null) {\r
-            return protocol.getUint8().longValue();\r
-        }\r
-        if (protocol.getIdentityref() != null) {\r
-            if (protocol.getIdentityref().equals(ProtocolTcp.class)) {\r
-                return IpProtoClassifierDefinition.TCP_VALUE;\r
-            }\r
-            if (protocol.getIdentityref().equals(ProtocolUdp.class)) {\r
-                return IpProtoClassifierDefinition.UDP_VALUE;\r
-            }\r
-            if (protocol.getIdentityref().equals(ProtocolIcmp.class)) {\r
-                return IpProtoClassifierDefinition.ICMP_VALUE;\r
-            }\r
-            if (protocol.getIdentityref().equals(ProtocolIcmpV6.class)) {\r
-                return IpProtoClassifierDefinition.ICMPv6_VALUE;\r
-            }\r
-        }\r
-        throw new IllegalArgumentException("Neutron Security Rule Protocol value " + protocol + " is not supported.");\r
-    }\r
-}\r
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.rule;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.opendaylight.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition;
+import org.opendaylight.groupbasedpolicy.api.sf.IpProtoClassifierDefinition;
+import org.opendaylight.groupbasedpolicy.api.sf.L4ClassifierDefinition;
+import org.opendaylight.groupbasedpolicy.neutron.mapper.util.MappingUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+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.ParameterName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubjectName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.change.action.of.security.group.rules.input.action.ActionChoice;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.change.action.of.security.group.rules.input.action.action.choice.AllowActionCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.change.action.of.security.group.rules.input.action.action.choice.SfcActionCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.HasDirection.Direction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.action.refs.ActionRef;
+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.has.classifier.refs.ClassifierRef.ConnectionTracking;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.classifier.refs.ClassifierRefBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.endpoint.identification.constraints.EndpointIdentificationConstraints;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.endpoint.identification.constraints.EndpointIdentificationConstraintsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.endpoint.identification.constraints.endpoint.identification.constraints.L3EndpointIdentificationConstraintsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.endpoint.identification.constraints.endpoint.identification.constraints.l3.endpoint.identification.constraints.PrefixConstraint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.endpoint.identification.constraints.endpoint.identification.constraints.l3.endpoint.identification.constraints.PrefixConstraintBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.parameter.value.RangeValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.Clause;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.ClauseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.clause.ConsumerMatchers;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.clause.ConsumerMatchersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ClassifierInstance;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ClassifierInstanceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.DirectionBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.DirectionEgress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.DirectionIngress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.EthertypeBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.EthertypeV4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.EthertypeV6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProtocolBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProtocolIcmp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProtocolIcmpV6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProtocolTcp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProtocolUdp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.SecurityRuleAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.rules.attributes.security.rules.SecurityRule;
+
+import com.google.common.collect.ImmutableList;
+
+public class SecRuleEntityDecoder {
+
+    private SecRuleEntityDecoder() {
+        throw new UnsupportedOperationException("Cannot create an instace.");
+    }
+
+    public static ContractId getContractId(SecurityRule secRule) {
+        return new ContractId(secRule.getUuid().getValue());
+    }
+
+    public static ClassifierInstance getClassifierInstance(SecurityRule secRule) {
+        ClassifierInstanceBuilder classifierBuilder = new ClassifierInstanceBuilder();
+        List<ParameterValue> params = new ArrayList<>();
+        Integer portMin = secRule.getPortRangeMin();
+        Integer portMax = secRule.getPortRangeMax();
+        if (portMin != null && portMax != null) {
+            classifierBuilder.setClassifierDefinitionId(L4ClassifierDefinition.DEFINITION.getId());
+            if (portMin.equals(portMax)) {
+                params.add(new ParameterValueBuilder().setName(new ParameterName(L4ClassifierDefinition.DST_PORT_PARAM))
+                    .setIntValue(portMin.longValue())
+                    .build());
+            } else {
+                params.add(new ParameterValueBuilder().setName(new ParameterName(L4ClassifierDefinition.DST_PORT_RANGE_PARAM))
+                    .setRangeValue(
+                            new RangeValueBuilder().setMin(portMin.longValue()).setMax(portMax.longValue()).build())
+                    .build());
+            }
+        }
+        Long protocol = getProtocol(secRule);
+        if (protocol != null) {
+            if (classifierBuilder.getClassifierDefinitionId() == null) {
+                classifierBuilder.setClassifierDefinitionId(IpProtoClassifierDefinition.DEFINITION.getId());
+            }
+            params.add(new ParameterValueBuilder().setName(new ParameterName(IpProtoClassifierDefinition.PROTO_PARAM))
+                .setIntValue(protocol)
+                .build());
+        }
+        Long ethertype = getEtherType(secRule);
+        if (ethertype != null) {
+            if (classifierBuilder.getClassifierDefinitionId() == null) {
+                classifierBuilder.setClassifierDefinitionId(EtherTypeClassifierDefinition.DEFINITION.getId());
+            }
+            params.add(new ParameterValueBuilder().setName(new ParameterName(EtherTypeClassifierDefinition.ETHERTYPE_PARAM))
+                .setIntValue(ethertype)
+                .build());
+        }
+        ClassifierName classifierName = SecRuleNameDecoder.getClassifierInstanceName(secRule);
+        return classifierBuilder.setParameterValue(params).setName(new ClassifierName(classifierName)).build();
+    }
+
+    public static ActionRef createActionRefFromActionChoice(ActionChoice action) {
+        if(action instanceof SfcActionCase){
+            return MappingUtils.createSfcActionRef(((SfcActionCase) action).getSfcChainName());
+        } else if (action instanceof AllowActionCase) {
+            return MappingUtils.ACTION_REF_ALLOW;
+        }
+        return null;
+    }
+
+    public static ClassifierRef getClassifierRef(SecurityRule secRule) {
+        checkNotNull(secRule);
+        ClassifierName classifierInstanceName = SecRuleNameDecoder.getClassifierInstanceName(secRule);
+        ClassifierRefBuilder classifierRefBuilder = new ClassifierRefBuilder()
+            .setConnectionTracking(ConnectionTracking.Reflexive).setInstanceName(classifierInstanceName);
+        Direction direction = getDirection(secRule);
+        classifierRefBuilder.setDirection(direction);
+        ClassifierName classifierRefName = SecRuleNameDecoder.getClassifierRefName(secRule);
+        return classifierRefBuilder.setName(classifierRefName).build();
+    }
+
+    /**
+     * @param secRule
+     * @return direction resolved from {@link SecurityRule#getDirection()}
+     * @throws IllegalArgumentException if return value of
+     *         {@link SecurityRule#getDirection()} is other than {@link DirectionIngress} or
+     *         {@link DirectionEgress}
+     */
+    public static Direction getDirection(SecurityRule secRule) {
+        Class<? extends DirectionBase> direction = secRule.getDirection();
+        if (direction == null) {
+            throw new IllegalArgumentException("Direction cannot be null.");
+        }
+        if (direction.isAssignableFrom(DirectionIngress.class)) {
+            return Direction.In;
+        }
+        if (direction.isAssignableFrom(DirectionEgress.class)) {
+            return Direction.Out;
+        }
+        throw new IllegalArgumentException("Direction " + direction + " from security group rule "
+                + secRule + " is not supported. Direction can be only 'ingress' or 'egress'.");
+    }
+
+    /**
+     * @param secRule {@link SecurityRule#getRemoteIpPrefix()} is used for EIC
+     *        and subject selection
+     * @return clause with the subject and with a consumer matcher containing EIC
+     */
+    public static Clause getClause(SecurityRule secRule) {
+        checkNotNull(secRule);
+        SubjectName subjectName = SecRuleNameDecoder.getSubjectName(secRule);
+        ClauseBuilder clauseBuilder =
+                new ClauseBuilder().setSubjectRefs(ImmutableList.of(subjectName)).setName(SecRuleNameDecoder.getClauseName(secRule));
+        IpPrefix remoteIpPrefix = secRule.getRemoteIpPrefix();
+        if (remoteIpPrefix != null) {
+            clauseBuilder.setConsumerMatchers(createConsumerMatchersWithEic(remoteIpPrefix));
+        }
+        return clauseBuilder.build();
+    }
+
+    private static ConsumerMatchers createConsumerMatchersWithEic(IpPrefix ipPrefix) {
+        PrefixConstraint consumerPrefixConstraint = new PrefixConstraintBuilder().setIpPrefix(ipPrefix).build();
+        EndpointIdentificationConstraints eic =
+                new EndpointIdentificationConstraintsBuilder()
+                    .setL3EndpointIdentificationConstraints(new L3EndpointIdentificationConstraintsBuilder()
+                        .setPrefixConstraint(ImmutableList.<PrefixConstraint>of(consumerPrefixConstraint)).build())
+                    .build();
+        return new ConsumerMatchersBuilder().setEndpointIdentificationConstraints(eic).build();
+    }
+
+    public static boolean isEtherTypeOfOneWithinTwo(SecurityRule one, SecurityRule two) {
+        Long oneEtherType = getEtherType(one);
+        Long twoEtherType = getEtherType(two);
+        return twoIsNullOrEqualsOne(oneEtherType, twoEtherType);
+    }
+
+    public static boolean isProtocolOfOneWithinTwo(SecurityRule one, SecurityRule two) {
+        Long oneProtocol = getProtocol(one);
+        Long twoProtocol = getProtocol(two);
+        return twoIsNullOrEqualsOne(oneProtocol, twoProtocol);
+    }
+
+    private static <T> boolean twoIsNullOrEqualsOne(T one, T two) {
+        if (two == null)
+            return true;
+        if (two.equals(one))
+            return true;
+        return false;
+    }
+
+    public static boolean isPortsOfOneWithinTwo(SecurityRule one, SecurityRule two) {
+        Integer onePortMin = one.getPortRangeMin();
+        Integer onePortMax = one.getPortRangeMax();
+        Integer twoPortMin = two.getPortRangeMin();
+        Integer twoPortMax = two.getPortRangeMax();
+        if (twoPortMin == null && twoPortMax == null) {
+            return true;
+        }
+        if ((onePortMin != null && twoPortMin != null && onePortMin >= twoPortMin)
+                && (onePortMax != null && twoPortMax != null && onePortMax <= twoPortMax)) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * @param secRule
+     * @return {@code null} if {@link SecurityRule#getEthertype()} is null; Otherwise ethertype
+     *         number
+     * @throws IllegalArgumentException if return value of
+     *         {@link SecurityRule#getEthertype()} is other {@link EthertypeV4} or
+     *         {@link EthertypeV6}
+     */
+    public static Long getEtherType(SecurityRule secRule) {
+        Class<? extends EthertypeBase> ethertype = secRule.getEthertype();
+        if (ethertype == null) {
+            return null;
+        }
+        if (ethertype.isAssignableFrom(EthertypeV4.class)) {
+            return EtherTypeClassifierDefinition.IPv4_VALUE;
+        }
+        if (ethertype.isAssignableFrom(EthertypeV6.class)) {
+            return EtherTypeClassifierDefinition.IPv6_VALUE;
+        }
+        throw new IllegalArgumentException("Ethertype " + ethertype + " is not supported.");
+    }
+
+    /**
+     * @param secRule
+     * @return {@code null} if {@link SecurityRule#getProtocol()} is null; Otherwise protocol number
+     * @throws IllegalArgumentException if return value of
+     *         {@link SecurityRule#getProtocol()} is other than {@link ProtocolTcp},
+     *         {@link ProtocolUdp}, {@link ProtocolIcmp}, {@link ProtocolIcmpV6}
+     */
+    public static Long getProtocol(SecurityRule secRule) {
+        SecurityRuleAttributes.Protocol protocol = secRule.getProtocol();
+        if (protocol == null) {
+            return null;
+        }
+        if (protocol.getUint8() != null) {
+            return protocol.getUint8().longValue();
+        }
+        if (protocol.getIdentityref() != null) {
+            if (protocol.getIdentityref().equals(ProtocolTcp.class)) {
+                return IpProtoClassifierDefinition.TCP_VALUE;
+            }
+            if (protocol.getIdentityref().equals(ProtocolUdp.class)) {
+                return IpProtoClassifierDefinition.UDP_VALUE;
+            }
+            if (protocol.getIdentityref().equals(ProtocolIcmp.class)) {
+                return IpProtoClassifierDefinition.ICMP_VALUE;
+            }
+            if (protocol.getIdentityref().equals(ProtocolIcmpV6.class)) {
+                return IpProtoClassifierDefinition.ICMPv6_VALUE;
+            }
+        }
+        throw new IllegalArgumentException("Neutron Security Rule Protocol value " + protocol + " is not supported.");
+    }
+}
index d1eb492ec890cbf09f09b14030a456b09bd902c7..a4c0e978d3acf419d6cc77299fac6cb1ee05cdf4 100644 (file)
@@ -1,36 +1,36 @@
-/*\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.neutron.vpp.mapper;\r
-\r
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
-import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.hostconfigs.VppNodeListener;\r
-import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.processors.NeutronListener;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-public class NeutronVppMapper implements AutoCloseable {\r
-\r
-    NeutronListener neutronListener;\r
-    VppNodeListener vppNodeListener;\r
-    private static final Logger LOG = LoggerFactory.getLogger(NeutronVppMapper.class);\r
-\r
-    public NeutronVppMapper(String socketPath, String socketPrefix, String routingNode, DataBroker dataBroker) {\r
-        SocketInfo socketInfo = new SocketInfo(socketPath, socketPrefix);\r
-        vppNodeListener = new VppNodeListener(dataBroker, socketInfo);\r
-        neutronListener = new NeutronListener(dataBroker, new NodeId(routingNode));\r
-        LOG.info("Neutron VPP started!");\r
-    }\r
-\r
-    @Override\r
-    public void close() {\r
-        neutronListener.close();\r
-        vppNodeListener.close();\r
-    }\r
-}\r
+/*
+ * 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.neutron.vpp.mapper;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.hostconfigs.VppNodeListener;
+import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.processors.NeutronListener;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NeutronVppMapper implements AutoCloseable {
+
+    NeutronListener neutronListener;
+    VppNodeListener vppNodeListener;
+    private static final Logger LOG = LoggerFactory.getLogger(NeutronVppMapper.class);
+
+    public NeutronVppMapper(String socketPath, String socketPrefix, String routingNode, DataBroker dataBroker) {
+        SocketInfo socketInfo = new SocketInfo(socketPath, socketPrefix);
+        vppNodeListener = new VppNodeListener(dataBroker, socketInfo);
+        neutronListener = new NeutronListener(dataBroker, new NodeId(routingNode));
+        LOG.info("Neutron VPP started!");
+    }
+
+    @Override
+    public void close() {
+        neutronListener.close();
+        vppNodeListener.close();
+    }
+}
index c98a07c158922ddc1cbb95c67ef5a1063d7097f0..e1f45d1c368ee9e37f112439a0f262bf4cbfc925 100644 (file)
@@ -1,64 +1,64 @@
-/*\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.neutron.vpp.mapper;\r
-\r
-public class SocketInfo {\r
-\r
-    private String socketPath;\r
-    private String socketPrefix;\r
-    private final String PORT_ID = "$PORT_ID";\r
-\r
-    public SocketInfo(String socketPath, String socketPrefix) {\r
-        this.socketPath = socketPath;\r
-        this.socketPrefix = socketPrefix;\r
-    }\r
-\r
-    public String getSocketPath() {\r
-        return socketPath;\r
-    }\r
-\r
-    public String getSocketPrefix() {\r
-        return socketPrefix;\r
-    }\r
-\r
-    public String getVhostUserSocket() {\r
-        return new StringBuilder().append(socketPath).append(socketPrefix).append(PORT_ID).toString();\r
-    }\r
-\r
-    @Override\r
-    public int hashCode() {\r
-        final int prime = 31;\r
-        int result = 1;\r
-        result = prime * result + ((socketPath == null) ? 0 : socketPath.hashCode());\r
-        result = prime * result + ((socketPrefix == null) ? 0 : socketPrefix.hashCode());\r
-        return result;\r
-    }\r
-\r
-    @Override\r
-    public boolean equals(Object obj) {\r
-        if (this == obj)\r
-            return true;\r
-        if (obj == null)\r
-            return false;\r
-        if (getClass() != obj.getClass())\r
-            return false;\r
-        SocketInfo other = (SocketInfo) obj;\r
-        if (socketPath == null) {\r
-            if (other.socketPath != null)\r
-                return false;\r
-        } else if (!socketPath.equals(other.socketPath))\r
-            return false;\r
-        if (socketPrefix == null) {\r
-            if (other.socketPrefix != null)\r
-                return false;\r
-        } else if (!socketPrefix.equals(other.socketPrefix))\r
-            return false;\r
-        return true;\r
-    }\r
-}\r
+/*
+ * 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.neutron.vpp.mapper;
+
+public class SocketInfo {
+
+    private String socketPath;
+    private String socketPrefix;
+    private final String PORT_ID = "$PORT_ID";
+
+    public SocketInfo(String socketPath, String socketPrefix) {
+        this.socketPath = socketPath;
+        this.socketPrefix = socketPrefix;
+    }
+
+    public String getSocketPath() {
+        return socketPath;
+    }
+
+    public String getSocketPrefix() {
+        return socketPrefix;
+    }
+
+    public String getVhostUserSocket() {
+        return new StringBuilder().append(socketPath).append(socketPrefix).append(PORT_ID).toString();
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((socketPath == null) ? 0 : socketPath.hashCode());
+        result = prime * result + ((socketPrefix == null) ? 0 : socketPrefix.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        SocketInfo other = (SocketInfo) obj;
+        if (socketPath == null) {
+            if (other.socketPath != null)
+                return false;
+        } else if (!socketPath.equals(other.socketPath))
+            return false;
+        if (socketPrefix == null) {
+            if (other.socketPrefix != null)
+                return false;
+        } else if (!socketPrefix.equals(other.socketPrefix))
+            return false;
+        return true;
+    }
+}
index c79b875dafd7303bf00b4dc85865d515069c28ea..000c95271e3d3a53682faa2667c42a38ecddbfb3 100644 (file)
-/*\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.neutron.vpp.mapper.hostconfigs;\r
-\r
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;\r
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;\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.groupbasedpolicy.neutron.vpp.mapper.SocketInfo;\r
-import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.util.HostconfigUtil;\r
-import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;\r
-import org.opendaylight.groupbasedpolicy.util.DataTreeChangeHandler;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.RendererName;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.Renderers;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.Renderer;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.RendererKey;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.RendererNodes;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.nodes.RendererNode;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.Hostconfigs;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.Hostconfig;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.HostconfigKey;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-public class VppNodeListener extends DataTreeChangeHandler<RendererNode> {\r
-\r
-    private static final Logger LOG = LoggerFactory.getLogger(VppNodeListener.class);\r
-\r
-    private SocketInfo socketInfo;\r
-    public static final RendererName VPP_RENDERER_NAME = new RendererName("vpp-renderer");\r
-\r
-    public VppNodeListener(DataBroker dataBroker, SocketInfo socketInfo) {\r
-        super(dataBroker);\r
-        this.socketInfo = socketInfo;\r
-        registerDataTreeChangeListener(new DataTreeIdentifier<>(\r
-                LogicalDatastoreType.OPERATIONAL, getVppNodeWildcardIid()));\r
-    }\r
-\r
-    private InstanceIdentifier<RendererNode> getVppNodeWildcardIid() {\r
-        return InstanceIdentifier.builder(Renderers.class)\r
-            .child(Renderer.class, new RendererKey(VPP_RENDERER_NAME))\r
-            .child(RendererNodes.class)\r
-            .child(RendererNode.class)\r
-            .build();\r
-    }\r
-\r
-    @Override\r
-    protected void onWrite(DataObjectModification<RendererNode> rootNode,\r
-            InstanceIdentifier<RendererNode> rootIdentifier) {\r
-        writeData(rootNode.getDataAfter());\r
-    }\r
-\r
-    @Override\r
-    protected void onDelete(DataObjectModification<RendererNode> rootNode,\r
-            InstanceIdentifier<RendererNode> rootIdentifier) {\r
-        deleteData(rootNode.getDataBefore());\r
-    }\r
-\r
-    @Override\r
-    protected void onSubtreeModified(DataObjectModification<RendererNode> rootNode,\r
-            InstanceIdentifier<RendererNode> rootIdentifier) {\r
-        deleteData(rootNode.getDataBefore());\r
-        writeData(rootNode.getDataAfter());\r
-    }\r
-\r
-    private void writeData(RendererNode rendererNode) {\r
-        NodeKey nodeKey = rendererNode.getNodePath().firstKeyOf(Node.class);\r
-        WriteTransaction wTx = dataProvider.newWriteOnlyTransaction();\r
-        Hostconfig hcData = HostconfigUtil.createHostconfigsDataFor(nodeKey.getNodeId(), socketInfo);\r
-        wTx.put(LogicalDatastoreType.OPERATIONAL, hostconfigIid(nodeKey.getNodeId()), hcData);\r
-        DataStoreHelper.submitToDs(wTx);\r
-        LOG.info("Hostconfig data written to DS for VPP node {}", nodeKey);\r
-    }\r
-\r
-    private InstanceIdentifier<Hostconfig> hostconfigIid(NodeId nodeId) {\r
-        return InstanceIdentifier.builder(Neutron.class)\r
-            .child(Hostconfigs.class)\r
-            .child(Hostconfig.class, new HostconfigKey(nodeId.getValue(), HostconfigUtil.L2_HOST_TYPE))\r
-            .build();\r
-    }\r
-\r
-    private void deleteData(RendererNode rendererNode) {\r
-        NodeKey nodeKey = rendererNode.getNodePath().firstKeyOf(Node.class);\r
-        ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction();\r
-        DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL, hostconfigIid(nodeKey.getNodeId()), rwTx);\r
-        DataStoreHelper.submitToDs(rwTx);\r
-        LOG.info("Hostconfig data removed from DS for VPP node {}", nodeKey);\r
-    }\r
-}\r
+/*
+ * 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.neutron.vpp.mapper.hostconfigs;
+
+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.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.SocketInfo;
+import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.util.HostconfigUtil;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+import org.opendaylight.groupbasedpolicy.util.DataTreeChangeHandler;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.RendererName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.Renderers;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.Renderer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.RendererKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.RendererNodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.nodes.RendererNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.Hostconfigs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.Hostconfig;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.HostconfigKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class VppNodeListener extends DataTreeChangeHandler<RendererNode> {
+
+    private static final Logger LOG = LoggerFactory.getLogger(VppNodeListener.class);
+
+    private SocketInfo socketInfo;
+    public static final RendererName VPP_RENDERER_NAME = new RendererName("vpp-renderer");
+
+    public VppNodeListener(DataBroker dataBroker, SocketInfo socketInfo) {
+        super(dataBroker);
+        this.socketInfo = socketInfo;
+        registerDataTreeChangeListener(new DataTreeIdentifier<>(
+                LogicalDatastoreType.OPERATIONAL, getVppNodeWildcardIid()));
+    }
+
+    private InstanceIdentifier<RendererNode> getVppNodeWildcardIid() {
+        return InstanceIdentifier.builder(Renderers.class)
+            .child(Renderer.class, new RendererKey(VPP_RENDERER_NAME))
+            .child(RendererNodes.class)
+            .child(RendererNode.class)
+            .build();
+    }
+
+    @Override
+    protected void onWrite(DataObjectModification<RendererNode> rootNode,
+            InstanceIdentifier<RendererNode> rootIdentifier) {
+        writeData(rootNode.getDataAfter());
+    }
+
+    @Override
+    protected void onDelete(DataObjectModification<RendererNode> rootNode,
+            InstanceIdentifier<RendererNode> rootIdentifier) {
+        deleteData(rootNode.getDataBefore());
+    }
+
+    @Override
+    protected void onSubtreeModified(DataObjectModification<RendererNode> rootNode,
+            InstanceIdentifier<RendererNode> rootIdentifier) {
+        deleteData(rootNode.getDataBefore());
+        writeData(rootNode.getDataAfter());
+    }
+
+    private void writeData(RendererNode rendererNode) {
+        NodeKey nodeKey = rendererNode.getNodePath().firstKeyOf(Node.class);
+        WriteTransaction wTx = dataProvider.newWriteOnlyTransaction();
+        Hostconfig hcData = HostconfigUtil.createHostconfigsDataFor(nodeKey.getNodeId(), socketInfo);
+        wTx.put(LogicalDatastoreType.OPERATIONAL, hostconfigIid(nodeKey.getNodeId()), hcData);
+        DataStoreHelper.submitToDs(wTx);
+        LOG.info("Hostconfig data written to DS for VPP node {}", nodeKey);
+    }
+
+    private InstanceIdentifier<Hostconfig> hostconfigIid(NodeId nodeId) {
+        return InstanceIdentifier.builder(Neutron.class)
+            .child(Hostconfigs.class)
+            .child(Hostconfig.class, new HostconfigKey(nodeId.getValue(), HostconfigUtil.L2_HOST_TYPE))
+            .build();
+    }
+
+    private void deleteData(RendererNode rendererNode) {
+        NodeKey nodeKey = rendererNode.getNodePath().firstKeyOf(Node.class);
+        ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction();
+        DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL, hostconfigIid(nodeKey.getNodeId()), rwTx);
+        DataStoreHelper.submitToDs(rwTx);
+        LOG.info("Hostconfig data removed from DS for VPP node {}", nodeKey);
+    }
+}
index fb8b6859b47bd59a636a7a802151679f0040162c..75cf5d1b5b4b4231f54e8680d42af195caba00b8 100644 (file)
@@ -1,23 +1,23 @@
-/*\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.neutron.vpp.mapper.processors;\r
-\r
-import org.opendaylight.yangtools.yang.binding.DataObject;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
-\r
-interface MappingProvider<T extends DataObject> {\r
-\r
-    InstanceIdentifier<T> getNeutronDtoIid();\r
-\r
-    void processCreatedNeutronDto(T t);\r
-\r
-    void processUpdatedNeutronDto(T original, T delta);\r
-\r
-    void processDeletedNeutronDto(T t);\r
-}\r
+/*
+ * 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.neutron.vpp.mapper.processors;
+
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+interface MappingProvider<T extends DataObject> {
+
+    InstanceIdentifier<T> getNeutronDtoIid();
+
+    void processCreatedNeutronDto(T t);
+
+    void processUpdatedNeutronDto(T original, T delta);
+
+    void processDeletedNeutronDto(T t);
+}
index f1958b36b2426f1420afa95153e0c9d90cfdaa7c..9a70ae81cb82fb3131fd0119b9d4b845d61ab2b2 100644 (file)
-/*\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.neutron.vpp.mapper.processors;\r
-\r
-import java.io.Closeable;\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.LinkedHashSet;\r
-import java.util.List;\r
-import java.util.Set;\r
-import java.util.concurrent.ExecutionException;\r
-\r
-import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;\r
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;\r
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;\r
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;\r
-import org.opendaylight.yangtools.concepts.ListenerRegistration;\r
-import org.opendaylight.yangtools.yang.binding.DataObject;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import com.google.common.annotations.VisibleForTesting;\r
-import com.google.common.collect.Iterators;\r
-import com.google.common.collect.PeekingIterator;\r
-\r
-public class NeutronListener implements ClusteredDataTreeChangeListener<Neutron>, Closeable {\r
-\r
-    private static final Logger LOG = LoggerFactory.getLogger(NeutronListener.class);\r
-\r
-    private final Set<MappingProvider<? extends DataObject>> dataChangeProviders = new LinkedHashSet<>();\r
-    protected ListenerRegistration<NeutronListener> registeredListener;\r
-\r
-    public NeutronListener(DataBroker dataBroker, NodeId routingNode) {\r
-        LOG.info("Routing node chosen in ODL is {}", routingNode);\r
-        registerHandlersAndListeners(dataBroker, routingNode);\r
-        registeredListener = dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(\r
-                LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(Neutron.class).build()), this);\r
-    }\r
-\r
-    private void registerHandlersAndListeners(DataBroker dataBroker, NodeId routingNode) {\r
-        PortHandler portHandler = new PortHandler(dataBroker, routingNode);\r
-        dataChangeProviders.add(new PortAware(portHandler, dataBroker));\r
-        dataChangeProviders.add(new NetworkAware(dataBroker));\r
-        dataChangeProviders.add(new SubnetAware(dataBroker));\r
-    }\r
-\r
-    @Override\r
-    public void onDataTreeChanged(Collection<DataTreeModification<Neutron>> changes) {\r
-        for (DataTreeModification<Neutron> change : changes) {\r
-            DataObjectModification<Neutron> rootNode = change.getRootNode();\r
-            for (MappingProvider<? extends DataObject> provider : dataChangeProviders) {\r
-                for (DataObjectModification<? extends DataObject> modDto : findModifiedData(provider, rootNode)) {\r
-                    try {\r
-                        processChangedData(modDto, modDto.getModificationType(), provider);\r
-                    } catch (InterruptedException | ExecutionException e) {\r
-                        LOG.error("Failed to process {} modification of node: {}. {}", modDto.getModificationType(),\r
-                                modDto.getIdentifier(), e.getStackTrace());\r
-                    }\r
-                }\r
-            }\r
-        }\r
-    }\r
-\r
-    List<DataObjectModification<? extends DataObject>> findModifiedData(MappingProvider<? extends DataObject> provider,\r
-            DataObjectModification<Neutron> rootNode) {\r
-        List<DataObjectModification<? extends DataObject>> modDtos = new ArrayList<>();\r
-        PeekingIterator<PathArgument> pathArgs = Iterators.peekingIterator(provider.getNeutronDtoIid()\r
-            .getPathArguments()\r
-            .iterator());\r
-        DataObjectModification<? extends DataObject> modifDto = rootNode;\r
-        while (pathArgs.hasNext()) {\r
-            pathArgs.next();\r
-            for (DataObjectModification<? extends DataObject> childDto : modifDto.getModifiedChildren()) {\r
-                if (pathArgs.hasNext() && childDto.getDataType().equals(pathArgs.peek().getType())) {\r
-                    if (childDto.getDataType().equals(provider.getNeutronDtoIid().getTargetType())) {\r
-                        modDtos.add(childDto);\r
-                    } else {\r
-                        modifDto = childDto;\r
-                        break;\r
-                    }\r
-                }\r
-            }\r
-        }\r
-        return modDtos;\r
-    }\r
-\r
-    @SuppressWarnings("unchecked")\r
-    <T extends DataObject> void processChangedData(DataObjectModification<?> dto, ModificationType m,\r
-            MappingProvider<T> processor) throws InterruptedException, ExecutionException {\r
-        switch (m) {\r
-            case WRITE: {\r
-                if (dto.getDataBefore() != null) {\r
-                    processor.processUpdatedNeutronDto((T) dto.getDataBefore(), (T) dto.getDataAfter());\r
-                } else {\r
-                    processor.processCreatedNeutronDto((T) dto.getDataAfter());\r
-                }\r
-                break;\r
-            }\r
-            case SUBTREE_MODIFIED: {\r
-                processor.processUpdatedNeutronDto((T) dto.getDataBefore(), (T) dto.getDataAfter());\r
-                break;\r
-            }\r
-            case DELETE: {\r
-                processor.processDeletedNeutronDto((T) dto.getDataBefore());\r
-                break;\r
-            }\r
-        }\r
-    }\r
-\r
-    @VisibleForTesting\r
-    void clearDataChangeProviders() {\r
-        dataChangeProviders.clear();\r
-    }\r
-\r
-    @VisibleForTesting\r
-    <T extends DataObject> void addDataChangeProvider(MappingProvider<T> t) {\r
-        dataChangeProviders.add(t);\r
-    }\r
-\r
-    @Override\r
-    public void close() {\r
-        registeredListener.close();\r
-    }\r
-}\r
+/*
+ * 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.neutron.vpp.mapper.processors;
+
+import java.io.Closeable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+
+import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
+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.DataObjectModification.ModificationType;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.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.InstanceIdentifier.PathArgument;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.Iterators;
+import com.google.common.collect.PeekingIterator;
+
+public class NeutronListener implements ClusteredDataTreeChangeListener<Neutron>, Closeable {
+
+    private static final Logger LOG = LoggerFactory.getLogger(NeutronListener.class);
+
+    private final Set<MappingProvider<? extends DataObject>> dataChangeProviders = new LinkedHashSet<>();
+    protected ListenerRegistration<NeutronListener> registeredListener;
+
+    public NeutronListener(DataBroker dataBroker, NodeId routingNode) {
+        LOG.info("Routing node chosen in ODL is {}", routingNode);
+        registerHandlersAndListeners(dataBroker, routingNode);
+        registeredListener = dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
+                LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(Neutron.class).build()), this);
+    }
+
+    private void registerHandlersAndListeners(DataBroker dataBroker, NodeId routingNode) {
+        PortHandler portHandler = new PortHandler(dataBroker, routingNode);
+        dataChangeProviders.add(new PortAware(portHandler, dataBroker));
+        dataChangeProviders.add(new NetworkAware(dataBroker));
+        dataChangeProviders.add(new SubnetAware(dataBroker));
+    }
+
+    @Override
+    public void onDataTreeChanged(Collection<DataTreeModification<Neutron>> changes) {
+        for (DataTreeModification<Neutron> change : changes) {
+            DataObjectModification<Neutron> rootNode = change.getRootNode();
+            for (MappingProvider<? extends DataObject> provider : dataChangeProviders) {
+                for (DataObjectModification<? extends DataObject> modDto : findModifiedData(provider, rootNode)) {
+                    try {
+                        processChangedData(modDto, modDto.getModificationType(), provider);
+                    } catch (InterruptedException | ExecutionException e) {
+                        LOG.error("Failed to process {} modification of node: {}. {}", modDto.getModificationType(),
+                                modDto.getIdentifier(), e.getStackTrace());
+                    }
+                }
+            }
+        }
+    }
+
+    List<DataObjectModification<? extends DataObject>> findModifiedData(MappingProvider<? extends DataObject> provider,
+            DataObjectModification<Neutron> rootNode) {
+        List<DataObjectModification<? extends DataObject>> modDtos = new ArrayList<>();
+        PeekingIterator<PathArgument> pathArgs = Iterators.peekingIterator(provider.getNeutronDtoIid()
+            .getPathArguments()
+            .iterator());
+        DataObjectModification<? extends DataObject> modifDto = rootNode;
+        while (pathArgs.hasNext()) {
+            pathArgs.next();
+            for (DataObjectModification<? extends DataObject> childDto : modifDto.getModifiedChildren()) {
+                if (pathArgs.hasNext() && childDto.getDataType().equals(pathArgs.peek().getType())) {
+                    if (childDto.getDataType().equals(provider.getNeutronDtoIid().getTargetType())) {
+                        modDtos.add(childDto);
+                    } else {
+                        modifDto = childDto;
+                        break;
+                    }
+                }
+            }
+        }
+        return modDtos;
+    }
+
+    @SuppressWarnings("unchecked")
+    <T extends DataObject> void processChangedData(DataObjectModification<?> dto, ModificationType m,
+            MappingProvider<T> processor) throws InterruptedException, ExecutionException {
+        switch (m) {
+            case WRITE: {
+                if (dto.getDataBefore() != null) {
+                    processor.processUpdatedNeutronDto((T) dto.getDataBefore(), (T) dto.getDataAfter());
+                } else {
+                    processor.processCreatedNeutronDto((T) dto.getDataAfter());
+                }
+                break;
+            }
+            case SUBTREE_MODIFIED: {
+                processor.processUpdatedNeutronDto((T) dto.getDataBefore(), (T) dto.getDataAfter());
+                break;
+            }
+            case DELETE: {
+                processor.processDeletedNeutronDto((T) dto.getDataBefore());
+                break;
+            }
+        }
+    }
+
+    @VisibleForTesting
+    void clearDataChangeProviders() {
+        dataChangeProviders.clear();
+    }
+
+    @VisibleForTesting
+    <T extends DataObject> void addDataChangeProvider(MappingProvider<T> t) {
+        dataChangeProviders.add(t);
+    }
+
+    @Override
+    public void close() {
+        registeredListener.close();
+    }
+}
index df44f2cfa0c2af43b9a9e4a1266d29f8e803a54b..e08508c38c65df32da5fbd80ee153c2c16b11f21 100644 (file)
@@ -1,84 +1,84 @@
-/*\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.neutron.vpp.mapper.processors;\r
-\r
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;\r
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
-import org.opendaylight.groupbasedpolicy.util.DataTreeChangeHandler;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.GbpByNeutronMappings;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.BaseEndpointsByPorts;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.base.endpoints.by.ports.BaseEndpointByPort;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-public class PortAware extends DataTreeChangeHandler<BaseEndpointByPort> implements\r
-        MappingProvider<Port> {\r
-\r
-    private static final Logger LOG = LoggerFactory.getLogger(PortAware.class);\r
-    private final PortHandler portHandler;\r
-\r
-    protected PortAware(PortHandler portHandler, DataBroker dataProvider) {\r
-        super(dataProvider);\r
-        this.portHandler = portHandler;\r
-        registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,\r
-                InstanceIdentifier.builder(Mappings.class)\r
-                    .child(GbpByNeutronMappings.class)\r
-                    .child(BaseEndpointsByPorts.class)\r
-                    .child(BaseEndpointByPort.class)\r
-                    .build()));\r
-    }\r
-\r
-    @Override\r
-    public InstanceIdentifier<Port> getNeutronDtoIid() {\r
-        return portHandler.createWildcartedPortIid();\r
-    }\r
-\r
-    @Override\r
-    public void processCreatedNeutronDto(Port port) {\r
-        LOG.trace("Neutron port created: {}", port);\r
-        portHandler.processCreated(port);\r
-    }\r
-\r
-    @Override\r
-    public void processUpdatedNeutronDto(Port original, Port delta) {\r
-        LOG.trace("Neutron port updated: {}, delta {}", original, delta);\r
-        portHandler.processUpdated(original, delta);\r
-    }\r
-\r
-    @Override\r
-    public void processDeletedNeutronDto(Port port) {\r
-        LOG.trace("Neutron port deleted: {}", port);\r
-        // handled by BaseEndpointByPort removal\r
-    }\r
-\r
-    @Override\r
-    protected void onWrite(DataObjectModification<BaseEndpointByPort> rootNode,\r
-            InstanceIdentifier<BaseEndpointByPort> rootIdentifier) {\r
-        if (rootNode.getDataBefore() == null) {\r
-            portHandler.processCreated(rootNode.getDataAfter());\r
-        }\r
-    }\r
-\r
-    @Override\r
-    protected void onDelete(DataObjectModification<BaseEndpointByPort> rootNode,\r
-            InstanceIdentifier<BaseEndpointByPort> rootIdentifier) {\r
-        portHandler.processDeleted(rootNode.getDataBefore());\r
-    }\r
-\r
-    @Override\r
-    protected void onSubtreeModified(DataObjectModification<BaseEndpointByPort> rootNode,\r
-            InstanceIdentifier<BaseEndpointByPort> rootIdentifier) {\r
-        // update should not happen\r
-    }\r
-}\r
+/*
+ * 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.neutron.vpp.mapper.processors;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.util.DataTreeChangeHandler;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.GbpByNeutronMappings;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.BaseEndpointsByPorts;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.base.endpoints.by.ports.BaseEndpointByPort;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PortAware extends DataTreeChangeHandler<BaseEndpointByPort> implements
+        MappingProvider<Port> {
+
+    private static final Logger LOG = LoggerFactory.getLogger(PortAware.class);
+    private final PortHandler portHandler;
+
+    protected PortAware(PortHandler portHandler, DataBroker dataProvider) {
+        super(dataProvider);
+        this.portHandler = portHandler;
+        registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
+                InstanceIdentifier.builder(Mappings.class)
+                    .child(GbpByNeutronMappings.class)
+                    .child(BaseEndpointsByPorts.class)
+                    .child(BaseEndpointByPort.class)
+                    .build()));
+    }
+
+    @Override
+    public InstanceIdentifier<Port> getNeutronDtoIid() {
+        return portHandler.createWildcartedPortIid();
+    }
+
+    @Override
+    public void processCreatedNeutronDto(Port port) {
+        LOG.trace("Neutron port created: {}", port);
+        portHandler.processCreated(port);
+    }
+
+    @Override
+    public void processUpdatedNeutronDto(Port original, Port delta) {
+        LOG.trace("Neutron port updated: {}, delta {}", original, delta);
+        portHandler.processUpdated(original, delta);
+    }
+
+    @Override
+    public void processDeletedNeutronDto(Port port) {
+        LOG.trace("Neutron port deleted: {}", port);
+        // handled by BaseEndpointByPort removal
+    }
+
+    @Override
+    protected void onWrite(DataObjectModification<BaseEndpointByPort> rootNode,
+            InstanceIdentifier<BaseEndpointByPort> rootIdentifier) {
+        if (rootNode.getDataBefore() == null) {
+            portHandler.processCreated(rootNode.getDataAfter());
+        }
+    }
+
+    @Override
+    protected void onDelete(DataObjectModification<BaseEndpointByPort> rootNode,
+            InstanceIdentifier<BaseEndpointByPort> rootIdentifier) {
+        portHandler.processDeleted(rootNode.getDataBefore());
+    }
+
+    @Override
+    protected void onSubtreeModified(DataObjectModification<BaseEndpointByPort> rootNode,
+            InstanceIdentifier<BaseEndpointByPort> rootIdentifier) {
+        // update should not happen
+    }
+}
index adf92cc3f43d5be3199eb7c202a29ef6e3fd2eaf..12f08cfb9a969e8adc59375961c37bb4a5275935 100644 (file)
-/*\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.neutron.vpp.mapper.processors;\r
-\r
-import java.util.Collections;\r
-import java.util.List;\r
-\r
-import javax.annotation.Nonnull;\r
-import javax.annotation.Nullable;\r
-\r
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;\r
-import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;\r
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
-import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;\r
-import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;\r
-import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;\r
-import org.opendaylight.groupbasedpolicy.util.SyncedChain;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.UniqueId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.GbpByNeutronMappings;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.BaseEndpointsByPorts;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.base.endpoints.by.ports.BaseEndpointByPort;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.base.endpoints.by.ports.BaseEndpointByPortKey;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.Config;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.ExcludeFromPolicy;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.ExcludeFromPolicyBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425._interface.attributes._interface.type.choice.LoopbackCase;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425._interface.attributes._interface.type.choice.LoopbackCaseBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425._interface.attributes._interface.type.choice.TapCase;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425._interface.attributes._interface.type.choice.TapCaseBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425._interface.attributes._interface.type.choice.VhostUserCaseBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpoint;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpointBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpointKey;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.binding.rev150712.PortBindingExtension;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.binding.rev150712.binding.attributes.VifDetails;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.RouterKey;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.PortKey;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.portsecurity.rev150712.PortSecurityExtension;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.SubnetKey;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import com.google.common.annotations.VisibleForTesting;\r
-import com.google.common.base.Optional;\r
-import com.google.common.base.Preconditions;\r
-import com.google.common.base.Strings;\r
-\r
-public class PortHandler implements TransactionChainListener {\r
-\r
-    private static final Logger LOG = LoggerFactory.getLogger(PortHandler.class);\r
-\r
-    private static final String COMPUTE_OWNER = "compute";\r
-    private static final String DHCP_OWNER = "dhcp";\r
-    static final String ROUTER_OWNER = "network:router_interface";\r
-    private static final String[] SUPPORTED_DEVICE_OWNERS = {COMPUTE_OWNER, DHCP_OWNER, ROUTER_OWNER};\r
-    private static final String VHOST_USER = "vhostuser";\r
-    private static final String UNBOUND = "unbound";\r
-    private static final String VPP_INTERFACE_NAME_PREFIX = "neutron_port_";\r
-    private static final String TAP_PORT_NAME_PREFIX = "tap";\r
-    private static final String RT_PORT_NAME_PREFIX = "qr-";\r
-    private static final String VHOST_SOCKET_KEY = "vhostuser_socket";\r
-    static final String DEFAULT_NODE = "default";\r
-\r
-    private final NodeId routingNode;\r
-    private SyncedChain syncedChain;\r
-    private DataBroker dataBroker;\r
-\r
-    PortHandler(DataBroker dataBroker, NodeId routingNodeId) {\r
-        this.dataBroker = dataBroker;\r
-        this.routingNode = routingNodeId;\r
-        this.syncedChain = new SyncedChain(Preconditions.checkNotNull(dataBroker.createTransactionChain(this)));\r
-    }\r
-\r
-    void processCreated(Port port) {\r
-        Optional<BaseEndpointByPort> optBaseEpByPort =\r
-                syncedChain.readFromDs(LogicalDatastoreType.OPERATIONAL, createBaseEpByPortIid(port.getUuid()));\r
-        if (!optBaseEpByPort.isPresent()) {\r
-            return;\r
-        }\r
-        processCreatedData(port, optBaseEpByPort.get());\r
-    }\r
-\r
-    void processCreated(BaseEndpointByPort bebp) {\r
-        Optional<Port> optPort =\r
-                syncedChain.readFromDs(LogicalDatastoreType.CONFIGURATION, createPortIid(bebp.getPortId()));\r
-        if (!optPort.isPresent()) {\r
-            return;\r
-        }\r
-        processCreatedData(optPort.get(), bebp);\r
-    }\r
-\r
-    @VisibleForTesting\r
-    void processCreatedData(Port port, BaseEndpointByPort bebp) {\r
-        if (isValidVhostUser(port)\r
-                // this is a hack for vpp router port\r
-                // Openstack does not send binding details yet\r
-                || isValidVppRouterPort(port)) {\r
-            VppEndpoint vppEp = buildVppEndpoint(port, bebp);\r
-            if (vppEp == null) {\r
-                LOG.warn("Cannot create vpp-endpoint from neutron port {}", port);\r
-                return;\r
-            }\r
-            writeVppEndpoint(createVppEndpointIid(vppEp.getKey()), vppEp);\r
-            LOG.debug("Created vpp-endpoint {}", vppEp);\r
-        }\r
-    }\r
-\r
-    private boolean isValidVhostUser(Port port) {\r
-        PortBindingExtension portBindingExt = port.getAugmentation(PortBindingExtension.class);\r
-        if (portBindingExt != null) {\r
-            String vifType = portBindingExt.getVifType();\r
-            String deviceOwner = port.getDeviceOwner();\r
-            if (vifType != null && deviceOwner != null) {\r
-                if (vifType.contains(VHOST_USER)) {\r
-                    for (String supportedDeviceOwner : SUPPORTED_DEVICE_OWNERS) {\r
-                        if (deviceOwner.contains(supportedDeviceOwner)) {\r
-                            return true;\r
-                        }\r
-                    }\r
-                }\r
-            }\r
-        }\r
-        return false;\r
-    }\r
-\r
-    void processUpdated(Port original, Port delta) {\r
-        if (!isUpdateNeeded(original, delta)) {\r
-            LOG.trace("Port update skipped, port didn`t change. before {}, after: {}", original, delta);\r
-            return;\r
-        }\r
-\r
-        LOG.trace("Updating port before: {}, after: {}", original, delta);\r
-        if (isValidVhostUser(original)) {\r
-            Optional<BaseEndpointByPort> optBebp =\r
-                    syncedChain.readFromDs(LogicalDatastoreType.OPERATIONAL, createBaseEpByPortIid(original.getUuid()));\r
-            if (!optBebp.isPresent()) {\r
-                return;\r
-            }\r
-            LOG.trace("Updating port - deleting old port {}", optBebp.get().getPortId());\r
-            processDeleted(optBebp.get());\r
-        }\r
-        LOG.trace("Updating port - creating new port {}", delta.getUuid());\r
-        processCreated(delta);\r
-    }\r
-\r
-    private boolean isUpdateNeeded(final Port oldPort, final Port newPort) {\r
-        // TODO fix this to better support update of ports for VPP\r
-        final PortBindingExtension oldPortAugmentation = oldPort.getAugmentation(PortBindingExtension.class);\r
-        final PortBindingExtension newPortAugmentation = newPort.getAugmentation(PortBindingExtension.class);\r
-\r
-        if (newPortAugmentation == null) {\r
-            LOG.trace("Port {} is no longer a vhost type port, updating port...");\r
-            return true;\r
-        }\r
-\r
-        final String oldDeviceOwner = oldPort.getDeviceOwner();\r
-        final String oldVifType = oldPortAugmentation.getVifType();\r
-        final String newDeviceOwner = newPort.getDeviceOwner();\r
-        final String newVifType = newPortAugmentation.getVifType();\r
-\r
-        // TODO potential bug here\r
-        // Temporary change for Openstack Mitaka: If old neutron-binding:vif-type is vhost, new one\r
-        // is unbound and\r
-        // device owner is ROUTER_OWNER, skip update. Openstack (or ml2) sometimes sends router\r
-        // update messages in\r
-        // incorrect order which causes unwanted port removal\r
-        if (oldVifType.equals(VHOST_USER) && newVifType.equals(UNBOUND) && oldDeviceOwner != null\r
-                && ROUTER_OWNER.equals(oldDeviceOwner) && ROUTER_OWNER.equals(newDeviceOwner)) {\r
-            LOG.warn(\r
-                    "Port vif-type was updated from vhost to unbound. This update is currently disabled and will be skipped");\r
-            return false;\r
-        }\r
-\r
-        if (newVifType != null && !newVifType.equals(oldVifType)) {\r
-            LOG.trace("Vif type changed, old: {} new {}", oldVifType, newVifType);\r
-            return true;\r
-        }\r
-\r
-        final List<VifDetails> vifDetails = oldPortAugmentation.getVifDetails();\r
-\r
-        if (!oldPortAugmentation.getHostId().equals(newPortAugmentation.getHostId())\r
-                || nullToEmpty(vifDetails).size() != nullToEmpty(newPortAugmentation.getVifDetails()).size()) {\r
-            return true;\r
-        }\r
-\r
-        for (VifDetails vifDetail : nullToEmpty(vifDetails)) {\r
-            // check if vhostuser_socket, vhostuser_mode and port_filter are changed\r
-            if (!newPortAugmentation.getVifDetails().contains(vifDetail))\r
-                return true;\r
-        }\r
-        return false;\r
-    }\r
-\r
-    void processDeleted(BaseEndpointByPort bebp) {\r
-        LOG.trace("Deleting vpp-endpoint by BaseEndpointByPort {}", bebp);\r
-        VppEndpointKey vppEpKey = new VppEndpointKey(bebp.getAddress(), bebp.getAddressType(), bebp.getContextId(),\r
-                bebp.getContextType());\r
-        InstanceIdentifier<VppEndpoint> vppEpIid = createVppEndpointIid(vppEpKey);\r
-        Optional<VppEndpoint> readVppEp = syncedChain.readFromDs(LogicalDatastoreType.CONFIGURATION, vppEpIid);\r
-        if (readVppEp.isPresent()) {\r
-            writeVppEndpoint(vppEpIid, null);\r
-            LOG.debug("Deleted vpp-endpoint {}", vppEpKey);\r
-        }\r
-    }\r
-\r
-    private synchronized void writeVppEndpoint(InstanceIdentifier<VppEndpoint> vppEpIid, VppEndpoint vppEp) {\r
-        WriteTransaction wTx = syncedChain.newWriteOnlyTransaction();\r
-        if (vppEp != null) {\r
-            wTx.put(LogicalDatastoreType.CONFIGURATION, vppEpIid, vppEp, true);\r
-        } else {\r
-            wTx.delete(LogicalDatastoreType.CONFIGURATION, vppEpIid);\r
-        }\r
-        syncedChain.submitNow(wTx);\r
-    }\r
-\r
-    @VisibleForTesting\r
-    VppEndpoint buildVppEndpoint(Port port, BaseEndpointByPort bebp) {\r
-        PortBindingExtension portBinding = port.getAugmentation(PortBindingExtension.class);\r
-        ExcludeFromPolicy excludeFromPolicy = new ExcludeFromPolicyBuilder().setExcludeFromPolicy(true).build();\r
-        VppEndpointBuilder vppEpBuilder = new VppEndpointBuilder().setDescription("neutron port")\r
-            .setContextId(bebp.getContextId())\r
-            .setContextType(bebp.getContextType())\r
-            .setAddress(bebp.getAddress())\r
-            .setAddressType(bebp.getAddressType())\r
-            .setVppInterfaceName(VPP_INTERFACE_NAME_PREFIX + bebp.getPortId().getValue())\r
-            .setVppNodeId(new NodeId(portBinding.getHostId()));\r
-\r
-        if (port.getDeviceOwner().contains(COMPUTE_OWNER)) {\r
-            vppEpBuilder.setInterfaceTypeChoice(\r
-                    new VhostUserCaseBuilder().setSocket(getSocketFromPortBinding(portBinding)).build());\r
-            Optional<PortSecurityExtension> portSecurity =\r
-                    Optional.fromNullable(port.getAugmentation(PortSecurityExtension.class));\r
-            if (portSecurity.isPresent() && !portSecurity.get().isPortSecurityEnabled()) {\r
-                vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy);\r
-            }\r
-\r
-        } else if (port.getDeviceOwner().contains(DHCP_OWNER) && port.getMacAddress() != null) {\r
-            IpAddress dhcpServerIpAddress = port.getFixedIps().stream().findFirst().isPresent() ?\r
-                port.getFixedIps().stream().findFirst().get().getIpAddress() : null;\r
-            TapCase tapCase = new TapCaseBuilder().setPhysicalAddress(new PhysAddress(port.getMacAddress().getValue()))\r
-                .setName(createPortName(port.getUuid()))\r
-                .setDhcpServerAddress(dhcpServerIpAddress)\r
-                .build();\r
-            vppEpBuilder.setInterfaceTypeChoice(tapCase);\r
-\r
-        } else if (isValidQRouterPort(port)) {\r
-            TapCase tapCase = new TapCaseBuilder().setPhysicalAddress(new PhysAddress(port.getMacAddress().getValue()))\r
-                .setName(createQRouterPortName(port.getUuid()))\r
-                .build();\r
-            vppEpBuilder.setInterfaceTypeChoice(tapCase);\r
-            vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy);\r
-\r
-        } else if (isValidVppRouterPort(port)) {\r
-            if (!DEFAULT_NODE.equals(routingNode.getValue())) {\r
-                LOG.warn(\r
-                        "Host-id changed by ODL for port {}. This is a supplementary workaround for choosing a routing node.",\r
-                        port);\r
-                vppEpBuilder.setVppNodeId(routingNode);\r
-            } else if (port.getDeviceId() != null) {\r
-                LOG.debug("Resolving host-id for unbound router port {}", port.getUuid());\r
-                Optional<Ports> optPorts = syncedChain.readFromDs(LogicalDatastoreType.CONFIGURATION,\r
-                        InstanceIdentifier.builder(Neutron.class).child(Ports.class).build());\r
-                if (optPorts.isPresent() && optPorts.get().getPort() != null) {\r
-                    java.util.Optional<Port> optPortOnTheSameNode = optPorts.get()\r
-                        .getPort()\r
-                        .stream()\r
-                        .filter(p -> !p.getUuid().equals(port.getUuid()))\r
-                        .filter(p -> p.getAugmentation(PortBindingExtension.class) != null)\r
-                        .filter(p -> p.getDeviceOwner().contains(DHCP_OWNER))\r
-                        .findFirst();\r
-                    if (optPortOnTheSameNode.isPresent()) {\r
-                        PortBindingExtension binding =\r
-                                optPortOnTheSameNode.get().getAugmentation(PortBindingExtension.class);\r
-                        if (binding != null && binding.getHostId() != null) {\r
-                            vppEpBuilder.setVppNodeId(new NodeId(binding.getHostId()));\r
-                        } else {\r
-                            LOG.warn("Cannot resolve location of router-port {}", port.getUuid());\r
-                            return null;\r
-                        }\r
-                    }\r
-                }\r
-            }\r
-            vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy);\r
-            vppEpBuilder.setInterfaceTypeChoice(getLoopbackCase(port));\r
-        }\r
-        return vppEpBuilder.build();\r
-    }\r
-\r
-    private String getSocketFromPortBinding(@Nonnull PortBindingExtension portBindingExtension) {\r
-        List<VifDetails> vifDetails = nullToEmpty(portBindingExtension.getVifDetails());\r
-\r
-        for (VifDetails detail : vifDetails) {\r
-            if (VHOST_SOCKET_KEY.equalsIgnoreCase(detail.getDetailsKey())) {\r
-                return detail.getValue();\r
-            }\r
-        }\r
-        return null;\r
-    }\r
-\r
-    private LoopbackCase getLoopbackCase(Port port) {\r
-        LoopbackCaseBuilder loopbackCase =\r
-                new LoopbackCaseBuilder().setPhysAddress(new PhysAddress(port.getMacAddress().getValue()));\r
-        Optional<FixedIps> fixedIpsOptional = resolveFirstFixedIps(port);\r
-        if (fixedIpsOptional.isPresent() && fixedIpsOptional.get().getIpAddress() != null) {\r
-            loopbackCase.setIpAddress(fixedIpsOptional.get().getIpAddress());\r
-            Optional<Subnet> subnetOptional = syncedChain.readFromDs(LogicalDatastoreType.CONFIGURATION,\r
-                    InstanceIdentifier.builder(Neutron.class)\r
-                        .child(Subnets.class)\r
-                        .child(Subnet.class, new SubnetKey(fixedIpsOptional.get().getSubnetId()))\r
-                        .build());\r
-            if (subnetOptional.isPresent()) {\r
-                Ipv4Prefix ipv4Prefix = subnetOptional.get().getCidr().getIpv4Prefix();\r
-                loopbackCase.setIpPrefix(new IpPrefix(ipv4Prefix));\r
-            } else {\r
-                LOG.warn("IpPrefix for loopback port: {} was not set.", port);\r
-            }\r
-            if (loopbackCase.getIpAddress() != null && loopbackCase.getIpPrefix() != null) {\r
-                loopbackCase.setBvi(true);\r
-                LOG.trace("Creating loopback BVI interface: {} for VPP router port: {}.", loopbackCase, port);\r
-            }\r
-\r
-        } else {\r
-            LOG.warn("IpAddress for loopback port: {} was not set.", port);\r
-        }\r
-        return loopbackCase.build();\r
-    }\r
-\r
-    /**\r
-     * If Qrouter (L3 Agent) is in use, any of Openstack neutron routers is not going be mapped\r
-     * to ODL neutron.\r
-     */\r
-    private boolean isValidQRouterPort(Port port) {\r
-        Optional<Router> optRouter = getRouterOptional(port);\r
-        return !optRouter.isPresent() && port.getDeviceOwner().contains(ROUTER_OWNER) && port.getMacAddress() != null;\r
-    }\r
-\r
-    private boolean isValidVppRouterPort(Port port) {\r
-        Optional<Router> optRouter = getRouterOptional(port);\r
-        return optRouter.isPresent() && port.getDeviceOwner().contains(ROUTER_OWNER) && port.getMacAddress() != null;\r
-    }\r
-\r
-    private Optional<Router> getRouterOptional(Port port) {\r
-        if (Strings.isNullOrEmpty(port.getDeviceId())) {\r
-            return Optional.absent();\r
-        }\r
-        RouterKey routerKey = null;\r
-        try {\r
-            routerKey = new RouterKey(new Uuid(port.getDeviceId()));\r
-        } catch (IllegalArgumentException e) {\r
-            // port.getDeviceId() may not match Uuid.PATTERN_CONSTANTS\r
-            return Optional.absent();\r
-        }\r
-        InstanceIdentifier<Router> routerIid =\r
-                InstanceIdentifier.builder(Neutron.class).child(Routers.class).child(Router.class, routerKey).build();\r
-        Optional<Router> optRouter = syncedChain.readFromDs(LogicalDatastoreType.CONFIGURATION, routerIid);\r
-        return optRouter;\r
-    }\r
-\r
-    public static Optional<FixedIps> resolveFirstFixedIps(Port port) {\r
-        List<FixedIps> fixedIps = port.getFixedIps();\r
-        if (fixedIps != null && !fixedIps.isEmpty()) {\r
-            return Optional.of(fixedIps.get(0));\r
-        }\r
-        return Optional.absent();\r
-    }\r
-\r
-    private String createPortName(Uuid portUuid) {\r
-        String tapPortName;\r
-        String uuid = portUuid.getValue();\r
-        if (uuid != null && uuid.length() >= 12) {\r
-            tapPortName = TAP_PORT_NAME_PREFIX + uuid.substring(0, 11);\r
-        } else {\r
-            tapPortName = TAP_PORT_NAME_PREFIX + uuid;\r
-        }\r
-        return tapPortName;\r
-    }\r
-\r
-    private String createQRouterPortName(Uuid portUuid) {\r
-        String tapPortName;\r
-        String uuid = portUuid.getValue();\r
-        if (uuid != null && uuid.length() >= 12) {\r
-            tapPortName = RT_PORT_NAME_PREFIX + uuid.substring(0, 11);\r
-        } else {\r
-            tapPortName = RT_PORT_NAME_PREFIX + uuid;\r
-        }\r
-        return tapPortName;\r
-    }\r
-\r
-    private InstanceIdentifier<VppEndpoint> createVppEndpointIid(VppEndpointKey vppEpKey) {\r
-        return InstanceIdentifier.builder(Config.class).child(VppEndpoint.class, vppEpKey).build();\r
-    }\r
-\r
-    private InstanceIdentifier<BaseEndpointByPort> createBaseEpByPortIid(Uuid uuid) {\r
-        return createBaseEpByPortIid(new UniqueId(uuid.getValue()));\r
-    }\r
-\r
-    private InstanceIdentifier<BaseEndpointByPort> createBaseEpByPortIid(UniqueId uuid) {\r
-        return InstanceIdentifier.builder(Mappings.class)\r
-            .child(GbpByNeutronMappings.class)\r
-            .child(BaseEndpointsByPorts.class)\r
-            .child(BaseEndpointByPort.class, new BaseEndpointByPortKey(uuid))\r
-            .build();\r
-    }\r
-\r
-    InstanceIdentifier<Port> createWildcartedPortIid() {\r
-        return portsIid().child(Port.class).build();\r
-    }\r
-\r
-    private InstanceIdentifier<Port> createPortIid(UniqueId uuid) {\r
-        return portsIid().child(Port.class, new PortKey(new Uuid(uuid.getValue()))).build();\r
-    }\r
-\r
-    private InstanceIdentifierBuilder<Ports> portsIid() {\r
-        return InstanceIdentifier.builder(Neutron.class).child(Ports.class);\r
-    }\r
-\r
-    @Override\r
-    public void onTransactionChainFailed(TransactionChain<?, ?> chain, AsyncTransaction<?, ?> transaction,\r
-            Throwable cause) {\r
-        LOG.error("Transaction chain failed. {} \nTransaction which caused the chain to fail {}", cause.getMessage(),\r
-                transaction, cause);\r
-        syncedChain.closeChain();\r
-        this.syncedChain = new SyncedChain(Preconditions.checkNotNull(dataBroker.createTransactionChain(this)));\r
-    }\r
-\r
-    @Override\r
-    public void onTransactionChainSuccessful(TransactionChain<?, ?> chain) {\r
-        LOG.trace("Transaction chain was successful. {}", chain);\r
-    }\r
-\r
-    private <T> List<T> nullToEmpty(@Nullable List<T> list) {\r
-        return list == null ? Collections.emptyList() : list;\r
-    }\r
-}\r
+/*
+ * 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.neutron.vpp.mapper.processors;
+
+import java.util.Collections;
+import java.util.List;
+
+import javax.annotation.Nonnull;
+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.AsyncTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.groupbasedpolicy.util.SyncedChain;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.UniqueId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.GbpByNeutronMappings;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.BaseEndpointsByPorts;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.base.endpoints.by.ports.BaseEndpointByPort;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.base.endpoints.by.ports.BaseEndpointByPortKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.Config;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.ExcludeFromPolicy;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.ExcludeFromPolicyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425._interface.attributes._interface.type.choice.LoopbackCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425._interface.attributes._interface.type.choice.LoopbackCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425._interface.attributes._interface.type.choice.TapCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425._interface.attributes._interface.type.choice.TapCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425._interface.attributes._interface.type.choice.VhostUserCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpointBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpointKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.binding.rev150712.PortBindingExtension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.binding.rev150712.binding.attributes.VifDetails;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.RouterKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.PortKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.portsecurity.rev150712.PortSecurityExtension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.SubnetKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+
+public class PortHandler implements TransactionChainListener {
+
+    private static final Logger LOG = LoggerFactory.getLogger(PortHandler.class);
+
+    private static final String COMPUTE_OWNER = "compute";
+    private static final String DHCP_OWNER = "dhcp";
+    static final String ROUTER_OWNER = "network:router_interface";
+    private static final String[] SUPPORTED_DEVICE_OWNERS = {COMPUTE_OWNER, DHCP_OWNER, ROUTER_OWNER};
+    private static final String VHOST_USER = "vhostuser";
+    private static final String UNBOUND = "unbound";
+    private static final String VPP_INTERFACE_NAME_PREFIX = "neutron_port_";
+    private static final String TAP_PORT_NAME_PREFIX = "tap";
+    private static final String RT_PORT_NAME_PREFIX = "qr-";
+    private static final String VHOST_SOCKET_KEY = "vhostuser_socket";
+    static final String DEFAULT_NODE = "default";
+
+    private final NodeId routingNode;
+    private SyncedChain syncedChain;
+    private DataBroker dataBroker;
+
+    PortHandler(DataBroker dataBroker, NodeId routingNodeId) {
+        this.dataBroker = dataBroker;
+        this.routingNode = routingNodeId;
+        this.syncedChain = new SyncedChain(Preconditions.checkNotNull(dataBroker.createTransactionChain(this)));
+    }
+
+    void processCreated(Port port) {
+        Optional<BaseEndpointByPort> optBaseEpByPort =
+                syncedChain.readFromDs(LogicalDatastoreType.OPERATIONAL, createBaseEpByPortIid(port.getUuid()));
+        if (!optBaseEpByPort.isPresent()) {
+            return;
+        }
+        processCreatedData(port, optBaseEpByPort.get());
+    }
+
+    void processCreated(BaseEndpointByPort bebp) {
+        Optional<Port> optPort =
+                syncedChain.readFromDs(LogicalDatastoreType.CONFIGURATION, createPortIid(bebp.getPortId()));
+        if (!optPort.isPresent()) {
+            return;
+        }
+        processCreatedData(optPort.get(), bebp);
+    }
+
+    @VisibleForTesting
+    void processCreatedData(Port port, BaseEndpointByPort bebp) {
+        if (isValidVhostUser(port)
+                // this is a hack for vpp router port
+                // Openstack does not send binding details yet
+                || isValidVppRouterPort(port)) {
+            VppEndpoint vppEp = buildVppEndpoint(port, bebp);
+            if (vppEp == null) {
+                LOG.warn("Cannot create vpp-endpoint from neutron port {}", port);
+                return;
+            }
+            writeVppEndpoint(createVppEndpointIid(vppEp.getKey()), vppEp);
+            LOG.debug("Created vpp-endpoint {}", vppEp);
+        }
+    }
+
+    private boolean isValidVhostUser(Port port) {
+        PortBindingExtension portBindingExt = port.getAugmentation(PortBindingExtension.class);
+        if (portBindingExt != null) {
+            String vifType = portBindingExt.getVifType();
+            String deviceOwner = port.getDeviceOwner();
+            if (vifType != null && deviceOwner != null) {
+                if (vifType.contains(VHOST_USER)) {
+                    for (String supportedDeviceOwner : SUPPORTED_DEVICE_OWNERS) {
+                        if (deviceOwner.contains(supportedDeviceOwner)) {
+                            return true;
+                        }
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+    void processUpdated(Port original, Port delta) {
+        if (!isUpdateNeeded(original, delta)) {
+            LOG.trace("Port update skipped, port didn`t change. before {}, after: {}", original, delta);
+            return;
+        }
+
+        LOG.trace("Updating port before: {}, after: {}", original, delta);
+        if (isValidVhostUser(original)) {
+            Optional<BaseEndpointByPort> optBebp =
+                    syncedChain.readFromDs(LogicalDatastoreType.OPERATIONAL, createBaseEpByPortIid(original.getUuid()));
+            if (!optBebp.isPresent()) {
+                return;
+            }
+            LOG.trace("Updating port - deleting old port {}", optBebp.get().getPortId());
+            processDeleted(optBebp.get());
+        }
+        LOG.trace("Updating port - creating new port {}", delta.getUuid());
+        processCreated(delta);
+    }
+
+    private boolean isUpdateNeeded(final Port oldPort, final Port newPort) {
+        // TODO fix this to better support update of ports for VPP
+        final PortBindingExtension oldPortAugmentation = oldPort.getAugmentation(PortBindingExtension.class);
+        final PortBindingExtension newPortAugmentation = newPort.getAugmentation(PortBindingExtension.class);
+
+        if (newPortAugmentation == null) {
+            LOG.trace("Port {} is no longer a vhost type port, updating port...");
+            return true;
+        }
+
+        final String oldDeviceOwner = oldPort.getDeviceOwner();
+        final String oldVifType = oldPortAugmentation.getVifType();
+        final String newDeviceOwner = newPort.getDeviceOwner();
+        final String newVifType = newPortAugmentation.getVifType();
+
+        // TODO potential bug here
+        // Temporary change for Openstack Mitaka: If old neutron-binding:vif-type is vhost, new one
+        // is unbound and
+        // device owner is ROUTER_OWNER, skip update. Openstack (or ml2) sometimes sends router
+        // update messages in
+        // incorrect order which causes unwanted port removal
+        if (oldVifType.equals(VHOST_USER) && newVifType.equals(UNBOUND) && oldDeviceOwner != null
+                && ROUTER_OWNER.equals(oldDeviceOwner) && ROUTER_OWNER.equals(newDeviceOwner)) {
+            LOG.warn(
+                    "Port vif-type was updated from vhost to unbound. This update is currently disabled and will be skipped");
+            return false;
+        }
+
+        if (newVifType != null && !newVifType.equals(oldVifType)) {
+            LOG.trace("Vif type changed, old: {} new {}", oldVifType, newVifType);
+            return true;
+        }
+
+        final List<VifDetails> vifDetails = oldPortAugmentation.getVifDetails();
+
+        if (!oldPortAugmentation.getHostId().equals(newPortAugmentation.getHostId())
+                || nullToEmpty(vifDetails).size() != nullToEmpty(newPortAugmentation.getVifDetails()).size()) {
+            return true;
+        }
+
+        for (VifDetails vifDetail : nullToEmpty(vifDetails)) {
+            // check if vhostuser_socket, vhostuser_mode and port_filter are changed
+            if (!newPortAugmentation.getVifDetails().contains(vifDetail))
+                return true;
+        }
+        return false;
+    }
+
+    void processDeleted(BaseEndpointByPort bebp) {
+        LOG.trace("Deleting vpp-endpoint by BaseEndpointByPort {}", bebp);
+        VppEndpointKey vppEpKey = new VppEndpointKey(bebp.getAddress(), bebp.getAddressType(), bebp.getContextId(),
+                bebp.getContextType());
+        InstanceIdentifier<VppEndpoint> vppEpIid = createVppEndpointIid(vppEpKey);
+        Optional<VppEndpoint> readVppEp = syncedChain.readFromDs(LogicalDatastoreType.CONFIGURATION, vppEpIid);
+        if (readVppEp.isPresent()) {
+            writeVppEndpoint(vppEpIid, null);
+            LOG.debug("Deleted vpp-endpoint {}", vppEpKey);
+        }
+    }
+
+    private synchronized void writeVppEndpoint(InstanceIdentifier<VppEndpoint> vppEpIid, VppEndpoint vppEp) {
+        WriteTransaction wTx = syncedChain.newWriteOnlyTransaction();
+        if (vppEp != null) {
+            wTx.put(LogicalDatastoreType.CONFIGURATION, vppEpIid, vppEp, true);
+        } else {
+            wTx.delete(LogicalDatastoreType.CONFIGURATION, vppEpIid);
+        }
+        syncedChain.submitNow(wTx);
+    }
+
+    @VisibleForTesting
+    VppEndpoint buildVppEndpoint(Port port, BaseEndpointByPort bebp) {
+        PortBindingExtension portBinding = port.getAugmentation(PortBindingExtension.class);
+        ExcludeFromPolicy excludeFromPolicy = new ExcludeFromPolicyBuilder().setExcludeFromPolicy(true).build();
+        VppEndpointBuilder vppEpBuilder = new VppEndpointBuilder().setDescription("neutron port")
+            .setContextId(bebp.getContextId())
+            .setContextType(bebp.getContextType())
+            .setAddress(bebp.getAddress())
+            .setAddressType(bebp.getAddressType())
+            .setVppInterfaceName(VPP_INTERFACE_NAME_PREFIX + bebp.getPortId().getValue())
+            .setVppNodeId(new NodeId(portBinding.getHostId()));
+
+        if (port.getDeviceOwner().contains(COMPUTE_OWNER)) {
+            vppEpBuilder.setInterfaceTypeChoice(
+                    new VhostUserCaseBuilder().setSocket(getSocketFromPortBinding(portBinding)).build());
+            Optional<PortSecurityExtension> portSecurity =
+                    Optional.fromNullable(port.getAugmentation(PortSecurityExtension.class));
+            if (portSecurity.isPresent() && !portSecurity.get().isPortSecurityEnabled()) {
+                vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy);
+            }
+
+        } else if (port.getDeviceOwner().contains(DHCP_OWNER) && port.getMacAddress() != null) {
+            IpAddress dhcpServerIpAddress = port.getFixedIps().stream().findFirst().isPresent() ?
+                port.getFixedIps().stream().findFirst().get().getIpAddress() : null;
+            TapCase tapCase = new TapCaseBuilder().setPhysicalAddress(new PhysAddress(port.getMacAddress().getValue()))
+                .setName(createPortName(port.getUuid()))
+                .setDhcpServerAddress(dhcpServerIpAddress)
+                .build();
+            vppEpBuilder.setInterfaceTypeChoice(tapCase);
+
+        } else if (isValidQRouterPort(port)) {
+            TapCase tapCase = new TapCaseBuilder().setPhysicalAddress(new PhysAddress(port.getMacAddress().getValue()))
+                .setName(createQRouterPortName(port.getUuid()))
+                .build();
+            vppEpBuilder.setInterfaceTypeChoice(tapCase);
+            vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy);
+
+        } else if (isValidVppRouterPort(port)) {
+            if (!DEFAULT_NODE.equals(routingNode.getValue())) {
+                LOG.warn(
+                        "Host-id changed by ODL for port {}. This is a supplementary workaround for choosing a routing node.",
+                        port);
+                vppEpBuilder.setVppNodeId(routingNode);
+            } else if (port.getDeviceId() != null) {
+                LOG.debug("Resolving host-id for unbound router port {}", port.getUuid());
+                Optional<Ports> optPorts = syncedChain.readFromDs(LogicalDatastoreType.CONFIGURATION,
+                        InstanceIdentifier.builder(Neutron.class).child(Ports.class).build());
+                if (optPorts.isPresent() && optPorts.get().getPort() != null) {
+                    java.util.Optional<Port> optPortOnTheSameNode = optPorts.get()
+                        .getPort()
+                        .stream()
+                        .filter(p -> !p.getUuid().equals(port.getUuid()))
+                        .filter(p -> p.getAugmentation(PortBindingExtension.class) != null)
+                        .filter(p -> p.getDeviceOwner().contains(DHCP_OWNER))
+                        .findFirst();
+                    if (optPortOnTheSameNode.isPresent()) {
+                        PortBindingExtension binding =
+                                optPortOnTheSameNode.get().getAugmentation(PortBindingExtension.class);
+                        if (binding != null && binding.getHostId() != null) {
+                            vppEpBuilder.setVppNodeId(new NodeId(binding.getHostId()));
+                        } else {
+                            LOG.warn("Cannot resolve location of router-port {}", port.getUuid());
+                            return null;
+                        }
+                    }
+                }
+            }
+            vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy);
+            vppEpBuilder.setInterfaceTypeChoice(getLoopbackCase(port));
+        }
+        return vppEpBuilder.build();
+    }
+
+    private String getSocketFromPortBinding(@Nonnull PortBindingExtension portBindingExtension) {
+        List<VifDetails> vifDetails = nullToEmpty(portBindingExtension.getVifDetails());
+
+        for (VifDetails detail : vifDetails) {
+            if (VHOST_SOCKET_KEY.equalsIgnoreCase(detail.getDetailsKey())) {
+                return detail.getValue();
+            }
+        }
+        return null;
+    }
+
+    private LoopbackCase getLoopbackCase(Port port) {
+        LoopbackCaseBuilder loopbackCase =
+                new LoopbackCaseBuilder().setPhysAddress(new PhysAddress(port.getMacAddress().getValue()));
+        Optional<FixedIps> fixedIpsOptional = resolveFirstFixedIps(port);
+        if (fixedIpsOptional.isPresent() && fixedIpsOptional.get().getIpAddress() != null) {
+            loopbackCase.setIpAddress(fixedIpsOptional.get().getIpAddress());
+            Optional<Subnet> subnetOptional = syncedChain.readFromDs(LogicalDatastoreType.CONFIGURATION,
+                    InstanceIdentifier.builder(Neutron.class)
+                        .child(Subnets.class)
+                        .child(Subnet.class, new SubnetKey(fixedIpsOptional.get().getSubnetId()))
+                        .build());
+            if (subnetOptional.isPresent()) {
+                Ipv4Prefix ipv4Prefix = subnetOptional.get().getCidr().getIpv4Prefix();
+                loopbackCase.setIpPrefix(new IpPrefix(ipv4Prefix));
+            } else {
+                LOG.warn("IpPrefix for loopback port: {} was not set.", port);
+            }
+            if (loopbackCase.getIpAddress() != null && loopbackCase.getIpPrefix() != null) {
+                loopbackCase.setBvi(true);
+                LOG.trace("Creating loopback BVI interface: {} for VPP router port: {}.", loopbackCase, port);
+            }
+
+        } else {
+            LOG.warn("IpAddress for loopback port: {} was not set.", port);
+        }
+        return loopbackCase.build();
+    }
+
+    /**
+     * If Qrouter (L3 Agent) is in use, any of Openstack neutron routers is not going be mapped
+     * to ODL neutron.
+     */
+    private boolean isValidQRouterPort(Port port) {
+        Optional<Router> optRouter = getRouterOptional(port);
+        return !optRouter.isPresent() && port.getDeviceOwner().contains(ROUTER_OWNER) && port.getMacAddress() != null;
+    }
+
+    private boolean isValidVppRouterPort(Port port) {
+        Optional<Router> optRouter = getRouterOptional(port);
+        return optRouter.isPresent() && port.getDeviceOwner().contains(ROUTER_OWNER) && port.getMacAddress() != null;
+    }
+
+    private Optional<Router> getRouterOptional(Port port) {
+        if (Strings.isNullOrEmpty(port.getDeviceId())) {
+            return Optional.absent();
+        }
+        RouterKey routerKey = null;
+        try {
+            routerKey = new RouterKey(new Uuid(port.getDeviceId()));
+        } catch (IllegalArgumentException e) {
+            // port.getDeviceId() may not match Uuid.PATTERN_CONSTANTS
+            return Optional.absent();
+        }
+        InstanceIdentifier<Router> routerIid =
+                InstanceIdentifier.builder(Neutron.class).child(Routers.class).child(Router.class, routerKey).build();
+        Optional<Router> optRouter = syncedChain.readFromDs(LogicalDatastoreType.CONFIGURATION, routerIid);
+        return optRouter;
+    }
+
+    public static Optional<FixedIps> resolveFirstFixedIps(Port port) {
+        List<FixedIps> fixedIps = port.getFixedIps();
+        if (fixedIps != null && !fixedIps.isEmpty()) {
+            return Optional.of(fixedIps.get(0));
+        }
+        return Optional.absent();
+    }
+
+    private String createPortName(Uuid portUuid) {
+        String tapPortName;
+        String uuid = portUuid.getValue();
+        if (uuid != null && uuid.length() >= 12) {
+            tapPortName = TAP_PORT_NAME_PREFIX + uuid.substring(0, 11);
+        } else {
+            tapPortName = TAP_PORT_NAME_PREFIX + uuid;
+        }
+        return tapPortName;
+    }
+
+    private String createQRouterPortName(Uuid portUuid) {
+        String tapPortName;
+        String uuid = portUuid.getValue();
+        if (uuid != null && uuid.length() >= 12) {
+            tapPortName = RT_PORT_NAME_PREFIX + uuid.substring(0, 11);
+        } else {
+            tapPortName = RT_PORT_NAME_PREFIX + uuid;
+        }
+        return tapPortName;
+    }
+
+    private InstanceIdentifier<VppEndpoint> createVppEndpointIid(VppEndpointKey vppEpKey) {
+        return InstanceIdentifier.builder(Config.class).child(VppEndpoint.class, vppEpKey).build();
+    }
+
+    private InstanceIdentifier<BaseEndpointByPort> createBaseEpByPortIid(Uuid uuid) {
+        return createBaseEpByPortIid(new UniqueId(uuid.getValue()));
+    }
+
+    private InstanceIdentifier<BaseEndpointByPort> createBaseEpByPortIid(UniqueId uuid) {
+        return InstanceIdentifier.builder(Mappings.class)
+            .child(GbpByNeutronMappings.class)
+            .child(BaseEndpointsByPorts.class)
+            .child(BaseEndpointByPort.class, new BaseEndpointByPortKey(uuid))
+            .build();
+    }
+
+    InstanceIdentifier<Port> createWildcartedPortIid() {
+        return portsIid().child(Port.class).build();
+    }
+
+    private InstanceIdentifier<Port> createPortIid(UniqueId uuid) {
+        return portsIid().child(Port.class, new PortKey(new Uuid(uuid.getValue()))).build();
+    }
+
+    private InstanceIdentifierBuilder<Ports> portsIid() {
+        return InstanceIdentifier.builder(Neutron.class).child(Ports.class);
+    }
+
+    @Override
+    public void onTransactionChainFailed(TransactionChain<?, ?> chain, AsyncTransaction<?, ?> transaction,
+            Throwable cause) {
+        LOG.error("Transaction chain failed. {} \nTransaction which caused the chain to fail {}", cause.getMessage(),
+                transaction, cause);
+        syncedChain.closeChain();
+        this.syncedChain = new SyncedChain(Preconditions.checkNotNull(dataBroker.createTransactionChain(this)));
+    }
+
+    @Override
+    public void onTransactionChainSuccessful(TransactionChain<?, ?> chain) {
+        LOG.trace("Transaction chain was successful. {}", chain);
+    }
+
+    private <T> List<T> nullToEmpty(@Nullable List<T> list) {
+        return list == null ? Collections.emptyList() : list;
+    }
+}
index 487c9c75639c354d96e51deef7ed23bfecf4c38b..3a0b71b366e0584bd7d9c5e2f9cc49083dfe2db9 100644 (file)
@@ -1,72 +1,72 @@
-/*\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.neutron.vpp.mapper.util;\r
-\r
-import java.util.List;\r
-\r
-import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.SocketInfo;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.Hostconfig;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.HostconfigBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;\r
-\r
-import com.google.common.base.Preconditions;\r
-import com.google.common.collect.Lists;\r
-import com.google.gson.JsonArray;\r
-import com.google.gson.JsonObject;\r
-\r
-\r
-public class HostconfigUtil {\r
-\r
-    public static final String L2_HOST_TYPE = "ODL L2";\r
-    private static final String VHOST_USER = "vhostuser";\r
-    private static final String VNIC_TYPE = "normal";\r
-    private static final String HAS_DATAPATH_TYPE_NETDEV = "False";\r
-    private static final String SUPPORT_VHOST_USER = "True";\r
-    private static final String VHOSTUSER_MODE = "server";\r
-    private static final List<String> supportedNetworkTypes = Lists.newArrayList("local", "vlan", "vxlan", "gre");\r
-\r
-    public static Hostconfig createHostconfigsDataFor(NodeId nodeId, SocketInfo socketInfo) {\r
-        Preconditions.checkNotNull(nodeId);\r
-        Preconditions.checkNotNull(socketInfo);\r
-        JsonObject odlL2 = new JsonObject();\r
-        odlL2.add("allowed_network_types", buildSupportedNetworkTypes());\r
-        odlL2.add("supported_vnic_types", buildSupportedVnicTypes(socketInfo));\r
-        return new HostconfigBuilder().setHostId(nodeId.getValue())\r
-            .setHostType(L2_HOST_TYPE)\r
-            .setConfig(odlL2.toString())\r
-            .build();\r
-    }\r
-\r
-    private static JsonArray buildSupportedNetworkTypes() {\r
-        JsonArray networkTypes = new JsonArray();\r
-        supportedNetworkTypes.forEach(networkTypes::add);\r
-        return networkTypes;\r
-    }\r
-\r
-    private static JsonArray buildSupportedVnicTypes(SocketInfo socketInfo) {\r
-        JsonArray supportedVnicTypes = new JsonArray();\r
-        JsonObject supportedVnicType = new JsonObject();\r
-        supportedVnicType.addProperty("vnic_type", VNIC_TYPE);\r
-        supportedVnicType.addProperty("vif_type", VHOST_USER);\r
-        supportedVnicType.add("vif_details", buildVifDetails(socketInfo));\r
-        supportedVnicTypes.add(supportedVnicType);\r
-        return supportedVnicTypes;\r
-    }\r
-\r
-    private static JsonObject buildVifDetails(SocketInfo socketInfo) {\r
-        JsonObject vifDetails = new JsonObject();\r
-        vifDetails.addProperty("has_datapath_type_netdev", HAS_DATAPATH_TYPE_NETDEV);\r
-        vifDetails.addProperty("support_vhost_user", SUPPORT_VHOST_USER);\r
-        vifDetails.addProperty("port_prefix", socketInfo.getSocketPrefix());\r
-        vifDetails.addProperty("vhostuser_socket_dir", socketInfo.getSocketPath());\r
-        vifDetails.addProperty("vhostuser_mode", VHOSTUSER_MODE);\r
-        vifDetails.addProperty("vhostuser_socket", socketInfo.getVhostUserSocket());\r
-        return vifDetails;\r
-    }\r
-}\r
+/*
+ * 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.neutron.vpp.mapper.util;
+
+import java.util.List;
+
+import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.SocketInfo;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.Hostconfig;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.HostconfigBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+
+
+public class HostconfigUtil {
+
+    public static final String L2_HOST_TYPE = "ODL L2";
+    private static final String VHOST_USER = "vhostuser";
+    private static final String VNIC_TYPE = "normal";
+    private static final String HAS_DATAPATH_TYPE_NETDEV = "False";
+    private static final String SUPPORT_VHOST_USER = "True";
+    private static final String VHOSTUSER_MODE = "server";
+    private static final List<String> supportedNetworkTypes = Lists.newArrayList("local", "vlan", "vxlan", "gre");
+
+    public static Hostconfig createHostconfigsDataFor(NodeId nodeId, SocketInfo socketInfo) {
+        Preconditions.checkNotNull(nodeId);
+        Preconditions.checkNotNull(socketInfo);
+        JsonObject odlL2 = new JsonObject();
+        odlL2.add("allowed_network_types", buildSupportedNetworkTypes());
+        odlL2.add("supported_vnic_types", buildSupportedVnicTypes(socketInfo));
+        return new HostconfigBuilder().setHostId(nodeId.getValue())
+            .setHostType(L2_HOST_TYPE)
+            .setConfig(odlL2.toString())
+            .build();
+    }
+
+    private static JsonArray buildSupportedNetworkTypes() {
+        JsonArray networkTypes = new JsonArray();
+        supportedNetworkTypes.forEach(networkTypes::add);
+        return networkTypes;
+    }
+
+    private static JsonArray buildSupportedVnicTypes(SocketInfo socketInfo) {
+        JsonArray supportedVnicTypes = new JsonArray();
+        JsonObject supportedVnicType = new JsonObject();
+        supportedVnicType.addProperty("vnic_type", VNIC_TYPE);
+        supportedVnicType.addProperty("vif_type", VHOST_USER);
+        supportedVnicType.add("vif_details", buildVifDetails(socketInfo));
+        supportedVnicTypes.add(supportedVnicType);
+        return supportedVnicTypes;
+    }
+
+    private static JsonObject buildVifDetails(SocketInfo socketInfo) {
+        JsonObject vifDetails = new JsonObject();
+        vifDetails.addProperty("has_datapath_type_netdev", HAS_DATAPATH_TYPE_NETDEV);
+        vifDetails.addProperty("support_vhost_user", SUPPORT_VHOST_USER);
+        vifDetails.addProperty("port_prefix", socketInfo.getSocketPrefix());
+        vifDetails.addProperty("vhostuser_socket_dir", socketInfo.getSocketPath());
+        vifDetails.addProperty("vhostuser_mode", VHOSTUSER_MODE);
+        vifDetails.addProperty("vhostuser_socket", socketInfo.getVhostUserSocket());
+        return vifDetails;
+    }
+}
index 50c8be8b9a83834b6541fa7a43f60c02edcb518f..eccfde536b92f58705c448044ddeac3c68f3e93b 100644 (file)
-/*\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.neutron.vpp.mapper.hostconfigs;\r
-\r
-import java.util.concurrent.ExecutionException;\r
-\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.WriteTransaction;\r
-import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;\r
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
-import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.util.HostconfigUtil;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.Renderers;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.Renderer;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.RendererKey;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.RendererNodes;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.nodes.RendererNode;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.nodes.RendererNodeBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.nodes.RendererNodeKey;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.Hostconfigs;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.Hostconfig;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.HostconfigKey;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
-\r
-import com.google.common.base.Optional;\r
-\r
-public class TestResources extends AbstractDataBrokerTest {\r
-\r
-    protected DataBroker dataBroker;\r
-\r
-    void setDataBroker() {\r
-        this.dataBroker = getDataBroker();\r
-    }\r
-\r
-    void writeTopologyNode(TopologyId topologyId, NodeId nodeId) throws InterruptedException, ExecutionException {\r
-        WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();\r
-        wTx.put(LogicalDatastoreType.CONFIGURATION, createNodeIid(topologyId, nodeId), new NodeBuilder().setNodeId(nodeId).build(), true);\r
-        wTx.submit().get();\r
-    }\r
-\r
-    void writeRendererNode(InstanceIdentifier<Node> nodeIid) throws InterruptedException,\r
-            ExecutionException {\r
-        InstanceIdentifier<RendererNode> rendererNodeIid = createRendererNodeIid(nodeIid);\r
-        RendererNode rendererNode = new RendererNodeBuilder().setNodePath(nodeIid).build();\r
-        WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();\r
-        wTx.put(LogicalDatastoreType.OPERATIONAL, rendererNodeIid, rendererNode, true);\r
-        wTx.submit().get();\r
-    }\r
-\r
-    void deleteRendererNode(InstanceIdentifier<Node> nodeIid) throws InterruptedException, ExecutionException {\r
-        InstanceIdentifier<RendererNode> rendererNodeIid = createRendererNodeIid(nodeIid);\r
-        WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();\r
-        wTx.delete(LogicalDatastoreType.OPERATIONAL, rendererNodeIid);\r
-        wTx.submit().get();\r
-    }\r
-\r
-    Optional<Hostconfig> readHostconfig(NodeId nodeId) throws InterruptedException, ExecutionException {\r
-        ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();\r
-        Optional<Hostconfig> opt = rTx.read(LogicalDatastoreType.OPERATIONAL, createHostconfigWildcardNodeIid(nodeId))\r
-            .get();\r
-        rTx.close();\r
-        return opt;\r
-    }\r
-\r
-    static InstanceIdentifier<Node> createNodeIid(TopologyId topologyId, NodeId nodeId) {\r
-        return InstanceIdentifier.builder(NetworkTopology.class)\r
-            .child(Topology.class, new TopologyKey(topologyId))\r
-            .child(Node.class, new NodeKey(nodeId))\r
-            .build();\r
-    }\r
-\r
-    InstanceIdentifier<RendererNode> createRendererNodeIid(InstanceIdentifier<Node> nodeIid) {\r
-        return InstanceIdentifier.builder(Renderers.class)\r
-            .child(Renderer.class, new RendererKey(VppNodeListener.VPP_RENDERER_NAME))\r
-            .child(RendererNodes.class)\r
-            .child(RendererNode.class, new RendererNodeKey(nodeIid))\r
-            .build();\r
-    }\r
-\r
-    InstanceIdentifier<Hostconfig> createHostconfigWildcardNodeIid(NodeId nodeId) {\r
-        return InstanceIdentifier.builder(Neutron.class)\r
-            .child(Hostconfigs.class)\r
-            .child(Hostconfig.class, new HostconfigKey(nodeId.getValue(), HostconfigUtil.L2_HOST_TYPE))\r
-            .build();\r
-    }\r
-}\r
+/*
+ * 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.neutron.vpp.mapper.hostconfigs;
+
+import java.util.concurrent.ExecutionException;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.util.HostconfigUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.Renderers;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.Renderer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.RendererKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.RendererNodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.nodes.RendererNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.nodes.RendererNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.nodes.RendererNodeKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.Hostconfigs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.Hostconfig;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.HostconfigKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+import com.google.common.base.Optional;
+
+public class TestResources extends AbstractDataBrokerTest {
+
+    protected DataBroker dataBroker;
+
+    void setDataBroker() {
+        this.dataBroker = getDataBroker();
+    }
+
+    void writeTopologyNode(TopologyId topologyId, NodeId nodeId) throws InterruptedException, ExecutionException {
+        WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
+        wTx.put(LogicalDatastoreType.CONFIGURATION, createNodeIid(topologyId, nodeId), new NodeBuilder().setNodeId(nodeId).build(), true);
+        wTx.submit().get();
+    }
+
+    void writeRendererNode(InstanceIdentifier<Node> nodeIid) throws InterruptedException,
+            ExecutionException {
+        InstanceIdentifier<RendererNode> rendererNodeIid = createRendererNodeIid(nodeIid);
+        RendererNode rendererNode = new RendererNodeBuilder().setNodePath(nodeIid).build();
+        WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
+        wTx.put(LogicalDatastoreType.OPERATIONAL, rendererNodeIid, rendererNode, true);
+        wTx.submit().get();
+    }
+
+    void deleteRendererNode(InstanceIdentifier<Node> nodeIid) throws InterruptedException, ExecutionException {
+        InstanceIdentifier<RendererNode> rendererNodeIid = createRendererNodeIid(nodeIid);
+        WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
+        wTx.delete(LogicalDatastoreType.OPERATIONAL, rendererNodeIid);
+        wTx.submit().get();
+    }
+
+    Optional<Hostconfig> readHostconfig(NodeId nodeId) throws InterruptedException, ExecutionException {
+        ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();
+        Optional<Hostconfig> opt = rTx.read(LogicalDatastoreType.OPERATIONAL, createHostconfigWildcardNodeIid(nodeId))
+            .get();
+        rTx.close();
+        return opt;
+    }
+
+    static InstanceIdentifier<Node> createNodeIid(TopologyId topologyId, NodeId nodeId) {
+        return InstanceIdentifier.builder(NetworkTopology.class)
+            .child(Topology.class, new TopologyKey(topologyId))
+            .child(Node.class, new NodeKey(nodeId))
+            .build();
+    }
+
+    InstanceIdentifier<RendererNode> createRendererNodeIid(InstanceIdentifier<Node> nodeIid) {
+        return InstanceIdentifier.builder(Renderers.class)
+            .child(Renderer.class, new RendererKey(VppNodeListener.VPP_RENDERER_NAME))
+            .child(RendererNodes.class)
+            .child(RendererNode.class, new RendererNodeKey(nodeIid))
+            .build();
+    }
+
+    InstanceIdentifier<Hostconfig> createHostconfigWildcardNodeIid(NodeId nodeId) {
+        return InstanceIdentifier.builder(Neutron.class)
+            .child(Hostconfigs.class)
+            .child(Hostconfig.class, new HostconfigKey(nodeId.getValue(), HostconfigUtil.L2_HOST_TYPE))
+            .build();
+    }
+}
index 12c1ec9f20e52bf4c30b11405f70f005a5585274..4fdcda6f454ea7761bc80a47bc7683ebb9559024 100644 (file)
@@ -1,57 +1,57 @@
-/*\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.neutron.vpp.mapper.hostconfigs;\r
-\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertTrue;\r
-\r
-import java.util.concurrent.ExecutionException;\r
-\r
-import org.junit.After;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.SocketInfo;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
-\r
-public class VppNodeListenerTest extends TestResources {\r
-\r
-    private TopologyId topologyId = new TopologyId("topology1");\r
-    private NodeId nodeId = new NodeId("node1");\r
-    private InstanceIdentifier<Node> nodeIid = createNodeIid(topologyId, nodeId);\r
-    private VppNodeListener vppNodeListener;\r
-\r
-    @Before\r
-    public void init() throws InterruptedException, ExecutionException {\r
-        String socketPath = "/tmp/";\r
-        String socketPrefix = "socket_";\r
-        setDataBroker();\r
-        vppNodeListener = new VppNodeListener(dataBroker, new SocketInfo(socketPath, socketPrefix));\r
-        writeTopologyNode(topologyId, nodeId);\r
-        writeRendererNode(createNodeIid(topologyId, nodeId));\r
-    }\r
-\r
-    @Test\r
-    public void writeDataTest() throws InterruptedException, ExecutionException {\r
-        assertTrue(readHostconfig(nodeId).isPresent());\r
-    }\r
-\r
-    @Test\r
-    public void deleteDataTest() throws InterruptedException, ExecutionException {\r
-        deleteRendererNode(nodeIid);\r
-        assertFalse(readHostconfig(nodeId).isPresent());\r
-    }\r
-\r
-    @After\r
-    public void after() {\r
-        vppNodeListener.close();\r
-    }\r
-}\r
+/*
+ * 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.neutron.vpp.mapper.hostconfigs;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.concurrent.ExecutionException;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.SocketInfo;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class VppNodeListenerTest extends TestResources {
+
+    private TopologyId topologyId = new TopologyId("topology1");
+    private NodeId nodeId = new NodeId("node1");
+    private InstanceIdentifier<Node> nodeIid = createNodeIid(topologyId, nodeId);
+    private VppNodeListener vppNodeListener;
+
+    @Before
+    public void init() throws InterruptedException, ExecutionException {
+        String socketPath = "/tmp/";
+        String socketPrefix = "socket_";
+        setDataBroker();
+        vppNodeListener = new VppNodeListener(dataBroker, new SocketInfo(socketPath, socketPrefix));
+        writeTopologyNode(topologyId, nodeId);
+        writeRendererNode(createNodeIid(topologyId, nodeId));
+    }
+
+    @Test
+    public void writeDataTest() throws InterruptedException, ExecutionException {
+        assertTrue(readHostconfig(nodeId).isPresent());
+    }
+
+    @Test
+    public void deleteDataTest() throws InterruptedException, ExecutionException {
+        deleteRendererNode(nodeIid);
+        assertFalse(readHostconfig(nodeId).isPresent());
+    }
+
+    @After
+    public void after() {
+        vppNodeListener.close();
+    }
+}
index 5b45f216213fc0af07a65df1a536e257f7b74b3b..e55187d9a37164295319638278ff61c20907fb2f 100644 (file)
-/*\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.neutron.vpp.mapper.processors;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertNull;\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertTrue;\r
-\r
-import java.util.List;\r
-import java.util.UUID;\r
-\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.mockito.Mockito;\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.WriteTransaction;\r
-import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;\r
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
-import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.FlatNetwork;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.VlanNetwork;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.GbpBridgeDomain;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.bridge.domain.base.attributes.PhysicalLocationRef;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.NetworkTypeFlat;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.NetworkTypeVlan;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.NetworkBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.NetworkProviderExtension;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.NetworkProviderExtensionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;\r
-\r
-import com.google.common.base.Optional;\r
-import com.google.common.collect.ImmutableList;\r
-\r
-public class NetworkAwareTest extends AbstractDataBrokerTest {\r
-\r
-    private DataBroker dataBroker;\r
-    private NetworkAware networkAware;\r
-    private NetworkProviderExtensionBuilder netExtBuilder;\r
-\r
-    @Before\r
-    public void init() {\r
-        dataBroker = Mockito.spy(getDataBroker());\r
-        networkAware = new NetworkAware(dataBroker);\r
-        netExtBuilder = new NetworkProviderExtensionBuilder();\r
-        netExtBuilder.setPhysicalNetwork("physicalNet");\r
-    }\r
-\r
-    @Test\r
-    public void testProcessCreatedNeutronDto_flat() {\r
-        netExtBuilder.setNetworkType(NetworkTypeFlat.class);\r
-        Network network = createTestNetwork("net", netExtBuilder.build());\r
-        networkAware.processCreatedNeutronDto(network);\r
-        ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();\r
-        Optional<GbpBridgeDomain> optBrDomain = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,\r
-                networkAware.getGbpBridgeDomainIid(network.getUuid().getValue()), rTx);\r
-        assertTrue(optBrDomain.isPresent());\r
-    }\r
-\r
-    @Test\r
-    public void testProcessUpdatedNeutronDto() {\r
-        netExtBuilder.setNetworkType(NetworkTypeFlat.class);\r
-        Network network1 = createTestNetwork("net1", netExtBuilder.build());\r
-        Network network2 = new NetworkBuilder(network1).setName("net2")\r
-            .addAugmentation(NetworkProviderExtension.class, netExtBuilder.build())\r
-            .build();\r
-        networkAware.processUpdatedNeutronDto(network1, network2);\r
-        ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();\r
-        Optional<GbpBridgeDomain> optBrDomain = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,\r
-                networkAware.getGbpBridgeDomainIid(network2.getUuid().getValue()), rTx);\r
-        assertTrue(optBrDomain.isPresent());\r
-        assertEquals(optBrDomain.get().getDescription(), "net2");\r
-    }\r
-\r
-    @Test\r
-    public void testProcessDeletedNeutronDto() {\r
-        netExtBuilder.setNetworkType(NetworkTypeFlat.class);\r
-        Network network = createTestNetwork("net1", netExtBuilder.build());\r
-        networkAware.processDeletedNeutronDto(network);\r
-        ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();\r
-        Optional<GbpBridgeDomain> optBrDomain = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,\r
-                networkAware.getGbpBridgeDomainIid(network.getUuid().getValue()), rTx);\r
-        assertFalse(optBrDomain.isPresent());\r
-    }\r
-\r
-    @Test\r
-    public void testCreateBridgeDomain_vlanNetwork() {\r
-        netExtBuilder.setNetworkType(NetworkTypeVlan.class);\r
-        netExtBuilder.setSegmentationId("2016");\r
-        Network vlanNetwork = createTestNetwork("VlanNet", netExtBuilder.build());\r
-        GbpBridgeDomain bridgeDomain = networkAware.createGbpBridgeDomain(vlanNetwork);\r
-        assertEquals(bridgeDomain.getId(), vlanNetwork.getUuid().getValue());\r
-        assertEquals(bridgeDomain.getDescription(), vlanNetwork.getName());\r
-        assertEquals(bridgeDomain.getType(), VlanNetwork.class);\r
-        assertEquals(bridgeDomain.getVlan(), new VlanId(Integer.valueOf(2016)));\r
-    }\r
-\r
-    @Test\r
-    public void testCreateBridgeDomain_flatNetwork() {\r
-        netExtBuilder.setNetworkType(NetworkTypeFlat.class);\r
-        Network flatNetwork = createTestNetwork("FlatNet", netExtBuilder.build());\r
-        GbpBridgeDomain bridgeDomain = networkAware.createGbpBridgeDomain(flatNetwork);\r
-        assertEquals(bridgeDomain.getId(), flatNetwork.getUuid().getValue());\r
-        assertEquals(bridgeDomain.getDescription(), flatNetwork.getName());\r
-        assertEquals(bridgeDomain.getType(), FlatNetwork.class);\r
-    }\r
-\r
-    @Test\r
-    public void testCreateBridgeDomain_noPhysicalNetwork() {\r
-        netExtBuilder.setNetworkType(NetworkTypeFlat.class);\r
-        netExtBuilder.setPhysicalNetwork(null);\r
-        Network flatNetwork = createTestNetwork("FlatNet", netExtBuilder.build());\r
-        GbpBridgeDomain bridgeDomain = networkAware.createGbpBridgeDomain(flatNetwork);\r
-        assertNull(bridgeDomain.getPhysicalLocationRef());\r
-    }\r
-\r
-    @Test\r
-    public void testCreateBridgeDomain_noNetworkType() {\r
-        Network vlanNetwork = createTestNetwork("noTypeNet", new NetworkProviderExtensionBuilder().build());\r
-        GbpBridgeDomain bridgeDomain = networkAware.createGbpBridgeDomain(vlanNetwork);\r
-        assertNull(bridgeDomain);\r
-    }\r
-\r
-    @Test\r
-    public void testResolveDomainLocations() {\r
-        NodeId nodeId = new NodeId("node1");\r
-        TpId tpId = new TpId("tp1");\r
-        TopologyId topologyId = new TopologyId("physicalNet");\r
-        writeBasicTopology(topologyId, nodeId, tpId);\r
-        NetworkProviderExtension netExt = new NetworkProviderExtensionBuilder().setPhysicalNetwork("physicalNet")\r
-            .build();\r
-        List<PhysicalLocationRef> resolvedLocations = networkAware.resolveDomainLocations(netExt);\r
-        PhysicalLocationRef physLocationRef = resolvedLocations.get(0);\r
-        assertEquals(nodeId, physLocationRef.getNodeId());\r
-        assertEquals(tpId.getValue(), physLocationRef.getInterface().get(0));\r
-    }\r
-\r
-    private Network createTestNetwork(String name, NetworkProviderExtension ext) {\r
-        return new NetworkBuilder().setUuid(new Uuid(UUID.randomUUID().toString()))\r
-            .setName(name)\r
-            .addAugmentation(NetworkProviderExtension.class, ext)\r
-            .build();\r
-    }\r
-\r
-    private void writeBasicTopology(TopologyId topologyId, NodeId nodeId, TpId tpId) {\r
-        TerminationPoint tp = new TerminationPointBuilder().setTpId(tpId).build();\r
-        Node node = new NodeBuilder().setNodeId(new NodeId(nodeId))\r
-            .setTerminationPoint(ImmutableList.<TerminationPoint>of(tp))\r
-            .build();\r
-        Topology topology = new TopologyBuilder().setTopologyId(topologyId)\r
-            .setNode(ImmutableList.<Node>of(node))\r
-            .build();\r
-        WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();\r
-        wTx.put(LogicalDatastoreType.CONFIGURATION, networkAware.getTopologyIid(new TopologyId("physicalNet")),\r
-                topology, true);\r
-        DataStoreHelper.submitToDs(wTx);\r
-    }\r
-}\r
+/*
+ * 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.neutron.vpp.mapper.processors;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+import java.util.UUID;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.FlatNetwork;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.VlanNetwork;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.GbpBridgeDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.bridge.domain.base.attributes.PhysicalLocationRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.NetworkTypeFlat;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.NetworkTypeVlan;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.NetworkBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.NetworkProviderExtension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.NetworkProviderExtensionBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
+
+public class NetworkAwareTest extends AbstractDataBrokerTest {
+
+    private DataBroker dataBroker;
+    private NetworkAware networkAware;
+    private NetworkProviderExtensionBuilder netExtBuilder;
+
+    @Before
+    public void init() {
+        dataBroker = Mockito.spy(getDataBroker());
+        networkAware = new NetworkAware(dataBroker);
+        netExtBuilder = new NetworkProviderExtensionBuilder();
+        netExtBuilder.setPhysicalNetwork("physicalNet");
+    }
+
+    @Test
+    public void testProcessCreatedNeutronDto_flat() {
+        netExtBuilder.setNetworkType(NetworkTypeFlat.class);
+        Network network = createTestNetwork("net", netExtBuilder.build());
+        networkAware.processCreatedNeutronDto(network);
+        ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();
+        Optional<GbpBridgeDomain> optBrDomain = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+                networkAware.getGbpBridgeDomainIid(network.getUuid().getValue()), rTx);
+        assertTrue(optBrDomain.isPresent());
+    }
+
+    @Test
+    public void testProcessUpdatedNeutronDto() {
+        netExtBuilder.setNetworkType(NetworkTypeFlat.class);
+        Network network1 = createTestNetwork("net1", netExtBuilder.build());
+        Network network2 = new NetworkBuilder(network1).setName("net2")
+            .addAugmentation(NetworkProviderExtension.class, netExtBuilder.build())
+            .build();
+        networkAware.processUpdatedNeutronDto(network1, network2);
+        ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();
+        Optional<GbpBridgeDomain> optBrDomain = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+                networkAware.getGbpBridgeDomainIid(network2.getUuid().getValue()), rTx);
+        assertTrue(optBrDomain.isPresent());
+        assertEquals(optBrDomain.get().getDescription(), "net2");
+    }
+
+    @Test
+    public void testProcessDeletedNeutronDto() {
+        netExtBuilder.setNetworkType(NetworkTypeFlat.class);
+        Network network = createTestNetwork("net1", netExtBuilder.build());
+        networkAware.processDeletedNeutronDto(network);
+        ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();
+        Optional<GbpBridgeDomain> optBrDomain = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+                networkAware.getGbpBridgeDomainIid(network.getUuid().getValue()), rTx);
+        assertFalse(optBrDomain.isPresent());
+    }
+
+    @Test
+    public void testCreateBridgeDomain_vlanNetwork() {
+        netExtBuilder.setNetworkType(NetworkTypeVlan.class);
+        netExtBuilder.setSegmentationId("2016");
+        Network vlanNetwork = createTestNetwork("VlanNet", netExtBuilder.build());
+        GbpBridgeDomain bridgeDomain = networkAware.createGbpBridgeDomain(vlanNetwork);
+        assertEquals(bridgeDomain.getId(), vlanNetwork.getUuid().getValue());
+        assertEquals(bridgeDomain.getDescription(), vlanNetwork.getName());
+        assertEquals(bridgeDomain.getType(), VlanNetwork.class);
+        assertEquals(bridgeDomain.getVlan(), new VlanId(Integer.valueOf(2016)));
+    }
+
+    @Test
+    public void testCreateBridgeDomain_flatNetwork() {
+        netExtBuilder.setNetworkType(NetworkTypeFlat.class);
+        Network flatNetwork = createTestNetwork("FlatNet", netExtBuilder.build());
+        GbpBridgeDomain bridgeDomain = networkAware.createGbpBridgeDomain(flatNetwork);
+        assertEquals(bridgeDomain.getId(), flatNetwork.getUuid().getValue());
+        assertEquals(bridgeDomain.getDescription(), flatNetwork.getName());
+        assertEquals(bridgeDomain.getType(), FlatNetwork.class);
+    }
+
+    @Test
+    public void testCreateBridgeDomain_noPhysicalNetwork() {
+        netExtBuilder.setNetworkType(NetworkTypeFlat.class);
+        netExtBuilder.setPhysicalNetwork(null);
+        Network flatNetwork = createTestNetwork("FlatNet", netExtBuilder.build());
+        GbpBridgeDomain bridgeDomain = networkAware.createGbpBridgeDomain(flatNetwork);
+        assertNull(bridgeDomain.getPhysicalLocationRef());
+    }
+
+    @Test
+    public void testCreateBridgeDomain_noNetworkType() {
+        Network vlanNetwork = createTestNetwork("noTypeNet", new NetworkProviderExtensionBuilder().build());
+        GbpBridgeDomain bridgeDomain = networkAware.createGbpBridgeDomain(vlanNetwork);
+        assertNull(bridgeDomain);
+    }
+
+    @Test
+    public void testResolveDomainLocations() {
+        NodeId nodeId = new NodeId("node1");
+        TpId tpId = new TpId("tp1");
+        TopologyId topologyId = new TopologyId("physicalNet");
+        writeBasicTopology(topologyId, nodeId, tpId);
+        NetworkProviderExtension netExt = new NetworkProviderExtensionBuilder().setPhysicalNetwork("physicalNet")
+            .build();
+        List<PhysicalLocationRef> resolvedLocations = networkAware.resolveDomainLocations(netExt);
+        PhysicalLocationRef physLocationRef = resolvedLocations.get(0);
+        assertEquals(nodeId, physLocationRef.getNodeId());
+        assertEquals(tpId.getValue(), physLocationRef.getInterface().get(0));
+    }
+
+    private Network createTestNetwork(String name, NetworkProviderExtension ext) {
+        return new NetworkBuilder().setUuid(new Uuid(UUID.randomUUID().toString()))
+            .setName(name)
+            .addAugmentation(NetworkProviderExtension.class, ext)
+            .build();
+    }
+
+    private void writeBasicTopology(TopologyId topologyId, NodeId nodeId, TpId tpId) {
+        TerminationPoint tp = new TerminationPointBuilder().setTpId(tpId).build();
+        Node node = new NodeBuilder().setNodeId(new NodeId(nodeId))
+            .setTerminationPoint(ImmutableList.<TerminationPoint>of(tp))
+            .build();
+        Topology topology = new TopologyBuilder().setTopologyId(topologyId)
+            .setNode(ImmutableList.<Node>of(node))
+            .build();
+        WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
+        wTx.put(LogicalDatastoreType.CONFIGURATION, networkAware.getTopologyIid(new TopologyId("physicalNet")),
+                topology, true);
+        DataStoreHelper.submitToDs(wTx);
+    }
+}
index 3d202801336bdc927d6e005b8615ea003fc788ed..ff5d5f3d73aac6f10c3262cab50160835d6fba8c 100644 (file)
-/*\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.neutron.vpp.mapper.processors;\r
-\r
-import static org.mockito.Matchers.any;\r
-import static org.mockito.Matchers.eq;\r
-import static org.mockito.Mockito.verify;\r
-\r
-import java.util.concurrent.ExecutionException;\r
-\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.mockito.Mockito;\r
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;\r
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;\r
-import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;\r
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.GbpByNeutronMappings;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.BaseEndpointsByPorts;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.base.endpoints.by.ports.BaseEndpointByPort;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.PortBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
-\r
-public class NeutronListenerTest extends AbstractDataBrokerTest {\r
-\r
-    private DataBroker dataBroker;\r
-\r
-    private NodeId routingNode;\r
-    private Port port;\r
-    private BaseEndpointByPort bebp;\r
-    private NeutronListener neutronListener;\r
-    private PortAware baseEpByPortListener;\r
-\r
-    @Before\r
-    public void init() {\r
-        port = TestUtils.createValidVppPort();\r
-        bebp = TestUtils.createBaseEndpointByPortForPort();\r
-        dataBroker = getDataBroker();\r
-        neutronListener = new NeutronListener(dataBroker, routingNode);\r
-        neutronListener.clearDataChangeProviders();\r
-        baseEpByPortListener = Mockito.spy(new PortAware(new PortHandler(\r
-                dataBroker, routingNode), dataBroker));\r
-        neutronListener.addDataChangeProvider(baseEpByPortListener);\r
-    }\r
-\r
-    @Test\r
-    public void constructorTest() {\r
-        dataBroker = Mockito.spy(dataBroker);\r
-        NeutronListener neutronListener = new NeutronListener(dataBroker, routingNode);\r
-        verify(dataBroker).registerDataTreeChangeListener(\r
-                eq(new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,\r
-                        InstanceIdentifier.builder(Neutron.class)\r
-                            .build())), any(NeutronListener.class));\r
-        verify(dataBroker).registerDataTreeChangeListener(\r
-                eq(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,\r
-                        InstanceIdentifier.builder(Mappings.class)\r
-                        .child(GbpByNeutronMappings.class)\r
-                        .child(BaseEndpointsByPorts.class)\r
-                        .child(BaseEndpointByPort.class)\r
-                        .build())), any(PortAware.class));\r
-        neutronListener.close();\r
-    }\r
-\r
-    @Test\r
-    public void testProcessCreatedNeutronDto() throws Exception {\r
-        putPortAndBaseEndpointByPort();\r
-        neutronListener.close();\r
-        verify(baseEpByPortListener).processCreatedNeutronDto(port);\r
-    }\r
-\r
-    @Test\r
-    public void testProcessUpdatedNeutronDto() throws Exception {\r
-        putPortAndBaseEndpointByPort();\r
-        Port updatedPort = new PortBuilder(port).setName("renamed").build();\r
-        WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();\r
-        wTx.put(LogicalDatastoreType.CONFIGURATION, TestUtils.createPortIid(updatedPort.getKey()), updatedPort);\r
-        wTx.submit().get();\r
-        neutronListener.close();\r
-        verify(baseEpByPortListener).processUpdatedNeutronDto(port, updatedPort);\r
-    }\r
-\r
-    @Test\r
-    public void testProcessDeletedNeutronDto() throws Exception {\r
-        putPortAndBaseEndpointByPort();\r
-        WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();\r
-        wTx.delete(LogicalDatastoreType.CONFIGURATION, TestUtils.createPortIid(port.getKey()));\r
-        wTx.submit().get();\r
-        verify(baseEpByPortListener).processDeletedNeutronDto(port);\r
-    }\r
-\r
-    private void putPortAndBaseEndpointByPort() throws InterruptedException, ExecutionException {\r
-        WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();\r
-        wTx.put(LogicalDatastoreType.CONFIGURATION, TestUtils.createPortIid(port.getKey()), port);\r
-        wTx.put(LogicalDatastoreType.OPERATIONAL, TestUtils.createBaseEpByPortIid(port.getUuid()), bebp);\r
-        wTx.submit().get();\r
-    }\r
-}\r
+/*
+ * 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.neutron.vpp.mapper.processors;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
+
+import java.util.concurrent.ExecutionException;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.GbpByNeutronMappings;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.BaseEndpointsByPorts;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.base.endpoints.by.ports.BaseEndpointByPort;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.PortBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class NeutronListenerTest extends AbstractDataBrokerTest {
+
+    private DataBroker dataBroker;
+
+    private NodeId routingNode;
+    private Port port;
+    private BaseEndpointByPort bebp;
+    private NeutronListener neutronListener;
+    private PortAware baseEpByPortListener;
+
+    @Before
+    public void init() {
+        port = TestUtils.createValidVppPort();
+        bebp = TestUtils.createBaseEndpointByPortForPort();
+        dataBroker = getDataBroker();
+        neutronListener = new NeutronListener(dataBroker, routingNode);
+        neutronListener.clearDataChangeProviders();
+        baseEpByPortListener = Mockito.spy(new PortAware(new PortHandler(
+                dataBroker, routingNode), dataBroker));
+        neutronListener.addDataChangeProvider(baseEpByPortListener);
+    }
+
+    @Test
+    public void constructorTest() {
+        dataBroker = Mockito.spy(dataBroker);
+        NeutronListener neutronListener = new NeutronListener(dataBroker, routingNode);
+        verify(dataBroker).registerDataTreeChangeListener(
+                eq(new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
+                        InstanceIdentifier.builder(Neutron.class)
+                            .build())), any(NeutronListener.class));
+        verify(dataBroker).registerDataTreeChangeListener(
+                eq(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
+                        InstanceIdentifier.builder(Mappings.class)
+                        .child(GbpByNeutronMappings.class)
+                        .child(BaseEndpointsByPorts.class)
+                        .child(BaseEndpointByPort.class)
+                        .build())), any(PortAware.class));
+        neutronListener.close();
+    }
+
+    @Test
+    public void testProcessCreatedNeutronDto() throws Exception {
+        putPortAndBaseEndpointByPort();
+        neutronListener.close();
+        verify(baseEpByPortListener).processCreatedNeutronDto(port);
+    }
+
+    @Test
+    public void testProcessUpdatedNeutronDto() throws Exception {
+        putPortAndBaseEndpointByPort();
+        Port updatedPort = new PortBuilder(port).setName("renamed").build();
+        WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
+        wTx.put(LogicalDatastoreType.CONFIGURATION, TestUtils.createPortIid(updatedPort.getKey()), updatedPort);
+        wTx.submit().get();
+        neutronListener.close();
+        verify(baseEpByPortListener).processUpdatedNeutronDto(port, updatedPort);
+    }
+
+    @Test
+    public void testProcessDeletedNeutronDto() throws Exception {
+        putPortAndBaseEndpointByPort();
+        WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
+        wTx.delete(LogicalDatastoreType.CONFIGURATION, TestUtils.createPortIid(port.getKey()));
+        wTx.submit().get();
+        verify(baseEpByPortListener).processDeletedNeutronDto(port);
+    }
+
+    private void putPortAndBaseEndpointByPort() throws InterruptedException, ExecutionException {
+        WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
+        wTx.put(LogicalDatastoreType.CONFIGURATION, TestUtils.createPortIid(port.getKey()), port);
+        wTx.put(LogicalDatastoreType.OPERATIONAL, TestUtils.createBaseEpByPortIid(port.getUuid()), bebp);
+        wTx.submit().get();
+    }
+}
index eae5be27e5c54649e83fe5321391cd3fbe030e5b..05eecb8461ab6bacad7ea68d675944b68638fda6 100644 (file)
-/*\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.neutron.vpp.mapper.processors;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.assertTrue;\r
-\r
-import java.util.Collections;\r
-import java.util.Iterator;\r
-\r
-import javax.annotation.Nonnull;\r
-\r
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;\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.groupbasedpolicy.neutron.mapper.util.MappingUtils;\r
-import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContextId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.UniqueId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev170511.MacAddressType;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.AddressType;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.ContextType;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.GbpByNeutronMappings;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.BaseEndpointsByPorts;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.base.endpoints.by.ports.BaseEndpointByPort;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.base.endpoints.by.ports.BaseEndpointByPortBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.base.endpoints.by.ports.BaseEndpointByPortKey;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.Config;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpoint;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpointKey;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.binding.rev150712.PortBindingExtension;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.binding.rev150712.PortBindingExtensionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.binding.rev150712.binding.attributes.VifDetailsBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.binding.rev150712.binding.attributes.VifDetailsKey;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.RouterBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.RouterKey;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.PortBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.PortKey;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;\r
-\r
-public class TestUtils {\r
-    static String TEST_SOCKET = "/tmp/socket_testsocket";\r
-    static final String NODE_1 = "devstack-control";\r
-    static final String DUMMY_UUID = "00000000-1111-2222-3333-444444444444";\r
-\r
-    public static Port createValidVppPort() {\r
-        PortBindingExtension portBindingExt = new PortBindingExtensionBuilder().setHostId(NODE_1)\r
-            .setVifType("vhostuser")\r
-            .setVifDetails(Collections.singletonList(\r
-                new VifDetailsBuilder().setKey(new VifDetailsKey("vhostuser_socket"))\r
-                    .setValue(TEST_SOCKET)\r
-                    .build()))\r
-            .build();\r
-        return new PortBuilder().setUuid(new Uuid(DUMMY_UUID))\r
-            .setDeviceOwner("compute")\r
-            .setDeviceId(DUMMY_UUID)\r
-            .setMacAddress(new MacAddress("00:11:00:00:11:11"))\r
-            .addAugmentation(PortBindingExtension.class, portBindingExt)\r
-            .build();\r
-    }\r
-\r
-    public static Port createNonVppPort() {\r
-        return new PortBuilder().setUuid(new Uuid(DUMMY_UUID))\r
-            .setDeviceOwner("owner1")\r
-            .build();\r
-    }\r
-\r
-    public static BaseEndpointByPort createBaseEndpointByPortForPort() {\r
-        return new BaseEndpointByPortBuilder().setContextId(new ContextId("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"))\r
-            .setAddress("00:11:11:11:11:11")\r
-            .setPortId(new UniqueId(DUMMY_UUID))\r
-            .setContextType(MappingUtils.L2_BRDIGE_DOMAIN)\r
-            .setAddressType(MacAddressType.class)\r
-            .build();\r
-    }\r
-\r
-    static void writeQrouter(@Nonnull DataBroker dataBroker, @Nonnull RouterKey routerKey) {\r
-        WriteTransaction tx = dataBroker.newWriteOnlyTransaction();\r
-        tx.put(LogicalDatastoreType.CONFIGURATION, createNeutronRouterIid(routerKey),\r
-                new RouterBuilder().setKey(routerKey).build(), true);\r
-        DataStoreHelper.submitToDs(tx);\r
-    }\r
-\r
-    public static VppEndpointKey createVppEndpointKey(BaseEndpointByPort bebp) {\r
-        return new VppEndpointKey(bebp.getAddress(), bebp.getAddressType(), bebp.getContextId(), bebp.getContextType());\r
-    }\r
-\r
-    public static InstanceIdentifier<VppEndpoint> createVppEpIid(VppEndpointKey key) {\r
-        return InstanceIdentifier.builder(Config.class).child(VppEndpoint.class, key).build();\r
-    }\r
-\r
-    public static InstanceIdentifier<VppEndpoint> createVppEpIid(String addr, Class<? extends AddressType> addrType,\r
-            ContextId ctxId, Class<? extends ContextType> ctxType) {\r
-        return createVppEpIid(new VppEndpointKey(addr, addrType, ctxId, ctxType));\r
-    }\r
-\r
-    public static InstanceIdentifier<Port> createPortIid(PortKey portKey) {\r
-        return InstanceIdentifier.builder(Neutron.class).child(Ports.class).child(Port.class, portKey).build();\r
-    }\r
-\r
-    public static InstanceIdentifier<BaseEndpointByPort> createBaseEpByPortIid(Uuid uuid) {\r
-        return createBaseEpByPortIid(new UniqueId(uuid.getValue()));\r
-    }\r
-\r
-    public static InstanceIdentifier<BaseEndpointByPort> createBaseEpByPortIid(UniqueId uuid) {\r
-        return InstanceIdentifier.builder(Mappings.class)\r
-            .child(GbpByNeutronMappings.class)\r
-            .child(BaseEndpointsByPorts.class)\r
-            .child(BaseEndpointByPort.class, new BaseEndpointByPortKey(uuid))\r
-            .build();\r
-    }\r
-\r
-    public static InstanceIdentifier<Router> createNeutronRouterIid(RouterKey routerKey) {\r
-        return InstanceIdentifier.builder(Neutron.class).child(Routers.class).child(Router.class, routerKey).build();\r
-    }\r
-\r
-    public static void assertPathArgumentTypes(Iterable<PathArgument> pathArguments, Class<?>[] expectedTypes) {\r
-        assertNotNull(pathArguments);\r
-        Iterator<PathArgument> it = pathArguments.iterator();\r
-        for (int i = 0; i < expectedTypes.length; ++i) {\r
-            assertTrue("Next path argument expected.", it.hasNext());\r
-            assertEquals("Unexpected path argument type.", expectedTypes[i], it.next().getType());\r
-        }\r
-    }\r
-}\r
+/*
+ * 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.neutron.vpp.mapper.processors;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collections;
+import java.util.Iterator;
+
+import javax.annotation.Nonnull;
+
+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.neutron.mapper.util.MappingUtils;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContextId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.UniqueId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev170511.MacAddressType;
+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.neutron.gbp.mapper.rev150513.Mappings;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.GbpByNeutronMappings;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.BaseEndpointsByPorts;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.base.endpoints.by.ports.BaseEndpointByPort;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.base.endpoints.by.ports.BaseEndpointByPortBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.mappings.gbp.by.neutron.mappings.base.endpoints.by.ports.BaseEndpointByPortKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.Config;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpointKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.binding.rev150712.PortBindingExtension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.binding.rev150712.PortBindingExtensionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.binding.rev150712.binding.attributes.VifDetailsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.binding.rev150712.binding.attributes.VifDetailsKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.RouterBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.RouterKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.PortBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.PortKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
+
+public class TestUtils {
+    static String TEST_SOCKET = "/tmp/socket_testsocket";
+    static final String NODE_1 = "devstack-control";
+    static final String DUMMY_UUID = "00000000-1111-2222-3333-444444444444";
+
+    public static Port createValidVppPort() {
+        PortBindingExtension portBindingExt = new PortBindingExtensionBuilder().setHostId(NODE_1)
+            .setVifType("vhostuser")
+            .setVifDetails(Collections.singletonList(
+                new VifDetailsBuilder().setKey(new VifDetailsKey("vhostuser_socket"))
+                    .setValue(TEST_SOCKET)
+                    .build()))
+            .build();
+        return new PortBuilder().setUuid(new Uuid(DUMMY_UUID))
+            .setDeviceOwner("compute")
+            .setDeviceId(DUMMY_UUID)
+            .setMacAddress(new MacAddress("00:11:00:00:11:11"))
+            .addAugmentation(PortBindingExtension.class, portBindingExt)
+            .build();
+    }
+
+    public static Port createNonVppPort() {
+        return new PortBuilder().setUuid(new Uuid(DUMMY_UUID))
+            .setDeviceOwner("owner1")
+            .build();
+    }
+
+    public static BaseEndpointByPort createBaseEndpointByPortForPort() {
+        return new BaseEndpointByPortBuilder().setContextId(new ContextId("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"))
+            .setAddress("00:11:11:11:11:11")
+            .setPortId(new UniqueId(DUMMY_UUID))
+            .setContextType(MappingUtils.L2_BRDIGE_DOMAIN)
+            .setAddressType(MacAddressType.class)
+            .build();
+    }
+
+    static void writeQrouter(@Nonnull DataBroker dataBroker, @Nonnull RouterKey routerKey) {
+        WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
+        tx.put(LogicalDatastoreType.CONFIGURATION, createNeutronRouterIid(routerKey),
+                new RouterBuilder().setKey(routerKey).build(), true);
+        DataStoreHelper.submitToDs(tx);
+    }
+
+    public static VppEndpointKey createVppEndpointKey(BaseEndpointByPort bebp) {
+        return new VppEndpointKey(bebp.getAddress(), bebp.getAddressType(), bebp.getContextId(), bebp.getContextType());
+    }
+
+    public static InstanceIdentifier<VppEndpoint> createVppEpIid(VppEndpointKey key) {
+        return InstanceIdentifier.builder(Config.class).child(VppEndpoint.class, key).build();
+    }
+
+    public static InstanceIdentifier<VppEndpoint> createVppEpIid(String addr, Class<? extends AddressType> addrType,
+            ContextId ctxId, Class<? extends ContextType> ctxType) {
+        return createVppEpIid(new VppEndpointKey(addr, addrType, ctxId, ctxType));
+    }
+
+    public static InstanceIdentifier<Port> createPortIid(PortKey portKey) {
+        return InstanceIdentifier.builder(Neutron.class).child(Ports.class).child(Port.class, portKey).build();
+    }
+
+    public static InstanceIdentifier<BaseEndpointByPort> createBaseEpByPortIid(Uuid uuid) {
+        return createBaseEpByPortIid(new UniqueId(uuid.getValue()));
+    }
+
+    public static InstanceIdentifier<BaseEndpointByPort> createBaseEpByPortIid(UniqueId uuid) {
+        return InstanceIdentifier.builder(Mappings.class)
+            .child(GbpByNeutronMappings.class)
+            .child(BaseEndpointsByPorts.class)
+            .child(BaseEndpointByPort.class, new BaseEndpointByPortKey(uuid))
+            .build();
+    }
+
+    public static InstanceIdentifier<Router> createNeutronRouterIid(RouterKey routerKey) {
+        return InstanceIdentifier.builder(Neutron.class).child(Routers.class).child(Router.class, routerKey).build();
+    }
+
+    public static void assertPathArgumentTypes(Iterable<PathArgument> pathArguments, Class<?>[] expectedTypes) {
+        assertNotNull(pathArguments);
+        Iterator<PathArgument> it = pathArguments.iterator();
+        for (int i = 0; i < expectedTypes.length; ++i) {
+            assertTrue("Next path argument expected.", it.hasNext());
+            assertEquals("Unexpected path argument type.", expectedTypes[i], it.next().getType());
+        }
+    }
+}
index dc32d35cf6d47310fb6ff88716f31a28045d3a87..f70c81d6c1d29bff462c09f24269b33f0e34c74d 100644 (file)
@@ -1,36 +1,36 @@
-/*\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.neutron.vpp.mapper.util;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertTrue;\r
-\r
-import org.junit.Test;\r
-import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.SocketInfo;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.Hostconfig;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;\r
-\r
-\r
-public class HostconfigUtilTest {\r
-\r
-    private final NodeId NODE_ID = new NodeId("node1");\r
-    private final String HOST_TYPE = "ODL L2";\r
-    private final String PATH = "/tmp/";\r
-    private final String PREFIX = "socket_";\r
-    private final String VHOSTUSER = "vhostuser";\r
-\r
-    @Test\r
-    public void createHostconfigsDataForTest() {\r
-        Hostconfig hc = HostconfigUtil.createHostconfigsDataFor(NODE_ID, new SocketInfo(PATH, PREFIX));\r
-        assertEquals(hc.getHostId(), NODE_ID.getValue());\r
-        assertEquals(hc.getHostType(), HOST_TYPE);\r
-        assertTrue(hc.getConfig().contains(PATH));\r
-        assertTrue(hc.getConfig().contains(VHOSTUSER));\r
-    }\r
-}\r
+/*
+ * 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.neutron.vpp.mapper.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.SocketInfo;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.Hostconfig;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+
+
+public class HostconfigUtilTest {
+
+    private final NodeId NODE_ID = new NodeId("node1");
+    private final String HOST_TYPE = "ODL L2";
+    private final String PATH = "/tmp/";
+    private final String PREFIX = "socket_";
+    private final String VHOSTUSER = "vhostuser";
+
+    @Test
+    public void createHostconfigsDataForTest() {
+        Hostconfig hc = HostconfigUtil.createHostconfigsDataFor(NODE_ID, new SocketInfo(PATH, PREFIX));
+        assertEquals(hc.getHostId(), NODE_ID.getValue());
+        assertEquals(hc.getHostType(), HOST_TYPE);
+        assertTrue(hc.getConfig().contains(PATH));
+        assertTrue(hc.getConfig().contains(VHOSTUSER));
+    }
+}
index ff20e02c22894a1b5ce8e54862d761c065a55e46..4005ece94793cde46632df0f8c69483b7ed19830 100755 (executable)
@@ -1,83 +1,83 @@
-/*\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
-package org.opendaylight.groupbasedpolicy.renderer.iovisor.endpoint;\r
-\r
-import static org.mockito.Mockito.mock;\r
-import static org.mockito.Mockito.spy;\r
-import static org.mockito.Mockito.when;\r
-\r
-import java.util.Set;\r
-\r
-import com.google.common.collect.ImmutableSet;\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.DataObjectModification;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;\r
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
-import org.opendaylight.groupbasedpolicy.util.IidFactory;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
-\r
-public class EndpointListenerCovrgTest {\r
-\r
-    private EndpointListener listener;\r
-    private DataObjectModification<EndpointL3> rootNode;\r
-    private Set<DataTreeModification<EndpointL3>> changes;\r
-\r
-    private InstanceIdentifier<EndpointL3> rootIdentifier;\r
-\r
-    @SuppressWarnings("unchecked")\r
-    @Before\r
-    public void init() {\r
-        DataBroker dataProvider = mock(DataBroker.class);\r
-\r
-        EndpointManager endpointManager = mock(EndpointManager.class);\r
-        listener = spy(new EndpointListener(dataProvider, endpointManager));\r
-\r
-        EndpointL3 endpointL3 = mock(EndpointL3.class);\r
-\r
-        rootNode = mock(DataObjectModification.class);\r
-        rootIdentifier = IidFactory.l3EndpointsIidWildcard();\r
-        DataTreeIdentifier<EndpointL3> rootPath =\r
-                new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, rootIdentifier);\r
-\r
-        DataTreeModification<EndpointL3> change = mock(DataTreeModification.class);\r
-\r
-        when(change.getRootNode()).thenReturn(rootNode);\r
-        when(change.getRootPath()).thenReturn(rootPath);\r
-\r
-        changes = ImmutableSet.of(change);\r
-\r
-        when(rootNode.getDataBefore()).thenReturn(endpointL3);\r
-        when(rootNode.getDataAfter()).thenReturn(endpointL3);\r
-    }\r
-\r
-    @Test\r
-    public void testOnWrite() {\r
-        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);\r
-\r
-        listener.onDataTreeChanged(changes);\r
-    }\r
-\r
-    @Test(expected = UnsupportedOperationException.class)\r
-    public void testOnDelete() {\r
-        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);\r
-\r
-        listener.onDataTreeChanged(changes);\r
-    }\r
-\r
-    @Test\r
-    public void testOnSubtreeModified() {\r
-        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);\r
-\r
-        listener.onDataTreeChanged(changes);\r
-    }\r
-\r
-}\r
+/*
+ * 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.iovisor.endpoint;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.util.Set;
+
+import com.google.common.collect.ImmutableSet;
+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.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.util.IidFactory;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class EndpointListenerCovrgTest {
+
+    private EndpointListener listener;
+    private DataObjectModification<EndpointL3> rootNode;
+    private Set<DataTreeModification<EndpointL3>> changes;
+
+    private InstanceIdentifier<EndpointL3> rootIdentifier;
+
+    @SuppressWarnings("unchecked")
+    @Before
+    public void init() {
+        DataBroker dataProvider = mock(DataBroker.class);
+
+        EndpointManager endpointManager = mock(EndpointManager.class);
+        listener = spy(new EndpointListener(dataProvider, endpointManager));
+
+        EndpointL3 endpointL3 = mock(EndpointL3.class);
+
+        rootNode = mock(DataObjectModification.class);
+        rootIdentifier = IidFactory.l3EndpointsIidWildcard();
+        DataTreeIdentifier<EndpointL3> rootPath =
+                new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, rootIdentifier);
+
+        DataTreeModification<EndpointL3> change = mock(DataTreeModification.class);
+
+        when(change.getRootNode()).thenReturn(rootNode);
+        when(change.getRootPath()).thenReturn(rootPath);
+
+        changes = ImmutableSet.of(change);
+
+        when(rootNode.getDataBefore()).thenReturn(endpointL3);
+        when(rootNode.getDataAfter()).thenReturn(endpointL3);
+    }
+
+    @Test
+    public void testOnWrite() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);
+
+        listener.onDataTreeChanged(changes);
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testOnDelete() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);
+
+        listener.onDataTreeChanged(changes);
+    }
+
+    @Test
+    public void testOnSubtreeModified() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+
+        listener.onDataTreeChanged(changes);
+    }
+
+}
index c44617d739ace0e8203de638a7d08653e5d9874f..861c65cef64020fc6dd8d65e62ce50dac979984b 100755 (executable)
@@ -1,69 +1,69 @@
-/*\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
-package org.opendaylight.groupbasedpolicy.renderer.iovisor.endpoint;\r
-\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.assertNull;\r
-import static org.mockito.Matchers.any;\r
-import static org.mockito.Mockito.mock;\r
-import static org.mockito.Mockito.verify;\r
-import static org.mockito.Mockito.when;\r
-\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.opendaylight.groupbasedpolicy.api.EpRendererAugmentationRegistry;\r
-import org.opendaylight.groupbasedpolicy.renderer.iovisor.test.GbpIovisorDataBrokerTest;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.IovisorModuleAugmentationInput;\r
-\r
-public class IovisorEndpointAugCovrgTest extends GbpIovisorDataBrokerTest {\r
-\r
-    private EpRendererAugmentationRegistry epRAR;\r
-    private IovisorEndpointAug aug;\r
-\r
-    @Before\r
-    public void init() {\r
-        epRAR = mock(EpRendererAugmentationRegistry.class);\r
-\r
-        aug = new IovisorEndpointAug(epRAR);\r
-    }\r
-\r
-    @Test\r
-    public void testClose() throws Exception {\r
-        IovisorEndpointAug other = new IovisorEndpointAug(epRAR);\r
-        other.close();\r
-\r
-        verify(epRAR).unregister(any(IovisorEndpointAug.class));\r
-    }\r
-\r
-    @Test\r
-    public void testBuildEndpointAugmentation() {\r
-        assertNull(aug.buildEndpointAugmentation(null));\r
-    }\r
-\r
-    @Test\r
-    public void testBuildEndpointL3Augmentation() {\r
-        RegisterEndpointInput input = mock(RegisterEndpointInput.class);\r
-        IovisorModuleAugmentationInput iomAugInput = mock(IovisorModuleAugmentationInput.class);\r
-        when(input.getAugmentation(IovisorModuleAugmentationInput.class)).thenReturn(iomAugInput);\r
-        assertNotNull(aug.buildEndpointL3Augmentation(input));\r
-    }\r
-\r
-    @Test\r
-    public void testBuildEndpointL3Augmentation_Null() {\r
-        RegisterEndpointInput input = mock(RegisterEndpointInput.class);\r
-        when(input.getAugmentation(IovisorModuleAugmentationInput.class)).thenReturn(null);\r
-        assertNull(aug.buildEndpointL3Augmentation(input));\r
-    }\r
-\r
-    @Test\r
-    public void testBuildL3PrefixEndpointAugmentation() {\r
-        assertNull(aug.buildL3PrefixEndpointAugmentation(null));\r
-    }\r
-\r
-}\r
+/*
+ * 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.iovisor.endpoint;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.groupbasedpolicy.api.EpRendererAugmentationRegistry;
+import org.opendaylight.groupbasedpolicy.renderer.iovisor.test.GbpIovisorDataBrokerTest;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.IovisorModuleAugmentationInput;
+
+public class IovisorEndpointAugCovrgTest extends GbpIovisorDataBrokerTest {
+
+    private EpRendererAugmentationRegistry epRAR;
+    private IovisorEndpointAug aug;
+
+    @Before
+    public void init() {
+        epRAR = mock(EpRendererAugmentationRegistry.class);
+
+        aug = new IovisorEndpointAug(epRAR);
+    }
+
+    @Test
+    public void testClose() throws Exception {
+        IovisorEndpointAug other = new IovisorEndpointAug(epRAR);
+        other.close();
+
+        verify(epRAR).unregister(any(IovisorEndpointAug.class));
+    }
+
+    @Test
+    public void testBuildEndpointAugmentation() {
+        assertNull(aug.buildEndpointAugmentation(null));
+    }
+
+    @Test
+    public void testBuildEndpointL3Augmentation() {
+        RegisterEndpointInput input = mock(RegisterEndpointInput.class);
+        IovisorModuleAugmentationInput iomAugInput = mock(IovisorModuleAugmentationInput.class);
+        when(input.getAugmentation(IovisorModuleAugmentationInput.class)).thenReturn(iomAugInput);
+        assertNotNull(aug.buildEndpointL3Augmentation(input));
+    }
+
+    @Test
+    public void testBuildEndpointL3Augmentation_Null() {
+        RegisterEndpointInput input = mock(RegisterEndpointInput.class);
+        when(input.getAugmentation(IovisorModuleAugmentationInput.class)).thenReturn(null);
+        assertNull(aug.buildEndpointL3Augmentation(input));
+    }
+
+    @Test
+    public void testBuildL3PrefixEndpointAugmentation() {
+        assertNull(aug.buildL3PrefixEndpointAugmentation(null));
+    }
+
+}
index daf72098880303535a956632a2d5af85da0566ac..ff5b87c9ae5a50f4d63676536e7768e1bf49c0cf 100755 (executable)
-/*\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
-package org.opendaylight.groupbasedpolicy.renderer.iovisor.sf;\r
-\r
-import static org.mockito.Mockito.mock;\r
-import static org.mockito.Mockito.spy;\r
-import static org.mockito.Mockito.verify;\r
-import static org.mockito.Mockito.when;\r
-\r
-import java.util.Set;\r
-\r
-import com.google.common.collect.ImmutableSet;\r
-import com.google.common.util.concurrent.CheckedFuture;\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.DataObjectModification;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;\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.groupbasedpolicy.api.sf.AllowActionDefinition;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.SubjectFeatureDefinitions;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinition;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinitionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinitionKey;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
-\r
-public class ActionDefinitionListenerTest {\r
-\r
-    private ActionDefinitionListener listener;\r
-    private DataObjectModification<ActionDefinition> rootNode;\r
-    private Set<DataTreeModification<ActionDefinition>> changes;\r
-\r
-    private InstanceIdentifier<ActionDefinition> rootIdentifier;\r
-    private DataBroker dataProvider;\r
-\r
-    @SuppressWarnings("unchecked")\r
-    @Before\r
-    public void init() {\r
-        dataProvider = mock(DataBroker.class);\r
-\r
-        listener = spy(new ActionDefinitionListener(dataProvider));\r
-\r
-        ActionDefinitionKey key = mock(ActionDefinitionKey.class);\r
-        rootNode = mock(DataObjectModification.class);\r
-        rootIdentifier =\r
-                InstanceIdentifier.builder(SubjectFeatureDefinitions.class).child(ActionDefinition.class, key).build();\r
-        DataTreeIdentifier<ActionDefinition> rootPath =\r
-                new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, rootIdentifier);\r
-\r
-        DataTreeModification<ActionDefinition> change = mock(DataTreeModification.class);\r
-\r
-        when(change.getRootNode()).thenReturn(rootNode);\r
-        when(change.getRootPath()).thenReturn(rootPath);\r
-\r
-        changes = ImmutableSet.of(change);\r
-\r
-        ActionDefinition def = new ActionDefinitionBuilder().setId(AllowActionDefinition.ID).build();\r
-\r
-        when(rootNode.getDataBefore()).thenReturn(def);\r
-        when(rootNode.getDataAfter()).thenReturn(def);\r
-    }\r
-\r
-    @Test\r
-    public void testOnWrite() {\r
-        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);\r
-        WriteTransaction wt = resetTransaction();\r
-\r
-        listener.onDataTreeChanged(changes);\r
-\r
-        verify(listener).onSubtreeModified(rootNode, rootIdentifier);\r
-    }\r
-\r
-    @Test\r
-    public void testOnDelete() {\r
-        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);\r
-        WriteTransaction wt = resetTransaction();\r
-\r
-        listener.onDataTreeChanged(changes);\r
-\r
-        verify(listener).onDelete(rootNode, rootIdentifier);\r
-    }\r
-\r
-    @Test\r
-    public void testOnSubtreeModified() {\r
-        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);\r
-        WriteTransaction wt = resetTransaction();\r
-\r
-        listener.onDataTreeChanged(changes);\r
-\r
-        verify(listener).onSubtreeModified(rootNode, rootIdentifier);\r
-    }\r
-\r
-    private WriteTransaction resetTransaction() {\r
-        WriteTransaction wt = mock(WriteTransaction.class);\r
-        CheckedFuture checkedFuture = mock(CheckedFuture.class);\r
-        when(wt.submit()).thenReturn(checkedFuture);\r
-        when(dataProvider.newWriteOnlyTransaction()).thenReturn(wt);\r
-        return wt;\r
-    }\r
-\r
-}\r
+/*
+ * 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.iovisor.sf;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.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.api.sf.AllowActionDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.SubjectFeatureDefinitions;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinitionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinitionKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class ActionDefinitionListenerTest {
+
+    private ActionDefinitionListener listener;
+    private DataObjectModification<ActionDefinition> rootNode;
+    private Set<DataTreeModification<ActionDefinition>> changes;
+
+    private InstanceIdentifier<ActionDefinition> rootIdentifier;
+    private DataBroker dataProvider;
+
+    @SuppressWarnings("unchecked")
+    @Before
+    public void init() {
+        dataProvider = mock(DataBroker.class);
+
+        listener = spy(new ActionDefinitionListener(dataProvider));
+
+        ActionDefinitionKey key = mock(ActionDefinitionKey.class);
+        rootNode = mock(DataObjectModification.class);
+        rootIdentifier =
+                InstanceIdentifier.builder(SubjectFeatureDefinitions.class).child(ActionDefinition.class, key).build();
+        DataTreeIdentifier<ActionDefinition> rootPath =
+                new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, rootIdentifier);
+
+        DataTreeModification<ActionDefinition> change = mock(DataTreeModification.class);
+
+        when(change.getRootNode()).thenReturn(rootNode);
+        when(change.getRootPath()).thenReturn(rootPath);
+
+        changes = ImmutableSet.of(change);
+
+        ActionDefinition def = new ActionDefinitionBuilder().setId(AllowActionDefinition.ID).build();
+
+        when(rootNode.getDataBefore()).thenReturn(def);
+        when(rootNode.getDataAfter()).thenReturn(def);
+    }
+
+    @Test
+    public void testOnWrite() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(listener).onSubtreeModified(rootNode, rootIdentifier);
+    }
+
+    @Test
+    public void testOnDelete() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(listener).onDelete(rootNode, rootIdentifier);
+    }
+
+    @Test
+    public void testOnSubtreeModified() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(listener).onSubtreeModified(rootNode, rootIdentifier);
+    }
+
+    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;
+    }
+
+}
index 2ac13317e1450b5e9c29f31902a540a50e6f152e..2c67742eb003c46e16bd8b3ea5e6e3f294070785 100755 (executable)
@@ -1,52 +1,52 @@
-/*\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.iovisor.sf;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertTrue;\r
-\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.opendaylight.groupbasedpolicy.api.ValidationResult;\r
-import org.opendaylight.groupbasedpolicy.api.sf.AllowActionDefinition;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ActionInstance;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ActionInstanceBuilder;\r
-\r
-public class AllowActionTest {\r
-\r
-    AllowAction action;\r
-\r
-    @Before\r
-    public void init() {\r
-        action = new AllowAction();\r
-    }\r
-\r
-    @Test\r
-    public void testGetId() {\r
-        assertEquals(action.getId(), AllowActionDefinition.ID);\r
-    }\r
-\r
-    @Test\r
-    public void testGetActionDef() {\r
-        assertEquals(action.getActionDef(), AllowActionDefinition.DEFINITION);\r
-    }\r
-\r
-    @Test\r
-    public void testGetSupportedParameterValues() {\r
-        assertTrue(action.getSupportedParameterValues().isEmpty());\r
-    }\r
-\r
-    @Test\r
-    public void testValidate() {\r
-        ActionInstance actionInstance = new ActionInstanceBuilder().build();\r
-        ValidationResult result = action.validate(actionInstance);\r
-        assertTrue(result.isValid());\r
-    }\r
-\r
-}\r
+/*
+ * 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.iovisor.sf;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.groupbasedpolicy.api.ValidationResult;
+import org.opendaylight.groupbasedpolicy.api.sf.AllowActionDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ActionInstance;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ActionInstanceBuilder;
+
+public class AllowActionTest {
+
+    AllowAction action;
+
+    @Before
+    public void init() {
+        action = new AllowAction();
+    }
+
+    @Test
+    public void testGetId() {
+        assertEquals(action.getId(), AllowActionDefinition.ID);
+    }
+
+    @Test
+    public void testGetActionDef() {
+        assertEquals(action.getActionDef(), AllowActionDefinition.DEFINITION);
+    }
+
+    @Test
+    public void testGetSupportedParameterValues() {
+        assertTrue(action.getSupportedParameterValues().isEmpty());
+    }
+
+    @Test
+    public void testValidate() {
+        ActionInstance actionInstance = new ActionInstanceBuilder().build();
+        ValidationResult result = action.validate(actionInstance);
+        assertTrue(result.isValid());
+    }
+
+}
index 74646facbea646d5b155e63fa5b0d82ba13b22b4..6d21f18ffbfb64aff2c0d1f181570df526fe00ab 100755 (executable)
@@ -1,51 +1,51 @@
-/*\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.iovisor.sf;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertTrue;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-\r
-public class ClassificationResultTest {\r
-\r
-    private static final String ERROR_MESSAGE = "error message";\r
-    private ClassificationResult resultOk;\r
-    private ClassificationResult resultError;\r
-\r
-    @Before\r
-    public void init() {\r
-        List<String> list = new ArrayList<>();\r
-        list.add("string");\r
-        resultOk = new ClassificationResult(list);\r
-        resultError = new ClassificationResult(ERROR_MESSAGE);\r
-    }\r
-\r
-    @Test\r
-    public void testConstructor_Result() {\r
-        assertTrue(resultOk.isSuccessfull());\r
-    }\r
-\r
-    @Test\r
-    public void testConstructor_ErrorMsg() {\r
-        assertFalse(resultError.isSuccessfull());\r
-    }\r
-\r
-    @Test\r
-    public void testGetErrorMessage() {\r
-        assertEquals(resultOk.getErrorMessage(), ClassificationResult.DEFAULT_ERROR_MESSAGE);\r
-        assertEquals(resultError.getErrorMessage(), ERROR_MESSAGE);\r
-    }\r
-\r
-}\r
+/*
+ * 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.iovisor.sf;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class ClassificationResultTest {
+
+    private static final String ERROR_MESSAGE = "error message";
+    private ClassificationResult resultOk;
+    private ClassificationResult resultError;
+
+    @Before
+    public void init() {
+        List<String> list = new ArrayList<>();
+        list.add("string");
+        resultOk = new ClassificationResult(list);
+        resultError = new ClassificationResult(ERROR_MESSAGE);
+    }
+
+    @Test
+    public void testConstructor_Result() {
+        assertTrue(resultOk.isSuccessfull());
+    }
+
+    @Test
+    public void testConstructor_ErrorMsg() {
+        assertFalse(resultError.isSuccessfull());
+    }
+
+    @Test
+    public void testGetErrorMessage() {
+        assertEquals(resultOk.getErrorMessage(), ClassificationResult.DEFAULT_ERROR_MESSAGE);
+        assertEquals(resultError.getErrorMessage(), ERROR_MESSAGE);
+    }
+
+}
index 3dd38c47b8e663689ea76afbdcd70a977efedb3b..b644ecc2a2f8898e01ecb6a673aa50fa4d550a5f 100755 (executable)
-/*\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
-package org.opendaylight.groupbasedpolicy.renderer.iovisor.sf;\r
-\r
-import static org.mockito.Mockito.mock;\r
-import static org.mockito.Mockito.spy;\r
-import static org.mockito.Mockito.verify;\r
-import static org.mockito.Mockito.when;\r
-\r
-import java.util.Set;\r
-\r
-import com.google.common.collect.ImmutableSet;\r
-import com.google.common.util.concurrent.CheckedFuture;\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.DataObjectModification;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;\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.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.SubjectFeatureDefinitions;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinition;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinitionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinitionKey;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
-\r
-public class ClassifierDefinitionListenerTest {\r
-\r
-    private ClassifierDefinitionListener listener;\r
-    private DataObjectModification<ClassifierDefinition> rootNode;\r
-    private Set<DataTreeModification<ClassifierDefinition>> changes;\r
-\r
-    private InstanceIdentifier<ClassifierDefinition> rootIdentifier;\r
-    private DataBroker dataProvider;\r
-\r
-    @SuppressWarnings("unchecked")\r
-    @Before\r
-    public void init() {\r
-        dataProvider = mock(DataBroker.class);\r
-\r
-        listener = spy(new ClassifierDefinitionListener(dataProvider));\r
-\r
-        ClassifierDefinitionKey key = mock(ClassifierDefinitionKey.class);\r
-        rootNode = mock(DataObjectModification.class);\r
-        rootIdentifier = InstanceIdentifier.builder(SubjectFeatureDefinitions.class)\r
-            .child(ClassifierDefinition.class, key)\r
-            .build();\r
-        DataTreeIdentifier<ClassifierDefinition> rootPath =\r
-                new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, rootIdentifier);\r
-\r
-        DataTreeModification<ClassifierDefinition> change = mock(DataTreeModification.class);\r
-\r
-        when(change.getRootNode()).thenReturn(rootNode);\r
-        when(change.getRootPath()).thenReturn(rootPath);\r
-\r
-        changes = ImmutableSet.of(change);\r
-\r
-        ClassifierDefinition def = new ClassifierDefinitionBuilder().setId(EtherTypeClassifierDefinition.ID).build();\r
-\r
-        when(rootNode.getDataBefore()).thenReturn(def);\r
-        when(rootNode.getDataAfter()).thenReturn(def);\r
-    }\r
-\r
-    @Test\r
-    public void testOnWrite() {\r
-        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);\r
-        WriteTransaction wt = resetTransaction();\r
-\r
-        listener.onDataTreeChanged(changes);\r
-\r
-        verify(listener).onSubtreeModified(rootNode, rootIdentifier);\r
-    }\r
-\r
-    @Test\r
-    public void testOnDelete() {\r
-        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);\r
-        WriteTransaction wt = resetTransaction();\r
-\r
-        listener.onDataTreeChanged(changes);\r
-\r
-        verify(listener).onDelete(rootNode, rootIdentifier);\r
-    }\r
-\r
-    @Test\r
-    public void testOnSubtreeModified() {\r
-        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);\r
-        WriteTransaction wt = resetTransaction();\r
-\r
-        listener.onDataTreeChanged(changes);\r
-\r
-        verify(listener).onSubtreeModified(rootNode, rootIdentifier);\r
-    }\r
-\r
-    private WriteTransaction resetTransaction() {\r
-        WriteTransaction wt = mock(WriteTransaction.class);\r
-        CheckedFuture checkedFuture = mock(CheckedFuture.class);\r
-        when(wt.submit()).thenReturn(checkedFuture);\r
-        when(dataProvider.newWriteOnlyTransaction()).thenReturn(wt);\r
-        return wt;\r
-    }\r
-\r
-}\r
+/*
+ * 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.iovisor.sf;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.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.api.sf.EtherTypeClassifierDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.SubjectFeatureDefinitions;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinitionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinitionKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class ClassifierDefinitionListenerTest {
+
+    private ClassifierDefinitionListener listener;
+    private DataObjectModification<ClassifierDefinition> rootNode;
+    private Set<DataTreeModification<ClassifierDefinition>> changes;
+
+    private InstanceIdentifier<ClassifierDefinition> rootIdentifier;
+    private DataBroker dataProvider;
+
+    @SuppressWarnings("unchecked")
+    @Before
+    public void init() {
+        dataProvider = mock(DataBroker.class);
+
+        listener = spy(new ClassifierDefinitionListener(dataProvider));
+
+        ClassifierDefinitionKey key = mock(ClassifierDefinitionKey.class);
+        rootNode = mock(DataObjectModification.class);
+        rootIdentifier = InstanceIdentifier.builder(SubjectFeatureDefinitions.class)
+            .child(ClassifierDefinition.class, key)
+            .build();
+        DataTreeIdentifier<ClassifierDefinition> rootPath =
+                new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, rootIdentifier);
+
+        DataTreeModification<ClassifierDefinition> change = mock(DataTreeModification.class);
+
+        when(change.getRootNode()).thenReturn(rootNode);
+        when(change.getRootPath()).thenReturn(rootPath);
+
+        changes = ImmutableSet.of(change);
+
+        ClassifierDefinition def = new ClassifierDefinitionBuilder().setId(EtherTypeClassifierDefinition.ID).build();
+
+        when(rootNode.getDataBefore()).thenReturn(def);
+        when(rootNode.getDataAfter()).thenReturn(def);
+    }
+
+    @Test
+    public void testOnWrite() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(listener).onSubtreeModified(rootNode, rootIdentifier);
+    }
+
+    @Test
+    public void testOnDelete() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(listener).onDelete(rootNode, rootIdentifier);
+    }
+
+    @Test
+    public void testOnSubtreeModified() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(listener).onSubtreeModified(rootNode, rootIdentifier);
+    }
+
+    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;
+    }
+
+}
index 8720c2fbe3027e99df7d35533fb6b77a782d8b97..bafa3caa932c97c58001201698fee9ad42e66e0b 100755 (executable)
@@ -1,87 +1,87 @@
-/*\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.iovisor.sf;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.assertNull;\r
-import static org.junit.Assert.assertTrue;\r
-import static org.junit.Assert.fail;\r
-\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.junit.Test;\r
-import org.opendaylight.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.parameters.type.ParameterType;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.parameters.type.parameter.type.Int;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.supported.classifier.definition.SupportedParameterValues;\r
-\r
-public class EtherTypeClassifierTest {\r
-\r
-    @Test\r
-    public void testGetId() {\r
-        assertEquals(EtherTypeClassifierDefinition.ID, Classifier.ETHER_TYPE_CL.getId());\r
-    }\r
-\r
-    @Test\r
-    public void testGetClassifierDefinition() {\r
-        assertEquals(EtherTypeClassifierDefinition.DEFINITION, Classifier.ETHER_TYPE_CL.getClassifierDefinition());\r
-    }\r
-\r
-    @Test\r
-    public void testGetSupportedParameterValues() {\r
-        List<SupportedParameterValues> valuesList = Classifier.ETHER_TYPE_CL.getSupportedParameterValues();\r
-        assertEquals(1, valuesList.size());\r
-\r
-        SupportedParameterValues values = valuesList.get(0);\r
-        assertNotNull(values);\r
-        assertEquals(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, values.getParameterName().getValue());\r
-        ParameterType pt = values.getParameterType();\r
-        assertTrue(pt instanceof Int);\r
-    }\r
-\r
-    @Test\r
-    public void testCheckPresenceOfRequiredParams() {\r
-        Map<String, ParameterValue> params = new HashMap<>();\r
-        ParameterValue pv = new ParameterValueBuilder().setIntValue(EtherTypeClassifierDefinition.ARP_VALUE).build();\r
-        params.put(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, pv);\r
-\r
-        try {\r
-            Classifier.ETHER_TYPE_CL.checkPresenceOfRequiredParams(params);\r
-        } catch (IllegalArgumentException e) {\r
-            fail("Required parameter missing");\r
-        }\r
-    }\r
-\r
-    @Test(expected = IllegalArgumentException.class)\r
-    public void testCheckPresenceOfRequiredParams_noParam() {\r
-        Map<String, ParameterValue> params = new HashMap<>();\r
-\r
-        Classifier.ETHER_TYPE_CL.checkPresenceOfRequiredParams(params);\r
-    }\r
-\r
-    @Test(expected = IllegalArgumentException.class)\r
-    public void testCheckPresenceOfRequiredParams_nullValue() {\r
-        Map<String, ParameterValue> params = new HashMap<>();\r
-        ParameterValue pv = new ParameterValueBuilder().build();\r
-        params.put(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, pv);\r
-\r
-        Classifier.ETHER_TYPE_CL.checkPresenceOfRequiredParams(params);\r
-    }\r
-\r
-    @Test\r
-    public void testGetParent() {\r
-        assertNull(Classifier.ETHER_TYPE_CL.getParent());\r
-    }\r
-\r
-}\r
+/*
+ * 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.iovisor.sf;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import org.opendaylight.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.parameters.type.ParameterType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.parameters.type.parameter.type.Int;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.supported.classifier.definition.SupportedParameterValues;
+
+public class EtherTypeClassifierTest {
+
+    @Test
+    public void testGetId() {
+        assertEquals(EtherTypeClassifierDefinition.ID, Classifier.ETHER_TYPE_CL.getId());
+    }
+
+    @Test
+    public void testGetClassifierDefinition() {
+        assertEquals(EtherTypeClassifierDefinition.DEFINITION, Classifier.ETHER_TYPE_CL.getClassifierDefinition());
+    }
+
+    @Test
+    public void testGetSupportedParameterValues() {
+        List<SupportedParameterValues> valuesList = Classifier.ETHER_TYPE_CL.getSupportedParameterValues();
+        assertEquals(1, valuesList.size());
+
+        SupportedParameterValues values = valuesList.get(0);
+        assertNotNull(values);
+        assertEquals(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, values.getParameterName().getValue());
+        ParameterType pt = values.getParameterType();
+        assertTrue(pt instanceof Int);
+    }
+
+    @Test
+    public void testCheckPresenceOfRequiredParams() {
+        Map<String, ParameterValue> params = new HashMap<>();
+        ParameterValue pv = new ParameterValueBuilder().setIntValue(EtherTypeClassifierDefinition.ARP_VALUE).build();
+        params.put(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, pv);
+
+        try {
+            Classifier.ETHER_TYPE_CL.checkPresenceOfRequiredParams(params);
+        } catch (IllegalArgumentException e) {
+            fail("Required parameter missing");
+        }
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testCheckPresenceOfRequiredParams_noParam() {
+        Map<String, ParameterValue> params = new HashMap<>();
+
+        Classifier.ETHER_TYPE_CL.checkPresenceOfRequiredParams(params);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testCheckPresenceOfRequiredParams_nullValue() {
+        Map<String, ParameterValue> params = new HashMap<>();
+        ParameterValue pv = new ParameterValueBuilder().build();
+        params.put(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, pv);
+
+        Classifier.ETHER_TYPE_CL.checkPresenceOfRequiredParams(params);
+    }
+
+    @Test
+    public void testGetParent() {
+        assertNull(Classifier.ETHER_TYPE_CL.getParent());
+    }
+
+}
index 57734e1fb85ad97d04c277c69ae67f5c3a7df59b..10befcf5ca27e32a79c56da6b97ec389e9b370be 100755 (executable)
-/*\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.iovisor.sf;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.assertNull;\r
-import static org.junit.Assert.assertTrue;\r
-import static org.junit.Assert.fail;\r
-\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.junit.Test;\r
-import org.opendaylight.groupbasedpolicy.api.sf.IpProtoClassifierDefinition;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.parameters.type.ParameterType;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.parameters.type.parameter.type.Int;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.supported.classifier.definition.SupportedParameterValues;\r
-\r
-public class IpProtoClassifierTest {\r
-\r
-    @Test\r
-    public void testGetId() {\r
-        assertEquals(IpProtoClassifierDefinition.ID, Classifier.IP_PROTO_CL.getId());\r
-    }\r
-\r
-    @Test\r
-    public void testGetClassifierDefinition() {\r
-        assertEquals(IpProtoClassifierDefinition.DEFINITION, Classifier.IP_PROTO_CL.getClassifierDefinition());\r
-    }\r
-\r
-    @Test\r
-    public void testGetSupportedParameterValues() {\r
-        List<SupportedParameterValues> valuesList = Classifier.IP_PROTO_CL.getSupportedParameterValues();\r
-        assertEquals(1, valuesList.size());\r
-\r
-        SupportedParameterValues values = valuesList.get(0);\r
-        assertNotNull(values);\r
-        assertEquals(IpProtoClassifierDefinition.PROTO_PARAM, values.getParameterName().getValue());\r
-        ParameterType pt = values.getParameterType();\r
-        assertTrue(pt instanceof Int);\r
-    }\r
-\r
-    @Test\r
-    public void testCheckPresenceOfRequiredParams() {\r
-        Map<String, ParameterValue> params = prepareParams(IpProtoClassifierDefinition.UDP_VALUE);\r
-\r
-        try {\r
-            Classifier.IP_PROTO_CL.checkPresenceOfRequiredParams(params);\r
-        } catch (IllegalArgumentException e) {\r
-            fail("Required parameter missing");\r
-        }\r
-    }\r
-\r
-    @Test(expected = IllegalArgumentException.class)\r
-    public void testCheckPresenceOfRequiredParams_noParam() {\r
-        Map<String, ParameterValue> params = new HashMap<>();\r
-\r
-        Classifier.IP_PROTO_CL.checkPresenceOfRequiredParams(params);\r
-    }\r
-\r
-    @Test(expected = IllegalArgumentException.class)\r
-    public void testCheckPresenceOfRequiredParams_nullValue() {\r
-        Map<String, ParameterValue> params = prepareParams_nullValue();\r
-\r
-        Classifier.IP_PROTO_CL.checkPresenceOfRequiredParams(params);\r
-    }\r
-\r
-    @Test\r
-    public void testGetIpProtoValue() {\r
-        Long expected = IpProtoClassifierDefinition.UDP_VALUE;\r
-\r
-        assertEquals(expected, IpProtoClassifier.getIpProtoValue(prepareParams(expected)));\r
-    }\r
-\r
-    @Test\r
-    public void testGetIpProtoValue_badParams() {\r
-        Map<String, ParameterValue> params = prepareParams_nullValue();\r
-\r
-        assertNull(IpProtoClassifier.getIpProtoValue(params));\r
-        assertNull(IpProtoClassifier.getIpProtoValue(new HashMap<String, ParameterValue>()));\r
-        assertNull(IpProtoClassifier.getIpProtoValue(null));\r
-    }\r
-\r
-    @Test\r
-    public void testGetParent() {\r
-        assertEquals(Classifier.IP_PROTO_CL.getParent(), Classifier.ETHER_TYPE_CL);\r
-    }\r
-\r
-    private Map<String, ParameterValue> prepareParams(Long intValue) {\r
-        Map<String, ParameterValue> params = new HashMap<>();\r
-        ParameterValue pv = new ParameterValueBuilder().setIntValue(intValue).build();\r
-        params.put(IpProtoClassifierDefinition.PROTO_PARAM, pv);\r
-        return params;\r
-    }\r
-\r
-    private Map<String, ParameterValue> prepareParams_nullValue() {\r
-        Map<String, ParameterValue> params = new HashMap<>();\r
-        ParameterValue pv = new ParameterValueBuilder().build();\r
-        params.put(IpProtoClassifierDefinition.PROTO_PARAM, pv);\r
-        return params;\r
-    }\r
-\r
-}\r
+/*
+ * 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.iovisor.sf;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import org.opendaylight.groupbasedpolicy.api.sf.IpProtoClassifierDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.parameters.type.ParameterType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.parameters.type.parameter.type.Int;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.supported.classifier.definition.SupportedParameterValues;
+
+public class IpProtoClassifierTest {
+
+    @Test
+    public void testGetId() {
+        assertEquals(IpProtoClassifierDefinition.ID, Classifier.IP_PROTO_CL.getId());
+    }
+
+    @Test
+    public void testGetClassifierDefinition() {
+        assertEquals(IpProtoClassifierDefinition.DEFINITION, Classifier.IP_PROTO_CL.getClassifierDefinition());
+    }
+
+    @Test
+    public void testGetSupportedParameterValues() {
+        List<SupportedParameterValues> valuesList = Classifier.IP_PROTO_CL.getSupportedParameterValues();
+        assertEquals(1, valuesList.size());
+
+        SupportedParameterValues values = valuesList.get(0);
+        assertNotNull(values);
+        assertEquals(IpProtoClassifierDefinition.PROTO_PARAM, values.getParameterName().getValue());
+        ParameterType pt = values.getParameterType();
+        assertTrue(pt instanceof Int);
+    }
+
+    @Test
+    public void testCheckPresenceOfRequiredParams() {
+        Map<String, ParameterValue> params = prepareParams(IpProtoClassifierDefinition.UDP_VALUE);
+
+        try {
+            Classifier.IP_PROTO_CL.checkPresenceOfRequiredParams(params);
+        } catch (IllegalArgumentException e) {
+            fail("Required parameter missing");
+        }
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testCheckPresenceOfRequiredParams_noParam() {
+        Map<String, ParameterValue> params = new HashMap<>();
+
+        Classifier.IP_PROTO_CL.checkPresenceOfRequiredParams(params);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testCheckPresenceOfRequiredParams_nullValue() {
+        Map<String, ParameterValue> params = prepareParams_nullValue();
+
+        Classifier.IP_PROTO_CL.checkPresenceOfRequiredParams(params);
+    }
+
+    @Test
+    public void testGetIpProtoValue() {
+        Long expected = IpProtoClassifierDefinition.UDP_VALUE;
+
+        assertEquals(expected, IpProtoClassifier.getIpProtoValue(prepareParams(expected)));
+    }
+
+    @Test
+    public void testGetIpProtoValue_badParams() {
+        Map<String, ParameterValue> params = prepareParams_nullValue();
+
+        assertNull(IpProtoClassifier.getIpProtoValue(params));
+        assertNull(IpProtoClassifier.getIpProtoValue(new HashMap<String, ParameterValue>()));
+        assertNull(IpProtoClassifier.getIpProtoValue(null));
+    }
+
+    @Test
+    public void testGetParent() {
+        assertEquals(Classifier.IP_PROTO_CL.getParent(), Classifier.ETHER_TYPE_CL);
+    }
+
+    private Map<String, ParameterValue> prepareParams(Long intValue) {
+        Map<String, ParameterValue> params = new HashMap<>();
+        ParameterValue pv = new ParameterValueBuilder().setIntValue(intValue).build();
+        params.put(IpProtoClassifierDefinition.PROTO_PARAM, pv);
+        return params;
+    }
+
+    private Map<String, ParameterValue> prepareParams_nullValue() {
+        Map<String, ParameterValue> params = new HashMap<>();
+        ParameterValue pv = new ParameterValueBuilder().build();
+        params.put(IpProtoClassifierDefinition.PROTO_PARAM, pv);
+        return params;
+    }
+
+}
index 14ddba6291ddad5f2d1f4de7c3433cae3ea2bfa2..d72cf4c685162b5f34c7bef90c94718f9511568a 100755 (executable)
-/*\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.iovisor.sf;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.assertTrue;\r
-\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.junit.Before;\r
-import org.junit.Rule;\r
-import org.junit.Test;\r
-import org.junit.rules.ExpectedException;\r
-import org.opendaylight.groupbasedpolicy.api.sf.L4ClassifierDefinition;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ParameterName;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.parameter.value.RangeValueBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.parameters.type.ParameterType;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.parameters.type.parameter.type.Int;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.supported.classifier.definition.SupportedParameterValues;\r
-\r
-public class L4ClassifierTest {\r
-\r
-    private ParameterValue pvSrcPort80;\r
-    private ParameterValue pvDstPort80;\r
-    private ParameterValue pvDstPort_null;\r
-    private ParameterValue pvSrcRange81_82;\r
-    private ParameterValue pvDstRange81_82;\r
-    private ParameterValue pvDstRange82_81;\r
-    private ParameterValue pvDstRange_null;\r
-\r
-    @Rule\r
-    public ExpectedException thrown = ExpectedException.none();\r
-\r
-    @Before\r
-    public void init() {\r
-        pvSrcPort80 = new ParameterValueBuilder().setName(\r
-                new ParameterName(L4ClassifierDefinition.SRC_PORT_PARAM)).setIntValue(80L).build();\r
-        pvDstPort80 = new ParameterValueBuilder().setName(\r
-                new ParameterName(L4ClassifierDefinition.DST_PORT_PARAM)).setIntValue(80L).build();\r
-        pvDstPort_null = new ParameterValueBuilder().setName(\r
-                new ParameterName(L4ClassifierDefinition.DST_PORT_PARAM)).build();\r
-        pvSrcRange81_82 = new ParameterValueBuilder().setName(\r
-                new ParameterName(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM))\r
-                .setRangeValue(new RangeValueBuilder().setMin(81L).setMax(82L).build())\r
-                .build();\r
-        pvDstRange81_82 = new ParameterValueBuilder().setName(\r
-                new ParameterName(L4ClassifierDefinition.DST_PORT_RANGE_PARAM))\r
-                .setRangeValue(new RangeValueBuilder().setMin(81L).setMax(82L).build())\r
-                .build();\r
-        pvDstRange82_81 = new ParameterValueBuilder().setName(\r
-                new ParameterName(L4ClassifierDefinition.DST_PORT_RANGE_PARAM))\r
-                .setRangeValue(new RangeValueBuilder().setMin(82L).setMax(81L).build())\r
-                .build();\r
-        pvDstRange_null = new ParameterValueBuilder().setName(\r
-                new ParameterName(L4ClassifierDefinition.DST_PORT_RANGE_PARAM))\r
-                //.setRangeValue(new RangeValueBuilder().setMin(82L).setMax(81L).build())\r
-                .build();\r
-    }\r
-\r
-    @Test\r
-    public void testGetId() {\r
-        assertEquals(L4ClassifierDefinition.ID, Classifier.L4_CL.getId());\r
-    }\r
-\r
-    @Test\r
-    public void testGetClassifierDefinition() {\r
-        assertEquals(L4ClassifierDefinition.DEFINITION, Classifier.L4_CL.getClassifierDefinition());\r
-    }\r
-\r
-    @Test\r
-    public void testGetSupportedParameterValues() {\r
-        List<SupportedParameterValues> valuesList = Classifier.L4_CL.getSupportedParameterValues();\r
-        assertEquals(4, valuesList.size());\r
-\r
-        SupportedParameterValues values = valuesList.get(0);\r
-        assertNotNull(values);\r
-        assertEquals(L4ClassifierDefinition.SRC_PORT_PARAM, values.getParameterName().getValue());\r
-        ParameterType pt = values.getParameterType();\r
-        assertTrue(pt instanceof Int);\r
-    }\r
-\r
-    @Test\r
-    public void testCheckPresenceOfRequiredParams_Empty() throws Exception {\r
-        // TODO check: sending empty map is ok?\r
-        Classifier.L4_CL.checkPresenceOfRequiredParams(new HashMap<String, ParameterValue>());\r
-    }\r
-\r
-    @Test\r
-    public void testCheckPresenceOfRequiredParams_SinglePorts() throws Exception {\r
-        Map<String, ParameterValue> params = new HashMap<>();\r
-        params.put(L4ClassifierDefinition.SRC_PORT_PARAM, pvSrcPort80);\r
-        params.put(L4ClassifierDefinition.DST_PORT_PARAM, pvDstPort80);\r
-\r
-        Classifier.L4_CL.checkPresenceOfRequiredParams(params);\r
-    }\r
-\r
-    @Test\r
-    public void testCheckPresenceOfRequiredParams_PortRanges() throws Exception {\r
-        Map<String, ParameterValue> params = new HashMap<>();\r
-        params.put(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM, pvSrcRange81_82);\r
-        params.put(L4ClassifierDefinition.DST_PORT_RANGE_PARAM, pvDstRange81_82);\r
-\r
-        Classifier.L4_CL.checkPresenceOfRequiredParams(params);\r
-    }\r
-\r
-    @Test\r
-    public void testCheckPresenceOfRequiredParams_DstPortNull() throws IllegalArgumentException {\r
-        Map<String, ParameterValue> params = new HashMap<>();\r
-        params.put(L4ClassifierDefinition.SRC_PORT_PARAM, pvSrcPort80);\r
-        params.put(L4ClassifierDefinition.DST_PORT_PARAM, pvDstPort_null);\r
-\r
-        thrown.expect(IllegalArgumentException.class);\r
-        thrown.expectMessage(L4Classifier.EXC_MSG_PARAM_VALUE_NOT_SPECIFIED);\r
-        Classifier.L4_CL.checkPresenceOfRequiredParams(params);\r
-    }\r
-\r
-    @Test\r
-    public void testCheckPresenceOfRequiredParams_DstRangeNull() throws IllegalArgumentException {\r
-        Map<String, ParameterValue> params = new HashMap<>();\r
-        params.put(L4ClassifierDefinition.SRC_PORT_PARAM, pvSrcPort80);\r
-        params.put(L4ClassifierDefinition.DST_PORT_RANGE_PARAM, pvDstRange_null);\r
-\r
-        thrown.expect(IllegalArgumentException.class);\r
-        thrown.expectMessage(L4Classifier.EXC_MSG_PARAM_VALUE_NOT_SPECIFIED);\r
-        Classifier.L4_CL.checkPresenceOfRequiredParams(params);\r
-    }\r
-\r
-    @Test\r
-    public void testCheckPresenceOfRequiredParams_ParamConflict() throws IllegalArgumentException {\r
-        Map<String, ParameterValue> params = new HashMap<>();\r
-        params.put(L4ClassifierDefinition.SRC_PORT_PARAM, pvSrcPort80);\r
-        params.put(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM, pvSrcRange81_82);\r
-\r
-        thrown.expect(IllegalArgumentException.class);\r
-        thrown.expectMessage(L4Classifier.EXC_MSG_MUT_EXCLUSIVE_PARAMS);\r
-        Classifier.L4_CL.checkPresenceOfRequiredParams(params);\r
-    }\r
-\r
-    @Test\r
-    public void testCheckPresenceOfRequiredParams_RangeInverted() throws IllegalArgumentException {\r
-        Map<String, ParameterValue> params = new HashMap<>();\r
-        params.put(L4ClassifierDefinition.SRC_PORT_PARAM, pvSrcPort80);\r
-        params.put(L4ClassifierDefinition.DST_PORT_RANGE_PARAM, pvDstRange82_81);\r
-\r
-        thrown.expect(IllegalArgumentException.class);\r
-        thrown.expectMessage(L4Classifier.EXC_MSG_RANGE_VALUE_MISMATCH);\r
-        Classifier.L4_CL.checkPresenceOfRequiredParams(params);\r
-    }\r
-\r
-    @Test\r
-    public void testCheckPresenceOfRequiredParams_emptyParams() {\r
-\r
-        Classifier.L4_CL.checkPresenceOfRequiredParams(new HashMap<String, ParameterValue>());\r
-    }\r
-\r
-    @Test\r
-    public void testGetParent() {\r
-        assertEquals(Classifier.L4_CL.getParent(), Classifier.IP_PROTO_CL);\r
-    }\r
-\r
-}\r
+/*
+ * 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.iovisor.sf;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.opendaylight.groupbasedpolicy.api.sf.L4ClassifierDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ParameterName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.parameter.value.RangeValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.parameters.type.ParameterType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.parameters.type.parameter.type.Int;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.supported.classifier.definition.SupportedParameterValues;
+
+public class L4ClassifierTest {
+
+    private ParameterValue pvSrcPort80;
+    private ParameterValue pvDstPort80;
+    private ParameterValue pvDstPort_null;
+    private ParameterValue pvSrcRange81_82;
+    private ParameterValue pvDstRange81_82;
+    private ParameterValue pvDstRange82_81;
+    private ParameterValue pvDstRange_null;
+
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
+
+    @Before
+    public void init() {
+        pvSrcPort80 = new ParameterValueBuilder().setName(
+                new ParameterName(L4ClassifierDefinition.SRC_PORT_PARAM)).setIntValue(80L).build();
+        pvDstPort80 = new ParameterValueBuilder().setName(
+                new ParameterName(L4ClassifierDefinition.DST_PORT_PARAM)).setIntValue(80L).build();
+        pvDstPort_null = new ParameterValueBuilder().setName(
+                new ParameterName(L4ClassifierDefinition.DST_PORT_PARAM)).build();
+        pvSrcRange81_82 = new ParameterValueBuilder().setName(
+                new ParameterName(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM))
+                .setRangeValue(new RangeValueBuilder().setMin(81L).setMax(82L).build())
+                .build();
+        pvDstRange81_82 = new ParameterValueBuilder().setName(
+                new ParameterName(L4ClassifierDefinition.DST_PORT_RANGE_PARAM))
+                .setRangeValue(new RangeValueBuilder().setMin(81L).setMax(82L).build())
+                .build();
+        pvDstRange82_81 = new ParameterValueBuilder().setName(
+                new ParameterName(L4ClassifierDefinition.DST_PORT_RANGE_PARAM))
+                .setRangeValue(new RangeValueBuilder().setMin(82L).setMax(81L).build())
+                .build();
+        pvDstRange_null = new ParameterValueBuilder().setName(
+                new ParameterName(L4ClassifierDefinition.DST_PORT_RANGE_PARAM))
+                //.setRangeValue(new RangeValueBuilder().setMin(82L).setMax(81L).build())
+                .build();
+    }
+
+    @Test
+    public void testGetId() {
+        assertEquals(L4ClassifierDefinition.ID, Classifier.L4_CL.getId());
+    }
+
+    @Test
+    public void testGetClassifierDefinition() {
+        assertEquals(L4ClassifierDefinition.DEFINITION, Classifier.L4_CL.getClassifierDefinition());
+    }
+
+    @Test
+    public void testGetSupportedParameterValues() {
+        List<SupportedParameterValues> valuesList = Classifier.L4_CL.getSupportedParameterValues();
+        assertEquals(4, valuesList.size());
+
+        SupportedParameterValues values = valuesList.get(0);
+        assertNotNull(values);
+        assertEquals(L4ClassifierDefinition.SRC_PORT_PARAM, values.getParameterName().getValue());
+        ParameterType pt = values.getParameterType();
+        assertTrue(pt instanceof Int);
+    }
+
+    @Test
+    public void testCheckPresenceOfRequiredParams_Empty() throws Exception {
+        // TODO check: sending empty map is ok?
+        Classifier.L4_CL.checkPresenceOfRequiredParams(new HashMap<String, ParameterValue>());
+    }
+
+    @Test
+    public void testCheckPresenceOfRequiredParams_SinglePorts() throws Exception {
+        Map<String, ParameterValue> params = new HashMap<>();
+        params.put(L4ClassifierDefinition.SRC_PORT_PARAM, pvSrcPort80);
+        params.put(L4ClassifierDefinition.DST_PORT_PARAM, pvDstPort80);
+
+        Classifier.L4_CL.checkPresenceOfRequiredParams(params);
+    }
+
+    @Test
+    public void testCheckPresenceOfRequiredParams_PortRanges() throws Exception {
+        Map<String, ParameterValue> params = new HashMap<>();
+        params.put(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM, pvSrcRange81_82);
+        params.put(L4ClassifierDefinition.DST_PORT_RANGE_PARAM, pvDstRange81_82);
+
+        Classifier.L4_CL.checkPresenceOfRequiredParams(params);
+    }
+
+    @Test
+    public void testCheckPresenceOfRequiredParams_DstPortNull() throws IllegalArgumentException {
+        Map<String, ParameterValue> params = new HashMap<>();
+        params.put(L4ClassifierDefinition.SRC_PORT_PARAM, pvSrcPort80);
+        params.put(L4ClassifierDefinition.DST_PORT_PARAM, pvDstPort_null);
+
+        thrown.expect(IllegalArgumentException.class);
+        thrown.expectMessage(L4Classifier.EXC_MSG_PARAM_VALUE_NOT_SPECIFIED);
+        Classifier.L4_CL.checkPresenceOfRequiredParams(params);
+    }
+
+    @Test
+    public void testCheckPresenceOfRequiredParams_DstRangeNull() throws IllegalArgumentException {
+        Map<String, ParameterValue> params = new HashMap<>();
+        params.put(L4ClassifierDefinition.SRC_PORT_PARAM, pvSrcPort80);
+        params.put(L4ClassifierDefinition.DST_PORT_RANGE_PARAM, pvDstRange_null);
+
+        thrown.expect(IllegalArgumentException.class);
+        thrown.expectMessage(L4Classifier.EXC_MSG_PARAM_VALUE_NOT_SPECIFIED);
+        Classifier.L4_CL.checkPresenceOfRequiredParams(params);
+    }
+
+    @Test
+    public void testCheckPresenceOfRequiredParams_ParamConflict() throws IllegalArgumentException {
+        Map<String, ParameterValue> params = new HashMap<>();
+        params.put(L4ClassifierDefinition.SRC_PORT_PARAM, pvSrcPort80);
+        params.put(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM, pvSrcRange81_82);
+
+        thrown.expect(IllegalArgumentException.class);
+        thrown.expectMessage(L4Classifier.EXC_MSG_MUT_EXCLUSIVE_PARAMS);
+        Classifier.L4_CL.checkPresenceOfRequiredParams(params);
+    }
+
+    @Test
+    public void testCheckPresenceOfRequiredParams_RangeInverted() throws IllegalArgumentException {
+        Map<String, ParameterValue> params = new HashMap<>();
+        params.put(L4ClassifierDefinition.SRC_PORT_PARAM, pvSrcPort80);
+        params.put(L4ClassifierDefinition.DST_PORT_RANGE_PARAM, pvDstRange82_81);
+
+        thrown.expect(IllegalArgumentException.class);
+        thrown.expectMessage(L4Classifier.EXC_MSG_RANGE_VALUE_MISMATCH);
+        Classifier.L4_CL.checkPresenceOfRequiredParams(params);
+    }
+
+    @Test
+    public void testCheckPresenceOfRequiredParams_emptyParams() {
+
+        Classifier.L4_CL.checkPresenceOfRequiredParams(new HashMap<String, ParameterValue>());
+    }
+
+    @Test
+    public void testGetParent() {
+        assertEquals(Classifier.L4_CL.getParent(), Classifier.IP_PROTO_CL);
+    }
+
+}
index 5884bb471b6e60202f03d5d77fd2b907da53c9c5..1ef61583ba5980674571fdab3301be5be790c2ad 100755 (executable)
@@ -1,56 +1,56 @@
-/*\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.iovisor.sf;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertTrue;\r
-\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.junit.Test;\r
-import org.opendaylight.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;\r
-\r
-public class ParamDerivatorTest {\r
-\r
-    private ParamDerivator derivator = ParamDerivator.ETHER_TYPE_DERIVATOR;\r
-\r
-    @Test\r
-    public void testDeriveParameter_noDerivation() {\r
-        Map<String, ParameterValue> params = new HashMap<>();\r
-        ParameterValue pv = new ParameterValueBuilder().setIntValue(EtherTypeClassifierDefinition.IPv4_VALUE).build();\r
-        params.put(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, pv);\r
-\r
-        List<Map<String, ParameterValue>> result = derivator.deriveParameter(params);\r
-\r
-        assertEquals(1, result.size());\r
-        assertEquals(params, result.get(0));\r
-    }\r
-\r
-    @Test\r
-    public void testDeriveParameter_withDerivation() {\r
-        Map<String, ParameterValue> params = new HashMap<>();\r
-        ParameterValue pv = new ParameterValueBuilder().setIntValue(EtherTypeClassifierDefinition.IPv4_VALUE).build();\r
-        params.put("dummy key", pv);\r
-\r
-        List<Map<String, ParameterValue>> derivedParams = derivator.deriveParameter(params);\r
-\r
-        assertEquals(2, derivedParams.size());\r
-\r
-        Map<String, ParameterValue> ipv4Params = derivedParams.get(0);\r
-        Map<String, ParameterValue> ipv6Params = derivedParams.get(1);\r
-\r
-        assertTrue(ipv4Params.containsKey(EtherTypeClassifierDefinition.ETHERTYPE_PARAM));\r
-        assertTrue(ipv6Params.containsKey(EtherTypeClassifierDefinition.ETHERTYPE_PARAM));\r
-    }\r
-\r
-}\r
+/*
+ * 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.iovisor.sf;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import org.opendaylight.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;
+
+public class ParamDerivatorTest {
+
+    private ParamDerivator derivator = ParamDerivator.ETHER_TYPE_DERIVATOR;
+
+    @Test
+    public void testDeriveParameter_noDerivation() {
+        Map<String, ParameterValue> params = new HashMap<>();
+        ParameterValue pv = new ParameterValueBuilder().setIntValue(EtherTypeClassifierDefinition.IPv4_VALUE).build();
+        params.put(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, pv);
+
+        List<Map<String, ParameterValue>> result = derivator.deriveParameter(params);
+
+        assertEquals(1, result.size());
+        assertEquals(params, result.get(0));
+    }
+
+    @Test
+    public void testDeriveParameter_withDerivation() {
+        Map<String, ParameterValue> params = new HashMap<>();
+        ParameterValue pv = new ParameterValueBuilder().setIntValue(EtherTypeClassifierDefinition.IPv4_VALUE).build();
+        params.put("dummy key", pv);
+
+        List<Map<String, ParameterValue>> derivedParams = derivator.deriveParameter(params);
+
+        assertEquals(2, derivedParams.size());
+
+        Map<String, ParameterValue> ipv4Params = derivedParams.get(0);
+        Map<String, ParameterValue> ipv6Params = derivedParams.get(1);
+
+        assertTrue(ipv4Params.containsKey(EtherTypeClassifierDefinition.ETHERTYPE_PARAM));
+        assertTrue(ipv6Params.containsKey(EtherTypeClassifierDefinition.ETHERTYPE_PARAM));
+    }
+
+}
index 743ca9e8af6fda7b88a513d51717c88727d2ee3f..a3d0bab71800c2c9d7367bc3a6b9de2d5b190cf3 100755 (executable)
@@ -1,41 +1,41 @@
-/*\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.iovisor.sf;\r
-\r
-import static junit.framework.Assert.assertEquals;\r
-import static org.junit.Assert.assertNotNull;\r
-\r
-import org.junit.Assert;\r
-import org.junit.Test;\r
-import org.opendaylight.groupbasedpolicy.api.sf.AllowActionDefinition;\r
-import org.opendaylight.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition;\r
-import org.opendaylight.groupbasedpolicy.api.sf.IpProtoClassifierDefinition;\r
-import org.opendaylight.groupbasedpolicy.api.sf.L4ClassifierDefinition;\r
-\r
-public class SubjectFeaturesTest {\r
-\r
-    @Test\r
-    public void testGetClassifier() {\r
-        assertEquals(Classifier.ETHER_TYPE_CL, SubjectFeatures.getClassifier(EtherTypeClassifierDefinition.ID));\r
-        assertEquals(Classifier.IP_PROTO_CL, SubjectFeatures.getClassifier(IpProtoClassifierDefinition.ID));\r
-        assertEquals(Classifier.L4_CL, SubjectFeatures.getClassifier(L4ClassifierDefinition.ID));\r
-    }\r
-\r
-    @Test\r
-    public void testGetActions() {\r
-        assertNotNull(SubjectFeatures.getActions());\r
-    }\r
-\r
-    @Test\r
-    public void testGetAction() {\r
-        Assert.assertEquals(AllowActionDefinition.DEFINITION,\r
-                SubjectFeatures.getAction(AllowActionDefinition.ID).getActionDef());\r
-    }\r
-\r
-}\r
+/*
+ * 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.iovisor.sf;
+
+import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.groupbasedpolicy.api.sf.AllowActionDefinition;
+import org.opendaylight.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition;
+import org.opendaylight.groupbasedpolicy.api.sf.IpProtoClassifierDefinition;
+import org.opendaylight.groupbasedpolicy.api.sf.L4ClassifierDefinition;
+
+public class SubjectFeaturesTest {
+
+    @Test
+    public void testGetClassifier() {
+        assertEquals(Classifier.ETHER_TYPE_CL, SubjectFeatures.getClassifier(EtherTypeClassifierDefinition.ID));
+        assertEquals(Classifier.IP_PROTO_CL, SubjectFeatures.getClassifier(IpProtoClassifierDefinition.ID));
+        assertEquals(Classifier.L4_CL, SubjectFeatures.getClassifier(L4ClassifierDefinition.ID));
+    }
+
+    @Test
+    public void testGetActions() {
+        assertNotNull(SubjectFeatures.getActions());
+    }
+
+    @Test
+    public void testGetAction() {
+        Assert.assertEquals(AllowActionDefinition.DEFINITION,
+                SubjectFeatures.getAction(AllowActionDefinition.ID).getActionDef());
+    }
+
+}
index 4cc50bb9f0b58f7a3a6e2c6bf7c623a2455bdd76..c85e29e194110b8f5a802574eccd1877bc1d3030 100644 (file)
@@ -1,99 +1,99 @@
-/*\r
- * Copyright (c) 2014 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
-package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.mapper.policyenforcer;\r
-\r
-import org.opendaylight.groupbasedpolicy.dto.EgKey;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.OrdinalFactory;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.OrdinalFactory.EndpointFwdCtxOrdinals;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContext;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-public class NetworkElements {\r
-\r
-    private static final Logger LOG = LoggerFactory.getLogger(NetworkElements.class);\r
-    private final Endpoint srcEp;\r
-    private final Endpoint dstEp;\r
-    private final EgKey srcEpg;\r
-    private final EgKey dstEpg;\r
-    private NodeId srcNodeId;\r
-    private NodeId dstNodeId;\r
-    private final NodeId localNodeId;\r
-    private EndpointFwdCtxOrdinals srcEpOrdinals;\r
-    private EndpointFwdCtxOrdinals dstEpOrdinals;\r
-\r
-    public NetworkElements(Endpoint srcEp, Endpoint dstEp, EgKey srcEpg, EgKey dstEpg, NodeId nodeId, OfContext ctx) throws Exception {\r
-        this.srcEp = srcEp;\r
-        this.dstEp = dstEp;\r
-        this.srcEpg = srcEpg;\r
-        this.dstEpg = dstEpg;\r
-        this.localNodeId = nodeId;\r
-        this.srcEpOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, srcEp);\r
-        if (this.srcEpOrdinals == null) {\r
-            LOG.debug("getEndpointFwdCtxOrdinals is null for EP {}", srcEp);\r
-            return;\r
-        }\r
-        this.dstEpOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, dstEp);\r
-        if (this.dstEpOrdinals == null) {\r
-            LOG.debug("getEndpointFwdCtxOrdinals is null for EP {}", dstEp);\r
-            return;\r
-        }\r
-        if (dstEp.getAugmentation(OfOverlayContext.class) != null) {\r
-            this.dstNodeId = dstEp.getAugmentation(OfOverlayContext.class).getNodeId();\r
-        }\r
-        if (srcEp.getAugmentation(OfOverlayContext.class) != null) {\r
-            this.srcNodeId = srcEp.getAugmentation(OfOverlayContext.class).getNodeId();\r
-        }\r
-    }\r
-\r
-\r
-    public Endpoint getSrcEp() {\r
-        return srcEp;\r
-    }\r
-\r
-\r
-    public Endpoint getDstEp() {\r
-        return dstEp;\r
-    }\r
-\r
-    public EgKey getSrcEpg() {\r
-        return srcEpg;\r
-    }\r
-\r
-    public EgKey getDstEpg() {\r
-        return dstEpg;\r
-    }\r
-\r
-    public NodeId getSrcNodeId() {\r
-        return srcNodeId;\r
-    }\r
-\r
-\r
-    public NodeId getDstNodeId() {\r
-        return dstNodeId;\r
-    }\r
-\r
-\r
-    public NodeId getLocalNodeId() {\r
-        return localNodeId;\r
-    }\r
-\r
-\r
-    public EndpointFwdCtxOrdinals getSrcEpOrdinals() {\r
-        return srcEpOrdinals;\r
-    }\r
-\r
-\r
-    public EndpointFwdCtxOrdinals getDstEpOrdinals() {\r
-        return dstEpOrdinals;\r
-    }\r
-\r
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.mapper.policyenforcer;
+
+import org.opendaylight.groupbasedpolicy.dto.EgKey;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.OrdinalFactory;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.OrdinalFactory.EndpointFwdCtxOrdinals;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NetworkElements {
+
+    private static final Logger LOG = LoggerFactory.getLogger(NetworkElements.class);
+    private final Endpoint srcEp;
+    private final Endpoint dstEp;
+    private final EgKey srcEpg;
+    private final EgKey dstEpg;
+    private NodeId srcNodeId;
+    private NodeId dstNodeId;
+    private final NodeId localNodeId;
+    private EndpointFwdCtxOrdinals srcEpOrdinals;
+    private EndpointFwdCtxOrdinals dstEpOrdinals;
+
+    public NetworkElements(Endpoint srcEp, Endpoint dstEp, EgKey srcEpg, EgKey dstEpg, NodeId nodeId, OfContext ctx) throws Exception {
+        this.srcEp = srcEp;
+        this.dstEp = dstEp;
+        this.srcEpg = srcEpg;
+        this.dstEpg = dstEpg;
+        this.localNodeId = nodeId;
+        this.srcEpOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, srcEp);
+        if (this.srcEpOrdinals == null) {
+            LOG.debug("getEndpointFwdCtxOrdinals is null for EP {}", srcEp);
+            return;
+        }
+        this.dstEpOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, dstEp);
+        if (this.dstEpOrdinals == null) {
+            LOG.debug("getEndpointFwdCtxOrdinals is null for EP {}", dstEp);
+            return;
+        }
+        if (dstEp.getAugmentation(OfOverlayContext.class) != null) {
+            this.dstNodeId = dstEp.getAugmentation(OfOverlayContext.class).getNodeId();
+        }
+        if (srcEp.getAugmentation(OfOverlayContext.class) != null) {
+            this.srcNodeId = srcEp.getAugmentation(OfOverlayContext.class).getNodeId();
+        }
+    }
+
+
+    public Endpoint getSrcEp() {
+        return srcEp;
+    }
+
+
+    public Endpoint getDstEp() {
+        return dstEp;
+    }
+
+    public EgKey getSrcEpg() {
+        return srcEpg;
+    }
+
+    public EgKey getDstEpg() {
+        return dstEpg;
+    }
+
+    public NodeId getSrcNodeId() {
+        return srcNodeId;
+    }
+
+
+    public NodeId getDstNodeId() {
+        return dstNodeId;
+    }
+
+
+    public NodeId getLocalNodeId() {
+        return localNodeId;
+    }
+
+
+    public EndpointFwdCtxOrdinals getSrcEpOrdinals() {
+        return srcEpOrdinals;
+    }
+
+
+    public EndpointFwdCtxOrdinals getDstEpOrdinals() {
+        return dstEpOrdinals;
+    }
+
 }
\ No newline at end of file
index ddd37000725745c7f73f3dcfc2203c683351682d..b9f108a0098004c5372f3ee1a48e95e959e244f6 100644 (file)
-/*\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
+/*
+ * 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.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.api.EpRendererAugmentationRegistry;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.test.TransactionMockUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.Name;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterL3PrefixEndpointInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterL3PrefixEndpointInputBuilder;
+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.EndpointL3;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContextInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContextInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class OfOverlayAugTest {
+
+    private static final String PORT_NAME = "portName";
+    private DataBroker dataProvider;
+    private EpRendererAugmentationRegistry epRendererAugmentationRegistry;
+    private OfOverlayAug ofOverlayAug;
+
+    @Before
+    public void init() {
+        dataProvider = mock(DataBroker.class);
+        epRendererAugmentationRegistry = mock(EpRendererAugmentationRegistry.class);
+        ofOverlayAug = new OfOverlayAug(dataProvider, epRendererAugmentationRegistry);
+    }
+
+    @Test
+    public void testConstructor() throws Exception {
+        OfOverlayAug other = new OfOverlayAug(dataProvider, epRendererAugmentationRegistry);
+        other.close();
+    }
+
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testBuildEndpointAugmentation() throws ExecutionException, InterruptedException {
+        Nodes nodes = buildNodes();
+
+        ReadOnlyTransaction roTx = mock(ReadOnlyTransaction.class);
+        TransactionMockUtils.setupRoTx(roTx, LogicalDatastoreType.OPERATIONAL,
+                InstanceIdentifier.builder(Nodes.class).build(), true, nodes);
+        when(dataProvider.newReadOnlyTransaction()).thenReturn(roTx);
+
+        OfOverlayContextInput contextInput =
+                new OfOverlayContextInputBuilder().setPortName(new Name(PORT_NAME)).build();
+
+        RegisterEndpointInput input =
+                new RegisterEndpointInputBuilder().addAugmentation(OfOverlayContextInput.class, contextInput).build();
+
+        Map.Entry<Class<? extends Augmentation<Endpoint>>, Augmentation<Endpoint>> entry =
+                ofOverlayAug.buildEndpointAugmentation(input);
+
+        assertNotNull(entry);
+        assertNotNull(entry.getValue());
+    }
+
+    @Test
+    public void testBuildEndpointAugmentation_null() {
+        RegisterEndpointInput input = new RegisterEndpointInputBuilder().build();
+
+        Map.Entry<Class<? extends Augmentation<Endpoint>>, Augmentation<Endpoint>> entry =
+                ofOverlayAug.buildEndpointAugmentation(input);
+
+        assertNull(entry);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testBuildEndpointL3Augmentation() throws ExecutionException, InterruptedException {
+        Nodes nodes = buildNodes();
+
+        ReadOnlyTransaction roTx = mock(ReadOnlyTransaction.class);
+        TransactionMockUtils.setupRoTx(roTx, LogicalDatastoreType.OPERATIONAL,
+                InstanceIdentifier.builder(Nodes.class).build(), true, nodes);
+        when(dataProvider.newReadOnlyTransaction()).thenReturn(roTx);
+
+        OfOverlayContextInput contextInput =
+                new OfOverlayContextInputBuilder().setPortName(new Name(PORT_NAME)).build();
+
+        RegisterEndpointInput input =
+                new RegisterEndpointInputBuilder().addAugmentation(OfOverlayContextInput.class, contextInput).build();
+
+        Map.Entry<Class<? extends Augmentation<EndpointL3>>, Augmentation<EndpointL3>> entry =
+                ofOverlayAug.buildEndpointL3Augmentation(input);
+
+        assertNotNull(entry);
+        assertNotNull(entry.getValue());
+    }
+
+    @Test
+    public void testBuildEndpointL3Augmentation_null() {
+        RegisterEndpointInput input = new RegisterEndpointInputBuilder().build();
+
+        Map.Entry<Class<? extends Augmentation<EndpointL3>>, Augmentation<EndpointL3>> entry =
+                ofOverlayAug.buildEndpointL3Augmentation(input);
+
+        assertNull(entry);
+    }
+
+    @Test
+    public void testBuildL3PrefixEndpointAugmentation() {
+        RegisterL3PrefixEndpointInput input = new RegisterL3PrefixEndpointInputBuilder().build();
+        Map.Entry<Class<? extends Augmentation<EndpointL3Prefix>>, Augmentation<EndpointL3Prefix>> entry =
+                ofOverlayAug.buildL3PrefixEndpointAugmentation(input);
+
+        // always returns null
+        assertNull(entry);
+    }
+
+    private Nodes buildNodes() {
+        FlowCapableNodeConnector fcnc = new FlowCapableNodeConnectorBuilder().setName(PORT_NAME).build();
+        NodeConnector nc = new NodeConnectorBuilder().addAugmentation(FlowCapableNodeConnector.class, fcnc).build();
+        List<NodeConnector> nodeConnectorList = new ArrayList<>();
+        nodeConnectorList.add(nc);
+        Node node = new NodeBuilder().setNodeConnector(nodeConnectorList).build();
+        List<Node> nodeList = new ArrayList<>();
+        nodeList.add(node);
+        return new NodesBuilder().setNode(nodeList).build();
+    }
+
+}
index b606add33acba6655d767e486c93ee2dc915dbc2..81db451c4f7b2561de9dd6b6f651b9b8700d4f4a 100644 (file)
@@ -1,80 +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.rev130715.IpAddress;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.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
+/*
+ * 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.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.mock;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.groupbasedpolicy.api.EpRendererAugmentationRegistry;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterL3PrefixEndpointInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterL3PrefixEndpointInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.l3endpoint.rev151217.NatAddressInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.l3endpoint.rev151217.NatAddressInputBuilder;
+
+public class OfOverlayL3NatAugTest {
+
+    private OfOverlayL3NatAug ofOverlayL3NatAug;
+    private EpRendererAugmentationRegistry epRendererAugmentationRegistry;
+
+    @Before
+    public void init() {
+        epRendererAugmentationRegistry = mock(EpRendererAugmentationRegistry.class);
+        ofOverlayL3NatAug = new OfOverlayL3NatAug(epRendererAugmentationRegistry);
+    }
+
+    @Test
+    public void testConstructor() throws Exception {
+        OfOverlayL3NatAug other = new OfOverlayL3NatAug(epRendererAugmentationRegistry);
+        other.close();
+    }
+
+    @Test
+    public void testBuildEndpointAugmentation() {
+        RegisterEndpointInput input = new RegisterEndpointInputBuilder().build();
+        // no op
+        assertNull(ofOverlayL3NatAug.buildEndpointAugmentation(input));
+    }
+
+    @Test
+    public void testBuildEndpointL3Augmentation() {
+        NatAddressInput natAddressInput = new NatAddressInputBuilder().setNatAddress(
+                new IpAddress(new Ipv4Address("10.0.0.2"))).build();
+        RegisterEndpointInput input =
+                new RegisterEndpointInputBuilder().addAugmentation(NatAddressInput.class,
+                        natAddressInput).build();
+        assertNotNull(ofOverlayL3NatAug.buildEndpointL3Augmentation(input));
+    }
+
+    @Test
+    public void testBuildEndpointL3Augmentation_noAug() {
+        RegisterEndpointInput input = new RegisterEndpointInputBuilder().build();
+        assertNull(ofOverlayL3NatAug.buildEndpointL3Augmentation(input));
+    }
+
+    @Test
+    public void testBuildL3PrefixEndpointAugmentation() {
+        RegisterL3PrefixEndpointInput input = new RegisterL3PrefixEndpointInputBuilder().build();
+        // no op
+
+        assertNull(ofOverlayL3NatAug.buildL3PrefixEndpointAugmentation(input));
+    }
+
+    @Test
+    public void testClose() {
+        //        fail("Not yet implemented");
+    }
+
+}
index e88eea004937aff270f0293140e50cf3d6a38df0..fccd023ae03b4b4f7df8fca0bc1898111ab4241f 100755 (executable)
-/*\r
- * Copyright (c) 2015 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.flow;\r
-\r
-import com.google.common.base.Preconditions;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.mockito.ArgumentCaptor;\r
-import org.mockito.Captor;\r
-import org.opendaylight.groupbasedpolicy.dto.EgKey;\r
-import org.opendaylight.groupbasedpolicy.dto.PolicyInfo;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.EndpointManager;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.mapper.MapperUtilsTest;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.mapper.policyenforcer.NetworkElements;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils.SfcNshHeader;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils.SfcNshHeader.SfcNshHeaderBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3Address;\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.EndpointBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.HasDirection;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.Tenant;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.TenantBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg0;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg1;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg5;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg7;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.TunnelTypeVxlanGpe;\r
-\r
-import java.math.BigInteger;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import static org.junit.Assert.assertArrayEquals;\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.assertTrue;\r
-import static org.mockito.Mockito.any;\r
-import static org.mockito.Mockito.mock;\r
-import static org.mockito.Mockito.times;\r
-import static org.mockito.Mockito.verify;\r
-import static org.mockito.Mockito.when;\r
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.RegMatch;\r
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.addNxNsiMatch;\r
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.addNxNspMatch;\r
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.addNxRegMatch;\r
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.addNxTunIdMatch;\r
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.applyActionIns;\r
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.base;\r
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.gotoTableIns;\r
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.instructions;\r
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadNshc1RegAction;\r
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadNshc2RegAction;\r
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadRegAction;\r
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadTunGpeNpAction;\r
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadTunIPv4Action;\r
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadTunIdAction;\r
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxOutputRegAction;\r
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxPopNshAction;\r
-\r
-public class ChainActionFlowsTest extends MapperUtilsTest {\r
-\r
-    @Captor\r
-    private final ArgumentCaptor<NodeId> nodeIdCaptor = ArgumentCaptor.forClass(NodeId.class);\r
-    private final ArgumentCaptor<Short> tableIdCaptor = ArgumentCaptor.forClass(Short.class);\r
-    private final ArgumentCaptor<Flow> flowCaptor = ArgumentCaptor.forClass(Flow.class);\r
-\r
-    @Before\r
-    public void init() {\r
-        ctx = mock(OfContext.class);\r
-        endpointManager = mock(EndpointManager.class);\r
-        switchManager = mock(SwitchManager.class);\r
-        policyManager = mock(PolicyManager.class);\r
-        policyInfo = mock(PolicyInfo.class);\r
-        ofWriter = mock(OfWriter.class);\r
-    }\r
-\r
-    @Test\r
-    public void createChainTunnelFlows_directionIn() throws Exception {\r
-        // Tenant\r
-        TenantBuilder tenantBuilder = buildTenant();\r
-        Tenant tenant = tenantBuilder.build();\r
-        // Source Endpoint\r
-        EndpointBuilder sourceEndpointBuilder = buildEndpoint(IPV4_0, MAC_0, CONNECTOR_0);\r
-        Endpoint sourceEndpoint = sourceEndpointBuilder.build();\r
-        EgKey sourceEgKey = new EgKey(tenant.getId(), ENDPOINT_GROUP_0);\r
-        // Destination Endpoint\r
-        EndpointBuilder destinationEndpointBuilder = buildEndpoint(IPV4_1, MAC_1, CONNECTOR_1);\r
-        Endpoint destinationEndpoint = destinationEndpointBuilder.build();\r
-        EgKey destinationEgKey = new EgKey(tenant.getId(), ENDPOINT_GROUP_1);\r
-        // Nsh header\r
-        SfcNshHeaderBuilder nshHeaderBuilder = new SfcNshHeaderBuilder();\r
-        nshHeaderBuilder.setNshMetaC1(Long.valueOf(0L));\r
-        nshHeaderBuilder.setNshNsiFromChain((short) 250);\r
-        nshHeaderBuilder.setNshNspFromChain(27L);\r
-        SfcNshHeader nshHeader = nshHeaderBuilder.build();\r
-\r
-        when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());\r
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);\r
-        when(ctx.getSwitchManager()).thenReturn(switchManager);\r
-        when(ctx.getPolicyManager()).thenReturn(policyManager);\r
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);\r
-        when(switchManager.getTunnelPort(NODE_ID, TunnelTypeVxlanGpe.class)).thenReturn(CONNECTOR_2);\r
-        when(switchManager.getTunnelIP(NODE_ID, TunnelTypeVxlanGpe.class)).thenReturn(new IpAddress(IPV4_2));\r
-        when(policyManager.getTABLEID_PORTSECURITY()).thenReturn((short) 4);\r
-        when(policyManager.getTABLEID_SOURCE_MAPPER()).thenReturn((short) 2);\r
-\r
-        // Net elements\r
-        NetworkElements netElements = new NetworkElements(sourceEndpoint, destinationEndpoint, sourceEgKey,\r
-                destinationEgKey, NODE_ID, ctx);\r
-        assertNotNull(netElements);\r
-\r
-        ChainActionFlows.createChainTunnelFlows(nshHeader, netElements, ofWriter, ctx, HasDirection.Direction.In);\r
-\r
-        // Verify flows and capture arguments\r
-        verify(ofWriter, times(4)).writeFlow(nodeIdCaptor.capture(), tableIdCaptor.capture(), flowCaptor.capture());\r
-\r
-        // Verify nodeIds\r
-        for (NodeId capturedNodeId : nodeIdCaptor.getAllValues()) {\r
-            assertEquals(capturedNodeId, NODE_ID);\r
-        }\r
-\r
-        // Verify tableIds\r
-        List<Short> tableIds = tableIdCaptor.getAllValues();\r
-        Short expectedTableIds[] = {4, 2, 0, 2};\r
-        assertArrayEquals(expectedTableIds, tableIds.toArray());\r
-\r
-        // Verify flows\r
-        List<Flow> flows = flowCaptor.getAllValues();\r
-        assertNotNull(flows);\r
-        assertTrue(flows.size() == 4);\r
-        assertEquals(flows.get(0), allowFromChainTestFlow());\r
-        assertEquals(flows.get(1), createChainTunnelTestFlow(netElements).get(0)); // contains only 1 entry\r
-        assertEquals(flows.get(2), allowFromChainTunnelTestFlow());\r
-        assertEquals(flows.get(3), createChainBroadcastTestFlow());\r
-    }\r
-\r
-    @Test\r
-    public void createChainTunnelFlows_directionOut() throws Exception {\r
-        // Tenant\r
-        TenantBuilder tenantBuilder = buildTenant();\r
-        Tenant tenant = tenantBuilder.build();\r
-        // Source Endpoint\r
-        EndpointBuilder sourceEndpointBuilder = buildEndpoint(IPV4_0, MAC_0, CONNECTOR_0);\r
-        Endpoint sourceEndpoint = sourceEndpointBuilder.build();\r
-        EgKey sourceEgKey = new EgKey(tenant.getId(), ENDPOINT_GROUP_0);\r
-        // Destination Endpoint\r
-        EndpointBuilder destinationEndpointBuilder = buildEndpoint(IPV4_1, MAC_1, CONNECTOR_1);\r
-        Endpoint destinationEndpoint = destinationEndpointBuilder.build();\r
-        EgKey destinationEgKey = new EgKey(tenant.getId(), ENDPOINT_GROUP_1);\r
-        // Nsh header\r
-        SfcNshHeaderBuilder nshHeaderBuilder = new SfcNshHeaderBuilder();\r
-        nshHeaderBuilder.setNshMetaC1(Long.valueOf(0L));\r
-        nshHeaderBuilder.setNshNsiToChain((short) 255);\r
-        nshHeaderBuilder.setNshNspToChain(27L);\r
-        nshHeaderBuilder.setNshTunIpDst(IPV4_2);\r
-        SfcNshHeader nshHeader = nshHeaderBuilder.build();\r
-\r
-        when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());\r
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);\r
-        when(ctx.getSwitchManager()).thenReturn(switchManager);\r
-        when(ctx.getPolicyManager()).thenReturn(policyManager);\r
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);\r
-        when(switchManager.getTunnelPort(NODE_ID, TunnelTypeVxlanGpe.class)).thenReturn(CONNECTOR_2);\r
-        when(switchManager.getTunnelIP(NODE_ID, TunnelTypeVxlanGpe.class)).thenReturn(new IpAddress(IPV4_2));\r
-        when(policyManager.getTABLEID_EXTERNAL_MAPPER()).thenReturn((short) 6);\r
-\r
-\r
-        // Net elements\r
-        NetworkElements netElements = new NetworkElements(sourceEndpoint, destinationEndpoint, sourceEgKey,\r
-                destinationEgKey, NODE_ID, ctx);\r
-        assertNotNull(netElements);\r
-\r
-        ChainActionFlows.createChainTunnelFlows(nshHeader, netElements, ofWriter, ctx, HasDirection.Direction.Out);\r
-\r
-        // Verify flows and capture arguments\r
-        verify(ofWriter, times(1)).writeFlow(NODE_ID, (short) 6, createExternalTestFlow(netElements));\r
-    }\r
-\r
-    private Flow allowFromChainTestFlow() {\r
-        MatchBuilder matchBuilder = new MatchBuilder();\r
-        FlowUtils.addNxNshc1RegMatch(matchBuilder, 0L);\r
-        FlowUtils.addNxNsiMatch(matchBuilder, (short) 250);\r
-        FlowUtils.addNxNspMatch(matchBuilder, 27L);\r
-        Match match = matchBuilder.setInPort(CONNECTOR_2).build();\r
-\r
-        FlowId flowId = FlowIdUtils.newFlowId((short) 4, "chainport", match);\r
-        FlowBuilder flowBuilder = new FlowBuilder().setTableId((short) 4).setBarrier(false).setHardTimeout(0)\r
-                .setIdleTimeout(0).setId(flowId).setPriority(1200).setMatch(match)\r
-                .setInstructions(FlowUtils.gotoTableInstructions((short) 2));\r
-        return flowBuilder.build();\r
-    }\r
-\r
-    private List<Flow> createChainTunnelTestFlow(NetworkElements networkElements) {\r
-        Preconditions.checkNotNull(networkElements);\r
-        List<Flow> flows = new ArrayList<>();\r
-        Action segReg = nxLoadRegAction(NxmNxReg0.class, BigInteger.valueOf(1L));\r
-        Action scgReg = nxLoadRegAction(NxmNxReg1.class, BigInteger.valueOf(0xffffff));\r
-        Action bdReg = nxLoadRegAction(NxmNxReg4.class, BigInteger.valueOf(3L));\r
-        Action fdReg = nxLoadRegAction(NxmNxReg5.class, BigInteger.valueOf(4L));\r
-        Action vrfReg = nxLoadRegAction(NxmNxReg6.class, BigInteger.valueOf(5L));\r
-        for (L3Address address : networkElements.getDstEp().getL3Address()) {\r
-            Layer3Match l3Match = new Ipv4MatchBuilder().setIpv4Source(new Ipv4Prefix(address.getIpAddress()\r
-                    .getIpv4Address().getValue() + IP_PREFIX_32)).build();\r
-            MatchBuilder mb = new MatchBuilder().setInPort(CONNECTOR_2).setLayer3Match(l3Match)\r
-                    .setEthernetMatch(FlowUtils.ethernetMatch(null, null, FlowUtils.IPv4));\r
-            addNxTunIdMatch(mb, networkElements.getSrcEpOrdinals().getTunnelId());\r
-            addNxNspMatch(mb, 27L);\r
-            addNxNsiMatch(mb, (short) 250);\r
-            Match match = mb.build();\r
-            FlowId flowId = FlowIdUtils.newFlowId((short) 2, "chaintunnel", match);\r
-            FlowBuilder flowBuilder = base((short) 2).setId(flowId).setPriority(150).setMatch(match).setInstructions(\r
-                    instructions(applyActionIns(segReg, scgReg, bdReg, fdReg, vrfReg),\r
-                            gotoTableIns(ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER())));\r
-            flows.add(flowBuilder.build());\r
-        }\r
-        assertTrue(flows.size() == 1);\r
-        return flows;\r
-    }\r
-\r
-    private Flow allowFromChainTunnelTestFlow() {\r
-        MatchBuilder matchBuilder = new MatchBuilder().setInPort(CONNECTOR_2);\r
-        addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg1.class, 0xffffffL));\r
-        Match match = matchBuilder.build();\r
-        FlowId flowId = FlowIdUtils.newFlowId((short) 0, "chainport", match);\r
-        FlowBuilder flowBuilder = base((short) 0).setId(flowId).setMatch(match)\r
-                .setPriority(65000).setInstructions(instructions(applyActionIns(nxPopNshAction(), nxOutputRegAction(NxmNxReg7.class))));\r
-        return flowBuilder.build();\r
-    }\r
-\r
-    private Flow createChainBroadcastTestFlow() {\r
-        MatchBuilder matchBuilder = new MatchBuilder().setInPort(CONNECTOR_2);\r
-        addNxNsiMatch(matchBuilder, (short) 250);\r
-        addNxNspMatch(matchBuilder, 27L);\r
-        addNxTunIdMatch(matchBuilder, 4);\r
-        Match match = matchBuilder.build();\r
-        FlowId flowId = FlowIdUtils.newFlowId((short) 2, "chainbroadcast", match);\r
-        FlowBuilder flowBuilder = base((short) 2).setId(flowId).setPriority(150).setMatch(match)\r
-                .setInstructions(instructions(applyActionIns(nxLoadRegAction(NxmNxReg5.class, BigInteger.valueOf(4))),\r
-                        gotoTableIns(ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER())));\r
-        return flowBuilder.build();\r
-    }\r
-\r
-    private Flow createExternalTestFlow(NetworkElements networkElements) {\r
-        int matchTunnelId = networkElements.getSrcEpOrdinals().getTunnelId();\r
-        long setTunnelId = networkElements.getDstEpOrdinals().getTunnelId();\r
-        final short TUN_GPE_NP_NSH = 0x4;\r
-\r
-        Action loadC1 = nxLoadNshc1RegAction(Long.valueOf(0));\r
-        Action loadC2 = nxLoadNshc2RegAction(setTunnelId);\r
-        Action loadChainTunVnId = nxLoadTunIdAction(BigInteger.valueOf(setTunnelId), false);\r
-        Action loadChainTunDest = nxLoadTunIPv4Action(IPV4_2.getValue(), false);\r
-        Action loadTunGpeNp = nxLoadTunGpeNpAction(BigInteger.valueOf(TUN_GPE_NP_NSH), false);\r
-        Action outputAction = FlowUtils.createActionResubmit(null, (short) 0);\r
-\r
-        MatchBuilder matchBuilder = new MatchBuilder();\r
-        addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, 5L));\r
-        addNxTunIdMatch(matchBuilder, matchTunnelId);\r
-        addNxNspMatch(matchBuilder, 27L);\r
-        addNxNsiMatch(matchBuilder, (short) 255);\r
-\r
-\r
-        Match match = matchBuilder.build();\r
-        FlowId flowId = FlowIdUtils.newFlowId(((short) 6), "chainexternal", match);\r
-        FlowBuilder flowBuilder = base((short) 6).setId(flowId).setPriority(1000).setMatch(match)\r
-                .setInstructions(instructions(applyActionIns(loadC1, loadC2, loadChainTunDest, loadChainTunVnId, loadTunGpeNp,\r
-                        outputAction)));\r
-        return flowBuilder.build();\r
-    }\r
-}\r
+/*
+ * 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.flow;
+
+import com.google.common.base.Preconditions;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.opendaylight.groupbasedpolicy.dto.EgKey;
+import org.opendaylight.groupbasedpolicy.dto.PolicyInfo;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.EndpointManager;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.mapper.MapperUtilsTest;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.mapper.policyenforcer.NetworkElements;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils.SfcNshHeader;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils.SfcNshHeader.SfcNshHeaderBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointBuilder;
+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;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.TenantBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg0;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg5;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg7;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.TunnelTypeVxlanGpe;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.RegMatch;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.addNxNsiMatch;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.addNxNspMatch;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.addNxRegMatch;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.addNxTunIdMatch;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.applyActionIns;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.base;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.gotoTableIns;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.instructions;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadNshc1RegAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadNshc2RegAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadRegAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadTunGpeNpAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadTunIPv4Action;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadTunIdAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxOutputRegAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxPopNshAction;
+
+public class ChainActionFlowsTest extends MapperUtilsTest {
+
+    @Captor
+    private final ArgumentCaptor<NodeId> nodeIdCaptor = ArgumentCaptor.forClass(NodeId.class);
+    private final ArgumentCaptor<Short> tableIdCaptor = ArgumentCaptor.forClass(Short.class);
+    private final ArgumentCaptor<Flow> flowCaptor = ArgumentCaptor.forClass(Flow.class);
+
+    @Before
+    public void init() {
+        ctx = mock(OfContext.class);
+        endpointManager = mock(EndpointManager.class);
+        switchManager = mock(SwitchManager.class);
+        policyManager = mock(PolicyManager.class);
+        policyInfo = mock(PolicyInfo.class);
+        ofWriter = mock(OfWriter.class);
+    }
+
+    @Test
+    public void createChainTunnelFlows_directionIn() throws Exception {
+        // Tenant
+        TenantBuilder tenantBuilder = buildTenant();
+        Tenant tenant = tenantBuilder.build();
+        // Source Endpoint
+        EndpointBuilder sourceEndpointBuilder = buildEndpoint(IPV4_0, MAC_0, CONNECTOR_0);
+        Endpoint sourceEndpoint = sourceEndpointBuilder.build();
+        EgKey sourceEgKey = new EgKey(tenant.getId(), ENDPOINT_GROUP_0);
+        // Destination Endpoint
+        EndpointBuilder destinationEndpointBuilder = buildEndpoint(IPV4_1, MAC_1, CONNECTOR_1);
+        Endpoint destinationEndpoint = destinationEndpointBuilder.build();
+        EgKey destinationEgKey = new EgKey(tenant.getId(), ENDPOINT_GROUP_1);
+        // Nsh header
+        SfcNshHeaderBuilder nshHeaderBuilder = new SfcNshHeaderBuilder();
+        nshHeaderBuilder.setNshMetaC1(Long.valueOf(0L));
+        nshHeaderBuilder.setNshNsiFromChain((short) 250);
+        nshHeaderBuilder.setNshNspFromChain(27L);
+        SfcNshHeader nshHeader = nshHeaderBuilder.build();
+
+        when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
+        when(ctx.getEndpointManager()).thenReturn(endpointManager);
+        when(ctx.getSwitchManager()).thenReturn(switchManager);
+        when(ctx.getPolicyManager()).thenReturn(policyManager);
+        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
+        when(switchManager.getTunnelPort(NODE_ID, TunnelTypeVxlanGpe.class)).thenReturn(CONNECTOR_2);
+        when(switchManager.getTunnelIP(NODE_ID, TunnelTypeVxlanGpe.class)).thenReturn(new IpAddress(IPV4_2));
+        when(policyManager.getTABLEID_PORTSECURITY()).thenReturn((short) 4);
+        when(policyManager.getTABLEID_SOURCE_MAPPER()).thenReturn((short) 2);
+
+        // Net elements
+        NetworkElements netElements = new NetworkElements(sourceEndpoint, destinationEndpoint, sourceEgKey,
+                destinationEgKey, NODE_ID, ctx);
+        assertNotNull(netElements);
+
+        ChainActionFlows.createChainTunnelFlows(nshHeader, netElements, ofWriter, ctx, HasDirection.Direction.In);
+
+        // Verify flows and capture arguments
+        verify(ofWriter, times(4)).writeFlow(nodeIdCaptor.capture(), tableIdCaptor.capture(), flowCaptor.capture());
+
+        // Verify nodeIds
+        for (NodeId capturedNodeId : nodeIdCaptor.getAllValues()) {
+            assertEquals(capturedNodeId, NODE_ID);
+        }
+
+        // Verify tableIds
+        List<Short> tableIds = tableIdCaptor.getAllValues();
+        Short expectedTableIds[] = {4, 2, 0, 2};
+        assertArrayEquals(expectedTableIds, tableIds.toArray());
+
+        // Verify flows
+        List<Flow> flows = flowCaptor.getAllValues();
+        assertNotNull(flows);
+        assertTrue(flows.size() == 4);
+        assertEquals(flows.get(0), allowFromChainTestFlow());
+        assertEquals(flows.get(1), createChainTunnelTestFlow(netElements).get(0)); // contains only 1 entry
+        assertEquals(flows.get(2), allowFromChainTunnelTestFlow());
+        assertEquals(flows.get(3), createChainBroadcastTestFlow());
+    }
+
+    @Test
+    public void createChainTunnelFlows_directionOut() throws Exception {
+        // Tenant
+        TenantBuilder tenantBuilder = buildTenant();
+        Tenant tenant = tenantBuilder.build();
+        // Source Endpoint
+        EndpointBuilder sourceEndpointBuilder = buildEndpoint(IPV4_0, MAC_0, CONNECTOR_0);
+        Endpoint sourceEndpoint = sourceEndpointBuilder.build();
+        EgKey sourceEgKey = new EgKey(tenant.getId(), ENDPOINT_GROUP_0);
+        // Destination Endpoint
+        EndpointBuilder destinationEndpointBuilder = buildEndpoint(IPV4_1, MAC_1, CONNECTOR_1);
+        Endpoint destinationEndpoint = destinationEndpointBuilder.build();
+        EgKey destinationEgKey = new EgKey(tenant.getId(), ENDPOINT_GROUP_1);
+        // Nsh header
+        SfcNshHeaderBuilder nshHeaderBuilder = new SfcNshHeaderBuilder();
+        nshHeaderBuilder.setNshMetaC1(Long.valueOf(0L));
+        nshHeaderBuilder.setNshNsiToChain((short) 255);
+        nshHeaderBuilder.setNshNspToChain(27L);
+        nshHeaderBuilder.setNshTunIpDst(IPV4_2);
+        SfcNshHeader nshHeader = nshHeaderBuilder.build();
+
+        when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
+        when(ctx.getEndpointManager()).thenReturn(endpointManager);
+        when(ctx.getSwitchManager()).thenReturn(switchManager);
+        when(ctx.getPolicyManager()).thenReturn(policyManager);
+        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
+        when(switchManager.getTunnelPort(NODE_ID, TunnelTypeVxlanGpe.class)).thenReturn(CONNECTOR_2);
+        when(switchManager.getTunnelIP(NODE_ID, TunnelTypeVxlanGpe.class)).thenReturn(new IpAddress(IPV4_2));
+        when(policyManager.getTABLEID_EXTERNAL_MAPPER()).thenReturn((short) 6);
+
+
+        // Net elements
+        NetworkElements netElements = new NetworkElements(sourceEndpoint, destinationEndpoint, sourceEgKey,
+                destinationEgKey, NODE_ID, ctx);
+        assertNotNull(netElements);
+
+        ChainActionFlows.createChainTunnelFlows(nshHeader, netElements, ofWriter, ctx, HasDirection.Direction.Out);
+
+        // Verify flows and capture arguments
+        verify(ofWriter, times(1)).writeFlow(NODE_ID, (short) 6, createExternalTestFlow(netElements));
+    }
+
+    private Flow allowFromChainTestFlow() {
+        MatchBuilder matchBuilder = new MatchBuilder();
+        FlowUtils.addNxNshc1RegMatch(matchBuilder, 0L);
+        FlowUtils.addNxNsiMatch(matchBuilder, (short) 250);
+        FlowUtils.addNxNspMatch(matchBuilder, 27L);
+        Match match = matchBuilder.setInPort(CONNECTOR_2).build();
+
+        FlowId flowId = FlowIdUtils.newFlowId((short) 4, "chainport", match);
+        FlowBuilder flowBuilder = new FlowBuilder().setTableId((short) 4).setBarrier(false).setHardTimeout(0)
+                .setIdleTimeout(0).setId(flowId).setPriority(1200).setMatch(match)
+                .setInstructions(FlowUtils.gotoTableInstructions((short) 2));
+        return flowBuilder.build();
+    }
+
+    private List<Flow> createChainTunnelTestFlow(NetworkElements networkElements) {
+        Preconditions.checkNotNull(networkElements);
+        List<Flow> flows = new ArrayList<>();
+        Action segReg = nxLoadRegAction(NxmNxReg0.class, BigInteger.valueOf(1L));
+        Action scgReg = nxLoadRegAction(NxmNxReg1.class, BigInteger.valueOf(0xffffff));
+        Action bdReg = nxLoadRegAction(NxmNxReg4.class, BigInteger.valueOf(3L));
+        Action fdReg = nxLoadRegAction(NxmNxReg5.class, BigInteger.valueOf(4L));
+        Action vrfReg = nxLoadRegAction(NxmNxReg6.class, BigInteger.valueOf(5L));
+        for (L3Address address : networkElements.getDstEp().getL3Address()) {
+            Layer3Match l3Match = new Ipv4MatchBuilder().setIpv4Source(new Ipv4Prefix(address.getIpAddress()
+                    .getIpv4Address().getValue() + IP_PREFIX_32)).build();
+            MatchBuilder mb = new MatchBuilder().setInPort(CONNECTOR_2).setLayer3Match(l3Match)
+                    .setEthernetMatch(FlowUtils.ethernetMatch(null, null, FlowUtils.IPv4));
+            addNxTunIdMatch(mb, networkElements.getSrcEpOrdinals().getTunnelId());
+            addNxNspMatch(mb, 27L);
+            addNxNsiMatch(mb, (short) 250);
+            Match match = mb.build();
+            FlowId flowId = FlowIdUtils.newFlowId((short) 2, "chaintunnel", match);
+            FlowBuilder flowBuilder = base((short) 2).setId(flowId).setPriority(150).setMatch(match).setInstructions(
+                    instructions(applyActionIns(segReg, scgReg, bdReg, fdReg, vrfReg),
+                            gotoTableIns(ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER())));
+            flows.add(flowBuilder.build());
+        }
+        assertTrue(flows.size() == 1);
+        return flows;
+    }
+
+    private Flow allowFromChainTunnelTestFlow() {
+        MatchBuilder matchBuilder = new MatchBuilder().setInPort(CONNECTOR_2);
+        addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg1.class, 0xffffffL));
+        Match match = matchBuilder.build();
+        FlowId flowId = FlowIdUtils.newFlowId((short) 0, "chainport", match);
+        FlowBuilder flowBuilder = base((short) 0).setId(flowId).setMatch(match)
+                .setPriority(65000).setInstructions(instructions(applyActionIns(nxPopNshAction(), nxOutputRegAction(NxmNxReg7.class))));
+        return flowBuilder.build();
+    }
+
+    private Flow createChainBroadcastTestFlow() {
+        MatchBuilder matchBuilder = new MatchBuilder().setInPort(CONNECTOR_2);
+        addNxNsiMatch(matchBuilder, (short) 250);
+        addNxNspMatch(matchBuilder, 27L);
+        addNxTunIdMatch(matchBuilder, 4);
+        Match match = matchBuilder.build();
+        FlowId flowId = FlowIdUtils.newFlowId((short) 2, "chainbroadcast", match);
+        FlowBuilder flowBuilder = base((short) 2).setId(flowId).setPriority(150).setMatch(match)
+                .setInstructions(instructions(applyActionIns(nxLoadRegAction(NxmNxReg5.class, BigInteger.valueOf(4))),
+                        gotoTableIns(ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER())));
+        return flowBuilder.build();
+    }
+
+    private Flow createExternalTestFlow(NetworkElements networkElements) {
+        int matchTunnelId = networkElements.getSrcEpOrdinals().getTunnelId();
+        long setTunnelId = networkElements.getDstEpOrdinals().getTunnelId();
+        final short TUN_GPE_NP_NSH = 0x4;
+
+        Action loadC1 = nxLoadNshc1RegAction(Long.valueOf(0));
+        Action loadC2 = nxLoadNshc2RegAction(setTunnelId);
+        Action loadChainTunVnId = nxLoadTunIdAction(BigInteger.valueOf(setTunnelId), false);
+        Action loadChainTunDest = nxLoadTunIPv4Action(IPV4_2.getValue(), false);
+        Action loadTunGpeNp = nxLoadTunGpeNpAction(BigInteger.valueOf(TUN_GPE_NP_NSH), false);
+        Action outputAction = FlowUtils.createActionResubmit(null, (short) 0);
+
+        MatchBuilder matchBuilder = new MatchBuilder();
+        addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, 5L));
+        addNxTunIdMatch(matchBuilder, matchTunnelId);
+        addNxNspMatch(matchBuilder, 27L);
+        addNxNsiMatch(matchBuilder, (short) 255);
+
+
+        Match match = matchBuilder.build();
+        FlowId flowId = FlowIdUtils.newFlowId(((short) 6), "chainexternal", match);
+        FlowBuilder flowBuilder = base((short) 6).setId(flowId).setPriority(1000).setMatch(match)
+                .setInstructions(instructions(applyActionIns(loadC1, loadC2, loadChainTunDest, loadChainTunVnId, loadTunGpeNp,
+                        outputAction)));
+        return flowBuilder.build();
+    }
+}
index fd9ee41c3e864bc7056e39180df21844577f7561..806c4e855013849aa35fed698bb3bfc9259518db 100755 (executable)
@@ -1,42 +1,42 @@
-/*\r
- * Copyright (c) 2014 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.flow;\r
-\r
-import java.util.Map;\r
-\r
-import org.junit.Ignore;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
-\r
-public class FlowTableTest extends OfTableTest {\r
-    protected FlowTable table;\r
-    InstanceIdentifier<Table> tiid;\r
-\r
-    protected void setup() throws Exception {\r
-        tiid = FlowUtils.createTablePath(nodeId,\r
-                                         table.getTableId());\r
-    }\r
-\r
-    @Ignore\r
-    protected OfWriter dosync(Map<String, Flow> flows) throws Exception {\r
-        OfWriter ofWriter = new OfWriter();\r
-        if (flows != null) {\r
-            for (String key : flows.keySet()) {\r
-                Flow flow = flows.get(key);\r
-                if (flow != null) {\r
-                    ofWriter.writeFlow(nodeId, flow.getTableId(), flow);\r
-                }\r
-            }\r
-        }\r
-        //table.sync(NODE_ID, ofWriter);\r
-        return ofWriter;\r
-    }\r
-}\r
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow;
+
+import java.util.Map;
+
+import org.junit.Ignore;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class FlowTableTest extends OfTableTest {
+    protected FlowTable table;
+    InstanceIdentifier<Table> tiid;
+
+    protected void setup() throws Exception {
+        tiid = FlowUtils.createTablePath(nodeId,
+                                         table.getTableId());
+    }
+
+    @Ignore
+    protected OfWriter dosync(Map<String, Flow> flows) throws Exception {
+        OfWriter ofWriter = new OfWriter();
+        if (flows != null) {
+            for (String key : flows.keySet()) {
+                Flow flow = flows.get(key);
+                if (flow != null) {
+                    ofWriter.writeFlow(nodeId, flow.getTableId(), flow);
+                }
+            }
+        }
+        //table.sync(NODE_ID, ofWriter);
+        return ofWriter;
+    }
+}
index dd64248a299c1942fd7a2138433b1e516570e949..38c3be56e20659355ec4a6e232323e10397472ac 100755 (executable)
-/*\r
- * Copyright (c) 2014 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.flow;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.opendaylight.groupbasedpolicy.api.sf.L4ClassifierDefinition;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.MockOfContext;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.MockPolicyManager;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.MockEndpointManager;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.MockSwitchManager;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.AllowAction;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.Classifier;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ActionName;\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.ClauseName;\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.L2BridgeDomainId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2FloodDomainId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L3ContextId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ParameterName;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SelectorName;\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.SubnetId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContext;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContextBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.Segmentation;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.SegmentationBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.HasDirection.Direction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.action.refs.ActionRefBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.classifier.refs.ClassifierRef;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.classifier.refs.ClassifierRefBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.TenantBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.ForwardingContextBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.PolicyBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2BridgeDomainBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2FloodDomainBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L3ContextBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.SubnetBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.ContractBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroupBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.SubjectFeatureInstancesBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.ClauseBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.Subject;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.SubjectBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.subject.Rule;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.subject.RuleBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.endpoint.group.ConsumerNamedSelectorBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.endpoint.group.ProviderNamedSelectorBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ActionInstanceBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ClassifierInstanceBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;\r
-\r
-import com.google.common.collect.ImmutableList;\r
-\r
-public class OfTableTest {\r
-    protected MockOfContext ctx;\r
-\r
-    protected MockEndpointManager endpointManager;\r
-    protected MockPolicyManager policyManager;\r
-    protected MockSwitchManager switchManager;\r
-    protected NodeId nodeId = new NodeId("openflow:1");\r
-    protected NodeId remoteNodeId = new NodeId("openflow:2");\r
-    protected NodeConnectorId nodeConnectorId =\r
-            new NodeConnectorId(nodeId.getValue() + ":4");\r
-\r
-    protected NodeConnectorId tunnelId =\r
-            new NodeConnectorId(nodeId.getValue() + ":42");\r
-\r
-    protected L3ContextId l3c = new L3ContextId("2cf51ee4-e996-467e-a277-2d380334a91d");\r
-    protected L2BridgeDomainId bd = new L2BridgeDomainId("c95182ba-7807-43f8-98f7-6c7c720b7639");\r
-    protected L2FloodDomainId fd = new L2FloodDomainId("98e1439e-52d2-46f8-bd69-5136e6088771");\r
-    protected L2FloodDomainId ext_fd = new L2FloodDomainId("d8024f7a-b83e-11e5-9912-ba0be0483c18");\r
-    protected SubnetId sub = new SubnetId("4fcf8dfc-53b5-4aef-84d3-6b5586992fcb");\r
-    protected SubnetId sub2 = new SubnetId("c285a59f-fcb8-42e6-bf29-87ea522fd626");\r
-    protected SubnetId sub3 = new SubnetId("a0380d52-2a25-48ef-882c-a4d4cd9e00ec");\r
-    protected SubnetId ext_sub = new SubnetId("8da17ad9-3261-4dc9-bcff-928a2f73cce7");\r
-    protected TenantId tid = new TenantId("1118c691-8520-47ad-80b8-4cf5e3fe3302");\r
-    protected EndpointGroupId eg = new EndpointGroupId("36dec84a-08c7-497b-80b6-a0035af72a12");\r
-    protected EndpointGroupId eg2 = new EndpointGroupId("632e5e11-7988-4eb5-8fe6-6c182d890276");\r
-    protected ContractId cid = new ContractId("a5874893-bcd5-46de-96af-3c8d99bedf9f");\r
-\r
-    protected void initCtx() {\r
-        endpointManager = new MockEndpointManager();\r
-        policyManager = new MockPolicyManager(endpointManager);\r
-        switchManager = new MockSwitchManager();\r
-        ctx = new MockOfContext(null,\r
-                             policyManager,\r
-                             switchManager,\r
-                             endpointManager,\r
-                             null);\r
-    }\r
-\r
-    protected TenantBuilder baseTenant() {\r
-        return new TenantBuilder().setId(tid)\r
-            .setPolicy(new PolicyBuilder()\r
-                .setEndpointGroup(ImmutableList.of(\r
-                        new EndpointGroupBuilder().setId(eg)\r
-                            .setNetworkDomain(sub)\r
-                            .setConsumerNamedSelector(ImmutableList.of(new ConsumerNamedSelectorBuilder()\r
-                                .setName(new SelectorName("cns1")).setContract(ImmutableList.of(cid)).build()))\r
-                            .build(),\r
-                        new EndpointGroupBuilder().setId(eg2)\r
-                            .setNetworkDomain(sub2)\r
-                            .setProviderNamedSelector(ImmutableList.of(new ProviderNamedSelectorBuilder()\r
-                                .setName(new SelectorName("pns1")).setContract(ImmutableList.of(cid)).build()))\r
-                            .build()))\r
-                .setSubjectFeatureInstances(\r
-                        new SubjectFeatureInstancesBuilder()\r
-                            .setClassifierInstance(\r
-                                    ImmutableList\r
-                                        .of(new ClassifierInstanceBuilder().setName(new ClassifierName("tcp_dst_80"))\r
-                                            .setClassifierDefinitionId(L4ClassifierDefinition.DEFINITION.getId())\r
-                                            .setParameterValue(ImmutableList.of(\r
-                                                    new ParameterValueBuilder().setName(new ParameterName("destport"))\r
-                                                        .setIntValue(Long.valueOf(80))\r
-                                                        .build(),\r
-                                                    new ParameterValueBuilder().setName(new ParameterName("proto"))\r
-                                                        .setIntValue(Long.valueOf(6))\r
-                                                        .build()))\r
-                                            .build(), new ClassifierInstanceBuilder()\r
-                                                .setName(new ClassifierName("tcp_src_80"))\r
-                                                .setClassifierDefinitionId(Classifier.L4_CL.getId())\r
-                                                .setParameterValue(ImmutableList.of(\r
-                                                        new ParameterValueBuilder()\r
-                                                            .setName(new ParameterName("sourceport"))\r
-                                                            .setIntValue(Long.valueOf(80))\r
-                                                            .build(),\r
-                                                        new ParameterValueBuilder().setName(new ParameterName("proto"))\r
-                                                            .setIntValue(Long.valueOf(6))\r
-                                                            .build()))\r
-                                                .build(),\r
-                                                new ClassifierInstanceBuilder()\r
-                                                    .setName(new ClassifierName("ether_type"))\r
-                                                    .setClassifierDefinitionId(Classifier.ETHER_TYPE_CL.getId())\r
-                                                    .setParameterValue(ImmutableList.of(new ParameterValueBuilder()\r
-                                                        .setName(new ParameterName("ethertype"))\r
-                                                        .setIntValue(Long.valueOf(FlowUtils.IPv4))\r
-                                                        .build()))\r
-                                                    .build()))\r
-                            .setActionInstance(\r
-                                    ImmutableList.of(new ActionInstanceBuilder().setName(new ActionName("allow"))\r
-                                        .setActionDefinitionId(new AllowAction().getId())\r
-                                        .build()))\r
-                            .build())\r
-                .build())\r
-            .setForwardingContext(\r
-                    new ForwardingContextBuilder()\r
-                        .setL3Context(ImmutableList.of(new L3ContextBuilder().setId(l3c).build()))\r
-                        .setL2BridgeDomain(\r
-                                ImmutableList.of(new L2BridgeDomainBuilder().setId(bd).setParent(l3c).build()))\r
-                        .setL2FloodDomain(ImmutableList.of(\r
-                                new L2FloodDomainBuilder()\r
-                                    .setId(fd)\r
-                                    .setParent(bd)\r
-                                    .addAugmentation(Segmentation.class,\r
-                                        new SegmentationBuilder()\r
-                                        .setSegmentationId(Integer.valueOf(216))\r
-                                        .build())\r
-                                    .build(),\r
-                                new L2FloodDomainBuilder()\r
-                                    .setId(ext_fd)\r
-                                    .addAugmentation(Segmentation.class,\r
-                                        new SegmentationBuilder()\r
-                                        .setSegmentationId(Integer.valueOf(2016))\r
-                                        .build())\r
-                                    .build()))\r
-                        .setSubnet(ImmutableList.of(\r
-                                new SubnetBuilder().setId(sub2)\r
-                                    .setParent(fd)\r
-                                    .setIpPrefix(new IpPrefix(new Ipv4Prefix("10.0.1.0/24")))\r
-                                    .setVirtualRouterIp(new IpAddress(new Ipv4Address("10.0.1.1")))\r
-                                    .build(),\r
-                                new SubnetBuilder().setId(sub)\r
-                                    .setParent(fd)\r
-                                    .setIpPrefix(new IpPrefix(new Ipv4Prefix("10.0.0.0/24")))\r
-                                    .setVirtualRouterIp(new IpAddress(new Ipv4Address("10.0.0.1")))\r
-                                    .build(),\r
-                                new SubnetBuilder().setId(sub3)\r
-                                    .setParent(bd)\r
-                                    .setIpPrefix(new IpPrefix(new Ipv4Prefix("10.0.2.0/24")))\r
-                                    .setVirtualRouterIp(new IpAddress(new Ipv4Address("10.0.2.1")))\r
-                                    .build(),\r
-                                new SubnetBuilder()\r
-                                    .setId(ext_sub)\r
-                                    .setIpPrefix(new IpPrefix(new Ipv4Prefix("192.168.111.0/24")))\r
-                                    .setParent(ext_fd)\r
-                                    .build()))\r
-                       .build());\r
-    }\r
-\r
-    protected ContractBuilder baseContract(List<Subject> subjects) {\r
-        ContractBuilder contractBuilder = new ContractBuilder().setId(cid).setSubject(subjects);\r
-        // TODO refactor\r
-        if (subjects == null) {\r
-            return contractBuilder.setClause(ImmutableList.of(new ClauseBuilder().setName(new ClauseName("test"))\r
-                .setSubjectRefs(ImmutableList.<SubjectName>of(new SubjectName("s1")))\r
-                .build()));\r
-        }\r
-        List<SubjectName> subjectNames = new ArrayList<>();\r
-        for (Subject subject : subjects) {\r
-            subjectNames.add(subject.getName());\r
-        }\r
-        return contractBuilder.setClause(ImmutableList.of(new ClauseBuilder().setName(new ClauseName("test"))\r
-            .setSubjectRefs(subjectNames)\r
-            .build()));\r
-    }\r
-\r
-    protected SubjectBuilder baseSubject(Direction direction) {\r
-        return new SubjectBuilder()\r
-            .setName(new SubjectName("s1"))\r
-            .setRule(ImmutableList.of(new RuleBuilder()\r
-                .setActionRef(ImmutableList.of(new ActionRefBuilder()\r
-                    .setName(new ActionName("allow"))\r
-                    .build()))\r
-                .setClassifierRef(ImmutableList.of(new ClassifierRefBuilder()\r
-                    .setName(new ClassifierName("tcp_dst_80"))\r
-                    .setDirection(direction)\r
-                    .setInstanceName(new ClassifierName("tcp_dst_80"))\r
-                    .build()))\r
-                .build()));\r
-    }\r
-\r
-\r
-    protected Subject createSubject(String name, List<Rule> rules){\r
-        return new SubjectBuilder().setName(new SubjectName(name)).setRule(rules).build();\r
-    }\r
-\r
-    protected List<ClassifierRef> createClassifierRefs(Map<String, Direction> refNamesAndDirections) {\r
-        List<ClassifierRef> refs = new ArrayList<>();\r
-        for (String refName : refNamesAndDirections.keySet()) {\r
-            refs.add(new ClassifierRefBuilder().setName(new ClassifierName(refName))\r
-                .setDirection(refNamesAndDirections.get(refName))\r
-                .setInstanceName(new ClassifierName(refName))\r
-                .build());\r
-        }\r
-        return refs;\r
-    }\r
-\r
-    protected EndpointBuilder baseEP() {\r
-        return new EndpointBuilder()\r
-            .setL2Context(bd)\r
-            .setTenant(tid)\r
-            .setEndpointGroup(eg)\r
-            .setMacAddress(new MacAddress("00:00:00:00:00:01"))\r
-            .setNetworkContainment(sub2);\r
-    }\r
-\r
-    protected EndpointBuilder localEP() {\r
-        OfOverlayContext ofc = new OfOverlayContextBuilder()\r
-            .setNodeId(nodeId)\r
-            .setNodeConnectorId(nodeConnectorId)\r
-            .build();\r
-        return baseEP()\r
-            .addAugmentation(OfOverlayContext.class, ofc);\r
-    }\r
-\r
-    protected EndpointBuilder remoteEP(NodeId id) {\r
-        OfOverlayContext ofc = new OfOverlayContextBuilder()\r
-            .setNodeId(id)\r
-            .setNodeConnectorId(new NodeConnectorId(id.getValue() + ":5"))\r
-            .build();\r
-        return baseEP()\r
-            .setMacAddress(new MacAddress("00:00:00:00:00:02"))\r
-            .addAugmentation(OfOverlayContext.class, ofc);\r
-    }\r
-\r
-}\r
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.opendaylight.groupbasedpolicy.api.sf.L4ClassifierDefinition;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.MockOfContext;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.MockPolicyManager;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.MockEndpointManager;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.MockSwitchManager;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.AllowAction;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.Classifier;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ActionName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClauseName;
+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.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.ParameterName;
+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.endpoint.rev140421.endpoints.EndpointBuilder;
+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.groupbasedpolicy.ofoverlay.rev140528.Segmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.SegmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.HasDirection.Direction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.action.refs.ActionRefBuilder;
+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.has.classifier.refs.ClassifierRefBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.TenantBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.ForwardingContextBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.PolicyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2BridgeDomainBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2FloodDomainBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L3ContextBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.SubnetBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.ContractBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroupBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.SubjectFeatureInstancesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.ClauseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.Subject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.SubjectBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.subject.Rule;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.subject.RuleBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.endpoint.group.ConsumerNamedSelectorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.endpoint.group.ProviderNamedSelectorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ActionInstanceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ClassifierInstanceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+
+import com.google.common.collect.ImmutableList;
+
+public class OfTableTest {
+    protected MockOfContext ctx;
+
+    protected MockEndpointManager endpointManager;
+    protected MockPolicyManager policyManager;
+    protected MockSwitchManager switchManager;
+    protected NodeId nodeId = new NodeId("openflow:1");
+    protected NodeId remoteNodeId = new NodeId("openflow:2");
+    protected NodeConnectorId nodeConnectorId =
+            new NodeConnectorId(nodeId.getValue() + ":4");
+
+    protected NodeConnectorId tunnelId =
+            new NodeConnectorId(nodeId.getValue() + ":42");
+
+    protected L3ContextId l3c = new L3ContextId("2cf51ee4-e996-467e-a277-2d380334a91d");
+    protected L2BridgeDomainId bd = new L2BridgeDomainId("c95182ba-7807-43f8-98f7-6c7c720b7639");
+    protected L2FloodDomainId fd = new L2FloodDomainId("98e1439e-52d2-46f8-bd69-5136e6088771");
+    protected L2FloodDomainId ext_fd = new L2FloodDomainId("d8024f7a-b83e-11e5-9912-ba0be0483c18");
+    protected SubnetId sub = new SubnetId("4fcf8dfc-53b5-4aef-84d3-6b5586992fcb");
+    protected SubnetId sub2 = new SubnetId("c285a59f-fcb8-42e6-bf29-87ea522fd626");
+    protected SubnetId sub3 = new SubnetId("a0380d52-2a25-48ef-882c-a4d4cd9e00ec");
+    protected SubnetId ext_sub = new SubnetId("8da17ad9-3261-4dc9-bcff-928a2f73cce7");
+    protected TenantId tid = new TenantId("1118c691-8520-47ad-80b8-4cf5e3fe3302");
+    protected EndpointGroupId eg = new EndpointGroupId("36dec84a-08c7-497b-80b6-a0035af72a12");
+    protected EndpointGroupId eg2 = new EndpointGroupId("632e5e11-7988-4eb5-8fe6-6c182d890276");
+    protected ContractId cid = new ContractId("a5874893-bcd5-46de-96af-3c8d99bedf9f");
+
+    protected void initCtx() {
+        endpointManager = new MockEndpointManager();
+        policyManager = new MockPolicyManager(endpointManager);
+        switchManager = new MockSwitchManager();
+        ctx = new MockOfContext(null,
+                             policyManager,
+                             switchManager,
+                             endpointManager,
+                             null);
+    }
+
+    protected TenantBuilder baseTenant() {
+        return new TenantBuilder().setId(tid)
+            .setPolicy(new PolicyBuilder()
+                .setEndpointGroup(ImmutableList.of(
+                        new EndpointGroupBuilder().setId(eg)
+                            .setNetworkDomain(sub)
+                            .setConsumerNamedSelector(ImmutableList.of(new ConsumerNamedSelectorBuilder()
+                                .setName(new SelectorName("cns1")).setContract(ImmutableList.of(cid)).build()))
+                            .build(),
+                        new EndpointGroupBuilder().setId(eg2)
+                            .setNetworkDomain(sub2)
+                            .setProviderNamedSelector(ImmutableList.of(new ProviderNamedSelectorBuilder()
+                                .setName(new SelectorName("pns1")).setContract(ImmutableList.of(cid)).build()))
+                            .build()))
+                .setSubjectFeatureInstances(
+                        new SubjectFeatureInstancesBuilder()
+                            .setClassifierInstance(
+                                    ImmutableList
+                                        .of(new ClassifierInstanceBuilder().setName(new ClassifierName("tcp_dst_80"))
+                                            .setClassifierDefinitionId(L4ClassifierDefinition.DEFINITION.getId())
+                                            .setParameterValue(ImmutableList.of(
+                                                    new ParameterValueBuilder().setName(new ParameterName("destport"))
+                                                        .setIntValue(Long.valueOf(80))
+                                                        .build(),
+                                                    new ParameterValueBuilder().setName(new ParameterName("proto"))
+                                                        .setIntValue(Long.valueOf(6))
+                                                        .build()))
+                                            .build(), new ClassifierInstanceBuilder()
+                                                .setName(new ClassifierName("tcp_src_80"))
+                                                .setClassifierDefinitionId(Classifier.L4_CL.getId())
+                                                .setParameterValue(ImmutableList.of(
+                                                        new ParameterValueBuilder()
+                                                            .setName(new ParameterName("sourceport"))
+                                                            .setIntValue(Long.valueOf(80))
+                                                            .build(),
+                                                        new ParameterValueBuilder().setName(new ParameterName("proto"))
+                                                            .setIntValue(Long.valueOf(6))
+                                                            .build()))
+                                                .build(),
+                                                new ClassifierInstanceBuilder()
+                                                    .setName(new ClassifierName("ether_type"))
+                                                    .setClassifierDefinitionId(Classifier.ETHER_TYPE_CL.getId())
+                                                    .setParameterValue(ImmutableList.of(new ParameterValueBuilder()
+                                                        .setName(new ParameterName("ethertype"))
+                                                        .setIntValue(Long.valueOf(FlowUtils.IPv4))
+                                                        .build()))
+                                                    .build()))
+                            .setActionInstance(
+                                    ImmutableList.of(new ActionInstanceBuilder().setName(new ActionName("allow"))
+                                        .setActionDefinitionId(new AllowAction().getId())
+                                        .build()))
+                            .build())
+                .build())
+            .setForwardingContext(
+                    new ForwardingContextBuilder()
+                        .setL3Context(ImmutableList.of(new L3ContextBuilder().setId(l3c).build()))
+                        .setL2BridgeDomain(
+                                ImmutableList.of(new L2BridgeDomainBuilder().setId(bd).setParent(l3c).build()))
+                        .setL2FloodDomain(ImmutableList.of(
+                                new L2FloodDomainBuilder()
+                                    .setId(fd)
+                                    .setParent(bd)
+                                    .addAugmentation(Segmentation.class,
+                                        new SegmentationBuilder()
+                                        .setSegmentationId(Integer.valueOf(216))
+                                        .build())
+                                    .build(),
+                                new L2FloodDomainBuilder()
+                                    .setId(ext_fd)
+                                    .addAugmentation(Segmentation.class,
+                                        new SegmentationBuilder()
+                                        .setSegmentationId(Integer.valueOf(2016))
+                                        .build())
+                                    .build()))
+                        .setSubnet(ImmutableList.of(
+                                new SubnetBuilder().setId(sub2)
+                                    .setParent(fd)
+                                    .setIpPrefix(new IpPrefix(new Ipv4Prefix("10.0.1.0/24")))
+                                    .setVirtualRouterIp(new IpAddress(new Ipv4Address("10.0.1.1")))
+                                    .build(),
+                                new SubnetBuilder().setId(sub)
+                                    .setParent(fd)
+                                    .setIpPrefix(new IpPrefix(new Ipv4Prefix("10.0.0.0/24")))
+                                    .setVirtualRouterIp(new IpAddress(new Ipv4Address("10.0.0.1")))
+                                    .build(),
+                                new SubnetBuilder().setId(sub3)
+                                    .setParent(bd)
+                                    .setIpPrefix(new IpPrefix(new Ipv4Prefix("10.0.2.0/24")))
+                                    .setVirtualRouterIp(new IpAddress(new Ipv4Address("10.0.2.1")))
+                                    .build(),
+                                new SubnetBuilder()
+                                    .setId(ext_sub)
+                                    .setIpPrefix(new IpPrefix(new Ipv4Prefix("192.168.111.0/24")))
+                                    .setParent(ext_fd)
+                                    .build()))
+                       .build());
+    }
+
+    protected ContractBuilder baseContract(List<Subject> subjects) {
+        ContractBuilder contractBuilder = new ContractBuilder().setId(cid).setSubject(subjects);
+        // TODO refactor
+        if (subjects == null) {
+            return contractBuilder.setClause(ImmutableList.of(new ClauseBuilder().setName(new ClauseName("test"))
+                .setSubjectRefs(ImmutableList.<SubjectName>of(new SubjectName("s1")))
+                .build()));
+        }
+        List<SubjectName> subjectNames = new ArrayList<>();
+        for (Subject subject : subjects) {
+            subjectNames.add(subject.getName());
+        }
+        return contractBuilder.setClause(ImmutableList.of(new ClauseBuilder().setName(new ClauseName("test"))
+            .setSubjectRefs(subjectNames)
+            .build()));
+    }
+
+    protected SubjectBuilder baseSubject(Direction direction) {
+        return new SubjectBuilder()
+            .setName(new SubjectName("s1"))
+            .setRule(ImmutableList.of(new RuleBuilder()
+                .setActionRef(ImmutableList.of(new ActionRefBuilder()
+                    .setName(new ActionName("allow"))
+                    .build()))
+                .setClassifierRef(ImmutableList.of(new ClassifierRefBuilder()
+                    .setName(new ClassifierName("tcp_dst_80"))
+                    .setDirection(direction)
+                    .setInstanceName(new ClassifierName("tcp_dst_80"))
+                    .build()))
+                .build()));
+    }
+
+
+    protected Subject createSubject(String name, List<Rule> rules){
+        return new SubjectBuilder().setName(new SubjectName(name)).setRule(rules).build();
+    }
+
+    protected List<ClassifierRef> createClassifierRefs(Map<String, Direction> refNamesAndDirections) {
+        List<ClassifierRef> refs = new ArrayList<>();
+        for (String refName : refNamesAndDirections.keySet()) {
+            refs.add(new ClassifierRefBuilder().setName(new ClassifierName(refName))
+                .setDirection(refNamesAndDirections.get(refName))
+                .setInstanceName(new ClassifierName(refName))
+                .build());
+        }
+        return refs;
+    }
+
+    protected EndpointBuilder baseEP() {
+        return new EndpointBuilder()
+            .setL2Context(bd)
+            .setTenant(tid)
+            .setEndpointGroup(eg)
+            .setMacAddress(new MacAddress("00:00:00:00:00:01"))
+            .setNetworkContainment(sub2);
+    }
+
+    protected EndpointBuilder localEP() {
+        OfOverlayContext ofc = new OfOverlayContextBuilder()
+            .setNodeId(nodeId)
+            .setNodeConnectorId(nodeConnectorId)
+            .build();
+        return baseEP()
+            .addAugmentation(OfOverlayContext.class, ofc);
+    }
+
+    protected EndpointBuilder remoteEP(NodeId id) {
+        OfOverlayContext ofc = new OfOverlayContextBuilder()
+            .setNodeId(id)
+            .setNodeConnectorId(new NodeConnectorId(id.getValue() + ":5"))
+            .build();
+        return baseEP()
+            .setMacAddress(new MacAddress("00:00:00:00:00:02"))
+            .addAugmentation(OfOverlayContext.class, ofc);
+    }
+
+}
index 1f18edee21a3d310d6ce64f33d35d545fb10dde5..c6d50ef110c5bc889bfb3667007c0543307c9e02 100644 (file)
-/*\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
-package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.mapper;\r
-\r
-import com.google.common.base.Preconditions;\r
-import com.google.common.collect.ImmutableList;\r
-import org.opendaylight.groupbasedpolicy.api.sf.L4ClassifierDefinition;\r
-import org.opendaylight.groupbasedpolicy.dto.IndexedTenant;\r
-import org.opendaylight.groupbasedpolicy.dto.PolicyInfo;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.EndpointManager;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowTable;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.AllowAction;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.ChainAction;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.Classifier;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ActionName;\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.ContextId;\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.L2BridgeDomainId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2FloodDomainId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L3ContextId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.NetworkDomainId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ParameterName;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SelectorName;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubnetId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3Address;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3AddressBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Builder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.l3endpoint.rev151217.NatAddress;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.l3endpoint.rev151217.NatAddressBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContext;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContextBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.Segmentation;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.SegmentationBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.TenantBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.ForwardingContextBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.Policy;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.PolicyBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2BridgeDomain;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2BridgeDomainBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2FloodDomain;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2FloodDomainBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L3Context;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L3ContextBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.Subnet;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.SubnetBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroup;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroupBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.SubjectFeatureInstances;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.SubjectFeatureInstancesBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.endpoint.group.ConsumerNamedSelectorBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.endpoint.group.ProviderNamedSelectorBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ActionInstance;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ActionInstanceBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ClassifierInstanceBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-public abstract class MapperUtilsTest {\r
-\r
-    protected static final MacAddress MAC_0 = new MacAddress("00:00:00:00:00:00");\r
-    protected static final MacAddress MAC_1 = new MacAddress("00:00:00:00:00:01");\r
-    protected static final MacAddress MAC_2 = new MacAddress("00:00:00:00:00:02");\r
-    protected static final Ipv4Address IPV4_0 = new Ipv4Address("170.0.0.1");\r
-    protected static final Ipv4Address IPV4_1 = new Ipv4Address("190.0.0.1");\r
-    protected static final Ipv4Address IPV4_2 = new Ipv4Address("210.0.0.1");\r
-    protected static final Ipv6Address IPV6_1 = new Ipv6Address("2000:db80:85a3:08ba:0947:8a2e:3a70:7334");\r
-    protected static final Ipv6Address IPV6_2 = new Ipv6Address("0947:db80:3a70:7334:85a3:8a2e:2000:08ba");\r
-    protected static final NodeConnectorId CONNECTOR_0 = new NodeConnectorId("0");\r
-    protected static final NodeConnectorId CONNECTOR_1 = new NodeConnectorId("1");\r
-    protected static final NodeConnectorId CONNECTOR_2 = new NodeConnectorId("2");\r
-    protected static final SubnetId SUBNET_0 = new SubnetId("subnet0");\r
-    protected static final SubnetId SUBNET_1 = new SubnetId("subnet1");\r
-    protected static final SubnetId SUBNET_2 = new SubnetId("subnet2");\r
-    protected static final SubnetId SUBNET_EXT = new SubnetId("externalSubnet");\r
-    protected static final String IP_PREFIX_32 = "/32";\r
-    protected static final String IP_PREFIX_128 = "/128";\r
-    protected static final TenantId TENANT_ID = new TenantId("tenantId");\r
-    protected static final NodeId NODE_ID = new NodeId("nodeId");\r
-    protected static final EndpointGroupId ENDPOINT_GROUP_0 = new EndpointGroupId("eg0");\r
-    protected static final EndpointGroupId ENDPOINT_GROUP_1 = new EndpointGroupId("eg1");\r
-    protected static final EndpointGroupId ENDPOINT_GROUP_2 = new EndpointGroupId("eg2");\r
-    protected static final SubnetId NET_DOMAIN_ID = new SubnetId("ndId");\r
-    protected static final L2BridgeDomainId L2BD_ID = new L2BridgeDomainId("l2bdId");\r
-    protected static final L2FloodDomainId L2FD_ID = new L2FloodDomainId("l2fdId");\r
-    protected static final L2FloodDomainId L2_FD_ID_EXT = new L2FloodDomainId("externalL2fdId");\r
-    protected static final L3ContextId L3C_ID = new L3ContextId("l3cId");\r
-    protected static final ContractId CONTRACT_ID = new ContractId("contractId");\r
-    protected static final ContextId CONTEXT_ID = new L3ContextId("ctxId");\r
-    // Often used strings\r
-    protected static final String ALLOW = "allow";\r
-    protected static final String CHAIN = "chain";\r
-    protected static final String L2 = "L2";\r
-    protected static final String OPENFLOW = "openflow:";\r
-    protected static final String DROP_ALL = "dropAll";\r
-    protected static final String DROP = "drop";\r
-    protected static final String TCP_SRC = "tcp_src_80";\r
-    // Mock variables\r
-    protected Short tableId;\r
-    protected OfContext ctx;\r
-    protected OfWriter ofWriter;\r
-    protected SwitchManager switchManager;\r
-    protected PolicyManager policyManager;\r
-    protected EndpointManager endpointManager;\r
-    protected PolicyInfo policyInfo;\r
-    protected FlowTable table;\r
-\r
-    protected FlowBuilder buildFlow(FlowId flowId, short tableId, Integer priority, Match match,\r
-            Instructions instructions) {\r
-        return FlowUtils.base(tableId)\r
-            .setId(flowId)\r
-            .setPriority(priority)\r
-            .setMatch(match)\r
-            .setInstructions(instructions);\r
-    }\r
-\r
-    protected EndpointL3Builder buildL3Endpoint(Ipv4Address natIp, Ipv4Address ip, MacAddress mac, String l2bd) {\r
-        Preconditions.checkNotNull(natIp);\r
-        Preconditions.checkNotNull(ip);\r
-        Preconditions.checkNotNull(mac);\r
-\r
-        NatAddress natAddress = new NatAddressBuilder().setNatAddress(new IpAddress(new Ipv4Address(natIp))).build();\r
-\r
-        EndpointL3Builder endpointL3Builder = new EndpointL3Builder().addAugmentation(NatAddress.class, natAddress)\r
-            .setIpAddress(new IpAddress(ip))\r
-            .setMacAddress(new MacAddress(mac));\r
-        if (l2bd != null) {\r
-            endpointL3Builder.setL2Context(new L2BridgeDomainId(l2bd));\r
-        }\r
-        if (ip.equals(IPV4_0)) {\r
-            endpointL3Builder.setNetworkContainment(SUBNET_0);\r
-        } else if (ip.equals(IPV4_1)) {\r
-            endpointL3Builder.setNetworkContainment(SUBNET_1);\r
-        } else if (ip.equals(IPV4_2)) {\r
-            endpointL3Builder.setNetworkContainment(SUBNET_2);\r
-        }\r
-        return endpointL3Builder;\r
-    }\r
-\r
-    protected EndpointL3Builder buildL3Endpoint(Ipv6Address natIp, Ipv6Address ip, MacAddress mac, String l2bd) {\r
-        Preconditions.checkNotNull(natIp);\r
-        Preconditions.checkNotNull(ip);\r
-        Preconditions.checkNotNull(mac);\r
-\r
-        NatAddress natAddress = new NatAddressBuilder().setNatAddress(new IpAddress(new Ipv6Address(natIp))).build();\r
-\r
-        EndpointL3Builder endpointL3Builder = new EndpointL3Builder().addAugmentation(NatAddress.class, natAddress)\r
-            .setIpAddress(new IpAddress(ip))\r
-            .setMacAddress(new MacAddress(mac));\r
-        if (l2bd != null) {\r
-            endpointL3Builder.setL2Context(new L2BridgeDomainId(l2bd));\r
-        }\r
-        return endpointL3Builder;\r
-    }\r
-\r
-    public SegmentationBuilder buildSegmentation() {\r
-        return new SegmentationBuilder().setSegmentationId(1);\r
-    }\r
-\r
-    protected TenantBuilder buildTenant() {\r
-        Policy policy = new PolicyBuilder().setEndpointGroup(getEndpointGroups())\r
-            .setSubjectFeatureInstances(getSubjectFeatureInstances())\r
-            .build();\r
-\r
-        return new TenantBuilder().setId(TENANT_ID)\r
-            .setForwardingContext(buildForwardingContext().build())\r
-            .setPolicy(policy);\r
-    }\r
-\r
-    protected TenantBuilder buildTenant(ActionInstance actionInstance) {\r
-        Policy policy = new PolicyBuilder().setEndpointGroup(getEndpointGroups())\r
-            .setSubjectFeatureInstances(getSubjectFeatureInstances(actionInstance))\r
-            .build();\r
-\r
-        return new TenantBuilder().setId(TENANT_ID)\r
-            .setForwardingContext(buildForwardingContext().build())\r
-            .setPolicy(policy);\r
-    }\r
-\r
-    protected IndexedTenant getTestIndexedTenant() {\r
-        return new IndexedTenant(buildTenant().build());\r
-    }\r
-\r
-    protected IndexedTenant getTestIndexedTenant(ActionInstance actionInstance) {\r
-        return new IndexedTenant(buildTenant(actionInstance).build());\r
-    }\r
-\r
-    protected ForwardingContextBuilder buildForwardingContext() {\r
-        return new ForwardingContextBuilder().setL2FloodDomain(getL2FloodDomainList(false))\r
-            .setL2BridgeDomain(getL2BridgeDomainList())\r
-            .setL3Context(getL3ContextList())\r
-            .setSubnet(getSubnetList());\r
-    }\r
-\r
-    protected List<L3Context> getL3ContextList() {\r
-        L3Context l3Context = new L3ContextBuilder().setId(L3C_ID).build();\r
-        return ImmutableList.of(l3Context);\r
-    }\r
-\r
-    protected List<L2BridgeDomain> getL2BridgeDomainList() {\r
-        L2BridgeDomain l2BridgeDomain = new L2BridgeDomainBuilder().setId(L2BD_ID).setParent(L3C_ID).build();\r
-        return ImmutableList.of(l2BridgeDomain);\r
-    }\r
-\r
-    protected List<L2FloodDomain> getL2FloodDomainList(boolean external) {\r
-        L2FloodDomainBuilder l2FloodDomainBuilder = new L2FloodDomainBuilder().setId(L2FD_ID)\r
-            .setParent(new L2BridgeDomainId(L2BD_ID))\r
-            .addAugmentation(Segmentation.class, buildSegmentation().build());\r
-        if (external) {\r
-            l2FloodDomainBuilder.setId(L2_FD_ID_EXT);\r
-        }\r
-        return ImmutableList.of(l2FloodDomainBuilder.build());\r
-    }\r
-\r
-    protected List<L3Address> getL3AddressList(Ipv4Address l3IpAddress, L3ContextId l3ContextId) {\r
-        L3Address l3Address = new L3AddressBuilder().setIpAddress(new IpAddress(l3IpAddress))\r
-            .setL3Context(new L3ContextId(l3ContextId))\r
-            .build();\r
-        return ImmutableList.of(l3Address);\r
-    }\r
-\r
-    protected List<L3Address> getL3AddressList(Ipv6Address l3IpAddress) {\r
-        L3Address l3Address = new L3AddressBuilder().setIpAddress(new IpAddress(l3IpAddress)).build();\r
-        return ImmutableList.of(l3Address);\r
-    }\r
-\r
-    protected OfOverlayContextBuilder getOfOverlayContext(NodeConnectorId connector) {\r
-        return new OfOverlayContextBuilder().setNodeConnectorId(connector).setNodeId(NODE_ID);\r
-    }\r
-\r
-    protected EndpointBuilder buildEndpoint(Ipv4Address l3IpAddress, MacAddress mac, NodeConnectorId connector) {\r
-        EndpointBuilder endpointBuilder = new EndpointBuilder().setTenant(TENANT_ID)\r
-            .setL3Address(getL3AddressList(l3IpAddress, L3C_ID))\r
-            .setMacAddress(new MacAddress(mac))\r
-            .setL2Context(new L2BridgeDomainId(L2BD_ID))\r
-            .setEndpointGroup(ENDPOINT_GROUP_0)\r
-            .addAugmentation(OfOverlayContext.class, getOfOverlayContext(connector).build());\r
-        if (l3IpAddress.equals(IPV4_0)) {\r
-            endpointBuilder.setNetworkContainment(SUBNET_0);\r
-        } else if (l3IpAddress.equals(IPV4_1)) {\r
-            endpointBuilder.setNetworkContainment(SUBNET_1);\r
-        } else if (l3IpAddress.equals(IPV4_2)) {\r
-            endpointBuilder.setNetworkContainment(SUBNET_2);\r
-        }\r
-        return endpointBuilder;\r
-    }\r
-\r
-    protected EndpointBuilder buildEndpoint(Ipv6Address l3IpAddress, MacAddress mac, NodeConnectorId connector) {\r
-        return new EndpointBuilder().setTenant(TENANT_ID)\r
-            .setL3Address(getL3AddressList(l3IpAddress))\r
-            .setMacAddress(new MacAddress(mac))\r
-            .setL2Context(new L2BridgeDomainId(L2BD_ID))\r
-            .setEndpointGroup(ENDPOINT_GROUP_0)\r
-            .setNetworkContainment(NET_DOMAIN_ID)\r
-            .addAugmentation(OfOverlayContext.class, getOfOverlayContext(connector).build());\r
-    }\r
-\r
-    public List<EndpointGroup> getEndpointGroups() {\r
-        return ImmutableList.of(\r
-                new EndpointGroupBuilder().setId(ENDPOINT_GROUP_0)\r
-                    .setNetworkDomain(SUBNET_0)\r
-                    .setConsumerNamedSelector(ImmutableList.of(new ConsumerNamedSelectorBuilder()\r
-                        .setName(new SelectorName("cns1")).setContract(ImmutableList.of(CONTRACT_ID)).build()))\r
-                    .build(),\r
-                new EndpointGroupBuilder().setId(ENDPOINT_GROUP_1)\r
-                    .setNetworkDomain(SUBNET_1)\r
-                    .setProviderNamedSelector(ImmutableList.of(new ProviderNamedSelectorBuilder()\r
-                        .setName(new SelectorName("pns1")).setContract(ImmutableList.of(CONTRACT_ID)).build()))\r
-                    .build());\r
-    }\r
-\r
-    protected SubjectFeatureInstances getSubjectFeatureInstances() {\r
-        SubjectFeatureInstancesBuilder builder = new SubjectFeatureInstancesBuilder();\r
-        return builder.setClassifierInstance(ImmutableList.of(\r
-                new ClassifierInstanceBuilder().setName(new ClassifierName("tcp_dst_80"))\r
-                    .setClassifierDefinitionId(L4ClassifierDefinition.DEFINITION.getId())\r
-                    .setParameterValue(ImmutableList.of(\r
-                            new ParameterValueBuilder().setName(new ParameterName("destport"))\r
-                                .setIntValue(80L) // Endpoint\r
-\r
-                                .build(),\r
-                            new ParameterValueBuilder().setName(new ParameterName("proto")).setIntValue(6L).build()))\r
-                    .build(),\r
-                new ClassifierInstanceBuilder().setName(new ClassifierName(TCP_SRC))\r
-                    .setClassifierDefinitionId(Classifier.L4_CL.getId())\r
-                    .setParameterValue(ImmutableList.of(\r
-                            new ParameterValueBuilder().setName(new ParameterName("sourceport"))\r
-                                .setIntValue(80L)\r
-                                .build(),\r
-                            new ParameterValueBuilder().setName(new ParameterName("proto")).setIntValue(6L).build()))\r
-                    .build(),\r
-                new ClassifierInstanceBuilder().setName(new ClassifierName("ether_type"))\r
-                    .setClassifierDefinitionId(Classifier.ETHER_TYPE_CL.getId())\r
-                    .setParameterValue(ImmutableList.of(new ParameterValueBuilder()\r
-                        .setName(new ParameterName("ethertype")).setIntValue(FlowUtils.IPv4).build()))\r
-                    .build()))\r
-            .setActionInstance(ImmutableList.of(new ActionInstanceBuilder().setName(new ActionName("allow"))\r
-                .setActionDefinitionId(new AllowAction().getId())\r
-                .build()))\r
-            .build();\r
-    }\r
-\r
-    protected SubjectFeatureInstances getSubjectFeatureInstances(ActionInstance actionInstance) {\r
-        SubjectFeatureInstancesBuilder builder = new SubjectFeatureInstancesBuilder();\r
-        return builder.setClassifierInstance(ImmutableList.of(\r
-                new ClassifierInstanceBuilder().setName(new ClassifierName("tcp_dst_80"))\r
-                    .setClassifierDefinitionId(L4ClassifierDefinition.DEFINITION.getId())\r
-                    .setParameterValue(ImmutableList.of(\r
-                            new ParameterValueBuilder().setName(new ParameterName("destport"))\r
-                                .setIntValue(80L) // Endpoint\r
-\r
-                                .build(),\r
-                            new ParameterValueBuilder().setName(new ParameterName("proto")).setIntValue(6L).build()))\r
-                    .build(),\r
-                new ClassifierInstanceBuilder().setName(new ClassifierName(TCP_SRC))\r
-                    .setClassifierDefinitionId(Classifier.L4_CL.getId())\r
-                    .setParameterValue(ImmutableList.of(\r
-                            new ParameterValueBuilder().setName(new ParameterName("sourceport"))\r
-                                .setIntValue(80L)\r
-                                .build(),\r
-                            new ParameterValueBuilder().setName(new ParameterName("proto")).setIntValue(6L).build()))\r
-                    .build(),\r
-                new ClassifierInstanceBuilder().setName(new ClassifierName("ether_type"))\r
-                    .setClassifierDefinitionId(Classifier.ETHER_TYPE_CL.getId())\r
-                    .setParameterValue(ImmutableList.of(new ParameterValueBuilder()\r
-                        .setName(new ParameterName("ethertype")).setIntValue(FlowUtils.IPv4).build()))\r
-                    .build()))\r
-            .setActionInstance(ImmutableList.of(actionInstance))\r
-            .build();\r
-    }\r
-\r
-    protected List<Subnet> getSubnetList() {\r
-        return ImmutableList.of(\r
-                new SubnetBuilder().setId(SUBNET_0)\r
-                    .setParent(L2FD_ID)\r
-                    .setIpPrefix(new IpPrefix(new Ipv4Prefix("10.0.1.0/24")))\r
-                    .setVirtualRouterIp(new IpAddress(new Ipv4Address("10.0.1.1")))\r
-                    .build(),\r
-                new SubnetBuilder().setId(SUBNET_1)\r
-                    .setParent(L2FD_ID)\r
-                    .setIpPrefix(new IpPrefix(new Ipv4Prefix("10.0.0.0/24")))\r
-                    .setVirtualRouterIp(new IpAddress(new Ipv4Address("10.0.0.1")))\r
-                    .build(),\r
-                new SubnetBuilder().setId(SUBNET_2)\r
-                    .setParent(L2BD_ID)\r
-                    .setIpPrefix(new IpPrefix(new Ipv4Prefix("10.0.2.0/24")))\r
-                    .setVirtualRouterIp(new IpAddress(new Ipv4Address("10.0.2.1")))\r
-                    .build(),\r
-                new SubnetBuilder().setId(SUBNET_EXT)\r
-                    .setParent(L2_FD_ID_EXT)\r
-                    .setIpPrefix(new IpPrefix(new Ipv4Prefix("192.168.111.0/24")))\r
-                    .build());\r
-    }\r
-}\r
+/*
+ * 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.mapper;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import org.opendaylight.groupbasedpolicy.api.sf.L4ClassifierDefinition;
+import org.opendaylight.groupbasedpolicy.dto.IndexedTenant;
+import org.opendaylight.groupbasedpolicy.dto.PolicyInfo;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.EndpointManager;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowTable;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.AllowAction;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.ChainAction;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.Classifier;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ActionName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContextId;
+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.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.ParameterName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SelectorName;
+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.endpoint.rev140421.endpoint.fields.L3Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3AddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.l3endpoint.rev151217.NatAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.l3endpoint.rev151217.NatAddressBuilder;
+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.groupbasedpolicy.ofoverlay.rev140528.Segmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.SegmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.TenantBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.ForwardingContextBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.Policy;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.PolicyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2BridgeDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2BridgeDomainBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2FloodDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2FloodDomainBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L3Context;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L3ContextBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.Subnet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.SubnetBuilder;
+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.policy.rev140421.tenants.tenant.policy.SubjectFeatureInstances;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.SubjectFeatureInstancesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.endpoint.group.ConsumerNamedSelectorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.endpoint.group.ProviderNamedSelectorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ActionInstance;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ActionInstanceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ClassifierInstanceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class MapperUtilsTest {
+
+    protected static final MacAddress MAC_0 = new MacAddress("00:00:00:00:00:00");
+    protected static final MacAddress MAC_1 = new MacAddress("00:00:00:00:00:01");
+    protected static final MacAddress MAC_2 = new MacAddress("00:00:00:00:00:02");
+    protected static final Ipv4Address IPV4_0 = new Ipv4Address("170.0.0.1");
+    protected static final Ipv4Address IPV4_1 = new Ipv4Address("190.0.0.1");
+    protected static final Ipv4Address IPV4_2 = new Ipv4Address("210.0.0.1");
+    protected static final Ipv6Address IPV6_1 = new Ipv6Address("2000:db80:85a3:08ba:0947:8a2e:3a70:7334");
+    protected static final Ipv6Address IPV6_2 = new Ipv6Address("0947:db80:3a70:7334:85a3:8a2e:2000:08ba");
+    protected static final NodeConnectorId CONNECTOR_0 = new NodeConnectorId("0");
+    protected static final NodeConnectorId CONNECTOR_1 = new NodeConnectorId("1");
+    protected static final NodeConnectorId CONNECTOR_2 = new NodeConnectorId("2");
+    protected static final SubnetId SUBNET_0 = new SubnetId("subnet0");
+    protected static final SubnetId SUBNET_1 = new SubnetId("subnet1");
+    protected static final SubnetId SUBNET_2 = new SubnetId("subnet2");
+    protected static final SubnetId SUBNET_EXT = new SubnetId("externalSubnet");
+    protected static final String IP_PREFIX_32 = "/32";
+    protected static final String IP_PREFIX_128 = "/128";
+    protected static final TenantId TENANT_ID = new TenantId("tenantId");
+    protected static final NodeId NODE_ID = new NodeId("nodeId");
+    protected static final EndpointGroupId ENDPOINT_GROUP_0 = new EndpointGroupId("eg0");
+    protected static final EndpointGroupId ENDPOINT_GROUP_1 = new EndpointGroupId("eg1");
+    protected static final EndpointGroupId ENDPOINT_GROUP_2 = new EndpointGroupId("eg2");
+    protected static final SubnetId NET_DOMAIN_ID = new SubnetId("ndId");
+    protected static final L2BridgeDomainId L2BD_ID = new L2BridgeDomainId("l2bdId");
+    protected static final L2FloodDomainId L2FD_ID = new L2FloodDomainId("l2fdId");
+    protected static final L2FloodDomainId L2_FD_ID_EXT = new L2FloodDomainId("externalL2fdId");
+    protected static final L3ContextId L3C_ID = new L3ContextId("l3cId");
+    protected static final ContractId CONTRACT_ID = new ContractId("contractId");
+    protected static final ContextId CONTEXT_ID = new L3ContextId("ctxId");
+    // Often used strings
+    protected static final String ALLOW = "allow";
+    protected static final String CHAIN = "chain";
+    protected static final String L2 = "L2";
+    protected static final String OPENFLOW = "openflow:";
+    protected static final String DROP_ALL = "dropAll";
+    protected static final String DROP = "drop";
+    protected static final String TCP_SRC = "tcp_src_80";
+    // Mock variables
+    protected Short tableId;
+    protected OfContext ctx;
+    protected OfWriter ofWriter;
+    protected SwitchManager switchManager;
+    protected PolicyManager policyManager;
+    protected EndpointManager endpointManager;
+    protected PolicyInfo policyInfo;
+    protected FlowTable table;
+
+    protected FlowBuilder buildFlow(FlowId flowId, short tableId, Integer priority, Match match,
+            Instructions instructions) {
+        return FlowUtils.base(tableId)
+            .setId(flowId)
+            .setPriority(priority)
+            .setMatch(match)
+            .setInstructions(instructions);
+    }
+
+    protected EndpointL3Builder buildL3Endpoint(Ipv4Address natIp, Ipv4Address ip, MacAddress mac, String l2bd) {
+        Preconditions.checkNotNull(natIp);
+        Preconditions.checkNotNull(ip);
+        Preconditions.checkNotNull(mac);
+
+        NatAddress natAddress = new NatAddressBuilder().setNatAddress(new IpAddress(new Ipv4Address(natIp))).build();
+
+        EndpointL3Builder endpointL3Builder = new EndpointL3Builder().addAugmentation(NatAddress.class, natAddress)
+            .setIpAddress(new IpAddress(ip))
+            .setMacAddress(new MacAddress(mac));
+        if (l2bd != null) {
+            endpointL3Builder.setL2Context(new L2BridgeDomainId(l2bd));
+        }
+        if (ip.equals(IPV4_0)) {
+            endpointL3Builder.setNetworkContainment(SUBNET_0);
+        } else if (ip.equals(IPV4_1)) {
+            endpointL3Builder.setNetworkContainment(SUBNET_1);
+        } else if (ip.equals(IPV4_2)) {
+            endpointL3Builder.setNetworkContainment(SUBNET_2);
+        }
+        return endpointL3Builder;
+    }
+
+    protected EndpointL3Builder buildL3Endpoint(Ipv6Address natIp, Ipv6Address ip, MacAddress mac, String l2bd) {
+        Preconditions.checkNotNull(natIp);
+        Preconditions.checkNotNull(ip);
+        Preconditions.checkNotNull(mac);
+
+        NatAddress natAddress = new NatAddressBuilder().setNatAddress(new IpAddress(new Ipv6Address(natIp))).build();
+
+        EndpointL3Builder endpointL3Builder = new EndpointL3Builder().addAugmentation(NatAddress.class, natAddress)
+            .setIpAddress(new IpAddress(ip))
+            .setMacAddress(new MacAddress(mac));
+        if (l2bd != null) {
+            endpointL3Builder.setL2Context(new L2BridgeDomainId(l2bd));
+        }
+        return endpointL3Builder;
+    }
+
+    public SegmentationBuilder buildSegmentation() {
+        return new SegmentationBuilder().setSegmentationId(1);
+    }
+
+    protected TenantBuilder buildTenant() {
+        Policy policy = new PolicyBuilder().setEndpointGroup(getEndpointGroups())
+            .setSubjectFeatureInstances(getSubjectFeatureInstances())
+            .build();
+
+        return new TenantBuilder().setId(TENANT_ID)
+            .setForwardingContext(buildForwardingContext().build())
+            .setPolicy(policy);
+    }
+
+    protected TenantBuilder buildTenant(ActionInstance actionInstance) {
+        Policy policy = new PolicyBuilder().setEndpointGroup(getEndpointGroups())
+            .setSubjectFeatureInstances(getSubjectFeatureInstances(actionInstance))
+            .build();
+
+        return new TenantBuilder().setId(TENANT_ID)
+            .setForwardingContext(buildForwardingContext().build())
+            .setPolicy(policy);
+    }
+
+    protected IndexedTenant getTestIndexedTenant() {
+        return new IndexedTenant(buildTenant().build());
+    }
+
+    protected IndexedTenant getTestIndexedTenant(ActionInstance actionInstance) {
+        return new IndexedTenant(buildTenant(actionInstance).build());
+    }
+
+    protected ForwardingContextBuilder buildForwardingContext() {
+        return new ForwardingContextBuilder().setL2FloodDomain(getL2FloodDomainList(false))
+            .setL2BridgeDomain(getL2BridgeDomainList())
+            .setL3Context(getL3ContextList())
+            .setSubnet(getSubnetList());
+    }
+
+    protected List<L3Context> getL3ContextList() {
+        L3Context l3Context = new L3ContextBuilder().setId(L3C_ID).build();
+        return ImmutableList.of(l3Context);
+    }
+
+    protected List<L2BridgeDomain> getL2BridgeDomainList() {
+        L2BridgeDomain l2BridgeDomain = new L2BridgeDomainBuilder().setId(L2BD_ID).setParent(L3C_ID).build();
+        return ImmutableList.of(l2BridgeDomain);
+    }
+
+    protected List<L2FloodDomain> getL2FloodDomainList(boolean external) {
+        L2FloodDomainBuilder l2FloodDomainBuilder = new L2FloodDomainBuilder().setId(L2FD_ID)
+            .setParent(new L2BridgeDomainId(L2BD_ID))
+            .addAugmentation(Segmentation.class, buildSegmentation().build());
+        if (external) {
+            l2FloodDomainBuilder.setId(L2_FD_ID_EXT);
+        }
+        return ImmutableList.of(l2FloodDomainBuilder.build());
+    }
+
+    protected List<L3Address> getL3AddressList(Ipv4Address l3IpAddress, L3ContextId l3ContextId) {
+        L3Address l3Address = new L3AddressBuilder().setIpAddress(new IpAddress(l3IpAddress))
+            .setL3Context(new L3ContextId(l3ContextId))
+            .build();
+        return ImmutableList.of(l3Address);
+    }
+
+    protected List<L3Address> getL3AddressList(Ipv6Address l3IpAddress) {
+        L3Address l3Address = new L3AddressBuilder().setIpAddress(new IpAddress(l3IpAddress)).build();
+        return ImmutableList.of(l3Address);
+    }
+
+    protected OfOverlayContextBuilder getOfOverlayContext(NodeConnectorId connector) {
+        return new OfOverlayContextBuilder().setNodeConnectorId(connector).setNodeId(NODE_ID);
+    }
+
+    protected EndpointBuilder buildEndpoint(Ipv4Address l3IpAddress, MacAddress mac, NodeConnectorId connector) {
+        EndpointBuilder endpointBuilder = new EndpointBuilder().setTenant(TENANT_ID)
+            .setL3Address(getL3AddressList(l3IpAddress, L3C_ID))
+            .setMacAddress(new MacAddress(mac))
+            .setL2Context(new L2BridgeDomainId(L2BD_ID))
+            .setEndpointGroup(ENDPOINT_GROUP_0)
+            .addAugmentation(OfOverlayContext.class, getOfOverlayContext(connector).build());
+        if (l3IpAddress.equals(IPV4_0)) {
+            endpointBuilder.setNetworkContainment(SUBNET_0);
+        } else if (l3IpAddress.equals(IPV4_1)) {
+            endpointBuilder.setNetworkContainment(SUBNET_1);
+        } else if (l3IpAddress.equals(IPV4_2)) {
+            endpointBuilder.setNetworkContainment(SUBNET_2);
+        }
+        return endpointBuilder;
+    }
+
+    protected EndpointBuilder buildEndpoint(Ipv6Address l3IpAddress, MacAddress mac, NodeConnectorId connector) {
+        return new EndpointBuilder().setTenant(TENANT_ID)
+            .setL3Address(getL3AddressList(l3IpAddress))
+            .setMacAddress(new MacAddress(mac))
+            .setL2Context(new L2BridgeDomainId(L2BD_ID))
+            .setEndpointGroup(ENDPOINT_GROUP_0)
+            .setNetworkContainment(NET_DOMAIN_ID)
+            .addAugmentation(OfOverlayContext.class, getOfOverlayContext(connector).build());
+    }
+
+    public List<EndpointGroup> getEndpointGroups() {
+        return ImmutableList.of(
+                new EndpointGroupBuilder().setId(ENDPOINT_GROUP_0)
+                    .setNetworkDomain(SUBNET_0)
+                    .setConsumerNamedSelector(ImmutableList.of(new ConsumerNamedSelectorBuilder()
+                        .setName(new SelectorName("cns1")).setContract(ImmutableList.of(CONTRACT_ID)).build()))
+                    .build(),
+                new EndpointGroupBuilder().setId(ENDPOINT_GROUP_1)
+                    .setNetworkDomain(SUBNET_1)
+                    .setProviderNamedSelector(ImmutableList.of(new ProviderNamedSelectorBuilder()
+                        .setName(new SelectorName("pns1")).setContract(ImmutableList.of(CONTRACT_ID)).build()))
+                    .build());
+    }
+
+    protected SubjectFeatureInstances getSubjectFeatureInstances() {
+        SubjectFeatureInstancesBuilder builder = new SubjectFeatureInstancesBuilder();
+        return builder.setClassifierInstance(ImmutableList.of(
+                new ClassifierInstanceBuilder().setName(new ClassifierName("tcp_dst_80"))
+                    .setClassifierDefinitionId(L4ClassifierDefinition.DEFINITION.getId())
+                    .setParameterValue(ImmutableList.of(
+                            new ParameterValueBuilder().setName(new ParameterName("destport"))
+                                .setIntValue(80L) // Endpoint
+
+                                .build(),
+                            new ParameterValueBuilder().setName(new ParameterName("proto")).setIntValue(6L).build()))
+                    .build(),
+                new ClassifierInstanceBuilder().setName(new ClassifierName(TCP_SRC))
+                    .setClassifierDefinitionId(Classifier.L4_CL.getId())
+                    .setParameterValue(ImmutableList.of(
+                            new ParameterValueBuilder().setName(new ParameterName("sourceport"))
+                                .setIntValue(80L)
+                                .build(),
+                            new ParameterValueBuilder().setName(new ParameterName("proto")).setIntValue(6L).build()))
+                    .build(),
+                new ClassifierInstanceBuilder().setName(new ClassifierName("ether_type"))
+                    .setClassifierDefinitionId(Classifier.ETHER_TYPE_CL.getId())
+                    .setParameterValue(ImmutableList.of(new ParameterValueBuilder()
+                        .setName(new ParameterName("ethertype")).setIntValue(FlowUtils.IPv4).build()))
+                    .build()))
+            .setActionInstance(ImmutableList.of(new ActionInstanceBuilder().setName(new ActionName("allow"))
+                .setActionDefinitionId(new AllowAction().getId())
+                .build()))
+            .build();
+    }
+
+    protected SubjectFeatureInstances getSubjectFeatureInstances(ActionInstance actionInstance) {
+        SubjectFeatureInstancesBuilder builder = new SubjectFeatureInstancesBuilder();
+        return builder.setClassifierInstance(ImmutableList.of(
+                new ClassifierInstanceBuilder().setName(new ClassifierName("tcp_dst_80"))
+                    .setClassifierDefinitionId(L4ClassifierDefinition.DEFINITION.getId())
+                    .setParameterValue(ImmutableList.of(
+                            new ParameterValueBuilder().setName(new ParameterName("destport"))
+                                .setIntValue(80L) // Endpoint
+
+                                .build(),
+                            new ParameterValueBuilder().setName(new ParameterName("proto")).setIntValue(6L).build()))
+                    .build(),
+                new ClassifierInstanceBuilder().setName(new ClassifierName(TCP_SRC))
+                    .setClassifierDefinitionId(Classifier.L4_CL.getId())
+                    .setParameterValue(ImmutableList.of(
+                            new ParameterValueBuilder().setName(new ParameterName("sourceport"))
+                                .setIntValue(80L)
+                                .build(),
+                            new ParameterValueBuilder().setName(new ParameterName("proto")).setIntValue(6L).build()))
+                    .build(),
+                new ClassifierInstanceBuilder().setName(new ClassifierName("ether_type"))
+                    .setClassifierDefinitionId(Classifier.ETHER_TYPE_CL.getId())
+                    .setParameterValue(ImmutableList.of(new ParameterValueBuilder()
+                        .setName(new ParameterName("ethertype")).setIntValue(FlowUtils.IPv4).build()))
+                    .build()))
+            .setActionInstance(ImmutableList.of(actionInstance))
+            .build();
+    }
+
+    protected List<Subnet> getSubnetList() {
+        return ImmutableList.of(
+                new SubnetBuilder().setId(SUBNET_0)
+                    .setParent(L2FD_ID)
+                    .setIpPrefix(new IpPrefix(new Ipv4Prefix("10.0.1.0/24")))
+                    .setVirtualRouterIp(new IpAddress(new Ipv4Address("10.0.1.1")))
+                    .build(),
+                new SubnetBuilder().setId(SUBNET_1)
+                    .setParent(L2FD_ID)
+                    .setIpPrefix(new IpPrefix(new Ipv4Prefix("10.0.0.0/24")))
+                    .setVirtualRouterIp(new IpAddress(new Ipv4Address("10.0.0.1")))
+                    .build(),
+                new SubnetBuilder().setId(SUBNET_2)
+                    .setParent(L2BD_ID)
+                    .setIpPrefix(new IpPrefix(new Ipv4Prefix("10.0.2.0/24")))
+                    .setVirtualRouterIp(new IpAddress(new Ipv4Address("10.0.2.1")))
+                    .build(),
+                new SubnetBuilder().setId(SUBNET_EXT)
+                    .setParent(L2_FD_ID_EXT)
+                    .setIpPrefix(new IpPrefix(new Ipv4Prefix("192.168.111.0/24")))
+                    .build());
+    }
+}
index b9d33229c919ba82a2602de2d808b20cf8a95add..26ce912ed54abc91eb708bd62ccc32d0515bafee 100755 (executable)
-/*\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
-package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf;\r
-\r
-import static org.mockito.Matchers.any;\r
-import static org.mockito.Matchers.eq;\r
-import static org.mockito.Mockito.mock;\r
-import static org.mockito.Mockito.spy;\r
-import static org.mockito.Mockito.verify;\r
-import static org.mockito.Mockito.when;\r
-\r
-import java.util.Set;\r
-\r
-import com.google.common.collect.ImmutableSet;\r
-import com.google.common.util.concurrent.CheckedFuture;\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.DataObjectModification;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;\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.groupbasedpolicy.api.sf.AllowActionDefinition;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.SubjectFeatureDefinitions;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinition;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinitionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinitionKey;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.SupportedActionDefinition;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
-\r
-public class ActionDefinitionListenerTest {\r
-\r
-    private ActionDefinitionListener listener;\r
-    private DataObjectModification<ActionDefinition> rootNode;\r
-    private Set<DataTreeModification<ActionDefinition>> changes;\r
-\r
-    private DataBroker dataProvider;\r
-\r
-    private InstanceIdentifier<ActionDefinition> rootIdentifier;\r
-\r
-    @SuppressWarnings("unchecked")\r
-    @Before\r
-    public void init() {\r
-\r
-        dataProvider = mock(DataBroker.class);\r
-\r
-        listener = spy(new ActionDefinitionListener(dataProvider));\r
-\r
-        ActionDefinitionKey key = mock(ActionDefinitionKey.class);\r
-\r
-        rootNode = mock(DataObjectModification.class);\r
-        rootIdentifier = InstanceIdentifier.builder(SubjectFeatureDefinitions.class)\r
-                .child(ActionDefinition.class, key)\r
-                .build();\r
-        DataTreeIdentifier<ActionDefinition> rootPath =\r
-                new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, rootIdentifier);\r
-\r
-        DataTreeModification<ActionDefinition> change = mock(DataTreeModification.class);\r
-\r
-        when(change.getRootNode()).thenReturn(rootNode);\r
-        when(change.getRootPath()).thenReturn(rootPath);\r
-\r
-        changes = ImmutableSet.of(change);\r
-\r
-        ActionDefinition def = new ActionDefinitionBuilder().setId(AllowActionDefinition.ID).build();\r
-\r
-        when(rootNode.getDataBefore()).thenReturn(def);\r
-        when(rootNode.getDataAfter()).thenReturn(def);\r
-    }\r
-\r
-    @Test\r
-    public void testOnDataTreeChanged_Write() {\r
-        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);\r
-\r
-        WriteTransaction wt = resetTransaction();\r
-\r
-        listener.onDataTreeChanged(changes);\r
-\r
-        verify(wt).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),\r
-                any(SupportedActionDefinition.class), eq(true));\r
-    }\r
-\r
-    @Test\r
-    public void testOnDataTreeChanged_SubtreeModified() {\r
-        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);\r
-\r
-        WriteTransaction wt = resetTransaction();\r
-\r
-        listener.onDataTreeChanged(changes);\r
-\r
-        verify(wt).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),\r
-                any(SupportedActionDefinition.class), eq(true));\r
-    }\r
-\r
-    @Test\r
-    public void testOnDataTreeChanged_Delete() {\r
-        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);\r
-\r
-        WriteTransaction wt = resetTransaction();\r
-\r
-        listener.onDataTreeChanged(changes);\r
-\r
-        verify(wt).delete(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class));\r
-    }\r
-\r
-    private WriteTransaction resetTransaction() {\r
-        WriteTransaction wt = mock(WriteTransaction.class);\r
-        CheckedFuture checkedFuture = mock(CheckedFuture.class);\r
-        when(wt.submit()).thenReturn(checkedFuture);\r
-        when(dataProvider.newWriteOnlyTransaction()).thenReturn(wt);\r
-        return wt;\r
-    }\r
-\r
-}\r
+/*
+ * 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.sf;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.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.api.sf.AllowActionDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.SubjectFeatureDefinitions;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinitionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinitionKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.SupportedActionDefinition;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class ActionDefinitionListenerTest {
+
+    private ActionDefinitionListener listener;
+    private DataObjectModification<ActionDefinition> rootNode;
+    private Set<DataTreeModification<ActionDefinition>> changes;
+
+    private DataBroker dataProvider;
+
+    private InstanceIdentifier<ActionDefinition> rootIdentifier;
+
+    @SuppressWarnings("unchecked")
+    @Before
+    public void init() {
+
+        dataProvider = mock(DataBroker.class);
+
+        listener = spy(new ActionDefinitionListener(dataProvider));
+
+        ActionDefinitionKey key = mock(ActionDefinitionKey.class);
+
+        rootNode = mock(DataObjectModification.class);
+        rootIdentifier = InstanceIdentifier.builder(SubjectFeatureDefinitions.class)
+                .child(ActionDefinition.class, key)
+                .build();
+        DataTreeIdentifier<ActionDefinition> rootPath =
+                new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, rootIdentifier);
+
+        DataTreeModification<ActionDefinition> change = mock(DataTreeModification.class);
+
+        when(change.getRootNode()).thenReturn(rootNode);
+        when(change.getRootPath()).thenReturn(rootPath);
+
+        changes = ImmutableSet.of(change);
+
+        ActionDefinition def = new ActionDefinitionBuilder().setId(AllowActionDefinition.ID).build();
+
+        when(rootNode.getDataBefore()).thenReturn(def);
+        when(rootNode.getDataAfter()).thenReturn(def);
+    }
+
+    @Test
+    public void testOnDataTreeChanged_Write() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);
+
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(wt).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),
+                any(SupportedActionDefinition.class), eq(true));
+    }
+
+    @Test
+    public void testOnDataTreeChanged_SubtreeModified() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(wt).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),
+                any(SupportedActionDefinition.class), eq(true));
+    }
+
+    @Test
+    public void testOnDataTreeChanged_Delete() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);
+
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(wt).delete(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class));
+    }
+
+    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;
+    }
+
+}
index 20f75b21a86b5290a5a3ae8b94ccef20a0fed5e0..2c89ebe3be21cd90c705fba3af45f4fc002173f1 100755 (executable)
-/*\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
-package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf;\r
-\r
-import static org.mockito.Matchers.any;\r
-import static org.mockito.Matchers.eq;\r
-import static org.mockito.Mockito.mock;\r
-import static org.mockito.Mockito.spy;\r
-import static org.mockito.Mockito.verify;\r
-import static org.mockito.Mockito.when;\r
-\r
-import java.util.Set;\r
-\r
-import com.google.common.collect.ImmutableSet;\r
-import com.google.common.util.concurrent.CheckedFuture;\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.DataObjectModification;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;\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.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.SubjectFeatureDefinitions;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinition;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinitionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinitionKey;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.SupportedClassifierDefinition;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
-\r
-public class ClassifierDefinitionListenerTest {\r
-\r
-    private ClassifierDefinitionListener listener;\r
-    private DataObjectModification<ClassifierDefinition> rootNode;\r
-    private Set<DataTreeModification<ClassifierDefinition>> changes;\r
-\r
-    private DataBroker dataProvider;\r
-\r
-    private InstanceIdentifier<ClassifierDefinition> rootIdentifier;\r
-\r
-    @SuppressWarnings("unchecked")\r
-    @Before\r
-    public void init() {\r
-\r
-        dataProvider = mock(DataBroker.class);\r
-\r
-        listener = spy(new ClassifierDefinitionListener(dataProvider));\r
-\r
-        ClassifierDefinitionKey key = mock(ClassifierDefinitionKey.class);\r
-\r
-        rootNode = mock(DataObjectModification.class);\r
-        rootIdentifier = InstanceIdentifier.builder(SubjectFeatureDefinitions.class)\r
-                .child(ClassifierDefinition.class, key)\r
-                .build();\r
-        DataTreeIdentifier<ClassifierDefinition> rootPath =\r
-                new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, rootIdentifier);\r
-\r
-        DataTreeModification<ClassifierDefinition> change = mock(DataTreeModification.class);\r
-\r
-        when(change.getRootNode()).thenReturn(rootNode);\r
-        when(change.getRootPath()).thenReturn(rootPath);\r
-\r
-        changes = ImmutableSet.of(change);\r
-\r
-        ClassifierDefinition def =\r
-                new ClassifierDefinitionBuilder().setId(EtherTypeClassifierDefinition.ID).build();\r
-\r
-        when(rootNode.getDataBefore()).thenReturn(def);\r
-        when(rootNode.getDataAfter()).thenReturn(def);\r
-    }\r
-\r
-    @Test\r
-    public void testOnDataTreeChanged_Write() {\r
-        when(rootNode.getModificationType()).thenReturn(\r
-                DataObjectModification.ModificationType.WRITE);\r
-\r
-        WriteTransaction wt = resetTransaction();\r
-\r
-        listener.onDataTreeChanged(changes);\r
-\r
-        verify(wt).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),\r
-                any(SupportedClassifierDefinition.class), eq(true));\r
-    }\r
-\r
-    @Test\r
-    public void testOnDataTreeChanged_SubtreeModified() {\r
-        when(rootNode.getModificationType()).thenReturn(\r
-                DataObjectModification.ModificationType.SUBTREE_MODIFIED);\r
-\r
-        WriteTransaction wt = resetTransaction();\r
-\r
-        listener.onDataTreeChanged(changes);\r
-\r
-        verify(wt).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),\r
-                any(SupportedClassifierDefinition.class), eq(true));\r
-    }\r
-\r
-    @Test\r
-    public void testOnDataTreeChanged_Delete() {\r
-        when(rootNode.getModificationType()).thenReturn(\r
-                DataObjectModification.ModificationType.DELETE);\r
-\r
-        WriteTransaction wt = resetTransaction();\r
-\r
-        listener.onDataTreeChanged(changes);\r
-\r
-        verify(wt).delete(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class));\r
-    }\r
-\r
-    private WriteTransaction resetTransaction() {\r
-        WriteTransaction wt = mock(WriteTransaction.class);\r
-        CheckedFuture checkedFuture = mock(CheckedFuture.class);\r
-        when(wt.submit()).thenReturn(checkedFuture);\r
-        when(dataProvider.newWriteOnlyTransaction()).thenReturn(wt);\r
-        return wt;\r
-    }\r
-\r
-}\r
+/*
+ * 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.sf;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.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.api.sf.EtherTypeClassifierDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.SubjectFeatureDefinitions;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinitionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinitionKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.SupportedClassifierDefinition;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class ClassifierDefinitionListenerTest {
+
+    private ClassifierDefinitionListener listener;
+    private DataObjectModification<ClassifierDefinition> rootNode;
+    private Set<DataTreeModification<ClassifierDefinition>> changes;
+
+    private DataBroker dataProvider;
+
+    private InstanceIdentifier<ClassifierDefinition> rootIdentifier;
+
+    @SuppressWarnings("unchecked")
+    @Before
+    public void init() {
+
+        dataProvider = mock(DataBroker.class);
+
+        listener = spy(new ClassifierDefinitionListener(dataProvider));
+
+        ClassifierDefinitionKey key = mock(ClassifierDefinitionKey.class);
+
+        rootNode = mock(DataObjectModification.class);
+        rootIdentifier = InstanceIdentifier.builder(SubjectFeatureDefinitions.class)
+                .child(ClassifierDefinition.class, key)
+                .build();
+        DataTreeIdentifier<ClassifierDefinition> rootPath =
+                new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, rootIdentifier);
+
+        DataTreeModification<ClassifierDefinition> change = mock(DataTreeModification.class);
+
+        when(change.getRootNode()).thenReturn(rootNode);
+        when(change.getRootPath()).thenReturn(rootPath);
+
+        changes = ImmutableSet.of(change);
+
+        ClassifierDefinition def =
+                new ClassifierDefinitionBuilder().setId(EtherTypeClassifierDefinition.ID).build();
+
+        when(rootNode.getDataBefore()).thenReturn(def);
+        when(rootNode.getDataAfter()).thenReturn(def);
+    }
+
+    @Test
+    public void testOnDataTreeChanged_Write() {
+        when(rootNode.getModificationType()).thenReturn(
+                DataObjectModification.ModificationType.WRITE);
+
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(wt).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),
+                any(SupportedClassifierDefinition.class), eq(true));
+    }
+
+    @Test
+    public void testOnDataTreeChanged_SubtreeModified() {
+        when(rootNode.getModificationType()).thenReturn(
+                DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(wt).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),
+                any(SupportedClassifierDefinition.class), eq(true));
+    }
+
+    @Test
+    public void testOnDataTreeChanged_Delete() {
+        when(rootNode.getModificationType()).thenReturn(
+                DataObjectModification.ModificationType.DELETE);
+
+        WriteTransaction wt = resetTransaction();
+
+        listener.onDataTreeChanged(changes);
+
+        verify(wt).delete(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class));
+    }
+
+    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;
+    }
+
+}
index f819633e312da8fca3c2432d9872542d81f404b2..7e12fbf92263ea7a2b2299d4a18b12285033b70b 100755 (executable)
@@ -1,85 +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
-    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
-        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
+/*
+ * 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.Mockito.mock;
+
+import java.util.Map;
+import java.util.concurrent.ScheduledExecutorService;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.groupbasedpolicy.api.StatisticsManager;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.test.TestUtils;
+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.RuleName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubjectName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.has.classifiers.Classifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.has.classifiers.ClassifierBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.resolved.policies.ResolvedPolicy;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class OFStatisticsManagerTest {
+
+    private final EndpointGroupId consumerEpgId = new EndpointGroupId("consumerEpg1");
+    private final EndpointGroupId providerEpgId = new EndpointGroupId("providerEpg1");
+    private final ContractId contractId = new ContractId("contract1");
+    private final TenantId tenantId = new TenantId("tenant1");
+    private final ClassifierName classifierName = ClassifierName.getDefaultInstance("classifier1");
+    private final SubjectName subjectName = SubjectName.getDefaultInstance("subject1");
+    private final RuleName ruleName = new RuleName("rule1");
+
+    private InstanceIdentifier<ResolvedPolicy> rpIid;
+    private ResolvedPolicy resolvedPolicy;
+
+    private ScheduledExecutorService executor;
+    private StatisticsManager statisticsManager;
+
+    private OFStatisticsManager ofStatisticsManager;
+    private Classifier classifier;
+    private Map<InstanceIdentifier<Classifier>, Classifier> classifierByIid;
+
+    @Before
+    public void init() {
+        executor = mock(ScheduledExecutorService.class);
+        statisticsManager = mock(StatisticsManager.class);
+
+        classifier = new ClassifierBuilder()
+                .setName(classifierName)
+                .build();
+        resolvedPolicy = TestUtils.newResolvedPolicy(tenantId, contractId, subjectName, ruleName,
+                consumerEpgId, providerEpgId, classifier);
+
+        rpIid = InstanceIdentifier.create(ResolvedPolicy.class);
+
+        ofStatisticsManager = new OFStatisticsManager(executor, statisticsManager);
+        ofStatisticsManager.setDelay(20L);
+        ofStatisticsManager.setSflowCollectorUri("http://localhost:1234");
+
+        classifierByIid =
+                ResolvedPolicyClassifierListener.resolveClassifiers(resolvedPolicy, rpIid);
+    }
+
+    @Test
+    public void testConstructor() throws Exception {
+        OFStatisticsManager other = new OFStatisticsManager(executor, statisticsManager);
+        other.close();
+    }
+
+    @Test
+    public void testTTT(){
+        for (Map.Entry<InstanceIdentifier<Classifier>, Classifier> classifierEntry : classifierByIid.entrySet()) {
+            ofStatisticsManager.pullStatsForClassifier(classifierEntry.getKey(),
+                    classifierEntry.getValue());
+        }
+    }
+}
index 873b73dc89840d2032b0a17da941dfdee5f2da51..6ba1ef27311b47ffdae339970f182f387a48947e 100755 (executable)
@@ -1,66 +1,66 @@
-/*\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.anyString;\r
-import static org.mockito.Mockito.doNothing;\r
-import static org.mockito.Mockito.mock;\r
-import static org.mockito.Mockito.when;\r
-\r
-import javax.ws.rs.core.MultivaluedMap;\r
-\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
-        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(), Mockito.<MultivaluedMap<String, String>>any())).thenReturn(response);\r
-        when(connection.getExecutor()).thenReturn(executor);\r
-        doNothing().when(executor).execute(any(Runnable.class));\r
-\r
-        task = new ReadGbpFlowCacheTask("cache1", connection, statisticsManager, 100, 0.1, "sum");\r
-    }\r
-\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
-}\r
+/*
+ * 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.Matchers.anyString;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import javax.ws.rs.core.MultivaluedMap;
+
+import java.util.concurrent.ScheduledExecutorService;
+
+import com.sun.jersey.api.client.ClientResponse;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.opendaylight.groupbasedpolicy.api.StatisticsManager;
+
+public class ReadGbpFlowCacheTaskTest {
+
+    ReadGbpFlowCacheTask task;
+    private JsonRestClientResponse response;
+
+    @Before
+    public void init() {
+        StatisticsManager statisticsManager = mock(StatisticsManager.class);
+        ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
+        ClientResponse clientResponse = mock(ClientResponse.class);
+        response = mock(JsonRestClientResponse.class);
+        when(response.getJsonResponse()).thenReturn("[{\"one\":1, \"two\":2, \"three\":3}]");
+        when(response.getStatusCode()).thenReturn(200);
+        when(response.getClientResponse()).thenReturn(clientResponse);
+        SFlowRTConnection connection = mock(SFlowRTConnection.class);
+        when(connection.get(anyString(), Mockito.<MultivaluedMap<String, String>>any())).thenReturn(response);
+        when(connection.getExecutor()).thenReturn(executor);
+        doNothing().when(executor).execute(any(Runnable.class));
+
+        task = new ReadGbpFlowCacheTask("cache1", connection, statisticsManager, 100, 0.1, "sum");
+    }
+
+    @Test
+    public void testRun() {
+        task.run();
+    }
+
+    @Test
+    public void testRun_response300() {
+        when(response.getStatusCode()).thenReturn(300);
+        task.run();
+    }
+
+    @Test
+    public void testRun_response400() {
+        when(response.getStatusCode()).thenReturn(400);
+        task.run();
+    }
+
+}
index 430eb59d2a72672e2e333774ebb2351b6eac3d2a..6292d4dd926e068eaed7c8f34a7deedbc92a9f5e 100755 (executable)
-/*\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
-import static org.mockito.Mockito.spy;\r
-import static org.mockito.Mockito.verify;\r
-import static org.mockito.Mockito.when;\r
-\r
-import java.util.Set;\r
-\r
-import com.google.common.collect.ImmutableSet;\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.DataObjectModification;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;\r
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
-import org.opendaylight.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition;\r
-import org.opendaylight.groupbasedpolicy.api.sf.IpProtoClassifierDefinition;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.test.ParameterValueList;\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.ResolvedPolicies;\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.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.resolved.policies.ResolvedPolicyKey;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
-\r
-public class ResolvedPolicyClassifierListenerTest {\r
-\r
-    private ResolvedPolicyClassifierListener classifierListener;\r
-    private DataObjectModification<ResolvedPolicy> rootNode;\r
-    private Set<DataTreeModification<ResolvedPolicy>> changes;\r
-\r
-    private InstanceIdentifier<ResolvedPolicy> rootIdentifier;\r
-\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 = new ClassifierName("classifier1");\r
-    private final SubjectName subjectName = new SubjectName("subject1");\r
-    private final RuleName ruleName = new RuleName("rule1");\r
-\r
-    @SuppressWarnings("unchecked")\r
-    @Before\r
-    public void init() {\r
-        DataBroker dataProvider = mock(DataBroker.class);\r
-        OFStatisticsManager ofStatisticsManager = mock(OFStatisticsManager.class);\r
-\r
-        classifierListener = spy(new ResolvedPolicyClassifierListener(dataProvider, ofStatisticsManager));\r
-\r
-        ResolvedPolicyKey key = mock(ResolvedPolicyKey.class);\r
-        rootNode = mock(DataObjectModification.class);\r
-        rootIdentifier = InstanceIdentifier.builder(ResolvedPolicies.class).child(ResolvedPolicy.class, key).build();\r
-        DataTreeIdentifier<ResolvedPolicy> rootPath =\r
-                new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, rootIdentifier);\r
-\r
-        DataTreeModification<ResolvedPolicy> change = mock(DataTreeModification.class);\r
-\r
-        when(change.getRootNode()).thenReturn(rootNode);\r
-        when(change.getRootPath()).thenReturn(rootPath);\r
-\r
-        changes = ImmutableSet.of(change);\r
-\r
-        ParameterValueList parameterValues = new ParameterValueList();\r
-        parameterValues.addEthertype(EtherTypeClassifierDefinition.IPv4_VALUE)\r
-            .addProto(IpProtoClassifierDefinition.TCP_VALUE);\r
-\r
-        Classifier classifier = new ClassifierBuilder().setName(classifierName)\r
-            .setClassifierDefinitionId(IpProtoClassifierDefinition.ID)\r
-            .setParameterValue(parameterValues)\r
-            .build();\r
-        ResolvedPolicy rp = TestUtils.newResolvedPolicy(tenantId, contractId, subjectName, ruleName, consumerEpgId,\r
-                providerEpgId, classifier);\r
-        when(rootNode.getDataBefore()).thenReturn(rp);\r
-        when(rootNode.getDataAfter()).thenReturn(rp);\r
-    }\r
-\r
-    @Test\r
-    public void testOnWrite() {\r
-        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);\r
-\r
-        classifierListener.onDataTreeChanged(changes);\r
-\r
-        verify(classifierListener).onWrite(rootNode, rootIdentifier);\r
-    }\r
-\r
-    @Test\r
-    public void testOnDelete() {\r
-        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);\r
-\r
-        classifierListener.onDataTreeChanged(changes);\r
-\r
-        verify(classifierListener).onDelete(rootNode, rootIdentifier);\r
-    }\r
-\r
-    @Test\r
-    public void testOnSubtreeModified() {\r
-        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);\r
-\r
-        classifierListener.onDataTreeChanged(changes);\r
-\r
-        verify(classifierListener).onSubtreeModified(rootNode, rootIdentifier);\r
-    }\r
-\r
-}\r
+/*
+ * 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.Mockito.mock;
+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 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.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition;
+import org.opendaylight.groupbasedpolicy.api.sf.IpProtoClassifierDefinition;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.test.ParameterValueList;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.test.TestUtils;
+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.RuleName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubjectName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.ResolvedPolicies;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.has.classifiers.Classifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.has.classifiers.ClassifierBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.resolved.policies.ResolvedPolicy;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.resolved.policies.ResolvedPolicyKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class ResolvedPolicyClassifierListenerTest {
+
+    private ResolvedPolicyClassifierListener classifierListener;
+    private DataObjectModification<ResolvedPolicy> rootNode;
+    private Set<DataTreeModification<ResolvedPolicy>> changes;
+
+    private InstanceIdentifier<ResolvedPolicy> rootIdentifier;
+
+    private final EndpointGroupId consumerEpgId = new EndpointGroupId("consumerEpg1");
+    private final EndpointGroupId providerEpgId = new EndpointGroupId("providerEpg1");
+    private final ContractId contractId = new ContractId("contract1");
+    private final TenantId tenantId = new TenantId("tenant1");
+    private final ClassifierName classifierName = new ClassifierName("classifier1");
+    private final SubjectName subjectName = new SubjectName("subject1");
+    private final RuleName ruleName = new RuleName("rule1");
+
+    @SuppressWarnings("unchecked")
+    @Before
+    public void init() {
+        DataBroker dataProvider = mock(DataBroker.class);
+        OFStatisticsManager ofStatisticsManager = mock(OFStatisticsManager.class);
+
+        classifierListener = spy(new ResolvedPolicyClassifierListener(dataProvider, ofStatisticsManager));
+
+        ResolvedPolicyKey key = mock(ResolvedPolicyKey.class);
+        rootNode = mock(DataObjectModification.class);
+        rootIdentifier = InstanceIdentifier.builder(ResolvedPolicies.class).child(ResolvedPolicy.class, key).build();
+        DataTreeIdentifier<ResolvedPolicy> rootPath =
+                new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, rootIdentifier);
+
+        DataTreeModification<ResolvedPolicy> change = mock(DataTreeModification.class);
+
+        when(change.getRootNode()).thenReturn(rootNode);
+        when(change.getRootPath()).thenReturn(rootPath);
+
+        changes = ImmutableSet.of(change);
+
+        ParameterValueList parameterValues = new ParameterValueList();
+        parameterValues.addEthertype(EtherTypeClassifierDefinition.IPv4_VALUE)
+            .addProto(IpProtoClassifierDefinition.TCP_VALUE);
+
+        Classifier classifier = new ClassifierBuilder().setName(classifierName)
+            .setClassifierDefinitionId(IpProtoClassifierDefinition.ID)
+            .setParameterValue(parameterValues)
+            .build();
+        ResolvedPolicy rp = TestUtils.newResolvedPolicy(tenantId, contractId, subjectName, ruleName, consumerEpgId,
+                providerEpgId, classifier);
+        when(rootNode.getDataBefore()).thenReturn(rp);
+        when(rootNode.getDataAfter()).thenReturn(rp);
+    }
+
+    @Test
+    public void testOnWrite() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);
+
+        classifierListener.onDataTreeChanged(changes);
+
+        verify(classifierListener).onWrite(rootNode, rootIdentifier);
+    }
+
+    @Test
+    public void testOnDelete() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);
+
+        classifierListener.onDataTreeChanged(changes);
+
+        verify(classifierListener).onDelete(rootNode, rootIdentifier);
+    }
+
+    @Test
+    public void testOnSubtreeModified() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+
+        classifierListener.onDataTreeChanged(changes);
+
+        verify(classifierListener).onSubtreeModified(rootNode, rootIdentifier);
+    }
+
+}
index c5e1b2074ce3605f69adc707a5d513aea4881412..baf32c45fe79906ccc58bf7b21c7f70456fbf8fc 100755 (executable)
@@ -1,97 +1,97 @@
-/*\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
-import static org.mockito.Mockito.spy;\r
-import static org.mockito.Mockito.times;\r
-import static org.mockito.Mockito.verify;\r
-import static org.mockito.Mockito.when;\r
-\r
-import java.util.Set;\r
-import java.util.concurrent.ScheduledExecutorService;\r
-\r
-import com.google.common.collect.ImmutableSet;\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.DataObjectModification;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;\r
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
-import org.opendaylight.groupbasedpolicy.api.StatisticsManager;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayConfig;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.sflow.values.SflowClientSettings;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
-\r
-public class SflowClientSettingsListenerTest {\r
-\r
-    private SflowClientSettingsListener listener;\r
-    private DataObjectModification<SflowClientSettings> rootNode;\r
-    private Set<DataTreeModification<SflowClientSettings>> changes;\r
-\r
-    private InstanceIdentifier<SflowClientSettings> rootIdentifier;\r
-\r
-    @SuppressWarnings("unchecked")\r
-    @Before\r
-    public void init() {\r
-        DataBroker dataProvider = mock(DataBroker.class);\r
-\r
-        StatisticsManager ofStatisticsManager = mock(StatisticsManager.class);\r
-        ScheduledExecutorService executor = mock(ScheduledExecutorService.class);\r
-        listener = spy(new SflowClientSettingsListener(dataProvider, executor, ofStatisticsManager));\r
-\r
-        SflowClientSettings sflowClientSettings = mock(SflowClientSettings.class);\r
-\r
-        rootNode = mock(DataObjectModification.class);\r
-        rootIdentifier = InstanceIdentifier.builder(OfOverlayConfig.class).child(SflowClientSettings.class).build();\r
-        DataTreeIdentifier<SflowClientSettings> rootPath =\r
-                new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, rootIdentifier);\r
-\r
-        DataTreeModification<SflowClientSettings> change = mock(DataTreeModification.class);\r
-\r
-        when(change.getRootNode()).thenReturn(rootNode);\r
-        when(change.getRootPath()).thenReturn(rootPath);\r
-\r
-        changes = ImmutableSet.of(change);\r
-\r
-        when(rootNode.getDataBefore()).thenReturn(sflowClientSettings);\r
-        when(rootNode.getDataAfter()).thenReturn(sflowClientSettings);\r
-    }\r
-\r
-    @Test\r
-    public void testOnWrite() {\r
-        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);\r
-\r
-        listener.onDataTreeChanged(changes);\r
-\r
-        verify(listener).onWrite(rootNode, rootIdentifier);\r
-    }\r
-\r
-    @Test\r
-    public void testOnDelete() {\r
-        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);\r
-\r
-        listener.onDataTreeChanged(changes);\r
-\r
-        verify(listener).onDelete(rootNode, rootIdentifier);\r
-    }\r
-\r
-    @Test\r
-    public void testOnSubtreeModified() {\r
-        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);\r
-\r
-        // first call will initialize uninitialized dependencies;\r
-        // second call will call #close on them\r
-        listener.onDataTreeChanged(changes);\r
-        listener.onDataTreeChanged(changes);\r
-        verify(listener, times(2)).onSubtreeModified(rootNode, rootIdentifier);\r
-    }\r
-\r
-}\r
+/*
+ * 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.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Set;
+import java.util.concurrent.ScheduledExecutorService;
+
+import com.google.common.collect.ImmutableSet;
+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.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.api.StatisticsManager;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayConfig;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.sflow.values.SflowClientSettings;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class SflowClientSettingsListenerTest {
+
+    private SflowClientSettingsListener listener;
+    private DataObjectModification<SflowClientSettings> rootNode;
+    private Set<DataTreeModification<SflowClientSettings>> changes;
+
+    private InstanceIdentifier<SflowClientSettings> rootIdentifier;
+
+    @SuppressWarnings("unchecked")
+    @Before
+    public void init() {
+        DataBroker dataProvider = mock(DataBroker.class);
+
+        StatisticsManager ofStatisticsManager = mock(StatisticsManager.class);
+        ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
+        listener = spy(new SflowClientSettingsListener(dataProvider, executor, ofStatisticsManager));
+
+        SflowClientSettings sflowClientSettings = mock(SflowClientSettings.class);
+
+        rootNode = mock(DataObjectModification.class);
+        rootIdentifier = InstanceIdentifier.builder(OfOverlayConfig.class).child(SflowClientSettings.class).build();
+        DataTreeIdentifier<SflowClientSettings> rootPath =
+                new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, rootIdentifier);
+
+        DataTreeModification<SflowClientSettings> change = mock(DataTreeModification.class);
+
+        when(change.getRootNode()).thenReturn(rootNode);
+        when(change.getRootPath()).thenReturn(rootPath);
+
+        changes = ImmutableSet.of(change);
+
+        when(rootNode.getDataBefore()).thenReturn(sflowClientSettings);
+        when(rootNode.getDataAfter()).thenReturn(sflowClientSettings);
+    }
+
+    @Test
+    public void testOnWrite() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);
+
+        listener.onDataTreeChanged(changes);
+
+        verify(listener).onWrite(rootNode, rootIdentifier);
+    }
+
+    @Test
+    public void testOnDelete() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);
+
+        listener.onDataTreeChanged(changes);
+
+        verify(listener).onDelete(rootNode, rootIdentifier);
+    }
+
+    @Test
+    public void testOnSubtreeModified() {
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+
+        // first call will initialize uninitialized dependencies;
+        // second call will call #close on them
+        listener.onDataTreeChanged(changes);
+        listener.onDataTreeChanged(changes);
+        verify(listener, times(2)).onSubtreeModified(rootNode, rootIdentifier);
+    }
+
+}
index 5750241ee890d3a85c3f3c37cbd8e09ce828ee3f..3e3d292d806fa1005424657182541be07ce7a7ab 100755 (executable)
@@ -1,77 +1,77 @@
-/*\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
-package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.flowcache;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.fail;\r
-\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.HasDirection.Direction;\r
-\r
-public class FlowCacheBuilderTest {\r
-\r
-    private static final String NAME_1 = "name_1";\r
-    private static final Direction direction = Direction.Bidirectional;\r
-    private static final String VALUE_1 = "value_1";\r
-    private FlowCacheDefinition flowCacheDefinition;\r
-    private FlowCache.FlowCacheBuilder builder;\r
-\r
-    @Before\r
-    public void init() {\r
-        builder = new FlowCache.FlowCacheBuilder();\r
-        flowCacheDefinition = FlowCacheDefinition.builder().setValue(VALUE_1).build();\r
-    }\r
-\r
-    @Test\r
-    public void testConstructor() {\r
-        FlowCache.FlowCacheBuilder b = null;\r
-        try {\r
-            b = new FlowCache.FlowCacheBuilder();\r
-        } catch (Exception e) {\r
-            fail("Exception thrown: " + e.getMessage());\r
-        }\r
-        assertNotNull(b);\r
-    }\r
-\r
-    @Test\r
-    public void testSetName() {\r
-        builder.setName(NAME_1);\r
-\r
-        assertEquals(NAME_1, builder.getName());\r
-    }\r
-\r
-    @Test\r
-    public void testSetDefinition() {\r
-        builder.setDefinition(flowCacheDefinition);\r
-\r
-        assertEquals(VALUE_1, builder.getDefinition().getValue());\r
-    }\r
-\r
-    @Test\r
-    public void testSetDirection() {\r
-        builder.setDirection(direction);\r
-\r
-        assertEquals(direction, builder.getDirection());\r
-    }\r
-\r
-    @Test\r
-    public void testBuild() {\r
-        FlowCache cache = builder.setName(NAME_1)\r
-                .setDefinition(flowCacheDefinition)\r
-                .setDirection(direction)\r
-                .build();\r
-\r
-        assertNotNull(cache);\r
-        assertEquals(NAME_1, cache.getName());\r
-        assertEquals(flowCacheDefinition, cache.getDefinition());\r
-        assertEquals(direction, cache.getDirection());\r
-    }\r
-\r
-}\r
+/*
+ * 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.flowcache;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.HasDirection.Direction;
+
+public class FlowCacheBuilderTest {
+
+    private static final String NAME_1 = "name_1";
+    private static final Direction direction = Direction.Bidirectional;
+    private static final String VALUE_1 = "value_1";
+    private FlowCacheDefinition flowCacheDefinition;
+    private FlowCache.FlowCacheBuilder builder;
+
+    @Before
+    public void init() {
+        builder = new FlowCache.FlowCacheBuilder();
+        flowCacheDefinition = FlowCacheDefinition.builder().setValue(VALUE_1).build();
+    }
+
+    @Test
+    public void testConstructor() {
+        FlowCache.FlowCacheBuilder b = null;
+        try {
+            b = new FlowCache.FlowCacheBuilder();
+        } catch (Exception e) {
+            fail("Exception thrown: " + e.getMessage());
+        }
+        assertNotNull(b);
+    }
+
+    @Test
+    public void testSetName() {
+        builder.setName(NAME_1);
+
+        assertEquals(NAME_1, builder.getName());
+    }
+
+    @Test
+    public void testSetDefinition() {
+        builder.setDefinition(flowCacheDefinition);
+
+        assertEquals(VALUE_1, builder.getDefinition().getValue());
+    }
+
+    @Test
+    public void testSetDirection() {
+        builder.setDirection(direction);
+
+        assertEquals(direction, builder.getDirection());
+    }
+
+    @Test
+    public void testBuild() {
+        FlowCache cache = builder.setName(NAME_1)
+                .setDefinition(flowCacheDefinition)
+                .setDirection(direction)
+                .build();
+
+        assertNotNull(cache);
+        assertEquals(NAME_1, cache.getName());
+        assertEquals(flowCacheDefinition, cache.getDefinition());
+        assertEquals(direction, cache.getDirection());
+    }
+
+}
index 33c7adcf8ad68a882ac12546191a2371da8f11b4..1de94c4dd0bb2ebdd975cf0877759411b439d58b 100755 (executable)
@@ -1,69 +1,69 @@
-/*\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
-package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.flowcache;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.assertNull;\r
-import static org.junit.Assert.assertTrue;\r
-import static org.junit.Assert.fail;\r
-\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-\r
-public class FlowCacheDefinitionBuilderTest {\r
-\r
-    private static final String VALUE = "value-1";\r
-\r
-    private FlowCacheDefinition.FlowCacheDefinitionBuilder builder;\r
-\r
-    @Before\r
-    public void init() {\r
-        builder = new FlowCacheDefinition.FlowCacheDefinitionBuilder();\r
-    }\r
-\r
-    @Test\r
-    public void testConstructor() {\r
-        FlowCacheDefinition.FlowCacheDefinitionBuilder b = null;\r
-        try {\r
-            b = new FlowCacheDefinition.FlowCacheDefinitionBuilder();\r
-        } catch (Exception e) {\r
-            fail("Exception thrown: " + e.getMessage());\r
-        }\r
-        assertNotNull(b);\r
-        assertFalse(b.isLog());\r
-        assertNotNull(b.getFilterBuilder());\r
-        assertNotNull(b.getKeysBuilder());\r
-        assertNotNull(b.getValue());\r
-    }\r
-\r
-    @Test\r
-    public void testSetValue() {\r
-        builder.setValue(VALUE);\r
-        assertEquals(VALUE, builder.getValue());\r
-    }\r
-\r
-    @Test\r
-    public void testSetLog() {\r
-        builder.setLog(true);\r
-        assertTrue(builder.isLog());\r
-    }\r
-\r
-    @Test\r
-    public void testBuild() {\r
-        builder.setValue(VALUE).setLog(true);\r
-        FlowCacheDefinition definition = builder.build();\r
-\r
-        assertEquals(VALUE, definition.getValue());\r
-        assertTrue(definition.getLog());\r
-        assertNotNull(definition.getKeys());\r
-        assertNotNull(definition.getFilter());\r
-    }\r
-\r
-}\r
+/*
+ * 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.flowcache;
+
+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.junit.Assert.fail;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class FlowCacheDefinitionBuilderTest {
+
+    private static final String VALUE = "value-1";
+
+    private FlowCacheDefinition.FlowCacheDefinitionBuilder builder;
+
+    @Before
+    public void init() {
+        builder = new FlowCacheDefinition.FlowCacheDefinitionBuilder();
+    }
+
+    @Test
+    public void testConstructor() {
+        FlowCacheDefinition.FlowCacheDefinitionBuilder b = null;
+        try {
+            b = new FlowCacheDefinition.FlowCacheDefinitionBuilder();
+        } catch (Exception e) {
+            fail("Exception thrown: " + e.getMessage());
+        }
+        assertNotNull(b);
+        assertFalse(b.isLog());
+        assertNotNull(b.getFilterBuilder());
+        assertNotNull(b.getKeysBuilder());
+        assertNotNull(b.getValue());
+    }
+
+    @Test
+    public void testSetValue() {
+        builder.setValue(VALUE);
+        assertEquals(VALUE, builder.getValue());
+    }
+
+    @Test
+    public void testSetLog() {
+        builder.setLog(true);
+        assertTrue(builder.isLog());
+    }
+
+    @Test
+    public void testBuild() {
+        builder.setValue(VALUE).setLog(true);
+        FlowCacheDefinition definition = builder.build();
+
+        assertEquals(VALUE, definition.getValue());
+        assertTrue(definition.getLog());
+        assertNotNull(definition.getKeys());
+        assertNotNull(definition.getFilter());
+    }
+
+}
index 37021c7b6b20fcfda326406a899fa7fdd092e2f3..fd4cf8d58df5702b443c75862c2dbbd4c5a2f1af 100755 (executable)
@@ -1,28 +1,28 @@
-/*\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
-package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.flowcache;\r
-\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.fail;\r
-\r
-import org.junit.Test;\r
-\r
-public class FlowCacheDefinitionTest {\r
-\r
-    @Test\r
-    public void testBuilder() {\r
-        FlowCacheDefinition.FlowCacheDefinitionBuilder builder = null;\r
-        try {\r
-            builder = FlowCacheDefinition.builder();\r
-        } catch (Exception e) {\r
-            fail("Exception thrown: " + e.getMessage());\r
-        }\r
-        assertNotNull(builder);\r
-    }\r
-\r
-}\r
+/*
+ * 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.flowcache;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+
+public class FlowCacheDefinitionTest {
+
+    @Test
+    public void testBuilder() {
+        FlowCacheDefinition.FlowCacheDefinitionBuilder builder = null;
+        try {
+            builder = FlowCacheDefinition.builder();
+        } catch (Exception e) {
+            fail("Exception thrown: " + e.getMessage());
+        }
+        assertNotNull(builder);
+    }
+
+}
index 791ea8de57680973cb675ac69cdb2c01b59b6e55..835b8b2c7abd9bd4c737969ef57b8778098d3370 100755 (executable)
-/*\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
-package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.flowcache;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.assertTrue;\r
-\r
-import java.util.Arrays;\r
-import java.util.List;\r
-\r
-import com.google.common.collect.ImmutableList;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.opendaylight.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition;\r
-import org.opendaylight.groupbasedpolicy.api.sf.IpProtoClassifierDefinition;\r
-import org.opendaylight.groupbasedpolicy.api.sf.L4ClassifierDefinition;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.ResolvedPolicyClassifierListener;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.util.FlowCacheCons;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.util.IidSflowNameUtil;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.test.ParameterValueList;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.test.TestUtils;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierDefinitionId;\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 FlowCacheFactoryTest {\r
-\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 String expectedName;\r
-\r
-    @Before\r
-    public void init() {\r
-        rpIid = InstanceIdentifier.create(ResolvedPolicy.class);\r
-        expectedName = tenantId.getValue() + IidSflowNameUtil.KEY_DELIMETER + contractId.getValue()\r
-                + IidSflowNameUtil.KEY_DELIMETER + subjectName.getValue() + IidSflowNameUtil.DELIMETER\r
-                + ruleName.getValue() + IidSflowNameUtil.DELIMETER + classifierName.getValue()\r
-                + IidSflowNameUtil.DELIMETER + FlowCacheCons.Value.BYTES.get();\r
-    }\r
-\r
-    @Test\r
-    public void testCreateFlowCache_EtherTypeClassifier_IPv4() {\r
-        ParameterValueList parameterValues = new ParameterValueList();\r
-        parameterValues.addEthertype(EtherTypeClassifierDefinition.IPv4_VALUE);\r
-\r
-        Classifier classifier = newEtherTypeClassifier(parameterValues);\r
-        ResolvedPolicy rp = TestUtils.newResolvedPolicy(tenantId, contractId, subjectName, ruleName, consumerEpgId,\r
-                providerEpgId, classifier);\r
-\r
-        FlowCache flowCache = callCreateFlowCache(rp, classifier);\r
-\r
-        assertNotNull(flowCache);\r
-\r
-        List<String> keys = Arrays.asList(flowCache.getKeyNames());\r
-        List<String> expectedKeys = ImmutableList.of(FlowCacheCons.Key.ETH_PROTOCOL.get(),\r
-                FlowCacheCons.Key.IP_SOURCE.get(), FlowCacheCons.Key.IP_DESTINATION.get());\r
-\r
-        assertEquals(expectedName, flowCache.getName());\r
-        assertEquals(expectedKeys.size(), keys.size());\r
-        assertTrue(keys.containsAll(expectedKeys));\r
-    }\r
-\r
-    @Test\r
-    public void testCreateFlowCache_IpProtoClassifier_TCP_IPv4() {\r
-\r
-        ParameterValueList parameterValues = new ParameterValueList();\r
-        parameterValues.addEthertype(EtherTypeClassifierDefinition.IPv4_VALUE)\r
-            .addProto(IpProtoClassifierDefinition.TCP_VALUE);\r
-\r
-        Classifier classifier = newIpProtoClassifier(parameterValues);\r
-        ResolvedPolicy rp = TestUtils.newResolvedPolicy(tenantId, contractId, subjectName, ruleName, consumerEpgId,\r
-                providerEpgId, classifier);\r
-\r
-        FlowCache flowCache = callCreateFlowCache(rp, classifier);\r
-\r
-        assertNotNull(flowCache);\r
-\r
-        List<String> keys = Arrays.asList(flowCache.getKeyNames());\r
-        List<String> expectedKeys =\r
-                ImmutableList.of(FlowCacheCons.Key.ETH_PROTOCOL.get(), FlowCacheCons.Key.IP_PROTOCOL.get(),\r
-                        FlowCacheCons.Key.IP_SOURCE.get(), FlowCacheCons.Key.IP_DESTINATION.get());\r
-\r
-        assertEquals(expectedName, flowCache.getName());\r
-        assertEquals(expectedKeys.size(), keys.size());\r
-        assertTrue(keys.containsAll(expectedKeys));\r
-    }\r
-\r
-    @Test\r
-    public void testCreateFlowCache_IpProtoClassifier_UDP_noEthertype() {\r
-        ParameterValueList parameterValues = new ParameterValueList();\r
-        parameterValues.addProto(IpProtoClassifierDefinition.UDP_VALUE);\r
-\r
-        Classifier classifier = newIpProtoClassifier(parameterValues);\r
-        ResolvedPolicy rp = TestUtils.newResolvedPolicy(tenantId, contractId, subjectName, ruleName, consumerEpgId,\r
-                providerEpgId, classifier);\r
-\r
-        FlowCache flowCache = callCreateFlowCache(rp, classifier);\r
-\r
-        assertNotNull(flowCache);\r
-\r
-        List<String> keys = Arrays.asList(flowCache.getKeyNames());\r
-        List<String> expectedKeys =\r
-                ImmutableList.of(FlowCacheCons.Key.ETH_PROTOCOL.get(), FlowCacheCons.Key.IP_PROTOCOL.get(),\r
-                        FlowCacheCons.Key.IP_SOURCE.get(), FlowCacheCons.Key.IP_DESTINATION.get());\r
-\r
-        assertEquals(expectedName, flowCache.getName());\r
-        assertEquals(expectedKeys.size(), keys.size());\r
-        assertTrue(keys.containsAll(expectedKeys));\r
-    }\r
-\r
-    @Test\r
-    public void testCreateFlowCache_L4Classifier_dstPort() {\r
-        ParameterValueList parameterValues = new ParameterValueList();\r
-        parameterValues.addEthertype(EtherTypeClassifierDefinition.IPv4_VALUE)\r
-            .addProto(IpProtoClassifierDefinition.TCP_VALUE)\r
-            .addDstPort((long) 80);\r
-        Classifier classifier = newL4Classifier(parameterValues);\r
-        ResolvedPolicy rp = TestUtils.newResolvedPolicy(tenantId, contractId, subjectName, ruleName, consumerEpgId,\r
-                providerEpgId, classifier);\r
-\r
-        FlowCache flowCache = callCreateFlowCache(rp, classifier);\r
-\r
-        assertNotNull(flowCache);\r
-\r
-        List<String> keys = Arrays.asList(flowCache.getKeyNames());\r
-        List<String> expectedKeys = ImmutableList.of(FlowCacheCons.Key.ETH_PROTOCOL.get(),\r
-                FlowCacheCons.Key.IP_PROTOCOL.get(), FlowCacheCons.Key.TCP_DST_PORT.get(),\r
-                FlowCacheCons.Key.IP_SOURCE.get(), FlowCacheCons.Key.IP_DESTINATION.get());\r
-\r
-        assertEquals(expectedName, flowCache.getName());\r
-        assertEquals(expectedKeys.size(), keys.size());\r
-        assertTrue(keys.containsAll(expectedKeys));\r
-\r
-        ParameterValueList parameterValuesUDP = new ParameterValueList();\r
-        parameterValuesUDP.addEthertype(EtherTypeClassifierDefinition.IPv4_VALUE)\r
-            .addProto(IpProtoClassifierDefinition.UDP_VALUE)\r
-            .addDstPort((long) 80);\r
-        Classifier classifierUDP = newL4Classifier(parameterValuesUDP);\r
-        ResolvedPolicy rpUDP = TestUtils.newResolvedPolicy(tenantId, contractId, subjectName, ruleName, consumerEpgId,\r
-                providerEpgId, classifierUDP);\r
-\r
-        FlowCache flowCacheUDP = callCreateFlowCache(rpUDP, classifierUDP);\r
-\r
-        assertNotNull(flowCacheUDP);\r
-\r
-        List<String> keysUDP = Arrays.asList(flowCacheUDP.getKeyNames());\r
-        List<String> expectedKeysUDP = ImmutableList.of(FlowCacheCons.Key.ETH_PROTOCOL.get(),\r
-                FlowCacheCons.Key.IP_PROTOCOL.get(), FlowCacheCons.Key.UDP_DST_PORT.get(),\r
-                FlowCacheCons.Key.IP_SOURCE.get(), FlowCacheCons.Key.IP_DESTINATION.get());\r
-\r
-        assertEquals(expectedName, flowCacheUDP.getName());\r
-        assertEquals(expectedKeysUDP.size(), keysUDP.size());\r
-        assertTrue(keysUDP.containsAll(expectedKeysUDP));\r
-    }\r
-\r
-    @Test\r
-    public void testCreateFlowCache_L4Classifier_srcPort() {\r
-        ParameterValueList parameterValues = new ParameterValueList();\r
-        parameterValues.addEthertype(EtherTypeClassifierDefinition.IPv4_VALUE)\r
-            .addProto(IpProtoClassifierDefinition.TCP_VALUE)\r
-            .addSrcPort((long) 80);\r
-        Classifier classifier = newL4Classifier(parameterValues);\r
-        ResolvedPolicy rp = TestUtils.newResolvedPolicy(tenantId, contractId, subjectName, ruleName, consumerEpgId,\r
-                providerEpgId, classifier);\r
-\r
-        FlowCache flowCache = callCreateFlowCache(rp, classifier);\r
-\r
-        assertNotNull(flowCache);\r
-\r
-        List<String> keys = Arrays.asList(flowCache.getKeyNames());\r
-        List<String> expectedKeys = ImmutableList.of(FlowCacheCons.Key.ETH_PROTOCOL.get(),\r
-                FlowCacheCons.Key.IP_PROTOCOL.get(), FlowCacheCons.Key.TCP_SRC_PORT.get(),\r
-                FlowCacheCons.Key.IP_SOURCE.get(), FlowCacheCons.Key.IP_DESTINATION.get());\r
-\r
-        assertEquals(expectedName, flowCache.getName());\r
-        assertEquals(expectedKeys.size(), keys.size());\r
-        assertTrue(keys.containsAll(expectedKeys));\r
-\r
-        ParameterValueList parameterValuesUDP = new ParameterValueList();\r
-        parameterValuesUDP.addEthertype(EtherTypeClassifierDefinition.IPv4_VALUE)\r
-            .addProto(IpProtoClassifierDefinition.UDP_VALUE)\r
-            .addSrcPort((long) 80);\r
-        Classifier classifierUDP = newL4Classifier(parameterValuesUDP);\r
-        ResolvedPolicy rpUDP = TestUtils.newResolvedPolicy(tenantId, contractId, subjectName, ruleName, consumerEpgId,\r
-                providerEpgId, classifierUDP);\r
-\r
-        FlowCache flowCacheUDP = callCreateFlowCache(rpUDP, classifierUDP);\r
-\r
-        assertNotNull(flowCacheUDP);\r
-\r
-        List<String> keysUDP = Arrays.asList(flowCacheUDP.getKeyNames());\r
-        List<String> expectedKeysUDP = ImmutableList.of(FlowCacheCons.Key.ETH_PROTOCOL.get(),\r
-                FlowCacheCons.Key.IP_PROTOCOL.get(), FlowCacheCons.Key.UDP_SRC_PORT.get(),\r
-                FlowCacheCons.Key.IP_SOURCE.get(), FlowCacheCons.Key.IP_DESTINATION.get());\r
-\r
-        assertEquals(expectedName, flowCacheUDP.getName());\r
-        assertEquals(expectedKeysUDP.size(), keysUDP.size());\r
-        assertTrue(keysUDP.containsAll(expectedKeysUDP));\r
-    }\r
-\r
-    private Classifier newClassifier(ClassifierDefinitionId classifierDefinitionId,\r
-            ParameterValueList parameterValues) {\r
-        return new ClassifierBuilder().setName(classifierName)\r
-            .setClassifierDefinitionId(classifierDefinitionId)\r
-            .setParameterValue(parameterValues)\r
-            .build();\r
-    }\r
-\r
-    private Classifier newEtherTypeClassifier(ParameterValueList parameterValues) {\r
-        return newClassifier(EtherTypeClassifierDefinition.ID, parameterValues);\r
-    }\r
-\r
-    private Classifier newIpProtoClassifier(ParameterValueList parameterValues) {\r
-        return newClassifier(IpProtoClassifierDefinition.ID, parameterValues);\r
-    }\r
-\r
-    private Classifier newL4Classifier(ParameterValueList parameterValues) {\r
-        return newClassifier(L4ClassifierDefinition.ID, parameterValues);\r
-    }\r
-\r
-    private FlowCache callCreateFlowCache(ResolvedPolicy rp, Classifier classifier) {\r
-        return FlowCacheFactory.createFlowCache(\r
-                TestUtils.getClassifierIid(ResolvedPolicyClassifierListener.resolveClassifiers(rp, rpIid)), classifier,\r
-                FlowCacheCons.Value.BYTES);\r
-    }\r
-\r
-}\r
+/*
+ * 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.flowcache;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition;
+import org.opendaylight.groupbasedpolicy.api.sf.IpProtoClassifierDefinition;
+import org.opendaylight.groupbasedpolicy.api.sf.L4ClassifierDefinition;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.ResolvedPolicyClassifierListener;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.util.FlowCacheCons;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.util.IidSflowNameUtil;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.test.ParameterValueList;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.test.TestUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierDefinitionId;
+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.RuleName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubjectName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.has.classifiers.Classifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.has.classifiers.ClassifierBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.resolved.policies.ResolvedPolicy;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class FlowCacheFactoryTest {
+
+    private final EndpointGroupId consumerEpgId = new EndpointGroupId("consumerEpg1");
+    private final EndpointGroupId providerEpgId = new EndpointGroupId("providerEpg1");
+    private final ContractId contractId = new ContractId("contract1");
+    private final TenantId tenantId = new TenantId("tenant1");
+    private final ClassifierName classifierName = ClassifierName.getDefaultInstance("classifier1");
+    private final SubjectName subjectName = SubjectName.getDefaultInstance("subject1");
+    private final RuleName ruleName = new RuleName("rule1");
+
+    private InstanceIdentifier<ResolvedPolicy> rpIid;
+    private String expectedName;
+
+    @Before
+    public void init() {
+        rpIid = InstanceIdentifier.create(ResolvedPolicy.class);
+        expectedName = tenantId.getValue() + IidSflowNameUtil.KEY_DELIMETER + contractId.getValue()
+                + IidSflowNameUtil.KEY_DELIMETER + subjectName.getValue() + IidSflowNameUtil.DELIMETER
+                + ruleName.getValue() + IidSflowNameUtil.DELIMETER + classifierName.getValue()
+                + IidSflowNameUtil.DELIMETER + FlowCacheCons.Value.BYTES.get();
+    }
+
+    @Test
+    public void testCreateFlowCache_EtherTypeClassifier_IPv4() {
+        ParameterValueList parameterValues = new ParameterValueList();
+        parameterValues.addEthertype(EtherTypeClassifierDefinition.IPv4_VALUE);
+
+        Classifier classifier = newEtherTypeClassifier(parameterValues);
+        ResolvedPolicy rp = TestUtils.newResolvedPolicy(tenantId, contractId, subjectName, ruleName, consumerEpgId,
+                providerEpgId, classifier);
+
+        FlowCache flowCache = callCreateFlowCache(rp, classifier);
+
+        assertNotNull(flowCache);
+
+        List<String> keys = Arrays.asList(flowCache.getKeyNames());
+        List<String> expectedKeys = ImmutableList.of(FlowCacheCons.Key.ETH_PROTOCOL.get(),
+                FlowCacheCons.Key.IP_SOURCE.get(), FlowCacheCons.Key.IP_DESTINATION.get());
+
+        assertEquals(expectedName, flowCache.getName());
+        assertEquals(expectedKeys.size(), keys.size());
+        assertTrue(keys.containsAll(expectedKeys));
+    }
+
+    @Test
+    public void testCreateFlowCache_IpProtoClassifier_TCP_IPv4() {
+
+        ParameterValueList parameterValues = new ParameterValueList();
+        parameterValues.addEthertype(EtherTypeClassifierDefinition.IPv4_VALUE)
+            .addProto(IpProtoClassifierDefinition.TCP_VALUE);
+
+        Classifier classifier = newIpProtoClassifier(parameterValues);
+        ResolvedPolicy rp = TestUtils.newResolvedPolicy(tenantId, contractId, subjectName, ruleName, consumerEpgId,
+                providerEpgId, classifier);
+
+        FlowCache flowCache = callCreateFlowCache(rp, classifier);
+
+        assertNotNull(flowCache);
+
+        List<String> keys = Arrays.asList(flowCache.getKeyNames());
+        List<String> expectedKeys =
+                ImmutableList.of(FlowCacheCons.Key.ETH_PROTOCOL.get(), FlowCacheCons.Key.IP_PROTOCOL.get(),
+                        FlowCacheCons.Key.IP_SOURCE.get(), FlowCacheCons.Key.IP_DESTINATION.get());
+
+        assertEquals(expectedName, flowCache.getName());
+        assertEquals(expectedKeys.size(), keys.size());
+        assertTrue(keys.containsAll(expectedKeys));
+    }
+
+    @Test
+    public void testCreateFlowCache_IpProtoClassifier_UDP_noEthertype() {
+        ParameterValueList parameterValues = new ParameterValueList();
+        parameterValues.addProto(IpProtoClassifierDefinition.UDP_VALUE);
+
+        Classifier classifier = newIpProtoClassifier(parameterValues);
+        ResolvedPolicy rp = TestUtils.newResolvedPolicy(tenantId, contractId, subjectName, ruleName, consumerEpgId,
+                providerEpgId, classifier);
+
+        FlowCache flowCache = callCreateFlowCache(rp, classifier);
+
+        assertNotNull(flowCache);
+
+        List<String> keys = Arrays.asList(flowCache.getKeyNames());
+        List<String> expectedKeys =
+                ImmutableList.of(FlowCacheCons.Key.ETH_PROTOCOL.get(), FlowCacheCons.Key.IP_PROTOCOL.get(),
+                        FlowCacheCons.Key.IP_SOURCE.get(), FlowCacheCons.Key.IP_DESTINATION.get());
+
+        assertEquals(expectedName, flowCache.getName());
+        assertEquals(expectedKeys.size(), keys.size());
+        assertTrue(keys.containsAll(expectedKeys));
+    }
+
+    @Test
+    public void testCreateFlowCache_L4Classifier_dstPort() {
+        ParameterValueList parameterValues = new ParameterValueList();
+        parameterValues.addEthertype(EtherTypeClassifierDefinition.IPv4_VALUE)
+            .addProto(IpProtoClassifierDefinition.TCP_VALUE)
+            .addDstPort((long) 80);
+        Classifier classifier = newL4Classifier(parameterValues);
+        ResolvedPolicy rp = TestUtils.newResolvedPolicy(tenantId, contractId, subjectName, ruleName, consumerEpgId,
+                providerEpgId, classifier);
+
+        FlowCache flowCache = callCreateFlowCache(rp, classifier);
+
+        assertNotNull(flowCache);
+
+        List<String> keys = Arrays.asList(flowCache.getKeyNames());
+        List<String> expectedKeys = ImmutableList.of(FlowCacheCons.Key.ETH_PROTOCOL.get(),
+                FlowCacheCons.Key.IP_PROTOCOL.get(), FlowCacheCons.Key.TCP_DST_PORT.get(),
+                FlowCacheCons.Key.IP_SOURCE.get(), FlowCacheCons.Key.IP_DESTINATION.get());
+
+        assertEquals(expectedName, flowCache.getName());
+        assertEquals(expectedKeys.size(), keys.size());
+        assertTrue(keys.containsAll(expectedKeys));
+
+        ParameterValueList parameterValuesUDP = new ParameterValueList();
+        parameterValuesUDP.addEthertype(EtherTypeClassifierDefinition.IPv4_VALUE)
+            .addProto(IpProtoClassifierDefinition.UDP_VALUE)
+            .addDstPort((long) 80);
+        Classifier classifierUDP = newL4Classifier(parameterValuesUDP);
+        ResolvedPolicy rpUDP = TestUtils.newResolvedPolicy(tenantId, contractId, subjectName, ruleName, consumerEpgId,
+                providerEpgId, classifierUDP);
+
+        FlowCache flowCacheUDP = callCreateFlowCache(rpUDP, classifierUDP);
+
+        assertNotNull(flowCacheUDP);
+
+        List<String> keysUDP = Arrays.asList(flowCacheUDP.getKeyNames());
+        List<String> expectedKeysUDP = ImmutableList.of(FlowCacheCons.Key.ETH_PROTOCOL.get(),
+                FlowCacheCons.Key.IP_PROTOCOL.get(), FlowCacheCons.Key.UDP_DST_PORT.get(),
+                FlowCacheCons.Key.IP_SOURCE.get(), FlowCacheCons.Key.IP_DESTINATION.get());
+
+        assertEquals(expectedName, flowCacheUDP.getName());
+        assertEquals(expectedKeysUDP.size(), keysUDP.size());
+        assertTrue(keysUDP.containsAll(expectedKeysUDP));
+    }
+
+    @Test
+    public void testCreateFlowCache_L4Classifier_srcPort() {
+        ParameterValueList parameterValues = new ParameterValueList();
+        parameterValues.addEthertype(EtherTypeClassifierDefinition.IPv4_VALUE)
+            .addProto(IpProtoClassifierDefinition.TCP_VALUE)
+            .addSrcPort((long) 80);
+        Classifier classifier = newL4Classifier(parameterValues);
+        ResolvedPolicy rp = TestUtils.newResolvedPolicy(tenantId, contractId, subjectName, ruleName, consumerEpgId,
+                providerEpgId, classifier);
+
+        FlowCache flowCache = callCreateFlowCache(rp, classifier);
+
+        assertNotNull(flowCache);
+
+        List<String> keys = Arrays.asList(flowCache.getKeyNames());
+        List<String> expectedKeys = ImmutableList.of(FlowCacheCons.Key.ETH_PROTOCOL.get(),
+                FlowCacheCons.Key.IP_PROTOCOL.get(), FlowCacheCons.Key.TCP_SRC_PORT.get(),
+                FlowCacheCons.Key.IP_SOURCE.get(), FlowCacheCons.Key.IP_DESTINATION.get());
+
+        assertEquals(expectedName, flowCache.getName());
+        assertEquals(expectedKeys.size(), keys.size());
+        assertTrue(keys.containsAll(expectedKeys));
+
+        ParameterValueList parameterValuesUDP = new ParameterValueList();
+        parameterValuesUDP.addEthertype(EtherTypeClassifierDefinition.IPv4_VALUE)
+            .addProto(IpProtoClassifierDefinition.UDP_VALUE)
+            .addSrcPort((long) 80);
+        Classifier classifierUDP = newL4Classifier(parameterValuesUDP);
+        ResolvedPolicy rpUDP = TestUtils.newResolvedPolicy(tenantId, contractId, subjectName, ruleName, consumerEpgId,
+                providerEpgId, classifierUDP);
+
+        FlowCache flowCacheUDP = callCreateFlowCache(rpUDP, classifierUDP);
+
+        assertNotNull(flowCacheUDP);
+
+        List<String> keysUDP = Arrays.asList(flowCacheUDP.getKeyNames());
+        List<String> expectedKeysUDP = ImmutableList.of(FlowCacheCons.Key.ETH_PROTOCOL.get(),
+                FlowCacheCons.Key.IP_PROTOCOL.get(), FlowCacheCons.Key.UDP_SRC_PORT.get(),
+                FlowCacheCons.Key.IP_SOURCE.get(), FlowCacheCons.Key.IP_DESTINATION.get());
+
+        assertEquals(expectedName, flowCacheUDP.getName());
+        assertEquals(expectedKeysUDP.size(), keysUDP.size());
+        assertTrue(keysUDP.containsAll(expectedKeysUDP));
+    }
+
+    private Classifier newClassifier(ClassifierDefinitionId classifierDefinitionId,
+            ParameterValueList parameterValues) {
+        return new ClassifierBuilder().setName(classifierName)
+            .setClassifierDefinitionId(classifierDefinitionId)
+            .setParameterValue(parameterValues)
+            .build();
+    }
+
+    private Classifier newEtherTypeClassifier(ParameterValueList parameterValues) {
+        return newClassifier(EtherTypeClassifierDefinition.ID, parameterValues);
+    }
+
+    private Classifier newIpProtoClassifier(ParameterValueList parameterValues) {
+        return newClassifier(IpProtoClassifierDefinition.ID, parameterValues);
+    }
+
+    private Classifier newL4Classifier(ParameterValueList parameterValues) {
+        return newClassifier(L4ClassifierDefinition.ID, parameterValues);
+    }
+
+    private FlowCache callCreateFlowCache(ResolvedPolicy rp, Classifier classifier) {
+        return FlowCacheFactory.createFlowCache(
+                TestUtils.getClassifierIid(ResolvedPolicyClassifierListener.resolveClassifiers(rp, rpIid)), classifier,
+                FlowCacheCons.Value.BYTES);
+    }
+
+}
index 85a02a323b4a44ee1e3896eb149961c0c5e9001b..0a41de2ee61cf70b0d6f622afbe947dedca8ef0d 100755 (executable)
@@ -1,80 +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
-package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.flowcache;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.assertTrue;\r
-import static org.junit.Assert.fail;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-\r
-public class FlowCacheFilterBuilderTest {\r
-\r
-    private static final String VALUE_1 = "value_1";\r
-    private static final String VALUE_2 = "value_2";\r
-    private static final String VALUE_3 = "value_3";\r
-    private static final List<String> LIST = new ArrayList<>();\r
-\r
-    private FlowCacheFilter.FlowCacheFilterBuilder builder;\r
-\r
-    @Before\r
-    public void init() {\r
-        builder = new FlowCacheFilter.FlowCacheFilterBuilder();\r
-        LIST.add(VALUE_1);\r
-        LIST.add(VALUE_2);\r
-    }\r
-\r
-    @Test\r
-    public void testConstructor() {\r
-        FlowCacheFilter.FlowCacheFilterBuilder b = null;\r
-        try {\r
-            b = new FlowCacheFilter.FlowCacheFilterBuilder();\r
-        } catch (Exception e) {\r
-            fail("Exception thrown: " + e.getMessage());\r
-        }\r
-        assertNotNull(b);\r
-        assertNotNull(b.getValues());\r
-        assertTrue(b.getValues().isEmpty());\r
-    }\r
-\r
-    @Test\r
-    public void testSetValues() {\r
-        builder.setValues(LIST);\r
-\r
-        assertFalse(builder.getValues().isEmpty());\r
-        assertEquals(LIST.size(), builder.getValues().size());\r
-        assertEquals(LIST.get(0), builder.getValues().get(0));\r
-    }\r
-\r
-    @Test\r
-    public void testAddValue() {\r
-        builder.setValues(LIST);\r
-        int expectedSize = LIST.size() + 1;\r
-\r
-        builder.addValue(VALUE_3);\r
-\r
-        assertEquals(expectedSize, builder.getValues().size());\r
-    }\r
-\r
-    @Test\r
-    public void testBuild() {\r
-        builder.setValues(LIST);\r
-\r
-        FlowCacheFilter filter = builder.build();\r
-\r
-        assertTrue(filter.getValue().contains(VALUE_1));\r
-        assertTrue(filter.getValue().contains(VALUE_2));\r
-    }\r
-\r
-}\r
+/*
+ * 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.flowcache;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class FlowCacheFilterBuilderTest {
+
+    private static final String VALUE_1 = "value_1";
+    private static final String VALUE_2 = "value_2";
+    private static final String VALUE_3 = "value_3";
+    private static final List<String> LIST = new ArrayList<>();
+
+    private FlowCacheFilter.FlowCacheFilterBuilder builder;
+
+    @Before
+    public void init() {
+        builder = new FlowCacheFilter.FlowCacheFilterBuilder();
+        LIST.add(VALUE_1);
+        LIST.add(VALUE_2);
+    }
+
+    @Test
+    public void testConstructor() {
+        FlowCacheFilter.FlowCacheFilterBuilder b = null;
+        try {
+            b = new FlowCacheFilter.FlowCacheFilterBuilder();
+        } catch (Exception e) {
+            fail("Exception thrown: " + e.getMessage());
+        }
+        assertNotNull(b);
+        assertNotNull(b.getValues());
+        assertTrue(b.getValues().isEmpty());
+    }
+
+    @Test
+    public void testSetValues() {
+        builder.setValues(LIST);
+
+        assertFalse(builder.getValues().isEmpty());
+        assertEquals(LIST.size(), builder.getValues().size());
+        assertEquals(LIST.get(0), builder.getValues().get(0));
+    }
+
+    @Test
+    public void testAddValue() {
+        builder.setValues(LIST);
+        int expectedSize = LIST.size() + 1;
+
+        builder.addValue(VALUE_3);
+
+        assertEquals(expectedSize, builder.getValues().size());
+    }
+
+    @Test
+    public void testBuild() {
+        builder.setValues(LIST);
+
+        FlowCacheFilter filter = builder.build();
+
+        assertTrue(filter.getValue().contains(VALUE_1));
+        assertTrue(filter.getValue().contains(VALUE_2));
+    }
+
+}
index 059f55006ef4e76f80c258bd5bb252be7344059b..5b37f5615ebc0a60697ebf7d8fd7988182cb2755 100755 (executable)
@@ -1,28 +1,28 @@
-/*\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
-package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.flowcache;\r
-\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.fail;\r
-\r
-import org.junit.Test;\r
-\r
-public class FlowCacheFilterTest {\r
-\r
-    @Test\r
-    public void testBuilder() {\r
-        FlowCacheFilter.FlowCacheFilterBuilder builder = null;\r
-        try {\r
-            builder = FlowCacheFilter.builder();\r
-        } catch (Exception e) {\r
-            fail("Exception thrown: " + e.getMessage());\r
-        }\r
-        assertNotNull(builder);\r
-    }\r
-\r
-}\r
+/*
+ * 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.flowcache;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+
+public class FlowCacheFilterTest {
+
+    @Test
+    public void testBuilder() {
+        FlowCacheFilter.FlowCacheFilterBuilder builder = null;
+        try {
+            builder = FlowCacheFilter.builder();
+        } catch (Exception e) {
+            fail("Exception thrown: " + e.getMessage());
+        }
+        assertNotNull(builder);
+    }
+
+}
index 6227e095229c479be72cfab4ae3cae090a7596fd..7c66567e8cfa13ab654315431fe884a19c637e19 100755 (executable)
@@ -1,80 +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
-package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.flowcache;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.assertTrue;\r
-import static org.junit.Assert.fail;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-\r
-public class FlowCacheKeysBuilderTest {\r
-\r
-    private static final String VALUE_1 = "value_1";\r
-    private static final String VALUE_2 = "value_2";\r
-    private static final String VALUE_3 = "value_3";\r
-    private static final List<String> LIST = new ArrayList<>();\r
-\r
-    private FlowCacheKeys.FlowCacheKeysBuilder builder;\r
-\r
-    @Before\r
-    public void init() {\r
-        builder = new FlowCacheKeys.FlowCacheKeysBuilder();\r
-        LIST.add(VALUE_1);\r
-        LIST.add(VALUE_2);\r
-    }\r
-\r
-    @Test\r
-    public void testConstructor() {\r
-        FlowCacheKeys.FlowCacheKeysBuilder b = null;\r
-        try {\r
-            b = new FlowCacheKeys.FlowCacheKeysBuilder();\r
-        } catch (Exception e) {\r
-            fail("Exception thrown: " + e.getMessage());\r
-        }\r
-        assertNotNull(b);\r
-        assertNotNull(b.getValues());\r
-        assertTrue(b.getValues().isEmpty());\r
-    }\r
-\r
-    @Test\r
-    public void testSetValues() {\r
-        builder.setValues(LIST);\r
-\r
-        assertFalse(builder.getValues().isEmpty());\r
-        assertEquals(LIST.size(), builder.getValues().size());\r
-        assertEquals(LIST.get(0), builder.getValues().get(0));\r
-    }\r
-\r
-    @Test\r
-    public void testAddValue() {\r
-        builder.setValues(LIST);\r
-        int expectedSize = LIST.size() + 1;\r
-\r
-        builder.addValue(VALUE_3);\r
-\r
-        assertEquals(expectedSize, builder.getValues().size());\r
-    }\r
-\r
-    @Test\r
-    public void testBuild() {\r
-        builder.setValues(LIST);\r
-\r
-        FlowCacheKeys keys = builder.build();\r
-\r
-        assertTrue(keys.getValue().contains(VALUE_1));\r
-        assertTrue(keys.getValue().contains(VALUE_2));\r
-    }\r
-\r
-}\r
+/*
+ * 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.flowcache;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class FlowCacheKeysBuilderTest {
+
+    private static final String VALUE_1 = "value_1";
+    private static final String VALUE_2 = "value_2";
+    private static final String VALUE_3 = "value_3";
+    private static final List<String> LIST = new ArrayList<>();
+
+    private FlowCacheKeys.FlowCacheKeysBuilder builder;
+
+    @Before
+    public void init() {
+        builder = new FlowCacheKeys.FlowCacheKeysBuilder();
+        LIST.add(VALUE_1);
+        LIST.add(VALUE_2);
+    }
+
+    @Test
+    public void testConstructor() {
+        FlowCacheKeys.FlowCacheKeysBuilder b = null;
+        try {
+            b = new FlowCacheKeys.FlowCacheKeysBuilder();
+        } catch (Exception e) {
+            fail("Exception thrown: " + e.getMessage());
+        }
+        assertNotNull(b);
+        assertNotNull(b.getValues());
+        assertTrue(b.getValues().isEmpty());
+    }
+
+    @Test
+    public void testSetValues() {
+        builder.setValues(LIST);
+
+        assertFalse(builder.getValues().isEmpty());
+        assertEquals(LIST.size(), builder.getValues().size());
+        assertEquals(LIST.get(0), builder.getValues().get(0));
+    }
+
+    @Test
+    public void testAddValue() {
+        builder.setValues(LIST);
+        int expectedSize = LIST.size() + 1;
+
+        builder.addValue(VALUE_3);
+
+        assertEquals(expectedSize, builder.getValues().size());
+    }
+
+    @Test
+    public void testBuild() {
+        builder.setValues(LIST);
+
+        FlowCacheKeys keys = builder.build();
+
+        assertTrue(keys.getValue().contains(VALUE_1));
+        assertTrue(keys.getValue().contains(VALUE_2));
+    }
+
+}
index 31e40fc34bb6539eaa4dc79547e541e3cb648e7e..dd06f5e37e21143c6401a5a6c34b93d5b4fb0961 100755 (executable)
@@ -1,28 +1,28 @@
-/*\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
-package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.flowcache;\r
-\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.fail;\r
-\r
-import org.junit.Test;\r
-\r
-public class FlowCacheKeysTest {\r
-\r
-    @Test\r
-    public void testBuilder() {\r
-        FlowCacheKeys.FlowCacheKeysBuilder builder = null;\r
-        try {\r
-            builder = FlowCacheKeys.builder();\r
-        } catch (Exception e) {\r
-            fail("Exception thrown: " + e.getMessage());\r
-        }\r
-        assertNotNull(builder);\r
-    }\r
-\r
-}\r
+/*
+ * 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.flowcache;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+
+public class FlowCacheKeysTest {
+
+    @Test
+    public void testBuilder() {
+        FlowCacheKeys.FlowCacheKeysBuilder builder = null;
+        try {
+            builder = FlowCacheKeys.builder();
+        } catch (Exception e) {
+            fail("Exception thrown: " + e.getMessage());
+        }
+        assertNotNull(builder);
+    }
+
+}
index c8f37abd3666fdcfbb61b6a83948ebe89e0f7338..6479c4de380a475a29ca30bf94f103e87a460bee 100755 (executable)
@@ -1,69 +1,69 @@
-/*\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
-package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.flowcache;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.fail;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.HasDirection;\r
-\r
-public class FlowCacheTest {\r
-\r
-    private static final String KEY_1 = "key_1";\r
-    private static final String KEY_2 = "key_2";\r
-    private static final String NAME_1 = "name_1";\r
-    private static final HasDirection.Direction direction = HasDirection.Direction.Bidirectional;\r
-    private static final String VALUE_1 = "value_1";\r
-    private static FlowCacheDefinition flowCacheDefinition;\r
-    private List<String> keysValues;\r
-    private String json;\r
-\r
-    @Before\r
-    public void init() {\r
-        keysValues = new ArrayList<>();\r
-        keysValues.add(KEY_1);\r
-        keysValues.add(KEY_2);\r
-\r
-        FlowCacheDefinition.FlowCacheDefinitionBuilder flowCacheDefinitionBuilder = FlowCacheDefinition.builder();\r
-        flowCacheDefinitionBuilder.getKeysBuilder().setValues(keysValues);\r
-        flowCacheDefinition = flowCacheDefinitionBuilder.setValue(VALUE_1).setLog(true).build();\r
-\r
-        json = "{\"keys\":\"" + KEY_1 + "," + KEY_2 + "\"," + "\"value\":\"" + VALUE_1 + "\","\r
-                + "\"filter\":\"\",\"log\":true}";\r
-    }\r
-\r
-    @Test\r
-    public void testBuilder() {\r
-        FlowCache.FlowCacheBuilder builder = null;\r
-        try {\r
-            builder = FlowCache.builder();\r
-        } catch (Exception e) {\r
-            fail("Exception thrown: " + e.getMessage());\r
-        }\r
-        assertNotNull(builder);\r
-    }\r
-\r
-    @Test\r
-    public void testConstructor_Implicitely() {\r
-        FlowCache flowCache =\r
-                FlowCache.builder().setDefinition(flowCacheDefinition).setDirection(direction).setName(NAME_1).build();\r
-\r
-        assertEquals(keysValues.size(), flowCache.getKeyNum());\r
-        assertEquals(keysValues.get(0), flowCache.getKeyNames()[0]);\r
-        assertEquals(keysValues.get(1), flowCache.getKeyNames()[1]);\r
-        assertEquals(FlowCache.API_FLOW + NAME_1 + FlowCache.SUFFIX_JSON, flowCache.getPath());\r
-        assertEquals(json, flowCache.getJsonDefinition());\r
-\r
-    }\r
-}\r
+/*
+ * 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.flowcache;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.HasDirection;
+
+public class FlowCacheTest {
+
+    private static final String KEY_1 = "key_1";
+    private static final String KEY_2 = "key_2";
+    private static final String NAME_1 = "name_1";
+    private static final HasDirection.Direction direction = HasDirection.Direction.Bidirectional;
+    private static final String VALUE_1 = "value_1";
+    private static FlowCacheDefinition flowCacheDefinition;
+    private List<String> keysValues;
+    private String json;
+
+    @Before
+    public void init() {
+        keysValues = new ArrayList<>();
+        keysValues.add(KEY_1);
+        keysValues.add(KEY_2);
+
+        FlowCacheDefinition.FlowCacheDefinitionBuilder flowCacheDefinitionBuilder = FlowCacheDefinition.builder();
+        flowCacheDefinitionBuilder.getKeysBuilder().setValues(keysValues);
+        flowCacheDefinition = flowCacheDefinitionBuilder.setValue(VALUE_1).setLog(true).build();
+
+        json = "{\"keys\":\"" + KEY_1 + "," + KEY_2 + "\"," + "\"value\":\"" + VALUE_1 + "\","
+                + "\"filter\":\"\",\"log\":true}";
+    }
+
+    @Test
+    public void testBuilder() {
+        FlowCache.FlowCacheBuilder builder = null;
+        try {
+            builder = FlowCache.builder();
+        } catch (Exception e) {
+            fail("Exception thrown: " + e.getMessage());
+        }
+        assertNotNull(builder);
+    }
+
+    @Test
+    public void testConstructor_Implicitely() {
+        FlowCache flowCache =
+                FlowCache.builder().setDefinition(flowCacheDefinition).setDirection(direction).setName(NAME_1).build();
+
+        assertEquals(keysValues.size(), flowCache.getKeyNum());
+        assertEquals(keysValues.get(0), flowCache.getKeyNames()[0]);
+        assertEquals(keysValues.get(1), flowCache.getKeyNames()[1]);
+        assertEquals(FlowCache.API_FLOW + NAME_1 + FlowCache.SUFFIX_JSON, flowCache.getPath());
+        assertEquals(json, flowCache.getJsonDefinition());
+
+    }
+}
index a493f470c08084164a5f489987de6aba9cce17b5..94627d57039775baa8063c6ab53c6e9052a7aa70 100755 (executable)
@@ -1,96 +1,96 @@
-/*\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
-package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.util;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.mockito.Mockito.mock;\r
-import static org.mockito.Mockito.when;\r
-\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.ResolvedPolicyClassifierListener;\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.ClassifierKey;\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 IidSflowNameUtilTest {\r
-\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
-    private InstanceIdentifier<ResolvedPolicy> rpIid;\r
-    private String testName;\r
-    private ResolvedPolicy resolvedPolicy;\r
-\r
-    @Before\r
-    public void init() {\r
-        Classifier classifier = mock(Classifier.class);\r
-        when(classifier.getKey()).thenReturn(new ClassifierKey(classifierName));\r
-\r
-        resolvedPolicy = TestUtils.newResolvedPolicy(tenantId, contractId, subjectName, ruleName,\r
-                consumerEpgId, providerEpgId, classifier);\r
-\r
-        rpIid = InstanceIdentifier.create(ResolvedPolicy.class);\r
-        testName =\r
-                tenantId.getValue() + IidSflowNameUtil.KEY_DELIMETER + contractId.getValue() + IidSflowNameUtil.KEY_DELIMETER + subjectName\r
-                        .getValue() + IidSflowNameUtil.DELIMETER + ruleName.getValue() + IidSflowNameUtil.DELIMETER + classifierName\r
-                        .getValue() + IidSflowNameUtil.DELIMETER + FlowCacheCons.Value.BYTES.get();\r
-    }\r
-\r
-    @Test\r
-    public void testCreateFlowCacheName() {\r
-        InstanceIdentifier<Classifier> classifierIid = TestUtils.getClassifierIid(\r
-                ResolvedPolicyClassifierListener.resolveClassifiers(resolvedPolicy, rpIid));\r
-\r
-        assertEquals(testName,\r
-                IidSflowNameUtil.createFlowCacheName(classifierIid, FlowCacheCons.Value.BYTES));\r
-    }\r
-\r
-    @Test\r
-    public void testResolveContractIdFromFlowCacheName() {\r
-        assertEquals(contractId.getValue(),\r
-                IidSflowNameUtil.resolveContractIdFromFlowCacheName(testName).getValue());\r
-    }\r
-\r
-    @Test\r
-    public void testResolveSubjectNameFromFlowCacheName() {\r
-        assertEquals(subjectName.getValue(),\r
-                IidSflowNameUtil.resolveSubjectNameFromFlowCacheName(testName).getValue());\r
-    }\r
-\r
-    @Test\r
-    public void testResolveRuleNameFromFlowCacheName() {\r
-        assertEquals(ruleName.getValue(),\r
-                IidSflowNameUtil.resolveRuleNameFromFlowCacheName(testName).getValue());\r
-    }\r
-\r
-    @Test\r
-    public void testResolveClassifierNameFromFlowCacheName() {\r
-        assertEquals(classifierName.getValue(),\r
-                IidSflowNameUtil.resolveClassifierNameFromFlowCacheName(testName).getValue());\r
-    }\r
-\r
-    @Test\r
-    public void testResolveFlowCacheValue() {\r
-        assertEquals(FlowCacheCons.Value.BYTES.get(),\r
-                IidSflowNameUtil.resolveFlowCacheValue(testName));\r
-    }\r
-\r
-}\r
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.ResolvedPolicyClassifierListener;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.test.TestUtils;
+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.RuleName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubjectName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.has.classifiers.Classifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.has.classifiers.ClassifierKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.resolved.policies.ResolvedPolicy;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class IidSflowNameUtilTest {
+
+    private final EndpointGroupId consumerEpgId = new EndpointGroupId("consumerEpg1");
+    private final EndpointGroupId providerEpgId = new EndpointGroupId("providerEpg1");
+    private final ContractId contractId = new ContractId("contract1");
+    private final TenantId tenantId = new TenantId("tenant1");
+    private final ClassifierName classifierName = ClassifierName.getDefaultInstance("classifier1");
+    private final SubjectName subjectName = SubjectName.getDefaultInstance("subject1");
+    private final RuleName ruleName = new RuleName("rule1");
+    private InstanceIdentifier<ResolvedPolicy> rpIid;
+    private String testName;
+    private ResolvedPolicy resolvedPolicy;
+
+    @Before
+    public void init() {
+        Classifier classifier = mock(Classifier.class);
+        when(classifier.getKey()).thenReturn(new ClassifierKey(classifierName));
+
+        resolvedPolicy = TestUtils.newResolvedPolicy(tenantId, contractId, subjectName, ruleName,
+                consumerEpgId, providerEpgId, classifier);
+
+        rpIid = InstanceIdentifier.create(ResolvedPolicy.class);
+        testName =
+                tenantId.getValue() + IidSflowNameUtil.KEY_DELIMETER + contractId.getValue() + IidSflowNameUtil.KEY_DELIMETER + subjectName
+                        .getValue() + IidSflowNameUtil.DELIMETER + ruleName.getValue() + IidSflowNameUtil.DELIMETER + classifierName
+                        .getValue() + IidSflowNameUtil.DELIMETER + FlowCacheCons.Value.BYTES.get();
+    }
+
+    @Test
+    public void testCreateFlowCacheName() {
+        InstanceIdentifier<Classifier> classifierIid = TestUtils.getClassifierIid(
+                ResolvedPolicyClassifierListener.resolveClassifiers(resolvedPolicy, rpIid));
+
+        assertEquals(testName,
+                IidSflowNameUtil.createFlowCacheName(classifierIid, FlowCacheCons.Value.BYTES));
+    }
+
+    @Test
+    public void testResolveContractIdFromFlowCacheName() {
+        assertEquals(contractId.getValue(),
+                IidSflowNameUtil.resolveContractIdFromFlowCacheName(testName).getValue());
+    }
+
+    @Test
+    public void testResolveSubjectNameFromFlowCacheName() {
+        assertEquals(subjectName.getValue(),
+                IidSflowNameUtil.resolveSubjectNameFromFlowCacheName(testName).getValue());
+    }
+
+    @Test
+    public void testResolveRuleNameFromFlowCacheName() {
+        assertEquals(ruleName.getValue(),
+                IidSflowNameUtil.resolveRuleNameFromFlowCacheName(testName).getValue());
+    }
+
+    @Test
+    public void testResolveClassifierNameFromFlowCacheName() {
+        assertEquals(classifierName.getValue(),
+                IidSflowNameUtil.resolveClassifierNameFromFlowCacheName(testName).getValue());
+    }
+
+    @Test
+    public void testResolveFlowCacheValue() {
+        assertEquals(FlowCacheCons.Value.BYTES.get(),
+                IidSflowNameUtil.resolveFlowCacheValue(testName));
+    }
+
+}
index ef01eb3793d8c3409e9edbfbc23fe750684e26ac..bc1904457d45b85c1f8c3db36c663df5e85c8f17 100644 (file)
@@ -1,84 +1,84 @@
-/*\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.nat;\r
-\r
-import java.util.Collections;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Set;\r
-import java.util.stream.Collectors;\r
-\r
-import javax.annotation.Nonnull;\r
-import javax.annotation.Nullable;\r
-\r
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
-import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.NatInstanceCommand;\r
-import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.NatInstanceCommand.NatInstanceCommandBuilder;\r
-import org.opendaylight.groupbasedpolicy.renderer.vpp.policy.PolicyContext;\r
-import org.opendaylight.groupbasedpolicy.renderer.vpp.util.GbpNetconfTransaction;\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.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntryBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.absolute.location.location.type.ExternalLocationCase;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.NatAddressRenderer;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.Endpoints;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;\r
-import org.slf4j.Logger;\r
-\r
-import com.google.common.base.Function;\r
-import com.google.common.collect.Sets;\r
-import com.google.common.collect.Table;\r
-\r
-public abstract class NatManager {\r
-\r
-    protected final DataBroker dataBroker;\r
-\r
-    public NatManager(DataBroker dataBroker) {\r
-        this.dataBroker = dataBroker;\r
-    }\r
-\r
-    abstract Logger getLogger();\r
-\r
-    abstract void submit(NatInstanceCommandBuilder nat, NodeId nodeId);\r
-\r
-    public abstract List<NodeId> resolveNodesForSnat();\r
-\r
-    abstract public Map<NodeId, NatInstanceCommandBuilder> staticEntries(\r
-            Table<NodeId, Long, List<MappingEntryBuilder>> staticEntries);\r
-\r
-    public abstract void dynamicEntries(PolicyContext ctx, Map<NodeId, NatInstanceCommandBuilder> nodeBuilders);\r
-\r
-    public void clearNodes(@Nonnull Endpoints before, @Nullable Endpoints after) {\r
-        Function<Endpoints, Set<NodeId>> f = x -> {\r
-            return nullToEmpty(x.getAddressEndpointWithLocation()).stream()\r
-                .filter(ep -> ep.getAugmentation(NatAddressRenderer.class) != null)\r
-                .filter(ep -> ep.getAbsoluteLocation() != null)\r
-                .map(ep -> (ExternalLocationCase) ep.getAbsoluteLocation().getLocationType())\r
-                .filter(loc -> loc.getExternalNodeMountPoint() != null)\r
-                .map(loc -> loc.getExternalNodeMountPoint().firstKeyOf(Node.class).getNodeId())\r
-                .collect(Collectors.toSet());\r
-        };\r
-        Set<NodeId> nodesToClear = (after != null) ? Sets.difference(f.apply(before), f.apply(after)) : f.apply(before);\r
-        NatInstanceCommand natCmd = new NatInstanceCommandBuilder().setOperation(General.Operations.DELETE).build();\r
-        getLogger().info("Clearing NAT from nodes {}", nodesToClear);\r
-        nodesToClear.forEach(nodeId -> GbpNetconfTransaction\r
-            .netconfSyncedDelete(VppIidFactory.getNetconfNodeIid(nodeId), natCmd, GbpNetconfTransaction.RETRY_COUNT));\r
-    }\r
-\r
-    private <T> List<T> nullToEmpty(@Nullable List<T> list) {\r
-        return list == null ? Collections.emptyList() : list;\r
-    }\r
-\r
-    public void submitNatChanges(Map<NodeId, NatInstanceCommandBuilder> nat) {\r
-        nat.keySet().forEach(nodeId -> {\r
-            submit(nat.get(nodeId), nodeId);\r
-        });\r
-    }\r
-}\r
+/*
+ * 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.nat;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.NatInstanceCommand;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.NatInstanceCommand.NatInstanceCommandBuilder;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.policy.PolicyContext;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.GbpNetconfTransaction;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.absolute.location.location.type.ExternalLocationCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.NatAddressRenderer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.Endpoints;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.slf4j.Logger;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Sets;
+import com.google.common.collect.Table;
+
+public abstract class NatManager {
+
+    protected final DataBroker dataBroker;
+
+    public NatManager(DataBroker dataBroker) {
+        this.dataBroker = dataBroker;
+    }
+
+    abstract Logger getLogger();
+
+    abstract void submit(NatInstanceCommandBuilder nat, NodeId nodeId);
+
+    public abstract List<NodeId> resolveNodesForSnat();
+
+    abstract public Map<NodeId, NatInstanceCommandBuilder> staticEntries(
+            Table<NodeId, Long, List<MappingEntryBuilder>> staticEntries);
+
+    public abstract void dynamicEntries(PolicyContext ctx, Map<NodeId, NatInstanceCommandBuilder> nodeBuilders);
+
+    public void clearNodes(@Nonnull Endpoints before, @Nullable Endpoints after) {
+        Function<Endpoints, Set<NodeId>> f = x -> {
+            return nullToEmpty(x.getAddressEndpointWithLocation()).stream()
+                .filter(ep -> ep.getAugmentation(NatAddressRenderer.class) != null)
+                .filter(ep -> ep.getAbsoluteLocation() != null)
+                .map(ep -> (ExternalLocationCase) ep.getAbsoluteLocation().getLocationType())
+                .filter(loc -> loc.getExternalNodeMountPoint() != null)
+                .map(loc -> loc.getExternalNodeMountPoint().firstKeyOf(Node.class).getNodeId())
+                .collect(Collectors.toSet());
+        };
+        Set<NodeId> nodesToClear = (after != null) ? Sets.difference(f.apply(before), f.apply(after)) : f.apply(before);
+        NatInstanceCommand natCmd = new NatInstanceCommandBuilder().setOperation(General.Operations.DELETE).build();
+        getLogger().info("Clearing NAT from nodes {}", nodesToClear);
+        nodesToClear.forEach(nodeId -> GbpNetconfTransaction
+            .netconfSyncedDelete(VppIidFactory.getNetconfNodeIid(nodeId), natCmd, GbpNetconfTransaction.RETRY_COUNT));
+    }
+
+    private <T> List<T> nullToEmpty(@Nullable List<T> list) {
+        return list == null ? Collections.emptyList() : list;
+    }
+
+    public void submitNatChanges(Map<NodeId, NatInstanceCommandBuilder> nat) {
+        nat.keySet().forEach(nodeId -> {
+            submit(nat.get(nodeId), nodeId);
+        });
+    }
+}
index 198cfb34c5dc0743d7971e4e5a5b14f52d5158d8..f820aee1f00bcd839eb5b20633f26195ce9c0936 100644 (file)
-/*\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.nat;\r
-\r
-import java.net.Inet4Address;\r
-import java.net.Inet6Address;\r
-import java.net.InetAddress;\r
-import java.net.UnknownHostException;\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.stream.Collectors;\r
-\r
-import javax.annotation.Nonnull;\r
-import javax.annotation.Nullable;\r
-\r
-import org.apache.commons.net.util.SubnetUtils;\r
-import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;\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.groupbasedpolicy.renderer.vpp.config.ConfigUtil;\r
-import org.opendaylight.groupbasedpolicy.renderer.vpp.policy.PolicyContext;\r
-import org.opendaylight.groupbasedpolicy.renderer.vpp.util.GbpNetconfTransaction;\r
-import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;\r
-import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;\r
-import org.opendaylight.groupbasedpolicy.util.NetUtils;\r
-import org.opendaylight.vbd.impl.transaction.VbdNetconfTransaction;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;\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.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntryBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.parameters.ExternalIpAddressPool;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.parameters.ExternalIpAddressPoolBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev170511.SubnetAugmentRenderer;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.RendererNodes;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.nodes.RendererNode;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.forwarding.RendererForwardingByTenant;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.VppInterfaceAugmentation;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.renderers.renderer.renderer.nodes.renderer.node.PhysicalInterface;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.renderers.renderer.renderer.nodes.renderer.node.PhysicalInterfaceKey;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816.NatInterfaceAugmentation;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816._interface.nat.attributes.Nat;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816._interface.nat.attributes.NatBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816._interface.nat.attributes.nat.InboundBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816._interface.nat.attributes.nat.OutboundBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import com.google.common.base.Function;\r
-import com.google.common.base.Optional;\r
-import com.google.common.base.Preconditions;\r
-import com.google.common.collect.ImmutableList;\r
-\r
-public class NatUtil {\r
-    private static final Logger LOG = LoggerFactory.getLogger(NatUtil.class);\r
-\r
-    @SuppressWarnings("unchecked")\r
-    static Function<InstanceIdentifier<PhysicalInterface>, NodeId> resolveNodeId = (intf) -> {\r
-        return Preconditions\r
-            .checkNotNull(checkIid(intf).firstKeyOf(RendererNode.class).getNodePath().firstKeyOf(Node.class))\r
-            .getNodeId();\r
-    };\r
-\r
-    @SuppressWarnings("unchecked")\r
-    static Function<InstanceIdentifier<PhysicalInterface>, InstanceIdentifier<Interface>> resolveInterfaceIid = (intf) -> {\r
-        checkIid(intf);\r
-        return VppIidFactory\r
-            .getInterfaceIID(new InterfaceKey(checkIid(intf).firstKeyOf(PhysicalInterface.class).getInterfaceName()));\r
-    };\r
-\r
-    static private InstanceIdentifier<PhysicalInterface> checkIid(InstanceIdentifier<PhysicalInterface> iid) {\r
-        Preconditions.checkNotNull(iid.firstKeyOf(RendererNode.class).getNodePath().firstKeyOf(Node.class));\r
-        return iid;\r
-    }\r
-\r
-    public void setInboundInterface(Interface iface, WriteTransaction wTx) {\r
-        InstanceIdentifier<Nat> natIid = buildNatIid(VppIidFactory.getInterfaceIID(iface.getKey()));\r
-        Nat nat =\r
-            new NatBuilder().setInbound(new InboundBuilder().setNat44Support(true).setPostRouting(ConfigUtil.getInstance().isL3FlatEnabled()).build())\r
-                .build();\r
-        wTx.put(LogicalDatastoreType.CONFIGURATION, natIid, nat);\r
-    }\r
-\r
-    public static void setOutboundInterface(Interface iface, InstanceIdentifier<Node> vppIid) {\r
-        InstanceIdentifier<Nat> natIid = buildNatIid(VppIidFactory.getInterfaceIID(iface.getKey()));\r
-        Nat nat =\r
-            new NatBuilder().setOutbound(new OutboundBuilder().setNat44Support(true).setPostRouting(ConfigUtil.getInstance().isL3FlatEnabled()).build())\r
-                .build();\r
-        GbpNetconfTransaction.netconfSyncedWrite(vppIid, natIid, nat, GbpNetconfTransaction.RETRY_COUNT);\r
-\r
-    }\r
-\r
-    public static void unsetOutboundInterface(Interface iface, InstanceIdentifier<Node> vppIid) {\r
-        InstanceIdentifier<Nat> natIid = buildNatIid(VppIidFactory.getInterfaceIID(iface.getKey()));\r
-        GbpNetconfTransaction.netconfSyncedDelete(vppIid, natIid, GbpNetconfTransaction.RETRY_COUNT);\r
-    }\r
-\r
-    public static InstanceIdentifier<Nat> buildNatIid(InstanceIdentifier<Interface> ifaceIid) {\r
-        return ifaceIid.builder().augmentation(NatInterfaceAugmentation.class).child(Nat.class).build();\r
-    }\r
-\r
-    public static @Nonnull List<InstanceIdentifier<PhysicalInterface>> resolvePhysicalInterface(IpPrefix extSubnetPrefix,\r
-        ReadOnlyTransaction rTx) {\r
-        Optional<RendererNodes> readFromDs =\r
-            DataStoreHelper.readFromDs(LogicalDatastoreType.OPERATIONAL, VppIidFactory.getRendererNodesIid(), rTx);\r
-        rTx.close();\r
-        if (!readFromDs.isPresent() || readFromDs.get().getRendererNode() == null) {\r
-            return Collections.emptyList();\r
-        }\r
-        RendererNodes rendererNodes = readFromDs.get();\r
-        List<RendererNode>\r
-            vppNodes =\r
-            rendererNodes.getRendererNode()\r
-                .stream()\r
-                .filter(rn -> rn.getAugmentation(VppInterfaceAugmentation.class) != null)\r
-                .filter(rn -> rn.getAugmentation(VppInterfaceAugmentation.class).getPhysicalInterface() != null)\r
-                .collect(Collectors.toList());\r
-        List<InstanceIdentifier<PhysicalInterface>> iids = new ArrayList<>();\r
-        for (RendererNode rn : vppNodes) {\r
-            java.util.Optional<PhysicalInterface>\r
-                optResolvedIface =\r
-                rn.getAugmentation(VppInterfaceAugmentation.class)\r
-                    .getPhysicalInterface()\r
-                    .stream()\r
-                    .filter(phIface -> phIface.getAddress() != null)\r
-                    .filter(phIface -> phIface.getAddress()\r
-                        .stream()\r
-                        .anyMatch(ipAddr -> NetUtils.isInRange(extSubnetPrefix, String.valueOf(ipAddr.getValue()))))\r
-                    .findFirst();\r
-            if (optResolvedIface.isPresent()) {\r
-                iids.add(VppIidFactory.getRendererNodeIid(rn)\r
-                    .builder()\r
-                    .augmentation(VppInterfaceAugmentation.class)\r
-                    .child(PhysicalInterface.class, new PhysicalInterfaceKey(optResolvedIface.get().getKey()))\r
-                    .build());\r
-            }\r
-        }\r
-        return iids;\r
-    }\r
-\r
-    public static @Nonnull List<InstanceIdentifier<PhysicalInterface>> resolvePhysicalInterface(ReadOnlyTransaction rTx) {\r
-            Optional<RendererNodes> readFromDs =\r
-                DataStoreHelper.readFromDs(LogicalDatastoreType.OPERATIONAL, VppIidFactory.getRendererNodesIid(), rTx);\r
-            rTx.close();\r
-            if (!readFromDs.isPresent() || readFromDs.get().getRendererNode() == null) {\r
-                return Collections.emptyList();\r
-            }\r
-            RendererNodes rendererNodes = readFromDs.get();\r
-            List<RendererNode>\r
-                vppNodes =\r
-                rendererNodes.getRendererNode()\r
-                    .stream()\r
-                    .filter(rn -> rn.getAugmentation(VppInterfaceAugmentation.class) != null)\r
-                    .filter(rn -> rn.getAugmentation(VppInterfaceAugmentation.class).getPhysicalInterface() != null)\r
-                    .collect(Collectors.toList());\r
-            List<InstanceIdentifier<PhysicalInterface>> iids = new ArrayList<>();\r
-            for (RendererNode rn : vppNodes) {\r
-                java.util.Optional<PhysicalInterface>\r
-                    optResolvedIface =\r
-                    rn.getAugmentation(VppInterfaceAugmentation.class)\r
-                        .getPhysicalInterface()\r
-                        .stream()\r
-                        .filter(phIface -> phIface.getAddress() != null)\r
-                        .filter(phIface -> phIface.isExternal())\r
-                        .findFirst();\r
-                if (optResolvedIface.isPresent()) {\r
-                    iids.add(VppIidFactory.getRendererNodeIid(rn)\r
-                        .builder()\r
-                        .augmentation(VppInterfaceAugmentation.class)\r
-                        .child(PhysicalInterface.class, new PhysicalInterfaceKey(optResolvedIface.get().getKey()))\r
-                        .build());\r
-                }\r
-            }\r
-            return iids;\r
-        }\r
-\r
-    public static Optional<MappingEntryBuilder> createStaticEntry(String internal, Ipv4Address external) {\r
-        IpAddress internalIp = null;\r
-        try {\r
-            InetAddress inetAddr = InetAddress.getByName(internal);\r
-            if (inetAddr instanceof Inet4Address) {\r
-                internalIp = new IpAddress(new Ipv4Address(internal));\r
-            } else if (inetAddr instanceof Inet6Address) {\r
-                internalIp = new IpAddress(new Ipv6Address(internal));\r
-            }\r
-        } catch (UnknownHostException e) {\r
-            LOG.error("Cannot resolve host IP {}. {}", internal, e.getMessage());\r
-            return Optional.absent();\r
-        }\r
-        SubnetUtils subnet = new SubnetUtils(internal + "/32");\r
-        Long index = Integer.toUnsignedLong(subnet.getInfo().asInteger(internal));\r
-        MappingEntryBuilder mappingEntryBuilder = new MappingEntryBuilder()\r
-            .setType(\r
-                    org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.MappingEntry.Type.Static)\r
-            .setIndex(index)\r
-            .setInternalSrcAddress(internalIp)\r
-            .setExternalSrcAddress(external);\r
-        return Optional.of(mappingEntryBuilder);\r
-    }\r
-\r
-    public static List<ExternalIpAddressPool> resolveDynamicNat(@Nonnull PolicyContext policyCtx,\r
-            @Nullable List<MappingEntryBuilder> sNatEntries) {\r
-        Optional<List<RendererForwardingByTenant>> forwardingByTenantLists = Optional.of(policyCtx)\r
-            .transform(x -> x.getPolicy())\r
-            .transform(x -> x.getConfiguration())\r
-            .transform(x -> x.getRendererForwarding())\r
-            .transform(x -> x.getRendererForwardingByTenant());\r
-        if (!forwardingByTenantLists.isPresent()) {\r
-            LOG.warn("No dynamic NAT resolved in cfg version {}.", policyCtx.getPolicy().getVersion());\r
-            return ImmutableList.of();\r
-        }\r
-        Map<Long, Ipv4Prefix> extCache = new HashMap<>();\r
-        forwardingByTenantLists.get()\r
-            .stream()\r
-            .map(rft -> rft.getRendererNetworkDomain())\r
-            .flatMap(Collection::stream)\r
-            .filter(domain -> domain.getAugmentation(SubnetAugmentRenderer.class) != null)\r
-            .map(domain -> domain.getAugmentation(SubnetAugmentRenderer.class).getSubnet())\r
-            .filter(subnet -> !subnet.isIsTenant() && subnet.getAllocationPool() != null)\r
-            .forEach(subnet -> {\r
-                final IpPrefix subnetIpPrefix = subnet.getIpPrefix();\r
-                subnet.getAllocationPool().forEach(pool -> {\r
-                    if (subnetIpPrefix.getIpv4Prefix() != null) {\r
-                        final String firstEntry = pool.getFirst();\r
-                        final String lastEntry = pool.getLast();\r
-                        extCache.putAll(resolveDynamicNatPrefix(subnetIpPrefix.getIpv4Prefix(), firstEntry, lastEntry,\r
-                                sNatEntries));\r
-                    }\r
-                });\r
-            });\r
-        List<ExternalIpAddressPool> extPools = extCache.entrySet()\r
-            .stream()\r
-            .map(entry -> new ExternalIpAddressPoolBuilder().setPoolId(entry.getKey())\r
-                .setExternalIpPool(entry.getValue())\r
-                .build())\r
-            .collect(Collectors.toList());\r
-        LOG.trace("Resolved dynamic NAT pools in cfg version {}: {}", policyCtx.getPolicy().getVersion(), extPools);\r
-        return extPools;\r
-    }\r
-\r
-\r
-    static Map<Long, Ipv4Prefix> resolveDynamicNatPrefix(@Nonnull final Ipv4Prefix prefix,\r
-                                                                 @Nonnull final String first,\r
-                                                                 @Nullable final String last,\r
-                                                                 @Nullable final List<MappingEntryBuilder> natEntries) {\r
-        LOG.trace("Resolving Ipv4Prefix. prefix: {}, first: {}, last: {}", prefix.getValue(), first, last);\r
-        final SubnetUtils subnet = new SubnetUtils(prefix.getValue());\r
-        final Map<Long, Ipv4Prefix> extCache = new HashMap<>();\r
-        int min = subnet.getInfo().asInteger(first);\r
-        // loop through all addresses\r
-        for (String address : subnet.getInfo().getAllAddresses()) {\r
-            int asInt = subnet.getInfo().asInteger(address);\r
-            if (asInt < min) {\r
-                continue;\r
-            }\r
-            extCache.put(Integer.toUnsignedLong(asInt), new Ipv4Prefix(address + "/32"));\r
-            if (last == null || subnet.getInfo().asInteger(address) >= subnet.getInfo().asInteger(last)) {\r
-                break;\r
-            }\r
-        }\r
-        if (natEntries != null) {\r
-            // remove every static NAT entry from extCache\r
-            for (MappingEntryBuilder natEntry : natEntries) {\r
-                final Ipv4Address externalSrcAddress = natEntry.getExternalSrcAddress();\r
-                final long id = Integer.toUnsignedLong(subnet.getInfo().asInteger(externalSrcAddress.getValue()));\r
-                if (extCache.get(id) != null) {\r
-                    extCache.remove(id);\r
-                }\r
-            }\r
-        }\r
-        return extCache;\r
-    }\r
-\r
-    public static void resolveOutboundNatInterface(InstanceIdentifier<Node> mountPointIid,\r
-        NodeId nodeId, Map<NodeId, PhysicalInterfaceKey> extInterfaces) {\r
-        if (extInterfaces.containsKey(nodeId)){\r
-            PhysicalInterfaceKey physicalInterfaceKey = extInterfaces.get(nodeId);\r
-            Optional<Interfaces> readIfaces = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,\r
-                InstanceIdentifier.create(Interfaces.class),\r
-                VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(mountPointIid).getKey().newReadOnlyTransaction());\r
-            if(readIfaces.isPresent() ) {\r
-                for (Interface nodeInterface : readIfaces.get().getInterface()) {\r
-                    if (nodeInterface.getName().equals(physicalInterfaceKey.getInterfaceName())) {\r
-                        LOG.trace("Setting outbound NAT on interface {} on node: {}", nodeInterface.getName(), mountPointIid);\r
-                        NatUtil.setOutboundInterface(nodeInterface, mountPointIid);\r
-                    }\r
-                }\r
-\r
-            }\r
-\r
-        }\r
-\r
-    }\r
-}\r
+/*
+ * 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.nat;
+
+import java.net.Inet4Address;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.apache.commons.net.util.SubnetUtils;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.config.ConfigUtil;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.policy.PolicyContext;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.GbpNetconfTransaction;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+import org.opendaylight.groupbasedpolicy.util.NetUtils;
+import org.opendaylight.vbd.impl.transaction.VbdNetconfTransaction;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.parameters.ExternalIpAddressPool;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.parameters.ExternalIpAddressPoolBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev170511.SubnetAugmentRenderer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.RendererNodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.nodes.RendererNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.forwarding.RendererForwardingByTenant;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.VppInterfaceAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.renderers.renderer.renderer.nodes.renderer.node.PhysicalInterface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.renderers.renderer.renderer.nodes.renderer.node.PhysicalInterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816.NatInterfaceAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816._interface.nat.attributes.Nat;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816._interface.nat.attributes.NatBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816._interface.nat.attributes.nat.InboundBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816._interface.nat.attributes.nat.OutboundBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+public class NatUtil {
+    private static final Logger LOG = LoggerFactory.getLogger(NatUtil.class);
+
+    @SuppressWarnings("unchecked")
+    static Function<InstanceIdentifier<PhysicalInterface>, NodeId> resolveNodeId = (intf) -> {
+        return Preconditions
+            .checkNotNull(checkIid(intf).firstKeyOf(RendererNode.class).getNodePath().firstKeyOf(Node.class))
+            .getNodeId();
+    };
+
+    @SuppressWarnings("unchecked")
+    static Function<InstanceIdentifier<PhysicalInterface>, InstanceIdentifier<Interface>> resolveInterfaceIid = (intf) -> {
+        checkIid(intf);
+        return VppIidFactory
+            .getInterfaceIID(new InterfaceKey(checkIid(intf).firstKeyOf(PhysicalInterface.class).getInterfaceName()));
+    };
+
+    static private InstanceIdentifier<PhysicalInterface> checkIid(InstanceIdentifier<PhysicalInterface> iid) {
+        Preconditions.checkNotNull(iid.firstKeyOf(RendererNode.class).getNodePath().firstKeyOf(Node.class));
+        return iid;
+    }
+
+    public void setInboundInterface(Interface iface, WriteTransaction wTx) {
+        InstanceIdentifier<Nat> natIid = buildNatIid(VppIidFactory.getInterfaceIID(iface.getKey()));
+        Nat nat =
+            new NatBuilder().setInbound(new InboundBuilder().setNat44Support(true).setPostRouting(ConfigUtil.getInstance().isL3FlatEnabled()).build())
+                .build();
+        wTx.put(LogicalDatastoreType.CONFIGURATION, natIid, nat);
+    }
+
+    public static void setOutboundInterface(Interface iface, InstanceIdentifier<Node> vppIid) {
+        InstanceIdentifier<Nat> natIid = buildNatIid(VppIidFactory.getInterfaceIID(iface.getKey()));
+        Nat nat =
+            new NatBuilder().setOutbound(new OutboundBuilder().setNat44Support(true).setPostRouting(ConfigUtil.getInstance().isL3FlatEnabled()).build())
+                .build();
+        GbpNetconfTransaction.netconfSyncedWrite(vppIid, natIid, nat, GbpNetconfTransaction.RETRY_COUNT);
+
+    }
+
+    public static void unsetOutboundInterface(Interface iface, InstanceIdentifier<Node> vppIid) {
+        InstanceIdentifier<Nat> natIid = buildNatIid(VppIidFactory.getInterfaceIID(iface.getKey()));
+        GbpNetconfTransaction.netconfSyncedDelete(vppIid, natIid, GbpNetconfTransaction.RETRY_COUNT);
+    }
+
+    public static InstanceIdentifier<Nat> buildNatIid(InstanceIdentifier<Interface> ifaceIid) {
+        return ifaceIid.builder().augmentation(NatInterfaceAugmentation.class).child(Nat.class).build();
+    }
+
+    public static @Nonnull List<InstanceIdentifier<PhysicalInterface>> resolvePhysicalInterface(IpPrefix extSubnetPrefix,
+        ReadOnlyTransaction rTx) {
+        Optional<RendererNodes> readFromDs =
+            DataStoreHelper.readFromDs(LogicalDatastoreType.OPERATIONAL, VppIidFactory.getRendererNodesIid(), rTx);
+        rTx.close();
+        if (!readFromDs.isPresent() || readFromDs.get().getRendererNode() == null) {
+            return Collections.emptyList();
+        }
+        RendererNodes rendererNodes = readFromDs.get();
+        List<RendererNode>
+            vppNodes =
+            rendererNodes.getRendererNode()
+                .stream()
+                .filter(rn -> rn.getAugmentation(VppInterfaceAugmentation.class) != null)
+                .filter(rn -> rn.getAugmentation(VppInterfaceAugmentation.class).getPhysicalInterface() != null)
+                .collect(Collectors.toList());
+        List<InstanceIdentifier<PhysicalInterface>> iids = new ArrayList<>();
+        for (RendererNode rn : vppNodes) {
+            java.util.Optional<PhysicalInterface>
+                optResolvedIface =
+                rn.getAugmentation(VppInterfaceAugmentation.class)
+                    .getPhysicalInterface()
+                    .stream()
+                    .filter(phIface -> phIface.getAddress() != null)
+                    .filter(phIface -> phIface.getAddress()
+                        .stream()
+                        .anyMatch(ipAddr -> NetUtils.isInRange(extSubnetPrefix, String.valueOf(ipAddr.getValue()))))
+                    .findFirst();
+            if (optResolvedIface.isPresent()) {
+                iids.add(VppIidFactory.getRendererNodeIid(rn)
+                    .builder()
+                    .augmentation(VppInterfaceAugmentation.class)
+                    .child(PhysicalInterface.class, new PhysicalInterfaceKey(optResolvedIface.get().getKey()))
+                    .build());
+            }
+        }
+        return iids;
+    }
+
+    public static @Nonnull List<InstanceIdentifier<PhysicalInterface>> resolvePhysicalInterface(ReadOnlyTransaction rTx) {
+            Optional<RendererNodes> readFromDs =
+                DataStoreHelper.readFromDs(LogicalDatastoreType.OPERATIONAL, VppIidFactory.getRendererNodesIid(), rTx);
+            rTx.close();
+            if (!readFromDs.isPresent() || readFromDs.get().getRendererNode() == null) {
+                return Collections.emptyList();
+            }
+            RendererNodes rendererNodes = readFromDs.get();
+            List<RendererNode>
+                vppNodes =
+                rendererNodes.getRendererNode()
+                    .stream()
+                    .filter(rn -> rn.getAugmentation(VppInterfaceAugmentation.class) != null)
+                    .filter(rn -> rn.getAugmentation(VppInterfaceAugmentation.class).getPhysicalInterface() != null)
+                    .collect(Collectors.toList());
+            List<InstanceIdentifier<PhysicalInterface>> iids = new ArrayList<>();
+            for (RendererNode rn : vppNodes) {
+                java.util.Optional<PhysicalInterface>
+                    optResolvedIface =
+                    rn.getAugmentation(VppInterfaceAugmentation.class)
+                        .getPhysicalInterface()
+                        .stream()
+                        .filter(phIface -> phIface.getAddress() != null)
+                        .filter(phIface -> phIface.isExternal())
+                        .findFirst();
+                if (optResolvedIface.isPresent()) {
+                    iids.add(VppIidFactory.getRendererNodeIid(rn)
+                        .builder()
+                        .augmentation(VppInterfaceAugmentation.class)
+                        .child(PhysicalInterface.class, new PhysicalInterfaceKey(optResolvedIface.get().getKey()))
+                        .build());
+                }
+            }
+            return iids;
+        }
+
+    public static Optional<MappingEntryBuilder> createStaticEntry(String internal, Ipv4Address external) {
+        IpAddress internalIp = null;
+        try {
+            InetAddress inetAddr = InetAddress.getByName(internal);
+            if (inetAddr instanceof Inet4Address) {
+                internalIp = new IpAddress(new Ipv4Address(internal));
+            } else if (inetAddr instanceof Inet6Address) {
+                internalIp = new IpAddress(new Ipv6Address(internal));
+            }
+        } catch (UnknownHostException e) {
+            LOG.error("Cannot resolve host IP {}. {}", internal, e.getMessage());
+            return Optional.absent();
+        }
+        SubnetUtils subnet = new SubnetUtils(internal + "/32");
+        Long index = Integer.toUnsignedLong(subnet.getInfo().asInteger(internal));
+        MappingEntryBuilder mappingEntryBuilder = new MappingEntryBuilder()
+            .setType(
+                    org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.MappingEntry.Type.Static)
+            .setIndex(index)
+            .setInternalSrcAddress(internalIp)
+            .setExternalSrcAddress(external);
+        return Optional.of(mappingEntryBuilder);
+    }
+
+    public static List<ExternalIpAddressPool> resolveDynamicNat(@Nonnull PolicyContext policyCtx,
+            @Nullable List<MappingEntryBuilder> sNatEntries) {
+        Optional<List<RendererForwardingByTenant>> forwardingByTenantLists = Optional.of(policyCtx)
+            .transform(x -> x.getPolicy())
+            .transform(x -> x.getConfiguration())
+            .transform(x -> x.getRendererForwarding())
+            .transform(x -> x.getRendererForwardingByTenant());
+        if (!forwardingByTenantLists.isPresent()) {
+            LOG.warn("No dynamic NAT resolved in cfg version {}.", policyCtx.getPolicy().getVersion());
+            return ImmutableList.of();
+        }
+        Map<Long, Ipv4Prefix> extCache = new HashMap<>();
+        forwardingByTenantLists.get()
+            .stream()
+            .map(rft -> rft.getRendererNetworkDomain())
+            .flatMap(Collection::stream)
+            .filter(domain -> domain.getAugmentation(SubnetAugmentRenderer.class) != null)
+            .map(domain -> domain.getAugmentation(SubnetAugmentRenderer.class).getSubnet())
+            .filter(subnet -> !subnet.isIsTenant() && subnet.getAllocationPool() != null)
+            .forEach(subnet -> {
+                final IpPrefix subnetIpPrefix = subnet.getIpPrefix();
+                subnet.getAllocationPool().forEach(pool -> {
+                    if (subnetIpPrefix.getIpv4Prefix() != null) {
+                        final String firstEntry = pool.getFirst();
+                        final String lastEntry = pool.getLast();
+                        extCache.putAll(resolveDynamicNatPrefix(subnetIpPrefix.getIpv4Prefix(), firstEntry, lastEntry,
+                                sNatEntries));
+                    }
+                });
+            });
+        List<ExternalIpAddressPool> extPools = extCache.entrySet()
+            .stream()
+            .map(entry -> new ExternalIpAddressPoolBuilder().setPoolId(entry.getKey())
+                .setExternalIpPool(entry.getValue())
+                .build())
+            .collect(Collectors.toList());
+        LOG.trace("Resolved dynamic NAT pools in cfg version {}: {}", policyCtx.getPolicy().getVersion(), extPools);
+        return extPools;
+    }
+
+
+    static Map<Long, Ipv4Prefix> resolveDynamicNatPrefix(@Nonnull final Ipv4Prefix prefix,
+                                                                 @Nonnull final String first,
+                                                                 @Nullable final String last,
+                                                                 @Nullable final List<MappingEntryBuilder> natEntries) {
+        LOG.trace("Resolving Ipv4Prefix. prefix: {}, first: {}, last: {}", prefix.getValue(), first, last);
+        final SubnetUtils subnet = new SubnetUtils(prefix.getValue());
+        final Map<Long, Ipv4Prefix> extCache = new HashMap<>();
+        int min = subnet.getInfo().asInteger(first);
+        // loop through all addresses
+        for (String address : subnet.getInfo().getAllAddresses()) {
+            int asInt = subnet.getInfo().asInteger(address);
+            if (asInt < min) {
+                continue;
+            }
+            extCache.put(Integer.toUnsignedLong(asInt), new Ipv4Prefix(address + "/32"));
+            if (last == null || subnet.getInfo().asInteger(address) >= subnet.getInfo().asInteger(last)) {
+                break;
+            }
+        }
+        if (natEntries != null) {
+            // remove every static NAT entry from extCache
+            for (MappingEntryBuilder natEntry : natEntries) {
+                final Ipv4Address externalSrcAddress = natEntry.getExternalSrcAddress();
+                final long id = Integer.toUnsignedLong(subnet.getInfo().asInteger(externalSrcAddress.getValue()));
+                if (extCache.get(id) != null) {
+                    extCache.remove(id);
+                }
+            }
+        }
+        return extCache;
+    }
+
+    public static void resolveOutboundNatInterface(InstanceIdentifier<Node> mountPointIid,
+        NodeId nodeId, Map<NodeId, PhysicalInterfaceKey> extInterfaces) {
+        if (extInterfaces.containsKey(nodeId)){
+            PhysicalInterfaceKey physicalInterfaceKey = extInterfaces.get(nodeId);
+            Optional<Interfaces> readIfaces = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+                InstanceIdentifier.create(Interfaces.class),
+                VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(mountPointIid).getKey().newReadOnlyTransaction());
+            if(readIfaces.isPresent() ) {
+                for (Interface nodeInterface : readIfaces.get().getInterface()) {
+                    if (nodeInterface.getName().equals(physicalInterfaceKey.getInterfaceName())) {
+                        LOG.trace("Setting outbound NAT on interface {} on node: {}", nodeInterface.getName(), mountPointIid);
+                        NatUtil.setOutboundInterface(nodeInterface, mountPointIid);
+                    }
+                }
+
+            }
+
+        }
+
+    }
+}
index ca1b886221dbe26533cce454771cb0e05051864e..0da74e37726780d38ec1b1abdfcc22c8955b6874 100644 (file)
@@ -1,40 +1,40 @@
-/*\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.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev170917.StaticRoutes1;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.Routing;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.LocationProviders;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.Renderer;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.Config;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816.NatInterfaceAugmentation;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unnumbered.interfaces.rev170510.unnumbered.config.attributes.Unnumbered;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.VhostUser;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.dhcp.rev170315.dhcp.attributes.relays.Relay;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;\r
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;\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, NetworkTopology.class,\r
-            Topology.class, Node.class, NetconfNode.class, Renderer.class, LocationProviders.class, Config.class,\r
-            NatInterfaceAugmentation.class, Routing.class, StaticRoutes1.class, Relay.class, Unnumbered.class);\r
-    }\r
-}\r
+/*
+ * 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 com.google.common.collect.ImmutableList;
+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.ipv4.unicast.routing.rev170917.StaticRoutes1;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.Routing;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.LocationProviders;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.Renderer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.Config;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816.NatInterfaceAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unnumbered.interfaces.rev170510.unnumbered.config.attributes.Unnumbered;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.VhostUser;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.dhcp.rev170315.dhcp.attributes.relays.Relay;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+
+import javax.annotation.Nonnull;
+import java.util.Collection;
+
+public class VppRendererDataBrokerTest extends CustomDataBrokerTest {
+
+    @Nonnull
+    @Override
+    public Collection<Class<?>> getClassesFromModules() {
+        return ImmutableList.of(Interfaces.class, Interface.class, VhostUser.class, NetworkTopology.class,
+            Topology.class, Node.class, NetconfNode.class, Renderer.class, LocationProviders.class, Config.class,
+            NatInterfaceAugmentation.class, Routing.class, StaticRoutes1.class, Relay.class, Unnumbered.class);
+    }
+}
index fbaa3fe934f5b0c7ea788783013232f6aaba6f0c..745ece86f6e6706b5be3d34ecc6722efe9ba722d 100644 (file)
-/*\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.groupbasedpolicy.util.NetUtils;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;\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.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1Builder;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4Builder;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.Subnet;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLength;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLengthBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816.NatInterfaceAugmentation;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816.NatInterfaceAugmentationBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816._interface.nat.attributes.NatBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816._interface.nat.attributes.nat.InboundBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.Loopback;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VppInterfaceAugmentation;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VppInterfaceAugmentationBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.L2Builder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.LoopbackBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.l2.config.attributes.interconnection.BridgeBasedBuilder;\r
-\r
-import java.util.Collections;\r
-import java.util.concurrent.ExecutionException;\r
-\r
-public class LoopbackCommandTest extends VppRendererDataBrokerTest {\r
-\r
-    private final static String DESCRIPTION = "used for testing";\r
-    private final static String INTERFACE_NAME = "testInterface";\r
-    private final static String BRIDGE_DOMAIN = "testBD";\r
-    private final static boolean IS_BVI = true;\r
-    private final static PhysAddress MAC_ADDRESS = new PhysAddress("00:11:22:33:44:55");\r
-    private final static IpAddress IP_ADDRESS = new IpAddress(new Ipv4Address("10.0.0.1"));\r
-    private final static IpPrefix IP_PREFIX = new IpPrefix(new Ipv4Prefix("10.0.0.1/24"));\r
-\r
-    private final static String UPD_DESCRIPTION = "updated description";\r
-    private final static PhysAddress UPD_MAC_ADDRESS = new PhysAddress("55:44:33:22:11:00");\r
-    private final static IpAddress UPD_IP_ADDRESS = new IpAddress(new Ipv4Address("20.0.0.1"));\r
-    private final static IpPrefix UPD_IP_PREFIX = new IpPrefix(new Ipv4Prefix("20.0.0.1/24"));\r
-\r
-    private final static VppInterfaceAugmentationBuilder vppAugmentationBuilder = new VppInterfaceAugmentationBuilder()\r
-        .setLoopback(new LoopbackBuilder().setMac(MAC_ADDRESS).build());\r
-\r
-    private final static VppInterfaceAugmentationBuilder vppAugmentationBuilderWithBD =\r
-            new VppInterfaceAugmentationBuilder(vppAugmentationBuilder.build())\r
-                .setL2(new L2Builder().setInterconnection(new BridgeBasedBuilder().setBridgeDomain(BRIDGE_DOMAIN)\r
-                    .setBridgedVirtualInterface(IS_BVI).setSplitHorizonGroup((short)0)\r
-                    .build()).build());\r
-\r
-    private final static InterfaceBuilder interfaceBuilder =\r
-            new InterfaceBuilder().setKey(new InterfaceKey(INTERFACE_NAME))\r
-                .setEnabled(true)\r
-                .setDescription(DESCRIPTION)\r
-                .setType(Loopback.class)\r
-                .setName(INTERFACE_NAME)\r
-                .setLinkUpDownTrapEnable(Interface.LinkUpDownTrapEnable.Enabled);\r
-\r
-    private final static Interface1Builder\r
-        interface1Builder =\r
-        new Interface1Builder().setIpv4(new Ipv4Builder().setAddress(Collections.singletonList(\r
-            new AddressBuilder()\r
-                .setIp(new Ipv4AddressNoZone(IP_ADDRESS.getIpv4Address()))\r
-                .setSubnet(new PrefixLengthBuilder().setPrefixLength((short) NetUtils.getMaskFromPrefix(IP_PREFIX.getIpv4Prefix().getValue())).build())\r
-                .build()))\r
-            .setEnabled(true)\r
-            .setForwarding(false)\r
-            .build());\r
-\r
-    private final static Interface BASIC_INTERFACE =\r
-            interfaceBuilder.addAugmentation(VppInterfaceAugmentation.class, vppAugmentationBuilder.build())\r
-                .addAugmentation(NatInterfaceAugmentation.class, new NatInterfaceAugmentationBuilder().setNat(\r
-                    new NatBuilder().setInbound(\r
-                        new InboundBuilder().setNat44Support(true).setPostRouting(false).build()).build())\r
-                    .build())\r
-                .addAugmentation(Interface1.class, interface1Builder.build()).build();\r
-\r
-    private final static Interface BASIC_INTERFACE_WITH_BD = interfaceBuilder\r
-        .addAugmentation(VppInterfaceAugmentation.class, vppAugmentationBuilderWithBD.build()).build();\r
-\r
-    private DataBroker dataBroker;\r
-\r
-    @Before\r
-    public void init() {\r
-        dataBroker = getDataBroker();\r
-    }\r
-\r
-    @Test\r
-    public void testAddLoopback() throws ExecutionException, InterruptedException {\r
-        ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();\r
-        LoopbackCommand addCommand = LoopbackCommand.builder()\r
-            .setOperation(General.Operations.PUT)\r
-            .setInterfaceName(INTERFACE_NAME)\r
-            .setDescription(DESCRIPTION)\r
-            .setBvi(IS_BVI)\r
-            .setPhysAddress(MAC_ADDRESS)\r
-            .setIpPrefix(IP_PREFIX)\r
-            .setIpAddress(IP_ADDRESS)\r
-            .setEnabled(true)\r
-            .build();\r
-\r
-        Assert.assertEquals(IS_BVI, addCommand.getBvi());\r
-        Assert.assertEquals(MAC_ADDRESS, addCommand.getPhysAddress());\r
-        Assert.assertEquals(IP_ADDRESS, addCommand.getIpAddress());\r
-        Assert.assertEquals(IP_PREFIX, addCommand.getIpPrefix());\r
-\r
-        Optional<Interface> optional = executeCommand(rwTx, addCommand);\r
-\r
-        Assert.assertTrue(optional.isPresent());\r
-        Assert.assertEquals(BASIC_INTERFACE, optional.get());\r
-\r
-    }\r
-\r
-    @Test\r
-    public void testAddLoopback_WithBridgeDomain() throws ExecutionException, InterruptedException {\r
-        ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();\r
-        LoopbackCommand addCommand = LoopbackCommand.builder()\r
-            .setOperation(General.Operations.PUT)\r
-            .setInterfaceName(INTERFACE_NAME)\r
-            .setDescription(DESCRIPTION)\r
-            .setBvi(true)\r
-            .setPhysAddress(MAC_ADDRESS)\r
-            .setIpPrefix(IP_PREFIX)\r
-            .setIpAddress(IP_ADDRESS)\r
-            .setBridgeDomain(BRIDGE_DOMAIN)\r
-            .setEnabled(true)\r
-            .build();\r
-\r
-        Assert.assertEquals(BRIDGE_DOMAIN, addCommand.getBridgeDomain());\r
-\r
-        Optional<Interface> optional = executeCommand(rwTx, addCommand);\r
-\r
-        Assert.assertTrue(optional.isPresent());\r
-        Assert.assertEquals(BASIC_INTERFACE_WITH_BD, optional.get());\r
-    }\r
-\r
-    private Optional<Interface> executeCommand(ReadWriteTransaction rwTx, LoopbackCommand addCommand)\r
-            throws ExecutionException, InterruptedException {\r
-        addCommand.execute(rwTx);\r
-\r
-        rwTx.submit().get();\r
-\r
-        ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();\r
-\r
-        return DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,\r
-                VppIidFactory.getInterfaceIID(new InterfaceKey(INTERFACE_NAME)), rTx);\r
-    }\r
-\r
-    @Test\r
-    public void testDeleteLoopbackPort() throws ExecutionException, InterruptedException {\r
-        ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();\r
-\r
-        rwTx.put(LogicalDatastoreType.CONFIGURATION, VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()),\r
-                BASIC_INTERFACE, true);\r
-        rwTx.submit().get();\r
-\r
-        Optional<Interface> optional = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,\r
-                VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()), dataBroker.newReadOnlyTransaction());\r
-\r
-        Assert.assertTrue(optional.isPresent());\r
-\r
-        LoopbackCommand deleteCommand = LoopbackCommand.builder()\r
-            .setOperation(General.Operations.DELETE)\r
-            .setInterfaceName(INTERFACE_NAME)\r
-            .setIpPrefix(IP_PREFIX)\r
-            .setIpAddress(IP_ADDRESS)\r
-            .build();\r
-\r
-        ReadWriteTransaction rwTxDel = dataBroker.newReadWriteTransaction();\r
-        deleteCommand.execute(rwTxDel);\r
-        rwTxDel.submit();\r
-\r
-        Optional<Interface> optionalDeleted = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,\r
-                VppIidFactory.getInterfaceIID(new InterfaceKey(deleteCommand.getName())),\r
-                dataBroker.newReadOnlyTransaction());\r
-\r
-        Assert.assertFalse(optionalDeleted.isPresent());\r
-    }\r
-\r
-    @Test\r
-    public void testUpdateLoopbackPort() throws ExecutionException, InterruptedException {\r
-        ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();\r
-\r
-        rwTx.put(LogicalDatastoreType.CONFIGURATION, VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()),\r
-                BASIC_INTERFACE, true);\r
-        rwTx.submit().get();\r
-\r
-        Optional<Interface> optional = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,\r
-                VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()), dataBroker.newReadOnlyTransaction());\r
-\r
-        Assert.assertTrue(optional.isPresent());\r
-\r
-        LoopbackCommand updateCommand = LoopbackCommand.builder()\r
-            .setOperation(General.Operations.MERGE)\r
-            .setInterfaceName(INTERFACE_NAME)\r
-            .setDescription(UPD_DESCRIPTION)\r
-            .setPhysAddress(UPD_MAC_ADDRESS)\r
-            .setIpPrefix(UPD_IP_PREFIX)\r
-            .setIpAddress(UPD_IP_ADDRESS)\r
-            .setEnabled(false)\r
-            .build();\r
-\r
-        ReadWriteTransaction rwTxUpd = dataBroker.newReadWriteTransaction();\r
-        updateCommand.execute(rwTxUpd);\r
-        rwTxUpd.submit().get();\r
-\r
-        Optional<Interface> optionalUpdated = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,\r
-                VppIidFactory.getInterfaceIID(new InterfaceKey(updateCommand.getName())),\r
-                dataBroker.newReadOnlyTransaction());\r
-\r
-        Assert.assertTrue(optionalUpdated.isPresent());\r
-        Interface updatedInterface = optionalUpdated.get();\r
-\r
-        Assert.assertEquals(UPD_DESCRIPTION, updatedInterface.getDescription());\r
-        Assert.assertFalse(updatedInterface.isEnabled());\r
-        VppInterfaceAugmentation augmentation = updatedInterface.getAugmentation(VppInterfaceAugmentation.class);\r
-        Assert.assertEquals(INTERFACE_NAME, updatedInterface.getName());\r
-        Assert.assertEquals(UPD_MAC_ADDRESS, augmentation.getLoopback().getMac());\r
-        Interface1 interface1 = updatedInterface.getAugmentation(Interface1.class);\r
-\r
-        // merge operation will add new ip address to list so index is 1 for new ip\r
-        String ip = interface1.getIpv4().getAddress().get(1).getIp().getValue();\r
-        Subnet subnet = interface1.getIpv4().getAddress().get(1).getSubnet();\r
-        String prefix = "";\r
-\r
-        if ( subnet instanceof PrefixLength){\r
-            prefix = ((PrefixLength) subnet).getPrefixLength().toString();\r
-        }\r
-        IpPrefix ipPrefix = new IpPrefix(new Ipv4Prefix(ip + "/" + prefix));\r
-        IpAddress ipAddress = new IpAddress( new Ipv4Address(ip));\r
-        Assert.assertEquals(UPD_IP_PREFIX, ipPrefix);\r
-        Assert.assertEquals(UPD_IP_ADDRESS, ipAddress);\r
-    }\r
-}\r
+/*
+ * 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.commands;
+
+import com.google.common.base.Optional;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.VppRendererDataBrokerTest;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+import org.opendaylight.groupbasedpolicy.util.NetUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+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.InterfaceBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.Subnet;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLength;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLengthBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816.NatInterfaceAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816.NatInterfaceAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816._interface.nat.attributes.NatBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816._interface.nat.attributes.nat.InboundBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.Loopback;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VppInterfaceAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VppInterfaceAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.L2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.LoopbackBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.l2.config.attributes.interconnection.BridgeBasedBuilder;
+
+import java.util.Collections;
+import java.util.concurrent.ExecutionException;
+
+public class LoopbackCommandTest extends VppRendererDataBrokerTest {
+
+    private final static String DESCRIPTION = "used for testing";
+    private final static String INTERFACE_NAME = "testInterface";
+    private final static String BRIDGE_DOMAIN = "testBD";
+    private final static boolean IS_BVI = true;
+    private final static PhysAddress MAC_ADDRESS = new PhysAddress("00:11:22:33:44:55");
+    private final static IpAddress IP_ADDRESS = new IpAddress(new Ipv4Address("10.0.0.1"));
+    private final static IpPrefix IP_PREFIX = new IpPrefix(new Ipv4Prefix("10.0.0.1/24"));
+
+    private final static String UPD_DESCRIPTION = "updated description";
+    private final static PhysAddress UPD_MAC_ADDRESS = new PhysAddress("55:44:33:22:11:00");
+    private final static IpAddress UPD_IP_ADDRESS = new IpAddress(new Ipv4Address("20.0.0.1"));
+    private final static IpPrefix UPD_IP_PREFIX = new IpPrefix(new Ipv4Prefix("20.0.0.1/24"));
+
+    private final static VppInterfaceAugmentationBuilder vppAugmentationBuilder = new VppInterfaceAugmentationBuilder()
+        .setLoopback(new LoopbackBuilder().setMac(MAC_ADDRESS).build());
+
+    private final static VppInterfaceAugmentationBuilder vppAugmentationBuilderWithBD =
+            new VppInterfaceAugmentationBuilder(vppAugmentationBuilder.build())
+                .setL2(new L2Builder().setInterconnection(new BridgeBasedBuilder().setBridgeDomain(BRIDGE_DOMAIN)
+                    .setBridgedVirtualInterface(IS_BVI).setSplitHorizonGroup((short)0)
+                    .build()).build());
+
+    private final static InterfaceBuilder interfaceBuilder =
+            new InterfaceBuilder().setKey(new InterfaceKey(INTERFACE_NAME))
+                .setEnabled(true)
+                .setDescription(DESCRIPTION)
+                .setType(Loopback.class)
+                .setName(INTERFACE_NAME)
+                .setLinkUpDownTrapEnable(Interface.LinkUpDownTrapEnable.Enabled);
+
+    private final static Interface1Builder
+        interface1Builder =
+        new Interface1Builder().setIpv4(new Ipv4Builder().setAddress(Collections.singletonList(
+            new AddressBuilder()
+                .setIp(new Ipv4AddressNoZone(IP_ADDRESS.getIpv4Address()))
+                .setSubnet(new PrefixLengthBuilder().setPrefixLength((short) NetUtils.getMaskFromPrefix(IP_PREFIX.getIpv4Prefix().getValue())).build())
+                .build()))
+            .setEnabled(true)
+            .setForwarding(false)
+            .build());
+
+    private final static Interface BASIC_INTERFACE =
+            interfaceBuilder.addAugmentation(VppInterfaceAugmentation.class, vppAugmentationBuilder.build())
+                .addAugmentation(NatInterfaceAugmentation.class, new NatInterfaceAugmentationBuilder().setNat(
+                    new NatBuilder().setInbound(
+                        new InboundBuilder().setNat44Support(true).setPostRouting(false).build()).build())
+                    .build())
+                .addAugmentation(Interface1.class, interface1Builder.build()).build();
+
+    private final static Interface BASIC_INTERFACE_WITH_BD = interfaceBuilder
+        .addAugmentation(VppInterfaceAugmentation.class, vppAugmentationBuilderWithBD.build()).build();
+
+    private DataBroker dataBroker;
+
+    @Before
+    public void init() {
+        dataBroker = getDataBroker();
+    }
+
+    @Test
+    public void testAddLoopback() throws ExecutionException, InterruptedException {
+        ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();
+        LoopbackCommand addCommand = LoopbackCommand.builder()
+            .setOperation(General.Operations.PUT)
+            .setInterfaceName(INTERFACE_NAME)
+            .setDescription(DESCRIPTION)
+            .setBvi(IS_BVI)
+            .setPhysAddress(MAC_ADDRESS)
+            .setIpPrefix(IP_PREFIX)
+            .setIpAddress(IP_ADDRESS)
+            .setEnabled(true)
+            .build();
+
+        Assert.assertEquals(IS_BVI, addCommand.getBvi());
+        Assert.assertEquals(MAC_ADDRESS, addCommand.getPhysAddress());
+        Assert.assertEquals(IP_ADDRESS, addCommand.getIpAddress());
+        Assert.assertEquals(IP_PREFIX, addCommand.getIpPrefix());
+
+        Optional<Interface> optional = executeCommand(rwTx, addCommand);
+
+        Assert.assertTrue(optional.isPresent());
+        Assert.assertEquals(BASIC_INTERFACE, optional.get());
+
+    }
+
+    @Test
+    public void testAddLoopback_WithBridgeDomain() throws ExecutionException, InterruptedException {
+        ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();
+        LoopbackCommand addCommand = LoopbackCommand.builder()
+            .setOperation(General.Operations.PUT)
+            .setInterfaceName(INTERFACE_NAME)
+            .setDescription(DESCRIPTION)
+            .setBvi(true)
+            .setPhysAddress(MAC_ADDRESS)
+            .setIpPrefix(IP_PREFIX)
+            .setIpAddress(IP_ADDRESS)
+            .setBridgeDomain(BRIDGE_DOMAIN)
+            .setEnabled(true)
+            .build();
+
+        Assert.assertEquals(BRIDGE_DOMAIN, addCommand.getBridgeDomain());
+
+        Optional<Interface> optional = executeCommand(rwTx, addCommand);
+
+        Assert.assertTrue(optional.isPresent());
+        Assert.assertEquals(BASIC_INTERFACE_WITH_BD, optional.get());
+    }
+
+    private Optional<Interface> executeCommand(ReadWriteTransaction rwTx, LoopbackCommand addCommand)
+            throws ExecutionException, InterruptedException {
+        addCommand.execute(rwTx);
+
+        rwTx.submit().get();
+
+        ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();
+
+        return DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+                VppIidFactory.getInterfaceIID(new InterfaceKey(INTERFACE_NAME)), rTx);
+    }
+
+    @Test
+    public void testDeleteLoopbackPort() throws ExecutionException, InterruptedException {
+        ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();
+
+        rwTx.put(LogicalDatastoreType.CONFIGURATION, VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()),
+                BASIC_INTERFACE, true);
+        rwTx.submit().get();
+
+        Optional<Interface> optional = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+                VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()), dataBroker.newReadOnlyTransaction());
+
+        Assert.assertTrue(optional.isPresent());
+
+        LoopbackCommand deleteCommand = LoopbackCommand.builder()
+            .setOperation(General.Operations.DELETE)
+            .setInterfaceName(INTERFACE_NAME)
+            .setIpPrefix(IP_PREFIX)
+            .setIpAddress(IP_ADDRESS)
+            .build();
+
+        ReadWriteTransaction rwTxDel = dataBroker.newReadWriteTransaction();
+        deleteCommand.execute(rwTxDel);
+        rwTxDel.submit();
+
+        Optional<Interface> optionalDeleted = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+                VppIidFactory.getInterfaceIID(new InterfaceKey(deleteCommand.getName())),
+                dataBroker.newReadOnlyTransaction());
+
+        Assert.assertFalse(optionalDeleted.isPresent());
+    }
+
+    @Test
+    public void testUpdateLoopbackPort() throws ExecutionException, InterruptedException {
+        ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();
+
+        rwTx.put(LogicalDatastoreType.CONFIGURATION, VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()),
+                BASIC_INTERFACE, true);
+        rwTx.submit().get();
+
+        Optional<Interface> optional = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+                VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()), dataBroker.newReadOnlyTransaction());
+
+        Assert.assertTrue(optional.isPresent());
+
+        LoopbackCommand updateCommand = LoopbackCommand.builder()
+            .setOperation(General.Operations.MERGE)
+            .setInterfaceName(INTERFACE_NAME)
+            .setDescription(UPD_DESCRIPTION)
+            .setPhysAddress(UPD_MAC_ADDRESS)
+            .setIpPrefix(UPD_IP_PREFIX)
+            .setIpAddress(UPD_IP_ADDRESS)
+            .setEnabled(false)
+            .build();
+
+        ReadWriteTransaction rwTxUpd = dataBroker.newReadWriteTransaction();
+        updateCommand.execute(rwTxUpd);
+        rwTxUpd.submit().get();
+
+        Optional<Interface> optionalUpdated = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+                VppIidFactory.getInterfaceIID(new InterfaceKey(updateCommand.getName())),
+                dataBroker.newReadOnlyTransaction());
+
+        Assert.assertTrue(optionalUpdated.isPresent());
+        Interface updatedInterface = optionalUpdated.get();
+
+        Assert.assertEquals(UPD_DESCRIPTION, updatedInterface.getDescription());
+        Assert.assertFalse(updatedInterface.isEnabled());
+        VppInterfaceAugmentation augmentation = updatedInterface.getAugmentation(VppInterfaceAugmentation.class);
+        Assert.assertEquals(INTERFACE_NAME, updatedInterface.getName());
+        Assert.assertEquals(UPD_MAC_ADDRESS, augmentation.getLoopback().getMac());
+        Interface1 interface1 = updatedInterface.getAugmentation(Interface1.class);
+
+        // merge operation will add new ip address to list so index is 1 for new ip
+        String ip = interface1.getIpv4().getAddress().get(1).getIp().getValue();
+        Subnet subnet = interface1.getIpv4().getAddress().get(1).getSubnet();
+        String prefix = "";
+
+        if ( subnet instanceof PrefixLength){
+            prefix = ((PrefixLength) subnet).getPrefixLength().toString();
+        }
+        IpPrefix ipPrefix = new IpPrefix(new Ipv4Prefix(ip + "/" + prefix));
+        IpAddress ipAddress = new IpAddress( new Ipv4Address(ip));
+        Assert.assertEquals(UPD_IP_PREFIX, ipPrefix);
+        Assert.assertEquals(UPD_IP_ADDRESS, ipAddress);
+    }
+}
index aeeb40681f3ab839e432f81616ea60a863f1ed58..373e07205d6e616a0304ffbdc307229d96de83f7 100644 (file)
-/*\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.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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.Tap;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VppInterfaceAugmentation;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VppInterfaceAugmentationBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.L2Builder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.TapBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.l2.config.attributes.interconnection.BridgeBasedBuilder;\r
-\r
-import java.util.concurrent.ExecutionException;\r
-\r
-public class TapPortCommandTest extends VppRendererDataBrokerTest {\r
-\r
-    private final static String DESCRIPTION = "used for testing";\r
-    private final static String INTERFACE_NAME = "testInterface";\r
-    private final static String TAP_NAME = "testTap00:11:22:33:44:55";\r
-    private final static String BRIDGE_DOMAIN = "testBD";\r
-    private final static Long DEVICE_ID = 0L;\r
-    private final static PhysAddress MAC_ADDRESS = new PhysAddress("00:11:22:33:44:55");\r
-\r
-    private final static String UPD_DESCRIPTION = "updated description";\r
-    private final static PhysAddress UPD_MAC_ADDRESS = new PhysAddress("55:44:33:22:11:00");\r
-    private final static String UPD_TAP_NAME = "testTapUpd";\r
-    private final static Long UPD_DEVICE_ID = 1L;\r
-\r
-    private final static VppInterfaceAugmentationBuilder vppAugmentationBuilder = new VppInterfaceAugmentationBuilder()\r
-        .setTap(new TapBuilder().setMac(MAC_ADDRESS).setTapName(TAP_NAME).setDeviceInstance(DEVICE_ID).build());\r
-\r
-    private final static VppInterfaceAugmentationBuilder vppAugmentationBuilderWithBD =\r
-            new VppInterfaceAugmentationBuilder(vppAugmentationBuilder.build())\r
-                .setL2(new L2Builder().setInterconnection(new BridgeBasedBuilder().setBridgeDomain(BRIDGE_DOMAIN)\r
-                    .setBridgedVirtualInterface(false).setSplitHorizonGroup((short)0)\r
-                    .build()).build());\r
-\r
-    private final static InterfaceBuilder interfaceBuilder =\r
-            new InterfaceBuilder().setKey(new InterfaceKey(INTERFACE_NAME))\r
-                .setEnabled(true)\r
-                .setDescription(DESCRIPTION)\r
-                .setType(Tap.class)\r
-                .setName(INTERFACE_NAME)\r
-                .setLinkUpDownTrapEnable(Interface.LinkUpDownTrapEnable.Enabled);\r
-\r
-    private final static Interface BASIC_INTERFACE =\r
-            interfaceBuilder.addAugmentation(VppInterfaceAugmentation.class, vppAugmentationBuilder.build()).build();\r
-    private final static Interface BASIC_INTERFACE_WITH_BD = interfaceBuilder\r
-        .addAugmentation(VppInterfaceAugmentation.class, vppAugmentationBuilderWithBD.build()).build();\r
-\r
-    private DataBroker dataBroker;\r
-\r
-    @Before\r
-    public void init() {\r
-        dataBroker = getDataBroker();\r
-    }\r
-\r
-    @Test\r
-    public void testAddTapPort() throws ExecutionException, InterruptedException {\r
-        ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();\r
-        TapPortCommand addCommand = TapPortCommand.builder()\r
-            .setOperation(General.Operations.PUT)\r
-            .setInterfaceName(INTERFACE_NAME)\r
-            .setTapName(TAP_NAME)\r
-            .setDescription(DESCRIPTION)\r
-            .setDeviceInstance(DEVICE_ID)\r
-            .setPhysAddress(MAC_ADDRESS)\r
-            .setEnabled(true)\r
-            .build();\r
-\r
-        Optional<Interface> optional = executeCommand(rwTx, addCommand);\r
-\r
-        Assert.assertTrue(optional.isPresent());\r
-        Assert.assertEquals(BASIC_INTERFACE, optional.get());\r
-\r
-    }\r
-\r
-    @Test\r
-    public void testAddTapPort_WithBridgeDomain() throws ExecutionException, InterruptedException {\r
-        ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();\r
-        TapPortCommand addCommand = TapPortCommand.builder()\r
-            .setOperation(General.Operations.PUT)\r
-            .setInterfaceName(INTERFACE_NAME)\r
-            .setTapName(TAP_NAME)\r
-            .setDescription(DESCRIPTION)\r
-            .setDeviceInstance(DEVICE_ID)\r
-            .setPhysAddress(MAC_ADDRESS)\r
-            .setBridgeDomain(BRIDGE_DOMAIN)\r
-            .setEnabled(true)\r
-            .build();\r
-\r
-        Optional<Interface> optional = executeCommand(rwTx, addCommand);\r
-\r
-        Assert.assertTrue(optional.isPresent());\r
-        Assert.assertEquals(BASIC_INTERFACE_WITH_BD, optional.get());\r
-\r
-    }\r
-\r
-    private Optional<Interface> executeCommand(ReadWriteTransaction rwTx, TapPortCommand addCommand)\r
-            throws ExecutionException, InterruptedException {\r
-        addCommand.execute(rwTx);\r
-\r
-        rwTx.submit().get();\r
-\r
-        ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();\r
-\r
-        return DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,\r
-                VppIidFactory.getInterfaceIID(new InterfaceKey(INTERFACE_NAME)), rTx);\r
-    }\r
-\r
-    @Test\r
-    public void testDeleteTapPort() throws ExecutionException, InterruptedException {\r
-        ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();\r
-\r
-        rwTx.put(LogicalDatastoreType.CONFIGURATION, VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()),\r
-                BASIC_INTERFACE, true);\r
-        rwTx.submit().get();\r
-\r
-        Optional<Interface> optional = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,\r
-                VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()), dataBroker.newReadOnlyTransaction());\r
-\r
-        Assert.assertTrue(optional.isPresent());\r
-\r
-        TapPortCommand deleteCommand = TapPortCommand.builder()\r
-            .setOperation(General.Operations.DELETE)\r
-            .setInterfaceName(INTERFACE_NAME)\r
-            .setTapName(TAP_NAME)\r
-            .build();\r
-\r
-        ReadWriteTransaction rwTxDel = dataBroker.newReadWriteTransaction();\r
-        deleteCommand.execute(rwTxDel);\r
-        rwTxDel.submit();\r
-\r
-        Optional<Interface> optionalDeleted = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,\r
-                VppIidFactory.getInterfaceIID(new InterfaceKey(deleteCommand.getName())),\r
-                dataBroker.newReadOnlyTransaction());\r
-\r
-        Assert.assertFalse(optionalDeleted.isPresent());\r
-    }\r
-\r
-    @Test\r
-    public void testUpdateTapPort() throws ExecutionException, InterruptedException {\r
-        ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();\r
-\r
-        rwTx.put(LogicalDatastoreType.CONFIGURATION, VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()),\r
-                BASIC_INTERFACE, true);\r
-        rwTx.submit().get();\r
-\r
-        Optional<Interface> optional = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,\r
-                VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()), dataBroker.newReadOnlyTransaction());\r
-\r
-        Assert.assertTrue(optional.isPresent());\r
-\r
-        TapPortCommand updateCommand = TapPortCommand.builder()\r
-            .setOperation(General.Operations.MERGE)\r
-            .setInterfaceName(INTERFACE_NAME)\r
-            .setTapName(UPD_TAP_NAME)\r
-            .setDescription(UPD_DESCRIPTION)\r
-            .setPhysAddress(UPD_MAC_ADDRESS)\r
-            .setDeviceInstance(UPD_DEVICE_ID)\r
-            .setEnabled(false)\r
-            .build();\r
-\r
-        ReadWriteTransaction rwTxUpd = dataBroker.newReadWriteTransaction();\r
-        updateCommand.execute(rwTxUpd);\r
-        rwTxUpd.submit().get();\r
-\r
-        Optional<Interface> optionalUpdated = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,\r
-                VppIidFactory.getInterfaceIID(new InterfaceKey(updateCommand.getName())),\r
-                dataBroker.newReadOnlyTransaction());\r
-\r
-        Assert.assertTrue(optionalUpdated.isPresent());\r
-        Interface updatedInterface = optionalUpdated.get();\r
-\r
-        Assert.assertEquals(UPD_DESCRIPTION, updatedInterface.getDescription());\r
-        Assert.assertFalse(updatedInterface.isEnabled());\r
-        VppInterfaceAugmentation augmentation = updatedInterface.getAugmentation(VppInterfaceAugmentation.class);\r
-        Assert.assertEquals(INTERFACE_NAME, updatedInterface.getName());\r
-        Assert.assertEquals(UPD_DEVICE_ID, augmentation.getTap().getDeviceInstance());\r
-        Assert.assertEquals(UPD_MAC_ADDRESS, augmentation.getTap().getMac());\r
-        Assert.assertEquals(UPD_TAP_NAME, augmentation.getTap().getTapName());\r
-\r
-    }\r
-}\r
+/*
+ * 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.commands;
+
+import com.google.common.base.Optional;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.VppRendererDataBrokerTest;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+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.InterfaceBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.Tap;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VppInterfaceAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VppInterfaceAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.L2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.TapBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.l2.config.attributes.interconnection.BridgeBasedBuilder;
+
+import java.util.concurrent.ExecutionException;
+
+public class TapPortCommandTest extends VppRendererDataBrokerTest {
+
+    private final static String DESCRIPTION = "used for testing";
+    private final static String INTERFACE_NAME = "testInterface";
+    private final static String TAP_NAME = "testTap00:11:22:33:44:55";
+    private final static String BRIDGE_DOMAIN = "testBD";
+    private final static Long DEVICE_ID = 0L;
+    private final static PhysAddress MAC_ADDRESS = new PhysAddress("00:11:22:33:44:55");
+
+    private final static String UPD_DESCRIPTION = "updated description";
+    private final static PhysAddress UPD_MAC_ADDRESS = new PhysAddress("55:44:33:22:11:00");
+    private final static String UPD_TAP_NAME = "testTapUpd";
+    private final static Long UPD_DEVICE_ID = 1L;
+
+    private final static VppInterfaceAugmentationBuilder vppAugmentationBuilder = new VppInterfaceAugmentationBuilder()
+        .setTap(new TapBuilder().setMac(MAC_ADDRESS).setTapName(TAP_NAME).setDeviceInstance(DEVICE_ID).build());
+
+    private final static VppInterfaceAugmentationBuilder vppAugmentationBuilderWithBD =
+            new VppInterfaceAugmentationBuilder(vppAugmentationBuilder.build())
+                .setL2(new L2Builder().setInterconnection(new BridgeBasedBuilder().setBridgeDomain(BRIDGE_DOMAIN)
+                    .setBridgedVirtualInterface(false).setSplitHorizonGroup((short)0)
+                    .build()).build());
+
+    private final static InterfaceBuilder interfaceBuilder =
+            new InterfaceBuilder().setKey(new InterfaceKey(INTERFACE_NAME))
+                .setEnabled(true)
+                .setDescription(DESCRIPTION)
+                .setType(Tap.class)
+                .setName(INTERFACE_NAME)
+                .setLinkUpDownTrapEnable(Interface.LinkUpDownTrapEnable.Enabled);
+
+    private final static Interface BASIC_INTERFACE =
+            interfaceBuilder.addAugmentation(VppInterfaceAugmentation.class, vppAugmentationBuilder.build()).build();
+    private final static Interface BASIC_INTERFACE_WITH_BD = interfaceBuilder
+        .addAugmentation(VppInterfaceAugmentation.class, vppAugmentationBuilderWithBD.build()).build();
+
+    private DataBroker dataBroker;
+
+    @Before
+    public void init() {
+        dataBroker = getDataBroker();
+    }
+
+    @Test
+    public void testAddTapPort() throws ExecutionException, InterruptedException {
+        ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();
+        TapPortCommand addCommand = TapPortCommand.builder()
+            .setOperation(General.Operations.PUT)
+            .setInterfaceName(INTERFACE_NAME)
+            .setTapName(TAP_NAME)
+            .setDescription(DESCRIPTION)
+            .setDeviceInstance(DEVICE_ID)
+            .setPhysAddress(MAC_ADDRESS)
+            .setEnabled(true)
+            .build();
+
+        Optional<Interface> optional = executeCommand(rwTx, addCommand);
+
+        Assert.assertTrue(optional.isPresent());
+        Assert.assertEquals(BASIC_INTERFACE, optional.get());
+
+    }
+
+    @Test
+    public void testAddTapPort_WithBridgeDomain() throws ExecutionException, InterruptedException {
+        ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();
+        TapPortCommand addCommand = TapPortCommand.builder()
+            .setOperation(General.Operations.PUT)
+            .setInterfaceName(INTERFACE_NAME)
+            .setTapName(TAP_NAME)
+            .setDescription(DESCRIPTION)
+            .setDeviceInstance(DEVICE_ID)
+            .setPhysAddress(MAC_ADDRESS)
+            .setBridgeDomain(BRIDGE_DOMAIN)
+            .setEnabled(true)
+            .build();
+
+        Optional<Interface> optional = executeCommand(rwTx, addCommand);
+
+        Assert.assertTrue(optional.isPresent());
+        Assert.assertEquals(BASIC_INTERFACE_WITH_BD, optional.get());
+
+    }
+
+    private Optional<Interface> executeCommand(ReadWriteTransaction rwTx, TapPortCommand addCommand)
+            throws ExecutionException, InterruptedException {
+        addCommand.execute(rwTx);
+
+        rwTx.submit().get();
+
+        ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();
+
+        return DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+                VppIidFactory.getInterfaceIID(new InterfaceKey(INTERFACE_NAME)), rTx);
+    }
+
+    @Test
+    public void testDeleteTapPort() throws ExecutionException, InterruptedException {
+        ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();
+
+        rwTx.put(LogicalDatastoreType.CONFIGURATION, VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()),
+                BASIC_INTERFACE, true);
+        rwTx.submit().get();
+
+        Optional<Interface> optional = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+                VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()), dataBroker.newReadOnlyTransaction());
+
+        Assert.assertTrue(optional.isPresent());
+
+        TapPortCommand deleteCommand = TapPortCommand.builder()
+            .setOperation(General.Operations.DELETE)
+            .setInterfaceName(INTERFACE_NAME)
+            .setTapName(TAP_NAME)
+            .build();
+
+        ReadWriteTransaction rwTxDel = dataBroker.newReadWriteTransaction();
+        deleteCommand.execute(rwTxDel);
+        rwTxDel.submit();
+
+        Optional<Interface> optionalDeleted = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+                VppIidFactory.getInterfaceIID(new InterfaceKey(deleteCommand.getName())),
+                dataBroker.newReadOnlyTransaction());
+
+        Assert.assertFalse(optionalDeleted.isPresent());
+    }
+
+    @Test
+    public void testUpdateTapPort() throws ExecutionException, InterruptedException {
+        ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();
+
+        rwTx.put(LogicalDatastoreType.CONFIGURATION, VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()),
+                BASIC_INTERFACE, true);
+        rwTx.submit().get();
+
+        Optional<Interface> optional = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+                VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()), dataBroker.newReadOnlyTransaction());
+
+        Assert.assertTrue(optional.isPresent());
+
+        TapPortCommand updateCommand = TapPortCommand.builder()
+            .setOperation(General.Operations.MERGE)
+            .setInterfaceName(INTERFACE_NAME)
+            .setTapName(UPD_TAP_NAME)
+            .setDescription(UPD_DESCRIPTION)
+            .setPhysAddress(UPD_MAC_ADDRESS)
+            .setDeviceInstance(UPD_DEVICE_ID)
+            .setEnabled(false)
+            .build();
+
+        ReadWriteTransaction rwTxUpd = dataBroker.newReadWriteTransaction();
+        updateCommand.execute(rwTxUpd);
+        rwTxUpd.submit().get();
+
+        Optional<Interface> optionalUpdated = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+                VppIidFactory.getInterfaceIID(new InterfaceKey(updateCommand.getName())),
+                dataBroker.newReadOnlyTransaction());
+
+        Assert.assertTrue(optionalUpdated.isPresent());
+        Interface updatedInterface = optionalUpdated.get();
+
+        Assert.assertEquals(UPD_DESCRIPTION, updatedInterface.getDescription());
+        Assert.assertFalse(updatedInterface.isEnabled());
+        VppInterfaceAugmentation augmentation = updatedInterface.getAugmentation(VppInterfaceAugmentation.class);
+        Assert.assertEquals(INTERFACE_NAME, updatedInterface.getName());
+        Assert.assertEquals(UPD_DEVICE_ID, augmentation.getTap().getDeviceInstance());
+        Assert.assertEquals(UPD_MAC_ADDRESS, augmentation.getTap().getMac());
+        Assert.assertEquals(UPD_TAP_NAME, augmentation.getTap().getTapName());
+
+    }
+}
index ff2e7eb6dcef119831f89d19fe2717f6dcc2926c..f9736bf8f01015fd3b3299024e96aa1e07f0cab8 100644 (file)
-/*\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.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.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.rev170607.VhostUserRole;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VppInterfaceAugmentation;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VppInterfaceAugmentationBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.L2Builder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.VhostUser;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.VhostUserBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.l2.config.attributes.interconnection.BridgeBased;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.l2.config.attributes.interconnection.BridgeBasedBuilder;\r
-\r
-import com.google.common.base.Optional;\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 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
-                .setBridgedVirtualInterface(IS_BRIDGED_DEFAULT).setSplitHorizonGroup((short)0)\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.rev170607.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
+/*
+ * 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.commands;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.VppRendererDataBrokerTest;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+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.InterfaceBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VhostUserRole;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VppInterfaceAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VppInterfaceAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.L2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.VhostUser;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.VhostUserBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.l2.config.attributes.interconnection.BridgeBased;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.l2.config.attributes.interconnection.BridgeBasedBuilder;
+
+import com.google.common.base.Optional;
+
+public class VhostUserCommandTest extends VppRendererDataBrokerTest {
+
+    private final static String BRIDGE_DOMAIN = "testBD";
+    private final static String DESCRIPTION = "used for testing";
+    private final static String INTERFACE_NAME = "testInterface";
+    private final static String SOCKET_NAME = "soc1";
+
+    private final static String UPD_BRIDGE_DOMAIN = "testBD2";
+    private final static String UPD_DESCRIPTION = "updated description";
+    private final static String UPD_SOCKET_NAME = "soc2";
+    private final static boolean IS_BRIDGED_DEFAULT = false;
+
+    private static Interface BASIC_INTERFACE;
+
+    private DataBroker dataBroker;
+
+    @Before
+    public void init() {
+        dataBroker = getDataBroker();
+
+        VhostUser vhostUser = new VhostUserBuilder().setRole(VhostUserRole.Server).setSocket(SOCKET_NAME).build();
+
+        VppInterfaceAugmentation vppAugmentation = new VppInterfaceAugmentationBuilder().setVhostUser(vhostUser)
+            .setL2(new L2Builder().setInterconnection(new BridgeBasedBuilder().setBridgeDomain(BRIDGE_DOMAIN)
+                .setBridgedVirtualInterface(IS_BRIDGED_DEFAULT).setSplitHorizonGroup((short)0)
+                .build()).build())
+            .build();
+
+        BASIC_INTERFACE =
+                new InterfaceBuilder().setDescription(DESCRIPTION)
+                    .setEnabled(true)
+                    .setKey(new InterfaceKey(INTERFACE_NAME))
+                    .setName(INTERFACE_NAME)
+                    .setType(
+                            org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VhostUser.class)
+                    .setLinkUpDownTrapEnable(Interface.LinkUpDownTrapEnable.Enabled)
+                    .addAugmentation(VppInterfaceAugmentation.class, vppAugmentation)
+                    .build();
+    }
+
+    @Test
+    public void AddVhostTest() {
+        ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();
+        VhostUserCommand addCommand = VhostUserCommand.builder()
+            .setOperation(General.Operations.PUT)
+            .setName(INTERFACE_NAME)
+            .setDescription(DESCRIPTION)
+            .setRole(VhostUserRole.Server)
+            .setSocket(SOCKET_NAME)
+            .setBridgeDomain(BRIDGE_DOMAIN)
+            .setEnabled(true)
+            .build();
+
+        addCommand.execute(transaction);
+
+        transaction.submit();
+
+        ReadOnlyTransaction readOnlyTransaction = dataBroker.newReadOnlyTransaction();
+
+        Optional<Interface> optional = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+                VppIidFactory.getInterfaceIID(new InterfaceKey(INTERFACE_NAME)), readOnlyTransaction);
+
+        Assert.assertTrue("Interface was not written to DS", optional.isPresent());
+
+        Interface anInterface = optional.get();
+
+        Assert.assertEquals(BASIC_INTERFACE, anInterface);
+
+    }
+
+    @Test
+    public void DeleteVhostTest() {
+        ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();
+
+        transaction.put(LogicalDatastoreType.CONFIGURATION, VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()),
+                BASIC_INTERFACE, true);
+        transaction.submit();
+
+        Optional<Interface> optional = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+                VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()), dataBroker.newReadOnlyTransaction());
+
+        Assert.assertTrue("Interface was not written to DS", optional.isPresent());
+
+        VhostUserCommand deleteCommand = VhostUserCommand.builder()
+                .setOperation(General.Operations.DELETE)
+                .setName(INTERFACE_NAME)
+                .setSocket(SOCKET_NAME)
+                .build();
+
+        ReadWriteTransaction deleteTransaction = dataBroker.newReadWriteTransaction();
+        deleteCommand.execute(deleteTransaction);
+        deleteTransaction.submit();
+
+        Optional<Interface> optionalDeleted = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+                VppIidFactory.getInterfaceIID(new InterfaceKey(deleteCommand.getName())),
+                dataBroker.newReadOnlyTransaction());
+
+        Assert.assertFalse("Interface was not deleted from DS", optionalDeleted.isPresent());
+    }
+
+    @Test
+    public void UpdateVhostTest() {
+        ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();
+
+        transaction.put(LogicalDatastoreType.CONFIGURATION, VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()),
+                BASIC_INTERFACE, true);
+        transaction.submit();
+
+        Optional<Interface> optional = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+                VppIidFactory.getInterfaceIID(BASIC_INTERFACE.getKey()), dataBroker.newReadOnlyTransaction());
+
+        Assert.assertTrue("Interface was not written to DS", optional.isPresent());
+
+        VhostUserCommand updateCommand = VhostUserCommand.builder()
+            .setOperation(General.Operations.MERGE)
+            .setName(INTERFACE_NAME)
+            .setDescription(UPD_DESCRIPTION)
+            .setEnabled(false)
+            .setRole(VhostUserRole.Client)
+            .setSocket(UPD_SOCKET_NAME)
+            .setBridgeDomain(UPD_BRIDGE_DOMAIN)
+            .build();
+
+        ReadWriteTransaction deleteTransaction = dataBroker.newReadWriteTransaction();
+        updateCommand.execute(deleteTransaction);
+        deleteTransaction.submit();
+
+        Optional<Interface> optionalUpdated = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
+                VppIidFactory.getInterfaceIID(new InterfaceKey(updateCommand.getName())),
+                dataBroker.newReadOnlyTransaction());
+
+        Assert.assertTrue("Interface was not found in DS", optionalUpdated.isPresent());
+        Interface updatedInterface = optionalUpdated.get();
+
+        Assert.assertEquals(UPD_DESCRIPTION, updatedInterface.getDescription());
+        Assert.assertFalse(updatedInterface.isEnabled());
+        VppInterfaceAugmentation vppInterfaceAugmentation =
+                updatedInterface.getAugmentation(VppInterfaceAugmentation.class);
+        Assert.assertEquals(VhostUserRole.Client, vppInterfaceAugmentation.getVhostUser().getRole());
+        Assert.assertEquals(UPD_SOCKET_NAME, vppInterfaceAugmentation.getVhostUser().getSocket());
+
+        Assert.assertTrue(vppInterfaceAugmentation.getL2().getInterconnection() instanceof BridgeBased);
+
+        Assert.assertEquals(UPD_BRIDGE_DOMAIN,
+                ((BridgeBased) vppInterfaceAugmentation.getL2().getInterconnection()).getBridgeDomain());
+    }
+}
index bd46833866001b1a419be7dbdff354ac01a91f42..296bebcf3b0f22862ccce9dcb84f88a5e9109d5a 100644 (file)
-/*\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.sf;\r
-\r
-import org.junit.Before;\r
-import org.junit.Rule;\r
-import org.junit.Test;\r
-import org.junit.rules.ExpectedException;\r
-import org.opendaylight.groupbasedpolicy.api.sf.IpProtoClassifierDefinition;\r
-import org.opendaylight.groupbasedpolicy.api.sf.L4ClassifierDefinition;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ParameterName;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.parameter.value.RangeValueBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.parameters.type.ParameterType;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.parameters.type.parameter.type.Int;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.supported.classifier.definition.SupportedParameterValues;\r
-\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import static org.junit.Assert.*;\r
-\r
-public class L4ClassifierTest {\r
-\r
-    private ParameterValue pvSrcPort80;\r
-    private ParameterValue pvDstPort80;\r
-    private ParameterValue pvDstPort_null;\r
-    private ParameterValue pvSrcRange81_82;\r
-    private ParameterValue pvDstRange81_82;\r
-    private ParameterValue pvDstRange82_81;\r
-    private ParameterValue pvDstRange_null;\r
-    private Classifier l4Cl;\r
-\r
-    @Rule\r
-    public ExpectedException thrown = ExpectedException.none();\r
-\r
-    @Before\r
-    public void init() {\r
-        pvSrcPort80 = new ParameterValueBuilder().setName(\r
-                new ParameterName(L4ClassifierDefinition.SRC_PORT_PARAM)).setIntValue(80L).build();\r
-        pvDstPort80 = new ParameterValueBuilder().setName(\r
-                new ParameterName(L4ClassifierDefinition.DST_PORT_PARAM)).setIntValue(80L).build();\r
-        pvDstPort_null = new ParameterValueBuilder().setName(\r
-                new ParameterName(L4ClassifierDefinition.DST_PORT_PARAM)).build();\r
-        pvSrcRange81_82 = new ParameterValueBuilder().setName(\r
-                new ParameterName(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM))\r
-                .setRangeValue(new RangeValueBuilder().setMin(81L).setMax(82L).build())\r
-                .build();\r
-        pvDstRange81_82 = new ParameterValueBuilder().setName(\r
-                new ParameterName(L4ClassifierDefinition.DST_PORT_RANGE_PARAM))\r
-                .setRangeValue(new RangeValueBuilder().setMin(81L).setMax(82L).build())\r
-                .build();\r
-        pvDstRange82_81 = new ParameterValueBuilder().setName(\r
-                new ParameterName(L4ClassifierDefinition.DST_PORT_RANGE_PARAM))\r
-                .setRangeValue(new RangeValueBuilder().setMin(82L).setMax(81L).build())\r
-                .build();\r
-        pvDstRange_null = new ParameterValueBuilder().setName(\r
-                new ParameterName(L4ClassifierDefinition.DST_PORT_RANGE_PARAM))\r
-                //.setRangeValue(new RangeValueBuilder().setMin(82L).setMax(81L).build())\r
-                .build();\r
-        l4Cl = SubjectFeatures.getClassifier(L4ClassifierDefinition.ID);\r
-    }\r
-\r
-    @Test\r
-    public void testGetId() {\r
-        assertEquals(L4ClassifierDefinition.ID, l4Cl.getId());\r
-    }\r
-\r
-    @Test\r
-    public void testGetClassifierDefinition() {\r
-        assertEquals(L4ClassifierDefinition.DEFINITION, l4Cl.getClassifierDefinition());\r
-    }\r
-\r
-    @Test\r
-    public void testGetSupportedParameterValues() {\r
-        List<SupportedParameterValues> valuesList = l4Cl.getSupportedParameterValues();\r
-        assertEquals(4, valuesList.size());\r
-\r
-        SupportedParameterValues values = valuesList.get(0);\r
-        assertNotNull(values);\r
-        assertEquals(L4ClassifierDefinition.SRC_PORT_PARAM, values.getParameterName().getValue());\r
-        ParameterType pt = values.getParameterType();\r
-        assertTrue(pt instanceof Int);\r
-    }\r
-\r
-    @Test\r
-    public void testCheckPresenceOfRequiredParams_Empty() throws Exception {\r
-        // TODO check: sending empty map is ok?\r
-        l4Cl.checkPresenceOfRequiredParams(new HashMap<String, ParameterValue>());\r
-    }\r
-\r
-    @Test\r
-    public void testCheckPresenceOfRequiredParams_SinglePorts() throws Exception {\r
-        Map<String, ParameterValue> params = new HashMap<>();\r
-        params.put(L4ClassifierDefinition.SRC_PORT_PARAM, pvSrcPort80);\r
-        params.put(L4ClassifierDefinition.DST_PORT_PARAM, pvDstPort80);\r
-\r
-        l4Cl.checkPresenceOfRequiredParams(params);\r
-    }\r
-\r
-    @Test\r
-    public void testCheckPresenceOfRequiredParams_PortRanges() throws Exception {\r
-        Map<String, ParameterValue> params = new HashMap<>();\r
-        params.put(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM, pvSrcRange81_82);\r
-        params.put(L4ClassifierDefinition.DST_PORT_RANGE_PARAM, pvDstRange81_82);\r
-\r
-        l4Cl.checkPresenceOfRequiredParams(params);\r
-    }\r
-\r
-    @Test\r
-    public void testCheckPresenceOfRequiredParams_DstPortNull() throws IllegalArgumentException {\r
-        Map<String, ParameterValue> params = new HashMap<>();\r
-        params.put(L4ClassifierDefinition.SRC_PORT_PARAM, pvSrcPort80);\r
-        params.put(L4ClassifierDefinition.DST_PORT_PARAM, pvDstPort_null);\r
-\r
-        thrown.expect(IllegalArgumentException.class);\r
-        thrown.expectMessage(L4Classifier.EXC_MSG_PARAM_VALUE_NOT_SPECIFIED);\r
-        l4Cl.checkPresenceOfRequiredParams(params);\r
-    }\r
-\r
-    @Test\r
-    public void testCheckPresenceOfRequiredParams_DstRangeNull() throws IllegalArgumentException {\r
-        Map<String, ParameterValue> params = new HashMap<>();\r
-        params.put(L4ClassifierDefinition.SRC_PORT_PARAM, pvSrcPort80);\r
-        params.put(L4ClassifierDefinition.DST_PORT_RANGE_PARAM, pvDstRange_null);\r
-\r
-        thrown.expect(IllegalArgumentException.class);\r
-        thrown.expectMessage(L4Classifier.EXC_MSG_PARAM_VALUE_NOT_SPECIFIED);\r
-        l4Cl.checkPresenceOfRequiredParams(params);\r
-    }\r
-\r
-    @Test\r
-    public void testCheckPresenceOfRequiredParams_ParamConflict() throws IllegalArgumentException {\r
-        Map<String, ParameterValue> params = new HashMap<>();\r
-        params.put(L4ClassifierDefinition.SRC_PORT_PARAM, pvSrcPort80);\r
-        params.put(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM, pvSrcRange81_82);\r
-\r
-        thrown.expect(IllegalArgumentException.class);\r
-        thrown.expectMessage(L4Classifier.EXC_MSG_MUT_EXCLUSIVE_PARAMS);\r
-        l4Cl.checkPresenceOfRequiredParams(params);\r
-    }\r
-\r
-    @Test\r
-    public void testCheckPresenceOfRequiredParams_RangeInverted() throws IllegalArgumentException {\r
-        Map<String, ParameterValue> params = new HashMap<>();\r
-        params.put(L4ClassifierDefinition.SRC_PORT_PARAM, pvSrcPort80);\r
-        params.put(L4ClassifierDefinition.DST_PORT_RANGE_PARAM, pvDstRange82_81);\r
-\r
-        thrown.expect(IllegalArgumentException.class);\r
-        thrown.expectMessage(L4Classifier.EXC_MSG_RANGE_VALUE_MISMATCH);\r
-        l4Cl.checkPresenceOfRequiredParams(params);\r
-    }\r
-\r
-    @Test\r
-    public void testCheckPresenceOfRequiredParams_emptyParams() {\r
-\r
-        l4Cl.checkPresenceOfRequiredParams(new HashMap<String, ParameterValue>());\r
-    }\r
-\r
-    @Test\r
-    public void testGetParent() {\r
-        assertEquals(l4Cl.getParent(), SubjectFeatures.getClassifier(IpProtoClassifierDefinition.ID));\r
-    }\r
-\r
-}\r
+/*
+ * 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.sf;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.opendaylight.groupbasedpolicy.api.sf.IpProtoClassifierDefinition;
+import org.opendaylight.groupbasedpolicy.api.sf.L4ClassifierDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ParameterName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.parameter.value.RangeValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.parameters.type.ParameterType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.parameters.type.parameter.type.Int;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.supported.classifier.definition.SupportedParameterValues;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+public class L4ClassifierTest {
+
+    private ParameterValue pvSrcPort80;
+    private ParameterValue pvDstPort80;
+    private ParameterValue pvDstPort_null;
+    private ParameterValue pvSrcRange81_82;
+    private ParameterValue pvDstRange81_82;
+    private ParameterValue pvDstRange82_81;
+    private ParameterValue pvDstRange_null;
+    private Classifier l4Cl;
+
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
+
+    @Before
+    public void init() {
+        pvSrcPort80 = new ParameterValueBuilder().setName(
+                new ParameterName(L4ClassifierDefinition.SRC_PORT_PARAM)).setIntValue(80L).build();
+        pvDstPort80 = new ParameterValueBuilder().setName(
+                new ParameterName(L4ClassifierDefinition.DST_PORT_PARAM)).setIntValue(80L).build();
+        pvDstPort_null = new ParameterValueBuilder().setName(
+                new ParameterName(L4ClassifierDefinition.DST_PORT_PARAM)).build();
+        pvSrcRange81_82 = new ParameterValueBuilder().setName(
+                new ParameterName(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM))
+                .setRangeValue(new RangeValueBuilder().setMin(81L).setMax(82L).build())
+                .build();
+        pvDstRange81_82 = new ParameterValueBuilder().setName(
+                new ParameterName(L4ClassifierDefinition.DST_PORT_RANGE_PARAM))
+                .setRangeValue(new RangeValueBuilder().setMin(81L).setMax(82L).build())
+                .build();
+        pvDstRange82_81 = new ParameterValueBuilder().setName(
+                new ParameterName(L4ClassifierDefinition.DST_PORT_RANGE_PARAM))
+                .setRangeValue(new RangeValueBuilder().setMin(82L).setMax(81L).build())
+                .build();
+        pvDstRange_null = new ParameterValueBuilder().setName(
+                new ParameterName(L4ClassifierDefinition.DST_PORT_RANGE_PARAM))
+                //.setRangeValue(new RangeValueBuilder().setMin(82L).setMax(81L).build())
+                .build();
+        l4Cl = SubjectFeatures.getClassifier(L4ClassifierDefinition.ID);
+    }
+
+    @Test
+    public void testGetId() {
+        assertEquals(L4ClassifierDefinition.ID, l4Cl.getId());
+    }
+
+    @Test
+    public void testGetClassifierDefinition() {
+        assertEquals(L4ClassifierDefinition.DEFINITION, l4Cl.getClassifierDefinition());
+    }
+
+    @Test
+    public void testGetSupportedParameterValues() {
+        List<SupportedParameterValues> valuesList = l4Cl.getSupportedParameterValues();
+        assertEquals(4, valuesList.size());
+
+        SupportedParameterValues values = valuesList.get(0);
+        assertNotNull(values);
+        assertEquals(L4ClassifierDefinition.SRC_PORT_PARAM, values.getParameterName().getValue());
+        ParameterType pt = values.getParameterType();
+        assertTrue(pt instanceof Int);
+    }
+
+    @Test
+    public void testCheckPresenceOfRequiredParams_Empty() throws Exception {
+        // TODO check: sending empty map is ok?
+        l4Cl.checkPresenceOfRequiredParams(new HashMap<String, ParameterValue>());
+    }
+
+    @Test
+    public void testCheckPresenceOfRequiredParams_SinglePorts() throws Exception {
+        Map<String, ParameterValue> params = new HashMap<>();
+        params.put(L4ClassifierDefinition.SRC_PORT_PARAM, pvSrcPort80);
+        params.put(L4ClassifierDefinition.DST_PORT_PARAM, pvDstPort80);
+
+        l4Cl.checkPresenceOfRequiredParams(params);
+    }
+
+    @Test
+    public void testCheckPresenceOfRequiredParams_PortRanges() throws Exception {
+        Map<String, ParameterValue> params = new HashMap<>();
+        params.put(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM, pvSrcRange81_82);
+        params.put(L4ClassifierDefinition.DST_PORT_RANGE_PARAM, pvDstRange81_82);
+
+        l4Cl.checkPresenceOfRequiredParams(params);
+    }
+
+    @Test
+    public void testCheckPresenceOfRequiredParams_DstPortNull() throws IllegalArgumentException {
+        Map<String, ParameterValue> params = new HashMap<>();
+        params.put(L4ClassifierDefinition.SRC_PORT_PARAM, pvSrcPort80);
+        params.put(L4ClassifierDefinition.DST_PORT_PARAM, pvDstPort_null);
+
+        thrown.expect(IllegalArgumentException.class);
+        thrown.expectMessage(L4Classifier.EXC_MSG_PARAM_VALUE_NOT_SPECIFIED);
+        l4Cl.checkPresenceOfRequiredParams(params);
+    }
+
+    @Test
+    public void testCheckPresenceOfRequiredParams_DstRangeNull() throws IllegalArgumentException {
+        Map<String, ParameterValue> params = new HashMap<>();
+        params.put(L4ClassifierDefinition.SRC_PORT_PARAM, pvSrcPort80);
+        params.put(L4ClassifierDefinition.DST_PORT_RANGE_PARAM, pvDstRange_null);
+
+        thrown.expect(IllegalArgumentException.class);
+        thrown.expectMessage(L4Classifier.EXC_MSG_PARAM_VALUE_NOT_SPECIFIED);
+        l4Cl.checkPresenceOfRequiredParams(params);
+    }
+
+    @Test
+    public void testCheckPresenceOfRequiredParams_ParamConflict() throws IllegalArgumentException {
+        Map<String, ParameterValue> params = new HashMap<>();
+        params.put(L4ClassifierDefinition.SRC_PORT_PARAM, pvSrcPort80);
+        params.put(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM, pvSrcRange81_82);
+
+        thrown.expect(IllegalArgumentException.class);
+        thrown.expectMessage(L4Classifier.EXC_MSG_MUT_EXCLUSIVE_PARAMS);
+        l4Cl.checkPresenceOfRequiredParams(params);
+    }
+
+    @Test
+    public void testCheckPresenceOfRequiredParams_RangeInverted() throws IllegalArgumentException {
+        Map<String, ParameterValue> params = new HashMap<>();
+        params.put(L4ClassifierDefinition.SRC_PORT_PARAM, pvSrcPort80);
+        params.put(L4ClassifierDefinition.DST_PORT_RANGE_PARAM, pvDstRange82_81);
+
+        thrown.expect(IllegalArgumentException.class);
+        thrown.expectMessage(L4Classifier.EXC_MSG_RANGE_VALUE_MISMATCH);
+        l4Cl.checkPresenceOfRequiredParams(params);
+    }
+
+    @Test
+    public void testCheckPresenceOfRequiredParams_emptyParams() {
+
+        l4Cl.checkPresenceOfRequiredParams(new HashMap<String, ParameterValue>());
+    }
+
+    @Test
+    public void testGetParent() {
+        assertEquals(l4Cl.getParent(), SubjectFeatures.getClassifier(IpProtoClassifierDefinition.ID));
+    }
+
+}