@@ -63,13 +63,27 @@ var dbNameToDbNum map[string]uint8
63
63
//map of lua script loaded
64
64
var luaScripts map [string ]* redis.Script
65
65
66
+ type whenInfo struct {
67
+ expr string //when expression
68
+ exprTree * xpath.Expr //compiled expression tree
69
+ nodeNames []string //list of nodes under when condition
70
+ yangListNames []string //all yang list in expression
71
+ }
72
+
66
73
type leafRefInfo struct {
67
74
path string //leafref path
68
75
exprTree * xpath.Expr //compiled expression tree
69
76
yangListNames []string //all yang list in path
70
77
targetNodeName string //target node name
71
78
}
72
79
80
+ type mustInfo struct {
81
+ expr string //must expression
82
+ exprTree * xpath.Expr //compiled expression tree
83
+ errCode string //err-app-tag
84
+ errStr string //error message
85
+ }
86
+
73
87
//Important schema information to be loaded at bootup time
74
88
type modelTableInfo struct {
75
89
dbNum uint8
@@ -82,7 +96,8 @@ type modelTableInfo struct {
82
96
mapLeaf []string //for 'mapping list'
83
97
leafRef map [string ][]* leafRefInfo //for storing all leafrefs for a leaf in a table,
84
98
//multiple leafref possible for union
85
- mustExp map [string ]string
99
+ mustExpr map [string ][]* mustInfo
100
+ whenExpr map [string ][]* whenInfo
86
101
tablesForMustExp map [string ]CVLOperation
87
102
refFromTables []tblFieldPair //list of table or table/field referring to this table
88
103
dfltLeafVal map [string ]string //map of leaf names and default value
@@ -370,7 +385,7 @@ func storeModelInfo(modelFile string, module *yparser.YParserModule) { //such mo
370
385
fieldCount ++
371
386
keypattern := []string {tableName }
372
387
373
- /* Create the default key pattern of the form Table Name|{key1}|{key2}. */
388
+ // Create the default key pattern of the form Table Name|{key1}|{key2}.
374
389
for _ , key := range tableInfo .keys {
375
390
keypattern = append (keypattern , fmt .Sprintf ("{%s}" ,key ))
376
391
}
@@ -420,7 +435,7 @@ func storeModelInfo(modelFile string, module *yparser.YParserModule) { //such mo
420
435
continue
421
436
}
422
437
423
- tableInfo .leafRef = make (map [string ][]* leafRefInfo )
438
+ tableInfo .leafRef = make (map [string ][]* leafRefInfo )
424
439
425
440
for _ , leafRefNode := range leafRefNodes {
426
441
if (leafRefNode .Parent == nil || leafRefNode .FirstChild == nil ) {
@@ -452,7 +467,7 @@ func storeModelInfo(modelFile string, module *yparser.YParserModule) { //such mo
452
467
continue
453
468
}
454
469
455
- tableInfo .mustExp = make (map [string ]string )
470
+ tableInfo .mustExpr = make (map [string ][] * mustInfo )
456
471
for _ , mustExp := range mustExps {
457
472
if (mustExp .Parent == nil ) {
458
473
continue
@@ -467,7 +482,10 @@ func storeModelInfo(modelFile string, module *yparser.YParserModule) { //such mo
467
482
}
468
483
}
469
484
if (parentName != "" ) {
470
- tableInfo .mustExp [parentName ] = getXmlNodeAttr (mustExp , "condition" )
485
+ tableInfo .mustExpr [parentName ] = append (tableInfo .mustExpr [parentName ],
486
+ & mustInfo {
487
+ expr : getXmlNodeAttr (mustExp , "condition" ),
488
+ })
471
489
}
472
490
}
473
491
@@ -559,22 +577,22 @@ func buildRefTableInfo() {
559
577
func addTableNamesForMustExp () {
560
578
561
579
for tblName , tblInfo := range modelInfo .tableInfo {
562
- if (tblInfo .mustExp == nil ) {
580
+ if (tblInfo .mustExpr == nil ) {
563
581
continue
564
582
}
565
583
566
584
tblInfo .tablesForMustExp = make (map [string ]CVLOperation )
567
585
568
- for _ , mustExp := range tblInfo .mustExp {
586
+ for _ , mustExp := range tblInfo .mustExpr {
569
587
var op CVLOperation = OP_NONE
570
588
//Check if 'must' expression should be executed for a particular operation
571
- if (strings .Contains (mustExp ,
589
+ if (strings .Contains (mustExp [ 0 ]. expr ,
572
590
"/scommon:operation/scommon:operation != CREATE" ) == true ) {
573
591
op = op | OP_CREATE
574
- } else if (strings .Contains (mustExp ,
592
+ } else if (strings .Contains (mustExp [ 0 ]. expr ,
575
593
"/scommon:operation/scommon:operation != UPDATE" ) == true ) {
576
594
op = op | OP_UPDATE
577
- } else if (strings .Contains (mustExp ,
595
+ } else if (strings .Contains (mustExp [ 0 ]. expr ,
578
596
"/scommon:operation/scommon:operation != DELETE" ) == true ) {
579
597
op = op | OP_DELETE
580
598
}
@@ -592,7 +610,7 @@ func addTableNamesForMustExp() {
592
610
//Table name should appear like "../VLAN_MEMBER/tagging_mode' or '
593
611
// "/prt:PORT/prt:ifname"
594
612
re := regexp .MustCompile (fmt .Sprintf (".*[/]([a-zA-Z]*:)?%s[\\ [/]" , tblNameSrch ))
595
- matches := re .FindStringSubmatch (mustExp )
613
+ matches := re .FindStringSubmatch (mustExp [ 0 ]. expr )
596
614
if (len (matches ) > 0 ) {
597
615
//stores the table name
598
616
tblInfo .tablesForMustExp [tblNameSrch ] = op
@@ -881,11 +899,11 @@ func (c *CVL) checkPathForTableEntry(tableName string, currentValue string, cfgD
881
899
//Node-set function such count() can be quite expensive and
882
900
//should be avoided through this function
883
901
func (c * CVL ) addTableEntryForMustExp (cfgData * CVLEditConfigData , tableName string ) CVLRetCode {
884
- if (modelInfo .tableInfo [tableName ].mustExp == nil ) {
902
+ if (modelInfo .tableInfo [tableName ].mustExpr == nil ) {
885
903
return CVL_SUCCESS
886
904
}
887
905
888
- for fieldName , mustExp := range modelInfo .tableInfo [tableName ].mustExp {
906
+ for fieldName , mustExp := range modelInfo .tableInfo [tableName ].mustExpr {
889
907
890
908
currentValue := "" // Current value for current() function
891
909
@@ -927,7 +945,7 @@ func (c *CVL) addTableEntryForMustExp(cfgData *CVLEditConfigData, tableName stri
927
945
}
928
946
929
947
mustExpStk := []string {} //Use the string slice as stack
930
- mustExpStr := "(" + mustExp + ")"
948
+ mustExpStr := "(" + mustExp [ 0 ]. expr + ")"
931
949
strLen := len (mustExpStr )
932
950
strTmp := ""
933
951
//Parse the xpath expression and fetch Redis entry by looking at xpath,
@@ -1005,7 +1023,7 @@ func (c *CVL) addTableEntryForMustExp(cfgData *CVLEditConfigData, tableName stri
1005
1023
1006
1024
//Add all other table data for validating all 'must' exp for tableName
1007
1025
func (c * CVL ) addTableDataForMustExp (op CVLOperation , tableName string ) CVLRetCode {
1008
- if (modelInfo .tableInfo [tableName ].mustExp == nil ) {
1026
+ if (modelInfo .tableInfo [tableName ].mustExpr == nil ) {
1009
1027
return CVL_SUCCESS
1010
1028
}
1011
1029
0 commit comments