Copyright update
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / PortModInputMessageFactory.java
index e83cdb7d13394ff12cd2e1a61f84e675515c59e7..3a576660afb4e085fbedefac647d3f5ba807ad7e 100644 (file)
-/* 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.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;\r
-\r
-/**\r
- * Translates PortMod messages\r
- * @author timotej.kubas\r
- * @author michal.polkorab\r
- */\r
-public class PortModInputMessageFactory implements OFSerializer<PortModInput> {\r
-    private static final byte MESSAGE_TYPE = 16;\r
-    private static final byte PADDING_IN_PORT_MOD_MESSAGE_01 = 4;\r
-    private static final byte PADDING_IN_PORT_MOD_MESSAGE_02 = 2;\r
-    private static final byte PADDING_IN_PORT_MOD_MESSAGE_03 = 4;\r
-    private static final int MESSAGE_LENGTH = 40;\r
-    private static PortModInputMessageFactory instance;\r
-    \r
-    private PortModInputMessageFactory() {\r
-        // singleton\r
-    }\r
-    \r
-    /**\r
-     * @return singleton factory\r
-     */\r
-    public static synchronized PortModInputMessageFactory getInstance() {\r
-        if (instance == null) {\r
-            instance = new PortModInputMessageFactory();\r
-        }\r
-        return instance;\r
-    }\r
-    \r
-    @Override\r
-    public void messageToBuffer(short version, ByteBuf out, PortModInput message) {\r
-        ByteBufUtils.writeOFHeader(instance, message, out);\r
-        out.writeInt(message.getPortNo().getValue().intValue());\r
-        ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_01, out);\r
-        out.writeBytes(ByteBufUtils.macAddressToBytes(message.getHwAddress().getValue()));\r
-        ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_02, out);\r
-        out.writeInt(createPortConfigBitmask(message.getConfig()));\r
-        out.writeInt(createPortConfigBitmask(message.getMask()));\r
-        out.writeInt(createPortFeaturesBitmask(message.getAdvertise()));\r
-        ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_03, out);\r
-    }\r
-\r
-    @Override\r
-    public int computeLength(PortModInput message) {\r
-        return MESSAGE_LENGTH;\r
-    }\r
-\r
-    @Override\r
-    public byte getMessageType() {\r
-        return MESSAGE_TYPE;\r
-    }\r
-   \r
-    \r
-    /**\r
-     * @param config\r
-     * @return port config bitmask \r
-     */\r
-    private static int createPortConfigBitmask(PortConfig config) {\r
-        int configBitmask = 0;\r
-        Map<Integer, Boolean> portConfigMap = new HashMap<>();\r
-        portConfigMap.put(0, config.isPortDown());\r
-        portConfigMap.put(2, config.isNoRecv());\r
-        portConfigMap.put(5, config.isNoFwd());\r
-        portConfigMap.put(6, config.isNoPacketIn());\r
-        \r
-        configBitmask = ByteBufUtils.fillBitMaskFromMap(portConfigMap);\r
-        return configBitmask;\r
-    }\r
-    \r
-    private static int createPortFeaturesBitmask(PortFeatures feature) {\r
-        int configBitmask = 0;\r
-        Map<Integer, Boolean> portFeaturesMap = new HashMap<>();\r
-        portFeaturesMap.put(0, feature.is_10mbHd());\r
-        portFeaturesMap.put(1, feature.is_10mbFd());\r
-        portFeaturesMap.put(2, feature.is_100mbHd());\r
-        portFeaturesMap.put(3, feature.is_100mbFd());\r
-        portFeaturesMap.put(4, feature.is_1gbHd());\r
-        portFeaturesMap.put(5, feature.is_1gbFd());\r
-        portFeaturesMap.put(6, feature.is_10gbFd());\r
-        portFeaturesMap.put(7, feature.is_40gbFd());\r
-        portFeaturesMap.put(8, feature.is_100gbFd());\r
-        portFeaturesMap.put(9, feature.is_1tbFd());\r
-        portFeaturesMap.put(10, feature.isOther());\r
-        portFeaturesMap.put(11, feature.isCopper());\r
-        portFeaturesMap.put(12, feature.isFiber());\r
-        portFeaturesMap.put(13, feature.isAutoneg());\r
-        portFeaturesMap.put(14, feature.isPause());\r
-        portFeaturesMap.put(15, feature.isPauseAsym());\r
-        \r
-        configBitmask = ByteBufUtils.fillBitMaskFromMap(portFeaturesMap);\r
-        return configBitmask;\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.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
+
+/**
+ * Translates PortMod messages
+ * @author timotej.kubas
+ * @author michal.polkorab
+ */
+public class PortModInputMessageFactory implements OFSerializer<PortModInput> {
+    private static final byte MESSAGE_TYPE = 16;
+    private static final byte PADDING_IN_PORT_MOD_MESSAGE_01 = 4;
+    private static final byte PADDING_IN_PORT_MOD_MESSAGE_02 = 2;
+    private static final byte PADDING_IN_PORT_MOD_MESSAGE_03 = 4;
+    private static final int MESSAGE_LENGTH = 40;
+    private static PortModInputMessageFactory instance;
+    
+    private PortModInputMessageFactory() {
+        // singleton
+    }
+    
+    /**
+     * @return singleton factory
+     */
+    public static synchronized PortModInputMessageFactory getInstance() {
+        if (instance == null) {
+            instance = new PortModInputMessageFactory();
+        }
+        return instance;
+    }
+    
+    @Override
+    public void messageToBuffer(short version, ByteBuf out, PortModInput message) {
+        ByteBufUtils.writeOFHeader(instance, message, out);
+        out.writeInt(message.getPortNo().getValue().intValue());
+        ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_01, out);
+        out.writeBytes(ByteBufUtils.macAddressToBytes(message.getHwAddress().getValue()));
+        ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_02, out);
+        out.writeInt(createPortConfigBitmask(message.getConfig()));
+        out.writeInt(createPortConfigBitmask(message.getMask()));
+        out.writeInt(createPortFeaturesBitmask(message.getAdvertise()));
+        ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE_03, out);
+    }
+
+    @Override
+    public int computeLength(PortModInput message) {
+        return MESSAGE_LENGTH;
+    }
+
+    @Override
+    public byte getMessageType() {
+        return MESSAGE_TYPE;
+    }
+   
+    
+    /**
+     * @param config
+     * @return port config bitmask 
+     */
+    private static int createPortConfigBitmask(PortConfig config) {
+        int configBitmask = 0;
+        Map<Integer, Boolean> portConfigMap = new HashMap<>();
+        portConfigMap.put(0, config.isPortDown());
+        portConfigMap.put(2, config.isNoRecv());
+        portConfigMap.put(5, config.isNoFwd());
+        portConfigMap.put(6, config.isNoPacketIn());
+        
+        configBitmask = ByteBufUtils.fillBitMaskFromMap(portConfigMap);
+        return configBitmask;
+    }
+    
+    private static int createPortFeaturesBitmask(PortFeatures feature) {
+        int configBitmask = 0;
+        Map<Integer, Boolean> portFeaturesMap = new HashMap<>();
+        portFeaturesMap.put(0, feature.is_10mbHd());
+        portFeaturesMap.put(1, feature.is_10mbFd());
+        portFeaturesMap.put(2, feature.is_100mbHd());
+        portFeaturesMap.put(3, feature.is_100mbFd());
+        portFeaturesMap.put(4, feature.is_1gbHd());
+        portFeaturesMap.put(5, feature.is_1gbFd());
+        portFeaturesMap.put(6, feature.is_10gbFd());
+        portFeaturesMap.put(7, feature.is_40gbFd());
+        portFeaturesMap.put(8, feature.is_100gbFd());
+        portFeaturesMap.put(9, feature.is_1tbFd());
+        portFeaturesMap.put(10, feature.isOther());
+        portFeaturesMap.put(11, feature.isCopper());
+        portFeaturesMap.put(12, feature.isFiber());
+        portFeaturesMap.put(13, feature.isAutoneg());
+        portFeaturesMap.put(14, feature.isPause());
+        portFeaturesMap.put(15, feature.isPauseAsym());
+        
+        configBitmask = ByteBufUtils.fillBitMaskFromMap(portFeaturesMap);
+        return configBitmask;
+    }
+}