bf33be31d8cd92ba970730a2adf0d0a3f8da87a3
[honeycomb.git] /
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package io.fd.honeycomb.translate.v3po.interfacesstate;
18
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;
26
27 import com.google.common.collect.Lists;
28 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
29 import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
30 import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest;
31 import io.fd.honeycomb.translate.v3po.util.NamingContext;
32 import java.net.InetAddress;
33 import java.net.UnknownHostException;
34 import java.util.HashMap;
35 import java.util.Map;
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.VxlanGpe;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.VxlanGpeBuilder;
44 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
45 import org.openvpp.jvpp.VppBaseCallException;
46 import org.openvpp.jvpp.core.dto.SwInterfaceDetails;
47 import org.openvpp.jvpp.core.dto.VxlanGpeTunnelDetails;
48 import org.openvpp.jvpp.core.dto.VxlanGpeTunnelDetailsReplyDump;
49 import org.openvpp.jvpp.core.dto.VxlanGpeTunnelDump;
50
51 public class VxlanGpeCustomizerTest extends ReaderCustomizerTest<VxlanGpe, VxlanGpeBuilder> {
52
53     private static final String IFC_CTX_NAME = "ifc-test-instance";
54     private static final String IF_NAME = "ifc2";
55     private static final int IF_INDEX = 0;
56
57     private NamingContext interfacesContext;
58     private static final InstanceIdentifier<VxlanGpe> VXLAN_GPE_ID =
59         InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME))
60             .augmentation(VppInterfaceStateAugmentation.class).child(VxlanGpe.class);
61
62     public VxlanGpeCustomizerTest() {
63         super(VxlanGpe.class);
64     }
65
66     @Override
67     public void setUp() throws UnknownHostException, VppBaseCallException {
68         interfacesContext = new NamingContext("vxlan_gpe_inf", IFC_CTX_NAME);
69         ContextTestUtils.mockMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
70
71         final SwInterfaceDetails v = new SwInterfaceDetails();
72         v.interfaceName = "vxlan_gpe_inf2".getBytes();
73         final Map<Integer, SwInterfaceDetails> map = new HashMap<>();
74         map.put(0, v);
75         cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, map);
76
77         final CompletableFuture<VxlanGpeTunnelDetailsReplyDump> vxlanGpeTunnelDetailsReplyDumpCompletionStage =
78             new CompletableFuture<>();
79
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;
90
91         value.vxlanGpeTunnelDetails = Lists.newArrayList(vxlanGpeTunnelDetails);
92         vxlanGpeTunnelDetailsReplyDumpCompletionStage.complete(value);
93
94         doReturn(vxlanGpeTunnelDetailsReplyDumpCompletionStage).when(api).vxlanGpeTunnelDump(any(VxlanGpeTunnelDump.class));
95
96     }
97
98     @Test
99     public void testReadCurrentAttributes() throws Exception {
100         final VxlanGpeBuilder builder = getCustomizer().getBuilder(VXLAN_GPE_ID);
101         getCustomizer().readCurrentAttributes(VXLAN_GPE_ID, builder, ctx);
102
103         assertNull(builder.getLocal().getIpv6Address());
104         assertNotNull(builder.getLocal().getIpv4Address());
105         assertEquals("1.2.3.4", builder.getLocal().getIpv4Address().getValue());
106
107         assertNull(builder.getRemote().getIpv6Address());
108         assertNotNull(builder.getRemote().getIpv4Address());
109         assertEquals("1.2.3.5", builder.getRemote().getIpv4Address().getValue());
110
111         assertEquals(9, builder.getVni().getValue().intValue());
112         assertEquals(1, builder.getNextProtocol().getIntValue());
113         assertEquals(55, builder.getEncapVrfId().intValue());
114         assertEquals(66, builder.getDecapVrfId().intValue());
115
116         verify(api).vxlanGpeTunnelDump(any(VxlanGpeTunnelDump.class));
117     }
118
119     @Test(expected = NullPointerException.class)
120     public void testReadCurrentAttributesVppNameNotCached() throws Exception {
121         InterfaceCustomizer.getCachedInterfaceDump(cache).remove(0);
122
123         final VxlanGpeBuilder builder = getCustomizer().getBuilder(VXLAN_GPE_ID);
124         getCustomizer().readCurrentAttributes(VXLAN_GPE_ID, builder, ctx);
125     }
126
127     @Test
128     public void testReadCurrentAttributesWrongType() throws Exception {
129         final SwInterfaceDetails v = new SwInterfaceDetails();
130         v.interfaceName = "tap-3".getBytes();
131         InterfaceCustomizer.getCachedInterfaceDump(cache).put(0, v);
132
133         final VxlanGpeBuilder builder = getCustomizer().getBuilder(VXLAN_GPE_ID);
134         getCustomizer().readCurrentAttributes(VXLAN_GPE_ID, builder, ctx);
135
136         // Should be ignored
137         verifyZeroInteractions(api);
138     }
139
140     @Override
141     protected ReaderCustomizer<VxlanGpe, VxlanGpeBuilder> initCustomizer() {
142         return new VxlanGpeCustomizer(api, interfacesContext);
143     }
144 }
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286