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.MultipartRequestInputFactoryTest.java
License:Open Source License
/** * @throws Exception/* www. ja v a 2s . co m*/ * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO */ @Test public void testMultipartRequestMeterMessageFactory() throws Exception { MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setType(MultipartType.forValue(9)); builder.setFlags(new MultipartRequestFlags(true)); builder.setMultipartRequestBody(createRequestMeter()); MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); Assert.assertEquals("Wrong meterBody", message.getMultipartRequestBody(), decodeRequestMeter(out)); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartRequestInputFactoryTest.java
License:Open Source License
private static MultipartRequestMeterCase decodeRequestMeter(ByteBuf output) { final byte PADDING_IN_MULTIPART_REQUEST_METER_BODY = 4; MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder(); MultipartRequestMeterBuilder builder = new MultipartRequestMeterBuilder(); builder.setMeterId(new MeterId(output.readUnsignedInt())); output.skipBytes(PADDING_IN_MULTIPART_REQUEST_METER_BODY); caseBuilder.setMultipartRequestMeter(builder.build()); return caseBuilder.build(); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartRequestInputFactoryTest.java
License:Open Source License
/** * @throws Exception// ww w . ja v a 2 s . co m * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO */ @Test public void testMultipartRequestMeterConfigMessageFactory() throws Exception { MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setType(MultipartType.forValue(10)); builder.setFlags(new MultipartRequestFlags(true)); builder.setMultipartRequestBody(createRequestMeterConfig()); MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); Assert.assertEquals("Wrong meterConfigBody", message.getMultipartRequestBody(), decodeRequestMeterConfig(out)); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartRequestInputFactoryTest.java
License:Open Source License
private static MultipartRequestMeterConfigCase decodeRequestMeterConfig(ByteBuf output) { final byte PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY = 4; MultipartRequestMeterConfigCaseBuilder caseBuilder = new MultipartRequestMeterConfigCaseBuilder(); MultipartRequestMeterConfigBuilder builder = new MultipartRequestMeterConfigBuilder(); builder.setMeterId(new MeterId(output.readUnsignedInt())); output.skipBytes(PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY); caseBuilder.setMultipartRequestMeterConfig(builder.build()); return caseBuilder.build(); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartRequestInputFactoryTest.java
License:Open Source License
/** * @throws Exception/*from w w w. j av a 2 s. c o m*/ * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO */ @Test public void testMultipartRequestExperimenterMessageFactory() throws Exception { MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setType(MultipartType.forValue(0xffff)); builder.setFlags(new MultipartRequestFlags(true)); builder.setMultipartRequestBody(createRequestExperimenter()); MultipartRequestInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); MultipartRequestInputFactory factory = MultipartRequestInputFactory.getInstance(); factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readUnsignedShort()); Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort())); out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE); Assert.assertEquals("Wrong experimenterBody", message.getMultipartRequestBody(), decodeRequestExperimenter(out)); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10FeaturesReplyMessageFactoryTest.java
License:Open Source License
@Test public void testSerialize() throws Exception { GetFeaturesOutputBuilder builder = new GetFeaturesOutputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); builder.setDatapathId(BigInteger.valueOf(1L)); builder.setBuffers(1L);//from www . j a v a 2 s. co m builder.setTables((short) 1); builder.setCapabilitiesV10(new CapabilitiesV10(true, false, true, false, true, false, true, false)); builder.setActionsV10(new ActionTypeV10(true, false, true, false, true, false, true, false, true, false, true, false, true)); builder.setPhyPort(createPorts()); GetFeaturesOutput message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.serialize(message, serializedBuffer); BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 80); Assert.assertEquals("Wrong datapath id", message.getDatapathId().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong n buffers", message.getBuffers().longValue(), serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong n tables", message.getTables().shortValue(), serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(3); Assert.assertEquals("Wrong capabilities", message.getCapabilitiesV10(), createCapabilities(serializedBuffer.readInt())); Assert.assertEquals("Wrong actions", message.getActionsV10(), createActionsV10(serializedBuffer.readInt())); PhyPort port = message.getPhyPort().get(0); Assert.assertEquals("Wrong port No", port.getPortNo().intValue(), serializedBuffer.readShort()); byte[] address = new byte[6]; serializedBuffer.readBytes(address); Assert.assertEquals("Wrong MacAddress", port.getHwAddr().getValue().toLowerCase(), new MacAddress(ByteBufUtils.macAddressToString(address)).getValue().toLowerCase()); byte[] name = new byte[16]; serializedBuffer.readBytes(name); Assert.assertEquals("Wrong name", port.getName(), new String(name).trim()); Assert.assertEquals("Wrong config", port.getConfigV10(), createPortConfig(serializedBuffer.readInt())); Assert.assertEquals("Wrong state", port.getStateV10(), createPortState(serializedBuffer.readInt())); Assert.assertEquals("Wrong current", port.getCurrentFeaturesV10(), createPortFeatures(serializedBuffer.readInt())); Assert.assertEquals("Wrong advertised", port.getAdvertisedFeaturesV10(), createPortFeatures(serializedBuffer.readInt())); Assert.assertEquals("Wrong supported", port.getSupportedFeaturesV10(), createPortFeatures(serializedBuffer.readInt())); Assert.assertEquals("Wrong peer", port.getPeerFeaturesV10(), createPortFeatures(serializedBuffer.readInt())); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10FlowModInputMessageFactoryTest.java
License:Open Source License
/** * @throws Exception /* www.j av a 2 s .co m*/ * Testing of {@link OF10FlowModInputMessageFactory} for correct translation from POJO */ @Test public void testFlowModInputMessageFactory() throws Exception { FlowModInputBuilder builder = new FlowModInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); MatchV10Builder matchBuilder = new MatchV10Builder(); matchBuilder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true)); matchBuilder.setNwSrcMask((short) 0); matchBuilder.setNwDstMask((short) 0); matchBuilder.setInPort(58); matchBuilder.setDlSrc(new MacAddress("01:01:01:01:01:01")); matchBuilder.setDlDst(new MacAddress("ff:ff:ff:ff:ff:ff")); matchBuilder.setDlVlan(18); matchBuilder.setDlVlanPcp((short) 5); matchBuilder.setDlType(42); matchBuilder.setNwTos((short) 4); matchBuilder.setNwProto((short) 7); matchBuilder.setNwSrc(new Ipv4Address("8.8.8.8")); matchBuilder.setNwDst(new Ipv4Address("16.16.16.16")); matchBuilder.setTpSrc(6653); matchBuilder.setTpDst(6633); builder.setMatchV10(matchBuilder.build()); byte[] cookie = new byte[] { (byte) 0xFF, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01 }; builder.setCookie(new BigInteger(1, cookie)); builder.setCommand(FlowModCommand.forValue(0)); builder.setIdleTimeout(12); builder.setHardTimeout(16); builder.setPriority(1); builder.setBufferId(2L); builder.setOutPort(new PortNumber(4422L)); builder.setFlagsV10(new FlowModFlagsV10(true, false, true)); List<Action> actions = new ArrayList<>(); ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setType(SetNwDst.class); IpAddressActionBuilder ipBuilder = new IpAddressActionBuilder(); ipBuilder.setIpAddress(new Ipv4Address("2.2.2.2")); actionBuilder.addAugmentation(IpAddressAction.class, ipBuilder.build()); actions.add(actionBuilder.build()); actionBuilder = new ActionBuilder(); actionBuilder.setType(SetTpSrc.class); PortActionBuilder portBuilder = new PortActionBuilder(); portBuilder.setPort(new PortNumber(42L)); actionBuilder.addAugmentation(PortAction.class, portBuilder.build()); actions.add(actionBuilder.build()); builder.setAction(actions); FlowModInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); OF10FlowModInputMessageFactory factory = OF10FlowModInputMessageFactory.getInstance(); factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); BufferHelper.checkHeaderV10(out, factory.getMessageType(), factory.computeLength(message)); Assert.assertEquals("Wrong wildcards", 3678463, out.readUnsignedInt()); Assert.assertEquals("Wrong inPort", 58, out.readUnsignedShort()); byte[] dlSrc = new byte[6]; out.readBytes(dlSrc); Assert.assertEquals("Wrong dlSrc", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc)); byte[] dlDst = new byte[6]; out.readBytes(dlDst); Assert.assertEquals("Wrong dlDst", "FF:FF:FF:FF:FF:FF", ByteBufUtils.macAddressToString(dlDst)); Assert.assertEquals("Wrong dlVlan", 18, out.readUnsignedShort()); Assert.assertEquals("Wrong dlVlanPcp", 5, out.readUnsignedByte()); out.skipBytes(1); Assert.assertEquals("Wrong dlType", 42, out.readUnsignedShort()); Assert.assertEquals("Wrong nwTos", 4, out.readUnsignedByte()); Assert.assertEquals("Wrong nwProto", 7, out.readUnsignedByte()); out.skipBytes(2); Assert.assertEquals("Wrong nwSrc", 134744072, out.readUnsignedInt()); Assert.assertEquals("Wrong nwDst", 269488144, out.readUnsignedInt()); Assert.assertEquals("Wrong tpSrc", 6653, out.readUnsignedShort()); Assert.assertEquals("Wrong tpDst", 6633, out.readUnsignedShort()); byte[] cookieRead = new byte[8]; out.readBytes(cookieRead); Assert.assertArrayEquals("Wrong cookie", cookie, cookieRead); Assert.assertEquals("Wrong command", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong idleTimeOut", 12, out.readUnsignedShort()); Assert.assertEquals("Wrong hardTimeOut", 16, out.readUnsignedShort()); Assert.assertEquals("Wrong priority", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong bufferId", 2, out.readUnsignedInt()); Assert.assertEquals("Wrong outPort", 4422, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 3, out.readUnsignedShort()); Assert.assertEquals("Wrong action - type", 7, out.readUnsignedShort()); Assert.assertEquals("Wrong action - length", 8, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 33686018, out.readUnsignedInt()); Assert.assertEquals("Wrong action - type", 9, out.readUnsignedShort()); Assert.assertEquals("Wrong action - length", 8, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 42, out.readUnsignedShort()); out.skipBytes(2); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10FlowRemovedMessageFactoryTest.java
License:Open Source License
@Test public void testSerialize() throws Exception { FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); MatchV10Builder matchBuilder = new MatchV10Builder(); matchBuilder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true)); matchBuilder.setNwSrcMask((short) 0); matchBuilder.setNwDstMask((short) 0); matchBuilder.setInPort(58);//w w w. j a v a 2 s . c om matchBuilder.setDlSrc(new MacAddress("01:01:01:01:01:01")); matchBuilder.setDlDst(new MacAddress("ff:ff:ff:ff:ff:ff")); matchBuilder.setDlVlan(18); matchBuilder.setDlVlanPcp((short) 5); matchBuilder.setDlType(42); matchBuilder.setNwTos((short) 4); matchBuilder.setNwProto((short) 7); matchBuilder.setNwSrc(new Ipv4Address("8.8.8.8")); matchBuilder.setNwDst(new Ipv4Address("16.16.16.16")); matchBuilder.setTpSrc(6653); matchBuilder.setTpDst(6633); builder.setMatchV10(matchBuilder.build()); byte[] cookie = new byte[] { (byte) 0xFF, 0x01, 0x04, 0x01, 0x01, 0x01, 0x04, 0x01 }; builder.setCookie(new BigInteger(1, cookie)); builder.setPriority(1); builder.setReason(FlowRemovedReason.forValue(1)); builder.setDurationSec(1L); builder.setDurationNsec(1L); builder.setIdleTimeout(12); builder.setPacketCount(BigInteger.valueOf(1L)); builder.setByteCount(BigInteger.valueOf(2L)); FlowRemovedMessage message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.serialize(message, serializedBuffer); BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 88); Assert.assertEquals("Wrong wildcards", 3678463, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong inPort", 58, serializedBuffer.readUnsignedShort()); byte[] dlSrc = new byte[6]; serializedBuffer.readBytes(dlSrc); Assert.assertEquals("Wrong dlSrc", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc)); byte[] dlDst = new byte[6]; serializedBuffer.readBytes(dlDst); Assert.assertEquals("Wrong dlDst", "FF:FF:FF:FF:FF:FF", ByteBufUtils.macAddressToString(dlDst)); Assert.assertEquals("Wrong dlVlan", 18, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong dlVlanPcp", 5, serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(1); Assert.assertEquals("Wrong dlType", 42, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong nwTos", 4, serializedBuffer.readUnsignedByte()); Assert.assertEquals("Wrong nwProto", 7, serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(2); Assert.assertEquals("Wrong nwSrc", 134744072, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong nwDst", 269488144, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong tpSrc", 6653, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong tpDst", 6633, serializedBuffer.readUnsignedShort()); byte[] cookieRead = new byte[8]; serializedBuffer.readBytes(cookieRead); Assert.assertArrayEquals("Wrong cookie", cookie, cookieRead); Assert.assertEquals("Wrong priority", 1, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong reason", 1, serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(1); Assert.assertEquals("Wrong duration", 1L, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong duration nsec", 1L, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong idle timeout", 12, serializedBuffer.readUnsignedShort()); serializedBuffer.skipBytes(2); Assert.assertEquals("Wrong packet count", 1L, serializedBuffer.readLong()); Assert.assertEquals("Wrong byte count", 2L, serializedBuffer.readLong()); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10PacketInMessageFactoryTest.java
License:Open Source License
@Test public void testSerialize() throws Exception { PacketInMessageBuilder builder = new PacketInMessageBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); builder.setBufferId(1L);//from w w w . ja v a 2 s. com builder.setTotalLen(1); builder.setInPort(1); builder.setReason(PacketInReason.forValue(0)); byte[] data = ByteBufUtils.hexStringToBytes("00 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14"); builder.setData(data); PacketInMessage message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.serialize(message, serializedBuffer); BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 34); Assert.assertEquals("Wrong buffer id", message.getBufferId().longValue(), serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong total len", message.getTotalLen().intValue(), serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong port in", message.getInPort().intValue(), serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong reason", message.getReason().getIntValue(), serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(1); byte[] readData = new byte[serializedBuffer.readableBytes()]; serializedBuffer.readBytes(readData); Assert.assertArrayEquals("Wrong data", message.getData(), readData); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10PacketOutInputMessageFactoryTest.java
License:Open Source License
/** * Testing of {@link OF10PacketOutInputMessageFactory} for correct translation from POJO * @throws Exception /*w ww. j ava2 s .c o m*/ */ @Test public void testPacketOutInputMessage() throws Exception { PacketOutInputBuilder builder = new PacketOutInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); builder.setBufferId(256L); builder.setInPort(new PortNumber(257L)); List<Action> actions = new ArrayList<>(); ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setType(Output.class); PortActionBuilder portBuilder = new PortActionBuilder(); portBuilder.setPort(new PortNumber((long) 42)); actionBuilder.addAugmentation(PortAction.class, portBuilder.build()); MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder(); maxLen.setMaxLength(50); actionBuilder.addAugmentation(MaxLengthAction.class, maxLen.build()); actions.add(actionBuilder.build()); actionBuilder = new ActionBuilder(); actionBuilder.setType(StripVlan.class); builder.setAction(actions); actions.add(actionBuilder.build()); builder.setAction(actions); builder.setData(ByteBufUtils.hexStringToBytes("00 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14")); PacketOutInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); OF10PacketOutInputMessageFactory factory = OF10PacketOutInputMessageFactory.getInstance(); factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); BufferHelper.checkHeaderV10(out, (byte) 13, 48); Assert.assertEquals("Wrong BufferId", 256, out.readUnsignedInt()); Assert.assertEquals("Wrong PortNumber", 257, out.readUnsignedShort()); Assert.assertEquals("Wrong actions length", 16, out.readUnsignedShort()); Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); Assert.assertEquals("Wrong port", 42, out.readUnsignedShort()); Assert.assertEquals("Wrong maxlength", 50, out.readUnsignedShort()); Assert.assertEquals("Wrong action type", 3, out.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort()); out.skipBytes(4); Assert.assertArrayEquals("Wrong data", message.getData(), out.readBytes(out.readableBytes()).array()); Assert.assertTrue("Unread data", out.readableBytes() == 0); }