b385b14ffa6847840016c2a69a89a8e8c210aadc
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / ServicehandlerTxRxCheck.java
1 /*
2  * Copyright © 2017 Orange, 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.servicehandler;
10
11 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ServiceEndpoint;
12 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ServiceFormat;
13 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.RxDirection;
14 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.TxDirection;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.lgx.Lgx;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.port.Port;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 /**
21  * Class for checking missing info on Tx/Rx for A/Z end.
22  *
23  * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
24  */
25 public class ServicehandlerTxRxCheck {
26     /* Logging. */
27     private static final Logger LOG = LoggerFactory.getLogger(ServicehandlerTxRxCheck.class);
28     /* ServiceEndpoint. */
29     private ServiceEndpoint serviceEnd;
30     /* Response message from procedure. */
31     private String message;
32     /* type serviceEndpoint : serviceAEnd / serviceZEnd. */
33     private String service = null;
34
35     /**
36      * ServicehandlerTxRxCheck class constructor.
37      *
38      * @param endPoint
39      *            ServiceEndpoint
40      * @param value
41      *            Integer to define ServiceAEND/ZEND
42      */
43     public ServicehandlerTxRxCheck(ServiceEndpoint endPoint, int value) {
44         this.serviceEnd = endPoint;
45         this.setMessage("");
46         if (value > 0) {
47             service = MyEndpoint.forValue(value).name();
48         }
49     }
50
51     /**
52      * Check if a String is not null and not equal to ''.
53      *
54      * @param value
55      *            String value
56      * @return true if String ok false if not
57      */
58     public Boolean checkString(String value) {
59         Boolean result = false;
60         if (value != null && value.compareTo("") != 0) {
61             result = true;
62         }
63         return result;
64
65     }
66
67     /**
68      * check if Port info is compliant.
69      *
70      * @param port
71      *            port info
72      * @return true if String ok false if not
73      */
74     public Boolean checkPort(Port port) {
75         Boolean result = false;
76         if (port != null) {
77             String portDeviceName = port.getPortDeviceName();
78             String portType = port.getPortType();
79             String portName = port.getPortName();
80             String portRack = port.getPortRack();
81             String portShelf = port.getPortShelf();
82
83             if (checkString(portDeviceName) && checkString(portType) && checkString(portName) && checkString(portRack)
84                     && checkString(portShelf)) {
85                 result = true;
86             }
87         }
88         return result;
89
90     }
91
92     /**
93      * Check if lgx info is compliant.
94      *
95      * @param lgx
96      *            lgx info
97      * @return true if String ok false if not
98      */
99     public Boolean checkLgx(Lgx lgx) {
100         Boolean result = false;
101         if (lgx != null) {
102             String lgxDeviceName = lgx.getLgxDeviceName();
103             String lgxPortName = lgx.getLgxPortName();
104             String lgxPortRack = lgx.getLgxPortRack();
105             String lgxPortShelf = lgx.getLgxPortShelf();
106             if (checkString(lgxDeviceName) && checkString(lgxPortName) && checkString(lgxPortRack)
107                     && checkString(lgxPortShelf)) {
108                 result = true;
109             }
110         }
111         return result;
112     }
113
114     /**
115      * Check if Tx/Rx Direction complaincy info.
116      *
117      * @param txDirection
118      *            TxDirection
119      * @param rxDirection
120      *            RxDirection
121      *
122      * @return <code>true</code> if check is ok <code>false</code> else
123      */
124     public boolean checkTxOrRxInfo(TxDirection txDirection, RxDirection rxDirection) {
125         Boolean result = true;
126         if (txDirection != null) {
127             if (!checkPort(txDirection.getPort())) {
128                 result = false;
129                 message = "Service TxDirection Port is not correctly set";
130             } else if (!checkLgx(txDirection.getLgx())) {
131                 result = false;
132                 message = "Service TxDirection Lgx is not correctly set";
133             } else if (rxDirection != null) {
134                 if (!checkPort(rxDirection.getPort())) {
135                     result = false;
136                     message = "Service RxDirection Port is not correctly set";
137                 } else if (!checkLgx(rxDirection.getLgx())) {
138                     result = false;
139                     message = "Service RxDirection Lgx is not correctly set";
140                 }
141             } else {
142                 result = false;
143                 message = "Service RxDirection is not correctly set";
144             }
145         } else {
146             result = false;
147             message = "Service TxDirection is not correctly set";
148         }
149         return result;
150     }
151
152     /**
153      * Check Compliancy of Service TxRx info.
154      *
155      * @return true if String ok false if not
156      */
157     public Boolean check() {
158         Boolean result = true;
159         if (serviceEnd != null) {
160             Long serviceRate = serviceEnd.getServiceRate();
161             ServiceFormat serviceformat = serviceEnd.getServiceFormat();
162             String clli = serviceEnd.getClli();
163             if (serviceRate != null && serviceRate <= 0) {
164                 result = false;
165                 message = "Service " + service + " rate is not set";
166                 LOG.debug(message);
167             } else if (serviceformat == null) {
168                 result = false;
169                 message = "Service " + service + " format is not set";
170                 LOG.debug(message);
171             } else if (!checkString(clli)) {
172                 result = false;
173                 message = "Service" + service + " clli format is not set";
174                 LOG.debug(message);
175             } else {
176                 if (!checkTxOrRxInfo(serviceEnd.getTxDirection(), serviceEnd.getRxDirection())) {
177                     result = false;
178                 }
179             }
180         } else {
181             result = false;
182             message = service + " is not set";
183             LOG.debug(message);
184         }
185         return result;
186
187     }
188
189     public static void main(String[] args) {
190
191     }
192
193     public String getMessage() {
194         return message;
195     }
196
197     public void setMessage(String message) {
198         this.message = message;
199     }
200
201 }