blob: 89115aaa7405dc9aa7a30d2024edaa51bd1fc5c9 [file] [log] [blame]
Matteo Scandoloef4e8f82021-05-17 11:20:49 -07001/*
2 * Copyright 2018-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 api
18
19import (
20 "context"
Elia Battistonac63b112022-01-12 18:40:49 +010021
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070022 "github.com/opencord/bbsim/api/bbsim"
23 "github.com/opencord/bbsim/internal/bbsim/devices"
24)
25
26func convertBBSimUniPortToProtoUniPort(u *devices.UniPort) *bbsim.UNI {
27 return &bbsim.UNI{
28 ID: int32(u.ID),
29 OnuID: int32(u.Onu.ID),
30 OnuSn: u.Onu.Sn(),
31 MeID: uint32(u.MeId.ToUint16()),
Matteo Scandolo8a574812021-05-20 15:18:53 -070032 PortNo: int32(u.PortNo),
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070033 OperState: u.OperState.Current(),
Matteo Scandolo8a574812021-05-20 15:18:53 -070034 Services: convertBBsimServicesToProtoServices(u.Services),
Elia Battistonac63b112022-01-12 18:40:49 +010035 Type: bbsim.UniType_ETH,
36 }
37}
38
39func convertBBSimPotsPortToProtoUniPort(u *devices.PotsPort) *bbsim.UNI {
40 return &bbsim.UNI{
41 ID: int32(u.ID),
42 OnuID: int32(u.Onu.ID),
43 OnuSn: u.Onu.Sn(),
44 MeID: uint32(u.MeId.ToUint16()),
45 PortNo: int32(u.PortNo),
46 OperState: u.OperState.Current(),
47 Type: bbsim.UniType_POTS,
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070048 }
49}
50
Matteo Scandolo8a574812021-05-20 15:18:53 -070051func convertBBsimUniPortsToProtoUniPorts(list []devices.UniPortIf) []*bbsim.UNI {
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070052 unis := []*bbsim.UNI{}
Matteo Scandolo8a574812021-05-20 15:18:53 -070053 for _, u := range list {
54 uni := u.(*devices.UniPort)
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070055 unis = append(unis, convertBBSimUniPortToProtoUniPort(uni))
56 }
57 return unis
58}
59
Elia Battistonac63b112022-01-12 18:40:49 +010060func convertBBsimPotsPortsToProtoUniPorts(list []devices.PotsPortIf) []*bbsim.UNI {
61 unis := []*bbsim.UNI{}
62 for _, u := range list {
63 uni := u.(*devices.PotsPort)
64 unis = append(unis, convertBBSimPotsPortToProtoUniPort(uni))
65 }
66 return unis
67}
68
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070069func (s BBSimServer) GetOnuUnis(ctx context.Context, req *bbsim.ONURequest) (*bbsim.UNIs, error) {
70 onu, err := s.GetONU(ctx, req)
71
72 if err != nil {
73 return nil, err
74 }
75
76 unis := bbsim.UNIs{
77 Items: onu.Unis,
78 }
79
80 return &unis, nil
81}