Bump upstreams for 2022.09 Chlorine
[ovsdb.git] / southbound / southbound-impl / src / main / java / org / opendaylight / ovsdb / southbound / transactions / md / OvsdbBridgeUpdateCommand.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, 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 package org.opendaylight.ovsdb.southbound.transactions.md;
9
10 import static java.util.Objects.requireNonNull;
11 import static org.opendaylight.ovsdb.southbound.SouthboundUtil.schemaMismatchLog;
12
13 import com.google.common.annotations.VisibleForTesting;
14 import com.google.common.net.InetAddresses;
15 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
16 import java.net.InetAddress;
17 import java.net.NetworkInterface;
18 import java.net.SocketException;
19 import java.util.ArrayList;
20 import java.util.Enumeration;
21 import java.util.List;
22 import java.util.Map;
23 import java.util.Map.Entry;
24 import java.util.Optional;
25 import java.util.Set;
26 import org.apache.commons.lang3.math.NumberUtils;
27 import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
28 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
29 import org.opendaylight.ovsdb.lib.error.SchemaVersionMismatchException;
30 import org.opendaylight.ovsdb.lib.message.TableUpdates;
31 import org.opendaylight.ovsdb.lib.notation.UUID;
32 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
33 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
34 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
35 import org.opendaylight.ovsdb.schema.openvswitch.Controller;
36 import org.opendaylight.ovsdb.southbound.InstanceIdentifierCodec;
37 import org.opendaylight.ovsdb.southbound.OvsdbConnectionInstance;
38 import org.opendaylight.ovsdb.southbound.SouthboundConstants;
39 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
40 import org.opendaylight.ovsdb.southbound.SouthboundUtil;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.DatapathId;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentationBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeName;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeProtocolBase;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeRef;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentationBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeRef;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeExternalIds;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeExternalIdsBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeExternalIdsKey;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeOtherConfigs;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeOtherConfigsBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeOtherConfigsKey;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntry;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntryKey;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagedNodeEntry;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagedNodeEntryBuilder;
64 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
65 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
66 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
67 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
68 import org.opendaylight.yangtools.yang.binding.DataObject;
69 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
70 import org.opendaylight.yangtools.yang.binding.util.BindingMap;
71 import org.slf4j.Logger;
72 import org.slf4j.LoggerFactory;
73
74 public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
75     private static final Logger LOG = LoggerFactory.getLogger(OvsdbBridgeUpdateCommand.class);
76     private final InstanceIdentifierCodec instanceIdentifierCodec;
77     private final Map<UUID,Bridge> updatedBridgeRows;
78     private final Map<UUID, Bridge> oldBridgeRows;
79     private final List<InstanceIdentifier<Node>> updatedBridges = new ArrayList<>();
80     private final Map<NodeId, Node> updatedBridgeNodes;
81
82     @SuppressFBWarnings(value = "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR", justification = "Non-final for mocking")
83     public OvsdbBridgeUpdateCommand(InstanceIdentifierCodec instanceIdentifierCodec, OvsdbConnectionInstance key,
84             TableUpdates updates, DatabaseSchema dbSchema,
85                                     Map<NodeId, Node> updatedBridgeNodes) {
86         super(key,updates,dbSchema);
87         this.instanceIdentifierCodec = instanceIdentifierCodec;
88         updatedBridgeRows = TyperUtils.extractRowsUpdated(Bridge.class, getUpdates(), getDbSchema());
89         oldBridgeRows = TyperUtils.extractRowsOld(Bridge.class, getUpdates(), getDbSchema());
90         this.updatedBridgeNodes = updatedBridgeNodes;
91     }
92
93     @Override
94     public void execute(ReadWriteTransaction transaction) {
95         if (updatedBridgeRows == null || updatedBridgeRows.isEmpty()) {
96             return;
97         }
98
99         final InstanceIdentifier<Node> connectionIId = getOvsdbConnectionInstance().getInstanceIdentifier();
100         Optional<Node> connection = SouthboundUtil.readNode(transaction, connectionIId);
101         if (!connection.isPresent()) {
102             return;
103         }
104
105         for (Entry<UUID, Bridge> entry : updatedBridgeRows.entrySet()) {
106             updateBridge(transaction, entry.getValue(), connectionIId);
107         }
108     }
109
110     @VisibleForTesting
111     void updateBridge(ReadWriteTransaction transaction,
112             Bridge bridge, InstanceIdentifier<Node> connectionIId) {
113         // Update the connection node to let it know it manages this bridge
114         Node connectionNode = buildConnectionNode(bridge);
115         transaction.merge(LogicalDatastoreType.OPERATIONAL, connectionIId, connectionNode);
116
117         // Update the bridge node with whatever data we are getting
118         InstanceIdentifier<Node> bridgeIid = getInstanceIdentifier(bridge);
119         Node bridgeNode = buildBridgeNode(bridge);
120         transaction.merge(LogicalDatastoreType.OPERATIONAL, bridgeIid, bridgeNode);
121         updatedBridges.add(bridgeIid);
122         updatedBridgeNodes.put(getNodeId(bridge), bridgeNode);
123         deleteEntries(transaction, protocolEntriesToRemove(bridgeIid, bridge));
124         deleteEntries(transaction, externalIdsToRemove(bridgeIid,bridge));
125         deleteEntries(transaction, bridgeOtherConfigsToRemove(bridgeIid,bridge));
126     }
127
128     @VisibleForTesting
129     <T extends DataObject> void deleteEntries(ReadWriteTransaction transaction,
130             List<InstanceIdentifier<T>> entryIids) {
131         for (InstanceIdentifier<T> entryIid : entryIids) {
132             transaction.delete(LogicalDatastoreType.OPERATIONAL, entryIid);
133         }
134     }
135
136     private List<InstanceIdentifier<BridgeOtherConfigs>> bridgeOtherConfigsToRemove(
137             InstanceIdentifier<Node> bridgeIid, Bridge bridge) {
138         requireNonNull(bridgeIid);
139         requireNonNull(bridge);
140         List<InstanceIdentifier<BridgeOtherConfigs>> result = new ArrayList<>();
141
142         Bridge oldBridge = oldBridgeRows.get(bridge.getUuid());
143
144         if (oldBridge != null && oldBridge.getOtherConfigColumn() != null) {
145             for (Entry<String, String> otherConfig:
146                 oldBridge.getOtherConfigColumn().getData().entrySet()) {
147                 if (bridge.getOtherConfigColumn() == null
148                         || !bridge.getOtherConfigColumn().getData().containsKey(otherConfig.getKey())) {
149                     InstanceIdentifier<BridgeOtherConfigs> iid = bridgeIid
150                             .augmentation(OvsdbBridgeAugmentation.class)
151                             .child(BridgeOtherConfigs.class,
152                                     new BridgeOtherConfigsKey(otherConfig.getKey()));
153                     result.add(iid);
154                 }
155             }
156         }
157         return result;
158     }
159
160     private List<InstanceIdentifier<BridgeExternalIds>> externalIdsToRemove(
161             InstanceIdentifier<Node> bridgeIid, Bridge bridge) {
162         requireNonNull(bridgeIid);
163         requireNonNull(bridge);
164         List<InstanceIdentifier<BridgeExternalIds>> result = new ArrayList<>();
165
166         Bridge oldBridge = oldBridgeRows.get(bridge.getUuid());
167
168         if (oldBridge != null && oldBridge.getExternalIdsColumn() != null) {
169             for (Entry<String, String> externalId:
170                 oldBridge.getExternalIdsColumn().getData().entrySet()) {
171                 if (bridge.getExternalIdsColumn() == null
172                         || !bridge.getExternalIdsColumn().getData().containsKey(externalId.getKey())) {
173                     InstanceIdentifier<BridgeExternalIds> iid = bridgeIid
174                             .augmentation(OvsdbBridgeAugmentation.class)
175                             .child(BridgeExternalIds.class,
176                                     new BridgeExternalIdsKey(externalId.getKey()));
177                     result.add(iid);
178                 }
179             }
180         }
181         return result;
182     }
183
184     private List<InstanceIdentifier<ProtocolEntry>> protocolEntriesToRemove(
185             InstanceIdentifier<Node> bridgeIid, Bridge bridge) {
186         requireNonNull(bridgeIid);
187         requireNonNull(bridge);
188         List<InstanceIdentifier<ProtocolEntry>> result = new ArrayList<>();
189         Bridge oldBridge = oldBridgeRows.get(bridge.getUuid());
190
191         try {
192             if (oldBridge != null && oldBridge.getProtocolsColumn() != null) {
193                 for (String protocol : oldBridge.getProtocolsColumn().getData()) {
194                     if (bridge.getProtocolsColumn() == null || !bridge.getProtocolsColumn().getData()
195                                 .contains(protocol)) {
196                         OvsdbBridgeProtocolBase proto = SouthboundConstants.OVSDB_PROTOCOL_MAP.inverse().get(protocol);
197                         InstanceIdentifier<ProtocolEntry> iid = bridgeIid
198                                 .augmentation(OvsdbBridgeAugmentation.class)
199                                 .child(ProtocolEntry.class, new ProtocolEntryKey(proto));
200                         result.add(iid);
201                     }
202                 }
203             }
204         } catch (SchemaVersionMismatchException e) {
205             schemaMismatchLog("protocols", "Bridge", e);
206         }
207         return result;
208     }
209
210     private Node buildConnectionNode(
211             Bridge bridge) {
212         //Update node with managed node reference
213         NodeBuilder connectionNode = new NodeBuilder();
214         connectionNode.setNodeId(getOvsdbConnectionInstance().getNodeId());
215
216         OvsdbNodeAugmentationBuilder ovsdbConnectionAugmentationBuilder = new OvsdbNodeAugmentationBuilder();
217         InstanceIdentifier<Node> bridgeIid =
218                 SouthboundMapper.createInstanceIdentifier(instanceIdentifierCodec, getOvsdbConnectionInstance(),
219                         bridge);
220         ManagedNodeEntry managedBridge = new ManagedNodeEntryBuilder().setBridgeRef(
221                 new OvsdbBridgeRef(bridgeIid)).build();
222         ovsdbConnectionAugmentationBuilder.setManagedNodeEntry(BindingMap.of(managedBridge));
223
224         connectionNode.addAugmentation(ovsdbConnectionAugmentationBuilder.build());
225
226         LOG.debug("Update node with bridge node ref {}",
227                 ovsdbConnectionAugmentationBuilder.getManagedNodeEntry().values().iterator().next());
228         return connectionNode.build();
229     }
230
231     private Node buildBridgeNode(Bridge bridge) {
232         NodeBuilder bridgeNodeBuilder = new NodeBuilder();
233         NodeId bridgeNodeId = getNodeId(bridge);
234         bridgeNodeBuilder.setNodeId(bridgeNodeId);
235         OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder();
236         ovsdbBridgeAugmentationBuilder.setBridgeName(new OvsdbBridgeName(bridge.getName()));
237         ovsdbBridgeAugmentationBuilder.setBridgeUuid(new Uuid(bridge.getUuid().toString()));
238         setDataPath(ovsdbBridgeAugmentationBuilder, bridge);
239         setDataPathType(ovsdbBridgeAugmentationBuilder, bridge);
240         setProtocol(ovsdbBridgeAugmentationBuilder, bridge);
241         setExternalIds(ovsdbBridgeAugmentationBuilder, bridge);
242         setOtherConfig(ovsdbBridgeAugmentationBuilder, bridge);
243         setFailMode(ovsdbBridgeAugmentationBuilder, bridge);
244         setOpenFlowNodeRef(ovsdbBridgeAugmentationBuilder, bridge);
245         setManagedBy(ovsdbBridgeAugmentationBuilder);
246         setAutoAttach(ovsdbBridgeAugmentationBuilder, bridge);
247         setStpEnalbe(ovsdbBridgeAugmentationBuilder,bridge);
248         bridgeNodeBuilder.addAugmentation(ovsdbBridgeAugmentationBuilder.build());
249
250         LOG.debug("Built with the intent to store bridge data {}",
251                 ovsdbBridgeAugmentationBuilder.build());
252         return bridgeNodeBuilder.build();
253     }
254
255     private static void setAutoAttach(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder, Bridge bridge) {
256         try {
257             if (bridge.getAutoAttachColumn() != null
258                     && bridge.getAutoAttachColumn().getData() != null
259                     && !bridge.getAutoAttachColumn().getData().isEmpty()) {
260                 Set<UUID> uuids = bridge.getAutoAttachColumn().getData();
261                 for (UUID uuid : uuids) {
262                     ovsdbBridgeAugmentationBuilder.setAutoAttach(new Uuid(uuid.toString()));
263                 }
264             }
265         } catch (SchemaVersionMismatchException e) {
266             schemaMismatchLog("auto_attach", "Bridge", e);
267         }
268     }
269
270     private void setManagedBy(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder) {
271         InstanceIdentifier<Node> connectionNodePath = getOvsdbConnectionInstance().getInstanceIdentifier();
272         ovsdbBridgeAugmentationBuilder.setManagedBy(new OvsdbNodeRef(connectionNodePath));
273     }
274
275     private static void setDataPathType(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder, Bridge bridge) {
276         ovsdbBridgeAugmentationBuilder.setDatapathType(
277                 SouthboundMapper.createDatapathType(bridge.getDatapathTypeColumn().getData()));
278     }
279
280     private static void setFailMode(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder, Bridge bridge) {
281         if (bridge.getFailModeColumn() != null
282                 && bridge.getFailModeColumn().getData() != null
283                 && !bridge.getFailModeColumn().getData().isEmpty()) {
284             String[] failmodeArray = new String[bridge.getFailModeColumn().getData().size()];
285             bridge.getFailModeColumn().getData().toArray(failmodeArray);
286             ovsdbBridgeAugmentationBuilder.setFailMode(
287                     SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get(failmodeArray[0]));
288         }
289     }
290
291     @VisibleForTesting
292     static void setOtherConfig(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder, Bridge bridge) {
293         Map<String, String> otherConfigs = bridge
294                 .getOtherConfigColumn().getData();
295         if (otherConfigs != null && !otherConfigs.isEmpty()) {
296             var otherConfigList = BindingMap.<BridgeOtherConfigsKey, BridgeOtherConfigs>orderedBuilder();
297             for (Entry<String, String> entry : otherConfigs.entrySet()) {
298                 String otherConfigKey = entry.getKey();
299                 String otherConfigValue = entry.getValue();
300                 if (otherConfigKey != null && otherConfigValue != null) {
301                     otherConfigList.add(new BridgeOtherConfigsBuilder()
302                             .setBridgeOtherConfigKey(otherConfigKey)
303                             .setBridgeOtherConfigValue(otherConfigValue)
304                             .build());
305                 }
306             }
307             ovsdbBridgeAugmentationBuilder.setBridgeOtherConfigs(otherConfigList.build());
308         }
309     }
310
311     @VisibleForTesting
312     static void setExternalIds(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder, Bridge bridge) {
313         Map<String, String> externalIds = bridge.getExternalIdsColumn().getData();
314         if (externalIds != null && !externalIds.isEmpty()) {
315             var externalIdsList = BindingMap.<BridgeExternalIdsKey, BridgeExternalIds>orderedBuilder();
316             for (Entry<String, String> entry : externalIds.entrySet()) {
317                 String externalIdKey = entry.getKey();
318                 String externalIdValue = entry.getValue();
319                 if (externalIdKey != null && externalIdValue != null) {
320                     externalIdsList.add(new BridgeExternalIdsBuilder()
321                             .setBridgeExternalIdKey(externalIdKey)
322                             .setBridgeExternalIdValue(externalIdValue)
323                             .build());
324                 }
325             }
326             ovsdbBridgeAugmentationBuilder.setBridgeExternalIds(externalIdsList.build());
327         }
328     }
329
330     @VisibleForTesting
331     static void setProtocol(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder, Bridge bridge) {
332         List<ProtocolEntry> protocols = SouthboundMapper.createMdsalProtocols(bridge);
333         if (!protocols.isEmpty()) {
334             ovsdbBridgeAugmentationBuilder.setProtocolEntry(BindingMap.of(protocols));
335         }
336     }
337
338     @VisibleForTesting
339     static void setDataPath(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder, Bridge bridge) {
340         DatapathId dpid = SouthboundMapper.createDatapathId(bridge);
341         if (dpid != null) {
342             ovsdbBridgeAugmentationBuilder.setDatapathId(dpid);
343         }
344     }
345
346     private static void setStpEnalbe(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder,
347                               Bridge bridge) {
348         if (bridge.getStpEnableColumn() != null) {
349             Boolean stpEnable = bridge.getStpEnableColumn().getData();
350             if (stpEnable != null) {
351                 ovsdbBridgeAugmentationBuilder.setStpEnable(stpEnable);
352             }
353         }
354     }
355
356     private void setOpenFlowNodeRef(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder, Bridge bridge) {
357         Map<UUID, Controller> updatedControllerRows =
358                 TyperUtils.extractRowsUpdated(Controller.class, getUpdates(), getDbSchema());
359         LOG.debug("setOpenFlowNodeRef: updatedControllerRows: {}", updatedControllerRows);
360         for (ControllerEntry controllerEntry: SouthboundMapper.createControllerEntries(bridge, updatedControllerRows)) {
361             if (controllerEntry != null
362                 && controllerEntry.getIsConnected() != null && controllerEntry.getIsConnected()) {
363                 String [] controllerTarget = controllerEntry.getTarget().getValue().split(":");
364                 IpAddress bridgeControllerIpAddress = null;
365                 for (String targetElement : controllerTarget) {
366                     if (InetAddresses.isInetAddress(targetElement)) {
367                         bridgeControllerIpAddress = parseIpAddress(targetElement);
368                         continue;
369                     }
370                     if (NumberUtils.isCreatable(targetElement)) {
371                         continue;
372                     }
373                 }
374                 try {
375                     Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
376                 networkInterfacesLoop:
377                     while (networkInterfaces.hasMoreElements()) {
378                         NetworkInterface networkInterface = networkInterfaces.nextElement();
379                         Enumeration<InetAddress> networkInterfaceAddresses = networkInterface.getInetAddresses();
380                         while (networkInterfaceAddresses.hasMoreElements()) {
381                             InetAddress networkInterfaceAddress = networkInterfaceAddresses.nextElement();
382                             if (bridgeControllerIpAddress.getIpv4Address().getValue()
383                                     .equals(networkInterfaceAddress.getHostAddress())) {
384                                 ovsdbBridgeAugmentationBuilder.setBridgeOpenflowNodeRef(
385                                         getOvsdbConnectionInstance().getInstanceIdentifier());
386                                 break networkInterfacesLoop;
387                             }
388                         }
389                     }
390                 } catch (SocketException e) {
391                     LOG.warn("Error getting local ip address", e);
392                 }
393             }
394         }
395     }
396
397     private static IpAddress parseIpAddress(final String ipAddress) {
398         try {
399             return new IpAddress(new Ipv4Address(ipAddress));
400         } catch (IllegalArgumentException e) {
401             LOG.debug("Failed to interpret {} as an Ipv4Address", ipAddress, e);
402         }
403         return new IpAddress(new Ipv6Address(ipAddress));
404     }
405
406     private InstanceIdentifier<Node> getInstanceIdentifier(Bridge bridge) {
407         return SouthboundMapper.createInstanceIdentifier(instanceIdentifierCodec, getOvsdbConnectionInstance(),
408                 bridge);
409     }
410
411     private NodeId getNodeId(Bridge bridge) {
412         NodeKey nodeKey = getInstanceIdentifier(bridge).firstKeyOf(Node.class);
413         return nodeKey.getNodeId();
414     }
415
416     @Override
417     public void onSuccess() {
418         for (InstanceIdentifier<Node> updatedBridge : updatedBridges) {
419             LOG.debug("Updated bridge {} in operational datastore", updatedBridge);
420         }
421     }
422
423     @Override
424     public void onFailure(Throwable throwable) {
425         for (InstanceIdentifier<Node> updatedBridge : updatedBridges) {
426             LOG.error("Failed to update bridge {} in operational datastore", updatedBridge);
427         }
428     }
429 }