diff --git a/models/yang/extensions/openconfig-interfaces-deviation.yang b/models/yang/extensions/openconfig-interfaces-deviation.yang index e3fd326b7..7050b8706 100644 --- a/models/yang/extensions/openconfig-interfaces-deviation.yang +++ b/models/yang/extensions/openconfig-interfaces-deviation.yang @@ -132,4 +132,8 @@ module openconfig-interfaces-deviation { deviate not-supported; } + deviation /oc-intf:interfaces/oc-intf:interface/oc-vlan:routed-vlan { + deviate not-supported; + } + } diff --git a/translib/transformer/xfmr_intf.go b/translib/transformer/xfmr_intf.go index 6d9ffb037..e4232b358 100644 --- a/translib/transformer/xfmr_intf.go +++ b/translib/transformer/xfmr_intf.go @@ -32,7 +32,6 @@ import ( "github.com/Azure/sonic-mgmt-common/translib/db" "github.com/Azure/sonic-mgmt-common/translib/ocbinds" "github.com/Azure/sonic-mgmt-common/translib/tlerr" - "github.com/Azure/sonic-mgmt-common/translib/utils" log "github.com/golang/glog" "github.com/openconfig/ygot/ygot" ) @@ -78,7 +77,6 @@ func init() { const ( PORT_ADMIN_STATUS = "admin_status" - PORTCHANNEL_TN = "PORTCHANNEL" PORT_SPEED = "speed" PORT_AUTONEG = "autoneg" DEFAULT_MTU = "9100" @@ -89,12 +87,6 @@ const ( COLON = ":" ETHERNET = "Eth" - MGMT = "eth" - VLAN = "Vlan" - PORTCHANNEL = "PortChannel" - LOOPBACK = "Loopback" - VXLAN = "vtep" - MANAGEMENT = "Management" ) type TblData struct { @@ -116,35 +108,12 @@ var IntfTypeTblMap = map[E_InterfaceType]IntfTblData{ appDb: TblData{portTN: "PORT_TABLE", intfTN: "INTF_TABLE", keySep: COLON}, stateDb: TblData{portTN: "PORT_TABLE", intfTN: "INTERFACE_TABLE", keySep: PIPE}, }, - IntfTypeMgmt: IntfTblData{ - cfgDb: TblData{portTN: "MGMT_PORT", intfTN: "MGMT_INTERFACE", keySep: PIPE}, - appDb: TblData{portTN: "MGMT_PORT_TABLE", intfTN: "MGMT_INTF_TABLE", keySep: COLON}, - stateDb: TblData{portTN: "MGMT_PORT_TABLE", intfTN: "MGMT_INTERFACE_TABLE", keySep: PIPE}, - }, - IntfTypePortChannel: IntfTblData{ - cfgDb: TblData{portTN: "PORTCHANNEL", intfTN: "PORTCHANNEL_INTERFACE", memberTN: "PORTCHANNEL_MEMBER", keySep: PIPE}, - appDb: TblData{portTN: "LAG_TABLE", intfTN: "INTF_TABLE", keySep: COLON, memberTN: "LAG_MEMBER_TABLE"}, - stateDb: TblData{portTN: "LAG_TABLE", intfTN: "INTERFACE_TABLE", keySep: PIPE}, - }, - IntfTypeVlan: IntfTblData{ - cfgDb: TblData{portTN: "VLAN", memberTN: "VLAN_MEMBER", intfTN: "VLAN_INTERFACE", keySep: PIPE}, - appDb: TblData{portTN: "VLAN_TABLE", memberTN: "VLAN_MEMBER_TABLE", intfTN: "INTF_TABLE", keySep: COLON}, - }, - IntfTypeLoopback: IntfTblData{ - cfgDb: TblData{portTN: "LOOPBACK", intfTN: "LOOPBACK_INTERFACE", keySep: PIPE}, - appDb: TblData{portTN: "LOOPBACK_TABLE", intfTN: "INTF_TABLE", keySep: COLON}, - }, - IntfTypeSubIntf: IntfTblData{ - cfgDb: TblData{portTN: "VLAN_SUB_INTERFACE", intfTN: "VLAN_SUB_INTERFACE", keySep: PIPE}, - appDb: TblData{portTN: "PORT_TABLE", intfTN: "INTF_TABLE", keySep: COLON}, - stateDb: TblData{portTN: "PORT_TABLE", intfTN: "INTERFACE_TABLE", keySep: PIPE}, - }, } var dbIdToTblMap = map[db.DBNum][]string{ - db.ConfigDB: {"PORT", "MGMT_PORT", "VLAN", "PORTCHANNEL", "LOOPBACK", "VXLAN_TUNNEL", "VLAN_SUB_INTERFACE"}, - db.ApplDB: {"PORT_TABLE", "MGMT_PORT_TABLE", "VLAN_TABLE", "LAG_TABLE"}, - db.StateDB: {"PORT_TABLE", "MGMT_PORT_TABLE", "LAG_TABLE"}, + db.ConfigDB: {"PORT"}, + db.ApplDB: {"PORT_TABLE"}, + db.StateDB: {"PORT_TABLE"}, } var intfOCToSpeedMap = map[ocbinds.E_OpenconfigIfEthernet_ETHERNET_SPEED]string{ @@ -167,30 +136,17 @@ type E_InterfaceType int64 const ( IntfTypeUnset E_InterfaceType = 0 IntfTypeEthernet E_InterfaceType = 1 - IntfTypeMgmt E_InterfaceType = 2 - IntfTypeVlan E_InterfaceType = 3 - IntfTypePortChannel E_InterfaceType = 4 - IntfTypeLoopback E_InterfaceType = 5 - IntfTypeVxlan E_InterfaceType = 6 - IntfTypeSubIntf E_InterfaceType = 7 ) type E_InterfaceSubType int64 const ( - IntfSubTypeUnset E_InterfaceSubType = 0 - IntfSubTypeVlanL2 E_InterfaceSubType = 1 - InterfaceSubTypeVlanL3 E_InterfaceSubType = 2 + IntfSubTypeUnset E_InterfaceSubType = 0 ) func getIntfTypeByName(name string) (E_InterfaceType, E_InterfaceSubType, error) { var err error - if strings.Contains(name, ".") { - if strings.HasPrefix(name, ETHERNET) || strings.HasPrefix(name, "Po") { - return IntfTypeSubIntf, IntfSubTypeUnset, err - } - } if strings.HasPrefix(name, ETHERNET) { return IntfTypeEthernet, IntfSubTypeUnset, err } else { @@ -227,13 +183,6 @@ func getPortTableNameByDBId(intftbl IntfTblData, curDb db.DBNum) (string, error) func performIfNameKeyXfmrOp(inParams *XfmrParams, requestUriPath *string, ifName *string, ifType E_InterfaceType, subintfid uint32) error { var err error switch inParams.oper { - case GET: - if ifType == IntfTypeSubIntf && subintfid == 0 { - errStr := "Invalid interface name: " + *ifName - log.Infof("Invalid interface name: %s for GET path: %v", *ifName, *requestUriPath) - err = tlerr.InvalidArgsError{Format: errStr} - return err - } case DELETE: if *requestUriPath == "/openconfig-interfaces:interfaces/interface/subinterfaces/subinterface" && subintfid != 0 { return nil @@ -268,16 +217,11 @@ func performIfNameKeyXfmrOp(inParams *XfmrParams, requestUriPath *string, ifName } if inParams.oper == REPLACE { if strings.Contains(*requestUriPath, "/openconfig-interfaces:interfaces/interface") { - if strings.Contains(*requestUriPath, "openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan") || - strings.Contains(*requestUriPath, "mapped-vlans") { - log.Infof("allow replace operation for switched-vlan") - } else { - // OC interfaces yang does not have attributes to set Physical interface critical attributes like speed, alias, lanes, index. - // Replace/PUT request without the critical attributes would end up in deletion of the same in PORT table, which cannot be allowed. - // Hence block the Replace/PUT request for Physical interfaces alone. - err_str := "Replace/PUT request not allowed for Physical interfaces" - return tlerr.NotSupported(err_str) - } + // OC interfaces yang does not have attributes to set Physical interface critical attributes like speed, alias, lanes, index. + // Replace/PUT request without the critical attributes would end up in deletion of the same in PORT table, which cannot be allowed. + // Hence block the Replace/PUT request for Physical interfaces alone. + err_str := "Replace/PUT request not allowed for Physical interfaces" + return tlerr.NotSupported(err_str) } } } @@ -400,13 +344,6 @@ var intf_table_xfmr TableXfmrFunc = func(inParams XfmrParams) ([]string, error) return dbIdToTblMap[inParams.curDb], nil } } - idx := pathInfo.Var("index") - var i32 uint32 - i32 = 0 - if idx != "" { - i64, _ := strconv.ParseUint(idx, 10, 32) - i32 = uint32(i64) - } intfType, _, ierr := getIntfTypeByName(ifName) if intfType == IntfTypeUnset || ierr != nil { @@ -424,32 +361,7 @@ var intf_table_xfmr TableXfmrFunc = func(inParams XfmrParams) ([]string, error) return tblList, tlerr.NotSupportedError{AppTag: "invalid-value", Path: "", Format: errStr} } else if strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/config") { - if IntfTypeVxlan != intfType { - tblList = append(tblList, intTbl.cfgDb.portTN) - } - - } else if intfType != IntfTypeEthernet && intfType != IntfTypeMgmt && - strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/openconfig-if-ethernet:ethernet") { - //Checking interface type at container level, if not Ethernet type return nil - return nil, nil - - } else if intfType != IntfTypePortChannel && - strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/openconfig-if-aggregate:aggregation") { - //Checking interface type at container level, if not PortChannel type return nil - return nil, nil - - } else if intfType != IntfTypeVlan && - strings.HasPrefix(targetUriPath, "openconfig-interfaces:interfaces/interface/openconfig-vlan:routed-vlan") { - //Checking interface type at container level, if not Vlan type return nil - return nil, nil - - } else if intfType != IntfTypeVxlan && - strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/openconfig-vxlan:vxlan-if") { - //Checking interface type at container level, if not Vxlan type return nil - return nil, nil - - } else if strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/state/counters") { - tblList = append(tblList, "NONE") + tblList = append(tblList, intTbl.cfgDb.portTN) } else if strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/state") || strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/ethernet/state") || @@ -461,11 +373,7 @@ var intf_table_xfmr TableXfmrFunc = func(inParams XfmrParams) ([]string, error) strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/subinterfaces/subinterface/ipv6/addresses/address/config") || strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/subinterfaces/subinterface/ipv6/config") || strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/subinterfaces/subinterface/openconfig-if-ip:ipv6/config") { - if i32 > 0 { - tblList = append(tblList, "VLAN_SUB_INTERFACE") - } else { - tblList = append(tblList, intTbl.cfgDb.intfTN) - } + tblList = append(tblList, intTbl.cfgDb.intfTN) } else if strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/subinterfaces/subinterface/ipv4/addresses/address/state") || strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/subinterfaces/subinterface/openconfig-if-ip:ipv4/addresses/address/state") || strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/subinterfaces/subinterface/openconfig-if-ip:ipv6/addresses/address/state") || @@ -563,9 +471,6 @@ var DbToYang_intf_admin_status_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams log.Info("DbToYang_intf_admin_status_xfmr - Invalid interface type IntfTypeUnset") return result, errors.New("Invalid interface type IntfTypeUnset") } - if IntfTypeVxlan == intfType { - return result, nil - } intTbl := IntfTypeTblMap[intfType] tblName, _ := getPortTableNameByDBId(intTbl, inParams.curDb) @@ -597,18 +502,9 @@ var DbToYang_intf_admin_status_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams var YangToDb_intf_enabled_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) - var ifName string intfsObj := getIntfsRoot(inParams.ygRoot) if intfsObj == nil || len(intfsObj.Interface) < 1 { return res_map, nil - } else { - for infK := range intfsObj.Interface { - ifName = infK - } - } - intfType, _, _ := getIntfTypeByName(ifName) - if IntfTypeVxlan == intfType { - return res_map, nil } enabled, _ := inParams.param.(*bool) var enStr string @@ -633,9 +529,6 @@ var DbToYang_intf_enabled_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (ma log.Info("DbToYang_intf_enabled_xfmr - Invalid interface type IntfTypeUnset") return result, errors.New("Invalid interface type IntfTypeUnset") } - if IntfTypeVxlan == intfType { - return result, nil - } intTbl := IntfTypeTblMap[intfType] @@ -1147,93 +1040,18 @@ var intf_pre_xfmr PreXfmrFunc = func(inParams XfmrParams) error { return err } -func populateVlanSubIntfTblKeys(inParams XfmrParams) error { - var key string - - (*inParams.dbDataMap)[db.ConfigDB]["VLAN_SUB_INTERFACE"] = make(map[string]db.Value) - mapIntfKeys, _ := inParams.d.GetKeys(&db.TableSpec{Name: "VLAN_SUB_INTERFACE"}) - if len(mapIntfKeys) > 0 { - for _, intfKey := range mapIntfKeys { - key = intfKey.Get(0) - key = *(&key) - if _, ok := (*inParams.dbDataMap)[db.ConfigDB]["VLAN_SUB_INTERFACE"][key]; !ok { - (*inParams.dbDataMap)[db.ConfigDB]["VLAN_SUB_INTERFACE"][key] = db.Value{Field: make(map[string]string)} - (*inParams.dbDataMap)[db.ConfigDB]["VLAN_SUB_INTERFACE"][key].Field["NULL"] = "NULL" - } - } - } - - if log.V(3) { - log.Infof("populateVlanSubIntfTblKeys, configDB dbdataMap[\"VLAN_SUB_INTERFACE\"]: %v ", (*inParams.dbDataMap)[db.ConfigDB]["VLAN_SUB_INTERFACE"]) - } - - return nil -} - var intf_subintfs_table_xfmr TableXfmrFunc = func(inParams XfmrParams) ([]string, error) { var tblList []string pathInfo := NewPathInfo(inParams.uri) - ifName := pathInfo.Var("name") idx := pathInfo.Var("index") - if inParams.oper == SUBSCRIBE { - var _intfTypeList []E_InterfaceType - - _addSubIntfToList := func() { - if idx == "*" || idx != "0" { - _intfTypeList = append(_intfTypeList, IntfTypeSubIntf) - } - } - - if ifName == "*" { - _intfTypeList = append(_intfTypeList, IntfTypeEthernet, IntfTypeMgmt, IntfTypePortChannel, IntfTypeLoopback) - _addSubIntfToList() - } else { - _ifType, _, _err := getIntfTypeByName(ifName) - if _ifType == IntfTypeUnset || _err != nil { - return tblList, errors.New("Invalid interface type IntfTypeUnset") - } - if IntfTypeVlan == _ifType || IntfTypeVxlan == _ifType { - return tblList, nil - } - _intfTypeList = append(_intfTypeList, _ifType) - _addSubIntfToList() - } - - for _, _ifType := range _intfTypeList { - _intfTblName, _ := getIntfTableNameByDBId(IntfTypeTblMap[_ifType], inParams.curDb) - tblList = append(tblList, _intfTblName) - } - - log.V(3).Info("intf_subintfs_table_xfmr: URI: ", inParams.uri, " OP:", inParams.oper, " ifName:", ifName, " idx:", idx, " tblList:", tblList) - return tblList, nil - } - - //if GET at top level, populate the VLAN_SUB_INTERFACE table with keys and store the flag to txCache - val, present := inParams.txCache.Load("vlan_sub_intf_tbl_keys_read") - reqPathInfo := NewPathInfo(inParams.requestUri) - requestUriPath := reqPathInfo.YangPath - var reqUriIfName string = reqPathInfo.Var("name") - if inParams.oper == GET && (requestUriPath == "/openconfig-interfaces:interfaces" || - requestUriPath == "/openconfig-interfaces:interfaces/interface") && reqUriIfName == "" { - if !present || val != true { - if inParams.dbDataMap != nil { - populateVlanSubIntfTblKeys(inParams) - inParams.txCache.Store("vlan_sub_intf_tbl_keys_read", true) - val = true - log.Info("intf_subintfs_table_xfmr, cached vlan_sub_intf_tbl_keys_read") - } - } - } - if idx == "" { if inParams.oper == GET || inParams.oper == DELETE { if inParams.dbDataMap != nil { (*inParams.dbDataMap)[db.ConfigDB]["SUBINTF_TBL"] = make(map[string]db.Value) (*inParams.dbDataMap)[db.ConfigDB]["SUBINTF_TBL"]["0"] = db.Value{Field: make(map[string]string)} tblList = append(tblList, "SUBINTF_TBL") - tblList = append(tblList, "VLAN_SUB_INTERFACE") } } log.Info("intf_subintfs_table_xfmr - Subinterface get operation ") @@ -1245,17 +1063,6 @@ var intf_subintfs_table_xfmr TableXfmrFunc = func(inParams XfmrParams) ([]string (*inParams.dbDataMap)[db.ConfigDB]["SUBINTF_TBL"]["0"].Field["NULL"] = "NULL" } tblList = append(tblList, "SUBINTF_TBL") - } else { - if inParams.dbDataMap != nil { - (*inParams.dbDataMap)[db.ConfigDB]["VLAN_SUB_INTERFACE"] = make(map[string]db.Value) - if val == true { - //reset cached flag - inParams.txCache.Store("vlan_sub_intf_tbl_keys_read", false) - log.Info("intf_subintfs_table_xfmr, reset vlan_sub_intf_tbl_keys_read cache") - } - } - tblList = append(tblList, "VLAN_SUB_INTERFACE") - *inParams.isVirtualTbl = false } if log.V(3) { log.Info("intf_subintfs_table_xfmr - Subinterface get operation ") @@ -1281,10 +1088,6 @@ var YangToDb_intf_subintfs_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (str if intfType == IntfTypeUnset || ierr != nil { return ifName, errors.New("Invalid interface type IntfTypeUnset") } - if IntfTypeVlan == intfType { - log.Info("YangToDb_intf_subintfs_xfmr - IntfTypeVlan") - return ifName, nil - } idx := pathInfo.Var("index") @@ -1378,10 +1181,7 @@ var DbToYangPath_intf_ip_path_xfmr PathXfmrDbToYangFunc = func(params XfmrDbToYg params.ygPathKeys[ifRoot+"/name"] = ifParts[0] - if params.tblName == "INTERFACE" || params.tblName == "VLAN_INTERFACE" || - params.tblName == "INTF_TABLE" || params.tblName == "MGMT_INTERFACE" || - params.tblName == "VLAN_SUB_INTERFACE" || params.tblName == "MGMT_INTF_TABLE" || - params.tblName == "PORTCHANNEL_INTERFACE" { + if params.tblName == "INTERFACE" || params.tblName == "INTF_TABLE" { addrPath := "/openconfig-if-ip:ipv4/addresses/address/ip" @@ -1397,16 +1197,13 @@ var DbToYangPath_intf_ip_path_xfmr PathXfmrDbToYangFunc = func(params XfmrDbToYg ipKey := strings.Split(dbKey, "/") - if strings.HasPrefix(params.tblKeyComp[0], "Vlan") { - return nil + if len(ifParts) > 1 { + params.ygPathKeys[subIf+"/index"] = ifParts[1] } else { - if len(ifParts) > 1 { - params.ygPathKeys[subIf+"/index"] = ifParts[1] - } else { - params.ygPathKeys[subIf+"/index"] = "0" - } - params.ygPathKeys[subIf+addrPath] = ipKey[0] + params.ygPathKeys[subIf+"/index"] = "0" } + params.ygPathKeys[subIf+addrPath] = ipKey[0] + } log.Infof("DbToYangPath_intf_ip_path_xfmr: tblName:%v dbKey:[%v] params.ygPathKeys: %v", params.tblName, dbKey, params.ygPathKeys) @@ -1500,9 +1297,6 @@ func handleAllIntfIPGetForTable(inParams XfmrParams, tblName string, isAppDb boo // YGOT filling for intfName, ipMapDB := range intfIpMap { - if strings.HasPrefix(intfName, "Vlan") { - continue - } var subIdxStr string var name string @@ -1559,12 +1353,7 @@ func ValidateIntfProvisionedForRelay(d *db.DB, ifName string, prefixIp string, e intTbl := IntfTypeTblMap[intfType] tblList = intTbl.cfgDb.intfTN - // for VLAN - DHCP info is stored in the VLAN Table - if intfType == IntfTypeVlan { - tblList = intTbl.cfgDb.portTN - } - - if entry == nil || intfType == IntfTypeVlan { + if entry == nil { ent, dbErr := d.GetEntry(&db.TableSpec{Name: tblList}, db.Key{Comp: []string{ifName}}) entry = &ent if dbErr != nil { @@ -1598,13 +1387,7 @@ func handleIntfIPGetByTargetURI(inParams XfmrParams, targetUriPath string, ifNam pathInfo := NewPathInfo(inParams.uri) ipAddr := pathInfo.Var("ip") - idx := pathInfo.Var("index") i32 := uint32(0) - if idx != "0" { - ifName = *utils.GetSubInterfaceDBKeyfromParentInterfaceAndSubInterfaceID(&ifName, &idx) - i64, _ := strconv.ParseUint(idx, 10, 32) - i32 = uint32(i64) - } intfType, _, ierr := getIntfTypeByName(ifName) if intfType == IntfTypeUnset || ierr != nil { errStr := "Invalid interface type IntfTypeUnset" @@ -1776,7 +1559,7 @@ var DbToYang_intf_ip_addr_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) e return nil } - intfTypeList := [5]E_InterfaceType{IntfTypeEthernet, IntfTypeMgmt, IntfTypePortChannel, IntfTypeLoopback, IntfTypeSubIntf} + intfTypeList := [1]E_InterfaceType{IntfTypeEthernet} // Get IP from all configDb table interfaces for i := 0; i < len(intfTypeList); i++ { @@ -1795,11 +1578,6 @@ var DbToYang_intf_ip_addr_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) e var intfObj *ocbinds.OpenconfigInterfaces_Interfaces_Interface ifName = *(&uriIfName) - intfType, _, _ := getIntfTypeByName(ifName) - if IntfTypeVlan == intfType { - return nil - } - if strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/subinterfaces") { if intfsObj != nil && intfsObj.Interface != nil && len(intfsObj.Interface) > 0 { var ok bool = false @@ -1849,14 +1627,6 @@ var YangToDb_intf_ip_addr_xfmr SubTreeXfmrYangToDb = func(inParams XfmrParams) ( log.Infof("YangToDb_intf_ip_addr_xfmr: Interface name retrieved from alias : %s is %s", ifName, *sonicIfName) ifName = *sonicIfName intfType, _, ierr := getIntfTypeByName(ifName) - if i32 > 0 { - intfType = IntfTypeSubIntf - ifName = *utils.GetSubInterfaceDBKeyfromParentInterfaceAndSubInterfaceID(&ifName, &idx) - } - - if IntfTypeVxlan == intfType || IntfTypeVlan == intfType { - return subIntfmap, nil - } intfsObj := getIntfsRoot(inParams.ygRoot) if intfsObj == nil || len(intfsObj.Interface) < 1 { @@ -2104,8 +1874,16 @@ func validateIpOverlap(d *db.DB, intf string, ipPref string, tblName string, isI log.Info("IP: ", ipPref, " overlaps with ", key.Get(1), " of ", key.Get(0)) } - errStr := "IP " + ipPref + " overlaps with IP or IP Anycast " + key.Get(1) + " of Interface " + key.Get(0) - return "", errors.New(errStr) + //Handle IP overlap across different interface + _, _, ierr := getIntfTypeByName(key.Get(0)) + if ierr != nil { + log.Errorf("Extracting Interface type for Interface: %s failed!", key.Get(0)) + return "", ierr + } + if intf != key.Get(0) { + errStr := "IP " + ipPref + " overlaps with IP or IP Anycast " + key.Get(1) + " of Interface " + key.Get(0) + return "", errors.New(errStr) + } } } } @@ -2390,12 +2168,6 @@ func interfaceIPcount(tblName string, d *db.DB, intfName *string, ipCnt *int) er return nil } func check_if_delete_l3_intf_entry(d *db.DB, tblName string, ifName string, ipCnt int, intfEntry *db.Value) bool { - if strings.HasPrefix(ifName, VLAN) { - sagIpKey, _ := d.GetKeysPattern(&db.TableSpec{Name: "SAG"}, db.Key{Comp: []string{ifName, "*"}}) - if len(sagIpKey) != 0 { - return false - } - } if intfEntry == nil { entry, err := d.GetEntry(&db.TableSpec{Name: tblName}, db.Key{Comp: []string{ifName}}) if err != nil { @@ -2407,10 +2179,9 @@ func check_if_delete_l3_intf_entry(d *db.DB, tblName string, ifName string, ipCn if ipCnt == 0 && intfEntry.IsPopulated() { intfEntryMap := intfEntry.Field _, nullValPresent := intfEntryMap["NULL"] - _, natZoneValPresent := intfEntryMap["nat_zone"] /* Note: Unbinding shouldn't happen if VRF config is associated with interface. - Hence, we check for map length and only if either NULL or NAT value is present */ - if (len(intfEntryMap) == 1 && nullValPresent) || (len(intfEntryMap) == 2 && nullValPresent && natZoneValPresent) { + Hence, we check for map length and only if NULL value is present */ + if len(intfEntryMap) == 1 && nullValPresent { return true } } @@ -2421,7 +2192,6 @@ var Subscribe_intf_ip_addr_xfmr = func(inParams XfmrSubscInParams) (XfmrSubscOut if log.V(3) { log.Info("Entering Subscribe_intf_ip_addr_xfmr") } - var err error var result XfmrSubscOutParams pathInfo := NewPathInfo(inParams.uri) @@ -2429,152 +2199,10 @@ var Subscribe_intf_ip_addr_xfmr = func(inParams XfmrSubscInParams) (XfmrSubscOut log.Infof("Subscribe_intf_ip_addr_xfmr:- subscProc:%v URI: %s", inParams.subscProc, inParams.uri) log.Infof("Subscribe_intf_ip_addr_xfmr:- Target URI path: %s", origTargetUriPath) - - // When the subscribe subtree is invoked in the GET or CRUD context the inParams.subscProc is set to TRANSLATE_EXISTS - if inParams.subscProc == TRANSLATE_EXISTS { - // Defer the DB resource check done by infra by setting the virtual table to true. - // Resource checks are now performed within the DbToYang or YangToDb subtree callback. - result.isVirtualTbl = true - return result, nil - } - if inParams.subscProc == TRANSLATE_SUBSCRIBE { - isRoutedVlan := false - - ifBasePath := "/openconfig-interfaces:interfaces/interface" - targetUriPath := origTargetUriPath[len(ifBasePath):] - - if strings.HasPrefix(targetUriPath, "/subinterfaces") { - targetUriPath = targetUriPath[len("/subinterfaces/subinterface"):] - } else { - isRoutedVlan = true - targetUriPath = targetUriPath[len("/openconfig-vlan:routed-vlan"):] - } - - if strings.HasPrefix(targetUriPath, "/openconfig-if-ip:ipv4") { - targetUriPath = targetUriPath[len("/openconfig-if-ip:ipv4/addresses"):] - } else { - targetUriPath = targetUriPath[len("/openconfig-if-ip:ipv6/addresses"):] - } - - if targetUriPath == "" || targetUriPath == "/address" { - result.isVirtualTbl = true - log.Info("Subscribe_intf_ip_addr_xfmr:- result.isVirtualTbl: ", result.isVirtualTbl) - return result, err - } - - result.onChange = OnchangeEnable - result.nOpts = ¬ificationOpts{} - result.nOpts.pType = OnChange - result.isVirtualTbl = false - - uriIfName := pathInfo.Var("name") - tableName := "" - ipKey := "" - ifKey := "" - subIfKey := "*" - - if uriIfName == "" || uriIfName == "*" { - ifKey = "*" - } else { - sonicIfName := &uriIfName - ifKey = *sonicIfName - } - - addressConfigPath := "/address/config" - addressStatePath := "/address/state" - - idx := pathInfo.Var("index") - if ifKey != "" { - if idx == "0" { - intfType, _, _ := getIntfTypeByName(ifKey) - intTbl := IntfTypeTblMap[intfType] - if targetUriPath == addressStatePath { - tableName = intTbl.appDb.intfTN - } else { - tableName = intTbl.cfgDb.intfTN - } - } else if idx == "*" || idx == "" { - subIfKey = *utils.GetSubInterfaceDBKeyfromParentInterfaceAndSubInterfaceID(&ifKey, &idx) - } else { - tableName = "VLAN_SUB_INTERFACE" - ifKey = *utils.GetSubInterfaceDBKeyfromParentInterfaceAndSubInterfaceID(&ifKey, &idx) - } - } - - ipKey = pathInfo.Var("ip") - if ipKey == "" { - ipKey = "*" - } - - if ipKey != "*" { - ipKey = ipKey + "/*" - } - - log.Infof("path:%v ifKey:%v, ipKey:%v tbl:[%v]", origTargetUriPath, ifKey, ipKey, tableName) - - keyName := "" - if targetUriPath == addressConfigPath { - keyName = ifKey + "|" + ipKey - if tableName != "" { - result.dbDataMap = RedisDbSubscribeMap{db.ConfigDB: {tableName: {keyName: {}}}} - } else { - if isRoutedVlan { - result.dbDataMap = RedisDbSubscribeMap{db.ConfigDB: {"VLAN_INTERFACE": {keyName: {}}}} - } else { - subIfKeyName := subIfKey + "|" + ipKey - result.dbDataMap = RedisDbSubscribeMap{db.ConfigDB: {"INTERFACE": {keyName: {}}, - "MGMT_INTERFACE": {keyName: {}}, - "LOOPBACK_INTERFACE": {keyName: {}}, - "VLAN_SUB_INTERFACE": {subIfKeyName: {}}, - "PORTCHANNEL_INTERFACE": {keyName: {}}}} - } - } - } else if targetUriPath == addressStatePath { - keyName = ifKey + ":" + ipKey - if tableName != "" { - result.dbDataMap = RedisDbSubscribeMap{db.ApplDB: {tableName: {keyName: {KEY_COMP_CNT: "2", DEL_AS_UPDATE: "true"}}}} - } else { - if isRoutedVlan { - result.dbDataMap = RedisDbSubscribeMap{db.ApplDB: {"INTF_TABLE": {keyName: {KEY_COMP_CNT: "2", DEL_AS_UPDATE: "true"}}}} - } else { - result.dbDataMap = RedisDbSubscribeMap{db.ApplDB: {"INTF_TABLE": {keyName: {KEY_COMP_CNT: "2", DEL_AS_UPDATE: "true"}}, - "MGMT_INTF_TABLE": {keyName: {KEY_COMP_CNT: "2", DEL_AS_UPDATE: "true"}}}} - } - } - } - - log.Info("Subscribe_intf_ip_addr_xfmr:- result dbDataMap: ", result.dbDataMap) - log.Info("Subscribe_intf_ip_addr_xfmr:- result secDbDataMap: ", result.secDbDataMap) - - return result, err - } - - result.isVirtualTbl = false - - result.dbDataMap = make(RedisDbSubscribeMap) - uriIfName := pathInfo.Var("name") - idx := pathInfo.Var("index") - sonicIfName := &uriIfName - keyName := *sonicIfName - - if keyName != "" { - intfType, _, _ := getIntfTypeByName(keyName) - intTbl := IntfTypeTblMap[intfType] - tblName := intTbl.cfgDb.intfTN - if idx != "" && idx != "0" { - tblName = "VLAN_SUB_INTERFACE" - keyName = *utils.GetSubInterfaceDBKeyfromParentInterfaceAndSubInterfaceID(&keyName, &idx) - } - result.dbDataMap = RedisDbSubscribeMap{db.ConfigDB: {tblName: {keyName: {}}}} - } - log.Info("Returning Subscribe_intf_ip_addr_xfmr, result:", result) - result.needCache = true - result.nOpts = new(notificationOpts) - result.nOpts.mInterval = 15 - result.nOpts.pType = OnChange - log.Info("Returning Subscribe_intf_ip_addr_xfmr, result:", result) - return result, err - + // Defer the DB resource check done by infra by setting the virtual table to true. + // Resource checks are now performed within the DbToYang or YangToDb subtree callback. + result.isVirtualTbl = true + return result, nil } // YangToDb_subintf_ipv6_tbl_key_xfmr is a YangToDB Key transformer for IPv6 config. @@ -2591,17 +2219,7 @@ var YangToDb_subintf_ipv6_tbl_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParam if log.V(3) { log.Info("inParams.requestUri: ", inParams.requestUri) } - idx := pathInfo.Var("index") - var i32 uint32 - i32 = 0 - if idx != "" { - i64, _ := strconv.ParseUint(idx, 10, 32) - i32 = uint32(i64) - } inst_key = ifName - if i32 > 0 { - inst_key = ifName + "." + idx - } log.Info("Exiting YangToDb_subintf_ipv6_tbl_key_xfmr, key ", inst_key) return inst_key, err } @@ -2625,16 +2243,9 @@ var YangToDb_ipv6_enabled_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (ma res_map := make(map[string]string) pathInfo := NewPathInfo(inParams.uri) ifUIName := pathInfo.Var("name") - idx := pathInfo.Var("index") - var i32 uint32 - i32 = 0 - if idx != "" { - i64, _ := strconv.ParseUint(idx, 10, 32) - i32 = uint32(i64) - } intfType, _, ierr := getIntfTypeByName(ifUIName) - if ierr != nil || intfType == IntfTypeUnset || intfType == IntfTypeVxlan || intfType == IntfTypeMgmt { + if ierr != nil || intfType == IntfTypeUnset { return res_map, errors.New("YangToDb_ipv6_enabled_xfmr, Error: Unsupported Interface: " + ifUIName) } @@ -2650,7 +2261,7 @@ var YangToDb_ipv6_enabled_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (ma // Vlan Interface (routed-vlan) contains only one Key "ifname" // For all other interfaces (subinterfaces/subintfaces) will have 2 keys "ifname" & "subintf-index" - if len(pathInfo.Vars) < 2 && intfType != IntfTypeVlan { + if len(pathInfo.Vars) < 2 { return res_map, errors.New("YangToDb_ipv6_enabled_xfmr, Error: Invalid Key length") } @@ -2662,10 +2273,6 @@ var YangToDb_ipv6_enabled_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (ma intTbl := IntfTypeTblMap[intfType] tblName := intTbl.cfgDb.intfTN - if i32 > 0 { - tblName = "VLAN_SUB_INTERFACE" - ifName = utils.GetSubInterfaceDBKeyfromParentInterfaceAndSubInterfaceID(ifName, &idx) - } ipMap, _ := getIntfIpByName(inParams.d, tblName, *ifName, true, true, "") var enStr string subOpMap := make(map[db.DBNum]map[string]map[string]db.Value) diff --git a/translib/utils/utils.go b/translib/utils/utils.go index d2aee1656..cc79ae0c7 100644 --- a/translib/utils/utils.go +++ b/translib/utils/utils.go @@ -21,7 +21,6 @@ package utils import ( "fmt" - //"github.com/Azure/sonic-mgmt-common/translib/db" "github.com/Azure/sonic-mgmt-common/cvl" "github.com/Azure/sonic-mgmt-common/translib/db" log "github.com/golang/glog" @@ -65,9 +64,3 @@ func RemoveElement(sl []string, str string) []string { } return sl } -func GetSubInterfaceDBKeyfromParentInterfaceAndSubInterfaceID(parentIf *string, subId *string) *string { - uiName := *parentIf + "." + *subId - key := *(&uiName) - log.V(3).Infof("GetSubInterfaceDBKeyfromParentInterfaceAndSubInterfaceID %s + %s => %s", *parentIf, *subId, key) - return &key -}