summaryrefslogtreecommitdiffstats
path: root/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/read/policy/PoliciesTest.java
blob: cc16964bbededf051a7272a4ad69c090134252bf (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
/*
 * 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.read.policy;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

import com.google.common.collect.ImmutableSet;
import io.fd.hc2vpp.common.translate.util.AddressTranslator;
import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
import io.fd.hc2vpp.srv6.util.CandidatePathContextManager;
import io.fd.hc2vpp.srv6.util.PolicyContextManager;
import io.fd.hc2vpp.srv6.write.sid.request.LocalSidRequestTest;
import io.fd.honeycomb.translate.ModificationCache;
import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.jvpp.core.dto.SrPoliciesDetails;
import io.fd.jvpp.core.dto.SrPoliciesDetailsReplyDump;
import io.fd.jvpp.core.types.Srv6Sid;
import io.fd.jvpp.core.types.Srv6SidList;
import java.util.Arrays;
import org.mockito.Mock;
import org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.oc.srte.policy.rev170918.ProvisioningMethodConfig;
import org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.oc.srte.policy.rev170918.ProvisioningMethodType;
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.Ipv6Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;

public abstract class PoliciesTest extends LocalSidRequestTest {
    Ipv6AddressNoZone BSID_ADR = new Ipv6AddressNoZone("a::e");
    Ipv6AddressNoZone BSID_2_ADR = new Ipv6AddressNoZone("e::a");
    IpAddress ENDPOINT_1 = new IpAddress(new Ipv6Address("e::1"));
    IpAddress ENDPOINT_2 = new IpAddress(new Ipv6Address("a::1"));
    Long COLOR_1 = 1L;
    Long COLOR_2 = 2L;
    long DISTINGUISHER_1 = 1L;
    long DISTINGUISHER_2 = 2L;
    long PREFERENCE_1 = 100L;
    long PREFERENCE_2 = 200L;
    Class<? extends ProvisioningMethodType> PROVISIONING_METHOD = ProvisioningMethodConfig.class;
    int WEIGHT = 0;
    SrPoliciesDetailsReplyDump replyDump = new SrPoliciesDetailsReplyDump();

    @Mock
    ReadContext readCtx;
    @Mock
    PolicyContextManager policyCtx;
    @Mock
    CandidatePathContextManager candidatePathCtx;
    Ipv6AddressNoZone A_ADDR = new Ipv6AddressNoZone("a::");
    Ipv6AddressNoZone B_ADDR = new Ipv6AddressNoZone("b::");
    Ipv6AddressNoZone C_ADDR = new Ipv6AddressNoZone("c::");

    @Mock
    private
    ModificationCache modificationCache;
    private Srv6Sid A = new Srv6Sid();
    private Srv6Sid B = new Srv6Sid();
    private Srv6Sid C = new Srv6Sid();
    private SrPoliciesDetails srPoliciesDetails1 = new SrPoliciesDetails();
    private SrPoliciesDetails srPoliciesDetails2 = new SrPoliciesDetails();

    @Override
    public void init() {
        Srv6Sid bsid = new Srv6Sid();
        bsid.addr = AddressTranslator.INSTANCE.ipAddressToArray(new IpAddress(BSID_ADR));
        srPoliciesDetails1.bsid = bsid;

        srPoliciesDetails1.numSidLists = 1;
        Srv6SidList[] srv6SidLists = new Srv6SidList[1];
        Srv6SidList srv6SidList = new Srv6SidList();
        srv6SidList.weight = WEIGHT;
        srv6SidList.numSids = 3;
        A.addr = AddressTranslator.INSTANCE.ipAddressToArray(new IpAddress(A_ADDR));
        B.addr = AddressTranslator.INSTANCE.ipAddressToArray(new IpAddress(B_ADDR));
        C.addr = AddressTranslator.INSTANCE.ipAddressToArray(new IpAddress(C_ADDR));

        srv6SidList.sids = ImmutableSet.of(B, C, A).toArray(new Srv6Sid[3]);

        srv6SidLists[0] = srv6SidList;
        srPoliciesDetails1.sidLists = srv6SidLists;
        // is_encap - behavior of SR policy.(0.SRH insert // 1.Encapsulation)
        srPoliciesDetails1.isEncap = ByteDataTranslator.BYTE_TRUE;
        // type is the type of the SR policy. (0.Default // 1.Spray)
        srPoliciesDetails1.type = 0;

        Srv6Sid bsid2 = new Srv6Sid();
        bsid2.addr = AddressTranslator.INSTANCE.ipAddressToArray(new IpAddress(BSID_2_ADR));
        srPoliciesDetails2.bsid = bsid2;
        srPoliciesDetails2.numSidLists = 1;
        Srv6SidList[] srv6SidLists2 = new Srv6SidList[1];
        Srv6SidList srv6SidList2 = new Srv6SidList();
        srv6SidList2.weight = WEIGHT;
        srv6SidList2.numSids = 3;

        srv6SidList2.sids = ImmutableSet.of(A, C, B).toArray(new Srv6Sid[3]);
        srv6SidLists2[0] = srv6SidList2;
        srPoliciesDetails2.sidLists = srv6SidLists2;
        srPoliciesDetails2.isEncap = ByteDataTranslator.BYTE_TRUE;
        srPoliciesDetails2.type = 0;

        replyDump.srPoliciesDetails = Arrays.asList(srPoliciesDetails1, srPoliciesDetails2);

        when(readCtx.getModificationCache()).thenReturn(modificationCache);
        when(readCtx.getMappingContext()).thenReturn(mappingContext);
        when(modificationCache.get(any())).thenReturn(replyDump);
    }
}