import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
+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.MountPoint;
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.transportpce.renderer.openroadminterface.OpenRoadmInterfaces;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.NodeTypes;
import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.Ports;
import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.PortsKey;
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.CircuitPacksKey;
import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.ConnectionPorts;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.Interface;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.InterfaceKey;
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.device.rev170206.org.openroadm.device.container.org.openroadm.device.Degree;
import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.DegreeKey;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
*/
public boolean createMappingData() {
- LOG.info(" Create Mapping Data for node " + nodeId);
+ LOG.info("Create Mapping Data for node " + nodeId);
DataBroker deviceDb = getDeviceDataBroker(nodeId, mps);
- Info deviceInfo = getDeviceInfo(deviceDb);
List<Mapping> portMapList = new ArrayList<>();
-
+ Info deviceInfo;
+ Integer nodeType = 1;
if (deviceDb != null) {
+ deviceInfo = getDeviceInfo(deviceDb);
if (deviceInfo != null) {
- Integer nodeType = deviceInfo.getNodeType().getIntValue();
+ if (deviceInfo.getNodeType() == null) {
+ LOG.info("Node type mandatory field is missing");
+ return false;
+ }
+ nodeType = deviceInfo.getNodeType().getIntValue();
// Create Mapping for Roadm Node
if (nodeType == 1) {
// Get TTP port mapping
}
}
} else {
- LOG.info(" Device info subtree is absent for " + nodeId);
+ LOG.info("Device info subtree is absent for " + nodeId);
return false;
}
} else {
- LOG.info(" Unable to get Data broker for node " + nodeId);
+ LOG.info("Unable to get Data broker for node " + nodeId);
return false;
}
- return postPortMapping(deviceInfo, portMapList);
+ return postPortMapping(deviceInfo, portMapList, nodeType);
+ }
+
+ /**
+ * This method removes mapping data from the datastore after disconnecting
+ * ODL from a Netconf device.
+ */
+ public void deleteMappingData() {
+ LOG.info("Deleting Mapping Data corresponding at node " + nodeId);
+ WriteTransaction rw = db.newWriteOnlyTransaction();
+ InstanceIdentifier<Nodes> nodesIID = InstanceIdentifier.create(Network.class)
+ .child(Nodes.class, new NodesKey(nodeId));
+ rw.delete(LogicalDatastoreType.CONFIGURATION, nodesIID);
+ try {
+ rw.submit().get(1, TimeUnit.SECONDS);
+ LOG.info("Port mapping removal for node " + nodeId);
+ } catch (InterruptedException | ExecutionException | TimeoutException e) {
+ LOG.error("Error for removing port mapping infos for node " + nodeId);
+ }
}
/**
InstanceIdentifier<Ports> portIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(
CircuitPacks.class, new CircuitPacksKey(circuitPackName)).child(Ports.class, new PortsKey(portName));
try {
- LOG.info("Fetching logical Connection Point value for port " + portName + " at circuit pack "
- + circuitPackName);
+ LOG.info("Fetching logical Connection Point value for port {} at circuit pack {}", portName,
+ circuitPackName);
ReadOnlyTransaction rtx = deviceDb.newReadOnlyTransaction();
Optional<Ports> portObject = rtx.read(LogicalDatastoreType.OPERATIONAL, portIID).get();
if (portObject.isPresent()) {
Ports port = portObject.get();
if (port.getLogicalConnectionPoint() != null) {
-
- LOG.info("Logical Connection Point for " + circuitPackName + " " + portName + " is " + port
+ LOG.info("Logical Connection Point for {} {} is {}", circuitPackName, portName, port
.getLogicalConnectionPoint());
portMapList.add(createMappingObject(port, circuitPackName, port.getLogicalConnectionPoint(),
deviceDb));
} else {
- LOG.warn("Logical Connection Point value missing for " + circuitPackName + " " + port
+ LOG.warn("Logical Connection Point value missing for {} {}", circuitPackName, port
.getPortName());
}
}
} catch (InterruptedException | ExecutionException ex) {
LOG.warn("Read failed for Logical Connection Point value missing for " + circuitPackName + " "
- + portName);
+ + portName, ex);
return false;
}
}
private boolean createPpPortMapping(DataBroker deviceDb, Info deviceInfo, List<Mapping> portMapList) {
// Creating mapping data for degree PP's
- List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> srgCps = getSrgCps(
- deviceDb, deviceInfo);
- for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks cps : srgCps) {
- String circuitPackName = cps.getCircuitPackName();
+ ReadOnlyTransaction rtx = deviceDb.newReadOnlyTransaction();
+ Integer maxSrg;
+ // Get value for max Srg from subtree, required for iteration
+ // if it is not defined in the netconf node then set maxSrg to 20
+ if (deviceInfo.getMaxSrgs() != null) {
+ maxSrg = deviceInfo.getMaxSrgs();
+ } else {
+ maxSrg = 20;
+ }
+
+ Integer srgCounter = 1;
+ Integer nbSrg = 0;
+ while (srgCounter <= maxSrg) {
+ List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> srgCps =
+ new ArrayList<>();
+ LOG.info("Getting CircuitPacks for Srg Number {}", srgCounter);
+ InstanceIdentifier<SharedRiskGroup> srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(
+ SharedRiskGroup.class, new SharedRiskGroupKey(srgCounter));
try {
- InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(
- CircuitPacks.class, new CircuitPacksKey(circuitPackName));
- ReadOnlyTransaction rtx = deviceDb.newReadOnlyTransaction();
- Optional<CircuitPacks> circuitPackObject = rtx.read(LogicalDatastoreType.OPERATIONAL, cpIID).get();
+ Optional<SharedRiskGroup> ordmSrgObject = rtx.read(LogicalDatastoreType.CONFIGURATION, srgIID).get();
- if (circuitPackObject.isPresent()) {
- CircuitPacks cp = circuitPackObject.get();
- if (!cp.getPorts().isEmpty()) {
- for (Ports port : cp.getPorts()) {
+ if (ordmSrgObject.isPresent()) {
+ srgCps.addAll(new ArrayList<>(ordmSrgObject.get().getCircuitPacks()));
+ nbSrg++;
+ }
+ } catch (InterruptedException | ExecutionException ex) {
+ LOG.warn("Failed to read Srg {}", srgCounter, ex);
+ break;
+ }
- if (port.getLogicalConnectionPoint() != null && port.getPortQual().getIntValue() == 2) {
- String logicalConnectionPoint = null;
- if (port.getPortDirection().getIntValue() == 1) {
- // Port direction is transmit
- logicalConnectionPoint = port.getLogicalConnectionPoint() + "-TX";
- }
- if (port.getPortDirection().getIntValue() == 2) {
- // Port direction is receive
- logicalConnectionPoint = port.getLogicalConnectionPoint() + "-RX";
+ for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks cps : srgCps) {
+ String circuitPackName = cps.getCircuitPackName();
+ try {
+ InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(
+ CircuitPacks.class, new CircuitPacksKey(circuitPackName));
+ Optional<CircuitPacks> circuitPackObject = rtx.read(LogicalDatastoreType.OPERATIONAL, cpIID).get();
+
+ if (circuitPackObject.isPresent()) {
+ CircuitPacks cp = circuitPackObject.get();
+ if (cp.getPorts() == null) {
+ LOG.warn("No port found for {} {}", deviceInfo.getNodeId(), circuitPackName);
+ } else if (!cp.getPorts().isEmpty()) {
+ for (Ports port : cp.getPorts()) {
+
+ if (port.getLogicalConnectionPoint() != null && port.getPortQual().getIntValue() == 2) {
+ String logicalConnectionPoint = null;
+ if (port.getPortDirection().getIntValue() == 1) {
+ // Port direction is transmit
+ if (!port.getLogicalConnectionPoint().contains("SRG")) {
+ logicalConnectionPoint = "SRG" + srgCounter + "-" + port
+ .getLogicalConnectionPoint() + "-TX";
+ } else {
+ logicalConnectionPoint = port.getLogicalConnectionPoint() + "-TX";
+ }
+ }
+ if (port.getPortDirection().getIntValue() == 2) {
+ // Port direction is receive
+ if (!port.getLogicalConnectionPoint().contains("SRG")) {
+ logicalConnectionPoint = "SRG" + srgCounter + "-" + port
+ .getLogicalConnectionPoint() + "-RX";
+ } else {
+ logicalConnectionPoint = port.getLogicalConnectionPoint() + "-RX";
+ }
+ }
+ if (port.getPortDirection().getIntValue() == 3) {
+ // port is bi-directional
+ if (!port.getLogicalConnectionPoint().contains("SRG")) {
+ logicalConnectionPoint = "SRG" + srgCounter + "-" + port
+ .getLogicalConnectionPoint() + "-TXRX";
+ } else {
+ logicalConnectionPoint = port.getLogicalConnectionPoint() + "-TXRX";
+ }
+ }
+
+ LOG.info("Logical Connection Point for {} {} is {}", circuitPackName, port
+ .getPortName(), logicalConnectionPoint);
+
+ portMapList.add(createMappingObject(port, circuitPackName, logicalConnectionPoint,
+ deviceDb));
+
+ } else if (port.getPortQual().getIntValue() == 1) {
+
+ LOG.info("Port is internal, skipping Logical Connection Point missing for "
+ + circuitPackName + " " + port.getPortName());
+
+ } else if (port.getLogicalConnectionPoint() == null) {
+
+ LOG.info("Value missing, Skipping Logical Connection Point missing for {} {}",
+ circuitPackName, port.getPortName());
}
- if (port.getPortDirection().getIntValue() == 3) {
- // port is bi-directional
- logicalConnectionPoint = port.getLogicalConnectionPoint() + "-TXRX";
- }
-
- LOG.info("Logical Connection Point for " + circuitPackName + " " + port.getPortName()
- + " is " + logicalConnectionPoint);
-
- portMapList.add(createMappingObject(port, circuitPackName, logicalConnectionPoint,
- deviceDb));
-
- } else if (port.getPortQual().getIntValue() == 1) {
- LOG.info("Port is internal, skipping Logical Connection Point missing for "
- + circuitPackName + " " + port.getPortName());
-
- } else if (port.getLogicalConnectionPoint() == null) {
-
- LOG.info("Value missing, Skipping Logical Connection Point missing for "
- + circuitPackName + " " + port.getPortName());
}
}
}
-
+ } catch (InterruptedException | ExecutionException ex) {
+ LOG.warn("Read failed for {}", circuitPackName, ex);
+ return false;
}
- } catch (InterruptedException | ExecutionException ex) {
- LOG.warn("Read failed for " + circuitPackName);
- return false;
}
+ srgCounter++;
}
-
+ LOG.info("Device has {} Srg", nbSrg);
return true;
}
if (deviceObject.isPresent()) {
for (CircuitPacks cp : deviceObject.get().getCircuitPacks()) {
String circuitPackName = cp.getCircuitPackName();
- for (Ports port : cp.getPorts()) {
- if (port.getPortQual().getIntValue() == 3) {
- // Port is xpdr-network
- portMapList.add(createMappingObject(port, circuitPackName, "LINE" + line, deviceDb));
- line++;
- }
- if (port.getPortQual().getIntValue() == 4) {
- // port is xpdr-client
- portMapList.add(createMappingObject(port, circuitPackName, "CLNT" + client, deviceDb));
- client++;
+ if (cp.getPorts() == null) {
+ LOG.warn("No port found for {}, circuit pack {}", deviceInfo.getNodeId(), circuitPackName);
+ } else {
+ for (Ports port : cp.getPorts()) {
+ if (port.getPortQual() != null) {
+ if (port.getPortQual().getIntValue() == 3) {
+ // Port is xpdr-network
+ portMapList.add(createMappingObject(port, circuitPackName, "XPDR-LINE"
+ + line, deviceDb));
+ LOG.info("Logical Connection Point for {} {} is XPDR-LINE{}", circuitPackName, port
+ .getPortName(), line);
+ line++;
+ }
+ if (port.getPortQual().getIntValue() == 4) {
+ // port is xpdr-client
+ portMapList.add(createMappingObject(port, circuitPackName, "XPDR-CLNT"
+ + client, deviceDb));
+ LOG.info("Logical Connection Point for {} {} is XPDR-CLNT{}", circuitPackName, port
+ .getPortName(), client);
+ client++;
+ }
+ } else {
+ LOG.info("no PortQual for port {} of circuit pack {}", port.getPortName(), cp
+ .getCircuitPackName());
+ }
}
}
}
} else {
- LOG.info("Circuit Packs are not present for " + nodeId);
+ LOG.info("No deviceObject present for {}", nodeId);
return false;
}
} catch (InterruptedException | ExecutionException ex) {
- LOG.warn("Read failed for CircuitPacks of " + nodeId);
+ LOG.warn("Read failed for CircuitPacks of {}", nodeId, ex);
return false;
}
return true;
// Get OMS and OTS interface provisioned on the TTP's
if (logicalConnectionPoint.contains("TTP") && port.getInterfaces() != null) {
for (Interfaces interfaces : port.getInterfaces()) {
- Class<? extends InterfaceType> interfaceType = getInterfaceType(deviceDb, interfaces
- .getInterfaceName());
+ Class<? extends InterfaceType> interfaceType = new OpenRoadmInterfaces(db, mps, nodeId,
+ logicalConnectionPoint).getInterface(interfaces.getInterfaceName()).getType();
// Check if interface type is OMS or OTS
if (interfaceType.equals(OpenROADMOpticalMultiplex.class)) {
String omsInterfaceName = interfaces.getInterfaceName();
return mpBldr.build();
}
- /**
- * This private does a get on the interface subtree of the device with the
- * interface name as the key and return the class corresponding to the
- * interface type.
- *
- * @param interfaceName
- * Name of the interface
- * @param deviceDb
- * Reference to device's databroker.
- *
- * @return true/false based on status of operation
- */
-
- private Class<? extends InterfaceType> getInterfaceType(DataBroker deviceDb, String interfaceName) {
- ReadOnlyTransaction rtx = deviceDb.newReadOnlyTransaction();
- InstanceIdentifier<Interface> interfacesIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(
- Interface.class, new InterfaceKey(interfaceName));
- try {
- Optional<Interface> interfaceObject = rtx.read(LogicalDatastoreType.OPERATIONAL, interfacesIID).get();
- if (interfaceObject.isPresent()) {
- return interfaceObject.get().getType();
- } else {
- LOG.info("Interface subtree is not present for " + interfaceName);
- }
- } catch (InterruptedException | ExecutionException ex) {
- LOG.info("Read failed on interface subtree for");
- return null;
- }
- return null;
- }
-
/**
* This method does a get operation on info subtree of the netconf device's
* configuration datastore and returns info object.It is required to get
try {
Optional<Info> ordmInfoObject = rtx.read(LogicalDatastoreType.OPERATIONAL, infoIID).get();
if (ordmInfoObject.isPresent()) {
+ LOG.info("Info subtree is present {}", ordmInfoObject.get());
return ordmInfoObject.get();
} else {
- LOG.info("Info subtree is not present");
+ LOG.error("Info subtree is not present");
}
+ } catch (NullPointerException ex) {
+ LOG.warn("Try to get Info from a non Open ROADM device {}", deviceDb);
+ return null;
} catch (InterruptedException | ExecutionException ex) {
- LOG.info("Read failed on info subtree for");
+ LOG.error("Read failed on info subtree ", ex);
return null;
}
return null;
Optional<Degree> ordmDegreeObject = rtx.read(LogicalDatastoreType.CONFIGURATION, deviceIID).get();
if (ordmDegreeObject.isPresent()) {
- degreeConPorts.addAll(new ArrayList<ConnectionPorts>(ordmDegreeObject.get().getConnectionPorts()));
+ degreeConPorts.addAll(new ArrayList<>(ordmDegreeObject.get().getConnectionPorts()));
} else {
LOG.info("Device has " + (degreeCounter - 1) + " degree");
break;
}
} catch (InterruptedException | ExecutionException ex) {
- LOG.info("Failed to read degree " + degreeCounter);
+ LOG.error("Failed to read degree " + degreeCounter, ex);
break;
}
return degreeConPorts;
}
- /**
- * This method does a get operation on shared risk group subtree of the
- * netconf device's config datastore and returns a list of all circuit packs
- * objects that are part of srgs. It is required to do a selective get on
- * all the circuit packs that contain add/drop ports of interest.
- *
- * @param deviceDb
- * Reference to device's databroker
- * @param ordmInfo
- * Info subtree from the device
- * @return List of circuit packs object belonging to- shared risk group
- * subtree
- */
-
- private List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> getSrgCps(
- DataBroker deviceDb, Info ordmInfo) {
-
- List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> srgCps =
- new ArrayList<>();
- ReadOnlyTransaction rtx = deviceDb.newReadOnlyTransaction();
- Integer maxSrg;
- // Get value for max Srg from info subtree, required for iteration
- // if not present assume to be 20 (temporary)
- if (ordmInfo.getMaxSrgs() != null) {
- maxSrg = ordmInfo.getMaxSrgs();
- } else {
- maxSrg = 20;
- }
-
- Integer srgCounter = 1;
- while (srgCounter <= maxSrg) {
- LOG.info("Getting Circuitpacks for Srg Number " + srgCounter);
- InstanceIdentifier<SharedRiskGroup> srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(
- SharedRiskGroup.class, new SharedRiskGroupKey(srgCounter));
- try {
- Optional<SharedRiskGroup> ordmSrgObject = rtx.read(LogicalDatastoreType.CONFIGURATION, srgIID).get();
-
- if (ordmSrgObject.isPresent()) {
-
- srgCps.addAll(
- new ArrayList<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg
- .CircuitPacks>(ordmSrgObject.get().getCircuitPacks()));
-
- } else {
- LOG.info("Device has " + (srgCounter - 1) + " Srg");
- break;
- }
- } catch (InterruptedException | ExecutionException ex) {
- LOG.warn("Failed to read Srg " + srgCounter);
- break;
- }
- srgCounter++;
- }
-
- return srgCps;
- }
-
/**
* This method for ports the portMapping corresponding to the
* portmapping.yang file to the MD-SAL datastore.
*
* @return Result true/false based on status of operation.
*/
- private boolean postPortMapping(Info deviceInfo, List<Mapping> portMapList) {
+ private boolean postPortMapping(Info deviceInfo, List<Mapping> portMapList, Integer nodeType) {
- List<Nodes> nodesList = new ArrayList<>();
NodesBuilder nodesBldr = new NodesBuilder();
nodesBldr.setKey(new NodesKey(deviceInfo.getNodeId())).setNodeId(deviceInfo.getNodeId());
+ nodesBldr.setNodeType(NodeTypes.forValue(nodeType));
nodesBldr.setMapping(portMapList);
+ List<Nodes> nodesList = new ArrayList<>();
nodesList.add(nodesBldr.build());
NetworkBuilder nwBldr = new NetworkBuilder();
nwBldr.setNodes(nodesList);
* Unique Identifier for the node of interest.
* @param logicalConnPoint
* Name of the logical point
+ * @param db
+ * Databroker / MD-SAL data store
*
* @return Result Mapping object if success otherwise null.
*/
return null;
}
} catch (InterruptedException | ExecutionException ex) {
- LOG.info("Unable to read mapping for logical connection point : " + logicalConnPoint + " for nodeId "
- + nodeId);
+ LOG.error("Unable to read mapping for logical connection point : " + logicalConnPoint + " for nodeId "
+ + nodeId, ex);
}
return null;
}
* @return Databroker for the given device
*/
public static DataBroker getDeviceDataBroker(String nodeId, MountPointService mps) {
+ MountPoint netconfNode = getDeviceMountPoint(nodeId, mps);
+ if (netconfNode != null) {
+ DataBroker netconfNodeDataBroker = netconfNode.getService(DataBroker.class).get();
+ return netconfNodeDataBroker;
+ } else {
+ LOG.error("Device Data broker not found for :" + nodeId);
+ return null;
+ }
+ }
+
+ public static MountPoint getDeviceMountPoint(String nodeId, MountPointService mps) {
InstanceIdentifier<Node> netconfNodeIID = InstanceIdentifier.builder(NetworkTopology.class).child(
Topology.class, new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName()))).child(Node.class,
new NodeKey(new NodeId(nodeId))).build();
- // Get the mount point for the specified node
+ // Get mount point for specified device
final Optional<MountPoint> netconfNodeOptional = mps.getMountPoint(netconfNodeIID);
if (netconfNodeOptional.isPresent()) {
MountPoint netconfNode = netconfNodeOptional.get();
- // Get the DataBroker for the mounted node
- DataBroker netconfNodeDataBroker = netconfNode.getService(DataBroker.class).get();
- return netconfNodeDataBroker;
+ return netconfNode;
} else {
- LOG.info("Device Data broker not found for :" + nodeId);
+ LOG.error("Mount Point not found for :" + nodeId);
+ return null;
}
- return null;
+
}
-}
\ No newline at end of file
+}