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.interfacesstate;
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNotNull;
21 import static org.junit.Assert.assertNull;
22 import static org.mockito.Matchers.any;
23 import static org.mockito.Mockito.doReturn;
24 import static org.mockito.Mockito.verify;
25 import static org.mockito.Mockito.verifyZeroInteractions;
27 import com.google.common.collect.Lists;
28 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
29 import io.fd.honeycomb.translate.v3po.util.NamingContext;
30 import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest;
31 import java.net.InetAddress;
32 import java.net.UnknownHostException;
33 import java.util.HashMap;
35 import org.junit.Test;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentation;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.VxlanGpe;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.VxlanGpeBuilder;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
43 import org.openvpp.jvpp.VppBaseCallException;
44 import org.openvpp.jvpp.core.dto.SwInterfaceDetails;
45 import org.openvpp.jvpp.core.dto.VxlanGpeTunnelDetails;
46 import org.openvpp.jvpp.core.dto.VxlanGpeTunnelDetailsReplyDump;
47 import org.openvpp.jvpp.core.dto.VxlanGpeTunnelDump;
49 public class VxlanGpeCustomizerTest extends ReaderCustomizerTest<VxlanGpe, VxlanGpeBuilder> {
51 private static final String IFC_CTX_NAME = "ifc-test-instance";
52 private static final String IF_NAME = "ifc2";
53 private static final int IF_INDEX = 0;
55 private NamingContext interfacesContext;
56 private static final InstanceIdentifier<VxlanGpe> VXLAN_GPE_ID =
57 InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME))
58 .augmentation(VppInterfaceStateAugmentation.class).child(VxlanGpe.class);
60 public VxlanGpeCustomizerTest() {
61 super(VxlanGpe.class);
65 public void setUp() throws UnknownHostException, VppBaseCallException {
66 interfacesContext = new NamingContext("vxlan_gpe_inf", IFC_CTX_NAME);
67 defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
69 final SwInterfaceDetails v = new SwInterfaceDetails();
70 v.interfaceName = "vxlan_gpe_inf2".getBytes();
71 final Map<Integer, SwInterfaceDetails> map = new HashMap<>();
73 cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, map);
75 final VxlanGpeTunnelDetailsReplyDump value = new VxlanGpeTunnelDetailsReplyDump();
76 final VxlanGpeTunnelDetails vxlanGpeTunnelDetails = new VxlanGpeTunnelDetails();
77 vxlanGpeTunnelDetails.isIpv6 = 0;
78 vxlanGpeTunnelDetails.local = InetAddress.getByName("1.2.3.4").getAddress();
79 vxlanGpeTunnelDetails.remote = InetAddress.getByName("1.2.3.5").getAddress();
80 vxlanGpeTunnelDetails.vni = 9;
81 vxlanGpeTunnelDetails.protocol = 1;
82 vxlanGpeTunnelDetails.encapVrfId = 55;
83 vxlanGpeTunnelDetails.decapVrfId = 66;
84 vxlanGpeTunnelDetails.swIfIndex = 0;
85 value.vxlanGpeTunnelDetails = Lists.newArrayList(vxlanGpeTunnelDetails);
86 doReturn(future(value)).when(api).vxlanGpeTunnelDump(any(VxlanGpeTunnelDump.class));
90 public void testReadCurrentAttributes() throws Exception {
91 final VxlanGpeBuilder builder = getCustomizer().getBuilder(VXLAN_GPE_ID);
92 getCustomizer().readCurrentAttributes(VXLAN_GPE_ID, builder, ctx);
94 assertNull(builder.getLocal().getIpv6Address());
95 assertNotNull(builder.getLocal().getIpv4Address());
96 assertEquals("1.2.3.4", builder.getLocal().getIpv4Address().getValue());
98 assertNull(builder.getRemote().getIpv6Address());
99 assertNotNull(builder.getRemote().getIpv4Address());
100 assertEquals("1.2.3.5", builder.getRemote().getIpv4Address().getValue());
102 assertEquals(9, builder.getVni().getValue().intValue());
103 assertEquals(1, builder.getNextProtocol().getIntValue());
104 assertEquals(55, builder.getEncapVrfId().intValue());
105 assertEquals(66, builder.getDecapVrfId().intValue());
107 verify(api).vxlanGpeTunnelDump(any(VxlanGpeTunnelDump.class));
110 @Test(expected = NullPointerException.class)
111 public void testReadCurrentAttributesVppNameNotCached() throws Exception {
112 InterfaceCustomizer.getCachedInterfaceDump(cache).remove(0);
114 final VxlanGpeBuilder builder = getCustomizer().getBuilder(VXLAN_GPE_ID);
115 getCustomizer().readCurrentAttributes(VXLAN_GPE_ID, builder, ctx);
119 public void testReadCurrentAttributesWrongType() throws Exception {
120 final SwInterfaceDetails v = new SwInterfaceDetails();
121 v.interfaceName = "tap-3".getBytes();
122 InterfaceCustomizer.getCachedInterfaceDump(cache).put(0, v);
124 final VxlanGpeBuilder builder = getCustomizer().getBuilder(VXLAN_GPE_ID);
125 getCustomizer().readCurrentAttributes(VXLAN_GPE_ID, builder, ctx);
128 verifyZeroInteractions(api);
132 protected ReaderCustomizer<VxlanGpe, VxlanGpeBuilder> initCustomizer() {
133 return new VxlanGpeCustomizer(api, interfacesContext);