summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2
diff options
context:
space:
mode:
Diffstat (limited to 'v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2')
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/ArpTerminationTableEntryCustomizerTest.java192
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/BridgeDomainCustomizerTest.java338
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/L2FibEntryCustomizerTest.java283
3 files changed, 813 insertions, 0 deletions
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/ArpTerminationTableEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/ArpTerminationTableEntryCustomizerTest.java
new file mode 100644
index 000000000..29caf068b
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/ArpTerminationTableEntryCustomizerTest.java
@@ -0,0 +1,192 @@
+/*
+ * 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.hc2vpp.v3po.l2;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.VppBaseCallException;
+import io.fd.vpp.jvpp.VppInvocationException;
+import io.fd.vpp.jvpp.core.dto.BdIpMacAddDel;
+import io.fd.vpp.jvpp.core.dto.BdIpMacAddDelReply;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+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.Ipv4AddressNoZone;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
+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.rev161214.BridgeDomains;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.ArpTerminationTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.arp.termination.table.ArpTerminationTableEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.arp.termination.table.ArpTerminationTableEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.arp.termination.table.ArpTerminationTableEntryKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomainKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class ArpTerminationTableEntryCustomizerTest extends WriterCustomizerTest {
+ private static final String BD_CTX_NAME = "bd-test-instance";
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+
+ private static final String BD_NAME = "testBD0";
+ private static final int BD_ID = 111;
+ private static final String IFACE_NAME = "eth0";
+ private static final int IFACE_ID = 123;
+ private ArpTerminationTableEntryCustomizer customizer;
+ private byte[] ipAddressRaw;
+ private byte[] ip6AddressRaw;
+ private byte[] physAddressRaw;
+ private PhysAddress physAddress;
+ private IpAddress ipAddress;
+ private IpAddress ip6Address;
+ private ArpTerminationTableEntry entry;
+ private ArpTerminationTableEntry ip6entry;
+ private InstanceIdentifier<ArpTerminationTableEntry> id;
+
+ private static InstanceIdentifier<ArpTerminationTableEntry> getArpEntryId(final IpAddress ipAddress,
+ final PhysAddress physAddress) {
+ return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(BD_NAME))
+ .child(ArpTerminationTable.class)
+ .child(ArpTerminationTableEntry.class, new ArpTerminationTableEntryKey(ipAddress, physAddress));
+ }
+
+ @Override
+ public void setUpTest() throws Exception {
+ customizer = new ArpTerminationTableEntryCustomizer(api, new NamingContext("generatedBdName", BD_CTX_NAME));
+
+ ipAddressRaw = new byte[]{1, 2, 3, 4};
+ ip6AddressRaw = new byte[]{32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 1};
+ physAddressRaw = new byte[]{1, 2, 3, 4, 5, 6};
+ physAddress = new PhysAddress("01:02:03:04:05:06");
+
+ ipAddress = new IpAddress(Ipv4AddressNoZone.getDefaultInstance("1.2.3.4"));
+ ip6Address = new IpAddress(Ipv6AddressNoZone.getDefaultInstance("2001:0db8:0a0b:12f0:0000:0000:0000:0001"));
+ entry = generateArpEntry(ipAddress, physAddress);
+ ip6entry = generateArpEntry(ip6Address, physAddress);
+ id = getArpEntryId(ipAddress, physAddress);
+
+ defineMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ }
+
+ private void whenBdIpMacAddDelThenSuccess() {
+ doReturn(future(new BdIpMacAddDelReply())).when(api).bdIpMacAddDel(any(BdIpMacAddDel.class));
+ }
+
+ private void whenBdIpMacAddDelThenFailure() {
+ doReturn(failedFuture()).when(api).bdIpMacAddDel(any(BdIpMacAddDel.class));
+ }
+
+ private BdIpMacAddDel generateBdIpMacAddDelRequest(final byte[] ipAddress, final byte[] macAddress,
+ final byte isAdd) {
+ final BdIpMacAddDel request = new BdIpMacAddDel();
+ request.ipAddress = ipAddress;
+ request.macAddress = macAddress;
+ request.bdId = BD_ID;
+ request.isAdd = isAdd;
+ return request;
+ }
+
+ private ArpTerminationTableEntry generateArpEntry(final IpAddress ipAddress, final PhysAddress physAddress) {
+ final ArpTerminationTableEntryBuilder entry = new ArpTerminationTableEntryBuilder();
+ entry.setKey(new ArpTerminationTableEntryKey(ipAddress, physAddress));
+ entry.setPhysAddress(physAddress);
+ entry.setIpAddress(ipAddress);
+ return entry.build();
+ }
+
+ private void verifyBdIpMacAddDelWasInvoked(final BdIpMacAddDel expected) throws
+ VppInvocationException {
+ ArgumentCaptor<BdIpMacAddDel> argumentCaptor = ArgumentCaptor.forClass(BdIpMacAddDel.class);
+ verify(api).bdIpMacAddDel(argumentCaptor.capture());
+ final BdIpMacAddDel actual = argumentCaptor.getValue();
+ assertArrayEquals(expected.macAddress, actual.macAddress);
+ assertArrayEquals(expected.ipAddress, actual.ipAddress);
+ assertEquals(expected.bdId, actual.bdId);
+ assertEquals(expected.isAdd, actual.isAdd);
+ }
+
+ @Test
+ public void testCreate() throws Exception {
+ whenBdIpMacAddDelThenSuccess();
+ customizer.writeCurrentAttributes(id, entry, writeContext);
+ verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ipAddressRaw, physAddressRaw, (byte) 1));
+ }
+
+ @Test
+ public void testCreateIpv6() throws Exception {
+ whenBdIpMacAddDelThenSuccess();
+ customizer.writeCurrentAttributes(id, ip6entry, writeContext);
+ verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ip6AddressRaw, physAddressRaw, (byte) 1));
+ }
+
+ @Test
+ public void testCreateFailed() throws Exception {
+ whenBdIpMacAddDelThenFailure();
+ try {
+ customizer.writeCurrentAttributes(id, entry, writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppBaseCallException);
+ verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ipAddressRaw, physAddressRaw, (byte) 1));
+ return;
+ }
+ fail("WriteFailedException.CreateFailedException was expected");
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testUpdate() throws Exception {
+ customizer.updateCurrentAttributes(InstanceIdentifier.create(ArpTerminationTableEntry.class),
+ mock(ArpTerminationTableEntry.class),
+ mock(ArpTerminationTableEntry.class), writeContext);
+ }
+
+ @Test
+ public void testDelete() throws Exception {
+ whenBdIpMacAddDelThenSuccess();
+ customizer.deleteCurrentAttributes(id, entry, writeContext);
+ verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ipAddressRaw, physAddressRaw, (byte) 0));
+ }
+
+ @Test
+ public void testDeleteIpv6() throws Exception {
+ whenBdIpMacAddDelThenSuccess();
+ customizer.deleteCurrentAttributes(id, ip6entry, writeContext);
+ verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ip6AddressRaw, physAddressRaw, (byte) 0));
+ }
+
+ @Test
+ public void testDeleteFailed() throws Exception {
+ whenBdIpMacAddDelThenFailure();
+ try {
+ customizer.deleteCurrentAttributes(id, entry, writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppBaseCallException);
+ verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ipAddressRaw, physAddressRaw, (byte) 0));
+ return;
+ }
+ fail("WriteFailedException.DeleteFailedException was expected");
+ }
+} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/BridgeDomainCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/BridgeDomainCustomizerTest.java
new file mode 100644
index 000000000..8bf7007fe
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/BridgeDomainCustomizerTest.java
@@ -0,0 +1,338 @@
+/*
+ * 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.hc2vpp.v3po.l2;
+
+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.Mockito.when;
+
+import com.google.common.base.Optional;
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.VppInvocationException;
+import io.fd.vpp.jvpp.core.dto.BridgeDomainAddDel;
+import io.fd.vpp.jvpp.core.dto.BridgeDomainAddDelReply;
+import java.util.Arrays;
+import javax.annotation.Nullable;
+import org.junit.Test;
+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.InterfacesBuilder;
+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.opendaylight.params.xml.ns.yang.v3po.rev161214.BridgeDomains;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomainBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomainKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.L2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.base.attributes.interconnection.BridgeBasedBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator {
+
+ private static final String BD_CTX_NAME = "bd-test-instance";
+ private static final byte ADD_OR_UPDATE_BD = (byte) 1;
+ private BridgeDomainCustomizer customizer;
+
+ @Nullable
+ private static Boolean intToBoolean(final int value) {
+ if (value == 0) {
+ return Boolean.FALSE;
+ }
+ if (value == 1) {
+ return Boolean.TRUE;
+ }
+ return null;
+ }
+
+ private static KeyedInstanceIdentifier<BridgeDomain, BridgeDomainKey> bdIdentifierForName(
+ final String bdName) {
+ return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(bdName));
+ }
+
+ @Override
+ public void setUpTest() throws Exception {
+ customizer = new BridgeDomainCustomizer(api, new NamingContext("generatedBDName", BD_CTX_NAME));
+ }
+
+ private BridgeDomain generateBridgeDomain(final String bdName) {
+ final byte arpTerm = 0;
+ final byte flood = 1;
+ final byte forward = 0;
+ final byte learn = 1;
+ final byte uuf = 0;
+ return generateBridgeDomain(bdName, arpTerm, flood, forward, learn, uuf);
+ }
+
+ private BridgeDomain generateBridgeDomain(final String bdName, final int arpTerm, final int flood,
+ final int forward, final int learn, final int uuf) {
+ return new BridgeDomainBuilder()
+ .setName(bdName)
+ .setArpTermination(intToBoolean(arpTerm))
+ .setFlood(intToBoolean(flood))
+ .setForward(intToBoolean(forward))
+ .setLearn(intToBoolean(learn))
+ .setUnknownUnicastFlood(intToBoolean(uuf))
+ .build();
+ }
+
+ private void verifyBridgeDomainAddOrUpdateWasInvoked(final BridgeDomain bd, final int bdId)
+ throws VppInvocationException {
+ final BridgeDomainAddDel expected = new BridgeDomainAddDel();
+ expected.arpTerm = booleanToByte(bd.isArpTermination());
+ expected.flood = booleanToByte(bd.isFlood());
+ expected.forward = booleanToByte(bd.isForward());
+ expected.learn = booleanToByte(bd.isLearn());
+ expected.uuFlood = booleanToByte(bd.isUnknownUnicastFlood());
+ expected.isAdd = ADD_OR_UPDATE_BD;
+ expected.bdId = bdId;
+ verify(api).bridgeDomainAddDel(expected);
+ }
+
+ private void verifyBridgeDomainDeleteWasInvoked(final int bdId) throws VppInvocationException {
+ final BridgeDomainAddDel expected = new BridgeDomainAddDel();
+ expected.bdId = bdId;
+ verify(api).bridgeDomainAddDel(expected);
+ }
+
+ private void whenBridgeDomainAddDelThenSuccess() {
+ when(api.bridgeDomainAddDel(any(BridgeDomainAddDel.class))).thenReturn(future(new BridgeDomainAddDelReply()));
+ }
+
+ private void whenBridgeDomainAddDelThenFailure() {
+ doReturn(failedFuture()).when(api).bridgeDomainAddDel(any(BridgeDomainAddDel.class));
+ }
+
+ @Test
+ public void testAddBridgeDomain() throws Exception {
+ final int bdId = 1;
+ final String bdName = "bd1";
+ final BridgeDomain bd = generateBridgeDomain(bdName);
+ noMappingDefined(mappingContext, bdName, BD_CTX_NAME);
+
+ whenBridgeDomainAddDelThenSuccess();
+
+ customizer.writeCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext);
+
+ verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId);
+ verify(mappingContext).put(mappingIid(bdName, BD_CTX_NAME), mapping(bdName, bdId).get());
+ }
+
+ @Test
+ public void testAddBridgeDomainPresentInBdContext() throws Exception {
+ final int bdId = 1;
+ final String bdName = "bd1";
+ final BridgeDomain bd = generateBridgeDomain(bdName);
+ defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
+
+ whenBridgeDomainAddDelThenSuccess();
+
+ customizer.writeCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext);
+
+ verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId);
+ verify(mappingContext).put(mappingIid(bdName, BD_CTX_NAME), mapping(bdName, bdId).get());
+ }
+
+ @Test
+ public void testAddBridgeDomainFailed() throws Exception {
+ final int bdId = 1;
+ final String bdName = "bd1";
+ final BridgeDomain bd = generateBridgeDomain(bdName);
+ noMappingDefined(mappingContext, bdName, BD_CTX_NAME);
+
+ whenBridgeDomainAddDelThenFailure();
+
+ try {
+ customizer.writeCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext);
+ } catch (WriteFailedException e) {
+ verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId);
+ return;
+ }
+ fail("WriteFailedException.CreateFailedException was expected");
+ }
+
+ @Test
+ public void testDeleteBridgeDomain() throws Exception {
+ final int bdId = 1;
+ final String bdName = "bd1";
+ final BridgeDomain bd = generateBridgeDomain(bdName);
+ defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
+ when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent());
+
+ whenBridgeDomainAddDelThenSuccess();
+
+ customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext);
+
+ verifyBridgeDomainDeleteWasInvoked(bdId);
+ }
+
+ @Test
+ public void testDeleteReferencedBridgeDomain() throws Exception {
+ final int bdId = 1;
+ final String bdName = "bd1";
+ final BridgeDomain bd = generateBridgeDomain(bdName);
+ defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
+ when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.of(
+ new InterfacesBuilder().setInterface(Arrays.asList(l2ReferenceToBd("bd1"), l2ReferenceToBd("other-bd")))
+ .build()
+ ));
+
+ try {
+ customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext);
+ } catch (IllegalStateException e) {
+ verify(api, never()).bridgeDomainAddDel(any(BridgeDomainAddDel.class));
+ return;
+ }
+ fail("IllegalStateException was expected");
+ }
+
+ @Test
+ public void testDeleteReferencedPartialData() throws Exception {
+ final int bdId = 1;
+ final String bdName = "bd1";
+ final BridgeDomain bd = generateBridgeDomain(bdName);
+ defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
+ whenBridgeDomainAddDelThenSuccess();
+ when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.of(
+ new InterfacesBuilder().setInterface(Arrays.asList(new InterfaceBuilder()
+ .addAugmentation(VppInterfaceAugmentation.class, new VppInterfaceAugmentationBuilder().build())
+ .build())).build()
+ ));
+
+ customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext);
+ verifyBridgeDomainDeleteWasInvoked(bdId);
+ }
+
+ private static Interface l2ReferenceToBd(final String bridgeDomain) {
+ return new InterfaceBuilder()
+ .addAugmentation(VppInterfaceAugmentation.class, new VppInterfaceAugmentationBuilder()
+ .setL2(new L2Builder()
+ .setInterconnection(new BridgeBasedBuilder()
+ .setBridgeDomain(bridgeDomain)
+ .build())
+ .build())
+ .build())
+ .build();
+ }
+
+ @Test
+ public void testDeleteUnknownBridgeDomain() throws Exception {
+ final String bdName = "bd1";
+ final BridgeDomain bd = generateBridgeDomain("bd1");
+ noMappingDefined(mappingContext, bdName, BD_CTX_NAME);
+ when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent());
+
+ try {
+ customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext);
+ } catch (IllegalArgumentException e) {
+ verify(api, never()).bridgeDomainAddDel(any(BridgeDomainAddDel.class));
+ return;
+ }
+ fail("IllegalArgumentException was expected");
+ }
+
+ @Test
+ public void testDeleteBridgeDomainFailed() throws Exception {
+ final int bdId = 1;
+ final String bdName = "bd1";
+ final BridgeDomain bd = generateBridgeDomain(bdName);
+ defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
+ when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent());
+
+ whenBridgeDomainAddDelThenFailure();
+
+ try {
+ customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext);
+ } catch (WriteFailedException e) {
+ verifyBridgeDomainDeleteWasInvoked(bdId);
+ return;
+ }
+
+ fail("WriteFailedException.DeleteFailedException was expected");
+ }
+
+ @Test
+ public void testUpdateBridgeDomain() throws Exception {
+ final int bdId = 1;
+ final String bdName = "bd1";
+ defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
+
+ final byte arpTermBefore = 1;
+ final byte floodBefore = 1;
+ final byte forwardBefore = 0;
+ final byte learnBefore = 1;
+ final byte uufBefore = 0;
+
+ final BridgeDomain dataBefore =
+ generateBridgeDomain(bdName, arpTermBefore, floodBefore, forwardBefore, learnBefore, uufBefore);
+ final BridgeDomain dataAfter =
+ generateBridgeDomain(bdName, arpTermBefore ^ 1, floodBefore ^ 1, forwardBefore ^ 1, learnBefore ^ 1,
+ uufBefore ^ 1);
+
+ whenBridgeDomainAddDelThenSuccess();
+
+ customizer
+ .updateCurrentAttributes(bdIdentifierForName(bdName), dataBefore, dataAfter,
+ writeContext);
+ verifyBridgeDomainAddOrUpdateWasInvoked(dataAfter, bdId);
+ }
+
+ @Test
+ public void testUpdateUnknownBridgeDomain() throws Exception {
+ final String bdName = "bd1";
+ final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0, 1, 0);
+ final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0, 1, 0);
+ noMappingDefined(mappingContext, bdName, BD_CTX_NAME);
+
+ try {
+ customizer
+ .updateCurrentAttributes(bdIdentifierForName(bdName), bdBefore, bdAfter,
+ writeContext);
+ } catch (IllegalArgumentException e) {
+ verify(api, never()).bridgeDomainAddDel(any(BridgeDomainAddDel.class));
+ return;
+ }
+ fail("IllegalArgumentException was expected");
+ }
+
+ @Test
+ public void testUpdateBridgeDomainFailed() throws Exception {
+ final int bdId = 1;
+ final String bdName = "bd1";
+ final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0, 1, 0);
+ final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0, 1, 0);
+ defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
+
+ whenBridgeDomainAddDelThenFailure();
+
+ try {
+ customizer.updateCurrentAttributes(bdIdentifierForName(bdName), bdBefore, bdAfter, writeContext);
+ } catch (WriteFailedException e) {
+ verifyBridgeDomainAddOrUpdateWasInvoked(bdAfter, bdId);
+ return;
+ }
+ fail("IllegalStateException was expected");
+ }
+
+} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/L2FibEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/L2FibEntryCustomizerTest.java
new file mode 100644
index 000000000..b00e9e7e2
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/L2FibEntryCustomizerTest.java
@@ -0,0 +1,283 @@
+/*
+ * 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.hc2vpp.v3po.l2;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.VppBaseCallException;
+import io.fd.vpp.jvpp.VppInvocationException;
+import io.fd.vpp.jvpp.core.dto.L2FibAddDel;
+import io.fd.vpp.jvpp.core.dto.L2FibAddDelReply;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+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.rev161214.BridgeDomains;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.L2FibFilter;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.L2FibForward;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomainKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class L2FibEntryCustomizerTest extends WriterCustomizerTest {
+ private static final String BD_CTX_NAME = "bd-test-instance";
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+
+ private static final String BD_NAME = "testBD0";
+ private static final int BD_ID = 111;
+ private static final String IFACE_NAME = "eth0";
+ private static final int IFACE_ID = 123;
+ private static final int NO_INTERFACE = -1;
+
+ private L2FibEntryCustomizer customizer;
+
+ private static InstanceIdentifier<L2FibEntry> getL2FibEntryId(final PhysAddress address) {
+ return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(BD_NAME))
+ .child(L2FibTable.class).child(L2FibEntry.class, new L2FibEntryKey(address));
+ }
+
+ @Override
+ public void setUpTest() throws Exception {
+ defineMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+
+ customizer = new L2FibEntryCustomizer(
+ api,
+ new NamingContext("generatedBdName", BD_CTX_NAME),
+ new NamingContext("generatedIfaceName", IFC_CTX_NAME));
+ }
+
+ private void whenL2FibAddDelThenSuccess() {
+ doReturn(future(new L2FibAddDelReply())).when(api).l2FibAddDel(any(L2FibAddDel.class));
+ }
+
+ private void whenL2FibAddDelThenFailure() {
+ doReturn(failedFuture()).when(api).l2FibAddDel(any(L2FibAddDel.class));
+ }
+
+ private L2FibAddDel generateL2FibAddDelFilterRequest(final long mac, final byte isAdd, final int ifaceIndex) {
+ final L2FibAddDel request = new L2FibAddDel();
+ request.mac = mac;
+ request.bdId = BD_ID;
+ request.swIfIndex = ifaceIndex;
+ request.isAdd = isAdd;
+ if (isAdd == 1) {
+ request.staticMac = 1;
+ request.filterMac = 1;
+ }
+ return request;
+ }
+
+ private L2FibAddDel generateL2FibAddDelForwardRequest(final long mac, final byte isAdd, final int ifaceIndex) {
+ final L2FibAddDel request = new L2FibAddDel();
+ request.mac = mac;
+ request.bdId = BD_ID;
+ request.swIfIndex = ifaceIndex;
+ request.isAdd = isAdd;
+ if (isAdd == 1) {
+ request.staticMac = 1;
+ request.filterMac = 0;
+ }
+ return request;
+ }
+
+ private L2FibEntry generateL2FibFilterEntry(final PhysAddress address) {
+ final L2FibEntryBuilder entry = new L2FibEntryBuilder();
+ entry.setKey(new L2FibEntryKey(address));
+ entry.setPhysAddress(address);
+ entry.setStaticConfig(true);
+ entry.setBridgedVirtualInterface(false);
+ entry.setAction(L2FibFilter.class);
+ return entry.build();
+ }
+
+ private L2FibEntry generateL2FibForwardEntry(final PhysAddress address) {
+ final L2FibEntryBuilder entry = new L2FibEntryBuilder();
+ entry.setKey(new L2FibEntryKey(address));
+ entry.setPhysAddress(address);
+ entry.setStaticConfig(true);
+ entry.setBridgedVirtualInterface(false);
+ entry.setAction(L2FibForward.class);
+ entry.setOutgoingInterface(IFACE_NAME);
+ return entry.build();
+ }
+
+
+ private void verifyL2FibAddDelWasInvoked(final L2FibAddDel expected) throws
+ VppInvocationException {
+ ArgumentCaptor<L2FibAddDel> argumentCaptor = ArgumentCaptor.forClass(L2FibAddDel.class);
+ verify(api).l2FibAddDel(argumentCaptor.capture());
+ final L2FibAddDel actual = argumentCaptor.getValue();
+ assertEquals(expected.mac, actual.mac);
+ assertEquals(expected.bdId, actual.bdId);
+ assertEquals(expected.swIfIndex, actual.swIfIndex);
+ assertEquals(expected.isAdd, actual.isAdd);
+ assertEquals(expected.staticMac, actual.staticMac);
+ assertEquals(expected.filterMac, actual.filterMac);
+ }
+
+ @Test
+ public void testCreateFilter() throws Exception {
+ final long address_vpp = 0x0102030405060000L;
+ final PhysAddress address = new PhysAddress("01:02:03:04:05:06");
+ final L2FibEntry entry = generateL2FibFilterEntry(address);
+ final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
+
+ whenL2FibAddDelThenSuccess();
+
+ customizer.writeCurrentAttributes(id, entry, writeContext);
+
+ verifyL2FibAddDelWasInvoked(generateL2FibAddDelFilterRequest(address_vpp, (byte) 1, NO_INTERFACE));
+ }
+
+ @Test
+ public void testCreateForward() throws Exception {
+ final long address_vpp = 0x0102030405060000L;
+ final PhysAddress address = new PhysAddress("01:02:03:04:05:06");
+ final L2FibEntry entry = generateL2FibForwardEntry(address);
+ final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
+
+ whenL2FibAddDelThenSuccess();
+
+ customizer.writeCurrentAttributes(id, entry, writeContext);
+
+ verifyL2FibAddDelWasInvoked(generateL2FibAddDelForwardRequest(address_vpp, (byte) 1, IFACE_ID));
+ }
+
+ @Test
+ public void testCreateFilterFailed() throws Exception {
+ final long address_vpp = 0x1122334455660000L;
+ final PhysAddress address = new PhysAddress("11:22:33:44:55:66");
+ final L2FibEntry entry = generateL2FibFilterEntry(address);
+ final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
+
+ whenL2FibAddDelThenFailure();
+
+ try {
+ customizer.writeCurrentAttributes(id, entry, writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppBaseCallException);
+ verifyL2FibAddDelWasInvoked(generateL2FibAddDelFilterRequest(address_vpp, (byte) 1, NO_INTERFACE));
+ return;
+ }
+ fail("WriteFailedException.CreateFailedException was expected");
+ }
+
+ @Test
+ public void testCreateForwardFailed() throws Exception {
+ final long address_vpp = 0x1122334455660000L;
+ final PhysAddress address = new PhysAddress("11:22:33:44:55:66");
+ final L2FibEntry entry = generateL2FibForwardEntry(address);
+ final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
+
+ whenL2FibAddDelThenFailure();
+
+ try {
+ customizer.writeCurrentAttributes(id, entry, writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppBaseCallException);
+ verifyL2FibAddDelWasInvoked(generateL2FibAddDelForwardRequest(address_vpp, (byte) 1, IFACE_ID));
+ return;
+ }
+ fail("WriteFailedException.CreateFailedException was expected");
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testUpdate() throws Exception {
+ customizer.updateCurrentAttributes(InstanceIdentifier.create(L2FibEntry.class), mock(L2FibEntry.class),
+ mock(L2FibEntry.class), writeContext);
+ }
+
+ @Test
+ public void testDeleteFilter() throws Exception {
+ final long address_vpp = 0x1122334455660000L;
+ final PhysAddress address = new PhysAddress("11:22:33:44:55:66");
+ final L2FibEntry entry = generateL2FibFilterEntry(address);
+ final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
+
+ whenL2FibAddDelThenSuccess();
+
+ customizer.deleteCurrentAttributes(id, entry, writeContext);
+
+ verifyL2FibAddDelWasInvoked(generateL2FibAddDelFilterRequest(address_vpp, (byte) 0, NO_INTERFACE));
+ }
+
+ @Test
+ public void testDeleteForward() throws Exception {
+ final long address_vpp = 0x1122334455660000L;
+ final PhysAddress address = new PhysAddress("11:22:33:44:55:66");
+ final L2FibEntry entry = generateL2FibForwardEntry(address);
+ final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
+
+ whenL2FibAddDelThenSuccess();
+
+ customizer.deleteCurrentAttributes(id, entry, writeContext);
+
+ verifyL2FibAddDelWasInvoked(generateL2FibAddDelForwardRequest(address_vpp, (byte) 0, IFACE_ID));
+ }
+
+
+ @Test
+ public void testDeleteFilterFailed() throws Exception {
+ final long address_vpp = 0x0102030405060000L;
+ final PhysAddress address = new PhysAddress("01:02:03:04:05:06");
+ final L2FibEntry entry = generateL2FibFilterEntry(address);
+ final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
+
+ whenL2FibAddDelThenFailure();
+
+ try {
+ customizer.deleteCurrentAttributes(id, entry, writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppBaseCallException);
+ verifyL2FibAddDelWasInvoked(generateL2FibAddDelFilterRequest(address_vpp, (byte) 0, NO_INTERFACE));
+ return;
+ }
+ fail("WriteFailedException.DeleteFailedException was expected");
+ }
+
+ @Test
+ public void testDeleteForwardFailed() throws Exception {
+ final long address_vpp = 0x0102030405060000L;
+ final PhysAddress address = new PhysAddress("01:02:03:04:05:06");
+ final L2FibEntry entry = generateL2FibForwardEntry(address);
+ final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
+
+ whenL2FibAddDelThenFailure();
+
+ try {
+ customizer.deleteCurrentAttributes(id, entry, writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppBaseCallException);
+ verifyL2FibAddDelWasInvoked(generateL2FibAddDelForwardRequest(address_vpp, (byte) 0, IFACE_ID));
+ return;
+ }
+ fail("WriteFailedException.DeleteFailedException was expected");
+ }
+} \ No newline at end of file