You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -1120,15 +1120,15 @@ Transformer consists of the following components and data:
1120
1120
***Transformer Core:** perform main transformer tasks, i.e. encode/decode YGOT, traverse the payload, lookup Transformer spec, call Transformer methods, construct the results, error reporting etc.
***Overloaded Transformer methods:** callback functions invoked by Transformer core to perform complex translation with developer supplied translation logic
1123
-
***Ouput framer:** aggregate the translated pieces returned from default and overloaded methods to construct the output payload
1123
+
***Ouput framer:** aggregate the translated pieces returned from default and/or overloaded methods to construct the output payload
1124
1124
***Method overloader:** dynamically lookup and invoke the overloaded transformer methods during data translation
1125
1125
***YANG schema tree:** provides the Transformer with the schema information that can be accessed by Transformer to get node information, like default values, parent/descendant nodes, etc.
Requests from Northbound Interfaces (NBI) are processed by Translib public APIs – Create, Replace, Update, Delete, (CRUD) and Get - that call a specific method on app modules. The app modules call Transformer APIs to translate the request, then use the translated data to proceed to DB/CVL layer to set or get data. If an app module is not registered to Translib, the **common app**is used as a default application module to generically handle both SET (CRUD) and GET, and Subscribe requests with Transformer.
1131
+
Requests from Northbound Interfaces (NBI) are processed by Translib public APIs – Create, Replace, Update, Delete, (CRUD) and Get - that call a specific method on the common app module. The common app calls Transformer APIs to translate the request, then use the translated data to proceed to DB/CVL layer to set or get data in Redis DB. The **common app** as a default application module generically handles both SET (CRUD) and GET, and Subscribe requests with Transformer. Note that a specific app module can be registered to the Translib to handle the requests if needed.
@@ -1153,34 +1153,41 @@ type yangXpathInfo struct {
1153
1153
}
1154
1154
```
1155
1155
1156
-
When a request lands at the common app in the form of a YGOT structure from the Translib request handler, the request is passed to Transformer that decodes the YGOT structure to read the request payload and look up the spec to get translation hints. Note that the Transformer cannot be used for OpenAPI spec. The Transformer Spec is structured with a two-way mapping to allow Transformer to map YANG-based data to ABNF data and vice-versa via reverse lookup. The reverse mapping is used to populate the data read from RedisDB to YANG structure for the response to get operation.
1156
+
When a request lands at the common app in the form of a YGOT structure from the Translib request handler, the request is passed to Transformer that decodes the YGOT structure to read the request payload and look up the spec to get translation hints. Note that the Transformer cannot be used for OpenAPI spec. The Transformer Spec is structured with a two-way mapping to allow Transformer to map YANG-based data to ABNF data and vice-versa via reverse lookup. The reverse mapping is used to populate the data read from Redis DB to YANG structure for the response to get operation.
1157
1157
1158
-
Transformer has a built-in default transformer method to perform static, simple translation from YANG to ABNF or vice versa. It performs simple mapping - e.g. a direct name/value mapping, generating DB Keys by a concatenation of multiple YANG keys with a default delimiter `|`, which can be customized by a YANG extension.
1158
+
Transformer has a built-in default transformer method to perform static, simple translation from YANG to ABNF or vice versa. It performs simple mapping - e.g. a direct name/value mapping, table/key/field name - which can be customized by a YANG extension.
1159
1159
1160
-
Additionally, for more complex translations of non-ABNF YANG models (such as OpenConfig), Transformer also allows developers to overload the default method by specifying a method name in YANG extensions, to perform translations with developer-supplied methods as callback functions. Transformer dynamically invokes those functions instead of using default method. Each transformer method must be defined to support two-way translation, i.e, YangToDb_<transformer_method> and DbToYang_<transformer_method>, which are invoked by Transformer core.
1160
+
Additionally, for more complex translations of non-ABNF YANG models, i.e. OpenConfig models, Transformer also allows developers to overload the default method by specifying a callback fucntion in YANG extensions, to perform translations with developer-supplied translation codes as callback functions. Transformer dynamically invokes those functions instead of using default method. Each transformer callback must be defined to support two-way translation, i.e, YangToDb_<transformer_callback> and DbToYang_<transformer_callback>, which are invoked by Transformer core.
1161
1161
1162
1162
###### 3.2.2.7.3 Process
1163
1163
1164
1164
CRUD requests (configuration) are processed via the following steps:
1165
1165
1166
1166
1. App module calls transformer, passing it a YGOT populated Go structure to translate YANG to ABNF
1167
-
2. App modules calls Transformer to get the ordered list of tables and watch tables to ensure DB update in this order
1167
+
2. App module calls CVL API to get all depenent table list to watch tables, and get the ordered table list
1168
1168
3. Transformer allocates buffer with 3-dimensional map: `[table-name][key-values][attributes]`
1169
1169
4. Transformer decodes YGOT structure and traverses the incoming request to get the YANG node name
1170
1170
5. Transformer looks up the Transformer Spec to check if a translation hint exists for the given path
1171
1171
6. If no spec or hint is found, the name and value are copied as-is
1172
1172
7. If a hint is found, check the hint to perform the action, either simple data translation or invoke external callbacks
1173
1173
8. Repeat steps 4 through 7 until traversal is completed
1174
1174
9. Invoke any annotated post-Transformer functions
1175
-
10. Transformer returns the buffer to App module
1176
-
11. App module proceeds to update DB
1175
+
10. Transformer aggregates the results to returns to App module
1176
+
11. App module proceeds to update DB to ensure DB update in the order learnt from step 2
1177
1177
1178
1178
GET requests are processed via the following steps:
1179
-
1. App module asks the transformer to translate the URL with key predicates to the query target, i.e. table name and keys
1180
-
2. Transformer returns the query target
1181
-
3. App module proceeds to query the DB via DB-access to get the result
1182
-
4. App module asks the Transformer to translate from ABNF to YANG, with either default transformer method or overloaded method
1183
-
5. Transformer returns the output to the App module to unmarshall the JSON payload
1179
+
1180
+
1. App module asks the transformer to translate the URL to the keyspec to the query target
1181
+
```YANG
1182
+
type KeySpec struct {
1183
+
dbNum db.DBNum
1184
+
Tsdb.TableSpec
1185
+
Key db.Key
1186
+
Child []KeySpec
1187
+
}
1188
+
2. Transformer proceeds to traverse the DB with the keyspec to get the results
1189
+
3. Transformer translate the results from ABNF to YANG, with default transformer method or callbacks
1190
+
4. Transformer aggregate the translated results, return to the App module to unmarshall the JSON payload
1184
1191
1185
1192
###### 3.2.2.7.4 Common App
1186
1193
@@ -1193,11 +1200,11 @@ Here is a diagram to show how the common app supports SET(CRUD)/GET requests.
1193
1200

