Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructured sonic yang changes #155

Merged
merged 13 commits into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ codegen:

yamlGen:
$(MAKE) -C models/yang
$(MAKE) -C models/yang/sonic

go-patch: go-deps
cd $(BUILD_GOPATH)/src/github.com/openconfig/ygot/; git reset --hard HEAD; git checkout 724a6b18a9224343ef04fe49199dfb6020ce132a 2>/dev/null ; true; \
Expand All @@ -120,6 +121,8 @@ install:
$(INSTALL) -d $(DESTDIR)/usr/sbin/schema/
$(INSTALL) -d $(DESTDIR)/usr/sbin/lib/
$(INSTALL) -d $(DESTDIR)/usr/models/yang/
$(INSTALL) -D $(TOPDIR)/models/yang/sonic/*.yang $(DESTDIR)/usr/models/yang/
$(INSTALL) -D $(TOPDIR)/models/yang/sonic/common/*.yang $(DESTDIR)/usr/models/yang/
$(INSTALL) -D $(TOPDIR)/src/cvl/schema/*.yin $(DESTDIR)/usr/sbin/schema/
$(INSTALL) -D $(TOPDIR)/src/cvl/testdata/schema/*.yin $(DESTDIR)/usr/sbin/schema/
$(INSTALL) -D $(TOPDIR)/src/cvl/schema/*.yang $(DESTDIR)/usr/models/yang/
Expand Down
3 changes: 2 additions & 1 deletion src/cvl/schema/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ out_common=$(patsubst %.yang, %.yin, $(shell ls -1 $(sonic_yang_common)/*.yang |
out_tree=$(patsubst %.yang, %.tree, $(src_files))
search_path=$(sonic_yang):$(sonic_yang_common):$(sonic_yang_common)/ietf

all: yamlGen allyangs.tree allyangs_tree.html schema
#all: yamlGen allyangs.tree allyangs_tree.html schema
all: schema

schema: $(out) $(out_common)

Expand Down
1 change: 1 addition & 0 deletions src/rest/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ $(REST_BUILD_DIR)/:
# Invokes yang and model make to generate swagger artifcats.
$(REST_BIN): $(REST_SRCS) | $(REST_BUILD_DIR)/
$(MAKE) -C $(TOPDIR)/models/yang
$(MAKE) -C $(TOPDIR)/models/yang/sonic
$(MAKE) -C $(TOPDIR)/models
ifeq ($(SONIC_COVERAGE_ON),y)
GOPATH=$(REST_GOPATH) $(GO) test -coverpkg=".././..." -c -o $@ main/main.go main/main_test.go
Expand Down
2 changes: 1 addition & 1 deletion src/translib/common_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ func checkAndProcessLeafList(existingEntry db.Value, tblRw db.Value, opcode int,
}
/* delete specific item from leaf-list */
if opcode == DELETE {
if mergeTblRw.Field == nil {
if len(mergeTblRw.Field) == 0 {
return tblRw
}
err := d.ModEntry(dbTblSpec, db.Key{Comp: []string{tblKey}}, mergeTblRw)
Expand Down
2 changes: 2 additions & 0 deletions src/translib/transformer/xconst.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ const (

XPATH_SEP_FWD_SLASH = "/"
XFMR_EMPTY_STRING = ""
SONIC_TABLE_INDEX = 2

)
27 changes: 15 additions & 12 deletions src/translib/transformer/xlate.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func XlateFuncBind(name string, fn interface{}) (err error) {
func XlateFuncCall(name string, params ...interface{}) (result []reflect.Value, err error) {
if _, ok := XlateFuncs[name]; !ok {
err = errors.New(name + " Xfmr function does not exist.")
return nil, nil
return nil, err
}
if len(params) != XlateFuncs[name].Type().NumIn() {
err = ErrParamsNotAdapted
Expand Down Expand Up @@ -118,11 +118,11 @@ func XlateUriToKeySpec(uri string, ygRoot *ygot.GoStruct, t *interface{}) (*[]Ke
var err error
var retdbFormat = make([]KeySpec, 0)

// In case of CVL yang, the tablename and key info is available in the xpath
if isCvlYang(uri) {
// In case of SONIC yang, the tablename and key info is available in the xpath
if isSonicYang(uri) {
/* Extract the xpath and key from input xpath */
xpath, keyStr, tableName := sonicXpathKeyExtract(uri)
retdbFormat = fillCvlKeySpec(xpath, tableName, keyStr)
retdbFormat = fillSonicKeySpec(xpath, tableName, keyStr)
} else {
/* Extract the xpath and key from input xpath */
xpath, keyStr, _ := xpathKeyExtract(nil, ygRoot, 0, uri)
Expand Down Expand Up @@ -179,7 +179,7 @@ func FillKeySpecs(yangXpath string , keyStr string, retdbFormat *[]KeySpec) ([]K
return *retdbFormat
}

func fillCvlKeySpec(xpath string , tableName string, keyStr string) ( []KeySpec ) {
func fillSonicKeySpec(xpath string , tableName string, keyStr string) ( []KeySpec ) {

var retdbFormat = make([]KeySpec, 0)

Expand All @@ -197,15 +197,14 @@ func fillCvlKeySpec(xpath string , tableName string, keyStr string) ( []KeySpec
retdbFormat = append(retdbFormat, dbFormat)
} else {
// If table name not available in xpath get top container name
tokens:= strings.Split(xpath, ":")
container := "/" + tokens[len(tokens)-1]
container := xpath
if xDbSpecMap != nil {
if _, ok := xDbSpecMap[container]; ok {
dbInfo := xDbSpecMap[container]
if dbInfo.fieldType == "container" {
for dir, _ := range dbInfo.dbEntry.Dir {
_, ok := xDbSpecMap[dir]
if ok && xDbSpecMap[dir].dbEntry.Node.Statement().Keyword == "list" {
if ok && xDbSpecMap[dir].dbEntry.Node.Statement().Keyword == "container" {
cdb := xDbSpecMap[dir].dbIndex
dbFormat := KeySpec{}
dbFormat.Ts.Name = dir
Expand Down Expand Up @@ -311,7 +310,7 @@ func XlateFromDb(uri string, ygRoot *ygot.GoStruct, dbs [db.MaxDB]*db.DB, data m
var cdb db.DBNum = db.ConfigDB

dbData = data
if isCvlYang(uri) {
if isSonicYang(uri) {
xpath, keyStr, tableName := sonicXpathKeyExtract(uri)
if (tableName != "") {
dbInfo, ok := xDbSpecMap[tableName]
Expand All @@ -321,10 +320,14 @@ func XlateFromDb(uri string, ygRoot *ygot.GoStruct, dbs [db.MaxDB]*db.DB, data m
cdb = dbInfo.dbIndex
}
tokens:= strings.Split(xpath, "/")
// Format /module:container/tableName[key]/fieldName
if tokens[len(tokens)-2] == tableName {
// Format /module:container/tableName/listname[key]/fieldName
if tokens[SONIC_TABLE_INDEX] == tableName {
fieldName := tokens[len(tokens)-1]
dbData[cdb] = extractFieldFromDb(tableName, keyStr, fieldName, data[cdb])
dbSpecField := tableName + "/" + fieldName
_, ok := xDbSpecMap[dbSpecField]
if ok && xDbSpecMap[dbSpecField].fieldType == "leaf" {
dbData[cdb] = extractFieldFromDb(tableName, keyStr, fieldName, data[cdb])
}
}
}
} else {
Expand Down
Loading