blob: 8f606d0ee3825e4c7f17ad8734e5dee7673d9736 [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{
Matteo Scandolocedde462021-03-09 17:37:16 -080040 ID: int32(o.ID),
41 SerialNumber: o.Sn(),
42 OperState: o.OperState.Current(),
43 InternalState: o.InternalState.Current(),
44 PonPortID: int32(o.PonPortID),
45 PortNo: int32(o.PortNo),
46 Services: convertBBsimServicesToProtoServices(o.Services),
47 ImageSoftwareReceivedSections: int32(o.ImageSoftwareReceivedSections),
48 ImageSoftwareExpectedSections: int32(o.ImageSoftwareExpectedSections),
49 ActiveImageEntityId: int32(o.ActiveImageEntityId),
50 CommittedImageEntityId: int32(o.CommittedImageEntityId),
Matteo Scandolo10f965c2019-09-24 10:40:46 -070051 }
52 onus.Items = append(onus.Items, &onu)
53 }
54 }
55 return &onus, nil
56}
57
Matteo Scandolod2ca2c72019-10-04 16:50:22 -070058func (s BBSimServer) GetONU(ctx context.Context, req *bbsim.ONURequest) (*bbsim.ONU, error) {
59 olt := devices.GetOLT()
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -070060 onu, err := olt.FindOnuBySn(req.SerialNumber)
Matteo Scandolod2ca2c72019-10-04 16:50:22 -070061
62 if err != nil {
63 res := bbsim.ONU{}
64 return &res, err
65 }
66
67 res := bbsim.ONU{
68 ID: int32(onu.ID),
69 SerialNumber: onu.Sn(),
70 OperState: onu.OperState.Current(),
71 InternalState: onu.InternalState.Current(),
72 PonPortID: int32(onu.PonPortID),
Matteo Scandolo27428702019-10-11 16:21:16 -070073 PortNo: int32(onu.PortNo),
Matteo Scandolo4a036262020-08-17 15:56:13 -070074 Services: convertBBsimServicesToProtoServices(onu.Services),
Matteo Scandolod2ca2c72019-10-04 16:50:22 -070075 }
76 return &res, nil
77}
78
Pragya Aryabd731ec2020-02-11 16:38:17 +053079// ShutdownONU sends DyingGasp indication for specified ONUs and mark ONUs as disabled.
Matteo Scandolo10f965c2019-09-24 10:40:46 -070080func (s BBSimServer) ShutdownONU(ctx context.Context, req *bbsim.ONURequest) (*bbsim.Response, error) {
Anand S Katti09541352020-01-29 15:54:01 +053081 // 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 -070082 // is this the only way to do? Should we address other cases?
83 // Investigate what happens when:
84 // - a fiber is pulled
85 // - ONU malfunction
86 // - ONU shutdown
Matteo Scandolo10f965c2019-09-24 10:40:46 -070087 logger.WithFields(log.Fields{
88 "OnuSn": req.SerialNumber,
89 }).Infof("Received request to shutdown ONU")
90
Pragya Aryabd731ec2020-02-11 16:38:17 +053091 res := &bbsim.Response{}
Matteo Scandolo10f965c2019-09-24 10:40:46 -070092 olt := devices.GetOLT()
93
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -070094 onu, err := olt.FindOnuBySn(req.SerialNumber)
Matteo Scandolo10f965c2019-09-24 10:40:46 -070095 if err != nil {
96 res.StatusCode = int32(codes.NotFound)
97 res.Message = err.Error()
98 return res, err
99 }
100
Pragya Aryabd731ec2020-02-11 16:38:17 +0530101 return handleShutdownONU(onu)
102}
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700103
Pragya Aryabd731ec2020-02-11 16:38:17 +0530104// ShutdownONUsOnPON sends DyingGasp indication for all ONUs under specified PON port
105func (s BBSimServer) ShutdownONUsOnPON(ctx context.Context, req *bbsim.PONRequest) (*bbsim.Response, error) {
106 logger.WithFields(log.Fields{
107 "IntfId": req.PonPortId,
108 }).Infof("Received request to shutdown all ONUs on PON")
Matteo Scandolod7cc6d32020-02-26 16:51:12 -0800109
Pragya Aryabd731ec2020-02-11 16:38:17 +0530110 res := &bbsim.Response{}
111 olt := devices.GetOLT()
112 pon, _ := olt.GetPonById(req.PonPortId)
Matteo Scandolod7cc6d32020-02-26 16:51:12 -0800113
Pragya Aryabd731ec2020-02-11 16:38:17 +0530114 go func() {
115 for _, onu := range pon.Onus {
116 res, _ = handleShutdownONU(onu)
117 }
118 }()
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700119 res.StatusCode = int32(codes.OK)
Pragya Aryabd731ec2020-02-11 16:38:17 +0530120 res.Message = fmt.Sprintf("Request accepted for shutdown all ONUs on PON port %d", pon.ID)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700121
122 return res, nil
123}
124
Pragya Aryabd731ec2020-02-11 16:38:17 +0530125// ShutdownAllONUs sends DyingGasp indication for all ONUs and mark ONUs as disabled.
126func (s BBSimServer) ShutdownAllONUs(context.Context, *bbsim.Empty) (*bbsim.Response, error) {
127 logger.Infof("Received request to shutdown all ONUs")
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700128 res := &bbsim.Response{}
Pragya Aryabd731ec2020-02-11 16:38:17 +0530129 olt := devices.GetOLT()
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700130
Pragya Aryabd731ec2020-02-11 16:38:17 +0530131 go func() {
132 for _, pon := range olt.Pons {
133 for _, onu := range pon.Onus {
134 res, _ = handleShutdownONU(onu)
135 }
136 }
137 }()
138 res.StatusCode = int32(codes.OK)
139 res.Message = fmt.Sprintf("Request Accepted for shutdown all ONUs in OLT %d", olt.ID)
140
141 return res, nil
142}
143
144// PoweronONU simulates ONU power on and start sending discovery indications to VOLTHA
145func (s BBSimServer) PoweronONU(ctx context.Context, req *bbsim.ONURequest) (*bbsim.Response, error) {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700146 logger.WithFields(log.Fields{
147 "OnuSn": req.SerialNumber,
148 }).Infof("Received request to poweron ONU")
149
Pragya Aryabd731ec2020-02-11 16:38:17 +0530150 res := &bbsim.Response{}
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700151 olt := devices.GetOLT()
152
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700153 onu, err := olt.FindOnuBySn(req.SerialNumber)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700154 if err != nil {
155 res.StatusCode = int32(codes.NotFound)
156 res.Message = err.Error()
157 return res, err
158 }
159
Pragya Arya2225f202020-01-29 18:05:01 +0530160 pon, _ := olt.GetPonById(onu.PonPortID)
161 if pon.InternalState.Current() != "enabled" {
162 err := fmt.Errorf("PON port %d not enabled", onu.PonPortID)
163 logger.WithFields(log.Fields{
164 "OnuId": onu.ID,
165 "IntfId": onu.PonPortID,
166 "OnuSn": onu.Sn(),
167 }).Errorf("Cannot poweron ONU: %s", err.Error())
168
169 res.StatusCode = int32(codes.FailedPrecondition)
170 res.Message = err.Error()
171 return res, err
172 }
173
Pragya Aryabd731ec2020-02-11 16:38:17 +0530174 return handlePoweronONU(onu)
175}
176
177// PoweronONUsOnPON simulates ONU power on for all ONUs under specified PON port
178func (s BBSimServer) PoweronONUsOnPON(ctx context.Context, req *bbsim.PONRequest) (*bbsim.Response, error) {
179 logger.WithFields(log.Fields{
180 "IntfId": req.PonPortId,
181 }).Infof("Received request to poweron all ONUs on PON")
182
183 res := &bbsim.Response{}
184 olt := devices.GetOLT()
185
186 pon, _ := olt.GetPonById(req.PonPortId)
187 if pon.InternalState.Current() != "enabled" {
188 err := fmt.Errorf("PON port %d not enabled", pon.ID)
189 logger.WithFields(log.Fields{
190 "IntfId": pon.ID,
191 }).Errorf("Cannot poweron ONUs on PON: %s", err.Error())
192
193 res.StatusCode = int32(codes.FailedPrecondition)
194 res.Message = err.Error()
195 return res, err
196 }
197
198 go func() {
199 for _, onu := range pon.Onus {
200 res, _ = handlePoweronONU(onu)
Pragya Arya2225f202020-01-29 18:05:01 +0530201 }
Pragya Aryabd731ec2020-02-11 16:38:17 +0530202 }()
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700203 res.StatusCode = int32(codes.OK)
Pragya Aryabd731ec2020-02-11 16:38:17 +0530204 res.Message = fmt.Sprintf("Request Accepted for power on all ONUs on PON port %d", pon.ID)
205
206 return res, nil
207}
208
209// PoweronAllONUs simulates ONU power on for all ONUs on all PON ports
210func (s BBSimServer) PoweronAllONUs(context.Context, *bbsim.Empty) (*bbsim.Response, error) {
211 logger.Infof("Received request to poweron all ONUs")
212
213 res := &bbsim.Response{}
214 olt := devices.GetOLT()
215
216 go func() {
217 for _, pon := range olt.Pons {
218 if pon.InternalState.Current() == "enabled" {
219 for _, onu := range pon.Onus {
220 res, _ = handlePoweronONU(onu)
221 }
222 }
223 }
224 }()
225 res.StatusCode = int32(codes.OK)
226 res.Message = fmt.Sprintf("Request Accepted for power on all ONUs in OLT %d", olt.ID)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700227
228 return res, nil
229}
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700230
Arjun E K57a7fcb2020-01-30 06:44:45 +0000231func (s BBSimServer) ChangeIgmpState(ctx context.Context, req *bbsim.IgmpRequest) (*bbsim.Response, error) {
Matteo Scandolo618a6582020-09-09 12:21:29 -0700232
233 // TODO check that the ONU is enabled and the services are initialized before changing the state
234
Arjun E K57a7fcb2020-01-30 06:44:45 +0000235 res := &bbsim.Response{}
236
237 logger.WithFields(log.Fields{
Onur Kalinagac9f9faca2021-01-21 14:04:34 +0000238 "OnuSn": req.OnuReq.SerialNumber,
239 "subAction": req.SubActionVal,
240 "GroupAddress": req.GroupAddress,
Matteo Scandoloc08a6082021-02-05 11:12:01 -0800241 }).Info("Received igmp request for ONU")
Arjun E K57a7fcb2020-01-30 06:44:45 +0000242
243 olt := devices.GetOLT()
244 onu, err := olt.FindOnuBySn(req.OnuReq.SerialNumber)
245
246 if err != nil {
247 res.StatusCode = int32(codes.NotFound)
248 res.Message = err.Error()
Matteo Scandoloc08a6082021-02-05 11:12:01 -0800249 logger.WithFields(log.Fields{
250 "OnuSn": req.OnuReq.SerialNumber,
251 "subAction": req.SubActionVal,
252 "GroupAddress": req.GroupAddress,
253 }).Warn("ONU not found for sending igmp packet.")
Arjun E K57a7fcb2020-01-30 06:44:45 +0000254 return res, err
255 } else {
256 event := ""
257 switch req.SubActionVal {
258 case bbsim.SubActionTypes_JOIN:
259 event = "igmp_join_start"
260 case bbsim.SubActionTypes_LEAVE:
261 event = "igmp_leave"
Anand S Katti09541352020-01-29 15:54:01 +0530262 case bbsim.SubActionTypes_JOINV3:
263 event = "igmp_join_startv3"
Arjun E K57a7fcb2020-01-30 06:44:45 +0000264 }
265
Matteo Scandolo618a6582020-09-09 12:21:29 -0700266 errors := []string{}
267 startedOn := []string{}
268 success := true
269
270 for _, s := range onu.Services {
271 service := s.(*devices.Service)
272 if service.NeedsIgmp {
273
274 logger.WithFields(log.Fields{
275 "OnuId": onu.ID,
276 "IntfId": onu.PonPortID,
277 "OnuSn": onu.Sn(),
278 "Service": service.Name,
279 }).Debugf("Sending %s event on Service %s", event, service.Name)
280
Matteo Scandolof9d43412021-01-12 11:11:34 -0800281 if err := service.IGMPState.Event(event, types.IgmpMessage{GroupAddress: req.GroupAddress}); err != nil {
Matteo Scandolo618a6582020-09-09 12:21:29 -0700282 logger.WithFields(log.Fields{
283 "OnuId": onu.ID,
284 "IntfId": onu.PonPortID,
285 "OnuSn": onu.Sn(),
286 "Service": service.Name,
287 }).Errorf("IGMP request failed: %s", err.Error())
288 errors = append(errors, fmt.Sprintf("%s: %s", service.Name, err.Error()))
289 success = false
290 }
291 startedOn = append(startedOn, service.Name)
292 }
293 }
294
295 if success {
296 res.StatusCode = int32(codes.OK)
Matteo Scandoloc08a6082021-02-05 11:12:01 -0800297 if len(startedOn) > 0 {
298 res.Message = fmt.Sprintf("IGMP %s sent on Services %s for ONU %s.",
299 event, fmt.Sprintf("%v", startedOn), onu.Sn())
300 } else {
301 res.Message = "No service requires IGMP"
302 }
303 logger.WithFields(log.Fields{
304 "OnuSn": req.OnuReq.SerialNumber,
305 "subAction": req.SubActionVal,
306 "GroupAddress": req.GroupAddress,
307 "Message": res.Message,
308 }).Info("Processed IGMP request for ONU")
Matteo Scandolo618a6582020-09-09 12:21:29 -0700309 } else {
Arjun E K57a7fcb2020-01-30 06:44:45 +0000310 res.StatusCode = int32(codes.FailedPrecondition)
Matteo Scandolo618a6582020-09-09 12:21:29 -0700311 res.Message = fmt.Sprintf("%v", errors)
Matteo Scandoloc08a6082021-02-05 11:12:01 -0800312 logger.WithFields(log.Fields{
313 "OnuSn": req.OnuReq.SerialNumber,
314 "subAction": req.SubActionVal,
315 "GroupAddress": req.GroupAddress,
316 "Message": res.Message,
317 }).Error("Error while processing IGMP request for ONU")
Arjun E K57a7fcb2020-01-30 06:44:45 +0000318 }
Matteo Scandoloc08a6082021-02-05 11:12:01 -0800319
Arjun E K57a7fcb2020-01-30 06:44:45 +0000320 }
321
322 return res, nil
323}
324
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700325func (s BBSimServer) RestartEapol(ctx context.Context, req *bbsim.ONURequest) (*bbsim.Response, error) {
326 res := &bbsim.Response{}
327
328 logger.WithFields(log.Fields{
329 "OnuSn": req.SerialNumber,
330 }).Infof("Received request to restart authentication ONU")
331
332 olt := devices.GetOLT()
333
334 onu, err := olt.FindOnuBySn(req.SerialNumber)
335
336 if err != nil {
337 res.StatusCode = int32(codes.NotFound)
338 res.Message = err.Error()
339 return res, err
340 }
341
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700342 errors := []string{}
Matteo Scandolo618a6582020-09-09 12:21:29 -0700343 startedOn := []string{}
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700344 success := true
345
346 for _, s := range onu.Services {
347 service := s.(*devices.Service)
348 if service.NeedsEapol {
349 if err := service.EapolState.Event("start_auth"); err != nil {
350 logger.WithFields(log.Fields{
351 "OnuId": onu.ID,
352 "IntfId": onu.PonPortID,
353 "OnuSn": onu.Sn(),
354 "Service": service.Name,
355 }).Errorf("Cannot restart authenticaton for Service: %s", err.Error())
356 errors = append(errors, fmt.Sprintf("%s: %s", service.Name, err.Error()))
357 success = false
358 }
Matteo Scandolo618a6582020-09-09 12:21:29 -0700359 startedOn = append(startedOn, service.Name)
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700360 }
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700361 }
362
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700363 if success {
364 res.StatusCode = int32(codes.OK)
Matteo Scandoloc08a6082021-02-05 11:12:01 -0800365 if len(startedOn) > 0 {
366 res.Message = fmt.Sprintf("Authentication restarted on Services %s for ONU %s.",
367 fmt.Sprintf("%v", startedOn), onu.Sn())
368 } else {
369 res.Message = "No service requires EAPOL"
370 }
371
372 logger.WithFields(log.Fields{
373 "OnuSn": req.SerialNumber,
374 "Message": res.Message,
375 }).Info("Processed EAPOL restart request for ONU")
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700376 } else {
377 res.StatusCode = int32(codes.FailedPrecondition)
378 res.Message = fmt.Sprintf("%v", errors)
Matteo Scandoloc08a6082021-02-05 11:12:01 -0800379 logger.WithFields(log.Fields{
380 "OnuSn": req.SerialNumber,
381 "Message": res.Message,
382 }).Error("Error while processing DHCP restart request for ONU")
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700383 }
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700384
385 return res, nil
386}
387
388func (s BBSimServer) RestartDhcp(ctx context.Context, req *bbsim.ONURequest) (*bbsim.Response, error) {
389 res := &bbsim.Response{}
390
391 logger.WithFields(log.Fields{
392 "OnuSn": req.SerialNumber,
393 }).Infof("Received request to restart DHCP on ONU")
394
395 olt := devices.GetOLT()
396
397 onu, err := olt.FindOnuBySn(req.SerialNumber)
398
399 if err != nil {
400 res.StatusCode = int32(codes.NotFound)
401 res.Message = err.Error()
402 return res, err
403 }
404
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700405 errors := []string{}
Matteo Scandolo618a6582020-09-09 12:21:29 -0700406 startedOn := []string{}
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700407 success := true
408
409 for _, s := range onu.Services {
410 service := s.(*devices.Service)
411 if service.NeedsDhcp {
412
413 if err := service.DHCPState.Event("start_dhcp"); err != nil {
414 logger.WithFields(log.Fields{
415 "OnuId": onu.ID,
416 "IntfId": onu.PonPortID,
417 "OnuSn": onu.Sn(),
418 "Service": service.Name,
419 }).Errorf("Cannot restart DHCP for Service: %s", err.Error())
420 errors = append(errors, fmt.Sprintf("%s: %s", service.Name, err.Error()))
421 success = false
422 }
Matteo Scandolo618a6582020-09-09 12:21:29 -0700423 startedOn = append(startedOn, service.Name)
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700424 }
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700425 }
426
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700427 if success {
428 res.StatusCode = int32(codes.OK)
Matteo Scandoloc08a6082021-02-05 11:12:01 -0800429 if len(startedOn) > 0 {
430 res.Message = fmt.Sprintf("DHCP restarted on Services %s for ONU %s.",
431 fmt.Sprintf("%v", startedOn), onu.Sn())
432
433 } else {
434 res.Message = "No service requires DHCP"
435 }
436 logger.WithFields(log.Fields{
437 "OnuSn": req.SerialNumber,
438 "Message": res.Message,
439 }).Info("Processed DHCP restart request for ONU")
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700440 } else {
441 res.StatusCode = int32(codes.FailedPrecondition)
442 res.Message = fmt.Sprintf("%v", errors)
Matteo Scandoloc08a6082021-02-05 11:12:01 -0800443 logger.WithFields(log.Fields{
444 "OnuSn": req.SerialNumber,
445 "Message": res.Message,
446 }).Error("Error while processing DHCP restart request for ONU")
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700447 }
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700448
449 return res, nil
450}
Anand S Katti09541352020-01-29 15:54:01 +0530451
Pragya Arya8bdb4532020-03-02 17:08:09 +0530452// GetFlows for OLT/ONUs
453func (s BBSimServer) GetFlows(ctx context.Context, req *bbsim.ONURequest) (*bbsim.Flows, error) {
454 logger.WithFields(log.Fields{
455 "OnuSn": req.SerialNumber,
456 }).Info("Received GetFlows request")
457
458 olt := devices.GetOLT()
459 res := &bbsim.Flows{}
460
461 if req.SerialNumber == "" {
Andrea Campanellabe8e12f2020-12-14 18:43:41 +0100462 olt.Flows.Range(func(flowKey, flow interface{}) bool {
463 flowObj := flow.(openolt.Flow)
464 res.Flows = append(res.Flows, &flowObj)
465 return true
466 })
467 res.FlowCount = uint32(len(res.Flows))
Pragya Arya8bdb4532020-03-02 17:08:09 +0530468 } else {
469 onu, err := olt.FindOnuBySn(req.SerialNumber)
470 if err != nil {
471 logger.WithFields(log.Fields{
472 "OnuSn": req.SerialNumber,
473 }).Error("Can't get ONU in GetFlows request")
474 return nil, err
475 }
476 for _, flowKey := range onu.Flows {
Andrea Campanellabe8e12f2020-12-14 18:43:41 +0100477 flow, _ := olt.Flows.Load(flowKey)
478 flowObj := flow.(openolt.Flow)
479 res.Flows = append(res.Flows, &flowObj)
Pragya Arya8bdb4532020-03-02 17:08:09 +0530480 }
481 res.FlowCount = uint32(len(onu.Flows))
482 }
483 return res, nil
484}
485
Anand S Katti09541352020-01-29 15:54:01 +0530486func (s BBSimServer) GetOnuTrafficSchedulers(ctx context.Context, req *bbsim.ONURequest) (*bbsim.ONUTrafficSchedulers, error) {
487 olt := devices.GetOLT()
488 ts := bbsim.ONUTrafficSchedulers{}
489
490 onu, err := olt.FindOnuBySn(req.SerialNumber)
491 if err != nil {
492 return &ts, err
493 }
494
495 if onu.TrafficSchedulers != nil {
496 ts.TraffSchedulers = onu.TrafficSchedulers
497 return &ts, nil
498 } else {
499 ts.TraffSchedulers = nil
500 return &ts, nil
501 }
502}
Pragya Aryabd731ec2020-02-11 16:38:17 +0530503
504func handlePoweronONU(onu *devices.Onu) (*bbsim.Response, error) {
505 res := &bbsim.Response{}
Pragya Aryabd731ec2020-02-11 16:38:17 +0530506
Matteo Scandolof9d43412021-01-12 11:11:34 -0800507 if err := onu.HandlePowerOnONU(); err != nil {
Pragya Aryabd731ec2020-02-11 16:38:17 +0530508 res.StatusCode = int32(codes.FailedPrecondition)
509 res.Message = err.Error()
510 return res, err
511 }
512
Pragya Aryabd731ec2020-02-11 16:38:17 +0530513 res.StatusCode = int32(codes.OK)
514 res.Message = fmt.Sprintf("ONU %s successfully powered on.", onu.Sn())
515
516 return res, nil
517}
518
519func handleShutdownONU(onu *devices.Onu) (*bbsim.Response, error) {
520 res := &bbsim.Response{}
Pragya Aryabd731ec2020-02-11 16:38:17 +0530521
Matteo Scandolof9d43412021-01-12 11:11:34 -0800522 if err := onu.HandleShutdownONU(); err != nil {
Pragya Aryabd731ec2020-02-11 16:38:17 +0530523 res.StatusCode = int32(codes.FailedPrecondition)
524 res.Message = err.Error()
525 return res, err
526 }
527
528 res.StatusCode = int32(codes.OK)
529 res.Message = fmt.Sprintf("ONU %s successfully shut down.", onu.Sn())
530
531 return res, nil
532}