Bump upstreams for 2022.09 Chlorine
[ovsdb.git] / southbound / southbound-impl / src / main / java / org / opendaylight / ovsdb / southbound / transactions / md / OvsdbBridgeUpdateCommand.java
index 99caee95ce766d44f08e1db967b86c8c99ed2b74..5c6ef0d18215c10d5191ad4730129b98152920ab 100644 (file)
@@ -12,6 +12,7 @@ import static org.opendaylight.ovsdb.southbound.SouthboundUtil.schemaMismatchLog
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.net.InetAddresses;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.net.InetAddress;
 import java.net.NetworkInterface;
 import java.net.SocketException;
@@ -38,7 +39,8 @@ import org.opendaylight.ovsdb.southbound.SouthboundConstants;
 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
 import org.opendaylight.ovsdb.southbound.SouthboundUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.DatapathId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
@@ -65,6 +67,7 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.util.BindingMap;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -76,6 +79,7 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
     private final List<InstanceIdentifier<Node>> updatedBridges = new ArrayList<>();
     private final Map<NodeId, Node> updatedBridgeNodes;
 
+    @SuppressFBWarnings(value = "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR", justification = "Non-final for mocking")
     public OvsdbBridgeUpdateCommand(InstanceIdentifierCodec instanceIdentifierCodec, OvsdbConnectionInstance key,
             TableUpdates updates, DatabaseSchema dbSchema,
                                     Map<NodeId, Node> updatedBridgeNodes) {
@@ -189,12 +193,10 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
                 for (String protocol : oldBridge.getProtocolsColumn().getData()) {
                     if (bridge.getProtocolsColumn() == null || !bridge.getProtocolsColumn().getData()
                                 .contains(protocol)) {
-                        Class<? extends OvsdbBridgeProtocolBase> proto = SouthboundConstants.OVSDB_PROTOCOL_MAP
-                                .inverse().get(protocol);
+                        OvsdbBridgeProtocolBase proto = SouthboundConstants.OVSDB_PROTOCOL_MAP.inverse().get(protocol);
                         InstanceIdentifier<ProtocolEntry> iid = bridgeIid
                                 .augmentation(OvsdbBridgeAugmentation.class)
-                                .child(ProtocolEntry.class,
-                                        new ProtocolEntryKey(proto));
+                                .child(ProtocolEntry.class, new ProtocolEntryKey(proto));
                         result.add(iid);
                     }
                 }
@@ -212,14 +214,12 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
         connectionNode.setNodeId(getOvsdbConnectionInstance().getNodeId());
 
         OvsdbNodeAugmentationBuilder ovsdbConnectionAugmentationBuilder = new OvsdbNodeAugmentationBuilder();
-        List<ManagedNodeEntry> managedBridges = new ArrayList<>();
         InstanceIdentifier<Node> bridgeIid =
                 SouthboundMapper.createInstanceIdentifier(instanceIdentifierCodec, getOvsdbConnectionInstance(),
                         bridge);
         ManagedNodeEntry managedBridge = new ManagedNodeEntryBuilder().setBridgeRef(
                 new OvsdbBridgeRef(bridgeIid)).build();
-        managedBridges.add(managedBridge);
-        ovsdbConnectionAugmentationBuilder.setManagedNodeEntry(managedBridges);
+        ovsdbConnectionAugmentationBuilder.setManagedNodeEntry(BindingMap.of(managedBridge));
 
         connectionNode.addAugmentation(ovsdbConnectionAugmentationBuilder.build());
 
@@ -288,11 +288,12 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
         }
     }
 
-    private static void setOtherConfig(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder, Bridge bridge) {
+    @VisibleForTesting
+    static void setOtherConfig(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder, Bridge bridge) {
         Map<String, String> otherConfigs = bridge
                 .getOtherConfigColumn().getData();
         if (otherConfigs != null && !otherConfigs.isEmpty()) {
-            List<BridgeOtherConfigs> otherConfigList = new ArrayList<>();
+            var otherConfigList = BindingMap.<BridgeOtherConfigsKey, BridgeOtherConfigs>orderedBuilder();
             for (Entry<String, String> entry : otherConfigs.entrySet()) {
                 String otherConfigKey = entry.getKey();
                 String otherConfigValue = entry.getValue();
@@ -303,15 +304,15 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
                             .build());
                 }
             }
-            ovsdbBridgeAugmentationBuilder.setBridgeOtherConfigs(otherConfigList);
+            ovsdbBridgeAugmentationBuilder.setBridgeOtherConfigs(otherConfigList.build());
         }
     }
 
-    private static void setExternalIds(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder, Bridge bridge) {
-        Map<String, String> externalIds = bridge.getExternalIdsColumn()
-                .getData();
+    @VisibleForTesting
+    static void setExternalIds(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder, Bridge bridge) {
+        Map<String, String> externalIds = bridge.getExternalIdsColumn().getData();
         if (externalIds != null && !externalIds.isEmpty()) {
-            List<BridgeExternalIds> externalIdsList = new ArrayList<>();
+            var externalIdsList = BindingMap.<BridgeExternalIdsKey, BridgeExternalIds>orderedBuilder();
             for (Entry<String, String> entry : externalIds.entrySet()) {
                 String externalIdKey = entry.getKey();
                 String externalIdValue = entry.getValue();
@@ -322,18 +323,20 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
                             .build());
                 }
             }
-            ovsdbBridgeAugmentationBuilder.setBridgeExternalIds(externalIdsList);
+            ovsdbBridgeAugmentationBuilder.setBridgeExternalIds(externalIdsList.build());
         }
     }
 
-    private static void setProtocol(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder, Bridge bridge) {
-        final List<ProtocolEntry> protocols = SouthboundMapper.createMdsalProtocols(bridge);
+    @VisibleForTesting
+    static void setProtocol(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder, Bridge bridge) {
+        List<ProtocolEntry> protocols = SouthboundMapper.createMdsalProtocols(bridge);
         if (!protocols.isEmpty()) {
-            ovsdbBridgeAugmentationBuilder.setProtocolEntry(protocols);
+            ovsdbBridgeAugmentationBuilder.setProtocolEntry(BindingMap.of(protocols));
         }
     }
 
-    private static void setDataPath(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder, Bridge bridge) {
+    @VisibleForTesting
+    static void setDataPath(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder, Bridge bridge) {
         DatapathId dpid = SouthboundMapper.createDatapathId(bridge);
         if (dpid != null) {
             ovsdbBridgeAugmentationBuilder.setDatapathId(dpid);
@@ -356,12 +359,12 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
         LOG.debug("setOpenFlowNodeRef: updatedControllerRows: {}", updatedControllerRows);
         for (ControllerEntry controllerEntry: SouthboundMapper.createControllerEntries(bridge, updatedControllerRows)) {
             if (controllerEntry != null
-                && controllerEntry.isIsConnected() != null && controllerEntry.isIsConnected()) {
+                && controllerEntry.getIsConnected() != null && controllerEntry.getIsConnected()) {
                 String [] controllerTarget = controllerEntry.getTarget().getValue().split(":");
                 IpAddress bridgeControllerIpAddress = null;
                 for (String targetElement : controllerTarget) {
                     if (InetAddresses.isInetAddress(targetElement)) {
-                        bridgeControllerIpAddress = IpAddressBuilder.getDefaultInstance(targetElement);
+                        bridgeControllerIpAddress = parseIpAddress(targetElement);
                         continue;
                     }
                     if (NumberUtils.isCreatable(targetElement)) {
@@ -391,6 +394,15 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
         }
     }
 
+    private static IpAddress parseIpAddress(final String ipAddress) {
+        try {
+            return new IpAddress(new Ipv4Address(ipAddress));
+        } catch (IllegalArgumentException e) {
+            LOG.debug("Failed to interpret {} as an Ipv4Address", ipAddress, e);
+        }
+        return new IpAddress(new Ipv6Address(ipAddress));
+    }
+
     private InstanceIdentifier<Node> getInstanceIdentifier(Bridge bridge) {
         return SouthboundMapper.createInstanceIdentifier(instanceIdentifierCodec, getOvsdbConnectionInstance(),
                 bridge);