2 * Copyright (c) 2013 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.parser.impl.message.update;
10 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.CommunitiesBuilder;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
15 * Object representation of a RFC1997 Community tag. Communities are a way for the advertising entity to attach semantic
16 * meaning/policy to advertised objects.
18 public final class CommunityUtil {
20 * NO_EXPORT community. All routes received carrying a communities attribute containing this value MUST NOT be
21 * advertised outside a BGP confederation boundary (a stand-alone autonomous system that is not part of a
22 * confederation should be considered a confederation itself).
24 public static final Community NO_EXPORT = CommunityUtil.create(0xFFFF, 0xFF01);
26 * NO_ADVERTISE community. All routes received carrying a communities attribute containing this value MUST NOT be
27 * advertised to other BGP peers.
29 public static final Community NO_ADVERTISE = CommunityUtil.create(0xFFFF, 0xFF02);
31 * NO_EXPORT_SUBCONFED community. All routes received carrying a communities attribute containing this value MUST
32 * NOT be advertised to external BGP peers (this includes peers in other members autonomous systems inside a BGP
35 public static final Community NO_EXPORT_SUBCONFED = CommunityUtil.create(0xFFFF, 0xFF03);
37 private CommunityUtil() {
42 * Creates a new Community given AS number value and semantics using generated CommunitiesBuilder.
45 * @param semantics long
46 * @return new Community
48 public static Community create(final long asn, final int semantics) {
49 final CommunitiesBuilder builder = new CommunitiesBuilder();
50 builder.setAsNumber(new AsNumber(asn));
51 builder.setSemantics(semantics);
52 return builder.build();
56 * Creates a Community from its String representation.
58 * @param string String representation of a community
59 * @return new Community
61 public static Community valueOf(final String string) {
62 final String[] parts = string.split(":", 2);
63 final CommunitiesBuilder builder = new CommunitiesBuilder();
64 builder.setAsNumber(new AsNumber(Long.valueOf(parts[0])));
65 builder.setSemantics(Integer.valueOf(parts[1]));
66 return builder.build();