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).
23 * @author michal.polkorab
25 public class OF10PortStatusMessageFactory implements OFDeserializer<PortStatusMessage> {
27 private static final byte PADDING_IN_PORT_STATUS_HEADER = 7;
30 public PortStatusMessage deserialize(final ByteBuf rawMessage) {
31 PortStatusMessageBuilder builder = new PortStatusMessageBuilder();
32 builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
33 builder.setXid(rawMessage.readUnsignedInt());
34 builder.setReason(PortReason.forValue(rawMessage.readUnsignedByte()));
35 rawMessage.skipBytes(PADDING_IN_PORT_STATUS_HEADER);
36 deserializePort(rawMessage, builder);
37 return builder.build();
40 private static void deserializePort(final ByteBuf rawMessage, final PortStatusMessageBuilder builder) {
41 builder.setPortNo((long) rawMessage.readUnsignedShort());
42 builder.setHwAddr(ByteBufUtils.readIetfMacAddress(rawMessage));
43 builder.setName(ByteBufUtils.decodeNullTerminatedString(rawMessage, EncodeConstants.MAX_PORT_NAME_LENGTH));
44 builder.setConfigV10(OpenflowUtils.createPortConfig(rawMessage.readUnsignedInt()));
45 builder.setStateV10(OpenflowUtils.createPortState(rawMessage.readUnsignedInt()));
46 builder.setCurrentFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));
47 builder.setAdvertisedFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));
48 builder.setSupportedFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));
49 builder.setPeerFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt()));