2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.translate.v3po.interfaces;
19 import static org.mockito.Matchers.any;
20 import static org.mockito.Mockito.verify;
21 import static org.mockito.Mockito.when;
23 import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator;
24 import io.fd.honeycomb.translate.write.WriteFailedException;
25 import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
26 import org.junit.Test;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceAugmentation;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.ProxyArp;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.ProxyArpBuilder;
34 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
35 import io.fd.vpp.jvpp.core.dto.ProxyArpAddDel;
36 import io.fd.vpp.jvpp.core.dto.ProxyArpAddDelReply;
38 public class ProxyArpCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator {
39 private static final String IF_NAME = "eth1";
41 private ProxyArpCustomizer customizer;
44 public void setUp() throws Exception {
45 customizer = new ProxyArpCustomizer(api);
49 public void testWrite() throws WriteFailedException {
50 when(api.proxyArpAddDel(any())).thenReturn(future(new ProxyArpAddDelReply()));
51 customizer.writeCurrentAttributes(getProxyArpId(IF_NAME), proxyArp(), writeContext);
52 verify(api).proxyArpAddDel(expectedRequest(true));
55 @Test(expected = WriteFailedException.class)
56 public void testWriteFailed() throws WriteFailedException {
57 when(api.proxyArpAddDel(any())).thenReturn(failedFuture());
58 customizer.writeCurrentAttributes(getProxyArpId(IF_NAME), proxyArp(), writeContext);
61 @Test(expected = WriteFailedException.UpdateFailedException.class)
62 public void testUpdate() throws WriteFailedException.UpdateFailedException {
63 customizer.updateCurrentAttributes(getProxyArpId(IF_NAME), proxyArp(), proxyArp(), writeContext);
67 public void testDelete() throws WriteFailedException {
68 when(api.proxyArpAddDel(any())).thenReturn(future(new ProxyArpAddDelReply()));
69 customizer.deleteCurrentAttributes(getProxyArpId(IF_NAME), proxyArp(), writeContext);
70 verify(api).proxyArpAddDel(expectedRequest(false));
73 @Test(expected = WriteFailedException.DeleteFailedException.class)
74 public void testDeleteFailed() throws WriteFailedException {
75 when(api.proxyArpAddDel(any())).thenReturn(failedFuture());
76 customizer.deleteCurrentAttributes(getProxyArpId(IF_NAME), proxyArp(), writeContext);
79 private ProxyArp proxyArp() {
80 return new ProxyArpBuilder().setVrfId(123L).setHighAddr(new Ipv4AddressNoZone("10.1.1.2"))
81 .setLowAddr(new Ipv4AddressNoZone("10.1.1.1")).build();
84 private ProxyArpAddDel expectedRequest(final boolean isAdd) {
85 final ProxyArpAddDel request = new ProxyArpAddDel();
86 request.isAdd = booleanToByte(isAdd);
88 request.lowAddress = new byte[]{10,1,1,1};
89 request.hiAddress = new byte[]{10,1,1,2};
93 private InstanceIdentifier<ProxyArp> getProxyArpId(final String eth0) {
94 return InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(eth0)).augmentation(
95 VppInterfaceAugmentation.class).child(ProxyArp.class);