fix BUG 391
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / action / ActionSetNwDstConvertorV10Impl.java
diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstConvertorV10Impl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstConvertorV10Impl.java
new file mode 100644 (file)
index 0000000..f3a0f95
--- /dev/null
@@ -0,0 +1,33 @@
+/**
+ * Copyright (c) 2013 Ericsson. 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.openflowplugin.openflow.md.core.sal.convertor.action;
+
+import java.math.BigInteger;
+
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4;
+
+/**
+ * Utility class for converting a MD-SAL action subelement into the OF subelement
+ */
+public class ActionSetNwDstConvertorV10Impl implements Convertor<SetNwDstActionCase, Object> {
+    
+    @Override
+    public Object convert(SetNwDstActionCase source, BigInteger datapathid) {
+        Address address = source.getSetNwDstAction().getAddress();
+        if (address instanceof Ipv4) {
+            return new Ipv4Address(((Ipv4) address).getIpv4Address().getValue());
+        } else {
+            throw new IllegalArgumentException("Address is not supported by OF-1.0: "+address.getClass().getName());
+        }
+    }
+}