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.Prohibit;
21 import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.SpecialNextHopGrouping.SpecialNextHop.Receive;
22 import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.SpecialNextHopGrouping.SpecialNextHop.Unreachable;
24 import io.fd.hc2vpp.routing.Ipv4RouteData;
25 import io.fd.hc2vpp.routing.helpers.ClassifyTableTestHelper;
26 import io.fd.hc2vpp.routing.helpers.RoutingRequestTestHelper;
27 import io.fd.hc2vpp.routing.helpers.SchemaContextTestHelper;
28 import io.fd.hc2vpp.routing.write.trait.RouteRequestProducer;
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.ipv4.unicast.routing.rev140524.StaticRoutes1;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev140524.routing.routing.instance.routing.protocols.routing.protocol._static.routes.ipv4.Route;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.SpecialNextHopGrouping;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.routing.routing.instance.routing.protocols.routing.protocol.StaticRoutes;
45 @RunWith(HoneycombTestRunner.class)
46 public class SpecialNextHopRequestFactoryIpv4Test
47 implements RouteRequestProducer, RoutingRequestTestHelper, ClassifyTableTestHelper,
48 SchemaContextTestHelper {
51 private VppClassifierContextManager classifierContextManager;
54 private MappingContext mappingContext;
56 private SpecialNextHopRequestFactory factory;
60 MockitoAnnotations.initMocks(this);
61 factory = SpecialNextHopRequestFactory.forClassifierContext(classifierContextManager);
63 addMapping(classifierContextManager, CLASSIFY_TABLE_NAME, CLASSIFY_TABLE_INDEX, mappingContext);
67 public void testIpv4WithClassifierBlackhole(
68 @InjectTestData(resourcePath = "/ipv4/specialHopRouteBlackhole.json", id = STATIC_ROUTE_PATH)
69 StaticRoutes routes) {
70 final IpAddDelRoute request =
71 factory.createIpv4SpecialHopRequest(true, extractSingleRoute(routes, 1L), mappingContext,
72 SpecialNextHopGrouping.SpecialNextHop.Blackhole);
74 assertEquals(desiredSpecialResult(1, 0, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 1, 0, 0, 0), request);
78 public void testIpv4WithClassifierReceive(
79 @InjectTestData(resourcePath = "/ipv4/specialHopRouteReceive.json", id = STATIC_ROUTE_PATH)
80 StaticRoutes routes) {
81 final IpAddDelRoute request =
82 factory.createIpv4SpecialHopRequest(true, extractSingleRoute(routes, 1L), mappingContext, Receive);
84 assertEquals(desiredSpecialResult(1, 0, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 0, 1, 0, 0), request);
88 public void testIpv4WithClassifierUnreach(
89 @InjectTestData(resourcePath = "/ipv4/specialHopRouteUnreachable.json", id = STATIC_ROUTE_PATH)
90 StaticRoutes routes) {
91 final IpAddDelRoute request =
92 factory.createIpv4SpecialHopRequest(true, extractSingleRoute(routes, 1L), mappingContext, Unreachable);
94 assertEquals(desiredSpecialResult(1, 0, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 0, 0, 1, 0), request);
98 public void testIpv4WithClassifierProhibited(
99 @InjectTestData(resourcePath = "/ipv4/specialHopRouteProhibited.json", id = STATIC_ROUTE_PATH)
100 StaticRoutes routes) {
101 final IpAddDelRoute request =
102 factory.createIpv4SpecialHopRequest(true, extractSingleRoute(routes, 1L), mappingContext, Prohibit);
104 assertEquals(desiredSpecialResult(1, 0, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 0, 0, 0, 1), request);
107 private Route extractSingleRoute(final StaticRoutes staticRoutes, final long id) {
108 return staticRoutes.getAugmentation(StaticRoutes1.class).getIpv4().getRoute().stream()
109 .filter(route -> route.getId() == id)
110 .collect(RWUtils.singleItemCollector());