Fix compilation problems caused by vxlan_add_del_tunnel definition change in vpe.api
authorMarek Gradzki <[email protected]>
Fri, 29 Apr 2016 07:14:32 +0000 (09:14 +0200)
committerMarek Gradzki <[email protected]>
Fri, 29 Apr 2016 07:54:40 +0000 (09:54 +0200)
Change-Id: I6599598cb9755f263a603df484710e210867e068
Signed-off-by: Marek Gradzki <[email protected]>
v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizer.java
v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/utils/V3poUtils.java
v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/utils/V3poUtilsTest.java [new file with mode: 0644]

index dbf8cb0..6e84c30 100644 (file)
@@ -24,7 +24,7 @@ import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException;
 import io.fd.honeycomb.v3po.translate.v3po.utils.V3poUtils;
 import io.fd.honeycomb.v3po.translate.write.WriteFailedException;
 import javax.annotation.Nonnull;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VxlanTunnel;
@@ -84,16 +84,19 @@ public class VxlanCustomizer extends VppApiCustomizer implements ChildWriterCust
     }
 
     private void createVxlanTunnel(final String swIfName, final Vxlan vxlan) throws VppApiInvocationException {
-        Ipv4Address srcAddress = vxlan.getSrc();
-        Ipv4Address dstAddress = vxlan.getDst();
+        Ipv4AddressNoZone srcAddress = V3poUtils.removeIpv4AddressNoZone(vxlan.getSrc());
+        Ipv4AddressNoZone dstAddress = V3poUtils.removeIpv4AddressNoZone(vxlan.getDst());
 
-        int srcAddr = V3poUtils.parseIp(srcAddress.getValue());
-        int dstAddr = V3poUtils.parseIp(dstAddress.getValue());
+        byte[] srcAddr = V3poUtils.ipv4AddressNoZoneToArray(srcAddress);
+        byte[] dstAddr = V3poUtils.ipv4AddressNoZoneToArray(dstAddress);
         int encapVrfId = vxlan.getEncapVrfId().intValue();
         int vni = vxlan.getVni().getValue().intValue();
 
         LOG.debug("Setting vxlan tunnel for interface: {}. Vxlan: {}", swIfName, vxlan);
-        int ctxId = getVppApi().vxlanAddDelTunnel((byte) 1 /* is add */, srcAddr, dstAddr, encapVrfId, -1, vni);
+        int ctxId = 0; getVppApi().vxlanAddDelTunnel(
+                (byte) 1 /* is add */,
+                (byte) 0 /* is ipv6 */,
+                srcAddr, dstAddr, encapVrfId, -1, vni);
         final int rv = V3poUtils.waitForResponse(ctxId, getVppApi());
         if (rv < 0) {
             LOG.debug("Failed to set vxlan tunnel for interface: {}, vxlan: {}", swIfName, vxlan);
index 18a8103..8862645 100644 (file)
 
 package io.fd.honeycomb.v3po.translate.v3po.utils;
 
+import com.google.common.base.Preconditions;
 import com.google.common.base.Splitter;
 import com.google.common.collect.BiMap;
 import com.google.common.collect.HashBiMap;
+import javax.annotation.Nonnull;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.EthernetCsmacd;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.SoftwareLoopback;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfaceType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VxlanTunnel;
@@ -75,4 +78,24 @@ public final class V3poUtils {
         }
         return retval;
     }
+
+    /**
+     * Removes zone index from Ipv4Address.
+     * @param ipv4Addr ipv4 address which can contain zone index
+     * @return ipv4 address without zone index
+     */
+    @Nonnull
+    public static Ipv4AddressNoZone removeIpv4AddressNoZone(@Nonnull final Ipv4Address ipv4Addr) {
+        Preconditions.checkNotNull(ipv4Addr, "ipv4Addr should not be null");
+        if (ipv4Addr instanceof Ipv4AddressNoZone) {
+            return (Ipv4AddressNoZone)ipv4Addr;
+        } else {
+            String value = ipv4Addr.getValue();
+            final int index = value.indexOf('%');
+            if (index != -1) {
+                value = value.substring(0, index);
+            }
+            return new Ipv4AddressNoZone(value);
+        }
+    }
 }
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/utils/V3poUtilsTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/utils/V3poUtilsTest.java
new file mode 100644 (file)
index 0000000..3cb054a
--- /dev/null
@@ -0,0 +1,35 @@
+package io.fd.honeycomb.v3po.translate.v3po.utils;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
+
+public class V3poUtilsTest {
+
+    @Test
+    public void testRemoveIpv4AddressNoZoneFromIpv4WithZone() throws Exception {
+        String ipWithZone = "1.2.3.4%20";
+        String ipNoZone = "1.2.3.4";
+        final Ipv4Address expectedIp = new Ipv4Address(ipNoZone);
+        final Ipv4AddressNoZone actualIp = V3poUtils.removeIpv4AddressNoZone(new Ipv4Address(ipWithZone));
+        assertEquals(expectedIp.getValue(), actualIp.getValue());
+    }
+
+    @Test
+    public void testRemoveIpv4AddressNoZoneFromIpv4WithoutZone() throws Exception {
+        String ipNoZone = "1.2.3.4";
+        final Ipv4Address expectedIp = new Ipv4Address(ipNoZone);
+        final Ipv4AddressNoZone actualIp = V3poUtils.removeIpv4AddressNoZone(expectedIp);
+        assertEquals(expectedIp.getValue(), actualIp.getValue());
+    }
+
+    @Test
+    public void testRemoveIpv4AddressNoZoneNop() throws Exception {
+        String ipNoZone = "1.2.3.4";
+        final Ipv4Address expectedIp = new Ipv4AddressNoZone(ipNoZone);
+        final Ipv4AddressNoZone actualIp = V3poUtils.removeIpv4AddressNoZone(expectedIp);
+        assertEquals(expectedIp, actualIp);
+    }
+}
\ No newline at end of file