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
6d34d130
Commit
6d34d130
authored
2 years ago
by
Malte Bauch
Browse files
Options
Downloads
Patches
Plain Diff
first steps for proof of concept to add route
parent
b1ea6e34
No related branches found
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
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
gnmiserver/model.go
+3
-3
3 additions, 3 deletions
gnmiserver/model.go
os_clients/ubuntu/supportedPaths.go
+37
-17
37 additions, 17 deletions
os_clients/ubuntu/supportedPaths.go
os_clients/ubuntu/ubuntu.go
+45
-26
45 additions, 26 deletions
os_clients/ubuntu/ubuntu.go
with
85 additions
and
46 deletions
gnmiserver/model.go
+
3
−
3
View file @
6d34d130
...
...
@@ -65,9 +65,9 @@ func (m *Model) NewConfigStruct(jsonConfig []byte) (ygot.ValidatedGoStruct, erro
if
err
:=
m
.
jsonUnmarshaler
(
jsonConfig
,
rootStruct
);
err
!=
nil
{
return
nil
,
err
}
if
err
:=
rootStruct
.
ΛValidate
();
err
!=
nil
{
return
nil
,
err
}
//
if err := rootStruct.ΛValidate(); err != nil {
//
return nil, err
//
}
}
return
rootStruct
,
nil
}
...
...
This diff is collapsed.
Click to expand it.
os_clients/ubuntu/supportedPaths.go
+
37
−
17
View file @
6d34d130
...
...
@@ -3,21 +3,23 @@ package ubuntu
import
(
"fmt"
"net"
"syscall"
"code.fbi.h-da.de/danet/gnmi-target/modeldata/gnmitargetygot"
osc
"code.fbi.h-da.de/danet/gnmi-target/os_clients"
"github.com/openconfig/gnmi/proto/gnmi"
"github.com/openconfig/ygot/util"
"github.com/openconfig/ygot/ygot"
"github.com/vishvananda/netlink"
)
var
supportedPaths
=
map
[
string
]
osc
.
PathFunc
{
"/system/config/hostname"
:
func
(
path
*
gnmi
.
Path
,
val
*
gnmi
.
TypedValue
)
error
{
//value, err := value.
ToS
calar(val)
//value, err := value.
tos
calar(val)
//if err != nil {
// return err
//}
//err = syscall.
S
ethostname([]byte(value.(string)))
//err = syscall.
s
ethostname([]byte(value.(string)))
//if err != nil {
// return err
//}
...
...
@@ -71,7 +73,8 @@ var supportedPaths = map[string]osc.PathFunc{
},
}
func
walkThroughConfig
(
config
any
)
error
{
// NOTE: playing around -> don't mind me
func
walkThroughConfig
(
config
ygot
.
ValidatedGoStruct
)
error
{
conf
,
ok
:=
config
.
(
*
gnmitargetygot
.
Gnmitarget
)
if
!
ok
{
return
fmt
.
Errorf
(
"failed type assertion for %T"
,
(
*
gnmitargetygot
.
Gnmitarget
)(
nil
))
...
...
@@ -90,6 +93,17 @@ func walkThroughConfig(config any) error {
}
}
}
if
system
:=
conf
.
System
;
system
!=
nil
{
if
config
:=
system
.
Config
;
config
!=
nil
{
if
hostname
:=
config
.
Hostname
;
hostname
!=
nil
{
err
:=
syscall
.
Sethostname
([]
byte
(
*
hostname
))
if
err
!=
nil
{
return
err
}
}
}
}
if
networkInstances
:=
conf
.
NetworkInstances
;
networkInstances
!=
nil
{
if
networkInstanceMap
:=
networkInstances
.
NetworkInstance
;
networkInstanceMap
!=
nil
{
for
_
,
networkInstance
:=
range
networkInstanceMap
{
...
...
@@ -126,8 +140,7 @@ func generateSubinterface(subintf *gnmitargetygot.OpenconfigInterfaces_Interface
if
!
util
.
IsValueNil
(
addr
.
Config
.
Ip
)
&&
!
util
.
IsValueNil
(
addr
.
Config
.
PrefixLength
)
{
netlinkAddr
:=
&
netlink
.
Addr
{
IPNet
:
&
net
.
IPNet
{
IP
:
net
.
ParseIP
(
*
addr
.
Config
.
Ip
),
// just for testing should come from other path
IP
:
net
.
ParseIP
(
*
addr
.
Config
.
Ip
),
Mask
:
net
.
CIDRMask
(
int
(
*
addr
.
Config
.
PrefixLength
),
32
),
},
}
...
...
@@ -144,8 +157,10 @@ func generateSubinterface(subintf *gnmitargetygot.OpenconfigInterfaces_Interface
}
func
generateProtocol
(
protocol
*
gnmitargetygot
.
OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol
)
error
{
for
_
,
staticRoute
:=
range
protocol
.
StaticRoutes
.
Static
{
staticRoutes
:=
protocol
.
StaticRoutes
for
_
,
staticRoute
:=
range
staticRoutes
.
Static
{
prefix
:=
staticRoute
.
Prefix
for
_
,
hop
:=
range
staticRoute
.
NextHops
.
NextHop
{
link
,
err
:=
netlink
.
LinkByName
(
*
hop
.
InterfaceRef
.
Config
.
Interface
)
if
err
!=
nil
{
...
...
@@ -154,26 +169,31 @@ func generateProtocol(protocol *gnmitargetygot.OpenconfigNetworkInstance_Network
return
err
}
}
source
:=
&
net
.
IPNet
{
IP
:
net
.
IPv4
(
0
,
0
,
0
,
0
),
Mask
:
net
.
CIDRMask
(
32
,
32
),
}
source
:=
net
.
ParseIP
()
dst
:=
&
net
.
IPNet
{
IP
:
net
.
ParseIP
(),
Mask
:
net
.
CIDRMask
(
32
,
32
),
ipnet
,
err
:=
CIDRToIPNet
(
*
prefix
)
if
err
!=
nil
{
return
err
}
route
=
netlink
.
Route
{
LinkIndex
:
link
.
Attrs
()
.
Index
,
Dst
:
dst
,
Src
:
source
}
nextHop
:=
net
.
ParseIP
(
hop
.
GetConfig
()
.
GetIndex
())
route
:=
netlink
.
Route
{
LinkIndex
:
link
.
Attrs
()
.
Index
,
Dst
:
ipnet
,
Src
:
nextHop
}
netlink
.
RouteAdd
(
&
route
)
}
}
return
nil
}
func
CIDRToIPNet
(
s
string
)
(
*
net
.
IPNet
,
error
)
{
ip
,
ipnet
,
err
:=
net
.
ParseCIDR
(
s
)
if
err
!=
nil
{
return
nil
,
err
}
ipnet
.
IP
=
ip
return
ipnet
,
nil
}
func
filterKeys
(
path
*
gnmi
.
Path
)
[]
map
[
string
]
string
{
keyMap
:=
make
([]
map
[
string
]
string
,
0
)
for
_
,
p
:=
range
path
.
GetElem
()
{
...
...
This diff is collapsed.
Click to expand it.
os_clients/ubuntu/ubuntu.go
+
45
−
26
View file @
6d34d130
package
ubuntu
import
(
"fmt"
"net"
"os"
"os/exec"
...
...
@@ -52,6 +51,8 @@ func (ou *OsclientUbuntu) GetConfig() *gnmitargetygot.Gnmitarget {
ou
.
getSystem
(
ou
.
gt
)
ou
.
getStaticRoutes
(
ou
.
gt
)
return
ou
.
gt
}
...
...
@@ -63,32 +64,33 @@ func (ou *OsclientUbuntu) callbackFunc(config ygot.ValidatedGoStruct) error {
//opts := []ygot.DiffOpt{
// &ygot.DiffPathOpt{MapToSinglePath: true},
//}
diffs
,
err
:=
ygot
.
Diff
(
ou
.
GetConfig
(),
config
)
if
err
!=
nil
{
return
err
}
//
diffs, err := ygot.Diff(ou.GetConfig(), config)
//
if err != nil {
//
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
()
{
schemaPath
,
err
:=
ygot
.
PathToSchemaPath
(
diff
.
GetPath
())
if
err
!=
nil
{
return
err
}
if
fn
,
found
:=
ou
.
pm
[
schemaPath
];
found
{
if
err
:=
fn
(
diff
.
GetPath
(),
diff
.
GetVal
());
err
!=
nil
{
return
err
}
}
else
{
//ignore all other paths for now
return
fmt
.
Errorf
(
"the path: %s is not supported"
,
schemaPath
)
}
}
//for _, path := range diffs.GetDelete() {
// stringPath, err := ygot.PathToString(path)
// if err != nil {
// return err
// }
// fmt.Println("PathToDelete: ", stringPath)
//}
//for _, diff := range diffs.GetUpdate() {
// schemaPath, err := ygot.PathToSchemaPath(diff.GetPath())
// if err != nil {
// return err
// }
// if fn, found := ou.pm[schemaPath]; found {
// if err := fn(diff.GetPath(), diff.GetVal()); err != nil {
// return err
// }
// } else {
// //ignore all other paths for now
// return fmt.Errorf("the path: %s is not supported", schemaPath)
// }
//}
walkThroughConfig
(
config
)
return
nil
}
...
...
@@ -226,6 +228,23 @@ func (ou *OsclientUbuntu) getSystem(gt *gnmitargetygot.Gnmitarget) {
}
}
func
(
ou
*
OsclientUbuntu
)
getStaticRoutes
(
gt
*
gnmitargetygot
.
Gnmitarget
)
{
networkInstances
:=
gt
.
GetOrCreateNetworkInstances
()
defaultNetworkInstance
:=
networkInstances
.
GetOrCreateNetworkInstance
(
"default"
)
defaultProtocols
:=
defaultNetworkInstance
.
GetOrCreateProtocols
()
defaultProtocol
:=
defaultProtocols
.
GetOrCreateProtocol
(
gnmitargetygot
.
OpenconfigPolicyTypes_INSTALL_PROTOCOL_TYPE_DIRECTLY_CONNECTED
,
"DIRECTLY_CONNECTED"
)
defaultProtocolStaticRoutes
:=
defaultProtocol
.
GetOrCreateStaticRoutes
()
defaultProtocolStaticRoute
:=
defaultProtocolStaticRoutes
.
GetOrCreateStatic
(
"10.10.10.1/24"
)
defaultNextHops
:=
defaultProtocolStaticRoute
.
GetOrCreateNextHops
()
defaultNextHop
:=
defaultNextHops
.
GetOrCreateNextHop
(
"AUTO_1_10-0-0-1"
)
defaultInterfaceRef
:=
defaultNextHop
.
GetOrCreateInterfaceRef
()
defaultInterfaceRefConf
:=
defaultInterfaceRef
.
GetOrCreateConfig
()
defaultInterfaceRefConf
.
Interface
=
ygot
.
String
(
"eth0"
)
}
//TODO: this will be removed in the near future
//func (ou OsclientUbuntu) TestUbuntu() {
// ou.gt = &gnmitargetygot.Gnmitarget{}
...
...
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