1194
1201
1195
1202
If a request is associated with multiple tables, the common app module processes the DB updates in the table order learned from CVL layer.
1196
-
e.g. in case that the sonic-acl.yang used by NBI and the payload with CRAETE operation has a data including both ACL_TABLE and ACL_RULE, the common app updates the CONFIG-DB to create an ACL TABLE instance, followed by ACL_RULE entry creation in this order. DELETE operates in the reverse order, i.e. ACL_RULE followed by ACL_TABLE.
1203
+
e.g. in case that the sonic-acl.yang used by NBI and the payload with CREATE operation has a data including both ACL_TABLE and ACL_RULE, the common app updates the CONFIG-DB to create an ACL TABLE instance, followed by ACL_RULE entry creation in this order. DELETE operates in the reverse order, i.e. ACL_RULE followed by ACL_TABLE.
1197
1204
1198
1205
###### 3.2.2.7.5 YANG Extensions
1199
1206
1200
-
The translation hints are defined as YANG extensions to support simple table/field name mapping or more complex data translation by overloading the default methods.
1207
+
The translation hints are defined as YANG extensions to support simple table/field name mapping or more complex data translation by external callbacks.
1201
1208
1202
1209
----------
1203
1210
@@ -1209,8 +1216,8 @@ The table-name is inherited to all descendant nodes unless another one is define
1209
1216
Map a YANG leafy - leaf or leaf-list - node to FIELD name, processed by the default transformer method
1210
1217
1211
1218
3.`sonic-ext:key-delimiter [string]`:
1212
-
Override the default delimiter, “|”, processed by the default transformer method. Used to concatenate multiple YANG keys of a YANG list into a single DB key.
1213
-
Note that the default delimiter “|” is used when keys are concatenated between current node and the nested nodes, i.e. container/list
1219
+
Override the default key delimiters used in Redis DB, processed by the default transformer method.
1220
+
Default delimiters are used by Transformer unless the extension is defined - CONFIG_DB: “|”, APPL_DB: “:”, ASIC_DB: “|”, COUNTERS_DB: “:”, FLEX_COUNTER_DB: “|”, STATE_DB: “|”
1214
1221
1215
1222
4.`sonic-ext:key-name [string]`:
1216
1223
Fixed key name, used for YANG container mapped to TABLE with a fixed key, processed by the default transformer method. Used to define a fixed key, mainly for container mapped to TABLE key
@@ -1221,15 +1228,15 @@ container global
1221
1228
sonic-ext:key-name “GLOBAL”
1222
1229
```
1223
1230
5.`sonic-ext:key-transformer [function]`:
1224
-
Overloading default method to generate DB keys(s), used when the key values in a YANG list are different from ones in DB TABLE.
1231
+
Overloading default method with a callback to generate DB keys(s), used when the key values in a YANG list are different from ones in DB TABLE.
1225
1232
A pair of callbacks should be implemented to support 2 way translation - **YangToDB***function*, **DbToYang***function*
1226
1233
1227
1234
6.`sonic-ext:field-transformer [function]`:
1228
-
Overloading default method to generate FIELD value, used when the leaf/leaf-list values defined in a YANG list are different from the field values in DB.
1235
+
Overloading default method with a callback to generate FIELD value, used when the leaf/leaf-list values defined in a YANG list are different from the field values in DB.
1229
1236
A pair of callbacks should be implemented to support 2 way translation - **YangToDB***function*, **DbToYang***function*
1230
1237
1231
1238
7.`sonic-ext:subtree-transformer [function]`:
1232
-
Overloading default method for the current subtree, allows the sub-tree transformer to take full control of translation. Note that, if any other extensions are annotated to the nodes on the subtree, they are not effective.
1239
+
Overloading default method with a callback for the current subtree, allows the sub-tree transformer to take full control of translation. Note that, if any other extensions, e.g. table-name etc., are annotated to the nodes on the subtree, they are not effective.
1233
1240
The subtree-transformer is inherited to all descendant nodes unless another one is defined, i.e. the scope of subtree-transformer callback is limited to the current and descendant nodes along the YANG path until a new subtree transformer is annotated.
1234
1241
A pair of callbacks should be implemented to support 2 way translation - **YangToDB***function*, **DbToYang***function*
1235
1242
@@ -1254,37 +1261,34 @@ Typically used to check the “when” condition to validate YANG node among mul
1254
1261
----------
1255
1262
1256
1263
1257
-
Note that the key-transformer, field-transformer and subtree-transformer have a pair of callbacks associated with 2 way translation using a prefix - **YangToDB***function*, **DbToYang***function*. It is not mandatory to implement both functions. E.g. if you need a translation for GET operation only, you can implement only **DbToYang***function*.
1264
+
Note that the key-transformer, field-transformer and subtree-transformer have a pair of callbacks associated with 2 way translation using a prefix - **YangToDB***function*, **DbToYang***function*. It is not mandatory to implement both functions. E.g. if a translation is required for GET operation only, you can implement only **DbToYang***function*.
1258
1265
1259
1266
The template annotation file can be generated and used by the developers to define extensions to the yang paths as needed to translate data between YANG and ABNF format. Refer to the 3.2.2.7.8 Utilities.
1260
1267
1261
1268
Here is the general guide you can check to find which extensions can be annotated in implementing your model.
1262
1269
```YANG
1263
-
1) If the translation is simple mapping between YANG container/list and TABLE, consider using the extensions - table-name, field-name, optionally key-delimiter
1264
-
2) If the translation requires a complex translation with your codes, consider the following transformer extensions - key-transformer, field-transformer, subtree-transformer to take a control during translation. Note that multiple subtree-transformers can be annotated along YANG path to divide the scope
1265
-
3) If multiple tables are mapped to a YANG list, e.g. openconfig-interface.yang, use the table-transformer to dynamically choose tables based on URI/payload
1266
-
4) In Get operation access to non CONFIG_DB, you can use the db-name extension
1267
-
5) In Get operation, you can annotate the subtree-transformer on the node to implement your own data access and translation with DbToYangxxx function
1268
-
6) In case of mapping a container to TABLE/KET, you can use the key-name along with the table-name extension
1270
+
1271
+
1. If the translation is simple mapping between YANG container/list and TABLE, consider using the extensions - table-name, field-name, optionally key-delimiter
1272
+
2. If the translation requires a complex translation with your codes, consider the following transformer extensions - key-transformer, field-transformer, subtree-transformer to take a control during translation. Note that multiple subtree-transformers can be annotated along YANG path to divide the scope
1273
+
3. If multiple tables are mapped to a YANG list, e.g. openconfig-interface.yang, use the table-transformer to dynamically choose tables based on URI/payload
1274
+
4. In Get operation access to non CONFIG_DB, you can use the db-name extension
1275
+
5. In Get operation, you can annotate the subtree-transformer on the node to implement your own data access and translation with DbToYangxxx function
1276
+
6. In case of mapping a container to TABLE/KEY, you can use the key-name along with the table-name extension
1269
1277
```
1270
1278
1271
1279
###### 3.2.2.7.6 Public Functions
1272
1280
1273
-
`XlateToDb()` and `GetAndXlateFromDb` are used by app modules to request translations.
1281
+
`XlateToDb()` and `GetAndXlateFromDb` are used by the common app to request translations.
func GetAndXlateFromDB(xpath string, uri *ygot.GoStruct, dbs [db.MaxDB]*db.DB) ([]byte, error) {}
1283
1288
1289
+
###### 3.2.2.7.7 Transformer Callbacks
1284
1290
1285
-
###### 3.2.2.7.7 Overloaded Methods
1286
-
1287
-
Overloaded transformer methods are prepended with ‘YangToDb’ or ‘DbToYang’ to support bi-directional data transfer. The function prototypes defined in the following-
1291
+
The function prototypes for external transformer callbacks are defined in the following-
1288
1292
1289
1293
```go
1290
1294
typeXfmrParamsstruct {
@@ -1734,7 +1738,9 @@ Refer to [APPENDIX](#APPENDIX) (section - "How to write CVL/SONiC Northbound YAN
1734
1738
1735
1739
* Place the main YANG modules under sonic-mgmt-framework/models/yang directory.
1736
1740
* By placing YANG module in this directory, on the next build, OpenAPI YAML (swagger spec) is generated for the YANG.
1737
-
* If there is YANG which is augmenting the main YANG module, this augmenting YANG should also be placed in sonic-mgmt-framework/models/yang directory itself.
1741
+
* If t
1742
+
*
1743
+
* here is YANG which is augmenting the main YANG module, this augmenting YANG should also be placed in sonic-mgmt-framework/models/yang directory itself.
1738
1744
* Place all dependent YANG modules which are imported into the main YANG module such as submodules or YANGs which define typedefs, etc under sonic-mgmt-framework/models/yang/common directory.
1739
1745
* By placing YANG module in this directory, OpenAPI YAML (swagger spec) is not generated for the YANG modules, but the YANGs placed under sonic-mgmt-framework/models/yang can utilize or refer to types, and other YANG constraints from the YANG modules present in this directory.
1740
1746
* Example: ietf-inet-types.yang which mainly has typedefs used by other YANG models and generally we won't prefer having a YAML for this YANG, this type of YANG files can be placed under sonic-mgmt-framework/models/yang/common.
0 commit comments