Search in sources :

Example 1 with GnmiUpdate

use of org.onosproject.gnmi.api.GnmiUpdate in project onos by opennetworkinglab.

the class GnmiDeviceStateSubscriber method handleGnmiUpdate.

private void handleGnmiUpdate(GnmiUpdate eventSubject) {
    Notification notification = eventSubject.update();
    if (notification == null) {
        log.warn("Cannot handle gNMI event without update data, abort");
        log.debug("gNMI update:\n{}", eventSubject);
        return;
    }
    long lastChange = 0;
    Update statusUpdate = null;
    Path path;
    PathElem lastElem;
    // to put in place the aggregation logic in ONOS
    for (Update update : notification.getUpdateList()) {
        path = update.getPath();
        lastElem = path.getElem(path.getElemCount() - 1);
        // Use last element to identify which state updated
        if ("oper-status".equals(lastElem.getName())) {
            statusUpdate = update;
        } else if ("last-change".equals(lastElem.getName())) {
            lastChange = update.getVal().getUintVal();
        } else if (log.isDebugEnabled()) {
            log.debug("Unrecognized update {}", GnmiUtils.pathToString(path));
        }
    }
    // Cannot proceed without the status update.
    if (statusUpdate != null) {
        handleOperStatusUpdate(eventSubject.deviceId(), statusUpdate, lastChange);
    }
}
Also used : Path(gnmi.Gnmi.Path) PathElem(gnmi.Gnmi.PathElem) GnmiUpdate(org.onosproject.gnmi.api.GnmiUpdate) Update(gnmi.Gnmi.Update) Notification(gnmi.Gnmi.Notification)

Aggregations

Notification (gnmi.Gnmi.Notification)1 Path (gnmi.Gnmi.Path)1 PathElem (gnmi.Gnmi.PathElem)1 Update (gnmi.Gnmi.Update)1 GnmiUpdate (org.onosproject.gnmi.api.GnmiUpdate)1