List of usage examples for io.netty.buffer ByteBuf skipBytes
public abstract ByteBuf skipBytes(int length);
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 . j a va2 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.ActionsDeserializer.java
License:Open Source License
private static Action createEmptyHeader(Class<? extends ActionBase> action, ByteBuf in, ActionBuilder actionBuilder) {/* w w w . j a va 2 s. c o m*/ actionBuilder.setType(action); in.skipBytes(PADDING_IN_ACTIONS_HEADER); return actionBuilder.build(); }
From source file:org.opendaylight.openflowjava.protocol.impl.util.ActionsDeserializer.java
License:Open Source License
private static Action createOutputAction(ByteBuf in, ActionBuilder actionBuilder) { actionBuilder.setType(Output.class); PortActionBuilder port = new PortActionBuilder(); port.setPort(new PortNumber(in.readUnsignedInt())); actionBuilder.addAugmentation(PortAction.class, port.build()); MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder(); maxLen.setMaxLength(in.readUnsignedShort()); actionBuilder.addAugmentation(MaxLengthAction.class, maxLen.build()); in.skipBytes(PADDING_IN_OUTPUT_ACTIONS_HEADER); return actionBuilder.build(); }
From source file:org.opendaylight.openflowjava.protocol.impl.util.ActionsDeserializer.java
License:Open Source License
private static Action createSetMplsTtlAction(ByteBuf in, ActionBuilder actionBuilder) { actionBuilder.setType(SetMplsTtl.class); MplsTtlActionBuilder mplsTtl = new MplsTtlActionBuilder(); mplsTtl.setMplsTtl(in.readUnsignedByte()); actionBuilder.addAugmentation(MplsTtlAction.class, mplsTtl.build()); in.skipBytes(PADDING_IN_SET_MPLS_TTL_ACTIONS_HEADER); return actionBuilder.build(); }
From source file:org.opendaylight.openflowjava.protocol.impl.util.ActionsDeserializer.java
License:Open Source License
private static Action createPushAction(Class<? extends ActionBase> action, ByteBuf in, ActionBuilder actionBuilder) {//from w ww.j a v a 2s. com actionBuilder.setType(action); EthertypeActionBuilder etherType = new EthertypeActionBuilder(); etherType.setEthertype(new EtherType(in.readUnsignedShort())); actionBuilder.addAugmentation(EthertypeAction.class, etherType.build()); in.skipBytes(PADDING_IN_PUSH_VLAN_ACTIONS_HEADER); return actionBuilder.build(); }
From source file:org.opendaylight.openflowjava.protocol.impl.util.ActionsDeserializer.java
License:Open Source License
private static Action createSetNwTtlAction(ByteBuf in, ActionBuilder actionBuilder) { actionBuilder.setType(SetNwTtl.class); NwTtlActionBuilder nwTtl = new NwTtlActionBuilder(); nwTtl.setNwTtl(in.readUnsignedByte()); actionBuilder.addAugmentation(NwTtlAction.class, nwTtl.build()); in.skipBytes(PADDING_IN_NW_TTL_ACTIONS_HEADER); return actionBuilder.build(); }
From source file:org.opendaylight.openflowjava.protocol.impl.util.ActionsDeserializerTest.java
License:Open Source License
/** * Testing actions deserialization//from w ww . j ava 2 s.com */ @Test public void test() { ByteBuf message = BufferHelper.buildBuffer("00 00 00 10 00 00 00 01 00 02 00 00 00 00 00 00 " + "00 0B 00 08 00 00 00 00 " + "00 0C 00 08 00 00 00 00 " + "00 0F 00 08 03 00 00 00 " + "00 10 00 08 00 00 00 00 " + "00 11 00 08 00 04 00 00 " + "00 12 00 08 00 00 00 00 " + "00 13 00 08 00 05 00 00 " + "00 14 00 08 00 06 00 00 " + "00 15 00 08 00 00 00 07 " + "00 16 00 08 00 00 00 08 " + "00 17 00 08 09 00 00 00 " + "00 18 00 08 00 00 00 00 " + "00 19 00 10 80 00 02 04 00 00 00 0B 00 00 00 00 " + "00 1A 00 08 00 0A 00 00 " + "00 1B 00 08 00 00 00 00 " + "FF FF 00 10 00 00 00 08 00 01 02 03 04 05 06 07"); message.skipBytes(4); // skip XID LOGGER.info("bytes: " + message.readableBytes()); List<Action> actions = ActionsDeserializer.createActions(message, message.readableBytes()); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + "openflow.common.action.rev130731.Output", actions.get(0).getType().getName()); Assert.assertEquals("Wrong action port", 1, actions.get(0).getAugmentation(PortAction.class).getPort().getValue().intValue()); Assert.assertEquals("Wrong action max-length", 2, actions.get(0).getAugmentation(MaxLengthAction.class).getMaxLength().intValue()); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + "openflow.common.action.rev130731.CopyTtlOut", actions.get(1).getType().getName()); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + "openflow.common.action.rev130731.CopyTtlIn", actions.get(2).getType().getName()); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + "openflow.common.action.rev130731.SetMplsTtl", actions.get(3).getType().getName()); Assert.assertEquals("Wrong action value", 3, actions.get(3).getAugmentation(MplsTtlAction.class).getMplsTtl().shortValue()); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + "openflow.common.action.rev130731.DecMplsTtl", actions.get(4).getType().getName()); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + "openflow.common.action.rev130731.PushVlan", actions.get(5).getType().getName()); Assert.assertEquals("Wrong action value", 4, actions.get(5).getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue()); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + "openflow.common.action.rev130731.PopVlan", actions.get(6).getType().getName()); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + "openflow.common.action.rev130731.PushMpls", actions.get(7).getType().getName()); Assert.assertEquals("Wrong action value", 5, actions.get(7).getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue()); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + "openflow.common.action.rev130731.PopMpls", actions.get(8).getType().getName()); Assert.assertEquals("Wrong action value", 6, actions.get(8).getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue()); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + "openflow.common.action.rev130731.SetQueue", actions.get(9).getType().getName()); Assert.assertEquals("Wrong action value", 7, actions.get(9).getAugmentation(QueueIdAction.class).getQueueId().intValue()); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + "openflow.common.action.rev130731.Group", actions.get(10).getType().getName()); Assert.assertEquals("Wrong action value", 8, actions.get(10).getAugmentation(GroupIdAction.class).getGroupId().intValue()); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + "openflow.common.action.rev130731.SetNwTtl", actions.get(11).getType().getName()); Assert.assertEquals("Wrong action value", 9, actions.get(11).getAugmentation(NwTtlAction.class).getNwTtl().intValue()); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + "openflow.common.action.rev130731.DecNwTtl", actions.get(12).getType().getName()); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + "openflow.common.action.rev130731.SetField", actions.get(13).getType().getName()); List<MatchEntries> entries = actions.get(13).getAugmentation(OxmFieldsAction.class).getMatchEntries(); Assert.assertEquals("Wrong number of fields", 1, entries.size()); Assert.assertEquals("Wrong match entry class", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow." + "oxm.rev130731.OpenflowBasicClass", entries.get(0).getOxmClass().getName()); Assert.assertEquals("Wrong match entry field", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow." + "oxm.rev130731.InPhyPort", entries.get(0).getOxmMatchField().getName()); Assert.assertEquals("Wrong match entry mask", false, entries.get(0).isHasMask()); Assert.assertEquals("Wrong match entry value", 11, entries.get(0).getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue()); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + "openflow.common.action.rev130731.PushPbb", actions.get(14).getType().getName()); Assert.assertEquals("Wrong action value", 10, actions.get(14).getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue()); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + "openflow.common.action.rev130731.PopPbb", actions.get(15).getType().getName()); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight." + "openflow.common.action.rev130731.Experimenter", actions.get(16).getType().getName()); Assert.assertEquals("Wrong experimenter", 8, actions.get(16).getAugmentation(ExperimenterAction.class).getExperimenter().intValue()); Assert.assertArrayEquals("Wrong data", new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }, actions.get(16).getAugmentation(ExperimenterAction.class).getData()); Assert.assertTrue("Unread data in message", message.readableBytes() == 0); }
From source file:org.opendaylight.openflowjava.protocol.impl.util.ActionsSerializerTest.java
License:Open Source License
/** * Testing correct serialization of actions *///from w ww . j a v a 2 s. c om @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.ByteBufUtilsTest.java
License:Open Source License
/** * Test of {@link ByteBufUtils#byteBufToHexString(ByteBuf)} *///from w w w.j av a 2 s . c om @Test public void testByteBufToHexString() { ByteBuf buf = ByteBufUtils.hexStringToByteBuf("00 01 02 03 04 05 06 07"); buf.skipBytes(4); Assert.assertEquals("Wrong data read", "04 05 06 07", ByteBufUtils.byteBufToHexString(buf)); }
From source file:org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMakerFactoryTest.java
License:Open Source License
/** * Tests {@link CodeKeyMakerFactory#createMatchEntriesKeyMaker(short)} *///from w w w . ja va2s .c o m @Test public void testMatchEntriesKeyMaker() { CodeKeyMaker keyMaker = CodeKeyMakerFactory.createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID); Assert.assertNotNull("Null key maker", keyMaker); ByteBuf buffer = BufferHelper.buildBuffer("80 00 00 04 00 00 00 01"); buffer.skipBytes(4); // skip XID MessageCodeKey codeKey = keyMaker.make(buffer); Assert.assertNotNull("Null key", codeKey); Assert.assertEquals("Wrong key", new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID, 32768, 0), codeKey); Assert.assertEquals("Buffer index modified", 8, buffer.readableBytes()); }