BGPCEP-577: Neighbor’s local AS configurable
[bgpcep.git] / bgp / openconfig-rp-statement / src / test / java / org / opendaylight / protocol / bgp / openconfig / routing / policy / statement / ExportAttributeTestUtil.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.openconfig.routing.policy.statement;
9
10 import java.util.Arrays;
11 import java.util.Collections;
12 import java.util.List;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPathBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.ClusterId;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.ClusterIdBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.OriginatorId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.OriginatorIdBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.Segments;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.SegmentsBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
25
26 public final class ExportAttributeTestUtil {
27     public static final long REMOTE_AS = 8;
28     public static final AsNumber LOCAL_AS = new AsNumber(65L);
29     public static final Ipv4Address IPV4 = new Ipv4Address("1.2.3.4");
30     public static final ClusterIdentifier CLUSTER = new ClusterIdentifier(IPV4);
31
32     private ExportAttributeTestUtil() {
33         throw new UnsupportedOperationException();
34     }
35
36     /**
37      * container cluster-id. {
38      * leaf-list cluster {
39      * type cluster-identifier;
40      * }
41      * uses cluster-id;
42      * container originator-id {
43      * leaf originator {
44      * type ipv4-address;
45      * }
46      * uses originator-id;
47      * }
48      */
49     public static Attributes createInputWithOriginator() {
50         return new AttributesBuilder().setClusterId(createClusterId()).setOriginatorId(createOriginatorId()).build();
51     }
52
53     public static Attributes createClusterInput() {
54         return new AttributesBuilder().setClusterId(createClusterIdInput()).build();
55     }
56
57     private static ClusterId createClusterId() {
58         final ClusterIdentifier cluster1 = new ClusterIdentifier(new Ipv4Address("1.1.1.1"));
59         final ClusterIdentifier cluster2 = new ClusterIdentifier(new Ipv4Address("1.1.1.2"));
60         return new ClusterIdBuilder().setCluster(Arrays.asList(CLUSTER, cluster1, cluster2)).build();
61     }
62
63     private static ClusterId createClusterIdInput() {
64         final ClusterIdentifier cluster1 = new ClusterIdentifier(new Ipv4Address("1.1.1.1"));
65         final ClusterIdentifier cluster2 = new ClusterIdentifier(new Ipv4Address("1.1.1.2"));
66         return new ClusterIdBuilder().setCluster(Arrays.asList(cluster1, cluster2)).build();
67     }
68
69     private static OriginatorId createOriginatorId() {
70         return new OriginatorIdBuilder().setOriginator(IPV4).build();
71     }
72
73     /**
74      * AsPath.
75      */
76     static Attributes createPathInputWithAs() {
77         return createPathInput(createSequenceWithLocalAs());
78     }
79
80     static Attributes createPathInput(final List<Segments> segB) {
81         return new AttributesBuilder().setAsPath(new AsPathBuilder().setSegments(segB).build()).build();
82     }
83
84     private static List<Segments> createSequenceWithLocalAs() {
85         return Collections.singletonList(new SegmentsBuilder()
86                 .setAsSequence(Arrays.asList(new AsNumber(LOCAL_AS), new AsNumber(REMOTE_AS))).build());
87     }
88 }