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.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
22 * @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(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 byte[] hwAddress = new byte[EncodeConstants.MAC_ADDRESS_LENGTH];
39 rawMessage.readBytes(hwAddress);
40 builder.setHwAddress(new MacAddress(ByteBufUtils.macAddressToString(hwAddress)));
41 rawMessage.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_2);
42 builder.setConfig(createPortConfig(rawMessage.readUnsignedInt()));
43 builder.setMask(createPortConfig(rawMessage.readUnsignedInt()));
44 builder.setAdvertise(createPortFeatures(rawMessage.readUnsignedInt()));
45 rawMessage.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_3);
46 return builder.build();
49 private static PortConfig createPortConfig(long input) {
50 final Boolean pcPortDown = ((input) & (1 << 0)) != 0;
51 final Boolean pcNRecv = ((input) & (1 << 2)) != 0;
52 final Boolean pcNFwd = ((input) & (1 << 5)) != 0;
53 final Boolean pcNPacketIn = ((input) & (1 << 6)) != 0;
54 return new PortConfig(pcNFwd, pcNPacketIn, pcNRecv, pcPortDown);
57 private static PortFeatures createPortFeatures(long input) {
58 final Boolean pf10mbHd = ((input) & (1 << 0)) != 0;
59 final Boolean pf10mbFd = ((input) & (1 << 1)) != 0;
60 final Boolean pf100mbHd = ((input) & (1 << 2)) != 0;
61 final Boolean pf100mbFd = ((input) & (1 << 3)) != 0;
62 final Boolean pf1gbHd = ((input) & (1 << 4)) != 0;
63 final Boolean pf1gbFd = ((input) & (1 << 5)) != 0;
64 final Boolean pf10gbFd = ((input) & (1 << 6)) != 0;
65 final Boolean pf40gbFd = ((input) & (1 << 7)) != 0;
66 final Boolean pf100gbFd = ((input) & (1 << 8)) != 0;
67 final Boolean pf1tbFd = ((input) & (1 << 9)) != 0;
68 final Boolean pfOther = ((input) & (1 << 10)) != 0;
69 final Boolean pfCopper = ((input) & (1 << 11)) != 0;
70 final Boolean pfFiber = ((input) & (1 << 12)) != 0;
71 final Boolean pfAutoneg = ((input) & (1 << 13)) != 0;
72 final Boolean pfPause = ((input) & (1 << 14)) != 0;
73 final Boolean pfPauseAsym = ((input) & (1 << 15)) != 0;
74 return new PortFeatures(pf100gbFd, pf100mbFd, pf100mbHd, pf10gbFd, pf10mbFd, pf10mbHd, pf1gbFd, pf1gbHd,
75 pf1tbFd, pf40gbFd, pfAutoneg, pfCopper, pfFiber, pfOther, pfPause, pfPauseAsym);