summaryrefslogtreecommitdiffstats
path: root/l3/impl/src/test/java/io/fd/hc2vpp/l3/write
diff options
context:
space:
mode:
Diffstat (limited to 'l3/impl/src/test/java/io/fd/hc2vpp/l3/write')
-rw-r--r--l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ProxyArpCustomizerTest.java95
-rw-r--r--l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ProxyRangeCustomizerTest.java96
-rw-r--r--l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4AddressCustomizerTest.java286
-rw-r--r--l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4NeighbourCustomizerTest.java154
-rw-r--r--l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/SubInterfaceIpv4AddressCustomizerTest.java145
-rw-r--r--l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6NeighbourCustomizerTest.java156
-rw-r--r--l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv6/nd/NdProxyCustomizerTest.java95
7 files changed, 1027 insertions, 0 deletions
diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ProxyArpCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ProxyArpCustomizerTest.java
new file mode 100644
index 000000000..e604df478
--- /dev/null
+++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ProxyArpCustomizerTest.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2017 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.l3.write;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+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.hc2vpp.l3.write.ipv4.ProxyArpCustomizer;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.core.dto.ProxyArpIntfcEnableDisable;
+import io.fd.vpp.jvpp.core.dto.ProxyArpIntfcEnableDisableReply;
+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.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.vpp.proxy.arp.rev170315.ProxyArpInterfaceAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev170315.interfaces._interface.ProxyArp;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class ProxyArpCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator {
+ private static final String IF_NAME = "eth1";
+ private static final int IF_INDEX = 42;
+ private static final String IFACE_CTX_NAME = "ifc-test-instance";
+
+ private static final InstanceIdentifier<ProxyArp>
+ IID = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME))
+ .augmentation(ProxyArpInterfaceAugmentation.class).child(ProxyArp.class);
+
+ private ProxyArpCustomizer customizer;
+ private ProxyArp data;
+
+ @Override
+ public void setUpTest() throws Exception {
+ data = mock(ProxyArp.class);
+ customizer = new ProxyArpCustomizer(api, new NamingContext("ifacePrefix", IFACE_CTX_NAME));
+ defineMapping(mappingContext, IF_NAME, IF_INDEX, IFACE_CTX_NAME);
+ }
+
+ @Test
+ public void testWrite() throws WriteFailedException {
+ when(api.proxyArpIntfcEnableDisable(any())).thenReturn(future(new ProxyArpIntfcEnableDisableReply()));
+ customizer.writeCurrentAttributes(IID, data, writeContext);
+ verify(api).proxyArpIntfcEnableDisable(expectedEnableRequest(true));
+ }
+
+ @Test(expected = WriteFailedException.class)
+ public void testWriteFailed() throws WriteFailedException {
+ when(api.proxyArpIntfcEnableDisable(any())).thenReturn(failedFuture());
+ customizer.writeCurrentAttributes(IID, data, writeContext);
+ }
+
+ @Test(expected = WriteFailedException.UpdateFailedException.class)
+ public void testUpdate() throws WriteFailedException {
+ customizer.updateCurrentAttributes(IID, data, data, writeContext);
+ }
+
+ @Test
+ public void testDelete() throws WriteFailedException {
+ when(api.proxyArpIntfcEnableDisable(any())).thenReturn(future(new ProxyArpIntfcEnableDisableReply()));
+ customizer.deleteCurrentAttributes(IID, data, writeContext);
+ verify(api).proxyArpIntfcEnableDisable(expectedEnableRequest(false));
+ }
+
+ @Test(expected = WriteFailedException.DeleteFailedException.class)
+ public void testDeleteFailed() throws WriteFailedException {
+ when(api.proxyArpIntfcEnableDisable(any())).thenReturn(failedFuture());
+ customizer.deleteCurrentAttributes(IID, data, writeContext);
+ }
+
+ private ProxyArpIntfcEnableDisable expectedEnableRequest(final boolean enable) {
+ final ProxyArpIntfcEnableDisable request = new ProxyArpIntfcEnableDisable();
+ request.swIfIndex = IF_INDEX;
+ request.enableDisable = booleanToByte(enable);
+ return request;
+ }
+}
diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ProxyRangeCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ProxyRangeCustomizerTest.java
new file mode 100644
index 000000000..49f4d0bc0
--- /dev/null
+++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ProxyRangeCustomizerTest.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2017 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.l3.write;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
+import io.fd.hc2vpp.l3.write.ipv4.ProxyRangeCustomizer;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.core.dto.ProxyArpAddDel;
+import io.fd.vpp.jvpp.core.dto.ProxyArpAddDelReply;
+import org.junit.Test;
+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.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev170315.ProxyRanges;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev170315.proxy.ranges.ProxyRange;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev170315.proxy.ranges.ProxyRangeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev170315.proxy.ranges.ProxyRangeKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+public class ProxyRangeCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator {
+
+ private KeyedInstanceIdentifier<ProxyRange, ProxyRangeKey> IID;
+ private ProxyRange RANGE;
+ private ProxyRangeCustomizer customizer;
+
+ @Override
+ public void setUpTest() throws Exception {
+ final Ipv4Address highAddr = new Ipv4AddressNoZone("10.1.1.2");
+ final Ipv4Address lowAddr = new Ipv4AddressNoZone("10.1.1.1");
+ final long vrfId = 123;
+ IID = InstanceIdentifier.create(ProxyRanges.class)
+ .child(ProxyRange.class, new ProxyRangeKey(highAddr, lowAddr, vrfId));
+ RANGE = new ProxyRangeBuilder().setVrfId(vrfId).setHighAddr(highAddr).setLowAddr(new Ipv4AddressNoZone(lowAddr))
+ .build();
+ customizer = new ProxyRangeCustomizer(api);
+ }
+
+ @Test
+ public void testWrite() throws WriteFailedException {
+ when(api.proxyArpAddDel(any())).thenReturn(future(new ProxyArpAddDelReply()));
+ customizer.writeCurrentAttributes(IID, RANGE, writeContext);
+ verify(api).proxyArpAddDel(expectedAddDelRequest(true));
+ }
+
+ @Test(expected = WriteFailedException.class)
+ public void testWriteFailed() throws WriteFailedException {
+ when(api.proxyArpAddDel(any())).thenReturn(failedFuture());
+ customizer.writeCurrentAttributes(IID, RANGE, writeContext);
+ }
+
+ @Test(expected = WriteFailedException.UpdateFailedException.class)
+ public void testUpdate() throws WriteFailedException {
+ customizer.updateCurrentAttributes(IID, RANGE, RANGE, writeContext);
+ }
+
+ @Test
+ public void testDelete() throws WriteFailedException {
+ when(api.proxyArpAddDel(any())).thenReturn(future(new ProxyArpAddDelReply()));
+ customizer.deleteCurrentAttributes(IID, RANGE, writeContext);
+ verify(api).proxyArpAddDel(expectedAddDelRequest(false));
+ }
+
+ @Test(expected = WriteFailedException.DeleteFailedException.class)
+ public void testDeleteFailed() throws WriteFailedException {
+ when(api.proxyArpAddDel(any())).thenReturn(failedFuture());
+ customizer.deleteCurrentAttributes(IID, RANGE, writeContext);
+ }
+
+ private ProxyArpAddDel expectedAddDelRequest(final boolean isAdd) {
+ final ProxyArpAddDel request = new ProxyArpAddDel();
+ request.isAdd = booleanToByte(isAdd);
+ request.vrfId = 123;
+ request.lowAddress = new byte[] {10, 1, 1, 1};
+ request.hiAddress = new byte[] {10, 1, 1, 2};
+ return request;
+ }
+}
diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4AddressCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4AddressCustomizerTest.java
new file mode 100644
index 000000000..269781319
--- /dev/null
+++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4AddressCustomizerTest.java
@@ -0,0 +1,286 @@
+/*
+ * Copyright (c) 2017 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.l3.write.ipv4;
+
+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 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.NamingContext;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.VppBaseCallException;
+import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump;
+import io.fd.vpp.jvpp.core.dto.SwInterfaceAddDelAddress;
+import io.fd.vpp.jvpp.core.dto.SwInterfaceAddDelAddressReply;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentMatcher;
+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.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.ip.rev140616.Interface1;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address;
+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.Netmask;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.NetmaskBuilder;
+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.DottedQuad;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class Ipv4AddressCustomizerTest extends WriterCustomizerTest {
+
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String IFACE_NAME = "eth0";
+ private static final int IFACE_ID = 123;
+
+ private NamingContext interfaceContext;
+ private Ipv4AddressCustomizer customizer;
+
+ private static InstanceIdentifier<Address> getAddressId(final String ifaceName) {
+ return InstanceIdentifier.builder(Interfaces.class)
+ .child(Interface.class, new InterfaceKey(ifaceName))
+ .augmentation(Interface1.class)
+ .child(Ipv4.class)
+ .child(Address.class)
+ .build();
+ }
+
+ private static ArgumentMatcher<InstanceIdentifier<?>> matchInstanceIdentifier(
+ Class<?> desiredClass) {
+ return o -> o instanceof InstanceIdentifier && (o.getTargetType().equals(desiredClass));
+ }
+
+ @Before
+ public void setUpTest() throws Exception {
+ interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
+
+ customizer = new Ipv4AddressCustomizer(api, interfaceContext);
+
+ doReturn(future(new IpAddressDetailsReplyDump())).when(api).ipAddressDump(any());
+ }
+
+ private void whenSwInterfaceAddDelAddressThenSuccess() {
+ doReturn(future(new SwInterfaceAddDelAddressReply())).when(api).swInterfaceAddDelAddress(any(SwInterfaceAddDelAddress.class));
+ }
+
+ private void whenSwInterfaceAddDelAddressThenFailure() {
+ doReturn(failedFuture()).when(api).swInterfaceAddDelAddress(any(SwInterfaceAddDelAddress.class));
+ }
+
+ @Test
+ public void testAddPrefixLengthIpv4Address() throws Exception {
+ final InstanceIdentifier<Address> id = getAddressId(IFACE_NAME);
+ when(writeContext.readBefore(id)).thenReturn(Optional.absent());
+
+ Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"));
+ PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build();
+ Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build();
+
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ whenSwInterfaceAddDelAddressThenSuccess();
+
+ customizer.writeCurrentAttributes(id, data, writeContext);
+
+ verify(api).swInterfaceAddDelAddress(generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1},
+ (byte) 1, (byte) 24));
+ }
+
+ @Test
+ public void testAddPrefixLengthIpv4AddressFailed() throws Exception {
+ final InstanceIdentifier<Address> id = getAddressId(IFACE_NAME);
+ when(writeContext.readBefore(id)).thenReturn(Optional.absent());
+
+ Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"));
+ PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build();
+ Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build();
+
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ whenSwInterfaceAddDelAddressThenFailure();
+
+ try {
+ customizer.writeCurrentAttributes(id, data, writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppBaseCallException);
+ verify(api).swInterfaceAddDelAddress(
+ generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1},
+ (byte) 1, (byte) 24));
+ return;
+ }
+ fail("WriteFailedException was expected");
+ }
+
+ @Test(expected = WriteFailedException.UpdateFailedException.class)
+ public void testUpdate() throws Exception {
+ final Address data = mock(Address.class);
+ customizer.updateCurrentAttributes(getAddressId(IFACE_NAME), data, data, writeContext);
+ }
+
+ private SwInterfaceAddDelAddress generateSwInterfaceAddDelAddressRequest(final byte[] address, final byte isAdd,
+ final byte prefixLength) {
+ final SwInterfaceAddDelAddress request = new SwInterfaceAddDelAddress();
+ request.swIfIndex = IFACE_ID;
+ request.isAdd = isAdd;
+ request.isIpv6 = 0;
+ request.delAll = 0;
+ request.addressLength = prefixLength;
+ request.address = address;
+ return request;
+ }
+
+ @Test
+ public void testDeletePrefixLengthIpv4Address() throws Exception {
+ final InstanceIdentifier<Address> id = getAddressId(IFACE_NAME);
+
+ Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"));
+ PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build();
+ Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build();
+
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ whenSwInterfaceAddDelAddressThenSuccess();
+
+ customizer.deleteCurrentAttributes(id, data, writeContext);
+
+ verify(api).swInterfaceAddDelAddress(generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1},
+ (byte) 0, (byte) 24));
+ }
+
+ @Test
+ public void testDeletePrefixLengthIpv4AddressFailed() throws Exception {
+ final InstanceIdentifier<Address> id = getAddressId(IFACE_NAME);
+
+ Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"));
+ PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build();
+ Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build();
+
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ whenSwInterfaceAddDelAddressThenFailure();
+
+ try {
+ customizer.deleteCurrentAttributes(id, data, writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppBaseCallException);
+ verify(api).swInterfaceAddDelAddress(
+ generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1},
+ (byte) 0, (byte) 24));
+ return;
+ }
+ fail("WriteFailedException was expec16ted");
+ }
+
+ @Test
+ public void testNetmaskFailed() {
+ final int expectedPrefixLength = 1;
+ final String stringMask = "128.0.0.0";
+ final InstanceIdentifier<Address> id = getAddressId(IFACE_NAME);
+ when(writeContext.readBefore(id)).thenReturn(Optional.absent());
+
+ Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"));
+ Netmask subnet = new NetmaskBuilder().setNetmask(new DottedQuad(stringMask)).build();
+ Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(subnet).build();
+
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ whenSwInterfaceAddDelAddressThenFailure();
+
+ try {
+ customizer.writeCurrentAttributes(id, data, writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppBaseCallException);
+ verify(api).swInterfaceAddDelAddress(generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1},
+ (byte) 1, (byte) expectedPrefixLength));
+ return;
+ }
+ fail("WriteFailedException was expec16ted");
+
+ }
+
+ private void testSingleNetmask(final int expectedPrefixLength, final String stringMask) throws Exception {
+ final InstanceIdentifier<Address> id = getAddressId(IFACE_NAME);
+ when(writeContext.readBefore(id)).thenReturn(Optional.absent());
+
+ Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"));
+ Netmask subnet = new NetmaskBuilder().setNetmask(new DottedQuad(stringMask)).build();
+ Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(subnet).build();
+
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ whenSwInterfaceAddDelAddressThenSuccess();
+
+ customizer.writeCurrentAttributes(id, data, writeContext);
+
+ verify(api).swInterfaceAddDelAddress(generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1},
+ (byte) 1, (byte) expectedPrefixLength));
+ }
+
+ private void testSingleIllegalNetmask(final String stringMask) throws Exception {
+ try {
+ final InstanceIdentifier<Address> id = getAddressId(IFACE_NAME);
+ when(writeContext.readBefore(id)).thenReturn(Optional.absent());
+
+ Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"));
+ Netmask subnet = new NetmaskBuilder().setNetmask(new DottedQuad(stringMask)).build();
+ Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(subnet).build();
+
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ whenSwInterfaceAddDelAddressThenSuccess();
+
+ customizer.writeCurrentAttributes(id, data, writeContext);
+ } catch (IllegalArgumentException e) {
+ return;
+ }
+ fail("IllegalArgumentException expected");
+
+ }
+
+ /**
+ * Test contiguous netmask length from QuadDotted notation
+ */
+ @Test
+ public void testNetmaskLength() throws Exception {
+ testSingleNetmask(1, "128.0.0.0");
+ testSingleNetmask(2, "192.0.0.0");
+ testSingleNetmask(8, "255.0.0.0");
+ testSingleNetmask(9, "255.128.0.0");
+ testSingleNetmask(16, "255.255.0.0");
+ testSingleNetmask(24, "255.255.255.0");
+ }
+
+ @Test
+ public void testNetmaskIllegal() throws Exception {
+ testSingleIllegalNetmask("");
+ testSingleIllegalNetmask(".");
+ testSingleIllegalNetmask(".255");
+ testSingleIllegalNetmask("255");
+ testSingleIllegalNetmask("255.");
+ testSingleIllegalNetmask("255.255");
+ testSingleIllegalNetmask("255.255.0");
+ testSingleIllegalNetmask("255.255.255.");
+ testSingleIllegalNetmask("255.255.255.256");
+ testSingleIllegalNetmask("0.0.0.0");
+ testSingleIllegalNetmask("10.10.10.10");
+ testSingleIllegalNetmask("255.1.255.0");
+ testSingleIllegalNetmask("255.255.255.255");
+ }
+}
diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4NeighbourCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4NeighbourCustomizerTest.java
new file mode 100644
index 000000000..54bdafe1b
--- /dev/null
+++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4NeighbourCustomizerTest.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 2017 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.l3.write.ipv4;
+
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.times;
+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.Ipv4Translator;
+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.core.dto.IpNeighborAddDel;
+import io.fd.vpp.jvpp.core.dto.IpNeighborAddDelReply;
+import org.junit.Test;
+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.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.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.interfaces._interface.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Neighbor;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.NeighborBuilder;
+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.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.interfaces._interface.RoutingBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class Ipv4NeighbourCustomizerTest extends WriterCustomizerTest implements Ipv4Translator {
+
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String IFACE_NAME = "parent";
+ private static final int IFACE_ID = 5;
+ private static final InstanceIdentifier<Neighbor> IID =
+ InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME))
+ .augmentation(Interface1.class).child(Ipv4.class).child(Neighbor.class);
+
+ private Ipv4NeighbourCustomizer customizer;
+
+ @Override
+ public void setUpTest() {
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ customizer = new Ipv4NeighbourCustomizer(api, new NamingContext("prefix", IFC_CTX_NAME));
+ }
+
+ @Test
+ public void testWriteCurrentAttributes() throws WriteFailedException {
+ when(writeContext.readBefore(IID.firstIdentifierOf(Interface.class))).thenReturn(Optional.absent());
+ when(api.ipNeighborAddDel(any())).thenReturn(future(new IpNeighborAddDelReply()));
+ customizer.writeCurrentAttributes(IID, getData(), writeContext);
+ verify(api).ipNeighborAddDel(getExpectedRequest(true));
+ }
+
+ @Test
+ public void testWriteCurrentAttributesFailed() {
+ when(writeContext.readBefore(IID.firstIdentifierOf(Interface.class))).thenReturn(Optional.absent());
+ when(api.ipNeighborAddDel(any())).thenReturn(failedFuture());
+ try {
+ customizer.writeCurrentAttributes(IID, getData(), writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppBaseCallException);
+ verify(api).ipNeighborAddDel(getExpectedRequest(true));
+ return;
+ }
+ fail("WriteFailedException expected");
+ }
+ @Test(expected = UnsupportedOperationException.class)
+ public void testUpdateCurrentAttributes() throws WriteFailedException {
+ customizer.updateCurrentAttributes(IID, getData(), getData(), writeContext);
+ }
+
+ @Test
+ public void testDeleteCurrentAttributes() throws WriteFailedException {
+ when(writeContext.readBefore(IID.firstIdentifierOf(Interface.class))).thenReturn(Optional.absent());
+ when(api.ipNeighborAddDel(any())).thenReturn(future(new IpNeighborAddDelReply()));
+ customizer.deleteCurrentAttributes(IID, getData(), writeContext);
+ verify(api).ipNeighborAddDel(getExpectedRequest(false));
+ }
+
+ @Test
+ public void testDeleteCurrentAttributesFailed() {
+ when(writeContext.readBefore(IID.firstIdentifierOf(Interface.class))).thenReturn(Optional.absent());
+ when(api.ipNeighborAddDel(any())).thenReturn(failedFuture());
+ try {
+ customizer.deleteCurrentAttributes(IID, getData(), writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppBaseCallException);
+ verify(api).ipNeighborAddDel(getExpectedRequest(false));
+ return;
+ }
+ fail("WriteFailedException expected");
+ }
+
+ @Test
+ public void testVrfExtractionCornerCases() throws WriteFailedException {
+ when(api.ipNeighborAddDel(any())).thenReturn(future(new IpNeighborAddDelReply()));
+
+ when(writeContext.readBefore(IID.firstIdentifierOf(Interface.class)))
+ // no augment
+ .thenReturn(Optional.of(new InterfaceBuilder().build()))
+ // empty augment
+ .thenReturn(Optional.of(new InterfaceBuilder()
+ .addAugmentation(VppInterfaceAugmentation.class, new VppInterfaceAugmentationBuilder().build()).build()))
+ //empty routing
+ .thenReturn(Optional.of(new InterfaceBuilder()
+ .addAugmentation(VppInterfaceAugmentation.class, new VppInterfaceAugmentationBuilder()
+ .setRouting(new RoutingBuilder().build())
+ .build()).build()));
+
+
+ customizer.writeCurrentAttributes(IID, getData(), writeContext);
+ customizer.writeCurrentAttributes(IID, getData(), writeContext);
+ customizer.writeCurrentAttributes(IID, getData(), writeContext);
+ verify(api, times(3)).ipNeighborAddDel(getExpectedRequest(true));
+ }
+
+ private Neighbor getData() {
+ final Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"));
+ final PhysAddress mac = new PhysAddress("aa:bb:cc:ee:11:22");
+ return new NeighborBuilder().setIp(noZoneIp).setLinkLayerAddress(mac).build();
+ }
+ private IpNeighborAddDel getExpectedRequest(final boolean isAdd) {
+ final IpNeighborAddDel request = new IpNeighborAddDel();
+ request.isIpv6 = 0;
+ request.isAdd = booleanToByte(isAdd);
+ request.isStatic = 1;
+ request.dstAddress = new byte[] {(byte) 192, (byte) 168, 2, 1};
+ request.macAddress = new byte[] {(byte) 0xaa, (byte) 0xbb, (byte) 0xcc, (byte) 0xee, 0x11, 0x22};
+ request.swIfIndex = IFACE_ID;
+ return request;
+ }
+} \ No newline at end of file
diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/SubInterfaceIpv4AddressCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/SubInterfaceIpv4AddressCustomizerTest.java
new file mode 100644
index 000000000..ce1711c32
--- /dev/null
+++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/SubInterfaceIpv4AddressCustomizerTest.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2017 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.l3.write.ipv4;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+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.hc2vpp.l3.write.ipv4.subinterface.SubInterfaceIpv4AddressCustomizer;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.VppBaseCallException;
+import io.fd.vpp.jvpp.core.dto.SwInterfaceAddDelAddress;
+import io.fd.vpp.jvpp.core.dto.SwInterfaceAddDelAddressReply;
+import org.junit.Test;
+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.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.yang.types.rev130715.DottedQuad;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.SubinterfaceAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.SubInterfaces;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.AddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.address.Subnet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.address.subnet.Netmask;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.address.subnet.NetmaskBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.address.subnet.PrefixLength;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.address.subnet.PrefixLengthBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class SubInterfaceIpv4AddressCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator {
+
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String IFACE_NAME = "eth0";
+ private static final int IFACE_INDEX = 0;
+ private static final String SUBIF_NAME = "eth0.1";
+ private static final long SUBIF_ID = 1;
+ private static final int SUBIF_INDEX = 123;
+ private static final InstanceIdentifier<Address> IID =
+ InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME))
+ .augmentation(SubinterfaceAugmentation.class).child(SubInterfaces.class)
+ .child(SubInterface.class, new SubInterfaceKey(SUBIF_ID)).child(Ipv4.class).child(Address.class);
+
+ private SubInterfaceIpv4AddressCustomizer customizer;
+
+ @Override
+ protected void setUpTest() {
+ customizer = new SubInterfaceIpv4AddressCustomizer(api, new NamingContext("prefix", IFC_CTX_NAME));
+ defineMapping(mappingContext, IFACE_NAME, IFACE_INDEX, IFC_CTX_NAME);
+ defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFC_CTX_NAME);
+ }
+
+ @Test
+ public void testWrite() throws WriteFailedException {
+ when(api.swInterfaceAddDelAddress(any())).thenReturn(future(new SwInterfaceAddDelAddressReply()));
+ customizer.writeCurrentAttributes(IID, address(prefixLength()), writeContext);
+ verify(api).swInterfaceAddDelAddress(expectedRequest(true));
+ }
+
+ @Test
+ public void testWriteFailed() {
+ when(api.swInterfaceAddDelAddress(any())).thenReturn(failedFuture());
+ try {
+ customizer.writeCurrentAttributes(IID, address(prefixLength()), writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppBaseCallException);
+ verify(api).swInterfaceAddDelAddress(expectedRequest(true));
+ return;
+ }
+ fail("WriteFailedException expected");
+ }
+
+ @Test
+ public void testDelete() throws WriteFailedException {
+ when(api.swInterfaceAddDelAddress(any())).thenReturn(future(new SwInterfaceAddDelAddressReply()));
+ customizer.deleteCurrentAttributes(IID, address(netmask()), writeContext);
+ verify(api).swInterfaceAddDelAddress(expectedRequest(false));
+ }
+
+ @Test
+ public void testDeleteFailed() {
+ when(api.swInterfaceAddDelAddress(any())).thenReturn(failedFuture());
+ try {
+ customizer.deleteCurrentAttributes(IID, address(netmask()), writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppBaseCallException);
+ verify(api).swInterfaceAddDelAddress(expectedRequest(false));
+ return;
+ }
+ fail("WriteFailedException expected");
+ }
+
+ private SwInterfaceAddDelAddress expectedRequest(boolean isAdd) {
+ final SwInterfaceAddDelAddress request = new SwInterfaceAddDelAddress();
+ request.isAdd = booleanToByte(isAdd);
+ request.swIfIndex = SUBIF_INDEX;
+ request.isIpv6 = 0;
+ request.delAll = 0;
+ request.addressLength = 24;
+ request.address = new byte[] {(byte) 192, (byte) 168, 2, 1};
+ return request;
+ }
+
+ @Test(expected = WriteFailedException.UpdateFailedException.class)
+ public void testUpdate() throws Exception {
+ final Address address = address(prefixLength());
+ customizer.updateCurrentAttributes(IID, address, address, writeContext);
+ }
+
+ private Address address(final Subnet subnet) {
+ final Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"));
+ return new AddressBuilder().setIp(noZoneIp).setSubnet(subnet).build();
+ }
+
+ private PrefixLength prefixLength() {
+ return new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build();
+ }
+
+ private Netmask netmask() {
+ return new NetmaskBuilder().setNetmask(new DottedQuad("255.255.255.0")).build();
+ }
+} \ No newline at end of file
diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6NeighbourCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6NeighbourCustomizerTest.java
new file mode 100644
index 000000000..e1a2f3d2e
--- /dev/null
+++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6NeighbourCustomizerTest.java
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2017 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.l3.write.ipv6;
+
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.times;
+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.Ipv6Translator;
+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.core.dto.IpNeighborAddDel;
+import io.fd.vpp.jvpp.core.dto.IpNeighborAddDelReply;
+import org.junit.Test;
+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.inet.types.rev130715.Ipv6AddressNoZone;
+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.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.interfaces._interface.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.Neighbor;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.NeighborBuilder;
+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.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.interfaces._interface.RoutingBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class Ipv6NeighbourCustomizerTest extends WriterCustomizerTest implements Ipv6Translator {
+
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String IFACE_NAME = "parent";
+ private static final int IFACE_ID = 5;
+ private static final InstanceIdentifier<Neighbor> IID =
+ InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME))
+ .augmentation(Interface1.class).child(Ipv6.class).child(Neighbor.class);
+
+ private Ipv6NeighbourCustomizer customizer;
+
+ @Override
+ public void setUpTest() {
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ customizer = new Ipv6NeighbourCustomizer(api, new NamingContext("prefix", IFC_CTX_NAME));
+ }
+
+ @Test
+ public void testWriteCurrentAttributes() throws WriteFailedException {
+ when(writeContext.readBefore(IID.firstIdentifierOf(Interface.class))).thenReturn(Optional.absent());
+ when(api.ipNeighborAddDel(any())).thenReturn(future(new IpNeighborAddDelReply()));
+ customizer.writeCurrentAttributes(IID, getData(), writeContext);
+ verify(api).ipNeighborAddDel(getExpectedRequest(true));
+ }
+
+ @Test
+ public void testWriteCurrentAttributesFailed() {
+ when(writeContext.readBefore(IID.firstIdentifierOf(Interface.class))).thenReturn(Optional.absent());
+ when(api.ipNeighborAddDel(any())).thenReturn(failedFuture());
+ try {
+ customizer.writeCurrentAttributes(IID, getData(), writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppBaseCallException);
+ verify(api).ipNeighborAddDel(getExpectedRequest(true));
+ return;
+ }
+ fail("WriteFailedException expected");
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testUpdateCurrentAttributes() throws WriteFailedException {
+ customizer.updateCurrentAttributes(IID, getData(), getData(), writeContext);
+ }
+
+ @Test
+ public void testDeleteCurrentAttributes() throws WriteFailedException {
+ when(writeContext.readBefore(IID.firstIdentifierOf(Interface.class))).thenReturn(Optional.absent());
+ when(api.ipNeighborAddDel(any())).thenReturn(future(new IpNeighborAddDelReply()));
+ customizer.deleteCurrentAttributes(IID, getData(), writeContext);
+ verify(api).ipNeighborAddDel(getExpectedRequest(false));
+ }
+
+ @Test
+ public void testDeleteCurrentAttributesFailed() {
+ when(writeContext.readBefore(IID.firstIdentifierOf(Interface.class))).thenReturn(Optional.absent());
+ when(api.ipNeighborAddDel(any())).thenReturn(failedFuture());
+ try {
+ customizer.deleteCurrentAttributes(IID, getData(), writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppBaseCallException);
+ verify(api).ipNeighborAddDel(getExpectedRequest(false));
+ return;
+ }
+ fail("WriteFailedException expected");
+ }
+
+ @Test
+ public void testVrfExtractionCornerCases() throws WriteFailedException {
+ when(api.ipNeighborAddDel(any())).thenReturn(future(new IpNeighborAddDelReply()));
+
+ when(writeContext.readBefore(IID.firstIdentifierOf(Interface.class)))
+ // no augment
+ .thenReturn(Optional.of(new InterfaceBuilder().build()))
+ // empty augment
+ .thenReturn(Optional.of(new InterfaceBuilder()
+ .addAugmentation(VppInterfaceAugmentation.class, new VppInterfaceAugmentationBuilder().build()).build()))
+ //empty routing
+ .thenReturn(Optional.of(new InterfaceBuilder()
+ .addAugmentation(VppInterfaceAugmentation.class, new VppInterfaceAugmentationBuilder()
+ .setRouting(new RoutingBuilder().build())
+ .build()).build()));
+
+
+ customizer.writeCurrentAttributes(IID, getData(), writeContext);
+ customizer.writeCurrentAttributes(IID, getData(), writeContext);
+ customizer.writeCurrentAttributes(IID, getData(), writeContext);
+ verify(api, times(3)).ipNeighborAddDel(getExpectedRequest(true));
+ }
+
+ private Neighbor getData() {
+ final Ipv6AddressNoZone noZoneIp = new Ipv6AddressNoZone(new Ipv6Address("2001:0db8:0a0b:12f0:0000:0000:0000:0001"));
+ final PhysAddress mac = new PhysAddress("aa:bb:cc:ee:11:22");
+ return new NeighborBuilder().setIp(noZoneIp).setLinkLayerAddress(mac).build();
+ }
+
+ private IpNeighborAddDel getExpectedRequest(final boolean isAdd) {
+ final IpNeighborAddDel request = new IpNeighborAddDel();
+ request.isIpv6 = 1;
+ request.isAdd = booleanToByte(isAdd);
+ request.isStatic = 1;
+ request.dstAddress = new byte[]{32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 1};
+ request.macAddress = new byte[]{(byte) 0xaa, (byte) 0xbb, (byte) 0xcc, (byte) 0xee, 0x11, 0x22};
+ request.swIfIndex = IFACE_ID;
+ return request;
+ }
+
+} \ No newline at end of file
diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv6/nd/NdProxyCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv6/nd/NdProxyCustomizerTest.java
new file mode 100644
index 000000000..bf6fe9d2c
--- /dev/null
+++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv6/nd/NdProxyCustomizerTest.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2017 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.l3.write.ipv6.nd;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+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.core.dto.Ip6NdProxyAddDel;
+import io.fd.vpp.jvpp.core.dto.Ip6NdProxyAddDelReply;
+import org.junit.Test;
+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.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.ip.rev140616.Interface1;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.NdProxyIp6Augmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.NdProxies;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxy;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxyKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class NdProxyCustomizerTest extends WriterCustomizerTest {
+ private static final String IF_NAME = "eth1";
+ private static final InstanceIdentifier<NdProxies> ND_PROXIES_IID =
+ InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME))
+ .augmentation(Interface1.class).child(Ipv6.class).augmentation(NdProxyIp6Augmentation.class)
+ .child(NdProxies.class);
+ private static final int IF_INDEX = 1;
+
+ private static final String IFACE_CTX_NAME = "ifc-test-instance";
+
+ private NdProxyCustomizer customizer;
+
+ @Override
+ protected void setUpTest() {
+ customizer = new NdProxyCustomizer(api, new NamingContext("ifacePrefix", IFACE_CTX_NAME));
+ when(api.ip6NdProxyAddDel(any())).thenReturn(future(new Ip6NdProxyAddDelReply()));
+ defineMapping(mappingContext, IF_NAME, IF_INDEX, IFACE_CTX_NAME);
+ }
+
+ @Test
+ public void testWrite() throws WriteFailedException {
+ final Ipv6AddressNoZone address = new Ipv6AddressNoZone("2001::1");
+ final NdProxy data = new NdProxyBuilder().setAddress(address).build();
+ customizer.writeCurrentAttributes(getId(address), data, writeContext);
+ final Ip6NdProxyAddDel request = new Ip6NdProxyAddDel();
+ request.swIfIndex = IF_INDEX;
+ request.address = new byte[] {0x20, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01};
+ verify(api).ip6NdProxyAddDel(request);
+ }
+
+ @Test(expected = WriteFailedException.UpdateFailedException.class)
+ public void testUpdate() throws WriteFailedException {
+ final Ipv6AddressNoZone address = new Ipv6AddressNoZone("2001::2");
+ final NdProxy data = new NdProxyBuilder().setAddress(address).build();
+ customizer.updateCurrentAttributes(getId(address), mock(NdProxy.class), data, writeContext);
+ }
+
+ @Test
+ public void testDelete() throws WriteFailedException {
+ final Ipv6AddressNoZone address = new Ipv6AddressNoZone("2001::3");
+ final NdProxy data = new NdProxyBuilder().setAddress(address).build();
+ customizer.deleteCurrentAttributes(getId(address), data, writeContext);
+ final Ip6NdProxyAddDel request = new Ip6NdProxyAddDel();
+ request.isDel = 1;
+ request.swIfIndex = IF_INDEX;
+ request.address = new byte[] {0x20, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x03};
+ verify(api).ip6NdProxyAddDel(request);
+ }
+
+ private InstanceIdentifier<NdProxy> getId(final Ipv6AddressNoZone address) {
+ return ND_PROXIES_IID.child(NdProxy.class, new NdProxyKey(address));
+ }
+} \ No newline at end of file