+
+ private void setTerminationPointsChangedMap(CircuitPacks changedCpack) {
+ List<Ports> portsList = new ArrayList<>(Objects.requireNonNull(changedCpack.getPorts()).values());
+ for (Ports port : portsList) {
+ String lcp = port.getLogicalConnectionPoint();
+ if (lcp != null && !this.terminationPointsChanged.containsKey(lcp)) {
+ this.terminationPointsChanged.put(lcp, State.forValue(port.getOperationalState().getIntValue()));
+ }
+ }
+ }
+
+ private void updateOpenRoadmNetworkTopologyTPs(List<Node> nodesList, String nodeId) {
+ /* 1. The nodes in nodesList are abstract nodes (i.e. ROADMA01-DEG1) and we have the id of the node that has
+ a change (i.e. ROADMA01). So we only need to look for the abstract nodes that belong to the physical node. */
+ String abstractNodeId;
+ for (Node node : nodesList) {
+ abstractNodeId = Objects.requireNonNull(node.getNodeId()).getValue();
+ // Checking if the node is operationally inService
+ if (abstractNodeId.contains(nodeId) && node.augmentation(org.opendaylight.yang.gen.v1.http
+ .org.openroadm.common.network.rev200529.Node1.class)
+ .getOperationalState().equals(State.InService)) {
+ /* 2. Check if the state of the termination points from the topology shard are equal to the state of
+ the termination points in the previously created map. */
+ List<TerminationPoint> tpList = new ArrayList<>(Objects.requireNonNull(node.augmentation(Node1.class))
+ .getTerminationPoint().values());
+ Map<TerminationPointKey, TerminationPoint> updatedTpMap = new HashMap<>();
+ for (TerminationPoint tp : tpList) {
+ String tpId = Objects.requireNonNull(tp.getTpId()).getValue();
+ State tpState = Objects.requireNonNull(tp.augmentation(org.opendaylight.yang.gen.v1.http
+ .org.openroadm.common.network.rev200529.TerminationPoint1.class)).getOperationalState();
+ if (this.terminationPointsChanged.containsKey(tpId) && !this.terminationPointsChanged.get(tpId)
+ .equals(tpState)) {
+ // The state of a termination point has changed... updating
+ State newTpOperationalState = null;
+ AdminStates newTpAdminState = null;
+ /* 3. If the TP has changed its state, it has to be added to the links Map, as a Link state
+ is defined by the state of the TPs that model the link. */
+ switch (this.terminationPointsChanged.get(tpId)) {
+ case InService:
+ newTpAdminState = AdminStates.InService;
+ newTpOperationalState = State.InService;
+ // Add TP and state inService to the links Map
+ this.linksChanged.put(tpId, State.InService);
+ // TODO: update change list for service handler notification
+ break;
+ case OutOfService:
+ newTpAdminState = AdminStates.OutOfService;
+ newTpOperationalState = State.OutOfService;
+ // Add TP and state outOfService to the links Map
+ this.linksChanged.put(tpId, State.OutOfService);
+ // TODO: update change list for service handler notification
+ break;
+ case Degraded:
+ LOG.warn("Operational state Degraded not handled");
+ break;
+ default:
+ LOG.warn("Unrecognized state!");
+ }
+ // 4. Add modified TP to the updated List.
+ TerminationPoint updTp = new TerminationPointBuilder().withKey(tp.key())
+ .setTpId(tp.getTpId())
+ .addAugmentation(new TerminationPoint1Builder()
+ .setAdministrativeState(newTpAdminState)
+ .setOperationalState(newTpOperationalState)
+ .build())
+ .build();
+ updatedTpMap.put(tp.key(), updTp);
+ }
+ // 5. Update the list of termination points of the corresponding node and merge to the datastore.
+ if (!updatedTpMap.isEmpty()) {
+ Node updNode = new NodeBuilder().setNodeId(node.getNodeId()).addAugmentation(new Node1Builder()
+ .setTerminationPoint(updatedTpMap).build()).build();
+ InstanceIdentifier<Node> iiOpenRoadmTopologyNode = InstanceIdentifier.builder(
+ Networks.class).child(Network.class, new NetworkKey(
+ new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))).child(Node.class, node.key())
+ .build();
+ networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyNode,
+ updNode);
+ try {
+ networkTransactionService.commit().get();
+ } catch (InterruptedException e) {
+ LOG.error("Couldnt commit change to openroadm topology.", e);
+ Thread.currentThread().interrupt();
+ } catch (ExecutionException e) {
+ LOG.error("Couldnt commit change to openroadm topology.", e);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private void updateOpenRoadmNetworkTopologyLinks(List<Link> linkList, List<Node> nodesList) {
+ for (Link link : linkList) {
+ String srcTp = link.getSource().getSourceTp().toString();
+ String dstTp = link.getDestination().getDestTp().toString();
+ String srcNode = link.getSource().getSourceNode().getValue();
+ String dstNode = link.getDestination().getDestNode().getValue();
+ State linkState = link.augmentation(org.opendaylight.yang.gen.v1.http
+ .org.openroadm.common.network.rev200529.Link1.class).getOperationalState();
+ /* 1. Check the current state of the source and dest tps of the link. If these tps exist on the links Map
+ and the states are different, then we need to update the link state accordingly.
+ There are several cases depending on the current link state:
+ - TPs were both inService and one of them (or both) is (are) now outOfService --> link to outOfService
+ - TPs were both outOfService and both of them are now inService --> link to inService
+ However, if only one TP exists on the Link map, we will need to check the state of the other end in order to
+ make a decision: i.e. we cannot assume that if a TP has changed from outOfService to inService the link will
+ become inService, as this can only happen if both TPs are inService, therefore we need to check the other
+ end. */
+ switch (linkState) {
+ case InService:
+ if (this.linksChanged.containsKey(srcTp) && this.linksChanged.containsKey(dstTp)) {
+ // Both TPs of the link have been updated. If one of them is outOfService --> link outOfService
+ if (State.OutOfService.equals(this.linksChanged.get(srcTp)) || State.OutOfService.equals(this
+ .linksChanged.get(dstTp))) {
+ updateLinkStates(link, State.OutOfService, AdminStates.OutOfService);
+ }
+ } else if (this.linksChanged.containsKey(srcTp) && State.OutOfService.equals(this.linksChanged
+ .get(srcTp))) {
+ // Source TP has been changed to outOfService --> link outOfService
+ updateLinkStates(link, State.OutOfService, AdminStates.OutOfService);
+ } else if (this.linksChanged.containsKey(dstTp) && State.OutOfService.equals(this.linksChanged
+ .get(dstTp))) {
+ // Destination TP has been changed to outOfService --> link outOfService
+ updateLinkStates(link, State.OutOfService, AdminStates.OutOfService);
+ }
+ break;
+ case OutOfService:
+ if (this.linksChanged.containsKey(srcTp) && this.linksChanged.containsKey(dstTp)) {
+ // Both TPs of the link have been updated. If both of them are inService --> link inService
+ if (State.InService.equals(this.linksChanged.get(srcTp)) || State.InService.equals(this
+ .linksChanged.get(dstTp))) {
+ updateLinkStates(link, State.InService, AdminStates.InService);
+ }
+ } else if (this.linksChanged.containsKey(srcTp) && State.InService.equals(this.linksChanged
+ .get(srcTp))) {
+ // Source TP has been changed to inService --> check the second TP and update link to inService
+ // only if both TPs are inService
+ if (tpInService(dstNode, dstTp, nodesList)) {
+ updateLinkStates(link, State.InService, AdminStates.InService);
+ }
+ } else if (this.linksChanged.containsKey(dstTp) && State.InService.equals(this.linksChanged
+ .get(dstTp))) {
+ // Destination TP has been changed to to inService --> check the second TP and update link to
+ // inService only if both TPs are inService
+ if (tpInService(srcNode, srcTp, nodesList)) {
+ updateLinkStates(link, State.InService, AdminStates.InService);
+ }
+ }
+ break;
+ case Degraded:
+ LOG.warn("Link state degraded not handled");
+ break;
+ default:
+ LOG.warn("Unrecognized state!");
+ }
+ }
+ }
+
+ private boolean tpInService(String nodeId, String tpId, List<Node> nodesList) {
+ // Check the node with dstNode id and check the state of the TP with id dstTP id
+ for (Node node : nodesList) {
+ if (Objects.requireNonNull(node.getNodeId()).getValue().equals(nodeId)) {
+ List<TerminationPoint> tpList = new ArrayList<>(Objects.requireNonNull(Objects.requireNonNull(node
+ .augmentation(Node1.class)).getTerminationPoint()).values());
+ for (TerminationPoint tp : tpList) {
+ if (Objects.requireNonNull(tp.getTpId()).getValue().equals(tpId)) {
+ if (State.InService.equals(tp.augmentation(org.opendaylight.yang.gen.v1.http
+ .org.openroadm.common.network.rev200529.TerminationPoint1.class)
+ .getOperationalState())) {
+ // The second TP is also inService
+ return true;
+ }
+ break;
+ }
+ }
+ break;
+ }
+ }
+ return false;
+ }
+
+ private void updateLinkStates(Link link, State state, AdminStates adminStates) {
+ // TODO: add change to list of changes
+ org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1 link1 = new Link1Builder()
+ .setOperationalState(state).setAdministrativeState(adminStates).build();
+ Link updLink = new LinkBuilder().withKey(link.key()).addAugmentation(link1).build();
+ InstanceIdentifier.InstanceIdentifierBuilder<Link> linkIID = InstanceIdentifier.builder(Networks.class)
+ .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
+ .augmentation(Network1.class).child(Link.class, link.key());
+ networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, linkIID.build(), updLink);
+ try {
+ networkTransactionService.commit().get();
+ } catch (InterruptedException e) {
+ LOG.error("Couldnt commit changed to openroadm topology. Error={}", e.getMessage());
+ Thread.currentThread().interrupt();
+ } catch (ExecutionException e) {
+ LOG.error("Couldnt commit changed to openroadm topology. Error={}", e.getMessage());
+ }
+ }