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.PortConfig;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
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 PortModInputMessageFactory implements OFDeserializer<PortModInput> {
27 private static final byte PADDING_IN_PORT_MOD_MESSAGE_1 = 4;
28 private static final byte PADDING_IN_PORT_MOD_MESSAGE_2 = 2;
29 private static final byte PADDING_IN_PORT_MOD_MESSAGE_3 = 4;
32 public PortModInput deserialize(final ByteBuf rawMessage) {
33 PortModInputBuilder builder = new PortModInputBuilder();
34 builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
35 builder.setXid(rawMessage.readUnsignedInt());
36 builder.setPortNo(new PortNumber(rawMessage.readUnsignedInt()));
37 rawMessage.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_1);
38 builder.setHwAddress(ByteBufUtils.readIetfMacAddress(rawMessage));
39 rawMessage.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_2);
40 builder.setConfig(createPortConfig(rawMessage.readUnsignedInt()));
41 builder.setMask(createPortConfig(rawMessage.readUnsignedInt()));
42 builder.setAdvertise(createPortFeatures(rawMessage.readUnsignedInt()));
43 rawMessage.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_3);
44 return builder.build();
47 private static PortConfig createPortConfig(final long input) {
48 final Boolean pcPortDown = (input & 1 << 0) != 0;
49 final Boolean pcNRecv = (input & 1 << 2) != 0;
50 final Boolean pcNFwd = (input & 1 << 5) != 0;
51 final Boolean pcNPacketIn = (input & 1 << 6) != 0;
52 return new PortConfig(pcNFwd, pcNPacketIn, pcNRecv, pcPortDown);
55 private static PortFeatures createPortFeatures(final long input) {
56 final Boolean pf10mbHd = (input & 1 << 0) != 0;
57 final Boolean pf10mbFd = (input & 1 << 1) != 0;
58 final Boolean pf100mbHd = (input & 1 << 2) != 0;
59 final Boolean pf100mbFd = (input & 1 << 3) != 0;
60 final Boolean pf1gbHd = (input & 1 << 4) != 0;
61 final Boolean pf1gbFd = (input & 1 << 5) != 0;
62 final Boolean pf10gbFd = (input & 1 << 6) != 0;
63 final Boolean pf40gbFd = (input & 1 << 7) != 0;
64 final Boolean pf100gbFd = (input & 1 << 8) != 0;
65 final Boolean pf1tbFd = (input & 1 << 9) != 0;
66 final Boolean pfOther = (input & 1 << 10) != 0;
67 final Boolean pfCopper = (input & 1 << 11) != 0;
68 final Boolean pfFiber = (input & 1 << 12) != 0;
69 final Boolean pfAutoneg = (input & 1 << 13) != 0;
70 final Boolean pfPause = (input & 1 << 14) != 0;
71 final Boolean pfPauseAsym = (input & 1 << 15) != 0;
72 return new PortFeatures(pf100gbFd, pf100mbFd, pf100mbHd, pf10gbFd, pf10mbFd, pf10mbHd, pf1gbFd, pf1gbHd,
73 pf1tbFd, pf40gbFd, pfAutoneg, pfCopper, pfFiber, pfOther, pfPause, pfPauseAsym);