729d956055fa3e130ff6bd5e3d37ba9a0cfc4592
[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.rev180329.path.attributes.Attributes;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.AsPathBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ClusterId;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ClusterIdBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.OriginatorId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.OriginatorIdBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.as.path.Segments;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.as.path.SegmentsBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ClusterIdentifier;
25 import org.opendaylight.yangtools.yang.common.Uint32;
26
27 public final class ExportAttributeTestUtil {
28     public static final Uint32 REMOTE_AS = Uint32.valueOf(8);
29     public static final AsNumber LOCAL_AS = new AsNumber(Uint32.valueOf(65));
30     public static final Ipv4Address IPV4 = new Ipv4Address("1.2.3.4");
31     public static final ClusterIdentifier CLUSTER = new ClusterIdentifier(IPV4);
32
33     private ExportAttributeTestUtil() {
34         // Hidden on purpose
35     }
36
37     /**
38      * container cluster-id. {
39      * leaf-list cluster {
40      * type cluster-identifier;
41      * }
42      * uses cluster-id;
43      * container originator-id {
44      * leaf originator {
45      * type ipv4-address;
46      * }
47      * uses originator-id;
48      * }
49      */
50     public static Attributes createInputWithOriginator() {
51         return new AttributesBuilder().setClusterId(createClusterId()).setOriginatorId(createOriginatorId()).build();
52     }
53
54     public static Attributes createClusterInput() {
55         return new AttributesBuilder().setClusterId(createClusterIdInput()).build();
56     }
57
58     private static ClusterId createClusterId() {
59         final ClusterIdentifier cluster1 = new ClusterIdentifier(new Ipv4Address("1.1.1.1"));
60         final ClusterIdentifier cluster2 = new ClusterIdentifier(new Ipv4Address("1.1.1.2"));
61         return new ClusterIdBuilder().setCluster(Arrays.asList(CLUSTER, cluster1, cluster2)).build();
62     }
63
64     private static ClusterId createClusterIdInput() {
65         final ClusterIdentifier cluster1 = new ClusterIdentifier(new Ipv4Address("1.1.1.1"));
66         final ClusterIdentifier cluster2 = new ClusterIdentifier(new Ipv4Address("1.1.1.2"));
67         return new ClusterIdBuilder().setCluster(Arrays.asList(cluster1, cluster2)).build();
68     }
69
70     private static OriginatorId createOriginatorId() {
71         return new OriginatorIdBuilder().setOriginator(IPV4).build();
72     }
73
74     /**
75      * AsPath.
76      */
77     static Attributes createPathInputWithAs() {
78         return createPathInput(createSequenceWithLocalAs());
79     }
80
81     static Attributes createPathInput(final List<Segments> segB) {
82         return new AttributesBuilder().setAsPath(new AsPathBuilder().setSegments(segB).build()).build();
83     }
84
85     private static List<Segments> createSequenceWithLocalAs() {
86         return Collections.singletonList(new SegmentsBuilder()
87                 .setAsSequence(Arrays.asList(new AsNumber(LOCAL_AS), new AsNumber(REMOTE_AS))).build());
88     }
89 }