-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
-\r
-import io.netty.buffer.ByteBuf;\r
-\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
-import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
-import org.opendaylight.openflowjava.protocol.impl.util.InstructionsSerializer;\r
-import org.opendaylight.openflowjava.protocol.impl.util.MatchSerializer;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;\r
-\r
-/**\r
- * Translates FlowMod messages\r
- * @author timotej.kubas\r
- * @author michal.polkorab\r
- */\r
-public class FlowModInputMessageFactory implements OFSerializer<FlowModInput> {\r
- private static final byte MESSAGE_TYPE = 14;\r
- private static final byte PADDING_IN_FLOW_MOD_MESSAGE = 2;\r
- private static final int MESSAGE_LENGTH = 48;\r
- private static FlowModInputMessageFactory instance;\r
- \r
- private FlowModInputMessageFactory() {\r
- // singleton\r
- }\r
- \r
- /**\r
- * @return singleton factory\r
- */\r
- public static synchronized FlowModInputMessageFactory getInstance() {\r
- if(instance == null) {\r
- instance = new FlowModInputMessageFactory();\r
- }\r
- return instance;\r
- }\r
- \r
- @Override\r
- public void messageToBuffer(short version, ByteBuf out, FlowModInput message) {\r
- ByteBufUtils.writeOFHeader(instance, message, out);\r
- out.writeLong(message.getCookie().longValue());\r
- out.writeLong(message.getCookieMask().longValue());\r
- out.writeByte(message.getTableId().getValue().byteValue());\r
- out.writeByte(message.getCommand().getIntValue());\r
- out.writeShort(message.getIdleTimeout().intValue());\r
- out.writeShort(message.getHardTimeout().intValue());\r
- out.writeShort(message.getPriority());\r
- out.writeInt(message.getBufferId().intValue());\r
- out.writeInt(message.getOutPort().getValue().intValue());\r
- out.writeInt(message.getOutGroup().intValue());\r
- out.writeShort(createFlowModFlagsBitmask(message.getFlags()));\r
- ByteBufUtils.padBuffer(PADDING_IN_FLOW_MOD_MESSAGE, out);\r
- MatchSerializer.encodeMatch(message.getMatch(), out);\r
- InstructionsSerializer.encodeInstructions(message.getInstructions(), out);\r
- }\r
-\r
- @Override\r
- public int computeLength(FlowModInput message) {\r
- return MESSAGE_LENGTH + MatchSerializer.computeMatchLength(message.getMatch())\r
- + InstructionsSerializer.computeInstructionsLength(message.getInstructions());\r
- }\r
-\r
- @Override\r
- public byte getMessageType() {\r
- return MESSAGE_TYPE;\r
- }\r
-\r
- private static int createFlowModFlagsBitmask(FlowModFlags flags) {\r
- int flowModFlagBitmask = 0;\r
- Map<Integer, Boolean> flowModFlagsMap = new HashMap<>();\r
- flowModFlagsMap.put(0, flags.isOFPFFSENDFLOWREM());\r
- flowModFlagsMap.put(1, flags.isOFPFFCHECKOVERLAP());\r
- flowModFlagsMap.put(2, flags.isOFPFFRESETCOUNTS());\r
- flowModFlagsMap.put(3, flags.isOFPFFNOPKTCOUNTS());\r
- flowModFlagsMap.put(4, flags.isOFPFFNOBYTCOUNTS());\r
- \r
- flowModFlagBitmask = ByteBufUtils.fillBitMaskFromMap(flowModFlagsMap);\r
- return flowModFlagBitmask;\r
- }\r
- \r
- \r
-}\r
+/*
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
+
+import io.netty.buffer.ByteBuf;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
+import org.opendaylight.openflowjava.protocol.impl.util.InstructionsSerializer;
+import org.opendaylight.openflowjava.protocol.impl.util.MatchSerializer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
+
+/**
+ * Translates FlowMod messages
+ * @author timotej.kubas
+ * @author michal.polkorab
+ */
+public class FlowModInputMessageFactory implements OFSerializer<FlowModInput> {
+ private static final byte MESSAGE_TYPE = 14;
+ private static final byte PADDING_IN_FLOW_MOD_MESSAGE = 2;
+ private static final int MESSAGE_LENGTH = 48;
+ private static FlowModInputMessageFactory instance;
+
+ private FlowModInputMessageFactory() {
+ // singleton
+ }
+
+ /**
+ * @return singleton factory
+ */
+ public static synchronized FlowModInputMessageFactory getInstance() {
+ if(instance == null) {
+ instance = new FlowModInputMessageFactory();
+ }
+ return instance;
+ }
+
+ @Override
+ public void messageToBuffer(short version, ByteBuf out, FlowModInput message) {
+ ByteBufUtils.writeOFHeader(instance, message, out);
+ out.writeLong(message.getCookie().longValue());
+ out.writeLong(message.getCookieMask().longValue());
+ out.writeByte(message.getTableId().getValue().byteValue());
+ out.writeByte(message.getCommand().getIntValue());
+ out.writeShort(message.getIdleTimeout().intValue());
+ out.writeShort(message.getHardTimeout().intValue());
+ out.writeShort(message.getPriority());
+ out.writeInt(message.getBufferId().intValue());
+ out.writeInt(message.getOutPort().getValue().intValue());
+ out.writeInt(message.getOutGroup().intValue());
+ out.writeShort(createFlowModFlagsBitmask(message.getFlags()));
+ ByteBufUtils.padBuffer(PADDING_IN_FLOW_MOD_MESSAGE, out);
+ MatchSerializer.encodeMatch(message.getMatch(), out);
+ InstructionsSerializer.encodeInstructions(message.getInstructions(), out);
+ }
+
+ @Override
+ public int computeLength(FlowModInput message) {
+ return MESSAGE_LENGTH + MatchSerializer.computeMatchLength(message.getMatch())
+ + InstructionsSerializer.computeInstructionsLength(message.getInstructions());
+ }
+
+ @Override
+ public byte getMessageType() {
+ return MESSAGE_TYPE;
+ }
+
+ private static int createFlowModFlagsBitmask(FlowModFlags flags) {
+ int flowModFlagBitmask = 0;
+ Map<Integer, Boolean> flowModFlagsMap = new HashMap<>();
+ flowModFlagsMap.put(0, flags.isOFPFFSENDFLOWREM());
+ flowModFlagsMap.put(1, flags.isOFPFFCHECKOVERLAP());
+ flowModFlagsMap.put(2, flags.isOFPFFRESETCOUNTS());
+ flowModFlagsMap.put(3, flags.isOFPFFNOPKTCOUNTS());
+ flowModFlagsMap.put(4, flags.isOFPFFNOBYTCOUNTS());
+
+ flowModFlagBitmask = ByteBufUtils.fillBitMaskFromMap(flowModFlagsMap);
+ return flowModFlagBitmask;
+ }
+
+
+}