Remove trailing whitespace
[openflowjava.git] / 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
9 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
10
11 import io.netty.buffer.ByteBuf;
12
13 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
14 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
15 import org.opendaylight.openflowjava.protocol.impl.util.OpenflowUtils;
16 import org.opendaylight.openflowjava.util.ByteBufUtils;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
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  * @author michal.polkorab
25  */
26 public class OF10PortStatusMessageFactory implements OFDeserializer<PortStatusMessage> {
27
28     private static final byte PADDING_IN_PORT_STATUS_HEADER = 7;
29
30     @Override
31     public PortStatusMessage deserialize(ByteBuf rawMessage) {
32         PortStatusMessageBuilder builder = new PortStatusMessageBuilder();
33         builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
34         builder.setXid(rawMessage.readUnsignedInt());
35         builder.setReason(PortReason.forValue(rawMessage.readUnsignedByte()));
36         rawMessage.skipBytes(PADDING_IN_PORT_STATUS_HEADER);
37         deserializePort(rawMessage, builder);
38         return builder.build();
39     }
40
41     private static void deserializePort(ByteBuf rawMessage, PortStatusMessageBuilder builder) {
42         builder.setPortNo((long) rawMessage.readUnsignedShort());
43         byte[] address = new byte[EncodeConstants.MAC_ADDRESS_LENGTH];
44         rawMessage.readBytes(address);
45         builder.setHwAddr(new MacAddress(ByteBufUtils.macAddressToString(address)));
46         builder.setName(ByteBufUtils.decodeNullTerminatedString(rawMessage, EncodeConstants.MAX_PORT_NAME_LENGTH));
47         builder.setConfigV10(OpenflowUtils.createPortConfig(rawMessage.readUnsignedInt()));
48         builder.setStateV10(OpenflowUtils.createPortState(rawMessage.readUnsignedInt()));
49         builder.setCurrentFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));
50         builder.setAdvertisedFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));
51         builder.setSupportedFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));
52         builder.setPeerFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));
53     }
54 }