Skip to content
Snippets Groups Projects
Commit 2e768095 authored by Malte Bauch's avatar Malte Bauch
Browse files

gNMI sub WIP

parent 6eb3e500
No related branches found
No related tags found
3 merge requests!376Add additional example application hostname-checker,!343Add basic application framework and example application to show interaction between events an NBI,!342Resolve "Add an option to send gNMI Subscribe requests via SBI"
Pipeline #107750 failed
......@@ -127,6 +127,14 @@ func (p *PndAdapter) Request(ctx context.Context, did uuid.UUID, path string) (*
return resp, nil
}
func (p *PndAdapter) SubscribeONDPath(ctx context.Context, did uuid.UUID, slist *ppb.SubscriptionList) (ppb.PndService_SubscribePathClient, error) {
resp, err := api.SubscribePath(ctx, p.endpoint, p.id.String(), did.String(), slist)
if err != nil {
return nil, err
}
return resp, nil
}
// RequestAll sends an API call to the controller requesting the specified path
// for all registered devices. Not yet implemented.
func (p *PndAdapter) RequestAll(ctx context.Context, path string) ([]proto.Message, error) {
......
/*
Copyright © 2021 da/net research group <danet.fbi.h-da.de>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
package cmd
import (
"io"
"code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd"
"github.com/google/uuid"
"github.com/pterm/pterm"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
// deviceGetCmd represents the get command
var deviceSubscribeCmd = &cobra.Command{
Use: "subscribe [uuid] [path]",
Args: cobra.ExactArgs(2),
Short: "do",
Long: `Requests a path from a specified orchestrated network device on the controller.
The device UUID and request path must be specified as a positional arguments.`,
RunE: func(cmd *cobra.Command, args []string) error {
did, err := uuid.Parse(args[0])
if err != nil {
pterm.Error.Println(err)
return err
}
subClient, err := pndAdapter.SubscribeONDPath(
createContextWithAuthorization(),
did,
&pnd.SubscriptionList{
Subscription: []*pnd.Subscription{
{
Path: "system/config/hostname",
StreamMode: pnd.StreamMode_STREAM_MODE_TARGET_DEFINED,
SampleInterval: 1000000000,
},
},
Mode: pnd.SubscriptionMode_SUBSCRIPTION_MODE_ONCE,
},
)
if err != nil {
pterm.Error.Println(err)
return err
}
for i := 0; i < 5; i++ {
subscribeResponse, err := subClient.Recv()
if err != nil {
if err != nil {
if err == io.EOF {
break
}
log.Error(err)
closeErr := subClient.CloseSend()
if closeErr != nil {
log.Error(err)
}
}
}
pterm.Println(subscribeResponse.String())
}
return nil
},
}
func init() {
deviceCmd.AddCommand(deviceSubscribeCmd)
}
......@@ -152,6 +152,23 @@ func GetPath(ctx context.Context, addr, pid, did, path string) (*ppb.GetPathResp
return pndClient.GetPath(ctx, req)
}
func SubscribePath(ctx context.Context, addr, pid, did string, slist *ppb.SubscriptionList) (ppb.PndService_SubscribePathClient, error) {
log.Println("subscribePath called")
pndClient, err := nbi.PndClient(addr, dialOptions...)
if err != nil {
return nil, err
}
req := &ppb.SubscribePathRequest{
Timestamp: time.Now().UnixNano(),
Did: did,
Pid: pid,
Sublist: slist,
}
return pndClient.SubscribePath(ctx, req)
}
// DeleteDevice deletes a device
func DeleteDevice(ctx context.Context, addr, pid, did string) (*ppb.DeleteOndResponse, error) {
pndClient, err := nbi.PndClient(addr, dialOptions...)
......
......@@ -206,6 +206,7 @@ func ensureDefaultRoleExists() error {
"/gosdn.pnd.PndService/SetPathList",
"/gosdn.pnd.PndService/SetSbiList",
"/gosdn.pnd.PndService/DeleteOnd",
"/gosdn.pnd.PndService/SubscribePath",
"/gosdn.southbound.SbiService/GetSchema",
}))
if err != nil {
......
......@@ -524,14 +524,15 @@ func (pnd *pndImplementation) SubscribePath(uuid uuid.UUID, subList *ppb.Subscri
for _, sub := range subList.Subscription {
opts := &gnmi.SubscribeOptions{
Paths: [][]string{{sub.Path}},
StreamMode: sub.GetStreamMode().String(),
SampleInterval: sub.SampleInterval,
Target: "172.100.0.12:6030",
Paths: [][]string{{"system", "config", "hostname"}},
}
ctx := context.Background()
ctx = context.WithValue(ctx, types.CtxKeyOpts, opts)
_ = sub
err := d.Transport().Subscribe(ctx)
if err != nil {
return err
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment