Terminaing service table fix in fibmanager
[vpnservice.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / vpnservice / mdsalutil / MetaDataUtil.java
1 /*
2  * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.vpnservice.mdsalutil;
9
10 import java.math.BigInteger;
11
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
22     public static BigInteger getMetaDataForLPortDispatcher(int lportTag, short serviceIndex) {
23         return getServiceIndexMetaData(serviceIndex).or(getLportTagMetaData(lportTag));
24     }
25
26     public static BigInteger getMetaDataForLPortDispatcher(int lportTag, short serviceIndex,
27                                                            BigInteger serviceMetaData) {
28         return getServiceIndexMetaData(serviceIndex).or(getLportTagMetaData(lportTag)).or(serviceMetaData);
29     }
30
31     public static BigInteger getServiceIndexMetaData(int serviceIndex) {
32         return new BigInteger("7", 16).and(BigInteger.valueOf(serviceIndex)).shiftLeft(61);
33     }
34
35     public static BigInteger getLportTagMetaData(int lportTag) {
36         return new BigInteger("1FFFFF", 16).and(BigInteger.valueOf(lportTag)).shiftLeft(40);
37     }
38
39     public static BigInteger getMetaDataMaskForLPortDispatcher() {
40         return METADATA_MASK_SERVICE_INDEX.or(METADATA_MASK_LPORT_TAG);
41     }
42
43     public static BigInteger getMetadataLPort(int lPortTag) {
44         return (new BigInteger("FFFF", 16).and(BigInteger.valueOf(lPortTag))).shiftLeft(40);
45     }
46
47     public static BigInteger getLportFromMetadata(BigInteger metadata) {
48         return (metadata.and(METADATA_MASK_LPORT_TAG)).shiftRight(40);
49     }
50
51     public static int getElanTagFromMetadata(BigInteger metadata) {
52         return (((metadata.and(MetaDataUtil.METADATA_MASK_SERVICE)).
53                 shiftRight(24))).intValue();
54     }
55
56     public static BigInteger getMetaDataMaskForLPortDispatcher(BigInteger metadataMaskForServiceIndex,
57                                                                BigInteger metadataMaskForLPortTag, BigInteger metadataMaskForService) {
58         return metadataMaskForServiceIndex.or(metadataMaskForLPortTag).or(metadataMaskForService);
59     }
60
61     /**
62      * For the tunnel id with VNI and valid-vni-flag set, the most significant byte
63      * should have 08. So, shifting 08 to 7 bytes (56 bits) and the result is OR-ed with
64      * VNI being shifted to 1 byte.
65      */
66     public static BigInteger getTunnelIdWithValidVniBitAndVniSet(int vni) {
67         return BigInteger.valueOf(0X08).shiftLeft(56).or(BigInteger.valueOf(vni).shiftLeft(8));
68     }
69 }