2 * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.impl.protocol.serialization.multipart;
11 import com.google.common.base.MoreObjects;
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector;
16 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.openflowplugin.api.OFConstants;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.multipart.request.multipart.request.body.MultipartRequestFlowStats;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.multipart.request.MultipartRequestBody;
24 public class MultipartRequestFlowStatsSerializer implements OFSerializer<MultipartRequestBody>,
25 SerializerRegistryInjector {
27 private static final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01 = 3;
28 private static final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02 = 4;
29 private SerializerRegistry registry;
32 public void serialize(final MultipartRequestBody multipartRequestBody, final ByteBuf byteBuf) {
33 final MultipartRequestFlowStats multipartRequestFlowStats = MultipartRequestFlowStats
35 .cast(multipartRequestBody);
37 byteBuf.writeByte(MoreObjects.firstNonNull(multipartRequestFlowStats.getTableId(),
38 OFConstants.OFPTT_ALL).byteValue());
39 byteBuf.writeZero(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01);
40 byteBuf.writeInt(MoreObjects.firstNonNull(multipartRequestFlowStats.getOutPort(),
41 OFConstants.OFPP_ANY).intValue());
42 byteBuf.writeInt(MoreObjects.firstNonNull(multipartRequestFlowStats.getOutGroup(),
43 OFConstants.OFPG_ANY).intValue());
44 byteBuf.writeZero(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02);
45 byteBuf.writeLong(MoreObjects.firstNonNull(multipartRequestFlowStats.getCookie(),
46 new FlowCookie(OFConstants.DEFAULT_COOKIE)).getValue().longValue());
47 byteBuf.writeLong(MoreObjects.firstNonNull(multipartRequestFlowStats.getCookieMask(),
48 new FlowCookie(OFConstants.DEFAULT_COOKIE_MASK)).getValue().longValue());
50 registry.<Match, OFSerializer<Match>>getSerializer(
51 new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Match.class))
52 .serialize(multipartRequestFlowStats.getMatch(), byteBuf);
56 public void injectSerializerRegistry(final SerializerRegistry serializerRegistry) {
57 registry = serializerRegistry;