Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -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 convertBBSimServiceToProtoService(s *devices.Service) *bbsim.Service { |
| 26 | return &bbsim.Service{ |
Matteo Scandolo | 75ed5b9 | 2020-09-03 09:03:16 -0700 | [diff] [blame] | 27 | Name: s.Name, |
| 28 | InternalState: s.InternalState.Current(), |
| 29 | HwAddress: s.HwAddress.String(), |
| 30 | OnuSn: s.Onu.Sn(), |
| 31 | CTag: int32(s.CTag), |
| 32 | STag: int32(s.STag), |
| 33 | NeedsEapol: s.NeedsEapol, |
| 34 | NeedsDhcp: s.NeedsDhcp, |
| 35 | NeedsIgmp: s.NeedsIgmp, |
| 36 | GemPort: int32(s.GemPort), |
| 37 | EapolState: s.EapolState.Current(), |
| 38 | DhcpState: s.DHCPState.Current(), |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 39 | IGMPState: s.IGMPState.Current(), |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 40 | } |
| 41 | } |
| 42 | |
| 43 | func convertBBsimServicesToProtoServices(list []devices.ServiceIf) []*bbsim.Service { |
| 44 | services := []*bbsim.Service{} |
| 45 | for _, service := range list { |
| 46 | s := service.(*devices.Service) |
| 47 | services = append(services, convertBBSimServiceToProtoService(s)) |
| 48 | } |
| 49 | return services |
| 50 | } |
| 51 | |
| 52 | func (s BBSimServer) GetServices(ctx context.Context, req *bbsim.Empty) (*bbsim.Services, error) { |
| 53 | |
| 54 | services := bbsim.Services{ |
| 55 | Items: []*bbsim.Service{}, |
| 56 | } |
| 57 | |
| 58 | olt := devices.GetOLT() |
| 59 | |
| 60 | for _, pon := range olt.Pons { |
| 61 | for _, o := range pon.Onus { |
| 62 | s := convertBBsimServicesToProtoServices(o.Services) |
| 63 | services.Items = append(services.Items, s...) |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | return &services, nil |
| 68 | } |
| 69 | |
| 70 | func (s BBSimServer) GetOnuServices(ctx context.Context, req *bbsim.ONURequest) (*bbsim.Services, error) { |
| 71 | onu, err := s.GetONU(ctx, req) |
| 72 | |
| 73 | if err != nil { |
| 74 | return nil, err |
| 75 | } |
| 76 | |
| 77 | services := bbsim.Services{ |
| 78 | Items: onu.Services, |
| 79 | } |
| 80 | |
| 81 | return &services, nil |
| 82 | } |