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
82d5eb42
Commit
82d5eb42
authored
3 years ago
by
Fabian Seidl
Committed by
Fabian Seidl
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
updated api/grpc according to other api changes
parent
f2e745bb
No related branches found
No related tags found
1 merge request
!238
Stfaseid http refactor
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/grpc.go
+87
-72
87 additions, 72 deletions
api/grpc.go
with
87 additions
and
72 deletions
api/grpc.go
+
87
−
72
View file @
82d5eb42
...
@@ -36,11 +36,11 @@ func Init(addr string) error {
...
@@ -36,11 +36,11 @@ func Init(addr string) error {
pid
:=
resp
.
Pnd
[
0
]
.
Id
pid
:=
resp
.
Pnd
[
0
]
.
Id
viper
.
Set
(
"CLI_PND"
,
pid
)
viper
.
Set
(
"CLI_PND"
,
pid
)
log
.
Infof
(
"PND: %v"
,
pid
)
log
.
Infof
(
"PND: %v"
,
pid
)
if
len
(
resp
.
Pnd
[
0
]
.
Sbi
)
!=
0
{
//
if len(resp.Pnd[0].Sbi) != 0 {
sbi
:=
resp
.
Pnd
[
0
]
.
Sbi
[
0
]
.
Id
//
sbi := resp.Pnd[0].Sbi[0].Id
viper
.
Set
(
"CLI_SBI"
,
sbi
)
//
viper.Set("CLI_SBI", sbi)
log
.
Infof
(
"SBI: %v"
,
sbi
)
//
log.Infof("SBI: %v", sbi)
}
//
}
}
}
return
viper
.
WriteConfig
()
return
viper
.
WriteConfig
()
}
}
...
@@ -55,29 +55,28 @@ func GetIds(addr string) ([]*ppb.PrincipalNetworkDomain, error) {
...
@@ -55,29 +55,28 @@ func GetIds(addr string) ([]*ppb.PrincipalNetworkDomain, error) {
return
resp
.
Pnd
,
nil
return
resp
.
Pnd
,
nil
}
}
func
getAllCore
(
ctx
context
.
Context
,
addr
string
)
(
*
pb
.
GetResponse
,
error
)
{
func
getAllCore
(
ctx
context
.
Context
,
addr
string
)
(
*
pb
.
Get
PndList
Response
,
error
)
{
coreClient
,
err
:=
nbi
.
CoreClient
(
addr
,
dialOptions
...
)
coreClient
,
err
:=
nbi
.
CoreClient
(
addr
,
dialOptions
...
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
req
:=
&
pb
.
GetRequest
{
req
:=
&
pb
.
Get
PndList
Request
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Timestamp
:
time
.
Now
()
.
UnixNano
(),
All
:
true
,
}
}
return
coreClient
.
Get
(
ctx
,
req
)
return
coreClient
.
Get
PndList
(
ctx
,
req
)
}
}
// AddPnd takes a name, description and SBI UUID to create a new
// AddPnd takes a name, description and SBI UUID to create a new
// PrincipalNetworkDomain on the controller
// PrincipalNetworkDomain on the controller
func
AddPnd
(
addr
,
name
,
description
,
sbi
string
)
(
*
pb
.
Se
tResponse
,
error
)
{
func
AddPnd
(
addr
,
name
,
description
,
sbi
string
)
(
*
pb
.
CreatePndLis
tResponse
,
error
)
{
coreClient
,
err
:=
nbi
.
CoreClient
(
addr
,
dialOptions
...
)
coreClient
,
err
:=
nbi
.
CoreClient
(
addr
,
dialOptions
...
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
req
:=
&
pb
.
Se
tRequest
{
req
:=
&
pb
.
CreatePndLis
tRequest
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Pnd
:
[]
*
pb
.
Set
Pnd
{
Pnd
:
[]
*
pb
.
Pnd
CreateProperties
{
{
{
Name
:
name
,
Name
:
name
,
Description
:
description
,
Description
:
description
,
...
@@ -86,13 +85,12 @@ func AddPnd(addr, name, description, sbi string) (*pb.SetResponse, error) {
...
@@ -86,13 +85,12 @@ func AddPnd(addr, name, description, sbi string) (*pb.SetResponse, error) {
},
},
}
}
return
coreClient
.
Se
t
(
ctx
,
req
)
return
coreClient
.
CreatePndLis
t
(
ctx
,
req
)
}
}
// GetPnd requests one or several PrincipalNetworkDomains from the
// GetPnd requests one PrincipalNetworkDomain from the
// controller. To request all PrincipalNetworkDomains without providing
// controller.
// names or UUIDs use GetIds()
func
GetPnd
(
addr
string
,
args
...
string
)
(
*
pb
.
GetPndResponse
,
error
)
{
func
GetPnd
(
addr
string
,
args
...
string
)
(
*
pb
.
GetResponse
,
error
)
{
coreClient
,
err
:=
nbi
.
CoreClient
(
addr
,
dialOptions
...
)
coreClient
,
err
:=
nbi
.
CoreClient
(
addr
,
dialOptions
...
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -101,40 +99,52 @@ func GetPnd(addr string, args ...string) (*pb.GetResponse, error) {
...
@@ -101,40 +99,52 @@ func GetPnd(addr string, args ...string) (*pb.GetResponse, error) {
return
nil
,
errors
.
New
(
"not enough arguments"
)
return
nil
,
errors
.
New
(
"not enough arguments"
)
}
}
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
req
:=
&
pb
.
GetRequest
{
req
:=
&
pb
.
Get
Pnd
Request
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Pid
:
args
,
Pid
:
args
,
}
}
return
coreClient
.
Get
(
ctx
,
req
)
return
coreClient
.
GetPnd
(
ctx
,
req
)
}
// GetPnds requests all PrincipalNetworkDomains from the
// controller.
func
GetPnds
(
addr
string
,
args
...
string
)
(
*
pb
.
GetPndListResponse
,
error
)
{
coreClient
,
err
:=
nbi
.
CoreClient
(
addr
,
dialOptions
...
)
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
args
)
<=
0
{
return
nil
,
errors
.
New
(
"not enough arguments"
)
}
ctx
:=
context
.
Background
()
req
:=
&
pb
.
GetPndListRequest
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
}
return
coreClient
.
GetPndList
(
ctx
,
req
)
}
}
// getChanges requests all pending and unconfirmed changes from the controller
// getChanges requests all pending and unconfirmed changes from the controller
func
getChanges
(
addr
,
pnd
string
)
(
*
ppb
.
GetResponse
,
error
)
{
func
getChanges
(
addr
,
pnd
string
)
(
*
ppb
.
Get
ChangeList
Response
,
error
)
{
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
client
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
client
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
req
:=
&
ppb
.
GetRequest
{
req
:=
&
ppb
.
Get
ChangeList
Request
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Request
:
&
ppb
.
GetRequest_Change
{
Pid
:
pnd
,
Change
:
&
ppb
.
GetChange
{
All
:
true
,
},
},
Pid
:
pnd
,
}
}
return
client
.
Get
(
ctx
,
req
)
return
client
.
Get
ChangeList
(
ctx
,
req
)
}
}
// commit sends a commit request for one or multiple changes to the
// commit sends a commit request for one or multiple changes to the
// controller.
// controller.
func
commit
(
addr
,
pnd
string
,
cuids
...
string
)
(
*
ppb
.
SetResponse
,
error
)
{
func
commit
(
addr
,
pnd
string
,
cuids
...
string
)
(
*
ppb
.
Set
ChangeList
Response
,
error
)
{
changes
:=
make
([]
*
ppb
.
SetChange
,
len
(
cuids
))
changes
:=
make
([]
*
ppb
.
SetChange
,
len
(
cuids
))
for
i
,
arg
:=
range
cuids
{
for
i
,
arg
:=
range
cuids
{
changes
[
i
]
=
&
ppb
.
SetChange
{
changes
[
i
]
=
&
ppb
.
SetChange
{
Cuid
:
arg
,
Cuid
:
arg
,
Op
:
ppb
.
SetChange
_COMMIT
,
Op
:
ppb
.
Operation_OPERATION
_COMMIT
,
}
}
}
}
return
commitConfirm
(
addr
,
pnd
,
changes
)
return
commitConfirm
(
addr
,
pnd
,
changes
)
...
@@ -142,40 +152,40 @@ func commit(addr, pnd string, cuids ...string) (*ppb.SetResponse, error) {
...
@@ -142,40 +152,40 @@ func commit(addr, pnd string, cuids ...string) (*ppb.SetResponse, error) {
// confirm sends a confirm request for one or multiple changes to the
// confirm sends a confirm request for one or multiple changes to the
// controller
// controller
func
confirm
(
addr
,
pnd
string
,
cuids
...
string
)
(
*
ppb
.
SetResponse
,
error
)
{
func
confirm
(
addr
,
pnd
string
,
cuids
...
string
)
(
*
ppb
.
Set
ChangeList
Response
,
error
)
{
changes
:=
make
([]
*
ppb
.
SetChange
,
len
(
cuids
))
changes
:=
make
([]
*
ppb
.
SetChange
,
len
(
cuids
))
for
i
,
arg
:=
range
cuids
{
for
i
,
arg
:=
range
cuids
{
changes
[
i
]
=
&
ppb
.
SetChange
{
changes
[
i
]
=
&
ppb
.
SetChange
{
Cuid
:
arg
,
Cuid
:
arg
,
Op
:
ppb
.
SetChange
_CONFIRM
,
Op
:
ppb
.
Operation_OPERATION
_CONFIRM
,
}
}
}
}
return
commitConfirm
(
addr
,
pnd
,
changes
)
return
commitConfirm
(
addr
,
pnd
,
changes
)
}
}
func
commitConfirm
(
addr
,
pnd
string
,
changes
[]
*
ppb
.
SetChange
)
(
*
ppb
.
SetResponse
,
error
)
{
func
commitConfirm
(
addr
,
pnd
string
,
changes
[]
*
ppb
.
SetChange
)
(
*
ppb
.
Set
ChangeList
Response
,
error
)
{
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
client
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
client
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
req
:=
&
ppb
.
SetRequest
{
req
:=
&
ppb
.
Set
ChangeList
Request
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Change
:
changes
,
Change
:
changes
,
Pid
:
pnd
,
Pid
:
pnd
,
}
}
return
client
.
Set
(
ctx
,
req
)
return
client
.
Set
ChangeList
(
ctx
,
req
)
}
}
// addDevice adds a new device to the controller. The device name is optional.
// 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.
// If no name is provided a name will be generated upon device creation.
func
addDevice
(
addr
,
deviceName
string
,
opt
*
tpb
.
TransportOption
,
sid
,
pid
uuid
.
UUID
)
(
*
ppb
.
SetResponse
,
error
)
{
func
addDevice
(
addr
,
deviceName
string
,
opt
*
tpb
.
TransportOption
,
sid
,
pid
uuid
.
UUID
)
(
*
ppb
.
Set
OndList
Response
,
error
)
{
pndClient
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
pndClient
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
req
:=
&
ppb
.
SetRequest
{
req
:=
&
ppb
.
Set
OndList
Request
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Ond
:
[]
*
ppb
.
SetOnd
{
Ond
:
[]
*
ppb
.
SetOnd
{
{
{
...
@@ -197,80 +207,85 @@ func addDevice(addr, deviceName string, opt *tpb.TransportOption, sid, pid uuid.
...
@@ -197,80 +207,85 @@ func addDevice(addr, deviceName string, opt *tpb.TransportOption, sid, pid uuid.
default
:
default
:
}
}
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
return
pndClient
.
Set
(
ctx
,
req
)
return
pndClient
.
Set
OndList
(
ctx
,
req
)
}
}
// getDevice requests one
or multiple
device
s
belonging to a given
// getDevice requests one device belonging to a given
// PrincipalNetworkDomain from the controller. If no device identifier
// PrincipalNetworkDomain from the controller. If no device identifier
// is provided, a
ll devices are requested
.
// is provided, a
n error is thrown
.
func
getDevice
(
addr
,
pid
string
,
did
...
string
)
(
*
ppb
.
GetResponse
,
error
)
{
func
getDevice
(
addr
,
pid
string
,
did
...
string
)
(
*
ppb
.
Get
Ond
Response
,
error
)
{
pndClient
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
pndClient
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
var
all
bool
if
len
(
did
)
==
0
{
if
len
(
did
)
==
0
{
all
=
true
return
nil
,
err
}
}
req
:=
&
ppb
.
GetRequest
{
req
:=
&
ppb
.
Get
Ond
Request
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Request
:
&
ppb
.
GetRequest_Ond
{
Did
:
did
,
Ond
:
&
ppb
.
GetOnd
{
Pid
:
pid
,
All
:
all
,
Did
:
did
,
},
},
Pid
:
pid
,
}
}
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
return
pndClient
.
Get
(
ctx
,
req
)
return
pndClient
.
Get
Ond
(
ctx
,
req
)
}
}
func
getPath
(
addr
,
pid
,
did
,
path
string
)
(
*
ppb
.
GetResponse
,
error
)
{
// getDevice requests all devices belonging to a given
// PrincipalNetworkDomain from the controller.
func
getDevices
(
addr
,
pid
string
)
(
*
ppb
.
GetOndListResponse
,
error
)
{
pndClient
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
pndClient
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
req
:=
&
ppb
.
GetRequest
{
req
:=
&
ppb
.
Get
OndList
Request
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Request
:
&
ppb
.
GetRequest_Path
{
Pid
:
pid
,
Path
:
&
ppb
.
GetPath
{
}
Did
:
did
,
ctx
:=
context
.
Background
()
Path
:
path
,
return
pndClient
.
GetOndList
(
ctx
,
req
)
},
}
},
Pid
:
pid
,
func
getPath
(
addr
,
pid
,
did
,
path
string
)
(
*
ppb
.
GetPathResponse
,
error
)
{
pndClient
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
if
err
!=
nil
{
return
nil
,
err
}
req
:=
&
ppb
.
GetPathRequest
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Did
:
did
,
Pid
:
pid
,
Path
:
path
,
}
}
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
return
pndClient
.
Get
(
ctx
,
req
)
return
pndClient
.
Get
Path
(
ctx
,
req
)
}
}
func
deleteDevice
(
addr
,
pid
,
did
string
)
(
*
ppb
.
DeleteResponse
,
error
)
{
func
deleteDevice
(
addr
,
pid
,
did
string
)
(
*
ppb
.
Delete
Ond
Response
,
error
)
{
pndClient
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
pndClient
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
req
:=
&
ppb
.
DeleteRequest
{
req
:=
&
ppb
.
Delete
Ond
Request
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Type
:
ppb
.
DeleteRequest_OND
,
Did
:
did
,
Uuid
:
did
,
Pid
:
pid
,
Pid
:
pid
,
}
}
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
return
pndClient
.
Delete
(
ctx
,
req
)
return
pndClient
.
Delete
Ond
(
ctx
,
req
)
}
}
// change creates a ChangeRequest for the specified OND. ApiOperations are
// change creates a ChangeRequest for the specified OND. ApiOperations are
// used to specify the type of the change (update, replace, delete as specified
// 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)
// 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.
// 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
)
{
func
changeRequest
(
addr
,
did
,
pid
,
path
,
value
string
,
op
ppb
.
ApiOperation
)
(
*
ppb
.
Set
PathList
Response
,
error
)
{
req
:=
&
ppb
.
ChangeRequest
{
req
:=
&
ppb
.
ChangeRequest
{
I
d
:
did
,
Di
d
:
did
,
Path
:
path
,
Path
:
path
,
Value
:
value
,
Value
:
value
,
ApiOp
:
op
,
ApiOp
:
op
,
...
@@ -278,16 +293,16 @@ func changeRequest(addr, did, pid, path, value string, op ppb.ApiOperation) (*pp
...
@@ -278,16 +293,16 @@ func changeRequest(addr, did, pid, path, value string, op ppb.ApiOperation) (*pp
return
sendChangeRequest
(
addr
,
pid
,
req
)
return
sendChangeRequest
(
addr
,
pid
,
req
)
}
}
func
sendChangeRequest
(
addr
,
pid
string
,
req
*
ppb
.
ChangeRequest
)
(
*
ppb
.
SetResponse
,
error
)
{
func
sendChangeRequest
(
addr
,
pid
string
,
req
*
ppb
.
ChangeRequest
)
(
*
ppb
.
Set
PathList
Response
,
error
)
{
pndClient
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
pndClient
,
err
:=
nbi
.
PndClient
(
addr
,
dialOptions
...
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
r
:=
&
ppb
.
SetRequest
{
r
:=
&
ppb
.
Set
PathList
Request
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
Timestamp
:
time
.
Now
()
.
UnixNano
(),
ChangeRequest
:
[]
*
ppb
.
ChangeRequest
{
req
},
ChangeRequest
:
[]
*
ppb
.
ChangeRequest
{
req
},
Pid
:
pid
,
Pid
:
pid
,
}
}
return
pndClient
.
Set
(
ctx
,
r
)
return
pndClient
.
Set
PathList
(
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