MVPN RFC6514 Extendend communities
[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 com.google.common.primitives.Shorts;
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.List;
23 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi;
24 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafiBuilder;
25 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.AfiSafisBuilder;
26 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.ConfigBuilder;
27 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.StateBuilder;
28 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
29 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborBuilder;
30 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Global;
31 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.GlobalBuilder;
32 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Neighbors;
33 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.NeighborsBuilder;
34 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
35 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV6UNICAST;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.GlobalAddPathsConfig;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.GlobalAddPathsConfigBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.BgpId;
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     private static final Long ALL_PATHS = 0L;
46
47     static {
48         AFISAFIS_IPV4.add(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
49                 .addAugmentation(GlobalAddPathsConfig.class, new GlobalAddPathsConfigBuilder().setReceive(true)
50                         .setSendMax(Shorts.checkedCast(ALL_PATHS)).build()).build());
51     }
52
53     static {
54         AFISAFIS_IPV6.add(new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class)
55                 .addAugmentation(GlobalAddPathsConfig.class, new GlobalAddPathsConfigBuilder().setReceive(true)
56                         .setSendMax(Shorts.checkedCast(ALL_PATHS)).build()).build());
57     }
58
59     private RIBTestsUtil() {
60         throw new UnsupportedOperationException();
61     }
62
63
64     public static Global createGlobalIpv4() {
65         return new GlobalBuilder()
66                 .setAfiSafis(new AfiSafisBuilder().setAfiSafi(AFISAFIS_IPV4).build())
67                 .setConfig(new ConfigBuilder().setAs(AS).setRouterId(BGP_ID).build())
68                 .setState(new StateBuilder().setAs(AS).build())
69                 .build();
70     }
71
72     public static Global createGlobalIpv6() {
73         return new GlobalBuilder()
74                 .setAfiSafis(new AfiSafisBuilder().setAfiSafi(AFISAFIS_IPV6).build())
75                 .setConfig(new ConfigBuilder().setAs(AS).setRouterId(BGP_ID).build())
76                 .setState(new StateBuilder().setAs(AS).build())
77                 .build();
78     }
79
80     public static Neighbors createNeighbors() {
81         return new NeighborsBuilder()
82                 .setNeighbor(Collections.singletonList(createNeighbor()))
83                 .build();
84     }
85
86     private static Neighbor createNeighbor() {
87         return createNeighborExpected(NEIGHBOR_ADDRESS);
88     }
89
90     public static Neighbors createNeighborsNoRR() {
91         return new NeighborsBuilder()
92                 .setNeighbor(Collections.singletonList(createNeighborNoRR()))
93                 .build();
94     }
95
96     private static Neighbor createNeighborNoRR() {
97         return new NeighborBuilder()
98                 .setAfiSafis(createAfiSafi())
99                 .setConfig(createConfig())
100                 .setNeighborAddress(NEIGHBOR_ADDRESS)
101                 .setTimers(createTimers())
102                 .setTransport(createTransport())
103                 .setAddPaths(createAddPath())
104                 .build();
105     }
106 }