[VOL-4673] Initial translation of data inside mountpoint
Change-Id: Icafbbe25fb4a6ef28049419b8e0eca793c0a0e19
diff --git a/internal/core/translation.go b/internal/core/translation.go
index bc7c692..634272c 100644
--- a/internal/core/translation.go
+++ b/internal/core/translation.go
@@ -19,14 +19,29 @@
import (
"fmt"
+ "github.com/opencord/voltha-protos/v5/go/common"
"github.com/opencord/voltha-protos/v5/go/voltha"
)
const (
DeviceAggregationModel = "bbf-device-aggregation"
DevicesPath = "/" + DeviceAggregationModel + ":devices"
- DeviceTypeOlt = "bbf-device-types:olt"
- DeviceTypeOnu = "bbf-device-types:onu"
+ HardwarePath = "data/ietf-hardware:hardware"
+
+ //Device types
+ DeviceTypeOlt = "bbf-device-types:olt"
+ DeviceTypeOnu = "bbf-device-types:onu"
+
+ //Admin states
+ ietfAdminStateUnknown = "unknown"
+ ietfAdminStateLocked = "locked"
+ ietfAdminStateUnlocked = "unlocked"
+
+ //Oper states
+ ietfOperStateUnknown = "unknown"
+ ietfOperStateDisabled = "disabled"
+ ietfOperStateEnabled = "enabled"
+ ietfOperStateTesting = "testing"
)
type YangItem struct {
@@ -39,20 +54,117 @@
return fmt.Sprintf("%s/device[name='%s']", DevicesPath, id)
}
+//getDevicePath returns the yang path to the root of the device's hardware module in its data mountpoint
+func getDeviceHardwarePath(id string) string {
+ return fmt.Sprintf("%s/device[name='%s']/%s/component[name='%s']", DevicesPath, id, HardwarePath, id)
+}
+
+//ietfHardwareAdminState returns the string that represents the ietf-hardware admin state
+//enum value corresponding to the one of VOLTHA
+func ietfHardwareAdminState(volthaAdminState voltha.AdminState_Types) string {
+ //TODO: verify this mapping is correct
+ switch volthaAdminState {
+ case common.AdminState_UNKNOWN:
+ return ietfAdminStateUnknown
+ case common.AdminState_PREPROVISIONED:
+ case common.AdminState_DOWNLOADING_IMAGE:
+ case common.AdminState_ENABLED:
+ return ietfAdminStateUnlocked
+ case common.AdminState_DISABLED:
+ return ietfAdminStateLocked
+ }
+
+ //TODO: does something map to "shutting-down" ?
+
+ return ietfAdminStateUnknown
+}
+
+//ietfHardwareOperState returns the string that represents the ietf-hardware oper state
+//enum value corresponding to the one of VOLTHA
+func ietfHardwareOperState(volthaOperState voltha.OperStatus_Types) string {
+ //TODO: verify this mapping is correct
+ switch volthaOperState {
+ case common.OperStatus_UNKNOWN:
+ return ietfOperStateUnknown
+ case common.OperStatus_TESTING:
+ return ietfOperStateTesting
+ case common.OperStatus_ACTIVE:
+ return ietfOperStateEnabled
+ case common.OperStatus_DISCOVERED:
+ case common.OperStatus_ACTIVATING:
+ case common.OperStatus_FAILED:
+ case common.OperStatus_RECONCILING:
+ case common.OperStatus_RECONCILING_FAILED:
+ return ietfOperStateDisabled
+ }
+
+ return ietfOperStateUnknown
+}
+
//translateDevice returns a slice of yang items that represent a voltha device
func translateDevice(device voltha.Device) []YangItem {
devicePath := getDevicePath(device.Id)
+ hardwarePath := getDeviceHardwarePath(device.Id)
- typeItem := YangItem{}
- typeItem.Path = fmt.Sprintf("%s/type", devicePath)
+ result := []YangItem{}
+ //Device type
if device.Root {
- typeItem.Value = DeviceTypeOlt
+ result = append(result, YangItem{
+ Path: fmt.Sprintf("%s/type", devicePath),
+ Value: DeviceTypeOlt,
+ })
} else {
- typeItem.Value = DeviceTypeOnu
+ result = append(result, YangItem{
+ Path: fmt.Sprintf("%s/type", devicePath),
+ Value: DeviceTypeOnu,
+ })
}
- return []YangItem{typeItem}
+ //Vendor name
+ result = append(result, YangItem{
+ Path: fmt.Sprintf("%s/mfg-name", hardwarePath),
+ Value: device.Vendor,
+ })
+
+ //Model
+ result = append(result, YangItem{
+ Path: fmt.Sprintf("%s/model-name", hardwarePath),
+ Value: device.Model,
+ })
+
+ //Hardware version
+ result = append(result, YangItem{
+ Path: fmt.Sprintf("%s/hardware-rev", hardwarePath),
+ Value: device.HardwareVersion,
+ })
+
+ //Firmware version
+ result = append(result, YangItem{
+ Path: fmt.Sprintf("%s/firmware-rev", hardwarePath),
+ Value: device.FirmwareVersion,
+ })
+
+ //Serial number
+ result = append(result, YangItem{
+ Path: fmt.Sprintf("%s/serial-num", hardwarePath),
+ Value: device.SerialNumber,
+ })
+
+ //Administrative state
+ //Translates VOLTHA admin state enum to ietf-hardware enum
+ result = append(result, YangItem{
+ Path: fmt.Sprintf("%s/state/admin-state", hardwarePath),
+ Value: ietfHardwareAdminState(device.AdminState),
+ })
+
+ //Operative state
+ result = append(result, YangItem{
+ Path: fmt.Sprintf("%s/state/oper-state", hardwarePath),
+ Value: ietfHardwareOperState(device.OperStatus),
+ })
+
+ return result
}
//translateDevices returns a slice of yang items that represent a list of voltha devices