Merge "Create McastMacs by Listening DS Changes"
authorSam Hague <shague@redhat.com>
Tue, 8 Dec 2015 13:47:19 +0000 (13:47 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 8 Dec 2015 13:47:19 +0000 (13:47 +0000)
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/McastMacsLocalUpdateCommand.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/McastMacsRemoteUpdateCommand.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/TransactUtils.java
resources/commons/Ovsdb-HwvtepSouthbound-Collection.json.postman_collection

index d21b23fbb446bc62ae7a37fd751baa4deeb7317d..63b40905d6f86fcedb5a368653fd86194237368d 100644 (file)
@@ -8,14 +8,42 @@
 
 package org.opendaylight.ovsdb.hwvtepsouthbound.transact;
 
+import static org.opendaylight.ovsdb.lib.operations.Operations.op;
+
 import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
 
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundConstants;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundMapper;
+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.hardwarevtep.McastMacsLocal;
+import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalLocator;
+import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalLocatorSet;
+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.hwvtep.rev150901.HwvtepGlobalAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalMcastMacs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitchesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.locator.set.attributes.LocatorSet;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+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.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Optional;
+
 public class McastMacsLocalUpdateCommand extends AbstractTransactCommand {
     private static final Logger LOG = LoggerFactory.getLogger(PhysicalPortRemoveCommand.class);
 
@@ -26,6 +54,141 @@ public class McastMacsLocalUpdateCommand extends AbstractTransactCommand {
 
     @Override
     public void execute(TransactionBuilder transaction) {
-        //TODO
+        Map<InstanceIdentifier<Node>, List<LocalMcastMacs>> createds =
+                extractCreated(getChanges(),LocalMcastMacs.class);
+        if (!createds.isEmpty()) {
+            for (Entry<InstanceIdentifier<Node>, List<LocalMcastMacs>> created:
+                createds.entrySet()) {
+                updateMcastMacsLocal(transaction,  created.getKey(), created.getValue());
+            }
+        }
+        Map<InstanceIdentifier<Node>, List<LocalMcastMacs>> updateds =
+                extractUpdated(getChanges(),LocalMcastMacs.class);
+        if (!updateds.isEmpty()) {
+            for (Entry<InstanceIdentifier<Node>, List<LocalMcastMacs>> updated:
+                updateds.entrySet()) {
+                updateMcastMacsLocal(transaction,  updated.getKey(), updated.getValue());
+            }
+        }
+    }
+
+    private void updateMcastMacsLocal(TransactionBuilder transaction,
+            InstanceIdentifier<Node> instanceIdentifier, List<LocalMcastMacs> localMcastMacs) {
+        for (LocalMcastMacs localMcastMac: localMcastMacs) {
+            LOG.debug("Creating localMcastMac, mac address: {}", localMcastMac.getMacEntryKey().getValue());
+            Optional<LocalMcastMacs> operationalMacOptional =
+                    getOperationalState().getLocalMcastMacs(instanceIdentifier, localMcastMac.getKey());
+            McastMacsLocal mcastMacsLocal = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), McastMacsLocal.class);
+            setIpAddress(mcastMacsLocal, localMcastMac);
+            setLocatorSet(transaction, mcastMacsLocal, localMcastMac);
+            setLogicalSwitch(instanceIdentifier, mcastMacsLocal, localMcastMac);
+            if (!operationalMacOptional.isPresent()) {
+                setMac(mcastMacsLocal, localMcastMac, operationalMacOptional);
+                transaction.add(op.insert(mcastMacsLocal));
+            } else {
+                LocalMcastMacs updatedMac = operationalMacOptional.get();
+                String existingMac = updatedMac.getMacEntryKey().getValue();
+                McastMacsLocal extraMac = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), McastMacsLocal.class);
+                extraMac.setMac("");;
+                transaction.add(op.update(mcastMacsLocal)
+                        .where(extraMac.getMacColumn().getSchema().opEqual(existingMac))
+                        .build());
+            }
+        }
+    }
+
+    private void setLogicalSwitch(InstanceIdentifier<Node> iid, McastMacsLocal mcastMacsLocal, LocalMcastMacs inputMac) {
+        if (inputMac.getLogicalSwitchRef() != null) {
+            HwvtepNodeName lswitchName = new HwvtepNodeName(inputMac.getLogicalSwitchRef().getValue());
+            Optional<LogicalSwitches> operationalSwitchOptional =
+                    getOperationalState().getLogicalSwitches(iid, new LogicalSwitchesKey(lswitchName));
+            if (operationalSwitchOptional.isPresent()) {
+                Uuid logicalSwitchUuid = operationalSwitchOptional.get().getLogicalSwitchUuid();
+                UUID logicalSwitchUUID = new UUID(logicalSwitchUuid.getValue());
+                mcastMacsLocal.setLogicalSwitch(logicalSwitchUUID);
+            } else {
+                LOG.warn("Create or update localMcastMac: No logical switch named {} found in operational datastore!",
+                        lswitchName);
+            }
+        }
+    }
+
+    private void setLocatorSet(TransactionBuilder transaction, McastMacsLocal mcastMacsLocal, LocalMcastMacs inputMac) {
+        if (inputMac.getLocatorSet() != null && !inputMac.getLocatorSet().isEmpty()) {
+            UUID locatorSetUuid = TransactUtils.createPhysicalLocatorSet(getOperationalState(), transaction, inputMac.getLocatorSet());
+            mcastMacsLocal.setLocatorSet(locatorSetUuid);
+        }
+    }
+
+    private void setIpAddress(McastMacsLocal mcastMacsLocal, LocalMcastMacs inputMac) {
+        if (inputMac.getIpaddr() != null) {
+            mcastMacsLocal.setIpAddress(inputMac.getIpaddr().getIpv4Address().getValue());
+        }
+    }
+
+    private void setMac(McastMacsLocal mcastMacsLocal, LocalMcastMacs inputMac,
+            Optional<LocalMcastMacs> inputSwitchOptional) {
+        if (inputMac.getMacEntryKey() != null) {
+            mcastMacsLocal.setMac(inputMac.getMacEntryKey().getValue());
+        } else if (inputSwitchOptional.isPresent() && inputSwitchOptional.get().getMacEntryKey() != null) {
+            mcastMacsLocal.setMac(inputSwitchOptional.get().getMacEntryKey().getValue());
+        }
+    }
+
+    private Map<InstanceIdentifier<Node>, List<LocalMcastMacs>> extractCreated(
+            Collection<DataTreeModification<Node>> changes, Class<LocalMcastMacs> class1) {
+        Map<InstanceIdentifier<Node>, List<LocalMcastMacs>> result
+            = new HashMap<InstanceIdentifier<Node>, List<LocalMcastMacs>>();
+        if (changes != null && !changes.isEmpty()) {
+            for (DataTreeModification<Node> change : changes) {
+                final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
+                final DataObjectModification<Node> mod = change.getRootNode();
+                Node created = TransactUtils.getCreated(mod);
+                if (created != null) {
+                    List<LocalMcastMacs> macListUpdated = null;
+                    HwvtepGlobalAugmentation hgAugmentation = created.getAugmentation(HwvtepGlobalAugmentation.class);
+                    if (hgAugmentation != null) {
+                        macListUpdated = hgAugmentation.getLocalMcastMacs();
+                    }
+                    if (macListUpdated != null) {
+                        result.put(key, macListUpdated);
+                    }
+                }
+            }
+        }
+        return result;
+    }
+
+    private Map<InstanceIdentifier<Node>, List<LocalMcastMacs>> extractUpdated(
+            Collection<DataTreeModification<Node>> changes, Class<LocalMcastMacs> class1) {
+        Map<InstanceIdentifier<Node>, List<LocalMcastMacs>> result
+            = new HashMap<InstanceIdentifier<Node>, List<LocalMcastMacs>>();
+        if (changes != null && !changes.isEmpty()) {
+            for (DataTreeModification<Node> change : changes) {
+                final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
+                final DataObjectModification<Node> mod = change.getRootNode();
+                Node updated = TransactUtils.getUpdated(mod);
+                Node before = mod.getDataBefore();
+                if (updated != null && before != null) {
+                    List<LocalMcastMacs> macListUpdated = null;
+                    List<LocalMcastMacs> macListBefore = null;
+                    HwvtepGlobalAugmentation hgUpdated = updated.getAugmentation(HwvtepGlobalAugmentation.class);
+                    if (hgUpdated != null) {
+                        macListUpdated = hgUpdated.getLocalMcastMacs();
+                    }
+                    HwvtepGlobalAugmentation hgBefore = before.getAugmentation(HwvtepGlobalAugmentation.class);
+                    if (hgBefore != null) {
+                        macListBefore = hgBefore.getLocalMcastMacs();
+                    }
+                    if (macListUpdated != null) {
+                        if (macListBefore != null) {
+                            macListUpdated.removeAll(macListBefore);
+                        }
+                        result.put(key, macListUpdated);
+                    }
+                }
+            }
+        }
+        return result;
     }
 }
