Skip to content

Commit 5fac1c1

Browse files
committed
Added the CommonApp's interface, Transformer, and Path validator details
1 parent 3fbf82a commit 5fac1c1

File tree

1 file changed

+129
-5
lines changed

1 file changed

+129
-5
lines changed

doc/mgmt/gnmi/gNMI_Subscription_for_YangData.md

+129-5
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ to support gNMI subscriptions and wildcard paths for YANG defined paths.
6666

6767
## Revision History
6868

69-
| Rev | Date | Author | Change Description |
70-
|-----|-------------|--------------------|--------------------------------------------------------|
71-
| 0.1 | 03/02/2023 | Sachin Holla | Initial draft |
69+
| Rev | Date | Author | Change Description |
70+
|-----|-------------|--------------------|-------------------------------------------------------------------------------|
71+
| 0.1 | 03/02/2023 | Sachin Holla | Initial draft |
72+
| 0.2 | 03/14/2023 | Balachandar Mani | Added the CommonApp's interface, Transformer, <br/>and Path validator details |
7273

7374
## Definition and Abbreviation
7475

@@ -874,9 +875,132 @@ type Notification struct {
874875
}
875876
```
876877

877-
### 3.3 Transformer
878+
#### 3.3 CommonApp module
878879

879-
### 3.4 gNMI Server
880+
The CommonApp is a default app that handles the GET/SET/Subscribe requests for the YANG modules unless an app module is registered to Translib.
881+
Please refer to [Management Framework HLD](https://github.com/sonic-net/SONiC/blob/master/doc/mgmt/Management%20Framework.md) for more details.
882+
883+
#### 3.3.1 CommonApp's TranslateSubscribe
884+
885+
The `TranslateSubscribe` interface will be implemented in the CommonApp to generically handle any given request path
886+
to find the DB information and preferences mapped for this path.
887+
This function will traverse the given request path to find and call the annotated key, table, and subscribe transformer
888+
accordingly to translate the YANG key into DB table key, and discover the DB number, table name, key components, and fields for its
889+
target node and all of its child nodes.
890+
891+
#### 3.3.2 CommonApp's ProcessSubscribe
892+
893+
The `ProcessSubscribe` interface will be implemented in the CommonApp to generically handle any given path
894+
to resolve YANG keys for a given DB entry.
895+
To resolve YANG keys, this function will traverse the given path to find and call its corresponding key, table, and path transformers.
896+
If there is no mapped transformer for the given path, then the given DB table key will be used as it is to resolve the YANG keys.
897+
898+
### 3.4 Transformer
899+
900+
#### 3.4.1 Subtree Subscribe transformer
901+
902+
For the subtree annotated YANG path, `SubTreeXfmrSubscribe' transformer callback function should
903+
handle the given path and all of its child node paths underneath and return the mapped DB number, table name,
904+
key components, and fields for the target node of the path and all of its child node path accordingly.
905+
906+
```go
907+
908+
// SubTreeXfmrSubscribe type is defined to use for handling subscribe(translateSubscribe & processSubscribe)
909+
// subtree transformer function definition.
910+
type SubTreeXfmrSubscribe func(inParams XfmrSubscInParams) (XfmrSubscOutParams, error)
911+
912+
// XfmrSubscInParams to represent the subscribe request info for the subtree path
913+
type XfmrSubscInParams struct {
914+
uri string // path of the subtree
915+
dbs [db.MaxDB]*db.DB // DB structure pointers
916+
subscProc SubscProcType // type of the subscription request
917+
}
918+
919+
// XfmrSubscOutParams to represent the mapped DB info., and notification preferences
920+
type XfmrSubscOutParams struct {
921+
dbDataMap RedisDbSubscribeMap // DB data map
922+
secDbDataMap RedisDbYgNodeMap // to map the DB table for leaf or leaf-list node, if this table is different from its parent node's (container/list) table
923+
onChange OnchangeMode // to enable or disable the ON_CHANGE mode
924+
nOpts *notificationOpts // to mention the sample interval, and its type
925+
isVirtualTbl bool // to specify if the DB tale is present or not
926+
}
927+
928+
// notificationOpts to define sample interval time and notification preference type
929+
type notificationOpts struct {
930+
mInterval int // sample subscription interval time
931+
pType NotificationType // to specify the notification preference types such as TARGET_DEFINED(default value), SAMPLE, ON_CHANGE.
932+
}
933+
934+
```
935+
936+
#### 3.4.2 Path transformer
937+
938+
A new transformer annotation `sonic-ext:path-transformer <transformer-name>` will be defined to specify the path transformer name
939+
to handle special cases --- subtree transformer or when there is no one-to-one mapping of YANG key to DB key.
940+
941+
A transformer callback function with name as specified in annotation must be defined in the transformer package inside the translib.
942+
This transformer function will convert the given DB table key into YANG keys of all the list nodes present in the given YANG path and fill
943+
these converted YANG keys in the given URI path by replacing the wildcard (*).
944+
945+
```go
946+
947+
// PathXfmrDbToYangFunc converts the given DB table key into the YANG key for all the list node in the given path.
948+
type PathXfmrDbToYangFunc func(params XfmrDbToYgPathParams) error
949+
950+
// XfmrDbToYgPathParams represents the input parameter of the path transformer callback function
951+
type XfmrDbToYgPathParams struct {
952+
yangPath *gnmi.Path // current path which needs to be resolved
953+
subscribePath *gnmi.Path // user input subscribe path
954+
ygSchemaPath string // current yg schema path
955+
tblName string // table name
956+
tblKeyComp []string // table key comp
957+
tblEntry *db.Value // updated or deleted db entry value
958+
dbNum db.DBNum // DB number
959+
dbs [db.MaxDB]*db.DB // DB structure pointers
960+
db *db.DB // DB pointer
961+
ygPathKeys map[string]string // to keep translated yang keys as values for each yang key leaf node
962+
}
963+
```
964+
965+
#### 3.4.3 Key transformer
966+
967+
YangToDb key transformer function should handle the wildcard (*) as a valid key present in the given YANG URI path,
968+
and return the translated mapped DB table key with wildcard.
969+
970+
#### 3.4.4 Table transformer
971+
972+
Table transformer function should handle wildcard (*) in the YANG URI path to accept the wildcard as a valid key and return the
973+
mapped table names based on the given path.
974+
975+
### 3.5 Path validator
976+
977+
To validate the syntax of the path element and its module prefix present in the given gNMI path against the YANG model.
978+
It can also add the missing valid module prefixes, and wild card keys to the path based on the input options.
979+
This validator will be used in the gNMI server to validate the path request.
980+
981+
```go
982+
983+
// NewPathValidator creates the pathValidator struct which will be used to validate the gNMI path.
984+
// PathValidatorOpt options can be AppendModulePrefix, and AddWildcardKeys.
985+
func NewPathValidator(opts ...PathValidatorOpt) *pathValidator
986+
987+
// To Validate the given gNMI path and also adds the missing module prefix, wild card keys in the given gnmi path
988+
// based on the given PathValidatorOpt while creating the path validator.
989+
func (*pathValidator) Validate(gPath *gnmi.Path) error
990+
991+
type pathValidator struct {
992+
gPath *gnmi.Path // gNMI path
993+
rootObj *ocbinds.Device // ygot root object of the YANG model
994+
sField *reflect.StructField // ygot struct field
995+
sValIntf interface{} // ygot struct field's value
996+
parentIntf interface{} // parent ygot struct
997+
opts []PathValidatorOpt // path validator options
998+
parentSchema *yang.Entry // YANG schema of the parent node
999+
err error // error information
1000+
}
1001+
```
1002+
1003+
### 3.6 gNMI Server
8801004

8811005
## 4 User Interface
8821006

0 commit comments

Comments
 (0)