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 java.lang.reflect.Constructor;
11 import java.math.BigInteger;
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.opendaylight.openflowjava.util.ByteBufUtils;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
23 public class MatchConvertorUtilTest {
25 private static Logger LOG = LoggerFactory
26 .getLogger(MatchConvertorUtilTest.class);
29 * Test method for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorUtil#ipv6ExthdrFlagsToInt(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags)}.
33 public void testIpv6ExthdrFlagsToInt() throws Exception {
34 Ipv6ExthdrFlags pField;
35 Constructor<Ipv6ExthdrFlags> ctor = Ipv6ExthdrFlags.class.getConstructor(
36 Boolean.class, Boolean.class, Boolean.class, Boolean.class,
37 Boolean.class, Boolean.class, Boolean.class, Boolean.class, Boolean.class);
39 int[] expectedFlagCumulants = new int[] {
40 4, 8, 2, 16, 64, 1, 32, 128, 256
43 for (int i = 0; i < 9; i++) {
44 pField = ctor.newInstance(createIpv6ExthdrFlagsCtorParams(i));
45 int intResult = MatchConvertorUtil.ipv6ExthdrFlagsToInt(pField);
46 LOG.debug("{}:Ipv6ExthdrFlags[{}] as int = {}", i, pField, intResult);
47 Assert.assertEquals(expectedFlagCumulants[i], intResult);
50 pField = new Ipv6ExthdrFlags(
51 false, false, false, false, false, false, false, false, false);
52 Assert.assertEquals(0, MatchConvertorUtil.ipv6ExthdrFlagsToInt(pField).intValue());
54 pField = new Ipv6ExthdrFlags(
55 true, true, true, true, true, true, true, true, true);
56 Assert.assertEquals(511, MatchConvertorUtil.ipv6ExthdrFlagsToInt(pField).intValue());
62 private static Object[] createIpv6ExthdrFlagsCtorParams(int trueIndex) {
63 Boolean[] flags = new Boolean[]{false, false, false, false, false, false, false, false, false};
64 flags[trueIndex] = true;
69 * 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)}.
73 public void testIpv6NetmaskArrayToCIDRValue() throws Exception {
74 BigInteger maskSeed = new BigInteger("1ffffffffffffffffffffffffffffffff", 16);
75 byte[] maskArray = new byte[16];
76 LOG.debug("maskSeed= {}", ByteBufUtils.bytesToHexString(maskSeed.toByteArray()));
78 for (int i = 0; i <= 128; i++) {
79 System.arraycopy(maskSeed.toByteArray(), 1, maskArray, 0, 16);
80 LOG.debug("maskHex[{}] = {}", i, ByteBufUtils.bytesToHexString(maskArray));
81 int cidr = MatchConvertorUtil.ipv6NetmaskArrayToCIDRValue(maskArray);
82 LOG.debug("cidr = {}", cidr);
83 Assert.assertEquals(128-i, cidr);
85 maskSeed = maskSeed.clearBit(i);