Search in sources :

Example 1 with OFSerializer

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);
    }
}
Also used : FlowStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats) OFSerializer(org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer) MultipartReplyFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow) MultipartReplyFlowCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase) ByteBuf(io.netty.buffer.ByteBuf) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match)

Example 2 with OFSerializer

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);
                }
            }
        })));
    }
}
Also used : SerializerRegistry(org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry) OFSerializer(org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer) Logger(org.slf4j.Logger) ExperimenterIdSerializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdSerializerKey) MeterMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterMessage) DscpRemark(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemark) MeterBandHeaders(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.MeterBandHeaders) LoggerFactory(org.slf4j.LoggerFactory) MoreObjects(com.google.common.base.MoreObjects) MeterFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterFlags) MeterBandType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandType) SerializerRegistryInjector(org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector) Drop(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Drop) Experimenter(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Experimenter) Objects(java.util.Objects) ByteBuf(io.netty.buffer.ByteBuf) EncodeConstants(org.opendaylight.openflowjava.protocol.api.util.EncodeConstants) Optional(java.util.Optional) ByteBufUtils(org.opendaylight.openflowjava.util.ByteBufUtils) DscpRemark(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemark) Experimenter(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Experimenter) ExperimenterIdSerializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdSerializerKey) Drop(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Drop)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)2 OFSerializer (org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer)2 MoreObjects (com.google.common.base.MoreObjects)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 SerializerRegistry (org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry)1 SerializerRegistryInjector (org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector)1 ExperimenterIdSerializerKey (org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdSerializerKey)1 EncodeConstants (org.opendaylight.openflowjava.protocol.api.util.EncodeConstants)1 ByteBufUtils (org.opendaylight.openflowjava.util.ByteBufUtils)1 MeterFlags (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterFlags)1 MeterMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterMessage)1 Drop (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Drop)1 DscpRemark (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemark)1 Experimenter (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Experimenter)1 MeterBandHeaders (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.MeterBandHeaders)1 MeterBandType (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandType)1 Match (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match)1 MultipartReplyFlowCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase)1 MultipartReplyFlow (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow)1