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.hc2vpp.routing.read;
19 import static io.fd.hc2vpp.routing.helpers.RoutingRequestTestHelper.ROUTE_PROTOCOL_NAME;
20 import static org.hamcrest.MatcherAssert.assertThat;
21 import static org.hamcrest.Matchers.hasSize;
22 import static org.hamcrest.core.IsCollectionContaining.hasItems;
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.Mockito.when;
27 import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest;
28 import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
29 import io.fd.hc2vpp.common.translate.util.NamingContext;
30 import io.fd.hc2vpp.routing.Ipv4RouteData;
31 import io.fd.hc2vpp.routing.Ipv6RouteData;
32 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
33 import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager;
34 import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor;
35 import io.fd.vpp.jvpp.core.dto.Ip6FibDetails;
36 import io.fd.vpp.jvpp.core.dto.Ip6FibDetailsReplyDump;
37 import io.fd.vpp.jvpp.core.dto.IpFibDetails;
38 import io.fd.vpp.jvpp.core.dto.IpFibDetailsReplyDump;
39 import io.fd.vpp.jvpp.core.types.FibPath;
40 import java.util.Arrays;
41 import java.util.List;
42 import org.junit.Test;
43 import org.mockito.Mock;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.Static;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.ControlPlaneProtocols;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.ControlPlaneProtocolsBuilder;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.control.plane.protocols.ControlPlaneProtocol;
48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.control.plane.protocols.ControlPlaneProtocolBuilder;
49 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.routing.control.plane.protocols.ControlPlaneProtocolKey;
50 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
52 public class ControlPlaneProtocolCustomizerTest
53 extends ListReaderCustomizerTest<ControlPlaneProtocol, ControlPlaneProtocolKey, ControlPlaneProtocolBuilder>
54 implements ByteDataTranslator {
56 private static final String VPP_PROTOCOL_PREFIX = "vpp-protocol";
59 private EntityDumpExecutor<IpFibDetailsReplyDump, Void> ipv4Executor;
62 private EntityDumpExecutor<Ip6FibDetailsReplyDump, Void> ipv6Executor;
63 private DumpCacheManager<IpFibDetailsReplyDump, Void> ipv4RoutesDumpManager;
64 private DumpCacheManager<Ip6FibDetailsReplyDump, Void> ipv6RoutesDumpManager;
66 private NamingContext routingProtocolContext;
68 public ControlPlaneProtocolCustomizerTest() { super(ControlPlaneProtocol.class, ControlPlaneProtocolsBuilder.class);
72 protected void setUp() throws Exception {
73 when(ipv4Executor.executeDump(any(), any())).thenReturn(replyDumpIpv4());
74 when(ipv6Executor.executeDump(any(), any())).thenReturn(replyDumpIpv6());
75 when(ctx.getModificationCache()).thenReturn(cache);
77 ipv4RoutesDumpManager = new DumpCacheManager.DumpCacheManagerBuilder<IpFibDetailsReplyDump, Void>()
78 .withExecutor(ipv4Executor)
79 .acceptOnly(IpFibDetailsReplyDump.class)
82 ipv6RoutesDumpManager = new DumpCacheManager.DumpCacheManagerBuilder<Ip6FibDetailsReplyDump, Void>()
83 .withExecutor(ipv6Executor)
84 .acceptOnly(Ip6FibDetailsReplyDump.class)
87 routingProtocolContext = new NamingContext("routing-protocol", "routing-protocol-context");
88 defineMapping(mappingContext, ROUTE_PROTOCOL_NAME, 1, "routing-protocol-context");
89 defineMapping(mappingContext, "tst-protocol-2", 2, "routing-protocol-context");
90 defineMapping(mappingContext, "tst-protocol-3", 3, "routing-protocol-context");
94 public void getAllIds() throws Exception {
95 final List<ControlPlaneProtocolKey> keys =
96 getCustomizer().getAllIds(InstanceIdentifier.create(ControlPlaneProtocol.class), ctx);
98 assertThat(keys, hasSize(3));
99 assertThat(keys, hasItems(new ControlPlaneProtocolKey(ROUTE_PROTOCOL_NAME, Static.class),
100 new ControlPlaneProtocolKey("tst-protocol-2", Static.class),
101 new ControlPlaneProtocolKey("tst-protocol-3", Static.class)));
105 public void readCurrentAttributes() throws Exception {
106 final InstanceIdentifier<ControlPlaneProtocol> identifier =
107 InstanceIdentifier.create(ControlPlaneProtocols.class)
108 .child(ControlPlaneProtocol.class, new ControlPlaneProtocolKey(ROUTE_PROTOCOL_NAME, Static.class));
110 final ControlPlaneProtocolBuilder builder = new ControlPlaneProtocolBuilder();
111 getCustomizer().readCurrentAttributes(identifier, builder, ctx);
113 assertEquals(ROUTE_PROTOCOL_NAME, builder.getName());
114 assertEquals(ROUTE_PROTOCOL_NAME, builder.getKey().getName());
115 assertEquals(Static.class, builder.getType());
119 protected ReaderCustomizer<ControlPlaneProtocol, ControlPlaneProtocolBuilder> initCustomizer() {
120 return new ControlPlaneProtocolCustomizer(routingProtocolContext, ipv4RoutesDumpManager, ipv6RoutesDumpManager);
123 private Ip6FibDetailsReplyDump replyDumpIpv6() {
124 Ip6FibDetailsReplyDump replyDump = new Ip6FibDetailsReplyDump();
127 Ip6FibDetails detail1 = new Ip6FibDetails();
129 detail1.address = Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY;
130 detail1.addressLength = 24;
132 FibPath path1 = new FibPath();
134 detail1.path = new FibPath[]{path1};
138 Ip6FibDetails detail2 = new Ip6FibDetails();
140 detail2.address = Ipv6RouteData.SECOND_ADDRESS_AS_ARRAY;
141 detail2.addressLength = 22;
142 detail2.path = new FibPath[]{};
144 FibPath path2 = new FibPath();
146 path2.nextHop = Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY;
149 detail2.path = new FibPath[]{path2};
152 Ip6FibDetails detail3 = new Ip6FibDetails();
154 detail3.address = Ipv6RouteData.SECOND_ADDRESS_AS_ARRAY;
155 detail3.addressLength = 16;
157 FibPath path3 = new FibPath();
160 path3.nextHop = Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY;
163 FibPath path4 = new FibPath();
166 path4.nextHop = Ipv6RouteData.SECOND_ADDRESS_AS_ARRAY;
169 detail3.path = new FibPath[]{path3, path4};
171 replyDump.ip6FibDetails = Arrays.asList(detail1, detail2, detail3);
175 private IpFibDetailsReplyDump replyDumpIpv4() {
176 IpFibDetailsReplyDump replyDump = new IpFibDetailsReplyDump();
179 IpFibDetails detail1 = new IpFibDetails();
181 detail1.address = Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY;
182 detail1.addressLength = 24;
184 FibPath path1 = new FibPath();
186 detail1.path = new FibPath[]{path1};
190 IpFibDetails detail2 = new IpFibDetails();
192 detail2.address = Ipv4RouteData.SECOND_ADDRESS_AS_ARRAY;
193 detail2.addressLength = 22;
194 detail2.path = new FibPath[]{};
196 FibPath path2 = new FibPath();
198 path2.nextHop = Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY;
201 detail2.path = new FibPath[]{path2};
204 IpFibDetails detail3 = new IpFibDetails();
206 detail3.address = Ipv4RouteData.SECOND_ADDRESS_AS_ARRAY;
207 detail3.addressLength = 16;
209 FibPath path3 = new FibPath();
212 path3.nextHop = Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY;
215 FibPath path4 = new FibPath();
218 path4.nextHop = Ipv4RouteData.SECOND_ADDRESS_AS_ARRAY;
221 detail3.path = new FibPath[]{path3, path4};
223 replyDump.ipFibDetails = Arrays.asList(detail1, detail2, detail3);