blob: bc7c692eae8709fa517284c8c1625a98ee8c25fa [file] [log] [blame]
Elia Battistone1cecb22022-03-21 10:05:25 +01001/*
2* Copyright 2022-present Open Networking Foundation
3
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7
8* http://www.apache.org/licenses/LICENSE-2.0
9
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15 */
16
17package core
18
19import (
20 "fmt"
21
22 "github.com/opencord/voltha-protos/v5/go/voltha"
23)
24
25const (
26 DeviceAggregationModel = "bbf-device-aggregation"
27 DevicesPath = "/" + DeviceAggregationModel + ":devices"
28 DeviceTypeOlt = "bbf-device-types:olt"
29 DeviceTypeOnu = "bbf-device-types:onu"
30)
31
32type YangItem struct {
33 Path string
34 Value string
35}
36
37//getDevicePath returns the yang path to the root of the device with a specific ID
38func getDevicePath(id string) string {
39 return fmt.Sprintf("%s/device[name='%s']", DevicesPath, id)
40}
41
42//translateDevice returns a slice of yang items that represent a voltha device
43func translateDevice(device voltha.Device) []YangItem {
44 devicePath := getDevicePath(device.Id)
45
46 typeItem := YangItem{}
47 typeItem.Path = fmt.Sprintf("%s/type", devicePath)
48
49 if device.Root {
50 typeItem.Value = DeviceTypeOlt
51 } else {
52 typeItem.Value = DeviceTypeOnu
53 }
54
55 return []YangItem{typeItem}
56}
57
58//translateDevices returns a slice of yang items that represent a list of voltha devices
59func translateDevices(devices voltha.Devices) []YangItem {
60 result := []YangItem{}
61
62 for _, device := range devices.Items {
63 result = append(result, translateDevice(*device)...)
64 }
65
66 return result
67}