2 * Copyright (c) 2015 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.parser.spi.extended.community;
12 * The utility functions related to the extended communities.
14 public final class ExtendedCommunityUtil {
16 private ExtendedCommunityUtil() {
17 throw new UnsupportedOperationException();
20 private static final byte NON_TRANS = 0x40;
23 * Sets transitivity flag for the Extended Community type.
25 * @param type Extended Community Type
26 * @param isTransitive Extended Community transitivity
27 * @return Extended Community type with a transitivity flag set if isTransitive false, otherwise returns unchanged
30 public static int setTransitivity(final int type, final boolean isTransitive) {
31 return isTransitive ? type : ExtendedCommunityUtil.toNonTransitiveType(type);
35 * Check the Extended Community type for transitivity.
37 * @param type Extended Community Type
38 * @return True if input type is transitive, false if the type is non-transitive
40 public static boolean isTransitive(final int type) {
41 return (type & NON_TRANS) == 0 ? true : false;
44 private static int toNonTransitiveType(final int type) {
45 return type | NON_TRANS;