Update Functional tests for SP1.6
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / PceNode.java
1 /*
2  * Copyright © 2017 AT&T, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.transportpce.pce;
10
11 import java.util.ArrayList;
12 import java.util.HashMap;
13 import java.util.List;
14 import java.util.Map;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev170929.Node1;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev170929.TerminationPoint1;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev170929.OpenroadmNodeType;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev170929.OpenroadmTpType;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.NodeId;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.network.Node;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 public class PceNode {
25
26     /* Logging. */
27     private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.class);
28
29     ////////////////////////// NODES ///////////////////////////
30     /*
31      */
32
33     private boolean valid = true;
34
35     private final Node node;
36     private final NodeId nodeId;
37     private final OpenroadmNodeType nodeType;
38
39     // wavelength calculation per node type
40     private List<Long> availableWLindex = new ArrayList<Long>();
41     private List<String> usedXpndrNWTps = new ArrayList<String>();
42
43     private List<PceLink> outgoingLinks = new ArrayList<PceLink>();
44
45     private Map<String, String> clientPerNwTp = new HashMap<String, String>();
46
47     public PceNode(Node node, OpenroadmNodeType nodeType, NodeId nodeId) {
48         this.node = node;
49         this.nodeId = nodeId;
50         this.nodeType = nodeType;
51
52         if ((node == null) || (nodeId == null) || (nodeType == null)) {
53             LOG.error("PceNode: one of parameters is not populated : nodeId, node type");
54             this.valid = false;
55         }
56     }
57
58     public void initWLlist() {
59
60         this.availableWLindex.clear();
61
62         if (!isValid()) {
63             return;
64         }
65
66         Node1 node1 = this.node.augmentation(Node1.class);
67
68         switch (this.nodeType) {
69             case SRG:
70                 List<org.opendaylight.yang.gen.v1.http.org.openroadm.srg.rev170929.srg.node.attributes
71                     .AvailableWavelengths> srgAvailableWL = node1.getSrgAttributes().getAvailableWavelengths();
72
73                 if (srgAvailableWL == null) {
74                     this.valid = false;
75                     LOG.error("initWLlist: SRG AvailableWavelengths is empty for node  {}", this.toString());
76                     return;
77                 }
78
79                 for (org.opendaylight.yang.gen.v1.http.org.openroadm.srg.rev170929.srg.node.attributes
80                     .AvailableWavelengths awl : srgAvailableWL) {
81                     this.availableWLindex.add(awl.getIndex());
82                     LOG.debug("initWLlist: SRG next = {} in {}" , awl.getIndex() , this.toString());
83                 }
84
85                 break;
86
87             case DEGREE:
88                 List<org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev170929.degree.node.attributes
89                     .AvailableWavelengths> degAvailableWL = node1.getDegreeAttributes().getAvailableWavelengths();
90
91                 if (degAvailableWL == null) {
92                     this.valid = false;
93                     LOG.error("initWLlist: DEG AvailableWavelengths is empty for node  {}", this.toString());
94                     return;
95                 }
96
97                 for (org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev170929.degree.node.attributes
98                     .AvailableWavelengths awl : degAvailableWL) {
99                     this.availableWLindex.add(awl.getIndex());
100                     LOG.debug("initWLlist: DEGREE next = {} in {}", awl.getIndex(), this.toString());
101                 }
102
103                 break;
104
105             case XPONDER:
106
107                 // HARD CODED 96
108                 for (long i = 1; i <= 96; i++) {
109                     this.availableWLindex.add(i);
110                 }
111
112                 break;
113
114             default:
115                 LOG.error("initWLlist: unsupported node type {} in node {}" , this.nodeType, this.toString());
116                 break;
117         }
118
119         if (this.availableWLindex.size() == 0) {
120             LOG.debug("initWLlist: There are no available wavelengths in node {}", this.toString());
121             this.valid = false;
122         }
123         LOG.debug("initWLlist: availableWLindex size = {} in {}" , this.availableWLindex.size(), this.toString());
124
125         return;
126     }
127
128     public void initXndrTps() {
129
130         if (!isValid()) {
131             return;
132         }
133
134         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.Node1 nodeTp =
135             this.node.augmentation(
136                 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.Node1.class);
137
138         List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.network.node
139             .TerminationPoint> allTps = nodeTp.getTerminationPoint();
140
141         if (allTps == null) {
142             this.valid = false;
143             LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this.toString());
144             return;
145         }
146
147         this.valid = false;
148
149         for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.network.node
150             .TerminationPoint tp : allTps) {
151
152             TerminationPoint1 tp1 = tp.augmentation(TerminationPoint1.class);
153
154             if (tp1.getTpType() == OpenroadmTpType.XPONDERNETWORK) {
155
156                 if (tp1.getXpdrNetworkAttributes().getWavelength() != null) {
157                     this.usedXpndrNWTps.add(tp.getTpId().getValue());
158                     LOG.debug("initWLlist: XPONDER tp = {} is used", tp.getTpId().getValue());
159                 } else {
160                     this.valid = true;
161                 }
162
163                 // find Client of this network TP
164                 String client = tp1.getXpdrNetworkAttributes().getTailEquipmentId();
165                 if ((client.equals("")) || (client == null)) {
166                     LOG.error("initXndrTps: XPONDER {} NW TP doesn't have defined Client {}",
167                         this.toString(),tp.getTpId().getValue());
168                     this.valid = false;
169                 }
170                 this.clientPerNwTp.put(tp.getTpId().getValue(), client);
171
172             }
173         }
174         if (!isValid()) {
175             LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node  {}", this.toString());
176             return;
177         }
178
179
180     }
181
182     public boolean checkTP(String tp) {
183         if (this.usedXpndrNWTps.contains(tp)) {
184             return false;
185         }
186         return true;
187     }
188
189     public boolean checkWL(long index) {
190         if (this.availableWLindex.contains(index)) {
191             return true;
192         }
193         return false;
194     }
195
196     public boolean isValid() {
197         return this.valid;
198     }
199
200     public List<Long> getAvailableWLs() {
201         return this.availableWLindex;
202     }
203
204     public void addOutgoingLink(PceLink outLink) {
205         this.outgoingLinks.add(outLink);
206     }
207
208     public List<PceLink> getOutgoingLinks() {
209         return this.outgoingLinks;
210     }
211
212     public String getClient(String tp) {
213         return this.clientPerNwTp.get(tp);
214     }
215
216     @Override
217     public String toString() {
218         return "PceNode type=" + this.nodeType + " ID=" + this.nodeId.getValue();
219     }
220
221 }