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("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);
23 public static final BigInteger METADATA_MASK_SUBNET_ROUTE = new BigInteger("0000FFFFFFFFFFFF", 16);
25 public static BigInteger getMetaDataForLPortDispatcher(int lportTag, short serviceIndex) {
26 return getServiceIndexMetaData(serviceIndex).or(getLportTagMetaData(lportTag));
29 public static BigInteger getMetaDataForLPortDispatcher(int lportTag, short serviceIndex,
30 BigInteger serviceMetaData) {
31 return getServiceIndexMetaData(serviceIndex).or(getLportTagMetaData(lportTag)).or(serviceMetaData);
34 public static BigInteger getServiceIndexMetaData(int serviceIndex) {
35 return new BigInteger("7", 16).and(BigInteger.valueOf(serviceIndex)).shiftLeft(61);
38 public static BigInteger getLportTagMetaData(int lportTag) {
39 return new BigInteger("1FFFFF", 16).and(BigInteger.valueOf(lportTag)).shiftLeft(40);
42 public static BigInteger getMetaDataMaskForLPortDispatcher() {
43 return METADATA_MASK_SERVICE_INDEX.or(METADATA_MASK_LPORT_TAG);
46 public static BigInteger getMetadataLPort(int lPortTag) {
47 return (new BigInteger("FFFF", 16).and(BigInteger.valueOf(lPortTag))).shiftLeft(40);
50 public static BigInteger getLportFromMetadata(BigInteger metadata) {
51 return (metadata.and(METADATA_MASK_LPORT_TAG)).shiftRight(40);
54 public static int getElanTagFromMetadata(BigInteger metadata) {
55 return (((metadata.and(MetaDataUtil.METADATA_MASK_SERVICE)).
56 shiftRight(24))).intValue();
59 public static BigInteger getMetaDataMaskForLPortDispatcher(BigInteger metadataMaskForServiceIndex,
60 BigInteger metadataMaskForLPortTag, BigInteger metadataMaskForService) {
61 return metadataMaskForServiceIndex.or(metadataMaskForLPortTag).or(metadataMaskForService);
65 * For the tunnel id with VNI and valid-vni-flag set, the most significant byte
66 * should have 08. So, shifting 08 to 7 bytes (56 bits) and the result is OR-ed with
67 * VNI being shifted to 1 byte.
69 public static BigInteger getTunnelIdWithValidVniBitAndVniSet(int vni) {
70 return BigInteger.valueOf(0X08).shiftLeft(56).or(BigInteger.valueOf(vni).shiftLeft(8));
73 public static long getNatRouterIdFromMetadata(BigInteger metadata){
74 return (metadata.and(METADATA_MASK_VRFID)).longValue();
77 public static BigInteger getWriteMetaDataMaskForDispatcherTable() {
78 return new BigInteger("FFFFFFFFFFFFFFFF", 16);