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 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.v3po.translate.Context;
29 import io.fd.honeycomb.v3po.translate.spi.read.RootReaderCustomizer;
30 import io.fd.honeycomb.v3po.translate.v3po.test.ChildReaderCustomizerTest;
31 import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
32 import java.net.InetAddress;
33 import java.net.UnknownHostException;
34 import java.util.HashMap;
36 import java.util.concurrent.CompletableFuture;
37 import org.junit.Test;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentation;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Vxlan;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.VxlanBuilder;
44 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
45 import org.openvpp.jvpp.dto.SwInterfaceDetails;
46 import org.openvpp.jvpp.dto.VxlanTunnelDetails;
47 import org.openvpp.jvpp.dto.VxlanTunnelDetailsReplyDump;
48 import org.openvpp.jvpp.dto.VxlanTunnelDump;
50 public class VxlanCustomizerTest extends ChildReaderCustomizerTest<Vxlan, VxlanBuilder> {
52 private NamingContext interfacesContext;
54 static final InstanceIdentifier<Vxlan> IID =
55 InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey("ifc1"))
56 .augmentation(VppInterfaceStateAugmentation.class).child(Vxlan.class);
58 public VxlanCustomizerTest() {
63 public void setUpBefore() {
64 interfacesContext = new NamingContext("vxlan-tunnel");
65 interfacesContext.addName(0, "ifc1");
68 final SwInterfaceDetails v = new SwInterfaceDetails();
69 v.interfaceName = "vxlan-tunnel4".getBytes();
70 final Map<Integer, SwInterfaceDetails> map = new HashMap<>();
72 ctx.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, map);
76 protected void setUpAfter() throws UnknownHostException {
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().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(ctx).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(ctx).put(0, v);
129 final VxlanBuilder builder = getCustomizer().getBuilder(IID);
130 getCustomizer().readCurrentAttributes(IID, builder, ctx);
133 verifyZeroInteractions(api);
137 protected RootReaderCustomizer<Vxlan, VxlanBuilder> initCustomizer() {
138 return new VxlanCustomizer(api, interfacesContext);