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 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.util.ByteBufUtils;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder;
25 * Translates PortStatus messages.
27 * @author michal.polkorab
28 * @author timotej.kubas
30 public class PortStatusMessageFactory implements OFDeserializer<PortStatusMessage> {
32 private static final byte PADDING_IN_PORT_STATUS_HEADER = 7;
33 private static final byte PADDING_IN_OFP_PORT_HEADER_1 = 4;
34 private static final byte PADDING_IN_OFP_PORT_HEADER_2 = 2;
37 public PortStatusMessage deserialize(final ByteBuf rawMessage) {
38 PortStatusMessageBuilder builder = new PortStatusMessageBuilder()
39 .setVersion(EncodeConstants.OF_VERSION_1_3)
40 .setXid(readUint32(rawMessage))
41 .setReason(PortReason.forValue(rawMessage.readUnsignedByte()));
42 rawMessage.skipBytes(PADDING_IN_PORT_STATUS_HEADER);
43 builder.setPortNo(readUint32(rawMessage));
44 rawMessage.skipBytes(PADDING_IN_OFP_PORT_HEADER_1);
45 builder.setHwAddr(ByteBufUtils.readIetfMacAddress(rawMessage));
46 rawMessage.skipBytes(PADDING_IN_OFP_PORT_HEADER_2);
47 builder.setName(ByteBufUtils.decodeNullTerminatedString(rawMessage, EncodeConstants.MAX_PORT_NAME_LENGTH));
48 builder.setConfig(createPortConfig(rawMessage.readUnsignedInt()));
49 builder.setState(createPortState(rawMessage.readUnsignedInt()));
50 builder.setCurrentFeatures(createPortFeatures(rawMessage.readUnsignedInt()));
51 builder.setAdvertisedFeatures(createPortFeatures(rawMessage.readUnsignedInt()));
52 builder.setSupportedFeatures(createPortFeatures(rawMessage.readUnsignedInt()));
53 builder.setPeerFeatures(createPortFeatures(rawMessage.readUnsignedInt()));
54 builder.setCurrSpeed(readUint32(rawMessage));
55 builder.setMaxSpeed(readUint32(rawMessage));
56 return builder.build();
59 private static PortFeatures createPortFeatures(final long input) {
60 final Boolean pf10mbHd = (input & 1 << 0) != 0;
61 final Boolean pf10mbFd = (input & 1 << 1) != 0;
62 final Boolean pf100mbHd = (input & 1 << 2) != 0;
63 final Boolean pf100mbFd = (input & 1 << 3) != 0;
64 final Boolean pf1gbHd = (input & 1 << 4) != 0;
65 final Boolean pf1gbFd = (input & 1 << 5) != 0;
66 final Boolean pf10gbFd = (input & 1 << 6) != 0;
67 final Boolean pf40gbFd = (input & 1 << 7) != 0;
68 final Boolean pf100gbFd = (input & 1 << 8) != 0;
69 final Boolean pf1tbFd = (input & 1 << 9) != 0;
70 final Boolean pfOther = (input & 1 << 10) != 0;
71 final Boolean pfCopper = (input & 1 << 11) != 0;
72 final Boolean pfFiber = (input & 1 << 12) != 0;
73 final Boolean pfAutoneg = (input & 1 << 13) != 0;
74 final Boolean pfPause = (input & 1 << 14) != 0;
75 final Boolean pfPauseAsym = (input & 1 << 15) != 0;
76 return new PortFeatures(pf100gbFd, pf100mbFd, pf100mbHd, pf10gbFd, pf10mbFd, pf10mbHd, pf1gbFd,
77 pf1gbHd, pf1tbFd, pf40gbFd, pfAutoneg, pfCopper, pfFiber, pfOther, pfPause, pfPauseAsym);
80 private static PortState createPortState(final long input) {
81 final Boolean psLinkDown = (input & 1 << 0) != 0;
82 final Boolean psBblocked = (input & 1 << 1) != 0;
83 final Boolean psLive = (input & 1 << 2) != 0;
84 return new PortState(psBblocked, psLinkDown, psLive);
87 private static PortConfig createPortConfig(final long input) {
88 final Boolean pcPortDown = (input & 1 << 0) != 0;
89 final Boolean pcNoRecv = (input & 1 << 2) != 0;
90 final Boolean pcNoFwd = (input & 1 << 5) != 0;
91 final Boolean pcNoPacketIn = (input & 1 << 6) != 0;
92 return new PortConfig(pcNoFwd, pcNoPacketIn, pcNoRecv, pcPortDown);