More southbound migration for netvirt
[ovsdb.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / impl / BridgeConfigurationManagerImpl.java
1 /*
2  * Copyright (C) 2013 Red Hat, Inc.
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  * Authors : Madhu Venugopal, Brent Salisbury, Sam Hague
9  */
10 package org.opendaylight.ovsdb.openstack.netvirt.impl;
11
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.neutron.spi.NeutronNetwork;
14 import org.opendaylight.ovsdb.lib.error.SchemaVersionMismatchException;
15 import org.opendaylight.ovsdb.lib.notation.Row;
16 import org.opendaylight.ovsdb.lib.notation.UUID;
17 import org.opendaylight.ovsdb.openstack.netvirt.NetworkHandler;
18 import org.opendaylight.ovsdb.openstack.netvirt.api.*;
19 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
20 import org.opendaylight.ovsdb.schema.openvswitch.Interface;
21 import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
22 import org.opendaylight.ovsdb.schema.openvswitch.Port;
23 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeName;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
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 import com.google.common.collect.Maps;
33 import org.apache.commons.lang3.tuple.ImmutablePair;
34 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38 import java.util.HashSet;
39 import java.util.List;
40 import java.util.Map;
41 import java.util.Set;
42
43 public class BridgeConfigurationManagerImpl implements BridgeConfigurationManager {
44     static final Logger LOGGER = LoggerFactory.getLogger(BridgeConfigurationManagerImpl.class);
45
46     // The implementation for each of these services is resolved by the OSGi Service Manager
47     private volatile ConfigurationService configurationService;
48     private volatile NetworkingProviderManager networkingProviderManager;
49     private volatile OvsdbConfigurationService ovsdbConfigurationService;
50
51     public BridgeConfigurationManagerImpl() {
52     }
53
54     @Override
55     public String getBridgeUuid(Node node, String bridgeName) {
56         return MdsalUtils.getBridgeUuid(node, bridgeName).toString();
57     }
58
59     @Override
60     public boolean isNodeNeutronReady(Node node) {
61         Preconditions.checkNotNull(configurationService);
62         return this.getBridgeUuid(node, configurationService.getIntegrationBridgeName()) != null;
63     }
64
65     @Override
66     public boolean isNodeOverlayReady(Node node) {
67         /* TODO SB_MIGRATION */
68         Preconditions.checkNotNull(ovsdbConfigurationService);
69         return this.isNodeNeutronReady(node)
70                && this.getBridgeUuid(node, configurationService.getNetworkBridgeName()) != null;
71     }
72
73     @Override
74     public boolean isPortOnBridge (Node node, Bridge bridge, String portName) {
75         /* TODO SB_MIGRATION */
76         Preconditions.checkNotNull(ovsdbConfigurationService);
77         for (UUID portsUUID : bridge.getPortsColumn().getData()) {
78             try {
79                 Row portRow = ovsdbConfigurationService.getRow(node,
80                                                         ovsdbConfigurationService.getTableName(node, Port.class),
81                                                         portsUUID.toString());
82
83                 Port port = ovsdbConfigurationService.getTypedRow(node, Port.class, portRow);
84                 if ((port != null) && port.getName().equalsIgnoreCase(portName)) {
85                     return true;
86                 }
87             } catch (Exception e) {
88                 LOGGER.error("Error getting port {} for bridge domain {}/{}", portsUUID, node, bridge.getName(), e);
89             }
90         }
91         return false;
92     }
93
94     @Override
95     public boolean isNodeTunnelReady(Node node) {
96         Preconditions.checkNotNull(configurationService);
97         Preconditions.checkNotNull(networkingProviderManager);
98
99         /* Is br-int created? */
100         Bridge intBridge = this.getBridge(node, configurationService.getIntegrationBridgeName());
101         if (intBridge == null) {
102             return false;
103         }
104
105         if (networkingProviderManager.getProvider(node).hasPerTenantTunneling()) {
106             /* Is br-net created? */
107             Bridge netBridge = this.getBridge(node, configurationService.getNetworkBridgeName());
108             if (netBridge == null) {
109                 return false;
110             }
111
112             if (!isNetworkPatchCreated(node, intBridge, netBridge)) {
113                 return false;
114             }
115         }
116         return true;
117     }
118
119     @Override
120     public boolean isNodeVlanReady(Node node, NeutronNetwork network) {
121         /* TODO SB_MIGRATION */
122         Preconditions.checkNotNull(ovsdbConfigurationService);
123         Preconditions.checkNotNull(networkingProviderManager);
124
125         /* is br-int created */
126         Bridge intBridge = this.getBridge(node, configurationService.getIntegrationBridgeName());
127         if (intBridge == null) {
128             LOGGER.trace("isNodeVlanReady: node: {}, br-int missing", node);
129             return false;
130         }
131
132         if (networkingProviderManager.getProvider(node).hasPerTenantTunneling()) {
133             /* is br-net created? */
134             Bridge netBridge = this.getBridge(node, configurationService.getNetworkBridgeName());
135
136             if (netBridge == null) {
137                 LOGGER.trace("isNodeVlanReady: node: {}, br-net missing", node);
138                 return false;
139             }
140
141             if (!isNetworkPatchCreated(node, intBridge, netBridge)) {
142                 LOGGER.trace("isNodeVlanReady: node: {}, patch missing", node);
143                 return false;
144             }
145
146             /* Check if physical device is added to br-net. */
147             String phyNetName = this.getPhysicalInterfaceName(node, network.getProviderPhysicalNetwork());
148             if (isPortOnBridge(node, netBridge, phyNetName)) {
149                 return true;
150             }
151         } else {
152             /* Check if physical device is added to br-int. */
153             String phyNetName = this.getPhysicalInterfaceName(node, network.getProviderPhysicalNetwork());
154             if (isPortOnBridge(node, intBridge, phyNetName)) {
155                 return true;
156             }
157         }
158
159         LOGGER.trace("isNodeVlanReady: node: {}, eth missing", node);
160         return false;
161     }
162
163     @Override
164     public void prepareNode(Node node) {
165         Preconditions.checkNotNull(networkingProviderManager);
166
167         try {
168             this.createIntegrationBridge(node);
169         } catch (Exception e) {
170             LOGGER.error("Error creating Integration Bridge on {}", node, e);
171             return;
172         }
173         networkingProviderManager.getProvider(node).initializeFlowRules(node);
174     }
175
176     /*
177      * Check if the full network setup is available. If not, create it.
178      */
179     @Override
180     public boolean createLocalNetwork (Node node, NeutronNetwork network) {
181         boolean isCreated = false;
182         if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
183             if (!this.isNodeVlanReady(node, network)) {
184                 try {
185                     isCreated = this.createBridges(node, network);
186                 } catch (Exception e) {
187                     LOGGER.error("Error creating internal net network " + node, e);
188                 }
189             } else {
190                 isCreated = true;
191             }
192         } else if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN) ||
193                    network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE)) {
194             if (!this.isNodeTunnelReady(node)) {
195                 try {
196                     isCreated = this.createBridges(node, network);
197                 } catch (Exception e) {
198                     LOGGER.error("Error creating internal net network " + node, e);
199                 }
200             } else {
201                 isCreated = true;
202             }
203         }
204         return isCreated;
205     }
206
207     @Override
208     public String getPhysicalInterfaceName (Node node, String physicalNetwork) {
209         String phyIf = null;
210         /* TODO SB_MIGRATION */
211         try {
212             Map<String, Row> ovsTable =
213                     ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, OpenVSwitch.class));
214
215             if (ovsTable == null) {
216                 LOGGER.error("OpenVSwitch table is null for Node {} ", node);
217                 return null;
218             }
219
220             // Loop through all the Open_vSwitch rows looking for the first occurrence of other_config.
221             // The specification does not restrict the number of rows so we choose the first we find.
222             for (Row row : ovsTable.values()) {
223                 String providerMaps;
224                 OpenVSwitch ovsRow = ovsdbConfigurationService.getTypedRow(node, OpenVSwitch.class, row);
225                 Map<String, String> configs = ovsRow.getOtherConfigColumn().getData();
226
227                 if (configs == null) {
228                     LOGGER.debug("OpenVSwitch table is null for Node {} ", node);
229                     continue;
230                 }
231
232                 providerMaps = configs.get(configurationService.getProviderMappingsKey());
233                 if (providerMaps == null) {
234                     providerMaps = configurationService.getDefaultProviderMapping();
235                 }
236
237                 if (providerMaps != null) {
238                     for (String map : providerMaps.split(",")) {
239                         String[] pair = map.split(":");
240                         if (pair[0].equals(physicalNetwork)) {
241                             phyIf = pair[1];
242                             break;
243                         }
244                     }
245                 }
246
247                 if (phyIf != null) {
248                     break;
249                 }
250             }
251         } catch (Exception e) {
252             LOGGER.error("Unable to find physical interface for Node: {}, Network {}",
253                          node, physicalNetwork, e);
254         }
255
256         if (phyIf == null) {
257             LOGGER.error("Physical interface not found for Node: {}, Network {}",
258                          node, physicalNetwork);
259         }
260
261         return phyIf;
262     }
263
264     @Override
265     public List<String> getAllPhysicalInterfaceNames(Node node) {
266         List<String> phyIfName = Lists.newArrayList();
267         /* TODO SB_MIGRATION */
268         try {
269             Map<String, Row> ovsTable =
270                     ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, OpenVSwitch.class));
271
272             if (ovsTable == null) {
273                 LOGGER.error("OpenVSwitch table is null for Node {} ", node);
274                 return null;
275             }
276
277             // While there is only one entry in the HashMap, we can't access it by index...
278             for (Row row : ovsTable.values()) {
279                 String bridgeMaps;
280                 OpenVSwitch ovsRow = ovsdbConfigurationService.getTypedRow(node, OpenVSwitch.class, row);
281                 Map<String, String> configs = ovsRow.getOtherConfigColumn().getData();
282
283                 if (configs == null) {
284                     LOGGER.debug("OpenVSwitch table is null for Node {} ", node);
285                     continue;
286                 }
287
288                 bridgeMaps = configs.get(configurationService.getProviderMappingsKey());
289                 if (bridgeMaps == null) {
290                     bridgeMaps = configurationService.getDefaultProviderMapping();
291                 }
292
293                 if (bridgeMaps != null) {
294                     for (String map : bridgeMaps.split(",")) {
295                         String[] pair = map.split(":");
296                         phyIfName.add(pair[1]);
297                     }
298                 }
299             }
300         } catch (Exception e) {
301             LOGGER.error("Unable to find physical interface for Node: " + node, e);
302         }
303
304         LOGGER.debug("Physical interface for Node: {}, If: {}",
305                      node, phyIfName);
306
307         return phyIfName;
308     }
309
310     /**
311      * Returns the Bridge for a given node and bridgeName
312      */
313     public Bridge getBridge (Node node, String bridgeName) {
314         /* TODO SB_MIGRATION */
315         Preconditions.checkNotNull(ovsdbConfigurationService);
316         try {
317             Map<String, Row> bridgeTable =
318                     ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, Bridge.class));
319             if (bridgeTable != null) {
320                 for (String key : bridgeTable.keySet()) {
321                     Bridge bridge = ovsdbConfigurationService.getTypedRow(node, Bridge.class, bridgeTable.get(key));
322                     if (bridge.getName().equals(bridgeName)) {
323                         return bridge;
324                     }
325                 }
326             }
327         } catch (Exception e) {
328             LOGGER.error("Error getting Bridge Identifier for {} / {}", node, bridgeName, e);
329         }
330
331         return null;
332     }
333
334     /**
335      * Returns true if a patch port exists between the Integration Bridge and Network Bridge
336      */
337     private boolean isNetworkPatchCreated (Node node, Bridge intBridge, Bridge netBridge) {
338         Preconditions.checkNotNull(configurationService);
339
340         boolean isPatchCreated = false;
341
342         String portName = configurationService.getPatchPortName(new ImmutablePair<>(intBridge, netBridge));
343         if (isPortOnBridge(node, intBridge, portName)) {
344             portName = configurationService.getPatchPortName(new ImmutablePair<>(netBridge, intBridge));
345             if (isPortOnBridge(node, netBridge, portName)) {
346                 isPatchCreated = true;
347             }
348         }
349
350         return isPatchCreated;
351     }
352
353     /**
354      * Creates the Integration Bridge
355      */
356     private void createIntegrationBridge (Node node) throws Exception {
357         Preconditions.checkNotNull(configurationService);
358
359         String brIntName = configurationService.getIntegrationBridgeName();
360
361         Status status = addBridge(node, brIntName, null, null);
362         if (!status.isSuccess()) {
363             LOGGER.debug("Integration Bridge Creation Status: {}", status);
364         }
365     }
366
367     /**
368      * Create and configure bridges for all network types and OpenFlow versions.
369      *
370        OF 1.0 vlan:
371        Bridge br-int
372             Port patch-net
373                 Interface patch-net
374                     type: patch
375                     options: {peer=patch-int}
376             Port br-int
377                 Interface br-int
378                     type: internal
379        Bridge br-net
380             Port "eth1"
381                 Interface "eth1"
382             Port patch-int
383                 Interface patch-int
384                     type: patch
385                     options: {peer=patch-net}
386             Port br-net
387                 Interface br-net
388                     type: internal
389
390        OF 1.0 tunnel:
391        Bridge br-int
392             Port patch-net
393                 Interface patch-net
394                     type: patch
395                     options: {peer=patch-int}
396             Port br-int
397                 Interface br-int
398                     type: internal
399        Bridge "br-net"
400             Port patch-int
401                 Interface patch-int
402                     type: patch
403                     options: {peer=patch-net}
404             Port br-net
405                 Interface br-net
406                     type: internal
407
408        OF 1.3 vlan:
409        Bridge br-int
410             Port "eth1"
411                 Interface "eth1"
412             Port br-int
413                 Interface br-int
414                     type: internal
415
416        OF 1.3 tunnel:
417        Bridge br-int
418             Port br-int
419                 Interface br-int
420                     type: internal
421      */
422     private boolean createBridges(Node node, NeutronNetwork network) throws Exception {
423         Preconditions.checkNotNull(configurationService);
424         Preconditions.checkNotNull(networkingProviderManager);
425         Status status;
426
427         LOGGER.debug("createBridges: node: {}, network type: {}", node, network.getProviderNetworkType());
428
429         if (networkingProviderManager.getProvider(node).hasPerTenantTunneling()) { /* indicates OF 1.0 */
430             String brInt = configurationService.getIntegrationBridgeName();
431             String brNet = configurationService.getNetworkBridgeName();
432             String patchNet = configurationService.getPatchPortName(new ImmutablePair<>(brInt, brNet));
433             String patchInt = configurationService.getPatchPortName(new ImmutablePair<>(brNet, brInt));
434
435             status = this.addBridge(node, brInt, patchNet, patchInt);
436             if (!status.isSuccess()) {
437                 LOGGER.debug("{} Bridge Creation Status: {}", brInt, status);
438                 return false;
439             }
440             status = this.addBridge(node, brNet, patchInt, patchNet);
441             if (!status.isSuccess()) {
442                 LOGGER.debug("{} Bridge Creation Status: {}", brNet, status);
443                 return false;
444             }
445
446             /* For vlan network types add physical port to br-net. */
447             if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
448                 String phyNetName = this.getPhysicalInterfaceName(node, network.getProviderPhysicalNetwork());
449                 status = addPortToBridge(node, brNet, phyNetName);
450                 if (!status.isSuccess()) {
451                     LOGGER.debug("Add Port {} to Bridge {} Status: {}", phyNetName, brNet, status);
452                     return false;
453                 }
454             }
455         } else {
456             String brInt = configurationService.getIntegrationBridgeName();
457             status = this.addBridge(node, brInt, null, null);
458             if (!status.isSuccess()) {
459                 LOGGER.debug("{} Bridge Creation Status: {}", brInt, status);
460                 return false;
461             }
462
463             /* For vlan network types add physical port to br-int. */
464             if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
465                 String phyNetName = this.getPhysicalInterfaceName(node, network.getProviderPhysicalNetwork());
466                 status = addPortToBridge(node, brInt, phyNetName);
467                 if (!status.isSuccess()) {
468                     LOGGER.debug("Add Port {} to Bridge {} Status: {}", phyNetName, brInt, status);
469                     return false;
470                 }
471             }
472         }
473
474         LOGGER.debug("createNetNetwork: node: {}, status: success", node);
475         return true;
476     }
477
478     /**
479      * Add a Port to a Bridge
480      */
481     private Status addPortToBridge (Node node, String bridgeName, String portName) throws Exception {
482         /* TODO SB_MIGRATION */
483         Preconditions.checkNotNull(ovsdbConfigurationService);
484
485         LOGGER.debug("addPortToBridge: Adding port: {} to Bridge {}, Node {}", portName, bridgeName, node);
486
487         String bridgeUUID = this.getBridgeUuid(node, bridgeName);
488         if (bridgeUUID == null) {
489             LOGGER.error("addPortToBridge: Could not find Bridge {} in Node {}", bridgeName, node);
490             return new Status(StatusCode.NOTFOUND, "Could not find "+bridgeName+" in "+node);
491         }
492
493         /* Check if the port already exists. */
494         Row row = ovsdbConfigurationService
495                 .getRow(node, ovsdbConfigurationService.getTableName(node, Bridge.class), bridgeUUID);
496         Bridge bridge = ovsdbConfigurationService.getTypedRow(node, Bridge.class, row);
497         if (bridge != null) {
498             if (isPortOnBridge(node, bridge, portName)) {
499                 LOGGER.debug("addPortToBridge: Port {} already in Bridge {}, Node {}", portName, bridgeName, node);
500                 return new Status(StatusCode.SUCCESS);
501             }
502         } else {
503             LOGGER.error("addPortToBridge: Could not find Port {} in Bridge {}, Node {}", portName, bridgeName, node);
504             return new Status(StatusCode.NOTFOUND, "Could not find "+portName+" in "+bridgeName);
505         }
506
507         Port port = ovsdbConfigurationService.createTypedRow(node, Port.class);
508         port.setName(portName);
509         StatusWithUuid statusWithUuid =
510                 ovsdbConfigurationService.insertRow(node, port.getSchema().getName(), bridgeUUID, port.getRow());
511         if (!statusWithUuid.isSuccess()) {
512             LOGGER.error("addPortToBridge: Failed to add Port {} in Bridge {}, Node {}", portName, bridgeName, node);
513             return statusWithUuid;
514         }
515
516         String portUUID = statusWithUuid.getUuid().toString();
517         String interfaceUUID = null;
518         int timeout = 6;
519         while ((interfaceUUID == null) && (timeout > 0)) {
520             Row portRow = ovsdbConfigurationService.getRow(node, port.getSchema().getName(), portUUID);
521             port = ovsdbConfigurationService.getTypedRow(node, Port.class, portRow);
522             Set<UUID> interfaces = port.getInterfacesColumn().getData();
523             if (interfaces == null || interfaces.size() == 0) {
524                 // Wait for the OVSDB update to sync up the Local cache.
525                 Thread.sleep(500);
526                 timeout--;
527                 continue;
528             }
529             interfaceUUID = interfaces.toArray()[0].toString();
530             Row intf = ovsdbConfigurationService.getRow(node,
531                                                 ovsdbConfigurationService.getTableName(node, Interface.class), interfaceUUID);
532             if (intf == null) {
533                 interfaceUUID = null;
534             }
535         }
536
537         if (interfaceUUID == null) {
538             LOGGER.error("addPortToBridge: Cannot identify Interface for port {}/{}", portName, portUUID);
539             return new Status(StatusCode.INTERNALERROR);
540         }
541
542         return new Status(StatusCode.SUCCESS);
543     }
544
545     /**
546      * Add a Patch Port to a Bridge
547      */
548     private Status addPatchPort (Node node, String bridgeUUID, String portName, String peerPortName) throws Exception {
549         /* TODO SB_MIGRATION */
550         Preconditions.checkNotNull(ovsdbConfigurationService);
551
552         LOGGER.debug("addPatchPort: node: {}, bridgeUUID: {}, port: {}, peer: {}",
553                      node, bridgeUUID, portName, peerPortName);
554
555         /* Check if the port already exists. */
556         Row bridgeRow = ovsdbConfigurationService.getRow(node,
557                                                   ovsdbConfigurationService.getTableName(node, Bridge.class), bridgeUUID);
558         Bridge bridge = ovsdbConfigurationService.getTypedRow(node, Bridge.class, bridgeRow);
559         if (bridge != null) {
560             if (isPortOnBridge(node, bridge, portName)) {
561                 LOGGER.debug("addPatchPort: Port {} already in Bridge, Node {}", portName, node);
562                 return new Status(StatusCode.SUCCESS);
563             }
564         } else {
565             LOGGER.error("addPatchPort: Could not find Port {} in Bridge, Node {}", portName, node);
566             return new Status(StatusCode.NOTFOUND, "Could not find "+portName+" in Bridge");
567         }
568
569         Port patchPort = ovsdbConfigurationService.createTypedRow(node, Port.class);
570         patchPort.setName(portName);
571         // Create patch port and interface
572         StatusWithUuid statusWithUuid =
573                 ovsdbConfigurationService.insertRow(node, patchPort.getSchema().getName(), bridgeUUID, patchPort.getRow());
574         if (!statusWithUuid.isSuccess()) {
575             return statusWithUuid;
576         }
577
578         String patchPortUUID = statusWithUuid.getUuid().toString();
579
580         String interfaceUUID = null;
581         int timeout = 6;
582         while ((interfaceUUID == null) && (timeout > 0)) {
583             Row portRow = ovsdbConfigurationService.getRow(node, patchPort.getSchema().getName(), patchPortUUID);
584             patchPort = ovsdbConfigurationService.getTypedRow(node, Port.class, portRow);
585             Set<UUID> interfaces = patchPort.getInterfacesColumn().getData();
586             if (interfaces == null || interfaces.size() == 0) {
587                 // Wait for the OVSDB update to sync up the Local cache.
588                 Thread.sleep(500);
589                 timeout--;
590                 continue;
591             }
592             interfaceUUID = interfaces.toArray()[0].toString();
593         }
594
595         if (interfaceUUID == null) {
596             return new Status(StatusCode.INTERNALERROR);
597         }
598
599         Interface intf = ovsdbConfigurationService.createTypedRow(node, Interface.class);
600         intf.setType("patch");
601         Map<String, String> options = Maps.newHashMap();
602         options.put("peer", peerPortName);
603         intf.setOptions(options);
604         return ovsdbConfigurationService.updateRow(node,
605                                             intf.getSchema().getName(),
606                                             patchPortUUID,
607                                             interfaceUUID,
608                                             intf.getRow());
609
610     }
611
612     /**
613      * Add Bridge to a Node
614      */
615     private Status addBridge(Node node, String bridgeName,
616                              String localPatchName, String remotePatchName) throws Exception {
617         Preconditions.checkNotNull(networkingProviderManager);
618         /* TODO SB_MIGRATION */
619
620         //String bridgeUUID = getBridgeUuid(node, bridgeName);
621         MdsalUtils.addBridge(node, bridgeName);//sb will also add port and interface if this is a new bridge
622
623
624         /*// TODO use the bridge it code to add bridge
625         Bridge bridge = ovsdbConfigurationService.createTypedRow(node, Bridge.class);
626         Set<String> failMode = new HashSet<>();
627         failMode.add("secure");
628         bridge.setFailMode(failMode);
629
630         Set<String> protocols = new HashSet<>();
631
632         // ToDo: Plugin should expose an easy way to get the OVS Version or Schema Version
633         // or, alternatively it should not attempt to add set unsupported fields
634         //
635
636         try {
637             protocols.add(Constants.OPENFLOW13);
638             bridge.setProtocols(protocols);
639         } catch (SchemaVersionMismatchException e) {
640             LOGGER.info("Failed to add protocol.", e);
641         }
642
643         if (bridgeUUID == null) {
644             bridge.setName(bridgeName);
645
646             StatusWithUuid statusWithUuid = ovsdbConfigurationService.insertRow(node,
647                                                                          bridge.getSchema().getName(),
648                                                                          null,
649                                                                          bridge.getRow());
650             if (!statusWithUuid.isSuccess()) {
651                 return statusWithUuid;
652             }
653             bridgeUUID = statusWithUuid.getUuid().toString();
654             Port port = ovsdbConfigurationService.createTypedRow(node, Port.class);
655             port.setName(bridgeName);
656             Status status = ovsdbConfigurationService.insertRow(node, port.getSchema().getName(), bridgeUUID, port.getRow());
657             LOGGER.debug("addBridge: Inserting Bridge {} {} with protocols {} and status {}",
658                          bridgeName, bridgeUUID, protocols, status);
659         } else {
660             Status status = ovsdbConfigurationService.updateRow(node,
661                                                          bridge.getSchema().getName(),
662                                                          null,
663                                                          bridgeUUID,
664                                                          bridge.getRow());
665             LOGGER.debug("addBridge: Updating Bridge {} {} with protocols {} and status {}",
666                          bridgeName, bridgeUUID, protocols, status);
667         }
668
669         ovsdbConfigurationService.setOFController(node, bridgeUUID);
670
671         if (localPatchName != null &&
672             remotePatchName != null &&
673             networkingProviderManager.getProvider(node).hasPerTenantTunneling()) {
674             return addPatchPort(node, bridgeUUID, localPatchName, remotePatchName);
675         }*/
676         return new Status(StatusCode.SUCCESS);
677     }
678
679
680 }