- public boolean createMappingData(String nodeId) {
-
- LOG.info("Create Mapping Data for node {}", nodeId);
- List<Mapping> portMapList = new ArrayList<>();
- InstanceIdentifier<Info> infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class);
- Optional<Info> deviceInfoOptional = this.deviceTransactionManager.getDataFromDevice(nodeId,
- LogicalDatastoreType.OPERATIONAL, infoIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-
- Info deviceInfo;
- if (deviceInfoOptional.isPresent()) {
- deviceInfo = deviceInfoOptional.get();
- } else {
- LOG.warn("Device info subtree is absent for {}", nodeId);
- return false;
- }
- if (deviceInfo.getNodeType() == null) {
- LOG.error("Node type field is missing"); // TODO make mandatory in yang
- return false;
- }
- switch (deviceInfo.getNodeType()) {
-
- case Rdm:
- // Get TTP port mapping
- if (!createTtpPortMapping(nodeId, deviceInfo, portMapList)) {
- // return false if mapping creation for TTP's failed
- LOG.warn("Unable to create mapping for TTP's on node {}", nodeId);
- return false;
- }
-
- // Get PP port mapping
- if (!createPpPortMapping(nodeId, deviceInfo, portMapList)) {
- // return false if mapping creation for PP's failed
- LOG.warn("Unable to create mapping for PP's on node {}", nodeId);
- return false;
- }
- break;
- case Xpdr:
- if (!createXpdrPortMapping(nodeId, portMapList)) {
- LOG.warn("Unable to create mapping for Xponder on node {}", nodeId);
- return false;
- }
- break;
- default:
- LOG.error("Unable to create mapping for node {} : unknown nodetype ", nodeId);
- break;
-
- }
- return postPortMapping(deviceInfo, portMapList, deviceInfo.getNodeType().getIntValue(), null);
- }
-
- /**
- * This private method gets the list of external ports on a degree. For each
- * port in the degree, it does a get on port subtree with
- * circuit-pack-name/port-name as key in order to get the logical connection
- * point name corresponding to it.
- *
- * @param deviceInfo
- * Info subtree read from the device
- * @param portMapList
- * Reference to the list containing the mapping to be pushed to
- * MD-SAL
- *
- * @return true/false based on status of operation
- */
- private boolean createTtpPortMapping(String nodeId, Info deviceInfo, List<Mapping> portMapList) {
- // Creating mapping data for degree TTP's
-
- List<Degree> degrees = getDegrees(nodeId, deviceInfo);
- List<ConnectionPorts> degreeConPorts = getDegreePorts(degrees);
- Map<String, String> interfaceList = getEthInterfaceList(nodeId);
- List<CpToDegree> cpToDegreeList = getCpToDegreeList(degrees, nodeId, interfaceList);
- LOG.info("Map looks like this {}",interfaceList);
-
- postPortMapping(deviceInfo, null, deviceInfo.getNodeType().getIntValue(), cpToDegreeList);
-
- // Getting circuit-pack-name/port-name corresponding to TTP's
- for (ConnectionPorts cp : degreeConPorts) {
- String circuitPackName = cp.getCircuitPackName();
- String portName = cp.getPortName().toString();
- InstanceIdentifier<Ports> portIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(
- CircuitPacks.class, new CircuitPacksKey(circuitPackName)).child(Ports.class, new PortsKey(portName));
-
- LOG.info("Fetching logical Connection Point value for port {} at circuit pack {}", portName,
- circuitPackName);
- Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
- LogicalDatastoreType.OPERATIONAL, portIID, Timeouts.DEVICE_READ_TIMEOUT,
- Timeouts.DEVICE_READ_TIMEOUT_UNIT);
- if (portObject.isPresent()) {
- Ports port = portObject.get();
- if (port.getLogicalConnectionPoint() != null) {
- LOG.info("Logical Connection Point for {} {} is {}", circuitPackName, portName, port
- .getLogicalConnectionPoint());
- portMapList.add(createMappingObject(nodeId, port, circuitPackName, port
- .getLogicalConnectionPoint()));
- } else {
- LOG.warn("Logical Connection Point value is missing for {} {}", circuitPackName, port
- .getPortName());
- }
- } else {
- LOG.warn("Port {} is not present in node {} in circuit pack {}!", portName, nodeId, circuitPackName);
- continue; // TODO continue or return true?
- }
- }
- return true;
- }
-
- private List<Degree> getDegrees(String deviceId, Info ordmInfo) {
- List<Degree> degrees = new ArrayList<>();
- Integer maxDegree;
-
- // Get value for max degree from info subtree, required for iteration
- // if not present assume to be 20 (temporary)
- if (ordmInfo.getMaxDegrees() != null) {
- maxDegree = ordmInfo.getMaxDegrees();
- } else {
- maxDegree = 20;
- }
-
- for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) {
- LOG.info("Getting Connection ports for Degree Number {}", degreeCounter);
- InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(
- Degree.class, new DegreeKey(degreeCounter));
- Optional<Degree> ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
- LogicalDatastoreType.CONFIGURATION, deviceIID, Timeouts.DEVICE_READ_TIMEOUT,
- Timeouts.DEVICE_READ_TIMEOUT_UNIT);
- if (ordmDegreeObject.isPresent()) {
- degrees.add(ordmDegreeObject.get());
- } else {
- LOG.info("Device has {} degree", degreeCounter - 1);
- break;
- }
- }
- return degrees;