summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/test/java/io/fd
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2016-05-16 15:04:18 +0200
committerMarek Gradzki <mgradzki@cisco.com>2016-05-19 12:47:18 +0000
commit5e8c6b50b595ef2098a1a53702ca3bee4222c483 (patch)
tree730ec844214b47af420e7abc65e5f5c9ab56efd7 /v3po/v3po2vpp/src/test/java/io/fd
parent7ded4b3e6cb22abfa5d96ada5be2cda764d106fa (diff)
HONEYCOMB-48: vlan tag rewrite support
Change-Id: Id20aa699db1fd48b253b3abb1b4341e779a9b98f Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/test/java/io/fd')
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VlanTagRewriteCustomizerTest.java232
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VlanTagRewriteCustomizerTest.java97
2 files changed, 329 insertions, 0 deletions
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VlanTagRewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VlanTagRewriteCustomizerTest.java
new file mode 100644
index 000000000..ae768145a
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VlanTagRewriteCustomizerTest.java
@@ -0,0 +1,232 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.v3po.translate.v3po.interfaces;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
+import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException;
+import io.fd.honeycomb.v3po.translate.write.WriteContext;
+import io.fd.honeycomb.v3po.translate.write.WriteFailedException;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+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.opendaylight.params.xml.ns.yang.v3po.rev150105.TagRewriteOperation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VlanTag;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VlanType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.L2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.l2.VlanTagRewrite;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.l2.VlanTagRewriteBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.openvpp.jvpp.dto.L2InterfaceVlanTagRewrite;
+import org.openvpp.jvpp.dto.L2InterfaceVlanTagRewriteReply;
+import org.openvpp.jvpp.future.FutureJVpp;
+
+public class VlanTagRewriteCustomizerTest {
+
+ @Mock
+ private FutureJVpp api;
+ @Mock
+ private WriteContext writeContext;
+
+ private NamingContext namingContext;
+ private VlanTagRewriteCustomizer customizer;
+
+ public static final String VLAN_IF_NAME = "local0.0";
+ public static final int VLAN_IF_ID = 1;
+
+ @Before
+ public void setUp() throws Exception {
+ initMocks(this);
+ namingContext = new NamingContext("generatedSubInterfaceName");
+ customizer = new VlanTagRewriteCustomizer(api, namingContext);
+ namingContext.addName(VLAN_IF_ID, VLAN_IF_NAME);
+ }
+
+ private InstanceIdentifier<VlanTagRewrite> getVlanTagRewriteId(final String name) {
+ return InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(name)).augmentation(
+ VppInterfaceAugmentation.class).child(L2.class).child(VlanTagRewrite.class);
+ }
+
+ private VlanTagRewrite generateVlanTagRewrite(final int vtrOp) {
+ final VlanTagRewriteBuilder builder = new VlanTagRewriteBuilder();
+ builder.setRewriteOperation(TagRewriteOperation.forValue(vtrOp));
+ builder.setTag1(new VlanTag(100));
+ builder.setTag2(new VlanTag(200));
+ builder.setFirstPushed(VlanType._802dot1ad);
+ return builder.build();
+ }
+
+ private L2InterfaceVlanTagRewrite generateL2InterfaceVlanTagRewrite(final int superIfId, final int vtrOp) {
+ final L2InterfaceVlanTagRewrite request = new L2InterfaceVlanTagRewrite();
+ request.swIfIndex = superIfId;
+ request.vtrOp = vtrOp;
+ request.pushDot1Q = 0;
+ request.tag1 = 100;
+ request.tag2 = 200;
+ return request;
+ }
+
+ private void whenL2InterfaceVlanTagRewriteThen(final int retval) throws ExecutionException, InterruptedException {
+ final CompletableFuture<L2InterfaceVlanTagRewriteReply> replyFuture = new CompletableFuture<>();
+ final L2InterfaceVlanTagRewriteReply reply = new L2InterfaceVlanTagRewriteReply();
+ reply.retval = retval;
+ replyFuture.complete(reply);
+ doReturn(replyFuture).when(api).l2InterfaceVlanTagRewrite(any(L2InterfaceVlanTagRewrite.class));
+ }
+
+ private void whenL2InterfaceVlanTagRewriteThenSuccess() throws ExecutionException, InterruptedException {
+ whenL2InterfaceVlanTagRewriteThen(0);
+ }
+
+ private void whenL2InterfaceVlanTagRewriteThenFailure() throws ExecutionException, InterruptedException {
+ whenL2InterfaceVlanTagRewriteThen(-1);
+ }
+
+ private void verifyL2InterfaceVlanTagRewriteWasInvoked(final L2InterfaceVlanTagRewrite expected) {
+ ArgumentCaptor<L2InterfaceVlanTagRewrite> argumentCaptor = ArgumentCaptor.forClass(L2InterfaceVlanTagRewrite.class);
+ verify(api).l2InterfaceVlanTagRewrite(argumentCaptor.capture());
+ final L2InterfaceVlanTagRewrite actual = argumentCaptor.getValue();
+ assertEquals(expected.swIfIndex, actual.swIfIndex);
+ assertEquals(expected.vtrOp, actual.vtrOp);
+ assertEquals(expected.pushDot1Q, actual.pushDot1Q);
+ assertEquals(expected.tag1, actual.tag1);
+ assertEquals(expected.tag2, actual.tag2);
+ }
+
+ private void verifyL2InterfaceVlanTagRewriteDeleteWasInvoked() {
+ final L2InterfaceVlanTagRewrite request = new L2InterfaceVlanTagRewrite();
+ request.swIfIndex = VLAN_IF_ID;
+ verifyL2InterfaceVlanTagRewriteWasInvoked(request);
+ }
+
+ @Test
+ public void testCreate() throws Exception {
+ final int vtrOp = 6;
+ final VlanTagRewrite vlanTagRewrite = generateVlanTagRewrite(vtrOp);
+ final InstanceIdentifier<VlanTagRewrite> id = getVlanTagRewriteId(VLAN_IF_NAME);
+
+ whenL2InterfaceVlanTagRewriteThenSuccess();
+
+ customizer.writeCurrentAttributes(id, vlanTagRewrite, writeContext);
+
+ verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_ID, vtrOp));
+ }
+
+ @Test
+ public void testCreateFailed() throws Exception {
+ final int vtrOp = 6;
+ final VlanTagRewrite vlanTagRewrite = generateVlanTagRewrite(vtrOp);
+ final InstanceIdentifier<VlanTagRewrite> id = getVlanTagRewriteId(VLAN_IF_NAME);
+
+ whenL2InterfaceVlanTagRewriteThenFailure();
+
+ try {
+ customizer.writeCurrentAttributes(id, vlanTagRewrite, writeContext);
+ } catch (WriteFailedException.CreateFailedException e) {
+ assertEquals(VppApiInvocationException.class, e.getCause().getClass());
+ verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_ID, vtrOp));
+ return;
+ }
+ fail("WriteFailedException.CreateFailedException was expected");
+ }
+
+ @Test
+ public void testUpdateNoChange() throws Exception {
+ final VlanTagRewrite before = generateVlanTagRewrite(6);
+ final VlanTagRewrite after = generateVlanTagRewrite(6);
+ customizer.updateCurrentAttributes(null, before, after, writeContext);
+ verify(api, never()).l2InterfaceVlanTagRewrite(any());
+ }
+
+ @Test
+ public void testUpdate() throws Exception {
+ final int vtrOpAfter = 5;
+ final VlanTagRewrite before = generateVlanTagRewrite(6);
+ final VlanTagRewrite after = generateVlanTagRewrite(vtrOpAfter);
+ final InstanceIdentifier<VlanTagRewrite> id = getVlanTagRewriteId(VLAN_IF_NAME);
+
+ whenL2InterfaceVlanTagRewriteThenSuccess();
+
+ customizer.updateCurrentAttributes(id, before, after, writeContext);
+
+ verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_ID, vtrOpAfter));
+ }
+
+ @Test
+ public void testUpdateFailed() throws Exception {
+ final int vtrOpAfter = 5;
+ final VlanTagRewrite before = generateVlanTagRewrite(6);
+ final VlanTagRewrite after = generateVlanTagRewrite(vtrOpAfter);
+ final InstanceIdentifier<VlanTagRewrite> id = getVlanTagRewriteId(VLAN_IF_NAME);
+
+ whenL2InterfaceVlanTagRewriteThenFailure();
+
+ try {
+ customizer.updateCurrentAttributes(id, before, after, writeContext);
+ } catch (WriteFailedException.UpdateFailedException e) {
+ assertEquals(VppApiInvocationException.class, e.getCause().getClass());
+ verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_ID, vtrOpAfter));
+ return;
+ }
+ fail("WriteFailedException.UpdateFailedException was expected");
+ }
+
+ @Test
+ public void testDelete() throws Exception {
+ final VlanTagRewriteBuilder builder = new VlanTagRewriteBuilder();
+ builder.setRewriteOperation(TagRewriteOperation.Disabled);
+ final InstanceIdentifier<VlanTagRewrite> id = getVlanTagRewriteId(VLAN_IF_NAME);
+
+ whenL2InterfaceVlanTagRewriteThenSuccess();
+
+ customizer.deleteCurrentAttributes(id, builder.build(), writeContext);
+
+ verifyL2InterfaceVlanTagRewriteDeleteWasInvoked();
+ }
+
+ @Test
+ public void testDeleteFailed() throws Exception {
+ final VlanTagRewriteBuilder builder = new VlanTagRewriteBuilder();
+ builder.setRewriteOperation(TagRewriteOperation.Disabled);
+ final InstanceIdentifier<VlanTagRewrite> id = getVlanTagRewriteId(VLAN_IF_NAME);
+
+ whenL2InterfaceVlanTagRewriteThenFailure();
+
+ try {
+ customizer.deleteCurrentAttributes(id, builder.build(), writeContext);
+ } catch (WriteFailedException.DeleteFailedException e) {
+ assertEquals(VppApiInvocationException.class, e.getCause().getClass());
+ verifyL2InterfaceVlanTagRewriteDeleteWasInvoked();
+ return;
+ }
+ fail("WriteFailedException.DeleteFailedException was expected");
+ }
+} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VlanTagRewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VlanTagRewriteCustomizerTest.java
new file mode 100644
index 000000000..2263160e3
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VlanTagRewriteCustomizerTest.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.v3po.translate.v3po.interfacesstate;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+import io.fd.honeycomb.v3po.translate.Context;
+import io.fd.honeycomb.v3po.translate.read.ReadFailedException;
+import io.fd.honeycomb.v3po.translate.spi.read.RootReaderCustomizer;
+import io.fd.honeycomb.v3po.translate.v3po.test.ChildReaderCustomizerTest;
+import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.TagRewriteOperation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VlanType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.L2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.L2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.l2.VlanTagRewrite;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.l2.VlanTagRewriteBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.openvpp.jvpp.dto.SwInterfaceDetails;
+
+public class VlanTagRewriteCustomizerTest extends ChildReaderCustomizerTest<VlanTagRewrite, VlanTagRewriteBuilder> {
+
+ private NamingContext interfacesContext;
+
+ public VlanTagRewriteCustomizerTest() {
+ super(VlanTagRewrite.class);
+ }
+
+ @Override
+ public void setUpBefore() {
+ interfacesContext = new NamingContext("generatedIfaceName");
+ }
+
+
+ @Override
+ protected RootReaderCustomizer<VlanTagRewrite, VlanTagRewriteBuilder> initCustomizer() {
+ return new VlanTagRewriteCustomizer(api, interfacesContext);
+ }
+
+ @Test
+ public void testMerge() {
+ final L2Builder builder = mock(L2Builder.class);
+ final VlanTagRewrite value = mock(VlanTagRewrite.class);
+ getCustomizer().merge(builder, value);
+ verify(builder).setVlanTagRewrite(value);
+ }
+
+ private InstanceIdentifier<VlanTagRewrite> getVlanTagRewriteId(final String name) {
+ return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(name)).augmentation(
+ VppInterfaceStateAugmentation.class).child(L2.class).child(VlanTagRewrite.class);
+ }
+
+ @Test
+ public void testRead() throws ReadFailedException {
+ final Context ctx = new Context();
+ final Map<Integer, SwInterfaceDetails> cachedInterfaceDump = new HashMap<>();
+ final int ifId = 1;
+ final String ifName = "eth0.sub0";
+ interfacesContext.addName(ifId, ifName);
+ final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails();
+ ifaceDetails.subId = ifId;
+ cachedInterfaceDump.put(ifId, ifaceDetails);
+ ctx.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump);
+
+ final VlanTagRewriteBuilder builder = mock(VlanTagRewriteBuilder.class);
+ getCustomizer().readCurrentAttributes(getVlanTagRewriteId(ifName), builder, ctx);
+
+ verify(builder).setFirstPushed(VlanType._802dot1ad);
+ verify(builder).setRewriteOperation(TagRewriteOperation.Disabled);
+ verify(builder, never()).setTag1(any());
+ verify(builder, never()).setTag2(any());
+ }
+} \ No newline at end of file