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.Vxlan;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.VxlanBuilder;
45 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
46 import org.openvpp.jvpp.VppInvocationException;
47 import org.openvpp.jvpp.dto.SwInterfaceDetails;
48 import org.openvpp.jvpp.dto.VxlanTunnelDetails;
49 import org.openvpp.jvpp.dto.VxlanTunnelDetailsReplyDump;
50 import org.openvpp.jvpp.dto.VxlanTunnelDump;
52 public class VxlanCustomizerTest extends ReaderCustomizerTest<Vxlan, VxlanBuilder> {
54 private NamingContext interfacesContext;
55 static final InstanceIdentifier<Vxlan> IID =
56 InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey("ifc1"))
57 .augmentation(VppInterfaceStateAugmentation.class).child(Vxlan.class);
59 public VxlanCustomizerTest() {
64 public void setUpBefore() {
65 interfacesContext = new NamingContext("vxlan-tunnel", "test-instance");
66 doReturn(getMapping("ifc1", 0)).when(mappingContext).read(getMappingIid("ifc1", "test-instance"));
68 final SwInterfaceDetails v = new SwInterfaceDetails();
69 v.interfaceName = "vxlan-tunnel4".getBytes();
70 final Map<Integer, SwInterfaceDetails> map = new HashMap<>();
72 cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, map);
76 protected void setUpAfter() throws UnknownHostException, VppInvocationException {
77 final CompletableFuture<VxlanTunnelDetailsReplyDump> vxlanTunnelDetailsReplyDumpCompletionStage =
78 new CompletableFuture<>();
80 final VxlanTunnelDetailsReplyDump value = new VxlanTunnelDetailsReplyDump();
81 final VxlanTunnelDetails vxlanTunnelDetails = new VxlanTunnelDetails();
82 vxlanTunnelDetails.isIpv6 = 0;
83 vxlanTunnelDetails.decapNextIndex = 1;
84 vxlanTunnelDetails.dstAddress = InetAddress.getByName("1.2.3.4").getAddress();
85 vxlanTunnelDetails.srcAddress = InetAddress.getByName("1.2.3.5").getAddress();
86 vxlanTunnelDetails.encapVrfId = 55;
87 vxlanTunnelDetails.swIfIndex = 0;
88 vxlanTunnelDetails.vni = 9;
90 value.vxlanTunnelDetails = Lists.newArrayList(vxlanTunnelDetails);
91 vxlanTunnelDetailsReplyDumpCompletionStage.complete(value);
93 doReturn(vxlanTunnelDetailsReplyDumpCompletionStage).when(api).vxlanTunnelDump(any(VxlanTunnelDump.class));
97 public void testReadCurrentAttributes() throws Exception {
98 final VxlanBuilder builder = getCustomizer().getBuilder(IID);
99 getCustomizer().readCurrentAttributes(IID, builder, ctx);
101 assertEquals(9, builder.getVni().getValue().intValue());
102 assertEquals(55, builder.getEncapVrfId().intValue());
104 assertNull(builder.getSrc().getIpv6Address());
105 assertNotNull(builder.getSrc().getIpv4Address());
106 assertEquals("1.2.3.5", builder.getSrc().getIpv4Address().getValue());
108 assertNull(builder.getDst().getIpv6Address());
109 assertNotNull(builder.getDst().getIpv4Address());
110 assertEquals("1.2.3.4", builder.getDst().getIpv4Address().getValue());
112 verify(api).vxlanTunnelDump(any(VxlanTunnelDump.class));
115 @Test(expected = NullPointerException.class)
116 public void testReadCurrentAttributesVppNameNotCached() throws Exception {
117 InterfaceCustomizer.getCachedInterfaceDump(cache).remove(0);
119 final VxlanBuilder builder = getCustomizer().getBuilder(IID);
120 getCustomizer().readCurrentAttributes(IID, builder, ctx);
124 public void testReadCurrentAttributesWrongType() throws Exception {
125 final SwInterfaceDetails v = new SwInterfaceDetails();
126 v.interfaceName = "tap-2".getBytes();
127 InterfaceCustomizer.getCachedInterfaceDump(cache).put(0, v);
129 final VxlanBuilder builder = getCustomizer().getBuilder(IID);
130 getCustomizer().readCurrentAttributes(IID, builder, ctx);
133 verifyZeroInteractions(api);
137 protected ReaderCustomizer<Vxlan, VxlanBuilder> initCustomizer() {
138 return new VxlanCustomizer(api, interfacesContext);