Optimize conversionMapping table
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / PortConvertor.java
index 779843d5fa54480b1fa65c533f5d8b2a9068f2b5..51560ae97ecdc66da7f9a4ae848f266c7169aaeb 100644 (file)
@@ -1,8 +1,19 @@
+/**
+ * Copyright (c) 2014 Ericsson India Global Services Pvt Ltd. 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
+ *
+ * Contributor: usha.m.s@ericsson.com
+ */
 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
 
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
 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.PortConfigV10;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
@@ -36,42 +47,48 @@ public final class PortConvertor {
             short version) {
 
 
-        PortConfig config = null;
+        PortConfig config = maskPortConfigFields(source.getConfiguration());
+        PortConfigV10 configV10 = maskPortConfigV10Fields(source.getConfiguration());
 
         PortModInputBuilder portModInputBuilder = new PortModInputBuilder();
         portModInputBuilder.setAdvertise(getPortFeatures(source.getAdvertisedFeatures()));
         portModInputBuilder.setPortNo(new PortNumber(source.getPortNumber()));
-        maskPortConfigFields(source.getConfiguration(), config);
+
         portModInputBuilder.setConfig(config);
-        portModInputBuilder.setHwAddress(new MacAddress(source.getHardwareAddress()));
-        config = null;
-        maskPortConfigFields(source.getMask(), config);
         portModInputBuilder.setMask(config);
+
+        portModInputBuilder.setHwAddress(new MacAddress(source.getHardwareAddress()));
+
         portModInputBuilder.setVersion(version);
+
+        portModInputBuilder.setConfigV10(configV10);
+        portModInputBuilder.setMaskV10(configV10);
+        portModInputBuilder.setAdvertiseV10(getPortFeaturesV10(source.getAdvertisedFeatures()));
         return portModInputBuilder.build();
 
     }
 
-    private static void maskPortConfigFields(
-            org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig configData,
-            PortConfig config) {
-        Boolean portDown = false;
-        Boolean noRecv = false;
-        Boolean noFwd = false;
-        Boolean noPacketIn = false;
-        if (configData.isNOFWD())
-            noFwd = true;
-        if (configData.isNOPACKETIN())
-            noPacketIn = true;
-        if (configData.isNORECV())
-            noRecv = true;
-        if (configData.isPORTDOWN())
-            portDown = true;
-
-        config = new PortConfig(noFwd, noPacketIn, noRecv, portDown);
+    private static PortConfig maskPortConfigFields(
+            org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig configData) {
+        Boolean portDown = configData.isPORTDOWN();
+        Boolean noRecv = configData.isNORECV();
+        Boolean noFwd = configData.isNOFWD();
+        Boolean noPacketIn = configData.isNOPACKETIN();
+
+        return new PortConfig(noFwd, noPacketIn, noRecv, portDown);
 
     }
 
+    private static PortConfigV10 maskPortConfigV10Fields(
+            org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig configData) {
+        Boolean portDown = configData.isPORTDOWN();
+        Boolean noRecv = configData.isNORECV();
+        Boolean noFwd = configData.isNOFWD();
+        Boolean noPacketIn = configData.isNOPACKETIN();
+
+        return new PortConfigV10(false, noFwd, noPacketIn, noRecv, true, true, portDown);
+
+    }
     private static PortFeatures getPortFeatures(
             org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures salPortFeatures) {
 
@@ -83,6 +100,15 @@ public final class PortConvertor {
                 salPortFeatures.isPause(), salPortFeatures.isPauseAsym());
     }
 
+    private static PortFeaturesV10 getPortFeaturesV10(
+            org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures salPortFeatures) {
+
+        return new PortFeaturesV10(salPortFeatures.isHundredMbFd(), salPortFeatures.isHundredMbHd(), salPortFeatures.isTenGbFd(), salPortFeatures.isTenMbFd(), salPortFeatures.isTenMbHd(),
+                salPortFeatures.isOneGbFd(), salPortFeatures.isOneGbHd(), salPortFeatures.isAutoeng(), salPortFeatures.isCopper(), salPortFeatures.isFiber(),
+                salPortFeatures.isPause(), salPortFeatures.isPauseAsym());
+    }
+
+
     /*
      * This method is called as a reply to OFPMP_PORT_DESCRIPTION
      * message(OF1.3.1)
@@ -104,11 +130,12 @@ public final class PortConvertor {
         OFPortDescDataBuilder.setHwAddr(source.getHardwareAddress());
         OFPortDescDataBuilder.setName(source.getName());
 
-        maskPortConfigFields(source.getConfiguration(), config);
+        config = maskPortConfigFields(source.getConfiguration());
 
         OFPortDescDataBuilder.setConfig(config);
 
-        getPortState(source.getState(), portState);
+        portState = getPortState(source.getState());
+
         OFPortDescDataBuilder.setState(portState);
         OFPortDescDataBuilder.setCurrentFeatures(getPortFeatures(source.getCurrentFeature()));
         OFPortDescDataBuilder.setAdvertisedFeatures(getPortFeatures(source.getAdvertisedFeatures()));
@@ -121,21 +148,14 @@ public final class PortConvertor {
 
     }
 
-    private static void getPortState(
-            org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortState state, PortState portState) {
-
-        boolean isLinkDown = false;// (0),
-        boolean isBlocked = false; // (1),
-        boolean isLive = false; // (2);
-
-        if (state.isLinkDown()) {
-            isLinkDown = true;
-        } else if (state.isBlocked()) {
-            isBlocked = true;
-        } else if (state.isLive()) {
-            isLive = true;
-        }
-        portState = new PortState(isLinkDown, isBlocked, isLive);
+    private static PortState getPortState(
+            org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortState state) {
+
+        boolean isLinkDown = state.isLinkDown();
+        boolean isBlocked = state.isBlocked();
+        boolean isLive = state.isLive();
+
+        return new PortState(isLinkDown, isBlocked, isLive);
 
     }