\ No newline at end of file
index 37fe0dd96ec5a5ae67c1a8427ab3fbe20778a3fd..c066e8f938cd7d2d62b0b3d7907a91860622799c 100644 (file)
@@ -8,14 +8,42 @@
 
 package org.opendaylight.ovsdb.hwvtepsouthbound.transact;
 
+import static org.opendaylight.ovsdb.lib.operations.Operations.op;
+
 import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
 
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundConstants;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundMapper;
+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.hardwarevtep.McastMacsRemote;
+import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalLocator;
+import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalLocatorSet;
+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.hwvtep.rev150901.HwvtepGlobalAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitchesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.locator.set.attributes.LocatorSet;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+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.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Optional;
+
 public class McastMacsRemoteUpdateCommand extends AbstractTransactCommand {
     private static final Logger LOG = LoggerFactory.getLogger(PhysicalPortRemoveCommand.class);
 
@@ -26,6 +54,141 @@ public class McastMacsRemoteUpdateCommand extends AbstractTransactCommand {
 
     @Override
     public void execute(TransactionBuilder transaction) {
-        //TODO
+        Map<InstanceIdentifier<Node>, List<RemoteMcastMacs>> createds =
+                extractCreated(getChanges(),RemoteMcastMacs.class);
+        if (!createds.isEmpty()) {
+            for (Entry<InstanceIdentifier<Node>, List<RemoteMcastMacs>> created:
+                createds.entrySet()) {
+                updateMcastMacRemote(transaction,  created.getKey(), created.getValue());
+            }
+        }
+        Map<InstanceIdentifier<Node>, List<RemoteMcastMacs>> updateds =
+                extractUpdated(getChanges(),RemoteMcastMacs.class);
+        if (!updateds.isEmpty()) {
+            for (Entry<InstanceIdentifier<Node>, List<RemoteMcastMacs>> updated:
+                updateds.entrySet()) {
+                updateMcastMacRemote(transaction,  updated.getKey(), updated.getValue());
+            }
+        }
+    }
+
+    private void updateMcastMacRemote(TransactionBuilder transaction,
+            InstanceIdentifier<Node> instanceIdentifier, List<RemoteMcastMacs> macList) {
+        for (RemoteMcastMacs mac: macList) {
+            LOG.debug("Creating remoteMcastMacs, mac address: {}", mac.getMacEntryKey().getValue());
+            Optional<RemoteMcastMacs> operationalMacOptional =
+                    getOperationalState().getRemoteMcastMacs(instanceIdentifier, mac.getKey());
+            McastMacsRemote mcastMacsRemote = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), McastMacsRemote.class);
+            setIpAddress(mcastMacsRemote, mac);
+            setLocatorSet(transaction, mcastMacsRemote, mac);
+            setLogicalSwitch(instanceIdentifier, mcastMacsRemote, mac);
+            if (!operationalMacOptional.isPresent()) {
+                setMac(mcastMacsRemote, mac, operationalMacOptional);
+                transaction.add(op.insert(mcastMacsRemote));
+            } else {
+                RemoteMcastMacs updatedMac = operationalMacOptional.get();
+                String existingMac = updatedMac.getMacEntryKey().getValue();
+                McastMacsRemote extraMac = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), McastMacsRemote.class);
+                extraMac.setMac("");;
+                transaction.add(op.update(mcastMacsRemote)
+                        .where(extraMac.getMacColumn().getSchema().opEqual(existingMac))
+                        .build());
+            }
+        }
+    }
+
+    private void setLogicalSwitch(InstanceIdentifier<Node> iid, McastMacsRemote mcastMacsRemote, RemoteMcastMacs inputMac) {
+        if (inputMac.getLogicalSwitchRef() != null) {
+            HwvtepNodeName lswitchName = new HwvtepNodeName(inputMac.getLogicalSwitchRef().getValue());
+            Optional<LogicalSwitches> operationalSwitchOptional =
+                    getOperationalState().getLogicalSwitches(iid, new LogicalSwitchesKey(lswitchName));
+            if (operationalSwitchOptional.isPresent()) {
+                Uuid logicalSwitchUuid = operationalSwitchOptional.get().getLogicalSwitchUuid();
+                UUID logicalSwitchUUID = new UUID(logicalSwitchUuid.getValue());
+                mcastMacsRemote.setLogicalSwitch(logicalSwitchUUID);
+            } else {
+                LOG.warn("Create or update remoteMcastMac: NO logical switch named {} found in operational datastore!",
+                        lswitchName);
+            }
+        }
+    }
+
+    private void setLocatorSet(TransactionBuilder transaction, McastMacsRemote mcastMacsRemote, RemoteMcastMacs inputMac) {
+        if (inputMac.getLocatorSet() != null && !inputMac.getLocatorSet().isEmpty()) {
+            UUID locatorSetUuid = TransactUtils.createPhysicalLocatorSet(getOperationalState(), transaction, inputMac.getLocatorSet());
+            mcastMacsRemote.setLocatorSet(locatorSetUuid);
+        }
+    }
+
+    private void setIpAddress(McastMacsRemote mcastMacsRemote, RemoteMcastMacs inputMac) {
+        if (inputMac.getIpaddr() != null) {
+            mcastMacsRemote.setIpAddress(inputMac.getIpaddr().getIpv4Address().getValue());
+        }
+    }
+
+    private void setMac(McastMacsRemote mcastMacsRemote, RemoteMcastMacs inputMac,
+            Optional<RemoteMcastMacs> inputSwitchOptional) {
+        if (inputMac.getMacEntryKey() != null) {
+            mcastMacsRemote.setMac(inputMac.getMacEntryKey().getValue());
+        } else if (inputSwitchOptional.isPresent() && inputSwitchOptional.get().getMacEntryKey() != null) {
+            mcastMacsRemote.setMac(inputSwitchOptional.get().getMacEntryKey().getValue());
+        }
+    }
+
+    private Map<InstanceIdentifier<Node>, List<RemoteMcastMacs>> extractCreated(
+            Collection<DataTreeModification<Node>> changes, Class<RemoteMcastMacs> class1) {
+        Map<InstanceIdentifier<Node>, List<RemoteMcastMacs>> result
+            = new HashMap<InstanceIdentifier<Node>, List<RemoteMcastMacs>>();
+        if (changes != null && !changes.isEmpty()) {
+            for (DataTreeModification<Node> change : changes) {
+                final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
+                final DataObjectModification<Node> mod = change.getRootNode();
+                Node created = TransactUtils.getCreated(mod);
+                if (created != null) {
+                    List<RemoteMcastMacs> macListUpdated = null;
+                    HwvtepGlobalAugmentation hgAugmentation = created.getAugmentation(HwvtepGlobalAugmentation.class);
+                    if (hgAugmentation != null) {
+                        macListUpdated = hgAugmentation.getRemoteMcastMacs();
+                    }
+                    if (macListUpdated != null) {
+                        result.put(key, macListUpdated);
+                    }
+                }
+            }
+        }
+        return result;
+    }
+
+    private Map<InstanceIdentifier<Node>, List<RemoteMcastMacs>> extractUpdated(
+            Collection<DataTreeModification<Node>> changes, Class<RemoteMcastMacs> class1) {
+        Map<InstanceIdentifier<Node>, List<RemoteMcastMacs>> result
+            = new HashMap<InstanceIdentifier<Node>, List<RemoteMcastMacs>>();
+        if (changes != null && !changes.isEmpty()) {
+            for (DataTreeModification<Node> change : changes) {
+                final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
+                final DataObjectModification<Node> mod = change.getRootNode();
+                Node updated = TransactUtils.getUpdated(mod);
+                Node before = mod.getDataBefore();
+                if (updated != null && before != null) {
+                    List<RemoteMcastMacs> macListUpdated = null;
+                    List<RemoteMcastMacs> macListBefore = null;
+                    HwvtepGlobalAugmentation hgUpdated = updated.getAugmentation(HwvtepGlobalAugmentation.class);
+                    if (hgUpdated != null) {
+                        macListUpdated = hgUpdated.getRemoteMcastMacs();
+                    }
+                    HwvtepGlobalAugmentation hgBefore = before.getAugmentation(HwvtepGlobalAugmentation.class);
+                    if (hgBefore != null) {
+                        macListBefore = hgBefore.getRemoteMcastMacs();
+                    }
+                    if (macListUpdated != null) {
+                        if (macListBefore != null) {
+                            macListUpdated.removeAll(macListBefore);
+                        }
+                        result.put(key, macListUpdated);
+                    }
+                }
+            }
+        }
+        return result;
     }
 }
