Incorrect IPv6 address for controller 57/75157/6
authorVishal Thapar <vthapar@redhat.com>
Mon, 13 Aug 2018 07:31:57 +0000 (13:01 +0530)
committerVishal Thapar <vthapar@redhat.com>
Tue, 28 Aug 2018 09:12:27 +0000 (14:42 +0530)
getControllersFromOvsdbNode() method to uses ':' as
delimiter for protocol, IP and Port, which is broken
by IPv6 addresses which use : as delimiters for address
octets.

Fix is to handle IPv6 addresses differently.

JIRA: OVSDB-466
Change-Id: Ifc7070d0d3ba5e60a124dc612cdfc66cafa1527b
Signed-off-by: Vishal Thapar <vthapar@redhat.com>
utils/southbound-utils/src/main/java/org/opendaylight/ovsdb/utils/southbound/utils/SouthboundUtils.java

index 1bae8e118f88cc81d6b3f58bd4e3d7e4fe4d3b63..645725024f112902bc95d314230206acf7902004 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 - 2017 Red Hat, Inc. and others.  All rights reserved.
+ * Copyright (c) 2015, 2018 Red Hat, Inc. 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,
@@ -19,6 +19,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -871,28 +872,34 @@ public class SouthboundUtils {
                         if (managerEntry == null || managerEntry.getTarget() == null) {
                             continue;
                         }
-                        String[] tokens = managerEntry.getTarget().getValue().split(":");
-                        if (tokens.length == 3 && tokens[0].equalsIgnoreCase("tcp")) {
-                            controllersStr.add(OPENFLOW_CONNECTION_PROTOCOL
-                                    + ":" + tokens[1] + ":" + getControllerOFPort());
-                        } else if (tokens[0].equalsIgnoreCase("ptcp")) {
+                        String managerStr = managerEntry.getTarget().getValue().toLowerCase(Locale.ROOT);
+                        int firstColonIdx = managerStr.indexOf(':');
+                        int lastColonIdx = managerStr.lastIndexOf(':');
+                        if (lastColonIdx <= firstColonIdx) {
+                            continue;
+                        }
+                        controllerIpStr = managerStr.substring(firstColonIdx + 1, lastColonIdx);
+                        if (managerStr.startsWith(("tcp"))) {
+                            controllersStr.add(OPENFLOW_CONNECTION_PROTOCOL + ":" + controllerIpStr + ":"
+                                + getControllerOFPort());
+                        } else if (managerStr.startsWith(("ssl"))) {
+                            controllersStr.add(OPENFLOW_SECURE_PROTOCOL + ":" + controllerIpStr + ":"
+                                + getControllerOFPort());
+                        } else if (managerStr.startsWith(("ptcp"))) {
                             ConnectionInfo connectionInfo = ovsdbNodeAugmentation.getConnectionInfo();
                             if (connectionInfo != null && connectionInfo.getLocalIp() != null) {
                                 controllerIpStr = connectionInfo.getLocalIp().stringValue();
                                 controllersStr.add(OPENFLOW_CONNECTION_PROTOCOL
-                                        + ":" + controllerIpStr + ":" + OPENFLOW_PORT);
+                                    + ":" + controllerIpStr + ":" + OPENFLOW_PORT);
                             } else {
                                 LOG.warn("Ovsdb Node does not contain connection info: {}", node);
                             }
-                        } else if (tokens.length == 3 && tokens[0].equalsIgnoreCase("ssl")) {
-                            controllersStr.add(OPENFLOW_SECURE_PROTOCOL
-                                    + ":" + tokens[1] + ":" + getControllerOFPort());
-                        } else if (tokens[0].equalsIgnoreCase("pssl")) {
+                        } else if (managerStr.startsWith(("pssl"))) {
                             ConnectionInfo connectionInfo = ovsdbNodeAugmentation.getConnectionInfo();
                             if (connectionInfo != null && connectionInfo.getLocalIp() != null) {
                                 controllerIpStr = connectionInfo.getLocalIp().stringValue();
                                 controllersStr.add(OPENFLOW_SECURE_PROTOCOL
-                                        + ":" + controllerIpStr + ":" + OPENFLOW_PORT);
+                                    + ":" + controllerIpStr + ":" + OPENFLOW_PORT);
                             } else {
                                 LOG.warn("Ovsdb Node does not contain connection info: {}", node);
                             }
@@ -913,7 +920,6 @@ public class SouthboundUtils {
             LOG.debug("Found {} OpenFlow Controller(s) :{}", controllersStr.size(),
                     controllersStr.stream().collect(Collectors.joining(" ")));
         }
-
         return controllersStr;
     }