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.impl.UnimgrUtils;
+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.UniAugmentation;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
evc.getUniDest().iterator().next().getIpAddress(),
LogicalDatastoreType.OPERATIONAL);
}
- Optional<Node> optionalUniSource = UnimgrUtils.readNode(dataBroker,
+ Optional<Node> optionalUniSource = MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
sourceUniIid);
- Optional<Node> optionalUniDestination = UnimgrUtils.readNode(dataBroker,
+ Optional<Node> optionalUniDestination = MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
destinationUniIid);
Node uniSource;
UniAugmentation destinationUniAugmentation =
uniDestination.getAugmentation(UniAugmentation.class);
Optional<Node> optionalSourceOvsdbNode =
- UnimgrUtils.readNode(dataBroker,
+ MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
sourceUniAugmentation
.getOvsdbNodeRef()
.getValue());
Optional<Node> optionalDestinationOvsdbNode =
- UnimgrUtils.readNode(dataBroker,
+ MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
destinationUniAugmentation
.getOvsdbNodeRef()
if (optionalSourceOvsdbNode.isPresent() && optionalDestinationOvsdbNode.isPresent()) {
InstanceIdentifier<Node> sourceBridgeIid =
UnimgrMapper.getOvsdbBridgeNodeIid(optionalSourceOvsdbNode.get());
- Optional<Node> optionalSourceBr = UnimgrUtils.readNode(dataBroker,
+ Optional<Node> optionalSourceBr = MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
sourceBridgeIid);
InstanceIdentifier<Node> destinationBridgeIid =
UnimgrMapper.getOvsdbBridgeNodeIid(optionalDestinationOvsdbNode.get());
- Optional<Node> optionalDestinationBr = UnimgrUtils.readNode(dataBroker,
+ Optional<Node> optionalDestinationBr = MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
destinationBridgeIid);
//update ovsdb qos-entry and queues with max-rate to match evc ingress BW
- UnimgrUtils.updateMaxRate(dataBroker, sourceUniAugmentation, destinationUniAugmentation, evc);
+ OvsdbUtils.updateMaxRate(dataBroker, sourceUniAugmentation, destinationUniAugmentation, evc);
Node sourceBr;
Node destinationBr;
if (optionalSourceBr.isPresent() && optionalDestinationBr.isPresent()) {
sourceBr = optionalSourceBr.get();
destinationBr = optionalDestinationBr.get();
- UnimgrUtils.createTerminationPointNode(dataBroker,
+ OvsdbUtils.createTerminationPointNode(dataBroker,
uniSource.getAugmentation(UniAugmentation.class),
sourceBr,
UnimgrConstants.DEFAULT_BRIDGE_NAME,
UnimgrConstants.DEFAULT_TUNNEL_IFACE);
- UnimgrUtils.createGreTunnel(dataBroker,
+ OvsdbUtils.createGreTunnel(dataBroker,
uniSource.getAugmentation(UniAugmentation.class),
uniDestination.getAugmentation(UniAugmentation.class),
sourceBr,
UnimgrConstants.DEFAULT_BRIDGE_NAME,
UnimgrConstants.DEFAULT_GRE_TUNNEL_NAME);
- UnimgrUtils.createTerminationPointNode(dataBroker,
+ OvsdbUtils.createTerminationPointNode(dataBroker,
uniDestination.getAugmentation(UniAugmentation.class),
destinationBr,
UnimgrConstants.DEFAULT_BRIDGE_NAME,
UnimgrConstants.DEFAULT_TUNNEL_IFACE);
- UnimgrUtils.createGreTunnel(dataBroker,
+ OvsdbUtils.createGreTunnel(dataBroker,
uniDestination.getAugmentation(UniAugmentation.class),
uniSource.getAugmentation(UniAugmentation.class), destinationBr,
UnimgrConstants.DEFAULT_BRIDGE_NAME,
UnimgrConstants.DEFAULT_GRE_TUNNEL_NAME);
- UnimgrUtils.updateEvcNode(LogicalDatastoreType.CONFIGURATION,
+ EvcUtils.updateEvcNode(LogicalDatastoreType.CONFIGURATION,
evcKey,
evc,
sourceUniIid,
destinationUniIid,
dataBroker);
- UnimgrUtils.updateEvcNode(LogicalDatastoreType.OPERATIONAL,
+ EvcUtils.updateEvcNode(LogicalDatastoreType.OPERATIONAL,
evcKey,
evc,
sourceUniIid,
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.UnimgrUtils;
+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;
@Override
public void execute() {
- Set<InstanceIdentifier<EvcAugmentation>> removedEvcs = UnimgrUtils.extractRemoved(changes,
+ Set<InstanceIdentifier<EvcAugmentation>> removedEvcs = OvsdbUtils.extractRemoved(changes,
EvcAugmentation.class);
if (!removedEvcs.isEmpty()) {
for (InstanceIdentifier<EvcAugmentation> removedEvcIid: removedEvcs) {
- EvcAugmentation evcAugmentation = UnimgrUtils.read(dataBroker,
+ EvcAugmentation evcAugmentation = MdsalUtils.read(dataBroker,
LogicalDatastoreType.OPERATIONAL,
removedEvcIid);
if (evcAugmentation != null) {
for (UniSource source: unisSource) {
if (source != null) {
Optional<Node> optionalSourceUniNode =
- UnimgrUtils.readNode(dataBroker,
+ MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
source.getUni());
- UnimgrUtils.deleteEvcData(dataBroker, optionalSourceUniNode);
+ EvcUtils.deleteEvcData(dataBroker, optionalSourceUniNode);
}
}
}
for (UniDest dest : unisDest) {
if (dest != null) {
Optional<Node> optionalDestUniNode =
- UnimgrUtils.readNode(dataBroker,
+ MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
dest.getUni());
- UnimgrUtils.deleteEvcData(dataBroker, optionalDestUniNode);
+ EvcUtils.deleteEvcData(dataBroker, optionalDestUniNode);
}
}
}
}
- UnimgrUtils.deleteNode(dataBroker, removedEvcIid, LogicalDatastoreType.OPERATIONAL);
+ MdsalUtils.deleteNode(dataBroker, removedEvcIid, LogicalDatastoreType.OPERATIONAL);
}
}
}
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.impl.UnimgrUtils;
+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.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.unimgr.rev151012.EvcAugmentation;
super.changes = changes;
}
+ @SuppressWarnings("unchecked")
@Override
public void execute() {
for (final Entry<InstanceIdentifier<?>, DataObject> updated : changes.entrySet()) {
} 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 = UnimgrUtils.readNode(dataBroker, LogicalDatastoreType.OPERATIONAL, formerUniIID);
- UnimgrUtils.deleteEvcData(dataBroker, formerUni);
+ final Optional<Node> formerUni = MdsalUtils.readNode(dataBroker, LogicalDatastoreType.OPERATIONAL, formerUniIID);
+ EvcUtils.deleteEvcData(dataBroker, formerUni);
}
if (formerUni2ip.equals(laterUni1Ip)) {
// 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 = UnimgrUtils.readNode(dataBroker, LogicalDatastoreType.OPERATIONAL, formerUniIID);
- UnimgrUtils.deleteEvcData(dataBroker, formerUni);
+ 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);
}
// Retrieve the source and destination UNIs
- final Optional<Node> optionalUniSource = UnimgrUtils.readNode(dataBroker,
+ final Optional<Node> optionalUniSource = MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
sourceUniIid);
- final Optional<Node> optionalUniDestination = UnimgrUtils.readNode(dataBroker,
+ final Optional<Node> optionalUniDestination = MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
destinationUniIid);
final UniAugmentation destinationUniAugmentation =
uniDestination.getAugmentation(UniAugmentation.class);
final Optional<Node> optionalSourceOvsdbNode =
- UnimgrUtils.readNode(dataBroker,
+ MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
sourceUniAugmentation
.getOvsdbNodeRef()
.getValue());
final Optional<Node> optionalDestinationOvsdbNode =
- UnimgrUtils.readNode(dataBroker,
+ MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
destinationUniAugmentation
.getOvsdbNodeRef()
// Retrieve the source and/or destination bridge
final InstanceIdentifier<Node> sourceBridgeIid =
UnimgrMapper.getOvsdbBridgeNodeIid(optionalSourceOvsdbNode.get());
- final Optional<Node> optionalSourceBr = UnimgrUtils.readNode(dataBroker,
+ final Optional<Node> optionalSourceBr = MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
sourceBridgeIid);
final InstanceIdentifier<Node> destinationBridgeIid =
UnimgrMapper.getOvsdbBridgeNodeIid(optionalDestinationOvsdbNode.get());
- final Optional<Node> optionalDestinationBr = UnimgrUtils.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
- UnimgrUtils.updateMaxRate(dataBroker, sourceUniAugmentation, destinationUniAugmentation, evc);
+ OvsdbUtils.updateMaxRate(dataBroker, sourceUniAugmentation, destinationUniAugmentation, evc);
Node sourceBr = null;
Node destinationBr = null;
if (optionalSourceBr.isPresent() && optionalDestinationBr.isPresent()) {
// Creating termination points (OVSDB CONFIG
// datastore)
- UnimgrUtils.createTerminationPointNode(dataBroker,
+ OvsdbUtils.createTerminationPointNode(dataBroker,
uniSource.getAugmentation(UniAugmentation.class),
sourceBr,
UnimgrConstants.DEFAULT_BRIDGE_NAME,
UnimgrConstants.DEFAULT_TUNNEL_IFACE);
// Create GRE tunnel (OVSDB CONFIG datastore)
- UnimgrUtils.createGreTunnel(dataBroker,
+ OvsdbUtils.createGreTunnel(dataBroker,
uniSource.getAugmentation(UniAugmentation.class),
uniDestination.getAugmentation(UniAugmentation.class),
sourceBr,
UnimgrConstants.DEFAULT_GRE_TUNNEL_NAME);
// Create termination points (CONFIG datastore)
- UnimgrUtils.createTerminationPointNode(dataBroker,
+ OvsdbUtils.createTerminationPointNode(dataBroker,
uniSource.getAugmentation(UniAugmentation.class),
destinationBr,
UnimgrConstants.DEFAULT_BRIDGE_NAME,
UnimgrConstants.DEFAULT_TUNNEL_IFACE);
// Create GRE tunnel (OVSDB CONFIG datastore)
- UnimgrUtils.createGreTunnel(dataBroker,
+ OvsdbUtils.createGreTunnel(dataBroker,
uniDestination.getAugmentation(UniAugmentation.class),
uniSource.getAugmentation(UniAugmentation.class), destinationBr,
UnimgrConstants.DEFAULT_BRIDGE_NAME,
UnimgrConstants.DEFAULT_GRE_TUNNEL_NAME);
// Update EVC
- UnimgrUtils.updateEvcNode(LogicalDatastoreType.CONFIGURATION,
+ EvcUtils.updateEvcNode(LogicalDatastoreType.CONFIGURATION,
evcKey,
evc,
sourceUniIid,
destinationUniIid,
dataBroker);
- UnimgrUtils.updateEvcNode(LogicalDatastoreType.OPERATIONAL,
+ EvcUtils.updateEvcNode(LogicalDatastoreType.OPERATIONAL,
evcKey,
evc,
sourceUniIid,
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.impl.UnimgrUtils;
+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;
*/
if (uni.getOvsdbNodeRef() != null) {
final OvsdbNodeRef ovsdbNodeRef = uni.getOvsdbNodeRef();
- final Optional<Node> optionalNode = UnimgrUtils.readNode(dataBroker,
+ 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 = UnimgrUtils.findOvsdbNode(dataBroker,
+ final Optional<Node> optionalOvsdbNode = OvsdbUtils.findOvsdbNode(dataBroker,
uni);
Node ovsdbNode;
if (optionalOvsdbNode.isPresent()) {
LOG.info("Retrieved the OVSDB node {}", ovsdbNode.getNodeId());
// Update QoS entries to ovsdb if speed is configured to UNI node
if (uni.getSpeed() != null) {
- UnimgrUtils.createQoSForOvsdbNode(dataBroker, uni);
+ OvsdbUtils.createQoSForOvsdbNode(dataBroker, uni);
}
- UnimgrUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
+ UniUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
uniKey,
uni,
ovsdbNode,
dataBroker);
} else {
- ovsdbNode = UnimgrUtils.createOvsdbNode(dataBroker,
+ ovsdbNode = OvsdbUtils.createOvsdbNode(dataBroker,
uni);
LOG.info("Could not retrieve the OVSDB node,"
+ " created a new one: {}", ovsdbNode.getNodeId());
- UnimgrUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
+ UniUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
uniKey,
uni,
ovsdbNode,
} else {
// We assume the ovs is in passive mode
// Check if the ovsdb node exist
- final Optional<Node> optionalOvsdbNode = UnimgrUtils.findOvsdbNode(dataBroker,
+ final Optional<Node> optionalOvsdbNode = OvsdbUtils.findOvsdbNode(dataBroker,
uni);
Node ovsdbNode;
if (optionalOvsdbNode.isPresent()) {
LOG.info("Retrieved the OVSDB node");
// Update QoS entries to ovsdb if speed is configured to UNI node
if (uni.getSpeed() != null) {
- UnimgrUtils.createQoSForOvsdbNode(dataBroker, uni);
+ OvsdbUtils.createQoSForOvsdbNode(dataBroker, uni);
}
- UnimgrUtils.createBridgeNode(dataBroker,
+ OvsdbUtils.createBridgeNode(dataBroker,
ovsdbIid,
uni,
UnimgrConstants.DEFAULT_BRIDGE_NAME);
- UnimgrUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
+ UniUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
uniKey,
uni,
ovsdbNode,
dataBroker);
- UnimgrUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL, uniKey, uni, ovsdbNode, dataBroker);
+ UniUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL, uniKey, uni, ovsdbNode, dataBroker);
} else {
- ovsdbNode = UnimgrUtils.createOvsdbNode(dataBroker,
+ ovsdbNode = OvsdbUtils.createOvsdbNode(dataBroker,
uni);
if (ovsdbNode != null) {
LOG.info("Could not retrieve the OVSDB node,"
+ "created a new one: {}", ovsdbNode.getNodeId());
- UnimgrUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
+ UniUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
uniKey,
uni,
ovsdbNode,
.getRemoteIp()
.getIpv4Address()
.getValue());
- final List<Node> uniNodes = UnimgrUtils.getUniNodes(dataBroker);
+ final List<Node> uniNodes = UniUtils.getUniNodes(dataBroker);
if (uniNodes != null && !uniNodes.isEmpty()) {
for (final Node uniNode: uniNodes) {
final UniAugmentation uniAugmentation = uniNode.getAugmentation(UniAugmentation.class);
.getValue()
.firstIdentifierOf(Node.class);
if (ovsdbNodeRefIid.equals(ovsdbIid)) {
- final Optional<Node> optionalOvsdbNode = UnimgrUtils.readNode(dataBroker,
+ final Optional<Node> optionalOvsdbNode = MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
ovsdbIid);
if (optionalOvsdbNode.isPresent()) {
LogicalDatastoreType.CONFIGURATION);
// Update QoS entries to ovsdb if speed is configured to UNI node
if (uniAugmentation.getSpeed() != null) {
- UnimgrUtils.createQoSForOvsdbNode(dataBroker, uniAugmentation);
+ OvsdbUtils.createQoSForOvsdbNode(dataBroker, uniAugmentation);
}
- UnimgrUtils.createBridgeNode(dataBroker,
+ OvsdbUtils.createBridgeNode(dataBroker,
ovsdbIid,
uniAugmentation,
UnimgrConstants.DEFAULT_BRIDGE_NAME);
- UnimgrUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL,
+ UniUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL,
uniIid,
uniAugmentation,
ovsdbIid,
final InstanceIdentifier<Node> uniIid = UnimgrMapper.getUniIid(dataBroker,
uniAugmentation.getIpAddress(),
LogicalDatastoreType.CONFIGURATION);
- UnimgrUtils.createBridgeNode(dataBroker,
+ OvsdbUtils.createBridgeNode(dataBroker,
ovsdbIid,
uniAugmentation,
UnimgrConstants.DEFAULT_BRIDGE_NAME);
- UnimgrUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL,
+ UniUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL,
uniIid,
uniAugmentation,
ovsdbIid,
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.impl.UnimgrUtils;
+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.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;
@Override
public void execute() {
- Set<InstanceIdentifier<UniAugmentation>> removedUnis = UnimgrUtils.extractRemoved(changes,
+ Set<InstanceIdentifier<UniAugmentation>> removedUnis = OvsdbUtils.extractRemoved(changes,
UniAugmentation.class);
if (!removedUnis.isEmpty()) {
for (InstanceIdentifier<UniAugmentation> removedUniIid: removedUnis) {
- UniAugmentation uniAugmentation = UnimgrUtils.read(dataBroker,
+ 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 = UnimgrUtils.readNode(dataBroker,
+ Optional<Node> optionalNode = MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
ovsdbNodeIid);
if (optionalNode.isPresent()) {
LOG.info("Delete bride node");
Node ovsdbNode = optionalNode.get();
InstanceIdentifier<Node> bridgeIid = UnimgrMapper.getOvsdbBridgeNodeIid(ovsdbNode);
- Optional<Node> optBridgeNode = UnimgrUtils.readNode(dataBroker, bridgeIid);
+ Optional<Node> optBridgeNode = MdsalUtils.readNode(dataBroker, bridgeIid);
if (optBridgeNode.isPresent()) {
Node bridgeNode = optBridgeNode.get();
InstanceIdentifier<TerminationPoint> iidTermPoint = UnimgrMapper.getTerminationPointIid(bridgeNode,
UnimgrConstants.DEFAULT_BRIDGE_NAME);
- UnimgrUtils.deleteNode(dataBroker, iidTermPoint, LogicalDatastoreType.CONFIGURATION);
+ MdsalUtils.deleteNode(dataBroker, iidTermPoint, LogicalDatastoreType.CONFIGURATION);
}
- UnimgrUtils.deleteNode(dataBroker, bridgeIid, LogicalDatastoreType.CONFIGURATION);
+ MdsalUtils.deleteNode(dataBroker, bridgeIid, LogicalDatastoreType.CONFIGURATION);
}
InstanceIdentifier<Node> iidUni = UnimgrMapper.getUniIid(dataBroker, uniAugmentation.getIpAddress(),
LogicalDatastoreType.OPERATIONAL);
if (iidUni != null)
- UnimgrUtils.deleteNode(dataBroker, iidUni, LogicalDatastoreType.OPERATIONAL);
+ MdsalUtils.deleteNode(dataBroker, iidUni, LogicalDatastoreType.OPERATIONAL);
}
else {
LOG.info("Received Uni Augmentation is null", removedUniIid);
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.unimgr.impl.UnimgrMapper;
-import org.opendaylight.unimgr.impl.UnimgrUtils;
+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;
for (Entry<InstanceIdentifier<?>, DataObject> updated : changes.entrySet()) {
if (updated.getValue() != null && updated.getValue() instanceof UniAugmentation) {
final UniAugmentation updatedUni = (UniAugmentation) updated.getValue();
- final UniAugmentation formerUni = UnimgrUtils.getUni(dataBroker, LogicalDatastoreType.OPERATIONAL, updatedUni.getIpAddress());
+ final UniAugmentation formerUni = UniUtils.getUni(dataBroker, LogicalDatastoreType.OPERATIONAL, updatedUni.getIpAddress());
if (formerUni != null) {
String formerUniIp = formerUni.getIpAddress().getIpv4Address().getValue();
if (updatedUni.getOvsdbNodeRef() != null) {
LOG.info("OVSDB NODE ref retreive for updated UNI {}", updatedUni.getOvsdbNodeRef());
final OvsdbNodeRef ovsdbNodeRef = updatedUni.getOvsdbNodeRef();
- Optional<Node> optOvsdbNode = UnimgrUtils.readNode(dataBroker,LogicalDatastoreType.OPERATIONAL, ovsdbNodeRef.getValue());
+ 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) {
- UnimgrUtils.createQoSForOvsdbNode(dataBroker, updatedUni);
+ OvsdbUtils.createQoSForOvsdbNode(dataBroker, updatedUni);
}
- UnimgrUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
+ UniUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
updated.getKey(),
updatedUni,
ovsdbNode,
return;
}
} else {
- Optional<Node> optOvsdbNode = UnimgrUtils.findOvsdbNode(dataBroker, updatedUni);
+ 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) {
- UnimgrUtils.createQoSForOvsdbNode(dataBroker, updatedUni);
+ OvsdbUtils.createQoSForOvsdbNode(dataBroker, updatedUni);
}
- UnimgrUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
+ UniUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
updated.getKey(),
updatedUni,
ovsdbNode,
LOG.info("UNI {} updated", uniKey);
final InstanceIdentifier<?> uniIID = UnimgrMapper.getUniIid(dataBroker, updatedUni.getIpAddress(), LogicalDatastoreType.OPERATIONAL);
- UnimgrUtils.deleteNode(dataBroker, uniIID, LogicalDatastoreType.OPERATIONAL);
- UnimgrUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL, uniIID, updatedUni, ovsdbNode, dataBroker);
+ MdsalUtils.deleteNode(dataBroker, uniIID, LogicalDatastoreType.OPERATIONAL);
+ UniUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL, uniIID, updatedUni, ovsdbNode, dataBroker);
}
}
if (updated.getValue() != null
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+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.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntries;
*/
public static InstanceIdentifier<Node> getUniIid(DataBroker dataBroker,
IpAddress ip) {
- List<Node> uniNodes = UnimgrUtils.getUniNodes(dataBroker,
+ List<Node> uniNodes = UniUtils.getUniNodes(dataBroker,
LogicalDatastoreType.OPERATIONAL);
for (Node node : uniNodes) {
UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class);
public static InstanceIdentifier<Node> getUniIid(DataBroker dataBroker,
IpAddress ip,
LogicalDatastoreType store) {
- List<Node> uniNodes = UnimgrUtils.getUniNodes(dataBroker,
+ List<Node> uniNodes = UniUtils.getUniNodes(dataBroker,
store);
for (Node node : uniNodes) {
UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class);
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;
+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.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeRef;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.Evc;
if ((uniAug == null) || (uniAug.getIpAddress() == null) || (uniAug.getMacAddress() == null)) {
return false;
}
- return UnimgrUtils.createUniNode(dataBroker, uniAug);
+ return UniUtils.createUniNode(dataBroker, uniAug);
}
@Override
return false;
}
- return UnimgrUtils.deleteNode(dataBroker, iidUni, LogicalDatastoreType.CONFIGURATION);
+ return MdsalUtils.deleteNode(dataBroker, iidUni, LogicalDatastoreType.CONFIGURATION);
}
@Override
public List<UniAugmentation> listUnis(LogicalDatastoreType dataStoreType) {
- return UnimgrUtils.getUnis(dataBroker, dataStoreType);
+ return UniUtils.getUnis(dataBroker, dataStoreType);
}
@Override
public UniAugmentation getUni(IpAddress ipAddress) {
- return UnimgrUtils.getUni(dataBroker, LogicalDatastoreType.OPERATIONAL, ipAddress);
+ return UniUtils.getUni(dataBroker, LogicalDatastoreType.OPERATIONAL, ipAddress);
}
@Override
public boolean addEvc(EvcAugmentation evc) {
- if((evc == null) || evc.getUniDest().isEmpty() || evc.getUniSource().isEmpty()) {
- return false;
- } else {
- return UnimgrUtils.createEvc(dataBroker, evc);
- }
+ // TODO Auto-generated method stub
+ return false;
}
@Override
UniDest uniDest) {
final InstanceIdentifier<?> sourceUniIid = uniSource.getUni();
final InstanceIdentifier<?> destinationUniIid = uniDest.getUni();
- return UnimgrUtils.updateEvcNode(LogicalDatastoreType.CONFIGURATION, evcKey, evc, sourceUniIid,
+ return EvcUtils.updateEvcNode(LogicalDatastoreType.CONFIGURATION, evcKey, evc, sourceUniIid,
destinationUniIid, dataBroker);
}
Node ovsdbNode;
if (uni.getOvsdbNodeRef() != null) {
final OvsdbNodeRef ovsdbNodeRef = uni.getOvsdbNodeRef();
- ovsdbNode= UnimgrUtils.readNode(dataBroker,
+ ovsdbNode= MdsalUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL, ovsdbNodeRef.getValue()).get();
- UnimgrUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL, uniIID, uni, ovsdbNode, dataBroker);
+ UniUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL, uniIID, uni, ovsdbNode, dataBroker);
LOG.trace("UNI updated {}.", uni.getIpAddress().getIpv4Address());
} else {
- final Optional<Node> optionalOvsdbNode = UnimgrUtils.findOvsdbNode(dataBroker, uni);
+ final Optional<Node> optionalOvsdbNode = OvsdbUtils.findOvsdbNode(dataBroker, uni);
ovsdbNode = optionalOvsdbNode.get();
}
- UnimgrUtils.deleteNode(dataBroker, uniIID, LogicalDatastoreType.OPERATIONAL);
- return (UnimgrUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION, uniIID,
- uni, ovsdbNode, dataBroker) && UnimgrUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL, uniIID,
+ MdsalUtils.deleteNode(dataBroker, uniIID, LogicalDatastoreType.OPERATIONAL);
+ return (UniUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION, uniIID,
+ uni, ovsdbNode, dataBroker) && UniUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL, uniIID,
uni, ovsdbNode, dataBroker));
}
return false;
--- /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.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+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.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+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.ovsdb.node.attributes.ManagedNodeEntry;
+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.EvcAugmentationBuilder;
+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.evc.UniDest;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDestBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDestKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSource;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSourceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSourceKey;
+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.topology.Link;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Optional;
+
+public class EvcUtils {
+
+ 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) {
+ if (optionalUni.isPresent()) {
+ final UniAugmentation uniAugmentation =
+ optionalUni
+ .get()
+ .getAugmentation(UniAugmentation.class);
+ final InstanceIdentifier<Node> ovsdbNodeIid =
+ uniAugmentation
+ .getOvsdbNodeRef()
+ .getValue()
+ .firstIdentifierOf(Node.class);
+ final Optional<Node> optionalOvsdNode =
+ MdsalUtils.readNode(dataBroker,
+ LogicalDatastoreType.OPERATIONAL,
+ ovsdbNodeIid);
+ if (optionalOvsdNode.isPresent()) {
+ final Node ovsdbNode = optionalOvsdNode.get();
+ final OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
+ for (final ManagedNodeEntry managedNodeEntry: ovsdbNodeAugmentation.getManagedNodeEntry()) {
+ final InstanceIdentifier<Node> bridgeIid = managedNodeEntry
+ .getBridgeRef()
+ .getValue()
+ .firstIdentifierOf(Node.class);
+ final Optional<Node> optBridgeNode = MdsalUtils.readNode(dataBroker, bridgeIid);
+ if (optBridgeNode.isPresent()) {
+ final Node bridgeNode = optBridgeNode.get();
+ final InstanceIdentifier<TerminationPoint> iidGreTermPoint = UnimgrMapper.getTerminationPointIid(bridgeNode,
+ UnimgrConstants.DEFAULT_GRE_TUNNEL_NAME);
+ final InstanceIdentifier<TerminationPoint> iidEthTermPoint = UnimgrMapper.getTerminationPointIid(bridgeNode,
+ UnimgrConstants.DEFAULT_TUNNEL_IFACE);
+ MdsalUtils.deleteNode(dataBroker, iidGreTermPoint, LogicalDatastoreType.CONFIGURATION);
+ MdsalUtils.deleteNode(dataBroker, iidEthTermPoint, LogicalDatastoreType.CONFIGURATION);
+ }
+ }
+ }
+ } else {
+ LOG.info("Unable to retrieve UNI from the EVC.");
+ }
+ }
+
+ /**
+ * Retrieve the list of links in the Operational DataStore
+ * @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) {
+ final List<Link> evcLinks = new ArrayList<>();
+ final InstanceIdentifier<Topology> evcTopology = UnimgrMapper.getEvcTopologyIid();
+ final Topology topology = MdsalUtils.read(dataBroker,
+ LogicalDatastoreType.OPERATIONAL,
+ evcTopology);
+ if ((topology != null) && (topology.getLink() != null)) {
+ for (final Link link : topology.getLink()) {
+ final EvcAugmentation evcAugmentation = link.getAugmentation(EvcAugmentation.class);
+ if (evcAugmentation != null) {
+ evcLinks.add(link);
+ }
+ }
+ }
+ return evcLinks;
+ }
+
+ /**
+ * Updates a specific EVC into a specific DataStore type
+ * @param dataStore The datastore type
+ * @param evcKey The EVC key
+ * @param evcAugmentation The EVC's data
+ * @param sourceUniIid The Source Uni Instance Identifier
+ * @param destinationUniIid The destination Uni Instance Identifier
+ * @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) {
+ 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 uniSource = new UniSourceBuilder()
+ .setOrder(sourceOrder)
+ .setKey(sourceKey)
+ .setIpAddress(sourceIp)
+ .setUni(sourceUniIid)
+ .build();
+ sourceList.add(uniSource);
+ 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 uniDest = new UniDestBuilder()
+ .setIpAddress(destIp)
+ .setOrder(destOrder)
+ .setKey(destKey)
+ .setUni(destinationUniIid)
+ .build();
+ destinationList.add(uniDest);
+ updatedEvcBuilder.setUniDest(destinationList);
+ final Optional<Link> optionalEvcLink = MdsalUtils.readLink(dataBroker,
+ LogicalDatastoreType.CONFIGURATION,
+ evcKey);
+ if (optionalEvcLink.isPresent()) {
+ final Link link = optionalEvcLink.get();
+ final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
+ final LinkBuilder linkBuilder = new LinkBuilder();
+ linkBuilder.setKey(link.getKey());
+ linkBuilder.setLinkId(link.getLinkId());
+ linkBuilder.setDestination(link.getDestination());
+ linkBuilder.setSource(link.getSource());
+ linkBuilder.addAugmentation(EvcAugmentation.class, updatedEvcBuilder.build());
+ transaction.put(dataStore, evcKey.firstIdentifierOf(Link.class), linkBuilder.build());
+ transaction.submit();
+ return true;
+ } else {
+ LOG.info("EvcLink is not present: " + optionalEvcLink.get().getKey());
+ }
+ } else {
+ LOG.info("Invalid instance identifiers for sourceUni and destUni.");
+ }
+ return false;
+ }
+}
--- /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.utils;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+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;
+import com.google.common.util.concurrent.CheckedFuture;
+
+public class MdsalUtils {
+
+ private static final Logger LOG = LoggerFactory.getLogger(MdsalUtils.class);
+
+ private MdsalUtils() {
+ throw new AssertionError("Instantiating utility class.");
+ }
+
+ /**
+ * Read a specific datastore type and return a DataObject as a casted
+ * class type Object.
+ * @param dataBroker The dataBroker instance to create transactions
+ * @param store The store type to query
+ * @param path The generic path to query
+ * @return The DataObject as a casted Object
+ */
+ public static <D extends org.opendaylight.yangtools.yang.binding.DataObject> D read(
+ DataBroker dataBroker,
+ final LogicalDatastoreType store,
+ final InstanceIdentifier<D> path) {
+ D result = null;
+ final ReadOnlyTransaction transaction = dataBroker.newReadOnlyTransaction();
+ Optional<D> optionalDataObject;
+ final CheckedFuture<Optional<D>, ReadFailedException> future = transaction.read(store, path);
+ try {
+ optionalDataObject = future.checkedGet();
+ if (optionalDataObject.isPresent()) {
+ result = optionalDataObject.get();
+ } else {
+ LOG.debug("{}: Failed to read {}",
+ Thread.currentThread().getStackTrace()[1], path);
+ }
+ } catch (final ReadFailedException e) {
+ LOG.warn("Failed to read {} ", path, e);
+ }
+ transaction.close();
+ return result;
+ }
+
+ /**
+ * Read a specific node from the Operational Data store by default.
+ * @param dataBroker The dataBroker instance to create transactions
+ * @param genericNode The Instance Identifier of the Node
+ * @return The Optional Node instance
+ */
+ public static final Optional<Node> readNode(DataBroker dataBroker,
+ InstanceIdentifier<?> genericNode) {
+ final ReadTransaction read = dataBroker.newReadOnlyTransaction();
+ final InstanceIdentifier<Node> nodeIid = genericNode.firstIdentifierOf(Node.class);
+ final CheckedFuture<Optional<Node>, ReadFailedException> nodeFuture =
+ read.read(LogicalDatastoreType.OPERATIONAL,
+ nodeIid);
+ try {
+ return nodeFuture.checkedGet();
+ } catch (final ReadFailedException e) {
+ LOG.info("Unable to read node with Iid {}", nodeIid);
+ }
+ return Optional.absent();
+ }
+
+ /**
+ * Generic function to delete a node on a specific dataStore
+ * @param dataBroker The instance of the data broker to create transactions.
+ * @param genericNode The instance identifier of a generic node
+ * @param store The dataStore where to send and submit the delete call.
+ */
+ public static boolean deleteNode(DataBroker dataBroker,
+ InstanceIdentifier<?> genericNode,
+ LogicalDatastoreType store) {
+ LOG.info("Received a request to delete node {}", genericNode);
+ boolean result = false;
+ final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
+ transaction.delete(store, genericNode);
+ try {
+ transaction.submit().checkedGet();
+ result = true;
+ } catch (final TransactionCommitFailedException e) {
+ LOG.error("Unable to remove node with Iid {} from store {}.", genericNode, store);
+ }
+ return result;
+ }
+
+ /**
+ * Read a specific Link from a specific datastore
+ * @param dataBroker The dataBroker instance to create transactions
+ * @param store The datastore type.
+ * @param genericNode The Instance Identifier of the Link
+ * @return An Optional Link instance
+ */
+ public static final Optional<Link> readLink(DataBroker dataBroker,
+ LogicalDatastoreType store,
+ InstanceIdentifier<?> genericNode) {
+ final ReadTransaction read = dataBroker.newReadOnlyTransaction();
+ final InstanceIdentifier<Link> linkIid = genericNode.firstIdentifierOf(Link.class);
+ final CheckedFuture<Optional<Link>, ReadFailedException> linkFuture = read.read(store, linkIid);
+ try {
+ return linkFuture.checkedGet();
+ } catch (final ReadFailedException e) {
+ LOG.info("Unable to read node with Iid {}", linkIid);
+ }
+ return Optional.absent();
+ }
+
+ /**
+ * Read a specific node from a specific data store type.
+ * @param dataBroker The dataBroker instance to create transactions
+ * @param store The data store type
+ * @param genericNode The Instance Identifier of a specific Node
+ * @return An Optional Node instance
+ */
+ public static final Optional<Node> readNode(DataBroker dataBroker,
+ LogicalDatastoreType store,
+ InstanceIdentifier<?> genericNode) {
+ final ReadTransaction read = dataBroker.newReadOnlyTransaction();
+ final InstanceIdentifier<Node> nodeIid = genericNode.firstIdentifierOf(Node.class);
+ final CheckedFuture<Optional<Node>, ReadFailedException> nodeFuture = read
+ .read(store, nodeIid);
+ try {
+ return nodeFuture.checkedGet();
+ } catch (final ReadFailedException e) {
+ LOG.info("Unable to read node with Iid {}", nodeIid);
+ }
+ return Optional.absent();
+ }
+}
* 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;
+
+package org.opendaylight.unimgr.utils;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.UUID;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.ovsdb.southbound.SouthboundConstants;
import org.opendaylight.ovsdb.southbound.SouthboundMapper;
+import org.opendaylight.unimgr.impl.UnimgrConstants;
+import org.opendaylight.unimgr.impl.UnimgrMapper;
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.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntryBuilder;
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.ConnectionInfoBuilder;
-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.QosEntries;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntriesBuilder;
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.port._interface.attributes.OptionsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.OptionsKey;
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.EvcAugmentationBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.Uni;
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.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDest;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDestBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDestKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSource;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSourceBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSourceKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.Speed;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed100M;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10G;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10M;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed1G;
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.Link;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkBuilder;
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 com.google.common.collect.Lists;
import com.google.common.util.concurrent.CheckedFuture;
-public class UnimgrUtils {
+public class OvsdbUtils {
+
+ private static final Logger LOG = LoggerFactory.getLogger(OvsdbUtils.class);
- private static final Logger LOG = LoggerFactory.getLogger(UnimgrUtils.class);
+ private OvsdbUtils() {
+ throw new AssertionError("Instantiating utility class.");
+ }
/**
* Creates and submit a Bridge Node to the Configuration Data Store.
* @param bridgeName The bridge name (example: br0)
*/
public static void createBridgeNode(DataBroker dataBroker,
- Node ovsdbNode,
- UniAugmentation uni,
- String bridgeName) {
+ Node ovsdbNode,
+ UniAugmentation uni,
+ String bridgeName) {
LOG.info("Creating a bridge on node {}", ovsdbNode.getNodeId().getValue());
final InstanceIdentifier<Node> ovsdbNodeIid = uni.getOvsdbNodeRef().getValue().firstIdentifierOf(Node.class);
if (ovsdbNodeIid != null) {
final NodeBuilder bridgeNodeBuilder = new NodeBuilder();
final InstanceIdentifier<Node> bridgeIid = UnimgrMapper.createOvsdbBridgeNodeIid(ovsdbNode,
- bridgeName);
+ bridgeName);
final NodeId bridgeNodeId = new NodeId(ovsdbNode.getNodeId()
- + UnimgrConstants.DEFAULT_BRIDGE_NODE_ID_SUFFIX
- + bridgeName);
+ + UnimgrConstants.DEFAULT_BRIDGE_NODE_ID_SUFFIX
+ + bridgeName);
bridgeNodeBuilder.setNodeId(bridgeNodeId);
final OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder();
ovsdbBridgeAugmentationBuilder.setBridgeName(new OvsdbBridgeName(bridgeName));
- ovsdbBridgeAugmentationBuilder.setProtocolEntry(UnimgrUtils.createMdsalProtocols());
+ ovsdbBridgeAugmentationBuilder.setProtocolEntry(OvsdbUtils.createMdsalProtocols());
final OvsdbNodeRef ovsdbNodeRef = new OvsdbNodeRef(ovsdbNodeIid);
ovsdbBridgeAugmentationBuilder.setManagedBy(ovsdbNodeRef);
bridgeNodeBuilder.addAugmentation(OvsdbBridgeAugmentation.class, ovsdbBridgeAugmentationBuilder.build());
* @param bridgeName The bridge name (example: br0)
*/
public static void createBridgeNode(DataBroker dataBroker,
- InstanceIdentifier<Node> ovsdbNodeIid,
- UniAugmentation uni,
- String bridgeName) {
+ InstanceIdentifier<Node> ovsdbNodeIid,
+ UniAugmentation uni,
+ String bridgeName) {
LOG.info("Creating a bridge on node {}", ovsdbNodeIid);
if (ovsdbNodeIid != null) {
final NodeBuilder bridgeNodeBuilder = new NodeBuilder();
- final Optional<Node> optionalOvsdbNode = UnimgrUtils.readNode(dataBroker,
- LogicalDatastoreType.OPERATIONAL,
- ovsdbNodeIid);
+ final Optional<Node> optionalOvsdbNode = MdsalUtils.readNode(dataBroker,
+ LogicalDatastoreType.OPERATIONAL,
+ ovsdbNodeIid);
if (optionalOvsdbNode.isPresent()) {
final Node ovsdbNode = optionalOvsdbNode.get();
final InstanceIdentifier<Node> bridgeIid = UnimgrMapper.createOvsdbBridgeNodeIid(ovsdbNode,
- bridgeName);
+ bridgeName);
final NodeId bridgeNodeId = new NodeId(ovsdbNode.getNodeId().getValue()
- + UnimgrConstants.DEFAULT_BRIDGE_NODE_ID_SUFFIX
- + bridgeName);
+ + UnimgrConstants.DEFAULT_BRIDGE_NODE_ID_SUFFIX
+ + bridgeName);
bridgeNodeBuilder.setNodeId(bridgeNodeId);
final OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder();
ovsdbBridgeAugmentationBuilder.setBridgeName(new OvsdbBridgeName(bridgeName));
- ovsdbBridgeAugmentationBuilder.setProtocolEntry(UnimgrUtils.createMdsalProtocols());
+ ovsdbBridgeAugmentationBuilder.setProtocolEntry(OvsdbUtils.createMdsalProtocols());
final OvsdbNodeRef ovsdbNodeRef = new OvsdbNodeRef(ovsdbNodeIid);
ovsdbBridgeAugmentationBuilder.setManagedBy(ovsdbNodeRef);
bridgeNodeBuilder.addAugmentation(OvsdbBridgeAugmentation.class,
- ovsdbBridgeAugmentationBuilder.build());
+ ovsdbBridgeAugmentationBuilder.build());
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
transaction.put(LogicalDatastoreType.CONFIGURATION,
- bridgeIid,
- bridgeNodeBuilder.build());
+ bridgeIid,
+ bridgeNodeBuilder.build());
transaction.submit();
}
} else {
* @param portName The Port Name (example: eth0)
*/
public static void createGreTunnel(DataBroker dataBroker,
- Uni source,
- Uni destination,
- Node bridgeNode,
- String bridgeName,
- String portName) {
+ Uni source,
+ Uni destination,
+ Node bridgeNode,
+ String bridgeName,
+ String portName) {
final InstanceIdentifier<TerminationPoint> tpIid =
- UnimgrMapper.getTerminationPointIid(bridgeNode,
- portName);
+ UnimgrMapper.getTerminationPointIid(bridgeNode,
+ portName);
final OvsdbTerminationPointAugmentationBuilder tpAugmentationBuilder =
- new OvsdbTerminationPointAugmentationBuilder();
+ new OvsdbTerminationPointAugmentationBuilder();
tpAugmentationBuilder.setName(portName);
final ArrayList<Options> options = Lists.newArrayList();
final OptionsKey optionKey = new OptionsKey("remote_ip");
final Options destinationIp = new OptionsBuilder()
- .setOption(destination.getIpAddress().getIpv4Address().getValue())
- .setKey(optionKey).setValue(destination.getIpAddress().getIpv4Address().getValue())
- .build();
+ .setOption(destination.getIpAddress().getIpv4Address().getValue())
+ .setKey(optionKey).setValue(destination.getIpAddress().getIpv4Address().getValue())
+ .build();
options.add(destinationIp);
tpAugmentationBuilder.setOptions(options);
tpAugmentationBuilder.setInterfaceType(SouthboundConstants.OVSDB_INTERFACE_TYPE_MAP.get("gre"));
tpBuilder.addAugmentation(OvsdbTerminationPointAugmentation.class, tpAugmentationBuilder.build());
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
transaction.put(LogicalDatastoreType.CONFIGURATION,
- tpIid,
- tpBuilder.build());
+ tpIid,
+ tpBuilder.build());
transaction.submit();
}
if ((ovsdbNodeRef != null) && (ovsdbNodeRef.getValue() != null)) {
final UUID bridgeUuid = UUID.randomUUID();
final OvsdbBridgeAugmentation ovsdbBridge = new OvsdbBridgeAugmentationBuilder()
- .setBridgeName(
- new OvsdbBridgeName(UnimgrConstants.DEFAULT_BRIDGE_NAME))
- .setManagedBy(ovsdbNodeRef)
- .setBridgeUuid(
- new Uuid(bridgeUuid.toString()))
- .build();
+ .setBridgeName(
+ new OvsdbBridgeName(UnimgrConstants.DEFAULT_BRIDGE_NAME))
+ .setManagedBy(ovsdbNodeRef)
+ .setBridgeUuid(
+ new Uuid(bridgeUuid.toString()))
+ .build();
return ovsdbBridge;
} else {
throw new Exception("Ovsdb Node Reference does not exist !");
* @param uni The UNI's data
*/
public static void createOvsdbNode(DataBroker dataBroker,
- NodeId ovsdbNodeId,
- Uni uni) {
+ NodeId ovsdbNodeId,
+ Uni uni) {
final InstanceIdentifier<Node> ovsdbNodeIid = UnimgrMapper.getOvsdbNodeIid(uni.getIpAddress());
try {
final NodeKey ovsdbNodeKey = new NodeKey(ovsdbNodeId);
final Node nodeData = new NodeBuilder()
- .setNodeId(ovsdbNodeId)
- .setKey(ovsdbNodeKey)
- .addAugmentation(OvsdbNodeAugmentation.class,
- UnimgrUtils.createOvsdbNodeAugmentation(uni))
- .build();
+ .setNodeId(ovsdbNodeId)
+ .setKey(ovsdbNodeKey)
+ .addAugmentation(OvsdbNodeAugmentation.class,
+ OvsdbUtils.createOvsdbNodeAugmentation(uni))
+ .build();
// Submit the node to the datastore
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
transaction.put(LogicalDatastoreType.CONFIGURATION, ovsdbNodeIid, nodeData);
* @return The instance of the Node
*/
public static Node createOvsdbNode(DataBroker dataBroker,
- UniAugmentation uni) {
+ UniAugmentation uni) {
final NodeId ovsdbNodeId = new NodeId(createOvsdbNodeId(uni.getIpAddress()));
try {
final InstanceIdentifier<Node> ovsdbNodeIid = UnimgrMapper.getOvsdbNodeIid(ovsdbNodeId);
final NodeKey ovsdbNodeKey = new NodeKey(ovsdbNodeId);
final Node nodeData = new NodeBuilder()
- .setNodeId(ovsdbNodeId)
- .setKey(ovsdbNodeKey)
- .addAugmentation(OvsdbNodeAugmentation.class,
- UnimgrUtils.createOvsdbNodeAugmentation(uni))
- .build();
+ .setNodeId(ovsdbNodeId)
+ .setKey(ovsdbNodeKey)
+ .addAugmentation(OvsdbNodeAugmentation.class,
+ OvsdbUtils.createOvsdbNodeAugmentation(uni))
+ .build();
// Submit the node to the datastore
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
transaction.put(LogicalDatastoreType.CONFIGURATION, ovsdbNodeIid, nodeData);
*/
public static OvsdbNodeAugmentation createOvsdbNodeAugmentation(Uni uni) {
final ConnectionInfo connectionInfos = new ConnectionInfoBuilder()
- .setRemoteIp(uni.getIpAddress())
- .setRemotePort(new PortNumber(UnimgrConstants.OVSDB_PORT))
- .build();
+ .setRemoteIp(uni.getIpAddress())
+ .setRemotePort(new PortNumber(UnimgrConstants.OVSDB_PORT))
+ .build();
final OvsdbNodeAugmentation ovsdbNode = new OvsdbNodeAugmentationBuilder()
- .setConnectionInfo(connectionInfos).build();
+ .setConnectionInfo(connectionInfos).build();
return ovsdbNode;
}
qOtherConfig = new QosOtherConfigBuilder()
.setKey(new QosOtherConfigKey(UnimgrConstants.QOS_MAX_RATE))
.setOtherConfigKey(UnimgrConstants.QOS_MAX_RATE)
- .setOtherConfigValue(getSpeed(uni.getSpeed().getSpeed()))
+ .setOtherConfigValue(UniUtils.getSpeed(uni.getSpeed().getSpeed()))
.build();
otherConfig.add(qOtherConfig);
queuesOtherConfig = new QueuesOtherConfigBuilder()
.setKey(new QueuesOtherConfigKey(UnimgrConstants.QOS_MAX_RATE))
.setQueueOtherConfigKey(UnimgrConstants.QOS_MAX_RATE)
- .setQueueOtherConfigValue(getSpeed(uni.getSpeed().getSpeed()))
+ .setQueueOtherConfigValue(UniUtils.getSpeed(uni.getSpeed().getSpeed()))
.build();
otherConfig.add(queuesOtherConfig);
return queuesList;
}
- private static String getSpeed(Speed speedObject) {
- String speed = null;
- if (speedObject instanceof Speed10M) {
- // map to 10MB
- speed = "10000000";
- }
- else if (speedObject instanceof Speed100M) {
- // map to 20MB
- speed = "20000000";
- }
- else if (speedObject instanceof Speed1G) {
- // map to 30MB
- speed = "30000000";
- }
- else if (speedObject instanceof Speed10G) {
- // map to 40MB
- speed = "40000000";
- }
- return speed;
- }
-
private static void updateQosEntries(DataBroker dataBroker, UniAugmentation uni) {
final Optional<Node> optionalNode = findOvsdbNode(dataBroker, uni);
if (optionalNode.isPresent()) {
UniAugmentation destinationUniAugmentation,
EvcAugmentation evc) {
Optional<Node> optionalNode;
- if (getSpeed(sourceUniAugmentation.getSpeed().getSpeed()).equals(getSpeed(evc.getIngressBw().getSpeed()))) {
+ if (UniUtils.getSpeed(sourceUniAugmentation.getSpeed().getSpeed())
+ .equals(UniUtils.getSpeed(evc.getIngressBw().getSpeed()))) {
LOG.info("Source UNI speed matches EVC ingress BW");
} else {
// update Uni's ovsdbNodeRef qos-entries and queues for max-rate to match EVC ingress BW
}
}
- if (getSpeed(destinationUniAugmentation.getSpeed().getSpeed()).equals(getSpeed(evc.getIngressBw().getSpeed()))) {
+ if (UniUtils.getSpeed(destinationUniAugmentation.getSpeed().getSpeed())
+ .equals(UniUtils.getSpeed(evc.getIngressBw().getSpeed()))) {
LOG.info("Destination UNI speed matches EVC ingress BW");
} else {
// update Uni's ovsdbNodeRef qos-entries and queues for max-rate to match EVC ingress BW
final QosOtherConfig qOtherConfig = new QosOtherConfigBuilder()
.setKey(new QosOtherConfigKey(UnimgrConstants.QOS_MAX_RATE))
.setOtherConfigKey(UnimgrConstants.QOS_MAX_RATE)
- .setOtherConfigValue(getSpeed(evc.getIngressBw().getSpeed()))
+ .setOtherConfigValue(UniUtils.getSpeed(evc.getIngressBw().getSpeed()))
.build();
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
transaction.put(LogicalDatastoreType.CONFIGURATION, qosOtherConfigIid, qOtherConfig, true);
final QueuesOtherConfig queuesOtherConfig = new QueuesOtherConfigBuilder()
.setKey(new QueuesOtherConfigKey(UnimgrConstants.QOS_MAX_RATE))
.setQueueOtherConfigKey(UnimgrConstants.QOS_MAX_RATE)
- .setQueueOtherConfigValue(getSpeed(evc.getIngressBw().getSpeed()))
+ .setQueueOtherConfigValue(UniUtils.getSpeed(evc.getIngressBw().getSpeed()))
.build();
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
transaction.put(LogicalDatastoreType.CONFIGURATION, queuesOtherConfigIid, queuesOtherConfig, true);
*/
public static NodeId createOvsdbNodeId(IpAddress ipAddress) {
final String nodeId = UnimgrConstants.OVSDB_PREFIX
- + ipAddress.getIpv4Address().getValue().toString()
- + ":"
- + UnimgrConstants.OVSDB_PORT;
+ + ipAddress.getIpv4Address().getValue().toString()
+ + ":"
+ + UnimgrConstants.OVSDB_PORT;
return new NodeId(nodeId);
}
// we will use nodeId to set interface port id
final VlanId vlanID = new VlanId(1);
final OvsdbTerminationPointAugmentation terminationPoint = new OvsdbTerminationPointAugmentationBuilder()
- .setName(UnimgrConstants.DEFAULT_INTERNAL_IFACE)
- .setVlanTag(vlanID)
- .setVlanMode(VlanMode.Access)
- .build();
+ .setName(UnimgrConstants.DEFAULT_INTERNAL_IFACE)
+ .setVlanTag(vlanID)
+ .setVlanMode(VlanMode.Access)
+ .build();
return terminationPoint;
}
- /**
- * Creates and submit an evc by using the Data contained in the EvcAugmentation
- * @param dataBroker The instance of the DataBroker to create transactions
- * @param evc The EVC's data
- * @return true if evc created
- */
- public static boolean createEvc(DataBroker dataBroker, EvcAugmentation evc) {
- return false;
- }
-
- /**
- * Creates and submit an UNI Node by using the Data contained in the UniAugmentation
- * @param dataBroker The instance of the DataBroker to create transactions
- * @param uni The UNI's data
- * @return true if uni created
- */
- public static boolean createUniNode(DataBroker dataBroker, UniAugmentation uni) {
- final NodeId uniNodeId = new NodeId(createUniNodeId(uni.getIpAddress()));
- boolean result = false;
- try {
- final InstanceIdentifier<Node> uniNodeIid = UnimgrMapper.getUniNodeIid(uniNodeId);
- final NodeKey uniNodeKey = new NodeKey(uniNodeId);
- final Node nodeData = new NodeBuilder()
- .setNodeId(uniNodeId)
- .setKey(uniNodeKey)
- .addAugmentation(UniAugmentation.class, uni)
- .build();
- final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
- transaction.put(LogicalDatastoreType.CONFIGURATION, uniNodeIid, nodeData);
- final CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
- future.checkedGet();
- result = true;
- LOG.info("Created and submitted a new Uni node {}", nodeData.getNodeId());
- } catch (final Exception e) {
- LOG.error("Exception while creating Uni Node" + "Uni Node Id: {}", uniNodeId);
- }
- return result;
- }
-
- /**
- * Creates an UNI node Id with an IP Address.
- * @param ipAddress The IP address of the UNI
- * @return A NodeId for a Specific UNI Node Id
- */
- public static NodeId createUniNodeId(IpAddress ipAddress) {
- return new NodeId(UnimgrConstants.UNI_PREFIX + ipAddress.getIpv4Address().getValue().toString());
- }
-
/**
* Creates and Submit a termination point Node to the configuration DateStore.
* @param dataBroker The instance of the data broker to create transactions
* to review the list of available Interface Types.
*/
public static void createTerminationPointNode(DataBroker dataBroker,
- Uni uni,
- Node bridgeNode,
- String bridgeName,
- String portName,
- String type) {
+ Uni uni,
+ Node bridgeNode,
+ String bridgeName,
+ String portName,
+ String type) {
final InstanceIdentifier<TerminationPoint> tpIid = UnimgrMapper
- .getTerminationPointIid(bridgeNode,
- portName);
+ .getTerminationPointIid(bridgeNode,
+ portName);
final OvsdbTerminationPointAugmentationBuilder tpAugmentationBuilder =
- new OvsdbTerminationPointAugmentationBuilder();
+ new OvsdbTerminationPointAugmentationBuilder();
tpAugmentationBuilder.setName(portName);
if (type != null) {
tpAugmentationBuilder.setInterfaceType(SouthboundConstants.OVSDB_INTERFACE_TYPE_MAP.get(type));
final TerminationPointBuilder tpBuilder = new TerminationPointBuilder();
tpBuilder.setKey(InstanceIdentifier.keyOf(tpIid));
tpBuilder.addAugmentation(OvsdbTerminationPointAugmentation.class,
- tpAugmentationBuilder.build());
+ tpAugmentationBuilder.build());
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
transaction.put(LogicalDatastoreType.CONFIGURATION,
- tpIid,
- tpBuilder.build());
+ tpIid,
+ tpBuilder.build());
transaction.submit();
}
* @param portName The Port name (example: eth0)
*/
public static void createTerminationPointNode(DataBroker dataBroker,
- Uni uni,
- Node bridgeNode,
- String bridgeName,
- String portName) {
+ Uni uni,
+ Node bridgeNode,
+ String bridgeName,
+ String portName) {
final InstanceIdentifier<TerminationPoint> tpIid = UnimgrMapper
- .getTerminationPointIid(bridgeNode,
- portName);
+ .getTerminationPointIid(bridgeNode,
+ portName);
final OvsdbTerminationPointAugmentationBuilder tpAugmentationBuilder =
- new OvsdbTerminationPointAugmentationBuilder();
+ new OvsdbTerminationPointAugmentationBuilder();
tpAugmentationBuilder.setName(portName);
tpAugmentationBuilder.setInterfaceType(null);
if (uni.getSpeed() != null) {
final TerminationPointBuilder tpBuilder = new TerminationPointBuilder();
tpBuilder.setKey(InstanceIdentifier.keyOf(tpIid));
tpBuilder.addAugmentation(OvsdbTerminationPointAugmentation.class,
- tpAugmentationBuilder.build());
+ tpAugmentationBuilder.build());
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
transaction.put(LogicalDatastoreType.CONFIGURATION,
- tpIid,
- tpBuilder.build());
+ tpIid,
+ tpBuilder.build());
transaction.submit();
}
private static Uuid getQosUuid(DataBroker dataBroker, Uni uni) {
Uuid qosUuid = null;
- final Optional<Node> optionalNode = findUniNode(dataBroker, uni.getIpAddress());
+ final Optional<Node> optionalNode = UniUtils.findUniNode(dataBroker, uni.getIpAddress());
if (optionalNode.isPresent()) {
final UniAugmentation uniAugmentation = optionalNode.get()
return result;
}
- public static void deleteEvcData(DataBroker dataBroker, Optional<Node> optionalUni) {
- if (optionalUni.isPresent()) {
- final UniAugmentation uniAugmentation =
- optionalUni
- .get()
- .getAugmentation(UniAugmentation.class);
- final InstanceIdentifier<Node> ovsdbNodeIid =
- uniAugmentation
- .getOvsdbNodeRef()
- .getValue()
- .firstIdentifierOf(Node.class);
- final Optional<Node> optionalOvsdNode =
- UnimgrUtils.readNode(dataBroker,
- LogicalDatastoreType.OPERATIONAL,
- ovsdbNodeIid);
- if (optionalOvsdNode.isPresent()) {
- final Node ovsdbNode = optionalOvsdNode.get();
- final OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
- for (final ManagedNodeEntry managedNodeEntry: ovsdbNodeAugmentation.getManagedNodeEntry()) {
- final InstanceIdentifier<Node> bridgeIid = managedNodeEntry
- .getBridgeRef()
- .getValue()
- .firstIdentifierOf(Node.class);
- final Optional<Node> optBridgeNode = UnimgrUtils.readNode(dataBroker, bridgeIid);
- if (optBridgeNode.isPresent()) {
- final Node bridgeNode = optBridgeNode.get();
- final InstanceIdentifier<TerminationPoint> iidGreTermPoint = UnimgrMapper.getTerminationPointIid(bridgeNode,
- UnimgrConstants.DEFAULT_GRE_TUNNEL_NAME);
- final InstanceIdentifier<TerminationPoint> iidEthTermPoint = UnimgrMapper.getTerminationPointIid(bridgeNode,
- UnimgrConstants.DEFAULT_TUNNEL_IFACE);
- UnimgrUtils.deleteNode(dataBroker, iidGreTermPoint, LogicalDatastoreType.CONFIGURATION);
- UnimgrUtils.deleteNode(dataBroker, iidEthTermPoint, LogicalDatastoreType.CONFIGURATION);
- }
- }
- }
- } else {
- LOG.info("Unable to retrieve UNI from the EVC.");
- }
- }
-
/**
* Deletes a termination Point from the configuration data store.
* @param dataBroker The instance of the data broker to create transactions
* @param ovsdbNode The ovsdb Node
* @return A checked Future
*/
- public static CheckedFuture<Void,
- TransactionCommitFailedException>
- deleteTerminationPoint(DataBroker dataBroker,
- TerminationPoint terminationPoint,
- Node ovsdbNode) {
+ public static CheckedFuture<Void, TransactionCommitFailedException> deleteTerminationPoint(DataBroker dataBroker,
+ TerminationPoint terminationPoint,
+ Node ovsdbNode) {
final InstanceIdentifier<TerminationPoint> terminationPointPath =
- InstanceIdentifier
- .create(NetworkTopology.class)
- .child(Topology.class,
- new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
- .child(Node.class,
- ovsdbNode.getKey())
- .child(TerminationPoint.class,
- terminationPoint.getKey());
+ InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class,
+ new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
+ .child(Node.class,
+ ovsdbNode.getKey())
+ .child(TerminationPoint.class,
+ terminationPoint.getKey());
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
transaction.delete(LogicalDatastoreType.CONFIGURATION, terminationPointPath);
transaction.delete(LogicalDatastoreType.OPERATIONAL, terminationPointPath);
return future;
}
- /**
- * Generic function to delete a node on a specific dataStore
- * @param dataBroker The instance of the data broker to create transactions.
- * @param genericNode The instance identifier of a generic node
- * @param store The dataStore where to send and submit the delete call.
- */
- public static boolean deleteNode(DataBroker dataBroker,
- InstanceIdentifier<?> genericNode,
- LogicalDatastoreType store) {
- LOG.info("Received a request to delete node {}", genericNode);
- boolean result = false;
- final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
- transaction.delete(store, genericNode);
- try {
- transaction.submit().checkedGet();
- result = true;
- } catch (final TransactionCommitFailedException e) {
- LOG.error("Unable to remove node with Iid {} from store {}.", genericNode, store);
- }
- return result;
- }
/**
* Extract a data object by using its instance indentifier and it's class type.
* @return The Optional OvsdbNode
*/
public static Optional<Node> findOvsdbNode(DataBroker dataBroker,
- UniAugmentation uni) {
+ UniAugmentation uni) {
final List<Node> ovsdbNodes = getOvsdbNodes(dataBroker);
Optional<Node> optionalOvsdb;
if (!ovsdbNodes.isEmpty()) {
for (final Node ovsdbNode : ovsdbNodes) {
final OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode
- .getAugmentation(OvsdbNodeAugmentation.class);
+ .getAugmentation(OvsdbNodeAugmentation.class);
if (ovsdbNodeAugmentation.getConnectionInfo()
- .getRemoteIp()
- .getIpv4Address()
+ .getRemoteIp()
+ .getIpv4Address()
.equals(uni.getIpAddress().getIpv4Address())) {
LOG.info("Found ovsdb node");
optionalOvsdb = Optional.of(ovsdbNode);
return Optional.absent();
}
- /**
- * Search the Operation DataStore for a specific UNI
- * @param dataBroker The dataBroker instance to create transactions
- * @param ipAddress The IP address of the UNI
- * @return An Optional UNI Node
- */
- public static Optional<Node> findUniNode(DataBroker dataBroker,
- IpAddress ipAddress) {
- final List<Node> uniNodes = getUniNodes(dataBroker);
- if (!uniNodes.isEmpty()) {
- for (final Node uniNode : uniNodes) {
- final UniAugmentation uniAugmentation = uniNode.getAugmentation(UniAugmentation.class);
- if (uniAugmentation.getIpAddress().equals(ipAddress)) {
- LOG.info("Found Uni node");
- return Optional.of(uniNode);
- }
- }
- }
- return Optional.absent();
- }
-
/**
* Retrieves the connection information from an Ovsdb Connection by
* using the Ovsdb Node Id
* @return The ConnectionInfo object
*/
public static ConnectionInfo getConnectionInfo(DataBroker dataBroker,
- NodeId ovsdbNodeId) {
+ NodeId ovsdbNodeId) {
final InstanceIdentifier<Node> nodeIid = UnimgrMapper.getOvsdbNodeIid(ovsdbNodeId);
- final Optional<Node> node = readNode(dataBroker,
- LogicalDatastoreType.OPERATIONAL,
- nodeIid);
+ final Optional<Node> node = MdsalUtils.readNode(dataBroker,
+ LogicalDatastoreType.OPERATIONAL,
+ nodeIid);
if (node.isPresent()) {
final Node ovsdbNode = node.get();
final OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode
- .getAugmentation(OvsdbNodeAugmentation.class);
+ .getAugmentation(OvsdbNodeAugmentation.class);
final ConnectionInfo connectionInfo = ovsdbNodeAugmentation.getConnectionInfo();
return connectionInfo;
} else {
}
}
- /**
- * Retrieve the list of links in the Operational DataStore
- * @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) {
- final List<Link> evcLinks = new ArrayList<>();
- final InstanceIdentifier<Topology> evcTopology = UnimgrMapper.getEvcTopologyIid();
- final Topology topology = UnimgrUtils.read(dataBroker,
- LogicalDatastoreType.OPERATIONAL,
- evcTopology);
- if ((topology != null) && (topology.getLink() != null)) {
- for (final Link link : topology.getLink()) {
- final EvcAugmentation evcAugmentation = link.getAugmentation(EvcAugmentation.class);
- if (evcAugmentation != null) {
- evcLinks.add(link);
- }
- }
- }
- return evcLinks;
- }
-
/**
* Retrieve the Local IP of the controller
* @return The LocalIp object of the Controller
public static List<Node> getOvsdbNodes(DataBroker dataBroker) {
final List<Node> ovsdbNodes = new ArrayList<>();
final InstanceIdentifier<Topology> ovsdbTopoIdentifier = UnimgrMapper.getOvsdbTopologyIid();
- final Topology topology = UnimgrUtils.read(dataBroker,
- LogicalDatastoreType.OPERATIONAL,
- ovsdbTopoIdentifier);
+ final Topology topology = MdsalUtils.read(dataBroker,
+ LogicalDatastoreType.OPERATIONAL,
+ ovsdbTopoIdentifier);
if ((topology != null) && (topology.getNode() != null)) {
for (final Node node : topology.getNode()) {
final OvsdbNodeAugmentation ovsdbNodeAugmentation = node.getAugmentation(OvsdbNodeAugmentation.class);
}
return ovsdbNodes;
}
-
- /**
- * Retrieve a list of Uni Nodes from the Configuration DataStore
- * @param dataBroker The dataBroker instance to create transactions
- * @return A list of Uni Nodes from the Config dataStore
- */
- public static List<Node> getUniNodes(DataBroker dataBroker) {
- final List<Node> uniNodes = new ArrayList<>();
- final InstanceIdentifier<Topology> topologyInstanceIdentifier = UnimgrMapper.getUniTopologyIid();
- final Topology topology = read(dataBroker,
- LogicalDatastoreType.CONFIGURATION,
- topologyInstanceIdentifier);
- if ((topology != null) && (topology.getNode() != null)) {
- for (final Node node : topology.getNode()) {
- final UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class);
- if (uniAugmentation != null) {
- uniNodes.add(node);
- }
- }
- }
- return uniNodes;
- }
-
- /**
- * Retrieve a list of Uni Nodes on a specific DataStore
- * @param dataBroker The dataBroker instance to create transactions
- * @param store The store to which to send the read request
- * @return A List of UNI Nodes.
- */
- public static List<Node> getUniNodes(DataBroker dataBroker,
- LogicalDatastoreType store) {
- final List<Node> uniNodes = new ArrayList<>();
- final InstanceIdentifier<Topology> topologyInstanceIdentifier = UnimgrMapper.getUniTopologyIid();
- final Topology topology = read(dataBroker,
- store,
- topologyInstanceIdentifier);
- if ((topology != null) && (topology.getNode() != null)) {
- for (final Node node : topology.getNode()) {
- final UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class);
- if (uniAugmentation != null) {
- uniNodes.add(node);
- }
- }
- }
- return uniNodes;
- }
-
- /**
- * Retrieve a list of Unis on a specific DataStore
- * @param dataBroker instance to create transactions
- * @param store to which send the read request
- * @return A List of Unis.
- */
- public static List<UniAugmentation> getUnis(DataBroker dataBroker,
- LogicalDatastoreType store) {
- final List<UniAugmentation> unis = new ArrayList<>();
- final InstanceIdentifier<Topology> topologyInstanceIdentifier = UnimgrMapper.getUniTopologyIid();
- final Topology topology = read(dataBroker,
- store,
- topologyInstanceIdentifier);
- if ((topology != null) && (topology.getNode() != null)) {
- for (final Node node : topology.getNode()) {
- final UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class);
- if (uniAugmentation != null) {
- unis.add(uniAugmentation);
- }
- }
- }
- return unis;
- }
-
- /**
- * Retrieve a list of Unis on a specific DataStore
- * @param dataBroker instance to create transactions
- * @param store to which send the read request
- * @param ipAddress of the required Uni
- * @return uni.
- */
- public static UniAugmentation getUni(DataBroker dataBroker,
- LogicalDatastoreType store, IpAddress ipAddress) {
- final InstanceIdentifier<Topology> topologyInstanceIdentifier = UnimgrMapper.getUniTopologyIid();
- final Topology topology = read(dataBroker,
- store,
- topologyInstanceIdentifier);
- if ((topology != null) && (topology.getNode() != null)) {
- for (final Node node : topology.getNode()) {
- final UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class);
- if ((uniAugmentation != null) && uniAugmentation.getIpAddress().getIpv4Address().getValue().equals(ipAddress.getIpv4Address().getValue())) {
- return uniAugmentation;
- }
- }
- }
- return null;
- }
-
- /**
- * Read a specific datastore type and return a DataObject as a casted
- * class type Object.
- * @param dataBroker The dataBroker instance to create transactions
- * @param store The store type to query
- * @param path The generic path to query
- * @return The DataObject as a casted Object
- */
- public static <D extends org.opendaylight.yangtools.yang.binding.DataObject> D read(
- DataBroker dataBroker,
- final LogicalDatastoreType store,
- final InstanceIdentifier<D> path) {
- D result = null;
- final ReadOnlyTransaction transaction = dataBroker.newReadOnlyTransaction();
- Optional<D> optionalDataObject;
- final CheckedFuture<Optional<D>, ReadFailedException> future = transaction.read(store, path);
- try {
- optionalDataObject = future.checkedGet();
- if (optionalDataObject.isPresent()) {
- result = optionalDataObject.get();
- } else {
- LOG.debug("{}: Failed to read {}",
- Thread.currentThread().getStackTrace()[1], path);
- }
- } catch (final ReadFailedException e) {
- LOG.warn("Failed to read {} ", path, e);
- }
- transaction.close();
- return result;
- }
-
- /**
- * Read a specific node from the Operational Data store by default.
- * @param dataBroker The dataBroker instance to create transactions
- * @param genericNode The Instance Identifier of the Node
- * @return The Optional Node instance
- */
- @Deprecated
- public static final Optional<Node> readNode(DataBroker dataBroker,
- InstanceIdentifier<?> genericNode) {
- final ReadTransaction read = dataBroker.newReadOnlyTransaction();
- final InstanceIdentifier<Node> nodeIid = genericNode.firstIdentifierOf(Node.class);
- final CheckedFuture<Optional<Node>, ReadFailedException> nodeFuture =
- read.read(LogicalDatastoreType.OPERATIONAL,
- nodeIid);
- try {
- return nodeFuture.checkedGet();
- } catch (final ReadFailedException e) {
- LOG.info("Unable to read node with Iid {}", nodeIid);
- }
- return Optional.absent();
- }
-
- /**
- * Read a specific Link from a specific datastore
- * @param dataBroker The dataBroker instance to create transactions
- * @param store The datastore type.
- * @param genericNode The Instance Identifier of the Link
- * @return An Optional Link instance
- */
- public static final Optional<Link> readLink(DataBroker dataBroker,
- LogicalDatastoreType store,
- InstanceIdentifier<?> genericNode) {
- final ReadTransaction read = dataBroker.newReadOnlyTransaction();
- final InstanceIdentifier<Link> linkIid = genericNode.firstIdentifierOf(Link.class);
- final CheckedFuture<Optional<Link>, ReadFailedException> linkFuture = read.read(store, linkIid);
- try {
- return linkFuture.checkedGet();
- } catch (final ReadFailedException e) {
- LOG.info("Unable to read node with Iid {}", linkIid);
- }
- return Optional.absent();
- }
-
- /**
- * Read a specific node from a specific data store type.
- * @param dataBroker The dataBroker instance to create transactions
- * @param store The data store type
- * @param genericNode The Instance Identifier of a specific Node
- * @return An Optional Node instance
- */
- public static final Optional<Node> readNode(DataBroker dataBroker,
- LogicalDatastoreType store,
- InstanceIdentifier<?> genericNode) {
- final ReadTransaction read = dataBroker.newReadOnlyTransaction();
- final InstanceIdentifier<Node> nodeIid = genericNode.firstIdentifierOf(Node.class);
- final CheckedFuture<Optional<Node>, ReadFailedException> nodeFuture = read
- .read(store, nodeIid);
- try {
- return nodeFuture.checkedGet();
- } catch (final ReadFailedException e) {
- LOG.info("Unable to read node with Iid {}", nodeIid);
- }
- return Optional.absent();
- }
-
- /**
- * Updates a specific Uni Node on a specific DataStore type
- * @param dataStore The datastore type
- * @param uniIID The UNI InstanceIdentifier
- * @param uni The Uni's data
- * @param ovsdbNode The Ovsdb Node
- * @param dataBroker The dataBroker instance to create transactions
- * @return true if uni is updated
- */
- public static boolean updateUniNode(LogicalDatastoreType dataStore,
- InstanceIdentifier<?> uniIID,
- UniAugmentation uni,
- Node ovsdbNode,
- DataBroker dataBroker) {
- final InstanceIdentifier<Node> ovsdbNodeIid = UnimgrMapper.getOvsdbNodeIid(ovsdbNode.getNodeId());
- final OvsdbNodeRef ovsdbNodeRef = new OvsdbNodeRef(ovsdbNodeIid);
- final UniAugmentationBuilder updatedUniBuilder = new UniAugmentationBuilder(uni);
- if (ovsdbNodeRef != null) {
- updatedUniBuilder.setOvsdbNodeRef(ovsdbNodeRef);
- }
- final Optional<Node> optionalNode = readNode(dataBroker,
- LogicalDatastoreType.CONFIGURATION,
- uniIID);
- if (optionalNode.isPresent()) {
- final Node node = optionalNode.get();
- final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
- final NodeBuilder nodeBuilder = new NodeBuilder();
- nodeBuilder.setKey(node.getKey());
- nodeBuilder.setNodeId(node.getNodeId());
- nodeBuilder.addAugmentation(UniAugmentation.class, updatedUniBuilder.build());
- transaction.put(dataStore, uniIID.firstIdentifierOf(Node.class), nodeBuilder.build());
- transaction.submit();
- return true;
- }
- return false;
- }
-
- /**
- * Update a specific UNI node on a specific datastore type
- * @param dataStore The datastore type
- * @param uniKey The UNI key
- * @param uni The Uni's data
- * @param ovsdbNodeIid The Ovsdb Node Instance Identifier
- * @param dataBroker The dataBroker instance to create transactions
- * @return true if uni is updated
- */
- public static boolean updateUniNode(LogicalDatastoreType dataStore,
- InstanceIdentifier<?> uniKey,
- UniAugmentation uni,
- InstanceIdentifier<?> ovsdbNodeIid,
- DataBroker dataBroker) {
- final OvsdbNodeRef ovsdbNodeRef = new OvsdbNodeRef(ovsdbNodeIid);
- final UniAugmentationBuilder updatedUniBuilder = new UniAugmentationBuilder(uni);
- if (ovsdbNodeRef != null) {
- updatedUniBuilder.setOvsdbNodeRef(ovsdbNodeRef);
- }
- final Optional<Node> optionalNode = readNode(dataBroker,
- LogicalDatastoreType.CONFIGURATION,
- uniKey);
- if (optionalNode.isPresent()) {
- final Node node = optionalNode.get();
- final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
- final NodeBuilder nodeBuilder = new NodeBuilder();
- nodeBuilder.setKey(node.getKey());
- nodeBuilder.setNodeId(node.getNodeId());
- nodeBuilder.addAugmentation(UniAugmentation.class, updatedUniBuilder.build());
- transaction.put(dataStore, uniKey.firstIdentifierOf(Node.class), nodeBuilder.build());
- transaction.submit();
- return true;
- }
- return false;
- }
-
- /**
- * Updates a specific EVC into a specific DataStore type
- * @param dataStore The datastore type
- * @param evcKey The EVC key
- * @param evcAugmentation The EVC's data
- * @param sourceUniIid The Source Uni Instance Identifier
- * @param destinationUniIid The destination Uni Instance Identifier
- * @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) {
- 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 uniSource = new UniSourceBuilder()
- .setOrder(sourceOrder)
- .setKey(sourceKey)
- .setIpAddress(sourceIp)
- .setUni(sourceUniIid)
- .build();
- sourceList.add(uniSource);
- 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 uniDest = new UniDestBuilder()
- .setIpAddress(destIp)
- .setOrder(destOrder)
- .setKey(destKey)
- .setUni(destinationUniIid)
- .build();
- destinationList.add(uniDest);
- updatedEvcBuilder.setUniDest(destinationList);
- final Optional<Link> optionalEvcLink = readLink(dataBroker,
- LogicalDatastoreType.CONFIGURATION,
- evcKey);
- if (optionalEvcLink.isPresent()) {
- final Link link = optionalEvcLink.get();
- final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
- final LinkBuilder linkBuilder = new LinkBuilder();
- linkBuilder.setKey(link.getKey());
- linkBuilder.setLinkId(link.getLinkId());
- linkBuilder.setDestination(link.getDestination());
- linkBuilder.setSource(link.getSource());
- linkBuilder.addAugmentation(EvcAugmentation.class, updatedEvcBuilder.build());
- transaction.put(dataStore, evcKey.firstIdentifierOf(Link.class), linkBuilder.build());
- transaction.submit();
- return true;
- } else {
- LOG.info("EvcLink is not present: " + optionalEvcLink.get().getKey());
- }
- } else {
- LOG.info("Invalid instance identifiers for sourceUni and destUni.");
- }
- return false;
- }
}
--- /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.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.unimgr.impl.UnimgrConstants;
+import org.opendaylight.unimgr.impl.UnimgrMapper;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+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.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.Speed;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed100M;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed100MBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10G;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10GBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10M;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10MBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed1G;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed1GBuilder;
+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.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.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+
+public class UniUtils {
+
+ private static final Logger LOG = LoggerFactory.getLogger(UniUtils.class);
+
+ private UniUtils() {
+ throw new AssertionError("Instantiating utility class.");
+ }
+
+ /**
+ * Creates and submit an UNI Node by using the Data contained in the UniAugmentation
+ * @param dataBroker The instance of the DataBroker to create transactions
+ * @param uni The UNI's data
+ * @return true if uni created
+ */
+ public static boolean createUniNode(DataBroker dataBroker, UniAugmentation uni) {
+ final NodeId uniNodeId = new NodeId(createUniNodeId(uni.getIpAddress()));
+ boolean result = false;
+ try {
+ final InstanceIdentifier<Node> uniNodeIid = UnimgrMapper.getUniNodeIid(uniNodeId);
+ final NodeKey uniNodeKey = new NodeKey(uniNodeId);
+ final Node nodeData = new NodeBuilder()
+ .setNodeId(uniNodeId)
+ .setKey(uniNodeKey)
+ .addAugmentation(UniAugmentation.class, uni)
+ .build();
+ final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
+ transaction.put(LogicalDatastoreType.CONFIGURATION, uniNodeIid, nodeData);
+ final CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
+ future.checkedGet();
+ result = true;
+ LOG.info("Created and submitted a new Uni node {}", nodeData.getNodeId());
+ } catch (final Exception e) {
+ LOG.error("Exception while creating Uni Node" + "Uni Node Id: {}", uniNodeId);
+ }
+ return result;
+ }
+
+ /**
+ * Creates an UNI node Id with an IP Address.
+ * @param ipAddress The IP address of the UNI
+ * @return A NodeId for a Specific UNI Node Id
+ */
+ public static NodeId createUniNodeId(IpAddress ipAddress) {
+ return new NodeId(UnimgrConstants.UNI_PREFIX + ipAddress.getIpv4Address().getValue().toString());
+ }
+
+ /**
+ * Search the Operation DataStore for a specific UNI
+ * @param dataBroker The dataBroker instance to create transactions
+ * @param ipAddress The IP address of the UNI
+ * @return An Optional UNI Node
+ */
+ public static Optional<Node> findUniNode(DataBroker dataBroker,
+ IpAddress ipAddress) {
+ final List<Node> uniNodes = getUniNodes(dataBroker);
+ if (!uniNodes.isEmpty()) {
+ for (final Node uniNode : uniNodes) {
+ final UniAugmentation uniAugmentation = uniNode.getAugmentation(UniAugmentation.class);
+ if (uniAugmentation.getIpAddress().equals(ipAddress)) {
+ LOG.info("Found Uni node");
+ return Optional.of(uniNode);
+ }
+ }
+ }
+ return Optional.absent();
+ }
+
+ /**
+ * Retrieve a list of Uni Nodes from the Configuration DataStore
+ * @param dataBroker The dataBroker instance to create transactions
+ * @return A list of Uni Nodes from the Config dataStore
+ */
+ public static List<Node> getUniNodes(DataBroker dataBroker) {
+ final List<Node> uniNodes = new ArrayList<>();
+ final InstanceIdentifier<Topology> topologyInstanceIdentifier = UnimgrMapper.getUniTopologyIid();
+ final Topology topology = MdsalUtils.read(dataBroker,
+ LogicalDatastoreType.CONFIGURATION,
+ topologyInstanceIdentifier);
+ if ((topology != null) && (topology.getNode() != null)) {
+ for (final Node node : topology.getNode()) {
+ final UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class);
+ if (uniAugmentation != null) {
+ uniNodes.add(node);
+ }
+ }
+ }
+ return uniNodes;
+ }
+
+ /**
+ * Retrieve a list of Uni Nodes on a specific DataStore
+ * @param dataBroker The dataBroker instance to create transactions
+ * @param store The store to which to send the read request
+ * @return A List of UNI Nodes.
+ */
+ public static List<Node> getUniNodes(DataBroker dataBroker,
+ LogicalDatastoreType store) {
+ final List<Node> uniNodes = new ArrayList<>();
+ final InstanceIdentifier<Topology> topologyInstanceIdentifier = UnimgrMapper.getUniTopologyIid();
+ final Topology topology = MdsalUtils.read(dataBroker,
+ store,
+ topologyInstanceIdentifier);
+ if ((topology != null) && (topology.getNode() != null)) {
+ for (final Node node : topology.getNode()) {
+ final UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class);
+ if (uniAugmentation != null) {
+ uniNodes.add(node);
+ }
+ }
+ }
+ return uniNodes;
+ }
+
+ /**
+ * Retrieve a list of Unis on a specific DataStore
+ * @param dataBroker instance to create transactions
+ * @param store to which send the read request
+ * @return A List of Unis.
+ */
+ public static List<UniAugmentation> getUnis(DataBroker dataBroker,
+ LogicalDatastoreType store) {
+ final List<UniAugmentation> unis = new ArrayList<>();
+ final InstanceIdentifier<Topology> topologyInstanceIdentifier = UnimgrMapper.getUniTopologyIid();
+ final Topology topology = MdsalUtils.read(dataBroker,
+ store,
+ topologyInstanceIdentifier);
+ if ((topology != null) && (topology.getNode() != null)) {
+ for (final Node node : topology.getNode()) {
+ final UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class);
+ if (uniAugmentation != null) {
+ unis.add(uniAugmentation);
+ }
+ }
+ }
+ return unis;
+ }
+
+ /**
+ * Retrieve a list of Unis on a specific DataStore
+ * @param dataBroker instance to create transactions
+ * @param store to which send the read request
+ * @param ipAddress of the required Uni
+ * @return uni.
+ */
+ public static UniAugmentation getUni(DataBroker dataBroker,
+ LogicalDatastoreType store, IpAddress ipAddress) {
+ final InstanceIdentifier<Topology> topologyInstanceIdentifier = UnimgrMapper.getUniTopologyIid();
+ final Topology topology = MdsalUtils.read(dataBroker,
+ store,
+ topologyInstanceIdentifier);
+ if ((topology != null) && (topology.getNode() != null)) {
+ for (final Node node : topology.getNode()) {
+ final UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class);
+ if ((uniAugmentation != null) && uniAugmentation.getIpAddress().getIpv4Address().getValue().equals(ipAddress.getIpv4Address().getValue())) {
+ return uniAugmentation;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Updates a specific Uni Node on a specific DataStore type
+ * @param dataStore The datastore type
+ * @param uniIID The UNI InstanceIdentifier
+ * @param uni The Uni's data
+ * @param ovsdbNode The Ovsdb Node
+ * @param dataBroker The dataBroker instance to create transactions
+ * @return true if uni is updated
+ */
+ public static boolean updateUniNode(LogicalDatastoreType dataStore,
+ InstanceIdentifier<?> uniIID,
+ UniAugmentation uni,
+ Node ovsdbNode,
+ DataBroker dataBroker) {
+ final InstanceIdentifier<Node> ovsdbNodeIid = UnimgrMapper.getOvsdbNodeIid(ovsdbNode.getNodeId());
+ final OvsdbNodeRef ovsdbNodeRef = new OvsdbNodeRef(ovsdbNodeIid);
+ final UniAugmentationBuilder updatedUniBuilder = new UniAugmentationBuilder(uni);
+ if (ovsdbNodeRef != null) {
+ updatedUniBuilder.setOvsdbNodeRef(ovsdbNodeRef);
+ }
+ final Optional<Node> optionalNode = MdsalUtils.readNode(dataBroker,
+ LogicalDatastoreType.CONFIGURATION,
+ uniIID);
+ if (optionalNode.isPresent()) {
+ final Node node = optionalNode.get();
+ final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
+ final NodeBuilder nodeBuilder = new NodeBuilder();
+ nodeBuilder.setKey(node.getKey());
+ nodeBuilder.setNodeId(node.getNodeId());
+ nodeBuilder.addAugmentation(UniAugmentation.class, updatedUniBuilder.build());
+ transaction.put(dataStore, uniIID.firstIdentifierOf(Node.class), nodeBuilder.build());
+ transaction.submit();
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Update a specific UNI node on a specific datastore type
+ * @param dataStore The datastore type
+ * @param uniKey The UNI key
+ * @param uni The Uni's data
+ * @param ovsdbNodeIid The Ovsdb Node Instance Identifier
+ * @param dataBroker The dataBroker instance to create transactions
+ * @return true if uni is updated
+ */
+ public static boolean updateUniNode(LogicalDatastoreType dataStore,
+ InstanceIdentifier<?> uniKey,
+ UniAugmentation uni,
+ InstanceIdentifier<?> ovsdbNodeIid,
+ DataBroker dataBroker) {
+ final OvsdbNodeRef ovsdbNodeRef = new OvsdbNodeRef(ovsdbNodeIid);
+ final UniAugmentationBuilder updatedUniBuilder = new UniAugmentationBuilder(uni);
+ if (ovsdbNodeRef != null) {
+ updatedUniBuilder.setOvsdbNodeRef(ovsdbNodeRef);
+ }
+ final Optional<Node> optionalNode = MdsalUtils.readNode(dataBroker,
+ LogicalDatastoreType.CONFIGURATION,
+ uniKey);
+ if (optionalNode.isPresent()) {
+ final Node node = optionalNode.get();
+ final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
+ final NodeBuilder nodeBuilder = new NodeBuilder();
+ nodeBuilder.setKey(node.getKey());
+ nodeBuilder.setNodeId(node.getNodeId());
+ nodeBuilder.addAugmentation(UniAugmentation.class, updatedUniBuilder.build());
+ transaction.put(dataStore, uniKey.firstIdentifierOf(Node.class), nodeBuilder.build());
+ transaction.submit();
+ return true;
+ }
+ return false;
+ }
+
+ public static String getSpeed(Speed speedObject) {
+ String speed = null;
+ if (speedObject instanceof Speed10M) {
+ // map to 10MB
+ speed = "10000000";
+ }
+ else if (speedObject instanceof Speed100M) {
+ // map to 20MB
+ speed = "20000000";
+ }
+ else if (speedObject instanceof Speed1G) {
+ // map to 30MB
+ speed = "30000000";
+ }
+ else if (speedObject instanceof Speed10G) {
+ // map to 40MB
+ speed = "40000000";
+ }
+ return speed;
+ }
+
+ public static Speed getSpeed(final String speed) {
+ Speed speedObject = null;
+ if (speed.equals("10M")) {
+ speedObject = new Speed10MBuilder().setSpeed10M(true)
+ .build();
+ }
+ else if (speed.equals("100M")) {
+ speedObject = new Speed100MBuilder().setSpeed100M(true)
+ .build();
+ }
+ else if (speed.equals("1G")) {
+ speedObject = new Speed1GBuilder().setSpeed1G(true)
+ .build();
+ }
+ else if (speed.equals("10G")) {
+ speedObject = new Speed10GBuilder().setSpeed10G(true)
+ .build();
+ }
+ return speedObject;
+ }
+}
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.impl.UnimgrUtils;
+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 com.google.common.base.Optional;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({UnimgrUtils.class,
- UnimgrMapper.class})
+@PrepareForTest({EvcUtils.class, MdsalUtils.class, OvsdbUtils.class, UnimgrMapper.class})
public class EvcCreateCommandTest {
private static final NodeId OVSDB_NODE_ID = new NodeId("ovsdb://7011db35-f44b-4aab-90f6-d89088caf9d8");
@SuppressWarnings("unchecked")
@Before
public void setUp(){
- PowerMockito.mockStatic(UnimgrUtils.class);
+ PowerMockito.mockStatic(MdsalUtils.class);
+ PowerMockito.mockStatic(EvcUtils.class);
+ PowerMockito.mockStatic(OvsdbUtils.class);
PowerMockito.mockStatic(UnimgrMapper.class);
changes = mock(Map.class);
dataBroker = mock(DataBroker.class);
when(node.getAugmentation(any(Class.class))).thenReturn(uniAugmentation);
when(ovsNodedRef.getValue()).thenReturn(evcKey);
- when(UnimgrUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
+ when(MdsalUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
any(InstanceIdentifier.class))).thenReturn(optionalOvsdbNode);
- PowerMockito.doNothing().when(UnimgrUtils.class, "updateMaxRate", dataBroker, uniAugmentation,
+ PowerMockito.doNothing().when(OvsdbUtils.class, "updateMaxRate", dataBroker, uniAugmentation,
uniAugmentation, evcAugmentation);
- PowerMockito.doNothing().when(UnimgrUtils.class, "createTerminationPointNode", dataBroker,
+ PowerMockito.doNothing().when(OvsdbUtils.class, "createTerminationPointNode", dataBroker,
uniAugmentation, node, UnimgrConstants.DEFAULT_BRIDGE_NAME, UnimgrConstants.DEFAULT_TUNNEL_IFACE);
- PowerMockito.doNothing().when(UnimgrUtils.class, "createGreTunnel", dataBroker, uniAugmentation,
+ PowerMockito.doNothing().when(OvsdbUtils.class, "createGreTunnel", dataBroker, uniAugmentation,
uniAugmentation, node, UnimgrConstants.DEFAULT_BRIDGE_NAME, UnimgrConstants.DEFAULT_GRE_TUNNEL_NAME);
- when(UnimgrUtils.createOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
+ when(OvsdbUtils.createOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
.thenReturn(node);
when(UnimgrMapper.getOvsdbNodeIid(any(NodeId.class))).thenReturn(evcKey);
when(UnimgrMapper.getUniIid(any(DataBroker.class), any(IpAddress.class),
evcCreateCommand.execute();
PowerMockito.verifyStatic(times(2));
- UnimgrUtils.createTerminationPointNode(any(DataBroker.class), any(UniAugmentation.class),
+ OvsdbUtils.createTerminationPointNode(any(DataBroker.class), any(UniAugmentation.class),
any(Node.class), any(String.class), any(String.class));
PowerMockito.verifyStatic(times(2));
- UnimgrUtils.createGreTunnel(any(DataBroker.class), any(UniAugmentation.class),
+ OvsdbUtils.createGreTunnel(any(DataBroker.class), any(UniAugmentation.class),
any(UniAugmentation.class), any(Node.class), any(String.class), any(String.class));
PowerMockito.verifyStatic(times(2));
- UnimgrUtils.updateEvcNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
+ EvcUtils.updateEvcNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
any(EvcAugmentation.class), any(InstanceIdentifier.class),
any(InstanceIdentifier.class), any(DataBroker.class));
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.UnimgrMapper;
-import org.opendaylight.unimgr.impl.UnimgrUtils;
+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.NodeId;
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;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({UnimgrUtils.class})
+@PrepareForTest({EvcUtils.class, MdsalUtils.class, OvsdbUtils.class, UnimgrMapper.class})
public class EvcDeleteCommandTest {
private EvcDeleteCommand evcDeleteCommand;
@SuppressWarnings("unchecked")
@Before
public void setUp(){
- PowerMockito.mockStatic(UnimgrUtils.class);
+ PowerMockito.mockStatic(MdsalUtils.class);
+ PowerMockito.mockStatic(EvcUtils.class);
+ PowerMockito.mockStatic(OvsdbUtils.class);
PowerMockito.mockStatic(UnimgrMapper.class);
changes = mock(AsyncDataChangeEvent.class);
dataBroker = mock(DataBroker.class);
when(evcAugmentation.getUniDest()).thenReturn(unisDest);
when(uniSource.getUni()).thenReturn(instanceOfNode);
when(uniDest.getUni()).thenReturn(instanceOfNode);
- when(UnimgrUtils.extractRemoved(any(AsyncDataChangeEvent.class), any(Class.class)))
+ when(OvsdbUtils.extractRemoved(any(AsyncDataChangeEvent.class), any(Class.class)))
.thenReturn(removedEvcs);
- when(UnimgrUtils.read(any(DataBroker.class), any(LogicalDatastoreType.class),
+ when(MdsalUtils.read(any(DataBroker.class), any(LogicalDatastoreType.class),
any(InstanceIdentifier.class))).thenReturn(evcAugmentation);
- when(UnimgrUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
+ when(MdsalUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
any(InstanceIdentifier.class))).thenReturn(optionalNode);
- PowerMockito.doNothing().when(UnimgrUtils.class, "deleteEvcData",
+ PowerMockito.doNothing().when(EvcUtils.class, "deleteEvcData",
any(DataBroker.class), any(Optional.class));
- when(UnimgrUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class),
+ when(MdsalUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class),
any(LogicalDatastoreType.class))).thenReturn(true);
evcDeleteCommand.execute();
PowerMockito.verifyStatic(times(2));
- UnimgrUtils.deleteEvcData(any(DataBroker.class), any(Optional.class));
+ EvcUtils.deleteEvcData(any(DataBroker.class), any(Optional.class));
PowerMockito.verifyStatic(times(1));
- UnimgrUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class),
+ MdsalUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class),
any(LogicalDatastoreType.class));
}
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.impl.UnimgrUtils;
+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 com.google.common.util.concurrent.CheckedFuture;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({UnimgrUtils.class,
- UnimgrMapper.class})
+@PrepareForTest({UniUtils.class, EvcUtils.class, MdsalUtils.class, OvsdbUtils.class, UnimgrMapper.class})
public class EvcUpdateCommandTest {
private static final NodeId OVSDB_NODE_ID = new NodeId("ovsdb://7011db35-f44b-4aab-90f6-d89088caf9d8");
@SuppressWarnings("unchecked")
@Before
public void setUp(){
- PowerMockito.mockStatic(UnimgrUtils.class);
+ PowerMockito.mockStatic(UniUtils.class);
+ PowerMockito.mockStatic(MdsalUtils.class);
+ PowerMockito.mockStatic(EvcUtils.class);
+ PowerMockito.mockStatic(OvsdbUtils.class);
PowerMockito.mockStatic(UnimgrMapper.class);
changes = mock(Map.class);
dataBroker = mock(DataBroker.class);
when(node.getAugmentation(any(Class.class))).thenReturn(uniAugmentation);
when(ovsNodedRef.getValue()).thenReturn(evcKey);
- PowerMockito.doNothing().when(UnimgrUtils.class, "deleteEvcData", dataBroker, optionalOvsdbNode);
- when(UnimgrUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
+ PowerMockito.doNothing().when(EvcUtils.class, "deleteEvcData", dataBroker, optionalOvsdbNode);
+ when(MdsalUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
any(InstanceIdentifier.class))).thenReturn(optionalOvsdbNode);
- PowerMockito.doNothing().when(UnimgrUtils.class, "updateMaxRate", dataBroker, uniAugmentation,
+ PowerMockito.doNothing().when(OvsdbUtils.class, "updateMaxRate", dataBroker, uniAugmentation,
uniAugmentation, evcAugmentation);
- PowerMockito.doNothing().when(UnimgrUtils.class, "createTerminationPointNode", dataBroker,
+ PowerMockito.doNothing().when(OvsdbUtils.class, "createTerminationPointNode", dataBroker,
uniAugmentation, node, UnimgrConstants.DEFAULT_BRIDGE_NAME, UnimgrConstants.DEFAULT_TUNNEL_IFACE);
- PowerMockito.doNothing().when(UnimgrUtils.class, "createGreTunnel", dataBroker, uniAugmentation,
+ PowerMockito.doNothing().when(OvsdbUtils.class, "createGreTunnel", dataBroker, uniAugmentation,
uniAugmentation, node, UnimgrConstants.DEFAULT_BRIDGE_NAME, UnimgrConstants.DEFAULT_GRE_TUNNEL_NAME);
- when(UnimgrUtils.createOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
+ when(OvsdbUtils.createOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
.thenReturn(node);
when(UnimgrMapper.getOvsdbBridgeNodeIid(any(Node.class))).thenReturn(evcKey);
when(UnimgrMapper.getUniIid(any(DataBroker.class), any(IpAddress.class),
UnimgrMapper.getUniIid(any(DataBroker.class), any(IpAddress.class),
any(LogicalDatastoreType.class));
PowerMockito.verifyStatic(times(deleteTimes));
- UnimgrUtils.deleteEvcData(any(DataBroker.class), any(Optional.class));
+ EvcUtils.deleteEvcData(any(DataBroker.class), any(Optional.class));
PowerMockito.verifyStatic(times(readNodeTimes));
- UnimgrUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
+ MdsalUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
any(InstanceIdentifier.class));
PowerMockito.verifyStatic(times(updateEvcTime));
UnimgrMapper.getOvsdbBridgeNodeIid(any(Node.class));
PowerMockito.verifyStatic(times(updateEvcTime));
- UnimgrUtils.createTerminationPointNode(any(DataBroker.class), any(UniAugmentation.class),
+ OvsdbUtils.createTerminationPointNode(any(DataBroker.class), any(UniAugmentation.class),
any(Node.class), any(String.class), any(String.class));
PowerMockito.verifyStatic(times(updateEvcTime));
- UnimgrUtils.createGreTunnel(any(DataBroker.class), any(UniAugmentation.class),
+ OvsdbUtils.createGreTunnel(any(DataBroker.class), any(UniAugmentation.class),
any(UniAugmentation.class), any(Node.class), any(String.class), any(String.class));
PowerMockito.verifyStatic(times(updateEvcTime));
- UnimgrUtils.updateEvcNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
+ EvcUtils.updateEvcNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
any(EvcAugmentation.class), any(InstanceIdentifier.class),
any(InstanceIdentifier.class), any(DataBroker.class));
}
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.impl.UnimgrUtils;
+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.OvsdbNodeAugmentation;
import com.google.common.base.Optional;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({UnimgrUtils.class,
- UnimgrMapper.class})
+@PrepareForTest({UniUtils.class, OvsdbUtils.class, MdsalUtils.class, UnimgrMapper.class})
public class UniCreateCommandTest {
private static final NodeId OVSDB_NODE_ID = new NodeId("ovsdb://7011db35-f44b-4aab-90f6-d89088caf9d8");
@SuppressWarnings("unchecked")
@Before
public void setUp(){
- PowerMockito.mockStatic(UnimgrUtils.class);
+ PowerMockito.mockStatic(UniUtils.class);
+ PowerMockito.mockStatic(OvsdbUtils.class);
+ PowerMockito.mockStatic(MdsalUtils.class);
PowerMockito.mockStatic(UnimgrMapper.class);
changes = mock(Map.class);
dataBroker = mock(DataBroker.class);
when(node.getAugmentation(any(Class.class))).thenReturn(uniAugmentation);
when(node.getNodeId()).thenReturn(nodeId);
when(nodeId.toString()).thenReturn("ovsdbNodeId_test");
- when(UnimgrUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
+ when(MdsalUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
any(InstanceIdentifier.class))).thenReturn(optionalOvsdbNode);
- when(UnimgrUtils.findOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
+ when(OvsdbUtils.findOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
.thenReturn(optionalOvsdbNode);
- when(UnimgrUtils.createQoSForOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
+ when(OvsdbUtils.createQoSForOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
.thenReturn(null);
- when(UnimgrUtils.updateUniNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
+ when(UniUtils.updateUniNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
any(UniAugmentation.class), any(Node.class), any(DataBroker.class))).thenReturn(true);
- when(UnimgrUtils.updateUniNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
+ when(UniUtils.updateUniNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
any(UniAugmentation.class), any(InstanceIdentifier.class), any(DataBroker.class)))
.thenReturn(true);
- when(UnimgrUtils.createOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
+ when(OvsdbUtils.createOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
.thenReturn(node);
- PowerMockito.doNothing().when(UnimgrUtils.class, "createBridgeNode",
+ PowerMockito.doNothing().when(OvsdbUtils.class, "createBridgeNode",
dataBroker, uniKey,
uniAugmentation, UnimgrConstants.DEFAULT_BRIDGE_NAME);
- when(UnimgrUtils.getUniNodes(any(DataBroker.class))).thenReturn(nodes);
+ when(UniUtils.getUniNodes(any(DataBroker.class))).thenReturn(nodes);
when(UnimgrMapper.getOvsdbNodeIid(any(NodeId.class))).thenReturn(uniKey);
when(UnimgrMapper.getUniIid(any(DataBroker.class), any(IpAddress.class),
any(LogicalDatastoreType.class))).thenReturn(uniKey);
verifyExecute(1, 0, 1, 0);
// Case UNI2 : optionalNode.isPresent()
- when(UnimgrUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
+ when(MdsalUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
any(InstanceIdentifier.class))).thenReturn(optionalOvsdbNode);
verifyExecute(1, 0, 1, 0);
private void verifyExecute(int qosTimes, int bridgeTimes, int updateNodeTime, int updateIIDTimes){
uniCreateCommand.execute();
PowerMockito.verifyStatic(times(qosTimes));
- UnimgrUtils.createQoSForOvsdbNode(any(DataBroker.class), any(UniAugmentation.class));
+ OvsdbUtils.createQoSForOvsdbNode(any(DataBroker.class), any(UniAugmentation.class));
PowerMockito.verifyStatic(times(bridgeTimes));
- UnimgrUtils.createBridgeNode(any(DataBroker.class), any(InstanceIdentifier.class),
+ OvsdbUtils.createBridgeNode(any(DataBroker.class), any(InstanceIdentifier.class),
any(UniAugmentation.class), any(String.class));
PowerMockito.verifyStatic(times(updateNodeTime));
- UnimgrUtils.updateUniNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
+ UniUtils.updateUniNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
any(UniAugmentation.class), any(Node.class), any(DataBroker.class));
PowerMockito.verifyStatic(times(updateIIDTimes));
- UnimgrUtils.updateUniNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
+ UniUtils.updateUniNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
any(UniAugmentation.class), any(InstanceIdentifier.class), any(DataBroker.class));
}
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.impl.UnimgrUtils;
+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 com.google.common.base.Optional;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({UnimgrUtils.class,
+@PrepareForTest({UniUtils.class, OvsdbUtils.class, MdsalUtils.class,
UnimgrMapper.class})
public class UniDeleteCommandTest {
@SuppressWarnings("unchecked")
@Before
public void setUp(){
- PowerMockito.mockStatic(UnimgrUtils.class);
+ PowerMockito.mockStatic(UniUtils.class);
+ PowerMockito.mockStatic(OvsdbUtils.class);
+ PowerMockito.mockStatic(MdsalUtils.class);
PowerMockito.mockStatic(UnimgrMapper.class);
changes = mock(AsyncDataChangeEvent.class);
dataBroker = mock(DataBroker.class);
when(ovsNodedRef.getValue()).thenReturn(uniKey);
when(optionalNode.isPresent()).thenReturn(true);
when(optionalNode.get()).thenReturn(mock(Node.class));
- when(UnimgrUtils.extractRemoved(any(AsyncDataChangeEvent.class), any(Class.class)))
+ when(OvsdbUtils.extractRemoved(any(AsyncDataChangeEvent.class), any(Class.class)))
.thenReturn(removedUnis);
- when(UnimgrUtils.read(any(DataBroker.class), any(LogicalDatastoreType.class),
+ when(MdsalUtils.read(any(DataBroker.class), any(LogicalDatastoreType.class),
any(InstanceIdentifier.class))).thenReturn(uniAugmentation);
- when(UnimgrUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
+ when(MdsalUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
any(InstanceIdentifier.class))).thenReturn(optionalNode);
- when(UnimgrUtils.readNode(any(DataBroker.class), any(InstanceIdentifier.class)))
+ when(MdsalUtils.readNode(any(DataBroker.class), any(InstanceIdentifier.class)))
.thenReturn(optionalNode);
when(UnimgrMapper.getOvsdbBridgeNodeIid(any(Node.class))).thenReturn(instanceOfNode);
when(UnimgrMapper.getTerminationPointIid(any(Node.class), any(String.class)))
.thenReturn(instanceOfNode);
when(UnimgrMapper.getUniIid(any(DataBroker.class), any(IpAddress.class),
any(LogicalDatastoreType.class))).thenReturn(instanceOfNode);
- when(UnimgrUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class),
+ when(MdsalUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class),
any(LogicalDatastoreType.class))).thenReturn(true);
uniDeleteCommand.execute();
PowerMockito.verifyStatic(times(3));
- UnimgrUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class),
+ MdsalUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class),
any(LogicalDatastoreType.class));
}
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.impl.UnimgrUtils;
+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.OvsdbNodeAugmentation;
import com.google.common.base.Optional;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({UnimgrUtils.class,
- UnimgrMapper.class})
+@PrepareForTest({UniUtils.class, MdsalUtils.class, OvsdbUtils.class, UnimgrMapper.class})
public class UniUpdateCommandTest {
private static final NodeId OVSDB_NODE_ID = new NodeId("ovsdb://7011db35-f44b-4aab-90f6-d89088caf9d8");
@SuppressWarnings("unchecked")
@Before
public void setUp(){
- PowerMockito.mockStatic(UnimgrUtils.class);
+ PowerMockito.mockStatic(UniUtils.class);
+ PowerMockito.mockStatic(MdsalUtils.class);
+ PowerMockito.mockStatic(OvsdbUtils.class);
PowerMockito.mockStatic(UnimgrMapper.class);
changes = mock(Map.class);
dataBroker = mock(DataBroker.class);
when(node.getNodeId()).thenReturn(nodeId);
when(nodeId.toString()).thenReturn("ovsdbNodeId_test");
- when(UnimgrUtils.getUni(any(DataBroker.class), any(LogicalDatastoreType.class), any(IpAddress.class)))
+ when(UniUtils.getUni(any(DataBroker.class), any(LogicalDatastoreType.class), any(IpAddress.class)))
.thenReturn(uniAugmentation);
- when(UnimgrUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
+ when(MdsalUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
any(InstanceIdentifier.class))).thenReturn(optionalOvsdbNode);
- when(UnimgrUtils.createQoSForOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
+ when(OvsdbUtils.createQoSForOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
.thenReturn(null);
- when(UnimgrUtils.updateUniNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
+ when(UniUtils.updateUniNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
any(UniAugmentation.class), any(Node.class), any(DataBroker.class))).thenReturn(true);
- when(UnimgrUtils.findOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
+ when(OvsdbUtils.findOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
.thenReturn(optionalOvsdbNode);
- when(UnimgrUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class),
+ when(MdsalUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class),
any(LogicalDatastoreType.class))).thenReturn(true);
when(UnimgrMapper.getUniIid(any(DataBroker.class), any(IpAddress.class),
any(LogicalDatastoreType.class))).thenReturn(uniKey);
private void verifyExecute(int qosTimes, int deleteTimes, int updateNodeTime, int getKeyTimes){
uniUpdateCommand.execute();
PowerMockito.verifyStatic(times(qosTimes));
- UnimgrUtils.createQoSForOvsdbNode(any(DataBroker.class), any(UniAugmentation.class));
+ OvsdbUtils.createQoSForOvsdbNode(any(DataBroker.class), any(UniAugmentation.class));
PowerMockito.verifyStatic(times(deleteTimes));
- UnimgrUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class),
+ MdsalUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class),
any(LogicalDatastoreType.class));
PowerMockito.verifyStatic(times(updateNodeTime));
- UnimgrUtils.updateUniNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
+ UniUtils.updateUniNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
any(UniAugmentation.class), any(Node.class), any(DataBroker.class));
verify(managedNodeEntry, times(getKeyTimes)).getKey();
}
import org.mockito.Mockito;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+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.OvsdbBridgeRef;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-@PrepareForTest({UnimgrUtils.class})
+@PrepareForTest({UniUtils.class})
@RunWith(PowerMockRunner.class)
public class UnimgrMapperTest {
Node node = mock(Node.class);
uniNodes.add(node);
- PowerMockito.mockStatic(UnimgrUtils.class);
- PowerMockito.when(UnimgrUtils.getUniNodes(any(DataBroker.class), any(LogicalDatastoreType.class))).thenReturn(uniNodes);
+ PowerMockito.mockStatic(UniUtils.class);
+ PowerMockito.when(UniUtils.getUniNodes(any(DataBroker.class), any(LogicalDatastoreType.class))).thenReturn(uniNodes);
UniAugmentation uniAugmentation = mock(UniAugmentation.class);
when(node.getAugmentation(UniAugmentation.class)).thenReturn(uniAugmentation);
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;
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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
InstanceIdentifier.class,
LogicalDatastoreType.class,
FrameworkUtil.class,
- UnimgrUtils.class,
+ UniUtils.class,
+ MdsalUtils.class,
+ OvsdbUtils.class,
UnimgrMapper.class})
public class UnimgrProviderTest {
@Test
public void testAddUni() throws Exception {
- PowerMockito.mockStatic(UnimgrUtils.class);
+ PowerMockito.mockStatic(UniUtils.class);
assertEquals(unimgrProvider.addUni(null), false);
final UniAugmentation mockUniAug = mock(UniAugmentation.class);
// false case
final UniAugmentationBuilder uniAugBuilder = new UniAugmentationBuilder()
.setIpAddress(mock(IpAddress.class))
.setMacAddress(mock(MacAddress.class));
- when(UnimgrUtils.createUniNode(any(DataBroker.class),
+ when(UniUtils.createUniNode(any(DataBroker.class),
any(UniAugmentation.class)))
.thenReturn(true);
assertEquals(true, unimgrProvider.addUni(uniAugBuilder.build()));
@SuppressWarnings("unchecked")
@Test
public void testRemoveUni() throws Exception {
- PowerMockito.mockStatic(UnimgrUtils.class);
+ PowerMockito.mockStatic(MdsalUtils.class);
PowerMockito.mockStatic(UnimgrMapper.class);
PowerMockito.mockStatic(InstanceIdentifier.class);
any(IpAddress.class),
any(LogicalDatastoreType.class)))
.thenReturn(iid);
- PowerMockito.when(UnimgrUtils.deleteNode(any(DataBroker.class),
+ PowerMockito.when(MdsalUtils.deleteNode(any(DataBroker.class),
any(InstanceIdentifier.class),
any(LogicalDatastoreType.class)))
.thenReturn(true);
@SuppressWarnings("unchecked")
@Test
public void testlistUnis() throws Exception {
- PowerMockito.mockStatic(UnimgrUtils.class);
+ PowerMockito.mockStatic(UniUtils.class);
final List<UniAugmentation> mockUniList = mock(List.class);
- when(UnimgrUtils.getUnis(any(DataBroker.class),
+ when(UniUtils.getUnis(any(DataBroker.class),
any(LogicalDatastoreType.class)))
.thenReturn(mockUniList);
assertEquals(mockUniList,
@Test
public void testgetUni() throws Exception {
- PowerMockito.mockStatic(UnimgrUtils.class);
+ PowerMockito.mockStatic(UniUtils.class);
final UniAugmentation mockUniAug = mock(UniAugmentation.class);
- when(UnimgrUtils.getUni(any(DataBroker.class),
+ when(UniUtils.getUni(any(DataBroker.class),
any(LogicalDatastoreType.class),
any(IpAddress.class)))
.thenReturn(mockUniAug);
+++ /dev/null
-package org.opendaylight.unimgr.impl;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.times;
-import static org.mockito.Matchers.argThat;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableBiMap;
-import com.google.common.util.concurrent.CheckedFuture;
-
-import ch.qos.logback.core.Appender;
-import ch.qos.logback.classic.spi.LoggingEvent;
-import org.mockito.ArgumentMatcher;
-
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.api.support.membermodification.MemberMatcher;
-import org.powermock.api.support.membermodification.MemberModifier;
-
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.runner.RunWith;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.ovsdb.southbound.SouthboundConstants;
-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.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentationBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeName;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeProtocolBase;
-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.OvsdbNodeAugmentationBuilder;
-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.OvsdbTerminationPointAugmentation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentationBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbPortInterfaceAttributes.VlanMode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntryBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntry;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntryBuilder;
-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.ConnectionInfoBuilder;
-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.EvcAugmentationBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.Uni;
-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.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.EgressBw;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.IngressBw;
-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.UniDestBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDestKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSource;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSourceBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSourceKey;
-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.TpId;
-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.NodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({LogicalDatastoreType.class, UnimgrMapper.class, UnimgrUtils.class, UUID.class})
-public class UnimgrUtilsTest {
-
- @Rule
- public final ExpectedException exception = ExpectedException.none();
- @Mock private DataBroker dataBroker;
- @Mock private Node bridgeNode;
- @Mock private String bridgeName;
- @Mock private String portName;
- @Mock private String type;
- @Mock private WriteTransaction transaction;
- @Mock private IpAddress mockIp;
- @SuppressWarnings("rawtypes")
- @Mock private Appender mockAppender;
- @SuppressWarnings({ "rawtypes" })
- @Mock private CheckedFuture checkedFuture;
- @SuppressWarnings("unchecked")
- private static final InstanceIdentifier<TerminationPoint> tpIid = PowerMockito.mock(InstanceIdentifier.class);
- private static final IpAddress IP = new IpAddress(new Ipv4Address("192.168.1.2"));
- private static final NodeId OVSDB_NODE_ID = new NodeId("ovsdb://7011db35-f44b-4aab-90f6-d89088caf9d8");
- @SuppressWarnings("unchecked")
- private static final InstanceIdentifier<Node> MOCK_NODE_IID = PowerMockito.mock(InstanceIdentifier.class);
- private ch.qos.logback.classic.Logger root;
-
- @SuppressWarnings("unchecked")
- @Before
- public void setUp() throws Exception {
- PowerMockito.mockStatic(UnimgrUtils.class, Mockito.CALLS_REAL_METHODS);
- PowerMockito.mockStatic(UnimgrMapper.class, Mockito.CALLS_REAL_METHODS);
- PowerMockito.mockStatic(LogicalDatastoreType.class);
- PowerMockito.mockStatic(UUID.class);
- root = (ch.qos.logback.classic.Logger)
- LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
- // Check logger messages
- when(mockAppender.getName()).thenReturn("MOCK");
- root.addAppender(mockAppender);
- }
-
- /*
- * This test for 2 functions with the
- * same name that take different parameters.
- */
- @SuppressWarnings({"unchecked", "rawtypes"})
- @Test
- public void testCreateBridgeNode() throws Exception {
- // Function 1
- Node ovsdbNode = new NodeBuilder().setNodeId(OVSDB_NODE_ID).build();
- InstanceIdentifier<Node> nodeIid = InstanceIdentifier
- .create(NetworkTopology.class)
- .child(Topology.class,
- new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
- .child(Node.class,
- new NodeKey(OVSDB_NODE_ID));
- OvsdbNodeRef ovsdbNodeRef = new OvsdbNodeRef(nodeIid);
- UniAugmentation uni = new UniAugmentationBuilder()
- .setIpAddress(new IpAddress(new Ipv4Address("192.168.1.1")))
- .setOvsdbNodeRef(ovsdbNodeRef)
- .build();
-
- when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
- doNothing().when(transaction).put(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(Node.class));
- when(transaction.submit()).thenReturn(checkedFuture);
- MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "createOvsdbBridgeNodeIid", Node.class, String.class));
- when(UnimgrMapper.createOvsdbBridgeNodeIid(any(Node.class),
- any(String.class))).thenReturn(MOCK_NODE_IID);
- UnimgrUtils.createBridgeNode(dataBroker, ovsdbNode, uni, "br0");
- verify(transaction).put(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(Node.class));
- verify(transaction).submit();
-
- // Function 2
- MemberModifier.suppress(MemberMatcher.method(UnimgrUtils.class,
- "readNode",
- DataBroker.class,
- LogicalDatastoreType.class,
- InstanceIdentifier.class));
- Optional<Node> mockOptional = mock(Optional.class);
- when(UnimgrUtils.readNode(any(DataBroker.class),
- any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class))).thenReturn(mockOptional);
- UnimgrUtils.createBridgeNode(dataBroker, nodeIid, uni, "br0");
- verify(transaction).put(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(Node.class));
- verify(transaction).submit();
-
- // Ensure correct logging
- verify(mockAppender, times(2)).doAppend(argThat(new ArgumentMatcher() {
- @Override
- public boolean matches(final Object argument) {
- return ((LoggingEvent)argument).getFormattedMessage().contains("Creating a bridge on node");
- }
- }));
- }
-
- @Test
- public void testCreateControllerEntries() {
- String targetString = new String("controllerEntry");
- List<ControllerEntry> controllerEntries = new ArrayList<ControllerEntry>();
- ControllerEntryBuilder controllerEntryBuilder = new ControllerEntryBuilder();
- controllerEntryBuilder.setTarget(new Uri(targetString));
- controllerEntries.add(controllerEntryBuilder.build());
- assertEquals(controllerEntries, UnimgrUtils.createControllerEntries(targetString));
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testCreateGreTunnel() throws Exception {
-
- UniAugmentation sourceUniAug = new UniAugmentationBuilder()
- .setIpAddress(new IpAddress(new Ipv4Address("192.168.1.1")))
- .build();
- UniAugmentation destUniAug = new UniAugmentationBuilder()
- .setIpAddress(new IpAddress(new Ipv4Address("192.168.1.2")))
- .build();
-
- when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
- doNothing().when(transaction).put(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(TerminationPoint.class));
- when(transaction.submit()).thenReturn(checkedFuture);
-
- MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getTerminationPointIid", Node.class, String.class));
- MemberModifier.suppress(MemberMatcher.method(UnimgrUtils.class, "createMdsalProtocols"));
-
- Node bNode = new NodeBuilder().setKey(new NodeKey(OVSDB_NODE_ID)).build();
- InstanceIdentifier<TerminationPoint> tpIid = InstanceIdentifier
- .create(NetworkTopology.class)
- .child(Topology.class,
- new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
- .child(Node.class, bNode.getKey())
- .child(TerminationPoint.class,
- new TerminationPointKey(new TpId(portName)));
- when(UnimgrMapper.getTerminationPointIid(any(Node.class), any(String.class))).thenReturn(tpIid);
- UnimgrUtils.createGreTunnel(dataBroker,
- sourceUniAug,
- destUniAug,
- bridgeNode,
- bridgeName,
- portName);
- verify(transaction).put(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(TerminationPoint.class));
- verify(transaction).submit();
- }
-
- @Test
- public void testCreateMdsalProtocols() {
- List<ProtocolEntry> protocolList = new ArrayList<ProtocolEntry>();
- ImmutableBiMap<String, Class<? extends OvsdbBridgeProtocolBase>> mapper =
- SouthboundConstants.OVSDB_PROTOCOL_MAP.inverse();
- ProtocolEntry protoEntry = new ProtocolEntryBuilder().setProtocol((Class<? extends OvsdbBridgeProtocolBase>) mapper.get("OpenFlow13")).build();
- protocolList.add(protoEntry);
- assertEquals(protocolList, UnimgrUtils.createMdsalProtocols());
- }
-
- @Test
- public void testCreateOvsdbBridgeAugmentation() throws Exception {
- OvsdbNodeRef ovsdbNodeRef = new OvsdbNodeRef(PowerMockito.mock(InstanceIdentifier.class));
- UniAugmentation uni = new UniAugmentationBuilder().setOvsdbNodeRef(ovsdbNodeRef).build();
- UUID bridgeUuid = PowerMockito.mock(UUID.class);
- PowerMockito.when(UUID.randomUUID()).thenReturn(bridgeUuid);
- OvsdbBridgeAugmentation ovsdbNode = new OvsdbBridgeAugmentationBuilder()
- .setBridgeName(new OvsdbBridgeName(UnimgrConstants.DEFAULT_BRIDGE_NAME))
- .setManagedBy(ovsdbNodeRef)
- .setBridgeUuid(new Uuid(bridgeUuid.toString()))
- .build();
- assertEquals(ovsdbNode, UnimgrUtils.createOvsdbBridgeAugmentation(uni));
- // Force an exception
- Uni ovsdbNodeRefNull = new UniAugmentationBuilder().setOvsdbNodeRef(null).build();
- exception.expect(Exception.class);
- UnimgrUtils.createOvsdbBridgeAugmentation(ovsdbNodeRefNull);
- }
-
- /*
- * This test for 2 functions with the
- * same name that take different parameters.
- */
- @SuppressWarnings({ "unchecked", "rawtypes" })
- @Test
- public void testCreateOvsdbNode() {
- MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getOvsdbNodeIid", IpAddress.class));
- PowerMockito.when(UnimgrMapper.getOvsdbNodeIid(mockIp)).thenReturn(MOCK_NODE_IID);
- when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
- //when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
- Uni uni = new UniAugmentationBuilder().setIpAddress(new IpAddress(new Ipv4Address("192.168.1.2"))).build();
- // createOvsdbNode with NodeId and Uni
- UnimgrUtils.createOvsdbNode(dataBroker, OVSDB_NODE_ID, uni);
- // Ensure correct logging
- verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
- @Override
- public boolean matches(final Object argument) {
- return ((LoggingEvent)argument).getFormattedMessage().contains("Created and submitted a new OVSDB node");
- }
- }));
- doNothing().when(transaction).put(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(Node.class));
- when(transaction.submit()).thenReturn(checkedFuture);
- verify(transaction).put(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(Node.class));
- verify(transaction).submit();
- // Test with a null uni
- exception.expect(Exception.class);
- UnimgrUtils.createOvsdbNode(dataBroker, OVSDB_NODE_ID, null);
- // Ensure correct logging
- verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
- @Override
- public boolean matches(final Object argument) {
- return ((LoggingEvent)argument).getFormattedMessage().contains("Created and submitted a new OVSDB node");
- }
- }));
- // createOvsdbNode with Uni
- UniAugmentation uniAug = new UniAugmentationBuilder(uni).build();
- UnimgrUtils.createOvsdbNode(dataBroker, uniAug);
- MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getOvsdbNodeIid", NodeId.class));
- PowerMockito.when(UnimgrMapper.getOvsdbNodeIid(any(NodeId.class))).thenReturn(MOCK_NODE_IID);
- doNothing().when(transaction).put(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(Node.class));
- when(transaction.submit()).thenReturn(checkedFuture);
- verify(transaction).put(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(Node.class));
- verify(transaction).submit();
- // try with a null uni
- PowerMockito.when(UnimgrMapper.getOvsdbNodeIid(any(NodeId.class))).thenReturn(null);
- UnimgrUtils.createOvsdbNode(dataBroker, null);
- exception.expect(Exception.class);
- UnimgrUtils.createOvsdbNode(dataBroker, null);
- }
-
- @Test
- public void testCreateOvsdbNodeAugmentation() {
- Uni uni = new UniAugmentationBuilder().setIpAddress(new IpAddress(new Ipv4Address("192.168.1.2"))).build();
- ConnectionInfo connectionInfos = new ConnectionInfoBuilder()
- .setRemoteIp(uni.getIpAddress())
- .setRemotePort(new PortNumber(UnimgrConstants.OVSDB_PORT))
- .build();
- OvsdbNodeAugmentation ovsdbNode = new OvsdbNodeAugmentationBuilder()
- .setConnectionInfo(connectionInfos).build();
- assertEquals(ovsdbNode, UnimgrUtils.createOvsdbNodeAugmentation(uni));
- }
-
- @Test
- public void testCreateOvsdbNodeId() {
- String nodeId = UnimgrConstants.OVSDB_PREFIX
- + IP.getIpv4Address().getValue().toString()
- + ":"
- + UnimgrConstants.OVSDB_PORT;
- assertEquals(new NodeId(nodeId), UnimgrUtils.createOvsdbNodeId(IP));
- }
-
- @Test
- public void testCreateOvsdbTerminationPointAugmentation() {
- Uni uni = new UniAugmentationBuilder().build();
- VlanId vlanID = new VlanId(1);
- OvsdbTerminationPointAugmentation terminationPoint = new OvsdbTerminationPointAugmentationBuilder()
- .setName(UnimgrConstants.DEFAULT_INTERNAL_IFACE)
- .setVlanTag(vlanID)
- .setVlanMode(VlanMode.Access)
- .build();
- assertEquals(terminationPoint, UnimgrUtils.createOvsdbTerminationPointAugmentation(uni));
- }
-
- @Test
- public void testCreateEvc() {
- EvcAugmentation evc = mock(EvcAugmentation.class);
- assertEquals(false, UnimgrUtils.createEvc(dataBroker, evc));
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- @Test
- public void testCreateUniNode() {
- UniAugmentation uniAug = new UniAugmentationBuilder()
- .setIpAddress(new IpAddress(new Ipv4Address("192.168.1.2")))
- .build();
- when(UnimgrMapper.getUniNodeIid(any(NodeId.class))).thenReturn(mock(InstanceIdentifier.class));
- doNothing().when(transaction).put(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(Node.class));
- when(transaction.submit()).thenReturn(checkedFuture);
- assertEquals(false, UnimgrUtils.createUniNode(dataBroker, uniAug));
- verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
- @Override
- public boolean matches(final Object argument) {
- return ((LoggingEvent)argument).getFormattedMessage().contains("Exception while creating Uni Node");
- }
- }));
- MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getUniNodeIid", NodeId.class));
- PowerMockito.when(UnimgrMapper.getUniNodeIid(any(NodeId.class))).thenReturn(MOCK_NODE_IID);
-
- when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
- UnimgrUtils.createUniNode(dataBroker, uniAug);
- verify(transaction).put(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(Node.class));
- verify(transaction).submit();
- verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
- @Override
- public boolean matches(final Object argument) {
- return ((LoggingEvent)argument).getFormattedMessage().contains("Created and submitted a new Uni");
- }
- }));
- }
-
- @Test
- public void testCreateUniNodeId() {
- NodeId nodeId = new NodeId(UnimgrConstants.UNI_PREFIX + IP.getIpv4Address().getValue().toString());
- assertEquals(nodeId, UnimgrUtils.createUniNodeId(IP));
- }
-
- /*
- * This test for 2 functions with the
- * same name that take different parameters.
- */
- @SuppressWarnings("unchecked")
- @Test
- public void testCreateTerminationPointNode() {
- Uni uni = new UniAugmentationBuilder().build();
- Node bridgeNode = new NodeBuilder().build();
-
- MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class,
- "getTerminationPointIid",
- Node.class,
- String.class));
- PowerMockito.when(UnimgrMapper.getTerminationPointIid(any(Node.class),
- any(String.class))).thenReturn(tpIid);
- when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
- Node bNode = new NodeBuilder().setKey(new NodeKey(OVSDB_NODE_ID)).build();
- InstanceIdentifier<TerminationPoint> tpIid = InstanceIdentifier
- .create(NetworkTopology.class)
- .child(Topology.class,
- new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
- .child(Node.class, bNode.getKey())
- .child(TerminationPoint.class,
- new TerminationPointKey(new TpId(portName)));
- when(UnimgrMapper.getTerminationPointIid(any(Node.class), any(String.class))).thenReturn(tpIid);
- // Function 1
- UnimgrUtils.createTerminationPointNode(dataBroker, uni, bNode, bridgeName, portName, type);
-
- //Function 2
- doNothing().when(transaction).put(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(TerminationPoint.class));
- when(transaction.submit()).thenReturn(checkedFuture);
- UnimgrUtils.createTerminationPointNode(dataBroker, uni, bridgeNode, bridgeName, portName);
- verify(transaction, times(2)).put(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(TerminationPoint.class));
- verify(transaction,times(2)).submit();
- }
-
- @Test
- public void testDelete() {
- // FIXME this function will be moved into an MdsalUtils class.
- // see bug: https://bugs.opendaylight.org/show_bug.cgi?id=5035
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testDeleteTerminationPoint() {
- TerminationPointKey tpKey = new TerminationPointKey(new TpId("abcde"));
- TerminationPoint terminationPoint = new TerminationPointBuilder().setKey(tpKey).build();
- Node ovsdbNode = new NodeBuilder().setKey(new NodeKey(OVSDB_NODE_ID)).build();
- when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
- doNothing().when(transaction).delete(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class));
-
- UnimgrUtils.deleteTerminationPoint(dataBroker, terminationPoint, ovsdbNode);
- verify(transaction,times(2)).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
- verify(transaction,times(2)).submit();
- CheckedFuture<Void, TransactionCommitFailedException> mockCheckedFuture = mock(CheckedFuture.class);
- when(transaction.submit()).thenReturn(mockCheckedFuture);
- assertEquals(mockCheckedFuture, UnimgrUtils.deleteTerminationPoint(dataBroker, terminationPoint, ovsdbNode));
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- @Test
- public void testDeleteNode() throws Exception {
- InstanceIdentifier<Node> genericNode = InstanceIdentifier
- .create(NetworkTopology.class)
- .child(Topology.class,
- new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
- .child(Node.class);
- when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
- doNothing().when(transaction).delete(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class));
- when(transaction.submit()).thenReturn(checkedFuture);
- assertEquals(true, UnimgrUtils.deleteNode(dataBroker, genericNode, LogicalDatastoreType.CONFIGURATION));
- verify(transaction).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
- verify(transaction).submit();
- verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
- @Override
- public boolean matches(final Object argument) {
- return ((LoggingEvent)argument).getFormattedMessage().contains("Received a request to delete node");
- }
- }));
- }
-
- @Test
- public void testExtract() {
- Map<InstanceIdentifier<?>, DataObject> changes = new HashMap<>();
- Class<DataObject> klazz = DataObject.class;
- assertEquals(HashMap.class, UnimgrUtils.extract(changes, klazz).getClass());
- }
-
-// FIXME
-// @SuppressWarnings("unchecked")
-// @Test
-// public void testExtractOriginal() {
-// AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes = mock(AsyncDataChangeEvent.class);
-// Class<DataObject> klazz = DataObject.class;
-// Map<InstanceIdentifier<?>, DataObject> map = new HashMap<>();
-// when(changes.getOriginalData()).thenReturn(map);
-// when(UnimgrUtils.extract(any(Map.class),eq(DataObject.class))).thenReturn(map);
-// assertEquals(map, UnimgrUtils.extractOriginal(changes, klazz));
-// }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testExtractRemoved() {
- AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes = mock(AsyncDataChangeEvent.class);
- Class<DataObject> klazz = DataObject.class;
- assertEquals(HashSet.class, UnimgrUtils.extractRemoved(changes, klazz).getClass());
- }
-
- @Test
- public void testFindOvsdbNode() {
- List<Node> ovsdbNodes = new ArrayList<Node>();
- UniAugmentation uni = new UniAugmentationBuilder()
- .setIpAddress(IP)
- .build();
- ConnectionInfo connInfo = new ConnectionInfoBuilder().setRemoteIp(IP).build();
- OvsdbNodeAugmentation augmentation = new OvsdbNodeAugmentationBuilder()
- .setConnectionInfo(connInfo)
- .build();
- Node node = new NodeBuilder().addAugmentation(OvsdbNodeAugmentation.class, augmentation).build();
- ovsdbNodes.add(node);
- MemberModifier.suppress(MemberMatcher.method(UnimgrUtils.class,
- "getOvsdbNodes",
- DataBroker.class));
- when(UnimgrUtils.getOvsdbNodes(any(DataBroker.class))).thenReturn(ovsdbNodes);
- Optional<Node> optNode = Optional.of(node);
- assertEquals(optNode, UnimgrUtils.findOvsdbNode(dataBroker, uni));
- }
-
- @Test
- public void testFindUniNode() {
- DataBroker dataBroker = mock(DataBroker.class);
- IpAddress ipAddress = mock(IpAddress.class);
- UniAugmentation uniAugmentation = mock(UniAugmentation.class);
- List<Node> uniNodes = new ArrayList<Node>();
- Node nd = mock(Node.class);
- uniNodes.add(nd);
- MemberModifier.suppress(MemberMatcher.method(UnimgrUtils.class, "getUniNodes", DataBroker.class));
- when(UnimgrUtils.getUniNodes(any(DataBroker.class))).thenReturn(uniNodes);
- when(nd.getAugmentation(UniAugmentation.class)).thenReturn(uniAugmentation);
- when(uniAugmentation.getIpAddress()).thenReturn(ipAddress);
- Optional<Node> optNode = UnimgrUtils.findUniNode(dataBroker, ipAddress);
- assertNotNull(optNode);
- assertTrue(optNode.isPresent());
- uniNodes.remove(0);
- optNode = UnimgrUtils.findUniNode(dataBroker, ipAddress);
- assertTrue(Optional.absent() == Optional.absent());
- }
-
- @Test
- public void testGetConnectionInfo() {
- DataBroker dataBroker = mock(DataBroker.class);
- InstanceIdentifier<Node> nodeIid = PowerMockito.mock(InstanceIdentifier.class);
- NodeId ovsdbNodeId = mock(NodeId.class);
- Optional<Node> optNode = mock(Optional.class);
- Node node = mock(Node.class);
- OvsdbNodeAugmentation ovsdbNodeAugmentation = mock(OvsdbNodeAugmentation.class);
- ConnectionInfo connectionInfo = mock(ConnectionInfo.class);
- MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getOvsdbNodeIid", NodeId.class));
- when(UnimgrMapper.getOvsdbNodeIid(any(NodeId.class))).thenReturn(nodeIid);
- MemberModifier.suppress(MemberMatcher.method(UnimgrUtils.class, "readNode", DataBroker.class, LogicalDatastoreType.class, InstanceIdentifier.class));
- when(UnimgrUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(optNode);
- when(optNode.isPresent()).thenReturn(true);
- when(optNode.get()).thenReturn(node);
- when(node.getAugmentation(OvsdbNodeAugmentation.class)).thenReturn(ovsdbNodeAugmentation);
- when(ovsdbNodeAugmentation.getConnectionInfo()).thenReturn(connectionInfo);
- ConnectionInfo expectedConnInfo = UnimgrUtils.getConnectionInfo(dataBroker, ovsdbNodeId);
- assertNotNull(expectedConnInfo);
- assertEquals(expectedConnInfo, connectionInfo);
- }
-
- @Test
- public void testGetEvcLinks() {
- Link link = mock(Link.class);
- List<Link> lnkList = new ArrayList<Link>();
- lnkList.add(link);
- Topology topology = mock (Topology.class);
- DataBroker dataBroker = mock(DataBroker.class);
- EvcAugmentation evcAugmentation = mock(EvcAugmentation.class, Mockito.RETURNS_MOCKS);
- InstanceIdentifier<Topology> topologyInstanceIdentifier = mock(InstanceIdentifier.class);
- MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getEvcTopologyIid"));
- when(UnimgrMapper.getEvcTopologyIid()).thenReturn(topologyInstanceIdentifier);
- MemberModifier.suppress(MemberMatcher.method(UnimgrUtils.class, "read", DataBroker.class, LogicalDatastoreType.class, InstanceIdentifier.class));
- when(UnimgrUtils.read(any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(topology);
- when(topology.getLink()).thenReturn(lnkList);
- when(link.getAugmentation(EvcAugmentation.class)).thenReturn(evcAugmentation);
- List<Link> expectedListLink = UnimgrUtils.getEvcLinks(dataBroker);
- assertNotNull(expectedListLink);
- assertEquals(expectedListLink.get(0), link);
- }
-
- @Test
- public void testGetLocalIp() {
- String ip = "";
- try {
- ip = InetAddress.getLocalHost().getHostAddress();
- } catch (UnknownHostException e) {
- ip = "127.0.0.1";
- }
- IpAddress ipAddress = UnimgrUtils.getLocalIp();
- assertNotNull(ipAddress);
- String expectedIp = new String(ipAddress.getValue());
- assertTrue(expectedIp.equals(ip));
- }
-
- @Test
- public void testGetOvsdbNodes() {
- Node node = mock(Node.class);
- List<Node> ndList = new ArrayList<Node>();
- ndList.add(node);
- Topology topology = mock (Topology.class);
- DataBroker dataBroker = mock(DataBroker.class);
- OvsdbNodeAugmentation ovsNdAugmentation = mock(OvsdbNodeAugmentation.class, Mockito.RETURNS_MOCKS);
- InstanceIdentifier<Topology> topologyInstanceIdentifier = mock(InstanceIdentifier.class);
- MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getOvsdbTopologyIid"));
- when(UnimgrMapper.getOvsdbTopologyIid()).thenReturn(topologyInstanceIdentifier);
- MemberModifier.suppress(MemberMatcher.method(UnimgrUtils.class, "read", DataBroker.class, LogicalDatastoreType.class, InstanceIdentifier.class));
- when(UnimgrUtils.read(any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(topology);
- when(topology.getNode()).thenReturn(ndList);
- when(node.getAugmentation(OvsdbNodeAugmentation.class)).thenReturn(ovsNdAugmentation);
- List<Node> expectedListNnList = UnimgrUtils.getOvsdbNodes(dataBroker);
- assertNotNull(expectedListNnList);
- assertEquals(expectedListNnList.get(0), node);
- }
-
- @Test
- public void testGetUniNodes() {
- Node node = mock(Node.class);
- List<Node> ndList = new ArrayList<Node>();
- ndList.add(node);
- Topology topology = mock (Topology.class);
- DataBroker dataBroker = mock(DataBroker.class);
- UniAugmentation uniAugmentation = mock(UniAugmentation.class);
- InstanceIdentifier<Topology> topologyInstanceIdentifier = mock(InstanceIdentifier.class);
- MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getUniTopologyIid"));
- when(UnimgrMapper.getUniTopologyIid()).thenReturn(topologyInstanceIdentifier);
- MemberModifier.suppress(MemberMatcher.method(UnimgrUtils.class, "read", DataBroker.class, LogicalDatastoreType.class, InstanceIdentifier.class));
- when(UnimgrUtils.read(any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(topology);
- when(topology.getNode()).thenReturn(ndList);
- when(node.getAugmentation(UniAugmentation.class)).thenReturn(uniAugmentation);
- List<Node> expectedListNnList = UnimgrUtils.getUniNodes(dataBroker);
- assertNotNull(expectedListNnList);
- assertEquals(expectedListNnList, ndList);
- }
-
- @Test
- public void testGetUniNodes2() {
- Node node = mock(Node.class);
- List<Node> ndList = new ArrayList<Node>();
- ndList.add(node);
- Topology topology = mock (Topology.class);
- DataBroker dataBroker = mock(DataBroker.class);
- UniAugmentation uniAugmentation = mock(UniAugmentation.class);
- InstanceIdentifier<Topology> topologyInstanceIdentifier = mock(InstanceIdentifier.class);
- MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getUniTopologyIid"));
- when(UnimgrMapper.getUniTopologyIid()).thenReturn(topologyInstanceIdentifier);
- MemberModifier.suppress(MemberMatcher.method(UnimgrUtils.class, "read", DataBroker.class, LogicalDatastoreType.class, InstanceIdentifier.class));
- when(UnimgrUtils.read(any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(topology);
- when(topology.getNode()).thenReturn(ndList);
- when(node.getAugmentation(UniAugmentation.class)).thenReturn(uniAugmentation);
- List<Node> expectedListNnList = UnimgrUtils.getUniNodes(dataBroker, LogicalDatastoreType.OPERATIONAL);
- assertNotNull(expectedListNnList);
- assertEquals(expectedListNnList, ndList);
- }
-
- @Test
- public void testGetUnis() {
- Node node = mock(Node.class);
- List<Node> ndList = new ArrayList<Node>();
- ndList.add(node);
- Topology topology = mock (Topology.class);
- DataBroker dataBroker = mock(DataBroker.class);
- UniAugmentation uniAugmentation = mock(UniAugmentation.class);
- InstanceIdentifier<Topology> topologyInstanceIdentifier = mock(InstanceIdentifier.class);
- MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getUniTopologyIid"));
- when(UnimgrMapper.getUniTopologyIid()).thenReturn(topologyInstanceIdentifier);
- MemberModifier.suppress(MemberMatcher.method(UnimgrUtils.class, "read", DataBroker.class, LogicalDatastoreType.class, InstanceIdentifier.class));
- when(UnimgrUtils.read(any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(topology);
- when(topology.getNode()).thenReturn(ndList);
- when(node.getAugmentation(UniAugmentation.class)).thenReturn(uniAugmentation);
- List<UniAugmentation> expectedListUni = UnimgrUtils.getUnis(dataBroker, LogicalDatastoreType.CONFIGURATION);
- assertNotNull(expectedListUni);
- assertEquals(expectedListUni.iterator().next(), uniAugmentation);
- }
-
- @Test
- public void testGetUni() {
- Node node = mock(Node.class);
- List<Node> ndList = new ArrayList<Node>();
- ndList.add(node);
- Topology topology = mock (Topology.class);
- DataBroker dataBroker = mock(DataBroker.class);
- UniAugmentation uniAugmentation = mock(UniAugmentation.class);
- IpAddress ipAddreDest = new IpAddress("10.10.0.2".toCharArray());
- InstanceIdentifier<Topology> topologyInstanceIdentifier = mock(InstanceIdentifier.class);
- MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getUniTopologyIid"));
- when(UnimgrMapper.getUniTopologyIid()).thenReturn(topologyInstanceIdentifier);
- MemberModifier.suppress(MemberMatcher.method(UnimgrUtils.class, "read", DataBroker.class, LogicalDatastoreType.class, InstanceIdentifier.class));
- when(UnimgrUtils.read(any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(topology);
- when(topology.getNode()).thenReturn(ndList);
- when(node.getAugmentation(UniAugmentation.class)).thenReturn(uniAugmentation);
- when(uniAugmentation.getIpAddress()).thenReturn(ipAddreDest);
- MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getUniTopologyIid"));
- when(UnimgrMapper.getUniTopologyIid()).thenReturn(topologyInstanceIdentifier);
- UniAugmentation expectedUniAug = UnimgrUtils.getUni(dataBroker, LogicalDatastoreType.CONFIGURATION, ipAddreDest);
- assertNotNull(expectedUniAug);
- assertEquals(expectedUniAug, uniAugmentation);
- }
-
- @Test
- public void testRead() throws ReadFailedException {
- DataBroker dataBroker = mock(DataBroker.class);
- InstanceIdentifier<Node> nodeIid = PowerMockito.mock(InstanceIdentifier.class);
- ReadOnlyTransaction transaction = mock(ReadOnlyTransaction.class);
- when(dataBroker.newReadOnlyTransaction()).thenReturn(transaction);
- Optional<Node> optionalDataObject = mock(Optional.class);
- CheckedFuture<Optional<Node>, ReadFailedException> future = mock(CheckedFuture.class);
- Node nd = mock(Node.class);
- when(transaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(future);
- when(future.checkedGet()).thenReturn(optionalDataObject);
- when(optionalDataObject.isPresent()).thenReturn(true);
- when(optionalDataObject.get()).thenReturn(nd);
- Node expectedNode = UnimgrUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, nodeIid);
- verify(transaction).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
- verify(transaction).close();
- assertNotNull(expectedNode);
- assertEquals(expectedNode, nd);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testReadLink() throws ReadFailedException {
- LinkId linkId = new LinkId("evc://7011db35-f44b-4aab-90f6-d89088caf9d8");
- InstanceIdentifier<?> nodeIid = InstanceIdentifier
- .create(NetworkTopology.class)
- .child(Topology.class,
- new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID))
- .child(Link.class,
- new LinkKey(linkId));
- ReadOnlyTransaction transaction = mock(ReadOnlyTransaction.class);
- when(dataBroker.newReadOnlyTransaction()).thenReturn(transaction);
- CheckedFuture<Optional<Link>, ReadFailedException> linkFuture = mock(CheckedFuture.class);
- Optional<Link> optLink = mock(Optional.class);
- when(transaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(linkFuture);
- when(linkFuture.checkedGet()).thenReturn(optLink);
- Optional<Link> expectedOpt = UnimgrUtils.readLink(dataBroker, LogicalDatastoreType.CONFIGURATION, nodeIid);
- verify(transaction).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
- assertNotNull(expectedOpt);
- assertEquals(expectedOpt, optLink);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testReadNode() throws ReadFailedException {
- InstanceIdentifier<?> nodeIid = InstanceIdentifier
- .create(NetworkTopology.class)
- .child(Topology.class,
- new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
- .child(Node.class,
- new NodeKey(OVSDB_NODE_ID));
- ReadOnlyTransaction transaction = mock(ReadOnlyTransaction.class);
- when(dataBroker.newReadOnlyTransaction()).thenReturn(transaction);
- CheckedFuture<Optional<Node>, ReadFailedException> nodeFuture = mock(CheckedFuture.class);
- Optional<Node> optNode = mock(Optional.class);
- when(transaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(nodeFuture);
- when(nodeFuture.checkedGet()).thenReturn(optNode);
- Optional<Node> expectedOpt = UnimgrUtils.readNode(dataBroker, LogicalDatastoreType.CONFIGURATION, nodeIid);
- verify(transaction).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
- assertNotNull(expectedOpt);
- assertEquals(expectedOpt, optNode);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testUpdateUniNode() {
- UniAugmentation uni = PowerMockito.mock(UniAugmentation.class);
- InstanceIdentifier<?> uniKey = InstanceIdentifier
- .create(NetworkTopology.class)
- .child(Topology.class,
- new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))//Any node id is fine for tests
- .child(Node.class,
- new NodeKey(OVSDB_NODE_ID));
- InstanceIdentifier<Node> ovsdbNodeIid = mock(InstanceIdentifier.class);
- Optional<Node> optionalNode = mock(Optional.class);
- Node nd = mock(Node.class, Mockito.RETURNS_MOCKS);
- when(optionalNode.isPresent()).thenReturn(true);
- when(optionalNode.get()).thenReturn(nd);
- WriteTransaction transaction = mock(WriteTransaction.class);
- when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
- doNothing().when(transaction).put(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(Node.class));
- MemberModifier.suppress(MemberMatcher.method(UnimgrUtils.class, "readNode", DataBroker.class, LogicalDatastoreType.class, InstanceIdentifier.class));
- when(UnimgrUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(optionalNode);
- UnimgrUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL, uniKey, uni, ovsdbNodeIid, dataBroker);
- verify(transaction).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class));
- verify(transaction).submit();
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testUpdateUniNode2() {
- UniAugmentation uni = PowerMockito.mock(UniAugmentation.class);
- InstanceIdentifier<?> uniKey = InstanceIdentifier
- .create(NetworkTopology.class)
- .child(Topology.class,
- new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
- .child(Node.class,
- new NodeKey(OVSDB_NODE_ID));//Any node id is fine for tests
- Node ovsdbNode = mock(Node.class);
- InstanceIdentifier<Node> ovsdbNodeIid = mock(InstanceIdentifier.class);
- Optional<Node> optionalNode = mock(Optional.class);
- Node nd = mock(Node.class);
- when(optionalNode.isPresent()).thenReturn(true);
- when(optionalNode.get()).thenReturn(nd);
- doNothing().when(transaction).put(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(Node.class));
- when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
- MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getOvsdbNodeIid", NodeId.class));
- when(UnimgrMapper.getOvsdbNodeIid(any(NodeId.class))).thenReturn(ovsdbNodeIid);
- MemberModifier.suppress(MemberMatcher.method(UnimgrUtils.class, "readNode", DataBroker.class, LogicalDatastoreType.class, InstanceIdentifier.class));
- when(UnimgrUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(optionalNode);
- UnimgrUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL, uniKey, uni, ovsdbNode, dataBroker);
- verify(transaction).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class));
- verify(transaction).submit();
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testUpdateEvcNode() {
- LinkId id = new LinkId("abcde");
- InstanceIdentifier<?> evcKey = InstanceIdentifier
- .create(NetworkTopology.class)
- .child(Topology.class,
- new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID))
- .child(Link.class,
- new LinkKey(id));
- InstanceIdentifier<?> sourceUniIid = PowerMockito.mock(InstanceIdentifier.class);
- InstanceIdentifier<?> destinationUniIid = PowerMockito.mock(InstanceIdentifier.class);
- WriteTransaction transaction = mock(WriteTransaction.class);
- when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
- Short order = new Short("0");
- IpAddress ipAddreSource = new IpAddress("10.10.1.1".toCharArray());
- UniSource uniSource = new UniSourceBuilder()
- .setIpAddress(ipAddreSource)
- .setKey(new UniSourceKey(order))
- .setOrder(order)
- .build();
- List<UniSource> uniSourceList = new ArrayList<UniSource>();
- uniSourceList.add(uniSource);
- IpAddress ipAddreDest = new IpAddress("10.10.0.2".toCharArray());
- UniDest uniDest = new UniDestBuilder()
- .setOrder(order)
- .setKey(new UniDestKey(order))
- .setIpAddress(ipAddreDest)
- .build();
- List<UniDest> uniDestList = new ArrayList<UniDest>();
- uniDestList.add(uniDest);
- EgressBw egressBw = mock(EgressBw.class);
- IngressBw ingressBw = mock(IngressBw.class);
- EvcAugmentation evcAug = new EvcAugmentationBuilder()
- .setCosId(UnimgrConstants.EVC_PREFIX + 1)
- .setEgressBw(egressBw)
- .setIngressBw(ingressBw)
- .setUniDest(uniDestList)
- .setUniSource(uniSourceList)
- .build();
- Optional<Link> optionalEvcLink = mock(Optional.class);
- Link lnk = mock (Link.class);
- when(optionalEvcLink.isPresent()).thenReturn(true);
- when(optionalEvcLink.get()).thenReturn(lnk);
- MemberModifier.suppress(MemberMatcher.method(UnimgrUtils.class, "readLink", DataBroker.class, LogicalDatastoreType.class, InstanceIdentifier.class));
- when(UnimgrUtils.readLink(any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(optionalEvcLink);
- doNothing().when(transaction).put(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(Node.class));
- UnimgrUtils.updateEvcNode(LogicalDatastoreType.OPERATIONAL, evcKey, evcAug,
- sourceUniIid, destinationUniIid, dataBroker);
- verify(transaction).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class));
- verify(transaction).submit();
- }
-
-}
--- /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.utils;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+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.WriteTransaction;
+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.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeRef;
+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.EvcAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentationBuilder;
+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.evc.EgressBw;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.IngressBw;
+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.UniDestBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDestKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSource;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSourceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSourceKey;
+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.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.InstanceIdentifier;
+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;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+
+import ch.qos.logback.core.Appender;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({LogicalDatastoreType.class, UnimgrMapper.class, EvcUtils.class, MdsalUtils.class})
+public class EvcUtilsTest {
+
+ @Rule
+ public final ExpectedException exception = ExpectedException.none();
+ @Mock private DataBroker dataBroker;
+ @Mock private Node bridgeNode;
+ @Mock private String bridgeName;
+ @Mock private String portName;
+ @Mock private String type;
+ @Mock private WriteTransaction transaction;
+ @Mock private IpAddress mockIp;
+ @SuppressWarnings("rawtypes")
+ @Mock private Appender mockAppender;
+ @SuppressWarnings({ "rawtypes" })
+ @Mock private CheckedFuture checkedFuture;
+ private ch.qos.logback.classic.Logger root;
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setUp() throws Exception {
+ PowerMockito.mockStatic(EvcUtils.class, Mockito.CALLS_REAL_METHODS);
+ PowerMockito.mockStatic(MdsalUtils.class, Mockito.CALLS_REAL_METHODS);
+ PowerMockito.mockStatic(UnimgrMapper.class, Mockito.CALLS_REAL_METHODS);
+ PowerMockito.mockStatic(LogicalDatastoreType.class);
+ root = (ch.qos.logback.classic.Logger)
+ LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+ // Check logger messages
+ when(mockAppender.getName()).thenReturn("MOCK");
+ root.addAppender(mockAppender);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testGetEvcLinks() {
+ Link link = mock(Link.class);
+ List<Link> lnkList = new ArrayList<Link>();
+ lnkList.add(link);
+ Topology topology = mock (Topology.class);
+ DataBroker dataBroker = mock(DataBroker.class);
+ EvcAugmentation evcAugmentation = mock(EvcAugmentation.class, Mockito.RETURNS_MOCKS);
+ InstanceIdentifier<Topology> topologyInstanceIdentifier = mock(InstanceIdentifier.class);
+ MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getEvcTopologyIid"));
+ when(UnimgrMapper.getEvcTopologyIid()).thenReturn(topologyInstanceIdentifier);
+ MemberModifier.suppress(MemberMatcher.method(MdsalUtils.class, "read", DataBroker.class, LogicalDatastoreType.class, InstanceIdentifier.class));
+ when(MdsalUtils.read(any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(topology);
+ when(topology.getLink()).thenReturn(lnkList);
+ when(link.getAugmentation(EvcAugmentation.class)).thenReturn(evcAugmentation);
+ List<Link> expectedListLink = EvcUtils.getEvcLinks(dataBroker);
+ assertNotNull(expectedListLink);
+ assertEquals(expectedListLink.get(0), link);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testUpdateEvcNode() {
+ LinkId id = new LinkId("abcde");
+ InstanceIdentifier<?> evcKey = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class,
+ new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID))
+ .child(Link.class,
+ new LinkKey(id));
+ InstanceIdentifier<?> sourceUniIid = PowerMockito.mock(InstanceIdentifier.class);
+ InstanceIdentifier<?> destinationUniIid = PowerMockito.mock(InstanceIdentifier.class);
+ WriteTransaction transaction = mock(WriteTransaction.class);
+ when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
+ Short order = new Short("0");
+ IpAddress ipAddreSource = new IpAddress("10.10.1.1".toCharArray());
+ UniSource uniSource = new UniSourceBuilder()
+ .setIpAddress(ipAddreSource)
+ .setKey(new UniSourceKey(order))
+ .setOrder(order)
+ .build();
+ List<UniSource> uniSourceList = new ArrayList<UniSource>();
+ uniSourceList.add(uniSource);
+ IpAddress ipAddreDest = new IpAddress("10.10.0.2".toCharArray());
+ UniDest uniDest = new UniDestBuilder()
+ .setOrder(order)
+ .setKey(new UniDestKey(order))
+ .setIpAddress(ipAddreDest)
+ .build();
+ List<UniDest> uniDestList = new ArrayList<UniDest>();
+ uniDestList.add(uniDest);
+ EgressBw egressBw = mock(EgressBw.class);
+ IngressBw ingressBw = mock(IngressBw.class);
+ EvcAugmentation evcAug = new EvcAugmentationBuilder()
+ .setCosId(UnimgrConstants.EVC_PREFIX + 1)
+ .setEgressBw(egressBw)
+ .setIngressBw(ingressBw)
+ .setUniDest(uniDestList)
+ .setUniSource(uniSourceList)
+ .build();
+ Optional<Link> optionalEvcLink = mock(Optional.class);
+ Link lnk = mock (Link.class);
+ when(optionalEvcLink.isPresent()).thenReturn(true);
+ when(optionalEvcLink.get()).thenReturn(lnk);
+ MemberModifier.suppress(MemberMatcher.method(MdsalUtils.class, "readLink", DataBroker.class, LogicalDatastoreType.class, InstanceIdentifier.class));
+ when(MdsalUtils.readLink(any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(optionalEvcLink);
+ doNothing().when(transaction).put(any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class),
+ any(Node.class));
+ EvcUtils.updateEvcNode(LogicalDatastoreType.OPERATIONAL, evcKey, evcAug,
+ sourceUniIid, destinationUniIid, dataBroker);
+ verify(transaction).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class));
+ verify(transaction).submit();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testDeleteEvcData() {
+ DataBroker dataBroker = mock(DataBroker.class);
+ Optional<Node> optionalUni = mock(Optional.class);
+ when(optionalUni.isPresent()).thenReturn(true);
+ Node node = mock(Node.class);
+ when(optionalUni.get()).thenReturn(node);
+ UniAugmentation uniAugmentation = mock(UniAugmentation.class);
+ when(node.getAugmentation(UniAugmentation.class)).thenReturn(uniAugmentation);
+ OvsdbNodeRef ovsdbNodeRef = mock(OvsdbNodeRef.class);
+ InstanceIdentifier<Node> iid = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class, new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
+ .child(Node.class, new NodeKey(new NodeId("uni://10.0.0.1")));
+ when((InstanceIdentifier<Node>) ovsdbNodeRef.getValue()).thenReturn(iid);
+ when(uniAugmentation.getOvsdbNodeRef()).thenReturn(ovsdbNodeRef);
+ MemberModifier.suppress(MemberMatcher.method(MdsalUtils.class, "readNode", DataBroker.class, LogicalDatastoreType.class, InstanceIdentifier.class));
+ Optional<Node> optionalOvsdNode = mock(Optional.class);
+ when(MdsalUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(optionalOvsdNode);
+ when(optionalOvsdNode.isPresent()).thenReturn(true);
+ Node ovsdbNode = mock(Node.class);
+ when(optionalOvsdNode.get()).thenReturn(ovsdbNode);
+ OvsdbNodeAugmentation ovsdbNodeAugmentation = mock(OvsdbNodeAugmentation.class);
+ when(ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class)).thenReturn(ovsdbNodeAugmentation);
+ List<ManagedNodeEntry> managedNodeEntryList = new ArrayList<>();
+ ManagedNodeEntry managedNodeEntry = mock(ManagedNodeEntry.class);
+ managedNodeEntryList.add(managedNodeEntry);
+ when(ovsdbNodeAugmentation.getManagedNodeEntry()).thenReturn(managedNodeEntryList);
+ OvsdbBridgeRef ovsdbBridgeRef = mock(OvsdbBridgeRef.class);
+ when(managedNodeEntry.getBridgeRef()).thenReturn(ovsdbBridgeRef);
+ InstanceIdentifier<Node> bridgeIid = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class, new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
+ .child(Node.class, new NodeKey(new NodeId("ovsbr0")));
+ when((InstanceIdentifier<Node>) ovsdbBridgeRef.getValue()).thenReturn(bridgeIid);
+ MemberModifier.suppress(MemberMatcher.method(MdsalUtils.class, "readNode", DataBroker.class, InstanceIdentifier.class));
+ Optional<Node> optBridgeNode = mock(Optional.class);
+ when(MdsalUtils.readNode(any(DataBroker.class), any(InstanceIdentifier.class))).thenReturn(optBridgeNode);
+ when(optBridgeNode.isPresent()).thenReturn(true);
+ when(optBridgeNode.get()).thenReturn(bridgeNode);
+
+ MemberModifier.suppress(MemberMatcher.method(MdsalUtils.class, "deleteNode", DataBroker.class, InstanceIdentifier.class,LogicalDatastoreType.class));
+ when(MdsalUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class), any(LogicalDatastoreType.class))).thenReturn(true);
+ PowerMockito.mockStatic(UnimgrMapper.class);
+ when(UnimgrMapper.getTerminationPointIid(any(Node.class), anyString())).thenReturn(mock(InstanceIdentifier.class));
+ when(UnimgrMapper.getTerminationPointIid(any(Node.class), anyString())).thenReturn(mock(InstanceIdentifier.class));
+ EvcUtils.deleteEvcData(dataBroker, optionalUni);
+ verify(optionalUni).isPresent();
+ verify(optionalOvsdNode).isPresent();
+ }
+}
--- /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.utils;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatcher;
+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.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+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.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.InstanceIdentifier;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+
+import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.core.Appender;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({LogicalDatastoreType.class, EvcUtils.class})
+public class MdsalUtilsTest {
+
+ @Rule
+ public final ExpectedException exception = ExpectedException.none();
+ @Mock private DataBroker dataBroker;
+ @Mock private Node bridgeNode;
+ @Mock private String bridgeName;
+ @Mock private String portName;
+ @Mock private String type;
+ @Mock private WriteTransaction transaction;
+ @Mock private IpAddress mockIp;
+ @SuppressWarnings("rawtypes")
+ @Mock private Appender mockAppender;
+ @SuppressWarnings({ "rawtypes" })
+ @Mock private CheckedFuture checkedFuture;
+ private static final NodeId OVSDB_NODE_ID = new NodeId("ovsdb://7011db35-f44b-4aab-90f6-d89088caf9d8");
+ private ch.qos.logback.classic.Logger root;
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setUp() throws Exception {
+ PowerMockito.mockStatic(MdsalUtils.class, Mockito.CALLS_REAL_METHODS);
+ PowerMockito.mockStatic(LogicalDatastoreType.class);
+ root = (ch.qos.logback.classic.Logger)
+ LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+ // Check logger messages
+ when(mockAppender.getName()).thenReturn("MOCK");
+ root.addAppender(mockAppender);
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Test
+ public void testDeleteNode() throws Exception {
+ InstanceIdentifier<Node> genericNode = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class,
+ new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
+ .child(Node.class);
+ when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
+ doNothing().when(transaction).delete(any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class));
+ when(transaction.submit()).thenReturn(checkedFuture);
+ assertEquals(true, MdsalUtils.deleteNode(dataBroker, genericNode, LogicalDatastoreType.CONFIGURATION));
+ verify(transaction).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
+ verify(transaction).submit();
+ verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
+ @Override
+ public boolean matches(final Object argument) {
+ return ((LoggingEvent)argument).getFormattedMessage().contains("Received a request to delete node");
+ }
+ }));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testRead() throws ReadFailedException {
+ DataBroker dataBroker = mock(DataBroker.class);
+ InstanceIdentifier<Node> nodeIid = PowerMockito.mock(InstanceIdentifier.class);
+ ReadOnlyTransaction transaction = mock(ReadOnlyTransaction.class);
+ when(dataBroker.newReadOnlyTransaction()).thenReturn(transaction);
+ Optional<Node> optionalDataObject = mock(Optional.class);
+ CheckedFuture<Optional<Node>, ReadFailedException> future = mock(CheckedFuture.class);
+ Node nd = mock(Node.class);
+ when(transaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(future);
+ when(future.checkedGet()).thenReturn(optionalDataObject);
+ when(optionalDataObject.isPresent()).thenReturn(true);
+ when(optionalDataObject.get()).thenReturn(nd);
+ Node expectedNode = MdsalUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, nodeIid);
+ verify(transaction).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
+ verify(transaction).close();
+ assertNotNull(expectedNode);
+ assertEquals(expectedNode, nd);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testReadLink() throws ReadFailedException {
+ LinkId linkId = new LinkId("evc://7011db35-f44b-4aab-90f6-d89088caf9d8");
+ InstanceIdentifier<?> nodeIid = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class,
+ new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID))
+ .child(Link.class,
+ new LinkKey(linkId));
+ ReadOnlyTransaction transaction = mock(ReadOnlyTransaction.class);
+ when(dataBroker.newReadOnlyTransaction()).thenReturn(transaction);
+ CheckedFuture<Optional<Link>, ReadFailedException> linkFuture = mock(CheckedFuture.class);
+ Optional<Link> optLink = mock(Optional.class);
+ when(transaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(linkFuture);
+ when(linkFuture.checkedGet()).thenReturn(optLink);
+ Optional<Link> expectedOpt = MdsalUtils.readLink(dataBroker, LogicalDatastoreType.CONFIGURATION, nodeIid);
+ verify(transaction).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
+ assertNotNull(expectedOpt);
+ assertEquals(expectedOpt, optLink);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testReadNode() throws ReadFailedException {
+ InstanceIdentifier<?> nodeIid = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class,
+ new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
+ .child(Node.class,
+ new NodeKey(OVSDB_NODE_ID));
+ ReadOnlyTransaction transaction = mock(ReadOnlyTransaction.class);
+ when(dataBroker.newReadOnlyTransaction()).thenReturn(transaction);
+ CheckedFuture<Optional<Node>, ReadFailedException> nodeFuture = mock(CheckedFuture.class);
+ Optional<Node> optNode = mock(Optional.class);
+ when(transaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(nodeFuture);
+ when(nodeFuture.checkedGet()).thenReturn(optNode);
+ Optional<Node> expectedOpt = MdsalUtils.readNode(dataBroker, LogicalDatastoreType.CONFIGURATION, nodeIid);
+ verify(transaction).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
+ assertNotNull(expectedOpt);
+ assertEquals(expectedOpt, optNode);
+ }
+}
--- /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.utils;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Matchers.eq;
+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.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatcher;
+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.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.ovsdb.southbound.SouthboundConstants;
+import org.opendaylight.unimgr.impl.UnimgrConstants;
+import org.opendaylight.unimgr.impl.UnimgrMapper;
+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.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeProtocolBase;
+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.OvsdbNodeAugmentationBuilder;
+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.OvsdbPortInterfaceAttributes.VlanMode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntryBuilder;
+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.ConnectionInfoBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.Uni;
+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.TpId;
+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.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
+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.MemberMatcher;
+import org.powermock.api.support.membermodification.MemberModifier;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableBiMap;
+import com.google.common.util.concurrent.CheckedFuture;
+
+import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.core.Appender;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({LogicalDatastoreType.class, UnimgrMapper.class, OvsdbUtils.class, MdsalUtils.class, UUID.class})
+public class OvsdbUtilsTest {
+
+ @Rule
+ public final ExpectedException exception = ExpectedException.none();
+ @Mock private DataBroker dataBroker;
+ @Mock private Node bridgeNode;
+ @Mock private String bridgeName;
+ @Mock private String portName;
+ @Mock private String type;
+ @Mock private WriteTransaction transaction;
+ @Mock private IpAddress mockIp;
+ @SuppressWarnings("rawtypes")
+ @Mock private Appender mockAppender;
+ @SuppressWarnings({ "rawtypes" })
+ @Mock private CheckedFuture checkedFuture;
+ @SuppressWarnings("unchecked")
+ private static final InstanceIdentifier<TerminationPoint> tpIid = PowerMockito.mock(InstanceIdentifier.class);
+ private static final IpAddress IP = new IpAddress(new Ipv4Address("192.168.1.2"));
+ private static final NodeId OVSDB_NODE_ID = new NodeId("ovsdb://7011db35-f44b-4aab-90f6-d89088caf9d8");
+ @SuppressWarnings("unchecked")
+ private static final InstanceIdentifier<Node> MOCK_NODE_IID = PowerMockito.mock(InstanceIdentifier.class);
+ private ch.qos.logback.classic.Logger root;
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setUp() throws Exception {
+ PowerMockito.mockStatic(OvsdbUtils.class, Mockito.CALLS_REAL_METHODS);
+ PowerMockito.mockStatic(MdsalUtils.class, Mockito.CALLS_REAL_METHODS);
+ PowerMockito.mockStatic(UnimgrMapper.class, Mockito.CALLS_REAL_METHODS);
+ PowerMockito.mockStatic(LogicalDatastoreType.class);
+ PowerMockito.mockStatic(UUID.class);
+ root = (ch.qos.logback.classic.Logger)
+ LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+ // Check logger messages
+ when(mockAppender.getName()).thenReturn("MOCK");
+ root.addAppender(mockAppender);
+ }
+
+ /*
+ * This test for 2 functions with the
+ * same name that take different parameters.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ @Test
+ public void testCreateBridgeNode() throws Exception {
+ // Function 1
+ Node ovsdbNode = new NodeBuilder().setNodeId(OVSDB_NODE_ID).build();
+ InstanceIdentifier<Node> nodeIid = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class,
+ new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
+ .child(Node.class,
+ new NodeKey(OVSDB_NODE_ID));
+ OvsdbNodeRef ovsdbNodeRef = new OvsdbNodeRef(nodeIid);
+ UniAugmentation uni = new UniAugmentationBuilder()
+ .setIpAddress(new IpAddress(new Ipv4Address("192.168.1.1")))
+ .setOvsdbNodeRef(ovsdbNodeRef)
+ .build();
+
+ when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
+ doNothing().when(transaction).put(any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class),
+ any(Node.class));
+ when(transaction.submit()).thenReturn(checkedFuture);
+ MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "createOvsdbBridgeNodeIid", Node.class, String.class));
+ when(UnimgrMapper.createOvsdbBridgeNodeIid(any(Node.class),
+ any(String.class))).thenReturn(MOCK_NODE_IID);
+ OvsdbUtils.createBridgeNode(dataBroker, ovsdbNode, uni, "br0");
+ verify(transaction).put(any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class),
+ any(Node.class));
+ verify(transaction).submit();
+
+ // Function 2
+ MemberModifier.suppress(MemberMatcher.method(MdsalUtils.class,
+ "readNode",
+ DataBroker.class,
+ LogicalDatastoreType.class,
+ InstanceIdentifier.class));
+ Optional<Node> mockOptional = mock(Optional.class);
+ when(MdsalUtils.readNode(any(DataBroker.class),
+ any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class))).thenReturn(mockOptional);
+ OvsdbUtils.createBridgeNode(dataBroker, nodeIid, uni, "br0");
+ verify(transaction).put(any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class),
+ any(Node.class));
+ verify(transaction).submit();
+
+ // Ensure correct logging
+ verify(mockAppender, times(2)).doAppend(argThat(new ArgumentMatcher() {
+ @Override
+ public boolean matches(final Object argument) {
+ return ((LoggingEvent)argument).getFormattedMessage().contains("Creating a bridge on node");
+ }
+ }));
+ }
+
+ @Test
+ public void testCreateControllerEntries() {
+ String targetString = new String("controllerEntry");
+ List<ControllerEntry> controllerEntries = new ArrayList<ControllerEntry>();
+ ControllerEntryBuilder controllerEntryBuilder = new ControllerEntryBuilder();
+ controllerEntryBuilder.setTarget(new Uri(targetString));
+ controllerEntries.add(controllerEntryBuilder.build());
+ assertEquals(controllerEntries, OvsdbUtils.createControllerEntries(targetString));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testCreateGreTunnel() throws Exception {
+
+ UniAugmentation sourceUniAug = new UniAugmentationBuilder()
+ .setIpAddress(new IpAddress(new Ipv4Address("192.168.1.1")))
+ .build();
+ UniAugmentation destUniAug = new UniAugmentationBuilder()
+ .setIpAddress(new IpAddress(new Ipv4Address("192.168.1.2")))
+ .build();
+
+ when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
+ doNothing().when(transaction).put(any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class),
+ any(TerminationPoint.class));
+ when(transaction.submit()).thenReturn(checkedFuture);
+
+ MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getTerminationPointIid", Node.class, String.class));
+ MemberModifier.suppress(MemberMatcher.method(OvsdbUtils.class, "createMdsalProtocols"));
+
+ Node bNode = new NodeBuilder().setKey(new NodeKey(OVSDB_NODE_ID)).build();
+ InstanceIdentifier<TerminationPoint> tpIid = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class,
+ new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
+ .child(Node.class, bNode.getKey())
+ .child(TerminationPoint.class,
+ new TerminationPointKey(new TpId(portName)));
+ when(UnimgrMapper.getTerminationPointIid(any(Node.class), any(String.class))).thenReturn(tpIid);
+ OvsdbUtils.createGreTunnel(dataBroker,
+ sourceUniAug,
+ destUniAug,
+ bridgeNode,
+ bridgeName,
+ portName);
+ verify(transaction).put(any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class),
+ any(TerminationPoint.class));
+ verify(transaction).submit();
+ }
+
+ @Test
+ public void testCreateMdsalProtocols() {
+ List<ProtocolEntry> protocolList = new ArrayList<ProtocolEntry>();
+ ImmutableBiMap<String, Class<? extends OvsdbBridgeProtocolBase>> mapper =
+ SouthboundConstants.OVSDB_PROTOCOL_MAP.inverse();
+ ProtocolEntry protoEntry = new ProtocolEntryBuilder().setProtocol((Class<? extends OvsdbBridgeProtocolBase>) mapper.get("OpenFlow13")).build();
+ protocolList.add(protoEntry);
+ assertEquals(protocolList, OvsdbUtils.createMdsalProtocols());
+ }
+
+ @Test
+ public void testCreateOvsdbBridgeAugmentation() throws Exception {
+ OvsdbNodeRef ovsdbNodeRef = new OvsdbNodeRef(PowerMockito.mock(InstanceIdentifier.class));
+ UniAugmentation uni = new UniAugmentationBuilder().setOvsdbNodeRef(ovsdbNodeRef).build();
+ UUID bridgeUuid = PowerMockito.mock(UUID.class);
+ PowerMockito.when(UUID.randomUUID()).thenReturn(bridgeUuid);
+ OvsdbBridgeAugmentation ovsdbNode = new OvsdbBridgeAugmentationBuilder()
+ .setBridgeName(new OvsdbBridgeName(UnimgrConstants.DEFAULT_BRIDGE_NAME))
+ .setManagedBy(ovsdbNodeRef)
+ .setBridgeUuid(new Uuid(bridgeUuid.toString()))
+ .build();
+ assertEquals(ovsdbNode, OvsdbUtils.createOvsdbBridgeAugmentation(uni));
+ // Force an exception
+ Uni ovsdbNodeRefNull = new UniAugmentationBuilder().setOvsdbNodeRef(null).build();
+ exception.expect(Exception.class);
+ OvsdbUtils.createOvsdbBridgeAugmentation(ovsdbNodeRefNull);
+ }
+
+ /*
+ * This test for 2 functions with the
+ * same name that take different parameters.
+ */
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Test
+ public void testCreateOvsdbNode() {
+ MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getOvsdbNodeIid", IpAddress.class));
+ PowerMockito.when(UnimgrMapper.getOvsdbNodeIid(mockIp)).thenReturn(MOCK_NODE_IID);
+ when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
+ //when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
+ Uni uni = new UniAugmentationBuilder().setIpAddress(new IpAddress(new Ipv4Address("192.168.1.2"))).build();
+ // createOvsdbNode with NodeId and Uni
+ OvsdbUtils.createOvsdbNode(dataBroker, OVSDB_NODE_ID, uni);
+ // Ensure correct logging
+ verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
+ @Override
+ public boolean matches(final Object argument) {
+ return ((LoggingEvent)argument).getFormattedMessage().contains("Created and submitted a new OVSDB node");
+ }
+ }));
+ doNothing().when(transaction).put(any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class),
+ any(Node.class));
+ when(transaction.submit()).thenReturn(checkedFuture);
+ verify(transaction).put(any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class),
+ any(Node.class));
+ verify(transaction).submit();
+ // Test with a null uni
+ exception.expect(Exception.class);
+ OvsdbUtils.createOvsdbNode(dataBroker, OVSDB_NODE_ID, null);
+ // Ensure correct logging
+ verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
+ @Override
+ public boolean matches(final Object argument) {
+ return ((LoggingEvent)argument).getFormattedMessage().contains("Created and submitted a new OVSDB node");
+ }
+ }));
+ // createOvsdbNode with Uni
+ UniAugmentation uniAug = new UniAugmentationBuilder(uni).build();
+ OvsdbUtils.createOvsdbNode(dataBroker, uniAug);
+ MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getOvsdbNodeIid", NodeId.class));
+ PowerMockito.when(UnimgrMapper.getOvsdbNodeIid(any(NodeId.class))).thenReturn(MOCK_NODE_IID);
+ doNothing().when(transaction).put(any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class),
+ any(Node.class));
+ when(transaction.submit()).thenReturn(checkedFuture);
+ verify(transaction).put(any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class),
+ any(Node.class));
+ verify(transaction).submit();
+ // try with a null uni
+ PowerMockito.when(UnimgrMapper.getOvsdbNodeIid(any(NodeId.class))).thenReturn(null);
+ OvsdbUtils.createOvsdbNode(dataBroker, null);
+ exception.expect(Exception.class);
+ OvsdbUtils.createOvsdbNode(dataBroker, null);
+ }
+
+ @Test
+ public void testCreateOvsdbNodeAugmentation() {
+ Uni uni = new UniAugmentationBuilder().setIpAddress(new IpAddress(new Ipv4Address("192.168.1.2"))).build();
+ ConnectionInfo connectionInfos = new ConnectionInfoBuilder()
+ .setRemoteIp(uni.getIpAddress())
+ .setRemotePort(new PortNumber(UnimgrConstants.OVSDB_PORT))
+ .build();
+ OvsdbNodeAugmentation ovsdbNode = new OvsdbNodeAugmentationBuilder()
+ .setConnectionInfo(connectionInfos).build();
+ assertEquals(ovsdbNode, OvsdbUtils.createOvsdbNodeAugmentation(uni));
+ }
+
+ @Test
+ public void testCreateOvsdbNodeId() {
+ String nodeId = UnimgrConstants.OVSDB_PREFIX
+ + IP.getIpv4Address().getValue().toString()
+ + ":"
+ + UnimgrConstants.OVSDB_PORT;
+ assertEquals(new NodeId(nodeId), OvsdbUtils.createOvsdbNodeId(IP));
+ }
+
+ @Test
+ public void testCreateOvsdbTerminationPointAugmentation() {
+ Uni uni = new UniAugmentationBuilder().build();
+ VlanId vlanID = new VlanId(1);
+ OvsdbTerminationPointAugmentation terminationPoint = new OvsdbTerminationPointAugmentationBuilder()
+ .setName(UnimgrConstants.DEFAULT_INTERNAL_IFACE)
+ .setVlanTag(vlanID)
+ .setVlanMode(VlanMode.Access)
+ .build();
+ assertEquals(terminationPoint, OvsdbUtils.createOvsdbTerminationPointAugmentation(uni));
+ }
+
+ /*
+ * This test for 2 functions with the
+ * same name that take different parameters.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testCreateTerminationPointNode() {
+ Uni uni = new UniAugmentationBuilder().build();
+ Node bridgeNode = new NodeBuilder().build();
+
+ MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class,
+ "getTerminationPointIid",
+ Node.class,
+ String.class));
+ PowerMockito.when(UnimgrMapper.getTerminationPointIid(any(Node.class),
+ any(String.class))).thenReturn(tpIid);
+ when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
+ Node bNode = new NodeBuilder().setKey(new NodeKey(OVSDB_NODE_ID)).build();
+ InstanceIdentifier<TerminationPoint> tpIid = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class,
+ new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
+ .child(Node.class, bNode.getKey())
+ .child(TerminationPoint.class,
+ new TerminationPointKey(new TpId(portName)));
+ when(UnimgrMapper.getTerminationPointIid(any(Node.class), any(String.class))).thenReturn(tpIid);
+ // Function 1
+ OvsdbUtils.createTerminationPointNode(dataBroker, uni, bNode, bridgeName, portName, type);
+
+ //Function 2
+ doNothing().when(transaction).put(any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class),
+ any(TerminationPoint.class));
+ when(transaction.submit()).thenReturn(checkedFuture);
+ OvsdbUtils.createTerminationPointNode(dataBroker, uni, bridgeNode, bridgeName, portName);
+ verify(transaction, times(2)).put(any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class),
+ any(TerminationPoint.class));
+ verify(transaction,times(2)).submit();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testDeleteTerminationPoint() {
+ TerminationPointKey tpKey = new TerminationPointKey(new TpId("abcde"));
+ TerminationPoint terminationPoint = new TerminationPointBuilder().setKey(tpKey).build();
+ Node ovsdbNode = new NodeBuilder().setKey(new NodeKey(OVSDB_NODE_ID)).build();
+ when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
+ doNothing().when(transaction).delete(any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class));
+
+ OvsdbUtils.deleteTerminationPoint(dataBroker, terminationPoint, ovsdbNode);
+ verify(transaction,times(2)).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
+ verify(transaction,times(2)).submit();
+ CheckedFuture<Void, TransactionCommitFailedException> mockCheckedFuture = mock(CheckedFuture.class);
+ when(transaction.submit()).thenReturn(mockCheckedFuture);
+ assertEquals(mockCheckedFuture, OvsdbUtils.deleteTerminationPoint(dataBroker, terminationPoint, ovsdbNode));
+ }
+
+ @Test
+ public void testExtract() {
+ Map<InstanceIdentifier<?>, DataObject> changes = new HashMap<>();
+ Class<DataObject> klazz = DataObject.class;
+ assertEquals(HashMap.class, OvsdbUtils.extract(changes, klazz).getClass());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testExtractOriginal() {
+ AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes = mock(AsyncDataChangeEvent.class);
+ Class<DataObject> klazz = DataObject.class;
+ Map<InstanceIdentifier<?>, DataObject> map = new HashMap<>();
+ when(changes.getOriginalData()).thenReturn(map);
+ Map<InstanceIdentifier<DataObject>, DataObject> map1 = new HashMap<>();
+ when(OvsdbUtils.extract(any(Map.class),eq(DataObject.class))).thenReturn(map1);
+ assertEquals(map1, OvsdbUtils.extractOriginal(changes, klazz));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testExtractRemoved() {
+ AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes = mock(AsyncDataChangeEvent.class);
+ Class<DataObject> klazz = DataObject.class;
+ assertEquals(HashSet.class, OvsdbUtils.extractRemoved(changes, klazz).getClass());
+ }
+
+ @Test
+ public void testFindOvsdbNode() {
+ List<Node> ovsdbNodes = new ArrayList<Node>();
+ UniAugmentation uni = new UniAugmentationBuilder()
+ .setIpAddress(IP)
+ .build();
+ ConnectionInfo connInfo = new ConnectionInfoBuilder().setRemoteIp(IP).build();
+ OvsdbNodeAugmentation augmentation = new OvsdbNodeAugmentationBuilder()
+ .setConnectionInfo(connInfo)
+ .build();
+ Node node = new NodeBuilder().addAugmentation(OvsdbNodeAugmentation.class, augmentation).build();
+ ovsdbNodes.add(node);
+ MemberModifier.suppress(MemberMatcher.method(OvsdbUtils.class,
+ "getOvsdbNodes",
+ DataBroker.class));
+ when(OvsdbUtils.getOvsdbNodes(any(DataBroker.class))).thenReturn(ovsdbNodes);
+ Optional<Node> optNode = Optional.of(node);
+ assertEquals(optNode, OvsdbUtils.findOvsdbNode(dataBroker, uni));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testGetConnectionInfo() {
+ DataBroker dataBroker = mock(DataBroker.class);
+ InstanceIdentifier<Node> nodeIid = PowerMockito.mock(InstanceIdentifier.class);
+ NodeId ovsdbNodeId = mock(NodeId.class);
+ Optional<Node> optNode = mock(Optional.class);
+ Node node = mock(Node.class);
+ OvsdbNodeAugmentation ovsdbNodeAugmentation = mock(OvsdbNodeAugmentation.class);
+ ConnectionInfo connectionInfo = mock(ConnectionInfo.class);
+ MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getOvsdbNodeIid", NodeId.class));
+ when(UnimgrMapper.getOvsdbNodeIid(any(NodeId.class))).thenReturn(nodeIid);
+ MemberModifier.suppress(MemberMatcher.method(MdsalUtils.class, "readNode", DataBroker.class, LogicalDatastoreType.class, InstanceIdentifier.class));
+ when(MdsalUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(optNode);
+ when(optNode.isPresent()).thenReturn(true);
+ when(optNode.get()).thenReturn(node);
+ when(node.getAugmentation(OvsdbNodeAugmentation.class)).thenReturn(ovsdbNodeAugmentation);
+ when(ovsdbNodeAugmentation.getConnectionInfo()).thenReturn(connectionInfo);
+ ConnectionInfo expectedConnInfo = OvsdbUtils.getConnectionInfo(dataBroker, ovsdbNodeId);
+ assertNotNull(expectedConnInfo);
+ assertEquals(expectedConnInfo, connectionInfo);
+ }
+
+ @Test
+ public void testGetLocalIp() {
+ String ip = "";
+ try {
+ ip = InetAddress.getLocalHost().getHostAddress();
+ } catch (UnknownHostException e) {
+ ip = "127.0.0.1";
+ }
+ IpAddress ipAddress = OvsdbUtils.getLocalIp();
+ assertNotNull(ipAddress);
+ String expectedIp = new String(ipAddress.getValue());
+ assertTrue(expectedIp.equals(ip));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testGetOvsdbNodes() {
+ Node node = mock(Node.class);
+ List<Node> ndList = new ArrayList<Node>();
+ ndList.add(node);
+ Topology topology = mock (Topology.class);
+ DataBroker dataBroker = mock(DataBroker.class);
+ OvsdbNodeAugmentation ovsNdAugmentation = mock(OvsdbNodeAugmentation.class, Mockito.RETURNS_MOCKS);
+ InstanceIdentifier<Topology> topologyInstanceIdentifier = mock(InstanceIdentifier.class);
+ MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getOvsdbTopologyIid"));
+ when(UnimgrMapper.getOvsdbTopologyIid()).thenReturn(topologyInstanceIdentifier);
+ MemberModifier.suppress(MemberMatcher.method(MdsalUtils.class, "read", DataBroker.class, LogicalDatastoreType.class, InstanceIdentifier.class));
+ when(MdsalUtils.read(any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(topology);
+ when(topology.getNode()).thenReturn(ndList);
+ when(node.getAugmentation(OvsdbNodeAugmentation.class)).thenReturn(ovsNdAugmentation);
+ List<Node> expectedListNnList = OvsdbUtils.getOvsdbNodes(dataBroker);
+ assertNotNull(expectedListNnList);
+ assertEquals(expectedListNnList.get(0), node);
+ }
+
+}
--- /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.utils;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatcher;
+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.WriteTransaction;
+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.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.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.NodeKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+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;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+
+import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.core.Appender;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({LogicalDatastoreType.class, UnimgrMapper.class, UniUtils.class, MdsalUtils.class})
+public class UniUtilsTest {
+
+ @Rule
+ public final ExpectedException exception = ExpectedException.none();
+ @Mock private DataBroker dataBroker;
+ @Mock private Node bridgeNode;
+ @Mock private String bridgeName;
+ @Mock private String portName;
+ @Mock private String type;
+ @Mock private WriteTransaction transaction;
+ @Mock private IpAddress mockIp;
+ @SuppressWarnings("rawtypes")
+ @Mock private Appender mockAppender;
+ @SuppressWarnings({ "rawtypes" })
+ @Mock private CheckedFuture checkedFuture;
+ private static final IpAddress IP = new IpAddress(new Ipv4Address("192.168.1.2"));
+ private static final NodeId OVSDB_NODE_ID = new NodeId("ovsdb://7011db35-f44b-4aab-90f6-d89088caf9d8");
+ @SuppressWarnings("unchecked")
+ private static final InstanceIdentifier<Node> MOCK_NODE_IID = PowerMockito.mock(InstanceIdentifier.class);
+ private ch.qos.logback.classic.Logger root;
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setUp() throws Exception {
+ PowerMockito.mockStatic(UniUtils.class, Mockito.CALLS_REAL_METHODS);
+ PowerMockito.mockStatic(MdsalUtils.class, Mockito.CALLS_REAL_METHODS);
+ PowerMockito.mockStatic(UnimgrMapper.class, Mockito.CALLS_REAL_METHODS);
+ PowerMockito.mockStatic(LogicalDatastoreType.class);
+ root = (ch.qos.logback.classic.Logger)
+ LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+ // Check logger messages
+ when(mockAppender.getName()).thenReturn("MOCK");
+ root.addAppender(mockAppender);
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Test
+ public void testCreateUniNode() {
+ UniAugmentation uniAug = new UniAugmentationBuilder()
+ .setIpAddress(new IpAddress(new Ipv4Address("192.168.1.2")))
+ .build();
+ when(UnimgrMapper.getUniNodeIid(any(NodeId.class))).thenReturn(mock(InstanceIdentifier.class));
+ doNothing().when(transaction).put(any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class),
+ any(Node.class));
+ when(transaction.submit()).thenReturn(checkedFuture);
+ assertEquals(false, UniUtils.createUniNode(dataBroker, uniAug));
+ verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
+ @Override
+ public boolean matches(final Object argument) {
+ return ((LoggingEvent)argument).getFormattedMessage().contains("Exception while creating Uni Node");
+ }
+ }));
+ MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getUniNodeIid", NodeId.class));
+ PowerMockito.when(UnimgrMapper.getUniNodeIid(any(NodeId.class))).thenReturn(MOCK_NODE_IID);
+
+ when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
+ UniUtils.createUniNode(dataBroker, uniAug);
+ verify(transaction).put(any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class),
+ any(Node.class));
+ verify(transaction).submit();
+ verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
+ @Override
+ public boolean matches(final Object argument) {
+ return ((LoggingEvent)argument).getFormattedMessage().contains("Created and submitted a new Uni");
+ }
+ }));
+ }
+
+ @Test
+ public void testCreateUniNodeId() {
+ NodeId nodeId = new NodeId(UnimgrConstants.UNI_PREFIX + IP.getIpv4Address().getValue().toString());
+ assertEquals(nodeId, UniUtils.createUniNodeId(IP));
+ }
+
+ @Test
+ public void testFindUniNode() {
+ DataBroker dataBroker = mock(DataBroker.class);
+ IpAddress ipAddress = mock(IpAddress.class);
+ UniAugmentation uniAugmentation = mock(UniAugmentation.class);
+ List<Node> uniNodes = new ArrayList<Node>();
+ Node nd = mock(Node.class);
+ uniNodes.add(nd);
+ MemberModifier.suppress(MemberMatcher.method(UniUtils.class, "getUniNodes", DataBroker.class));
+ when(UniUtils.getUniNodes(any(DataBroker.class))).thenReturn(uniNodes);
+ when(nd.getAugmentation(UniAugmentation.class)).thenReturn(uniAugmentation);
+ when(uniAugmentation.getIpAddress()).thenReturn(ipAddress);
+ Optional<Node> optNode = UniUtils.findUniNode(dataBroker, ipAddress);
+ assertNotNull(optNode);
+ assertTrue(optNode.isPresent());
+ uniNodes.remove(0);
+ optNode = UniUtils.findUniNode(dataBroker, ipAddress);
+ assertTrue(Optional.absent() == Optional.absent());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testGetUniNodes() {
+ Node node = mock(Node.class);
+ List<Node> ndList = new ArrayList<Node>();
+ ndList.add(node);
+ Topology topology = mock (Topology.class);
+ DataBroker dataBroker = mock(DataBroker.class);
+ UniAugmentation uniAugmentation = mock(UniAugmentation.class);
+ InstanceIdentifier<Topology> topologyInstanceIdentifier = mock(InstanceIdentifier.class);
+ MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getUniTopologyIid"));
+ when(UnimgrMapper.getUniTopologyIid()).thenReturn(topologyInstanceIdentifier);
+ MemberModifier.suppress(MemberMatcher.method(MdsalUtils.class, "read", DataBroker.class, LogicalDatastoreType.class, InstanceIdentifier.class));
+ when(MdsalUtils.read(any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(topology);
+ when(topology.getNode()).thenReturn(ndList);
+ when(node.getAugmentation(UniAugmentation.class)).thenReturn(uniAugmentation);
+ List<Node> expectedListNnList = UniUtils.getUniNodes(dataBroker);
+ assertNotNull(expectedListNnList);
+ assertEquals(expectedListNnList, ndList);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testGetUniNodes2() {
+ Node node = mock(Node.class);
+ List<Node> ndList = new ArrayList<Node>();
+ ndList.add(node);
+ Topology topology = mock (Topology.class);
+ DataBroker dataBroker = mock(DataBroker.class);
+ UniAugmentation uniAugmentation = mock(UniAugmentation.class);
+ InstanceIdentifier<Topology> topologyInstanceIdentifier = mock(InstanceIdentifier.class);
+ MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getUniTopologyIid"));
+ when(UnimgrMapper.getUniTopologyIid()).thenReturn(topologyInstanceIdentifier);
+ MemberModifier.suppress(MemberMatcher.method(MdsalUtils.class, "read", DataBroker.class, LogicalDatastoreType.class, InstanceIdentifier.class));
+ when(MdsalUtils.read(any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(topology);
+ when(topology.getNode()).thenReturn(ndList);
+ when(node.getAugmentation(UniAugmentation.class)).thenReturn(uniAugmentation);
+ List<Node> expectedListNnList = UniUtils.getUniNodes(dataBroker, LogicalDatastoreType.OPERATIONAL);
+ assertNotNull(expectedListNnList);
+ assertEquals(expectedListNnList, ndList);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testGetUnis() {
+ Node node = mock(Node.class);
+ List<Node> ndList = new ArrayList<Node>();
+ ndList.add(node);
+ Topology topology = mock (Topology.class);
+ DataBroker dataBroker = mock(DataBroker.class);
+ UniAugmentation uniAugmentation = mock(UniAugmentation.class);
+ InstanceIdentifier<Topology> topologyInstanceIdentifier = mock(InstanceIdentifier.class);
+ MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getUniTopologyIid"));
+ when(UnimgrMapper.getUniTopologyIid()).thenReturn(topologyInstanceIdentifier);
+ MemberModifier.suppress(MemberMatcher.method(MdsalUtils.class, "read", DataBroker.class, LogicalDatastoreType.class, InstanceIdentifier.class));
+ when(MdsalUtils.read(any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(topology);
+ when(topology.getNode()).thenReturn(ndList);
+ when(node.getAugmentation(UniAugmentation.class)).thenReturn(uniAugmentation);
+ List<UniAugmentation> expectedListUni = UniUtils.getUnis(dataBroker, LogicalDatastoreType.CONFIGURATION);
+ assertNotNull(expectedListUni);
+ assertEquals(expectedListUni.iterator().next(), uniAugmentation);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testGetUni() {
+ Node node = mock(Node.class);
+ List<Node> ndList = new ArrayList<Node>();
+ ndList.add(node);
+ Topology topology = mock (Topology.class);
+ DataBroker dataBroker = mock(DataBroker.class);
+ UniAugmentation uniAugmentation = mock(UniAugmentation.class);
+ IpAddress ipAddreDest = new IpAddress("10.10.0.2".toCharArray());
+ InstanceIdentifier<Topology> topologyInstanceIdentifier = mock(InstanceIdentifier.class);
+ MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getUniTopologyIid"));
+ when(UnimgrMapper.getUniTopologyIid()).thenReturn(topologyInstanceIdentifier);
+ MemberModifier.suppress(MemberMatcher.method(MdsalUtils.class, "read", DataBroker.class, LogicalDatastoreType.class, InstanceIdentifier.class));
+ when(MdsalUtils.read(any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(topology);
+ when(topology.getNode()).thenReturn(ndList);
+ when(node.getAugmentation(UniAugmentation.class)).thenReturn(uniAugmentation);
+ when(uniAugmentation.getIpAddress()).thenReturn(ipAddreDest);
+ MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getUniTopologyIid"));
+ when(UnimgrMapper.getUniTopologyIid()).thenReturn(topologyInstanceIdentifier);
+ UniAugmentation expectedUniAug = UniUtils.getUni(dataBroker, LogicalDatastoreType.CONFIGURATION, ipAddreDest);
+ assertNotNull(expectedUniAug);
+ assertEquals(expectedUniAug, uniAugmentation);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testUpdateUniNode() {
+ UniAugmentation uni = PowerMockito.mock(UniAugmentation.class);
+ InstanceIdentifier<?> uniKey = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class,
+ new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))//Any node id is fine for tests
+ .child(Node.class,
+ new NodeKey(OVSDB_NODE_ID));
+ InstanceIdentifier<Node> ovsdbNodeIid = mock(InstanceIdentifier.class);
+ Optional<Node> optionalNode = mock(Optional.class);
+ Node nd = mock(Node.class, Mockito.RETURNS_MOCKS);
+ when(optionalNode.isPresent()).thenReturn(true);
+ when(optionalNode.get()).thenReturn(nd);
+ WriteTransaction transaction = mock(WriteTransaction.class);
+ when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
+ doNothing().when(transaction).put(any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class),
+ any(Node.class));
+ MemberModifier.suppress(MemberMatcher.method(MdsalUtils.class, "readNode", DataBroker.class, LogicalDatastoreType.class, InstanceIdentifier.class));
+ when(MdsalUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(optionalNode);
+ UniUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL, uniKey, uni, ovsdbNodeIid, dataBroker);
+ verify(transaction).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class));
+ verify(transaction).submit();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testUpdateUniNode2() {
+ UniAugmentation uni = PowerMockito.mock(UniAugmentation.class);
+ InstanceIdentifier<?> uniKey = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class,
+ new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
+ .child(Node.class,
+ new NodeKey(OVSDB_NODE_ID));//Any node id is fine for tests
+ Node ovsdbNode = mock(Node.class);
+ InstanceIdentifier<Node> ovsdbNodeIid = mock(InstanceIdentifier.class);
+ Optional<Node> optionalNode = mock(Optional.class);
+ Node nd = mock(Node.class);
+ when(optionalNode.isPresent()).thenReturn(true);
+ when(optionalNode.get()).thenReturn(nd);
+ doNothing().when(transaction).put(any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class),
+ any(Node.class));
+ when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
+ MemberModifier.suppress(MemberMatcher.method(UnimgrMapper.class, "getOvsdbNodeIid", NodeId.class));
+ when(UnimgrMapper.getOvsdbNodeIid(any(NodeId.class))).thenReturn(ovsdbNodeIid);
+ MemberModifier.suppress(MemberMatcher.method(MdsalUtils.class, "readNode", DataBroker.class, LogicalDatastoreType.class, InstanceIdentifier.class));
+ when(MdsalUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(optionalNode);
+ UniUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL, uniKey, uni, ovsdbNode, dataBroker);
+ verify(transaction).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class));
+ verify(transaction).submit();
+ }
+}