List of usage examples for io.netty.buffer ByteBuf setShort
public abstract ByteBuf setShort(int index, int value);
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.action.OF13SetFieldActionSerializer.java
License:Open Source License
@Override public void serialize(Action action, ByteBuf outBuffer) { int startIndex = outBuffer.writerIndex(); outBuffer.writeShort(ActionConstants.SET_FIELD_CODE); int lengthIndex = outBuffer.writerIndex(); outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH); MatchEntry entry = ((SetFieldCase) action.getActionChoice()).getSetFieldAction().getMatchEntry().get(0); MatchEntrySerializerKey<?, ?> key = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, entry.getOxmClass(), entry.getOxmMatchField()); if (entry.getOxmClass().equals(ExperimenterClass.class)) { ExperimenterIdCase experimenterIdCase = (ExperimenterIdCase) entry.getMatchEntryValue(); key.setExperimenterId(experimenterIdCase.getExperimenter().getExperimenter().getValue()); } else {// w w w . ja v a 2 s . c om key.setExperimenterId(null); } OFSerializer<MatchEntry> serializer = registry.getSerializer(key); serializer.serialize(entry, outBuffer); int paddingRemainder = (outBuffer.writerIndex() - startIndex) % EncodeConstants.PADDING; if (paddingRemainder != 0) { outBuffer.writeZero(EncodeConstants.PADDING - paddingRemainder); } outBuffer.setShort(lengthIndex, outBuffer.writerIndex() - startIndex); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.experimenter.AbstractBundleMessageFactory.java
License:Open Source License
protected void writeBundleProperties(final List<BundleProperty> properties, final ByteBuf outBuffer) { for (BundleProperty property : properties) { BundlePropertyType type = property.getType(); if (type != null && type.equals(BundlePropertyType.ONFETBPTEXPERIMENTER)) { int startIndex = outBuffer.writerIndex(); outBuffer.writeShort(type.getIntValue()); int lengthIndex = outBuffer.writerIndex(); outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH); writeBundleExperimenterProperty(property, outBuffer); outBuffer.setShort(lengthIndex, outBuffer.writerIndex() - startIndex); } else {/*from w w w . j a va 2 s . c om*/ LOG.warn("lTrying to serialize unknown bundle property (type: {}), skipping", type.getIntValue()); } } }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.experimenters.OF10VendorActionSerializer.java
License:Open Source License
@Override public void serialize(Action action, ByteBuf outBuffer) { int startIndex = outBuffer.writerIndex(); outBuffer.writeShort(EncodeConstants.EXPERIMENTER_VALUE); int lengthIndex = outBuffer.writerIndex(); outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH); ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class); outBuffer.writeInt(experimenter.getExperimenter().intValue()); byte[] data = experimenter.getData(); if (data != null) { outBuffer.writeBytes(data);//from ww w .ja va 2s .c om } outBuffer.setShort(lengthIndex, outBuffer.writerIndex() - startIndex); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.experimenters.OF13ExperimenterActionSerializer.java
License:Open Source License
@Override public void serialize(Action action, ByteBuf outBuffer) { int actionStartIndex = outBuffer.writerIndex(); outBuffer.writeShort(EncodeConstants.EXPERIMENTER_VALUE); int actionLengthIndex = outBuffer.writerIndex(); outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH); ExperimenterAction expAction = action.getAugmentation(ExperimenterAction.class); outBuffer.writeInt(expAction.getExperimenter().intValue()); if (expAction.getData() != null) { outBuffer.writeBytes(expAction.getData()); }//from ww w .j a v a 2 s . co m outBuffer.setShort(actionLengthIndex, outBuffer.writerIndex() - actionStartIndex); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.experimenters.OF13ExperimenterInstructionSerializer.java
License:Open Source License
@Override public void serialize(Instruction instruction, ByteBuf outBuffer) { int startIndex = outBuffer.writerIndex(); outBuffer.writeShort(EncodeConstants.EXPERIMENTER_VALUE); int lengthIndex = outBuffer.writerIndex(); outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH); ExperimenterInstruction experimenter = instruction.getAugmentation(ExperimenterInstruction.class); outBuffer.writeInt(experimenter.getExperimenter().intValue()); if (experimenter.getData() != null) { outBuffer.writeBytes(experimenter.getData()); }/* ww w. j a va 2s . com*/ outBuffer.setShort(lengthIndex, outBuffer.writerIndex() - startIndex); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.experimenters.OF13MeterBandExperimenterSerializer.java
License:Open Source License
@Override public void serialize(MeterBandExperimenter meterBand, ByteBuf outBuffer) { int startIndex = outBuffer.writerIndex(); outBuffer.writeShort(meterBand.getType().getIntValue()); int lengthIndex = outBuffer.writerIndex(); outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH); outBuffer.writeInt(meterBand.getRate().intValue()); outBuffer.writeInt(meterBand.getBurstSize().intValue()); outBuffer.writeInt(meterBand.getExperimenter().intValue()); if (meterBand.getData() != null) { outBuffer.writeBytes(meterBand.getData()); }//from ww w. j av a2 s .c o m outBuffer.setShort(lengthIndex, outBuffer.writerIndex() - startIndex); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.experimenters.OF13TableFeatExpSerializer.java
License:Open Source License
@Override public void serialize(TableFeatureProperties property, ByteBuf outBuffer) { int startIndex = outBuffer.writerIndex(); if (property.getType().equals(TableFeaturesPropType.OFPTFPTEXPERIMENTER)) { outBuffer.writeShort(EXPERIMENTER_CODE); } else {/* ww w . j a va 2 s .co m*/ outBuffer.writeShort(EXPERIMENTER_MISS_CODE); } int lengthIndex = outBuffer.writerIndex(); outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH); ExperimenterRelatedTableFeatureProperty exp = property .getAugmentation(ExperimenterRelatedTableFeatureProperty.class); outBuffer.writeInt(exp.getExperimenter().intValue()); outBuffer.writeInt(exp.getExpType().intValue()); byte[] data = exp.getData(); if (data != null) { outBuffer.writeBytes(data); } int paddingRemainder = (outBuffer.writerIndex() - startIndex) % EncodeConstants.PADDING; if (paddingRemainder != 0) { int padding = EncodeConstants.PADDING - paddingRemainder; ByteBufUtils.padBuffer(padding, outBuffer); } outBuffer.setShort(lengthIndex, outBuffer.writerIndex() - startIndex); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactory.java
License:Open Source License
private void serializeTableFeaturesBody(final MultipartReplyBody body, final ByteBuf outBuffer) { MultipartReplyTableFeaturesCase tableFeaturesCase = (MultipartReplyTableFeaturesCase) body; MultipartReplyTableFeatures tableFeatures = tableFeaturesCase.getMultipartReplyTableFeatures(); for (TableFeatures tableFeature : tableFeatures.getTableFeatures()) { ByteBuf tableFeatureBuff = UnpooledByteBufAllocator.DEFAULT.buffer(); tableFeatureBuff.writeShort(EncodeConstants.EMPTY_LENGTH); tableFeatureBuff.writeByte(tableFeature.getTableId()); tableFeatureBuff.writeZero(TABLE_FEATURES_PADDING); write32String(tableFeature.getName(), tableFeatureBuff); tableFeatureBuff.writeBytes(tableFeature.getMetadataMatch()); tableFeatureBuff.writeZero(64 - tableFeature.getMetadataMatch().length); tableFeatureBuff.writeBytes(tableFeature.getMetadataWrite()); tableFeatureBuff.writeZero(64 - tableFeature.getMetadataWrite().length); writeTableConfig(tableFeature.getConfig(), tableFeatureBuff); tableFeatureBuff.writeInt(tableFeature.getMaxEntries().intValue()); for (TableFeatureProperties tableFeatureProp : tableFeature.getTableFeatureProperties()) { switch (tableFeatureProp.getType()) { case OFPTFPTINSTRUCTIONS: writeInstructionRelatedTableProperty(tableFeatureBuff, tableFeatureProp, INSTRUCTIONS_CODE); break; case OFPTFPTINSTRUCTIONSMISS: writeInstructionRelatedTableProperty(tableFeatureBuff, tableFeatureProp, INSTRUCTIONS_MISS_CODE); break; case OFPTFPTNEXTTABLES: writeNextTableRelatedTableProperty(tableFeatureBuff, tableFeatureProp, NEXT_TABLE_CODE); break; case OFPTFPTNEXTTABLESMISS: writeNextTableRelatedTableProperty(tableFeatureBuff, tableFeatureProp, NEXT_TABLE_MISS_CODE); break; case OFPTFPTWRITEACTIONS: writeActionsRelatedTableProperty(tableFeatureBuff, tableFeatureProp, WRITE_ACTIONS_CODE); break; case OFPTFPTWRITEACTIONSMISS: writeActionsRelatedTableProperty(tableFeatureBuff, tableFeatureProp, WRITE_ACTIONS_MISS_CODE); break; case OFPTFPTAPPLYACTIONS: writeActionsRelatedTableProperty(tableFeatureBuff, tableFeatureProp, APPLY_ACTIONS_CODE); break; case OFPTFPTAPPLYACTIONSMISS: writeActionsRelatedTableProperty(tableFeatureBuff, tableFeatureProp, APPLY_ACTIONS_MISS_CODE); break; case OFPTFPTMATCH: writeOxmRelatedTableProperty(tableFeatureBuff, tableFeatureProp, MATCH_CODE); break; case OFPTFPTWILDCARDS: writeOxmRelatedTableProperty(tableFeatureBuff, tableFeatureProp, WILDCARDS_CODE); break; case OFPTFPTWRITESETFIELD: writeOxmRelatedTableProperty(tableFeatureBuff, tableFeatureProp, WRITE_SETFIELD_CODE); break; case OFPTFPTWRITESETFIELDMISS: writeOxmRelatedTableProperty(tableFeatureBuff, tableFeatureProp, WRITE_SETFIELD_MISS_CODE); break; case OFPTFPTAPPLYSETFIELD: writeOxmRelatedTableProperty(tableFeatureBuff, tableFeatureProp, APPLY_SETFIELD_CODE); break; case OFPTFPTAPPLYSETFIELDMISS: writeOxmRelatedTableProperty(tableFeatureBuff, tableFeatureProp, APPLY_SETFIELD_MISS_CODE); break; case OFPTFPTEXPERIMENTER: writeExperimenterRelatedTableProperty(tableFeatureBuff, tableFeatureProp); break; case OFPTFPTEXPERIMENTERMISS: writeExperimenterRelatedTableProperty(tableFeatureBuff, tableFeatureProp); break; }// w w w. j a v a2 s . c o m } tableFeatureBuff.setShort(TABLE_FEATURES_LENGTH_INDEX, tableFeatureBuff.readableBytes()); outBuffer.writeBytes(tableFeatureBuff); } }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactory.java
License:Open Source License
private void serializeMeterConfigBody(final MultipartReplyBody body, final ByteBuf outBuffer) { MultipartReplyMeterConfigCase meterConfigCase = (MultipartReplyMeterConfigCase) body; MultipartReplyMeterConfig meter = meterConfigCase.getMultipartReplyMeterConfig(); for (MeterConfig meterConfig : meter.getMeterConfig()) { ByteBuf meterConfigBuff = UnpooledByteBufAllocator.DEFAULT.buffer(); meterConfigBuff.writeShort(EncodeConstants.EMPTY_LENGTH); writeMeterFlags(meterConfig.getFlags(), meterConfigBuff); meterConfigBuff.writeInt(meterConfig.getMeterId().getValue().intValue()); for (Bands currentBand : meterConfig.getBands()) { MeterBand meterBand = currentBand.getMeterBand(); if (meterBand instanceof MeterBandDropCase) { MeterBandDropCase dropBandCase = (MeterBandDropCase) meterBand; MeterBandDrop dropBand = dropBandCase.getMeterBandDrop(); writeBandCommonFields(dropBand, meterConfigBuff); } else if (meterBand instanceof MeterBandDscpRemarkCase) { MeterBandDscpRemarkCase dscpRemarkBandCase = (MeterBandDscpRemarkCase) meterBand; MeterBandDscpRemark dscpRemarkBand = dscpRemarkBandCase.getMeterBandDscpRemark(); writeBandCommonFields(dscpRemarkBand, meterConfigBuff); } else if (meterBand instanceof MeterBandExperimenterCase) { MeterBandExperimenterCase experimenterBandCase = (MeterBandExperimenterCase) meterBand; MeterBandExperimenter experimenterBand = experimenterBandCase.getMeterBandExperimenter(); writeBandCommonFields(experimenterBand, meterConfigBuff); }//from w w w .j a v a 2s. com } meterConfigBuff.setShort(METER_CONFIG_LENGTH_INDEX, meterConfigBuff.readableBytes()); outBuffer.writeBytes(meterConfigBuff); } }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactory.java
License:Open Source License
private void serializeGroupDescBody(final MultipartReplyBody body, final ByteBuf outBuffer, final MultipartReplyMessage message) { MultipartReplyGroupDescCase groupDescCase = (MultipartReplyGroupDescCase) body; MultipartReplyGroupDesc group = groupDescCase.getMultipartReplyGroupDesc(); for (GroupDesc groupDesc : group.getGroupDesc()) { ByteBuf groupDescBuff = UnpooledByteBufAllocator.DEFAULT.buffer(); groupDescBuff.writeShort(EncodeConstants.EMPTY_LENGTH); groupDescBuff.writeByte(groupDesc.getType().getIntValue()); groupDescBuff.writeZero(GROUP_DESC_PADDING); groupDescBuff.writeInt(groupDesc.getGroupId().getValue().intValue()); for (BucketsList bucket : groupDesc.getBucketsList()) { ByteBuf bucketBuff = UnpooledByteBufAllocator.DEFAULT.buffer(); bucketBuff.writeShort(EncodeConstants.EMPTY_LENGTH); bucketBuff.writeShort(bucket.getWeight()); bucketBuff.writeInt(bucket.getWatchPort().getValue().intValue()); bucketBuff.writeInt(bucket.getWatchGroup().intValue()); bucketBuff.writeZero(BUCKET_PADDING); ListSerializer.serializeList(bucket.getAction(), TypeKeyMakerFactory.createActionKeyMaker(message.getVersion()), registry, bucketBuff); bucketBuff.setShort(BUCKET_LENGTH_INDEX, bucketBuff.readableBytes()); groupDescBuff.writeBytes(bucketBuff); }/*from ww w. j a v a2s .co m*/ groupDescBuff.setShort(GROUP_DESC_LENGTH_INDEX, groupDescBuff.readableBytes()); outBuffer.writeBytes(groupDescBuff); } }