summaryrefslogtreecommitdiffstats
path: root/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/util/JvppRequestTest.java
blob: f241716d5591e8fc46f73958cca0bd44145eb529 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
 * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.fd.hc2vpp.srv6.util;

import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject;
import io.fd.hc2vpp.common.test.util.FutureProducer;
import io.fd.hc2vpp.common.test.util.NamingContextHelper;
import io.fd.hc2vpp.common.translate.util.AddressTranslator;
import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.hc2vpp.srv6.util.function.LocalSidFunctionReadBindingRegistry;
import io.fd.hc2vpp.srv6.util.function.LocalSidFunctionWriteBindingRegistry;
import io.fd.hc2vpp.srv6.util.function.lookup.EndDT4FunctionBinder;
import io.fd.hc2vpp.srv6.util.function.lookup.EndDT6FunctionBinder;
import io.fd.hc2vpp.srv6.util.function.lookup.EndTFunctionBinder;
import io.fd.hc2vpp.srv6.util.function.nofunction.EndFunctionBinder;
import io.fd.hc2vpp.srv6.util.function.xconnect.EndDX2FunctionBinder;
import io.fd.hc2vpp.srv6.util.function.xconnect.EndDX4FunctionBinder;
import io.fd.hc2vpp.srv6.util.function.xconnect.EndDX6FunctionBinder;
import io.fd.hc2vpp.srv6.util.function.xconnect.EndXFunctionBinder;
import io.fd.honeycomb.test.tools.HoneycombTestRunner;
import io.fd.honeycomb.test.tools.annotations.SchemaContextProvider;
import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.vpp.jvpp.core.dto.SrSteeringAddDel;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
import org.junit.Assert;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;


@RunWith(HoneycombTestRunner.class)
public abstract class JvppRequestTest implements FutureProducer, NamingContextHelper {
    protected static final LocalSidFunctionReadBindingRegistry READ_REGISTRY =
            new LocalSidFunctionReadBindingRegistry();
    protected static final LocalSidFunctionWriteBindingRegistry WRITE_REGISTRY =
            new LocalSidFunctionWriteBindingRegistry();

    protected static final String NAMED_SEG_LISTS_PATH = "/hc2vpp-oc-srte-policy:segment-routing" +
            "/hc2vpp-oc-srte-policy:traffic-engineering" +
            "/hc2vpp-oc-srte-policy:named-segment-lists";

    protected static final String POLICIES_LISTS_PATH = "/hc2vpp-oc-srte-policy:segment-routing" +
            "/hc2vpp-oc-srte-policy:traffic-engineering" +
            "/hc2vpp-oc-srte-policy:policies";

    @Inject
    @Mock
    protected static FutureJVppCore api;

    @Mock
    protected static WriteContext ctx;

    @Mock
    protected static MappingContext mappingContext;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        NamingContext interfaceContext = new NamingContext("iface", "interface-context");

        EndFunctionBinder endFunctionBinder = new EndFunctionBinder(api);
        EndTFunctionBinder endTFunctionBinder = new EndTFunctionBinder(api);
        EndDT4FunctionBinder endDT4FunctionBinder = new EndDT4FunctionBinder(api);
        EndDT6FunctionBinder endDT6FunctionBinder = new EndDT6FunctionBinder(api);
        EndXFunctionBinder endXFunctionBinder = new EndXFunctionBinder(api, interfaceContext);
        EndDX2FunctionBinder endDX2FunctionBinder = new EndDX2FunctionBinder(api, interfaceContext);
        EndDX4FunctionBinder endDX4FunctionBinder = new EndDX4FunctionBinder(api, interfaceContext);
        EndDX6FunctionBinder endDX6FunctionBinder = new EndDX6FunctionBinder(api, interfaceContext);
        READ_REGISTRY.registerReadFunctionType(endFunctionBinder);
        READ_REGISTRY.registerReadFunctionType(endTFunctionBinder);
        READ_REGISTRY.registerReadFunctionType(endDT4FunctionBinder);
        READ_REGISTRY.registerReadFunctionType(endDT6FunctionBinder);
        READ_REGISTRY.registerReadFunctionType(endXFunctionBinder);
        READ_REGISTRY.registerReadFunctionType(endDX2FunctionBinder);
        READ_REGISTRY.registerReadFunctionType(endDX4FunctionBinder);
        READ_REGISTRY.registerReadFunctionType(endDX6FunctionBinder);
        WRITE_REGISTRY.registerWriteFunctionType(endFunctionBinder);
        WRITE_REGISTRY.registerWriteFunctionType(endTFunctionBinder);
        WRITE_REGISTRY.registerWriteFunctionType(endDT4FunctionBinder);
        WRITE_REGISTRY.registerWriteFunctionType(endDT6FunctionBinder);
        WRITE_REGISTRY.registerWriteFunctionType(endXFunctionBinder);
        WRITE_REGISTRY.registerWriteFunctionType(endDX2FunctionBinder);
        WRITE_REGISTRY.registerWriteFunctionType(endDX4FunctionBinder);
        WRITE_REGISTRY.registerWriteFunctionType(endDX6FunctionBinder);
        init();
    }

    @SchemaContextProvider
    public ModuleInfoBackedContext createSchemaContext() {
        ModuleInfoBackedContext mibContext = ModuleInfoBackedContext.create();
        mibContext.addModuleInfos(ImmutableSet.of(
                org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.$YangModuleInfoImpl
                        .getInstance(),
                org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.$YangModuleInfoImpl
                        .getInstance(),
                org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.$YangModuleInfoImpl
                        .getInstance(),
                org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.$YangModuleInfoImpl
                        .getInstance(),
                org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.$YangModuleInfoImpl
                        .getInstance(),
                org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.oc.srte.policy.rev170918.$YangModuleInfoImpl
                        .getInstance(),
                org.opendaylight.yang.gen.v1.urn.hc2vpp.params.xml.ns.yang.vpp.oc.srte.policy.rev180514.$YangModuleInfoImpl
                        .getInstance()));
        return mibContext;
    }

    protected abstract void init();

    protected void testSrSteeringAddDelValidity(SrSteeringAddDel srSteering, byte isDel, byte trafficType, boolean ipV6,
                                                Ipv6Address bsidAdr, IpPrefix prefix) {
        Assert.assertEquals((long) 0, srSteering.tableId);
        Assert.assertArrayEquals(AddressTranslator.INSTANCE.ipAddressToArray(new IpAddress(bsidAdr)),
                srSteering.bsidAddr);
        Assert.assertEquals(isDel, srSteering.isDel);
        Assert.assertEquals(trafficType, srSteering.trafficType);

        if (ipV6) {
            Assert.assertArrayEquals(AddressTranslator.INSTANCE.ipv6AddressPrefixToArray(prefix.getIpv6Prefix()),
                    srSteering.prefixAddr);
            Assert.assertEquals(AddressTranslator.INSTANCE.extractPrefix(prefix.getIpv6Prefix()),
                    srSteering.maskWidth);
        } else {
            Assert.assertArrayEquals(AddressTranslator.INSTANCE.ipv4AddressPrefixToArray(prefix.getIpv4Prefix()),
                    srSteering.prefixAddr);
            Assert.assertEquals(AddressTranslator.INSTANCE.extractPrefix(prefix.getIpv4Prefix()),
                    srSteering.maskWidth);
        }

    }
}