Skip to content

Commit ffa2ee6

Browse files
author
Prabhu Sreenivasan
committed
Revert "Merge pull request #173 from project-arlo/transformer-phase2"
This reverts commit ca4b330, reversing changes made to 211f17e.
1 parent ca4b330 commit ffa2ee6

29 files changed

+591
-2460
lines changed

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ codegen:
9494

9595
yamlGen:
9696
$(MAKE) -C models/yang
97-
$(MAKE) -C models/yang/sonic
9897

9998
go-patch: go-deps
10099
cd $(BUILD_GOPATH)/src/github.com/openconfig/ygot/; git reset --hard HEAD; git checkout 724a6b18a9224343ef04fe49199dfb6020ce132a 2>/dev/null ; true; \
@@ -109,10 +108,9 @@ install:
109108
$(INSTALL) -d $(DESTDIR)/usr/sbin/schema/
110109
$(INSTALL) -d $(DESTDIR)/usr/sbin/lib/
111110
$(INSTALL) -d $(DESTDIR)/usr/models/yang/
112-
$(INSTALL) -D $(TOPDIR)/models/yang/sonic/*.yang $(DESTDIR)/usr/models/yang/
113-
$(INSTALL) -D $(TOPDIR)/models/yang/sonic/common/*.yang $(DESTDIR)/usr/models/yang/
114111
$(INSTALL) -D $(TOPDIR)/src/cvl/schema/*.yin $(DESTDIR)/usr/sbin/schema/
115112
$(INSTALL) -D $(TOPDIR)/src/cvl/testdata/schema/*.yin $(DESTDIR)/usr/sbin/schema/
113+
$(INSTALL) -D $(TOPDIR)/src/cvl/schema/*.yang $(DESTDIR)/usr/models/yang/
116114
$(INSTALL) -D $(TOPDIR)/models/yang/*.yang $(DESTDIR)/usr/models/yang/
117115
$(INSTALL) -D $(TOPDIR)/config/transformer/models_list $(DESTDIR)/usr/models/yang/
118116
$(INSTALL) -D $(TOPDIR)/models/yang/common/*.yang $(DESTDIR)/usr/models/yang/

goyang-modified-files/annotate.go

Lines changed: 21 additions & 273 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424

2525
var allimports = make(map[string]string)
2626
var modules = make(map[string]*yang.Module)
27-
var allmodules = make(map[string]*yang.Module)
2827

2928
func init() {
3029
register(&formatter{
@@ -37,13 +36,14 @@ func init() {
3736

3837
// Get the modules for which annotation file needs to be generated
3938
func getFile(files []string, mods map[string]*yang.Module) {
40-
allmodules = mods
4139
for _, name := range files {
4240
slash := strings.Split(name, "/")
41+
if strings.HasSuffix(name, ".yang") {
4342
modname := slash[len(slash)-1]
4443
modname = strings.TrimSuffix(modname, ".yang");
4544
/* Save the yang.Module entries we are interested in */
4645
modules[modname] = mods[modname]
46+
}
4747
}
4848
}
4949

@@ -53,8 +53,7 @@ func genAnnotate(w io.Writer, entries []*yang.Entry) {
5353
for _, e := range entries {
5454
if _, ok := modules[e.Name]; ok {
5555
var path string = ""
56-
var prefix string = ""
57-
generate(w, e, path, prefix)
56+
generate(w, e, path)
5857
// { Add closing brace for each module
5958
fmt.Fprintln(w, "}")
6059
fmt.Fprintln(w)
@@ -63,97 +62,66 @@ func genAnnotate(w io.Writer, entries []*yang.Entry) {
6362
}
6463

6564
// generate writes to stdoutput a template annotation file entry for the selected modules.
66-
func generate(w io.Writer, e *yang.Entry, path string, prefix string) {
65+
func generate(w io.Writer, e *yang.Entry, path string) {
6766
if e.Parent == nil {
6867
if e.Name != "" {
6968
fmt.Fprintf(w, "module %s-annot {\n", e.Name) //}
7069
fmt.Fprintln(w)
71-
fmt.Fprintf(w, " yang-version \"%s\";\n", getYangVersion(e.Name, modules))
70+
fmt.Fprintf(w, " yang-version \"%s\"\n", getYangVersion(e.Name, modules))
7271
fmt.Fprintln(w)
73-
fmt.Fprintf(w, " namespace \"http://openconfig.net/yang/annotation/%s-annot\";\n", e.Prefix.Name)
72+
fmt.Fprintf(w, " namespace \"http://openconfig.net/yang/annotation\";\n")
7473
if e.Prefix != nil {
75-
fmt.Fprintf(w, " prefix \"%s-annot\";\n", e.Prefix.Name)
74+
fmt.Fprintf(w, " prefix \"%s-annot\" \n", e.Prefix.Name)
7675
}
7776
fmt.Fprintln(w)
7877

7978
var imports = make(map[string]string)
8079
imports = getImportModules(e.Name, modules)
8180
for k := range imports {
8281
if e.Name != k {
83-
fmt.Fprintf(w, " import %s { prefix %s; }\n", k, allimports[k])
82+
fmt.Fprintf(w, " import %s { prefix %s }\n", k, allimports[k])
8483
}
8584
}
86-
// Include the module for which annotation is being generated
87-
fmt.Fprintf(w, " import %s { prefix %s; }\n", e.Name, e.Prefix.Name)
8885

8986
fmt.Fprintln(w)
9087
}
9188
}
9289

9390
name := e.Name
94-
if prefix == "" && e.Prefix != nil {
95-
prefix = e.Prefix.Name
91+
if e.Prefix != nil {
92+
name = e.Prefix.Name + ":" + name
9693
}
97-
name = prefix + ":" + name
9894

99-
if (e.Node.Kind() != "module") {
100-
path = path + "/" + name
101-
printDeviation(w, path)
95+
delim := ""
96+
if path != "" {
97+
delim = "/"
10298
}
99+
path = path + delim + name
100+
101+
fmt.Fprintf(w, " deviation %s {\n", path)
102+
fmt.Fprintf(w, " deviate add {\n")
103+
fmt.Fprintf(w, " }\n")
104+
fmt.Fprintf(w, " }\n")
105+
fmt.Fprintln(w)
103106

104107
var names []string
105108
for k := range e.Dir {
106109
names = append(names, k)
107110
}
108111

109-
if (e.Node.Kind() == "module") {
110-
if len(e.Node.(*yang.Module).Augment) > 0 {
111-
for _,a := range e.Node.(*yang.Module).Augment {
112-
pathList := strings.Split(a.Name, "/")
113-
pathList = pathList[1:]
114-
for i, pvar := range pathList {
115-
if len(pvar) > 0 && !strings.Contains(pvar, ":") {
116-
pvar = e.Prefix.Name + ":" + pvar
117-
pathList[i] = pvar
118-
}
119-
}
120-
path = "/" + strings.Join(pathList, "/")
121-
handleAugments(w, a, e.Node.(*yang.Module).Grouping, e.Prefix.Name, path)
122-
}
123-
}
124-
}
125-
126112
for _, k := range names {
127-
generate(w, e.Dir[k], path, prefix)
113+
generate(w, e.Dir[k], path)
128114
}
129115

130116
}
131117

132-
func printDeviation(w io.Writer, path string){
133-
fmt.Fprintf(w, " deviation %s {\n", path)
134-
fmt.Fprintf(w, " deviate add {\n")
135-
fmt.Fprintf(w, " }\n")
136-
fmt.Fprintf(w, " }\n")
137-
fmt.Fprintln(w)
138-
}
139-
140-
141118
// Save to map all imported modules
142119
func GetAllImports(entries []*yang.Entry) {
143120
for _, e := range entries {
144121
allimports[e.Name] = e.Prefix.Name
145122
}
146123
}
147124

148-
func GetModuleFromPrefix(prefix string) string {
149-
for m, p := range allimports {
150-
if prefix == p {
151-
return m
152-
}
153-
}
154-
return ""
155-
}
156-
157125
//Get Yang version from the yang.Modules
158126
func getYangVersion(modname string, mods map[string]*yang.Module) string {
159127
if (mods[modname].YangVersion != nil) {
@@ -173,223 +141,3 @@ func getImportModules(modname string, mods map[string]*yang.Module) map[string]s
173141
}
174142
return imports
175143
}
176-
177-
func handleAugments(w io.Writer, a *yang.Augment, grp []*yang.Grouping, prefix string, path string) {
178-
for _, u := range a.Uses {
179-
grpN := u.Name
180-
for _, g := range grp {
181-
if grpN == g.Name {
182-
if len(g.Container) > 0 {
183-
handleContainer(w, g.Container, grp, prefix, path)
184-
}
185-
if len(g.List) > 0 {
186-
handleList(w, g.List, grp, prefix, path)
187-
}
188-
if len(g.LeafList) > 0 {
189-
handleLeafList(w, g.LeafList, prefix, path)
190-
}
191-
if len(g.Leaf) > 0 {
192-
handleLeaf(w, g.Leaf, prefix, path)
193-
}
194-
if len(g.Choice) > 0 {
195-
handleChoice(w, g.Choice, grp, prefix, path)
196-
}
197-
if len(g.Uses) > 0 {
198-
handleUses(w, g.Uses, grp, prefix, path)
199-
}
200-
}
201-
}
202-
}
203-
204-
}
205-
206-
func handleUses(w io.Writer, u []*yang.Uses, grp []*yang.Grouping, prefix string, path string) {
207-
for _, u := range u {
208-
grpN := u.Name
209-
if strings.Contains(grpN, ":") {
210-
tokens := strings.Split(grpN, ":")
211-
nprefix := tokens[0]
212-
grpN = tokens[1]
213-
mod := GetModuleFromPrefix(nprefix)
214-
grp = allmodules[mod].Grouping
215-
}
216-
for _, g := range grp {
217-
if grpN == g.Name {
218-
if len(g.Container) > 0 {
219-
handleContainer(w, g.Container, grp, prefix, path)
220-
}
221-
if len(g.List) > 0 {
222-
handleList(w, g.List, grp, prefix, path)
223-
}
224-
if len(g.LeafList) > 0 {
225-
handleLeafList(w, g.LeafList, prefix, path)
226-
}
227-
if len(g.Leaf) > 0 {
228-
handleLeaf(w, g.Leaf, prefix, path)
229-
}
230-
if len(g.Choice) > 0 {
231-
handleChoice(w, g.Choice, grp, prefix, path)
232-
}
233-
if len(g.Uses) > 0 {
234-
handleUses(w, g.Uses, grp, prefix, path)
235-
}
236-
237-
}
238-
}
239-
}
240-
241-
}
242-
243-
func handleContainer(w io.Writer, ctr []*yang.Container, grp []*yang.Grouping, prefix string, path string) {
244-
for _, c := range ctr {
245-
npath := path + "/" + prefix + ":" + c.Name
246-
printDeviation(w, npath)
247-
if len(c.Container) > 0 {
248-
handleContainer(w, c.Container, grp, prefix, npath)
249-
}
250-
if len(c.List) > 0 {
251-
handleList(w, c.List, grp, prefix, npath)
252-
}
253-
if len(c.LeafList) > 0 {
254-
handleLeafList(w, c.LeafList, prefix, npath)
255-
}
256-
if len(c.Leaf) > 0 {
257-
handleLeaf(w, c.Leaf, prefix, npath)
258-
}
259-
if len(c.Choice) > 0 {
260-
handleChoice(w, c.Choice, grp, prefix, npath)
261-
}
262-
if len(c.Grouping) > 0 {
263-
handleGrouping(w, c.Grouping, grp, prefix, npath)
264-
}
265-
if len(c.Uses) > 0 {
266-
handleUses(w, c.Uses, grp, prefix, npath)
267-
}
268-
}
269-
}
270-
271-
func handleList(w io.Writer, lst []*yang.List, grp []*yang.Grouping, prefix string, path string) {
272-
for _, l := range lst {
273-
npath := path + "/" + prefix + ":" + l.Name
274-
printDeviation(w, npath)
275-
if len(l.Container) > 0 {
276-
handleContainer(w, l.Container, grp, prefix, npath)
277-
}
278-
if len(l.List) > 0 {
279-
handleList(w, l.List, grp, prefix, npath)
280-
}
281-
if len(l.LeafList) > 0 {
282-
handleLeafList(w, l.LeafList, prefix, npath)
283-
}
284-
if len(l.Leaf) > 0 {
285-
handleLeaf(w, l.Leaf, prefix, npath)
286-
}
287-
if len(l.Choice) > 0 {
288-
handleChoice(w, l.Choice, grp, prefix, npath)
289-
}
290-
if len(l.Grouping) > 0 {
291-
handleGrouping(w, l.Grouping, grp, prefix, npath)
292-
}
293-
if len(l.Uses) > 0 {
294-
handleUses(w, l.Uses, grp, prefix, npath)
295-
}
296-
297-
}
298-
}
299-
300-
func handleGrouping(w io.Writer, grp []*yang.Grouping, grptop []*yang.Grouping, prefix string, path string) {
301-
for _, g := range grp {
302-
npath := path + "/" + prefix + ":" + g.Name
303-
printDeviation(w, npath)
304-
if len(g.Container) > 0 {
305-
handleContainer(w, g.Container, grptop, prefix, npath)
306-
}
307-
if len(g.List) > 0 {
308-
handleList(w, g.List, grptop, prefix, npath)
309-
}
310-
if len(g.LeafList) > 0 {
311-
handleLeafList(w, g.LeafList, prefix, npath)
312-
}
313-
if len(g.Leaf) > 0 {
314-
handleLeaf(w, g.Leaf, prefix, npath)
315-
}
316-
if len(g.Choice) > 0 {
317-
handleChoice(w, g.Choice, grptop, prefix, npath)
318-
}
319-
if len(g.Grouping) > 0 {
320-
handleGrouping(w, g.Grouping, grptop, prefix, npath)
321-
}
322-
if len(g.Uses) > 0 {
323-
handleUses(w, g.Uses, grptop, prefix, npath)
324-
}
325-
326-
}
327-
}
328-
329-
func handleLeaf (w io.Writer, lf []*yang.Leaf, prefix string, path string) {
330-
if len(lf) > 0 {
331-
for _, l := range lf {
332-
npath := path + "/" + prefix + ":" + l.Name
333-
printDeviation(w, npath)
334-
}
335-
}
336-
337-
}
338-
339-
func handleLeafList (w io.Writer, llst []*yang.LeafList, prefix string, path string) {
340-
if len(llst) > 0 {
341-
for _, l := range llst {
342-
npath := path + "/" + prefix + ":" + l.Name
343-
printDeviation(w, npath)
344-
}
345-
}
346-
}
347-
348-
func handleChoice (w io.Writer, ch []*yang.Choice, grp []*yang.Grouping, prefix string, path string) {
349-
for _, c := range ch {
350-
npath := path + "/" + prefix + ":" + c.Name
351-
printDeviation(w, npath)
352-
if len(c.Container) > 0 {
353-
handleContainer(w, c.Container, grp, prefix, npath)
354-
}
355-
if len(c.List) > 0 {
356-
handleList(w, c.List, grp, prefix, npath)
357-
}
358-
if len(c.LeafList) > 0 {
359-
handleLeafList(w, c.LeafList, prefix, npath)
360-
}
361-
if len(c.Leaf) > 0 {
362-
handleLeaf(w, c.Leaf, prefix, npath)
363-
}
364-
if len(c.Case) > 0 {
365-
handleCase(w, c.Case, grp, prefix, npath)
366-
}
367-
}
368-
}
369-
370-
func handleCase (w io.Writer, ch []*yang.Case, grp []*yang.Grouping, prefix string, path string) {
371-
for _, c := range ch {
372-
npath := path + "/" + prefix + ":" + c.Name
373-
printDeviation(w, npath)
374-
if len(c.Container) > 0 {
375-
handleContainer(w, c.Container, grp, prefix, npath)
376-
}
377-
if len(c.List) > 0 {
378-
handleList(w, c.List, grp, prefix, npath)
379-
}
380-
if len(c.LeafList) > 0 {
381-
handleLeafList(w, c.LeafList, prefix, npath)
382-
}
383-
if len(c.Leaf) > 0 {
384-
handleLeaf(w, c.Leaf, prefix, npath)
385-
}
386-
if len(c.Choice) > 0 {
387-
handleChoice(w, c.Choice, grp, prefix, npath)
388-
}
389-
if len(c.Uses) > 0 {
390-
handleUses(w, c.Uses, grp, prefix, npath)
391-
}
392-
393-
}
394-
}
395-

0 commit comments

Comments
 (0)