2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
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
9 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
14 import org.opendaylight.openflowjava.protocol.impl.util.OpenflowUtils;
15 import org.opendaylight.openflowjava.util.ByteBufUtils;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder;
21 * Translates PortStatus messages (OpenFlow v1.0)
22 * @author michal.polkorab
24 public class OF10PortStatusMessageFactory implements OFDeserializer<PortStatusMessage> {
26 private static final byte PADDING_IN_PORT_STATUS_HEADER = 7;
29 public PortStatusMessage deserialize(final ByteBuf rawMessage) {
30 PortStatusMessageBuilder builder = new PortStatusMessageBuilder();
31 builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
32 builder.setXid(rawMessage.readUnsignedInt());
33 builder.setReason(PortReason.forValue(rawMessage.readUnsignedByte()));
34 rawMessage.skipBytes(PADDING_IN_PORT_STATUS_HEADER);
35 deserializePort(rawMessage, builder);
36 return builder.build();
39 private static void deserializePort(final ByteBuf rawMessage, final PortStatusMessageBuilder builder) {
40 builder.setPortNo((long) rawMessage.readUnsignedShort());
41 builder.setHwAddr(ByteBufUtils.readIetfMacAddress(rawMessage));
42 builder.setName(ByteBufUtils.decodeNullTerminatedString(rawMessage, EncodeConstants.MAX_PORT_NAME_LENGTH));
43 builder.setConfigV10(OpenflowUtils.createPortConfig(rawMessage.readUnsignedInt()));
44 builder.setStateV10(OpenflowUtils.createPortState(rawMessage.readUnsignedInt()));
45 builder.setCurrentFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));
46 builder.setAdvertisedFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));
47 builder.setSupportedFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));
48 builder.setPeerFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));