if (ipv6AddressMatchEntry != null) {
String ipv6PrefixStr = ipv6AddressMatchEntry.getIpv6Address().getValue();
MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
- if (maskMatchEntry != null) {
- ipv6PrefixStr += PREFIX_SEPARATOR + ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
- }
+
+ ipv6PrefixStr += PREFIX_SEPARATOR
+ + MatchConvertorUtil.ipv6NetmaskArrayToCIDRValue(maskMatchEntry.getMask());
+
if (ofMatch.getOxmMatchField().equals(Ipv6Src.class)) {
ipv6MatchBuilder.setIpv6Source(new Ipv6Prefix(ipv6PrefixStr));
}
*/
package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags;
/**
bitmap |= pField.isUnseq() ? (1 << 8) : 0;
return bitmap;
}
+
+ public static int ipv6NetmaskArrayToCIDRValue(byte[] rawMask){
+
+ /*
+ * Openflow Spec : 1.3.2+
+ * An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
+ * So when user specify 128 as a mask, switch omit that mask and we get null as a mask in flow
+ * statistics response.
+ */
+
+ int maskValue = 128;
+
+ if (rawMask != null) {
+ maskValue = 0;
+ for(int subArrayCounter=0;subArrayCounter<4;subArrayCounter++){
+ int copyFrom = subArrayCounter * 4;
+
+ byte[] subArray = Arrays.copyOfRange(rawMask, copyFrom, copyFrom+4);
+
+ int receivedMask = ByteBuffer.wrap(subArray).getInt();
+
+ int shiftCount=0;
+
+ if (receivedMask == 0) {
+ break;
+ }
+
+ while(receivedMask != 0xffffffff){
+ receivedMask = receivedMask >> 1;
+ shiftCount++;
+ }
+
+ maskValue = maskValue+(32-shiftCount);
+ if(shiftCount != 0) {
+ break;
+ }
+ }
+ }
+ return maskValue;
+ }
}
package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match;
import java.lang.reflect.Constructor;
+import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
return flags;
}
+ /**
+ * Test method for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorUtil#ipv6NetmaskArrayToCIDRValue(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry)}.
+ * @throws Exception
+ */
+ @Test
+ public void testIpv6NetmaskArrayToCIDRValue() throws Exception {
+ BigInteger maskSeed = new BigInteger("1ffffffffffffffffffffffffffffffff", 16);
+ byte[] maskArray = new byte[16];
+ LOG.debug("maskSeed= {}", ByteBufUtils.bytesToHexString(maskSeed.toByteArray()));
+
+ for (int i = 0; i <= 128; i++) {
+ System.arraycopy(maskSeed.toByteArray(), 1, maskArray, 0, 16);
+ LOG.debug("maskHex[{}] = {}", i, ByteBufUtils.bytesToHexString(maskArray));
+ int cidr = MatchConvertorUtil.ipv6NetmaskArrayToCIDRValue(maskArray);
+ LOG.debug("cidr = {}", cidr);
+ Assert.assertEquals(128-i, cidr);
+
+ maskSeed = maskSeed.clearBit(i);
+ }
+ }
+
}