- return true;
- }
-
- /**
- * 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 deviceId
- * Device id
- * @param ordmInfo
- * Info subtree from the device
- * @return List of circuit packs object belonging to- shared risk group
- * subtree
- */
- private HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg
- .CircuitPacks>> getSrgCps(String deviceId, Info ordmInfo) {
- HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg
- .CircuitPacks>> cpPerSrg = new HashMap<>();
- 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;
- }
- for (int srgCounter = 1; srgCounter <= maxSrg; srgCounter++) {
- 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));
- Optional<SharedRiskGroup> ordmSrgObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
- LogicalDatastoreType.CONFIGURATION,
- srgIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
- if (ordmSrgObject.isPresent()) {
- srgCps.addAll(ordmSrgObject.get().getCircuitPacks());
- cpPerSrg.put(ordmSrgObject.get().getSrgNumber(), srgCps);
- }
- }
- LOG.info("Device {} has {} Srg", deviceId, cpPerSrg.size());
- return cpPerSrg;
- }
-
- /**
- * This private method gets the list of circuit packs on a xponder. For each
- * circuit pack on a Xponder, it does a get on circuit-pack subtree with
- * circuit-pack-name as key in order to get the list of ports. It then
- * iterates over the list of ports to get ports with port-qual as
- * xpdr-network/xpdr-client. The line and client ports are saved as:
- *
- * <p>
- * 1. LINEn
- *
- * <p>
- * 2. CLNTn
- *
- * @param nodeId
- * Id of 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 createXpdrPortMapping(String nodeId, List<Mapping> portMapList) {
- // Creating for Xponder Line and Client Ports
- InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
- Optional<OrgOpenroadmDevice> deviceObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
- LogicalDatastoreType.OPERATIONAL, deviceIID,
- Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-
- // Variable to keep track of number of line ports
- int line = 1;
- // Variable to keep track of number of client ports
- int client = 1;
- if (!deviceObject.isPresent() || (deviceObject.get().getCircuitPacks() == null)) {
- LOG.warn("Circuit Packs are not present for {}", nodeId);
- return false; // TODO return false or continue?
- }
-
- List<CircuitPacks> circuitPackList = deviceObject.get().getCircuitPacks();
- circuitPackList.sort(Comparator.comparing(CircuitPack::getCircuitPackName));
-
- for (CircuitPacks cp : circuitPackList) {
- String circuitPackName = cp.getCircuitPackName();
- if (cp.getPorts() == null) {
- LOG.warn("Ports were not found for circuit pack: {}", circuitPackName);
- continue;
- }
- for (Ports port : cp.getPorts()) {
- if (Port.PortQual.XpdrNetwork.equals(port.getPortQual())) {
- portMapList.add(createMappingObject(nodeId, port, circuitPackName,
- "XPDR1"+OpenRoadmInterfacesImpl.NETWORK_TOKEN + line));
- line++;
- } else if (Port.PortQual.XpdrClient.equals(port.getPortQual())) {
- portMapList.add(createMappingObject(nodeId, port, circuitPackName,
- "XPDR1"+OpenRoadmInterfacesImpl.CLIENT_TOKEN + client));
- client++;
- } else {
- LOG.warn("Not supported type of port! Port type: {}", port.getPortQual());
- }
- }
- }
- return true;
- }
-
- /**
- * This private method builds the mapping object to be pushed in MD-SAL in
- * order to save port mapping. In case of TTP ports, it also saves the
- * OTS,OMS interfaces provisioned on the port.
- *
- * @param port
- * Reference to device's port subtree object.
- * @param circuitPackName
- * Name of cp where port exists.
- * @param logicalConnectionPoint
- * logical name of the port.
- *
- * @return true/false based on status of operation
- */
-
- private Mapping createMappingObject(String nodeId, Ports port, String circuitPackName,
- String logicalConnectionPoint) {
- MappingBuilder mpBldr = new MappingBuilder();
- mpBldr.withKey(new MappingKey(logicalConnectionPoint)).setLogicalConnectionPoint(logicalConnectionPoint)
- .setSupportingCircuitPackName(circuitPackName).setSupportingPort(port.getPortName());
-
- // Get OMS and OTS interface provisioned on the TTP's
- if (logicalConnectionPoint.contains(OpenRoadmInterfacesImpl.TTP_TOKEN) && (port.getInterfaces() != null)) {
- for (Interfaces interfaces : port.getInterfaces()) {
- try {
- Optional<Interface> openRoadmInterface = this.openRoadmInterfaces.getInterface(nodeId,
- interfaces.getInterfaceName());
- if (openRoadmInterface.isPresent()) {
- Class<? extends InterfaceType> interfaceType = openRoadmInterface.get().getType();
- // Check if interface type is OMS or OTS
- if (interfaceType.equals(OpenROADMOpticalMultiplex.class)) {
- mpBldr.setSupportingOms(interfaces.getInterfaceName());
- }
- if (interfaceType.equals(OpticalTransport.class)) {
- mpBldr.setSupportingOts(interfaces.getInterfaceName());
- }
- } else {
- LOG.warn("Interface {} from node {} was null!", interfaces.getInterfaceName(), nodeId);
- }
- } catch (OpenRoadmInterfaceException ex) {
- LOG.warn("Error while getting interface {} from node {}!", interfaces.getInterfaceName(), nodeId,
- ex);
- }
- }
- }
- return mpBldr.build();
- }
-
- private static CpToDegree createCpToDegreeObject(String circuitPackName, String degreeNumber) {
- return new CpToDegreeBuilder().withKey(new CpToDegreeKey(circuitPackName)).setCircuitPackName(circuitPackName)
- .setDegreeNumber(new Long(degreeNumber)).build();
- }
-
- private static List<ConnectionPorts> getDegreePorts(List<Degree> degrees) {
- return degrees.stream().filter(degree -> degree.getConnectionPorts() != null)
- .flatMap(degree -> degree.getConnectionPorts().stream()).collect(Collectors.toList());
- }
-
- private List<CpToDegree> getCpToDegreeList(List<Degree> degrees) {
- List<CpToDegree> cpToDegreeList = new ArrayList<>();
- for (Degree degree : degrees) {
- if (degree.getCircuitPacks() != null) {
- cpToDegreeList.addAll(degree.getCircuitPacks().stream()
- .map(cp -> createCpToDegreeObject(cp.getCircuitPackName(), degree.getDegreeNumber().toString()))
- .collect(Collectors.toList()));
- }