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;
13 import java.util.HashMap;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
17 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
18 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
24 * Translates PortMod messages
25 * @author timotej.kubas
26 * @author michal.polkorab
28 public class PortModInputMessageFactory implements OFSerializer<PortModInput> {
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 PortModInput message, final ByteBuf outBuffer) {
36 ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
37 outBuffer.writeInt(message.getPortNo().getValue().intValue());
38 ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_01, outBuffer);
39 outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(message.getHwAddress().getValue()));
40 ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_02, outBuffer);
41 outBuffer.writeInt(createPortConfigBitmask(message.getConfig()));
42 outBuffer.writeInt(createPortConfigBitmask(message.getMask()));
43 outBuffer.writeInt(createPortFeaturesBitmask(message.getAdvertise()));
44 ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_03, outBuffer);
45 ByteBufUtils.updateOFHeaderLength(outBuffer);
50 * @return port config bitmask
52 private static int createPortConfigBitmask(final PortConfig config) {
53 int configBitmask = 0;
54 Map<Integer, Boolean> portConfigMap = new HashMap<>();
55 portConfigMap.put(0, config.isPortDown());
56 portConfigMap.put(2, config.isNoRecv());
57 portConfigMap.put(5, config.isNoFwd());
58 portConfigMap.put(6, config.isNoPacketIn());
60 configBitmask = ByteBufUtils.fillBitMaskFromMap(portConfigMap);
64 private static int createPortFeaturesBitmask(final PortFeatures feature) {
65 return ByteBufUtils.fillBitMask(0, feature.is_10mbHd(),
80 feature.isPauseAsym());