List of usage examples for io.netty.buffer ByteBuf writeZero
public abstract ByteBuf writeZero(int length);
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 . j a va 2 s .c o m 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.action.OF13SetMplsTtlActionSerializer.java
License:Open Source License
@Override public void serialize(Action action, ByteBuf outBuffer) { super.serialize(action, outBuffer); outBuffer.writeByte(((SetMplsTtlCase) action.getActionChoice()).getSetMplsTtlAction().getMplsTtl()); outBuffer.writeZero(ActionConstants.SET_MPLS_TTL_PADDING); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.action.OF13SetNwTtlActionSerializer.java
License:Open Source License
@Override public void serialize(Action action, ByteBuf outBuffer) { super.serialize(action, outBuffer); outBuffer.writeByte(((SetNwTtlCase) action.getActionChoice()).getSetNwTtlAction().getNwTtl()); outBuffer.writeZero(ActionConstants.SET_NW_TTL_PADDING); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.experimenter.BundleAddMessageFactory.java
License:Open Source License
@Override public void serialize(BundleAddMessage input, ByteBuf outBuffer) { outBuffer.writeInt(input.getBundleId().getValue().intValue()); outBuffer.writeZero(2); writeBundleFlags(input.getFlags(), outBuffer); int msgStart = outBuffer.writerIndex(); serializeInnerMessage(input.getMessage(), outBuffer, input.getMessage().getImplementedInterface()); int msgLength = outBuffer.writerIndex() - msgStart; List<BundleProperty> bundleProperties = input.getBundleProperty(); if (bundleProperties != null && !bundleProperties.isEmpty()) { outBuffer.writeZero(paddingNeeded(msgLength)); writeBundleProperties(input.getBundleProperty(), outBuffer); }/*from w ww.j a v a 2s . c om*/ }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactory.java
License:Open Source License
@Override public void serialize(final MultipartReplyMessage message, final ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeShort(message.getType().getIntValue()); writeFlags(message.getFlags(), outBuffer); outBuffer.writeZero(PADDING); switch (message.getType()) { case OFPMPDESC: serializeDescBody(message.getMultipartReplyBody(), outBuffer); break;/* www. j a va 2 s.c o m*/ case OFPMPFLOW: serializeFlowBody(message.getMultipartReplyBody(), outBuffer, message); break; case OFPMPAGGREGATE: serializeAggregateBody(message.getMultipartReplyBody(), outBuffer); break; case OFPMPTABLE: serializeTableBody(message.getMultipartReplyBody(), outBuffer); break; case OFPMPPORTSTATS: serializePortStatsBody(message.getMultipartReplyBody(), outBuffer); break; case OFPMPQUEUE: serializeQueueBody(message.getMultipartReplyBody(), outBuffer); break; case OFPMPGROUP: serializeGroupBody(message.getMultipartReplyBody(), outBuffer); break; case OFPMPGROUPDESC: serializeGroupDescBody(message.getMultipartReplyBody(), outBuffer, message); break; case OFPMPGROUPFEATURES: serializeGroupFeaturesBody(message.getMultipartReplyBody(), outBuffer); break; case OFPMPMETER: serializeMeterBody(message.getMultipartReplyBody(), outBuffer); break; case OFPMPMETERCONFIG: serializeMeterConfigBody(message.getMultipartReplyBody(), outBuffer); break; case OFPMPMETERFEATURES: serializeMeterFeaturesBody(message.getMultipartReplyBody(), outBuffer); break; case OFPMPTABLEFEATURES: serializeTableFeaturesBody(message.getMultipartReplyBody(), outBuffer); break; case OFPMPPORTDESC: serializePortDescBody(message.getMultipartReplyBody(), outBuffer); break; case OFPMPEXPERIMENTER: serializeExperimenterBody(message.getMultipartReplyBody(), outBuffer); break; } ByteBufUtils.updateOFHeaderLength(outBuffer); }
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 av a2 s . c om } 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 serializeMeterFeaturesBody(final MultipartReplyBody body, final ByteBuf outBuffer) { MultipartReplyMeterFeaturesCase meterFeaturesCase = (MultipartReplyMeterFeaturesCase) body; MultipartReplyMeterFeatures meterFeatures = meterFeaturesCase.getMultipartReplyMeterFeatures(); outBuffer.writeInt(meterFeatures.getMaxMeter().intValue()); writeBandTypes(meterFeatures.getBandTypes(), outBuffer); writeMeterFlags(meterFeatures.getCapabilities(), outBuffer); outBuffer.writeByte(meterFeatures.getMaxBands()); outBuffer.writeByte(meterFeatures.getMaxColor()); outBuffer.writeZero(METER_FEATURES_PADDING); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactory.java
License:Open Source License
private void serializeMeterBody(final MultipartReplyBody body, final ByteBuf outBuffer) { MultipartReplyMeterCase meterCase = (MultipartReplyMeterCase) body; MultipartReplyMeter meter = meterCase.getMultipartReplyMeter(); for (MeterStats meterStats : meter.getMeterStats()) { ByteBuf meterStatsBuff = UnpooledByteBufAllocator.DEFAULT.buffer(); meterStatsBuff.writeInt(meterStats.getMeterId().getValue().intValue()); meterStatsBuff.writeInt(EncodeConstants.EMPTY_LENGTH); meterStatsBuff.writeZero(METER_PADDING); meterStatsBuff.writeInt(meterStats.getFlowCount().intValue()); meterStatsBuff.writeLong(meterStats.getPacketInCount().longValue()); meterStatsBuff.writeLong(meterStats.getByteInCount().longValue()); meterStatsBuff.writeInt(meterStats.getDurationSec().intValue()); meterStatsBuff.writeInt(meterStats.getDurationNsec().intValue()); for (MeterBandStats meterBandStats : meterStats.getMeterBandStats()) { meterStatsBuff.writeLong(meterBandStats.getPacketBandCount().longValue()); meterStatsBuff.writeLong(meterBandStats.getByteBandCount().longValue()); }// ww w. j a v a 2 s .com meterStatsBuff.setInt(METER_LENGTH_INDEX, meterStatsBuff.readableBytes()); outBuffer.writeBytes(meterStatsBuff); } }
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 w ww .j av a 2 s. c o m groupDescBuff.setShort(GROUP_DESC_LENGTH_INDEX, groupDescBuff.readableBytes()); outBuffer.writeBytes(groupDescBuff); } }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactory.java
License:Open Source License
private void serializeGroupBody(final MultipartReplyBody body, final ByteBuf outBuffer) { MultipartReplyGroupCase groupCase = (MultipartReplyGroupCase) body; MultipartReplyGroup group = groupCase.getMultipartReplyGroup(); for (GroupStats groupStats : group.getGroupStats()) { ByteBuf groupStatsBuff = UnpooledByteBufAllocator.DEFAULT.buffer(); groupStatsBuff.writeShort(EncodeConstants.EMPTY_LENGTH); groupStatsBuff.writeZero(GROUP_STATS_PADDING_1); groupStatsBuff.writeInt(groupStats.getGroupId().getValue().intValue()); groupStatsBuff.writeInt(groupStats.getRefCount().intValue()); groupStatsBuff.writeZero(GROUP_STATS_PADDING_2); groupStatsBuff.writeLong(groupStats.getPacketCount().longValue()); groupStatsBuff.writeLong(groupStats.getByteCount().longValue()); groupStatsBuff.writeInt(groupStats.getDurationSec().intValue()); groupStatsBuff.writeInt(groupStats.getDurationNsec().intValue()); for (BucketStats bucketStats : groupStats.getBucketStats()) { groupStatsBuff.writeLong(bucketStats.getPacketCount().longValue()); groupStatsBuff.writeLong(bucketStats.getByteCount().longValue()); }/*from w w w . j a va2 s .c o m*/ groupStatsBuff.setShort(GROUP_STATS_LENGTH_INDEX, groupStatsBuff.readableBytes()); outBuffer.writeBytes(groupStatsBuff); } }