2 * Copyright (c) 2013 Cisco Systems, Inc. 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.openflowplugin.openflow.md.core.sal.convertor.match;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags;
11 import java.nio.ByteBuffer;
12 import java.util.Arrays;
17 public abstract class MatchConvertorUtil {
19 private static final String PREFIX_SEPARATOR = "/";
23 * @return subnetwork suffix in form of "/"+<mask value {0..32}>
25 public static String getIpv4Mask(byte[] maskEntry) {
26 int receivedMask = ByteBuffer.wrap(maskEntry).getInt();
29 if (receivedMask == 0) {
32 while (receivedMask != 0xffffffff) {
33 receivedMask = receivedMask >> 1;
35 if (shiftCount >= 32) {
36 throw new IllegalArgumentException("given mask is invalid: " + Arrays.toString(maskEntry));
40 return PREFIX_SEPARATOR + (32 - shiftCount);
45 * @return integer containing lower 9 bits filled with corresponding flags
47 public static Integer ipv6ExthdrFlagsToInt(Ipv6ExthdrFlags pField) {
49 bitmap |= pField.isNonext() ? (1 << 0) : 0;
50 bitmap |= pField.isEsp() ? (1 << 1) : 0;
51 bitmap |= pField.isAuth() ? (1 << 2) : 0;
52 bitmap |= pField.isDest() ? (1 << 3) : 0;
53 bitmap |= pField.isFrag() ? (1 << 4) : 0;
54 bitmap |= pField.isRouter() ? (1 << 5) : 0;
55 bitmap |= pField.isHop() ? (1 << 6) : 0;
56 bitmap |= pField.isUnrep() ? (1 << 7) : 0;
57 bitmap |= pField.isUnseq() ? (1 << 8) : 0;
61 public static int ipv6NetmaskArrayToCIDRValue(byte[] rawMask) {
64 * Openflow Spec : 1.3.2+
65 * An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
66 * So when user specify 128 as a mask, switch omit that mask and we get null as a mask in flow
67 * statistics response.
72 if (rawMask != null) {
74 for (int subArrayCounter = 0; subArrayCounter < 4; subArrayCounter++) {
75 int copyFrom = subArrayCounter * 4;
77 byte[] subArray = Arrays.copyOfRange(rawMask, copyFrom, copyFrom + 4);
79 int receivedMask = ByteBuffer.wrap(subArray).getInt();
83 if (receivedMask == 0) {
87 while (receivedMask != 0xffffffff) {
88 receivedMask = receivedMask >> 1;
92 maskValue = maskValue + (32 - shiftCount);
93 if (shiftCount != 0) {