Skip to content

Commit 11578d1

Browse files
committed
Merge branch 'dell_sonic_share' into pimv6_mld_dev
2 parents bc9fa54 + 2c7ce1c commit 11578d1

File tree

14 files changed

+210
-194
lines changed

14 files changed

+210
-194
lines changed

cvl/custom_validation/sonic_pac.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"fmt"
2424
"strings"
2525

26+
util "github.com/Azure/sonic-mgmt-common/cvl/internal/util"
2627
log "github.com/golang/glog"
2728
)
2829

@@ -48,7 +49,7 @@ func (t *CustomValidation) ValidatePacPortChannelIntf(vc *CustValidationCtxt) CV
4849
ErrCode: CVL_SEMANTIC_ERROR,
4950
TableName: "PAC_PORT_CONFIG_TABLE",
5051
Keys: strings.Split(vc.CurCfg.Key, "|"),
51-
ConstraintErrMsg: fmt.Sprintf("Cannot configure PAC on %s interface as it is a member of a portchannel.", if_name),
52+
ConstraintErrMsg: fmt.Sprintf("Cannot configure PAC on %s interface as it is a member of a portchannel.", util.Format("ifname", if_name)),
5253
CVLErrDetails: "Config Validation Error",
5354
}
5455
}
@@ -78,7 +79,7 @@ func (t *CustomValidation) ValidateMabPortChannelIntf(vc *CustValidationCtxt) CV
7879
ErrCode: CVL_SEMANTIC_ERROR,
7980
TableName: "MAB_PORT_CONFIG_TABLE",
8081
Keys: strings.Split(vc.CurCfg.Key, "|"),
81-
ConstraintErrMsg: fmt.Sprintf("Cannot configure MAB on %s interface as it is a member of a portchannel.", if_name),
82+
ConstraintErrMsg: fmt.Sprintf("Cannot configure MAB on %s interface as it is a member of a portchannel.", util.Format("ifname", if_name)),
8283
CVLErrDetails: "Config Validation Error",
8384
}
8485
}
@@ -108,7 +109,7 @@ func (t *CustomValidation) ValidatePacRoutingIntfCheck(vc *CustValidationCtxt) C
108109
ErrCode: CVL_SEMANTIC_ERROR,
109110
TableName: "PAC_PORT_CONFIG_TABLE",
110111
Keys: strings.Split(vc.CurCfg.Key, "|"),
111-
ConstraintErrMsg: fmt.Sprintf("Cannot configure PAC on %s as it is a routing interface.", if_name),
112+
ConstraintErrMsg: fmt.Sprintf("Cannot configure PAC on %s as it is a routing interface.", util.Format("ifname", if_name)),
112113
CVLErrDetails: "Config Validation Error",
113114
}
114115
}
@@ -137,7 +138,7 @@ func (t *CustomValidation) ValidateMabRoutingIntfCheck(vc *CustValidationCtxt) C
137138
ErrCode: CVL_SEMANTIC_ERROR,
138139
TableName: "MAB_PORT_CONFIG_TABLE",
139140
Keys: strings.Split(vc.CurCfg.Key, "|"),
140-
ConstraintErrMsg: fmt.Sprintf("Cannot configure MAB on %s as it is a routing interface.", if_name),
141+
ConstraintErrMsg: fmt.Sprintf("Cannot configure MAB on %s as it is a routing interface.", util.Format("ifname", if_name)),
141142
CVLErrDetails: "Config Validation Error",
142143
}
143144
}
@@ -166,7 +167,7 @@ func (t *CustomValidation) ValidatePacMirrorSessionDstPort(vc *CustValidationCtx
166167
return CVLErrorInfo{
167168
ErrCode: CVL_SEMANTIC_ERROR,
168169
TableName: "PAC_PORT_CONFIG_TABLE",
169-
ConstraintErrMsg: fmt.Sprintf("Cannot configure PAC on %s as it is configured as destination port in a mirror session.", if_name),
170+
ConstraintErrMsg: fmt.Sprintf("Cannot configure PAC on %s as it is configured as destination port in a mirror session.", util.Format("ifname", if_name)),
170171
CVLErrDetails: "Config Validation Error",
171172
}
172173
}
@@ -194,7 +195,7 @@ func (t *CustomValidation) ValidatePacPmsPort(vc *CustValidationCtxt) CVLErrorIn
194195
ErrCode: CVL_SEMANTIC_ERROR,
195196
TableName: "PAC_PORT_CONFIG_TABLE",
196197
Keys: strings.Split(vc.CurCfg.Key, "|"),
197-
ConstraintErrMsg: fmt.Sprintf("Cannot configure PAC on %s as PMS is enabled on it.", ifname),
198+
ConstraintErrMsg: fmt.Sprintf("Cannot configure PAC on %s as PMS is enabled on it.", util.Format("ifname", ifname)),
198199
CVLErrDetails: "Config Validation Error",
199200
}
200201
}

