Skip to content

Commit

Permalink
Merge branch 'dell_sonic_share' into pimv6_mld_dev
Browse files Browse the repository at this point in the history
  • Loading branch information
vidya.chidambaram committed Feb 25, 2022
2 parents bc9fa54 + 2c7ce1c commit 11578d1
Show file tree
Hide file tree
Showing 14 changed files with 210 additions and 194 deletions.
13 changes: 7 additions & 6 deletions cvl/custom_validation/sonic_pac.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"strings"

util "github.com/Azure/sonic-mgmt-common/cvl/internal/util"
log "github.com/golang/glog"
)

Expand All @@ -48,7 +49,7 @@ func (t *CustomValidation) ValidatePacPortChannelIntf(vc *CustValidationCtxt) CV
ErrCode: CVL_SEMANTIC_ERROR,
TableName: "PAC_PORT_CONFIG_TABLE",
Keys: strings.Split(vc.CurCfg.Key, "|"),
ConstraintErrMsg: fmt.Sprintf("Cannot configure PAC on %s interface as it is a member of a portchannel.", if_name),
ConstraintErrMsg: fmt.Sprintf("Cannot configure PAC on %s interface as it is a member of a portchannel.", util.Format("ifname", if_name)),
CVLErrDetails: "Config Validation Error",
}
}
Expand Down Expand Up @@ -78,7 +79,7 @@ func (t *CustomValidation) ValidateMabPortChannelIntf(vc *CustValidationCtxt) CV
ErrCode: CVL_SEMANTIC_ERROR,
TableName: "MAB_PORT_CONFIG_TABLE",
Keys: strings.Split(vc.CurCfg.Key, "|"),
ConstraintErrMsg: fmt.Sprintf("Cannot configure MAB on %s interface as it is a member of a portchannel.", if_name),
ConstraintErrMsg: fmt.Sprintf("Cannot configure MAB on %s interface as it is a member of a portchannel.", util.Format("ifname", if_name)),
CVLErrDetails: "Config Validation Error",
}
}
Expand Down Expand Up @@ -108,7 +109,7 @@ func (t *CustomValidation) ValidatePacRoutingIntfCheck(vc *CustValidationCtxt) C
ErrCode: CVL_SEMANTIC_ERROR,
TableName: "PAC_PORT_CONFIG_TABLE",
Keys: strings.Split(vc.CurCfg.Key, "|"),
ConstraintErrMsg: fmt.Sprintf("Cannot configure PAC on %s as it is a routing interface.", if_name),
ConstraintErrMsg: fmt.Sprintf("Cannot configure PAC on %s as it is a routing interface.", util.Format("ifname", if_name)),
CVLErrDetails: "Config Validation Error",
}
}
Expand Down Expand Up @@ -137,7 +138,7 @@ func (t *CustomValidation) ValidateMabRoutingIntfCheck(vc *CustValidationCtxt) C
ErrCode: CVL_SEMANTIC_ERROR,
TableName: "MAB_PORT_CONFIG_TABLE",
Keys: strings.Split(vc.CurCfg.Key, "|"),
ConstraintErrMsg: fmt.Sprintf("Cannot configure MAB on %s as it is a routing interface.", if_name),
ConstraintErrMsg: fmt.Sprintf("Cannot configure MAB on %s as it is a routing interface.", util.Format("ifname", if_name)),
CVLErrDetails: "Config Validation Error",
}
}
Expand Down Expand Up @@ -166,7 +167,7 @@ func (t *CustomValidation) ValidatePacMirrorSessionDstPort(vc *CustValidationCtx
return CVLErrorInfo{
ErrCode: CVL_SEMANTIC_ERROR,
TableName: "PAC_PORT_CONFIG_TABLE",
ConstraintErrMsg: fmt.Sprintf("Cannot configure PAC on %s as it is configured as destination port in a mirror session.", if_name),
ConstraintErrMsg: fmt.Sprintf("Cannot configure PAC on %s as it is configured as destination port in a mirror session.", util.Format("ifname", if_name)),
CVLErrDetails: "Config Validation Error",
}
}
Expand Down Expand Up @@ -194,7 +195,7 @@ func (t *CustomValidation) ValidatePacPmsPort(vc *CustValidationCtxt) CVLErrorIn
ErrCode: CVL_SEMANTIC_ERROR,
TableName: "PAC_PORT_CONFIG_TABLE",
Keys: strings.Split(vc.CurCfg.Key, "|"),
ConstraintErrMsg: fmt.Sprintf("Cannot configure PAC on %s as PMS is enabled on it.", ifname),
ConstraintErrMsg: fmt.Sprintf("Cannot configure PAC on %s as PMS is enabled on it.", util.Format("ifname", ifname)),
CVLErrDetails: "Config Validation Error",
}
}
Expand Down
4 changes: 2 additions & 2 deletions cvl/custom_validation/sonic_subinterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func (t *CustomValidation) ValidateSubInterfaceIntf(vc *CustValidationCtxt) CVLE
ErrCode: CVL_SEMANTIC_ERROR,
TableName: "VLAN_SUB_INTERFACE",
Keys: strings.Split(vc.CurCfg.Key, "|"),
ConstraintErrMsg: fmt.Sprintf("Cannot configure sub-interface as %s is a member of portchannel.", parentIfName),
ConstraintErrMsg: fmt.Sprintf("Cannot configure sub-interface as %s is a member of portchannel.", util.Format("ifname", parentIfName)),
CVLErrDetails: "Config Validation Error",
}
}
Expand Down Expand Up @@ -330,7 +330,7 @@ func (t *CustomValidation) ValidateSubInterfaceIntf(vc *CustValidationCtxt) CVLE
ErrCode: CVL_SEMANTIC_ERROR,
TableName: "VLAN_SUB_INTERFACE",
Keys: strings.Split(vc.CurCfg.Key, "|"),
ConstraintErrMsg: fmt.Sprintf("Cannot configure sub-interface as %s has switchport config.", parentIfName),
ConstraintErrMsg: fmt.Sprintf("Cannot configure sub-interface as %s has switchport config.", util.Format("ifname", parentIfName)),
CVLErrDetails: "Config Validation Error",
}
}
Expand Down
4 changes: 4 additions & 0 deletions cvl/cvl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1102,3 +1102,7 @@ func isMandatoryTrueNode(tblName, field string) bool {

return false
}

