Quick and Dirty fix for bridge controller ip address 54/19754/1
authorAnil Vishnoi <vishnoianil@gmail.com>
Wed, 6 May 2015 23:00:24 +0000 (04:30 +0530)
committerAnil Vishnoi <vishnoianil@gmail.com>
Wed, 6 May 2015 23:00:39 +0000 (04:30 +0530)
Rather the using the hardcoded value, using the  local host ip address.
This is dirty fix, we should remove it once we get the valid fix using
the connectionInfo local ip address. I think local ip address issues is now
fixed for conncetion-info, so we can probably use that. We need to merge the
 master to netvirtsb branch, that will bring that fix.
With this fix, netvirt create br-int and install all the pipeline flow
successfully.

Change-Id: If9d4e1289e0bb8c2a2888801f3c219f01f9a962d
Signed-off-by: Anil Vishnoi <vishnoianil@gmail.com>
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/impl/BridgeConfigurationManagerImpl.java

index b922cdb84528d9079d732ee0245e4b95fa4f2eb0..738fbaa633e29636af4a40c5c653cb4fab9e9050 100644 (file)
@@ -10,7 +10,9 @@
 package org.opendaylight.ovsdb.openstack.netvirt.impl;
 
 import java.net.InetAddress;
+import java.net.NetworkInterface;
 import java.net.UnknownHostException;
+
 import org.opendaylight.neutron.spi.NeutronNetwork;
 import org.opendaylight.ovsdb.lib.notation.Row;
 import org.opendaylight.ovsdb.lib.notation.UUID;
@@ -27,10 +29,12 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
+
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.Enumeration;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -409,7 +413,25 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
          * hardcoding value, need to find better way to get local ip
          */
         //String target = "tcp:" + getControllerIPAddress() + ":" + getControllerOFPort();
-        String target = "tcp:192.168.120.1:6633";
-        return target;
+        //TODO: dirty fix, need to remove it once we have proper solution
+        String ipaddress = null;
+        try{
+            for (Enumeration ifaces = NetworkInterface.getNetworkInterfaces();ifaces.hasMoreElements();){
+                NetworkInterface iface = (NetworkInterface) ifaces.nextElement();
+
+                for (Enumeration inetAddrs = iface.getInetAddresses(); inetAddrs.hasMoreElements();) {
+                    InetAddress inetAddr = (InetAddress) inetAddrs.nextElement();
+                    if (!inetAddr.isLoopbackAddress()) {
+                        if (inetAddr.isSiteLocalAddress()) {
+                            ipaddress = inetAddr.getHostAddress();
+                            break;
+                        }
+                    }
+                }
+            }
+        }catch (Exception e){
+            LOGGER.warn("ROYALLY SCREWED : Exception while fetching local host ip address ",e);
+        }
+        return "tcp:"+ipaddress+":6633";
     }
 }