blob: 10d671d0763f065f9d57066005c614a27a56b9bf [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"
Pragya Arya1d5ffb82020-03-20 18:51:37 +053022
Matteo Scandolo10f965c2019-09-24 10:40:46 -070023 "github.com/opencord/bbsim/api/bbsim"
Matteo Scandolod7cc6d32020-02-26 16:51:12 -080024 "github.com/opencord/bbsim/internal/bbsim/alarmsim"
Matteo Scandolo10f965c2019-09-24 10:40:46 -070025 "github.com/opencord/bbsim/internal/bbsim/devices"
26 log "github.com/sirupsen/logrus"
27 "google.golang.org/grpc/codes"
28)
29
30func (s BBSimServer) GetONUs(ctx context.Context, req *bbsim.Empty) (*bbsim.ONUs, error) {
31 olt := devices.GetOLT()
32 onus := bbsim.ONUs{
33 Items: []*bbsim.ONU{},
34 }
35
36 for _, pon := range olt.Pons {
37 for _, o := range pon.Onus {
38 onu := bbsim.ONU{
39 ID: int32(o.ID),
40 SerialNumber: o.Sn(),
41 OperState: o.OperState.Current(),
42 InternalState: o.InternalState.Current(),
43 PonPortID: int32(o.PonPortID),
Matteo Scandolo27428702019-10-11 16:21:16 -070044 PortNo: int32(o.PortNo),
Matteo Scandolo4a036262020-08-17 15:56:13 -070045 Services: convertBBsimServicesToProtoServices(o.Services),
Matteo Scandolo10f965c2019-09-24 10:40:46 -070046 }
47 onus.Items = append(onus.Items, &onu)
48 }
49 }
50 return &onus, nil
51}
52
Matteo Scandolod2ca2c72019-10-04 16:50:22 -070053func (s BBSimServer) GetONU(ctx context.Context, req *bbsim.ONURequest) (*bbsim.ONU, error) {
54 olt := devices.GetOLT()
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -070055 onu, err := olt.FindOnuBySn(req.SerialNumber)
Matteo Scandolod2ca2c72019-10-04 16:50:22 -070056
57 if err != nil {
58 res := bbsim.ONU{}
59 return &res, err
60 }
61
62 res := bbsim.ONU{
63 ID: int32(onu.ID),
64 SerialNumber: onu.Sn(),
65 OperState: onu.OperState.Current(),
66 InternalState: onu.InternalState.Current(),
67 PonPortID: int32(onu.PonPortID),
Matteo Scandolo27428702019-10-11 16:21:16 -070068 PortNo: int32(onu.PortNo),
Matteo Scandolo4a036262020-08-17 15:56:13 -070069 Services: convertBBsimServicesToProtoServices(onu.Services),
Matteo Scandolod2ca2c72019-10-04 16:50:22 -070070 }
71 return &res, nil
72}
73
Pragya Aryabd731ec2020-02-11 16:38:17 +053074// ShutdownONU sends DyingGasp indication for specified ONUs and mark ONUs as disabled.
Matteo Scandolo10f965c2019-09-24 10:40:46 -070075func (s BBSimServer) ShutdownONU(ctx context.Context, req *bbsim.ONURequest) (*bbsim.Response, error) {
Anand S Katti09541352020-01-29 15:54:01 +053076 // 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 -070077 // is this the only way to do? Should we address other cases?
78 // Investigate what happens when:
79 // - a fiber is pulled
80 // - ONU malfunction
81 // - ONU shutdown
Matteo Scandolo10f965c2019-09-24 10:40:46 -070082 logger.WithFields(log.Fields{
83 "OnuSn": req.SerialNumber,
84 }).Infof("Received request to shutdown ONU")
85
Pragya Aryabd731ec2020-02-11 16:38:17 +053086 res := &bbsim.Response{}
Matteo Scandolo10f965c2019-09-24 10:40:46 -070087 olt := devices.GetOLT()
88
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -070089 onu, err := olt.FindOnuBySn(req.SerialNumber)
Matteo Scandolo10f965c2019-09-24 10:40:46 -070090 if err != nil {
91 res.StatusCode = int32(codes.NotFound)
92 res.Message = err.Error()
93 return res, err
94 }
95
Pragya Aryabd731ec2020-02-11 16:38:17 +053096 return handleShutdownONU(onu)
97}
Matteo Scandolo10f965c2019-09-24 10:40:46 -070098
Pragya Aryabd731ec2020-02-11 16:38:17 +053099// ShutdownONUsOnPON sends DyingGasp indication for all ONUs under specified PON port
100func (s BBSimServer) ShutdownONUsOnPON(ctx context.Context, req *bbsim.PONRequest) (*bbsim.Response, error) {
101 logger.WithFields(log.Fields{
102 "IntfId": req.PonPortId,
103 }).Infof("Received request to shutdown all ONUs on PON")
Matteo Scandolod7cc6d32020-02-26 16:51:12 -0800104
Pragya Aryabd731ec2020-02-11 16:38:17 +0530105 res := &bbsim.Response{}
106 olt := devices.GetOLT()
107 pon, _ := olt.GetPonById(req.PonPortId)
Matteo Scandolod7cc6d32020-02-26 16:51:12 -0800108
Pragya Aryabd731ec2020-02-11 16:38:17 +0530109 go func() {
110 for _, onu := range pon.Onus {
111 res, _ = handleShutdownONU(onu)
112 }
113 }()
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700114 res.StatusCode = int32(codes.OK)
Pragya Aryabd731ec2020-02-11 16:38:17 +0530115 res.Message = fmt.Sprintf("Request accepted for shutdown all ONUs on PON port %d", pon.ID)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700116
117 return res, nil
118}
119
Pragya Aryabd731ec2020-02-11 16:38:17 +0530120// ShutdownAllONUs sends DyingGasp indication for all ONUs and mark ONUs as disabled.
121func (s BBSimServer) ShutdownAllONUs(context.Context, *bbsim.Empty) (*bbsim.Response, error) {
122 logger.Infof("Received request to shutdown all ONUs")
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700123 res := &bbsim.Response{}
Pragya Aryabd731ec2020-02-11 16:38:17 +0530124 olt := devices.GetOLT()
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700125
Pragya Aryabd731ec2020-02-11 16:38:17 +0530126 go func() {
127 for _, pon := range olt.Pons {
128 for _, onu := range pon.Onus {
129 res, _ = handleShutdownONU(onu)
130 }
131 }
132 }()
133 res.StatusCode = int32(codes.OK)
134 res.Message = fmt.Sprintf("Request Accepted for shutdown all ONUs in OLT %d", olt.ID)
135
136 return res, nil
137}
138
139// PoweronONU simulates ONU power on and start sending discovery indications to VOLTHA
140func (s BBSimServer) PoweronONU(ctx context.Context, req *bbsim.ONURequest) (*bbsim.Response, error) {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700141 logger.WithFields(log.Fields{
142 "OnuSn": req.SerialNumber,
143 }).Infof("Received request to poweron ONU")
144
Pragya Aryabd731ec2020-02-11 16:38:17 +0530145 res := &bbsim.Response{}
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700146 olt := devices.GetOLT()
147
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700148 onu, err := olt.FindOnuBySn(req.SerialNumber)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700149 if err != nil {
150 res.StatusCode = int32(codes.NotFound)
151 res.Message = err.Error()
152 return res, err
153 }
154
Pragya Arya2225f202020-01-29 18:05:01 +0530155 pon, _ := olt.GetPonById(onu.PonPortID)
156 if pon.InternalState.Current() != "enabled" {
157 err := fmt.Errorf("PON port %d not enabled", onu.PonPortID)
158 logger.WithFields(log.Fields{
159 "OnuId": onu.ID,
160 "IntfId": onu.PonPortID,
161 "OnuSn": onu.Sn(),
162 }).Errorf("Cannot poweron ONU: %s", err.Error())
163
164 res.StatusCode = int32(codes.FailedPrecondition)
165 res.Message = err.Error()
166 return res, err
167 }
168
Pragya Aryabd731ec2020-02-11 16:38:17 +0530169 return handlePoweronONU(onu)
170}
171
172// PoweronONUsOnPON simulates ONU power on for all ONUs under specified PON port
173func (s BBSimServer) PoweronONUsOnPON(ctx context.Context, req *bbsim.PONRequest) (*bbsim.Response, error) {
174 logger.WithFields(log.Fields{
175 "IntfId": req.PonPortId,
176 }).Infof("Received request to poweron all ONUs on PON")
177
178 res := &bbsim.Response{}
179 olt := devices.GetOLT()
180
181 pon, _ := olt.GetPonById(req.PonPortId)
182 if pon.InternalState.Current() != "enabled" {
183 err := fmt.Errorf("PON port %d not enabled", pon.ID)
184 logger.WithFields(log.Fields{
185 "IntfId": pon.ID,
186 }).Errorf("Cannot poweron ONUs on PON: %s", err.Error())
187
188 res.StatusCode = int32(codes.FailedPrecondition)
189 res.Message = err.Error()
190 return res, err
191 }
192
193 go func() {
194 for _, onu := range pon.Onus {
195 res, _ = handlePoweronONU(onu)
Pragya Arya2225f202020-01-29 18:05:01 +0530196 }
Pragya Aryabd731ec2020-02-11 16:38:17 +0530197 }()
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700198 res.StatusCode = int32(codes.OK)
Pragya Aryabd731ec2020-02-11 16:38:17 +0530199 res.Message = fmt.Sprintf("Request Accepted for power on all ONUs on PON port %d", pon.ID)
200
201 return res, nil
202}
203
204// PoweronAllONUs simulates ONU power on for all ONUs on all PON ports
205func (s BBSimServer) PoweronAllONUs(context.Context, *bbsim.Empty) (*bbsim.Response, error) {
206 logger.Infof("Received request to poweron all ONUs")
207
208 res := &bbsim.Response{}
209 olt := devices.GetOLT()
210
211 go func() {
212 for _, pon := range olt.Pons {
213 if pon.InternalState.Current() == "enabled" {
214 for _, onu := range pon.Onus {
215 res, _ = handlePoweronONU(onu)
216 }
217 }
218 }
219 }()
220 res.StatusCode = int32(codes.OK)
221 res.Message = fmt.Sprintf("Request Accepted for power on all ONUs in OLT %d", olt.ID)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700222
223 return res, nil
224}
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700225
Arjun E K57a7fcb2020-01-30 06:44:45 +0000226func (s BBSimServer) ChangeIgmpState(ctx context.Context, req *bbsim.IgmpRequest) (*bbsim.Response, error) {
Matteo Scandolo618a6582020-09-09 12:21:29 -0700227
228 // TODO check that the ONU is enabled and the services are initialized before changing the state
229
Arjun E K57a7fcb2020-01-30 06:44:45 +0000230 res := &bbsim.Response{}
231
232 logger.WithFields(log.Fields{
233 "OnuSn": req.OnuReq.SerialNumber,
234 "subAction": req.SubActionVal,
235 }).Infof("Received igmp request for ONU")
236
237 olt := devices.GetOLT()
238 onu, err := olt.FindOnuBySn(req.OnuReq.SerialNumber)
239
240 if err != nil {
241 res.StatusCode = int32(codes.NotFound)
242 res.Message = err.Error()
243 fmt.Println("ONU not found for sending igmp packet.")
244 return res, err
245 } else {
246 event := ""
247 switch req.SubActionVal {
248 case bbsim.SubActionTypes_JOIN:
249 event = "igmp_join_start"
250 case bbsim.SubActionTypes_LEAVE:
251 event = "igmp_leave"
Anand S Katti09541352020-01-29 15:54:01 +0530252 case bbsim.SubActionTypes_JOINV3:
253 event = "igmp_join_startv3"
Arjun E K57a7fcb2020-01-30 06:44:45 +0000254 }
255
Matteo Scandolo618a6582020-09-09 12:21:29 -0700256 errors := []string{}
257 startedOn := []string{}
258 success := true
259
260 for _, s := range onu.Services {
261 service := s.(*devices.Service)
262 if service.NeedsIgmp {
263
264 logger.WithFields(log.Fields{
265 "OnuId": onu.ID,
266 "IntfId": onu.PonPortID,
267 "OnuSn": onu.Sn(),
268 "Service": service.Name,
269 }).Debugf("Sending %s event on Service %s", event, service.Name)
270
271 if err := service.IGMPState.Event(event); err != nil {
272 logger.WithFields(log.Fields{
273 "OnuId": onu.ID,
274 "IntfId": onu.PonPortID,
275 "OnuSn": onu.Sn(),
276 "Service": service.Name,
277 }).Errorf("IGMP request failed: %s", err.Error())
278 errors = append(errors, fmt.Sprintf("%s: %s", service.Name, err.Error()))
279 success = false
280 }
281 startedOn = append(startedOn, service.Name)
282 }
283 }
284
285 if success {
286 res.StatusCode = int32(codes.OK)
287 res.Message = fmt.Sprintf("Authentication restarted on Services %s for ONU %s.",
288 fmt.Sprintf("%v", startedOn), onu.Sn())
289 } else {
Arjun E K57a7fcb2020-01-30 06:44:45 +0000290 res.StatusCode = int32(codes.FailedPrecondition)
Matteo Scandolo618a6582020-09-09 12:21:29 -0700291 res.Message = fmt.Sprintf("%v", errors)
Arjun E K57a7fcb2020-01-30 06:44:45 +0000292 }
293 }
294
295 return res, nil
296}
297
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700298func (s BBSimServer) RestartEapol(ctx context.Context, req *bbsim.ONURequest) (*bbsim.Response, error) {
299 res := &bbsim.Response{}
300
301 logger.WithFields(log.Fields{
302 "OnuSn": req.SerialNumber,
303 }).Infof("Received request to restart authentication ONU")
304
305 olt := devices.GetOLT()
306
307 onu, err := olt.FindOnuBySn(req.SerialNumber)
308
309 if err != nil {
310 res.StatusCode = int32(codes.NotFound)
311 res.Message = err.Error()
312 return res, err
313 }
314
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700315 errors := []string{}
Matteo Scandolo618a6582020-09-09 12:21:29 -0700316 startedOn := []string{}
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700317 success := true
318
319 for _, s := range onu.Services {
320 service := s.(*devices.Service)
321 if service.NeedsEapol {
322 if err := service.EapolState.Event("start_auth"); err != nil {
323 logger.WithFields(log.Fields{
324 "OnuId": onu.ID,
325 "IntfId": onu.PonPortID,
326 "OnuSn": onu.Sn(),
327 "Service": service.Name,
328 }).Errorf("Cannot restart authenticaton for Service: %s", err.Error())
329 errors = append(errors, fmt.Sprintf("%s: %s", service.Name, err.Error()))
330 success = false
331 }
Matteo Scandolo618a6582020-09-09 12:21:29 -0700332 startedOn = append(startedOn, service.Name)
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700333 }
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700334 }
335
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700336 if success {
337 res.StatusCode = int32(codes.OK)
Matteo Scandolo618a6582020-09-09 12:21:29 -0700338 res.Message = fmt.Sprintf("Authentication restarted on Services %s for ONU %s.",
339 fmt.Sprintf("%v", startedOn), onu.Sn())
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700340 } else {
341 res.StatusCode = int32(codes.FailedPrecondition)
342 res.Message = fmt.Sprintf("%v", errors)
343 }
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700344
345 return res, nil
346}
347
348func (s BBSimServer) RestartDhcp(ctx context.Context, req *bbsim.ONURequest) (*bbsim.Response, error) {
349 res := &bbsim.Response{}
350
351 logger.WithFields(log.Fields{
352 "OnuSn": req.SerialNumber,
353 }).Infof("Received request to restart DHCP on ONU")
354
355 olt := devices.GetOLT()
356
357 onu, err := olt.FindOnuBySn(req.SerialNumber)
358
359 if err != nil {
360 res.StatusCode = int32(codes.NotFound)
361 res.Message = err.Error()
362 return res, err
363 }
364
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700365 errors := []string{}
Matteo Scandolo618a6582020-09-09 12:21:29 -0700366 startedOn := []string{}
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700367 success := true
368
369 for _, s := range onu.Services {
370 service := s.(*devices.Service)
371 if service.NeedsDhcp {
372
373 if err := service.DHCPState.Event("start_dhcp"); err != nil {
374 logger.WithFields(log.Fields{
375 "OnuId": onu.ID,
376 "IntfId": onu.PonPortID,
377 "OnuSn": onu.Sn(),
378 "Service": service.Name,
379 }).Errorf("Cannot restart DHCP for Service: %s", err.Error())
380 errors = append(errors, fmt.Sprintf("%s: %s", service.Name, err.Error()))
381 success = false
382 }
Matteo Scandolo618a6582020-09-09 12:21:29 -0700383 startedOn = append(startedOn, service.Name)
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700384 }
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700385 }
386
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700387 if success {
388 res.StatusCode = int32(codes.OK)
Matteo Scandolo618a6582020-09-09 12:21:29 -0700389 res.Message = fmt.Sprintf("DHCP restarted on Services %s for ONU %s.",
390 fmt.Sprintf("%v", startedOn), onu.Sn())
Matteo Scandoloadc72a82020-09-08 18:46:08 -0700391 } else {
392 res.StatusCode = int32(codes.FailedPrecondition)
393 res.Message = fmt.Sprintf("%v", errors)
394 }
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700395
396 return res, nil
397}
Anand S Katti09541352020-01-29 15:54:01 +0530398
Pragya Arya8bdb4532020-03-02 17:08:09 +0530399// GetFlows for OLT/ONUs
400func (s BBSimServer) GetFlows(ctx context.Context, req *bbsim.ONURequest) (*bbsim.Flows, error) {
401 logger.WithFields(log.Fields{
402 "OnuSn": req.SerialNumber,
403 }).Info("Received GetFlows request")
404
405 olt := devices.GetOLT()
406 res := &bbsim.Flows{}
407
408 if req.SerialNumber == "" {
409 for flowKey := range olt.Flows {
410 flow := olt.Flows[flowKey]
411 res.Flows = append(res.Flows, &flow)
412 }
413 res.FlowCount = uint32(len(olt.Flows))
414 } else {
415 onu, err := olt.FindOnuBySn(req.SerialNumber)
416 if err != nil {
417 logger.WithFields(log.Fields{
418 "OnuSn": req.SerialNumber,
419 }).Error("Can't get ONU in GetFlows request")
420 return nil, err
421 }
422 for _, flowKey := range onu.Flows {
423 flow := olt.Flows[flowKey]
424 res.Flows = append(res.Flows, &flow)
425 }
426 res.FlowCount = uint32(len(onu.Flows))
427 }
428 return res, nil
429}
430
Anand S Katti09541352020-01-29 15:54:01 +0530431func (s BBSimServer) GetOnuTrafficSchedulers(ctx context.Context, req *bbsim.ONURequest) (*bbsim.ONUTrafficSchedulers, error) {
432 olt := devices.GetOLT()
433 ts := bbsim.ONUTrafficSchedulers{}
434
435 onu, err := olt.FindOnuBySn(req.SerialNumber)
436 if err != nil {
437 return &ts, err
438 }
439
440 if onu.TrafficSchedulers != nil {
441 ts.TraffSchedulers = onu.TrafficSchedulers
442 return &ts, nil
443 } else {
444 ts.TraffSchedulers = nil
445 return &ts, nil
446 }
447}
Pragya Aryabd731ec2020-02-11 16:38:17 +0530448
449func handlePoweronONU(onu *devices.Onu) (*bbsim.Response, error) {
450 res := &bbsim.Response{}
451 olt := devices.GetOLT()
452 intitalState := onu.InternalState.Current()
453 if onu.InternalState.Current() == "created" || onu.InternalState.Current() == "disabled" {
454 if err := onu.InternalState.Event("initialize"); err != nil {
455 logger.WithFields(log.Fields{
456 "OnuId": onu.ID,
457 "IntfId": onu.PonPortID,
458 "OnuSn": onu.Sn(),
459 }).Errorf("Cannot poweron ONU: %s", err.Error())
460 res.StatusCode = int32(codes.FailedPrecondition)
461 res.Message = err.Error()
462 return res, err
463 }
464 }
465
466 losReq := bbsim.ONUAlarmRequest{
Pragya Arya1d5ffb82020-03-20 18:51:37 +0530467 AlarmType: "ONU_ALARM_LOS",
Pragya Aryabd731ec2020-02-11 16:38:17 +0530468 SerialNumber: onu.Sn(),
469 Status: "off",
470 }
471
472 if err := alarmsim.SimulateOnuAlarm(context.TODO(), &losReq, olt); err != nil {
473 logger.WithFields(log.Fields{
474 "OnuId": onu.ID,
475 "IntfId": onu.PonPortID,
476 "OnuSn": onu.Sn(),
477 }).Errorf("Cannot send LOS: %s", err.Error())
478 res.StatusCode = int32(codes.FailedPrecondition)
479 res.Message = err.Error()
480 return res, err
481 }
482
483 if err := onu.InternalState.Event("discover"); err != nil {
484 logger.WithFields(log.Fields{
485 "OnuId": onu.ID,
486 "IntfId": onu.PonPortID,
487 "OnuSn": onu.Sn(),
488 }).Errorf("Cannot poweron ONU: %s", err.Error())
489 res.StatusCode = int32(codes.FailedPrecondition)
490 res.Message = err.Error()
491 return res, err
492 }
493 // move onu directly to enable state only when its a powercycle case
494 // in case of first time onu poweron onu will be moved to enable on
495 // receiving ActivateOnu request from openolt adapter
496 if intitalState == "disabled" {
497 if err := onu.InternalState.Event("enable"); err != nil {
498 logger.WithFields(log.Fields{
499 "OnuId": onu.ID,
500 "IntfId": onu.PonPortID,
501 "OnuSn": onu.Sn(),
502 }).Errorf("Cannot enable ONU: %s", err.Error())
503 res.StatusCode = int32(codes.FailedPrecondition)
504 res.Message = err.Error()
505 return res, err
506 }
507 }
508
509 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{}
517 olt := devices.GetOLT()
518
519 dyingGasp := bbsim.ONUAlarmRequest{
Pragya Arya1d5ffb82020-03-20 18:51:37 +0530520 AlarmType: "DYING_GASP",
Pragya Aryabd731ec2020-02-11 16:38:17 +0530521 SerialNumber: onu.Sn(),
522 Status: "on",
523 }
524
525 if err := alarmsim.SimulateOnuAlarm(context.TODO(), &dyingGasp, olt); err != nil {
526 logger.WithFields(log.Fields{
527 "OnuId": onu.ID,
528 "IntfId": onu.PonPortID,
529 "OnuSn": onu.Sn(),
530 }).Errorf("Cannot send Dying Gasp: %s", err.Error())
531 res.StatusCode = int32(codes.FailedPrecondition)
532 res.Message = err.Error()
533 return res, err
534 }
535
536 losReq := bbsim.ONUAlarmRequest{
Pragya Arya1d5ffb82020-03-20 18:51:37 +0530537 AlarmType: "ONU_ALARM_LOS",
Pragya Aryabd731ec2020-02-11 16:38:17 +0530538 SerialNumber: onu.Sn(),
539 Status: "on",
540 }
541
542 if err := alarmsim.SimulateOnuAlarm(context.TODO(), &losReq, olt); err != nil {
543 logger.WithFields(log.Fields{
544 "OnuId": onu.ID,
545 "IntfId": onu.PonPortID,
546 "OnuSn": onu.Sn(),
547 }).Errorf("Cannot send LOS: %s", err.Error())
548 res.StatusCode = int32(codes.FailedPrecondition)
549 res.Message = err.Error()
550 return res, err
551 }
552
553 // TODO if it's the last ONU on the PON, then send a PON LOS
554
555 if err := onu.InternalState.Event("disable"); err != nil {
556 logger.WithFields(log.Fields{
557 "OnuId": onu.ID,
558 "IntfId": onu.PonPortID,
559 "OnuSn": onu.Sn(),
560 }).Errorf("Cannot shutdown ONU: %s", err.Error())
561 res.StatusCode = int32(codes.FailedPrecondition)
562 res.Message = err.Error()
563 return res, err
564 }
565
566 res.StatusCode = int32(codes.OK)
567 res.Message = fmt.Sprintf("ONU %s successfully shut down.", onu.Sn())
568
569 return res, nil
570}