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" |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame^] | 21 | |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 22 | "github.com/opencord/bbsim/api/bbsim" |
| 23 | "github.com/opencord/bbsim/internal/bbsim/devices" |
| 24 | ) |
| 25 | |
| 26 | func 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 Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 32 | PortNo: int32(u.PortNo), |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 33 | OperState: u.OperState.Current(), |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 34 | Services: convertBBsimServicesToProtoServices(u.Services), |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame^] | 35 | Type: bbsim.UniType_ETH, |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | func 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 Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 51 | func convertBBsimUniPortsToProtoUniPorts(list []devices.UniPortIf) []*bbsim.UNI { |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 52 | unis := []*bbsim.UNI{} |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 53 | for _, u := range list { |
| 54 | uni := u.(*devices.UniPort) |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 55 | unis = append(unis, convertBBSimUniPortToProtoUniPort(uni)) |
| 56 | } |
| 57 | return unis |
| 58 | } |
| 59 | |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame^] | 60 | func 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 Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 69 | func (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 | } |