Gaurav Agrawal | b102b01 | 2016-08-02 12:52:48 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Foundation |
Gaurav Agrawal | b102b01 | 2016-08-02 12:52:48 +0530 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.yms.ymsm; |
| 18 | |
| 19 | import java.util.List; |
| 20 | |
| 21 | import org.onosproject.yms.ych.YangCodecHandler; |
VinodKumarS-Huawei | af9c7a7 | 2016-08-30 19:43:39 +0530 | [diff] [blame] | 22 | import org.onosproject.yms.ych.YangDataTreeCodec; |
| 23 | import org.onosproject.yms.ych.YangProtocolEncodingFormat; |
Gaurav Agrawal | b102b01 | 2016-08-02 12:52:48 +0530 | [diff] [blame] | 24 | import org.onosproject.yms.ydt.YdtBuilder; |
| 25 | import org.onosproject.yms.ydt.YdtResponse; |
| 26 | import org.onosproject.yms.ydt.YdtWalker; |
VinodKumarS-Huawei | af9c7a7 | 2016-08-30 19:43:39 +0530 | [diff] [blame] | 27 | import org.onosproject.yms.ydt.YmsOperationType; |
Gaurav Agrawal | b102b01 | 2016-08-02 12:52:48 +0530 | [diff] [blame] | 28 | import org.onosproject.yms.ynh.YangNotificationService; |
Bharat saraswal | f53b29a | 2016-09-27 15:35:15 +0530 | [diff] [blame] | 29 | import org.onosproject.yms.ysr.YangModuleIdentifier; |
VinodKumarS-Huawei | af9c7a7 | 2016-08-30 19:43:39 +0530 | [diff] [blame] | 30 | import org.onosproject.yms.ysr.YangModuleLibrary; |
Gaurav Agrawal | b102b01 | 2016-08-02 12:52:48 +0530 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Abstraction of an entity which provides interfaces to YANG management |
| 34 | * system. YMS is a core of YANG in ONOS. |
| 35 | * |
| 36 | * In NBI, it acts as a broker in between the protocol and application, |
| 37 | * here there is a separate protocol implementation, which does the conversion |
| 38 | * of protocol representation to abstract data tree. The protocol |
| 39 | * implementation takes care of the protocol specific actions for |
| 40 | * e.g. RESTCONF handling the entity-tag / timestamp related operations. |
| 41 | * |
| 42 | * In SBI, driver or provider uses YANG codec handler as a utility to translate |
| 43 | * the request information in java(YANG utils generated) to protocol specific |
| 44 | * format and vice versa. |
| 45 | */ |
| 46 | public interface YmsService { |
| 47 | |
| 48 | /** |
| 49 | * Returns YANG data tree builder. |
| 50 | * |
| 51 | * NBI protocol implementation takes care of the protocol specific |
| 52 | * operations. They are abstracted from the intricacies of understanding |
| 53 | * the application identification or handling the interaction with |
| 54 | * applications. |
| 55 | * |
| 56 | * NBI protocols need to handle the encoding and decoding of data to the |
| 57 | * protocol specific format. They are unaware of the YANG of applications, |
| 58 | * i.e. protocols are unaware of the data structure / organization in |
| 59 | * applications. |
| 60 | * |
| 61 | * They need to translate the protocol operation request, into a protocol |
| 62 | * independent abstract tree called the YANG data tree (YDT). In order to |
| 63 | * enable the protocol in building these abstract data tree, YANG |
| 64 | * management system provides a utility called the YANG data tree builder. |
| 65 | * |
| 66 | * Using the YANG data tree utility API's protocols are expected to walk |
| 67 | * the data received in request and pass the information during the walk. |
| 68 | * YANG data tree builder, identifies the application which supports the |
| 69 | * request and validates it against the schema defined in YANG, and |
| 70 | * constructs the abstract YANG data tree. |
| 71 | * |
| 72 | * Interaction type is a MANDATORY parameter which is used by YANG |
| 73 | * management system to perform the required operation in ONOS. |
| 74 | * |
| 75 | * NOTE: Same YDT builder instance cannot be reused across different |
| 76 | * operation request. A new instance needs to be used for every operation. |
| 77 | * |
| 78 | * Returns YANG data tree builder logical root container node. |
| 79 | * Protocol use this to logical root container to hold schema specific data |
| 80 | * that spans across different modules schema. |
| 81 | * |
| 82 | * @param logicalRootName name of a protocol specific logical container |
| 83 | * node to group data across multiple applications. |
| 84 | * This is only a logical container to group more |
| 85 | * than one application's root node. It is not |
| 86 | * validated against any YANG definition |
| 87 | * @param rootNamespace namespace of logical root container, if any, |
| 88 | * otherwise it can be sent as null |
| 89 | * @param operationType maps the request type to a corresponding |
| 90 | * operation request type to YANG management system |
| 91 | * @return YANG data tree builder, using which the abstract tree can be |
| 92 | * built corresponding to the data exchanged between protocol and YANG |
| 93 | * management system. |
| 94 | */ |
| 95 | YdtBuilder getYdtBuilder(String logicalRootName, String rootNamespace, |
| 96 | YmsOperationType operationType); |
| 97 | |
| 98 | /** |
| 99 | * Returns YANG data tree builder attached with a given schema registry. |
| 100 | * |
| 101 | * YMS provides a framework where-in protocols can register their protocol |
| 102 | * data format specific CODECS with YMS. These registered CODEC will be |
| 103 | * used by YMS to perform translations from data format to YDT and YDT to |
| 104 | * data format. YMS may intend to use these CODECS both for NBI and SBI. |
| 105 | * |
| 106 | * To perform decode i.e. generate YDT for given data format string, these |
| 107 | * CODECS implementation needs to call the API's of YDT. YDT referred the |
| 108 | * registered schema information while building tree. In case of NBI their |
| 109 | * is a single schema registry, but for SBI schema registry is per |
| 110 | * driver/provider. |
| 111 | * |
| 112 | * Now this schema registry information is provided to protocols |
| 113 | * CODECS while invoking "decodeProtocolDataToYdt" and |
| 114 | * "decodeCompositeProtocolDataToYdt", protocol CODECS needs to provide |
| 115 | * the schema registry while getting instance of YDT builder. |
| 116 | * The schemaRegistry may be null when the YMS is performing decode for NBI |
| 117 | * protocols. |
| 118 | * |
| 119 | * Validations for NBI and SBI will vary, schemaRegistry value will also |
| 120 | * indicate the usage scenario and will be used by YdtBuilder to carry out |
| 121 | * necessary validations. |
| 122 | * |
| 123 | * This is an overloaded method to YdtBuilder which MUST be used by the |
| 124 | * overridden protocols CODECS. |
| 125 | * |
| 126 | * @param logicalRootName name of a protocol specific logical container |
| 127 | * node to group data across multiple |
| 128 | * applications. |
| 129 | * This is only a logical container to group |
| 130 | * more |
| 131 | * than one application's root node. It is not |
| 132 | * validated against any YANG definition |
| 133 | * @param rootNamespace namespace of logical root container, if any, |
| 134 | * otherwise it can be sent as null |
| 135 | * @param operationType maps the request type to a corresponding |
| 136 | * operation request type to YANG management |
| 137 | * system |
| 138 | * @param schemaRegistryForYdt schema registry for Ydt, protocol CODECS get |
| 139 | * this value from YMS in |
| 140 | * "decodeProtocolDataToYdt" and |
| 141 | * "decodeCompositeProtocolDataToYdt" and |
| 142 | * provide it while obtaining YdtBuilder |
| 143 | * @return YANG data tree builder, using which the abstract tree can be |
| 144 | * built corresponding to the data exchanged between protocol and YANG |
| 145 | * management system. |
| 146 | */ |
| 147 | YdtBuilder getYdtBuilder(String logicalRootName, String rootNamespace, |
| 148 | YmsOperationType operationType, |
| 149 | Object schemaRegistryForYdt); |
| 150 | |
| 151 | /** |
| 152 | * Returns YANG data tree walker. |
| 153 | * |
| 154 | * YANG management system gets data from application to be returned |
| 155 | * in protocol operation or to notify to protocol(s) clients, YANG |
| 156 | * management system encodes the data in a YANG data tree and informs the |
| 157 | * protocol. |
| 158 | * Protocols can use the YANG data tree walker utility to have their |
| 159 | * callbacks to be invoked as per the YANG data tree walking. |
| 160 | * By this way protocols can encode the data from abstract YANG data tree |
| 161 | * into a protocol specific representation. |
| 162 | * |
| 163 | * @return YANG data tree walker utility |
| 164 | */ |
| 165 | YdtWalker getYdtWalker(); |
| 166 | |
| 167 | /** |
| 168 | * Once the NBI protocol translates the request information into an abstract |
| 169 | * YANG data tree, it uses YANG management system as a broker to get the |
| 170 | * operation executed in ONOS. |
| 171 | * |
| 172 | * YANG management system is responsible to split the protocol operation |
| 173 | * across application(s) which needs to participate, and collate the |
| 174 | * response(s) from application(s) and return an effective result of the |
| 175 | * operation request. |
| 176 | * |
| 177 | * YMS identifies the type of operation to be performed using the |
| 178 | * operation type in YANG builder data tree and process the corresponding |
| 179 | * operation request on the applicable application(s). |
| 180 | * The response information maintained in response YANG data tree and |
| 181 | * given to NBI protocol's to encode it using a YANG data tree walker. |
| 182 | * |
| 183 | * Depending on the operation type set in the YANG builder tree, the |
| 184 | * application(s) get / set / operation interface is invoked. |
| 185 | * These interface are part to the YANG modelled service interface. |
Gaurav Agrawal | b102b01 | 2016-08-02 12:52:48 +0530 | [diff] [blame] | 186 | * Depending on the operation type, the YANG response data tree can have |
| 187 | * the following information. |
| 188 | * |
| 189 | * In case of EDIT_CONFIG operation, it will have the status of the |
| 190 | * operation execution. If there is any applications schema specific |
| 191 | * error, then the schema error information will be encoded in the |
| 192 | * corresponding context node. In case the edit operation is successful |
| 193 | * there is no YANG response data tree created, hence getRootNode will |
| 194 | * return null. |
| 195 | * |
| 196 | * In case of query operation, it will have the status of the operation |
| 197 | * execution. If there is any application schema specific error, then |
| 198 | * schema error information will be encoded in the corresponding YANG |
| 199 | * context. In case the query operation is successful, YANG data tree |
| 200 | * contains the application data that matched the filter in the |
| 201 | * operation request. NBI protocol to use a Yang data tree walker to |
| 202 | * construct the protocol specific reply. |
| 203 | * |
| 204 | * In case of RPC operation, it will have the status of the operation |
| 205 | * execution. If there is any application schema specific error, then |
| 206 | * schema error information will be encoded in the corresponding YANG |
| 207 | * context. In case the RPC operation is successful, and the RPC |
| 208 | * does not have any RPC reply in YANG, then the YANG data tree will |
| 209 | * be null. |
| 210 | * In case the RPC has a RPC reply in YANG, then the YANG data tree |
| 211 | * will contain the application's RPC reply schema specific . |
| 212 | * NBI protocol to use a Yang data tree walker to construct the |
| 213 | * protocol specific reply. |
VinodKumarS-Huawei | af9c7a7 | 2016-08-30 19:43:39 +0530 | [diff] [blame] | 214 | * |
| 215 | * @param operationRequest operation request that was constructed |
| 216 | * by NBI protocol using YANG data tree |
| 217 | * builder. This operation request contains |
| 218 | * operation request that needs to be |
| 219 | * executed on the applicable application(s) |
| 220 | * @return returns the result of the operation execution. |
Gaurav Agrawal | b102b01 | 2016-08-02 12:52:48 +0530 | [diff] [blame] | 221 | */ |
| 222 | YdtResponse executeOperation(YdtBuilder operationRequest); |
| 223 | |
VinodKumarS-Huawei | af9c7a7 | 2016-08-30 19:43:39 +0530 | [diff] [blame] | 224 | /* TODO add execute operation which directly take data format string as |
| 225 | input.*/ |
Gaurav Agrawal | b102b01 | 2016-08-02 12:52:48 +0530 | [diff] [blame] | 226 | |
| 227 | /** |
| 228 | * Returns YANG notification service. |
| 229 | * |
| 230 | * NBI Protocols which can support notification delivery for application(s) |
| 231 | * needs to add themselves as a listeners with YANG notification service. |
| 232 | * Also protocols can use YANG notification service to check if a received |
| 233 | * notification should be filtered against any of their protocol specific |
| 234 | * filtering mechanism. |
| 235 | * |
| 236 | * @return YANG notification service instance |
| 237 | */ |
| 238 | YangNotificationService getYangNotificationService(); |
| 239 | |
| 240 | /** |
| 241 | * Registers service with YANG management system. |
| 242 | * |
| 243 | * Applications model their exposed interface in YANG, and register with |
| 244 | * YANG management system, so that it can be configured / managed by the |
| 245 | * set of protocols supported in ONOS. |
| 246 | * |
| 247 | * ONOS YANG tools generate the applications service interface |
| 248 | * corresponding to the application's interface designed in YANG. |
| 249 | * |
| 250 | * The Application which implements this service registers the generated |
| 251 | * service with YANG management system. The generated service interfaces |
| 252 | * have all the information modeled by applications in YANG. |
| 253 | * |
| 254 | * Registers application's YANG model with YANG management system. This |
| 255 | * is used by applications/core to register their service with YMS. |
| 256 | * |
| 257 | * @param appManager application manager instance which is |
| 258 | * implementing the service defined in YANG. |
| 259 | * @param yangService service interface generated by ONOS YANG |
| 260 | * tools corresponding to the interface modeled |
| 261 | * in YANG. |
| 262 | * @param supportedFeatureList mentions the list of YANG features supported |
| 263 | * by the application implementation. |
| 264 | * If it is null, then the application |
| 265 | * implementation supports all the features |
| 266 | * defined in the registered YANG module. |
| 267 | */ |
| 268 | void registerService(Object appManager, Class<?> yangService, |
| 269 | List<String> supportedFeatureList); |
| 270 | |
| 271 | /** |
| 272 | * Unregisters service which is registered in YANG management system. |
| 273 | * |
| 274 | * Applications model their exposed interface in YANG, and register with |
| 275 | * YANG management system, so that it can be configured / managed by the |
| 276 | * set of protocols supported in ONOS. |
| 277 | * |
| 278 | * ONOS YANG tools generate the applications service interface |
| 279 | * corresponding to the application's interface designed in YANG. |
| 280 | * |
| 281 | * The Application which implements this service registers the generated |
| 282 | * service with YANG management system. The generated service interfaces |
| 283 | * have all the information modeled by applications in YANG. |
| 284 | * |
| 285 | * Registers application's YANG model with YANG management system. This |
| 286 | * is used by applications/core to register their service with YMS. |
| 287 | * |
| 288 | * @param appManager application manager instance which is implementing |
| 289 | * the service defined in YANG. |
| 290 | * @param yangService service interface generated by ONOS YANG tools |
| 291 | * corresponding to the interface modeled in YANG. |
| 292 | */ |
| 293 | void unRegisterService(Object appManager, Class<?> yangService); |
| 294 | |
| 295 | /** |
VinodKumarS-Huawei | af9c7a7 | 2016-08-30 19:43:39 +0530 | [diff] [blame] | 296 | * Protocols like RESTCONF, share the list of YANG modules it support. |
| 297 | * using ietf-yang-library |
| 298 | * |
| 299 | * Retrieves the YANG module library supported by the server. |
| 300 | * |
| 301 | * @return YANG module library supported by the server |
| 302 | */ |
| 303 | YangModuleLibrary getYangModuleLibrary(); |
| 304 | |
| 305 | /** |
| 306 | * Protocols like RESTCONF, use the definitions within the YANG modules |
| 307 | * advertised by the server are used to construct an RPC operation or |
| 308 | * data resource identifier. |
| 309 | * |
| 310 | * Schema Resource: |
| 311 | * The server can optionally support retrieval of the YANG modules it |
| 312 | * supports. |
| 313 | * |
Bharat saraswal | f53b29a | 2016-09-27 15:35:15 +0530 | [diff] [blame] | 314 | * |
| 315 | * @param moduleIdentifier module's identifier |
VinodKumarS-Huawei | af9c7a7 | 2016-08-30 19:43:39 +0530 | [diff] [blame] | 316 | * @return YANG file contents of the requested YANG module. |
| 317 | */ |
Bharat saraswal | f53b29a | 2016-09-27 15:35:15 +0530 | [diff] [blame] | 318 | String getYangFile(YangModuleIdentifier moduleIdentifier); |
VinodKumarS-Huawei | af9c7a7 | 2016-08-30 19:43:39 +0530 | [diff] [blame] | 319 | |
| 320 | /** |
| 321 | * Register protocol specific default CODEC. This is can be used by 1st |
| 322 | * protocol |
| 323 | * to support a protocol format CODEC. This CODEC will be used in both |
| 324 | * NBI and SBI. |
| 325 | * |
| 326 | * @param defaultCodec default codec to be used for a particular protocol |
| 327 | * data format |
| 328 | * @param dataFormat data format to which encoding to be done. |
| 329 | * Currently XML and |
| 330 | * JSON formats are supported. |
| 331 | */ |
| 332 | void registerDefaultCodec(YangDataTreeCodec defaultCodec, |
| 333 | YangProtocolEncodingFormat dataFormat); |
| 334 | |
| 335 | /** |
Gaurav Agrawal | b102b01 | 2016-08-02 12:52:48 +0530 | [diff] [blame] | 336 | * Returns YANG codec handler utility. |
| 337 | * |
| 338 | * In SBI, the provider or driver uses YANG management system as a CODEC |
| 339 | * utility. These providers/drivers use the YANG codec utility to register |
| 340 | * the device schema. YANG utils is used to generate the java files |
| 341 | * corresponding to the device schema. Provider or driver use these classes |
| 342 | * to seamlessly manage the device as java objects. While sending the |
VinodKumarS-Huawei | af9c7a7 | 2016-08-30 19:43:39 +0530 | [diff] [blame] | 343 | * request |
| 344 | * to device, drivers use the utility to translate the objects to protocol |
| 345 | * specific data representation and then send to the device. |
Gaurav Agrawal | b102b01 | 2016-08-02 12:52:48 +0530 | [diff] [blame] | 346 | * Protocol or driver use the same instance of the codec utility across |
VinodKumarS-Huawei | af9c7a7 | 2016-08-30 19:43:39 +0530 | [diff] [blame] | 347 | * multiple |
| 348 | * translation request. |
| 349 | * Protocol or driver should not use the same instance of utility |
| 350 | * concurrently. |
Gaurav Agrawal | b102b01 | 2016-08-02 12:52:48 +0530 | [diff] [blame] | 351 | * |
| 352 | * @return YANG codec utility |
| 353 | */ |
| 354 | YangCodecHandler getYangCodecHandler(); |
| 355 | |
| 356 | // TODO exceptions handling and sending. |
| 357 | } |