2 * Copyright (c) 2015 NetIDE Consortium 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 io.netty.buffer.ByteBuf;
11 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
12 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
13 import org.opendaylight.openflowjava.util.ByteBufUtils;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
21 * Translates PortModInput messages.
23 * @author giuseppex.petralia@intel.com
25 public class OF10PortModInputMessageFactory implements OFDeserializer<PortModInput> {
28 public PortModInput deserialize(final ByteBuf rawMessage) {
29 PortModInputBuilder builder = new PortModInputBuilder();
30 builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
31 builder.setXid(rawMessage.readUnsignedInt());
32 builder.setPortNo(new PortNumber((long) rawMessage.readUnsignedShort()));
33 builder.setHwAddress(ByteBufUtils.readIetfMacAddress(rawMessage));
34 builder.setConfigV10(createPortConfig(rawMessage.readUnsignedInt()));
35 builder.setMaskV10(createPortConfig(rawMessage.readUnsignedInt()));
36 builder.setAdvertiseV10(createPortFeatures(rawMessage.readUnsignedInt()));
37 return builder.build();
40 private static PortConfigV10 createPortConfig(final long input) {
41 final Boolean _portDown = (input & 1 << 0) != 0;
42 final Boolean _noStp = (input & 1 << 1) != 0;
43 final Boolean _noRecv = (input & 1 << 2) != 0;
44 final Boolean _noRecvStp = (input & 1 << 3) != 0;
45 final Boolean _noFlood = (input & 1 << 4) != 0;
46 final Boolean _noFwd = (input & 1 << 5) != 0;
47 final Boolean _noPacketIn = (input & 1 << 6) != 0;
48 return new PortConfigV10(_noFlood, _noFwd, _noPacketIn, _noRecv, _noRecvStp, _noStp, _portDown);
51 private static PortFeaturesV10 createPortFeatures(final long input) {
52 final Boolean _10mbHd = (input & 1 << 0) != 0;
53 final Boolean _10mbFd = (input & 1 << 1) != 0;
54 final Boolean _100mbHd = (input & 1 << 2) != 0;
55 final Boolean _100mbFd = (input & 1 << 3) != 0;
56 final Boolean _1gbHd = (input & 1 << 4) != 0;
57 final Boolean _1gbFd = (input & 1 << 5) != 0;
58 final Boolean _10gbFd = (input & 1 << 6) != 0;
59 final Boolean _copper = (input & 1 << 7) != 0;
60 final Boolean _fiber = (input & 1 << 8) != 0;
61 final Boolean _autoneg = (input & 1 << 9) != 0;
62 final Boolean _pause = (input & 1 << 10) != 0;
63 final Boolean _pauseAsym = (input & 1 << 11) != 0;
64 return new PortFeaturesV10(_100mbFd, _100mbHd, _10gbFd, _10mbFd, _10mbHd, _1gbFd, _1gbHd, _autoneg, _copper,
65 _fiber, _pause, _pauseAsym);