2 * Copyright (c) 2013 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
11 import io.netty.buffer.ByteBuf;
12 import java.util.HashMap;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
15 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
16 import org.opendaylight.openflowjava.util.ByteBufUtils;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortMod;
23 * Translates PortMod messages.
24 * OF protocol versions: 1.3.
25 * @author timotej.kubas
26 * @author michal.polkorab
28 public class PortModInputMessageFactory implements OFSerializer<PortMod> {
29 private static final byte MESSAGE_TYPE = 16;
30 private static final byte PADDING_IN_PORT_MOD_MESSAGE_01 = 4;
31 private static final byte PADDING_IN_PORT_MOD_MESSAGE_02 = 2;
32 private static final byte PADDING_IN_PORT_MOD_MESSAGE_03 = 4;
35 public void serialize(final PortMod message, final ByteBuf outBuffer) {
36 int index = outBuffer.writerIndex();
37 ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
38 outBuffer.writeInt(message.getPortNo().getValue().intValue());
39 outBuffer.writeZero(PADDING_IN_PORT_MOD_MESSAGE_01);
40 outBuffer.writeBytes(IetfYangUtil.INSTANCE.bytesFor(message.getHwAddress()));
41 outBuffer.writeZero(PADDING_IN_PORT_MOD_MESSAGE_02);
42 outBuffer.writeInt(createPortConfigBitmask(message.getConfig()));
43 outBuffer.writeInt(createPortConfigBitmask(message.getMask()));
44 outBuffer.writeInt(createPortFeaturesBitmask(message.getAdvertise()));
45 outBuffer.writeZero(PADDING_IN_PORT_MOD_MESSAGE_03);
46 ByteBufUtils.updateOFHeaderLength(outBuffer, index);
51 * @return port config bitmask
53 private static int createPortConfigBitmask(final PortConfig config) {
54 int configBitmask = 0;
55 Map<Integer, Boolean> portConfigMap = new HashMap<>();
56 portConfigMap.put(0, config.isPortDown());
57 portConfigMap.put(2, config.isNoRecv());
58 portConfigMap.put(5, config.isNoFwd());
59 portConfigMap.put(6, config.isNoPacketIn());
61 configBitmask = ByteBufUtils.fillBitMaskFromMap(portConfigMap);
65 private static int createPortFeaturesBitmask(final PortFeatures feature) {
66 return ByteBufUtils.fillBitMask(0, feature.is_10mbHd(),
81 feature.isPauseAsym());