[ONOS-5845] NullPointerException occurs, if OVSDB connection is closed while creating a OVS bridge on OVS.
Change-Id: I2dc2b48a1d5524afe2aa35247ea92f4791fd02cd
diff --git a/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbBridgeConfig.java b/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbBridgeConfig.java
index 02402a5..5656664 100644
--- a/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbBridgeConfig.java
+++ b/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbBridgeConfig.java
@@ -38,6 +38,7 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@@ -73,6 +74,9 @@
addBridge(bridgeDesc);
OvsdbClientService client = getOvsdbClientService(handler());
+ if (client == null) {
+ return;
+ }
client.createPort(bridgeName.name(), exPortName);
}
@@ -93,7 +97,9 @@
@Override
public boolean addBridge(BridgeDescription bridgeDesc) {
OvsdbClientService client = getOvsdbClientService(handler());
-
+ if (client == null) {
+ return false;
+ }
OvsdbBridge.Builder bridgeBuilder = OvsdbBridge.builder(bridgeDesc);
if (bridgeDesc.enableLocalController()) {
bridgeBuilder.controller(client.localController());
@@ -104,12 +110,19 @@
@Override
public void deleteBridge(BridgeName bridgeName) {
OvsdbClientService client = getOvsdbClientService(handler());
+ if (client == null) {
+ return;
+ }
client.dropBridge(bridgeName.name());
}
@Override
public Collection<BridgeDescription> getBridges() {
OvsdbClientService client = getOvsdbClientService(handler());
+ if (client == null) {
+ return Collections.emptyList();
+ }
+
Set<OvsdbBridge> bridges = client.getBridges();
return bridges.stream()
@@ -123,18 +136,27 @@
@Override
public void addPort(BridgeName bridgeName, String portName) {
OvsdbClientService client = getOvsdbClientService(handler());
+ if (client == null) {
+ return;
+ }
client.createPort(bridgeName.name(), portName);
}
@Override
public void deletePort(BridgeName bridgeName, String portName) {
OvsdbClientService client = getOvsdbClientService(handler());
+ if (client == null) {
+ return;
+ }
client.dropPort(bridgeName.name(), portName);
}
@Override
public Collection<PortDescription> getPorts() {
OvsdbClientService client = getOvsdbClientService(handler());
+ if (client == null) {
+ return Collections.emptyList();
+ }
Set<OvsdbPort> ports = client.getPorts();
return ports.stream()
@@ -170,6 +192,9 @@
public Set<PortNumber> getPortNumbers() {
DriverHandler handler = handler();
OvsdbClientService client = getOvsdbClientService(handler);
+ if (client == null) {
+ return Collections.emptySet();
+ }
Set<OvsdbPort> ports = client.getPorts();
return ports.stream()
@@ -186,6 +211,9 @@
List<PortNumber> ports = new ArrayList<>();
DriverHandler handler = handler();
OvsdbClientService client = getOvsdbClientService(handler);
+ if (client == null) {
+ return Collections.emptyList();
+ }
Set<OvsdbPort> ovsdbSet = client.getLocalPorts(ifaceIds);
ovsdbSet.forEach(o -> {
PortNumber port = PortNumber.portNumber(o.portNumber().value(),