Stubpce Update
[transportpce.git] / tests / stubpce / src / main / java / org / opendaylight / transportpce / stubpce / StubpceTxRxCheck.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.stubpce;
10
11 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ServiceFormat;
12 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.lgx.Lgx;
13 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.port.Port;
14 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.ServiceEndpointSp;
15 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.service.endpoint.sp.RxDirection;
16 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.service.endpoint.sp.TxDirection;
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 StubpceTxRxCheck {
26     /** Logging. */
27     private static final Logger LOG = LoggerFactory.getLogger(StubpceTxRxCheck.class);
28     /** ServiceEndpoint. */
29     private ServiceEndpointSp 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 StubpceTxRxCheck(ServiceEndpointSp 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 (rxDirection != null) {
131                 if (!checkPort(rxDirection.getPort())) {
132                     result = false;
133                     message = "Service RxDirection Port is not correctly set";
134                 }
135             } else {
136                 result = false;
137                 message = "Service RxDirection is not correctly set";
138             }
139         } else {
140             result = false;
141             message = "Service TxDirection is not correctly set";
142         }
143         return result;
144     }
145
146     /**
147      * Check Compliancy of Service TxRx info.
148      *
149      * @return true if String ok false if not
150      */
151     public Boolean check() {
152         Boolean result = true;
153         if (serviceEnd != null) {
154             Long serviceRate = serviceEnd.getServiceRate();
155             ServiceFormat serviceformat = serviceEnd.getServiceFormat();
156             String clli = serviceEnd.getClli();
157             if (serviceRate != null && serviceRate <= 0) {
158                 result = false;
159                 message = "Service " + service + " rate is not set";
160                 LOG.info(message);
161             } else if (serviceformat == null) {
162                 result = false;
163                 message = "Service " + service + " format is not set";
164                 LOG.info(message);
165             } else if (!checkString(clli)) {
166                 result = false;
167                 message = "Service" + service + " clli format is not set";
168                 LOG.info(message);
169             } else {
170                 if (!checkTxOrRxInfo(serviceEnd.getTxDirection(), serviceEnd.getRxDirection())) {
171                     result = false;
172                 }
173             }
174         } else {
175             result = false;
176             message = service + " is not set";
177             LOG.info(message);
178         }
179         return result;
180
181     }
182
183     public static void main(String[] args) {
184
185     }
186
187     public String getMessage() {
188         return message;
189     }
190
191     public void setMessage(String message) {
192         this.message = message;
193     }
194
195 }