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