Skip to content
Merged
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,31 @@ You can also build a debian package and install it:
* See [SONiC telemetry in dial-out mode](./doc/dialout.md) for how to run dial-out mode system telemetry client
* See [gNMI Usage Examples](./doc/gNMI_usage_examples.md) for gNMI client usage examples.

### Streaming events
SONiC publishes events of interest via gNMI.
Sample events could be bgp-state change, link-state change.
A sample query URL is as below.
`gnmi_cli -client_types=gnmi -a 127.0.0.1:50051 -t EVENTS -logtostderr -insecure -v 7 -streaming_type ON_CHANGE -q all -qt s`

The events URL can take the following optional parameters.<br/>
heartbeat:<br/>
`[heartbeat=<N>]`
<br/>
&nbsp;&nbsp;&nbsp;&nbsp;The SONiC switch publishes periodic hearbeats when there are no events to publish.<br/>
&nbsp;&nbsp;&nbsp;&nbsp;The frequency of the heartbeat can be controlled by this parameter as beat in every N seconds.<br/>

usecache:<br/>
`[usecache=true/false]`
<br/>
&nbsp;&nbsp;&nbsp;&nbsp;The SONiC switch does offline cache when gNMI client is down.<br/>
&nbsp;&nbsp;&nbsp;&nbsp;The cached events are delivered upon nest gNMI connection<br/>
&nbsp;&nbsp;&nbsp;&nbsp;Only one client should use the cache service<br/>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to guarantee this limitation?
If two clients use the cache service, what will happen?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Limitation by design.
Trade off between code complexity in supporting multiple clients with cache vs practical use case.
In practice, there is only one client streaming out.
This is added to enable test tools to function w/o disturbing the main service.
To answer your question: If multiple use cache, of course first come first served. The cache will go to one or other.

&nbsp;&nbsp;&nbsp;&nbsp;The cached events are delivered upon nest gNMI connection<br/>
&nbsp;&nbsp;&nbsp;&nbsp;If you are running test clients, use this param to turn off cache use.<br/>

Sample URL: <br/>
`gnmi_cli -client_types=gnmi -a 127.0.0.1:50051 -t EVENTS -logtostderr -insecure -v 7 -streaming_type ON_CHANGE -q all[heartbeat=5][usecache=false] -qt s`

## Need Help?

For general questions, setup help, or troubleshooting:
Expand Down
4 changes: 2 additions & 2 deletions gnmi_server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2619,7 +2619,7 @@ func TestClient(t *testing.T) {
rcv_timeout := sdc.SUBSCRIBER_TIMEOUT
deinit_done := false

mock1 := gomonkey.ApplyFunc(sdc.C_init_subs, func() unsafe.Pointer {
mock1 := gomonkey.ApplyFunc(sdc.C_init_subs, func(use_cache bool) unsafe.Pointer {
return nil
})
defer mock1.Reset()
Expand Down Expand Up @@ -2672,7 +2672,7 @@ func TestClient(t *testing.T) {
},
}

sdc.C_init_subs()
sdc.C_init_subs(true)

for _, tt := range tests {
heartbeat = 0
Expand Down
13 changes: 10 additions & 3 deletions sonic_data_client/events_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const TEST_EVENT = "{\"sonic-host:device-test-event"
// Path parameter
const PARAM_HEARTBEAT = "heartbeat"
const PARAM_QSIZE = "qsize"
const PARAM_USE_CACHE = "usecache"

type EventClient struct {

Expand Down Expand Up @@ -90,12 +91,13 @@ func Set_heartbeat(val int) {
}
}

func C_init_subs() unsafe.Pointer {
return C.events_init_subscriber_wrap(true, C.int(SUBSCRIBER_TIMEOUT))
func C_init_subs(use_cache bool) unsafe.Pointer {
return C.events_init_subscriber_wrap(C.bool(use_cache), C.int(SUBSCRIBER_TIMEOUT))
}

func NewEventClient(paths []*gnmipb.Path, prefix *gnmipb.Path, logLevel int) (Client, error) {
var evtc EventClient
use_cache := true
evtc.prefix = prefix
evtc.pq_max = PQ_DEF_SIZE
log.V(4).Infof("Events priority Q max set default = %v", evtc.pq_max)
Expand Down Expand Up @@ -132,14 +134,19 @@ func NewEventClient(paths []*gnmipb.Path, prefix *gnmipb.Path, logLevel int) (Cl
evtc.pq_max = val
log.V(7).Infof("Events priority Q max set by qsize param = %v", evtc.pq_max)
}
} else if (k == PARAM_USE_CACHE) {
if strings.ToLower(v) == "false" {
use_cache = false
log.V(7).Infof("Cache use is turned off")
}
}
}
}

C.swssSetLogPriority(C.int(logLevel))

/* Init subscriber with cache use and defined time out */
evtc.subs_handle = C_init_subs()
evtc.subs_handle = C_init_subs(use_cache)
evtc.stopped = 0

/* Init list & counters */
Expand Down