2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.bgp.testtool;
10 import java.util.ArrayList;
11 import java.util.List;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ExtendedCommunities;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ExtendedCommunitiesBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ShortAsNumber;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.as._4.route.target.extended.community.grouping.As4RouteTargetExtendedCommunityBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.as._4.spec.common.As4SpecificCommon;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.as._4.spec.common.As4SpecificCommonBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.As4GenericSpecExtendedCommunityCaseBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.As4RouteOriginExtendedCommunityCaseBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.As4RouteTargetExtendedCommunityCaseBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.AsSpecificExtendedCommunityCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.Inet4SpecificExtendedCommunityCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.LinkBandwidthCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.OpaqueExtendedCommunityCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.RouteOriginExtendedCommunityCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.RouteOriginIpv4CaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.RouteTargetExtendedCommunityCaseBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.RouteTargetIpv4CaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.as._4.generic.spec.extended.community._case.As4GenericSpecExtendedCommunityBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.as._4.route.origin.extended.community._case.As4RouteOriginExtendedCommunityBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.as.specific.extended.community._case.AsSpecificExtendedCommunityBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.inet4.specific.extended.community._case.Inet4SpecificExtendedCommunityBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.link.bandwidth._case.LinkBandwidthExtendedCommunityBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.opaque.extended.community._case.OpaqueExtendedCommunityBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.route.origin.extended.community._case.RouteOriginExtendedCommunityBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.route.origin.ipv4._case.RouteOriginIpv4Builder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.extended.community.grouping.RouteTargetExtendedCommunityBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.ipv4.grouping.RouteTargetIpv4Builder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
43 import org.opendaylight.yangtools.yang.common.Uint16;
44 import org.opendaylight.yangtools.yang.common.Uint32;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
48 final class CommunitiesBuilder {
49 private static final Logger LOG = LoggerFactory.getLogger(CommunitiesBuilder.class);
50 private static final ShortAsNumber SHORT_AS = new ShortAsNumber(Uint32.valueOf(20));
51 private static final As4SpecificCommon AS_4_COMMON = new As4SpecificCommonBuilder()
52 .setAsNumber(SHORT_AS).setLocalAdministrator(Uint16.valueOf(100)).build();
53 private static final Ipv4AddressNoZone IPV4 = new Ipv4AddressNoZone("192.168.1.0");
54 private static final byte[] BYTE = new byte[]{(byte) 0x4f, (byte) 0x70, (byte) 0x00, (byte) 0x00};
55 private static final Uint16 LA = Uint16.valueOf(4660).intern();
57 private CommunitiesBuilder() {
61 static List<ExtendedCommunities> createExtComm(final List<String> extCom) {
62 final List<ExtendedCommunities> extendedCommunities = new ArrayList<>();
63 for (String ec : extCom) {
64 ExtendedCommunity community = null;
66 case "as-4-generic-spec-extended-community":
67 community = CommunitiesBuilder.as4GenSpecBuild();
69 case "as-4-route-target-extended-community":
70 community = CommunitiesBuilder.as4RTBuild();
72 case "as-4-route-origin-extended-community":
73 community = CommunitiesBuilder.as4ROBuild();
76 community = CommunitiesBuilder.rOBuild();
79 community = CommunitiesBuilder.rTBuild();
81 case "route-origin-extended-community":
82 community = CommunitiesBuilder.rOECBuild();
84 case "route-target-extended-community":
85 community = CommunitiesBuilder.rTECBuild();
87 case "link-bandwidth-extended-community":
88 community = CommunitiesBuilder.linkBandBuild();
90 case "opaque-extended-community":
91 community = CommunitiesBuilder.opaqueBuild();
93 case "inet4-specific-extended-community":
94 community = CommunitiesBuilder.inet4Build();
96 case "as-specific-extended-community":
97 community = CommunitiesBuilder.asSpecBuild();
100 LOG.debug("Not recognized Extended Community {}", ec);
103 extendedCommunities.add(new ExtendedCommunitiesBuilder()
104 .setTransitive(true).setExtendedCommunity(community).build());
106 return extendedCommunities;
109 private static ExtendedCommunity as4GenSpecBuild() {
110 return new As4GenericSpecExtendedCommunityCaseBuilder()
111 .setAs4GenericSpecExtendedCommunity(new As4GenericSpecExtendedCommunityBuilder()
112 .setAs4SpecificCommon(AS_4_COMMON).build()).build();
115 private static ExtendedCommunity as4RTBuild() {
116 return new As4RouteTargetExtendedCommunityCaseBuilder().setAs4RouteTargetExtendedCommunity(
117 new As4RouteTargetExtendedCommunityBuilder().setAs4SpecificCommon(AS_4_COMMON).build()).build();
120 private static ExtendedCommunity as4ROBuild() {
121 return new As4RouteOriginExtendedCommunityCaseBuilder().setAs4RouteOriginExtendedCommunity(
122 new As4RouteOriginExtendedCommunityBuilder().setAs4SpecificCommon(AS_4_COMMON).build()).build();
125 private static ExtendedCommunity rTBuild() {
126 return new RouteTargetIpv4CaseBuilder().setRouteTargetIpv4(
127 new RouteTargetIpv4Builder().setGlobalAdministrator(IPV4).setLocalAdministrator(LA).build()).build();
130 private static ExtendedCommunity rOBuild() {
131 return new RouteOriginIpv4CaseBuilder().setRouteOriginIpv4(
132 new RouteOriginIpv4Builder().setGlobalAdministrator(IPV4).setLocalAdministrator(LA).build()).build();
135 private static ExtendedCommunity linkBandBuild() {
136 return new LinkBandwidthCaseBuilder()
137 .setLinkBandwidthExtendedCommunity(new LinkBandwidthExtendedCommunityBuilder()
138 .setBandwidth(new Bandwidth(new Float32(BYTE))).build()).build();
141 private static ExtendedCommunity rOECBuild() {
142 return new RouteOriginExtendedCommunityCaseBuilder().setRouteOriginExtendedCommunity(
143 new RouteOriginExtendedCommunityBuilder().setGlobalAdministrator(SHORT_AS)
144 .setLocalAdministrator(BYTE).build()).build();
147 private static ExtendedCommunity rTECBuild() {
148 return new RouteTargetExtendedCommunityCaseBuilder().setRouteTargetExtendedCommunity(
149 new RouteTargetExtendedCommunityBuilder().setGlobalAdministrator(SHORT_AS)
150 .setLocalAdministrator(BYTE).build()).build();
153 private static ExtendedCommunity opaqueBuild() {
154 return new OpaqueExtendedCommunityCaseBuilder().setOpaqueExtendedCommunity(
155 new OpaqueExtendedCommunityBuilder().setValue(BYTE).build()).build();
158 private static ExtendedCommunity inet4Build() {
159 return new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
160 new Inet4SpecificExtendedCommunityBuilder().setGlobalAdministrator(IPV4)
161 .setLocalAdministrator(BYTE).build()).build();
164 private static ExtendedCommunity asSpecBuild() {
165 return new AsSpecificExtendedCommunityCaseBuilder().setAsSpecificExtendedCommunity(
166 new AsSpecificExtendedCommunityBuilder().setGlobalAdministrator(SHORT_AS)
167 .setLocalAdministrator(BYTE).build()).build();