Skip to content

Commit

Permalink
Merge branch 'split-protogen-package' into delete-YANGCodeGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
wenovus committed Jun 9, 2022
2 parents a407ebd + bc05185 commit 30dd9cb
Show file tree
Hide file tree
Showing 9 changed files with 51,335 additions and 48,977 deletions.
10 changes: 5 additions & 5 deletions demo/bgp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ func CreateDemoBGPInstance() (*oc.NetworkInstance_Protocol_Bgp, error) {
// Initialize all containers underneath the newly created peer. This allows us
// to now specify containers in the hierarchy that we didn't yet initialize.
ygot.BuildEmptyTree(nPeer)
nPeer.Timers.HoldTime = ygot.Float64(30)
nPeer.Timers.HoldTime = ygot.Uint16(30)

// Elements of the schema that themselves are containers have a struct
// generated for them which can be set directly.
nPeer.Timers = &oc.NetworkInstance_Protocol_Bgp_Neighbor_Timers{
HoldTime: ygot.Float64(90.0),
KeepaliveInterval: ygot.Float64(30.0),
HoldTime: ygot.Uint16(90.0),
KeepaliveInterval: ygot.Uint16(30.0),
}

// An entry in a list can be directly defined as a map entry, with the multi-key
Expand All @@ -93,8 +93,8 @@ func CreateDemoBGPInstance() (*oc.NetworkInstance_Protocol_Bgp, error) {
NeighborAddress: ygot.String("192.0.2.1"),
Description: ygot.String("BT UK"),
Timers: &oc.NetworkInstance_Protocol_Bgp_Neighbor_Timers{
HoldTime: ygot.Float64(30.0),
KeepaliveInterval: ygot.Float64(10.0),
HoldTime: ygot.Uint16(30.0),
KeepaliveInterval: ygot.Uint16(10.0),
},
Transport: &oc.NetworkInstance_Protocol_Bgp_Neighbor_Transport{
PassiveMode: ygot.Bool(true),
Expand Down
8 changes: 4 additions & 4 deletions demo/bgp/testdata/bgp-ietf.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
},
"timers": {
"config": {
"hold-time": "30",
"keepalive-interval": "10"
"hold-time": 30,
"keepalive-interval": 10
}
},
"transport": {
Expand All @@ -41,8 +41,8 @@
"neighbor-address": "2001:DB8::1",
"timers": {
"config": {
"hold-time": "90",
"keepalive-interval": "30"
"hold-time": 90,
"keepalive-interval": 30
}
}
}
Expand Down
85,042 changes: 42,722 additions & 42,320 deletions exampleoc/oc.go

Large diffs are not rendered by default.

4,265 changes: 2,444 additions & 1,821 deletions exampleoc/ocpath.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions exampleoc/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ go run ../generator/generator.go -path=public,deps -output_file=oc.go \
public/release/models/interfaces/openconfig-if-ethernet.yang \
public/release/models/interfaces/openconfig-if-ip-ext.yang \
public/release/models/relay-agent/openconfig-relay-agent.yang \
public/release/models/aft/openconfig-aft-network-instance.yang \
public/release/models/lldp/openconfig-lldp.yang
runsed -i 's/This package was generated by.*/NOTE WELL: This is an example code file that is distributed with ygot.\nIt should not be used within your application, as it WILL change,\nwithout warning. Rather, you should generate structs directly from\nOpenConfig models using the ygot package.\n\nThis package was generated by github.com\/openconfig\/ygot/g' oc.go
gofmt -w -s oc.go
Expand Down
10,695 changes: 5,997 additions & 4,698 deletions uexampleoc/oc.go

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions ygot/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4109,6 +4109,10 @@ func TestMarshal7951(t *testing.T) {
Str: String("test-string"),
},
want: `{"str":"test-string"}`,
}, {
desc: "nil GoStruct",
in: (*renderExample)(nil),
want: `null`,
}, {
desc: "simple GoStruct with PreferShadowPath",
in: &renderExample{
Expand Down Expand Up @@ -4174,6 +4178,16 @@ func TestMarshal7951(t *testing.T) {
in: map[string]*renderExample{},
// null as empty array is not valid, RFC7951 section 5.4 specify that the array must be an array, and JSON empty arrays are not null value
want: `[]`,
}, {
desc: "nil map",
in: (map[string]*renderExample)(nil),
// While not specified by RFC7951 section 5.4, using null to
// represent a non-initialized map is the behaviour that has
// been longstanding within ygot (Hyrum's Law).
// As with other 'null' representations, it is only shown in
// the JSON when the list is directly being marshalled, as
// opposed to when an ancestor node is being marshalled.
want: `null`,
}, {
desc: "nil string pointer",
in: (*string)(nil),
Expand Down
267 changes: 143 additions & 124 deletions ytypes/schema_tests/testdata/local-routing-example.json
Original file line number Diff line number Diff line change
@@ -1,129 +1,148 @@
{
"openconfig-local-routing:local-routes": {
"static-routes": {
"static": [
{
"prefix": "10.0.0.0/8",
"config": {
"prefix": "10.0.0.0/8"
},
"next-hops": {
"next-hop": [
{
"index": "**10.10.16.254**",
"openconfig-network-instance:network-instances": {
"network-instance": [
{
"config": {
"index": "**10.10.16.254**",
"next-hop": "10.10.16.254",
"metric": 200
"name": "DEFAULT"
},
"name": "DEFAULT",
"protocols": {
"protocol": [
{
"config": {
"identifier": "openconfig-policy-types:STATIC",
"name": "0"
},
"identifier": "openconfig-policy-types:STATIC",
"name": "0",
"static-routes": {
"static": [
{
"config": {
"prefix": "10.0.0.0/8"
},
"next-hops": {
"next-hop": [
{
"config": {
"index": "**10.10.16.254**",
"metric": 200,
"next-hop": "10.10.16.254"
},
"index": "**10.10.16.254**"
},
{
"config": {
"index": "**10.10.17.254**",
"metric": 200,
"next-hop": "10.10.17.254"
},
"index": "**10.10.17.254**"
},
{
"config": {
"index": "**10.10.18.254**",
"metric": 200,
"next-hop": "10.10.18.254"
},
"index": "**10.10.18.254**"
}
]
},
"prefix": "10.0.0.0/8"
},
{
"config": {
"prefix": "10.244.168.0/25",
"set-tag": 9999
},
"next-hops": {
"next-hop": [
{
"config": {
"index": "**openconfig-local-routing:DROP**",
"next-hop": "openconfig-local-routing:DROP"
},
"index": "**openconfig-local-routing:DROP**"
}
]
},
"prefix": "10.244.168.0/25"
},
{
"config": {
"prefix": "172.16.0.0/12"
},
"next-hops": {
"next-hop": [
{
"config": {
"index": "**10.10.16.254**",
"metric": 200,
"next-hop": "10.10.16.254"
},
"index": "**10.10.16.254**"
},
{
"config": {
"index": "**10.10.17.254**",
"metric": 200,
"next-hop": "10.10.17.254"
},
"index": "**10.10.17.254**"
},
{
"config": {
"index": "**10.10.18.254**",
"metric": 200,
"next-hop": "10.10.18.254"
},
"index": "**10.10.18.254**"
}
]
},
"prefix": "172.16.0.0/12"
},
{
"config": {
"prefix": "192.0.2.1/32"
},
"next-hops": {
"next-hop": [
{
"config": {
"index": "**openconfig-local-routing:DROP**",
"next-hop": "openconfig-local-routing:DROP"
},
"index": "**openconfig-local-routing:DROP**"
}
]
},
"prefix": "192.0.2.1/32"
},
{
"config": {
"prefix": "fc00::/128"
},
"next-hops": {
"next-hop": [
{
"config": {
"index": "**openconfig-local-routing:DROP**",
"next-hop": "openconfig-local-routing:DROP"
},
"index": "**openconfig-local-routing:DROP**"
}
]
},
"prefix": "fc00::/128"
}
]
}
}
]
}
},
{
"index": "**10.10.17.254**",
"config": {
"index": "**10.10.17.254**",
"next-hop": "10.10.17.254",
"metric": 200
}
},
{
"index": "**10.10.18.254**",
"config": {
"index": "**10.10.18.254**",
"next-hop": "10.10.18.254",
"metric": 200
}
}
]
}
},
{
"prefix": "10.244.168.0/25",
"config": {
"prefix": "10.244.168.0/25",
"set-tag": 9999
},
"next-hops": {
"next-hop": [
{
"index": "**openconfig-local-routing:DROP**",
"config": {
"index": "**openconfig-local-routing:DROP**",
"next-hop": "openconfig-local-routing:DROP"
}
}
]
}
},
{
"prefix": "172.16.0.0/12",
"config": {
"prefix": "172.16.0.0/12"
},
"next-hops": {
"next-hop": [
{
"index": "**10.10.16.254**",
"config": {
"index": "**10.10.16.254**",
"next-hop": "10.10.16.254",
"metric": 200
}
},
{
"index": "**10.10.17.254**",
"config": {
"index": "**10.10.17.254**",
"next-hop": "10.10.17.254",
"metric": 200
}
},
{
"index": "**10.10.18.254**",
"config": {
"index": "**10.10.18.254**",
"next-hop": "10.10.18.254",
"metric": 200
}
}
]
}
},
{
"prefix": "192.0.2.1/32",
"config": {
"prefix": "192.0.2.1/32"
},
"next-hops": {
"next-hop": [
{
"index": "**openconfig-local-routing:DROP**",
"config": {
"index": "**openconfig-local-routing:DROP**",
"next-hop": "openconfig-local-routing:DROP"
}
}
]
}
},
{
"prefix": "fc00::/128",
"config": {
"prefix": "fc00::/128"
},
"next-hops": {
"next-hop": [
{
"index": "**openconfig-local-routing:DROP**",
"config": {
"index": "**openconfig-local-routing:DROP**",
"next-hop": "openconfig-local-routing:DROP"
}
}
]
}
}
]
}
]
}
}
}

10 changes: 5 additions & 5 deletions ytypes/schema_tests/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ import (
// To debug a schema node subtree, any of the following can be used:
//
// 1. Print hierarchy without details (good for viewing large subtrees):
// fmt.Println(schemaTreeString(oc.SchemaTree["LocalRoutes_Static"], ""))
// fmt.Println(schemaTreeString(oc.SchemaTree["NetworkInstance_Protocol_Static"], ""))
//
// 2. Print in-memory structure representations. Replace is needed due to large
// default util.Indentations:
// fmt.Println(strings.Replace(pretty.Sprint(oc.SchemaTree["LocalRoutes_Static"].Dir["next-hops"].Dir["next-hop"].Dir["config"].Dir["next-hop"])[0:], " ", " ", -1))
// fmt.Println(strings.Replace(pretty.Sprint(oc.SchemaTree["NetworkInstance_Protocol_Static"].Dir["next-hops"].Dir["next-hop"].Dir["config"].Dir["next-hop"])[0:], " ", " ", -1))
//
// 3. Detailed representation in JSON format:
// j, _ := json.MarshalIndent(oc.SchemaTree["LocalRoutes_Static"].Dir["next-hops"].Dir["next-hop"].Dir["config"].Dir["next-hop"], "", " ")
// j, _ := json.MarshalIndent(oc.SchemaTree["NetworkInstance_Protocol_Static"].Dir["next-hops"].Dir["next-hop"].Dir["config"].Dir["next-hop"], "", " ")
// fmt.Println(string(j))
//
// 4. Combination of schema and data trees:
Expand Down Expand Up @@ -511,8 +511,8 @@ func TestValidateBGP(t *testing.T) {

func TestValidateLocalRoutes(t *testing.T) {
// This schema element contains a union of union.
lrs := &oc.LocalRoutes_Static{
NextHop: map[string]*oc.LocalRoutes_Static_NextHop{
lrs := &oc.NetworkInstance_Protocol_Static{
NextHop: map[string]*oc.NetworkInstance_Protocol_Static_NextHop{
"10.10.10.10": {
Index: ygot.String("10.10.10.10"),
NextHop: oc.UnionString("10.10.10.1"),
Expand Down

0 comments on commit 30dd9cb

Please sign in to comment.