List of usage examples for io.netty.buffer ByteBuf readUnsignedShort
public abstract int readUnsignedShort();
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.MeterModInputMessageFactory.java
License:Open Source License
@Override public MeterModInput deserialize(ByteBuf rawMessage) { MeterModInputBuilder builder = new MeterModInputBuilder(); builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); builder.setCommand(MeterModCommand.forValue(rawMessage.readUnsignedShort())); builder.setFlags(createMeterFlags(rawMessage.readUnsignedShort())); builder.setMeterId(new MeterId(rawMessage.readUnsignedInt())); List<Bands> bandsList = new ArrayList<>(); while (rawMessage.readableBytes() > 0) { BandsBuilder bandsBuilder = new BandsBuilder(); int bandStartIndex = rawMessage.readerIndex(); int bandType = rawMessage.readUnsignedShort(); switch (bandType) { case 1:// w w w. java 2 s .c om MeterBandDropCaseBuilder bandDropCaseBuilder = new MeterBandDropCaseBuilder(); MeterBandDropBuilder bandDropBuilder = new MeterBandDropBuilder(); bandDropBuilder.setType(MeterBandType.forValue(bandType)); rawMessage.readUnsignedShort(); bandDropBuilder.setRate(rawMessage.readUnsignedInt()); bandDropBuilder.setBurstSize(rawMessage.readUnsignedInt()); rawMessage.skipBytes(PADDING_IN_METER_BAND_DROP_HEADER); bandDropCaseBuilder.setMeterBandDrop(bandDropBuilder.build()); bandsBuilder.setMeterBand(bandDropCaseBuilder.build()); break; case 2: MeterBandDscpRemarkCaseBuilder bandDscpRemarkCaseBuilder = new MeterBandDscpRemarkCaseBuilder(); MeterBandDscpRemarkBuilder bandDscpRemarkBuilder = new MeterBandDscpRemarkBuilder(); bandDscpRemarkBuilder.setType(MeterBandType.forValue(bandType)); rawMessage.readUnsignedShort(); bandDscpRemarkBuilder.setRate(rawMessage.readUnsignedInt()); bandDscpRemarkBuilder.setBurstSize(rawMessage.readUnsignedInt()); bandDscpRemarkBuilder.setPrecLevel(rawMessage.readUnsignedByte()); rawMessage.skipBytes(PADDING_IN_METER_BAND_DSCP_HEADER); bandDscpRemarkCaseBuilder.setMeterBandDscpRemark(bandDscpRemarkBuilder.build()); bandsBuilder.setMeterBand(bandDscpRemarkCaseBuilder.build()); break; case 0xFFFF: long expId = rawMessage .getUnsignedInt(rawMessage.readerIndex() + 2 * EncodeConstants.SIZE_OF_INT_IN_BYTES); rawMessage.readerIndex(bandStartIndex); OFDeserializer<MeterBandExperimenterCase> deserializer = registry .getDeserializer(ExperimenterDeserializerKeyFactory .createMeterBandDeserializerKey(EncodeConstants.OF13_VERSION_ID, expId)); bandsBuilder.setMeterBand(deserializer.deserialize(rawMessage)); break; } bandsList.add(bandsBuilder.build()); } builder.setBands(bandsList); return builder.build(); }
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);//from w w w .j a v a2s. c om switch (MultipartType.forValue(type)) { case OFPMPDESC: builder.setMultipartRequestBody(setDesc(rawMessage)); break; 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 w w w .j a v a 2 s.co 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);// w ww .j av a2 s. co m 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.OF10FlowModInputMessageFactory.java
License:Open Source License
@Override public FlowModInput deserialize(ByteBuf rawMessage) { FlowModInputBuilder builder = new FlowModInputBuilder(); builder.setVersion((short) EncodeConstants.OF10_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); OFDeserializer<MatchV10> matchDeserializer = registry.getDeserializer( new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class)); builder.setMatchV10(matchDeserializer.deserialize(rawMessage)); byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; rawMessage.readBytes(cookie);/*w ww . jav a 2 s .co m*/ builder.setCookie(new BigInteger(1, cookie)); builder.setCommand(FlowModCommand.forValue(rawMessage.readUnsignedShort())); builder.setIdleTimeout(rawMessage.readUnsignedShort()); builder.setHardTimeout(rawMessage.readUnsignedShort()); builder.setPriority(rawMessage.readUnsignedShort()); builder.setBufferId(rawMessage.readUnsignedInt()); builder.setOutPort(new PortNumber((long) rawMessage.readUnsignedShort())); builder.setFlagsV10(createFlowModFlagsFromBitmap(rawMessage.readUnsignedShort())); CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF10_VERSION_ID); List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF10_VERSION_ID, rawMessage.readableBytes(), rawMessage, keyMaker, registry); builder.setAction(actions); return builder.build(); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.OF10GetQueueConfigInputMessageFactory.java
License:Open Source License
@Override public GetQueueConfigInput deserialize(ByteBuf rawMessage) { GetQueueConfigInputBuilder builder = new GetQueueConfigInputBuilder(); builder.setVersion((short) EncodeConstants.OF10_VERSION_ID); builder.setXid((rawMessage.readUnsignedInt())); builder.setPort(new PortNumber((long) rawMessage.readUnsignedShort())); return builder.build(); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.OF10PacketOutInputMessageFactory.java
License:Open Source License
@Override public PacketOutInput deserialize(ByteBuf rawMessage) { PacketOutInputBuilder builder = new PacketOutInputBuilder(); builder.setVersion((short) EncodeConstants.OF10_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); builder.setBufferId(rawMessage.readUnsignedInt()); builder.setInPort(new PortNumber((long) rawMessage.readUnsignedShort())); int actions_len = rawMessage.readShort(); CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF10_VERSION_ID); List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF10_VERSION_ID, actions_len, rawMessage, keyMaker, registry); builder.setAction(actions);// w w w. ja v a 2s .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.OF10PortModInputMessageFactory.java
License:Open Source License
@Override public PortModInput deserialize(ByteBuf rawMessage) { PortModInputBuilder builder = new PortModInputBuilder(); builder.setVersion((short) EncodeConstants.OF10_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); builder.setPortNo(new PortNumber((long) rawMessage.readUnsignedShort())); byte[] hwAddress = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; rawMessage.readBytes(hwAddress);/*from w ww .jav a 2 s .c o m*/ builder.setHwAddress(new MacAddress(ByteBufUtils.macAddressToString(hwAddress))); builder.setConfigV10(createPortConfig(rawMessage.readUnsignedInt())); builder.setMaskV10(createPortConfig(rawMessage.readUnsignedInt())); builder.setAdvertiseV10(createPortFeatures(rawMessage.readUnsignedInt())); return builder.build(); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.OF10SetConfigMessageFactory.java
License:Open Source License
@Override public SetConfigInput deserialize(ByteBuf rawMessage) { SetConfigInputBuilder builder = new SetConfigInputBuilder(); builder.setVersion((short) EncodeConstants.OF10_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); builder.setFlags(SwitchConfigFlag.forValue(rawMessage.readUnsignedShort())); builder.setMissSendLen(rawMessage.readUnsignedShort()); return builder.build(); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.OF10StatsRequestInputFactory.java
License:Open Source License
@Override public MultipartRequestInput deserialize(ByteBuf rawMessage) { MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); builder.setVersion((short) EncodeConstants.OF10_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); int type = rawMessage.readUnsignedShort(); builder.setType(getMultipartType(type)); builder.setFlags(getMultipartRequestFlags(rawMessage.readUnsignedShort())); switch (getMultipartType(type)) { case OFPMPDESC: builder.setMultipartRequestBody(setDesc(rawMessage)); break;/* ww w .j a v a 2s. c om*/ case OFPMPFLOW: builder.setMultipartRequestBody(setFlow(rawMessage)); break; case OFPMPAGGREGATE: builder.setMultipartRequestBody(setAggregate(rawMessage)); break; case OFPMPTABLE: builder.setMultipartRequestBody(setTable(rawMessage)); break; case OFPMPPORTSTATS: builder.setMultipartRequestBody(setPortStats(rawMessage)); break; case OFPMPQUEUE: builder.setMultipartRequestBody(setQueue(rawMessage)); break; case OFPMPEXPERIMENTER: builder.setMultipartRequestBody(setExperimenter(rawMessage)); break; default: break; } return builder.build(); }