Bug 1981: NumberFormatException in ArpResponderService while programming Static ARP... 80/11380/3
authorFlavio Fernandes <ffernand@redhat.com>
Fri, 19 Sep 2014 18:59:40 +0000 (14:59 -0400)
committerMadhu Venugopal <mavenugo@gmail.com>
Sun, 21 Sep 2014 04:51:54 +0000 (21:51 -0700)
The function ActionUtils.nxLoadArpShaAction() can now take a BitInteger or MacAddress.

Change-Id: Ia53a1e32d33b69f2ec0453d5c816d5f8c404814d
Signed-off-by: Flavio Fernandes <ffernand@redhat.com>
Signed-off-by: Madhu Venugopal <mavenugo@gmail.com>
openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/services/ArpResponderService.java
utils/mdsal-openflow/src/main/java/org/opendaylight/ovsdb/utils/mdsal/openflow/ActionUtils.java

index 9543a567f654fbeb0275f0684a1310516f70b861..88383a287eae5f3cc464d0976e4c79476ba1b872 100644 (file)
@@ -9,6 +9,10 @@
  */
 package org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.services;
 
+import java.math.BigInteger;
+import java.net.InetAddress;
+import java.util.List;
+
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.utils.Status;
 import org.opendaylight.controller.sal.utils.StatusCode;
@@ -36,10 +40,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherTyp
 
 import com.google.common.collect.Lists;
 
-import java.math.BigInteger;
-import java.net.InetAddress;
-import java.util.List;
-
 public class ArpResponderService extends AbstractServiceInstance implements ArpProvider {
     public ArpResponderService() {
         super(Service.ARP_RESPONDER);
@@ -55,10 +55,11 @@ public class ArpResponderService extends AbstractServiceInstance implements ArpP
     }
 
     @Override
-    public Status programStaticArpEntry(Node node, Long dpid, String segmentationId, String macAddress,
+    public Status programStaticArpEntry(Node node, Long dpid, String segmentationId, String macAddressStr,
                                         InetAddress ipAddress, Action action) {
 
         String nodeName = Constants.OPENFLOW_NODE_PREFIX + dpid;
+        MacAddress macAddress = new MacAddress(macAddressStr);
 
         MatchBuilder matchBuilder = new MatchBuilder();
         NodeBuilder nodeBuilder = OF13Provider.createNodeBuilder(nodeName);
@@ -78,7 +79,7 @@ public class ArpResponderService extends AbstractServiceInstance implements ArpP
         instructions.add(ib.build());
 
         // Set Eth Src
-        InstructionUtils.createDlSrcInstructions(ib, new MacAddress(macAddress));
+        InstructionUtils.createDlSrcInstructions(ib, macAddress);
         ib.setOrder(1);
         ib.setKey(new InstructionKey(1));
         instructions.add(ib.build());
@@ -102,7 +103,7 @@ public class ArpResponderService extends AbstractServiceInstance implements ArpP
         instructions.add(ib.build());
 
         // Load Mac to ARP SHA
-        ib.setInstruction(InstructionUtils.applyActionIns(ActionUtils.nxLoadArpShaAction(new BigInteger(macAddress))));
+        ib.setInstruction(InstructionUtils.applyActionIns(ActionUtils.nxLoadArpShaAction(macAddress)));
         ib.setOrder(5);
         ib.setKey(new InstructionKey(5));
         instructions.add(ib.build());
index 5a55b040eaeb906ded96c8179ac3b4c4dc718351..03aa519938b9534ad91dc14dc4709949da348315 100644 (file)
@@ -189,6 +189,9 @@ public final class ActionUtils {
             .setOfArpOp(Boolean.TRUE).build(), value, 15, false);
     }
 
+    public static Action nxLoadArpShaAction(MacAddress macAddress) {
+        return nxLoadArpShaAction(BigInteger.valueOf(toLong(macAddress)));
+    }
     public static Action nxLoadArpShaAction(BigInteger value) {
         return nxLoadRegAction(new DstNxArpShaCaseBuilder()
             .setNxArpSha(Boolean.TRUE).build(), value, 47, false);
@@ -331,4 +334,54 @@ public final class ActionUtils {
             .build();
         return new NxActionMultipathNodesNodeTableFlowApplyActionsCaseBuilder().setNxMultipath(r).build();
     }
+
+    /**
+     * Accepts a MAC address and returns the corresponding long, where the
+     * MAC bytes are set on the lower order bytes of the long.
+     * @param macAddress
+     * @return a long containing the mac address bytes
+     */
+    public static long toLong(byte[] macAddress) {
+        long mac = 0;
+        for (int i = 0; i < 6; i++) {
+            long t = (macAddress[i] & 0xffL) << ((5-i)*8);
+            mac |= t;
+        }
+        return mac;
+    }
+
+    /**
+     * Accepts a MAC address of the form 00:aa:11:bb:22:cc, case does not
+     * matter, and returns the corresponding long, where the MAC bytes are set
+     * on the lower order bytes of the long.
+     *
+     * @param macAddress
+     *            in String format
+     * @return a long containing the mac address bytes
+     */
+    public static long toLong(MacAddress macAddress) {
+        return toLong(toMACAddress(macAddress.getValue()));
+    }
+
+    /**
+     * Accepts a MAC address of the form 00:aa:11:bb:22:cc, case does not
+     * matter, and returns a corresponding byte[].
+     * @param macAddress
+     * @return
+     */
+    public static byte[] toMACAddress(String macAddress) {
+        final String HEXES = "0123456789ABCDEF";
+        byte[] address = new byte[6];
+        String[] macBytes = macAddress.split(":");
+        if (macBytes.length != 6)
+            throw new IllegalArgumentException(
+                    "Specified MAC Address must contain 12 hex digits" +
+                    " separated pairwise by :'s.");
+        for (int i = 0; i < 6; ++i) {
+            address[i] = (byte) ((HEXES.indexOf(macBytes[i].toUpperCase()
+                                                        .charAt(0)) << 4) | HEXES.indexOf(macBytes[i].toUpperCase()
+                                                                                                  .charAt(1)));
+        }
+        return address;
+    }
 }