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
9 package org.opendaylight.protocol.bgp.testtool;
11 import com.google.common.collect.Lists;
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.rev130919.path.attributes.attributes.ExtendedCommunities;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.ExtendedCommunitiesBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ShortAsNumber;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as._4.spec.common.As4SpecificCommon;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as._4.spec.common.As4SpecificCommonBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.As4GenericSpecExtendedCommunityCaseBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.As4RouteOriginExtendedCommunityCaseBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.As4RouteTargetExtendedCommunityCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.AsSpecificExtendedCommunityCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.Inet4SpecificExtendedCommunityCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.LinkBandwidthCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.OpaqueExtendedCommunityCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteOriginExtendedCommunityCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteOriginIpv4CaseBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteTargetExtendedCommunityCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteTargetIpv4CaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.as._4.generic.spec.extended.community._case.As4GenericSpecExtendedCommunityBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.as._4.route.origin.extended.community._case.As4RouteOriginExtendedCommunityBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.as._4.route.target.extended.community._case.As4RouteTargetExtendedCommunityBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.as.specific.extended.community._case.AsSpecificExtendedCommunityBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.inet4.specific.extended.community._case.Inet4SpecificExtendedCommunityBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.link.bandwidth._case.LinkBandwidthExtendedCommunityBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.opaque.extended.community._case.OpaqueExtendedCommunityBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.route.origin.extended.community._case.RouteOriginExtendedCommunityBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.route.origin.ipv4._case.RouteOriginIpv4Builder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.route.target.extended.community._case.RouteTargetExtendedCommunityBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.route.target.ipv4._case.RouteTargetIpv4Builder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
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 final static As4SpecificCommon AS_4_COMMON = new As4SpecificCommonBuilder().setAsNumber(new AsNumber(20L)).setLocalAdministrator(100).build();
51 private final static Ipv4Address IPV4 = new Ipv4Address("192.168.1.0");
52 private final static byte[] BYTE = new byte[]{(byte) 0x4f, (byte) 0x70, (byte) 0x00, (byte) 0x00};
53 private final static int LA = 4660;
54 private final static ShortAsNumber SHORT_AS = new ShortAsNumber(20L);
56 private CommunitiesBuilder() {
57 throw new UnsupportedOperationException();
60 static List<ExtendedCommunities> createExtComm(final List<String> extCom) {
61 final List<ExtendedCommunities> extendedCommunities = Lists.newArrayList();
62 for (String ec : extCom) {
63 ExtendedCommunity community = null;
65 case "as-4-generic-spec-extended-community":
66 community = CommunitiesBuilder.as4GenSpecBuild();
68 case "as-4-route-target-extended-community":
69 community = CommunitiesBuilder.as4RTBuild();
71 case "as-4-route-origin-extended-community":
72 community = CommunitiesBuilder.as4ROBuild();
75 community = CommunitiesBuilder.rOBuild();
78 community = CommunitiesBuilder.rTBuild();
80 case "route-origin-extended-community":
81 community = CommunitiesBuilder.rOECBuild();
83 case "route-target-extended-community":
84 community = CommunitiesBuilder.rTECBuild();
86 case "link-bandwidth-extended-community":
87 community = CommunitiesBuilder.linkBandBuild();
89 case "opaque-extended-community":
90 community = CommunitiesBuilder.opaqueBuild();
92 case "inet4-specific-extended-community":
93 community = CommunitiesBuilder.inet4Build();
95 case "as-specific-extended-community":
96 community = CommunitiesBuilder.asSpecBuild();
99 LOG.debug("Not recognized Extended Community {}", ec);
102 extendedCommunities.add(new ExtendedCommunitiesBuilder().setTransitive(true).setExtendedCommunity(community).build());
104 return extendedCommunities;
107 private static ExtendedCommunity as4GenSpecBuild() {
108 return new As4GenericSpecExtendedCommunityCaseBuilder()
109 .setAs4GenericSpecExtendedCommunity(new As4GenericSpecExtendedCommunityBuilder()
110 .setAs4SpecificCommon(AS_4_COMMON).build()).build();
113 private static ExtendedCommunity as4RTBuild() {
114 return new As4RouteTargetExtendedCommunityCaseBuilder().setAs4RouteTargetExtendedCommunity(
115 new As4RouteTargetExtendedCommunityBuilder().setAs4SpecificCommon(AS_4_COMMON).build()).build();
118 private static ExtendedCommunity as4ROBuild() {
119 return new As4RouteOriginExtendedCommunityCaseBuilder().setAs4RouteOriginExtendedCommunity(
120 new As4RouteOriginExtendedCommunityBuilder().setAs4SpecificCommon(AS_4_COMMON).build()).build();
123 private static ExtendedCommunity rTBuild() {
124 return new RouteTargetIpv4CaseBuilder().setRouteTargetIpv4(
125 new RouteTargetIpv4Builder().setGlobalAdministrator(IPV4).setLocalAdministrator(LA).build()).build();
128 private static ExtendedCommunity rOBuild() {
129 return new RouteOriginIpv4CaseBuilder().setRouteOriginIpv4(
130 new RouteOriginIpv4Builder().setGlobalAdministrator(IPV4).setLocalAdministrator(LA).build()).build();
133 private static ExtendedCommunity linkBandBuild() {
134 return new LinkBandwidthCaseBuilder().setLinkBandwidthExtendedCommunity(new LinkBandwidthExtendedCommunityBuilder()
135 .setBandwidth(new Bandwidth(new Float32(BYTE))).build()).build();
138 private static ExtendedCommunity rOECBuild() {
139 return new RouteOriginExtendedCommunityCaseBuilder().setRouteOriginExtendedCommunity(
140 new RouteOriginExtendedCommunityBuilder().setGlobalAdministrator(SHORT_AS).setLocalAdministrator(BYTE).build()).build();
143 private static ExtendedCommunity rTECBuild() {
144 return new RouteTargetExtendedCommunityCaseBuilder().setRouteTargetExtendedCommunity(
145 new RouteTargetExtendedCommunityBuilder().setGlobalAdministrator(SHORT_AS).setLocalAdministrator(BYTE).build()).build();
148 private static ExtendedCommunity opaqueBuild() {
149 return new OpaqueExtendedCommunityCaseBuilder().setOpaqueExtendedCommunity(
150 new OpaqueExtendedCommunityBuilder().setValue(BYTE).build()).build();
153 private static ExtendedCommunity inet4Build() {
154 return new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
155 new Inet4SpecificExtendedCommunityBuilder().setGlobalAdministrator(IPV4).setLocalAdministrator(BYTE).build()).build();
158 private static ExtendedCommunity asSpecBuild() {
159 return new AsSpecificExtendedCommunityCaseBuilder().setAsSpecificExtendedCommunity(
160 new AsSpecificExtendedCommunityBuilder().setGlobalAdministrator(SHORT_AS).setLocalAdministrator(BYTE).build()).build();