e95da995da8f7190b9b45d28e8fac1664645c29a
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / protocol / bgp / rib / impl / config / RIBTestsUtil.java
1 /*
2  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.protocol.bgp.rib.impl.config;
9
10 import static org.opendaylight.protocol.bgp.rib.impl.config.AbstractConfig.AS;
11 import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.NEIGHBOR_ADDRESS;
12 import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createAddPath;
13 import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createAfiSafi;
14 import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createConfig;
15 import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createNeighborExpected;
16 import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createTimers;
17 import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createTransport;
18
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.List;
22 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi;
23 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafiBuilder;
24 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.AfiSafisBuilder;
25 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.ConfigBuilder;
26 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.StateBuilder;
27 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
28 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborBuilder;
29 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Global;
30 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.GlobalBuilder;
31 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Neighbors;
32 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.NeighborsBuilder;
33 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
34 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV6UNICAST;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.GlobalAddPathsConfig;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.GlobalAddPathsConfigBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.BgpId;
39 import org.opendaylight.yangtools.yang.common.Uint8;
40
41 final class RIBTestsUtil {
42     private static final Ipv4Address BGP_ID = new BgpId(new Ipv4Address("127.0.0.1"));
43     private static final List<AfiSafi> AFISAFIS_IPV4 = new ArrayList<>();
44     private static final List<AfiSafi> AFISAFIS_IPV6 = new ArrayList<>();
45
46     static {
47         AFISAFIS_IPV4.add(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
48                 .addAugmentation(GlobalAddPathsConfig.class, new GlobalAddPathsConfigBuilder().setReceive(true)
49                         .setSendMax(Uint8.ZERO).build()).build());
50     }
51
52     static {
53         AFISAFIS_IPV6.add(new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class)
54                 .addAugmentation(GlobalAddPathsConfig.class, new GlobalAddPathsConfigBuilder().setReceive(true)
55                         .setSendMax(Uint8.ZERO).build()).build());
56     }
57
58     private RIBTestsUtil() {
59         // Hidden on purpose
60     }
61
62     public static Global createGlobalIpv4() {
63         return new GlobalBuilder()
64                 .setAfiSafis(new AfiSafisBuilder().setAfiSafi(AFISAFIS_IPV4).build())
65                 .setConfig(new ConfigBuilder().setAs(AS).setRouterId(BGP_ID).build())
66                 .setState(new StateBuilder().setAs(AS).build())
67                 .build();
68     }
69
70     public static Global createGlobalIpv6() {
71         return new GlobalBuilder()
72                 .setAfiSafis(new AfiSafisBuilder().setAfiSafi(AFISAFIS_IPV6).build())
73                 .setConfig(new ConfigBuilder().setAs(AS).setRouterId(BGP_ID).build())
74                 .setState(new StateBuilder().setAs(AS).build())
75                 .build();
76     }
77
78     public static Neighbors createNeighbors() {
79         return new NeighborsBuilder()
80                 .setNeighbor(Collections.singletonList(createNeighbor()))
81                 .build();
82     }
83
84     private static Neighbor createNeighbor() {
85         return createNeighborExpected(NEIGHBOR_ADDRESS);
86     }
87
88     public static Neighbors createNeighborsNoRR() {
89         return new NeighborsBuilder()
90                 .setNeighbor(Collections.singletonList(createNeighborNoRR()))
91                 .build();
92     }
93
94     private static Neighbor createNeighborNoRR() {
95         return new NeighborBuilder()
96                 .setAfiSafis(createAfiSafi())
97                 .setConfig(createConfig())
98                 .setNeighborAddress(NEIGHBOR_ADDRESS)
99                 .setTimers(createTimers())
100                 .setTransport(createTransport())
101                 .setAddPaths(createAddPath())
102                 .build();
103     }
104 }