d5f504094d27a79e347d0ad945b6a4e5763ac1c1
[hc2vpp.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.hc2vpp.routing.write.factory;
18
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;
24
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;
43
44 @RunWith(HoneycombTestRunner.class)
45 public class SpecialNextHopRequestFactoryIpv6Test
46         implements RoutingRequestTestHelper, ClassifyTableTestHelper, SchemaContextTestHelper {
47
48     @Mock
49     private VppClassifierContextManager classifierContextManager;
50
51     @Mock
52     private MappingContext mappingContext;
53
54     private SpecialNextHopRequestFactory factory;
55
56     @Before
57     public void init() {
58         MockitoAnnotations.initMocks(this);
59         factory = SpecialNextHopRequestFactory.forClassifierContext(classifierContextManager);
60
61         addMapping(classifierContextManager, CLASSIFY_TABLE_NAME, CLASSIFY_TABLE_INDEX, mappingContext);
62     }
63
64     @Test
65     public void testIpv6Blackhole(
66             @InjectTestData(resourcePath = "/ipv6/specialhop/specialHopRouteBlackhole.json", id = STATIC_ROUTE_PATH)
67                     StaticRoutes routes) {
68         final IpAddDelRoute request =
69                 factory.createIpv6SpecialHopRequest(true, extractSingleRoute(routes, 1L), mappingContext, Blackhole);
70
71         assertEquals(desiredSpecialResult(1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 1, 0, 0, 0),
72                 request);
73     }
74
75     @Test
76     public void testIpv6Receive(
77             @InjectTestData(resourcePath = "/ipv6/specialhop/specialHopRouteReceive.json", id = STATIC_ROUTE_PATH)
78                     StaticRoutes routes) {
79         final IpAddDelRoute request =
80                 factory.createIpv6SpecialHopRequest(true, extractSingleRoute(routes, 1L), mappingContext, Receive);
81
82         assertEquals(desiredSpecialResult(1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 0, 1, 0, 0), request);
83     }
84
85     @Test
86     public void testIpv6Unreach(
87             @InjectTestData(resourcePath = "/ipv6/specialhop/specialHopRouteUnreachable.json", id = STATIC_ROUTE_PATH)
88                     StaticRoutes routes) {
89         final IpAddDelRoute request =
90                 factory.createIpv6SpecialHopRequest(true, extractSingleRoute(routes, 1L), mappingContext, Unreachable);
91
92         assertEquals(desiredSpecialResult(1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 0, 0, 1, 0), request);
93     }
94
95     @Test
96     public void testIpv6Prohibited(
97             @InjectTestData(resourcePath = "/ipv6/specialhop/specialHopRouteProhibited.json", id = STATIC_ROUTE_PATH)
98                     StaticRoutes routes) {
99         final IpAddDelRoute request =
100                 factory.createIpv6SpecialHopRequest(true, extractSingleRoute(routes, 1L), mappingContext, Prohibit);
101
102         assertEquals(desiredSpecialResult(1, 1, Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY, 24, 0, 0, 0, 1), request);
103     }
104
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());
109     }
110
111 }