--- /dev/null
+/*
+ * Copyright (c) 2016 CableLabs 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.unimgr.api;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+
+public abstract class AbstractCommand<D extends DataObject> {
+
+ protected DataBroker dataBroker;
+ protected DataTreeModification<D> dataObject;
+
+ /**
+ * Abstract command basic constructor
+ * @param dataBroker
+ * @param dataObject
+ */
+ public AbstractCommand(final DataBroker dataBroker, final DataTreeModification<D> dataObject) {
+ this.dataBroker = dataBroker;
+ this.dataObject = dataObject;
+ }
+
+ /**
+ * Abstract execute method
+ */
+ public abstract void execute();
+
+}
+++ /dev/null
-/*
- * Copyright (c) 2015 CableLabs 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.unimgr.api;
-
-import java.util.Map;
-
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-public interface IUnimgrDataChangeListener extends DataChangeListener,
- AutoCloseable {
-
- void create(Map<InstanceIdentifier<?>, DataObject> changes);
-
- void update(Map<InstanceIdentifier<?>, DataObject> changes);
-
- void delete(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes);
-}
--- /dev/null
+/*
+ * Copyright (c) 2016 CableLabs 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.unimgr.api;
+
+import java.util.Collection;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+
+/**
+ * abstract class for unimgr data tree changes.
+ * @author mohamed el-serngawy
+ * @param <D> extended data object
+ */
+public abstract class UnimgrDataTreeChangeListener<D extends DataObject> implements DataTreeChangeListener<D>, AutoCloseable {
+
+ protected DataBroker dataBroker;
+
+ public UnimgrDataTreeChangeListener(final DataBroker dataBroker) {
+ this.dataBroker = dataBroker;
+ }
+
+ /**
+ * Basic Implementation of DataTreeChange Listener to execute add, update or remove command
+ * based on the data object modification type.
+ */
+ @Override
+ public void onDataTreeChanged(Collection<DataTreeModification<D>> collection) {
+ for (final DataTreeModification<D> change : collection) {
+ final DataObjectModification<D> root = change.getRootNode();
+ switch (root.getModificationType()) {
+ case SUBTREE_MODIFIED:
+ update(change);
+ break;
+ case WRITE:
+ add(change);
+ break;
+ case DELETE:
+ remove(change);
+ break;
+ }
+ }
+ }
+
+ /**
+ * method should implements the added data object command
+ * @param newDataObject
+ */
+ public abstract void add(DataTreeModification<D> newDataObject);
+
+ /**
+ * method should implements the removed data object command
+ * @param removedDataObject
+ */
+ public abstract void remove(DataTreeModification<D> removedDataObject);
+
+ /**
+ * method should implements the updated data object command
+ * @param modifiedDataObject
+ */
+ public abstract void update(DataTreeModification<D> modifiedDataObject);
+}
+++ /dev/null
-/*
- * Copyright (c) 2015 CableLabs 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.unimgr.command;
-
-import java.util.Map;
-
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-public abstract class AbstractCreateCommand implements Command {
-
- protected Map<InstanceIdentifier<?>, DataObject> changes;
- protected DataBroker dataBroker;
-
- @Override
- public abstract void execute();
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 CableLabs 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.unimgr.command;
-
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-public abstract class AbstractDeleteCommand implements Command {
-
- protected AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes;
- protected DataBroker dataBroker;
-
- @Override
- public abstract void execute();
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 CableLabs 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.unimgr.command;
-
-import java.util.Map;
-
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-public abstract class AbstractUpdateCommand implements Command {
-
- protected Map<InstanceIdentifier<?>, DataObject> changes;
- protected DataBroker dataBroker;
-
- @Override
- public abstract void execute();
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 CableLabs 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.unimgr.command;
-
-public interface Command {
-
- public void execute();
-
-}
/*
- * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ * Copyright (c) 2016 CableLabs 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,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.unimgr.command;
-import java.util.Map;
-import java.util.Map.Entry;
+package org.opendaylight.unimgr.command;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.unimgr.api.AbstractCommand;
import org.opendaylight.unimgr.impl.UnimgrConstants;
import org.opendaylight.unimgr.impl.UnimgrMapper;
import org.opendaylight.unimgr.utils.EvcUtils;
import org.opendaylight.unimgr.utils.OvsdbUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
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.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Optional;
-public class EvcCreateCommand extends AbstractCreateCommand {
+public class EvcAddCommand extends AbstractCommand<Link> {
- private static final Logger LOG = LoggerFactory.getLogger(EvcCreateCommand.class);
+ private static final Logger LOG = LoggerFactory.getLogger(EvcAddCommand.class);
- public EvcCreateCommand(DataBroker dataBroker,
- Map<InstanceIdentifier<?>, DataObject> changes) {
- super.dataBroker = dataBroker;
- super.changes = changes;
+ public EvcAddCommand(final DataBroker dataBroker, final DataTreeModification<Link> newEvcLink) {
+ super(dataBroker, newEvcLink);
}
@Override
public void execute() {
- for (Entry<InstanceIdentifier<?>, DataObject> created : changes.entrySet()) {
- if ((created.getValue() != null) && (created.getValue() instanceof EvcAugmentation)) {
- EvcAugmentation evc = (EvcAugmentation) created.getValue();
- InstanceIdentifier<?> evcKey = created.getKey();
+ final InstanceIdentifier<?> evcKey = dataObject.getRootPath().getRootIdentifier();
+ Optional<Link> optLinks = MdsalUtils.readLink(dataBroker, LogicalDatastoreType.OPERATIONAL, evcKey);
+ if (!optLinks.isPresent()) {
+ final Link evcLink = dataObject.getRootNode().getDataAfter();
+ final EvcAugmentation evc = evcLink.getAugmentation(EvcAugmentation.class);
+ if (evc != null) {
// For now, we assume that there is 1 uni per source/destination
if ((evc.getUniDest() == null) || evc.getUniDest().isEmpty()) {
LOG.error("Destination UNI cannot be null.");
- break;
+ return;
}
if ((evc.getUniSource() == null) || evc.getUniSource().isEmpty()) {
LOG.error("Source UNI cannot be null.");
- break;
+ return;
}
LOG.info("New EVC created, source IP: {} destination IP {}.",
evc.getUniSource().iterator().next().getIpAddress().getIpv4Address(),
InstanceIdentifier<Node> destinationUniIid;
//FIXME we are assuming that there is only 1 UNI source and destination
// per evc
- InstanceIdentifier<?> iidSource = evc.getUniSource().iterator().next().getUni();
+ final InstanceIdentifier<?> iidSource = evc.getUniSource().iterator().next().getUni();
if (iidSource != null) {
sourceUniIid = iidSource.firstIdentifierOf(Node.class);
} else {
evc.getUniSource().iterator().next().getIpAddress(),
LogicalDatastoreType.OPERATIONAL);
}
- InstanceIdentifier<?> iidDest = evc.getUniDest().iterator().next().getUni();
+ final InstanceIdentifier<?> iidDest = evc.getUniDest().iterator().next().getUni();
if (iidDest != null) {
destinationUniIid = iidDest.firstIdentifierOf(Node.class);
} else {
evc.getUniDest().iterator().next().getIpAddress(),
LogicalDatastoreType.OPERATIONAL);
}
- Optional<Node> optionalUniSource = MdsalUtils.readNode(dataBroker,
+ final Optional<Node> optionalUniSource = MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
sourceUniIid);
- Optional<Node> optionalUniDestination = MdsalUtils.readNode(dataBroker,
+ final Optional<Node> optionalUniDestination = MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
destinationUniIid);
Node uniSource;
uniSource = optionalUniSource.get();
uniDestination = optionalUniDestination.get();
// Set source and destination
- UniAugmentation sourceUniAugmentation =
+ final UniAugmentation sourceUniAugmentation =
uniSource.getAugmentation(UniAugmentation.class);
- UniAugmentation destinationUniAugmentation =
+ final UniAugmentation destinationUniAugmentation =
uniDestination.getAugmentation(UniAugmentation.class);
- Optional<Node> optionalSourceOvsdbNode =
+ final Optional<Node> optionalSourceOvsdbNode =
MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
sourceUniAugmentation
.getOvsdbNodeRef()
.getValue());
- Optional<Node> optionalDestinationOvsdbNode =
+ final Optional<Node> optionalDestinationOvsdbNode =
MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
destinationUniAugmentation
.getOvsdbNodeRef()
.getValue());
if (optionalSourceOvsdbNode.isPresent() && optionalDestinationOvsdbNode.isPresent()) {
- InstanceIdentifier<Node> sourceBridgeIid =
+ final InstanceIdentifier<Node> sourceBridgeIid =
UnimgrMapper.getOvsdbBridgeNodeIid(optionalSourceOvsdbNode.get());
- Optional<Node> optionalSourceBr = MdsalUtils.readNode(dataBroker,
+ final Optional<Node> optionalSourceBr = MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
sourceBridgeIid);
- InstanceIdentifier<Node> destinationBridgeIid =
+ final InstanceIdentifier<Node> destinationBridgeIid =
UnimgrMapper.getOvsdbBridgeNodeIid(optionalDestinationOvsdbNode.get());
- Optional<Node> optionalDestinationBr = MdsalUtils.readNode(dataBroker,
+ final Optional<Node> optionalDestinationBr = MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
destinationBridgeIid);
//update ovsdb qos-entry and queues with max-rate to match evc ingress BW
UnimgrConstants.DEFAULT_BRIDGE_NAME,
UnimgrConstants.DEFAULT_GRE_TUNNEL_NAME);
EvcUtils.updateEvcNode(LogicalDatastoreType.CONFIGURATION,
- evcKey,
- evc,
- sourceUniIid,
- destinationUniIid,
- dataBroker);
+ evcKey,
+ evc,
+ sourceUniIid,
+ destinationUniIid,
+ dataBroker);
EvcUtils.updateEvcNode(LogicalDatastoreType.OPERATIONAL,
evcKey,
evc,
+++ /dev/null
-/*
- * Copyright (c) 2016 CableLabs 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.unimgr.command;
-
-import java.util.List;
-import java.util.Set;
-
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.unimgr.utils.EvcUtils;
-import org.opendaylight.unimgr.utils.MdsalUtils;
-import org.opendaylight.unimgr.utils.OvsdbUtils;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDest;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSource;
-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.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-import com.google.common.base.Optional;
-
-public class EvcDeleteCommand extends AbstractDeleteCommand {
-
- public EvcDeleteCommand(DataBroker dataBroker,
- AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes) {
- super.changes = changes;
- super.dataBroker = dataBroker;
- }
-
- @Override
- public void execute() {
- Set<InstanceIdentifier<EvcAugmentation>> removedEvcs = OvsdbUtils.extractRemoved(changes,
- EvcAugmentation.class);
- if (!removedEvcs.isEmpty()) {
- for (InstanceIdentifier<EvcAugmentation> removedEvcIid: removedEvcs) {
- EvcAugmentation evcAugmentation = MdsalUtils.read(dataBroker,
- LogicalDatastoreType.OPERATIONAL,
- removedEvcIid);
- if (evcAugmentation != null) {
- List<UniSource> unisSource = evcAugmentation.getUniSource();
- List<UniDest> unisDest = evcAugmentation.getUniDest();
- if (unisSource != null && !unisSource.isEmpty()) {
- for (UniSource source: unisSource) {
- if (source != null) {
- Optional<Node> optionalSourceUniNode =
- MdsalUtils.readNode(dataBroker,
- LogicalDatastoreType.OPERATIONAL,
- source.getUni());
- EvcUtils.deleteEvcData(dataBroker, optionalSourceUniNode);
- }
- }
- }
- if (unisDest != null && !unisDest.isEmpty()) {
- for (UniDest dest : unisDest) {
- if (dest != null) {
- Optional<Node> optionalDestUniNode =
- MdsalUtils.readNode(dataBroker,
- LogicalDatastoreType.OPERATIONAL,
- dest.getUni());
- EvcUtils.deleteEvcData(dataBroker, optionalDestUniNode);
- }
- }
- }
- }
- MdsalUtils.deleteNode(dataBroker, removedEvcIid, LogicalDatastoreType.OPERATIONAL);
- }
- }
- }
-}
--- /dev/null
+/*
+ * Copyright (c) 2016 CableLabs 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.unimgr.command;
+
+import java.util.List;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.unimgr.api.AbstractCommand;
+import org.opendaylight.unimgr.utils.EvcUtils;
+import org.opendaylight.unimgr.utils.MdsalUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDest;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSource;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Optional;
+
+public class EvcRemoveCommand extends AbstractCommand<Link> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(EvcRemoveCommand.class);
+
+ public EvcRemoveCommand(final DataBroker dataBroker, final DataTreeModification<Link> removedEvcLink) {
+ super(dataBroker, removedEvcLink);
+ }
+
+ @Override
+ public void execute() {
+ final Link evcLink = dataObject.getRootNode().getDataBefore();
+ final EvcAugmentation evcAugmentation = evcLink.getAugmentation(EvcAugmentation.class);
+ final InstanceIdentifier<?> removedEvcIid = dataObject.getRootPath().getRootIdentifier();
+ if (evcAugmentation != null) {
+ final List<UniSource> unisSource = evcAugmentation.getUniSource();
+ final List<UniDest> unisDest = evcAugmentation.getUniDest();
+ if (unisSource != null && !unisSource.isEmpty()) {
+ for (final UniSource source: unisSource) {
+ if (source != null) {
+ final Optional<Node> optionalSourceUniNode =
+ MdsalUtils.readNode(dataBroker,
+ LogicalDatastoreType.OPERATIONAL,
+ source.getUni());
+ EvcUtils.deleteEvcData(dataBroker, optionalSourceUniNode);
+ }
+ }
+ }
+ if (unisDest != null && !unisDest.isEmpty()) {
+ for (final UniDest dest : unisDest) {
+ if (dest != null) {
+ final Optional<Node> optionalDestUniNode =
+ MdsalUtils.readNode(dataBroker,
+ LogicalDatastoreType.OPERATIONAL,
+ dest.getUni());
+ EvcUtils.deleteEvcData(dataBroker, optionalDestUniNode);
+ }
+ }
+ }
+ }
+ else {
+ LOG.info("EvcAugmentation is null");
+ }
+ MdsalUtils.deleteNode(dataBroker, removedEvcIid, LogicalDatastoreType.OPERATIONAL);
+ }
+}
/*
- * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ * Copyright (c) 2016 CableLabs 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,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
+
package org.opendaylight.unimgr.command;
-import java.util.Map;
-import java.util.Map.Entry;
+import java.util.concurrent.ExecutionException;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.unimgr.api.AbstractCommand;
import org.opendaylight.unimgr.impl.UnimgrConstants;
import org.opendaylight.unimgr.impl.UnimgrMapper;
import org.opendaylight.unimgr.utils.EvcUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
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.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.CheckedFuture;
-public class EvcUpdateCommand extends AbstractUpdateCommand {
+public class EvcUpdateCommand extends AbstractCommand<Link> {
private static final Logger LOG = LoggerFactory.getLogger(EvcUpdateCommand.class);
- public EvcUpdateCommand(final DataBroker dataBroker,
- final Map<InstanceIdentifier<?>, DataObject> changes) {
- super.dataBroker = dataBroker;
- super.changes = changes;
+ public EvcUpdateCommand(final DataBroker dataBroker, final DataTreeModification<Link> updatedEvcLink) {
+ super(dataBroker, updatedEvcLink);
}
- @SuppressWarnings("unchecked")
@Override
public void execute() {
- for (final Entry<InstanceIdentifier<?>, DataObject> updated : changes.entrySet()) {
- if ((updated.getValue() != null) && (updated.getValue() instanceof EvcAugmentation)) {
- final EvcAugmentation evc = (EvcAugmentation) updated.getValue();
- final InstanceIdentifier<?> evcKey = updated.getKey();
-
- // FIXME: For now, we assume that there is 1 uni per
- // source/destination
- if ((evc.getUniDest() == null) || evc.getUniDest().isEmpty()) {
- LOG.error("Destination UNI cannot be null.");
- break;
- }
- if ((evc.getUniSource() == null) || evc.getUniSource().isEmpty()) {
- LOG.error("Source UNI cannot be null.");
- break;
- }
-
- final Ipv4Address laterUni1Ip = evc.getUniSource().iterator().next().getIpAddress().getIpv4Address();
- final Ipv4Address laterUni2Ip = evc.getUniDest().iterator().next().getIpAddress().getIpv4Address();
- LOG.trace("New EVC created, source IP: {} destination IP {}.", laterUni1Ip, laterUni2Ip);
-
-
- final ReadTransaction readTransac = dataBroker.newReadOnlyTransaction();
- final CheckedFuture<?, ReadFailedException> retFormerEvc = readTransac.read(LogicalDatastoreType.OPERATIONAL, evcKey);
- EvcAugmentation formerEvc;
- try {
- formerEvc = (EvcAugmentation) ((Optional<EvcAugmentation>) retFormerEvc.checkedGet()).get();
- final Ipv4Address formerUni1ip = formerEvc.getUniSource().iterator().next().getIpAddress().getIpv4Address();
- final Ipv4Address formerUni2ip = formerEvc.getUniDest().iterator().next().getIpAddress().getIpv4Address();
-
- if (formerUni1ip.equals(laterUni1Ip)) {
- // do nothing
- } else if (formerUni1ip.equals(laterUni2Ip)) {
- // do nothing
- } else {
- LOG.info("{} is not part of the EVC, removing configuration", formerUni1ip);
- final InstanceIdentifier<?> formerUniIID = UnimgrMapper.getUniIid(dataBroker, new IpAddress(formerUni1ip), LogicalDatastoreType.OPERATIONAL);
- final Optional<Node> formerUni = MdsalUtils.readNode(dataBroker, LogicalDatastoreType.OPERATIONAL, formerUniIID);
- EvcUtils.deleteEvcData(dataBroker, formerUni);
- }
- if (formerUni2ip.equals(laterUni1Ip)) {
- // do nothing
- } else if (formerUni2ip.equals(laterUni2Ip)) {
- // do nothing
- } else {
- LOG.info("{} is not part of the EVC, removing configuration", formerUni2ip);
- final InstanceIdentifier<?> formerUniIID = UnimgrMapper.getUniIid(dataBroker, new IpAddress(formerUni2ip), LogicalDatastoreType.OPERATIONAL);
- final Optional<Node> formerUni = MdsalUtils.readNode(dataBroker, LogicalDatastoreType.OPERATIONAL, formerUniIID);
- EvcUtils.deleteEvcData(dataBroker, formerUni);
- }
- } catch (final ReadFailedException e) {
- LOG.error("Failed to retrieve former EVC {}", evcKey, e);
- }
-
- InstanceIdentifier<Node> sourceUniIid;
- InstanceIdentifier<Node> destinationUniIid;
+ final Link evcLink = dataObject.getRootNode().getDataAfter();
+ final EvcAugmentation evc = evcLink.getAugmentation(EvcAugmentation.class);
+ final InstanceIdentifier<Link> evcKey = dataObject.getRootPath().getRootIdentifier();
+ if (evc != null) {
+ // FIXME: For now, we assume that there is 1 uni per
+ // source/destination
+ if ((evc.getUniDest() == null) || evc.getUniDest().isEmpty()) {
+ LOG.error("Destination UNI cannot be null.");
+ return;
+ }
+ if ((evc.getUniSource() == null) || evc.getUniSource().isEmpty()) {
+ LOG.error("Source UNI cannot be null.");
+ return;
+ }
- final InstanceIdentifier<?> iidSource = evc.getUniSource().iterator().next().getUni();
- if (iidSource != null) {
- sourceUniIid = iidSource.firstIdentifierOf(Node.class);
+ final Ipv4Address laterUni1Ip = evc.getUniSource().iterator().next().getIpAddress().getIpv4Address();
+ final Ipv4Address laterUni2Ip = evc.getUniDest().iterator().next().getIpAddress().getIpv4Address();
+ LOG.trace("New EVC created, source IP: {} destination IP {}.", laterUni1Ip, laterUni2Ip);
+
+ final ReadTransaction readTransac = dataBroker.newReadOnlyTransaction();
+ final CheckedFuture<Optional<Link>, ReadFailedException> retFormerEvc = readTransac.read(LogicalDatastoreType.OPERATIONAL, evcKey);
+ EvcAugmentation formerEvc;
+ try {
+ Optional<Link> optLinks = retFormerEvc.get();
+ if(optLinks != null && optLinks.isPresent()) {
+ formerEvc = optLinks.get().getAugmentation(EvcAugmentation.class);
+ final Ipv4Address formerUni1ip = formerEvc.getUniSource().iterator().next().getIpAddress().getIpv4Address();
+ final Ipv4Address formerUni2ip = formerEvc.getUniDest().iterator().next().getIpAddress().getIpv4Address();
+
+ if (formerUni1ip.equals(laterUni1Ip)) {
+ // do nothing
+ } else if (formerUni1ip.equals(laterUni2Ip)) {
+ // do nothing
} else {
- sourceUniIid = UnimgrMapper.getUniIid(dataBroker,
- evc.getUniSource().iterator().next().getIpAddress(),
- LogicalDatastoreType.OPERATIONAL);
+ LOG.info("{} is not part of the EVC, removing configuration", formerUni1ip);
+ final InstanceIdentifier<?> formerUniIID = UnimgrMapper.getUniIid(dataBroker, new IpAddress(formerUni1ip), LogicalDatastoreType.OPERATIONAL);
+ final Optional<Node> formerUni = MdsalUtils.readNode(dataBroker, LogicalDatastoreType.OPERATIONAL, formerUniIID);
+ EvcUtils.deleteEvcData(dataBroker, formerUni);
}
- final InstanceIdentifier<?> iidDest = evc.getUniDest().iterator().next().getUni();
- if (iidDest != null) {
- destinationUniIid = iidDest.firstIdentifierOf(Node.class);
+ if (formerUni2ip.equals(laterUni1Ip)) {
+ // do nothing
+ } else if (formerUni2ip.equals(laterUni2Ip)) {
+ // do nothing
} else {
- destinationUniIid = UnimgrMapper.getUniIid(dataBroker,
- evc.getUniDest().iterator().next().getIpAddress(),
- LogicalDatastoreType.OPERATIONAL);
+ LOG.info("{} is not part of the EVC, removing configuration", formerUni2ip);
+ final InstanceIdentifier<?> formerUniIID = UnimgrMapper.getUniIid(dataBroker, new IpAddress(formerUni2ip), LogicalDatastoreType.OPERATIONAL);
+ final Optional<Node> formerUni = MdsalUtils.readNode(dataBroker, LogicalDatastoreType.OPERATIONAL, formerUniIID);
+ EvcUtils.deleteEvcData(dataBroker, formerUni);
+ }
}
+ } catch (final InterruptedException | ExecutionException e) {
+ LOG.error("Failed to retrieve former EVC {}", evcKey, e);
+ }
- // Retrieve the source and destination UNIs
- final Optional<Node> optionalUniSource = MdsalUtils.readNode(dataBroker,
- LogicalDatastoreType.OPERATIONAL,
- sourceUniIid);
- final Optional<Node> optionalUniDestination = MdsalUtils.readNode(dataBroker,
- LogicalDatastoreType.OPERATIONAL,
- destinationUniIid);
-
- Node uniSource = null;
- Node uniDestination = null;
-
- if (optionalUniSource.isPresent() && optionalUniDestination.isPresent()) {
- uniSource = optionalUniSource.get();
- uniDestination = optionalUniDestination.get();
-
- // Retrieve the source and/or destination OVSDB node
- final UniAugmentation sourceUniAugmentation =
- uniSource.getAugmentation(UniAugmentation.class);
- final UniAugmentation destinationUniAugmentation =
- uniDestination.getAugmentation(UniAugmentation.class);
- final Optional<Node> optionalSourceOvsdbNode =
- MdsalUtils.readNode(dataBroker,
- LogicalDatastoreType.OPERATIONAL,
- sourceUniAugmentation
- .getOvsdbNodeRef()
- .getValue());
- final Optional<Node> optionalDestinationOvsdbNode =
- MdsalUtils.readNode(dataBroker,
- LogicalDatastoreType.OPERATIONAL,
- destinationUniAugmentation
- .getOvsdbNodeRef()
- .getValue());
- if (optionalSourceOvsdbNode.isPresent() && optionalDestinationOvsdbNode.isPresent()) {
- // Retrieve the source and/or destination bridge
- final InstanceIdentifier<Node> sourceBridgeIid =
- UnimgrMapper.getOvsdbBridgeNodeIid(optionalSourceOvsdbNode.get());
- final Optional<Node> optionalSourceBr = MdsalUtils.readNode(dataBroker,
+ InstanceIdentifier<Node> sourceUniIid;
+ InstanceIdentifier<Node> destinationUniIid;
+
+ final InstanceIdentifier<?> iidSource = evc.getUniSource().iterator().next().getUni();
+ if (iidSource != null) {
+ sourceUniIid = iidSource.firstIdentifierOf(Node.class);
+ } else {
+ sourceUniIid = UnimgrMapper.getUniIid(dataBroker,
+ evc.getUniSource().iterator().next().getIpAddress(),
+ LogicalDatastoreType.OPERATIONAL);
+ }
+ final InstanceIdentifier<?> iidDest = evc.getUniDest().iterator().next().getUni();
+ if (iidDest != null) {
+ destinationUniIid = iidDest.firstIdentifierOf(Node.class);
+ } else {
+ destinationUniIid = UnimgrMapper.getUniIid(dataBroker,
+ evc.getUniDest().iterator().next().getIpAddress(),
+ LogicalDatastoreType.OPERATIONAL);
+ }
+
+ // Retrieve the source and destination UNIs
+ final Optional<Node> optionalUniSource = MdsalUtils.readNode(dataBroker,
+ LogicalDatastoreType.OPERATIONAL,
+ sourceUniIid);
+ final Optional<Node> optionalUniDestination = MdsalUtils.readNode(dataBroker,
+ LogicalDatastoreType.OPERATIONAL,
+ destinationUniIid);
+
+ Node uniSource = null;
+ Node uniDestination = null;
+
+ if (optionalUniSource.isPresent() && optionalUniDestination.isPresent()) {
+ uniSource = optionalUniSource.get();
+ uniDestination = optionalUniDestination.get();
+
+ // Retrieve the source and/or destination OVSDB node
+ final UniAugmentation sourceUniAugmentation =
+ uniSource.getAugmentation(UniAugmentation.class);
+ final UniAugmentation destinationUniAugmentation =
+ uniDestination.getAugmentation(UniAugmentation.class);
+ final Optional<Node> optionalSourceOvsdbNode =
+ MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
- sourceBridgeIid);
- final InstanceIdentifier<Node> destinationBridgeIid =
- UnimgrMapper.getOvsdbBridgeNodeIid(optionalDestinationOvsdbNode.get());
- final Optional<Node> optionalDestinationBr = MdsalUtils.readNode(dataBroker,
+ sourceUniAugmentation
+ .getOvsdbNodeRef()
+ .getValue());
+ final Optional<Node> optionalDestinationOvsdbNode =
+ MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
- destinationBridgeIid);
- //update ovsdb qos-entry and queues with max-rate to match evc ingress BW
- OvsdbUtils.updateMaxRate(dataBroker, sourceUniAugmentation, destinationUniAugmentation, evc);
- Node sourceBr = null;
- Node destinationBr = null;
- if (optionalSourceBr.isPresent() && optionalDestinationBr.isPresent()) {
- sourceBr = optionalSourceBr.get();
- destinationBr = optionalDestinationBr.get();
-
- // Creating termination points (OVSDB CONFIG
- // datastore)
- OvsdbUtils.createTerminationPointNode(dataBroker,
- uniSource.getAugmentation(UniAugmentation.class),
- sourceBr,
- UnimgrConstants.DEFAULT_BRIDGE_NAME,
- UnimgrConstants.DEFAULT_TUNNEL_IFACE);
-
- // Create GRE tunnel (OVSDB CONFIG datastore)
- OvsdbUtils.createGreTunnel(dataBroker,
- uniSource.getAugmentation(UniAugmentation.class),
- uniDestination.getAugmentation(UniAugmentation.class),
- sourceBr,
- UnimgrConstants.DEFAULT_BRIDGE_NAME,
- UnimgrConstants.DEFAULT_GRE_TUNNEL_NAME);
-
- // Create termination points (CONFIG datastore)
- OvsdbUtils.createTerminationPointNode(dataBroker,
- uniSource.getAugmentation(UniAugmentation.class),
- destinationBr,
- UnimgrConstants.DEFAULT_BRIDGE_NAME,
- UnimgrConstants.DEFAULT_TUNNEL_IFACE);
-
- // Create GRE tunnel (OVSDB CONFIG datastore)
- OvsdbUtils.createGreTunnel(dataBroker,
- uniDestination.getAugmentation(UniAugmentation.class),
- uniSource.getAugmentation(UniAugmentation.class), destinationBr,
- UnimgrConstants.DEFAULT_BRIDGE_NAME,
- UnimgrConstants.DEFAULT_GRE_TUNNEL_NAME);
-
- // Update EVC
- EvcUtils.updateEvcNode(LogicalDatastoreType.CONFIGURATION,
- evcKey,
- evc,
- sourceUniIid,
- destinationUniIid,
- dataBroker);
- EvcUtils.updateEvcNode(LogicalDatastoreType.OPERATIONAL,
- evcKey,
- evc,
- sourceUniIid,
- destinationUniIid,
- dataBroker);
- } else {
- LOG.info("Unable to retrieve the source and/or destination bridge.");
- }
+ destinationUniAugmentation
+ .getOvsdbNodeRef()
+ .getValue());
+ if (optionalSourceOvsdbNode.isPresent() && optionalDestinationOvsdbNode.isPresent()) {
+ // Retrieve the source and/or destination bridge
+ final InstanceIdentifier<Node> sourceBridgeIid =
+ UnimgrMapper.getOvsdbBridgeNodeIid(optionalSourceOvsdbNode.get());
+ final Optional<Node> optionalSourceBr = MdsalUtils.readNode(dataBroker,
+ LogicalDatastoreType.OPERATIONAL,
+ sourceBridgeIid);
+ final InstanceIdentifier<Node> destinationBridgeIid =
+ UnimgrMapper.getOvsdbBridgeNodeIid(optionalDestinationOvsdbNode.get());
+ final Optional<Node> optionalDestinationBr = MdsalUtils.readNode(dataBroker,
+ LogicalDatastoreType.OPERATIONAL,
+ destinationBridgeIid);
+ //update ovsdb qos-entry and queues with max-rate to match evc ingress BW
+ OvsdbUtils.updateMaxRate(dataBroker, sourceUniAugmentation, destinationUniAugmentation, evc);
+ Node sourceBr = null;
+ Node destinationBr = null;
+ if (optionalSourceBr.isPresent() && optionalDestinationBr.isPresent()) {
+ sourceBr = optionalSourceBr.get();
+ destinationBr = optionalDestinationBr.get();
+
+ // Creating termination points (OVSDB CONFIG
+ // datastore)
+ OvsdbUtils.createTerminationPointNode(dataBroker,
+ uniSource.getAugmentation(UniAugmentation.class),
+ sourceBr,
+ UnimgrConstants.DEFAULT_BRIDGE_NAME,
+ UnimgrConstants.DEFAULT_TUNNEL_IFACE);
+
+ // Create GRE tunnel (OVSDB CONFIG datastore)
+ OvsdbUtils.createGreTunnel(dataBroker,
+ uniSource.getAugmentation(UniAugmentation.class),
+ uniDestination.getAugmentation(UniAugmentation.class),
+ sourceBr,
+ UnimgrConstants.DEFAULT_BRIDGE_NAME,
+ UnimgrConstants.DEFAULT_GRE_TUNNEL_NAME);
+
+ // Create termination points (CONFIG datastore)
+ OvsdbUtils.createTerminationPointNode(dataBroker,
+ uniSource.getAugmentation(UniAugmentation.class),
+ destinationBr,
+ UnimgrConstants.DEFAULT_BRIDGE_NAME,
+ UnimgrConstants.DEFAULT_TUNNEL_IFACE);
+
+ // Create GRE tunnel (OVSDB CONFIG datastore)
+ OvsdbUtils.createGreTunnel(dataBroker,
+ uniDestination.getAugmentation(UniAugmentation.class),
+ uniSource.getAugmentation(UniAugmentation.class), destinationBr,
+ UnimgrConstants.DEFAULT_BRIDGE_NAME,
+ UnimgrConstants.DEFAULT_GRE_TUNNEL_NAME);
+
+ // Update EVC
+ EvcUtils.updateEvcNode(LogicalDatastoreType.CONFIGURATION,
+ evcKey,
+ evc,
+ sourceUniIid,
+ destinationUniIid,
+ dataBroker);
+ EvcUtils.updateEvcNode(LogicalDatastoreType.OPERATIONAL,
+ evcKey,
+ evc,
+ sourceUniIid,
+ destinationUniIid,
+ dataBroker);
} else {
- LOG.info("Uname to retrieve the source and/or destination ovsdbNode.");
+ LOG.info("Unable to retrieve the source and/or destination bridge.");
}
} else {
- LOG.info("Unable to retrieve the source and/or destination Uni.");
+ LOG.info("Unable to retrieve the source and/or destination ovsdbNode.");
}
+ } else {
+ LOG.info("Unable to retrieve the source and/or destination Uni.");
}
}
}
+
}
--- /dev/null
+/*
+ * Copyright (c) 2016 CableLabs 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.unimgr.command;
+
+import java.util.List;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.unimgr.api.AbstractCommand;
+import org.opendaylight.unimgr.impl.UnimgrConstants;
+import org.opendaylight.unimgr.impl.UnimgrMapper;
+import org.opendaylight.unimgr.utils.MdsalUtils;
+import org.opendaylight.unimgr.utils.OvsdbUtils;
+import org.opendaylight.unimgr.utils.UniUtils;
+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.unimgr.rev151012.UniAugmentation;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Optional;
+
+public class OvsNodeAddCommand extends AbstractCommand<Node> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(OvsNodeAddCommand.class);
+
+ public OvsNodeAddCommand(final DataBroker dataBroker, final DataTreeModification<Node> newOvsNode) {
+ super(dataBroker, newOvsNode);
+ }
+
+ @Override
+ public void execute() {
+ final Node ovsNode = dataObject.getRootNode().getDataAfter();
+ final OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsNode.getAugmentation(OvsdbNodeAugmentation.class);
+ final InstanceIdentifier<Node> ovsdbIid = dataObject.getRootPath().getRootIdentifier();
+ if (ovsdbNodeAugmentation != null) {
+ LOG.info("Received an OVSDB node create {}",
+ ovsdbNodeAugmentation.getConnectionInfo()
+ .getRemoteIp()
+ .getIpv4Address()
+ .getValue());
+ final List<Node> uniNodes = UniUtils.getUniNodes(dataBroker);
+ if (uniNodes != null && !uniNodes.isEmpty()) {
+ for (final Node uniNode: uniNodes) {
+ final UniAugmentation uniAugmentation = uniNode.getAugmentation(UniAugmentation.class);
+ if (uniAugmentation.getOvsdbNodeRef() != null
+ && uniAugmentation.getOvsdbNodeRef().getValue() != null) {
+ final InstanceIdentifier<Node> ovsdbNodeRefIid = uniAugmentation
+ .getOvsdbNodeRef()
+ .getValue()
+ .firstIdentifierOf(Node.class);
+ if (ovsdbNodeRefIid.equals(ovsdbIid)) {
+ final Optional<Node> optionalOvsdbNode = MdsalUtils.readNode(dataBroker,
+ LogicalDatastoreType.OPERATIONAL,
+ ovsdbIid);
+ if (optionalOvsdbNode.isPresent()) {
+ final InstanceIdentifier<Node> uniIid =
+ UnimgrMapper.getUniIid(dataBroker,
+ uniAugmentation.getIpAddress(),
+ LogicalDatastoreType.CONFIGURATION);
+ // Update QoS entries to ovsdb if speed is configured to UNI node
+ if (uniAugmentation.getSpeed() != null) {
+ OvsdbUtils.createQoSForOvsdbNode(dataBroker, uniAugmentation);
+ }
+ OvsdbUtils.createBridgeNode(dataBroker,
+ ovsdbIid,
+ uniAugmentation,
+ UnimgrConstants.DEFAULT_BRIDGE_NAME);
+ UniUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL,
+ uniIid,
+ uniAugmentation,
+ ovsdbIid,
+ dataBroker);
+ }
+ }
+ } else if (ovsdbNodeAugmentation
+ .getConnectionInfo()
+ .getRemoteIp()
+ .equals(uniAugmentation.getIpAddress())) {
+ final InstanceIdentifier<Node> uniIid = UnimgrMapper.getUniIid(dataBroker,
+ uniAugmentation.getIpAddress(),
+ LogicalDatastoreType.CONFIGURATION);
+ OvsdbUtils.createBridgeNode(dataBroker,
+ ovsdbIid,
+ uniAugmentation,
+ UnimgrConstants.DEFAULT_BRIDGE_NAME);
+ UniUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL,
+ uniIid,
+ uniAugmentation,
+ ovsdbIid,
+ dataBroker);
+ }
+ }
+ } else {
+ LOG.info("Received a new OVSDB node connection from {}"
+ + ovsdbNodeAugmentation.getConnectionInfo()
+ .getRemoteIp().getIpv4Address());
+ }
+ }
+ }
+
+}
+++ /dev/null
-/*
- * Copyright (c) 2015 CableLabs 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.unimgr.command;
-
-import java.util.List;
-
-public class TransactionInvoker {
-
- private Command command;
- private List<Command> commands;
-
- public void setCommand(Command command) {
- this.command = command;
- }
-
- public void setCommands(List<Command> commands) {
- this.commands = commands;
- }
-
- public void invoke() {
- if (command != null) {
- command.execute();
- }
- if (!commands.isEmpty()) {
- for (Command invokableCommand: commands) {
- invokableCommand.execute();
- }
- }
- }
-
-}
--- /dev/null
+/*
+ * Copyright (c) 2016 CableLabs 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.unimgr.command;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.unimgr.api.AbstractCommand;
+import org.opendaylight.unimgr.impl.UnimgrConstants;
+import org.opendaylight.unimgr.impl.UnimgrMapper;
+import org.opendaylight.unimgr.utils.MdsalUtils;
+import org.opendaylight.unimgr.utils.OvsdbUtils;
+import org.opendaylight.unimgr.utils.UniUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Optional;
+
+public class UniAddCommand extends AbstractCommand<Node>{
+
+ private static final Logger LOG = LoggerFactory.getLogger(UniAddCommand.class);
+
+ public UniAddCommand(final DataBroker dataBroker, final DataTreeModification<Node> newUniNode) {
+ super(dataBroker, newUniNode);
+ }
+
+ @Override
+ public void execute() {
+ final InstanceIdentifier<?> uniKey = dataObject.getRootPath().getRootIdentifier();
+ final Optional<Node> optNode = MdsalUtils.readNode(dataBroker, LogicalDatastoreType.OPERATIONAL, uniKey);
+ if(!optNode.isPresent()) {
+ final Node uniNode = dataObject.getRootNode().getDataAfter();
+ final UniAugmentation uni = uniNode.getAugmentation(UniAugmentation.class);
+ if (uni != null) {
+ LOG.info("New UNI created {}.", uni.getIpAddress().getIpv4Address());
+ // We assume the ovs is in active mode tcp:ipAddress:6640
+ if (uni.getOvsdbNodeRef() != null) {
+ final OvsdbNodeRef ovsdbNodeRef = uni.getOvsdbNodeRef();
+ final Optional<Node> optionalNode = MdsalUtils.readNode(dataBroker,
+ LogicalDatastoreType.OPERATIONAL,
+ ovsdbNodeRef.getValue());
+ if (!optionalNode.isPresent()) {
+ LOG.info("Invalid OVSDB node instance identifier specified, "
+ + "attempting to retrieve the node.");
+ final Optional<Node> optionalOvsdbNode = OvsdbUtils.findOvsdbNode(dataBroker,
+ uni);
+ Node ovsdbNode;
+ if (optionalOvsdbNode.isPresent()) {
+ ovsdbNode = optionalOvsdbNode.get();
+ LOG.info("Retrieved the OVSDB node {}", ovsdbNode.getNodeId());
+ // Update QoS entries to ovsdb if speed is configured to UNI node
+ if (uni.getSpeed() != null) {
+ OvsdbUtils.createQoSForOvsdbNode(dataBroker, uni);
+ }
+ UniUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
+ uniKey,
+ uni,
+ ovsdbNode,
+ dataBroker);
+ } else {
+ ovsdbNode = OvsdbUtils.createOvsdbNode(dataBroker,
+ uni);
+ LOG.info("Could not retrieve the OVSDB node,"
+ + " created a new one: {}", ovsdbNode.getNodeId());
+ UniUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
+ uniKey,
+ uni,
+ ovsdbNode,
+ dataBroker);
+ }
+ }
+ } else {
+ // We assume the ovs is in passive mode
+ // Check if the ovsdb node exist
+ final Optional<Node> optionalOvsdbNode = OvsdbUtils.findOvsdbNode(dataBroker,
+ uni);
+ Node ovsdbNode;
+ if (optionalOvsdbNode.isPresent()) {
+ ovsdbNode = optionalOvsdbNode.get();
+ final InstanceIdentifier<Node> ovsdbIid = UnimgrMapper.getOvsdbNodeIid(ovsdbNode.getNodeId());
+ LOG.info("Retrieved the OVSDB node");
+ // Update QoS entries to ovsdb if speed is configured to UNI node
+ if (uni.getSpeed() != null) {
+ OvsdbUtils.createQoSForOvsdbNode(dataBroker, uni);
+ }
+ OvsdbUtils.createBridgeNode(dataBroker,
+ ovsdbIid,
+ uni,
+ UnimgrConstants.DEFAULT_BRIDGE_NAME);
+ UniUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
+ uniKey,
+ uni,
+ ovsdbNode,
+ dataBroker);
+ UniUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL, uniKey, uni, ovsdbNode, dataBroker);
+ } else {
+ ovsdbNode = OvsdbUtils.createOvsdbNode(dataBroker,
+ uni);
+ if (ovsdbNode != null) {
+ LOG.info("Could not retrieve the OVSDB node,"
+ + "created a new one: {}", ovsdbNode.getNodeId());
+ UniUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
+ uniKey,
+ uni,
+ ovsdbNode,
+ dataBroker);
+ }
+ }
+ }
+ }
+ }
+ }
+
+}
+++ /dev/null
-/*
- * Copyright (c) 2015 CableLabs 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.unimgr.command;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.unimgr.impl.UnimgrConstants;
-import org.opendaylight.unimgr.impl.UnimgrMapper;
-import org.opendaylight.unimgr.utils.MdsalUtils;
-import org.opendaylight.unimgr.utils.OvsdbUtils;
-import org.opendaylight.unimgr.utils.UniUtils;
-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.OvsdbNodeRef;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
-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.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Optional;
-
-public class UniCreateCommand extends AbstractCreateCommand {
-
- private static final Logger LOG = LoggerFactory.getLogger(UniCreateCommand.class);
-
- public UniCreateCommand(DataBroker dataBroker,
- Map<InstanceIdentifier<?>, DataObject> changes) {
- super.dataBroker = dataBroker;
- super.changes = changes;
- }
-
- @Override
- public void execute() {
- for (final Entry<InstanceIdentifier<?>, DataObject> created : changes.entrySet()) {
- if (created.getValue() != null && created.getValue() instanceof UniAugmentation) {
- final UniAugmentation uni = (UniAugmentation) created.getValue();
- final InstanceIdentifier<?> uniKey = created.getKey();
- LOG.trace("New UNI created {}.", uni.getIpAddress().getIpv4Address());
- /* We assume that when the user specifies the
- * ovsdb-node-ref that the node already exists in
- * the controller and that the OVS instance is in
- * active mode.
- *
- * We assume that when the user doesn't specify the
- * ovsdb-node-id that the node doesn't exist therefor
- * has to be created with the IP address because it's
- * in passive mode.
- *
- * Active mode (TCP): the UUID is in format ovsdb://UUID
- * Passive mode (PTCP): the UUID is in format ovsdb://IP:6640
- *
- */
- if (uni.getOvsdbNodeRef() != null) {
- final OvsdbNodeRef ovsdbNodeRef = uni.getOvsdbNodeRef();
- final Optional<Node> optionalNode = MdsalUtils.readNode(dataBroker,
- LogicalDatastoreType.OPERATIONAL,
- ovsdbNodeRef.getValue());
- if (!optionalNode.isPresent()) {
- LOG.info("Invalid OVSDB node instance identifier specified, "
- + "attempting to retrieve the node.");
- final Optional<Node> optionalOvsdbNode = OvsdbUtils.findOvsdbNode(dataBroker,
- uni);
- Node ovsdbNode;
- if (optionalOvsdbNode.isPresent()) {
- ovsdbNode = optionalOvsdbNode.get();
- LOG.info("Retrieved the OVSDB node {}", ovsdbNode.getNodeId());
- // Update QoS entries to ovsdb if speed is configured to UNI node
- if (uni.getSpeed() != null) {
- OvsdbUtils.createQoSForOvsdbNode(dataBroker, uni);
- }
- UniUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
- uniKey,
- uni,
- ovsdbNode,
- dataBroker);
- } else {
- ovsdbNode = OvsdbUtils.createOvsdbNode(dataBroker,
- uni);
- LOG.info("Could not retrieve the OVSDB node,"
- + " created a new one: {}", ovsdbNode.getNodeId());
- UniUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
- uniKey,
- uni,
- ovsdbNode,
- dataBroker);
- }
- }
- } else {
- // We assume the ovs is in passive mode
- // Check if the ovsdb node exist
- final Optional<Node> optionalOvsdbNode = OvsdbUtils.findOvsdbNode(dataBroker,
- uni);
- Node ovsdbNode;
- if (optionalOvsdbNode.isPresent()) {
- ovsdbNode = optionalOvsdbNode.get();
- final InstanceIdentifier<Node> ovsdbIid = UnimgrMapper.getOvsdbNodeIid(ovsdbNode.getNodeId());
- LOG.info("Retrieved the OVSDB node");
- // Update QoS entries to ovsdb if speed is configured to UNI node
- if (uni.getSpeed() != null) {
- OvsdbUtils.createQoSForOvsdbNode(dataBroker, uni);
- }
- OvsdbUtils.createBridgeNode(dataBroker,
- ovsdbIid,
- uni,
- UnimgrConstants.DEFAULT_BRIDGE_NAME);
- UniUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
- uniKey,
- uni,
- ovsdbNode,
- dataBroker);
- UniUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL, uniKey, uni, ovsdbNode, dataBroker);
- } else {
- ovsdbNode = OvsdbUtils.createOvsdbNode(dataBroker,
- uni);
- if (ovsdbNode != null) {
- LOG.info("Could not retrieve the OVSDB node,"
- + "created a new one: {}", ovsdbNode.getNodeId());
- UniUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
- uniKey,
- uni,
- ovsdbNode,
- dataBroker);
- }
- }
- }
- }
- if (created.getValue() != null && created.getValue() instanceof OvsdbNodeAugmentation) {
- final OvsdbNodeAugmentation ovsdbNodeAugmentation = (OvsdbNodeAugmentation) created
- .getValue();
- final InstanceIdentifier<Node> ovsdbIid = created.getKey().firstIdentifierOf(Node.class);
- if (ovsdbNodeAugmentation != null) {
- LOG.info("Received an OVSDB node create {}",
- ovsdbNodeAugmentation.getConnectionInfo()
- .getRemoteIp()
- .getIpv4Address()
- .getValue());
- final List<Node> uniNodes = UniUtils.getUniNodes(dataBroker);
- if (uniNodes != null && !uniNodes.isEmpty()) {
- for (final Node uniNode: uniNodes) {
- final UniAugmentation uniAugmentation = uniNode.getAugmentation(UniAugmentation.class);
- if (uniAugmentation.getOvsdbNodeRef() != null
- && uniAugmentation.getOvsdbNodeRef().getValue() != null) {
- final InstanceIdentifier<Node> ovsdbNodeRefIid = uniAugmentation
- .getOvsdbNodeRef()
- .getValue()
- .firstIdentifierOf(Node.class);
- if (ovsdbNodeRefIid.equals(ovsdbIid)) {
- final Optional<Node> optionalOvsdbNode = MdsalUtils.readNode(dataBroker,
- LogicalDatastoreType.OPERATIONAL,
- ovsdbIid);
- if (optionalOvsdbNode.isPresent()) {
- final InstanceIdentifier<Node> uniIid =
- UnimgrMapper.getUniIid(dataBroker,
- uniAugmentation.getIpAddress(),
- LogicalDatastoreType.CONFIGURATION);
- // Update QoS entries to ovsdb if speed is configured to UNI node
- if (uniAugmentation.getSpeed() != null) {
- OvsdbUtils.createQoSForOvsdbNode(dataBroker, uniAugmentation);
- }
- OvsdbUtils.createBridgeNode(dataBroker,
- ovsdbIid,
- uniAugmentation,
- UnimgrConstants.DEFAULT_BRIDGE_NAME);
- UniUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL,
- uniIid,
- uniAugmentation,
- ovsdbIid,
- dataBroker);
- }
- }
- } else if (ovsdbNodeAugmentation
- .getConnectionInfo()
- .getRemoteIp()
- .equals(uniAugmentation.getIpAddress())) {
- final InstanceIdentifier<Node> uniIid = UnimgrMapper.getUniIid(dataBroker,
- uniAugmentation.getIpAddress(),
- LogicalDatastoreType.CONFIGURATION);
- OvsdbUtils.createBridgeNode(dataBroker,
- ovsdbIid,
- uniAugmentation,
- UnimgrConstants.DEFAULT_BRIDGE_NAME);
- UniUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL,
- uniIid,
- uniAugmentation,
- ovsdbIid,
- dataBroker);
- }
- }
- } else {
- LOG.info("Received a new OVSDB node connection from {}"
- + ovsdbNodeAugmentation.getConnectionInfo()
- .getRemoteIp().getIpv4Address());
- }
- }
- }
- }
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 CableLabs 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.unimgr.command;
-
-import java.util.List;
-import java.util.Set;
-
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.unimgr.impl.UnimgrConstants;
-import org.opendaylight.unimgr.impl.UnimgrMapper;
-import org.opendaylight.unimgr.utils.MdsalUtils;
-import org.opendaylight.unimgr.utils.OvsdbUtils;
-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.OvsdbNodeRef;
-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.node.attributes.QosEntriesKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.Queues;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QueuesKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
-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.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Optional;
-
-public class UniDeleteCommand extends AbstractDeleteCommand {
-
- private static final Logger LOG = LoggerFactory.getLogger(UniDeleteCommand.class);
-
- public UniDeleteCommand(DataBroker dataBroker,
- AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes) {
- super.changes = changes;
- super.dataBroker = dataBroker;
- }
-
- @Override
- public void execute() {
- Set<InstanceIdentifier<UniAugmentation>> removedUnis = OvsdbUtils.extractRemoved(changes,
- UniAugmentation.class);
- if (!removedUnis.isEmpty()) {
- for (InstanceIdentifier<UniAugmentation> removedUniIid: removedUnis) {
- UniAugmentation uniAugmentation = MdsalUtils.read(dataBroker,
- LogicalDatastoreType.OPERATIONAL,
- removedUniIid);
- if (uniAugmentation != null) {
- OvsdbNodeRef ovsNodedRef = uniAugmentation.getOvsdbNodeRef();
- InstanceIdentifier<Node> ovsdbNodeIid = ovsNodedRef.getValue().firstIdentifierOf(Node.class);
- Optional<Node> optionalNode = MdsalUtils.readNode(dataBroker,
- LogicalDatastoreType.OPERATIONAL,
- ovsdbNodeIid);
- if (optionalNode.isPresent()) {
- Node ovsdbNode = optionalNode.get();
- LOG.info("Delete QoS and Queues entries");
- List<QosEntries> qosList = ovsdbNode
- .getAugmentation(OvsdbNodeAugmentation.class)
- .getQosEntries();
- QosEntriesKey qosEntryKey = null;
- for (final QosEntries qosEntry : qosList) {
- qosEntryKey = qosEntry.getKey();
- InstanceIdentifier<QosEntries> qosIid = UnimgrMapper.getOvsdbQoSEntriesIid(ovsdbNode, qosEntryKey);
- MdsalUtils.deleteNode(dataBroker, qosIid, LogicalDatastoreType.CONFIGURATION);
- }
-
- List<Queues> queuesList = ovsdbNode
- .getAugmentation(OvsdbNodeAugmentation.class)
- .getQueues();
- QueuesKey queuesKey = null;
- for (final Queues queue : queuesList) {
- queuesKey = queue.getKey();
- InstanceIdentifier<Queues> queuesIid = UnimgrMapper.getOvsdbQueuesIid(ovsdbNode, queuesKey);
- MdsalUtils.deleteNode(dataBroker, queuesIid, LogicalDatastoreType.CONFIGURATION);
- }
-
- LOG.info("Delete bridge node");
- InstanceIdentifier<Node> bridgeIid = UnimgrMapper.getOvsdbBridgeNodeIid(ovsdbNode);
- Optional<Node> optBridgeNode = MdsalUtils.readNode(dataBroker, bridgeIid);
- if (optBridgeNode.isPresent()) {
- Node bridgeNode = optBridgeNode.get();
- InstanceIdentifier<TerminationPoint> iidTermPoint = UnimgrMapper.getTerminationPointIid(bridgeNode,
- UnimgrConstants.DEFAULT_BRIDGE_NAME);
- MdsalUtils.deleteNode(dataBroker, iidTermPoint, LogicalDatastoreType.CONFIGURATION);
- }
- MdsalUtils.deleteNode(dataBroker, bridgeIid, LogicalDatastoreType.CONFIGURATION);
- }
- InstanceIdentifier<Node> iidUni = UnimgrMapper.getUniIid(dataBroker, uniAugmentation.getIpAddress(),
- LogicalDatastoreType.OPERATIONAL);
- if (iidUni != null)
- MdsalUtils.deleteNode(dataBroker, iidUni, LogicalDatastoreType.OPERATIONAL);
- }
- else {
- LOG.info("Received Uni Augmentation is null", removedUniIid);
- }
- }
- }
- }
-}
--- /dev/null
+/*
+ * Copyright (c) 2016 CableLabs 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.unimgr.command;
+
+import java.util.List;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.unimgr.api.AbstractCommand;
+import org.opendaylight.unimgr.impl.UnimgrMapper;
+import org.opendaylight.unimgr.utils.MdsalUtils;
+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.OvsdbNodeRef;
+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.node.attributes.QosEntriesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.Queues;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QueuesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Optional;
+
+public class UniRemoveCommand extends AbstractCommand<Node> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(UniRemoveCommand.class);
+
+ public UniRemoveCommand(final DataBroker dataBroker, final DataTreeModification<Node> removedUniNode) {
+ super(dataBroker, removedUniNode);
+ }
+
+ @Override
+ public void execute() {
+ final Node uniNode = dataObject.getRootNode().getDataBefore();
+ final UniAugmentation uniAugmentation = uniNode.getAugmentation(UniAugmentation.class);
+ final InstanceIdentifier<?> removedUniIid = dataObject.getRootPath().getRootIdentifier()
+ .firstIdentifierOf(UniAugmentation.class);
+ if (uniAugmentation != null) {
+ final OvsdbNodeRef ovsNodedRef = uniAugmentation.getOvsdbNodeRef();
+ final InstanceIdentifier<Node> ovsdbNodeIid = ovsNodedRef.getValue().firstIdentifierOf(Node.class);
+ final Optional<Node> optionalNode = MdsalUtils.readNode(dataBroker,
+ LogicalDatastoreType.OPERATIONAL,
+ ovsdbNodeIid);
+ if (optionalNode.isPresent()) {
+ final Node ovsdbNode = optionalNode.get();
+ LOG.info("Delete QoS and Queues entries");
+ List<QosEntries> qosList = ovsdbNode
+ .getAugmentation(OvsdbNodeAugmentation.class)
+ .getQosEntries();
+ QosEntriesKey qosEntryKey = null;
+ for (final QosEntries qosEntry : qosList) {
+ qosEntryKey = qosEntry.getKey();
+ InstanceIdentifier<QosEntries> qosIid = UnimgrMapper.getOvsdbQoSEntriesIid(ovsdbNode, qosEntryKey);
+ MdsalUtils.deleteNode(dataBroker, qosIid, LogicalDatastoreType.CONFIGURATION);
+ }
+ List<Queues> queuesList = ovsdbNode
+ .getAugmentation(OvsdbNodeAugmentation.class)
+ .getQueues();
+ QueuesKey queuesKey = null;
+ for (final Queues queue : queuesList) {
+ queuesKey = queue.getKey();
+ InstanceIdentifier<Queues> queuesIid = UnimgrMapper.getOvsdbQueuesIid(ovsdbNode, queuesKey);
+ MdsalUtils.deleteNode(dataBroker, queuesIid, LogicalDatastoreType.CONFIGURATION);
+ }
+ LOG.info("Delete bride node");
+ final InstanceIdentifier<Node> bridgeIid = UnimgrMapper.getOvsdbBridgeNodeIid(ovsdbNode);
+ MdsalUtils.deleteNode(dataBroker, bridgeIid, LogicalDatastoreType.CONFIGURATION);
+ }
+ final InstanceIdentifier<Node> iidUni = UnimgrMapper.getUniIid(dataBroker, uniAugmentation.getIpAddress(),
+ LogicalDatastoreType.OPERATIONAL);
+ if (iidUni != null) {
+ MdsalUtils.deleteNode(dataBroker, iidUni, LogicalDatastoreType.OPERATIONAL);
+ }
+ }
+ else {
+ LOG.info("Received Uni Augmentation is null", removedUniIid);
+ }
+ }
+
+}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.unimgr.command;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
+package org.opendaylight.unimgr.command;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.unimgr.impl.UnimgrMapper;
+import org.opendaylight.unimgr.api.AbstractCommand;
import org.opendaylight.unimgr.utils.MdsalUtils;
import org.opendaylight.unimgr.utils.OvsdbUtils;
import org.opendaylight.unimgr.utils.UniUtils;
-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.OvsdbNodeRef;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagedNodeEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
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.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
-public class UniUpdateCommand extends AbstractUpdateCommand {
+public class UniUpdateCommand extends AbstractCommand<Node> {
private static final Logger LOG = LoggerFactory.getLogger(UniUpdateCommand.class);
- public UniUpdateCommand(DataBroker dataBroker,
- Map<InstanceIdentifier<?>, DataObject> changes) {
- super.dataBroker = dataBroker;
- super.changes = changes;
+ public UniUpdateCommand(final DataBroker dataBroker, final DataTreeModification<Node> updatedUniNode) {
+ super(dataBroker, updatedUniNode);
}
@Override
public void execute() {
- for (Entry<InstanceIdentifier<?>, DataObject> updated : changes.entrySet()) {
- if (updated.getValue() != null && updated.getValue() instanceof UniAugmentation) {
- final UniAugmentation updatedUni = (UniAugmentation) updated.getValue();
- final UniAugmentation formerUni = UniUtils.getUni(dataBroker, LogicalDatastoreType.OPERATIONAL, updatedUni.getIpAddress());
-
- if (formerUni != null) {
- String formerUniIp = formerUni.getIpAddress().getIpv4Address().getValue();
- String updatedUniIp = updatedUni.getIpAddress().getIpv4Address().getValue();
- String uniKey = updated.getKey().firstKeyOf(Node.class).toString();
- Preconditions.checkArgument(formerUniIp.equals(updatedUniIp),
- "Can't update UNI with a different IP address. Former IP was %s"
- + "Updated IP is %s. Please create a UNI instead of updating this one %s",
- formerUniIp, updatedUniIp, uniKey);
- Node ovsdbNode;
- if (updatedUni.getOvsdbNodeRef() != null) {
- LOG.info("OVSDB NODE ref retreive for updated UNI {}", updatedUni.getOvsdbNodeRef());
- final OvsdbNodeRef ovsdbNodeRef = updatedUni.getOvsdbNodeRef();
- Optional<Node> optOvsdbNode = MdsalUtils.readNode(dataBroker,LogicalDatastoreType.OPERATIONAL, ovsdbNodeRef.getValue());
- if(optOvsdbNode.isPresent()) {
- ovsdbNode= optOvsdbNode.get();
- LOG.info("Retrieved the OVSDB node {}", ovsdbNode.getNodeId());
- // Update QoS entries to ovsdb if speed is configured to UNI node
- if (updatedUni.getSpeed() != null) {
- OvsdbUtils.createQoSForOvsdbNode(dataBroker, updatedUni);
- }
- UniUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
- updated.getKey(),
- updatedUni,
- ovsdbNode,
- dataBroker);
- } else {
- // This should never happen, because on creation,
- // the UNI is assigned and OVSDB node
- LOG.error("OVSDB node not found for UNI {}, but got OVSDB ref", uniKey, updatedUni.getOvsdbNodeRef());
- return;
- }
- } else {
- Optional<Node> optOvsdbNode = OvsdbUtils.findOvsdbNode(dataBroker, updatedUni);
- if (optOvsdbNode.isPresent()) {
- ovsdbNode = optOvsdbNode.get();
- LOG.info("Retrieved the OVSDB node {}", ovsdbNode.getNodeId());
- // Update QoS entries to ovsdb if speed is configured to UNI node
- if (updatedUni.getSpeed() != null) {
-
- OvsdbUtils.createQoSForOvsdbNode(dataBroker, updatedUni);
- }
- UniUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
- updated.getKey(),
- updatedUni,
- ovsdbNode,
- dataBroker);
- } else {
- // This should never happen, because on creation,
- // the UNI is assigned and OVSDB node
- LOG.error("OVSDB node not found for UNI {}", uniKey);
- return;
- }
+ final UniAugmentation updatedUni = dataObject.getRootNode().getDataAfter().getAugmentation(UniAugmentation.class);
+ final UniAugmentation formerUni = dataObject.getRootNode().getDataBefore().getAugmentation(UniAugmentation.class);
+ if (formerUni != null) {
+ final String formerUniIp = formerUni.getIpAddress().getIpv4Address().getValue();
+ final String updatedUniIp = updatedUni.getIpAddress().getIpv4Address().getValue();
+ final InstanceIdentifier<?> updatedUniIid = dataObject.getRootPath().getRootIdentifier();
+ final String uniKey = updatedUniIid.firstKeyOf(Node.class).toString();
+ Preconditions.checkArgument(formerUniIp.equals(updatedUniIp),
+ "Can't update UNI with a different IP address. Former IP was %s"
+ + "Updated IP is %s. Please create a UNI instead of updating this one %s",
+ formerUniIp, updatedUniIp, uniKey);
+ Node ovsdbNode;
+ if (updatedUni.getOvsdbNodeRef() != null) {
+ LOG.info("OVSDB NODE ref retreive for updated UNI {}", updatedUni.getOvsdbNodeRef());
+ final OvsdbNodeRef ovsdbNodeRef = updatedUni.getOvsdbNodeRef();
+ final Optional<Node> optOvsdbNode = MdsalUtils.readNode(dataBroker,LogicalDatastoreType.OPERATIONAL, ovsdbNodeRef.getValue());
+ if(optOvsdbNode.isPresent()) {
+ ovsdbNode= optOvsdbNode.get();
+ LOG.info("Retrieved the OVSDB node {}", ovsdbNode.getNodeId());
+ // Update QoS entries to ovsdb if speed is configured to UNI node
+ if (updatedUni.getSpeed() != null) {
+ OvsdbUtils.createQoSForOvsdbNode(dataBroker, updatedUni);
}
- LOG.info("UNI {} updated", uniKey);
-
- final InstanceIdentifier<?> uniIID = UnimgrMapper.getUniIid(dataBroker, updatedUni.getIpAddress(), LogicalDatastoreType.OPERATIONAL);
- MdsalUtils.deleteNode(dataBroker, uniIID, LogicalDatastoreType.OPERATIONAL);
- UniUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL, uniIID, updatedUni, ovsdbNode, dataBroker);
+ UniUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL, updatedUniIid, updatedUni,
+ ovsdbNode, dataBroker);
+ } else {
+ // This should never happen, because on creation,
+ // the UNI is assigned and OVSDB node
+ LOG.error("OVSDB node not found for UNI {}, but got OVSDB ref", uniKey, updatedUni.getOvsdbNodeRef());
+ return;
}
- }
- if (updated.getValue() != null
- && updated.getValue() instanceof OvsdbNodeAugmentation) {
- OvsdbNodeAugmentation ovsdbNodeAugmentation = (OvsdbNodeAugmentation) updated.getValue();
- if (ovsdbNodeAugmentation != null) {
- LOG.trace("Received an OVSDB node create {}",
- ovsdbNodeAugmentation.getConnectionInfo()
- .getRemoteIp().getIpv4Address().getValue());
- final List<ManagedNodeEntry> managedNodeEntries = ovsdbNodeAugmentation.getManagedNodeEntry();
- if (managedNodeEntries != null) {
- for (ManagedNodeEntry managedNodeEntry : managedNodeEntries) {
- LOG.trace("Received an update from an OVSDB node {}.", managedNodeEntry.getKey());
- // We received a node update from the southbound plugin
- // so we have to check if it belongs to the UNI
- }
+ } else {
+ final Optional<Node> optOvsdbNode = OvsdbUtils.findOvsdbNode(dataBroker, updatedUni);
+ if (optOvsdbNode.isPresent()) {
+ ovsdbNode = optOvsdbNode.get();
+ LOG.info("Retrieved the OVSDB node {}", ovsdbNode.getNodeId());
+ // Update QoS entries to ovsdb if speed is configured to UNI node
+ if (updatedUni.getSpeed() != null) {
+ OvsdbUtils.createQoSForOvsdbNode(dataBroker, updatedUni);
}
+ UniUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL, updatedUniIid, updatedUni,
+ ovsdbNode, dataBroker);
+ } else {
+ // This should never happen, because on creation,
+ // the UNI is assigned and OVSDB node
+ LOG.error("OVSDB node not found for UNI {}", uniKey);
+ return;
}
}
+ LOG.info("UNI {} updated", uniKey);
}
}
}
--- /dev/null
+/*
+ * Copyright (c) 2016 CableLabs 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.unimgr.impl;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.unimgr.api.UnimgrDataTreeChangeListener;
+import org.opendaylight.unimgr.command.EvcAddCommand;
+import org.opendaylight.unimgr.command.EvcRemoveCommand;
+import org.opendaylight.unimgr.command.EvcUpdateCommand;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class EvcDataTreeChangeListener extends UnimgrDataTreeChangeListener<Link> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(EvcDataTreeChangeListener.class);
+ private final ListenerRegistration<EvcDataTreeChangeListener> listener;
+
+ public EvcDataTreeChangeListener(final DataBroker dataBroker) {
+ super(dataBroker);
+ final DataTreeIdentifier<Link> dataTreeIid = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getEvcTopologyPath());
+ listener = dataBroker.registerDataTreeChangeListener(dataTreeIid, this);
+ LOG.info("EvcDataTreeChangeListener created and registered");
+ }
+
+ @Override
+ public void add(final DataTreeModification<Link> newDataObject) {
+ if(newDataObject.getRootPath() != null && newDataObject.getRootNode() != null) {
+ LOG.info("evc link {} created", newDataObject.getRootNode().getIdentifier());
+ final EvcAddCommand evcAddCmd = new EvcAddCommand(dataBroker, newDataObject);
+ evcAddCmd.execute();
+ }
+ }
+
+ @Override
+ public void close() throws Exception {
+ listener.close();
+ }
+
+ private InstanceIdentifier<Link> getEvcTopologyPath() {
+ final InstanceIdentifier<Link> evcPath = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class, new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID))
+ .child(Link.class);
+ return evcPath;
+ }
+
+ @Override
+ public void remove(final DataTreeModification<Link> removedDataObject) {
+ if(removedDataObject.getRootPath() != null && removedDataObject.getRootNode() != null) {
+ LOG.info("evc link {} deleted", removedDataObject.getRootNode().getIdentifier());
+ final EvcRemoveCommand evcRemovedCmd = new EvcRemoveCommand(dataBroker, removedDataObject);
+ evcRemovedCmd.execute();
+ }
+ }
+
+ @Override
+ public void update(final DataTreeModification<Link> modifiedDataObject) {
+ if(modifiedDataObject.getRootPath() != null && modifiedDataObject.getRootNode() != null) {
+ LOG.info("evc link {} updated", modifiedDataObject.getRootNode().getIdentifier());
+ final EvcUpdateCommand evcUpdateCmd = new EvcUpdateCommand(dataBroker, modifiedDataObject);
+ evcUpdateCmd.execute();
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 CableLabs 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.unimgr.impl;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.unimgr.api.UnimgrDataTreeChangeListener;
+import org.opendaylight.unimgr.command.OvsNodeAddCommand;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class OvsNodeDataTreeChangeListener extends UnimgrDataTreeChangeListener<Node> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(OvsNodeDataTreeChangeListener.class);
+ private final ListenerRegistration<OvsNodeDataTreeChangeListener> listener;
+
+ public OvsNodeDataTreeChangeListener(final DataBroker dataBroker) {
+ super(dataBroker);
+ final InstanceIdentifier<Node> nodePath = getOvsNodeTopologyPath();
+ final DataTreeIdentifier<Node> dataTreeIid = new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, nodePath);
+ listener = dataBroker.registerDataTreeChangeListener(dataTreeIid, this);
+ LOG.info("ovsNodeDataTreeChangeListener created and registered");
+ }
+
+ @Override
+ public void add(final DataTreeModification<Node> newDataObject) {
+ if (newDataObject.getRootPath() != null && newDataObject.getRootNode() != null) {
+ LOG.info("ovs node {} created", newDataObject.getRootNode().getIdentifier());
+ final OvsNodeAddCommand ovsNodeAddCmd = new OvsNodeAddCommand(dataBroker, newDataObject);
+ ovsNodeAddCmd.execute();
+ }
+ }
+
+ @Override
+ public void close() throws Exception {
+ listener.close();
+ }
+
+ private InstanceIdentifier<Node> getOvsNodeTopologyPath() {
+ final InstanceIdentifier<Node> topoPath = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class,
+ new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
+ .child(Node.class);
+ return topoPath;
+ }
+
+ @Override
+ public void remove(final DataTreeModification<Node> removedDataObject) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void update(final DataTreeModification<Node> modifiedDataObject) {
+ // TODO Auto-generated method stub
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 CableLabs 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.unimgr.impl;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.unimgr.api.UnimgrDataTreeChangeListener;
+import org.opendaylight.unimgr.command.UniAddCommand;
+import org.opendaylight.unimgr.command.UniRemoveCommand;
+import org.opendaylight.unimgr.command.UniUpdateCommand;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class UniDataTreeChangeListener extends UnimgrDataTreeChangeListener<Node> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(UniDataTreeChangeListener.class);
+ private final ListenerRegistration<UniDataTreeChangeListener> listener;
+
+
+ public UniDataTreeChangeListener(final DataBroker dataBroker) {
+ super(dataBroker);
+ final InstanceIdentifier<Node> uniPath = getUniTopologyPath();
+ final DataTreeIdentifier<Node> dataTreeIid = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, uniPath);
+ listener = dataBroker.registerDataTreeChangeListener(dataTreeIid, this);
+ LOG.info("UniDataTreeChangeListener created and registered");
+ }
+
+ @Override
+ public void add(final DataTreeModification<Node> newDataObject) {
+ if (newDataObject.getRootPath() != null && newDataObject.getRootNode() != null) {
+ LOG.info("uni node {} created", newDataObject.getRootNode().getIdentifier());
+ final UniAddCommand uniAddCmd = new UniAddCommand(dataBroker, newDataObject);
+ uniAddCmd.execute();
+ }
+ }
+
+ @Override
+ public void close() throws Exception {
+ listener.close();
+ }
+
+ private InstanceIdentifier<Node> getUniTopologyPath() {
+ final InstanceIdentifier<Node> nodePath = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class,
+ new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
+ .child(Node.class);
+ return nodePath;
+ }
+
+ @Override
+ public void remove(final DataTreeModification<Node> removedDataObject) {
+ if (removedDataObject.getRootPath() != null && removedDataObject.getRootNode() != null) {
+ LOG.info("uni node {} deleted", removedDataObject.getRootNode().getIdentifier());
+ final UniRemoveCommand uniRemoveCmd = new UniRemoveCommand(dataBroker, removedDataObject);
+ uniRemoveCmd.execute();
+ }
+ }
+
+ @Override
+ public void update(final DataTreeModification<Node> modifiedDataObject) {
+ if (modifiedDataObject.getRootPath() != null && modifiedDataObject.getRootNode() != null) {
+ LOG.info("uni node {} created", modifiedDataObject.getRootNode().getIdentifier());
+ final UniUpdateCommand uniUpdateCmd = new UniUpdateCommand(dataBroker, modifiedDataObject);
+ uniUpdateCmd.execute();
+ }
+ }
+
+}
+++ /dev/null
-/*
- * Copyright (c) 2015 CableLabs 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.unimgr.impl;
-
-import java.util.ArrayList;
-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.DataChangeListener;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.unimgr.api.IUnimgrDataChangeListener;
-import org.opendaylight.unimgr.command.Command;
-import org.opendaylight.unimgr.command.EvcCreateCommand;
-import org.opendaylight.unimgr.command.EvcDeleteCommand;
-import org.opendaylight.unimgr.command.EvcUpdateCommand;
-import org.opendaylight.unimgr.command.TransactionInvoker;
-import org.opendaylight.unimgr.command.UniCreateCommand;
-import org.opendaylight.unimgr.command.UniDeleteCommand;
-import org.opendaylight.unimgr.command.UniUpdateCommand;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class UnimgrDataChangeListener implements IUnimgrDataChangeListener {
-
- private static final Logger LOG = LoggerFactory.getLogger(UnimgrDataChangeListener.class);
- private Set<ListenerRegistration<DataChangeListener>> listeners;
- private DataBroker dataBroker;
- private TransactionInvoker invoker;
-
- public UnimgrDataChangeListener(DataBroker dataBroker, TransactionInvoker invoker) {
- this.dataBroker = dataBroker;
- this.invoker = invoker;
- listeners = new HashSet<ListenerRegistration<DataChangeListener>>();
- listeners.add(dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
- UnimgrMapper.getUniTopologyIid(),
- this,
- DataChangeScope.SUBTREE));
- listeners.add(dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
- UnimgrMapper.getEvcTopologyIid(),
- this,
- DataChangeScope.SUBTREE));
- listeners.add(dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
- UnimgrMapper.getOvsdbTopologyIid(),
- this,
- DataChangeScope.SUBTREE));
- LOG.info("UnimgrDataChangeListener initialized");
- }
-
- @Override
- public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>,
- DataObject> change) {
- create(change.getCreatedData());
- update(change.getUpdatedData());
- delete(change);
- }
-
- @Override
- public void create(Map<InstanceIdentifier<?>,
- DataObject> changes) {
- if (changes != null) {
- List<Command> commands = new ArrayList<Command>();
- Command uniCreate = new UniCreateCommand(dataBroker, changes);
- Command evcCreate = new EvcCreateCommand(dataBroker, changes);
- commands.add(uniCreate);
- commands.add(evcCreate);
- invoker.setCommands(commands);
- invoker.invoke();
- }
- }
-
- @Override
- public void update(Map<InstanceIdentifier<?>,
- DataObject> changes) {
- if (changes != null) {
- List<Command> commands = new ArrayList<Command>();
- Command uniUpdate = new UniUpdateCommand(dataBroker, changes);
- Command evcUpdate = new EvcUpdateCommand(dataBroker, changes);
- commands.add(uniUpdate);
- commands.add(evcUpdate);
- invoker.setCommands(commands);
- invoker.invoke();
- }
- }
-
- @Override
- public void delete(AsyncDataChangeEvent<InstanceIdentifier<?>,
- DataObject> changes) {
- if (changes != null) {
- List<Command> commands = new ArrayList<Command>();
- Command uniDelete = new UniDeleteCommand(dataBroker, changes);
- Command evcDelete = new EvcDeleteCommand(dataBroker, changes);
- commands.add(uniDelete);
- commands.add(evcDelete);
- invoker.setCommands(commands);
- invoker.invoke();
- }
- }
-
- @Override
- public void close() throws Exception {
- LOG.info("UnimgrDataChangeListener stopped.");
- for (ListenerRegistration<DataChangeListener> listener : listeners) {
- if (listener != null) {
- listener.close();
- }
- }
- }
-}
*/
package org.opendaylight.unimgr.impl;
-
import java.util.List;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
import org.opendaylight.unimgr.api.IUnimgrConsoleProvider;
-import org.opendaylight.unimgr.command.TransactionInvoker;
import org.opendaylight.unimgr.utils.EvcUtils;
import org.opendaylight.unimgr.utils.MdsalUtils;
import org.opendaylight.unimgr.utils.OvsdbUtils;
public class UnimgrProvider implements BindingAwareProvider, AutoCloseable, IUnimgrConsoleProvider {
private static final Logger LOG = LoggerFactory.getLogger(UnimgrProvider.class);
-
- private UnimgrDataChangeListener listener;
- private TransactionInvoker invoker;
-
private DataBroker dataBroker;
+ private EvcDataTreeChangeListener evcListener;
+ private OvsNodeDataTreeChangeListener ovsListener;
+ private UniDataTreeChangeListener uniListener;
private ServiceRegistration<IUnimgrConsoleProvider> unimgrConsoleRegistration;
public UnimgrProvider() {
}
@Override
- public void onSessionInitiated(ProviderContext session) {
- LOG.info("UnimgrProvider Session Initiated");
-
- // Retrieve the data broker to create transactions
- dataBroker = session.getSALService(DataBroker.class);
- invoker = new TransactionInvoker();
-
- // Register the unimgr OSGi CLI
- final BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
- unimgrConsoleRegistration = context.registerService(IUnimgrConsoleProvider.class,
- this,
- null);
-
- // Register the uni data change listener
- listener = new UnimgrDataChangeListener(dataBroker, invoker);
+ public boolean addEvc(final EvcAugmentation evc) {
+ // TODO Auto-generated method stub
+ return false;
+ }
- // Initialize operational and default config data in MD-SAL data store
- initDatastore(LogicalDatastoreType.CONFIGURATION,
- UnimgrConstants.UNI_TOPOLOGY_ID);
- initDatastore(LogicalDatastoreType.OPERATIONAL,
- UnimgrConstants.UNI_TOPOLOGY_ID);
- initDatastore(LogicalDatastoreType.CONFIGURATION,
- UnimgrConstants.EVC_TOPOLOGY_ID);
- initDatastore(LogicalDatastoreType.OPERATIONAL,
- UnimgrConstants.EVC_TOPOLOGY_ID);
+ @Override
+ public boolean addUni(final UniAugmentation uniAug) {
+ if ((uniAug == null) || (uniAug.getIpAddress() == null) || (uniAug.getMacAddress() == null)) {
+ return false;
+ }
+ return UniUtils.createUniNode(dataBroker, uniAug);
}
@Override
public void close() throws Exception {
LOG.info("UnimgrProvider Closed");
unimgrConsoleRegistration.unregister();
- listener.close();
+ uniListener.close();
+ evcListener.close();
+ ovsListener.close();
+ }
+
+ @Override
+ public Evc getEvc(final String uuid) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public UniAugmentation getUni(final IpAddress ipAddress) {
+ return UniUtils.getUni(dataBroker, LogicalDatastoreType.OPERATIONAL, ipAddress);
}
protected void initDatastore(final LogicalDatastoreType type,
- TopologyId topoId) {
+ final TopologyId topoId) {
final InstanceIdentifier<Topology> path = InstanceIdentifier
.create(NetworkTopology.class)
.child(Topology.class,
}
}
- private void initializeTopology(LogicalDatastoreType type) {
+ private void initializeTopology(final LogicalDatastoreType type) {
final ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();
final InstanceIdentifier<NetworkTopology> path = InstanceIdentifier.create(NetworkTopology.class);
final CheckedFuture<Optional<NetworkTopology>, ReadFailedException> topology = transaction.read(type,path);
}
@Override
- public boolean addUni(UniAugmentation uniAug) {
- if ((uniAug == null) || (uniAug.getIpAddress() == null) || (uniAug.getMacAddress() == null)) {
- return false;
- }
- return UniUtils.createUniNode(dataBroker, uniAug);
- }
-
- @Override
- public boolean removeUni(IpAddress ipAddress) {
- final InstanceIdentifier<Node> iidUni = UnimgrMapper.getUniIid(dataBroker, ipAddress, LogicalDatastoreType.CONFIGURATION);
- if (iidUni == null) {
- return false;
- }
-
- return MdsalUtils.deleteNode(dataBroker, iidUni, LogicalDatastoreType.CONFIGURATION);
- }
-
- @Override
- public List<UniAugmentation> listUnis(LogicalDatastoreType dataStoreType) {
+ public List<UniAugmentation> listUnis(final LogicalDatastoreType dataStoreType) {
return UniUtils.getUnis(dataBroker, dataStoreType);
}
@Override
- public UniAugmentation getUni(IpAddress ipAddress) {
- return UniUtils.getUni(dataBroker, LogicalDatastoreType.OPERATIONAL, ipAddress);
- }
+ public void onSessionInitiated(final ProviderContext session) {
+ LOG.info("UnimgrProvider Session Initiated");
+
+ // Retrieve the data broker to create transactions
+ dataBroker = session.getSALService(DataBroker.class);
+ // Register the unimgr OSGi CLI
+ final BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
+ unimgrConsoleRegistration = context.registerService(IUnimgrConsoleProvider.class,this, null);
+ // Register the data trees change listener
+ uniListener = new UniDataTreeChangeListener(dataBroker);
+ evcListener = new EvcDataTreeChangeListener(dataBroker);
+ ovsListener = new OvsNodeDataTreeChangeListener(dataBroker);
- @Override
- public boolean removeEvc(String uuid) {
- // TODO Auto-generated method stub
- return false;
+ // Initialize operational and default config data in MD-SAL data store
+ initDatastore(LogicalDatastoreType.CONFIGURATION,
+ UnimgrConstants.UNI_TOPOLOGY_ID);
+ initDatastore(LogicalDatastoreType.OPERATIONAL,
+ UnimgrConstants.UNI_TOPOLOGY_ID);
+ initDatastore(LogicalDatastoreType.CONFIGURATION,
+ UnimgrConstants.EVC_TOPOLOGY_ID);
+ initDatastore(LogicalDatastoreType.OPERATIONAL,
+ UnimgrConstants.EVC_TOPOLOGY_ID);
}
@Override
- public boolean addEvc(EvcAugmentation evc) {
+ public boolean removeEvc(final String uuid) {
// TODO Auto-generated method stub
return false;
}
@Override
- public Evc getEvc(String uuid) {
- // TODO Auto-generated method stub
- return null;
+ public boolean removeUni(final IpAddress ipAddress) {
+ final InstanceIdentifier<Node> iidUni = UnimgrMapper.getUniIid(dataBroker, ipAddress, LogicalDatastoreType.CONFIGURATION);
+ if (iidUni == null) {
+ return false;
+ }
+ return MdsalUtils.deleteNode(dataBroker, iidUni, LogicalDatastoreType.CONFIGURATION);
}
@Override
- public boolean updateEvc(InstanceIdentifier<Link> evcKey, EvcAugmentation evc, UniSource uniSource,
- UniDest uniDest) {
+ public boolean updateEvc(final InstanceIdentifier<Link> evcKey, final EvcAugmentation evc, final UniSource uniSource,
+ final UniDest uniDest) {
final InstanceIdentifier<?> sourceUniIid = uniSource.getUni();
final InstanceIdentifier<?> destinationUniIid = uniDest.getUni();
return EvcUtils.updateEvcNode(LogicalDatastoreType.CONFIGURATION, evcKey, evc, sourceUniIid,
}
@Override
- public boolean updateUni(UniAugmentation uni) {
+ public boolean updateUni(final UniAugmentation uni) {
// Remove the old UNI with IpAdress and create a new one with updated informations
if (uni != null) {
LOG.trace("UNI updated {}.", uni.getIpAddress().getIpv4Address());
private static final Logger LOG = LoggerFactory.getLogger(EvcUtils.class);
- private EvcUtils() {
- throw new AssertionError("Instantiating utility class.");
- }
-
/**
* Delete EVC data from configuration datastore
* @param dataBroker The dataBroker instance to create transactions
* @param optionalUni Optional Uni Node
*/
- public static void deleteEvcData(DataBroker dataBroker, Optional<Node> optionalUni) {
+ public static void deleteEvcData(final DataBroker dataBroker, final Optional<Node> optionalUni) {
if (optionalUni.isPresent()) {
final UniAugmentation uniAugmentation =
optionalUni
* @param dataBroker The dataBroker instance to create transactions
* @return A list of Links retrieved from the Operational DataStore
*/
- public static List<Link> getEvcLinks(DataBroker dataBroker) {
+ public static List<Link> getEvcLinks(final DataBroker dataBroker) {
final List<Link> evcLinks = new ArrayList<>();
final InstanceIdentifier<Topology> evcTopology = UnimgrMapper.getEvcTopologyIid();
final Topology topology = MdsalUtils.read(dataBroker,
* @param dataBroker The dataBroker instance to create transactions
* @return true if evc is updated
*/
- public static boolean updateEvcNode(LogicalDatastoreType dataStore,
- InstanceIdentifier<?> evcKey,
- EvcAugmentation evcAugmentation,
- InstanceIdentifier<?> sourceUniIid,
- InstanceIdentifier<?> destinationUniIid,
- DataBroker dataBroker) {
+ public static boolean updateEvcNode(final LogicalDatastoreType dataStore,
+ final InstanceIdentifier<?> evcKey,
+ final EvcAugmentation evcAugmentation,
+ final InstanceIdentifier<?> sourceUniIid,
+ final InstanceIdentifier<?> destinationUniIid,
+ final DataBroker dataBroker) {
final EvcAugmentationBuilder updatedEvcBuilder = new EvcAugmentationBuilder(evcAugmentation);
if ((sourceUniIid != null) && (destinationUniIid != null)) {
final List<UniSource> sourceList = new ArrayList<UniSource>();
- final UniSourceKey sourceKey = evcAugmentation.getUniSource().iterator().next().getKey();
- final short sourceOrder = evcAugmentation.getUniSource().iterator().next().getOrder();
- final IpAddress sourceIp = evcAugmentation.getUniSource().iterator().next().getIpAddress();
+ final UniSource evcUniSource = evcAugmentation.getUniSource().iterator().next();
+ final UniSourceKey sourceKey = evcUniSource.getKey();
+ final short sourceOrder = evcUniSource.getOrder();
+ final IpAddress sourceIp = evcUniSource.getIpAddress();
final UniSource uniSource = new UniSourceBuilder()
.setOrder(sourceOrder)
.setKey(sourceKey)
updatedEvcBuilder.setUniSource(sourceList);
final List<UniDest> destinationList = new ArrayList<UniDest>();
- final UniDestKey destKey = evcAugmentation.getUniDest().iterator().next().getKey();
- final short destOrder = evcAugmentation.getUniDest().iterator().next().getOrder();
- final IpAddress destIp = evcAugmentation.getUniDest().iterator().next().getIpAddress();
+ final UniDest evcUniDest = evcAugmentation.getUniDest().iterator().next();
+ final UniDestKey destKey = evcUniDest.getKey();
+ final short destOrder = evcUniDest.getOrder();
+ final IpAddress destIp = evcUniDest.getIpAddress();
final UniDest uniDest = new UniDestBuilder()
.setIpAddress(destIp)
.setOrder(destOrder)
}
return false;
}
+
+ private EvcUtils() {
+ throw new AssertionError("Instantiating utility class.");
+ }
}
public static List<Node> getOvsdbNodes(DataBroker dataBroker) {
final List<Node> ovsdbNodes = new ArrayList<>();
final InstanceIdentifier<Topology> ovsdbTopoIdentifier = UnimgrMapper.getOvsdbTopologyIid();
- final Topology topology = MdsalUtils.read(dataBroker,
+ Topology topology = MdsalUtils.read(dataBroker,
LogicalDatastoreType.OPERATIONAL,
ovsdbTopoIdentifier);
if ((topology != null) && (topology.getNode() != null)) {
ovsdbNodes.add(node);
}
}
+ } else {
+ topology = MdsalUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, ovsdbTopoIdentifier);
+ if ((topology != null) && (topology.getNode() != null)) {
+ for (final Node node : topology.getNode()) {
+ final OvsdbNodeAugmentation ovsdbNodeAugmentation = node.getAugmentation(OvsdbNodeAugmentation.class);
+ if (ovsdbNodeAugmentation != null) {
+ ovsdbNodes.add(node);
+ }
+ }
+ }
}
return ovsdbNodes;
}
--- /dev/null
+/*
+ * Copyright (c) 2016 CableLabs 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.unimgr.command;
+
+import java.util.Collection;
+
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkKey;
+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.NodeKey;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+import org.opendaylight.yangtools.yang.binding.ChildOf;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.Identifiable;
+import org.opendaylight.yangtools.yang.binding.Identifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
+
+/**
+ * DataTreeModificationHelper help to get a dummy value of DataTreeModification object as DataTreeModification
+ * class is a final class.
+ */
+public final class DataTreeModificationHelper {
+
+ public static final DataTreeModification<Node> getUniNode(final Node node) {
+ final DataTreeIdentifier<Node> uniDataTreeIid = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getUniIid("10.10.1.3"));
+ final DataObjectModification<Node> uniDataTreeObj = new DataObjectModification<Node>() {
+ @Override
+ public Collection<DataObjectModification<? extends DataObject>> getModifiedChildren() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public <C extends Identifiable<K> & ChildOf<? super Node>, K extends Identifier<C>> DataObjectModification<C> getModifiedChildListItem(
+ Class<C> arg0, K arg1) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public <C extends ChildOf<? super Node>> DataObjectModification<C> getModifiedChildContainer(Class<C> arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public DataObjectModification<? extends DataObject> getModifiedChild(PathArgument arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public <C extends Augmentation<Node> & DataObject> DataObjectModification<C> getModifiedAugmentation(
+ Class<C> arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public ModificationType getModificationType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public PathArgument getIdentifier() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public Class<Node> getDataType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public Node getDataBefore() {
+ return node;
+ }
+ @Override
+ public Node getDataAfter() {
+ return node;
+ }
+ };
+ DataTreeModification<Node> uniNode = new DataTreeModification<Node>() {
+ @Override
+ public DataTreeIdentifier<Node> getRootPath() {
+ return uniDataTreeIid;
+ }
+ @Override
+ public DataObjectModification<Node> getRootNode() {
+ return uniDataTreeObj;
+ }
+ };
+ return uniNode;
+ }
+
+ private static final InstanceIdentifier<Node> getUniIid(String nodeId) {
+ NodeId uniNodeId = new NodeId(new NodeId(nodeId));
+ InstanceIdentifier<Node> uniNodeIid = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class, new TopologyKey(new TopologyId(new Uri("unimgr:uni"))))
+ .child(Node.class, new NodeKey(uniNodeId));
+ return uniNodeIid;
+ }
+
+ public static final DataTreeModification<Link> getEvcLink(final Link link) {
+ final DataTreeIdentifier<Link> evcDataTreeIid = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getEvcLinkIid("1"));
+ final DataObjectModification<Link> evcDataTreeObj = new DataObjectModification<Link>() {
+ @Override
+ public Collection<DataObjectModification<? extends DataObject>> getModifiedChildren() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public <C extends Identifiable<K> & ChildOf<? super Link>, K extends Identifier<C>> DataObjectModification<C> getModifiedChildListItem(
+ Class<C> arg0, K arg1) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public <C extends ChildOf<? super Link>> DataObjectModification<C> getModifiedChildContainer(Class<C> arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public DataObjectModification<? extends DataObject> getModifiedChild(PathArgument arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public <C extends Augmentation<Link> & DataObject> DataObjectModification<C> getModifiedAugmentation(
+ Class<C> arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public ModificationType getModificationType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public PathArgument getIdentifier() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public Class<Link> getDataType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public Link getDataBefore() {
+ return link;
+ }
+ @Override
+ public Link getDataAfter() {
+ return link;
+ }
+ };
+ DataTreeModification<Link> evcLink = new DataTreeModification<Link>() {
+
+ @Override
+ public DataTreeIdentifier<Link> getRootPath() {
+ return evcDataTreeIid;
+ }
+
+ @Override
+ public DataObjectModification<Link> getRootNode() {
+ return evcDataTreeObj;
+ }
+ };
+ return evcLink;
+ }
+
+ private static InstanceIdentifier<Link> getEvcLinkIid(String linkId) {
+ LinkId evcLinkId = new LinkId(new LinkId("evc://" + linkId));
+ InstanceIdentifier<Link> linkPath = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class,new TopologyKey(new TopologyId(new Uri("unimgr:evc"))))
+ .child(Link.class, new LinkKey(evcLinkId));
+ return linkPath;
+ }
+}
import static org.mockito.Mockito.when;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.unimgr.impl.UnimgrConstants;
import org.opendaylight.unimgr.impl.UnimgrMapper;
import org.opendaylight.unimgr.utils.EvcUtils;
import org.opendaylight.unimgr.utils.MdsalUtils;
import org.opendaylight.unimgr.utils.OvsdbUtils;
-import org.opendaylight.unimgr.utils.UniUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeRef;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
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.NodeKey;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
@RunWith(PowerMockRunner.class)
@PrepareForTest({EvcUtils.class, MdsalUtils.class, OvsdbUtils.class, UnimgrMapper.class})
-public class EvcCreateCommandTest {
+public class EvcAddCommandTest {
private static final NodeId OVSDB_NODE_ID = new NodeId("ovsdb://7011db35-f44b-4aab-90f6-d89088caf9d8");
- private EvcCreateCommand evcCreateCommand;
- private Map<InstanceIdentifier<?>, DataObject> changes;
+ private EvcAddCommand evcAddCommand;
+ private DataTreeModification<Link> evcLink;
private DataBroker dataBroker;
+ private Link link;
+ private Optional<Link> optLinks;
@SuppressWarnings("unchecked")
@Before
PowerMockito.mockStatic(EvcUtils.class);
PowerMockito.mockStatic(OvsdbUtils.class);
PowerMockito.mockStatic(UnimgrMapper.class);
- changes = mock(Map.class);
dataBroker = mock(DataBroker.class);
- evcCreateCommand = new EvcCreateCommand(dataBroker, changes);
+ link = mock(Link.class);
+ optLinks = mock(Optional.class);
+ evcLink = DataTreeModificationHelper.getEvcLink(link);
+ evcAddCommand = new EvcAddCommand(dataBroker, evcLink);
}
/**
- * Test method for {@link org.opendaylight.unimgr.command.EvcCreateCommand#execute()}.
+ * Test method for {@link org.opendaylight.unimgr.command.evcAddCommand#execute()}.
* @throws Exception
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
.create(NetworkTopology.class)
.child(Topology.class, new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID))
.child(Node.class, new NodeKey(OVSDB_NODE_ID));
- final Set<Entry<InstanceIdentifier<?>, DataObject>> setCreated = new HashSet<Map.Entry<InstanceIdentifier<?>,DataObject>>();
- final Entry<InstanceIdentifier<?>, DataObject> created = new Entry<InstanceIdentifier<?>, DataObject>() {
- @Override
- public DataObject setValue(DataObject value) { return null; }
- @Override
- public DataObject getValue() { return evcAugmentation; }
- @Override
- public InstanceIdentifier getKey() { return evcKey; }
- };
-
- setCreated.add(created);
unisSource.add(uniSource);
unisDest.add(uniDest);
- when(changes.entrySet()).thenReturn(setCreated);
+ when(link.getAugmentation(EvcAugmentation.class)).thenReturn(evcAugmentation);
+ when(optLinks.isPresent()).thenReturn(false);
when(uniAugmentation.getOvsdbNodeRef()).thenReturn(ovsNodedRef);
when(evcAugmentation.getUniSource()).thenReturn(unisSource);
when(evcAugmentation.getUniDest()).thenReturn(unisDest);
when(node.getAugmentation(any(Class.class))).thenReturn(uniAugmentation);
when(ovsNodedRef.getValue()).thenReturn(evcKey);
+ when(MdsalUtils.readLink(any(DataBroker.class), any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class))).thenReturn(optLinks);
when(MdsalUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
any(InstanceIdentifier.class))).thenReturn(optionalOvsdbNode);
PowerMockito.doNothing().when(OvsdbUtils.class, "updateMaxRate", dataBroker, uniAugmentation,
when(UnimgrMapper.getUniIid(any(DataBroker.class), any(IpAddress.class),
any(LogicalDatastoreType.class))).thenReturn(evcKey);
- evcCreateCommand.execute();
+ evcAddCommand.execute();
PowerMockito.verifyStatic(times(2));
OvsdbUtils.createTerminationPointNode(any(DataBroker.class), any(UniAugmentation.class),
any(Node.class), any(String.class), any(String.class));
EvcUtils.updateEvcNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
any(EvcAugmentation.class), any(InstanceIdentifier.class),
any(InstanceIdentifier.class), any(DataBroker.class));
-
}
}
import static org.mockito.Mockito.when;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.unimgr.impl.UnimgrMapper;
import org.opendaylight.unimgr.utils.EvcUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDest;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSource;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
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.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
@RunWith(PowerMockRunner.class)
@PrepareForTest({EvcUtils.class, MdsalUtils.class, OvsdbUtils.class, UnimgrMapper.class})
-public class EvcDeleteCommandTest {
+public class EvcRemoveCommandTest {
- private EvcDeleteCommand evcDeleteCommand;
- private AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes;
+ private EvcRemoveCommand evcRemoveCommand;
+ private DataTreeModification<Link> evcLink;
+ private Link link;
private DataBroker dataBroker;
@SuppressWarnings("unchecked")
PowerMockito.mockStatic(EvcUtils.class);
PowerMockito.mockStatic(OvsdbUtils.class);
PowerMockito.mockStatic(UnimgrMapper.class);
- changes = mock(AsyncDataChangeEvent.class);
dataBroker = mock(DataBroker.class);
- evcDeleteCommand = new EvcDeleteCommand(dataBroker, changes);
+ link = mock(Link.class);
+ evcLink = DataTreeModificationHelper.getEvcLink(link);
+ evcRemoveCommand = new EvcRemoveCommand(dataBroker, evcLink);
}
/**
- * Test method for {@link org.opendaylight.unimgr.command.EvcDeleteCommand#EvcDeleteCommand(org.opendaylight.controller.md.sal.binding.api.DataBroker, org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent)}.
+ * Test method for {@link org.opendaylight.unimgr.command.EvcRemoveCommand#execute().
* @throws Exception
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
- public void testEvcDeleteCommand() throws Exception {
- final Set<InstanceIdentifier<EvcAugmentation>> removedEvcs =
- new HashSet<InstanceIdentifier<EvcAugmentation>>();
+ public void testEvcRemoveCommand() throws Exception {
final List<UniSource> unisSource = new ArrayList<UniSource>();
final UniSource uniSource = mock(UniSource.class);
final List<UniDest> unisDest = new ArrayList<UniDest>();
final EvcAugmentation evcAugmentation = mock(EvcAugmentation.class);
final Optional<Node> optionalNode = mock(Optional.class);
final InstanceIdentifier instanceOfNode = mock(InstanceIdentifier.class);
- removedEvcs.add(mock(InstanceIdentifier.class));
unisSource.add(uniSource);
unisDest.add(uniDest);
+ when(link.getAugmentation(EvcAugmentation.class)).thenReturn(evcAugmentation);
when(evcAugmentation.getUniSource()).thenReturn(unisSource);
when(evcAugmentation.getUniDest()).thenReturn(unisDest);
when(uniSource.getUni()).thenReturn(instanceOfNode);
when(uniDest.getUni()).thenReturn(instanceOfNode);
- when(OvsdbUtils.extractRemoved(any(AsyncDataChangeEvent.class), any(Class.class)))
- .thenReturn(removedEvcs);
when(MdsalUtils.read(any(DataBroker.class), any(LogicalDatastoreType.class),
any(InstanceIdentifier.class))).thenReturn(evcAugmentation);
when(MdsalUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
when(MdsalUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class),
any(LogicalDatastoreType.class))).thenReturn(true);
- evcDeleteCommand.execute();
+ evcRemoveCommand.execute();
PowerMockito.verifyStatic(times(2));
EvcUtils.deleteEvcData(any(DataBroker.class), any(Optional.class));
PowerMockito.verifyStatic(times(1));
any(LogicalDatastoreType.class));
}
-}
+}
\ No newline at end of file
import static org.mockito.Mockito.when;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.unimgr.impl.UnimgrConstants;
import org.opendaylight.unimgr.impl.UnimgrMapper;
import org.opendaylight.unimgr.utils.EvcUtils;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
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.NodeKey;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcError;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
private static final NodeId OVSDB_NODE_ID = new NodeId("ovsdb://7011db35-f44b-4aab-90f6-d89088caf9d8");
private EvcUpdateCommand evcUpdateCommand;
- private Map<InstanceIdentifier<?>, DataObject> changes;
+ private Link link;
+ private DataTreeModification<Link> evcLink;
private DataBroker dataBroker;
@SuppressWarnings("unchecked")
PowerMockito.mockStatic(EvcUtils.class);
PowerMockito.mockStatic(OvsdbUtils.class);
PowerMockito.mockStatic(UnimgrMapper.class);
- changes = mock(Map.class);
dataBroker = mock(DataBroker.class);
- evcUpdateCommand = new EvcUpdateCommand(dataBroker, changes);
+ link = mock(Link.class);
+ evcLink = DataTreeModificationHelper.getEvcLink(link);
+ evcUpdateCommand = new EvcUpdateCommand(dataBroker, evcLink);
}
/**
* Test method for {@link org.opendaylight.unimgr.command.EvcUpdateCommand#execute()}.
* @throws Exception
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
- @Test//(expected = ReadFailedException.class)
+ @Test
public void testExecute() throws Exception {
final ReadTransaction readTransac = mock(ReadOnlyTransaction.class);
final CheckedFuture retFormerEvc = mock(CheckedFuture.class);
.create(NetworkTopology.class)
.child(Topology.class, new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID))
.child(Node.class, new NodeKey(OVSDB_NODE_ID));
- final Set<Entry<InstanceIdentifier<?>, DataObject>> setCreated = new HashSet<Map.Entry<InstanceIdentifier<?>,DataObject>>();
- final Entry<InstanceIdentifier<?>, DataObject> created = new Entry<InstanceIdentifier<?>, DataObject>() {
- @Override
- public DataObject setValue(DataObject value) { return null; }
- @Override
- public DataObject getValue() { return evcAugmentation; }
- @Override
- public InstanceIdentifier getKey() { return evcKey; }
- };
-
- setCreated.add(created);
unisSource.add(uniSource);
unisDest.add(uniDest);
formerUnisSource.add(formerUniSource);
// Case EVC1 : formerUni1ip.equals(laterUni1Ip), formerUni2ip.equals(laterUni2Ip)
// iidSource != null, iidDest != null
- when(changes.entrySet()).thenReturn(setCreated);
+ when(link.getAugmentation(EvcAugmentation.class)).thenReturn(evcAugmentation);
when(dataBroker.newReadOnlyTransaction()).thenReturn((ReadOnlyTransaction) readTransac);
when(readTransac.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)))
.thenReturn(retFormerEvc);
any(LogicalDatastoreType.class))).thenReturn(evcKey);
verifyExecute(0, 0, 6, 2);
-
- // Case EVC2 : formerUni1ip.equals(laterUni1Ip), formerUni2ip.equals(laterUni2Ip)
- // iidSource != null, iidDest != null
+ // iidSource != null, iidDest != null
when(formerUniSource.getIpAddress()).thenReturn(formerIpAddressSource);
when(formerUniDest.getIpAddress()).thenReturn(formerIpAddressDest);
when(uniSource.getUni()).thenReturn(null);
when(uniDest.getUni()).thenReturn(null);
- verifyExecute(4, 2, 14, 4);
-
- // Case EVC3 : EVC2 with ReadFailedError
- when(retFormerEvc.checkedGet()).thenThrow(
- new ReadFailedException("Test ReadFailedException", (RpcError[]) null));
- verifyExecute(6, 2, 20, 6);
+ verifyExecute(2, 0, 12, 4);
}
@SuppressWarnings("unchecked")
any(InstanceIdentifier.class), any(DataBroker.class));
}
-}
+}
\ No newline at end of file
import static org.mockito.Mockito.when;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.unimgr.impl.UnimgrConstants;
import org.opendaylight.unimgr.impl.UnimgrMapper;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
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.NodeKey;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
@RunWith(PowerMockRunner.class)
@PrepareForTest({UniUtils.class, OvsdbUtils.class, MdsalUtils.class, UnimgrMapper.class})
-public class UniCreateCommandTest {
+public class UniAddCommandTest {
private static final NodeId OVSDB_NODE_ID = new NodeId("ovsdb://7011db35-f44b-4aab-90f6-d89088caf9d8");
- private UniCreateCommand uniCreateCommand;
- private Map<InstanceIdentifier<?>, DataObject> changes;
+ private UniAddCommand uniAddCommand;
+ private DataTreeModification<Node> uni;
private DataBroker dataBroker;
+ private Node uniNode;
+ private Optional<Node> optUniNode;
@SuppressWarnings("unchecked")
@Before
PowerMockito.mockStatic(OvsdbUtils.class);
PowerMockito.mockStatic(MdsalUtils.class);
PowerMockito.mockStatic(UnimgrMapper.class);
- changes = mock(Map.class);
dataBroker = mock(DataBroker.class);
- uniCreateCommand = new UniCreateCommand(dataBroker, changes);
+ uniNode = mock(Node.class);
+ optUniNode = mock(Optional.class);
+ uni = DataTreeModificationHelper.getUniNode(uniNode);
+ uniAddCommand = new UniAddCommand(dataBroker, uni);
}
/**
- * Test method for {@link org.opendaylight.unimgr.command.UniCreateCommand#execute()}.
+ * Test method for {@link org.opendaylight.unimgr.command.uniAddCommandTest#execute()}.
* @throws Exception
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
.create(NetworkTopology.class)
.child(Topology.class, new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
.child(Node.class, new NodeKey(OVSDB_NODE_ID));
- final Set<Entry<InstanceIdentifier<?>, DataObject>> setCreated = new HashSet<Map.Entry<InstanceIdentifier<?>,DataObject>>();
- Entry<InstanceIdentifier<?>, DataObject> created = new Entry<InstanceIdentifier<?>, DataObject>() {
- @Override
- public DataObject setValue(DataObject value) { return null; }
- @Override
- public DataObject getValue() { return uniAugmentation; }
- @Override
- public InstanceIdentifier getKey() { return uniKey; }
- };
nodes.add(node);
- setCreated.add(created);
// Case UNI1 : uni.getOvsdbNodeRef() != null, !optionalNode.isPresent()
- when(changes.entrySet()).thenReturn(setCreated);
+ when(uniNode.getAugmentation(UniAugmentation.class)).thenReturn(uniAugmentation);
+ when(optUniNode.isPresent()).thenReturn(false);
+ when(MdsalUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class))).thenReturn(optUniNode).thenReturn(optionalOvsdbNode);
when(optionalOvsdbNode.isPresent()).thenReturn(false).thenReturn(true);
when(optionalOvsdbNode.get()).thenReturn(node);
when(uniAugmentation.getIpAddress()).thenReturn(ipAddress);
when(node.getAugmentation(any(Class.class))).thenReturn(uniAugmentation);
when(node.getNodeId()).thenReturn(nodeId);
when(nodeId.toString()).thenReturn("ovsdbNodeId_test");
- when(MdsalUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class))).thenReturn(optionalOvsdbNode);
when(OvsdbUtils.findOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
.thenReturn(optionalOvsdbNode);
when(OvsdbUtils.createQoSForOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
// Case UNI3 : uni.getOvsdbNodeRef() == null, optionalNode.isPresent()
when(uniAugmentation.getOvsdbNodeRef()).thenReturn(null);
+ when(optionalOvsdbNode.isPresent()).thenReturn(true);
+ when(MdsalUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class))).thenReturn(optUniNode).thenReturn(optionalOvsdbNode);
verifyExecute(2, 1, 3, 0);
// Case UNI4 : uni.getOvsdbNodeRef() == null, !optionalNode.isPresent()
when(optionalOvsdbNode.isPresent()).thenReturn(false);
verifyExecute(2, 1, 4, 0);
-
- // Case OVSDB0 ovsdbNodeAugmentation == null
- created = new Entry<InstanceIdentifier<?>, DataObject>() {
- @Override
- public DataObject setValue(DataObject value) { return null; }
- @Override
- public DataObject getValue() { return null; }
- @Override
- public InstanceIdentifier getKey() { return uniKey; }
- };
- setCreated.clear();
- setCreated.add(created);
- verifyExecute(2, 1, 4, 0);
-
- // Case OVSDB1 : uniNodes != null && !uniNodes.isEmpty(),
- // uniAugmentation.getOvsdbNodeRef() != null &&
- // uniAugmentation.getOvsdbNodeRef().getValue() != null
- created = new Entry<InstanceIdentifier<?>, DataObject>() {
- @Override
- public DataObject setValue(DataObject value) { return null; }
- @Override
- public DataObject getValue() { return ovsdbNodeAugmentation; }
- @Override
- public InstanceIdentifier getKey() { return uniKey; }
- };
- setCreated.clear();
- setCreated.add(created);
-
- when(uniAugmentation.getOvsdbNodeRef()).thenReturn(ovsNodedRef);
- when(optionalOvsdbNode.isPresent()).thenReturn(true);
- verifyExecute(3, 2, 4, 1);
-
- // Case OVSDB2 : uniNodes != null && !uniNodes.isEmpty(),
- // ovsdbNodeAugmentation.getConnectionInfo().getRemoteIp()
- // .equals(uniAugmentation.getIpAddress())
- when(uniAugmentation.getOvsdbNodeRef()).thenReturn(null);
- verifyExecute(3, 3, 4, 2);
}
+ @SuppressWarnings("unchecked")
private void verifyExecute(int qosTimes, int bridgeTimes, int updateNodeTime, int updateIIDTimes){
- uniCreateCommand.execute();
+ uniAddCommand.execute();
PowerMockito.verifyStatic(times(qosTimes));
OvsdbUtils.createQoSForOvsdbNode(any(DataBroker.class), any(UniAugmentation.class));
PowerMockito.verifyStatic(times(bridgeTimes));
UniUtils.updateUniNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
any(UniAugmentation.class), any(InstanceIdentifier.class), any(DataBroker.class));
}
-
-}
+}
\ No newline at end of file
*/
package org.opendaylight.unimgr.command;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.doNothing;
+import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import static org.powermock.api.support.membermodification.MemberMatcher.method;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Mockito;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.unimgr.impl.UnimgrConstants;
import org.opendaylight.unimgr.impl.UnimgrMapper;
import org.opendaylight.unimgr.utils.OvsdbUtils;
import org.opendaylight.unimgr.utils.UniUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
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.OvsdbNodeRef;
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.node.attributes.Queues;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QueuesKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentationBuilder;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
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.NodeBuilder;
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.InstanceIdentifier.InstanceIdentifierBuilder;
import org.powermock.api.mockito.PowerMockito;
-import org.powermock.api.support.membermodification.MemberMatcher;
-import org.powermock.api.support.membermodification.MemberModifier;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
@PrepareForTest({UniUtils.class, OvsdbUtils.class, MdsalUtils.class,
UnimgrMapper.class})
-public class UniDeleteCommandTest {
+public class UniRemoveCommandTest {
private static final NodeId OVSDB_NODE_ID = new NodeId("ovsdb://7011db35-f44b-4aab-90f6-d89088caf9d8");
- private static final String NODE_ID = "uni://10.0.0.1";
-
- private UniDeleteCommand uniDeleteCommand;
- private AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes;
+ private UniRemoveCommand uniRemoveCommand;
+ private DataTreeModification<Node> uni;
private DataBroker dataBroker;
+ private Node uniNode;
@SuppressWarnings("unchecked")
@Before
PowerMockito.mockStatic(OvsdbUtils.class);
PowerMockito.mockStatic(MdsalUtils.class);
PowerMockito.mockStatic(UnimgrMapper.class);
- changes = mock(AsyncDataChangeEvent.class);
dataBroker = mock(DataBroker.class);
- uniDeleteCommand = new UniDeleteCommand(dataBroker, changes);
+ uniNode = mock(Node.class);
+ uni = DataTreeModificationHelper.getUniNode(uniNode);
+ uniRemoveCommand = new UniRemoveCommand(dataBroker, uni);
}
/**
- * Test method for {@link org.opendaylight.unimgr.command.UniDeleteCommand#execute()}.
+ * Test method for {@link org.opendaylight.unimgr.command.UniRemoveCommand#execute()}.
*/
@SuppressWarnings({ "unchecked", "rawtypes"})
@Test
public void testExecute() {
- final Set<InstanceIdentifier<UniAugmentation>> removedUnis =
- new HashSet<InstanceIdentifier<UniAugmentation>>();
- removedUnis.add(mock(InstanceIdentifier.class));
final UniAugmentation uniAugmentation = mock(UniAugmentation.class);
final OvsdbNodeRef ovsNodedRef = mock(OvsdbNodeRef.class);
final Optional<Node> optionalNode = mock(Optional.class);
final OvsdbNodeAugmentation ovsdbNodeAugmentation = mock(OvsdbNodeAugmentation.class);
final QosEntries qosEntries = mock(QosEntries.class);
final Queues queues = mock(Queues.class);
-
+ when(uniNode.getAugmentation(UniAugmentation.class)).thenReturn(uniAugmentation);
when(uniAugmentation.getIpAddress()).thenReturn(mock(IpAddress.class));
when(uniAugmentation.getOvsdbNodeRef()).thenReturn(ovsNodedRef);
when(ovsNodedRef.getValue()).thenReturn(uniKey);
when(queues.getKey()).thenReturn(mock(QueuesKey.class));
queuesList.add(queues);
when(ovsdbNodeAugmentation.getQueues()).thenReturn(queuesList);
- when(OvsdbUtils.extractRemoved(any(AsyncDataChangeEvent.class), any(Class.class)))
- .thenReturn(removedUnis);
when(MdsalUtils.read(any(DataBroker.class), any(LogicalDatastoreType.class),
any(InstanceIdentifier.class))).thenReturn(uniAugmentation);
when(MdsalUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
when(UnimgrMapper.getOvsdbQueuesIid(any(Node.class), any(QueuesKey.class))).thenReturn(instanceOfNode);
when(MdsalUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class),
any(LogicalDatastoreType.class))).thenReturn(true);
- uniDeleteCommand.execute();
-
- PowerMockito.verifyStatic(times(5));
+ uniRemoveCommand.execute();
+ PowerMockito.verifyStatic(times(4));
MdsalUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class),
any(LogicalDatastoreType.class));
}
-}
+}
\ No newline at end of file
*/
package org.opendaylight.unimgr.command;
-import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.unimgr.impl.UnimgrConstants;
import org.opendaylight.unimgr.impl.UnimgrMapper;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeRef;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagedNodeEntry;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagedNodeEntryKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.uni.Speed;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
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.NodeKey;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
private static final NodeId OVSDB_NODE_ID = new NodeId("ovsdb://7011db35-f44b-4aab-90f6-d89088caf9d8");
private UniUpdateCommand uniUpdateCommand;
- private Map<InstanceIdentifier<?>, DataObject> changes;
+ private DataTreeModification<Node> uni;
private DataBroker dataBroker;
- private ManagedNodeEntry managedNodeEntry;
+ private Node uniNode;
@SuppressWarnings("unchecked")
@Before
PowerMockito.mockStatic(MdsalUtils.class);
PowerMockito.mockStatic(OvsdbUtils.class);
PowerMockito.mockStatic(UnimgrMapper.class);
- changes = mock(Map.class);
dataBroker = mock(DataBroker.class);
- uniUpdateCommand = new UniUpdateCommand(dataBroker, changes);
+ uniNode = mock(Node.class);
+ uni = DataTreeModificationHelper.getUniNode(uniNode);
+ uniUpdateCommand = new UniUpdateCommand(dataBroker, uni);
}
/**
final Optional<Node> optionalOvsdbNode = mock(Optional.class);
final UniAugmentation uniAugmentation = mock(UniAugmentation.class);
final OvsdbNodeAugmentation ovsdbNodeAugmentation = mock(OvsdbNodeAugmentation.class);
- managedNodeEntry = mock(ManagedNodeEntry.class);
- final ManagedNodeEntryKey managedNodeEntryKey = mock(ManagedNodeEntryKey.class);
final List<ManagedNodeEntry> managedNodeEntries = new ArrayList<ManagedNodeEntry>();
final ConnectionInfo connectionInfo = mock(ConnectionInfo.class);
final IpAddress ipAddress = mock(IpAddress.class);
.create(NetworkTopology.class)
.child(Topology.class, new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
.child(Node.class, new NodeKey(OVSDB_NODE_ID));
- final Set<Entry<InstanceIdentifier<?>, DataObject>> setCreated = new HashSet<Map.Entry<InstanceIdentifier<?>,DataObject>>();
- Entry<InstanceIdentifier<?>, DataObject> created = new Entry<InstanceIdentifier<?>, DataObject>() {
- @Override
- public DataObject setValue(DataObject value) { return null; }
- @Override
- public DataObject getValue() { return uniAugmentation; }
- @Override
- public InstanceIdentifier getKey() { return uniKey; }
- };
- setCreated.add(created);
- managedNodeEntries.add(managedNodeEntry);
// Case UNI1 : updatedUni.getOvsdbNodeRef() != null, optOvsdbNode.isPresent()
- when(changes.entrySet()).thenReturn(setCreated);
+ when(uniNode.getAugmentation(UniAugmentation.class)).thenReturn(uniAugmentation);
when(optionalOvsdbNode.isPresent()).thenReturn(true);
when(optionalOvsdbNode.get()).thenReturn(node);
when(uniAugmentation.getIpAddress()).thenReturn(ipAddress);
when(uniAugmentation.getOvsdbNodeRef()).thenReturn(ovsNodedRef);
when(ovsdbNodeAugmentation.getConnectionInfo()).thenReturn(connectionInfo);
when(ovsdbNodeAugmentation.getManagedNodeEntry()).thenReturn(managedNodeEntries);
- when(managedNodeEntry.getKey()).thenReturn(managedNodeEntryKey);
when(connectionInfo.getRemoteIp()).thenReturn(ipAddress);
when(ipAddress.getIpv4Address()).thenReturn(ipv4Address);
when(ipv4Address.toString()).thenReturn("ipv4Address_test");
when(node.getAugmentation(any(Class.class))).thenReturn(uniAugmentation);
when(node.getNodeId()).thenReturn(nodeId);
when(nodeId.toString()).thenReturn("ovsdbNodeId_test");
-
when(UniUtils.getUni(any(DataBroker.class), any(LogicalDatastoreType.class), any(IpAddress.class)))
.thenReturn(uniAugmentation);
when(MdsalUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
any(LogicalDatastoreType.class))).thenReturn(true);
when(UnimgrMapper.getUniIid(any(DataBroker.class), any(IpAddress.class),
any(LogicalDatastoreType.class))).thenReturn(uniKey);
- verifyExecute(1, 1, 2, 0);
-
- // Case UNI2 : updatedUni.getOvsdbNodeRef() != null, !optOvsdbNode.isPresent()
- when(optionalOvsdbNode.isPresent()).thenReturn(false);
- verifyExecute(1, 1, 2, 0);
+ verifyExecute(1, 1);
- // Case UNI3 : updatedUni.getOvsdbNodeRef() == null, !optOvsdbNode.isPresent()
- when(uniAugmentation.getOvsdbNodeRef()).thenReturn(null);
- verifyExecute(1, 1, 2, 0);
-
- // Case UNI4 : updatedUni.getOvsdbNodeRef() == null, optOvsdbNode.isPresent()
- when(optionalOvsdbNode.isPresent()).thenReturn(true);
- verifyExecute(2, 2, 4, 0);
-
- // Case OVSDB
- created = new Entry<InstanceIdentifier<?>, DataObject>() {
- @Override
- public DataObject setValue(DataObject value) { return null; }
- @Override
- public DataObject getValue() { return ovsdbNodeAugmentation; }
- @Override
- public InstanceIdentifier getKey() { return uniKey; }
- };
- setCreated.clear();
- setCreated.add(created);
-
- when(uniAugmentation.getOvsdbNodeRef()).thenReturn(ovsNodedRef);
+ // Case 2 : updatedUni.getOvsdbNodeRef() == null, optOvsdbNode.isPresent()
when(optionalOvsdbNode.isPresent()).thenReturn(true);
- verifyExecute(2, 2, 4, 1);
+ verifyExecute(2, 2);
}
- private void verifyExecute(int qosTimes, int deleteTimes, int updateNodeTime, int getKeyTimes){
+ private void verifyExecute(int qosTimes, int updateNodeTime){
uniUpdateCommand.execute();
PowerMockito.verifyStatic(times(qosTimes));
OvsdbUtils.createQoSForOvsdbNode(any(DataBroker.class), any(UniAugmentation.class));
- PowerMockito.verifyStatic(times(deleteTimes));
- MdsalUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class),
- any(LogicalDatastoreType.class));
PowerMockito.verifyStatic(times(updateNodeTime));
UniUtils.updateUniNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
any(UniAugmentation.class), any(Node.class), any(DataBroker.class));
- verify(managedNodeEntry, times(getKeyTimes)).getKey();
}
-}
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 CableLabs 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.unimgr.impl;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+import org.opendaylight.yangtools.yang.binding.ChildOf;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.Identifiable;
+import org.opendaylight.yangtools.yang.binding.Identifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class EvcDataTreeChangeListenerTest {
+
+ private EvcDataTreeChangeListener evcDataTreeChangeListener;
+
+ @Before
+ public void setUp() throws Exception {
+ evcDataTreeChangeListener = mock(EvcDataTreeChangeListener.class, Mockito.CALLS_REAL_METHODS);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testEvcmgrDataTreeChangeListener() {
+ Collection<DataTreeModification<Link>> collection = new ArrayList<DataTreeModification<Link>>();
+ DataTreeModification<Link> evc = getDataTreeLink(ModificationType.WRITE);
+ collection.add(evc);
+ evc = getDataTreeLink(ModificationType.DELETE);
+ collection.add(evc);
+ evc = getDataTreeLink(ModificationType.SUBTREE_MODIFIED);
+ collection.add(evc);
+ evcDataTreeChangeListener.onDataTreeChanged(collection);
+ verify(evcDataTreeChangeListener, times(1)).add(any(DataTreeModification.class));
+ verify(evcDataTreeChangeListener, times(1)).remove(any(DataTreeModification.class));
+ verify(evcDataTreeChangeListener, times(1)).update(any(DataTreeModification.class));
+ }
+
+ private DataTreeModification<Link> getDataTreeLink(final ModificationType modificationType) {
+ final DataObjectModification<Link> evcDataObjModification = new DataObjectModification<Link>() {
+ @Override
+ public Collection<DataObjectModification<? extends DataObject>> getModifiedChildren() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public <C extends Identifiable<K> & ChildOf<? super Link>, K extends Identifier<C>> DataObjectModification<C> getModifiedChildListItem(
+ Class<C> arg0, K arg1) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public <C extends ChildOf<? super Link>> DataObjectModification<C> getModifiedChildContainer(Class<C> arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public DataObjectModification<? extends DataObject> getModifiedChild(PathArgument arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public <C extends Augmentation<Link> & DataObject> DataObjectModification<C> getModifiedAugmentation(
+ Class<C> arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public ModificationType getModificationType() {
+ return modificationType;
+ }
+ @Override
+ public PathArgument getIdentifier() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public Class<Link> getDataType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public Link getDataBefore() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public Link getDataAfter() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+ DataTreeModification<Link> modifiedEvc = new DataTreeModification<Link>() {
+ @Override
+ public DataTreeIdentifier<Link> getRootPath() {
+ return null;
+ }
+ @Override
+ public DataObjectModification<Link> getRootNode() {
+ return evcDataObjModification;
+ }
+ };
+ return modifiedEvc;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 CableLabs 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.unimgr.impl;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+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.Augmentation;
+import org.opendaylight.yangtools.yang.binding.ChildOf;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.Identifiable;
+import org.opendaylight.yangtools.yang.binding.Identifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+
+@RunWith(PowerMockRunner.class)
+public class UniDataTreeChangeListenerTest {
+
+ private UniDataTreeChangeListener uniDataTreeChangeListener;
+
+ @Before
+ public void setUp() throws Exception {
+ uniDataTreeChangeListener = mock(UniDataTreeChangeListener.class, Mockito.CALLS_REAL_METHODS);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testUnimgrDataTreeChangeListener() {
+ Collection<DataTreeModification<Node>> collection = new ArrayList<DataTreeModification<Node>>();
+ DataTreeModification<Node> uni = getDataTreeNode(ModificationType.WRITE);
+ collection.add(uni);
+ uni = getDataTreeNode(ModificationType.DELETE);
+ collection.add(uni);
+ uni = getDataTreeNode(ModificationType.SUBTREE_MODIFIED);
+ collection.add(uni);
+ uniDataTreeChangeListener.onDataTreeChanged(collection);
+ verify(uniDataTreeChangeListener, times(1)).add(any(DataTreeModification.class));
+ verify(uniDataTreeChangeListener, times(1)).remove(any(DataTreeModification.class));
+ verify(uniDataTreeChangeListener, times(1)).update(any(DataTreeModification.class));
+ }
+
+ private DataTreeModification<Node> getDataTreeNode(final ModificationType modificationType) {
+ final DataObjectModification<Node> uniDataObjModification = new DataObjectModification<Node>() {
+ @Override
+ public Collection<DataObjectModification<? extends DataObject>> getModifiedChildren() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public <C extends Identifiable<K> & ChildOf<? super Node>, K extends Identifier<C>> DataObjectModification<C> getModifiedChildListItem(
+ Class<C> arg0, K arg1) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public <C extends ChildOf<? super Node>> DataObjectModification<C> getModifiedChildContainer(Class<C> arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public DataObjectModification<? extends DataObject> getModifiedChild(PathArgument arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public <C extends Augmentation<Node> & DataObject> DataObjectModification<C> getModifiedAugmentation(
+ Class<C> arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public ModificationType getModificationType() {
+ return modificationType;
+ }
+ @Override
+ public PathArgument getIdentifier() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public Class<Node> getDataType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public Node getDataBefore() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public Node getDataAfter() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+ DataTreeModification<Node> modifiedUni = new DataTreeModification<Node>() {
+ @Override
+ public DataTreeIdentifier<Node> getRootPath() {
+ return null;
+ }
+ @Override
+ public DataObjectModification<Node> getRootNode() {
+ return uniDataObjModification;
+ }
+ };
+ return modifiedUni;
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2016 CableLabs 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.unimgr.impl;
-
-import static org.junit.Assert.assertFalse;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.atLeast;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.unimgr.command.Command;
-import org.opendaylight.unimgr.command.EvcCreateCommand;
-import org.opendaylight.unimgr.command.EvcDeleteCommand;
-import org.opendaylight.unimgr.command.EvcUpdateCommand;
-import org.opendaylight.unimgr.command.TransactionInvoker;
-import org.opendaylight.unimgr.command.UniCreateCommand;
-import org.opendaylight.unimgr.command.UniDeleteCommand;
-import org.opendaylight.unimgr.command.UniUpdateCommand;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.api.support.membermodification.MemberModifier;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({UnimgrMapper.class,
- UnimgrDataChangeListener.class})
-public class UnimgrDataChangeListenerTest {
-
- @Mock private UnimgrDataChangeListener unimgrDataChangeListener;
- @Mock private HashSet<ListenerRegistration<DataChangeListener>> listeners;
- @Mock private DataBroker dataBroker;
- @Mock private TransactionInvoker invoker;
-
- @Before
- public void setUp() throws Exception {
- unimgrDataChangeListener = mock(UnimgrDataChangeListener.class, Mockito.CALLS_REAL_METHODS);
- MemberModifier.field(UnimgrDataChangeListener.class, "invoker").set(unimgrDataChangeListener, invoker);
- }
-
- @SuppressWarnings({ "unchecked", "resource" })
- @Test
- public void testUnimgrDataChangeListener() throws Exception {
- final InstanceIdentifier<Topology> path = mock(InstanceIdentifier.class);
- final ListenerRegistration<DataChangeListener> listenerRegistration = mock(ListenerRegistration.class);
- PowerMockito.mockStatic(UnimgrMapper.class);
- PowerMockito.when(UnimgrMapper.getUniTopologyIid()).thenReturn(path);
- PowerMockito.when(UnimgrMapper.getEvcTopologyIid()).thenReturn(path);
- PowerMockito.when(UnimgrMapper.getOvsdbTopologyIid()).thenReturn(path);
- PowerMockito.whenNew(HashSet.class).withNoArguments().thenReturn(listeners);
- when(listeners.add(any(ListenerRegistration.class))).thenReturn(true);
- when(dataBroker.registerDataChangeListener(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(UnimgrDataChangeListener.class),
- eq(DataChangeScope.SUBTREE))).thenReturn(listenerRegistration);
- new UnimgrDataChangeListener(dataBroker, invoker);
- assertFalse(listeners.isEmpty());
- verify(listeners, atLeast(3)).add(any(ListenerRegistration.class));
- verify(dataBroker, atLeast(3)).registerDataChangeListener(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(UnimgrDataChangeListener.class),
- eq(DataChangeScope.SUBTREE));
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- @Test
- public void testOnDataChanged() {
- final AsyncDataChangeEvent change = mock(AsyncDataChangeEvent.class);
- final Map map = mock(Map.class);
- when(change.getCreatedData()).thenReturn(map);
- doNothing().when(unimgrDataChangeListener).create(any(Map.class));
- doNothing().when(unimgrDataChangeListener).update(any(Map.class));
- doNothing().when(unimgrDataChangeListener).delete(any(AsyncDataChangeEvent.class));
- unimgrDataChangeListener.onDataChanged(change);
- verify(unimgrDataChangeListener).create(any(Map.class));
- verify(unimgrDataChangeListener).update(any(Map.class));
- verify(unimgrDataChangeListener).delete(any(AsyncDataChangeEvent.class));
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testCreate() throws Exception {
- // False case
- unimgrDataChangeListener.create(null);
-
- // True case
- final Map<InstanceIdentifier<?>, DataObject> changes = mock(Map.class);
- final UniCreateCommand uniCreate = mock(UniCreateCommand.class);
- final EvcCreateCommand evcCreate = mock(EvcCreateCommand.class);
- final List<Command> commands = mock(ArrayList.class);
- PowerMockito.whenNew(ArrayList.class).withNoArguments()
- .thenReturn((ArrayList<Command>) commands);
- PowerMockito.whenNew(UniCreateCommand.class).withArguments(any(DataBroker.class),
- any(Map.class)).thenReturn(uniCreate);
- PowerMockito.whenNew(EvcCreateCommand.class).withArguments(any(DataBroker.class),
- any(Map.class)).thenReturn(evcCreate);
- when(commands.add(any(Command.class))).thenReturn(true);
- doNothing().when(invoker).setCommands(any(ArrayList.class));
- doNothing().when(invoker).invoke();
- unimgrDataChangeListener.create(changes);
- verify(invoker, times(1)).setCommands(any(List.class));
- verify(invoker, times(1)).invoke();
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testUpdate() throws Exception {
- // False case
- unimgrDataChangeListener.update(null);
-
- // True case
- final Map<InstanceIdentifier<?>, DataObject> changes = mock(Map.class);
- final UniUpdateCommand uniUpdate = mock(UniUpdateCommand.class);
- final EvcUpdateCommand evcUpdate = mock(EvcUpdateCommand.class);
- final List<Command> commands = mock(ArrayList.class);
- PowerMockito.whenNew(ArrayList.class).withNoArguments()
- .thenReturn((ArrayList<Command>) commands);
- PowerMockito.whenNew(UniUpdateCommand.class).withArguments(any(DataBroker.class),
- any(Map.class)).thenReturn(uniUpdate);
- PowerMockito.whenNew(EvcUpdateCommand.class).withArguments(any(DataBroker.class),
- any(Map.class)).thenReturn(evcUpdate);
- when(commands.add(any(Command.class))).thenReturn(true);
- doNothing().when(invoker).setCommands(any(ArrayList.class));
- doNothing().when(invoker).invoke();
- unimgrDataChangeListener.update(changes);
- verify(invoker, times(1)).setCommands(any(List.class));
- verify(invoker, times(1)).invoke();
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testDelete() throws Exception {
- // False case
- unimgrDataChangeListener.delete(null);
-
- // True case
- final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes = mock(AsyncDataChangeEvent.class);
- final UniDeleteCommand uniDelete = mock(UniDeleteCommand.class);
- final EvcDeleteCommand evcDelete = mock(EvcDeleteCommand.class);
- final List<Command> commands = mock(ArrayList.class);
- PowerMockito.whenNew(ArrayList.class).withNoArguments()
- .thenReturn((ArrayList<Command>) commands);
- PowerMockito.whenNew(UniDeleteCommand.class).withArguments(any(DataBroker.class),
- any(AsyncDataChangeEvent.class)).thenReturn(uniDelete);
- PowerMockito.whenNew(EvcDeleteCommand.class).withArguments(any(DataBroker.class),
- any(AsyncDataChangeEvent.class)).thenReturn(evcDelete);
- when(commands.add(any(Command.class))).thenReturn(true);
- doNothing().when(invoker).setCommands(any(ArrayList.class));
- doNothing().when(invoker).invoke();
- unimgrDataChangeListener.delete(changes);
- verify(invoker, times(1)).setCommands(any(List.class));
- verify(invoker, times(1)).invoke();
- }
-}
*/
package org.opendaylight.unimgr.impl;
+import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.isNull;
+import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.isNull;
-
-import static org.junit.Assert.assertEquals;
import java.util.Dictionary;
import java.util.List;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
import org.opendaylight.unimgr.api.IUnimgrConsoleProvider;
-import org.opendaylight.unimgr.command.TransactionInvoker;
import org.opendaylight.unimgr.utils.MdsalUtils;
import org.opendaylight.unimgr.utils.OvsdbUtils;
import org.opendaylight.unimgr.utils.UniUtils;
UnimgrMapper.class})
public class UnimgrProviderTest {
- @Mock private UnimgrDataChangeListener listener;
- @Mock private DataBroker dataBroker;
- @Mock private UnimgrProvider unimgrProvider;
@Mock private IUnimgrConsoleProvider console;
+ @Mock private UniDataTreeChangeListener uniListener;
+ @Mock private EvcDataTreeChangeListener evcListener;
+ @Mock private OvsNodeDataTreeChangeListener ovsListener;
+ @Mock private DataBroker dataBroker;
@Mock private ServiceRegistration<IUnimgrConsoleProvider> mockUnimgrConsoleRegistration;
+ @Mock private UnimgrProvider unimgrProvider;
@Before
public void setUp() throws Exception {
unimgrProvider = PowerMockito.mock(UnimgrProvider.class, Mockito.CALLS_REAL_METHODS);
- MemberModifier.field(UnimgrProvider.class, "listener").set(unimgrProvider, listener);
MemberModifier.field(UnimgrProvider.class, "dataBroker").set(unimgrProvider, dataBroker);
+ MemberModifier.field(UnimgrProvider.class, "uniListener").set(unimgrProvider, uniListener);
+ MemberModifier.field(UnimgrProvider.class, "evcListener").set(unimgrProvider, evcListener);
+ MemberModifier.field(UnimgrProvider.class, "ovsListener").set(unimgrProvider, ovsListener);
console = unimgrProvider;
}
- @SuppressWarnings("unchecked")
@Test
- public void testOnSessionInitiated() throws Exception {
- final ProviderContext session = mock(ProviderContext.class);
- when(session.getSALService(DataBroker.class)).thenReturn(dataBroker);
- final BundleContext context = mock(BundleContext.class);
- PowerMockito.mockStatic(FrameworkUtil.class);
- final Bundle bundle = mock(Bundle.class);
- when(bundle.getBundleContext()).thenReturn(context);
- PowerMockito.when(FrameworkUtil.getBundle(unimgrProvider.getClass())).thenReturn(bundle);
- mockUnimgrConsoleRegistration = mock(ServiceRegistration.class);
- when(context.registerService(eq(IUnimgrConsoleProvider.class),
- any(IUnimgrConsoleProvider.class),
- isNull(Dictionary.class))).thenReturn(mockUnimgrConsoleRegistration);
- PowerMockito.whenNew(UnimgrDataChangeListener.class).withArguments(any(DataBroker.class),
- any(TransactionInvoker.class))
- .thenReturn(listener);
- MemberModifier.suppress(MemberMatcher.method(UnimgrProvider.class, "initDatastore"));
- unimgrProvider.onSessionInitiated(session);
- verify(unimgrProvider, atLeast(4)).initDatastore(any(LogicalDatastoreType.class), any(TopologyId.class));
+ public void testAddEvc() throws Exception {
+ assertEquals(false, unimgrProvider.addEvc(any(EvcAugmentation.class)));
}
- @SuppressWarnings("unchecked")
@Test
- public void testInitializeTopology() throws Exception {
- final InstanceIdentifier<NetworkTopology> path = mock(InstanceIdentifier.class);
- PowerMockito.mockStatic(InstanceIdentifier.class);
- when(InstanceIdentifier.create(NetworkTopology.class)).thenReturn(path);
-
- final CheckedFuture<Optional<NetworkTopology>, ReadFailedException> topology = mock(CheckedFuture.class);
- final ReadWriteTransaction transaction = mock(ReadWriteTransaction.class);
- when(dataBroker.newReadWriteTransaction()).thenReturn(transaction);
- when(transaction.read(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class))).thenReturn(topology);
+ public void testAddUni() throws Exception {
+ PowerMockito.mockStatic(UniUtils.class);
+ assertEquals(unimgrProvider.addUni(null), false);
+ final UniAugmentation mockUniAug = mock(UniAugmentation.class);
+ // false case
+ when(mockUniAug.getIpAddress()).thenReturn(null);
+ assertEquals(unimgrProvider.addUni(mockUniAug), false);
+ when(mockUniAug.getMacAddress()).thenReturn(null);
+ assertEquals(unimgrProvider.addUni(mockUniAug), false);
+ // true case
+ when(mockUniAug.getIpAddress()).thenReturn(mock(IpAddress.class));
+ when(mockUniAug.getMacAddress()).thenReturn(mock(MacAddress.class));
+ final UniAugmentationBuilder uniAugBuilder = new UniAugmentationBuilder()
+ .setIpAddress(mock(IpAddress.class))
+ .setMacAddress(mock(MacAddress.class));
+ when(UniUtils.createUniNode(any(DataBroker.class),
+ any(UniAugmentation.class)))
+ .thenReturn(true);
+ assertEquals(true, unimgrProvider.addUni(uniAugBuilder.build()));
+ }
- final Optional<NetworkTopology> optNetTopo = mock(Optional.class);
- when(topology.get()).thenReturn(optNetTopo);
- when(optNetTopo.isPresent()).thenReturn(false);
- final NetworkTopologyBuilder ntb = mock(NetworkTopologyBuilder.class);
- PowerMockito.whenNew(NetworkTopologyBuilder.class).withNoArguments().thenReturn(ntb);
- final NetworkTopology networkTopology = mock(NetworkTopology.class);
- when(ntb.build()).thenReturn(networkTopology);
- doNothing().when(transaction).put(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(NetworkTopology.class));
- when(transaction.submit()).thenReturn(mock(CheckedFuture.class));
+ @Test
+ public void testGetEvc() throws Exception {
+ assertEquals(null, unimgrProvider.getEvc(any(String.class)));
+ }
- final LogicalDatastoreType type = PowerMockito.mock(LogicalDatastoreType.class);
- Whitebox.invokeMethod(unimgrProvider, "initializeTopology", type);
- verify(ntb).build();
- verify(transaction).put(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(NetworkTopology.class));
- verify(transaction).submit();
+ @Test
+ public void testgetUni() throws Exception {
+ PowerMockito.mockStatic(UniUtils.class);
+ final UniAugmentation mockUniAug = mock(UniAugmentation.class);
+ when(UniUtils.getUni(any(DataBroker.class),
+ any(LogicalDatastoreType.class),
+ any(IpAddress.class)))
+ .thenReturn(mockUniAug);
+ final IpAddress mockIpAddress = mock(IpAddress.class);
+ assertEquals(mockUniAug, unimgrProvider.getUni(mockIpAddress));
}
@SuppressWarnings("unchecked")
any(LogicalDatastoreType.class));
}
+ @SuppressWarnings("unchecked")
@Test
- public void testAddUni() throws Exception {
+ public void testInitializeTopology() throws Exception {
+ final InstanceIdentifier<NetworkTopology> path = mock(InstanceIdentifier.class);
+ PowerMockito.mockStatic(InstanceIdentifier.class);
+ when(InstanceIdentifier.create(NetworkTopology.class)).thenReturn(path);
+
+ final CheckedFuture<Optional<NetworkTopology>, ReadFailedException> topology = mock(CheckedFuture.class);
+ final ReadWriteTransaction transaction = mock(ReadWriteTransaction.class);
+ when(dataBroker.newReadWriteTransaction()).thenReturn(transaction);
+ when(transaction.read(any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class))).thenReturn(topology);
+
+ final Optional<NetworkTopology> optNetTopo = mock(Optional.class);
+ when(topology.get()).thenReturn(optNetTopo);
+ when(optNetTopo.isPresent()).thenReturn(false);
+ final NetworkTopologyBuilder ntb = mock(NetworkTopologyBuilder.class);
+ PowerMockito.whenNew(NetworkTopologyBuilder.class).withNoArguments().thenReturn(ntb);
+ final NetworkTopology networkTopology = mock(NetworkTopology.class);
+ when(ntb.build()).thenReturn(networkTopology);
+ doNothing().when(transaction).put(any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class),
+ any(NetworkTopology.class));
+ when(transaction.submit()).thenReturn(mock(CheckedFuture.class));
+
+ final LogicalDatastoreType type = PowerMockito.mock(LogicalDatastoreType.class);
+ Whitebox.invokeMethod(unimgrProvider, "initializeTopology", type);
+ verify(ntb).build();
+ verify(transaction).put(any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class),
+ any(NetworkTopology.class));
+ verify(transaction).submit();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testlistUnis() throws Exception {
PowerMockito.mockStatic(UniUtils.class);
- assertEquals(unimgrProvider.addUni(null), false);
- final UniAugmentation mockUniAug = mock(UniAugmentation.class);
- // false case
- when(mockUniAug.getIpAddress()).thenReturn(null);
- assertEquals(unimgrProvider.addUni(mockUniAug), false);
- when(mockUniAug.getMacAddress()).thenReturn(null);
- assertEquals(unimgrProvider.addUni(mockUniAug), false);
- // true case
- when(mockUniAug.getIpAddress()).thenReturn(mock(IpAddress.class));
- when(mockUniAug.getMacAddress()).thenReturn(mock(MacAddress.class));
- final UniAugmentationBuilder uniAugBuilder = new UniAugmentationBuilder()
- .setIpAddress(mock(IpAddress.class))
- .setMacAddress(mock(MacAddress.class));
- when(UniUtils.createUniNode(any(DataBroker.class),
- any(UniAugmentation.class)))
- .thenReturn(true);
- assertEquals(true, unimgrProvider.addUni(uniAugBuilder.build()));
+ final List<UniAugmentation> mockUniList = mock(List.class);
+ when(UniUtils.getUnis(any(DataBroker.class),
+ any(LogicalDatastoreType.class)))
+ .thenReturn(mockUniList);
+ assertEquals(mockUniList,
+ unimgrProvider.listUnis(any(LogicalDatastoreType.class)));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testOnSessionInitiated() throws Exception {
+ final ProviderContext session = mock(ProviderContext.class);
+ when(session.getSALService(DataBroker.class)).thenReturn(dataBroker);
+ final BundleContext context = mock(BundleContext.class);
+ PowerMockito.mockStatic(FrameworkUtil.class);
+ final Bundle bundle = mock(Bundle.class);
+ when(bundle.getBundleContext()).thenReturn(context);
+ PowerMockito.when(FrameworkUtil.getBundle(unimgrProvider.getClass())).thenReturn(bundle);
+ mockUnimgrConsoleRegistration = mock(ServiceRegistration.class);
+ when(context.registerService(eq(IUnimgrConsoleProvider.class),
+ any(IUnimgrConsoleProvider.class),
+ isNull(Dictionary.class))).thenReturn(mockUnimgrConsoleRegistration);
+ PowerMockito.whenNew(UniDataTreeChangeListener.class).withArguments(any(DataBroker.class)).thenReturn(uniListener);
+ PowerMockito.whenNew(EvcDataTreeChangeListener.class).withArguments(any(DataBroker.class)).thenReturn(evcListener);
+ PowerMockito.whenNew(OvsNodeDataTreeChangeListener.class).withArguments(any(DataBroker.class)).thenReturn(ovsListener);
+ MemberModifier.suppress(MemberMatcher.method(UnimgrProvider.class, "initDatastore"));
+ unimgrProvider.onSessionInitiated(session);
+ verify(unimgrProvider, atLeast(4)).initDatastore(any(LogicalDatastoreType.class), any(TopologyId.class));
+ }
+
+ @Test
+ public void testRemoveEvc() throws Exception {
+ assertEquals(false, unimgrProvider.removeEvc(any(String.class)));
}
@SuppressWarnings("unchecked")
assertEquals(true, unimgrProvider.removeUni(ipAddress));
}
- @SuppressWarnings("unchecked")
- @Test
- public void testlistUnis() throws Exception {
- PowerMockito.mockStatic(UniUtils.class);
- final List<UniAugmentation> mockUniList = mock(List.class);
- when(UniUtils.getUnis(any(DataBroker.class),
- any(LogicalDatastoreType.class)))
- .thenReturn(mockUniList);
- assertEquals(mockUniList,
- unimgrProvider.listUnis(any(LogicalDatastoreType.class)));
- }
-
- @Test
- public void testgetUni() throws Exception {
- PowerMockito.mockStatic(UniUtils.class);
- final UniAugmentation mockUniAug = mock(UniAugmentation.class);
- when(UniUtils.getUni(any(DataBroker.class),
- any(LogicalDatastoreType.class),
- any(IpAddress.class)))
- .thenReturn(mockUniAug);
- final IpAddress mockIpAddress = mock(IpAddress.class);
- assertEquals(mockUniAug, unimgrProvider.getUni(mockIpAddress));
- }
-
- @Test
- public void testRemoveEvc() throws Exception {
- assertEquals(false, unimgrProvider.removeEvc(any(String.class)));
- }
-
- @Test
- public void testAddEvc() throws Exception {
- assertEquals(false, unimgrProvider.addEvc(any(EvcAugmentation.class)));
- }
-
- @Test
- public void testGetEvc() throws Exception {
- assertEquals(null, unimgrProvider.getEvc(any(String.class)));
- }
-
@Test
public void testUpdateEvc() throws Exception {
final UniSource uniSource = mock(UniSource.class);
}
@Test
- public void testCreateEvc() {
+ public void createAndDeleteUNITest() {
+ UniAugmentation uni = new UniAugmentationBuilder()
+ .setMacAddress(new MacAddress(MAC_ADDRESS_1))
+ .setMacLayer(MAC_LAYER)
+ .setMode(MODE)
+ .setMtuSize(BigInteger.valueOf(Long.valueOf(MTU_SIZE)))
+ .setPhysicalMedium(PHY_MEDIUM)
+ .setSpeed(null)
+ .setType(TYPE)
+ .setIpAddress(new IpAddress(IP_1.toCharArray()))
+ .build();
+
+ InstanceIdentifier<Node> nodePath = createUniNode(MAC_ADDRESS_1, IP_1);
+ Assert.assertTrue(validateUni(true, nodePath));
+
+ InstanceIdentifier<Node> deletedNodePath = deleteNode(MAC_ADDRESS_1, IP_1);
+ Assert.assertTrue(validateUni(false, deletedNodePath));
+ }
+
+ @Test
+ public void testCreateAndDeleteEvc() {
LOG.info("Test for create Evc");
// Create an evc between the two Uni nodes
- InstanceIdentifier<Link> evcIid = createOrDeleteEvcLink(IP_1, MAC_ADDRESS_1, IP_2, MAC_ADDRESS_2, EVC_ID_1, true);
+ InstanceIdentifier<Link> evcIid = createEvcLink(IP_1, MAC_ADDRESS_1, IP_2, MAC_ADDRESS_2, EVC_ID_1);
Assert.assertNotNull(evcIid);
// Validate Evc create operation
boolean status = validateEvc(true, EVC_ID_1);
Assert.assertTrue(status);
- }
-
- @Test
- public void testDeleteEvc() {
- LOG.info("Test for delete Evc");
- // Create an evc between the two Uni nodes
- InstanceIdentifier<Link> evcIid = createOrDeleteEvcLink(IP_1, MAC_ADDRESS_1, IP_2, MAC_ADDRESS_2, EVC_ID_1, true);
- Assert.assertNotNull(evcIid);
//Delete the Evc
- evcIid = createOrDeleteEvcLink(IP_1, MAC_ADDRESS_1, IP_2, MAC_ADDRESS_2, EVC_ID_1, false);
+ evcIid = deleteEvc(EVC_ID_1);
Assert.assertNotNull(evcIid);
// Validate Evc delete operation
- boolean status = validateEvc(false, EVC_ID_1);
+ status = validateEvc(false, EVC_ID_1);
Assert.assertTrue(status);
}
return uniNodeIid;
}
- private InstanceIdentifier<Link> createOrDeleteEvcLink(String srcUniIp, String srcMac,
- String dstUniIp, String dstMac, String evcId,
- boolean isCreate) {
+ private InstanceIdentifier<Link> deleteEvc(String evcId) {
+ LinkId evcLinkId = new LinkId(new LinkId("evc://" + evcId));
+ InstanceIdentifier<Link> evcLinkIid = null;
+ evcLinkIid = getEvcLinkIid(evcId);
+ if (evcLinkIid != null) {
+ WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
+ transaction.delete(LogicalDatastoreType.CONFIGURATION, evcLinkIid);
+ CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
+ try {
+ future.checkedGet();
+ } catch (TransactionCommitFailedException e) {
+ LOG.error("Error while deleting Evc {}", evcLinkIid);
+ }
+ LOG.info("Deleted an Evc link {}", evcLinkId);
+ }
+ return evcLinkIid;
+ }
+
+ private InstanceIdentifier<Link> createEvcLink(String srcUniIp, String srcMac,
+ String dstUniIp, String dstMac, String evcId) {
// Create two Uni nodes before creating an Evc
InstanceIdentifier<Node> uniIid = createUniNode(srcMac, srcUniIp);
Assert.assertNotNull(uniIid);
InstanceIdentifier<Link> evcLinkIid = null;
try {
evcLinkIid = getEvcLinkIid(evcId);
- if(isCreate) {
- LinkKey evcLinkKey = new LinkKey(evcLinkId);
- Source mandatorySrcNode = new SourceBuilder().setSourceNode(new NodeId("uni://" + srcUniIp)).build();
- Destination mandatoryDstNode = new DestinationBuilder().setDestNode(new NodeId("uni://" + dstUniIp)).build();
- Link linkData = new LinkBuilder()
+ LinkKey evcLinkKey = new LinkKey(evcLinkId);
+ Source mandatorySrcNode = new SourceBuilder().setSourceNode(new NodeId("uni://" + srcUniIp)).build();
+ Destination mandatoryDstNode = new DestinationBuilder().setDestNode(new NodeId("uni://" + dstUniIp)).build();
+ Link linkData = new LinkBuilder()
.setKey(evcLinkKey)
.setSource(mandatorySrcNode)
.setDestination(mandatoryDstNode)
.setLinkId(evcLinkId)
.addAugmentation(EvcAugmentation.class, evc)
.build();
- WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
- transaction.put(LogicalDatastoreType.CONFIGURATION, evcLinkIid, linkData);
- CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
- future.checkedGet();
- LOG.info("Created and submitted a new Evc link {}", evcLinkId);
- } else {
- WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
- transaction.delete(LogicalDatastoreType.CONFIGURATION, evcLinkIid);
- CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
- future.checkedGet();
- LOG.info("Deleted an Evc link {}", evcLinkId);
- }
+ WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
+ transaction.put(LogicalDatastoreType.CONFIGURATION, evcLinkIid, linkData);
+ CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
+ future.checkedGet();
+ LOG.info("Created and submitted a new Evc link {}", evcLinkId);
} catch (Exception e) {
- if (isCreate) {
- LOG.error("Exception while creating Evc " + "Evc link Id: {}, {}", evcLinkId, e);
- } else {
- LOG.error("Exception while deleting Evc " + "Evc link Id: {}, {}", evcLinkId, e);
- }
+ LOG.error("Exception while creating Evc " + "Evc link Id: {}, {}", evcLinkId, e);
return null;
}
return evcLinkIid;
return result;
}
- @Test
- public void createAndDeleteUNITest() {
- UniAugmentation uni = new UniAugmentationBuilder()
- .setMacAddress(new MacAddress(MAC_ADDRESS_1))
- .setMacLayer(MAC_LAYER)
- .setMode(MODE)
- .setMtuSize(BigInteger.valueOf(Long.valueOf(MTU_SIZE)))
- .setPhysicalMedium(PHY_MEDIUM)
- .setSpeed(null)
- .setType(TYPE)
- .setIpAddress(new IpAddress(IP_1.toCharArray()))
- .build();
-
- InstanceIdentifier<Node> nodePath = createUniNode(MAC_ADDRESS_1, IP_1);
- Assert.assertTrue(validateUni(true, nodePath));
-
- InstanceIdentifier<Node> deletedNodePath = deleteNode(MAC_ADDRESS_1, IP_1);
- Assert.assertTrue(validateUni(false, deletedNodePath));
- }
-
private boolean validateUni(boolean forCreate, InstanceIdentifier<Node> iid) {
Node uni = read(LogicalDatastoreType.CONFIGURATION, iid);
if (forCreate && uni != null) {