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 * @author giuseppex.petralia@intel.com
24 public class PortModInputMessageFactory implements OFDeserializer<PortModInput> {
26 private static final byte PADDING_IN_PORT_MOD_MESSAGE_1 = 4;
27 private static final byte PADDING_IN_PORT_MOD_MESSAGE_2 = 2;
28 private static final byte PADDING_IN_PORT_MOD_MESSAGE_3 = 4;
31 public PortModInput deserialize(final ByteBuf rawMessage) {
32 PortModInputBuilder builder = new PortModInputBuilder();
33 builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
34 builder.setXid(rawMessage.readUnsignedInt());
35 builder.setPortNo(new PortNumber(rawMessage.readUnsignedInt()));
36 rawMessage.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_1);
37 builder.setHwAddress(ByteBufUtils.readIetfMacAddress(rawMessage));
38 rawMessage.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_2);
39 builder.setConfig(createPortConfig(rawMessage.readUnsignedInt()));
40 builder.setMask(createPortConfig(rawMessage.readUnsignedInt()));
41 builder.setAdvertise(createPortFeatures(rawMessage.readUnsignedInt()));
42 rawMessage.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_3);
43 return builder.build();
46 private static PortConfig createPortConfig(final long input) {
47 final Boolean pcPortDown = ((input) & (1 << 0)) != 0;
48 final Boolean pcNRecv = ((input) & (1 << 2)) != 0;
49 final Boolean pcNFwd = ((input) & (1 << 5)) != 0;
50 final Boolean pcNPacketIn = ((input) & (1 << 6)) != 0;
51 return new PortConfig(pcNFwd, pcNPacketIn, pcNRecv, pcPortDown);
54 private static PortFeatures createPortFeatures(final long input) {
55 final Boolean pf10mbHd = ((input) & (1 << 0)) != 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;
71 return new PortFeatures(pf100gbFd, pf100mbFd, pf100mbHd, pf10gbFd, pf10mbFd, pf10mbHd, pf1gbFd, pf1gbHd,
72 pf1tbFd, pf40gbFd, pfAutoneg, pfCopper, pfFiber, pfOther, pfPause, pfPauseAsym);