3a340616b895beece0a848fe32998f91dd44f9a5
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / PceResult.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.transportpce.common.ResponseCodes;
12 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.AToZDirection;
13 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ZToADirection;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 public class PceResult {
18     /* Logging. */
19     private static final Logger LOG = LoggerFactory.getLogger(PceResult.class);
20     private String calcMessage = "503 Calculator Unavailable";
21     private boolean calcStatus = false;
22     private String responseCode = ResponseCodes.RESPONSE_FAILED;
23     private long resultWavelength = -1;
24     private long rate = -1; // for now it is constant returned as received from A-end
25
26     public enum LocalCause {
27         NONE, TOO_HIGH_LATENCY, NO_PATH_EXISTS, INT_PROBLEM;
28     }
29
30     private LocalCause localCause = LocalCause.NONE;
31
32     private AToZDirection atozdirection = null;
33     private ZToADirection ztoadirection = null;
34
35     public PceResult() {
36     }
37
38     public void setRC(String rc) {
39         switch (rc) {
40             case ResponseCodes.RESPONSE_OK:
41                 this.calcMessage = "Path is calculated";
42                 this.calcStatus = true;
43                 this.responseCode = ResponseCodes.RESPONSE_OK;
44                 break;
45             case ResponseCodes.RESPONSE_FAILED:
46                 this.responseCode = ResponseCodes.RESPONSE_FAILED;
47                 this.calcStatus = false;
48                 this.calcMessage = "No path available";
49                 break;
50             default:
51                 LOG.error("setRC: RespondeCodes unknown");//requires sl4j but not imported
52         }
53     }
54
55     @Override
56     public String toString() {
57         return ("[" + this.calcMessage + "] code:[" + this.responseCode + "] wavelength=" + this.resultWavelength
58                 + " localCause=" + this.localCause + " rate=" + this.rate);
59     }
60
61     public boolean getStatus() {
62         return this.calcStatus;
63     }
64
65     public String getMessage() {
66         return this.calcMessage;
67     }
68
69     public String getResponseCode() {
70         return this.responseCode;
71     }
72
73     public long getResultWavelength() {
74         return this.resultWavelength;
75     }
76
77     public void setResultWavelength(long resultWavelength) {
78         this.resultWavelength = resultWavelength;
79     }
80
81     public AToZDirection getAtoZDirection() {
82         return this.atozdirection;
83     }
84
85     public ZToADirection getZtoADirection() {
86         return this.ztoadirection;
87     }
88
89     public void setAtoZDirection(AToZDirection atozdirectionIn) {
90         this.atozdirection = atozdirectionIn;
91     }
92
93     public void setZtoADirection(ZToADirection ztoadirectionIn) {
94         this.ztoadirection = ztoadirectionIn;
95     }
96
97     public long getRate() {
98         return this.rate;
99     }
100
101     public void setRate(long rate) {
102         this.rate = rate;
103     }
104
105     public LocalCause getLocalCause() {
106         return this.localCause;
107     }
108
109     public void setLocalCause(LocalCause lc) {
110         // For now keep the very first fatal problem
111         // TODO. Later this value might become history of algo if all significant problems are added here as to List
112         if (this.localCause == LocalCause.NONE) {
113             this.localCause = lc;
114         }
115     }
116
117
118     public void setCalcMessage(String calcMessage) {
119         this.calcMessage = calcMessage;
120     }
121
122
123 }