2 * Copyright (c) 2016 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.openflowplugin.impl.protocol.deserialization.messages;
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.util.ByteBufUtils;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortMessage;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortMessageBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni;
21 public class PortMessageDeserializer implements OFDeserializer<PortMessage> {
23 private static final byte PADDING_IN_PORT_MOD_MESSAGE_1 = 4;
24 private static final byte PADDING_IN_PORT_MOD_MESSAGE_2 = 2;
25 private static final byte PADDING_IN_PORT_MOD_MESSAGE_3 = 4;
28 public PortMessage deserialize(ByteBuf message) {
29 final PortMessageBuilder builder = new PortMessageBuilder()
30 .setVersion((short) EncodeConstants.OF13_VERSION_ID)
31 .setXid(message.readUnsignedInt())
32 .setPortNumber(new PortNumberUni(message.readUnsignedInt()));
34 message.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_1);
35 builder.setHardwareAddress(ByteBufUtils.readIetfMacAddress(message));
36 message.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_2);
37 builder.setConfiguration(readPortConfig(message));
38 message.skipBytes(EncodeConstants.SIZE_OF_INT_IN_BYTES); // Skip mask
39 builder.setAdvertisedFeatures(readPortFeatures(message));
40 message.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_3);
41 return builder.build();
44 private static PortConfig readPortConfig(ByteBuf message) {
45 final long input = message.readUnsignedInt();
46 final Boolean pcPortDown = ((input) & (1)) != 0;
47 final Boolean pcNRecv = ((input) & (1 << 2)) != 0;
48 final Boolean pcNFwd = ((input) & (1 << 5)) != 0;
49 final Boolean pcNPacketIn = ((input) & (1 << 6)) != 0;
50 return new PortConfig(pcNFwd, pcNPacketIn, pcNRecv, pcPortDown);
53 private static PortFeatures readPortFeatures(ByteBuf message) {
54 final long input = message.readUnsignedInt();
55 final Boolean pf10mbHd = ((input) & (1)) != 0;
56 final Boolean pf10mbFd = ((input) & (1 << 1)) != 0;
57 final Boolean pf100mbHd = ((input) & (1 << 2)) != 0;
58 final Boolean pf100mbFd = ((input) & (1 << 3)) != 0;
59 final Boolean pf1gbHd = ((input) & (1 << 4)) != 0;
60 final Boolean pf1gbFd = ((input) & (1 << 5)) != 0;
61 final Boolean pf10gbFd = ((input) & (1 << 6)) != 0;
62 final Boolean pf40gbFd = ((input) & (1 << 7)) != 0;
63 final Boolean pf100gbFd = ((input) & (1 << 8)) != 0;
64 final Boolean pf1tbFd = ((input) & (1 << 9)) != 0;
65 final Boolean pfOther = ((input) & (1 << 10)) != 0;
66 final Boolean pfCopper = ((input) & (1 << 11)) != 0;
67 final Boolean pfFiber = ((input) & (1 << 12)) != 0;
68 final Boolean pfAutoneg = ((input) & (1 << 13)) != 0;
69 final Boolean pfPause = ((input) & (1 << 14)) != 0;
70 final Boolean pfPauseAsym = ((input) & (1 << 15)) != 0;
72 return new PortFeatures(
73 pfAutoneg, pfCopper, pfFiber,
74 pf40gbFd, pf100gbFd, pf100mbFd,
75 pf100mbHd, pf1gbFd, pf1gbHd, pf1tbFd,
76 pfOther, pfPause, pfPauseAsym,
77 pf10gbFd, pf10mbFd, pf10mbHd);