package org.opendaylight.transportpce.renderer.provisiondevice;
+import com.google.common.base.Optional;
+
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.MountPointService;
+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.transportpce.renderer.mapping.PortMapping;
import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaces;
import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmOchInterface;
+import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmXponderInterface;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacks;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacksBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacksKey;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev161014.States;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.OchAttributes.ModulationFormat;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.R100G;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.RendererService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.ServicePathInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.ServicePathOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.ServicePathOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.service.path.input.Nodes;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
/**
- * This method set's wavelength path based on following steps: For each
- * node:
+ * This method set's wavelength path based on the following steps.
+ * For each node:
*
* <p>
* 1. Create Och interface on source termination point. 2. Create Och
*/
public ServicePathOutputBuilder setupServicePath(ServicePathInput input) {
+ String serviceName = input.getServiceName();
List<Nodes> nodes = input.getNodes();
ServicePathOutputBuilder setServBldr = new ServicePathOutputBuilder();
LOG.info(currentMountedDevice.toString());
+ int crossConnectFlag;
for (Nodes n : nodes) {
- LOG.info("Starting provisioning for node : " + n.getNodeId());
+ LOG.info("Starting provisioning for node : {}", n.getNodeId());
+ crossConnectFlag = 0;
String nodeId = n.getNodeId();
// if the node is currently mounted then proceed
if (currentMountedDevice.contains(n.getNodeId())) {
String destTp = n.getDestTp();
Long waveNumber = input.getWaveNumber();
- String srcIf = new OpenRoadmOchInterface(db, mps, nodeId, srcTp).createInterface(waveNumber);
- // if source interface creation was successful then proceed
- // otherwise return.
- if (srcIf == null) {
- LOG.warn("Unable to create OCH interface on " + nodeId + " at " + srcTp);
- return setServBldr.setResult("Unable to create OCH interface on " + nodeId + " at " + srcTp);
+ String mf = input.getModulationFormat();
+ if (destTp.contains("LINE")) {
+ crossConnectFlag++;
+
+ ModulationFormat modulationFormat = null;
+ for (int i = 0; i < ModulationFormat.values().length; i++) {
+ ModulationFormat smodulationFormat = ModulationFormat.forValue(i);
+ if (smodulationFormat.getName().equals(mf)) {
+ modulationFormat = smodulationFormat;
+ }
+ }
+ try {
+ LOG.info("Modulation Format {} configured exists.", modulationFormat.getName());
+ } catch (NullPointerException e) {
+ LOG.error("{} modulation format does not exist.",mf);
+ }
+
+ if (!new OpenRoadmXponderInterface(db, mps, nodeId, destTp, serviceName)
+ .createLineInterfaces(waveNumber, R100G.class, modulationFormat)) {
+
+ return setServBldr.setResult("Unable to LINE interface on " + nodeId + " at " + destTp);
+ }
+ if (!activateService(nodeId, destTp, mps, true)) {
+ return setServBldr
+ .setResult("Unable to activate Equipment State on " + nodeId + " for " + destTp);
+ }
}
- // if destination interface creation was then proceed otherwise
- // return.
- String dstIf = new OpenRoadmOchInterface(db, mps, nodeId, destTp).createInterface(waveNumber);
- if (dstIf == null) {
- LOG.warn("Unable to create OCH interface on " + nodeId + " at " + destTp);
- return setServBldr.setResult("Unable to create OCH interface on " + nodeId + " at " + destTp);
+ if (srcTp.contains("CLNT")) {
+ crossConnectFlag++;
+ if (!new OpenRoadmXponderInterface(db, mps, nodeId, srcTp, serviceName).createClientInterfaces()) {
+ return setServBldr.setResult("Unable to Client interface on " + nodeId + " at " + srcTp);
+ }
}
- LOG.info("Creating cross connect between source :" + srcTp + " destination " + destTp + " for node " + n
- .getNodeId());
- DataBroker netconfNodeDataBroker = PortMapping.getDeviceDataBroker(nodeId, mps);
- CrossConnect roadmConnections = new CrossConnect(netconfNodeDataBroker);
- if (roadmConnections.postCrossConnect(waveNumber, srcTp, destTp) == true) {
- nodesProvisioned.add(nodeId);
- roadmConnections.getConnectionPortTrail(nodeId, mps, waveNumber, srcTp, destTp);
-
- } else {
- return setServBldr.setResult("Unable to post Roadm-connection for node " + nodeId);
+ String srcIf;
+ String dstIf;
+ if (srcTp.contains("TTP") || srcTp.contains("PP")) {
+ srcIf = new OpenRoadmOchInterface(db, mps, nodeId, srcTp, serviceName).createInterface(waveNumber);
+ // if source interface creation was successful
+ // then proceed otherwise return.
+ if (srcIf == null) {
+ LOG.warn("Unable to create OCH interface on {} at {}", nodeId, srcTp);
+ return setServBldr.setResult("Unable to create OCH interface on " + nodeId + " at " + srcTp);
+ }
+ }
+ if (destTp.contains("TTP") || destTp.contains("PP")) {
+ dstIf = new OpenRoadmOchInterface(db, mps, nodeId, destTp, serviceName).createInterface(waveNumber);
+ // if destination interface creation was successful
+ // then proceed otherwise return.
+ if (dstIf == null) {
+ LOG.warn("Unable to create OCH interface on {} at {}", nodeId, destTp);
+ return setServBldr.setResult("Unable to create OCH interface on " + nodeId + " at " + destTp);
+ }
+ }
+ if (crossConnectFlag < 1) {
+ LOG.info("Creating cross connect between source :{} destination {} for node {}", srcTp, destTp,
+ n.getNodeId());
+ DataBroker netconfNodeDataBroker = PortMapping.getDeviceDataBroker(nodeId, mps);
+ String crossConnectName = srcTp + "-" + destTp + "-" + waveNumber;
+ CrossConnect roadmConnections = new CrossConnect(netconfNodeDataBroker);
+ if (roadmConnections.postCrossConnect(waveNumber, srcTp, destTp)) {
+ nodesProvisioned.add(nodeId);
+ roadmConnections.getConnectionPortTrail(nodeId, mps, waveNumber, srcTp, destTp);
+ } else {
+ return setServBldr.setResult("Unable to post Roadm-connection for node " + nodeId);
+ }
}
} else {
- LOG.warn(nodeId + " is not mounted on the controller");
+ LOG.warn("{} is not mounted on the controller", nodeId);
return setServBldr.setResult(nodeId + " is not mounted on the controller");
}
}
* node:
*
* <p>
- * 1. Delete Cross connect between source and destination tps. 2. Delete Och
- * interface on source termination point. 3. Delete Och interface on
- * destination termination point.
+ * 1. Delete Cross connect between source and destination tps.
+ * 2. Delete Och interface on source termination point.
+ * 3. Delete Och interface on destination termination point.
*
* <p>
* Naming convention used for OCH interfaces name : tp-wavenumber Naming
for (Nodes n : nodes) {
String nodeId = n.getNodeId();
- LOG.info("Deleting service setup on node " + nodeId);
+ LOG.info("Deleting service setup on node {}", nodeId);
String srcTp = n.getSrcTp();
String destTp = n.getDestTp();
Long waveNumber = input.getWaveNumber();
// if the node is currently mounted then proceed.
if (currentMountedDevice.contains(nodeId)) {
+
+ if (destTp.contains("LINE")) {
+ if (!activateService(nodeId, destTp, mps, false)) {
+ LOG.error("Unable to desactivate Equipment State on {} for {}", nodeId, destTp);
+ }
+ if (new OpenRoadmInterfaces(db, mps, nodeId, destTp)
+ .deleteInterface(destTp + "-ODU") == false) {
+ LOG.error("Failed to delete interface {}-ODU on {}", destTp, nodeId);
+ }
+ if (new OpenRoadmInterfaces(db, mps, nodeId, destTp)
+ .deleteInterface(destTp + "-OTU") == false) {
+ LOG.error("Failed to delete interface {}-OTU on {}", destTp, nodeId);
+ }
+ if (new OpenRoadmInterfaces(db, mps, nodeId, destTp)
+ .deleteInterface(destTp + "-" + waveNumber) == false) {
+ LOG.error("Failed to delete interface {}-{} on {}", destTp, waveNumber, nodeId);
+ }
+ }
+ if (srcTp.contains("CLNT")) {
+ // Deleting interface on source termination point
+ if (new OpenRoadmInterfaces(db, mps, nodeId, srcTp)
+ .deleteInterface(srcTp + "-ETHERNET") == false) {
+ LOG.error("Failed to delete Ethernet interface on {} on {}", srcTp, nodeId);
+ }
+ continue;
+ }
String connectionNumber = srcTp + "-" + destTp + "-" + waveNumber;
CrossConnect roadmConnection = new CrossConnect(PortMapping.getDeviceDataBroker(nodeId, mps),
connectionNumber);
if (!roadmConnection.deleteCrossConnect()) {
- LOG.error("Failed to delete {} ", srcTp + "-" + destTp + "-" + waveNumber);
+ LOG.error("Failed to delete {} on {}", connectionNumber, nodeId);
}
// Deleting interface on source termination point
- if (new OpenRoadmInterfaces(db, mps, nodeId, srcTp).deleteInterface(srcTp + "-" + waveNumber
- .toString()) == false) {
- LOG.error("Failed to delete interface " + srcTp + "-" + waveNumber.toString());
+ if (!new OpenRoadmInterfaces(db, mps, nodeId, srcTp)
+ .deleteInterface(srcTp + "-" + waveNumber.toString())) {
+ LOG.error("Failed to delete interface {}-{} on {}", srcTp, waveNumber.toString(), nodeId);
}
// Deleting interface on destination termination point
- if (new OpenRoadmInterfaces(db, mps, nodeId, srcTp).deleteInterface(destTp + "-" + waveNumber
- .toString()) == false) {
- LOG.error("Failed to delete interface " + srcTp + "-" + waveNumber.toString());
+ if (!new OpenRoadmInterfaces(db, mps, nodeId, destTp)
+ .deleteInterface(destTp + "-" + waveNumber.toString())) {
+ LOG.error("Failed to delete interface {}-{} on {}", destTp, waveNumber.toString(), nodeId);
}
} else {
- LOG.warn(nodeId + " is not mounted on the controller");
+ LOG.warn("{} is not mounted on the controller", nodeId);
return delServBldr.setResult(nodeId + " is not mounted on the controller");
}
}
return delServBldr.setResult("Request processed");
}
-}
\ No newline at end of file
+
+ /**
+ * This method does a post(edit-config) on a given circuit-packs subtree to
+ * change its equipment-state.
+ *
+ * @param nodeId
+ * Netconf device.
+ * @param logicalConnPoint
+ * Logical Connection point resulting from PortMapping to
+ * retrieve associated circuit-pack.
+ * @param mps
+ * Mount point service.
+ * @param activate
+ * true to configure the circuit-pack to "NotReservedInuse".
+ * false to configure the circuit-pack to "NotReservedAvailable".
+ * @return true/false based on status of operation.
+ */
+ private boolean activateService(String nodeId, String logicalConnPoint, MountPointService mps, boolean activate) {
+ DataBroker deviceDb = PortMapping.getDeviceDataBroker(nodeId, mps);
+ String circuitPack = PortMapping.getMapping(nodeId, logicalConnPoint, db).getSupportingCircuitPackName();
+
+ InstanceIdentifier<CircuitPacks> circuitPackIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
+ .child(CircuitPacks.class, new CircuitPacksKey(circuitPack));
+ ReadOnlyTransaction readTx = deviceDb.newReadOnlyTransaction();
+ // retrieve relevent CircuitPack object
+ Optional<CircuitPacks> cpObject;
+ CircuitPacks cp = null;
+ try {
+ cpObject = readTx.read(LogicalDatastoreType.CONFIGURATION, circuitPackIID).get();
+ if (cpObject.isPresent()) {
+ cp = cpObject.get();
+ } else {
+ LOG.info("Could not find CircuitPack {} in equipment config datastore for nodeId {}", circuitPack,
+ nodeId);
+ return false;
+ }
+
+ } catch (InterruptedException | ExecutionException ex) {
+ LOG.error("Issue reading config datastore on node {}", nodeId, ex);
+ }
+ CircuitPacksBuilder cpBldr = new CircuitPacksBuilder(cp);
+ if (activate) {
+ cpBldr.setEquipmentState(States.NotReservedInuse);
+ } else {
+ cpBldr.setEquipmentState(States.NotReservedAvailable);
+ }
+ WriteTransaction wt = deviceDb.newWriteOnlyTransaction();
+ wt.put(LogicalDatastoreType.CONFIGURATION, circuitPackIID, cpBldr.build());
+ try {
+ wt.submit().get(15, TimeUnit.SECONDS);
+ LOG.info("Successfully posted Equipment State on circuit pack {} on node {}", circuitPack, nodeId);
+ return true;
+ } catch (InterruptedException | ExecutionException | TimeoutException e) {
+ LOG.warn("Failed to post {} on node {}", circuitPack, nodeId, e);
+ return false;
+ }
+ }
+}