blob: 276cddbb5f5d06b6473d6fac17ee16992d9a311b [file] [log] [blame]
Matteo Scandolo10f965c2019-09-24 10:40:46 -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 "fmt"
Matteo Scandolof9d43412021-01-12 11:11:34 -080022 "github.com/opencord/bbsim/internal/bbsim/types"
Andrea Campanellabe8e12f2020-12-14 18:43:41 +010023 "github.com/opencord/voltha-protos/v4/go/openolt"
Pragya Arya1d5ffb82020-03-20 18:51:37 +053024
Matteo Scandolo10f965c2019-09-24 10:40:46 -070025 "github.com/opencord/bbsim/api/bbsim"
26 "github.com/opencord/bbsim/internal/bbsim/devices"
27 log "github.com/sirupsen/logrus"
28 "google.golang.org/grpc/codes"
29)
30
31func (s BBSimServer) GetONUs(ctx context.Context, req *bbsim.Empty) (*bbsim.ONUs, error) {
32 olt := devices.GetOLT()
33 onus := bbsim.ONUs{
34 Items: []*bbsim.ONU{},
35 }
36
37 for _, pon := range olt.Pons {
38 for _, o := range pon.Onus {
39 onu := bbsim.ONU{
40 ID: int32(o.ID),
41 SerialNumber: o.Sn(),
42 OperState: o.OperState.Current(),
43 InternalState: o.InternalState.Current(),
44 PonPortID: int32(o.PonPortID),
Matteo Scandolo27428702019-10-11 16:21:16 -070045 PortNo: int32(o.PortNo),
Matteo Scandolo4a036262020-08-17 15:56:13 -070046 Services: convertBBsimServicesToProtoServices(o.Services),
Matteo Scandolo10f965c2019-09-24 10:40:46 -070047 }
48 onus.Items = append(onus.Items, &onu)
49 }
50 }
51 return &onus, nil
52}
53
Matteo Scandolod2ca2c72019-10-04 16:50:22 -070054func (s BBSimServer) GetONU(ctx context.Context, req *bbsim.ONURequest) (*bbsim.ONU, error) {
55 olt := devices.GetOLT()
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -070056 onu, err := olt.FindOnuBySn(req.SerialNumber)
Matteo Scandolod2ca2c72019-10-04 16:50:22 -070057
58 if err != nil {
59 res := bbsim.ONU{}
60 return &res, err
61 }
62
63 res := bbsim.ONU{
64 ID: int32(onu.ID),
65 SerialNumber: onu.Sn(),
66 OperState: onu.OperState.Current(),
67 InternalState: onu.InternalState.Current(),
68 PonPortID: int32(onu.PonPortID),
Matteo Scandolo27428702019-10-11 16:21:16 -070069 PortNo: int32(onu.PortNo),
Matteo Scandolo4a036262020-08-17 15:56:13 -070070 Services: convertBBsimServicesToProtoServices(onu.Services),
Matteo Scandolod2ca2c72019-10-04 16:50:22 -070071 }
72 return &res, nil
73}
74
Pragya Aryabd731ec2020-02-11 16:38:17 +053075// ShutdownONU sends DyingGasp indication for specified ONUs and mark ONUs as disabled.
Matteo Scandolo10f965c2019-09-24 10:40:46 -070076func (s BBSimServer) ShutdownONU(ctx context.Context, req *bbsim.ONURequest) (*bbsim.Response, error) {
Anand S Katti09541352020-01-29 15:54:01 +053077 // NOTE this method is now sending a Dying Gasp and then disabling the device (operState: down, adminState: up),
Matteo Scandolo10f965c2019-09-24 10:40:46 -070078 // is this the only way to do? Should we address other cases?
79 // Investigate what happens when:
80 // - a fiber is pulled
81 // - ONU malfunction
82 // - ONU shutdown
Matteo Scandolo10f965c2019-09-24 10:40:46 -070083 logger.WithFields(log.Fields{
84 "OnuSn": req.SerialNumber,
85 }).Infof("Received request to shutdown ONU")
86
Pragya Aryabd731ec2020-02-11 16:38:17 +053087 res := &bbsim.Response{}
Matteo Scandolo10f965c2019-09-24 10:40:46 -070088 olt := devices.GetOLT()
89
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -070090 onu, err := olt.FindOnuBySn(req.SerialNumber)
Matteo Scandolo10f965c2019-09-24 10:40:46 -070091 if err != nil {
92 res.StatusCode = int32(codes.NotFound)
93 res.Message = err.Error()
94 return res, err
95 }
96
Pragya Aryabd731ec2020-02-11 16:38:17 +053097 return handleShutdownONU(onu)
98}
Matteo Scandolo10f965c2019-09-24 10:40:46 -070099
Pragya Aryabd731ec2020-02-11 16:38:17 +0530100// ShutdownONUsOnPON sends DyingGasp indication for all ONUs under specified PON port
101func (s BBSimServer) ShutdownONUsOnPON(ctx context.Context, req *bbsim.PONRequest) (*bbsim.Response, error) {
102 logger.WithFields(log.Fields{
103 "IntfId": req.PonPortId,
104 }).Infof("Received request to shutdown all ONUs on PON")
Matteo Scandolod7cc6d32020-02-26 16:51:12 -0800105
Pragya Aryabd731ec2020-02-11 16:38:17 +0530106 res := &bbsim.Response{}
107 olt := devices.GetOLT()
108 pon, _ := olt.GetPonById(req.PonPortId)
Matteo Scandolod7cc6d32020-02-26 16:51:12 -0800109
Pragya Aryabd731ec2020-02-11 16:38:17 +0530110 go func() {
111 for _, onu := range pon.Onus {
112 res, _ = handleShutdownONU(onu)
113 }
114 }()
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700115 res.StatusCode = int32(codes.OK)
Pragya Aryabd731ec2020-02-11 16:38:17 +0530116 res.Message = fmt.Sprintf("Request accepted for shutdown all ONUs on PON port %d", pon.ID)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700117
118 return res, nil
119}
120
Pragya Aryabd731ec2020-02-11 16:38:17 +0530121// ShutdownAllONUs sends DyingGasp indication for all ONUs and mark ONUs as disabled.
122func (s BBSimServer) ShutdownAllONUs(context.Context, *bbsim.Empty) (*bbsim.Response, error) {
123 logger.Infof("Received request to shutdown all ONUs")
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700124 res := &bbsim.Response{}
Pragya Aryabd731ec2020-02-11 16:38:17 +0530125 olt := devices.GetOLT()
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700126
Pragya Aryabd731ec2020-02-11 16:38:17 +0530127 go func() {
128 for _, pon := range olt.Pons {
129 for _, onu := range pon.Onus {
130 res, _ = handleShutdownONU(onu)
131 }
132 }
133 }()
134 res.StatusCode = int32(codes.OK)
135 res.Message = fmt.Sprintf("Request Accepted for shutdown all ONUs in OLT %d", olt.ID)
136
137 return res, nil
138}
139
140// PoweronONU simulates ONU power on and start sending discovery indications to VOLTHA
141func (s BBSimServer) PoweronONU(ctx context.Context, req *bbsim.ONURequest) (*bbsim.Response, error) {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700142 logger.WithFields(log.Fields{
143 "OnuSn": req.SerialNumber,
144 }).Infof("Received request to poweron ONU")
145
Pragya Aryabd731ec2020-02-11 16:38:17 +0530146 res := &bbsim.Response{}
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700147 olt := devices.GetOLT()
148
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700149 onu, err := olt.FindOnuBySn(req.SerialNumber)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700150 if err != nil {
151 res.StatusCode = int32(codes.NotFound)
152 res.Message = err.Error()
153 return res, err
154 }
155
Pragya Arya2225f202020-01-29 18:05:01 +0530156 pon, _ := olt.GetPonById(onu.PonPortID)
157 if pon.InternalState.Current() != "enabled" {
158 err := fmt.Errorf("PON port %d not enabled", onu.PonPortID)
159 logger.WithFields(log.Fields{
160 "OnuId": onu.ID,
161 "IntfId": onu.PonPortID,
162 "OnuSn": onu.Sn(),
163 }).Errorf("Cannot poweron ONU: %s", err.Error())
164
165 res.StatusCode = int32(codes.FailedPrecondition)
166 res.Message = err.Error()
167 return res, err
168 }
169
Pragya Aryabd731ec2020-02-11 16:38:17 +0530170 return handlePoweronONU(onu)
171}
172
173// PoweronONUsOnPON simulates ONU power on for all ONUs under specified PON port
174func (s BBSimServer) PoweronONUsOnPON(ctx context.Context, req *bbsim.PONRequest) (*bbsim.Response, error) {
175 logger.WithFields(log.Fields{
176 "IntfId": req.PonPortId,
177 }).Infof("Received request to poweron all ONUs on PON")
178
179 res := &bbsim.Response{}
180 olt := devices.GetOLT()
181
182 pon, _ := olt.GetPonById(req.PonPortId)
183 if pon.InternalState.Current() != "enabled" {
184 err := fmt.Errorf("PON port %d not enabled", pon.ID)
185 logger.WithFields(log.Fields{
186 "IntfId": pon.ID,
187 }).Errorf("Cannot poweron ONUs on PON: %s", err.Error())
188
189 res.StatusCode = int32(codes.FailedPrecondition)
190 res.Message = err.Error()
191 return res, err
192 }
193
194 go func() {
195 for _, onu := range pon.Onus {
196 res, _ = handlePoweronONU(onu)
Pragya Arya2225f202020-01-29 18:05:01 +0530197 }
Pragya Aryabd731ec2020-02-11 16:38:17 +0530198 }()
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700199 res.StatusCode = int32(codes.OK)
Pragya Aryabd731ec2020-02-11 16:38:17 +0530200 res.Message = fmt.Sprintf("Request Accepted for power on all ONUs on PON port %d", pon.ID)
201
202 return res, nil
203}
204
205// PoweronAllONUs simulates ONU power on for all ONUs on all PON ports
206func (s BBSimServer) PoweronAllONUs(context.Context, *bbsim.Empty) (*bbsim.Response, error) {
207 logger.Infof("Received request to poweron all ONUs")
208
209 res := &bbsim.Response{}
210 olt := devices.GetOLT()
211
212 go func() {
213 for _, pon := range olt.Pons {
214 if pon.InternalState.Current() == "enabled" {
215 for _, onu := range pon.Onus {
216 res, _ = handlePoweronONU(onu)
217 }
218 }
219 }
220 }()
221 res.StatusCode = int32(codes.OK)
222 res.Message = fmt.Sprintf("Request Accepted for power on all ONUs in OLT %d", olt.ID)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700223
224 return res, nil
225}
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700226
Arjun E K57a7fcb2020-01-30 06:44:45 +0000227func (s BBSimServer) ChangeIgmpState(ctx context.Context, req *bbsim.IgmpRequest) (*bbsim.Response, error) {
Matteo Scandolo618a6582020-09-09 12:21:29 -0700228
229 // TODO check that the ONU is enabled and the services are initialized before changing the state
230
Arjun E K57a7fcb2020-01-30 06:44:45 +0000231 res := &bbsim.Response{}
232
233 logger.WithFields(log.Fields{
Onur Kalinagac9f9faca2021-01-21 14:04:34 +0000234 "OnuSn": req.OnuReq.SerialNumber,
235 "subAction": req.SubActionVal,
236 "GroupAddress": req.GroupAddress,
Matteo Scandoloc08a6082021-02-05 11:12:01 -0800237 }).Info("Received igmp request for ONU")
Arjun E K57a7fcb2020-01-30 06:44:45 +0000238
239 olt := devices.GetOLT()
240 onu, err := olt.FindOnuBySn(req.OnuReq.SerialNumber)
241
242 if err != nil {
243 res.StatusCode = int32(codes.NotFound)
244 res.Message = err.Error()
Matteo Scandoloc08a6082021-02-05 11:12:01 -0800245 logger.WithFields(log.Fields{
246 "OnuSn": req.OnuReq.SerialNumber,
247 "subAction": req.SubActionVal,
248 "GroupAddress": req.GroupAddress,
249 }).Warn("ONU not found for sending igmp packet.")
Arjun E K57a7fcb2020-01-30 06:44:45 +0000250 return res, err
251 } else {
252 event := ""
253 switch req.SubActionVal {
254 case bbsim.SubActionTypes_JOIN:
255 event = "igmp_join_start"
256 case bbsim.SubActionTypes_LEAVE:
257 event = "igmp_leave"
Anand S Katti09541352020-01-29 15:54:01 +0530258 case bbsim.SubActionTypes_JOINV3:
259 event = "igmp_join_startv3"
Arjun E K57a7fcb2020-01-30 06:44:45 +0000260 }
261
Matteo Scandolo618a6582020-09-09 12:21:29 -0700262 errors := []string{}
263 startedOn := []string{}
264 success := true
265
266 for _, s := range onu.Services {
267 service := s.(*devices.Service)
268 if service.NeedsIgmp {
269
270 logger.WithFields(log.Fields{
271 "OnuId": onu.ID,
272 "IntfId": onu.PonPortID,
273 "OnuSn": onu.Sn(),
274 "Service": service.Name,
275 }).Debugf("Sending %s event on Service %s", event, service.Name)
276
Matteo Scandolof9d43412021-01-12 11:11:34 -0800277 if err := service.IGMPState.Event(event, types.IgmpMessage{GroupAddress: req.GroupAddress}); err != nil {
Matteo Scandolo618a6582020-09-09 12:21:29 -0700278 logger.WithFields(log.Fields{
279 "OnuId": onu.ID,
280 "IntfId": onu.PonPortID,
281 "OnuSn": onu.Sn(),
282 "Service": service.Name,
283 }).Errorf("IGMP request failed: %s", err.Error())
284 errors = append(errors, fmt.Sprintf("%s: %s", service.Name, err.Error()))
285 success = false
286 }
287 startedOn = append(startedOn, service.Name)
288 }
289 }
290
291 if success {
292 res.StatusCode = int32(codes.OK)
Matteo Scandoloc08a6082021-02-05 11:12:01 -0800293 if len(startedOn) > 0 {
294 res.Message = fmt.Sprintf("IGMP %s sent on Services %s for ONU %s.",
295 event, fmt.Sprintf("%v", startedOn), onu.Sn())
296 } else {
297 res.Message = "No service requires IGMP"
298 }
299 logger.WithFields(log.Fields{
300 "OnuSn": req.OnuReq.SerialNumber,
301 "subAction": req.SubActionVal,
302 "GroupAddress": req.GroupAddress,
303 "Message": res.Message,
304 }).Info("Processed IGMP request for ONU")
Matteo Scandolo618a6582020-09-09 12:21:29 -0700305 } else {
Arjun E K57a7fcb2020-01-30 06:44:45 +0000306 res.StatusCode = int32(codes.FailedPrecondition)
Matteo Scandolo618a6582020-09-09 12:21:29 -0700307 res.Message = fmt.Sprintf("%v", errors)
Matteo Scandoloc08a6082021-02-05 11:12:01 -0800308 logger.WithFields(log.Fields{
309 "OnuSn": req.OnuReq.SerialNumber,
310 "subAction": req.SubActionVal,
311 "GroupAddress": req.GroupAddress,
312 "Message": res.Message,
313 }).Error("Error while processing IGMP request for ONU")
Arjun E K57a7fcb2020-01-30 06:44:45 +0000314 }
Matteo Scandoloc08a6082021-02-05 11:12:01 -0800315
Arjun E K57a7fcb2020-01-30 06:44:45 +0000316 }
317
318 return res, nil
319}
320
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700321func (s BBSimServer) RestartEapol(ctx context.Context, req *bbsim.ONURequest) (*bbsim.Response, error) {
322 res := &bbsim.Response{}
323
324 logger.WithFields(log.Fields{
325 "OnuSn": req.SerialNumber,
326 }).Infof("Received request to restart authentication ONU")
327
328 olt := devices.GetOLT()
329
330 onu, err := olt.FindOnuBySn(req.SerialNumber)
331
332 if err != nil {
333 res.StatusCode = int32(codes.NotFound)
334 res.Message = err.Error()
335 return res, err
336 }
337
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700338 errors := []string{}
Matteo Scandolo618a6582020-09-09 12:21:29 -0700339 startedOn := []string{}
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700340 success := true
341
342 for _, s := range onu.Services {
343 service := s.(*devices.Service)
344 if service.NeedsEapol {
345 if err := service.EapolState.Event("start_auth"); err != nil {
346 logger.WithFields(log.Fields{
347 "OnuId": onu.ID,
348 "IntfId": onu.PonPortID,
349 "OnuSn": onu.Sn(),
350 "Service": service.Name,
351 }).Errorf("Cannot restart authenticaton for Service: %s", err.Error())
352 errors = append(errors, fmt.Sprintf("%s: %s", service.Name, err.Error()))
353 success = false
354 }
Matteo Scandolo618a6582020-09-09 12:21:29 -0700355 startedOn = append(startedOn, service.Name)
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700356 }
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700357 }
358
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700359 if success {
360 res.StatusCode = int32(codes.OK)
Matteo Scandoloc08a6082021-02-05 11:12:01 -0800361 if len(startedOn) > 0 {
362 res.Message = fmt.Sprintf("Authentication restarted on Services %s for ONU %s.",
363 fmt.Sprintf("%v", startedOn), onu.Sn())
364 } else {
365 res.Message = "No service requires EAPOL"
366 }
367
368 logger.WithFields(log.Fields{
369 "OnuSn": req.SerialNumber,
370 "Message": res.Message,
371 }).Info("Processed EAPOL restart request for ONU")
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700372 } else {
373 res.StatusCode = int32(codes.FailedPrecondition)
374 res.Message = fmt.Sprintf("%v", errors)
Matteo Scandoloc08a6082021-02-05 11:12:01 -0800375 logger.WithFields(log.Fields{
376 "OnuSn": req.SerialNumber,
377 "Message": res.Message,
378 }).Error("Error while processing DHCP restart request for ONU")
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700379 }
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700380
381 return res, nil
382}
383
384func (s BBSimServer) RestartDhcp(ctx context.Context, req *bbsim.ONURequest) (*bbsim.Response, error) {
385 res := &bbsim.Response{}
386
387 logger.WithFields(log.Fields{
388 "OnuSn": req.SerialNumber,
389 }).Infof("Received request to restart DHCP on ONU")
390
391 olt := devices.GetOLT()
392
393 onu, err := olt.FindOnuBySn(req.SerialNumber)
394
395 if err != nil {
396 res.StatusCode = int32(codes.NotFound)
397 res.Message = err.Error()
398 return res, err
399 }
400
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700401 errors := []string{}
Matteo Scandolo618a6582020-09-09 12:21:29 -0700402 startedOn := []string{}
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700403 success := true
404
405 for _, s := range onu.Services {
406 service := s.(*devices.Service)
407 if service.NeedsDhcp {
408
409 if err := service.DHCPState.Event("start_dhcp"); err != nil {
410 logger.WithFields(log.Fields{
411 "OnuId": onu.ID,
412 "IntfId": onu.PonPortID,
413 "OnuSn": onu.Sn(),
414 "Service": service.Name,
415 }).Errorf("Cannot restart DHCP for Service: %s", err.Error())
416 errors = append(errors, fmt.Sprintf("%s: %s", service.Name, err.Error()))
417 success = false
418 }
Matteo Scandolo618a6582020-09-09 12:21:29 -0700419 startedOn = append(startedOn, service.Name)
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700420 }
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700421 }
422
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700423 if success {
424 res.StatusCode = int32(codes.OK)
Matteo Scandoloc08a6082021-02-05 11:12:01 -0800425 if len(startedOn) > 0 {
426 res.Message = fmt.Sprintf("DHCP restarted on Services %s for ONU %s.",
427 fmt.Sprintf("%v", startedOn), onu.Sn())
428
429 } else {
430 res.Message = "No service requires DHCP"
431 }
432 logger.WithFields(log.Fields{
433 "OnuSn": req.SerialNumber,
434 "Message": res.Message,
435 }).Info("Processed DHCP restart request for ONU")
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700436 } else {
437 res.StatusCode = int32(codes.FailedPrecondition)
438 res.Message = fmt.Sprintf("%v", errors)
Matteo Scandoloc08a6082021-02-05 11:12:01 -0800439 logger.WithFields(log.Fields{
440 "OnuSn": req.SerialNumber,
441 "Message": res.Message,
442 }).Error("Error while processing DHCP restart request for ONU")
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700443 }
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700444
445 return res, nil
446}
Anand S Katti09541352020-01-29 15:54:01 +0530447
Pragya Arya8bdb4532020-03-02 17:08:09 +0530448// GetFlows for OLT/ONUs
449func (s BBSimServer) GetFlows(ctx context.Context, req *bbsim.ONURequest) (*bbsim.Flows, error) {
450 logger.WithFields(log.Fields{
451 "OnuSn": req.SerialNumber,
452 }).Info("Received GetFlows request")
453
454 olt := devices.GetOLT()
455 res := &bbsim.Flows{}
456
457 if req.SerialNumber == "" {
Andrea Campanellabe8e12f2020-12-14 18:43:41 +0100458 olt.Flows.Range(func(flowKey, flow interface{}) bool {
459 flowObj := flow.(openolt.Flow)
460 res.Flows = append(res.Flows, &flowObj)
461 return true
462 })
463 res.FlowCount = uint32(len(res.Flows))
Pragya Arya8bdb4532020-03-02 17:08:09 +0530464 } else {
465 onu, err := olt.FindOnuBySn(req.SerialNumber)
466 if err != nil {
467 logger.WithFields(log.Fields{
468 "OnuSn": req.SerialNumber,
469 }).Error("Can't get ONU in GetFlows request")
470 return nil, err
471 }
472 for _, flowKey := range onu.Flows {
Andrea Campanellabe8e12f2020-12-14 18:43:41 +0100473 flow, _ := olt.Flows.Load(flowKey)
474 flowObj := flow.(openolt.Flow)
475 res.Flows = append(res.Flows, &flowObj)
Pragya Arya8bdb4532020-03-02 17:08:09 +0530476 }
477 res.FlowCount = uint32(len(onu.Flows))
478 }
479 return res, nil
480}
481
Anand S Katti09541352020-01-29 15:54:01 +0530482func (s BBSimServer) GetOnuTrafficSchedulers(ctx context.Context, req *bbsim.ONURequest) (*bbsim.ONUTrafficSchedulers, error) {
483 olt := devices.GetOLT()
484 ts := bbsim.ONUTrafficSchedulers{}
485
486 onu, err := olt.FindOnuBySn(req.SerialNumber)
487 if err != nil {
488 return &ts, err
489 }
490
491 if onu.TrafficSchedulers != nil {
492 ts.TraffSchedulers = onu.TrafficSchedulers
493 return &ts, nil
494 } else {
495 ts.TraffSchedulers = nil
496 return &ts, nil
497 }
498}
Pragya Aryabd731ec2020-02-11 16:38:17 +0530499
500func handlePoweronONU(onu *devices.Onu) (*bbsim.Response, error) {
501 res := &bbsim.Response{}
Pragya Aryabd731ec2020-02-11 16:38:17 +0530502
Matteo Scandolof9d43412021-01-12 11:11:34 -0800503 if err := onu.HandlePowerOnONU(); err != nil {
Pragya Aryabd731ec2020-02-11 16:38:17 +0530504 res.StatusCode = int32(codes.FailedPrecondition)
505 res.Message = err.Error()
506 return res, err
507 }
508
Pragya Aryabd731ec2020-02-11 16:38:17 +0530509 res.StatusCode = int32(codes.OK)
510 res.Message = fmt.Sprintf("ONU %s successfully powered on.", onu.Sn())
511
512 return res, nil
513}
514
515func handleShutdownONU(onu *devices.Onu) (*bbsim.Response, error) {
516 res := &bbsim.Response{}
Pragya Aryabd731ec2020-02-11 16:38:17 +0530517
Matteo Scandolof9d43412021-01-12 11:11:34 -0800518 if err := onu.HandleShutdownONU(); err != nil {
Pragya Aryabd731ec2020-02-11 16:38:17 +0530519 res.StatusCode = int32(codes.FailedPrecondition)
520 res.Message = err.Error()
521 return res, err
522 }
523
524 res.StatusCode = int32(codes.OK)
525 res.Message = fmt.Sprintf("ONU %s successfully shut down.", onu.Sn())
526
527 return res, nil
528}