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.v3po.translate.v3po.interfacesstate;
19 import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping;
20 import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid;
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertNotNull;
23 import static org.junit.Assert.assertNull;
24 import static org.mockito.Matchers.any;
25 import static org.mockito.Mockito.doReturn;
26 import static org.mockito.Mockito.verify;
27 import static org.mockito.Mockito.verifyZeroInteractions;
29 import com.google.common.collect.Lists;
30 import io.fd.honeycomb.v3po.translate.spi.read.ReaderCustomizer;
31 import io.fd.honeycomb.v3po.translate.v3po.test.ReaderCustomizerTest;
32 import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
33 import java.net.InetAddress;
34 import java.net.UnknownHostException;
35 import java.util.HashMap;
37 import java.util.concurrent.CompletableFuture;
38 import org.junit.Test;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentation;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.VxlanGpe;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.VxlanGpeBuilder;
45 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
46 import org.openvpp.jvpp.VppBaseCallException;
47 import org.openvpp.jvpp.dto.SwInterfaceDetails;
48 import org.openvpp.jvpp.dto.VxlanGpeTunnelDetails;
49 import org.openvpp.jvpp.dto.VxlanGpeTunnelDetailsReplyDump;
50 import org.openvpp.jvpp.dto.VxlanGpeTunnelDump;
52 public class VxlanGpeCustomizerTest extends ReaderCustomizerTest<VxlanGpe, VxlanGpeBuilder> {
54 private NamingContext interfacesContext;
55 static final InstanceIdentifier<VxlanGpe> VXLAN_GPE_ID =
56 InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey("ifc2"))
57 .augmentation(VppInterfaceStateAugmentation.class).child(VxlanGpe.class);
59 public VxlanGpeCustomizerTest() {
60 super(VxlanGpe.class);
64 public void setUpBefore() {
65 interfacesContext = new NamingContext("vxlan_gpe_inf", "test-instance");
66 doReturn(getMapping("ifc2", 0)).when(mappingContext).read(getMappingIid("ifc2", "test-instance"));
68 final SwInterfaceDetails v = new SwInterfaceDetails();
69 v.interfaceName = "vxlan_gpe_inf2".getBytes();
70 final Map<Integer, SwInterfaceDetails> map = new HashMap<>();
72 cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, map);
76 protected void setUpAfter() throws UnknownHostException, VppBaseCallException {
77 final CompletableFuture<VxlanGpeTunnelDetailsReplyDump> vxlanGpeTunnelDetailsReplyDumpCompletionStage =
78 new CompletableFuture<>();
80 final VxlanGpeTunnelDetailsReplyDump value = new VxlanGpeTunnelDetailsReplyDump();
81 final VxlanGpeTunnelDetails vxlanGpeTunnelDetails = new VxlanGpeTunnelDetails();
82 vxlanGpeTunnelDetails.isIpv6 = 0;
83 vxlanGpeTunnelDetails.local = InetAddress.getByName("1.2.3.4").getAddress();
84 vxlanGpeTunnelDetails.remote = InetAddress.getByName("1.2.3.5").getAddress();
85 vxlanGpeTunnelDetails.vni = 9;
86 vxlanGpeTunnelDetails.protocol = 1;
87 vxlanGpeTunnelDetails.encapVrfId = 55;
88 vxlanGpeTunnelDetails.decapVrfId = 66;
89 vxlanGpeTunnelDetails.swIfIndex = 0;
91 value.vxlanGpeTunnelDetails = Lists.newArrayList(vxlanGpeTunnelDetails);
92 vxlanGpeTunnelDetailsReplyDumpCompletionStage.complete(value);
94 doReturn(vxlanGpeTunnelDetailsReplyDumpCompletionStage).when(api).vxlanGpeTunnelDump(any(VxlanGpeTunnelDump.class));
98 public void testReadCurrentAttributes() throws Exception {
99 final VxlanGpeBuilder builder = getCustomizer().getBuilder(VXLAN_GPE_ID);
100 getCustomizer().readCurrentAttributes(VXLAN_GPE_ID, builder, ctx);
102 assertNull(builder.getLocal().getIpv6Address());
103 assertNotNull(builder.getLocal().getIpv4Address());
104 assertEquals("1.2.3.4", builder.getLocal().getIpv4Address().getValue());
106 assertNull(builder.getRemote().getIpv6Address());
107 assertNotNull(builder.getRemote().getIpv4Address());
108 assertEquals("1.2.3.5", builder.getRemote().getIpv4Address().getValue());
110 assertEquals(9, builder.getVni().getValue().intValue());
111 assertEquals(1, builder.getNextProtocol().getIntValue());
112 assertEquals(55, builder.getEncapVrfId().intValue());
113 assertEquals(66, builder.getDecapVrfId().intValue());
115 verify(api).vxlanGpeTunnelDump(any(VxlanGpeTunnelDump.class));
118 @Test(expected = NullPointerException.class)
119 public void testReadCurrentAttributesVppNameNotCached() throws Exception {
120 InterfaceCustomizer.getCachedInterfaceDump(cache).remove(0);
122 final VxlanGpeBuilder builder = getCustomizer().getBuilder(VXLAN_GPE_ID);
123 getCustomizer().readCurrentAttributes(VXLAN_GPE_ID, builder, ctx);
127 public void testReadCurrentAttributesWrongType() throws Exception {
128 final SwInterfaceDetails v = new SwInterfaceDetails();
129 v.interfaceName = "tap-3".getBytes();
130 InterfaceCustomizer.getCachedInterfaceDump(cache).put(0, v);
132 final VxlanGpeBuilder builder = getCustomizer().getBuilder(VXLAN_GPE_ID);
133 getCustomizer().readCurrentAttributes(VXLAN_GPE_ID, builder, ctx);
136 verifyZeroInteractions(api);
140 protected ReaderCustomizer<VxlanGpe, VxlanGpeBuilder> initCustomizer() {
141 return new VxlanGpeCustomizer(api, interfacesContext);