List of usage examples for io.netty.buffer ByteBuf skipBytes
public abstract ByteBuf skipBytes(int length);
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.MultipartRequestInputMessageFactory.java
License:Open Source License
@Override public MultipartRequestInput deserialize(ByteBuf rawMessage) { MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); int type = rawMessage.readUnsignedShort(); builder.setType(getMultipartType(type)); builder.setFlags(getMultipartRequestFlags(rawMessage.readUnsignedShort())); rawMessage.skipBytes(PADDING); switch (MultipartType.forValue(type)) { case OFPMPDESC: builder.setMultipartRequestBody(setDesc(rawMessage)); break;//from w w w . ja v a 2 s . co m case OFPMPFLOW: builder.setMultipartRequestBody(setFlow(rawMessage)); break; case OFPMPAGGREGATE: builder.setMultipartRequestBody(setAggregate(rawMessage)); break; case OFPMPTABLE: builder.setMultipartRequestBody(setTable(rawMessage)); break; case OFPMPTABLEFEATURES: builder.setMultipartRequestBody(setTableFeatures(rawMessage)); break; case OFPMPPORTSTATS: builder.setMultipartRequestBody(setPortStats(rawMessage)); break; case OFPMPPORTDESC: builder.setMultipartRequestBody(setPortDesc(rawMessage)); break; case OFPMPQUEUE: builder.setMultipartRequestBody(setQueue(rawMessage)); break; case OFPMPGROUP: builder.setMultipartRequestBody(setGroup(rawMessage)); break; case OFPMPGROUPDESC: builder.setMultipartRequestBody(setGroupDesc(rawMessage)); break; case OFPMPGROUPFEATURES: builder.setMultipartRequestBody(setGroupFeatures(rawMessage)); break; case OFPMPMETER: builder.setMultipartRequestBody(setMeter(rawMessage)); break; case OFPMPMETERCONFIG: builder.setMultipartRequestBody(setMeterConfig(rawMessage)); break; case OFPMPMETERFEATURES: builder.setMultipartRequestBody(setMeterFeatures(rawMessage)); break; case OFPMPEXPERIMENTER: builder.setMultipartRequestBody(setExperimenter(rawMessage)); break; default: break; } return builder.build(); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.MultipartRequestInputMessageFactory.java
License:Open Source License
private MultipartRequestTableFeaturesCase setTableFeatures(ByteBuf input) { MultipartRequestTableFeaturesCaseBuilder caseBuilder = new MultipartRequestTableFeaturesCaseBuilder(); MultipartRequestTableFeaturesBuilder tableFeaturesBuilder = new MultipartRequestTableFeaturesBuilder(); List<TableFeatures> features = new ArrayList<>(); while (input.readableBytes() > 0) { TableFeaturesBuilder featuresBuilder = new TableFeaturesBuilder(); int length = input.readUnsignedShort(); featuresBuilder.setTableId(input.readUnsignedByte()); input.skipBytes(PADDING_IN_MULTIPART_REQUEST_TABLE_FEATURES); featuresBuilder.setName(ByteBufUtils.decodeNullTerminatedString(input, MAX_TABLE_NAME_LENGTH)); byte[] metadataMatch = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; input.readBytes(metadataMatch);//from www . j a va 2 s .c o m featuresBuilder.setMetadataMatch(new BigInteger(1, metadataMatch)); byte[] metadataWrite = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; input.readBytes(metadataWrite); featuresBuilder.setMetadataWrite(new BigInteger(1, metadataWrite)); featuresBuilder.setConfig(createTableConfig(input.readUnsignedInt())); featuresBuilder.setMaxEntries(input.readUnsignedInt()); featuresBuilder.setTableFeatureProperties(createTableFeaturesProperties(input, length - MULTIPART_REQUEST_TABLE_FEATURES_STRUCTURE_LENGTH)); features.add(featuresBuilder.build()); } tableFeaturesBuilder.setTableFeatures(features); caseBuilder.setMultipartRequestTableFeatures(tableFeaturesBuilder.build()); return caseBuilder.build(); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.MultipartRequestInputMessageFactory.java
License:Open Source License
private List<TableFeatureProperties> createTableFeaturesProperties(ByteBuf input, int length) { List<TableFeatureProperties> properties = new ArrayList<>(); int tableFeaturesLength = length; while (tableFeaturesLength > 0) { int propStartIndex = input.readerIndex(); TableFeaturePropertiesBuilder builder = new TableFeaturePropertiesBuilder(); TableFeaturesPropType type = TableFeaturesPropType.forValue(input.readUnsignedShort()); builder.setType(type);//from w w w. ja v a 2 s .c om int propertyLength = input.readUnsignedShort(); int paddingRemainder = propertyLength % EncodeConstants.PADDING; tableFeaturesLength -= propertyLength; if (type.equals(TableFeaturesPropType.OFPTFPTINSTRUCTIONS) || type.equals(TableFeaturesPropType.OFPTFPTINSTRUCTIONSMISS)) { InstructionRelatedTableFeaturePropertyBuilder insBuilder = new InstructionRelatedTableFeaturePropertyBuilder(); CodeKeyMaker keyMaker = CodeKeyMakerFactory .createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID); List<Instruction> instructions = ListDeserializer.deserializeHeaders( EncodeConstants.OF13_VERSION_ID, propertyLength - COMMON_PROPERTY_LENGTH, input, keyMaker, registry); insBuilder.setInstruction(instructions); builder.addAugmentation(InstructionRelatedTableFeatureProperty.class, insBuilder.build()); } else if (type.equals(TableFeaturesPropType.OFPTFPTNEXTTABLES) || type.equals(TableFeaturesPropType.OFPTFPTNEXTTABLESMISS)) { propertyLength -= COMMON_PROPERTY_LENGTH; NextTableRelatedTableFeaturePropertyBuilder tableBuilder = new NextTableRelatedTableFeaturePropertyBuilder(); List<NextTableIds> ids = new ArrayList<>(); while (propertyLength > 0) { NextTableIdsBuilder nextTableIdsBuilder = new NextTableIdsBuilder(); nextTableIdsBuilder.setTableId(input.readUnsignedByte()); ids.add(nextTableIdsBuilder.build()); propertyLength--; } tableBuilder.setNextTableIds(ids); builder.addAugmentation(NextTableRelatedTableFeatureProperty.class, tableBuilder.build()); } else if (type.equals(TableFeaturesPropType.OFPTFPTWRITEACTIONS) || type.equals(TableFeaturesPropType.OFPTFPTWRITEACTIONSMISS) || type.equals(TableFeaturesPropType.OFPTFPTAPPLYACTIONS) || type.equals(TableFeaturesPropType.OFPTFPTAPPLYACTIONSMISS)) { ActionRelatedTableFeaturePropertyBuilder actionBuilder = new ActionRelatedTableFeaturePropertyBuilder(); CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID); List<Action> actions = ListDeserializer.deserializeHeaders(EncodeConstants.OF13_VERSION_ID, propertyLength - COMMON_PROPERTY_LENGTH, input, keyMaker, registry); actionBuilder.setAction(actions); builder.addAugmentation(ActionRelatedTableFeatureProperty.class, actionBuilder.build()); } else if (type.equals(TableFeaturesPropType.OFPTFPTMATCH) || type.equals(TableFeaturesPropType.OFPTFPTWILDCARDS) || type.equals(TableFeaturesPropType.OFPTFPTWRITESETFIELD) || type.equals(TableFeaturesPropType.OFPTFPTWRITESETFIELDMISS) || type.equals(TableFeaturesPropType.OFPTFPTAPPLYSETFIELD) || type.equals(TableFeaturesPropType.OFPTFPTAPPLYSETFIELDMISS)) { OxmRelatedTableFeaturePropertyBuilder oxmBuilder = new OxmRelatedTableFeaturePropertyBuilder(); CodeKeyMaker keyMaker = CodeKeyMakerFactory .createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID); List<MatchEntry> entries = ListDeserializer.deserializeHeaders(EncodeConstants.OF13_VERSION_ID, propertyLength - COMMON_PROPERTY_LENGTH, input, keyMaker, registry); oxmBuilder.setMatchEntry(entries); builder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build()); } else if (type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTER) || type.equals(TableFeaturesPropType.OFPTFPTEXPERIMENTERMISS)) { long expId = input.readUnsignedInt(); input.readerIndex(propStartIndex); OFDeserializer<TableFeatureProperties> propDeserializer = registry .getDeserializer(ExperimenterDeserializerKeyFactory .createMultipartReplyTFDeserializerKey(EncodeConstants.OF13_VERSION_ID, expId)); TableFeatureProperties expProp = propDeserializer.deserialize(input); properties.add(expProp); continue; } if (paddingRemainder != 0) { input.skipBytes(EncodeConstants.PADDING - paddingRemainder); tableFeaturesLength -= EncodeConstants.PADDING - paddingRemainder; } properties.add(builder.build()); } return properties; }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.MultipartRequestInputMessageFactory.java
License:Open Source License
private MultipartRequestFlowCase setFlow(ByteBuf input) { MultipartRequestFlowCaseBuilder caseBuilder = new MultipartRequestFlowCaseBuilder(); MultipartRequestFlowBuilder flowBuilder = new MultipartRequestFlowBuilder(); flowBuilder.setTableId(input.readUnsignedByte()); input.skipBytes(FLOW_PADDING_1); flowBuilder.setOutPort(input.readUnsignedInt()); flowBuilder.setOutGroup(input.readUnsignedInt()); input.skipBytes(FLOW_PADDING_2);/*from ww w. j ava 2 s .c o m*/ byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; input.readBytes(cookie); flowBuilder.setCookie(new BigInteger(1, cookie)); byte[] cookie_mask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; input.readBytes(cookie_mask); flowBuilder.setCookieMask(new BigInteger(1, cookie_mask)); OFDeserializer<Match> matchDeserializer = registry.getDeserializer( new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class)); flowBuilder.setMatch(matchDeserializer.deserialize(input)); caseBuilder.setMultipartRequestFlow(flowBuilder.build()); return caseBuilder.build(); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.MultipartRequestInputMessageFactory.java
License:Open Source License
private MultipartRequestAggregateCase setAggregate(ByteBuf input) { MultipartRequestAggregateCaseBuilder caseBuilder = new MultipartRequestAggregateCaseBuilder(); MultipartRequestAggregateBuilder aggregateBuilder = new MultipartRequestAggregateBuilder(); aggregateBuilder.setTableId(input.readUnsignedByte()); input.skipBytes(AGGREGATE_PADDING_1); aggregateBuilder.setOutPort(input.readUnsignedInt()); aggregateBuilder.setOutGroup(input.readUnsignedInt()); input.skipBytes(AGGREGATE_PADDING_2); byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; input.readBytes(cookie);//from ww w.j a va2 s .c o m aggregateBuilder.setCookie(new BigInteger(1, cookie)); byte[] cookie_mask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; input.readBytes(cookie_mask); aggregateBuilder.setCookieMask(new BigInteger(1, cookie_mask)); OFDeserializer<Match> matchDeserializer = registry.getDeserializer( new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class)); aggregateBuilder.setMatch(matchDeserializer.deserialize(input)); caseBuilder.setMultipartRequestAggregate(aggregateBuilder.build()); return caseBuilder.build(); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.OF10StatsRequestInputFactory.java
License:Open Source License
private MultipartRequestQueueCase setQueue(ByteBuf input) { MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder(); MultipartRequestQueueBuilder queueBuilder = new MultipartRequestQueueBuilder(); queueBuilder.setPortNo((long) input.readUnsignedShort()); input.skipBytes(2); queueBuilder.setQueueId(input.readUnsignedInt()); caseBuilder.setMultipartRequestQueue(queueBuilder.build()); return caseBuilder.build(); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.OF10StatsRequestInputFactory.java
License:Open Source License
private MultipartRequestAggregateCase setAggregate(ByteBuf input) { MultipartRequestAggregateCaseBuilder caseBuilder = new MultipartRequestAggregateCaseBuilder(); MultipartRequestAggregateBuilder aggregateBuilder = new MultipartRequestAggregateBuilder(); OFDeserializer<MatchV10> matchDeserializer = registry.getDeserializer( new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class)); aggregateBuilder.setMatchV10(matchDeserializer.deserialize(input)); aggregateBuilder.setTableId(input.readUnsignedByte()); input.skipBytes(AGGREGATE_PADDING_1); aggregateBuilder.setOutPort((long) input.readUnsignedShort()); caseBuilder.setMultipartRequestAggregate(aggregateBuilder.build()); return caseBuilder.build(); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.OF10StatsRequestInputFactory.java
License:Open Source License
private MultipartRequestFlowCase setFlow(ByteBuf input) { MultipartRequestFlowCaseBuilder caseBuilder = new MultipartRequestFlowCaseBuilder(); MultipartRequestFlowBuilder flowBuilder = new MultipartRequestFlowBuilder(); OFDeserializer<MatchV10> matchDeserializer = registry.getDeserializer( new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class)); flowBuilder.setMatchV10(matchDeserializer.deserialize(input)); flowBuilder.setTableId(input.readUnsignedByte()); input.skipBytes(FLOW_PADDING_1); flowBuilder.setOutPort((long) input.readUnsignedShort()); caseBuilder.setMultipartRequestFlow(flowBuilder.build()); return caseBuilder.build(); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.PacketOutInputMessageFactory.java
License:Open Source License
@Override public PacketOutInput deserialize(ByteBuf rawMessage) { PacketOutInputBuilder builder = new PacketOutInputBuilder(); builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); builder.setBufferId(rawMessage.readUnsignedInt()); builder.setInPort(new PortNumber(rawMessage.readUnsignedInt())); int actions_len = rawMessage.readShort(); rawMessage.skipBytes(PADDING); CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID); List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, actions_len, rawMessage, keyMaker, registry); builder.setAction(actions);//from w w w . j a v a 2 s . co m byte[] data = rawMessage.readBytes(rawMessage.readableBytes()).array(); if (data != null) { builder.setData(data); } return builder.build(); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.PacketOutInputMessageFactoryTest.java
License:Open Source License
@Test public void test() throws Exception { PacketOutInput expectedMessage = createMessage(); SerializerRegistry registry = new SerializerRegistryImpl(); registry.init();//from w w w . j a v a 2 s .c o m NetIdePacketOutInputMessageFactory serializer = new NetIdePacketOutInputMessageFactory(); serializer.injectSerializerRegistry(registry); ByteBuf originalBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.serialize(expectedMessage, originalBuffer); // TODO: Skipping first 4 bytes due to the way deserializer is // implemented // Skipping version, type and length from OF header originalBuffer.skipBytes(4); PacketOutInput deserializedMessage = BufferHelper.deserialize(factory, originalBuffer); Assert.assertEquals("Wrong version", expectedMessage.getVersion(), deserializedMessage.getVersion()); Assert.assertEquals("Wrong XId", expectedMessage.getXid(), deserializedMessage.getXid()); Assert.assertEquals("Wrong buffer Id", expectedMessage.getBufferId(), deserializedMessage.getBufferId()); Assert.assertEquals("Wrong In Port", expectedMessage.getInPort().getValue(), deserializedMessage.getInPort().getValue()); Assert.assertEquals("Wrong Numbers of actions", expectedMessage.getAction().size(), deserializedMessage.getAction().size()); int i = 0; for (Action a : expectedMessage.getAction()) { Assert.assertEquals("Wrong action", a, deserializedMessage.getAction().get(i)); i++; } Assert.assertArrayEquals("Wrong data", expectedMessage.getData(), deserializedMessage.getData()); }