PCE module init
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / PceLink.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 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev170929.Link1;
12 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev170929.OpenroadmLinkType;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.NodeId;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.LinkId;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.network.Link;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 public class PceLink {
20
21     /* Logging. */
22     private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.class);
23
24     ///////////////////////// LINKS ////////////////////
25     /*
26      * extension of Link to include constraints and Graph weight
27      */
28     // double capacity = 1;
29
30     double weight = 0;
31
32     private boolean isValid = true;
33
34     // this member is for XPONDER INPUT/OUTPUT links.
35     // it keeps name of client correcponding to NETWORK TP
36     private String client = "";
37
38     private final LinkId linkId;
39     private final OpenroadmLinkType linkType;
40     private final NodeId sourceId;
41     private final NodeId destId;
42     private final Object sourceTP;
43     private final Object destTP;
44     private final LinkId oppositeLink;
45     private final Long latency;
46
47     public PceLink(Link link) {
48         LOG.debug("PceLink: : PceLink start ");
49
50         this.linkId = link.getLinkId();
51
52         this.sourceId = link.getSource().getSourceNode();
53         this.destId = link.getDestination().getDestNode();
54
55         this.sourceTP = link.getSource().getSourceTp();
56         this.destTP = link.getDestination().getDestTp();
57
58         this.linkType = calcType(link);
59
60         this.oppositeLink = calcOpposite(link);
61         this.latency = calcLatency(link);
62
63         LOG.debug("PceLink: created PceLink  {}", toString());
64     }
65
66     private OpenroadmLinkType calcType(Link link) {
67         Link1 link1 = null;
68         OpenroadmLinkType tmplType = null;
69
70         // ID and type
71         link1 = link.getAugmentation(Link1.class);
72         if (link1 == null) {
73             this.isValid = false;
74             LOG.error("PceLink: No Link augmentation available. Link is ignored {}", this.linkId);
75             return null;
76         }
77
78         tmplType = link1.getLinkType();
79         if (tmplType == null) {
80             this.isValid = false;
81             LOG.error("PceLink: No Link type available. Link is ignored {}", this.linkId);
82             return null;
83         }
84         return tmplType;
85     }
86
87     private LinkId calcOpposite(Link link) {
88         // opposite link
89         LinkId tmpoppositeLink = null;
90         org.opendaylight.yang.gen.v1.http.org.openroadm.opposite.links.rev170929.Link1 linkOpposite = link
91             .getAugmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.opposite.links.rev170929.Link1.class);
92         tmpoppositeLink = linkOpposite.getOppositeLink();
93         LOG.debug("PceLink: reading oppositeLink.  {}", linkOpposite.toString());
94         if (tmpoppositeLink == null) {
95             this.isValid = false;
96             LOG.error("PceLink: Error reading oppositeLink. Link is ignored {}", this.linkId);
97             return null;
98         }
99         return tmpoppositeLink;
100     }
101
102     private Long calcLatency(Link link) {
103         Long tmplatency = (long)0;
104         Link1 link1 = null;
105         // latency
106         link1 = link.getAugmentation(Link1.class);
107         tmplatency = link1.getLinkLatency();
108         if (tmplatency == null) {
109             tmplatency = (long) 0;
110         }
111         return tmplatency;
112
113     }
114
115
116     public LinkId getOppositeLink() {
117         return this.oppositeLink;
118     }
119
120     public Object getSourceTP() {
121         return this.sourceTP;
122     }
123
124     public Object getDestTP() {
125         return this.destTP;
126     }
127
128     public OpenroadmLinkType getLinkType() {
129         return this.linkType;
130     }
131
132     public LinkId getLinkId() {
133         return this.linkId;
134     }
135
136     public NodeId getSourceId() {
137         return this.sourceId;
138     }
139
140     public NodeId getDestId() {
141         return this.destId;
142     }
143
144     public String getClient() {
145         return this.client;
146     }
147
148     public void setClient(String client) {
149         this.client = client;
150     }
151
152     // Double for transformer of JUNG graph
153     public Double getLatency() {
154         return this.latency.doubleValue();
155     }
156
157     public boolean isValid() {
158         if ((this.linkId == null) || (this.linkType == null) || (this.oppositeLink == null)) {
159             this.isValid = false;
160             LOG.error("PceLink: No Link type or opposite link is available. Link is ignored {}", this.linkId);
161         }
162         if ((this.sourceId == null) || (this.destId == null) || (this.sourceTP == null) || (this.destTP == null)) {
163             this.isValid = false;
164             LOG.error("PceLink: No Link source or destination is available. Link is ignored {}", this.linkId);
165         }
166
167         return this.isValid;
168     }
169
170     @Override
171     public String toString() {
172         return "PceLink type=" + this.linkType + " ID=" + this.linkId.toString() + " latecy=" + this.latency;
173     }
174
175 }