List of usage examples for io.netty.buffer UnpooledByteBufAllocator DEFAULT
UnpooledByteBufAllocator DEFAULT
To view the source code for io.netty.buffer UnpooledByteBufAllocator DEFAULT.
Click Source Link
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.SetAsyncInputMessageFactoryTest.java
License:Open Source License
/** * @throws Exception /*from w w w. j av a2 s . c o m*/ * Testing of {@link SetAsyncInputMessageFactory} for correct translation from POJO */ @Test public void testSetAsyncInputMessage() throws Exception { SetAsyncInputBuilder builder = new SetAsyncInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setPacketInMask(createPacketInMask()); builder.setPortStatusMask(createPortStatusMask()); builder.setFlowRemovedMask(createFlowRemowedMask()); SetAsyncInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); SetAsyncInputMessageFactory factory = SetAsyncInputMessageFactory.getInstance(); factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); LOGGER.debug("<< " + ByteBufUtils.byteBufToHexString(out)); BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); Assert.assertEquals("Wrong packetInMask", 5, out.readUnsignedInt()); Assert.assertEquals("Wrong packetInMask", 7, out.readUnsignedInt()); Assert.assertEquals("Wrong portStatusMask", 6, out.readUnsignedInt()); Assert.assertEquals("Wrong portStatusMask", 0, out.readUnsignedInt()); Assert.assertEquals("Wrong flowRemovedMask", 10, out.readUnsignedInt()); Assert.assertEquals("Wrong flowRemovedMask", 5, out.readUnsignedInt()); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.SetConfigMessageFactoryTest.java
License:Open Source License
/** * Testing of {@link SetConfigMessageFactory} for correct translation from POJO * @throws Exception //from w w w . j a va2 s . c o m */ @Test public void testSetConfigMessageV13() throws Exception { SetConfigInputBuilder builder = new SetConfigInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); SwitchConfigFlag flag = SwitchConfigFlag.FRAGNORMAL; builder.setFlags(flag); builder.setMissSendLen(10); SetConfigInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); SetConfigMessageFactory factory = SetConfigMessageFactory.getInstance(); factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH); Assert.assertEquals("Wrong flags", SwitchConfigFlag.FRAGNORMAL.getIntValue(), out.readUnsignedShort()); Assert.assertEquals("Wrong missSendLen", 10, out.readUnsignedShort()); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.SetConfigMessageFactoryTest.java
License:Open Source License
/** * Testing of {@link SetConfigMessageFactory} for correct translation from POJO * @throws Exception /*from w w w .j a va 2 s. c o m*/ */ @Test public void testSetConfigMessageV10() throws Exception { SetConfigInputBuilder builder = new SetConfigInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); SwitchConfigFlag flag = SwitchConfigFlag.OFPCFRAGDROP; builder.setFlags(flag); builder.setMissSendLen(85); SetConfigInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); SetConfigMessageFactory factory = SetConfigMessageFactory.getInstance(); factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); BufferHelper.checkHeaderV10(out, MESSAGE_TYPE, MESSAGE_LENGTH); Assert.assertEquals("Wrong flags", SwitchConfigFlag.OFPCFRAGDROP.getIntValue(), out.readUnsignedShort()); Assert.assertEquals("Wrong missSendLen", 85, out.readUnsignedShort()); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.TableModInputMessageFactoryTest.java
License:Open Source License
/** * Testing of {@link TableModInputMessageFactory} for correct translation from POJO * @throws Exception //from w w w. ja v a 2 s .co m */ @Test public void testTableModInput() throws Exception { TableModInputBuilder builder = new TableModInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setTableId(new TableId(9L)); builder.setConfig(new TableConfig(true)); TableModInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); TableModInputMessageFactory factory = TableModInputMessageFactory.getInstance(); factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 16); Assert.assertEquals("Wrong TableID", message.getTableId().getValue().intValue(), out.readUnsignedByte()); out.skipBytes(PADDING_IN_TABLE_MOD_MESSAGE); Assert.assertEquals("Wrong TableConfig", 8, out.readUnsignedInt()); }
From source file:org.opendaylight.openflowjava.protocol.impl.util.ActionsSerializerTest.java
License:Open Source License
/** * Testing correct serialization of actions *//*from www . j a v a 2 s . co m*/ @Test public void test() { List<Action> actions = new ArrayList<>(); ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setType(Output.class); PortActionBuilder port = new PortActionBuilder(); port.setPort(new PortNumber(42L)); actionBuilder.addAugmentation(PortAction.class, port.build()); MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder(); maxLen.setMaxLength(52); actionBuilder.addAugmentation(MaxLengthAction.class, maxLen.build()); actions.add(actionBuilder.build()); actionBuilder = new ActionBuilder(); actionBuilder.setType(CopyTtlOut.class); actions.add(actionBuilder.build()); actionBuilder = new ActionBuilder(); actionBuilder.setType(CopyTtlIn.class); actions.add(actionBuilder.build()); actionBuilder = new ActionBuilder(); actionBuilder.setType(SetMplsTtl.class); MplsTtlActionBuilder mplsTtl = new MplsTtlActionBuilder(); mplsTtl.setMplsTtl((short) 4); actionBuilder.addAugmentation(MplsTtlAction.class, mplsTtl.build()); actions.add(actionBuilder.build()); actionBuilder = new ActionBuilder(); actionBuilder.setType(DecMplsTtl.class); actions.add(actionBuilder.build()); actionBuilder = new ActionBuilder(); actionBuilder.setType(PushVlan.class); EthertypeActionBuilder etherType = new EthertypeActionBuilder(); etherType.setEthertype(new EtherType(16)); actionBuilder.addAugmentation(EthertypeAction.class, etherType.build()); actions.add(actionBuilder.build()); actionBuilder = new ActionBuilder(); actionBuilder.setType(PopVlan.class); actions.add(actionBuilder.build()); actionBuilder = new ActionBuilder(); actionBuilder.setType(PushMpls.class); etherType = new EthertypeActionBuilder(); etherType.setEthertype(new EtherType(17)); actionBuilder.addAugmentation(EthertypeAction.class, etherType.build()); actions.add(actionBuilder.build()); actionBuilder = new ActionBuilder(); actionBuilder.setType(PopMpls.class); etherType = new EthertypeActionBuilder(); etherType.setEthertype(new EtherType(18)); actionBuilder.addAugmentation(EthertypeAction.class, etherType.build()); actions.add(actionBuilder.build()); actionBuilder = new ActionBuilder(); actionBuilder.setType(SetQueue.class); QueueIdActionBuilder queueId = new QueueIdActionBuilder(); queueId.setQueueId(1234L); actionBuilder.addAugmentation(QueueIdAction.class, queueId.build()); actions.add(actionBuilder.build()); actionBuilder = new ActionBuilder(); actionBuilder.setType(Group.class); GroupIdActionBuilder group = new GroupIdActionBuilder(); group.setGroupId(555L); actionBuilder.addAugmentation(GroupIdAction.class, group.build()); actions.add(actionBuilder.build()); actionBuilder = new ActionBuilder(); actionBuilder.setType(SetNwTtl.class); NwTtlActionBuilder nwTtl = new NwTtlActionBuilder(); nwTtl.setNwTtl((short) 8); actionBuilder.addAugmentation(NwTtlAction.class, nwTtl.build()); actions.add(actionBuilder.build()); actionBuilder = new ActionBuilder(); actionBuilder.setType(DecNwTtl.class); actions.add(actionBuilder.build()); actionBuilder = new ActionBuilder(); actionBuilder.setType(SetField.class); OxmFieldsActionBuilder matchEntries = new OxmFieldsActionBuilder(); List<MatchEntries> entries = new ArrayList<>(); MatchEntriesBuilder matchBuilder = new MatchEntriesBuilder(); matchBuilder.setOxmClass(OpenflowBasicClass.class); matchBuilder.setOxmMatchField(InPort.class); matchBuilder.setHasMask(false); PortNumberMatchEntryBuilder portBuilder = new PortNumberMatchEntryBuilder(); portBuilder.setPortNumber(new PortNumber(1L)); matchBuilder.addAugmentation(PortNumberMatchEntry.class, portBuilder.build()); entries.add(matchBuilder.build()); matchEntries.setMatchEntries(entries); actionBuilder.addAugmentation(OxmFieldsAction.class, matchEntries.build()); actions.add(actionBuilder.build()); actionBuilder = new ActionBuilder(); actionBuilder.setType(PushPbb.class); etherType = new EthertypeActionBuilder(); etherType.setEthertype(new EtherType(19)); actionBuilder.addAugmentation(EthertypeAction.class, etherType.build()); actions.add(actionBuilder.build()); actionBuilder = new ActionBuilder(); actionBuilder.setType(PopPbb.class); actions.add(actionBuilder.build()); actionBuilder = new ActionBuilder(); actionBuilder.setType(Experimenter.class); ExperimenterActionBuilder experimenter = new ExperimenterActionBuilder(); experimenter.setExperimenter(4L); experimenter.setData(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }); actionBuilder.addAugmentation(ExperimenterAction.class, experimenter.build()); actions.add(actionBuilder.build()); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); ActionsSerializer.encodeActions(actions, out); Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort()); Assert.assertEquals("Wrong action port", 42, out.readUnsignedInt()); Assert.assertEquals("Wrong action max-length", 52, out.readUnsignedShort()); out.skipBytes(6); Assert.assertEquals("Wrong action type", 11, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); out.skipBytes(4); Assert.assertEquals("Wrong action type", 12, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); out.skipBytes(4); Assert.assertEquals("Wrong action type", 15, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); Assert.assertEquals("Wrong action mpls-ttl", 4, out.readUnsignedByte()); out.skipBytes(3); Assert.assertEquals("Wrong action type", 16, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); out.skipBytes(4); Assert.assertEquals("Wrong action type", 17, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); Assert.assertEquals("Wrong action ethertype", 16, out.readUnsignedShort()); out.skipBytes(2); Assert.assertEquals("Wrong action type", 18, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); out.skipBytes(4); Assert.assertEquals("Wrong action type", 19, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); Assert.assertEquals("Wrong action ethertype", 17, out.readUnsignedShort()); out.skipBytes(2); Assert.assertEquals("Wrong action type", 20, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); Assert.assertEquals("Wrong action ethertype", 18, out.readUnsignedShort()); out.skipBytes(2); Assert.assertEquals("Wrong action type", 21, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); Assert.assertEquals("Wrong action queue-id", 1234, out.readUnsignedInt()); Assert.assertEquals("Wrong action type", 22, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); Assert.assertEquals("Wrong action group", 555, out.readUnsignedInt()); Assert.assertEquals("Wrong action type", 23, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); Assert.assertEquals("Wrong action nw-ttl", 8, out.readUnsignedByte()); out.skipBytes(3); Assert.assertEquals("Wrong action type", 24, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); out.skipBytes(4); Assert.assertEquals("Wrong action type", 25, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & mask", 0, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 1, out.readUnsignedInt()); out.skipBytes(4); Assert.assertEquals("Wrong action type", 26, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); Assert.assertEquals("Wrong action ethertype", 19, out.readUnsignedShort()); out.skipBytes(2); Assert.assertEquals("Wrong action type", 27, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); out.skipBytes(4); Assert.assertEquals("Wrong action type", 65535, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort()); Assert.assertEquals("Wrong experimenter", 4, out.readUnsignedInt()); byte[] data = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; out.readBytes(data); Assert.assertArrayEquals("Wrong data", new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }, data); Assert.assertTrue("Unread data", out.readableBytes() == 0); }
From source file:org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils.java
License:Open Source License
/** * Creates ByteBuf filled with specified data * @param hexSrc input String of bytes in hex format * @return ByteBuf with specified hexString converted *///from www . j a v a 2s. c o m public static ByteBuf hexStringToByteBuf(String hexSrc) { ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); hexStringToByteBuf(hexSrc, out); return out; }
From source file:org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtilsTest.java
License:Open Source License
/** * Test of {@link ByteBufUtils#hexStringToByteBuf(String, ByteBuf)} *///from www . ja v a 2 s . c o m @Test public void testHexStringToGivenByteBuf() { ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(); ByteBufUtils.hexStringToByteBuf("01 02 03 04 05 ff", buffer); Assert.assertArrayEquals(expected, byteBufToByteArray(buffer)); }
From source file:org.opendaylight.openflowjava.protocol.impl.util.InstructionsSerializerTest.java
License:Open Source License
/** * Testing instructions translation/*w ww. j a va 2 s.c o m*/ */ @Test public void test() { List<Instruction> instructions = new ArrayList<>(); // Goto_table instruction InstructionBuilder builder = new InstructionBuilder(); builder.setType(GotoTable.class); TableIdInstructionBuilder tableIdBuilder = new TableIdInstructionBuilder(); tableIdBuilder.setTableId((short) 5); builder.addAugmentation(TableIdInstruction.class, tableIdBuilder.build()); instructions.add(builder.build()); builder = new InstructionBuilder(); // Write_metadata instruction builder.setType(WriteMetadata.class); MetadataInstructionBuilder metaBuilder = new MetadataInstructionBuilder(); metaBuilder.setMetadata(ByteBufUtils.hexStringToBytes("00 01 02 03 04 05 06 07")); metaBuilder.setMetadataMask(ByteBufUtils.hexStringToBytes("07 06 05 04 03 02 01 00")); builder.addAugmentation(MetadataInstruction.class, metaBuilder.build()); instructions.add(builder.build()); // Clear_actions instruction builder = new InstructionBuilder(); builder.setType(ClearActions.class); instructions.add(builder.build()); // Meter instruction builder = new InstructionBuilder(); builder.setType(Meter.class); MeterIdInstructionBuilder meterBuilder = new MeterIdInstructionBuilder(); meterBuilder.setMeterId(42L); builder.addAugmentation(MeterIdInstruction.class, meterBuilder.build()); instructions.add(builder.build()); // Write_actions instruction builder = new InstructionBuilder(); builder.setType(WriteActions.class); ActionsInstructionBuilder actionsBuilder = new ActionsInstructionBuilder(); List<Action> actions = new ArrayList<>(); ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setType(Output.class); PortActionBuilder portBuilder = new PortActionBuilder(); portBuilder.setPort(new PortNumber(45L)); actionBuilder.addAugmentation(PortAction.class, portBuilder.build()); MaxLengthActionBuilder maxBuilder = new MaxLengthActionBuilder(); maxBuilder.setMaxLength(55); actionBuilder.addAugmentation(MaxLengthAction.class, maxBuilder.build()); actions.add(actionBuilder.build()); actionBuilder = new ActionBuilder(); actionBuilder.setType(SetNwTtl.class); NwTtlActionBuilder nwTtl = new NwTtlActionBuilder(); nwTtl.setNwTtl((short) 64); actionBuilder.addAugmentation(NwTtlAction.class, nwTtl.build()); actions.add(actionBuilder.build()); actionsBuilder.setAction(actions); builder.addAugmentation(ActionsInstruction.class, actionsBuilder.build()); instructions.add(builder.build()); // Apply_actions instruction builder = new InstructionBuilder(); builder.setType(ApplyActions.class); actionsBuilder = new ActionsInstructionBuilder(); actions = new ArrayList<>(); actionBuilder = new ActionBuilder(); actionBuilder.setType(PushVlan.class); EthertypeActionBuilder ethertypeBuilder = new EthertypeActionBuilder(); ethertypeBuilder.setEthertype(new EtherType(14)); actionBuilder.addAugmentation(EthertypeAction.class, ethertypeBuilder.build()); actions.add(actionBuilder.build()); actionBuilder = new ActionBuilder(); actionBuilder.setType(PopPbb.class); actions.add(actionBuilder.build()); actionsBuilder.setAction(actions); builder.addAugmentation(ActionsInstruction.class, actionsBuilder.build()); instructions.add(builder.build()); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); InstructionsSerializer.encodeInstructions(instructions, out); Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 8, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction table-id", 5, out.readUnsignedByte()); out.skipBytes(3); Assert.assertEquals("Wrong instruction type", 2, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 24, out.readUnsignedShort()); out.skipBytes(4); byte[] actual = new byte[8]; out.readBytes(actual); Assert.assertEquals("Wrong instruction metadata", "00 01 02 03 04 05 06 07", ByteBufUtils.bytesToHexString(actual)); actual = new byte[8]; out.readBytes(actual); Assert.assertEquals("Wrong instruction metadata-mask", "07 06 05 04 03 02 01 00", ByteBufUtils.bytesToHexString(actual)); Assert.assertEquals("Wrong instruction type", 5, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 8, out.readUnsignedShort()); out.skipBytes(4); Assert.assertEquals("Wrong instruction type", 6, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 8, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction meter-id", 42, out.readUnsignedInt()); Assert.assertEquals("Wrong instruction type", 3, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 32, out.readUnsignedShort()); out.skipBytes(4); Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort()); Assert.assertEquals("Wrong action type", 45, out.readUnsignedInt()); Assert.assertEquals("Wrong action type", 55, out.readUnsignedShort()); out.skipBytes(6); Assert.assertEquals("Wrong action type", 23, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); Assert.assertEquals("Wrong action type", 64, out.readUnsignedByte()); out.skipBytes(3); Assert.assertEquals("Wrong instruction type", 4, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 24, out.readUnsignedShort()); out.skipBytes(4); Assert.assertEquals("Wrong action type", 17, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); Assert.assertEquals("Wrong action ethertype", 14, out.readUnsignedShort()); out.skipBytes(2); Assert.assertEquals("Wrong action type", 27, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); out.skipBytes(4); Assert.assertTrue("Not all data were read", out.readableBytes() == 0); }
From source file:org.opendaylight.openflowjava.protocol.impl.util.MatchSerializerTest.java
License:Open Source License
/** * Test for correct serialization of Ipv4Address match entry */// w w w .ja v a 2s. c om @Test public void testIpv4Src() { MatchBuilder builder = new MatchBuilder(); builder.setType(OxmMatchType.class); List<MatchEntries> entries = new ArrayList<>(); MatchEntriesBuilder entriesBuilder = new MatchEntriesBuilder(); entriesBuilder.setOxmClass(OpenflowBasicClass.class); entriesBuilder.setOxmMatchField(Ipv4Src.class); entriesBuilder.setHasMask(false); Ipv4AddressMatchEntryBuilder addressBuilder = new Ipv4AddressMatchEntryBuilder(); addressBuilder.setIpv4Address(new Ipv4Address("1.2.3.4")); entriesBuilder.addAugmentation(Ipv4AddressMatchEntry.class, addressBuilder.build()); entries.add(entriesBuilder.build()); builder.setMatchEntries(entries); Match match = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); MatchSerializer.encodeMatch(match, out); Assert.assertEquals("Wrong type", 1, out.readUnsignedShort()); out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong field and mask", 22, out.readUnsignedByte()); out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); Assert.assertEquals("Wrong ip address (first number)", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong ip address (second number)", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong ip address (third number)", 3, out.readUnsignedByte()); Assert.assertEquals("Wrong ip address (fourth number)", 4, out.readUnsignedByte()); }
From source file:org.opendaylight.openflowjava.protocol.impl.util.MatchSerializerTest.java
License:Open Source License
/** * Test for correct serialization of Ipv6Address match entry *//*from w w w . j a v a 2 s. c o m*/ @Test public void testIpv6Various() { MatchBuilder builder = new MatchBuilder(); builder.setType(OxmMatchType.class); List<MatchEntries> entries = new ArrayList<>(); // ipv6 match entry with correct Ipv6 address MatchEntriesBuilder entriesBuilder = new MatchEntriesBuilder(); entriesBuilder.setOxmClass(OpenflowBasicClass.class); entriesBuilder.setOxmMatchField(Ipv6Src.class); entriesBuilder.setHasMask(false); Ipv6AddressMatchEntryBuilder addressBuilder = new Ipv6AddressMatchEntryBuilder(); addressBuilder.setIpv6Address(new Ipv6Address("1:2:3:4:5:6:7:8")); entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build()); entries.add(entriesBuilder.build()); // ipv6 match entry with abbreviated Ipv6 address entriesBuilder = new MatchEntriesBuilder(); entriesBuilder.setOxmClass(OpenflowBasicClass.class); entriesBuilder.setOxmMatchField(Ipv6NdTarget.class); entriesBuilder.setHasMask(false); addressBuilder = new Ipv6AddressMatchEntryBuilder(); addressBuilder.setIpv6Address(new Ipv6Address("1:2::6:7:8")); entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build()); entries.add(entriesBuilder.build()); // ipv6 match entry with abbreviated Ipv6 address entriesBuilder = new MatchEntriesBuilder(); entriesBuilder.setOxmClass(Nxm1Class.class); entriesBuilder.setOxmMatchField(Ipv6Dst.class); entriesBuilder.setHasMask(false); addressBuilder = new Ipv6AddressMatchEntryBuilder(); addressBuilder.setIpv6Address(new Ipv6Address("1::8")); entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build()); entries.add(entriesBuilder.build()); // ipv6 match entry with abbreviated Ipv6 address entriesBuilder = new MatchEntriesBuilder(); entriesBuilder.setOxmClass(Nxm1Class.class); entriesBuilder.setOxmMatchField(Ipv6Dst.class); entriesBuilder.setHasMask(false); addressBuilder = new Ipv6AddressMatchEntryBuilder(); addressBuilder.setIpv6Address(new Ipv6Address("::1")); entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build()); entries.add(entriesBuilder.build()); // ipv6 match entry with abbreviated Ipv6 address entriesBuilder = new MatchEntriesBuilder(); entriesBuilder.setOxmClass(Nxm0Class.class); entriesBuilder.setOxmMatchField(Ipv6Dst.class); entriesBuilder.setHasMask(false); addressBuilder = new Ipv6AddressMatchEntryBuilder(); addressBuilder.setIpv6Address(new Ipv6Address("::")); entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build()); entries.add(entriesBuilder.build()); // ipv6 match entry with incorrect Ipv6 address (longer) entriesBuilder = new MatchEntriesBuilder(); entriesBuilder.setOxmClass(OpenflowBasicClass.class); entriesBuilder.setOxmMatchField(Ipv6Dst.class); entriesBuilder.setHasMask(false); addressBuilder = new Ipv6AddressMatchEntryBuilder(); addressBuilder.setIpv6Address(new Ipv6Address("1:2:3:4:5:6:7:8:9")); entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build()); entries.add(entriesBuilder.build()); builder.setMatchEntries(entries); Match match = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); MatchSerializer.encodeMatch(match, out); Assert.assertEquals("Wrong type", 1, out.readUnsignedShort()); out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong field and mask", 52, out.readUnsignedByte()); Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte()); Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 2, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 3, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 4, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 5, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 6, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 7, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort()); Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong field and mask", 62, out.readUnsignedByte()); Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte()); Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 2, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 6, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 7, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort()); Assert.assertEquals("Wrong class", 0x0001, out.readUnsignedShort()); Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte()); Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte()); Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort()); Assert.assertEquals("Wrong class", 0x0001, out.readUnsignedShort()); Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte()); Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong class", 0x0000, out.readUnsignedShort()); Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte()); Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte()); Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte()); Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 2, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 3, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 4, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 5, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 6, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 7, out.readUnsignedShort()); Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort()); }