index 43e5617ecc946d8087dbc583b430a6efb5e6b0e7..ea74000d76f14051220be463eecf9325e76c8e83 100644 (file)
@@ -11,7 +11,10 @@ import static org.opendaylight.ovsdb.lib.operations.Operations.op;
 
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
@@ -26,8 +29,11 @@ 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.hardwarevtep.PhysicalLocator;
+import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalLocatorSet;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.locator.set.attributes.LocatorSet;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+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.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -149,6 +155,43 @@ public class TransactUtils {
         return node;
     }
 
+    public static UUID createPhysicalLocatorSet(HwvtepOperationalState hwvtepOperationalState, TransactionBuilder transaction, List<LocatorSet> locatorList) {
+        Set<UUID> locators = new HashSet<UUID>();
+        for (LocatorSet locator: locatorList) {
+            UUID locatorUuid = null;
+            @SuppressWarnings("unchecked")
+            InstanceIdentifier<TerminationPoint> iid =(InstanceIdentifier<TerminationPoint>) locator.getLocatorRef().getValue();
+            //try to find locator in operational DS
+            Optional<HwvtepPhysicalLocatorAugmentation> operationalLocatorOptional =
+                    hwvtepOperationalState.getPhysicalLocatorAugmentation(iid);
+            if (operationalLocatorOptional.isPresent()) {
+                //if exist, get uuid
+                HwvtepPhysicalLocatorAugmentation locatorAugmentation = operationalLocatorOptional.get();
+                locatorUuid = new UUID(locatorAugmentation.getPhysicalLocatorUuid().getValue());
+            } else {
+                //if no, get it from config DS and create id
+                Optional<TerminationPoint> configLocatorOptional =
+                        readNodeFromConfig(hwvtepOperationalState.getReadWriteTransaction(), iid);
+                if (configLocatorOptional.isPresent()) {
+                    HwvtepPhysicalLocatorAugmentation locatorAugmentation =
+                            configLocatorOptional.get().getAugmentation(HwvtepPhysicalLocatorAugmentation.class);
+                    locatorUuid = TransactUtils.createPhysicalLocator(transaction, locatorAugmentation);
+                } else {
+                    LOG.warn("Create or update localMcastMac: No physical locator found in operational datastore!"
+                            + "Its indentifier is {}", locator.getLocatorRef().getValue());
+                }
+            }
+            if (locatorUuid != null) {
+                locators.add(locatorUuid);
+            }
+        }
+        PhysicalLocatorSet physicalLocatorSet = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), PhysicalLocatorSet.class);
+        physicalLocatorSet.setLocators(locators);
+        String locatorSetUuid = "PhysicalLocatorSet_" + HwvtepSouthboundMapper.getRandomUUID();
+        transaction.add(op.insert(physicalLocatorSet).withId(locatorSetUuid));
+        return new UUID(locatorSetUuid);
+    }
+
     public static UUID createPhysicalLocator(TransactionBuilder transaction, HwvtepPhysicalLocatorAugmentation inputLocator) {
         LOG.debug("Creating a physical locator: {}", inputLocator.getDstIp());
         PhysicalLocator physicalLocator = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), PhysicalLocator.class);
