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