<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.openflowplugin.model</groupId>
+ <artifactId>model-flow-base</artifactId>
+ <version>0.3.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<!-- project build -->
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.config.yang.config.vpp_provider.impl;
+
+import com.google.common.base.Optional;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.MountPoint;
+import org.opendaylight.controller.md.sal.binding.api.MountPointService;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.VppRendererDataBrokerTest;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+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.capabilities.SupportedActionDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.SupportedClassifierDefinition;
+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 java.util.List;
+
+@RunWith(MockitoJUnitRunner.class)
+public class VppRendererTest extends VppRendererDataBrokerTest {
+ private final String CLASSIFIER = "Classifier-EtherType";
+ private final String ACTION_ALLOW = "Action-Allow";
+ private final String SUPPORTED_PARAM_NAME = "ethertype";
+
+ private DataBroker dataBroker;
+ @Mock
+ DataBroker dataBroker2;
+ @Mock
+ BindingAwareBroker bindingAwareBroker;
+ @Mock
+ MountPointService mountPointService;
+ @Mock
+ MountPoint mountPoint;
+ @Mock
+ BindingAwareBroker.ProviderContext providerContext;
+
+ @Before
+ public void init(){
+ dataBroker = getDataBroker();
+ Mockito.when(providerContext.getSALService(Matchers.<Class<MountPointService>>any()))
+ .thenReturn(mountPointService);
+ Mockito.when(mountPointService.getMountPoint(Matchers.<InstanceIdentifier<Node>>any()))
+ .thenReturn(Optional.of(mountPoint));
+ Mockito.when(mountPoint.getService(Matchers.<Class<DataBroker>>any())).thenReturn(Optional.of(dataBroker2));
+
+
+ }
+
+ @Test
+ public void testCreateVppRenderer() throws Exception {
+ VppRenderer vppRenderer = new VppRenderer(dataBroker, bindingAwareBroker);
+
+ vppRenderer.onSessionInitiated(providerContext);
+
+ Optional<Renderer> rendererOptional = DataStoreHelper.readFromDs(
+ LogicalDatastoreType.OPERATIONAL,
+ VppIidFactory.getRendererIID(new RendererKey(VppRenderer.NAME)),
+ dataBroker.newReadOnlyTransaction());
+
+ Assert.assertTrue(rendererOptional.isPresent());
+ Renderer renderer = rendererOptional.get();
+ Assert.assertEquals(VppRenderer.NAME, renderer.getName());
+ List<SupportedClassifierDefinition> definition = renderer.getCapabilities().getSupportedClassifierDefinition();
+ Assert.assertEquals(1, definition.size());
+ Assert.assertEquals(CLASSIFIER, definition.get(0).getClassifierDefinitionId().getValue());
+ Assert.assertEquals(SUPPORTED_PARAM_NAME, definition.get(0).getSupportedParameterValues().get(0).getParameterName().getValue());
+
+ List<SupportedActionDefinition> actionDefinition = renderer.getCapabilities().getSupportedActionDefinition();
+ Assert.assertEquals(1, actionDefinition.size());
+ Assert.assertEquals(ACTION_ALLOW, actionDefinition.get(0).getActionDefinitionId().getValue());
+ Assert.assertTrue(actionDefinition.get(0).getSupportedParameterValues().isEmpty());
+
+ vppRenderer.close();
+ rendererOptional = DataStoreHelper.readFromDs(
+ LogicalDatastoreType.OPERATIONAL,
+ VppIidFactory.getRendererIID(new RendererKey(VppRenderer.NAME)),
+ dataBroker.newReadOnlyTransaction());
+ Assert.assertFalse(rendererOptional.isPresent());
+ }
+}
import com.google.common.collect.ImmutableList;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.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.v3po.rev150105.interfaces._interface.VhostUser;\r
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;\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);\r
+ Topology.class, Node.class, NetconfNode.class, Renderer.class, LocationProviders.class, Config.class);\r
}\r
}\r
--- /dev/null
+/*
+ * 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.Assert;
+import org.junit.Test;
+import org.opendaylight.groupbasedpolicy.api.sf.AllowActionDefinition;
+
+public class AllowActionTest {
+
+ @Test
+ public void testAllowAction_BasicParams() {
+ AllowAction allowAction = new AllowAction();
+
+ Assert.assertTrue(allowAction.getSupportedParameterValues().isEmpty());
+ Assert.assertEquals(AllowActionDefinition.DEFINITION, allowAction.getActionDef());
+ Assert.assertEquals(AllowActionDefinition.ID, allowAction.getId());
+ }
+}
--- /dev/null
+/*
+ * 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 java.util.Map;
+
+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 com.google.common.collect.ImmutableMap;
+
+public class ClassifierTestUtils {
+
+ public static final String MSG_NOT_SPECIFIED = "not specified";
+ public static final String MSG_PARAMETER_IS_NOT_PRESENT = "parameter is not present";
+ public static final String SUPPORTED_PARAM_NAME_ETH = "ethertype";
+ public static final String SUPPORTED_PARAM_NAME_IP = "proto";
+
+ static final Long TCP = 6L;
+
+ static Map<String, ParameterValue> createIntValueParam(String paramName, Long value) {
+ if (value == null)
+ return ImmutableMap.of(paramName, new ParameterValueBuilder().build());
+ else
+ return ImmutableMap.of(paramName, new ParameterValueBuilder().setIntValue(value).build());
+ }
+}
--- /dev/null
+/*
+ * 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 java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.opendaylight.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition;
+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.renderer.rev151103.renderers.renderer.capabilities.supported.classifier.definition.SupportedParameterValues;
+
+public class EtherTypeClassifierTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void testGetSupportedParameterValues() {
+ List<SupportedParameterValues> supportedParameterValues =
+ Classifier.ETHER_TYPE_CL.getSupportedParameterValues();
+
+ Assert.assertEquals(1, supportedParameterValues.size());
+ Assert.assertEquals(ClassifierTestUtils.SUPPORTED_PARAM_NAME_ETH,
+ supportedParameterValues.get(0).getParameterName().getValue());
+
+ Assert.assertEquals(EtherTypeClassifierDefinition.DEFINITION,
+ Classifier.ETHER_TYPE_CL.getClassifierDefinition());
+ Assert.assertEquals(EtherTypeClassifierDefinition.ID, Classifier.ETHER_TYPE_CL.getId());
+ Assert.assertNull(Classifier.ETHER_TYPE_CL.getParent());
+ }
+
+ @Test
+ public void testCheckPresenceOfRequiredParameters_EtherTypeMissing() {
+ Map<String, ParameterValue> params = new HashMap<>();
+ params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
+ ClassifierTestUtils.TCP));
+
+ thrown.expect(IllegalArgumentException.class);
+ thrown.expectMessage(ClassifierTestUtils.MSG_NOT_SPECIFIED);
+ Classifier.ETHER_TYPE_CL.checkPresenceOfRequiredParams(params);
+ }
+
+ @Test
+ public void testCheckPresenceOfRequiredParameters_EtherTypeNull() {
+ Map<String, ParameterValue> params = new HashMap<>();
+ params.putAll(ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, null));
+
+ thrown.expect(IllegalArgumentException.class);
+ thrown.expectMessage(ClassifierTestUtils.MSG_PARAMETER_IS_NOT_PRESENT);
+ Classifier.ETHER_TYPE_CL.checkPresenceOfRequiredParams(params);
+ }
+}
--- /dev/null
+/*
+ * 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 java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.opendaylight.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition;
+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.renderer.rev151103.renderers.renderer.capabilities.supported.classifier.definition.SupportedParameterValues;
+
+public class IpProtoClassifierTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void testGetSupportedParameterValues() {
+ List<SupportedParameterValues> supportedParameterValues = Classifier.IP_PROTO_CL.getSupportedParameterValues();
+
+ Assert.assertEquals(1, supportedParameterValues.size());
+ Assert.assertEquals(ClassifierTestUtils.SUPPORTED_PARAM_NAME_IP,
+ supportedParameterValues.get(0).getParameterName().getValue());
+
+ Assert.assertEquals(IpProtoClassifierDefinition.DEFINITION, Classifier.IP_PROTO_CL.getClassifierDefinition());
+ Assert.assertEquals(IpProtoClassifierDefinition.ID, Classifier.IP_PROTO_CL.getId());
+ Assert.assertEquals(Classifier.ETHER_TYPE_CL, Classifier.IP_PROTO_CL.getParent());
+ }
+
+ @Test
+ public void testCheckPresenceOfRequiredParameters_ProtoMissing() {
+ Map<String, ParameterValue> params = new HashMap<>();
+ params.putAll(ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM,
+ EtherTypeClassifierDefinition.IPv4_VALUE));
+
+ Assert.assertNull(IpProtoClassifier.getIpProtoValue(params));
+
+ thrown.expect(IllegalArgumentException.class);
+ thrown.expectMessage(ClassifierTestUtils.MSG_NOT_SPECIFIED);
+ Classifier.IP_PROTO_CL.checkPresenceOfRequiredParams(params);
+ }
+
+ @Test
+ public void testCheckPresenceOfRequiredParameters_ProtoNull() {
+ Map<String, ParameterValue> params = new HashMap<>();
+ params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM, null));
+
+ Assert.assertNull(IpProtoClassifier.getIpProtoValue(params));
+
+ thrown.expect(IllegalArgumentException.class);
+ thrown.expectMessage(ClassifierTestUtils.MSG_PARAMETER_IS_NOT_PRESENT);
+ Classifier.IP_PROTO_CL.checkPresenceOfRequiredParams(params);
+ }
+
+ @Test
+ public void testCheckPresenceOfRequiredParameters() {
+ Map<String, ParameterValue> params = new HashMap<>();
+ params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
+ IpProtoClassifierDefinition.TCP_VALUE));
+
+ Classifier.IP_PROTO_CL.checkPresenceOfRequiredParams(params);
+
+ Assert.assertEquals(ClassifierTestUtils.TCP, IpProtoClassifier.getIpProtoValue(params));
+ }
+}