-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.go
128 lines (102 loc) · 2.51 KB
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package main
import (
"fmt"
"os"
ygotsrl "steiler/yangtest/generated/srl"
"github.com/openconfig/gnmi/proto/gnmi"
"github.com/openconfig/ygot/ygot"
)
func getActual() *ygotsrl.Device {
config := `{
"interface": [
{
"admin-state": "enable",
"description": "if1",
"name": "ethernet-1/1",
"subinterface": [
{
"index": 1,
"ipv4": {
"address": [
{
"ip-prefix": "192.168.1.1/24"
}
]
}
}
]
},
{
"admin-state": "enable",
"description": "if2",
"name": "ethernet-1/2",
"subinterface": [
{
"index": 1,
"ipv4": {
"address": [
{
"ip-prefix": "192.168.2.1/24"
}
]
}
}
]
}
]
}`
dx := &ygotsrl.Device{}
ygotsrl.Unmarshal([]byte(config), dx)
dx.GetOrCreateNetworkInstance("default")
return dx
}
func appendE150(config *ygotsrl.Device) {
if50, err := createInterfaceWithIP("ethernet-1/50", "myDescription", 55, "192.168.5.2/24")
if err != nil {
panic(err)
}
config.AppendInterface(if50)
}
func loadConfigFromFile(filename string) *ygotsrl.Device {
config, err := os.ReadFile(filename)
if err != nil {
panic(err)
}
dx := &ygotsrl.Device{}
ygotsrl.Unmarshal([]byte(config), dx)
dx.GetOrCreateNetworkInstance("default")
return dx
}
func getSpec() *ygotsrl.Device {
specDevice := &ygotsrl.Device{}
if1 := specDevice.GetOrCreateInterface("ethernet-1/1")
si, err := createSubInterfaceWithIP(5, "192.168.200.200/24")
if err != nil {
panic(err)
}
if1.AppendSubinterface(si)
sif3, err := if1.NewSubinterface(46)
if err != nil {
panic(err)
}
vlan := sif3.GetOrCreateVlan()
enc := vlan.GetOrCreateEncap() //.SingleTagged.VlanId = ygotsrl.UnionUint16(5)
enc.GetOrCreateSingleTagged().VlanId = ygotsrl.UnionUint16(5)
sif3.GetOrCreateIpv4().NewAddress("192.168.5.1/24")
specDevice.GetOrCreateSystem().GetOrCreateSshServer().GetOrCreateNetworkInstance("default").AdminState = ygotsrl.SrlNokiaCommon_AdminState_enable
return specDevice
}
func printGnmiPaths(p []*gnmi.Path) {
for _, rp := range p {
fmt.Println(rp.String())
}
}
func createInterfaceWithIP(name string, description string, subIfIndex uint32, ip string) (*ygotsrl.SrlNokiaInterfaces_Interface, error) {
interf := &ygotsrl.SrlNokiaInterfaces_Interface{Name: ygot.String(name), Description: ygot.String(description)}
suif, err := createSubInterfaceWithIP(subIfIndex, ip)
if err != nil {
return nil, err
}
interf.AppendSubinterface(suif)
return interf, nil
}