onosproject / gnxi-simulators

Code for simulating various device and orchestration entities with which ONOS interacts, e.g. gNMI, gNOI, P4Runtime
13 stars 15 forks source link

Add own YANG module #129

Closed MrEnte closed 1 year ago

MrEnte commented 1 year ago

I am trying to add my own YANG module to the simulator.

I changed the command.sh file to this:

go get -u github.com/openconfig/ygot@v0.8.3
(cd $GOPATH/pkg/mod/github.com/openconfig/ygot@v0.8.3 && go get -t -d ./...)
cd $GOPATH/pkg/mod && go run github.com/openconfig/ygot@v0.8.3/generator/generator.go -generate_fakeroot -output_file github.com/onosproject/gnxi-simulators/pkg/gnmi/modeldata/gostruct/generated.go -package_name gostruct -exclude_modules ietf-interfaces -path github.com/openconfig/public,github.com/YangModels/yang example.yang

Here i am using the version 0.8.3. of ygot because it upgrades to the latest version automatically and i got this error:

go: module github.com/openconfig/ygot@upgrade found (v0.25.4), but does not contain package github.com/openconfig/ygot/experimental/ygotutils

But when i changed to the supported version i got this error when i execute command.sh:

go: module github.com/golang/protobuf is deprecated: Use the "google.golang.org/protobuf" module instead.
# command-line-arguments
github.com/openconfig/ygot@v0.8.3/generator/generator.go:82:62: undefined: ygen.DefaultAnnotationPrefix
github.com/openconfig/ygot@v0.8.3/generator/generator.go:99:54: undefined: ygen.GeneratedGoCode
github.com/openconfig/ygot@v0.8.3/generator/generator.go:143:36: undefined: ygen.GeneratedGoCode
github.com/openconfig/ygot@v0.8.3/generator/generator.go:299:14: undefined: ygen.NewYANGCodeGenerator
github.com/openconfig/ygot@v0.8.3/generator/generator.go:299:41: undefined: ygen.GeneratorConfig
github.com/openconfig/ygot@v0.8.3/generator/generator.go:302:5: unknown field 'SkipEnumDeduplication' in struct literal of type ygen.ParseOpts
github.com/openconfig/ygot@v0.8.3/generator/generator.go:316:20: undefined: ygen.GoOpts
github.com/openconfig/ygot@v0.8.3/generator/generator.go:422:36: cannot use pathCode (variable of type map[string]*ypathgen.GeneratedPathCode) as type *ypathgen.GeneratedPathCode in argument to writeGoPathCodeSingleFile
github.com/openconfig/ygot@v0.8.3/generator/generator.go:426:26: pathCode.SplitFiles undefined (type map[string]*ypathgen.GeneratedPathCode has no field or method SplitFiles)
SeanCondon commented 1 year ago

This kind of thing worked for me

go get github.com/openconfig/ygot@v0.8.3
(cd $GOPATH/pkg/mod/github.com/openconfig/ygot@v0.8.3 && go get -t -d ./...)
go get github.com/openconfig/public
go get github.com/google/go-cmp/cmp
go get github.com/openconfig/gnmi/ctree
go get github.com/openconfig/gnmi/proto/gnmi
go get github.com/openconfig/gnmi/value
go get github.com/YangModels/yang
go get github.com/golang/glog
go get github.com/golang/protobuf/proto
go get github.com/kylelemons/godebug/pretty
go get github.com/openconfig/goyang/pkg/yang@v0.0.0-20200803193518-78bac27bdff1
go get google.golang.org/grpc
go run $GOPATH/pkg/mod/github.com/openconfig/ygot@v0.8.3/generator/generator.go -generate_fakeroot -output_file github.com/onosproject/gnxi-simulators/pkg/gnmi/modeldata/gostruct/generated.go -package_name gostruct -exclude_modules ietf-interfaces -path github.com/openconfig/public,github.com/YangModels/yang example.yang

Also you should consider using: https://github.com/onosproject/config-models/blob/master/models/devicesim-1.0.x/api/generated.go

In this repo the devicesim model is the same as the gnxi simulator. Here we generate the code using the model-compiler docker image using make models

MrEnte commented 1 year ago

@SeanCondon thanks for the fast response!

Your comment fix the error but now i get this error:

#14 64.37 cmd/gnmi_target/gnmi_target.go:38:3: undefined: gostruct.ΛEnum

when i use this command to build a new docker image:

docker build -t onosproject/device-simulator:stable -f Dockerfile .

