Merge "Add NodeConfiguratorImpl enqueue trace"
[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 package org.opendaylight.openflowplugin.impl.protocol.serialization.multipart;
9
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
12 import org.opendaylight.openflowplugin.api.OFConstants;
13 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
14 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.multipart.request.multipart.request.body.MultipartRequestPortStats;
16
17 public class MultipartRequestPortStatsSerializer implements OFSerializer<MultipartRequestPortStats> {
18     private static final byte PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY = 4;
19
20     @Override
21     public void serialize(final MultipartRequestPortStats multipartRequestPortStats, final ByteBuf byteBuf) {
22         if (multipartRequestPortStats.getNodeConnectorId() == null) {
23             byteBuf.writeInt(OFConstants.OFPP_ANY.intValue());
24         } else {
25             byteBuf.writeInt(InventoryDataServiceUtil
26                 .portNumberfromNodeConnectorId(
27                     OpenflowVersion.OF13,
28                     multipartRequestPortStats.getNodeConnectorId()).intValue());
29         }
30
31         byteBuf.writeZero(PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY);
32     }
33 }