2 * Copyright (c) 2017 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.hc2vpp.routing.write;
19 import static org.mockito.ArgumentMatchers.any;
20 import static org.mockito.Mockito.mock;
21 import static org.mockito.Mockito.verify;
22 import static org.mockito.Mockito.when;
24 import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
25 import io.fd.hc2vpp.common.translate.util.NamingContext;
26 import io.fd.hc2vpp.routing.helpers.SchemaContextTestHelper;
27 import io.fd.honeycomb.test.tools.HoneycombTestRunner;
28 import io.fd.honeycomb.test.tools.annotations.InjectTestData;
29 import io.fd.honeycomb.translate.write.WriteFailedException;
30 import io.fd.vpp.jvpp.core.dto.SwInterfaceIp6NdRaConfig;
31 import io.fd.vpp.jvpp.core.dto.SwInterfaceIp6NdRaConfigReply;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev170917.Interface1;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev170917.routing.routing.instance.interfaces._interface.Ipv6RouterAdvertisements;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.Routing;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.routing.RoutingInstance;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.routing.RoutingInstanceKey;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.routing.routing.instance.Interfaces;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.routing.routing.instance.interfaces.Interface;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.routing.routing.instance.interfaces.InterfaceKey;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
44 @RunWith(HoneycombTestRunner.class)
45 public class RouterAdvertisementsCustomizerTest extends WriterCustomizerTest implements SchemaContextTestHelper {
47 private static final String INSTANCE_NAME = "tst-protocol";
48 private static final String CTX_NAME = "interface-context";
49 private static final String IFC_NAME = "eth0";
50 private static final int IFC_INDEX = 1;
51 private static final InstanceIdentifier<Ipv6RouterAdvertisements> IID = InstanceIdentifier.create(Routing.class)
52 .child(RoutingInstance.class, new RoutingInstanceKey(INSTANCE_NAME)).child(Interfaces.class)
53 .child(Interface.class, new InterfaceKey(IFC_NAME)).augmentation(
54 Interface1.class).child(Ipv6RouterAdvertisements.class);
56 private static final String RA_PATH = "/hc2vpp-ietf-routing:routing" +
57 "/hc2vpp-ietf-routing:routing-instance[hc2vpp-ietf-routing:name='" + INSTANCE_NAME + "']" +
58 "/hc2vpp-ietf-routing:interfaces";
60 private RouterAdvertisementsCustomizer customizer;
61 private NamingContext interfaceContext = new NamingContext("ifaces", CTX_NAME);
65 protected void setUpTest() throws Exception {
66 customizer = new RouterAdvertisementsCustomizer(api, interfaceContext);
67 defineMapping(mappingContext, IFC_NAME, IFC_INDEX, CTX_NAME);
68 when(api.swInterfaceIp6NdRaConfig(any())).thenReturn(future(new SwInterfaceIp6NdRaConfigReply()));
72 public void testWrite(@InjectTestData(resourcePath = "/ra/simpleRa.json", id = RA_PATH) Interfaces ifc)
73 throws WriteFailedException {
74 final Ipv6RouterAdvertisements data = getRA(ifc);
75 customizer.writeCurrentAttributes(IID, data, writeContext);
76 final SwInterfaceIp6NdRaConfig request = new SwInterfaceIp6NdRaConfig();
77 request.swIfIndex = IFC_INDEX;
78 request.maxInterval = 600;
80 verify(api).swInterfaceIp6NdRaConfig(request);
84 public void testUpdate(@InjectTestData(resourcePath = "/ra/complexRa.json", id = RA_PATH) Interfaces ifc)
85 throws WriteFailedException {
86 final Ipv6RouterAdvertisements data = getRA(ifc);
87 customizer.updateCurrentAttributes(IID, mock(Ipv6RouterAdvertisements.class), data, writeContext);
88 final SwInterfaceIp6NdRaConfig request = new SwInterfaceIp6NdRaConfig();
89 request.swIfIndex = IFC_INDEX;
90 request.initialCount = 2;
91 request.initialInterval = 15;
92 request.maxInterval = 100;
93 request.minInterval = 20;
94 request.lifetime = 601;
95 request.defaultRouter = 1;
96 verify(api).swInterfaceIp6NdRaConfig(request);
100 public void testDelete() throws WriteFailedException {
101 customizer.deleteCurrentAttributes(IID, mock(Ipv6RouterAdvertisements.class), writeContext);
102 final SwInterfaceIp6NdRaConfig request = new SwInterfaceIp6NdRaConfig();
103 request.swIfIndex = IFC_INDEX;
104 request.suppress = 1;
105 verify(api).swInterfaceIp6NdRaConfig(request);
108 private static Ipv6RouterAdvertisements getRA(final Interfaces ifc) {
109 return ifc.getInterface().get(0).getAugmentation(Interface1.class).getIpv6RouterAdvertisements();