Gaurav Agrawal | b102b01 | 2016-08-02 12:52:48 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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.ych; |
| 18 | |
Shankara-Huawei | d5823ab | 2016-11-22 10:14:52 +0530 | [diff] [blame] | 19 | import org.onosproject.yms.ydt.YmsOperationType; |
| 20 | |
VinodKumarS-Huawei | af9c7a7 | 2016-08-30 19:43:39 +0530 | [diff] [blame] | 21 | import java.util.List; |
| 22 | import java.util.Map; |
| 23 | |
Gaurav Agrawal | b102b01 | 2016-08-02 12:52:48 +0530 | [diff] [blame] | 24 | /** |
| 25 | * Abstraction of an entity which provides interfaces to YANG codec handler. |
Shankara-Huawei | d5823ab | 2016-11-22 10:14:52 +0530 | [diff] [blame] | 26 | * <p> |
Gaurav Agrawal | b102b01 | 2016-08-02 12:52:48 +0530 | [diff] [blame] | 27 | * In SBI, the provider or driver uses YANG management system as a CODEC |
VinodKumarS-Huawei | af9c7a7 | 2016-08-30 19:43:39 +0530 | [diff] [blame] | 28 | * utility. Providers/drivers register the device schema with YANG management |
| 29 | * system. YANG utils is used to generate the java files corresponding to the |
| 30 | * device schema. Provider or driver use these classes to seamlessly manage |
| 31 | * the device as java objects. While sending the request to device, drivers |
| 32 | * use the utility to translate the objects to protocol specific data |
| 33 | * representation and then send to the device. Protocol or driver use the |
| 34 | * same instance of the codec utility across multiple translation request. |
Gaurav Agrawal | b102b01 | 2016-08-02 12:52:48 +0530 | [diff] [blame] | 35 | * Protocol or driver should not use the same instance of utility concurrently. |
| 36 | */ |
| 37 | public interface YangCodecHandler { |
VinodKumarS-Huawei | af9c7a7 | 2016-08-30 19:43:39 +0530 | [diff] [blame] | 38 | /** |
| 39 | * Provider / driver needs to register the device schema with code handler. |
| 40 | * Then the provider / driver can use the codec handler to perform the |
| 41 | * codec operation. When the codec operation is being performed, the |
| 42 | * codec utility finds the mapping registered device model and perform the |
| 43 | * translation against the device schema. |
| 44 | * |
| 45 | * @param yangModule YANG utils generated class corresponding to SBI |
| 46 | * device schema module |
| 47 | */ |
Shankara-Huawei | d5823ab | 2016-11-22 10:14:52 +0530 | [diff] [blame] | 48 | void addDeviceSchema(Class<?> yangModule); |
VinodKumarS-Huawei | af9c7a7 | 2016-08-30 19:43:39 +0530 | [diff] [blame] | 49 | |
| 50 | |
| 51 | /** |
| 52 | * When the drivers / providers need to encode a protocol operation |
| 53 | * requests, which is in a single block, this encode API is used. |
| 54 | * A single protocol operation can span across multiple application, then |
| 55 | * the driver / provider need to provide the list of application(s) module |
| 56 | * object. Each module object contains the request information |
| 57 | * corresponding to that application. |
Shankara-Huawei | d5823ab | 2016-11-22 10:14:52 +0530 | [diff] [blame] | 58 | * <p> |
VinodKumarS-Huawei | af9c7a7 | 2016-08-30 19:43:39 +0530 | [diff] [blame] | 59 | * The protocols can have a logical root node which acts as a container |
| 60 | * of applications module node. For example in NETCONF, it could be |
| 61 | * data/filter/config, etc. Protocols needs to pass this parameter in the |
| 62 | * encode request, so that it is part of the encoded protocol packet. |
| 63 | * There is no validation done on the value of this parameter. It is up to |
| 64 | * the protocol to use it. It is a mandatory parameter and protocols must |
| 65 | * pass this parameter. In protocols like NETCONF, these logical root |
| 66 | * node may be in a specific name space, in such cases, it needs to be |
| 67 | * passed to encode it as part of the request. There could be additional |
| 68 | * tags that can be attached to the root node, for example in NETCONF, |
| 69 | * the tag type="subtree" can be specified. In such scenarios the |
| 70 | * required tags should be sent as a parameter. |
Shankara-Huawei | d5823ab | 2016-11-22 10:14:52 +0530 | [diff] [blame] | 71 | * <p> |
VinodKumarS-Huawei | af9c7a7 | 2016-08-30 19:43:39 +0530 | [diff] [blame] | 72 | * The provider / driver would require to operate on multiple schema |
| 73 | * nodes in a single request, for example it may be require to configure |
| 74 | * a tunnel and associate a QOS to this tunnel, in this scenario, it |
| 75 | * needs to have the tunnel related information in the tunnel module's |
| 76 | * Java object and and QOS related information in QOS modules Java |
| 77 | * object. So in a single request, it can send the list of Java objects |
| 78 | * corresponding to the modules which need to participate in the operation. |
| 79 | * If the request to be generated needs to be a wild card for no |
| 80 | * application(s), then this parameter needs to be null. For example a |
| 81 | * "empty filter" request in NETCONF get request. |
Shankara-Huawei | d5823ab | 2016-11-22 10:14:52 +0530 | [diff] [blame] | 82 | * <p> |
VinodKumarS-Huawei | af9c7a7 | 2016-08-30 19:43:39 +0530 | [diff] [blame] | 83 | * If the request to be generated needs to be a wild card for all |
| 84 | * application(s), then the driver / provider should not invoke this API, |
| 85 | * as there is no encoding of application related information for the |
| 86 | * operation, it is only limited to the protocol operation. For example a |
| 87 | * "no filter" request in NETCONF get request. |
| 88 | * |
| 89 | * @param rootName name of logical root node as required by |
| 90 | * the protocol |
| 91 | * @param rootNamespace namespace of logical root node as |
| 92 | * required by the protocol encoding. It is |
| 93 | * an optional parameter. |
| 94 | * @param tagAttributeLinkedMap Specifies the list of attributes that |
| 95 | * needs to be tagged with the logical root |
| 96 | * node. It is an optional parameter |
| 97 | * if not required for the protocol. |
| 98 | * @param yangModuleList list of YANG module's object(s) |
| 99 | * participating in the operation. |
| 100 | * @param dataFormat data format to which encoding to be done. |
| 101 | * @param protocolOperation protocol operation being performed |
| 102 | * @return string containing the requested applications object |
| 103 | * information encoded in protocol format. |
| 104 | */ |
| 105 | String encodeOperation(String rootName, String rootNamespace, |
| 106 | Map<String, String> tagAttributeLinkedMap, |
| 107 | List<Object> yangModuleList, |
| 108 | YangProtocolEncodingFormat dataFormat, |
| 109 | YmsOperationType protocolOperation); |
| 110 | |
| 111 | /** |
| 112 | * When the drivers / providers need to encode protocol composite |
| 113 | * operation requests, which is split in a composite blocks, this encode |
| 114 | * composite operation API is used. The application module object |
| 115 | * containing the request information has both the resource identifier |
| 116 | * part and the resource information part. |
Shankara-Huawei | d5823ab | 2016-11-22 10:14:52 +0530 | [diff] [blame] | 117 | * <p> |
VinodKumarS-Huawei | af9c7a7 | 2016-08-30 19:43:39 +0530 | [diff] [blame] | 118 | * The protocols can have a logical root node which acts as a container |
| 119 | * of applications module node. For example in RESTCONF, it could be |
| 120 | * RootResource/data, etc. There is no validation done on the value |
| 121 | * of this parameter. It is upto the protocol to use it. It is a |
| 122 | * mandatory parameter and protocols must pass this parameter. |
Shankara-Huawei | d5823ab | 2016-11-22 10:14:52 +0530 | [diff] [blame] | 123 | * <p> |
VinodKumarS-Huawei | af9c7a7 | 2016-08-30 19:43:39 +0530 | [diff] [blame] | 124 | * The resource to be operated upon in the device is identified in a |
| 125 | * module's schema object. This modules object should contain the |
| 126 | * information about the resource on which the operation needs to be |
| 127 | * performed. The resource is identified by initial chain of objects for |
| 128 | * which operation type is none. Once the resource is reached using none |
| 129 | * operations, the actual information about the operation on the device |
| 130 | * is encoded. |
| 131 | * |
| 132 | * @param rootName name of logical root node as required by the |
| 133 | * protocol |
| 134 | * @param rootNamespace namespace of logical root node as required by |
| 135 | * the |
| 136 | * protocol encoding. It is optional, and there |
| 137 | * is no |
| 138 | * namespace set to the logical root node |
| 139 | * @param appModuleObject object containing the information about the |
| 140 | * resource on which the operation is being |
| 141 | * performed |
| 142 | * @param dataFormat data format to which request needs to |
| 143 | * be encoded |
| 144 | * @param protocolOperation protocol operation being performed |
| 145 | * @return the composite protocol operation request. |
| 146 | */ |
| 147 | YangCompositeEncoding encodeCompositeOperation(String rootName, |
| 148 | String rootNamespace, |
| 149 | Object appModuleObject, |
| 150 | YangProtocolEncodingFormat |
| 151 | dataFormat, |
| 152 | YmsOperationType |
| 153 | protocolOperation); |
| 154 | |
| 155 | /** |
| 156 | * When the driver or provider receive the data from the SBI protocol, It |
| 157 | * will be in the protocol specific data representation. Drivers / |
| 158 | * provider need to interact with the device using native JAVA objects. |
| 159 | * Drivers use this decode method to translate the received |
| 160 | * protocol specific simple data to YANG modeled Java objects. |
| 161 | * If the response received is not in line with the schema, for example, |
| 162 | * there is some error info, etc, then the decode operation will throw an |
| 163 | * exception and decode operation will fail. |
| 164 | * |
| 165 | * @param protocolData input string containing the resource information |
| 166 | * in protocol format |
| 167 | * @param dataFormat data format from which decoding has to be done |
| 168 | * @param protocolOperation protocol operation being performed |
| 169 | * @return list of applications module/notification objects corresponding |
| 170 | * to the protocol data input |
| 171 | */ |
| 172 | List<Object> decode(String protocolData, |
| 173 | YangProtocolEncodingFormat dataFormat, |
| 174 | YmsOperationType protocolOperation); |
| 175 | |
| 176 | /** |
| 177 | * When the driver or provider receive the composite data from the SBI |
| 178 | * protocol, It will be in the protocol specific data representation. |
| 179 | * Drivers / provider need to interact with the device |
| 180 | * using native JAVA objects. Drivers use this Decode method to translate |
| 181 | * the received protocol specific composite data to YANG modeled Java |
| 182 | * objects. |
Shankara-Huawei | d5823ab | 2016-11-22 10:14:52 +0530 | [diff] [blame] | 183 | * <p> |
VinodKumarS-Huawei | af9c7a7 | 2016-08-30 19:43:39 +0530 | [diff] [blame] | 184 | * If the response received is not in line with the schema, for example, |
| 185 | * there is some error info, etc, then the decode operation will throw an |
| 186 | * exception and decode operation will fail. |
| 187 | * |
| 188 | * @param protocolData composite protocol data containing the resource |
| 189 | * information |
| 190 | * @param dataFormat data format from which decoding has to be done |
| 191 | * @param protocolOperation protocol operation being performed |
| 192 | * @return application module/notification object corresponding to the |
| 193 | * protocol data infput |
| 194 | */ |
| 195 | Object decode(YangCompositeEncoding protocolData, |
| 196 | YangProtocolEncodingFormat dataFormat, |
| 197 | YmsOperationType protocolOperation); |
| 198 | |
| 199 | /** |
| 200 | * Register the provider / driver specific overridden codec. This is can |
| 201 | * be used by provider to support any protocol specific extension or |
| 202 | * vendor specific implementation. This framework can also be used |
| 203 | * by providers / drivers to support any new protocol data format which |
| 204 | * is not supported by default in YANG codec utility. |
| 205 | * |
| 206 | * @param overriddenCodec provider / driver specific overridden instance |
| 207 | * of the codec |
| 208 | * @param dataFormat data format to which encoding to be done. |
| 209 | */ |
| 210 | void registerOverriddenCodec(YangDataTreeCodec overriddenCodec, |
| 211 | YangProtocolEncodingFormat dataFormat); |
Gaurav Agrawal | b102b01 | 2016-08-02 12:52:48 +0530 | [diff] [blame] | 212 | } |