Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
gNMI Target
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
danet
gNMI Target
Commits
03968a97
Commit
03968a97
authored
3 years ago
by
Malte Bauch
Browse files
Options
Downloads
Patches
Plain Diff
WIP
parent
585bb2d6
Branches
Branches containing commit
No related tags found
4 merge requests
!17
Build basic ci
,
!10
Add simple modem support on linux through modemmanager
,
!8
General refactoring
,
!5
Draft: Add basic set support for ip/routing via gnmi
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
os_clients/ubuntu/supportedPaths.go
+57
-6
57 additions, 6 deletions
os_clients/ubuntu/supportedPaths.go
os_clients/ubuntu/ubuntu.go
+12
-0
12 additions, 0 deletions
os_clients/ubuntu/ubuntu.go
with
69 additions
and
6 deletions
os_clients/ubuntu/supportedPaths.go
+
57
−
6
View file @
03968a97
package
ubuntu
package
ubuntu
import
(
import
(
"syscall"
"fmt"
"net"
osc
"code.fbi.h-da.de/danet/gnmi-target/os_clients"
osc
"code.fbi.h-da.de/danet/gnmi-target/os_clients"
"github.com/openconfig/gnmi/proto/gnmi"
"github.com/openconfig/gnmi/proto/gnmi"
"github.com/
openconfig/gnmi/value
"
"github.com/
vishvananda/netlink
"
)
)
var
supportedPaths
=
map
[
string
]
osc
.
PathFunc
{
var
supportedPaths
=
map
[
string
]
osc
.
PathFunc
{
"/system/config/hostname"
:
func
(
path
*
gnmi
.
Path
,
val
*
gnmi
.
TypedValue
)
error
{
"/system/config/hostname"
:
func
(
path
*
gnmi
.
Path
,
val
*
gnmi
.
TypedValue
)
error
{
value
,
err
:=
value
.
ToScalar
(
val
)
//value, err := value.ToScalar(val)
if
err
!=
nil
{
//if err != nil {
return
err
// return err
//}
//err = syscall.Sethostname([]byte(value.(string)))
//if err != nil {
// return err
//}
return
nil
},
"/interfaces/interface/subinterfaces/subinterface/ipv4/addresses/address/ip"
:
func
(
path
*
gnmi
.
Path
,
val
*
gnmi
.
TypedValue
)
error
{
//NOTE: this is just for testing purpose. Normally the information from
// different paths should be combined
keys
:=
filterKeys
(
path
)
linkName
,
ok
:=
keys
[
0
][
"name"
]
if
!
ok
{
return
fmt
.
Errorf
(
"internal error: no interface key has been provided within path:"
)
}
}
err
=
syscall
.
Sethostname
([]
byte
(
value
.
(
string
)))
link
,
err
:=
netlink
.
LinkByName
(
linkName
)
if
err
!=
nil
{
if
err
!=
nil
{
_
,
ok
:=
err
.
(
netlink
.
LinkNotFoundError
)
if
!
ok
{
return
err
}
link
=
&
netlink
.
Dummy
{
LinkAttrs
:
netlink
.
LinkAttrs
{
Flags
:
net
.
FlagUp
,
Name
:
linkName
,
},
}
}
addr
:=
&
netlink
.
Addr
{
IPNet
:
&
net
.
IPNet
{
IP
:
net
.
ParseIP
(
val
.
GetStringVal
()),
// just for testing should come from other path
Mask
:
net
.
CIDRMask
(
24
,
32
),
},
}
if
err
:=
netlink
.
AddrAdd
(
link
,
addr
);
err
!=
nil
{
fmt
.
Println
(
"adding the address has failed: "
,
err
)
return
err
return
err
}
}
return
nil
return
nil
},
},
"/interfaces/interface/name"
:
func
(
path
*
gnmi
.
Path
,
val
*
gnmi
.
TypedValue
)
error
{
"/interfaces/interface/name"
:
func
(
path
*
gnmi
.
Path
,
val
*
gnmi
.
TypedValue
)
error
{
fmt
.
Printf
(
"we were in: %s"
,
"/interfaces/interface/name"
)
return
nil
return
nil
},
},
}
}
func
filterKeys
(
path
*
gnmi
.
Path
)
[]
map
[
string
]
string
{
keyMap
:=
make
([]
map
[
string
]
string
,
0
)
for
_
,
p
:=
range
path
.
GetElem
()
{
if
key
:=
p
.
GetKey
();
key
!=
nil
{
keyMap
=
append
(
keyMap
,
key
)
}
}
return
keyMap
}
This diff is collapsed.
Click to expand it.
os_clients/ubuntu/ubuntu.go
+
12
−
0
View file @
03968a97
package
ubuntu
package
ubuntu
import
(
import
(
"fmt"
"net"
"net"
"os"
"os"
"os/exec"
"os/exec"
...
@@ -59,10 +60,21 @@ func (ou *OsclientUbuntu) GetCallbackFunc() func(ygot.ValidatedGoStruct) error {
...
@@ -59,10 +60,21 @@ func (ou *OsclientUbuntu) GetCallbackFunc() func(ygot.ValidatedGoStruct) error {
}
}
func
(
ou
*
OsclientUbuntu
)
callbackFunc
(
config
ygot
.
ValidatedGoStruct
)
error
{
func
(
ou
*
OsclientUbuntu
)
callbackFunc
(
config
ygot
.
ValidatedGoStruct
)
error
{
//opts := []ygot.DiffOpt{
// &ygot.DiffPathOpt{MapToSinglePath: true},
//}
diffs
,
err
:=
ygot
.
Diff
(
ou
.
GetConfig
(),
config
)
diffs
,
err
:=
ygot
.
Diff
(
ou
.
GetConfig
(),
config
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
for
_
,
path
:=
range
diffs
.
GetDelete
()
{
stringPath
,
err
:=
ygot
.
PathToString
(
path
)
if
err
!=
nil
{
return
err
}
fmt
.
Println
(
"PathToDelete: "
,
stringPath
)
}
for
_
,
diff
:=
range
diffs
.
GetUpdate
()
{
for
_
,
diff
:=
range
diffs
.
GetUpdate
()
{
schemaPath
,
err
:=
ygot
.
PathToSchemaPath
(
diff
.
GetPath
())
schemaPath
,
err
:=
ygot
.
PathToSchemaPath
(
diff
.
GetPath
())
if
err
!=
nil
{
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment