4fcac08e8a98e3ab0898bad44585109104b1535a
[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 LOCAL_AS = 8;
28     public static final Ipv4Address IPV4 = new Ipv4Address("1.2.3.4");
29     public static final ClusterIdentifier CLUSTER = new ClusterIdentifier(IPV4);
30
31     private ExportAttributeTestUtil() {
32         throw new UnsupportedOperationException();
33     }
34
35     /**
36      * container cluster-id. {
37      * leaf-list cluster {
38      * type cluster-identifier;
39      * }
40      * uses cluster-id;
41      * container originator-id {
42      * leaf originator {
43      * type ipv4-address;
44      * }
45      * uses originator-id;
46      * }
47      */
48     public static Attributes createInputWithOriginator() {
49         return new AttributesBuilder().setClusterId(createClusterId()).setOriginatorId(createOriginatorId()).build();
50     }
51
52     public static Attributes createClusterInput() {
53         return new AttributesBuilder().setClusterId(createClusterIdInput()).build();
54     }
55
56     private static ClusterId createClusterId() {
57         final ClusterIdentifier cluster1 = new ClusterIdentifier(new Ipv4Address("1.1.1.1"));
58         final ClusterIdentifier cluster2 = new ClusterIdentifier(new Ipv4Address("1.1.1.2"));
59         return new ClusterIdBuilder().setCluster(Arrays.asList(CLUSTER, cluster1, cluster2)).build();
60     }
61
62     private static ClusterId createClusterIdInput() {
63         final ClusterIdentifier cluster1 = new ClusterIdentifier(new Ipv4Address("1.1.1.1"));
64         final ClusterIdentifier cluster2 = new ClusterIdentifier(new Ipv4Address("1.1.1.2"));
65         return new ClusterIdBuilder().setCluster(Arrays.asList(cluster1, cluster2)).build();
66     }
67
68     private static OriginatorId createOriginatorId() {
69         return new OriginatorIdBuilder().setOriginator(IPV4).build();
70     }
71
72     /**
73      * AsPath.
74      */
75     static Attributes createPathInputWithAs() {
76         return createPathInput(createSequenceWithLocalAs());
77     }
78
79     static Attributes createPathInput(final List<Segments> segB) {
80         return new AttributesBuilder().setAsPath(new AsPathBuilder().setSegments(segB).build()).build();
81     }
82
83     private static List<Segments> createSequenceWithLocalAs() {
84         return Collections.singletonList(new SegmentsBuilder()
85                 .setAsSequence(Collections.singletonList(new AsNumber(LOCAL_AS))).build());
86     }
87 }