Merge "Migrate uint/ByteBuf interactions"
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / OF10PortModInputMessageFactory.java
1 /*
2  * Copyright (c) 2015 NetIDE Consortium and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
9
10 import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint16;
11 import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint32;
12
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.PortConfigV10;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
22
23 /**
24  * Translates PortModInput messages.
25  *
26  * @author giuseppex.petralia@intel.com
27  */
28 public class OF10PortModInputMessageFactory implements OFDeserializer<PortModInput> {
29
30     @Override
31     public PortModInput deserialize(final ByteBuf rawMessage) {
32         PortModInputBuilder builder = new PortModInputBuilder();
33         builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
34         builder.setXid(readUint32(rawMessage));
35         builder.setPortNo(new PortNumber(readUint16(rawMessage).toUint32()));
36         builder.setHwAddress(ByteBufUtils.readIetfMacAddress(rawMessage));
37         builder.setConfigV10(createPortConfig(rawMessage.readUnsignedInt()));
38         builder.setMaskV10(createPortConfig(rawMessage.readUnsignedInt()));
39         builder.setAdvertiseV10(createPortFeatures(rawMessage.readUnsignedInt()));
40         return builder.build();
41     }
42
43     private static PortConfigV10 createPortConfig(final long input) {
44         final Boolean _portDown = (input & 1 << 0) != 0;
45         final Boolean _noStp = (input & 1 << 1) != 0;
46         final Boolean _noRecv = (input & 1 << 2) != 0;
47         final Boolean _noRecvStp = (input & 1 << 3) != 0;
48         final Boolean _noFlood = (input & 1 << 4) != 0;
49         final Boolean _noFwd = (input & 1 << 5) != 0;
50         final Boolean _noPacketIn = (input & 1 << 6) != 0;
51         return new PortConfigV10(_noFlood, _noFwd, _noPacketIn, _noRecv, _noRecvStp, _noStp, _portDown);
52     }
53
54     private static PortFeaturesV10 createPortFeatures(final long input) {
55         final Boolean _10mbHd = (input & 1 << 0) != 0;
56         final Boolean _10mbFd = (input & 1 << 1) != 0;
57         final Boolean _100mbHd = (input & 1 << 2) != 0;
58         final Boolean _100mbFd = (input & 1 << 3) != 0;
59         final Boolean _1gbHd = (input & 1 << 4) != 0;
60         final Boolean _1gbFd = (input & 1 << 5) != 0;
61         final Boolean _10gbFd = (input & 1 << 6) != 0;
62         final Boolean _copper = (input & 1 << 7) != 0;
63         final Boolean _fiber = (input & 1 << 8) != 0;
64         final Boolean _autoneg = (input & 1 << 9) != 0;
65         final Boolean _pause = (input & 1 << 10) != 0;
66         final Boolean _pauseAsym = (input & 1 << 11) != 0;
67         return new PortFeaturesV10(_100mbFd, _100mbHd, _10gbFd, _10mbFd, _10mbHd, _1gbFd, _1gbHd, _autoneg, _copper,
68                 _fiber, _pause, _pauseAsym);
69     }
70
71 }