blob: 50b9911ebec7077081d4e96741b1b2ff53d405de [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"
21 "github.com/opencord/bbsim/api/bbsim"
22 "github.com/opencord/bbsim/internal/bbsim/devices"
23)
24
25func convertBBSimUniPortToProtoUniPort(u *devices.UniPort) *bbsim.UNI {
26 return &bbsim.UNI{
27 ID: int32(u.ID),
28 OnuID: int32(u.Onu.ID),
29 OnuSn: u.Onu.Sn(),
30 MeID: uint32(u.MeId.ToUint16()),
Matteo Scandolo8a574812021-05-20 15:18:53 -070031 PortNo: int32(u.PortNo),
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070032 OperState: u.OperState.Current(),
Matteo Scandolo8a574812021-05-20 15:18:53 -070033 Services: convertBBsimServicesToProtoServices(u.Services),
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070034 }
35}
36
Matteo Scandolo8a574812021-05-20 15:18:53 -070037func convertBBsimUniPortsToProtoUniPorts(list []devices.UniPortIf) []*bbsim.UNI {
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070038 unis := []*bbsim.UNI{}
Matteo Scandolo8a574812021-05-20 15:18:53 -070039 for _, u := range list {
40 uni := u.(*devices.UniPort)
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070041 unis = append(unis, convertBBSimUniPortToProtoUniPort(uni))
42 }
43 return unis
44}
45
46func (s BBSimServer) GetOnuUnis(ctx context.Context, req *bbsim.ONURequest) (*bbsim.UNIs, error) {
47 onu, err := s.GetONU(ctx, req)
48
49 if err != nil {
50 return nil, err
51 }
52
53 unis := bbsim.UNIs{
54 Items: onu.Unis,
55 }
56
57 return &unis, nil
58}