Furthermore a look into the repository you recommended and i am not sure how a can put my YANG module in there. Additionally i can't run the docker container like suggested in the README because my computer does not support AMD64 images. Maybe i can try it later on a different computer.

Here is the whole output:

[+] Building 68.6s (11/19)
 => [internal] load build definition from Dockerfile                                                                                                                                                             0.0s
 => => transferring dockerfile: 74B                                                                                                                                                                              0.0s
 => [internal] load .dockerignore                                                                                                                                                                                0.0s
 => => transferring context: 72B                                                                                                                                                                                 0.0s
 => [internal] load metadata for docker.io/library/alpine:3.11                                                                                                                                                   1.6s
 => [internal] load metadata for docker.io/onosproject/golang-build:v1.2.0                                                                                                                                       1.7s
 => [build 1/5] FROM docker.io/onosproject/golang-build:v1.2.0@sha256:f8f0f947a9fd68e8404ec30532f5e6f2680533cb93f8cd31961b4e41deb57603                                                                           0.0s
 => [internal] load build context                                                                                                                                                                                0.0s
 => => transferring context: 167.18kB                                                                                                                                                                            0.0s
 => [stage-1 1/9] FROM docker.io/library/alpine:3.11@sha256:bcae378eacedab83da66079d9366c8f5df542d7ed9ab23bf487e3e1a8481375d                                                                                     0.0s
 => CACHED [build 2/5] RUN cd /go     && GO111MODULE=on go get -u       github.com/google/gnxi/gnoi_target@6697a080bc2d3287d9614501a3298b3dcfea06df       github.com/google/gnxi/gnoi_cert@6697a080bc2d3287d961  0.0s
 => CACHED [build 3/5] RUN mkdir -p /go/src/github.com/onosproject/gnxi-simulators/                                                                                                                              0.0s
 => [build 4/5] COPY . /go/src/github.com/onosproject/gnxi-simulators                                                                                                                                            0.0s
 => ERROR [build 5/5] RUN cd /go/src/github.com/onosproject/gnxi-simulators && GO111MODULE=on go build -o /go/bin/gnmi_target ./cmd/gnmi_target                                                                 66.8s
------
 > [build 5/5] RUN cd /go/src/github.com/onosproject/gnxi-simulators && GO111MODULE=on go build -o /go/bin/gnmi_target ./cmd/gnmi_target:
