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
ca0da1f0
Commit
ca0da1f0
authored
3 years ago
by
Fabian Seidl
Browse files
Options
Downloads
Patches
Plain Diff
test for subscribe component, ugly code, WIP
parent
ee56ce6b
No related branches found
No related tags found
3 merge requests
!376
Add additional example application hostname-checker
,
!343
Add basic application framework and example application to show interaction between events an NBI
,
!342
Resolve "Add an option to send gNMI Subscribe requests via SBI"
Pipeline
#107924
failed
3 years ago
Stage: build
Stage: test
Stage: analyze
Stage: integration-test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
controller/nucleus/gnmi_transport.go
+66
-0
66 additions, 0 deletions
controller/nucleus/gnmi_transport.go
with
66 additions
and
0 deletions
controller/nucleus/gnmi_transport.go
+
66
−
0
View file @
ca0da1f0
...
@@ -3,6 +3,8 @@ package nucleus
...
@@ -3,6 +3,8 @@ package nucleus
import
(
import
(
"context"
"context"
"fmt"
"fmt"
"path"
"time"
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/change"
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/change"
...
@@ -327,6 +329,70 @@ func (g *Gnmi) subscribe(ctx context.Context) error {
...
@@ -327,6 +329,70 @@ func (g *Gnmi) subscribe(ctx context.Context) error {
return
gnmi
.
SubscribeErr
(
ctx
,
g
.
client
,
opts
,
g
.
RespChan
)
return
gnmi
.
SubscribeErr
(
ctx
,
g
.
client
,
opts
,
g
.
RespChan
)
}
}
// Subscribe calls GNMI subscribe
func
(
g
*
Gnmi
)
subscribe2
(
ctx
context
.
Context
,
stringRespChan
chan
string
)
error
{
ctx
=
gnmi
.
NewContext
(
ctx
,
g
.
config
)
opts
,
ok
:=
ctx
.
Value
(
types
.
CtxKeyOpts
)
.
(
*
gnmi
.
SubscribeOptions
)
if
!
ok
{
return
&
errors
.
ErrInvalidTypeAssertion
{
Value
:
ctx
.
Value
(
types
.
CtxKeyOpts
),
Type
:
&
gnmi
.
SubscribeOptions
{},
}
}
go
func
()
{
log
.
WithFields
(
log
.
Fields
{
"address"
:
opts
.
Target
,
"paths"
:
opts
.
Paths
,
"mode"
:
opts
.
Mode
,
"interval"
:
opts
.
SampleInterval
,
})
.
Info
(
"subscribed to gNMI target"
)
for
{
resp
:=
<-
g
.
RespChan
if
resp
!=
nil
{
if
err
:=
LogSubscribeResponse
(
resp
,
stringRespChan
);
err
!=
nil
{
log
.
Fatal
(
err
)
}
}
}
}()
return
gnmi
.
SubscribeErr
(
ctx
,
g
.
client
,
opts
,
g
.
RespChan
)
}
// LogSubscribeResponse logs update responses to stderr.
func
LogSubscribeResponse
(
response
*
gpb
.
SubscribeResponse
,
stringRespChan
chan
string
)
error
{
switch
resp
:=
response
.
Response
.
(
type
)
{
case
*
gpb
.
SubscribeResponse_Error
:
//return errors.New(resp.Error.Message)
//TODO: fix error
return
errors
.
ErrNotYetImplemented
{}
case
*
gpb
.
SubscribeResponse_SyncResponse
:
if
!
resp
.
SyncResponse
{
//return errors.New("initial sync failed")
//TODO: fix error
return
errors
.
ErrNotYetImplemented
{}
}
case
*
gpb
.
SubscribeResponse_Update
:
t
:=
time
.
Unix
(
0
,
resp
.
Update
.
Timestamp
)
.
UTC
()
prefix
:=
resp
.
Update
.
Prefix
var
target
string
if
t
:=
resp
.
Update
.
Prefix
.
GetTarget
();
t
!=
""
{
target
=
"("
+
t
+
") "
}
for
_
,
update
:=
range
resp
.
Update
.
Update
{
stringRespChan
<-
fmt
.
Sprintf
(
"[%s] %s%s = %s
\n
"
,
t
.
Format
(
time
.
RFC3339Nano
),
target
,
path
.
Join
(
prefix
.
String
(),
update
.
Path
.
String
()),
update
.
String
())
}
for
_
,
del
:=
range
resp
.
Update
.
Delete
{
stringRespChan
<-
fmt
.
Sprintf
(
"[%s] %sDeleted %s
\n
"
,
t
.
Format
(
time
.
RFC3339Nano
),
target
,
path
.
Join
(
prefix
.
String
(),
del
.
String
()))
}
}
return
nil
}
// Close calls GNMI close
// Close calls GNMI close
func
(
g
*
Gnmi
)
Close
()
error
{
func
(
g
*
Gnmi
)
Close
()
error
{
return
nil
return
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