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.openflowjava.protocol.impl.util.OF10ActionsSerializer;
19 import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchSerializer;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlagsV10;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
24 * Translates FlowMod messages
25 * @author michal.polkorab
27 public class OF10FlowModInputMessageFactory implements OFSerializer<FlowModInput> {
29 private static final byte MESSAGE_TYPE = 14;
30 private static final int MESSAGE_LENGTH = 72;
32 private static OF10FlowModInputMessageFactory instance;
34 private OF10FlowModInputMessageFactory() {
39 * @return singleton factory
41 public static synchronized OF10FlowModInputMessageFactory getInstance() {
42 if(instance == null) {
43 instance = new OF10FlowModInputMessageFactory();
49 public void messageToBuffer(short version, ByteBuf out, FlowModInput message) {
50 ByteBufUtils.writeOFHeader(instance, message, out);
51 OF10MatchSerializer.encodeMatchV10(out, message.getMatchV10());
52 out.writeLong(message.getCookie().longValue());
53 out.writeShort(message.getCommand().getIntValue());
54 out.writeShort(message.getIdleTimeout().intValue());
55 out.writeShort(message.getHardTimeout().intValue());
56 out.writeShort(message.getPriority());
57 out.writeInt(message.getBufferId().intValue());
58 out.writeShort(message.getOutPort().getValue().intValue());
59 out.writeShort(createFlowModFlagsBitmask(message.getFlagsV10()));
60 OF10ActionsSerializer.encodeActionsV10(out, message.getActionsList());
64 public int computeLength(FlowModInput message) {
65 return MESSAGE_LENGTH + OF10ActionsSerializer.computeActionsLength(message.getActionsList());
69 public byte getMessageType() {
73 private static int createFlowModFlagsBitmask(FlowModFlagsV10 flags) {
74 int flowModFlagBitmask = 0;
75 Map<Integer, Boolean> flowModFlagsMap = new HashMap<>();
76 flowModFlagsMap.put(0, flags.isOFPFFSENDFLOWREM());
77 flowModFlagsMap.put(1, flags.isOFPFFCHECKOVERLAP());
78 flowModFlagsMap.put(2, flags.isOFPFFEMERG());
79 flowModFlagBitmask = ByteBufUtils.fillBitMaskFromMap(flowModFlagsMap);
80 return flowModFlagBitmask;