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;
21 import io.fd.hc2vpp.common.translate.util.NamingContext;
22 import io.fd.hc2vpp.routing.Ipv4RouteData;
23 import io.fd.hc2vpp.routing.helpers.ClassifyTableTestHelper;
24 import io.fd.hc2vpp.routing.helpers.InterfaceTestHelper;
25 import io.fd.hc2vpp.routing.helpers.RoutingRequestTestHelper;
26 import io.fd.hc2vpp.routing.helpers.SchemaContextTestHelper;
27 import io.fd.hc2vpp.v3po.vppclassifier.VppClassifierContextManager;
28 import io.fd.honeycomb.test.tools.HoneycombTestRunner;
29 import io.fd.honeycomb.test.tools.annotations.InjectTestData;
30 import io.fd.honeycomb.translate.MappingContext;
31 import io.fd.vpp.jvpp.core.dto.IpAddDelRoute;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.mockito.Mock;
36 import org.mockito.MockitoAnnotations;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev140524.StaticRoutes1;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.routing.routing.instance.routing.protocols.routing.protocol.StaticRoutes;
40 @RunWith(HoneycombTestRunner.class)
41 public class SimpleHopRequestFactoryIpv4Test
42 implements RoutingRequestTestHelper, ClassifyTableTestHelper, InterfaceTestHelper, SchemaContextTestHelper {
44 private VppClassifierContextManager classifierContextManager;
47 private MappingContext mappingContext;
49 @InjectTestData(resourcePath = "/ipv4/simpleHopRouteWithClassifier.json", id = STATIC_ROUTE_PATH)
50 private StaticRoutes ipv4StaticRouteWithClassifier;
52 @InjectTestData(resourcePath = "/ipv4/simpleHopRouteWithoutClassifier.json", id = STATIC_ROUTE_PATH)
53 private StaticRoutes ipv4StaticRouteWithoutClassifier;
55 private NamingContext interfaceContext;
56 private NamingContext routingProtocolContext;
57 private SimpleHopRequestFactory factory;
61 MockitoAnnotations.initMocks(this);
62 interfaceContext = new NamingContext("interface", "interface-context");
63 routingProtocolContext = new NamingContext("routing-protocol", "routing-protocol-context");
65 SimpleHopRequestFactory.forContexts(classifierContextManager, interfaceContext, routingProtocolContext);
67 addMapping(classifierContextManager, CLASSIFY_TABLE_NAME, CLASSIFY_TABLE_INDEX, mappingContext);
68 defineMapping(mappingContext, INTERFACE_NAME, INTERFACE_INDEX, "interface-context");
69 defineMapping(mappingContext, ROUTE_PROTOCOL_NAME, 1, "routing-protocol-context");
73 public void testIpv4WithClassifier() {
74 final IpAddDelRoute request =
75 factory.createIpv4SimpleHopRequest(false, ROUTE_PROTOCOL_NAME,
76 getIpv4RouteWithId(ipv4StaticRouteWithClassifier, 1L),
79 assertEquals(desiredFlaglessResult(0, 0, 0, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24,
80 Ipv4RouteData.SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 0,
81 1, 1, 0, CLASSIFY_TABLE_INDEX, 1), request);
85 public void testIpv4WithoutClassifier() {
86 final IpAddDelRoute request =
87 factory.createIpv4SimpleHopRequest(false, ROUTE_PROTOCOL_NAME,
88 ipv4StaticRouteWithoutClassifier.getAugmentation(StaticRoutes1.class).getIpv4().getRoute()
89 .get(0), mappingContext);
92 desiredFlaglessResult(0, 0, 0, Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY, 24,
93 Ipv4RouteData.SECOND_ADDRESS_AS_ARRAY, INTERFACE_INDEX, 0, 1, 1, 0, 0, 0), request);