From 67e0895209eba92ecfcc25c4b88936747e97c1a0 Mon Sep 17 00:00:00 2001 From: Vishal Thapar Date: Mon, 13 Aug 2018 13:01:57 +0530 Subject: [PATCH] Incorrect IPv6 address for controller 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 --- .../southbound/utils/SouthboundUtils.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/utils/southbound-utils/src/main/java/org/opendaylight/ovsdb/utils/southbound/utils/SouthboundUtils.java b/utils/southbound-utils/src/main/java/org/opendaylight/ovsdb/utils/southbound/utils/SouthboundUtils.java index 1bae8e118..645725024 100644 --- a/utils/southbound-utils/src/main/java/org/opendaylight/ovsdb/utils/southbound/utils/SouthboundUtils.java +++ b/utils/southbound-utils/src/main/java/org/opendaylight/ovsdb/utils/southbound/utils/SouthboundUtils.java @@ -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; } -- 2.36.6