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.impl.serialization.OFSerializer;
17 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput;
22 * Translates TableMod messages
23 * @author timotej.kubas
24 * @author michal.polkorab
26 public class TableModInputMessageFactory implements OFSerializer<TableModInput> {
27 private static final byte MESSAGE_TYPE = 17;
28 private static final byte PADDING_IN_TABLE_MOD_MESSAGE = 3;
29 private static final int MESSAGE_LENGTH = 16;
30 private static TableModInputMessageFactory instance;
32 private TableModInputMessageFactory() {
37 * @return singleton factory
39 public static synchronized TableModInputMessageFactory getInstance() {
41 instance = new TableModInputMessageFactory();
47 public void messageToBuffer(short version, ByteBuf out, TableModInput message) {
48 ByteBufUtils.writeOFHeader(instance, message, out);
49 out.writeByte(message.getTableId().getValue().byteValue());
50 ByteBufUtils.padBuffer(PADDING_IN_TABLE_MOD_MESSAGE, out);
51 out.writeInt(createConfigBitmask(message.getConfig()));
55 public int computeLength(TableModInput message) {
56 return MESSAGE_LENGTH;
60 public byte getMessageType() {
66 * @return port config bitmask
68 private static int createConfigBitmask(TableConfig tableConfig) {
69 Map<Integer, Boolean> portConfigMap = new HashMap<>();
70 portConfigMap.put(3, tableConfig.isOFPTCDEPRECATEDMASK());
71 int configBitmask = ByteBufUtils.fillBitMaskFromMap(portConfigMap);