index bd634b0f3d50aedfafa50a098180fcf03e1b4d79..c523adc018a395c3980b547314ebf0b6b8268e27 100755 (executable)
         "6329fb56-9e3b-647f-141a-dad277c303fd",
         "51384eb0-05f8-7636-90d8-6d55605f80e6",
         "dd1cd03e-ab78-b6da-5cd8-271e1c6f9c75",
+        "0dba0439-6a45-88cf-802e-cd678f8541a8",
+        "63b2a578-04fd-803c-8327-2809cdf3fb6d",
+        "950426a5-e1e5-b907-a927-8ba96727232e",
+        "950b4c53-a6ab-7479-4fd8-7edb7a113c34",
+        "29d99111-06d1-3bb7-b482-2c492f072b31",
+        "112f40f9-05b8-d6f0-fcb2-7b9d50fb8fdc",
+        "14fbdff8-1255-5c24-7483-fba3d217d51c",
+        "daafe0e1-62d7-8040-b6b1-0956b937a233",
         "22354294-1d01-cebf-180c-d609747be9bc",
         "c8e8f3fd-3bfb-aafa-e3ec-a671a942f426",
         "d362ddc4-1c5f-67d5-e354-c2a8d2ba9d79",
@@ -37,7 +45,9 @@
         "a13e6877-997e-84e1-c8e8-e83ef5e9a002",
         "3c86ab7c-a7ee-6b71-3ec1-da7d20f97d1a",
         "4602c331-5850-0813-c276-d4ec3ae7b3d6",