#14 9.814 go: downloading github.com/google/gnxi v0.0.0-20190228205329-8521faedac37
#14 9.816 go: downloading github.com/onosproject/onos-lib-go v0.8.0
#14 9.817 go: downloading github.com/openconfig/gnmi v0.0.0-20220920173703-480bf53a74d2
#14 9.817 go: downloading github.com/openconfig/ygot v0.8.3
#14 9.867 go: downloading github.com/eapache/channels v1.1.0
#14 10.01 go: downloading github.com/openconfig/goyang v0.0.0-20200803193518-78bac27bdff1
#14 10.17 go: downloading github.com/eapache/queue v1.1.0
#14 10.19 go: downloading github.com/Shopify/sarama v1.29.1
#14 10.21 go: downloading github.com/mitchellh/go-homedir v1.1.0
#14 10.25 go: downloading github.com/spf13/viper v1.7.1
#14 10.32 go: downloading go.uber.org/zap v1.16.0
#14 10.51 go: downloading github.com/gogo/protobuf v1.3.2
#14 10.51 go: downloading github.com/atomix/atomix-go-framework v0.6.5
#14 10.80 go: downloading github.com/atomix/go-client v0.4.1
#14 10.95 go: downloading github.com/fsnotify/fsnotify v1.4.7
#14 10.99 go: downloading github.com/hashicorp/hcl v1.0.0
#14 11.09 go: downloading github.com/magiconair/properties v1.8.1
#14 11.15 go: downloading github.com/mitchellh/mapstructure v1.1.2
#14 11.20 go: downloading github.com/pelletier/go-toml v1.2.0
#14 11.28 go: downloading github.com/spf13/afero v1.3.3
#14 11.36 go: downloading github.com/spf13/cast v1.3.0
#14 11.41 go: downloading github.com/spf13/jwalterweatherman v1.0.0
#14 11.46 go: downloading github.com/spf13/pflag v1.0.5
#14 11.55 go: downloading github.com/subosito/gotenv v1.2.0
#14 11.59 go: downloading gopkg.in/ini.v1 v1.51.0
#14 11.61 go: downloading gopkg.in/yaml.v2 v2.4.0
#14 11.61 go: downloading github.com/davecgh/go-spew v1.1.1
#14 11.62 go: downloading github.com/eapache/go-resiliency v1.2.0
#14 11.68 go: downloading github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21
#14 11.68 go: downloading github.com/jcmturner/gofork v1.0.0
#14 11.69 go: downloading github.com/jcmturner/gokrb5/v8 v8.4.2
#14 11.84 go: downloading github.com/klauspost/compress v1.12.2
#14 11.85 go: downloading github.com/pierrec/lz4 v2.6.0+incompatible
#14 11.85 go: downloading github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
#14 11.85 go: downloading go.uber.org/atomic v1.6.0
#14 11.85 go: downloading go.uber.org/multierr v1.5.0
#14 11.90 go: downloading github.com/atomix/api v0.3.3
#14 11.91 go: downloading github.com/google/go-cmp v0.5.9
#14 11.91 go: downloading github.com/golang/snappy v0.0.3
#14 11.97 go: downloading github.com/jcmturner/dnsutils/v2 v2.0.0
#14 12.00 go: downloading github.com/hashicorp/go-uuid v1.0.2
#14 12.03 go: downloading golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
#14 12.03 go: downloading github.com/jcmturner/rpc/v2 v2.0.3
#14 12.11 go: downloading github.com/jcmturner/aescts/v2 v2.0.0
#14 66.67 # github.com/onosproject/gnxi-simulators/cmd/gnmi_target
#14 66.67 cmd/gnmi_target/gnmi_target.go:38:3: undefined: gostruct.ΛEnum
------
executor failed running [/bin/sh -c cd $ONOS_SIMULATORS_ROOT && GO111MODULE=on go build -o /go/bin/gnmi_target ./cmd/gnmi_target]: exit code: 2
 ✘ juanlesmes@MBP-von-Juan  ~/Projects/Uni/NEIDI/gnxi-simulators   master ±  go mod tidy
 juanlesmes@MBP-von-Juan  ~/Projects/Uni/NEIDI/gnxi-simulators   master ±  docker build -t onosproject/device-simulator:stable -f Dockerfile .
[+] Building 66.0s (11/19)
 => [internal] load build definition from Dockerfile                                                                                                                                                             0.0s
 => => transferring dockerfile: 74B                                                                                                                                                                              0.0s
 => [internal] load .dockerignore                                                                                                                                                                                0.0s
 => => transferring context: 72B                                                                                                                                                                                 0.0s
 => [internal] load metadata for docker.io/library/alpine:3.11                                                                                                                                                   1.3s
 => [internal] load metadata for docker.io/onosproject/golang-build:v1.2.0                                                                                                                                       1.3s
 => [build 1/5] FROM docker.io/onosproject/golang-build:v1.2.0@sha256:f8f0f947a9fd68e8404ec30532f5e6f2680533cb93f8cd31961b4e41deb57603                                                                           0.0s
 => [internal] load build context                                                                                                                                                                                0.0s
 => => transferring context: 166.38kB                                                                                                                                                                            0.0s
 => [stage-1 1/9] FROM docker.io/library/alpine:3.11@sha256:bcae378eacedab83da66079d9366c8f5df542d7ed9ab23bf487e3e1a8481375d                                                                                     0.0s
 => CACHED [build 2/5] RUN cd /go     && GO111MODULE=on go get -u       github.com/google/gnxi/gnoi_target@6697a080bc2d3287d9614501a3298b3dcfea06df       github.com/google/gnxi/gnoi_cert@6697a080bc2d3287d961  0.0s
 => CACHED [build 3/5] RUN mkdir -p /go/src/github.com/onosproject/gnxi-simulators/                                                                                                                              0.0s
 => [build 4/5] COPY . /go/src/github.com/onosproject/gnxi-simulators                                                                                                                                            0.0s
 => ERROR [build 5/5] RUN cd /go/src/github.com/onosproject/gnxi-simulators && GO111MODULE=on go build -o /go/bin/gnmi_target ./cmd/gnmi_target                                                                 64.5s
------
 > [build 5/5] RUN cd /go/src/github.com/onosproject/gnxi-simulators && GO111MODULE=on go build -o /go/bin/gnmi_target ./cmd/gnmi_target:
