MD-SAL API integration
[ovsdb.git] / southbound / southbound-impl / src / main / java / org / opendaylight / ovsdb / southbound / ovsdb / transact / TerminationPointUpdateCommand.java
index 159161905fd26f9bfa851df82d9df96fced078ba..9df44ab503babd3fb3407fbd49138ed8cbacef9c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Brocade Communications Systems, Inc. and others.  All rights reserved.
+ * Copyright © 2015, 2017 Brocade Communications Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -7,26 +7,40 @@
  */
 package org.opendaylight.ovsdb.southbound.ovsdb.transact;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
+import static org.opendaylight.ovsdb.southbound.SouthboundUtil.schemaMismatchLog;
 
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Optional;
 import java.util.Set;
-
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.binding.api.ReadTransaction;
 import org.opendaylight.ovsdb.lib.error.SchemaVersionMismatchException;
 import org.opendaylight.ovsdb.lib.notation.UUID;
 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
-import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
 import org.opendaylight.ovsdb.schema.openvswitch.Interface;
 import org.opendaylight.ovsdb.schema.openvswitch.Port;
+import org.opendaylight.ovsdb.southbound.InstanceIdentifierCodec;
 import org.opendaylight.ovsdb.southbound.SouthboundConstants;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
+import org.opendaylight.ovsdb.southbound.SouthboundProvider;
+import org.opendaylight.ovsdb.southbound.SouthboundUtil;
+import org.opendaylight.ovsdb.utils.yang.YangUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbPortInterfaceAttributes.VlanMode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbQosRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntries;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceBfd;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceExternalIds;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceLldp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceOtherConfigs;
@@ -34,78 +48,90 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.re
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.PortExternalIds;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.PortOtherConfigs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.Trunks;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
-import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Sets;
-
-public class TerminationPointUpdateCommand extends AbstractTransactCommand {
+public class TerminationPointUpdateCommand implements TransactCommand {
 
     private static final Logger LOG = LoggerFactory.getLogger(TerminationPointUpdateCommand.class);
 
-    public TerminationPointUpdateCommand(BridgeOperationalState state,
-            AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes) {
-        super(state, changes);
+    @Override
+    public void execute(final TransactionBuilder transaction, final BridgeOperationalState state,
+            final DataChangeEvent events, final InstanceIdentifierCodec instanceIdentifierCodec) {
+        execute(transaction, state,
+                TransactUtils.extractCreatedOrUpdated(events, OvsdbTerminationPointAugmentation.class),
+                instanceIdentifierCodec);
     }
 
     @Override
-    public void execute(TransactionBuilder transaction) {
-        LOG.trace("TerminationPointUpdateCommand called");
-        Map<InstanceIdentifier<OvsdbTerminationPointAugmentation>, OvsdbTerminationPointAugmentation> created =
-            TransactUtils.extractCreated(getChanges(),OvsdbTerminationPointAugmentation.class);
-        for (Entry<InstanceIdentifier<OvsdbTerminationPointAugmentation>,
-                 OvsdbTerminationPointAugmentation> terminationPointEntry : created.entrySet()) {
-            updateTerminationPoint(transaction, terminationPointEntry.getKey(), terminationPointEntry.getValue());
-        }
-        Map<InstanceIdentifier<OvsdbTerminationPointAugmentation>, OvsdbTerminationPointAugmentation> updated =
-                TransactUtils.extractUpdated(getChanges(), OvsdbTerminationPointAugmentation.class);
+    public void execute(final TransactionBuilder transaction, final BridgeOperationalState state,
+            final Collection<DataTreeModification<Node>> modifications,
+            final InstanceIdentifierCodec instanceIdentifierCodec) {
+        execute(transaction, state,
+                TransactUtils.extractCreatedOrUpdated(modifications, OvsdbTerminationPointAugmentation.class),
+                instanceIdentifierCodec);
+    }
+
+    private void execute(final TransactionBuilder transaction, final BridgeOperationalState state,
+            final Map<InstanceIdentifier<OvsdbTerminationPointAugmentation>, OvsdbTerminationPointAugmentation>
+                    createdOrUpdated,
+            final InstanceIdentifierCodec instanceIdentifierCodec) {
         for (Entry<InstanceIdentifier<OvsdbTerminationPointAugmentation>,
-                 OvsdbTerminationPointAugmentation> terminationPointEntry : updated.entrySet()) {
-            updateTerminationPoint(transaction, terminationPointEntry.getKey(),
-                    terminationPointEntry.getValue());
+                 OvsdbTerminationPointAugmentation> terminationPointEntry : createdOrUpdated.entrySet()) {
+            updateTerminationPoint(transaction, state, terminationPointEntry.getKey(),
+                    terminationPointEntry.getValue(), instanceIdentifierCodec);
         }
     }
 
-    public void updateTerminationPoint(TransactionBuilder transaction,
-            InstanceIdentifier<OvsdbTerminationPointAugmentation> iid,
-            OvsdbTerminationPointAugmentation terminationPoint) {
-        if (terminationPoint instanceof OvsdbTerminationPointAugmentation) {
+    public void updateTerminationPoint(final TransactionBuilder transaction, final BridgeOperationalState state,
+            final InstanceIdentifier<OvsdbTerminationPointAugmentation> iid,
+            final OvsdbTerminationPointAugmentation terminationPoint,
+            final InstanceIdentifierCodec instanceIdentifierCodec) {
+
+        if (terminationPoint != null) {
             LOG.debug("Received request to update termination point {}",
-                    terminationPoint.getName());
+                   terminationPoint.getName());
 
             // Update interface
-            Interface ovsInterface =
-                    TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Interface.class);
+            Interface ovsInterface = transaction.getTypedRowWrapper(Interface.class);
             updateInterface(terminationPoint, ovsInterface);
-            Interface extraInterface = TyperUtils.getTypedRowWrapper(
-                    transaction.getDatabaseSchema(), Interface.class);
+            Interface extraInterface = transaction.getTypedRowWrapper(Interface.class);
             extraInterface.setName("");
             transaction.add(op.update(ovsInterface)
                     .where(extraInterface.getNameColumn().getSchema().opEqual(terminationPoint.getName()))
                     .build());
 
             TerminationPointCreateCommand.stampInstanceIdentifier(transaction,
-                    iid.firstIdentifierOf(TerminationPoint.class), terminationPoint.getName());
-
+                    iid.firstIdentifierOf(OvsdbTerminationPointAugmentation.class), terminationPoint.getName(),
+                    instanceIdentifierCodec);
+            final String opendaylightIid = instanceIdentifierCodec.serialize(iid);
             // Update port
-            Port port = TyperUtils.getTypedRowWrapper(
-                    transaction.getDatabaseSchema(), Port.class);
-            updatePort(terminationPoint,port);
-            Port extraPort = TyperUtils.getTypedRowWrapper(
-                    transaction.getDatabaseSchema(), Port.class);
-            extraPort.setName("");
-            transaction.add(op.update(port)
-                    .where(extraPort.getNameColumn().getSchema().opEqual(terminationPoint.getName()))
-                    .build());
+            // Bug#6136
+            Optional<OvsdbBridgeAugmentation> ovsdbBridgeOptional = state.getOvsdbBridgeAugmentation(iid);
+            if (ovsdbBridgeOptional != null && ovsdbBridgeOptional.isPresent()) {
+                OvsdbBridgeAugmentation operBridge = ovsdbBridgeOptional.get();
+                if (operBridge != null) {
+                    Port port = transaction.getTypedRowWrapper(Port.class);
+                    updatePort(terminationPoint, port, operBridge, opendaylightIid);
+                    Port extraPort = transaction.getTypedRowWrapper(Port.class);
+                    extraPort.setName("");
+                    transaction.add(op.update(port)
+                        .where(extraPort.getNameColumn().getSchema().opEqual(terminationPoint.getName()))
+                        .build());
+                    LOG.info("Updated Termination Point : {}  with Uuid : {}",
+                        terminationPoint.getName(), terminationPoint.getPortUuid());
+                }
+            } else {
+                LOG.warn("OVSDB bridge node was not found: {}", iid);
+            }
         }
     }
 
-    private void updateInterface(
-            final OvsdbTerminationPointAugmentation terminationPoint,
+    private static void updateInterface(final OvsdbTerminationPointAugmentation terminationPoint,
             final Interface ovsInterface) {
         updateOfPort(terminationPoint, ovsInterface);
         updateOfPortRequest(terminationPoint, ovsInterface);
@@ -113,115 +139,133 @@ public class TerminationPointUpdateCommand extends AbstractTransactCommand {
         updateInterfaceOtherConfig(terminationPoint, ovsInterface);
         updateInterfaceExternalIds(terminationPoint, ovsInterface);
         updateInterfaceLldp(terminationPoint, ovsInterface);
+        updateInterfaceBfd(terminationPoint, ovsInterface);
+        updateInterfacePolicing(terminationPoint, ovsInterface);
     }
 
-    private void updatePort(
-            final OvsdbTerminationPointAugmentation terminationPoint,
-            final Port port) {
-
+    private static void updatePort(final OvsdbTerminationPointAugmentation terminationPoint,
+            final Port port, final OvsdbBridgeAugmentation operBridge, final String opendaylightIid) {
         updatePortOtherConfig(terminationPoint, port);
         updatePortVlanTag(terminationPoint, port);
         updatePortVlanTrunk(terminationPoint, port);
         updatePortVlanMode(terminationPoint, port);
-        updatePortExternalIds(terminationPoint, port);
-        updatePortQos(terminationPoint, port);
+        updatePortExternalIds(terminationPoint, port, opendaylightIid);
+        updatePortQos(terminationPoint, port, operBridge);
     }
 
-    private void updatePortQos(
-            final OvsdbTerminationPointAugmentation terminationPoint,
-            final Port port) {
-
-        Set<UUID> uuidSet = Sets.newHashSet();
-        Uuid qosUuid = terminationPoint.getQos();
-        if (qosUuid != null) {
-            uuidSet.add(new UUID(qosUuid.getValue()));
+    private static void updatePortQos(final OvsdbTerminationPointAugmentation terminationPoint,
+            final Port port, final OvsdbBridgeAugmentation operBridge) {
+
+        Set<UUID> uuidSet = new HashSet<>();
+
+        // First check if QosEntry is present and use that
+        if (terminationPoint.getQosEntry() != null && !terminationPoint.getQosEntry().isEmpty()) {
+            OvsdbQosRef qosRef = terminationPoint.getQosEntry().iterator().next().getQosRef();
+            Uri qosId = qosRef.getValue().firstKeyOf(QosEntries.class).getQosId();
+            OvsdbNodeAugmentation operNode = getOperNode(operBridge);
+            if (operNode != null && operNode.getQosEntries() != null
+                    && !operNode.getQosEntries().isEmpty()) {
+                for (QosEntries qosEntry : operNode.getQosEntries()) {
+                    if (qosEntry.getQosId().equals(qosId)) {
+                        uuidSet.add(new UUID(qosEntry.getQosUuid().getValue()));
+                    }
+                }
+            }
+            if (uuidSet.size() == 0) {
+                uuidSet.add(new UUID(SouthboundConstants.QOS_NAMED_UUID_PREFIX
+                        + TransactUtils.bytesToHexString(qosId.getValue().getBytes(UTF_8))));
+            }
         }
         port.setQos(uuidSet);
     }
 
+    @SuppressWarnings("IllegalCatch")
+    private static OvsdbNodeAugmentation getOperNode(final OvsdbBridgeAugmentation operBridge) {
+        @SuppressWarnings("unchecked")
+        InstanceIdentifier<Node> iidNode = (InstanceIdentifier<Node>)operBridge.getManagedBy().getValue();
+        OvsdbNodeAugmentation operNode = null;
+        try (ReadTransaction transaction = SouthboundProvider.getDb().newReadOnlyTransaction()) {
+            Optional<Node> nodeOptional = SouthboundUtil.readNode(transaction, iidNode);
+            if (nodeOptional.isPresent()) {
+                operNode = nodeOptional.get().augmentation(OvsdbNodeAugmentation.class);
+            }
+        } catch (Exception exp) {
+            LOG.error("Error in getting the brideNode for {}", iidNode, exp);
+        }
+        return operNode;
+    }
 
-    private void updateOfPort(
-            final OvsdbTerminationPointAugmentation terminationPoint,
+    private static void updateOfPort(final OvsdbTerminationPointAugmentation terminationPoint,
             final Interface ovsInterface) {
 
-        Long ofPort = terminationPoint.getOfport();
+        Uint32 ofPort = terminationPoint.getOfport();
         if (ofPort != null) {
-            ovsInterface.setOpenFlowPort(Sets.newHashSet(ofPort));
+            ovsInterface.setOpenFlowPort(Collections.singleton(ofPort.toJava()));
         }
     }
 
-    private void updateOfPortRequest(
-            final OvsdbTerminationPointAugmentation terminationPoint,
+    private static void updateOfPortRequest(final OvsdbTerminationPointAugmentation terminationPoint,
             final Interface ovsInterface) {
 
-        Integer ofPortRequest = terminationPoint.getOfportRequest();
+        Uint16 ofPortRequest = terminationPoint.getOfportRequest();
         if (ofPortRequest != null) {
-            ovsInterface.setOpenFlowPortRequest(Sets.newHashSet(ofPortRequest.longValue()));
+            ovsInterface.setOpenFlowPortRequest(Collections.singleton(ofPortRequest.longValue()));
         }
     }
 
-    private void updateInterfaceOptions(
-            final OvsdbTerminationPointAugmentation terminationPoint,
+    private static void updateInterfaceOptions(final OvsdbTerminationPointAugmentation terminationPoint,
             final Interface ovsInterface) {
 
         //Configure optional input
         if (terminationPoint.getOptions() != null) {
-            Map<String, String> optionsMap = new HashMap<>();
-            for (Options option : terminationPoint.getOptions()) {
-                optionsMap.put(option.getOption(), option.getValue());
-            }
             try {
-                ovsInterface.setOptions(ImmutableMap.copyOf(optionsMap));
+                ovsInterface.setOptions(YangUtils.convertYangKeyValueListToMap(terminationPoint.getOptions(),
+                        Options::getOption, Options::getValue));
             } catch (NullPointerException e) {
                 LOG.warn("Incomplete OVSDB interface options", e);
             }
         }
     }
 
-    private void updateInterfaceExternalIds(
-            final OvsdbTerminationPointAugmentation terminationPoint,
+    private static void updateInterfaceExternalIds(final OvsdbTerminationPointAugmentation terminationPoint,
             final Interface ovsInterface) {
 
         List<InterfaceExternalIds> interfaceExternalIds =
                 terminationPoint.getInterfaceExternalIds();
         if (interfaceExternalIds != null && !interfaceExternalIds.isEmpty()) {
-            Map<String, String> externalIdsMap = new HashMap<>();
-            for (InterfaceExternalIds externalId: interfaceExternalIds) {
-                externalIdsMap.put(externalId.getExternalIdKey(), externalId.getExternalIdValue());
-            }
-            try {
-                ovsInterface.setExternalIds(ImmutableMap.copyOf(externalIdsMap));
-            } catch (NullPointerException e) {
-                LOG.warn("Incomplete OVSDB interface external_ids", e);
-            }
+            interfaceExternalIds.add(SouthboundUtil.createExternalIdsForInterface(
+                SouthboundConstants.CREATED_BY, SouthboundConstants.ODL));
+        } else {
+            interfaceExternalIds = Arrays.asList(SouthboundUtil.createExternalIdsForInterface(
+                SouthboundConstants.CREATED_BY, SouthboundConstants.ODL));
+        }
+        try {
+            ovsInterface.setExternalIds(YangUtils.convertYangKeyValueListToMap(interfaceExternalIds,
+                    InterfaceExternalIds::getExternalIdKey, InterfaceExternalIds::getExternalIdValue));
+        } catch (NullPointerException e) {
+            LOG.warn("Incomplete OVSDB interface external_ids", e);
         }
     }
 
-    private void updateInterfaceLldp(
-            final OvsdbTerminationPointAugmentation terminationPoint,
+    private static void updateInterfaceLldp(final OvsdbTerminationPointAugmentation terminationPoint,
             final Interface ovsInterface) {
-
         try {
             List<InterfaceLldp> interfaceLldpList =
                     terminationPoint.getInterfaceLldp();
             if (interfaceLldpList != null && !interfaceLldpList.isEmpty()) {
-                Map<String, String> interfaceLldpMap = new HashMap<>();
-                for (InterfaceLldp interfaceLldp : interfaceLldpList) {
-                    interfaceLldpMap.put(interfaceLldp.getLldpKey(), interfaceLldp.getLldpValue());
-                }
                 try {
-                    ovsInterface.setLldp(ImmutableMap.copyOf(interfaceLldpMap));
+                    ovsInterface.setLldp(YangUtils.convertYangKeyValueListToMap(interfaceLldpList,
+                            InterfaceLldp::getLldpKey, InterfaceLldp::getLldpValue));
                 } catch (NullPointerException e) {
                     LOG.warn("Incomplete OVSDB interface lldp", e);
                 }
             }
         } catch (SchemaVersionMismatchException e) {
-            LOG.debug("lldp column for Interface Table unsupported for this version of ovsdb schema", e);
+            schemaMismatchLog("lldp", "Interface", e);
         }
     }
 
-    private void updateInterfaceOtherConfig(
-            final OvsdbTerminationPointAugmentation terminationPoint,
+    private static void updateInterfaceOtherConfig(final OvsdbTerminationPointAugmentation terminationPoint,
             final Interface ovsInterface) {
 
         List<InterfaceOtherConfigs> interfaceOtherConfigs =
@@ -240,28 +284,54 @@ public class TerminationPointUpdateCommand extends AbstractTransactCommand {
         }
     }
 
-    private void updatePortExternalIds(
-            final OvsdbTerminationPointAugmentation terminationPoint,
-            final Port port) {
+    private static void updateInterfaceBfd(final OvsdbTerminationPointAugmentation terminationPoint,
+            final Interface ovsInterface) {
 
-        List<PortExternalIds> portExternalIds = terminationPoint.getPortExternalIds();
-        if (portExternalIds != null && !portExternalIds.isEmpty()) {
-            Map<String, String> externalIdsMap = new HashMap<>();
-            for (PortExternalIds externalId: portExternalIds) {
-                externalIdsMap.put(externalId.getExternalIdKey(), externalId.getExternalIdValue());
-            }
-            try {
-                port.setExternalIds(ImmutableMap.copyOf(externalIdsMap));
-            } catch (NullPointerException e) {
-                LOG.warn("Incomplete OVSDB port external_ids", e);
+        try {
+            List<InterfaceBfd> interfaceBfdList =
+                    terminationPoint.getInterfaceBfd();
+            if (interfaceBfdList != null && !interfaceBfdList.isEmpty()) {
+                try {
+                    ovsInterface.setBfd(YangUtils.convertYangKeyValueListToMap(interfaceBfdList,
+                            InterfaceBfd::getBfdKey, InterfaceBfd::getBfdValue));
+                } catch (NullPointerException e) {
+                    LOG.warn("Incomplete OVSDB interface bfd", e);
+                }
             }
+        } catch (SchemaVersionMismatchException e) {
+            schemaMismatchLog("bfd", "Interface", e);
         }
     }
 
-    private void updatePortVlanTag(
-            final OvsdbTerminationPointAugmentation terminationPoint,
-            final Port port) {
+    private static void updateInterfacePolicing(final OvsdbTerminationPointAugmentation terminationPoint,
+            final Interface ovsInterface) {
 
+        Uint32 ingressPolicingRate = terminationPoint.getIngressPolicingRate();
+        if (ingressPolicingRate != null) {
+            ovsInterface.setIngressPolicingRate(ingressPolicingRate.toJava());
+        }
+        Uint32 ingressPolicingBurst = terminationPoint.getIngressPolicingBurst();
+        if (ingressPolicingBurst != null) {
+            ovsInterface.setIngressPolicingBurst(ingressPolicingBurst.toJava());
+        }
+    }
+
+    private static void updatePortExternalIds(final OvsdbTerminationPointAugmentation terminationPoint,
+            final Port port, final String opendaylightIid) {
+
+        Map<String, String> externalIdMap = new HashMap<>();
+        externalIdMap.put(SouthboundConstants.IID_EXTERNAL_ID_KEY, opendaylightIid);
+        externalIdMap.put(SouthboundConstants.CREATED_BY, SouthboundConstants.ODL);
+        try {
+            YangUtils.copyYangKeyValueListToMap(externalIdMap, terminationPoint.getPortExternalIds(),
+                    PortExternalIds::getExternalIdKey, PortExternalIds::getExternalIdValue);
+        } catch (NullPointerException e) {
+            LOG.warn("Incomplete OVSDB port external_ids", e);
+        }
+        port.setExternalIds(externalIdMap);
+    }
+
+    private static void updatePortVlanTag(final OvsdbTerminationPointAugmentation terminationPoint, final Port port) {
         if (terminationPoint.getVlanTag() != null) {
             Set<Long> vlanTag = new HashSet<>();
             vlanTag.add(terminationPoint.getVlanTag().getValue().longValue());
@@ -269,14 +339,11 @@ public class TerminationPointUpdateCommand extends AbstractTransactCommand {
         }
     }
 
-    private void updatePortVlanTrunk(
-            final OvsdbTerminationPointAugmentation terminationPoint,
-            final Port port) {
-
+    private static void updatePortVlanTrunk(final OvsdbTerminationPointAugmentation terminationPoint, final Port port) {
         if (terminationPoint.getTrunks() != null && terminationPoint.getTrunks().size() > 0) {
             Set<Long> portTrunks = new HashSet<>();
             List<Trunks> modelTrunks = terminationPoint.getTrunks();
-            for (Trunks trunk: modelTrunks) {
+            for (Trunks trunk : modelTrunks) {
                 if (trunk.getTrunk() != null) {
                     portTrunks.add(trunk.getTrunk().getValue().longValue());
                 }
@@ -285,34 +352,26 @@ public class TerminationPointUpdateCommand extends AbstractTransactCommand {
         }
     }
 
-    private void updatePortVlanMode(
-            final OvsdbTerminationPointAugmentation terminationPoint,
-            final Port port) {
+    private static void updatePortVlanMode(final OvsdbTerminationPointAugmentation terminationPoint, final Port port) {
         if (terminationPoint.getVlanMode() != null) {
             Set<String> portVlanMode = new HashSet<>();
             VlanMode modelVlanMode = terminationPoint.getVlanMode();
-            portVlanMode.add(SouthboundConstants.VLANMODES.values()[modelVlanMode.getIntValue() - 1].getMode());
+            portVlanMode.add(SouthboundConstants.VlanModes.values()[modelVlanMode.getIntValue() - 1].getMode());
             port.setVlanMode(portVlanMode);
         }
     }
 
-    private void updatePortOtherConfig(
-            final OvsdbTerminationPointAugmentation terminationPoint,
+    private static void updatePortOtherConfig(final OvsdbTerminationPointAugmentation terminationPoint,
             final Port ovsPort) {
         List<PortOtherConfigs> portOtherConfigs =
                 terminationPoint.getPortOtherConfigs();
         if (portOtherConfigs != null && !portOtherConfigs.isEmpty()) {
-            Map<String, String> otherConfigsMap = new HashMap<>();
-            for (PortOtherConfigs portOtherConfig : portOtherConfigs) {
-                otherConfigsMap.put(portOtherConfig.getOtherConfigKey(),
-                        portOtherConfig.getOtherConfigValue());
-            }
             try {
-                ovsPort.setOtherConfig(ImmutableMap.copyOf(otherConfigsMap));
+                ovsPort.setOtherConfig(YangUtils.convertYangKeyValueListToMap(portOtherConfigs,
+                        PortOtherConfigs::getOtherConfigKey, PortOtherConfigs::getOtherConfigValue));
             } catch (NullPointerException e) {
                 LOG.warn("Incomplete OVSDB port other_config", e);
             }
         }
     }
-
 }