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.write.factory;
19 import static org.junit.Assert.assertEquals;
20 import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.SpecialNextHopGrouping.SpecialNextHop.Blackhole;
21 import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.SpecialNextHopGrouping.SpecialNextHop.Prohibit;
22 import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.SpecialNextHopGrouping.SpecialNextHop.Receive;
23 import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.SpecialNextHopGrouping.SpecialNextHop.Unreachable;
25 import io.fd.hc2vpp.routing.Ipv6RouteData;
26 import io.fd.hc2vpp.routing.helpers.ClassifyTableTestHelper;
27 import io.fd.hc2vpp.routing.helpers.RoutingRequestTestHelper;
28 import io.fd.hc2vpp.routing.helpers.SchemaContextTestHelper;
29 import io.fd.hc2vpp.v3po.vppclassifier.VppClassifierContextManager;
30 import io.fd.honeycomb.test.tools.HoneycombTestRunner;
31 import io.fd.honeycomb.test.tools.annotations.InjectTestData;
32 import io.fd.honeycomb.translate.MappingContext;
33 import io.fd.honeycomb.translate.util.RWUtils;
34 import io.fd.vpp.jvpp.core.dto.IpAddDelRoute;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.mockito.Mock;
39 import org.mockito.MockitoAnnotations;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev140525.StaticRoutes1;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev140525.routing.routing.instance.routing.protocols.routing.protocol._static.routes.ipv6.Route;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.routing.routing.instance.routing.protocols.routing.protocol.StaticRoutes;
44 @RunWith(HoneycombTestRunner.class)
45 public class SpecialNextHopRequestFactoryIpv6Test
46 implements RoutingRequestTestHelper, ClassifyTableTestHelper, SchemaContextTestHelper {
49 private VppClassifierContextManager classifierContextManager;
52 private MappingContext mappingContext;
54 private SpecialNextHopRequestFactory factory;
58 MockitoAnnotations.initMocks(this);
59 factory = SpecialNextHopRequestFactory.forClassifierContext(classifierContextManager);
61 addMapping(classifierContextManager, CLASSIFY_TABLE_NAME, CLASSIFY_TABLE_INDEX, mappingContext);
65 public void testIpv6Blackhole(
66 @InjectTestData(resourcePath = "/ipv6/specialHopRouteBlackhole.json", id = STATIC_ROUTE_PATH)
67 StaticRoutes routes) {
68 final IpAddDelRoute request =
69 factory.createIpv6SpecialHopRequest(true, extractSingleRoute(routes, 1L), mappingContext, Blackhole);
71 assertEquals(desiredSpecialResult(1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 1, 0, 0, 0),
76 public void testIpv6Receive(
77 @InjectTestData(resourcePath = "/ipv6/specialHopRouteReceive.json", id = STATIC_ROUTE_PATH)
78 StaticRoutes routes) {
79 final IpAddDelRoute request =
80 factory.createIpv6SpecialHopRequest(true, extractSingleRoute(routes, 1L), mappingContext, Receive);
82 assertEquals(desiredSpecialResult(1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 0, 1, 0, 0), request);
86 public void testIpv6Unreach(
87 @InjectTestData(resourcePath = "/ipv6/specialHopRouteUnreachable.json", id = STATIC_ROUTE_PATH)
88 StaticRoutes routes) {
89 final IpAddDelRoute request =
90 factory.createIpv6SpecialHopRequest(true, extractSingleRoute(routes, 1L), mappingContext, Unreachable);
92 assertEquals(desiredSpecialResult(1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 0, 0, 1, 0), request);
96 public void testIpv6Prohibited(
97 @InjectTestData(resourcePath = "/ipv6/specialHopRouteProhibited.json", id = STATIC_ROUTE_PATH)
98 StaticRoutes routes) {
99 final IpAddDelRoute request =
100 factory.createIpv6SpecialHopRequest(true, extractSingleRoute(routes, 1L), mappingContext, Prohibit);
102 assertEquals(desiredSpecialResult(1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 0, 0, 0, 1), request);
105 private Route extractSingleRoute(final StaticRoutes staticRoutes, final long id) {
106 return staticRoutes.getAugmentation(StaticRoutes1.class).getIpv6().getRoute().stream()
107 .filter(route -> route.getId() == id).collect(
108 RWUtils.singleItemCollector());