Remove EncodeConstants.SIZE_OF_{BYTE,SHORT,INT,LONG}_IN_BYTES
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / OF10PortStatusMessageFactory.java
1 /*
2  * Copyright (c) 2013 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.openflowjava.protocol.impl.deserialization.factories;
9
10 import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint16;
11 import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint32;
12
13 import io.netty.buffer.ByteBuf;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
15 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
16 import org.opendaylight.openflowjava.protocol.impl.util.OpenflowUtils;
17 import org.opendaylight.openflowjava.util.ByteBufUtils;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder;
21
22 /**
23  * Translates PortStatus messages (OpenFlow v1.0).
24  *
25  * @author michal.polkorab
26  */
27 public class OF10PortStatusMessageFactory implements OFDeserializer<PortStatusMessage> {
28
29     private static final byte PADDING_IN_PORT_STATUS_HEADER = 7;
30
31     @Override
32     public PortStatusMessage deserialize(final ByteBuf rawMessage) {
33         PortStatusMessageBuilder builder = new PortStatusMessageBuilder()
34                 .setVersion(EncodeConstants.OF_VERSION_1_0)
35                 .setXid(readUint32(rawMessage))
36                 .setReason(PortReason.forValue(rawMessage.readUnsignedByte()));
37         rawMessage.skipBytes(PADDING_IN_PORT_STATUS_HEADER);
38         deserializePort(rawMessage, builder);
39         return builder.build();
40     }
41
42     private static void deserializePort(final ByteBuf rawMessage, final PortStatusMessageBuilder builder) {
43         builder.setPortNo(readUint16(rawMessage).toUint32());
44         builder.setHwAddr(ByteBufUtils.readIetfMacAddress(rawMessage));
45         builder.setName(ByteBufUtils.decodeNullTerminatedString(rawMessage, EncodeConstants.MAX_PORT_NAME_LENGTH));
46         builder.setConfigV10(OpenflowUtils.createPortConfig(rawMessage.readUnsignedInt()));
47         builder.setStateV10(OpenflowUtils.createPortState(rawMessage.readUnsignedInt()));
48         builder.setCurrentFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));
49         builder.setAdvertisedFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));
50         builder.setSupportedFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));
51         builder.setPeerFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));
52     }
53 }