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;
20 import static org.junit.Assert.assertEquals;
22 import io.fd.hc2vpp.common.translate.util.NamingContext;
23 import io.fd.hc2vpp.routing.Ipv4RouteData;
24 import io.fd.hc2vpp.routing.helpers.ClassifyTableTestHelper;
25 import io.fd.hc2vpp.routing.helpers.InterfaceTestHelper;
26 import io.fd.hc2vpp.routing.helpers.RoutingRequestTestHelper;
27 import io.fd.hc2vpp.routing.helpers.SchemaContextTestHelper;
28 import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager;
29 import io.fd.honeycomb.test.tools.HoneycombTestRunner;
30 import io.fd.honeycomb.test.tools.annotations.InjectTestData;
31 import io.fd.honeycomb.translate.MappingContext;
32 import io.fd.vpp.jvpp.core.dto.IpAddDelRoute;
33 import java.util.List;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.mockito.Mock;
38 import org.mockito.MockitoAnnotations;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev170917.routing.routing.instance.routing.protocols.routing.protocol._static.routes.ipv4.Route;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev170917.routing.routing.instance.routing.protocols.routing.protocol._static.routes.ipv4.route.next.hop.options.NextHopList;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev170917.routing.routing.instance.routing.protocols.routing.protocol._static.routes.ipv4.route.next.hop.options.next.hop.list.next.hop.list.NextHop;
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 MultipathHopRequestFactoryIpv4Test
46 implements RoutingRequestTestHelper, ClassifyTableTestHelper, SchemaContextTestHelper, InterfaceTestHelper {
49 private VppClassifierContextManager classifierContextManager;
52 private MappingContext mappingContext;
54 @InjectTestData(resourcePath = "/ipv4/multihop/multiHopRouteWithClassifier.json", id = STATIC_ROUTE_PATH)
55 private StaticRoutes ipv4StaticRoutesWithClassifier;
57 @InjectTestData(resourcePath = "/ipv4/multihop/multiHopRouteWithoutClassifier.json", id = STATIC_ROUTE_PATH)
58 private StaticRoutes ipv4StaticRoutesWithoutClassifier;
60 @InjectTestData(resourcePath = "/ipv4/multihop/multiHopRouteWithNoRouteAttrs.json", id = STATIC_ROUTE_PATH)
61 private StaticRoutes ipv4StaticRoutesWithoutRouteAttrs;
63 private Route ipv4MutlipathRouteWithClassifier;
64 private NextHop ipv4nextHopWithClassifier;
66 private Route ipv4MutlipathRouteWithoutClassifier;
67 private NextHop ipv4nextHopWithoutClassifier;
69 private Route ipv4MutlipathRouteWithoutRouteAtts;
70 private NextHop ipv4nextHopWithoutRouteAtts;
72 private NamingContext interfaceContext;
73 private NamingContext routingProtocolContext;
74 private MultipathHopRequestFactory factory;
78 MockitoAnnotations.initMocks(this);
79 interfaceContext = new NamingContext("interface", "interface-context");
80 routingProtocolContext = new NamingContext("routing-protocol", "routing-protocol-context");
81 factory = MultipathHopRequestFactory
82 .forContexts(classifierContextManager, interfaceContext, routingProtocolContext);
84 addMapping(classifierContextManager, CLASSIFY_TABLE_NAME, CLASSIFY_TABLE_INDEX, mappingContext);
85 defineMapping(mappingContext, INTERFACE_NAME, INTERFACE_INDEX, "interface-context");
86 defineMapping(mappingContext, ROUTE_PROTOCOL_NAME, 1, "routing-protocol-context");
88 ipv4MutlipathRouteWithClassifier = getIpv4RouteWithId(ipv4StaticRoutesWithClassifier, 1L);
89 final List<NextHop> ipv4HopsClassified =
90 NextHopList.class.cast(ipv4MutlipathRouteWithClassifier.getNextHopOptions()).getNextHopList()
92 ipv4nextHopWithClassifier =
93 ipv4HopsClassified.stream().filter(nextHop -> nextHop.getId() == 1L).findFirst().get();
95 ipv4MutlipathRouteWithoutClassifier = getIpv4RouteWithId(ipv4StaticRoutesWithoutClassifier, 1L);
96 final List<NextHop> ipv4HopsNonClassified =
97 NextHopList.class.cast(ipv4MutlipathRouteWithoutClassifier.getNextHopOptions()).getNextHopList()
99 ipv4nextHopWithoutClassifier =
100 ipv4HopsNonClassified.stream().filter(nextHop -> nextHop.getId() == 1L).findFirst().get();
102 ipv4MutlipathRouteWithoutRouteAtts = getIpv4RouteWithId(ipv4StaticRoutesWithoutRouteAttrs, 1L);
103 final List<NextHop> ipv4HopsNonRouteAttrs =
104 NextHopList.class.cast(ipv4MutlipathRouteWithoutRouteAtts.getNextHopOptions()).getNextHopList()
106 ipv4nextHopWithoutRouteAtts =
107 ipv4HopsNonClassified.stream().filter(nextHop -> nextHop.getId() == 1L).findFirst().get();
111 public void testIpv4WithClassifier() {
112 final IpAddDelRoute request =
113 factory.createIpv4MultipathHopRequest(false, ROUTE_PROTOCOL_NAME, ipv4MutlipathRouteWithClassifier,
114 ipv4nextHopWithClassifier,
117 assertEquals(desiredFlaglessResult(0, 0, 1, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24,
118 Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 2, 1, 0, CLASSIFY_TABLE_INDEX, 1), request);
122 public void testIpv4WithoutClassifier() {
123 final IpAddDelRoute request =
124 factory.createIpv4MultipathHopRequest(false, ROUTE_PROTOCOL_NAME, ipv4MutlipathRouteWithoutClassifier,
125 ipv4nextHopWithoutClassifier,
129 desiredFlaglessResult(0, 0, 1, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24,
130 Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 2, 1, 0, 0, 0), request);
134 public void testIpv4WithoutRouteAttrs() {
135 final IpAddDelRoute request =
136 factory.createIpv4MultipathHopRequest(false, ROUTE_PROTOCOL_NAME, ipv4MutlipathRouteWithoutRouteAtts,
137 ipv4nextHopWithoutRouteAtts,
141 desiredFlaglessResult(0, 0, 1, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24,
142 Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 2, 1, 0, 0, 0), request);