@@ -78,6 +78,7 @@ type modelTableInfo struct {
78
78
//multiple leafref possible for union
79
79
mustExp map [string ]string
80
80
tablesForMustExp map [string ]CVLOperation
81
+ dfltLeafVal map [string ]string //map of leaf names and default value
81
82
}
82
83
83
84
@@ -94,14 +95,21 @@ type CVLErrorInfo struct {
94
95
ErrAppTag string
95
96
}
96
97
98
+ // Struct for request data and YANG data
99
+ type requestCacheType struct {
100
+ reqData CVLEditConfigData
101
+ yangData * xmlquery.Node
102
+ }
103
+
97
104
type CVL struct {
98
105
redisClient * redis.Client
99
106
yp * yparser.YParser
100
107
tmpDbCache map [string ]interface {} //map of table storing map of key-value pair
101
- requestCache map [string ]map [string ][]CVLEditConfigData //Cache of validated data,
102
- //might be used as dependent data in next request
108
+ requestCache map [string ]map [string ][]* requestCacheType //Cache of validated data,
109
+ //per table, per key. Can be used as dependent data in next request
103
110
batchLeaf string
104
111
chkLeafRefWithOthCache bool
112
+ yv * YValidator //Custom YANG validator for validating external dependencies
105
113
}
106
114
107
115
type modelNamespace struct {
@@ -205,6 +213,11 @@ func Debug(on bool) {
205
213
yparser .Debug (on )
206
214
}
207
215
216
+ // isLeafListNode checks if the xml node represents a leaf-list field
217
+ func isLeafListNode (node * xmlquery.Node ) bool {
218
+ return len (node .Attr ) != 0 && node .Attr [0 ].Name .Local == "leaf-list"
219
+ }
220
+
208
221
//Get attribute value of xml node
209
222
func getXmlNodeAttr (node * xmlquery.Node , attrName string ) string {
210
223
for _ , attr := range node .Attr {
@@ -216,6 +229,14 @@ func getXmlNodeAttr(node *xmlquery.Node, attrName string) string {
216
229
return ""
217
230
}
218
231
232
+ // getNodeName returns database field name for the xml node.
233
+ func getNodeName (node * xmlquery.Node ) string {
234
+ if isLeafListNode (node ) {
235
+ return node .Data + "@"
236
+ }
237
+ return node .Data
238
+ }
239
+
219
240
//Store useful schema data during initialization
220
241
func storeModelInfo (modelFile string , module * yparser.YParserModule ) { //such model info can be maintained in C code and fetched from there
221
242
f , err := os .Open (CVL_SCHEMA + modelFile )
@@ -394,6 +415,20 @@ func storeModelInfo(modelFile string, module *yparser.YParserModule) { //such mo
394
415
}
395
416
}
396
417
418
+ // Get YANG list to Redis table name
419
+ func getYangListToRedisTbl (yangListName string ) string {
420
+ if (strings .HasSuffix (yangListName , "_LIST" )) {
421
+ yangListName = yangListName [0 :len (yangListName ) - len ("_LIST" )]
422
+ }
423
+ tInfo , exists := modelInfo .tableInfo [yangListName ]
424
+
425
+ if exists && (tInfo .redisTableName != "" ) {
426
+ return tInfo .redisTableName
427
+ }
428
+
429
+ return yangListName
430
+ }
431
+
397
432
//Find the tables names in must expression, these tables data need to be fetched
398
433
//during semantic validation
399
434
func addTableNamesForMustExp () {
@@ -475,24 +510,30 @@ func splitRedisKey(key string) (string, string) {
475
510
return tblName , key [prefixLen :]
476
511
}
477
512
478
- //Get the YANG list name from Redis key
513
+ //Get the YANG list name from Redis key and table name
479
514
//This just returns same YANG list name as Redis table name
480
515
//when 1:1 mapping is there. For one Redis table to
481
516
//multiple YANG list, it returns appropriate YANG list name
482
517
//INTERFACE:Ethernet12 returns ==> INTERFACE
483
518
//INTERFACE:Ethernet12:1.1.1.0/32 ==> INTERFACE_IPADDR
484
- func getRedisKeyToYangList (tableName , key string ) string {
519
+ func getRedisTblToYangList (tableName , key string ) (yangList string ) {
520
+ defer func () {
521
+ pYangList := & yangList
522
+ TRACE_LOG (INFO_API , TRACE_SYNTAX , "Got YANG list '%s' " +
523
+ "from Redis Table '%s', Key '%s'" , * pYangList , tableName , key )
524
+ }()
525
+
485
526
mapArr , exists := modelInfo .redisTableToYangList [tableName ]
486
527
487
- if exists == false {
528
+ if ! exists || ( len ( mapArr ) == 1 ) { //no map or only one
488
529
//1:1 mapping case
489
530
return tableName
490
531
}
491
532
492
533
//As of now determine the mapping based on number of keys
493
534
var foundIdx int = - 1
494
535
numOfKeys := 1 //Assume only one key initially
495
- for keyDelim , _ := range modelInfo .allKeyDelims {
536
+ for keyDelim := range modelInfo .allKeyDelims {
496
537
foundIdx = strings .Index (key , keyDelim )
497
538
if (foundIdx >= 0 ) {
498
539
//Matched with key delim
@@ -505,7 +546,7 @@ func getRedisKeyToYangList(tableName, key string) string {
505
546
//Check which list has number of keys as 'numOfKeys'
506
547
for i := 0 ; i < len (mapArr ); i ++ {
507
548
tblInfo , exists := modelInfo.tableInfo [mapArr [i ]]
508
- if exists == true {
549
+ if exists {
509
550
if (len (tblInfo .keys ) == numOfKeys ) {
510
551
//Found the YANG list matching the number of keys
511
552
return mapArr [i ]
0 commit comments