-        "3b8a86df-fe33-5104-2da7-5e0cbdb7a881"
+        "3b8a86df-fe33-5104-2da7-5e0cbdb7a881",
+        "4e706a35-365a-13e4-f2ec-eee027148450",
+        "06025ed3-7251-5ee4-3d6b-c01557eb3dd2"
     ],
     "owner":0,
     "sharedWithTeam":false,
             "time": 1449315928725,
             "name": "Get Specific Operational UcastMacLocal ",
             "description": ""
+        },
+        {
+            "collectionId": "19f6b1a8-4d54-62f8-6bd6-f52e0b6e40b8",
+            "id": "0dba0439-6a45-88cf-802e-cd678f8541a8",
+            "headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
+            "url": "http://{{controllerHost}}:8181/restconf/config/network-topology:network-topology/topology/hwvtep:1/node/hwvtep:%2F%2F{{hwvtepNodeIp}}:6640",
+            "preRequestScript": "",
+            "pathVariables": {},
+            "method": "POST",
+            "data": [],
+            "dataMode": "raw",
+            "version": 2,
+            "tests": "",
+            "currentHelper": "normal",
+            "helperAttributes": {},
+            "time": 1449468092415,
+            "name": "Create Specific Config McastMacRemote",
+            "description": "",
+            "rawModeData": "{\n  \"remote-mcast-macs\": [\n        {\n            \"mac-entry-key\": \"33:33:33:33:33:55\",\n            \"logical-switch-ref\": \"ls0\",\n            \"ipaddr\": \"3.3.3.5\",\n            \"locator-set\": [\n                {\n                    \"locator-ref\": \"/network-topology:network-topology/network-topology:topology[network-topology:topology-id='hwvtep:1']/network-topology:node[network-topology:node-id='hwvtep://{{hwvtepNodeIp}}:6640']/network-topology:termination-point[network-topology:tp-id='vxlan_over_ipv4:219.141.189.49']\"\n                },\n                {\n                    \"locator-ref\": \"/network-topology:network-topology/network-topology:topology[network-topology:topology-id='hwvtep:1']/network-topology:node[network-topology:node-id='hwvtep://{{hwvtepNodeIp}}:6640']/network-topology:termination-point[network-topology:tp-id='vxlan_over_ipv4:219.141.189.48']\"\n                }\n            ]\n        }\n    ]\n}"
+        },
+        {
+            "collectionId": "19f6b1a8-4d54-62f8-6bd6-f52e0b6e40b8",
+            "id": "63b2a578-04fd-803c-8327-2809cdf3fb6d",
+            "headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
+            "url": "http://{{controllerHost}}:8181/restconf/config/network-topology:network-topology/topology/hwvtep:1/node/hwvtep:%2F%2F{{hwvtepNodeIp}}:6640/remote-mcast-macs/33:33:33:33:33:33",
+            "preRequestScript": "",
+            "pathVariables": {},
+            "method": "PUT",
+            "data": [],
+            "dataMode": "raw",
+            "version": 2,
+            "tests": "",
+            "currentHelper": "normal",
+            "helperAttributes": {},
+            "time": 1449468318065,
+            "name": "Update Specific Config McastMacRemote ",
+            "description": "",
+            "rawModeData": "{\n  \"remote-mcast-macs\": [\n        {\n            \"mac-entry-key\": \"33:33:33:33:33:33\",\n            \"logical-switch-ref\": \"ls1\",\n            \"ipaddr\": \"3.3.3.3\",\n            \"locator-set\": [\n                {\n                    \"locator-ref\": \"/network-topology:network-topology/network-topology:topology[network-topology:topology-id='hwvtep:1']/network-topology:node[network-topology:node-id='hwvtep://{{hwvtepNodeIp}}:6640']/network-topology:termination-point[network-topology:tp-id='vxlan_over_ipv4:219.141.189.49']\"\n                },\n                {\n                    \"locator-ref\": \"/network-topology:network-topology/network-topology:topology[network-topology:topology-id='hwvtep:1']/network-topology:node[network-topology:node-id='hwvtep://{{hwvtepNodeIp}}:6640']/network-topology:termination-point[network-topology:tp-id='vxlan_over_ipv4:219.141.189.48']\"\n                }\n            ]\n        }\n    ]\n}"
+        },
+        {
+            "collectionId": "19f6b1a8-4d54-62f8-6bd6-f52e0b6e40b8",
+            "id": "950426a5-e1e5-b907-a927-8ba96727232e",
+            "headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
+            "url": "http://{{controllerHost}}:8181/restconf/config/network-topology:network-topology/topology/hwvtep:1/node/hwvtep:%2F%2F{{hwvtepNodeIp}}:6640/remote-mcast-macs/33:33:33:33:33:33",
+            "preRequestScript": "",
+            "pathVariables": {},
+            "method": "GET",
+            "data": [],
+            "dataMode": "params",
+            "version": 2,
+            "tests": "",
+            "currentHelper": "normal",
+            "helperAttributes": {},
+            "time": 1449553538252,
+            "name": "Get Specific Config McastMacRemote ",
+            "description": ""
+        },
+        {
+            "collectionId": "19f6b1a8-4d54-62f8-6bd6-f52e0b6e40b8",
+            "id": "950b4c53-a6ab-7479-4fd8-7edb7a113c34",
+            "headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
+            "url": "http://{{controllerHost}}:8181/restconf/config/network-topology:network-topology/topology/hwvtep:1/node/hwvtep:%2F%2F{{hwvtepNodeIp}}:6640/remote-mcast-macs/33:33:33:33:33:33",
+            "preRequestScript": "",
+            "pathVariables": {},
+            "method": "DELETE",
+            "data": [],
+            "dataMode": "raw",
+            "version": 2,
+            "tests": "",
+            "currentHelper": "normal",
+            "helperAttributes": {},
+            "time": 1449553525974,
+            "name": "delete Specific Config McastMacRemote ",
+            "description": "",
+            "rawModeData": ""
+        },
+        {
+            "collectionId": "19f6b1a8-4d54-62f8-6bd6-f52e0b6e40b8",
+            "id": "4e706a35-365a-13e4-f2ec-eee027148450",
+            "headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
+            "url": "http://{{controllerHost}}:8181/restconf/operational/network-topology:network-topology/topology/hwvtep:1/node/hwvtep:%2F%2F{{hwvtepNodeIp}}:6640/remote-mcast-macs/33:33:33:33:33:33",
+            "preRequestScript": "",
+            "pathVariables": {},
+            "method": "GET",
+            "data": [],
+            "dataMode": "raw",
+            "version": 2,
+            "tests": "",
+            "currentHelper": "normal",
+            "helperAttributes": {},
+            "time": 1449553579687,
+            "name": "Get Specific Operational McastMacRemote ",
+            "description": "",
+            "rawModeData": ""
+        },
+        {
+            "collectionId": "19f6b1a8-4d54-62f8-6bd6-f52e0b6e40b8",
+            "id": "29d99111-06d1-3bb7-b482-2c492f072b31",
+            "headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
+            "url": "http://{{controllerHost}}:8181/restconf/config/network-topology:network-topology/topology/hwvtep:1/node/hwvtep:%2F%2F{{hwvtepNodeIp}}:6640",
+            "preRequestScript": "",
+            "pathVariables": {},
+            "method": "POST",
+            "data": [],
+            "dataMode": "raw",
+            "version": 2,
+            "tests": "",
+            "currentHelper": "normal",
+            "helperAttributes": {},
+            "time": 1449468010690,
+            "name": "Create Specific Config McastMacLocal",
+            "description": "",
+            "rawModeData": "{\n  \"local-mcast-macs\": [\n        {\n            \"mac-entry-key\": \"44:44:44:44:44:66\",\n            \"logical-switch-ref\": \"ls0\",\n            \"ipaddr\": \"4.4.4.6\",\n            \"locator-set\": [\n                {\n                    \"locator-ref\": \"/network-topology:network-topology/network-topology:topology[network-topology:topology-id='hwvtep:1']/network-topology:node[network-topology:node-id='hwvtep://{{hwvtepNodeIp}}:6640']/network-topology:termination-point[network-topology:tp-id='vxlan_over_ipv4:219.141.189.49']\"\n                },\n                {\n                    \"locator-ref\": \"/network-topology:network-topology/network-topology:topology[network-topology:topology-id='hwvtep:1']/network-topology:node[network-topology:node-id='hwvtep://{{hwvtepNodeIp}}:6640']/network-topology:termination-point[network-topology:tp-id='vxlan_over_ipv4:219.141.189.48']\"\n                }\n            ]\n        }\n    ]\n}"
+        },
+        {
+            "collectionId": "19f6b1a8-4d54-62f8-6bd6-f52e0b6e40b8",
+            "id": "112f40f9-05b8-d6f0-fcb2-7b9d50fb8fdc",
+            "headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
+            "url": "http://{{controllerHost}}:8181/restconf/config/network-topology:network-topology/topology/hwvtep:1/node/hwvtep:%2F%2F{{hwvtepNodeIp}}:6640/local-mcast-macs/44:44:44:44:44:44",
+            "preRequestScript": "",
+            "pathVariables": {},
+            "method": "PUT",
+            "data": [],
+            "dataMode": "raw",
+            "version": 2,
+            "tests": "",
+            "currentHelper": "normal",
+            "helperAttributes": {},
+            "time": 1449468504628,
+            "name": "Update Specific Config McastMacLocal",
+            "description": "",
+            "rawModeData": "{\n  \"local-mcast-macs\": [\n        {\n            \"mac-entry-key\": \"44:44:44:44:44:44\",\n            \"logical-switch-ref\": \"ls0\",\n            \"ipaddr\": \"4.4.4.4\",\n            \"locator-set\": [\n                {\n                    \"locator-ref\": \"/network-topology:network-topology/network-topology:topology[network-topology:topology-id='hwvtep:1']/network-topology:node[network-topology:node-id='hwvtep://{{hwvtepNodeIp}}:6640']/network-topology:termination-point[network-topology:tp-id='vxlan_over_ipv4:219.141.189.49']\"\n                },\n                {\n                    \"locator-ref\": \"/network-topology:network-topology/network-topology:topology[network-topology:topology-id='hwvtep:1']/network-topology:node[network-topology:node-id='hwvtep://{{hwvtepNodeIp}}:6640']/network-topology:termination-point[network-topology:tp-id='vxlan_over_ipv4:219.141.189.48']\"\n                }\n            ]\n        }\n    ]\n}"
+        },
+        {
+            "collectionId": "19f6b1a8-4d54-62f8-6bd6-f52e0b6e40b8",
+            "id": "14fbdff8-1255-5c24-7483-fba3d217d51c",
+            "headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
+            "url": "http://{{controllerHost}}:8181/restconf/config/network-topology:network-topology/topology/hwvtep:1/node/hwvtep:%2F%2F{{hwvtepNodeIp}}:6640/local-mcast-macs/44:44:44:44:44:44",
+            "preRequestScript": "",
+            "pathVariables": {},
+            "method": "GET",
+            "data": [],
+            "dataMode": "params",
+            "version": 2,
+            "tests": "",
+            "currentHelper": "normal",
+            "helperAttributes": {},
+            "time": 1449553697904,
+            "name": "Get Specific Config McastMacLocal ",
+            "description": ""
+        },
+        {
+            "collectionId": "19f6b1a8-4d54-62f8-6bd6-f52e0b6e40b8",
+            "id": "daafe0e1-62d7-8040-b6b1-0956b937a233",
+            "headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
+            "url": "http://{{controllerHost}}:8181/restconf/config/network-topology:network-topology/topology/hwvtep:1/node/hwvtep:%2F%2F{{hwvtepNodeIp}}:6640/local-mcast-macs/44:44:44:44:44:44",
+            "preRequestScript": "",
+            "pathVariables": {},
+            "method": "DELETE",
+            "data": [],
+            "dataMode": "raw",
+            "version": 2,
+            "tests": "",
+            "currentHelper": "normal",
+            "helperAttributes": {},
+            "time": 1449553714791,
+            "name": "Delete Specific Config McastMacLocal ",
+            "description": "",
+            "rawModeData": ""
+        },
+        {
+            "collectionId": "19f6b1a8-4d54-62f8-6bd6-f52e0b6e40b8",
+            "id": "06025ed3-7251-5ee4-3d6b-c01557eb3dd2",
+            "headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
+            "url": "http://{{controllerHost}}:8181/restconf/operational/network-topology:network-topology/topology/hwvtep:1/node/hwvtep:%2F%2F{{hwvtepNodeIp}}:6640/local-mcast-macs/44:44:44:44:44:44",
+            "preRequestScript": "",
+            "pathVariables": {},
+            "method": "GET",
+            "data": [],
+            "dataMode": "params",
+            "version": 2,
+            "tests": "",
+            "currentHelper": "normal",
+            "helperAttributes": {},
+            "time": 1449553741834,
+            "name": "Get Specific Operational McastMacLocal ",
+            "description": ""
         }
     ]
 }