cvl/custom_validation/sonic_subinterface.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func (t *CustomValidation) ValidateSubInterfaceIntf(vc *CustValidationCtxt) CVLE
296296
ErrCode: CVL_SEMANTIC_ERROR,
297297
TableName: "VLAN_SUB_INTERFACE",
298298
Keys: strings.Split(vc.CurCfg.Key, "|"),
299-
ConstraintErrMsg: fmt.Sprintf("Cannot configure sub-interface as %s is a member of portchannel.", parentIfName),
299+
ConstraintErrMsg: fmt.Sprintf("Cannot configure sub-interface as %s is a member of portchannel.", util.Format("ifname", parentIfName)),
300300
CVLErrDetails: "Config Validation Error",
301301
}
302302
}
@@ -330,7 +330,7 @@ func (t *CustomValidation) ValidateSubInterfaceIntf(vc *CustValidationCtxt) CVLE
330330
ErrCode: CVL_SEMANTIC_ERROR,
331331
TableName: "VLAN_SUB_INTERFACE",
332332
Keys: strings.Split(vc.CurCfg.Key, "|"),
333-
ConstraintErrMsg: fmt.Sprintf("Cannot configure sub-interface as %s has switchport config.", parentIfName),
333+
ConstraintErrMsg: fmt.Sprintf("Cannot configure sub-interface as %s has switchport config.", util.Format("ifname", parentIfName)),
334334
CVLErrDetails: "Config Validation Error",
335335
}
336336
}

cvl/cvl.go

+4
Original file line numberDiff line numberDiff line change
@@ -1102,3 +1102,7 @@ func isMandatoryTrueNode(tblName, field string) bool {
11021102

11031103
return false
11041104
}
1105+
1106+
func AddFormatterFunc(s string, f Formatter) error {
1107+
return AddToFormatterFuncsMap(s, f)
1108+
}

cvl/internal/util/util.go

+24
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ const ENV_VAR_SONIC_DB_CONFIG_FILE = "DB_CONFIG_PATH"
6868

6969
var sonic_db_config = make(map[string]interface{})
7070

