Merge "Avoid calling the String constructor explicitly"
[netvirt.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / impl / BridgeConfigurationManagerImpl.java
1 /*
2  * Copyright (c) 2013, 2015 Red Hat, Inc. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.ovsdb.openstack.netvirt.impl;
10
11 import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronNetwork;
12 import org.opendaylight.ovsdb.openstack.netvirt.ConfigInterface;
13 import org.opendaylight.ovsdb.openstack.netvirt.NetworkHandler;
14 import org.opendaylight.ovsdb.openstack.netvirt.api.BridgeConfigurationManager;
15 import org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService;
16 import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
17 import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProviderManager;
18 import org.opendaylight.ovsdb.openstack.netvirt.api.OvsdbTables;
19 import org.opendaylight.ovsdb.openstack.netvirt.api.Southbound;
20 import org.opendaylight.ovsdb.utils.config.ConfigProperties;
21 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.DatapathTypeBase;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.DatapathTypeNetdev;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.DatapathTypeSystem;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagerEntry;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
29
30 import com.google.common.base.Preconditions;
31 import com.google.common.collect.Lists;
32
33 import java.net.InetAddress;
34 import java.net.NetworkInterface;
35 import java.net.UnknownHostException;
36 import java.util.ArrayList;
37 import java.util.Enumeration;
38 import java.util.List;
39
40 import org.apache.commons.lang3.tuple.ImmutablePair;
41 import org.osgi.framework.ServiceReference;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44
45 /**
46  * @author Madhu Venugopal
47  * @author Brent Salisbury
48  * @author Sam Hague (shague@redhat.com)
49  */
50 public class BridgeConfigurationManagerImpl implements BridgeConfigurationManager, ConfigInterface {
51     private static final Logger LOG = LoggerFactory.getLogger(BridgeConfigurationManagerImpl.class);
52
53     // The implementation for each of these services is resolved by the OSGi Service Manager
54     private volatile ConfigurationService configurationService;
55     private volatile NetworkingProviderManager networkingProviderManager;
56     private volatile Southbound southbound;
57
58     public void setConfigurationService(ConfigurationService configurationService) {
59         this.configurationService = configurationService;
60     }
61
62     public void setSouthbound(Southbound southbound) {
63         this.southbound = southbound;
64     }
65
66     @Override
67     public String getBridgeUuid(Node node, String bridgeName) {
68         return southbound.getBridgeUuid(node, bridgeName);
69     }
70
71     @Override
72     public boolean isNodeNeutronReady(Node node) {
73         Preconditions.checkNotNull(configurationService);
74         return southbound.getBridge(node, configurationService.getIntegrationBridgeName()) != null;
75     }
76
77     @Override
78     public boolean isNodeOverlayReady(Node node) {
79         Preconditions.checkNotNull(configurationService);
80         return isNodeNeutronReady(node)
81                 && southbound.getBridge(node, configurationService.getNetworkBridgeName()) != null;
82     }
83
84     @Override
85     public boolean isPortOnBridge (Node bridgeNode, String portName) {
86         return southbound.extractTerminationPointAugmentation(bridgeNode, portName) != null;
87     }
88
89     @Override
90     public boolean isNodeTunnelReady(Node bridgeNode, Node ovsdbNode) {
91         Preconditions.checkNotNull(configurationService);
92         if (!southbound.isBridgeOnOvsdbNode(ovsdbNode, configurationService.getIntegrationBridgeName())) {
93             LOG.trace("isNodeTunnelReady: node: {}, {} missing",
94                     bridgeNode, configurationService.getIntegrationBridgeName());
95             return false;
96         }
97
98         return isNodeL3Ready(bridgeNode, ovsdbNode);
99     }
100
101     @Override
102     public boolean isNodeVlanReady(Node bridgeNode, Node ovsdbNode, NeutronNetwork network) {
103         Preconditions.checkNotNull(configurationService);
104
105         final String brInt = configurationService.getIntegrationBridgeName();
106         if (!southbound.isBridgeOnOvsdbNode(ovsdbNode, brInt)) {
107             LOG.trace("isNodeVlanReady: node: {}, {} missing", bridgeNode, brInt);
108             return false;
109         }
110
111         /* Check if physical device is added to br-int. */
112         String phyNetName = getPhysicalInterfaceName(ovsdbNode, network.getProviderPhysicalNetwork());
113         if (!isPortOnBridge(bridgeNode, phyNetName)) {
114             LOG.trace("isNodeVlanReady: node: {}, eth missing", bridgeNode);
115             return false;
116         }
117
118         return isNodeL3Ready(bridgeNode, ovsdbNode);
119     }
120
121     public boolean isNodeL3Ready(Node bridgeNode, Node ovsdbNode) {
122         Preconditions.checkNotNull(configurationService);
123         boolean ready = false;
124         if (configurationService.isL3ForwardingEnabled()) {
125             final String brInt = configurationService.getIntegrationBridgeName();
126             final String brExt = configurationService.getExternalBridgeName();
127             final String portNameInt = configurationService.getPatchPortName(new ImmutablePair<>(brInt, brExt));
128             final String portNameExt = configurationService.getPatchPortName(new ImmutablePair<>(brExt, brInt));
129             Preconditions.checkNotNull(portNameInt);
130             Preconditions.checkNotNull(portNameExt);
131
132             if (southbound.isBridgeOnOvsdbNode(ovsdbNode, brExt)) {
133                 ready = isNetworkPatchCreated(bridgeNode, southbound.readBridgeNode(ovsdbNode, brExt));
134             } else {
135                 LOG.trace("isNodeL3Ready: node: {}, {} missing",
136                         bridgeNode, brExt);
137             }
138         } else {
139             ready = true;
140         }
141         return ready;
142     }
143
144     @Override
145     public void prepareNode(Node ovsdbNode) {
146         Preconditions.checkNotNull(configurationService);
147
148         try {
149             createIntegrationBridge(ovsdbNode);
150         } catch (Exception e) {
151             LOG.error("Error creating Integration Bridge on {}", ovsdbNode, e);
152             return;
153         }
154
155         try {
156             if (configurationService.isL3ForwardingEnabled()) {
157                 createExternalBridge(ovsdbNode);
158             }
159         } catch (Exception e) {
160             LOG.error("Error creating External Bridge on {}", ovsdbNode, e);
161             return;
162         }
163         // this node is an ovsdb node so it doesn't have a bridge
164         // so either look up the bridges or just wait for the bridge update to come in
165         // and add the flows there.
166         //networkingProviderManager.getProvider(node).initializeFlowRules(node);
167     }
168
169     /**
170      * Check if the full network setup is available. If not, create it.
171      */
172     @Override
173     public boolean createLocalNetwork (Node bridgeNode, NeutronNetwork network) {
174         boolean isCreated = false;
175         Node ovsdbNode = southbound.readOvsdbNode(bridgeNode);
176         if (ovsdbNode == null) {
177             //this should never happen
178             LOG.error("createLocalNetwork could not find ovsdbNode from bridge node " + bridgeNode);
179             return false;
180         }
181         if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
182             if (!isNodeVlanReady(bridgeNode, ovsdbNode, network)) {
183                 try {
184                     isCreated = createBridges(bridgeNode, ovsdbNode, network);
185                 } catch (Exception e) {
186                     LOG.error("Error creating internal vlan net network " + bridgeNode, e);
187                 }
188             } else {
189                 isCreated = true;
190             }
191         } else if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN) ||
192                    network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE)) {
193             if (!isNodeTunnelReady(bridgeNode, ovsdbNode)) {
194                 try {
195                     isCreated = createBridges(bridgeNode, ovsdbNode, network);
196                 } catch (Exception e) {
197                     LOG.error("Error creating internal vxlan/gre net network " + bridgeNode, e);
198                 }
199             } else {
200                 isCreated = true;
201             }
202         }
203         return isCreated;
204     }
205
206
207
208     @Override
209     public String getExternalInterfaceName (Node node, String extNetwork) {
210         String phyIf = null;
211         String providerMaps = southbound.getOtherConfig(node, OvsdbTables.OPENVSWITCH,
212                 configurationService.getProviderMappingsKey());
213         if (providerMaps != null) {
214             for (String map : providerMaps.split(",")) {
215                 String[] pair = map.split(":");
216                 if (pair[0].equals(extNetwork)) {
217                     phyIf = pair[1];
218                     break;
219                 }
220             }
221         }
222         if (phyIf == null) {
223             LOG.error("External interface not found for Node: {}, Network {}",
224                     node, extNetwork);
225         }
226         else {
227             LOG.info("External interface found for Node: {}, Network {} is {}",node,extNetwork,phyIf);
228         }
229         return phyIf;
230     }
231
232
233
234     @Override
235     public String getPhysicalInterfaceName (Node node, String physicalNetwork) {
236         String phyIf = null;
237         String providerMaps = southbound.getOtherConfig(node, OvsdbTables.OPENVSWITCH,
238                 configurationService.getProviderMappingsKey());
239         if (providerMaps == null) {
240             providerMaps = configurationService.getDefaultProviderMapping();
241         }
242
243         if (providerMaps != null) {
244             for (String map : providerMaps.split(",")) {
245                 String[] pair = map.split(":");
246                 if (pair[0].equals(physicalNetwork)) {
247                     phyIf = pair[1];
248                     break;
249                 }
250             }
251         }
252
253         if (phyIf == null) {
254             LOG.error("Physical interface not found for Node: {}, Network {}",
255                     node, physicalNetwork);
256         }
257
258         return phyIf;
259     }
260
261     @Override
262     public List<String> getAllPhysicalInterfaceNames(Node node) {
263         List<String> phyIfName = Lists.newArrayList();
264         String providerMaps = southbound.getOtherConfig(node, OvsdbTables.OPENVSWITCH,
265                 configurationService.getProviderMappingsKey());
266         if (providerMaps == null) {
267             providerMaps = configurationService.getDefaultProviderMapping();
268         }
269
270         if (providerMaps != null) {
271             for (String map : providerMaps.split(",")) {
272                 String[] pair = map.split(":");
273                 phyIfName.add(pair[1]);
274             }
275         }
276
277         return phyIfName;
278     }
279
280     /**
281      * Returns true if a patch port exists between the Integration Bridge and Network Bridge
282      */
283     private boolean isNetworkPatchCreated(Node intBridge, Node netBridge) {
284         Preconditions.checkNotNull(configurationService);
285
286         boolean isPatchCreated = false;
287
288         String portName = configurationService.getPatchPortName(new ImmutablePair<>(intBridge, netBridge));
289         if (isPortOnBridge(intBridge, portName)) {
290             portName = configurationService.getPatchPortName(new ImmutablePair<>(netBridge, intBridge));
291             if (isPortOnBridge(netBridge, portName)) {
292                 isPatchCreated = true;
293             }
294         }
295
296         return isPatchCreated;
297     }
298
299     /**
300      * Creates the Integration Bridge
301      */
302     private boolean createIntegrationBridge(Node ovsdbNode) {
303         Preconditions.checkNotNull(configurationService);
304
305         if (!addBridge(ovsdbNode, configurationService.getIntegrationBridgeName())) {
306             LOG.debug("Integration Bridge Creation failed");
307             return false;
308         }
309         return true;
310     }
311
312     private boolean createExternalBridge(Node ovsdbNode) {
313         Preconditions.checkNotNull(configurationService);
314
315         if (!addBridge(ovsdbNode, configurationService.getExternalBridgeName())) {
316             LOG.debug("External Bridge Creation failed");
317             return false;
318         }
319         return true;
320     }
321
322     /**
323      * Create and configure bridges for all network types and OpenFlow versions.
324      *
325        OF 1.0 vlan:
326        Bridge br-int
327             Port patch-net
328                 Interface patch-net
329                     type: patch
330                     options: {peer=patch-int}
331             Port br-int
332                 Interface br-int
333                     type: internal
334        Bridge br-net
335             Port "eth1"
336                 Interface "eth1"
337             Port patch-int
338                 Interface patch-int
339                     type: patch
340                     options: {peer=patch-net}
341             Port br-net
342                 Interface br-net
343                     type: internal
344
345        OF 1.0 tunnel:
346        Bridge br-int
347             Port patch-net
348                 Interface patch-net
349                     type: patch
350                     options: {peer=patch-int}
351             Port br-int
352                 Interface br-int
353                     type: internal
354        Bridge "br-net"
355             Port patch-int
356                 Interface patch-int
357                     type: patch
358                     options: {peer=patch-net}
359             Port br-net
360                 Interface br-net
361                     type: internal
362
363        OF 1.3 vlan:
364        Bridge br-int
365             Port "eth1"
366                 Interface "eth1"
367             Port br-int
368                 Interface br-int
369                     type: internal
370
371        OF 1.3 tunnel:
372        Bridge br-int
373             Port br-int
374                 Interface br-int
375                     type: internal
376      */
377     private boolean createBridges(Node bridgeNode, Node ovsdbNode, NeutronNetwork network) {
378         Preconditions.checkNotNull(configurationService);
379         Preconditions.checkNotNull(networkingProviderManager);
380
381         LOG.debug("createBridges: node: {}, network type: {}", bridgeNode, network.getProviderNetworkType());
382
383         final String brInt = configurationService.getIntegrationBridgeName();
384         if (! createIntegrationBridge(ovsdbNode)) {
385             LOG.debug("{} Bridge creation failed", brInt);
386             return false;
387         }
388
389         if (configurationService.isL3ForwardingEnabled()) {
390             final String brExt = configurationService.getExternalBridgeName();
391             if (! createExternalBridge(ovsdbNode)) {
392                 LOG.error("{} Bridge creation failed", brExt);
393                 return false;
394             }
395
396             //get two patch port names
397             final String portNameInt = configurationService.getPatchPortName(new ImmutablePair<>(brInt, brExt));
398             final String portNameExt = configurationService.getPatchPortName(new ImmutablePair<>(brExt, brInt));
399             Preconditions.checkNotNull(portNameInt);
400             Preconditions.checkNotNull(portNameExt);
401
402             if (!addPatchPort(bridgeNode, brInt, portNameInt, portNameExt)) {
403                 LOG.error("Add Port {} to Bridge {} failed", portNameInt, brInt);
404                 return false;
405             }
406             Node extBridgeNode = southbound.readBridgeNode(ovsdbNode, brExt);
407             Preconditions.checkNotNull(extBridgeNode);
408             if (!addPatchPort(extBridgeNode, brExt, portNameExt, portNameInt)) {
409                 LOG.error("Add Port {} to Bridge {} failed", portNameExt, brExt);
410                 return false;
411             }
412             String extNetName = getExternalInterfaceName(extBridgeNode, brExt);
413             if ( extNetName != null) {
414                 if (!addPortToBridge(extBridgeNode, brExt, extNetName)) {
415                     LOG.error("Add External Port {} to Bridge {} failed", extNetName, brExt);
416                     return false;
417                 }
418             LOG.info("Add External Port {} to Ext Bridge {} success", extNetName, brExt);
419             }
420         }
421         /* For vlan network types add physical port to br-int. */
422         if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
423             String phyNetName = this.getPhysicalInterfaceName(bridgeNode, network.getProviderPhysicalNetwork());
424             if (!addPortToBridge(bridgeNode, brInt, phyNetName)) {
425                 LOG.debug("Add Port {} to Bridge {} failed", phyNetName, brInt);
426                 return false;
427             }
428         }
429
430         LOG.info("createBridges: node: {}, status: success", bridgeNode);
431         return true;
432     }
433
434     /**
435      * Add a Port to a Bridge
436      */
437     private boolean addPortToBridge (Node node, String bridgeName, String portName) {
438         boolean rv = true;
439
440         if (southbound.extractTerminationPointAugmentation(node, portName) == null) {
441             rv = southbound.addTerminationPoint(node, bridgeName, portName, null);
442
443             if (rv) {
444                 LOG.info("addPortToBridge: node: {}, bridge: {}, portname: {} status: success",
445                         node.getNodeId().getValue(), bridgeName, portName);
446             } else {
447                 LOG.error("addPortToBridge: node: {}, bridge: {}, portname: {} status: FAILED",
448                         node.getNodeId().getValue(), bridgeName, portName);
449             }
450         } else {
451             LOG.trace("addPortToBridge: node: {}, bridge: {}, portname: {} status: not_needed",
452                     node.getNodeId().getValue(), bridgeName, portName);
453         }
454
455         return rv;
456     }
457
458     /**
459      * Add a Patch Port to a Bridge
460      */
461     private boolean addPatchPort (Node node, String bridgeName, String portName, String peerPortName) {
462         boolean rv = true;
463
464         if (southbound.extractTerminationPointAugmentation(node, portName) == null) {
465             rv = southbound.addPatchTerminationPoint(node, bridgeName, portName, peerPortName);
466
467             if (rv) {
468                 LOG.info("addPatchPort: node: {}, bridge: {}, portname: {} peer: {} status: success",
469                         node.getNodeId().getValue(), bridgeName, portName, peerPortName);
470             } else {
471                 LOG.error("addPatchPort: node: {}, bridge: {}, portname: {} peer: {} status: FAILED",
472                         node.getNodeId().getValue(), bridgeName, portName, peerPortName);
473             }
474         } else {
475             LOG.trace("addPatchPort: node: {}, bridge: {}, portname: {} peer: {} status: not_needed",
476                     node.getNodeId().getValue(), bridgeName, portName, peerPortName);
477         }
478
479         return rv;
480     }
481
482     /**
483      * Add Bridge to a Node
484      */
485     private boolean addBridge(Node ovsdbNode, String bridgeName) {
486         boolean rv = true;
487         if ((!southbound.isBridgeOnOvsdbNode(ovsdbNode, bridgeName)) ||
488                 (southbound.getBridgeFromConfig(ovsdbNode, bridgeName) == null)) {
489             Class<? extends DatapathTypeBase> dpType = null;
490             if (configurationService.isUserSpaceEnabled()) {
491                 dpType = DatapathTypeNetdev.class;
492             }
493             rv = southbound.addBridge(ovsdbNode, bridgeName, getControllersFromOvsdbNode(ovsdbNode), dpType);
494         }
495         return rv;
496     }
497
498     private String getControllerIPAddress() {
499         String addressString = ConfigProperties.getProperty(this.getClass(), "ovsdb.controller.address");
500         if (addressString != null) {
501             try {
502                 if (InetAddress.getByName(addressString) != null) {
503                     return addressString;
504                 }
505             } catch (UnknownHostException e) {
506                 LOG.error("Host {} is invalid", addressString);
507             }
508         }
509
510         addressString = ConfigProperties.getProperty(this.getClass(), "of.address");
511         if (addressString != null) {
512             try {
513                 if (InetAddress.getByName(addressString) != null) {
514                     return addressString;
515                 }
516             } catch (UnknownHostException e) {
517                 LOG.error("Host {} is invalid", addressString);
518             }
519         }
520
521         return null;
522     }
523
524     private short getControllerOFPort() {
525         short openFlowPort = Constants.OPENFLOW_PORT;
526         String portString = ConfigProperties.getProperty(this.getClass(), "of.listenPort");
527         if (portString != null) {
528             try {
529                 openFlowPort = Short.parseShort(portString);
530             } catch (NumberFormatException e) {
531                 LOG.warn("Invalid port:{}, use default({})", portString,
532                         openFlowPort);
533             }
534         }
535         return openFlowPort;
536     }
537
538     private List<String> getControllersFromOvsdbNode(Node node) {
539         List<String> controllersStr = new ArrayList<>();
540
541         String controllerIpStr = getControllerIPAddress();
542         if (controllerIpStr != null) {
543             // If codepath makes it here, the ip address to be used was explicitly provided.
544             // Being so, also fetch openflowPort provided via ConfigProperties.
545             controllersStr.add(Constants.OPENFLOW_CONNECTION_PROTOCOL
546                     + ":" + controllerIpStr + ":" + getControllerOFPort());
547         } else {
548             // Check if ovsdb node has manager entries
549             OvsdbNodeAugmentation ovsdbNodeAugmentation = southbound.extractOvsdbNode(node);
550             if (ovsdbNodeAugmentation != null) {
551                 List<ManagerEntry> managerEntries = ovsdbNodeAugmentation.getManagerEntry();
552                 if (managerEntries != null && !managerEntries.isEmpty()) {
553                     for (ManagerEntry managerEntry : managerEntries) {
554                         if (managerEntry == null || managerEntry.getTarget() == null) {
555                             continue;
556                         }
557                         String[] tokens = managerEntry.getTarget().getValue().split(":");
558                         if (tokens.length == 3 && tokens[0].equalsIgnoreCase("tcp")) {
559                             controllersStr.add(Constants.OPENFLOW_CONNECTION_PROTOCOL
560                                     + ":" + tokens[1] + ":" + getControllerOFPort());
561                         } else if (tokens[0].equalsIgnoreCase("ptcp")) {
562                             ConnectionInfo connectionInfo = ovsdbNodeAugmentation.getConnectionInfo();
563                             if (connectionInfo != null && connectionInfo.getLocalIp() != null) {
564                                 controllerIpStr = String.valueOf(connectionInfo.getLocalIp().getValue());
565                                 controllersStr.add(Constants.OPENFLOW_CONNECTION_PROTOCOL
566                                         + ":" + controllerIpStr + ":" + Constants.OPENFLOW_PORT);
567                             } else {
568                                 LOG.warn("Ovsdb Node does not contain connection info: {}", node);
569                             }
570                         } else {
571                             LOG.trace("Skipping manager entry {} for node {}",
572                                     managerEntry.getTarget(), node.getNodeId().getValue());
573                         }
574                     }
575                 } else {
576                     LOG.warn("Ovsdb Node does not contain manager entries : {}", node);
577                 }
578             }
579         }
580
581         if (controllersStr.isEmpty()) {
582             // Neither user provided ip nor ovsdb node has manager entries. Lets use local machine ip address.
583             LOG.debug("Use local machine ip address as a OpenFlow Controller ip address");
584             controllerIpStr = getLocalControllerHostIpAddress();
585             if (controllerIpStr != null) {
586                 controllersStr.add(Constants.OPENFLOW_CONNECTION_PROTOCOL
587                         + ":" + controllerIpStr + ":" + Constants.OPENFLOW_PORT);
588             }
589         }
590
591         if (controllersStr.isEmpty()) {
592             LOG.warn("Failed to determine OpenFlow controller ip address");
593         } else if (LOG.isDebugEnabled()) {
594             controllerIpStr = "";
595             for (String currControllerIpStr : controllersStr) {
596                 controllerIpStr += " " + currControllerIpStr;
597             }
598             LOG.debug("Found {} OpenFlow Controller(s) :{}", controllersStr.size(), controllerIpStr);
599         }
600
601         return controllersStr;
602     }
603
604     private String getLocalControllerHostIpAddress() {
605         String ipaddress = null;
606         try{
607             for (Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();ifaces.hasMoreElements();){
608                 NetworkInterface iface = ifaces.nextElement();
609
610                 for (Enumeration<InetAddress> inetAddrs = iface.getInetAddresses(); inetAddrs.hasMoreElements();) {
611                     InetAddress inetAddr = inetAddrs.nextElement();
612                     if (!inetAddr.isLoopbackAddress() && inetAddr.isSiteLocalAddress()) {
613                         ipaddress = inetAddr.getHostAddress();
614                         break;
615                     }
616                 }
617             }
618         }catch (Exception e){
619             LOG.warn("Exception while fetching local host ip address ", e);
620         }
621         return ipaddress;
622     }
623
624     @Override
625     public void setDependencies(ServiceReference serviceReference) {
626         configurationService =
627                 (ConfigurationService) ServiceHelper.getGlobalInstance(ConfigurationService.class, this);
628         networkingProviderManager =
629                 (NetworkingProviderManager) ServiceHelper.getGlobalInstance(NetworkingProviderManager.class, this);
630         southbound =
631                 (Southbound) ServiceHelper.getGlobalInstance(Southbound.class, this);
632     }
633
634     @Override
635     public void setDependencies(Object impl) {
636     }
637 }