copyright header added
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / PortConvertor.java
index 2581eedee245e868c41353170600df698c116ef6..e11eb8dca66c1cd7e7e4a93d37b47a72cf6618af 100644 (file)
@@ -1,17 +1,23 @@
+/**
+ * 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 java.util.List;
-
 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.flow.types.port.rev130925.port.mod.port.Port;
 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.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;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc.Ports;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc.PortsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.multipart.reply.port.desc.Ports;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.multipart.reply.port.desc.PortsBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -35,22 +41,22 @@ public final class PortConvertor {
      */
 
     public static PortModInput toPortModInput(
-            org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortMod input) {
+            org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port source,
+            short version) {
 
-        List<Port> source = input.getPort().getPort();
 
         PortConfig config = null;
 
         PortModInputBuilder portModInputBuilder = new PortModInputBuilder();
-        portModInputBuilder.setAdvertise(getPortFeatures(source.get(0).getAdvertisedFeatures()));
-        portModInputBuilder.setPortNo(new PortNumber(source.get(0).getPortNumber()));
-        maskPortConfigFields(source.get(0).getConfiguration(), config);
+        portModInputBuilder.setAdvertise(getPortFeatures(source.getAdvertisedFeatures()));
+        portModInputBuilder.setPortNo(new PortNumber(source.getPortNumber()));
+        maskPortConfigFields(source.getConfiguration(), config);
         portModInputBuilder.setConfig(config);
-        portModInputBuilder.setHwAddress(new MacAddress(source.get(0).getHardwareAddress()));
+        portModInputBuilder.setHwAddress(new MacAddress(source.getHardwareAddress()));
         config = null;
-        maskPortConfigFields(source.get(0).getMask(), config);
+        maskPortConfigFields(source.getMask(), config);
         portModInputBuilder.setMask(config);
-
+        portModInputBuilder.setVersion(version);
         return portModInputBuilder.build();
 
     }
@@ -78,10 +84,10 @@ public final class PortConvertor {
     private static PortFeatures getPortFeatures(
             org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures salPortFeatures) {
 
-        return new PortFeatures(salPortFeatures.is_100gbFd(), salPortFeatures.is_100mbFd(),
-                salPortFeatures.is_100mbHd(), salPortFeatures.is_10gbFd(), salPortFeatures.is_10mbFd(),
-                salPortFeatures.is_10mbHd(), salPortFeatures.is_1gbFd(), salPortFeatures.is_1gbHd(),
-                salPortFeatures.is_1tbFd(), salPortFeatures.is_40gbFd(), salPortFeatures.isAutoeng(),
+        return new PortFeatures(salPortFeatures.isHundredGbFd(), salPortFeatures.isHundredMbFd(),
+                salPortFeatures.isHundredMbHd(), salPortFeatures.isTenGbFd(), salPortFeatures.isTenMbFd(),
+                salPortFeatures.isTenMbHd(), salPortFeatures.isOneGbFd(), salPortFeatures.isOneGbHd(),
+                salPortFeatures.isOneTbFd(), salPortFeatures.isFortyGbFd(), salPortFeatures.isAutoeng(),
                 salPortFeatures.isCopper(), salPortFeatures.isFiber(), salPortFeatures.isOther(),
                 salPortFeatures.isPause(), salPortFeatures.isPauseAsym());
     }
@@ -131,11 +137,11 @@ public final class PortConvertor {
         boolean isBlocked = false; // (1),
         boolean isLive = false; // (2);
 
-        if (state.getIntValue() == 0) {
+        if (state.isLinkDown()) {
             isLinkDown = true;
-        } else if (state.getIntValue() == 1) {
+        } else if (state.isBlocked()) {
             isBlocked = true;
-        } else if (state.getIntValue() == 2) {
+        } else if (state.isLive()) {
             isLive = true;
         }
         portState = new PortState(isLinkDown, isBlocked, isLive);