Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package api |
| 18 | |
| 19 | import ( |
| 20 | "context" |
| 21 | "github.com/opencord/bbsim/api/bbsim" |
| 22 | "github.com/opencord/bbsim/internal/bbsim/devices" |
| 23 | ) |
| 24 | |
| 25 | func 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 Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 31 | PortNo: int32(u.PortNo), |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 32 | OperState: u.OperState.Current(), |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 33 | Services: convertBBsimServicesToProtoServices(u.Services), |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 34 | } |
| 35 | } |
| 36 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 37 | func convertBBsimUniPortsToProtoUniPorts(list []devices.UniPortIf) []*bbsim.UNI { |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 38 | unis := []*bbsim.UNI{} |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame^] | 39 | for _, u := range list { |
| 40 | uni := u.(*devices.UniPort) |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 41 | unis = append(unis, convertBBSimUniPortToProtoUniPort(uni)) |
| 42 | } |
| 43 | return unis |
| 44 | } |
| 45 | |
| 46 | func (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 | } |