71+
type Formatter func(string) string
72+
73+
var formatterFunctionsMap map[string]Formatter
74+
7175
//package init function
7276
func init() {
7377
if os.Getenv("CVL_SCHEMA_PATH") != "" {
@@ -83,6 +87,8 @@ func init() {
8387

8488
//Initialize DB settings
8589
dbCfgInit()
90+
91+
formatterFunctionsMap = make(map[string]Formatter)
8692
}
8793

8894
var cvlCfgMap map[string]string
@@ -692,3 +698,21 @@ func GetTableAndKeyFromRedisKey(redisKey, delim string) (string, string) {
692698

693699
return redisKey[:idx], redisKey[idx+1:]
694700
}
701+
702+
func AddToFormatterFuncsMap(s string, f Formatter) error {
703+
if _, ok := formatterFunctionsMap[s]; !ok {
704+
formatterFunctionsMap[s] = f
705+
} else {
706+
return fmt.Errorf("Formatter '%s' is already registered", s)
707+
}
708+
709+
return nil
710+
}
711+
712+
func Format(fname string, val string) string {
713+
if formatter, ok := formatterFunctionsMap[fname]; ok {
714+
return formatter(val)
715+
} else {
716+
return val
717+
}
718+
}

models/yang/sonic/sonic-mgmt-port.yang

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ module sonic-mgmt-port {
4848
}
4949

5050
leaf autoneg {
51-
type string;
52-
default "on";
51+
type boolean;
52+
default true;
5353
}
5454

5555
leaf alias {

translib/acl_app.go

+23-13
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ const (
102102
ACL_CLIENT_L3_REDIRECT_ACL = "L3_REDIRECT_ACL@"
103103
ACL_CLIENT_L3V6_SECURITY_ACL = "L3V6_SECURITY_ACL@"
104104
ACL_CLIENT_L3V6_REDIRECT_ACL = "L3V6_REDIRECT_ACL@"
105+
ACL_INTERNAL_FIELD_SOURCE = "_SOURCE"
105106
)
106107

107108
var IP_PROTOCOL_MAP = map[ocbinds.E_OpenconfigPacketMatchTypes_IP_PROTOCOL]uint8{
@@ -934,6 +935,7 @@ func (app *AclApp) convertDBAclToInternal(dbs [db.MaxDB]*db.DB, aclkey db.Key) e
934935
}
935936
if entry.IsPopulated() {
936937
if entry.Field[ACL_FIELD_TYPE] == SONIC_ACL_TYPE_L2 || entry.Field[ACL_FIELD_TYPE] == SONIC_ACL_TYPE_IPV4 || entry.Field[ACL_FIELD_TYPE] == SONIC_ACL_TYPE_IPV6 {
938+
entry.Field[ACL_INTERNAL_FIELD_SOURCE] = "User"
937939
app.aclTableMap[aclkey.Get(0)] = entry
938940
app.ruleTableMap[aclkey.Get(0)] = make(map[string]db.Value)
939941
err = app.convertDBAclRulesToInternal(dbs, aclkey.Get(0), "", db.Key{})
@@ -1438,7 +1440,7 @@ func convertInternalAclBindingStatusTypeToOC(status string) ocbinds.E_Openconfig
14381440
return ocStatusType
14391441
}
14401442

1441-
func (app *AclApp) getAclExtStateInfoForNameStage(statedb *db.DB, intfId string, stage string, aclName string, aclType ocbinds.E_OpenconfigAcl_ACL_TYPE, aclSetState reflect.Value) error {
1443+
func (app *AclApp) getAclExtStateInfoForNameStage(statedb *db.DB, intfId string, stage string, aclName string, aclType ocbinds.E_OpenconfigAcl_ACL_TYPE, aclSetState reflect.Value, pacBinding *bool) error {
14421444
log.Infof("Intf:%s stage:%s name:%s Type:%v", intfId, stage, aclName, aclType)
14431445

14441446
bindingTblData, bindingTblErr := statedb.GetEntry(app.aclBindStateTs, db.Key{Comp: []string{intfId, stage}})
@@ -1452,6 +1454,7 @@ func (app *AclApp) getAclExtStateInfoForNameStage(statedb *db.DB, intfId string,
14521454
prio, _ := strconv.ParseUint(parts[3], 10, 16)
14531455
prio_uint := uint16(prio)
14541456
source := convertInternalAclSourceTypeToOC(parts[1])
1457+
*pacBinding = (SONIC_ACL_SOURCE_PAC == parts[1])
14551458
aclSetState.Elem().FieldByName("Priority").Set(reflect.ValueOf(&prio_uint))
14561459
aclSetState.Elem().FieldByName("Source").Set(reflect.ValueOf(source))
14571460
if parts[2] != "" {
@@ -1477,7 +1480,6 @@ func (app *AclApp) getOCIntfAclSetData(dbs [db.MaxDB]*db.DB, intfId string, stag
14771480
// Validate and return error always.
14781481
aclDbName := app.getAclKeyByCheckingDbForNameWithoutType(dbs[db.ConfigDB], aclName, aclType)
14791482

1480-
aclDataFromStateDB := false
14811483
var aclData db.Value
14821484
if len(app.aclTableMap) > 0 && len(app.aclStateTableMap) > 0 {
14831485
var found bool
@@ -1488,7 +1490,6 @@ func (app *AclApp) getOCIntfAclSetData(dbs [db.MaxDB]*db.DB, intfId string, stag
14881490
log.Infof("ACL:%s Type:%v not found", aclDbName, aclType)
14891491
return tlerr.NotFound("ACL:%s:%v not found", aclName, aclType)
14901492
}
1491-
aclDataFromStateDB = true
14921493
}
14931494
} else {
14941495
var err error
@@ -1498,7 +1499,6 @@ func (app *AclApp) getOCIntfAclSetData(dbs [db.MaxDB]*db.DB, intfId string, stag
14981499
if err != nil {
14991500
return err
15001501
} else {
1501-
aclDataFromStateDB = true
15021502
app.aclStateTableMap[aclDbName] = aclData
15031503
}
15041504
} else {
@@ -1516,20 +1516,13 @@ func (app *AclApp) getOCIntfAclSetData(dbs [db.MaxDB]*db.DB, intfId string, stag
15161516
return tlerr.NotFound("requested binding not found for %s and %s at %s", aclName, intfId, stage)
15171517
}
15181518

1519-
if !aclDataFromStateDB {
1520-
aclSetCfg := aclSet.Elem().FieldByName("Config")
1521-
if !aclSetCfg.IsNil() {
1522-
aclSetCfg.Elem().FieldByName("SetName").Set(aclSet.Elem().FieldByName("SetName"))
1523-
aclSetCfg.Elem().FieldByName("Type").Set(aclSet.Elem().FieldByName("Type"))
1524-
}
1525-
}
1526-
1519+
pacBinding := false
15271520
aclSetState := aclSet.Elem().FieldByName("State")
15281521
if !aclSetState.IsNil() {
15291522
aclSetState.Elem().FieldByName("SetName").Set(aclSet.Elem().FieldByName("SetName"))
15301523
aclSetState.Elem().FieldByName("Type").Set(aclSet.Elem().FieldByName("Type"))
15311524
if intfId != ACL_GLOBAL_PORT && intfId != ACL_CTRL_PLANE_PORT {
1532-
err := app.getAclExtStateInfoForNameStage(dbs[db.StateDB], intfId, stage, aclName, aclType, aclSetState)
1525+
err := app.getAclExtStateInfoForNameStage(dbs[db.StateDB], intfId, stage, aclName, aclType, aclSetState, &pacBinding)
15331526
if isNotFoundError(err) {
15341527
return tlerr.NotFound("Binding not found for ACL %s on %s at %s", aclName, intfId, stage)
15351528
} else if err != nil {
@@ -1541,6 +1534,14 @@ func (app *AclApp) getOCIntfAclSetData(dbs [db.MaxDB]*db.DB, intfId string, stag
15411534
}
15421535
}
15431536

1537+
if !pacBinding {
1538+
aclSetCfg := aclSet.Elem().FieldByName("Config")
1539+
if !aclSetCfg.IsNil() {
1540+
aclSetCfg.Elem().FieldByName("SetName").Set(aclSet.Elem().FieldByName("SetName"))
1541+
aclSetCfg.Elem().FieldByName("Type").Set(aclSet.Elem().FieldByName("Type"))
1542+
}
1543+
}
1544+
15441545
// At this stage we have verified that the ACL binding exists. Starts filling the actual data
15451546
// Check if the data was requested for a specific Entry else find all the rules
15461547
aclEntries := aclSet.Elem().FieldByName("AclEntries")
@@ -3370,6 +3371,7 @@ func (app *AclApp) convertStateDBAclToInternal(dbs [db.MaxDB]*db.DB, aclkey db.K
33703371

33713372
if entry.IsPopulated() {
33723373
if entry.Field[ACL_CLIENT_FIELD_TYPE] == SONIC_ACL_TYPE_L2 || entry.Field[ACL_CLIENT_FIELD_TYPE] == SONIC_ACL_TYPE_IPV4 || entry.Field[ACL_CLIENT_FIELD_TYPE] == SONIC_ACL_TYPE_IPV6 {
3374+
entry.Field[ACL_INTERNAL_FIELD_SOURCE] = "PAC"
33733375
app.aclStateTableMap[aclkey.Get(0)] = entry
33743376
app.ruleStateTableMap[aclkey.Get(0)] = make(map[string]db.Value)
33753377
err = app.convertStateDBAclRulesToInternal(dbs, aclkey.Get(0), "", db.Key{})
@@ -3398,6 +3400,7 @@ func (app *AclApp) convertStateDBInternalToOCAcl(aclName string, aclSets *ocbind
33983400
if len(aclName) > 0 {
33993401
aclData := app.aclStateTableMap[aclName]
34003402
if aclSet != nil {
3403+
aclSet.Config = nil
34013404
aclSet.State.Name = aclSet.Name
34023405
aclSet.State.Type = aclSet.Type
34033406

@@ -3407,6 +3410,13 @@ func (app *AclApp) convertStateDBInternalToOCAcl(aclName string, aclSets *ocbind
34073410
aclSet.State.Description = &descr
34083411
} else if k == "ports@" {
34093412
continue
3413+
} else if k == ACL_INTERNAL_FIELD_SOURCE {
3414+
src := aclData.Get(k)
3415+
if src == "PAC" {
3416+
aclSet.State.Source = ocbinds.OpenconfigAclExt_ACL_SOURCE_TYPE_ACL_PAC_CREATED
3417+
} else {
3418+
aclSet.State.Source = ocbinds.OpenconfigAclExt_ACL_SOURCE_TYPE_ACL_USER_CREATED
3419+
}
34103420
}
34113421
}
34123422
app.convertStateDBInternalToOCAclRule(aclName, aclSet.Type, "", aclSet, nil)

translib/db/db.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,9 @@ func (d *DB) getEntry(ts *TableSpec, key Key, forceReadDB bool) (Value, error) {
559559

560560
if !cacheHit && !txCacheHit {
561561
// Increase (i.e. more verbose) V() level if it gets too noisy.
562-
glog.Info("getEntry: RedisCmd: ", d.Name(), ": ", "HGETALL ", entry)
562+
if glog.V(3) {
563+
glog.Info("getEntry: RedisCmd: ", d.Name(), ": ", "HGETALL ", entry)
564+
}
563565
v, e = d.client.HGetAll(entry).Result()
564566

565567
if len(v) != 0 {

translib/path_validator.go

+3
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ func (pv *pathValidator) getYangSchema() (*yang.Entry, error) {
107107
func (pv *pathValidator) getStructField(nodeName string) *reflect.StructField {
108108
var sField *reflect.StructField
109109
sval := reflect.ValueOf(pv.sValIntf).Elem()
110+
if sval.Kind() != reflect.Struct {
111+
return nil
112+
}
110113
stype := sval.Type()
111114
for i := 0; i < sval.NumField(); i++ {
112115
fType := stype.Field(i)

0 commit comments

Comments
 (0)