func AddFormatterFunc(s string, f Formatter) error {
return AddToFormatterFuncsMap(s, f)
}
24 changes: 24 additions & 0 deletions cvl/internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ const ENV_VAR_SONIC_DB_CONFIG_FILE = "DB_CONFIG_PATH"

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

type Formatter func(string) string

var formatterFunctionsMap map[string]Formatter

//package init function
func init() {
if os.Getenv("CVL_SCHEMA_PATH") != "" {
Expand All @@ -83,6 +87,8 @@ func init() {

//Initialize DB settings
dbCfgInit()

formatterFunctionsMap = make(map[string]Formatter)
}

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

return redisKey[:idx], redisKey[idx+1:]
}

func AddToFormatterFuncsMap(s string, f Formatter) error {
if _, ok := formatterFunctionsMap[s]; !ok {
formatterFunctionsMap[s] = f
} else {
return fmt.Errorf("Formatter '%s' is already registered", s)
}

return nil
}

func Format(fname string, val string) string {
if formatter, ok := formatterFunctionsMap[fname]; ok {
return formatter(val)
} else {
return val
}
}
4 changes: 2 additions & 2 deletions models/yang/sonic/sonic-mgmt-port.yang
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ module sonic-mgmt-port {
}

leaf autoneg {
type string;
default "on";
type boolean;
default true;
}

leaf alias {
Expand Down
36 changes: 23 additions & 13 deletions translib/acl_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const (
ACL_CLIENT_L3_REDIRECT_ACL = "L3_REDIRECT_ACL@"
ACL_CLIENT_L3V6_SECURITY_ACL = "L3V6_SECURITY_ACL@"
ACL_CLIENT_L3V6_REDIRECT_ACL = "L3V6_REDIRECT_ACL@"
ACL_INTERNAL_FIELD_SOURCE = "_SOURCE"
)

var IP_PROTOCOL_MAP = map[ocbinds.E_OpenconfigPacketMatchTypes_IP_PROTOCOL]uint8{
Expand Down Expand Up @@ -934,6 +935,7 @@ func (app *AclApp) convertDBAclToInternal(dbs [db.MaxDB]*db.DB, aclkey db.Key) e
}
if entry.IsPopulated() {
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 {
entry.Field[ACL_INTERNAL_FIELD_SOURCE] = "User"
app.aclTableMap[aclkey.Get(0)] = entry
app.ruleTableMap[aclkey.Get(0)] = make(map[string]db.Value)
err = app.convertDBAclRulesToInternal(dbs, aclkey.Get(0), "", db.Key{})
Expand Down Expand Up @@ -1438,7 +1440,7 @@ func convertInternalAclBindingStatusTypeToOC(status string) ocbinds.E_Openconfig
return ocStatusType
}

func (app *AclApp) getAclExtStateInfoForNameStage(statedb *db.DB, intfId string, stage string, aclName string, aclType ocbinds.E_OpenconfigAcl_ACL_TYPE, aclSetState reflect.Value) error {
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 {
log.Infof("Intf:%s stage:%s name:%s Type:%v", intfId, stage, aclName, aclType)

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

aclDataFromStateDB := false
var aclData db.Value
if len(app.aclTableMap) > 0 && len(app.aclStateTableMap) > 0 {
var found bool
Expand All @@ -1488,7 +1490,6 @@ func (app *AclApp) getOCIntfAclSetData(dbs [db.MaxDB]*db.DB, intfId string, stag
log.Infof("ACL:%s Type:%v not found", aclDbName, aclType)
return tlerr.NotFound("ACL:%s:%v not found", aclName, aclType)
}
aclDataFromStateDB = true
}
} else {
var err error
Expand All @@ -1498,7 +1499,6 @@ func (app *AclApp) getOCIntfAclSetData(dbs [db.MaxDB]*db.DB, intfId string, stag
if err != nil {
return err
} else {
aclDataFromStateDB = true
app.aclStateTableMap[aclDbName] = aclData
}
} else {
Expand All @@ -1516,20 +1516,13 @@ func (app *AclApp) getOCIntfAclSetData(dbs [db.MaxDB]*db.DB, intfId string, stag
return tlerr.NotFound("requested binding not found for %s and %s at %s", aclName, intfId, stage)
}

if !aclDataFromStateDB {
aclSetCfg := aclSet.Elem().FieldByName("Config")
if !aclSetCfg.IsNil() {
aclSetCfg.Elem().FieldByName("SetName").Set(aclSet.Elem().FieldByName("SetName"))
aclSetCfg.Elem().FieldByName("Type").Set(aclSet.Elem().FieldByName("Type"))
}
}

pacBinding := false
aclSetState := aclSet.Elem().FieldByName("State")
if !aclSetState.IsNil() {
aclSetState.Elem().FieldByName("SetName").Set(aclSet.Elem().FieldByName("SetName"))
aclSetState.Elem().FieldByName("Type").Set(aclSet.Elem().FieldByName("Type"))
if intfId != ACL_GLOBAL_PORT && intfId != ACL_CTRL_PLANE_PORT {
err := app.getAclExtStateInfoForNameStage(dbs[db.StateDB], intfId, stage, aclName, aclType, aclSetState)
err := app.getAclExtStateInfoForNameStage(dbs[db.StateDB], intfId, stage, aclName, aclType, aclSetState, &pacBinding)
if isNotFoundError(err) {
return tlerr.NotFound("Binding not found for ACL %s on %s at %s", aclName, intfId, stage)
} else if err != nil {
Expand All @@ -1541,6 +1534,14 @@ func (app *AclApp) getOCIntfAclSetData(dbs [db.MaxDB]*db.DB, intfId string, stag
}
}

if !pacBinding {
aclSetCfg := aclSet.Elem().FieldByName("Config")
if !aclSetCfg.IsNil() {
aclSetCfg.Elem().FieldByName("SetName").Set(aclSet.Elem().FieldByName("SetName"))
aclSetCfg.Elem().FieldByName("Type").Set(aclSet.Elem().FieldByName("Type"))
}
}

// At this stage we have verified that the ACL binding exists. Starts filling the actual data
// Check if the data was requested for a specific Entry else find all the rules
aclEntries := aclSet.Elem().FieldByName("AclEntries")
Expand Down Expand Up @@ -3370,6 +3371,7 @@ func (app *AclApp) convertStateDBAclToInternal(dbs [db.MaxDB]*db.DB, aclkey db.K

if entry.IsPopulated() {
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 {
entry.Field[ACL_INTERNAL_FIELD_SOURCE] = "PAC"
app.aclStateTableMap[aclkey.Get(0)] = entry
app.ruleStateTableMap[aclkey.Get(0)] = make(map[string]db.Value)
err = app.convertStateDBAclRulesToInternal(dbs, aclkey.Get(0), "", db.Key{})
Expand Down Expand Up @@ -3398,6 +3400,7 @@ func (app *AclApp) convertStateDBInternalToOCAcl(aclName string, aclSets *ocbind
if len(aclName) > 0 {
aclData := app.aclStateTableMap[aclName]
if aclSet != nil {
aclSet.Config = nil
aclSet.State.Name = aclSet.Name
aclSet.State.Type = aclSet.Type

Expand All @@ -3407,6 +3410,13 @@ func (app *AclApp) convertStateDBInternalToOCAcl(aclName string, aclSets *ocbind
aclSet.State.Description = &descr
} else if k == "ports@" {
continue
} else if k == ACL_INTERNAL_FIELD_SOURCE {
src := aclData.Get(k)
if src == "PAC" {
aclSet.State.Source = ocbinds.OpenconfigAclExt_ACL_SOURCE_TYPE_ACL_PAC_CREATED
} else {
aclSet.State.Source = ocbinds.OpenconfigAclExt_ACL_SOURCE_TYPE_ACL_USER_CREATED
}
}
}
app.convertStateDBInternalToOCAclRule(aclName, aclSet.Type, "", aclSet, nil)
Expand Down
4 changes: 3 additions & 1 deletion translib/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,9 @@ func (d *DB) getEntry(ts *TableSpec, key Key, forceReadDB bool) (Value, error) {

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

if len(v) != 0 {
Expand Down
3 changes: 3 additions & 0 deletions translib/path_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ func (pv *pathValidator) getYangSchema() (*yang.Entry, error) {
func (pv *pathValidator) getStructField(nodeName string) *reflect.StructField {
var sField *reflect.StructField
sval := reflect.ValueOf(pv.sValIntf).Elem()
if sval.Kind() != reflect.Struct {
return nil
}
stype := sval.Type()
for i := 0; i < sval.NumField(); i++ {
fType := stype.Field(i)
Expand Down
Loading

0 comments on commit 11578d1

Please sign in to comment.