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
8 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
10 import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint16;
11 import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint32;
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;
23 * Translates PortStatus messages (OpenFlow v1.0).
25 * @author michal.polkorab
27 public class OF10PortStatusMessageFactory implements OFDeserializer<PortStatusMessage> {
29 private static final byte PADDING_IN_PORT_STATUS_HEADER = 7;
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();
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()));