use of org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactory method serializeFlowBody.
private void serializeFlowBody(final MultipartReplyBody body, final ByteBuf outBuffer, final MultipartReplyMessage message) {
MultipartReplyFlowCase flowCase = (MultipartReplyFlowCase) body;
MultipartReplyFlow flow = flowCase.getMultipartReplyFlow();
for (FlowStats flowStats : flow.getFlowStats()) {
ByteBuf flowStatsBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
flowStatsBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
flowStatsBuff.writeByte((byte) flowStats.getTableId().longValue());
flowStatsBuff.writeZero(FLOW_STATS_PADDING_1);
flowStatsBuff.writeInt(flowStats.getDurationSec().intValue());
flowStatsBuff.writeInt(flowStats.getDurationNsec().intValue());
flowStatsBuff.writeShort(flowStats.getPriority());
flowStatsBuff.writeShort(flowStats.getIdleTimeout());
flowStatsBuff.writeShort(flowStats.getHardTimeout());
flowStatsBuff.writeZero(FLOW_STATS_PADDING_2);
flowStatsBuff.writeLong(flowStats.getCookie().longValue());
flowStatsBuff.writeLong(flowStats.getPacketCount().longValue());
flowStatsBuff.writeLong(flowStats.getByteCount().longValue());
OFSerializer<Match> matchSerializer = registry.<Match, OFSerializer<Match>>getSerializer(new MessageTypeKey<>(message.getVersion(), Match.class));
matchSerializer.serialize(flowStats.getMatch(), flowStatsBuff);
ListSerializer.serializeList(flowStats.getInstruction(), TypeKeyMakerFactory.createInstructionKeyMaker(message.getVersion()), registry, flowStatsBuff);
flowStatsBuff.setShort(FLOW_STATS_LENGTH_INDEX, flowStatsBuff.readableBytes());
outBuffer.writeBytes(flowStatsBuff);
}
}
use of org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer in project openflowplugin by opendaylight.
the class MeterMessageSerializer method serializeBands.
private void serializeBands(final MeterBandHeaders meterBandHeaders, final ByteBuf outBuffer) {
if (Objects.nonNull(meterBandHeaders) && Objects.nonNull(meterBandHeaders.getMeterBandHeader())) {
meterBandHeaders.getMeterBandHeader().forEach(meterBandHeader -> Optional.ofNullable(meterBandHeader.getMeterBandTypes()).flatMap(m -> Optional.ofNullable(m.getFlags())).ifPresent(flags -> Optional.ofNullable(meterBandHeader.getBandType()).ifPresent(type -> {
if (flags.isOfpmbtDrop()) {
final Drop band = Drop.class.cast(type);
outBuffer.writeShort(MeterBandType.OFPMBTDROP.getIntValue());
outBuffer.writeShort(LENGTH_OF_METER_BANDS);
outBuffer.writeInt(band.getDropRate().intValue());
outBuffer.writeInt(band.getDropBurstSize().intValue());
outBuffer.writeZero(PADDING_IN_METER_BAND_DROP);
} else if (flags.isOfpmbtDscpRemark()) {
final DscpRemark band = DscpRemark.class.cast(type);
outBuffer.writeShort(MeterBandType.OFPMBTDSCPREMARK.getIntValue());
outBuffer.writeShort(LENGTH_OF_METER_BANDS);
outBuffer.writeInt(band.getDscpRemarkRate().intValue());
outBuffer.writeInt(band.getDscpRemarkBurstSize().intValue());
outBuffer.writeByte(band.getPrecLevel());
outBuffer.writeZero(PADDING_IN_METER_BAND_DSCP_REMARK);
} else if (flags.isOfpmbtExperimenter()) {
final Experimenter band = Experimenter.class.cast(type);
// TODO: finish experimenter serialization
final ExperimenterIdSerializerKey<Experimenter> key = new ExperimenterIdSerializerKey<>(EncodeConstants.OF13_VERSION_ID, band.getExperimenter(), (Class<Experimenter>) type.getImplementedInterface());
try {
final OFSerializer<Experimenter> serializer = registry.getSerializer(key);
serializer.serialize(band, outBuffer);
} catch (final IllegalStateException e) {
LOG.warn("Serializer for key: {} wasn't found, exception {}", key, e);
}
}
})));
}
}
Aggregations