1 package org.opendaylight.vpnservice.mdsalutil;
3 import java.math.BigInteger;
5 public class MetaDataUtil {
7 public static final BigInteger METADATA_NO_MASK = new BigInteger("0000000000000000", 16);
8 public static final BigInteger METADATA_MASK_SCF_MATCH = new BigInteger("FF00000000000000", 16);
9 public static final BigInteger METADATA_MASK_SUBP_MATCH = new BigInteger("00000000FFFF0000", 16);
10 public static final BigInteger METADATA_MASK_APPP_MATCH = new BigInteger("000000000000FFFF", 16);
11 public static final BigInteger METADATA_MASK_LPORT_MATCH = new BigInteger("00FFFF0000000000", 16);
12 public static final BigInteger METADATA_MASK_SCID_MATCH = new BigInteger("000000000000FFFF", 16);
13 public static final BigInteger METADATA_MASK_SCID_WRITE = new BigInteger("000000000000FFFF", 16);
14 public static final BigInteger METADATA_MASK_SUBP_WRITE = new BigInteger("00000000FFFF0000", 16);
15 public static final BigInteger METADATA_MASK_APPP_WRITE = new BigInteger("000000000000FFFF", 16);
16 public static final BigInteger MASK_DMAC_WRITE = new BigInteger("0000FFFFFFFFFFFF", 16);
17 public static final BigInteger METADATA_MASK_SCF_WRITE = new BigInteger("FF00000000000000", 16);
18 public static final BigInteger METADATA_MASK_LPORT_WRITE = new BigInteger("00FFFF0000000000", 16);
19 public static final BigInteger METADATA_MASK_LPORT_TAG = new BigInteger("1FFFFF0000000000", 16);
20 public static final BigInteger METADATA_MASK_SERVICE_INDEX = new BigInteger("E000000000000000", 16);
21 public static final BigInteger METADATA_MASK_SERVICE = new BigInteger("000000FFFF000000", 16);
22 public static final BigInteger METADA_MASK_TUNNEL_ID_VNI = new BigInteger("00000000FFFFFF00", 16);
23 public static final BigInteger METADATA_MASK_LABEL_ITM = new BigInteger("40FFFFFF000000FF", 16);
24 public static final BigInteger METADA_MASK_VALID_TUNNEL_ID_BIT_AND_TUNNEL_ID = new BigInteger("08000000FFFFFF00", 16);
25 public static final BigInteger METADATA_MASK_LABEL_L3 = new BigInteger("000000FFFF000000", 16);
26 public static final BigInteger METADATA_MASK_VRFID = new BigInteger("00000000FFFFFFFF", 16);
28 public static BigInteger getMetadataSCF(int scfTag) {
29 return (new BigInteger("FF", 16).and(BigInteger.valueOf(scfTag))).shiftLeft(56);
32 public static BigInteger getMetadataSCID(int scId) {
33 return BigInteger.valueOf(scId).and(new BigInteger("FFFF", 16));
36 public static BigInteger getMetadataSubProfID(int subProfId) {
37 return (BigInteger.valueOf(subProfId).and(new BigInteger("FFFF", 16))).shiftLeft(16);
40 public static BigInteger getMetadataAppProfID(int appProfId) {
41 return BigInteger.valueOf(appProfId).and(new BigInteger("FFFF", 16));
44 public static BigInteger getMetadataAPPP(int appProfId) {
45 return BigInteger.valueOf(appProfId).and(new BigInteger("FFFF", 16));
48 public static BigInteger getCookieSCFEthTypeFilter(int scfTag) {
49 return MetaDataConstants.COOKIE_SCF_BASE.add(new BigInteger("0120000", 16)).add(BigInteger.valueOf(scfTag));
52 public static BigInteger getCookieSubFilter(int scfTag) {
53 return MetaDataConstants.COOKIE_SCF_BASE.add(new BigInteger("0310000", 16)).add(BigInteger.valueOf(scfTag));
56 public static BigInteger getCookieProfMap(int scfTag) {
57 return MetaDataConstants.COOKIE_SCF_BASE.add(new BigInteger("0510000", 16)).add(BigInteger.valueOf(scfTag));
60 public static BigInteger getCookieSCFAppFilter(int scfTag) {
61 return MetaDataConstants.COOKIE_SCF_BASE.add(new BigInteger("0410000", 16)).add(BigInteger.valueOf(scfTag));
64 public static BigInteger getEthDestForIpNextHop(int groupId) {
65 return BigInteger.valueOf(groupId).and(MASK_DMAC_WRITE);
67 public static long getIpAddress(byte[] rawIpAddress) {
68 return (((rawIpAddress[0] & 0xFF) << (3 * 8)) + ((rawIpAddress[1] & 0xFF) << (2 * 8))
69 + ((rawIpAddress[2] & 0xFF) << (1 * 8)) + (rawIpAddress[3] & 0xFF)) & 0xffffffffL;
72 public static BigInteger getMetadataLPort(int lPortTag) {
73 return (new BigInteger("FFFF", 16).and(BigInteger.valueOf(lPortTag))).shiftLeft(40);
76 public static BigInteger getMetadataScHop(int scfInstanceTag, int scfPortTag, int serviceChainId) {
77 return getMetadataSCF(scfInstanceTag).or(getMetadataLPort(scfPortTag)).or(getMetadataSCID(serviceChainId));
80 public static BigInteger getMetadataMaskScHop() {
81 return METADATA_MASK_SCF_WRITE.or(METADATA_MASK_LPORT_WRITE).or(METADATA_MASK_SCID_WRITE);
84 public static BigInteger getCookieSCHop(int scfInstanceTag) {
85 return MetaDataConstants.COOKIE_SCF_BASE.add(new BigInteger("0610000", 16)).add(BigInteger.valueOf(scfInstanceTag));
88 public static BigInteger getMetadataScfPort(int scfInstanceTag, int scfPortTag) {
89 return getMetadataSCF(scfInstanceTag).or(getMetadataLPort(scfPortTag));
92 public static BigInteger getMetadataMaskScfPort() {
93 return METADATA_MASK_LPORT_WRITE.or(METADATA_MASK_SCF_WRITE);
96 public static BigInteger getCookieSCFPort() {
97 return new BigInteger("5000000", 16);
100 public static BigInteger getCookieSCFIpv4EthTypeFilter(int scfInstanceTag) {
101 return MetaDataConstants.COOKIE_SCF_BASE.add(new BigInteger("0100000", 16)).add(BigInteger.valueOf(scfInstanceTag));
104 public static BigInteger getCookieSCFArpEthTypeFilter(int scfInstanceTag) {
105 return MetaDataConstants.COOKIE_SCF_BASE.add(new BigInteger("0110000", 16)).add(BigInteger.valueOf(scfInstanceTag));
108 public static BigInteger getLportTagMetaData(int lportTag) {
109 return new BigInteger("1FFFFF", 16).and(BigInteger.valueOf(lportTag)).shiftLeft(40);
112 public static BigInteger getLportFromMetadata(BigInteger metadata) {
113 return (metadata.and(METADATA_MASK_LPORT_TAG)).shiftRight(40);
116 public static BigInteger getServiceIndexMetaData(int serviceIndex) {
117 return new BigInteger("7", 16).and(BigInteger.valueOf(serviceIndex)).shiftLeft(61);
120 public static BigInteger getMetaDataForLPortDispatcher(int lportTag, short serviceIndex) {
121 return getServiceIndexMetaData(serviceIndex).or(getLportTagMetaData(lportTag));
124 public static BigInteger getMetaDataMaskForLPortDispatcher() {
125 return METADATA_MASK_SERVICE_INDEX.or(METADATA_MASK_LPORT_TAG);
128 public static BigInteger getWriteMetaDataMaskForServicePorts() {
129 return METADATA_MASK_SERVICE_INDEX.or(METADATA_MASK_LPORT_TAG).or(METADATA_MASK_SERVICE);
132 public static BigInteger getMetaDataMaskForLPortDispatcher(BigInteger metadataMaskForServiceIndex,
133 BigInteger metadataMaskForLPortTag, BigInteger metadataMaskForService) {
134 return metadataMaskForServiceIndex.or(metadataMaskForLPortTag).or(metadataMaskForService);
137 public static BigInteger getMetaDataForLPortDispatcher(int lportTag, short serviceIndex,
138 BigInteger serviceMetaData) {
139 return getServiceIndexMetaData(serviceIndex).or(getLportTagMetaData(lportTag)).or(serviceMetaData);
143 public static BigInteger getVmLportTagMetaData(int vrfId) {
144 return BigInteger.valueOf(vrfId);
147 public static BigInteger getTunnelIdWithVni(int vni) {
148 return BigInteger.valueOf(vni).shiftLeft(8);
152 * For the tunnel id with VNI and valid-vni-flag set, the most significant byte
153 * should have 08. So, shifting 08 to 7 bytes (56 bits) and the result is OR-ed with
154 * VNI being shifted to 1 byte.
156 public static BigInteger getTunnelIdWithValidVniBitAndVniSet(int vni) {
157 return BigInteger.valueOf(0X08).shiftLeft(56).or(BigInteger.valueOf(vni).shiftLeft(8));