blob: fafe1c95dd39c63debaed6d6401289aa74c195be [file] [log] [blame]
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +09001/*
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 core
18
19import (
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020020 "time"
21
Zack Williams2abf3932019-08-05 14:07:05 -070022 "github.com/opencord/voltha-bbsim/common/logger"
23 "github.com/opencord/voltha-bbsim/device"
24 openolt "github.com/opencord/voltha-bbsim/protos"
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090025)
26
Keita NISHIMOTO9c6f6f12018-10-18 04:56:34 +090027func sendOltIndUp(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error {
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090028 data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "up"}}
29 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080030 logger.Error("Failed to send OLT UP indication: %v", err)
Keita NISHIMOTO9c6f6f12018-10-18 04:56:34 +090031 return err
32 }
33 return nil
34}
35
36func sendOltIndDown(stream openolt.Openolt_EnableIndicationServer) error {
37 data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "down"}}
38 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080039 logger.Error("Failed to send OLT DOWN indication: %v", err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090040 return err
41 }
42 return nil
43}
44
45func sendIntfInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error {
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020046 // There is no need to send IntfInd for NNI
47 for i := uint32(0); i < olt.NumPonIntf; i++ {
48 intf := olt.PonIntfs[i]
49 data := &openolt.Indication_IntfInd{&openolt.IntfIndication{IntfId: intf.IntfID, OperState: intf.OperState}}
50 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
51 logger.Error("Failed to send Intf [id: %d] indication : %v", i, err)
52 return err
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090053 }
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020054 logger.Info("SendIntfInd olt:%d intf:%d (%s)", olt.ID, intf.IntfID, intf.Type)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090055 }
56 return nil
57}
58
59func sendOperInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error {
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020060 // Send OperInd for Nni
61 for i := uint32(0); i < olt.NumNniIntf; i++ {
62 intf := olt.NniIntfs[i]
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090063 data := &openolt.Indication_IntfOperInd{&openolt.IntfOperIndication{Type: intf.Type, IntfId: intf.IntfID, OperState: intf.OperState}}
64 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020065 logger.Error("Failed to send NNI IntfOper [id: %d] indication : %v", i, err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090066 return err
67 }
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020068 logger.Info("SendOperInd NNI olt:%d intf:%d (%s)", olt.ID, intf.IntfID, intf.Type)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090069 }
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090070
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020071 // Send OperInd for Pon
72 for i := uint32(0); i < olt.NumPonIntf; i++ {
73 intf := olt.PonIntfs[i]
74 data := &openolt.Indication_IntfOperInd{&openolt.IntfOperIndication{Type: intf.Type, IntfId: intf.IntfID, OperState: intf.OperState}}
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090075 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020076 logger.Error("Failed to send PON IntfOper [id: %d] indication : %v", i, err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090077 return err
78 }
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020079 logger.Info("SendOperInd PON olt:%d intf:%d (%s)", olt.ID, intf.IntfID, intf.Type)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090080 }
81 return nil
82}
83
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020084func sendOnuDiscInd(stream openolt.Openolt_EnableIndicationServer, onu *device.Onu) error {
85 data := &openolt.Indication_OnuDiscInd{OnuDiscInd: &openolt.OnuDiscIndication{IntfId: onu.IntfID, SerialNumber: onu.SerialNumber}}
Mahir Gunyel9897f6e2019-05-22 14:54:05 -070086 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020087 logger.Error("Failed to send ONUDiscInd [id: %d]: %v", onu.OnuID, err)
88 return err
89 }
Keita NISHIMOTO9617c852019-06-17 21:46:44 +090090 device.LoggerWithOnu(onu).Info("sendONUDiscInd Onuid")
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020091 return nil
92}
93
94func sendOnuInd(stream openolt.Openolt_EnableIndicationServer, onu *device.Onu, delay int, operState string, adminState string) error {
95 time.Sleep(time.Duration(delay) * time.Millisecond)
96 data := &openolt.Indication_OnuInd{OnuInd: &openolt.OnuIndication{
Keita NISHIMOTO9617c852019-06-17 21:46:44 +090097 IntfId: onu.IntfID,
98 OnuId: onu.OnuID,
99 OperState: operState,
100 AdminState: adminState,
101 SerialNumber: onu.SerialNumber,
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200102 }}
103 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
104 logger.Error("Failed to send ONUInd [id: %d]: %v", onu.OnuID, err)
105 return err
Mahir Gunyel9897f6e2019-05-22 14:54:05 -0700106 }
Keita NISHIMOTO9617c852019-06-17 21:46:44 +0900107 device.LoggerWithOnu(onu).Info("sendONUInd Onuid")
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200108 return nil
109}
Mahir Gunyel9897f6e2019-05-22 14:54:05 -0700110
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200111func sendDyingGaspInd(stream openolt.Openolt_EnableIndicationServer, intfID uint32, onuID uint32) error {
112 // Form DyingGasp Indication with ONU-ID and Intf-ID
113 alarmData := &openolt.AlarmIndication_DyingGaspInd{DyingGaspInd: &openolt.DyingGaspIndication{IntfId: intfID, OnuId: onuID, Status: "on"}}
114 data := &openolt.Indication_AlarmInd{AlarmInd: &openolt.AlarmIndication{Data: alarmData}}
115
116 // Send Indication to VOLTHA
117 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
118 logger.Error("Failed to send DyingGaspInd : %v", err)
119 return err
120 }
121 logger.Info("sendDyingGaspInd Intf-ID:%d ONU-ID:%d", intfID, onuID)
122 return nil
123}
124
125func startAlarmLoop(stream openolt.Openolt_EnableIndicationServer, alarmchan chan *openolt.Indication) {
126 logger.Debug("SendAlarm() Invoked")
127 for {
128 select {
129 case ind := <-alarmchan:
130 logger.Debug("Alarm recieved at alarm-channel to send to voltha %+v", ind)
131 err := stream.Send(ind)
132 if err != nil {
133 logger.Debug("Error occured while sending alarm indication %v", err)
134 }
135 }
136 }
Mahir Gunyel9897f6e2019-05-22 14:54:05 -0700137}