2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.vpnservice.mdsalutil;
10 import java.math.BigInteger;
12 public class MetaDataUtil {
13 public static final BigInteger METADATA_MASK_VRFID = new BigInteger("00000000FFFFFFFF", 16);
14 public static final BigInteger METADATA_MASK_LPORT_TAG = new BigInteger("1FFFFF0000000000", 16);
15 public static final BigInteger METADATA_MASK_SERVICE = new BigInteger("000000FFFF000000", 16);
16 public static final BigInteger METADATA_MASK_SERVICE_INDEX = new BigInteger("E000000000000000", 16);
17 public static final BigInteger METADATA_MASK_LPORT_WRITE = new BigInteger("00FFFF0000000000", 16);
18 public static final BigInteger METADA_MASK_VALID_TUNNEL_ID_BIT_AND_TUNNEL_ID = new BigInteger("08000000FFFFFF00", 16);
19 public static final BigInteger METADATA_MASK_LABEL_ITM = new BigInteger("40FFFFFF000000FF", 16);
20 public static final BigInteger METADA_MASK_TUNNEL_ID = new BigInteger("00000000FFFFFF00", 16);
21 public static final BigInteger METADATA_MASK_SERVICE_SH_FLAG = new BigInteger("000000FFFF000001", 16);
22 public static final BigInteger METADATA_MASK_LPORT_TAG_SH_FLAG = new BigInteger("1FFFFF0000000001", 16);
24 public static BigInteger getMetaDataForLPortDispatcher(int lportTag, short serviceIndex) {
25 return getServiceIndexMetaData(serviceIndex).or(getLportTagMetaData(lportTag));
28 public static BigInteger getMetaDataForLPortDispatcher(int lportTag, short serviceIndex,
29 BigInteger serviceMetaData) {
30 return getServiceIndexMetaData(serviceIndex).or(getLportTagMetaData(lportTag)).or(serviceMetaData);
33 public static BigInteger getServiceIndexMetaData(int serviceIndex) {
34 return new BigInteger("7", 16).and(BigInteger.valueOf(serviceIndex)).shiftLeft(61);
37 public static BigInteger getLportTagMetaData(int lportTag) {
38 return new BigInteger("1FFFFF", 16).and(BigInteger.valueOf(lportTag)).shiftLeft(40);
41 public static BigInteger getMetaDataMaskForLPortDispatcher() {
42 return METADATA_MASK_SERVICE_INDEX.or(METADATA_MASK_LPORT_TAG);
45 public static BigInteger getMetadataLPort(int lPortTag) {
46 return (new BigInteger("FFFF", 16).and(BigInteger.valueOf(lPortTag))).shiftLeft(40);
49 public static BigInteger getLportFromMetadata(BigInteger metadata) {
50 return (metadata.and(METADATA_MASK_LPORT_TAG)).shiftRight(40);
53 public static int getElanTagFromMetadata(BigInteger metadata) {
54 return (((metadata.and(MetaDataUtil.METADATA_MASK_SERVICE)).
55 shiftRight(24))).intValue();
58 public static BigInteger getMetaDataMaskForLPortDispatcher(BigInteger metadataMaskForServiceIndex,
59 BigInteger metadataMaskForLPortTag, BigInteger metadataMaskForService) {
60 return metadataMaskForServiceIndex.or(metadataMaskForLPortTag).or(metadataMaskForService);
64 * For the tunnel id with VNI and valid-vni-flag set, the most significant byte
65 * should have 08. So, shifting 08 to 7 bytes (56 bits) and the result is OR-ed with
66 * VNI being shifted to 1 byte.
68 public static BigInteger getTunnelIdWithValidVniBitAndVniSet(int vni) {
69 return BigInteger.valueOf(0X08).shiftLeft(56).or(BigInteger.valueOf(vni).shiftLeft(8));
72 public static long getNatRouterIdFromMetadata(BigInteger metadata){
73 return (metadata.and(METADATA_MASK_VRFID)).longValue();