2 * Copyright © 2017 AT&T, Inc. and others. All rights reserved.
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
9 package org.opendaylight.transportpce.pce;
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;
19 public class PceLink {
22 private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.class);
24 ///////////////////////// LINKS ////////////////////
26 * extension of Link to include constraints and Graph weight
28 // double capacity = 1;
32 private boolean isValid = true;
34 // this member is for XPONDER INPUT/OUTPUT links.
35 // it keeps name of client correcponding to NETWORK TP
36 private String client = "";
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;
47 public PceLink(Link link) {
48 LOG.debug("PceLink: : PceLink start ");
50 this.linkId = link.getLinkId();
52 this.sourceId = link.getSource().getSourceNode();
53 this.destId = link.getDestination().getDestNode();
55 this.sourceTP = link.getSource().getSourceTp();
56 this.destTP = link.getDestination().getDestTp();
58 this.linkType = calcType(link);
60 this.oppositeLink = calcOpposite(link);
61 this.latency = calcLatency(link);
63 LOG.debug("PceLink: created PceLink {}", toString());
66 private OpenroadmLinkType calcType(Link link) {
68 OpenroadmLinkType tmplType = null;
71 link1 = link.augmentation(Link1.class);
74 LOG.error("PceLink: No Link augmentation available. Link is ignored {}", this.linkId);
78 tmplType = link1.getLinkType();
79 if (tmplType == null) {
81 LOG.error("PceLink: No Link type available. Link is ignored {}", this.linkId);
87 private LinkId calcOpposite(Link link) {
89 LinkId tmpoppositeLink = null;
90 org.opendaylight.yang.gen.v1.http.org.openroadm.opposite.links.rev170929.Link1 linkOpposite = link
91 .augmentation(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) {
96 LOG.error("PceLink: Error reading oppositeLink. Link is ignored {}", this.linkId);
99 return tmpoppositeLink;
102 private Long calcLatency(Link link) {
103 Long tmplatency = (long)0;
106 link1 = link.augmentation(Link1.class);
107 tmplatency = link1.getLinkLatency();
108 if (tmplatency == null) {
109 tmplatency = (long) 0;
116 public LinkId getOppositeLink() {
117 return this.oppositeLink;
120 public Object getSourceTP() {
121 return this.sourceTP;
124 public Object getDestTP() {
128 public OpenroadmLinkType getLinkType() {
129 return this.linkType;
132 public LinkId getLinkId() {
136 public NodeId getSourceId() {
137 return this.sourceId;
140 public NodeId getDestId() {
144 public String getClient() {
148 public void setClient(String client) {
149 this.client = client;
152 // Double for transformer of JUNG graph
153 public Double getLatency() {
154 return this.latency.doubleValue();
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);
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);
171 public String toString() {
172 return "PceLink type=" + this.linkType + " ID=" + this.linkId.toString() + " latecy=" + this.latency;