X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflow-protocol-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fserialization%2Fmatch%2FOxmIcmpv6TypeSerializerTest.java;h=1c4240ad3b206419ecfa6b92d123775717961802;hb=519a86d1ddcfb8f0fe264174e62e5424e1efba1f;hp=2c2a60ea07e6f4995a7870e8baf0425a9806463e;hpb=df67db32e6f1b3dbdfd6688945118a3bfa209c80;p=openflowjava.git diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv6TypeSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv6TypeSerializerTest.java index 2c2a60ea..1c4240ad 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv6TypeSerializerTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv6TypeSerializerTest.java @@ -1,110 +1,110 @@ -/* - * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.openflowjava.protocol.impl.serialization.match; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.PooledByteBufAllocator; - -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; -import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; - -/** - * @author michal.polkorab - * - */ -public class OxmIcmpv6TypeSerializerTest { - - OxmIcmpv6TypeSerializer serializer = new OxmIcmpv6TypeSerializer(); - - /** - * Test correct serialization - */ - @Test - public void testSerialize() { - MatchEntriesBuilder builder = prepareIcmpv6TypeMatchEntry((short) 123); - - ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer(); - serializer.serialize(builder.build(), buffer); - - checkHeader(buffer, false); - assertEquals("Wrong value", 123, buffer.readUnsignedByte()); - assertTrue("Unexpected data", buffer.readableBytes() == 0); - } - - /** - * Test correct header serialization - */ - @Test - public void testSerializeHeader() { - MatchEntriesBuilder builder = prepareIcmpv6TypeHeader(false); - - ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer(); - serializer.serializeHeader(builder.build(), buffer); - - checkHeader(buffer, false); - assertTrue("Unexpected data", buffer.readableBytes() == 0); - } - - /** - * Test correct oxm-class return value - */ - @Test - public void testGetOxmClassCode() { - assertEquals("Wrong oxm-class", OxmMatchConstants.OPENFLOW_BASIC_CLASS, serializer.getOxmClassCode()); - } - - /** - * Test correct oxm-field return value - */ - @Test - public void getOxmFieldCode() { - assertEquals("Wrong oxm-class", OxmMatchConstants.ICMPV6_TYPE, serializer.getOxmFieldCode()); - } - - /** - * Test correct value length return value - */ - @Test - public void testGetValueLength() { - assertEquals("Wrong value length", EncodeConstants.SIZE_OF_BYTE_IN_BYTES, serializer.getValueLength()); - } - - - private static MatchEntriesBuilder prepareIcmpv6TypeMatchEntry(short value) { - MatchEntriesBuilder builder = prepareIcmpv6TypeHeader(false); - Icmpv6TypeMatchEntryBuilder icmpv6Builder = new Icmpv6TypeMatchEntryBuilder(); - icmpv6Builder.setIcmpv6Type(value); - builder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6Builder.build()); - return builder; - } - - private static MatchEntriesBuilder prepareIcmpv6TypeHeader(boolean hasMask) { - MatchEntriesBuilder builder = new MatchEntriesBuilder(); - builder.setOxmClass(OpenflowBasicClass.class); - builder.setOxmMatchField(Icmpv6Type.class); - builder.setHasMask(hasMask); - return builder; - } - - private static void checkHeader(ByteBuf buffer, boolean hasMask) { - assertEquals("Wrong oxm-class", OxmMatchConstants.OPENFLOW_BASIC_CLASS, buffer.readUnsignedShort()); - short fieldAndMask = buffer.readUnsignedByte(); - assertEquals("Wrong oxm-field", OxmMatchConstants.ICMPV6_TYPE, fieldAndMask >>> 1); - assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0); - assertEquals("Wrong length", EncodeConstants.SIZE_OF_BYTE_IN_BYTES, buffer.readUnsignedByte()); - } +/* + * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.serialization.match; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.PooledByteBufAllocator; + +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; + +/** + * @author michal.polkorab + * + */ +public class OxmIcmpv6TypeSerializerTest { + + OxmIcmpv6TypeSerializer serializer = new OxmIcmpv6TypeSerializer(); + + /** + * Test correct serialization + */ + @Test + public void testSerialize() { + MatchEntriesBuilder builder = prepareIcmpv6TypeMatchEntry((short) 123); + + ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer(); + serializer.serialize(builder.build(), buffer); + + checkHeader(buffer, false); + assertEquals("Wrong value", 123, buffer.readUnsignedByte()); + assertTrue("Unexpected data", buffer.readableBytes() == 0); + } + + /** + * Test correct header serialization + */ + @Test + public void testSerializeHeader() { + MatchEntriesBuilder builder = prepareIcmpv6TypeHeader(false); + + ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer(); + serializer.serializeHeader(builder.build(), buffer); + + checkHeader(buffer, false); + assertTrue("Unexpected data", buffer.readableBytes() == 0); + } + + /** + * Test correct oxm-class return value + */ + @Test + public void testGetOxmClassCode() { + assertEquals("Wrong oxm-class", OxmMatchConstants.OPENFLOW_BASIC_CLASS, serializer.getOxmClassCode()); + } + + /** + * Test correct oxm-field return value + */ + @Test + public void getOxmFieldCode() { + assertEquals("Wrong oxm-class", OxmMatchConstants.ICMPV6_TYPE, serializer.getOxmFieldCode()); + } + + /** + * Test correct value length return value + */ + @Test + public void testGetValueLength() { + assertEquals("Wrong value length", EncodeConstants.SIZE_OF_BYTE_IN_BYTES, serializer.getValueLength()); + } + + + private static MatchEntriesBuilder prepareIcmpv6TypeMatchEntry(short value) { + MatchEntriesBuilder builder = prepareIcmpv6TypeHeader(false); + Icmpv6TypeMatchEntryBuilder icmpv6Builder = new Icmpv6TypeMatchEntryBuilder(); + icmpv6Builder.setIcmpv6Type(value); + builder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6Builder.build()); + return builder; + } + + private static MatchEntriesBuilder prepareIcmpv6TypeHeader(boolean hasMask) { + MatchEntriesBuilder builder = new MatchEntriesBuilder(); + builder.setOxmClass(OpenflowBasicClass.class); + builder.setOxmMatchField(Icmpv6Type.class); + builder.setHasMask(hasMask); + return builder; + } + + private static void checkHeader(ByteBuf buffer, boolean hasMask) { + assertEquals("Wrong oxm-class", OxmMatchConstants.OPENFLOW_BASIC_CLASS, buffer.readUnsignedShort()); + short fieldAndMask = buffer.readUnsignedByte(); + assertEquals("Wrong oxm-field", OxmMatchConstants.ICMPV6_TYPE, fieldAndMask >>> 1); + assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0); + assertEquals("Wrong length", EncodeConstants.SIZE_OF_BYTE_IN_BYTES, buffer.readUnsignedByte()); + } } \ No newline at end of file