2 * Copyright (c) 2016 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.genius.mdsalutil;
10 import java.math.BigInteger;
12 public class MetaDataUtil {
13 public static final BigInteger METADATA_MASK_VRFID = new BigInteger("00000000FFFFFFFE", 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);
23 public static final BigInteger METADATA_MASK_ELAN_SUBNET_ROUTE = new BigInteger("0000FFFF00000000", 16);
24 public static final BigInteger METADATA_MASK_SUBNET_ROUTE = new BigInteger("0000FFFFFFFFFFFE", 16);
26 public static BigInteger getMetaDataForLPortDispatcher(int lportTag, short serviceIndex) {
27 return getServiceIndexMetaData(serviceIndex).or(getLportTagMetaData(lportTag));
30 public static BigInteger getMetaDataForLPortDispatcher(int lportTag, short serviceIndex,
31 BigInteger serviceMetaData) {
32 return getMetaDataForLPortDispatcher(lportTag, serviceIndex, serviceMetaData, false);
35 public static BigInteger getMetaDataForLPortDispatcher(int lportTag, short serviceIndex,
36 BigInteger serviceMetaData, boolean isSHFlagSet) {
37 int shBit = (isSHFlagSet) ? 1 : 0;
38 return getServiceIndexMetaData(serviceIndex).or(getLportTagMetaData(lportTag)).or(serviceMetaData)
39 .or(BigInteger.valueOf(shBit));
42 public static BigInteger getServiceIndexMetaData(int serviceIndex) {
43 return new BigInteger("7", 16).and(BigInteger.valueOf(serviceIndex)).shiftLeft(61);
46 public static BigInteger getLportTagMetaData(int lportTag) {
47 return new BigInteger("1FFFFF", 16).and(BigInteger.valueOf(lportTag)).shiftLeft(40);
50 public static BigInteger getMetaDataMaskForLPortDispatcher() {
51 return getMetaDataMaskForLPortDispatcher(METADATA_MASK_LPORT_TAG);
54 public static BigInteger getMetaDataMaskForLPortDispatcher(BigInteger metadataMaskForLPortTag) {
55 return METADATA_MASK_SERVICE_INDEX.or(metadataMaskForLPortTag);
58 public static BigInteger getMetadataLPort(int lPortTag) {
59 return (new BigInteger("FFFF", 16).and(BigInteger.valueOf(lPortTag))).shiftLeft(40);
62 public static BigInteger getLportFromMetadata(BigInteger metadata) {
63 return (metadata.and(METADATA_MASK_LPORT_TAG)).shiftRight(40);
66 public static int getElanTagFromMetadata(BigInteger metadata) {
67 return (((metadata.and(MetaDataUtil.METADATA_MASK_SERVICE)).
68 shiftRight(24))).intValue();
71 public static int getServiceTagFromMetadata(BigInteger metadata) {
72 return (((metadata.and(MetaDataUtil.METADATA_MASK_SERVICE_INDEX)).
73 shiftRight(61))).intValue();
76 public static BigInteger getMetaDataMaskForLPortDispatcher(BigInteger metadataMaskForServiceIndex,
77 BigInteger metadataMaskForLPortTag, BigInteger metadataMaskForService) {
78 return metadataMaskForServiceIndex.or(metadataMaskForLPortTag).or(metadataMaskForService);
82 * For the tunnel id with VNI and valid-vni-flag set, the most significant byte
83 * should have 08. So, shifting 08 to 7 bytes (56 bits) and the result is OR-ed with
84 * VNI being shifted to 1 byte.
86 public static BigInteger getTunnelIdWithValidVniBitAndVniSet(int vni) {
87 return BigInteger.valueOf(0X08).shiftLeft(56).or(BigInteger.valueOf(vni).shiftLeft(8));
90 public static long getNatRouterIdFromMetadata(BigInteger metadata){
91 return getVpnIdFromMetadata(metadata);
94 public static BigInteger getVpnIdMetadata(long vrfId) {
95 return METADATA_MASK_VRFID.and(BigInteger.valueOf(vrfId).shiftLeft(1));
98 public static long getVpnIdFromMetadata(BigInteger metadata) {
99 return (metadata.and(METADATA_MASK_VRFID).shiftRight(1)).longValue();
101 public static BigInteger getWriteMetaDataMaskForDispatcherTable() {
102 return new BigInteger("FFFFFFFFFFFFFFFE", 16);
105 public static BigInteger getLportTagForReg6(int lportTag) {
106 return new BigInteger("1FFFFF", 16).and(BigInteger.valueOf(lportTag)).shiftLeft(8);
108 public static BigInteger getServiceIndexForReg6(int serviceIndex) {
109 return new BigInteger("7", 16).and(BigInteger.valueOf(serviceIndex)).shiftLeft(29);
111 public static long getReg6ValueForLPortDispatcher(int lportTag, short serviceIndex) {
112 return getServiceIndexForReg6(serviceIndex).or(getLportTagForReg6(lportTag)).longValue();