blob: e406917709df435be0dec6f95320c2d608bae123 [file] [log] [blame]
Matteo Scandolo4a036262020-08-17 15:56:13 -07001/*
Joey Armstrong14628cd2023-01-10 08:38:31 -05002 * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors
Matteo Scandolo4a036262020-08-17 15:56:13 -07003
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"
Elia Battistonde6becb2022-01-28 16:45:31 +010021 "strconv"
22
Matteo Scandolo4a036262020-08-17 15:56:13 -070023 "github.com/opencord/bbsim/api/bbsim"
24 "github.com/opencord/bbsim/internal/bbsim/devices"
25)
26
27func convertBBSimServiceToProtoService(s *devices.Service) *bbsim.Service {
28 return &bbsim.Service{
Elia Battiston9a1da622022-02-09 14:43:52 +010029 Name: s.Name,
30 InternalState: s.InternalState.Current(),
31 HwAddress: s.HwAddress.String(),
32 OnuSn: s.UniPort.Onu.Sn(),
33 UniId: s.UniPort.ID,
34 UniTagMatch: int32(s.UniTagMatch),
35 CTag: int32(s.CTag),
36 UsCTagPriority: uint32(s.UsPonCTagPriority),
37 DsCTagPriority: uint32(s.DsPonCTagPriority),
38 STag: int32(s.STag),
39 UsSTagPriority: uint32(s.UsPonSTagPriority),
40 DsSTagPriority: uint32(s.DsPonSTagPriority),
41 NeedsEapol: s.NeedsEapol,
42 NeedsDhcp: s.NeedsDhcp,
43 NeedsIgmp: s.NeedsIgmp,
44 NeedsPPPoE: s.NeedsPPPoE,
45 ConfigureMacAddress: s.ConfigureMacAddress,
46 EnableMacLearning: s.EnableMacLearning,
47 GemPort: int32(s.GemPort),
48 EapolState: s.EapolState.Current(),
49 DhcpState: s.DHCPState.Current(),
50 IGMPState: s.IGMPState.Current(),
Matteo Scandolo4a036262020-08-17 15:56:13 -070051 }
52}
53
54func convertBBsimServicesToProtoServices(list []devices.ServiceIf) []*bbsim.Service {
55 services := []*bbsim.Service{}
56 for _, service := range list {
57 s := service.(*devices.Service)
58 services = append(services, convertBBSimServiceToProtoService(s))
59 }
60 return services
61}
62
Nitin Subramanianb0a333a2021-07-08 15:01:41 -070063func (s BBSimServer) GetServices(ctx context.Context, req *bbsim.UNIRequest) (*bbsim.Services, error) {
Matteo Scandolo4a036262020-08-17 15:56:13 -070064
65 services := bbsim.Services{
66 Items: []*bbsim.Service{},
67 }
68
69 olt := devices.GetOLT()
70
71 for _, pon := range olt.Pons {
72 for _, o := range pon.Onus {
Matteo Scandolo8a574812021-05-20 15:18:53 -070073 for _, u := range o.UniPorts {
74 uni := u.(*devices.UniPort)
75 s := convertBBsimServicesToProtoServices(uni.Services)
Nitin Subramanianb0a333a2021-07-08 15:01:41 -070076 for _, service := range s {
77 intVar, err := strconv.Atoi(req.UniID)
78 if req.UniID == "" && req.OnuSerialNumber == "" {
Elia Battistonde6becb2022-01-28 16:45:31 +010079 services.Items = append(services.Items, service)
Nitin Subramanianb0a333a2021-07-08 15:01:41 -070080 } else if err == nil && service.UniId == uint32(intVar) && service.OnuSn == req.OnuSerialNumber {
Elia Battistonde6becb2022-01-28 16:45:31 +010081 services.Items = append(services.Items, service)
Nitin Subramanianb0a333a2021-07-08 15:01:41 -070082 } else if req.UniID == "" && service.OnuSn == req.OnuSerialNumber {
Elia Battistonde6becb2022-01-28 16:45:31 +010083 services.Items = append(services.Items, service)
Nitin Subramanianb0a333a2021-07-08 15:01:41 -070084 }
85 }
Matteo Scandolo8a574812021-05-20 15:18:53 -070086 }
Matteo Scandolo4a036262020-08-17 15:56:13 -070087 }
88 }
89
90 return &services, nil
91}