Add multipart request message serializers
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / serialization / multipart / MultipartRequestQueueStatsSerializer.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowplugin.impl.protocol.serialization.multipart;
10
11 import com.google.common.base.MoreObjects;
12 import io.netty.buffer.ByteBuf;
13 import java.util.Objects;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
15 import org.opendaylight.openflowplugin.api.OFConstants;
16 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
17 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.queue.rev130925.QueueId;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.multipart.request.MultipartRequestBody;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.multipart.request.multipart.request.body.MultipartRequestQueueStats;
21
22 public class MultipartRequestQueueStatsSerializer implements OFSerializer<MultipartRequestBody> {
23
24     @Override
25     public void serialize(final MultipartRequestBody multipartRequestBody, final ByteBuf byteBuf) {
26         final MultipartRequestQueueStats multipartRequestQueueStats = MultipartRequestQueueStats
27             .class
28             .cast(multipartRequestBody);
29
30         if (Objects.isNull(multipartRequestQueueStats.getNodeConnectorId())) {
31             byteBuf.writeInt(OFConstants.OFPP_ANY.intValue());
32         } else {
33             byteBuf.writeInt(InventoryDataServiceUtil
34                 .portNumberfromNodeConnectorId(
35                     OpenflowVersion.OF13,
36                     multipartRequestQueueStats.getNodeConnectorId()).intValue());
37         }
38
39         byteBuf.writeInt(MoreObjects
40             .firstNonNull(multipartRequestQueueStats.getQueueId(), new QueueId(OFConstants.OFPQ_ALL)).getValue().intValue());
41     }
42
43 }