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