Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
goSDN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
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
Terraform modules
Analyze
Contributor analytics
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
goSDN
Commits
8f01fc9c
Commit
8f01fc9c
authored
4 years ago
by
Manuel Kieweg
Browse files
Options
Downloads
Patches
Plain Diff
pnd adapter skeleton
parent
79d7afb0
No related branches found
No related tags found
1 merge request
!168
pnd adapter skeleton
Pipeline
#75842
passed
4 years ago
Stage: test
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
api/apiIntegration_test.go
+7
-5
7 additions, 5 deletions
api/apiIntegration_test.go
api/api_test.go
+5
-5
5 additions, 5 deletions
api/api_test.go
api/grpc.go
+1
-172
1 addition, 172 deletions
api/grpc.go
api/pnd.go
+260
-0
260 additions, 0 deletions
api/pnd.go
with
273 additions
and
182 deletions
api/apiIntegration_test.go
+
7
−
5
View file @
8f01fc9c
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"os"
"os"
"testing"
"testing"
"code.fbi.h-da.de/cocsn/api/go/gosdn/pnd"
tpb
"code.fbi.h-da.de/cocsn/api/go/gosdn/transport"
tpb
"code.fbi.h-da.de/cocsn/api/go/gosdn/transport"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/util/proto"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/util/proto"
guuid
"github.com/google/uuid"
guuid
"github.com/google/uuid"
...
@@ -110,7 +111,7 @@ func TestApiIntegration(t *testing.T) {
...
@@ -110,7 +111,7 @@ func TestApiIntegration(t *testing.T) {
cliPnd
:=
viper
.
GetString
(
"CLI_PND"
)
cliPnd
:=
viper
.
GetString
(
"CLI_PND"
)
cliSbi
:=
viper
.
GetString
(
"CLI_SBI"
)
cliSbi
:=
viper
.
GetString
(
"CLI_SBI"
)
if
_
,
err
:=
A
ddDevice
(
if
_
,
err
:=
a
ddDevice
(
testAPIEndpoint
,
testAPIEndpoint
,
testUsername
,
testUsername
,
testPassword
,
testPassword
,
...
@@ -124,7 +125,7 @@ func TestApiIntegration(t *testing.T) {
...
@@ -124,7 +125,7 @@ func TestApiIntegration(t *testing.T) {
}
}
did
:=
viper
.
GetString
(
"LAST_DEVICE_UUID"
)
did
:=
viper
.
GetString
(
"LAST_DEVICE_UUID"
)
_
,
err
:=
G
etDevice
(
_
,
err
:=
g
etDevice
(
testAPIEndpoint
,
testAPIEndpoint
,
cliPnd
,
cliPnd
,
testPath
,
testPath
,
...
@@ -135,7 +136,7 @@ func TestApiIntegration(t *testing.T) {
...
@@ -135,7 +136,7 @@ func TestApiIntegration(t *testing.T) {
return
return
}
}
_
,
err
=
G
etDevice
(
_
,
err
=
g
etDevice
(
testAPIEndpoint
,
testAPIEndpoint
,
cliPnd
,
cliPnd
,
""
,
""
,
...
@@ -147,19 +148,20 @@ func TestApiIntegration(t *testing.T) {
...
@@ -147,19 +148,20 @@ func TestApiIntegration(t *testing.T) {
}
}
hostname
:=
guuid
.
New
()
.
String
()
hostname
:=
guuid
.
New
()
.
String
()
_
,
err
=
Update
(
_
,
err
=
changeRequest
(
testAPIEndpoint
,
testAPIEndpoint
,
did
,
did
,
cliPnd
,
cliPnd
,
testPath
,
testPath
,
hostname
,
hostname
,
pnd
.
ApiOperation_UPDATE
,
)
)
if
(
err
!=
nil
)
!=
tt
.
wantErr
{
if
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"gosdn cli set error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
t
.
Errorf
(
"gosdn cli set error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
return
return
}
}
resp
,
err
:=
G
etDevice
(
testAddress
,
testUsername
,
testPassword
,
testPath
)
resp
,
err
:=
g
etDevice
(
testAddress
,
testUsername
,
testPassword
,
testPath
)
if
err
!=
nil
{
if
err
!=
nil
{
if
!
tt
.
wantErr
{
if
!
tt
.
wantErr
{
t
.
Errorf
(
"Get() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
t
.
Errorf
(
"Get() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
...
...
This diff is collapsed.
Click to expand it.
api/
grpc
_test.go
→
api/
api
_test.go
+
5
−
5
View file @
8f01fc9c
...
@@ -154,7 +154,7 @@ func Test_CommitConfirm(t *testing.T) {
...
@@ -154,7 +154,7 @@ func Test_CommitConfirm(t *testing.T) {
}
}
func
Test_AddDevice
(
t
*
testing
.
T
)
{
func
Test_AddDevice
(
t
*
testing
.
T
)
{
resp
,
err
:=
A
ddDevice
(
bufnet
,
"test"
,
"test"
,
sbiID
,
pndID
,
"test"
,
"test"
)
resp
,
err
:=
a
ddDevice
(
bufnet
,
"test"
,
"test"
,
sbiID
,
pndID
,
"test"
,
"test"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
(
err
)
t
.
Error
(
err
)
return
return
...
@@ -163,7 +163,7 @@ func Test_AddDevice(t *testing.T) {
...
@@ -163,7 +163,7 @@ func Test_AddDevice(t *testing.T) {
}
}
func
Test_GetDevice
(
t
*
testing
.
T
)
{
func
Test_GetDevice
(
t
*
testing
.
T
)
{
resp
,
err
:=
G
etDevice
(
bufnet
,
pndID
,
""
,
ondID
)
resp
,
err
:=
g
etDevice
(
bufnet
,
pndID
,
""
,
ondID
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
(
err
)
t
.
Error
(
err
)
return
return
...
@@ -175,7 +175,7 @@ func Test_GetDevice(t *testing.T) {
...
@@ -175,7 +175,7 @@ func Test_GetDevice(t *testing.T) {
}
}
func
Test_Update
(
t
*
testing
.
T
)
{
func
Test_Update
(
t
*
testing
.
T
)
{
resp
,
err
:=
Update
(
bufnet
,
ondID
,
pndID
,
""
,
""
)
resp
,
err
:=
changeRequest
(
bufnet
,
ondID
,
pndID
,
""
,
""
,
ppb
.
ApiOperation_UPDATE
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
(
err
)
t
.
Error
(
err
)
return
return
...
@@ -184,7 +184,7 @@ func Test_Update(t *testing.T) {
...
@@ -184,7 +184,7 @@ func Test_Update(t *testing.T) {
}
}
func
Test_Replace
(
t
*
testing
.
T
)
{
func
Test_Replace
(
t
*
testing
.
T
)
{
resp
,
err
:=
Replace
(
bufnet
,
ondID
,
pndID
,
""
,
""
)
resp
,
err
:=
changeRequest
(
bufnet
,
ondID
,
pndID
,
""
,
""
,
ppb
.
ApiOperation_REPLACE
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
(
err
)
t
.
Error
(
err
)
return
return
...
@@ -193,7 +193,7 @@ func Test_Replace(t *testing.T) {
...
@@ -193,7 +193,7 @@ func Test_Replace(t *testing.T) {
}
}
func
Test_Delete
(
t
*
testing
.
T
)
{
func
Test_Delete
(
t
*
testing
.
T
)
{
resp
,
err
:=
Delete
(
bufnet
,
ondID
,
pndID
,
""
)
resp
,
err
:=
changeRequest
(
bufnet
,
ondID
,
pndID
,
""
,
""
,
ppb
.
ApiOperation_DELETE
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
(
err
)
t
.
Error
(
err
)
return
return
...
...
This diff is collapsed.
Click to expand it.
api/grpc.go
+
1
−
172
View file @
8f01fc9c
...
@@ -5,14 +5,12 @@ import (
...
@@ -5,14 +5,12 @@ import (
"errors"
"errors"
"time"
"time"
pb
"code.fbi.h-da.de/cocsn/api/go/gosdn/core"
ppb
"code.fbi.h-da.de/cocsn/api/go/gosdn/pnd"
ppb
"code.fbi.h-da.de/cocsn/api/go/gosdn/pnd"
spb
"code.fbi.h-da.de/cocsn/api/go/gosdn/southbound"
tpb
"code.fbi.h-da.de/cocsn/api/go/gosdn/transport"
nbi
"code.fbi.h-da.de/cocsn/gosdn/northbound/client"
nbi
"code.fbi.h-da.de/cocsn/gosdn/northbound/client"
log
"github.com/sirupsen/logrus"
log
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
"github.com/spf13/viper"
pb
"code.fbi.h-da.de/cocsn/api/go/gosdn/core"
"google.golang.org/grpc"
"google.golang.org/grpc"
)
)
...
@@ -106,172 +104,3 @@ func GetPnd(addr string, args ...string) (*pb.GetResponse, error) {
...
@@ -106,172 +104,3 @@ func GetPnd(addr string, args ...string) (*pb.GetResponse, error) {
}
}
return
coreClient
.
Get
(
ctx
,
req
)
return
coreClient
.
Get
(
ctx
,
req
)
}
}
// GetChanges requests all pending and unconfirmed changes from the controller
func
GetChanges
(
addr
,
pnd
string
)
(
*
ppb
.
GetResponse
,
error
)
{
ctx
:=
context
.
Background
()
client
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
if
err
!=
nil
{
return
nil
,
err
}
req
:=
&
ppb
.
GetRequest
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Request
:
&
ppb
.
GetRequest_Change
{
Change
:
&
ppb
.
GetChange
{
All
:
true
,
},
},
Pid
:
pnd
,
}
return
client
.
Get
(
ctx
,
req
)
}
// Commit sends a commit request for one or multiple changes to the
// controller.
func
Commit
(
addr
,
pnd
string
,
cuids
...
string
)
(
*
ppb
.
SetResponse
,
error
)
{
changes
:=
make
([]
*
ppb
.
SetChange
,
len
(
cuids
))
for
i
,
arg
:=
range
cuids
{
changes
[
i
]
=
&
ppb
.
SetChange
{
Cuid
:
arg
,
Op
:
ppb
.
SetChange_COMMIT
,
}
}
return
commitConfirm
(
addr
,
pnd
,
changes
)
}
// Confirm sends a confirm request for one or multiple changes to the
// controller
func
Confirm
(
addr
,
pnd
string
,
cuids
...
string
)
(
*
ppb
.
SetResponse
,
error
)
{
changes
:=
make
([]
*
ppb
.
SetChange
,
len
(
cuids
))
for
i
,
arg
:=
range
cuids
{
changes
[
i
]
=
&
ppb
.
SetChange
{
Cuid
:
arg
,
Op
:
ppb
.
SetChange_CONFIRM
,
}
}
return
commitConfirm
(
addr
,
pnd
,
changes
)
}
func
commitConfirm
(
addr
,
pnd
string
,
changes
[]
*
ppb
.
SetChange
)
(
*
ppb
.
SetResponse
,
error
)
{
ctx
:=
context
.
Background
()
client
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
if
err
!=
nil
{
return
nil
,
err
}
req
:=
&
ppb
.
SetRequest
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Change
:
changes
,
Pid
:
pnd
,
}
return
client
.
Set
(
ctx
,
req
)
}
// AddDevice adds a new device to the controller. The device name is optional.
// If no name is provided a name will be generated upon device creation.
func
AddDevice
(
addr
,
username
,
password
,
sbi
,
pnd
,
deviceAddress
,
deviceName
string
)
(
*
ppb
.
SetResponse
,
error
)
{
pndClient
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
if
err
!=
nil
{
return
nil
,
err
}
req
:=
&
ppb
.
SetRequest
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Ond
:
[]
*
ppb
.
SetOnd
{
{
Address
:
deviceAddress
,
Sbi
:
&
spb
.
SouthboundInterface
{
Id
:
sbi
,
},
DeviceName
:
deviceName
,
TransportOption
:
&
tpb
.
TransportOption
{
Address
:
addr
,
Username
:
username
,
Password
:
password
,
TransportOption
:
&
tpb
.
TransportOption_GnmiTransportOption
{
GnmiTransportOption
:
&
tpb
.
GnmiTransportOption
{},
},
},
},
},
Pid
:
pnd
,
}
ctx
:=
context
.
Background
()
return
pndClient
.
Set
(
ctx
,
req
)
}
// GetDevice requests one or multiple devices belonging to a given
// PrincipalNetworkDomain from the controller. If no device identifier
// is provided, all devices are requested.
func
GetDevice
(
addr
,
pid
,
path
string
,
did
...
string
)
(
*
ppb
.
GetResponse
,
error
)
{
pndClient
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
if
err
!=
nil
{
return
nil
,
err
}
var
all
bool
if
len
(
did
)
==
0
{
all
=
true
}
req
:=
&
ppb
.
GetRequest
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Request
:
&
ppb
.
GetRequest_Ond
{
Ond
:
&
ppb
.
GetOnd
{
All
:
all
,
Did
:
did
,
},
},
Pid
:
pid
,
}
ctx
:=
context
.
Background
()
return
pndClient
.
Get
(
ctx
,
req
)
}
// Update creates a ChangeRequest to update the given path with the given value
// at the given OND on the controller.
func
Update
(
addr
,
did
,
pid
,
path
,
value
string
)
(
*
ppb
.
SetResponse
,
error
)
{
req
:=
&
ppb
.
ChangeRequest
{
Id
:
did
,
Path
:
path
,
Value
:
value
,
ApiOp
:
ppb
.
ApiOperation_UPDATE
,
}
return
sendChangeRequest
(
addr
,
pid
,
req
)
}
// Replace creates a ChangeRequest to replace the given path with the given value
// at the given OND on the controller.
func
Replace
(
addr
,
did
,
pid
,
path
,
value
string
)
(
*
ppb
.
SetResponse
,
error
)
{
req
:=
&
ppb
.
ChangeRequest
{
Id
:
did
,
Path
:
path
,
Value
:
value
,
ApiOp
:
ppb
.
ApiOperation_REPLACE
,
}
return
sendChangeRequest
(
addr
,
pid
,
req
)
}
// Delete creates a ChangeRequest to delete the given path node
// at the given OND on the controller.
func
Delete
(
addr
,
did
,
pid
,
path
string
)
(
*
ppb
.
SetResponse
,
error
)
{
req
:=
&
ppb
.
ChangeRequest
{
Id
:
did
,
Path
:
path
,
ApiOp
:
ppb
.
ApiOperation_DELETE
,
}
return
sendChangeRequest
(
addr
,
pid
,
req
)
}
func
sendChangeRequest
(
addr
,
pid
string
,
req
*
ppb
.
ChangeRequest
)
(
*
ppb
.
SetResponse
,
error
)
{
pndClient
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
if
err
!=
nil
{
return
nil
,
err
}
ctx
:=
context
.
Background
()
r
:=
&
ppb
.
SetRequest
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
ChangeRequest
:
[]
*
ppb
.
ChangeRequest
{
req
},
Pid
:
pid
,
}
return
pndClient
.
Set
(
ctx
,
r
)
}
This diff is collapsed.
Click to expand it.
api/pnd.go
0 → 100644
+
260
−
0
View file @
8f01fc9c
package
api
import
(
"context"
"time"
ppb
"code.fbi.h-da.de/cocsn/api/go/gosdn/pnd"
spb
"code.fbi.h-da.de/cocsn/api/go/gosdn/southbound"
tpb
"code.fbi.h-da.de/cocsn/api/go/gosdn/transport"
"code.fbi.h-da.de/cocsn/gosdn/interfaces/change"
"code.fbi.h-da.de/cocsn/gosdn/interfaces/device"
"code.fbi.h-da.de/cocsn/gosdn/interfaces/southbound"
"code.fbi.h-da.de/cocsn/gosdn/interfaces/store"
nbi
"code.fbi.h-da.de/cocsn/gosdn/northbound/client"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/errors"
"github.com/google/uuid"
)
type
PrincipalNetworkDomainAdapter
struct
{
id
uuid
.
UUID
endpoint
string
}
func
(
p
*
PrincipalNetworkDomainAdapter
)
Destroy
()
error
{
return
&
errors
.
ErrNotYetImplemented
{}
}
func
(
p
*
PrincipalNetworkDomainAdapter
)
AddSbi
(
s
southbound
.
SouthboundInterface
)
error
{
return
&
errors
.
ErrNotYetImplemented
{}
}
func
(
p
*
PrincipalNetworkDomainAdapter
)
RemoveSbi
(
uuid
.
UUID
)
error
{
return
&
errors
.
ErrNotYetImplemented
{}
}
func
(
p
*
PrincipalNetworkDomainAdapter
)
AddDevice
(
name
string
,
opts
*
tpb
.
TransportOption
,
sid
uuid
.
UUID
)
error
{
return
&
errors
.
ErrNotYetImplemented
{}
}
func
(
p
*
PrincipalNetworkDomainAdapter
)
GetDevice
(
identifier
string
)
(
device
.
Device
,
error
)
{
return
nil
,
&
errors
.
ErrNotYetImplemented
{}
}
func
(
p
*
PrincipalNetworkDomainAdapter
)
RemoveDevice
(
uuid
.
UUID
)
error
{
return
&
errors
.
ErrNotYetImplemented
{}
}
func
(
p
*
PrincipalNetworkDomainAdapter
)
Devices
()
[]
uuid
.
UUID
{
return
nil
}
func
(
p
*
PrincipalNetworkDomainAdapter
)
ChangeOND
(
uuid
uuid
.
UUID
,
operation
ppb
.
ApiOperation
,
path
string
,
value
...
string
)
error
{
return
&
errors
.
ErrNotYetImplemented
{}
}
func
(
p
*
PrincipalNetworkDomainAdapter
)
Request
(
uuid
.
UUID
,
string
)
error
{
return
&
errors
.
ErrNotYetImplemented
{}
}
func
(
p
*
PrincipalNetworkDomainAdapter
)
RequestAll
(
string
)
error
{
return
&
errors
.
ErrNotYetImplemented
{}
}
func
(
p
*
PrincipalNetworkDomainAdapter
)
GetName
()
string
{
return
""
}
func
(
p
*
PrincipalNetworkDomainAdapter
)
GetDescription
()
string
{
return
""
}
func
(
p
*
PrincipalNetworkDomainAdapter
)
MarshalDevice
(
string
)
(
string
,
error
)
{
return
""
,
&
errors
.
ErrNotYetImplemented
{}
}
func
(
p
*
PrincipalNetworkDomainAdapter
)
ContainsDevice
(
uuid
.
UUID
)
bool
{
return
false
}
func
(
p
*
PrincipalNetworkDomainAdapter
)
GetSBIs
()
store
.
Store
{
return
nil
}
func
(
p
*
PrincipalNetworkDomainAdapter
)
ID
()
uuid
.
UUID
{
return
p
.
id
}
func
(
p
*
PrincipalNetworkDomainAdapter
)
PendingChanges
()
[]
uuid
.
UUID
{
return
nil
}
func
(
p
*
PrincipalNetworkDomainAdapter
)
CommittedChanges
()
[]
uuid
.
UUID
{
return
nil
}
func
(
p
*
PrincipalNetworkDomainAdapter
)
GetChange
(
uuid
.
UUID
,
...
int
)
(
change
.
Change
,
error
)
{
return
nil
,
&
errors
.
ErrNotYetImplemented
{}
}
func
(
p
*
PrincipalNetworkDomainAdapter
)
Commit
(
uuid
.
UUID
)
error
{
return
&
errors
.
ErrNotYetImplemented
{}
}
func
(
p
*
PrincipalNetworkDomainAdapter
)
Confirm
(
uuid
.
UUID
)
error
{
return
&
errors
.
ErrNotYetImplemented
{}
}
// GetChanges requests all pending and unconfirmed changes from the controller
func
GetChanges
(
addr
,
pnd
string
)
(
*
ppb
.
GetResponse
,
error
)
{
ctx
:=
context
.
Background
()
client
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
if
err
!=
nil
{
return
nil
,
err
}
req
:=
&
ppb
.
GetRequest
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Request
:
&
ppb
.
GetRequest_Change
{
Change
:
&
ppb
.
GetChange
{
All
:
true
,
},
},
Pid
:
pnd
,
}
return
client
.
Get
(
ctx
,
req
)
}
// Commit sends a commit request for one or multiple changes to the
// controller.
func
Commit
(
addr
,
pnd
string
,
cuids
...
string
)
(
*
ppb
.
SetResponse
,
error
)
{
changes
:=
make
([]
*
ppb
.
SetChange
,
len
(
cuids
))
for
i
,
arg
:=
range
cuids
{
changes
[
i
]
=
&
ppb
.
SetChange
{
Cuid
:
arg
,
Op
:
ppb
.
SetChange_COMMIT
,
}
}
return
commitConfirm
(
addr
,
pnd
,
changes
)
}
// Confirm sends a confirm request for one or multiple changes to the
// controller
func
Confirm
(
addr
,
pnd
string
,
cuids
...
string
)
(
*
ppb
.
SetResponse
,
error
)
{
changes
:=
make
([]
*
ppb
.
SetChange
,
len
(
cuids
))
for
i
,
arg
:=
range
cuids
{
changes
[
i
]
=
&
ppb
.
SetChange
{
Cuid
:
arg
,
Op
:
ppb
.
SetChange_CONFIRM
,
}
}
return
commitConfirm
(
addr
,
pnd
,
changes
)
}
func
commitConfirm
(
addr
,
pnd
string
,
changes
[]
*
ppb
.
SetChange
)
(
*
ppb
.
SetResponse
,
error
)
{
ctx
:=
context
.
Background
()
client
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
if
err
!=
nil
{
return
nil
,
err
}
req
:=
&
ppb
.
SetRequest
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Change
:
changes
,
Pid
:
pnd
,
}
return
client
.
Set
(
ctx
,
req
)
}
// addDevice adds a new device to the controller. The device name is optional.
// If no name is provided a name will be generated upon device creation.
func
addDevice
(
addr
,
username
,
password
,
sbi
,
pnd
,
deviceAddress
,
deviceName
string
)
(
*
ppb
.
SetResponse
,
error
)
{
pndClient
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
if
err
!=
nil
{
return
nil
,
err
}
req
:=
&
ppb
.
SetRequest
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Ond
:
[]
*
ppb
.
SetOnd
{
{
Address
:
deviceAddress
,
Sbi
:
&
spb
.
SouthboundInterface
{
Id
:
sbi
,
},
DeviceName
:
deviceName
,
TransportOption
:
&
tpb
.
TransportOption
{
Address
:
deviceAddress
,
Username
:
username
,
Password
:
password
,
TransportOption
:
&
tpb
.
TransportOption_GnmiTransportOption
{
GnmiTransportOption
:
&
tpb
.
GnmiTransportOption
{},
},
},
},
},
Pid
:
pnd
,
}
if
sbi
==
"csbi"
{
req
.
Ond
[
0
]
.
Sbi
.
Id
=
uuid
.
Nil
.
String
()
req
.
Ond
[
0
]
.
Sbi
.
Type
=
spb
.
Type_CONTAINERISED
req
.
Ond
[
0
]
.
TransportOption
.
Csbi
=
true
}
ctx
:=
context
.
Background
()
return
pndClient
.
Set
(
ctx
,
req
)
}
// getDevice requests one or multiple devices belonging to a given
// PrincipalNetworkDomain from the controller. If no device identifier
// is provided, all devices are requested.
func
getDevice
(
addr
,
pid
,
path
string
,
did
...
string
)
(
*
ppb
.
GetResponse
,
error
)
{
pndClient
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
if
err
!=
nil
{
return
nil
,
err
}
var
all
bool
if
len
(
did
)
==
0
{
all
=
true
}
req
:=
&
ppb
.
GetRequest
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Request
:
&
ppb
.
GetRequest_Ond
{
Ond
:
&
ppb
.
GetOnd
{
All
:
all
,
Did
:
did
,
},
},
Pid
:
pid
,
}
ctx
:=
context
.
Background
()
return
pndClient
.
Get
(
ctx
,
req
)
}
// change creates a ChangeRequest for the specified OND. ApiOperations are
// used to specify the type of the change (update, replace, delete as specified
// in https://github.com/openconfig/reference/blob/master/rpc/gnmi/gnmi-specification.md#34-modifying-state)
// For delete operations the value field needs to contain an empty string.
func
changeRequest
(
addr
,
did
,
pid
,
path
,
value
string
,
op
ppb
.
ApiOperation
)
(
*
ppb
.
SetResponse
,
error
)
{
req
:=
&
ppb
.
ChangeRequest
{
Id
:
did
,
Path
:
path
,
Value
:
value
,
ApiOp
:
op
,
}
return
sendChangeRequest
(
addr
,
pid
,
req
)
}
func
sendChangeRequest
(
addr
,
pid
string
,
req
*
ppb
.
ChangeRequest
)
(
*
ppb
.
SetResponse
,
error
)
{
pndClient
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
if
err
!=
nil
{
return
nil
,
err
}
ctx
:=
context
.
Background
()
r
:=
&
ppb
.
SetRequest
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
ChangeRequest
:
[]
*
ppb
.
ChangeRequest
{
req
},
Pid
:
pid
,
}
return
pndClient
.
Set
(
ctx
,
r
)
}
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