#14 8.760 go: downloading github.com/google/gnxi v0.0.0-20190228205329-8521faedac37
#14 8.762 go: downloading github.com/onosproject/onos-lib-go v0.8.0
#14 8.763 go: downloading github.com/openconfig/gnmi v0.0.0-20220920173703-480bf53a74d2
#14 8.763 go: downloading github.com/openconfig/ygot v0.8.3
#14 8.808 go: downloading github.com/eapache/channels v1.1.0
#14 8.934 go: downloading github.com/openconfig/goyang v0.0.0-20200803193518-78bac27bdff1
#14 9.135 go: downloading github.com/eapache/queue v1.1.0
#14 9.145 go: downloading github.com/Shopify/sarama v1.29.1
#14 9.159 go: downloading github.com/mitchellh/go-homedir v1.1.0
#14 9.199 go: downloading github.com/spf13/viper v1.7.1
#14 9.261 go: downloading go.uber.org/zap v1.16.0
#14 9.424 go: downloading github.com/gogo/protobuf v1.3.2
#14 9.425 go: downloading github.com/atomix/atomix-go-framework v0.6.5
#14 9.713 go: downloading github.com/atomix/go-client v0.4.1
#14 9.801 go: downloading github.com/fsnotify/fsnotify v1.4.7
#14 9.854 go: downloading github.com/hashicorp/hcl v1.0.0
#14 9.960 go: downloading github.com/magiconair/properties v1.8.1
#14 9.999 go: downloading github.com/mitchellh/mapstructure v1.1.2
#14 10.03 go: downloading github.com/pelletier/go-toml v1.2.0
#14 10.10 go: downloading github.com/spf13/afero v1.3.3
#14 10.16 go: downloading github.com/spf13/cast v1.3.0
#14 10.19 go: downloading github.com/spf13/jwalterweatherman v1.0.0
#14 10.23 go: downloading github.com/spf13/pflag v1.0.5
#14 10.32 go: downloading github.com/subosito/gotenv v1.2.0
#14 10.34 go: downloading gopkg.in/ini.v1 v1.51.0
#14 10.41 go: downloading gopkg.in/yaml.v2 v2.4.0
#14 10.47 go: downloading github.com/davecgh/go-spew v1.1.1
#14 10.48 go: downloading github.com/eapache/go-resiliency v1.2.0
#14 10.49 go: downloading github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21
#14 10.49 go: downloading github.com/jcmturner/gofork v1.0.0
#14 10.53 go: downloading github.com/jcmturner/gokrb5/v8 v8.4.2
#14 10.66 go: downloading github.com/klauspost/compress v1.12.2
#14 10.66 go: downloading github.com/pierrec/lz4 v2.6.0+incompatible
#14 10.66 go: downloading github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
#14 10.66 go: downloading go.uber.org/atomic v1.6.0
#14 10.67 go: downloading go.uber.org/multierr v1.5.0
#14 10.72 go: downloading github.com/atomix/api v0.3.3
#14 10.73 go: downloading github.com/google/go-cmp v0.5.9
#14 10.73 go: downloading github.com/golang/snappy v0.0.3
#14 10.79 go: downloading github.com/jcmturner/dnsutils/v2 v2.0.0
#14 10.82 go: downloading github.com/hashicorp/go-uuid v1.0.2
#14 10.84 go: downloading golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
#14 10.86 go: downloading github.com/jcmturner/rpc/v2 v2.0.3
#14 10.97 go: downloading github.com/jcmturner/aescts/v2 v2.0.0
#14 64.37 # github.com/onosproject/gnxi-simulators/cmd/gnmi_target
#14 64.37 cmd/gnmi_target/gnmi_target.go:38:3: undefined: gostruct.ΛEnum
------
executor failed running [/bin/sh -c cd $ONOS_SIMULATORS_ROOT && GO111MODULE=on go build -o /go/bin/gnmi_target ./cmd/gnmi_target]: exit code: 2
mk1307 commented 1 year ago

I'm trying to add my own YANG module to the simulator too.

After a while I ran into the same issue. My professor gave me a solution to this problem:

You have to go into cmd/gnmi_target/gnmi_target.go and change line 38 from gostruct.ΛEnum to gostruct.GoStructEnumData{} and make all after that.

After that, delete the 2 lines under

deps: # @HELP ensure that the required dependencies are in place

in build/build-tools/make/onf-common.mk

and then you should be able to build your docker container.

It didn't work for me though. Changing gostruct.ΛEnum to gostruct.GoStructEnumData{} didn't resolve the error for me.

MrEnte commented 1 year ago

@mk1307 Yeah i also came to the same solution a while ago but forgot to update this issue. Thanks anyway