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()), |
| 31 | OperState: u.OperState.Current(), |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | func convertBBsimUniPortsToProtoUniPorts(list []*devices.UniPort) []*bbsim.UNI { |
| 36 | unis := []*bbsim.UNI{} |
| 37 | for _, uni := range list { |
| 38 | unis = append(unis, convertBBSimUniPortToProtoUniPort(uni)) |
| 39 | } |
| 40 | return unis |
| 41 | } |
| 42 | |
| 43 | func (s BBSimServer) GetOnuUnis(ctx context.Context, req *bbsim.ONURequest) (*bbsim.UNIs, error) { |
| 44 | onu, err := s.GetONU(ctx, req) |
| 45 | |
| 46 | if err != nil { |
| 47 | return nil, err |
| 48 | } |
| 49 | |
| 50 | unis := bbsim.UNIs{ |
| 51 | Items: onu.Unis, |
| 52 | } |
| 53 | |
| 54 | return &unis, nil |
| 55 | } |