Merge "OPNFLWPLUG-983 Group and flow removal stats are not reported in order"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / serialization / multipart / MultipartRequestPortStatsSerializer.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 io.netty.buffer.ByteBuf;
12 import java.util.Objects;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
14 import org.opendaylight.openflowplugin.api.OFConstants;
15 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
16 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.multipart.request.multipart.request.body.MultipartRequestPortStats;
18
19 public class MultipartRequestPortStatsSerializer implements OFSerializer<MultipartRequestPortStats> {
20
21     private static final byte PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY = 4;
22
23     @Override
24     public void serialize(final MultipartRequestPortStats multipartRequestPortStats, final ByteBuf byteBuf) {
25         if (Objects.isNull(multipartRequestPortStats.getNodeConnectorId())) {
26             byteBuf.writeInt(OFConstants.OFPP_ANY.intValue());
27         } else {
28             byteBuf.writeInt(InventoryDataServiceUtil
29                 .portNumberfromNodeConnectorId(
30                     OpenflowVersion.OF13,
31                     multipartRequestPortStats.getNodeConnectorId()).intValue());
32         }
33
34         byteBuf.writeZero(PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY);
35     }
36
37 }