blob: dc48577ab4abf43256619077500b1a88dab901cf [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
Matteo Scandolo88e91892018-11-06 16:29:19 -080022 "gerrit.opencord.org/voltha-bbsim/common/logger"
23 "gerrit.opencord.org/voltha-bbsim/common/utils"
Keita NISHIMOTO9708e042018-10-27 09:24:44 +090024 "gerrit.opencord.org/voltha-bbsim/device"
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020025 openolt "gerrit.opencord.org/voltha-bbsim/protos"
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090026)
27
Keita NISHIMOTO9c6f6f12018-10-18 04:56:34 +090028func sendOltIndUp(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error {
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090029 data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "up"}}
30 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080031 logger.Error("Failed to send OLT UP indication: %v", err)
Keita NISHIMOTO9c6f6f12018-10-18 04:56:34 +090032 return err
33 }
34 return nil
35}
36
37func sendOltIndDown(stream openolt.Openolt_EnableIndicationServer) error {
38 data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "down"}}
39 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080040 logger.Error("Failed to send OLT DOWN indication: %v", err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090041 return err
42 }
43 return nil
44}
45
46func sendIntfInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error {
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020047 // There is no need to send IntfInd for NNI
48 for i := uint32(0); i < olt.NumPonIntf; i++ {
49 intf := olt.PonIntfs[i]
50 data := &openolt.Indication_IntfInd{&openolt.IntfIndication{IntfId: intf.IntfID, OperState: intf.OperState}}
51 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
52 logger.Error("Failed to send Intf [id: %d] indication : %v", i, err)
53 return err
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090054 }
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020055 logger.Info("SendIntfInd olt:%d intf:%d (%s)", olt.ID, intf.IntfID, intf.Type)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090056 }
57 return nil
58}
59
60func sendOperInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error {
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020061 // Send OperInd for Nni
62 for i := uint32(0); i < olt.NumNniIntf; i++ {
63 intf := olt.NniIntfs[i]
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090064 data := &openolt.Indication_IntfOperInd{&openolt.IntfOperIndication{Type: intf.Type, IntfId: intf.IntfID, OperState: intf.OperState}}
65 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020066 logger.Error("Failed to send NNI IntfOper [id: %d] indication : %v", i, err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090067 return err
68 }
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020069 logger.Info("SendOperInd NNI olt:%d intf:%d (%s)", olt.ID, intf.IntfID, intf.Type)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090070 }
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090071
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020072 // Send OperInd for Pon
73 for i := uint32(0); i < olt.NumPonIntf; i++ {
74 intf := olt.PonIntfs[i]
75 data := &openolt.Indication_IntfOperInd{&openolt.IntfOperIndication{Type: intf.Type, IntfId: intf.IntfID, OperState: intf.OperState}}
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090076 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020077 logger.Error("Failed to send PON IntfOper [id: %d] indication : %v", i, err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090078 return err
79 }
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020080 logger.Info("SendOperInd PON olt:%d intf:%d (%s)", olt.ID, intf.IntfID, intf.Type)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090081 }
82 return nil
83}
84
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020085func sendOnuDiscInd(stream openolt.Openolt_EnableIndicationServer, onu *device.Onu) error {
86 data := &openolt.Indication_OnuDiscInd{OnuDiscInd: &openolt.OnuDiscIndication{IntfId: onu.IntfID, SerialNumber: onu.SerialNumber}}
Mahir Gunyel9897f6e2019-05-22 14:54:05 -070087 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020088 logger.Error("Failed to send ONUDiscInd [id: %d]: %v", onu.OnuID, err)
89 return err
90 }
91 utils.LoggerWithOnu(onu).Info("sendONUDiscInd Onuid")
92 return nil
93}
94
95func sendOnuInd(stream openolt.Openolt_EnableIndicationServer, onu *device.Onu, delay int, operState string, adminState string) error {
96 time.Sleep(time.Duration(delay) * time.Millisecond)
97 data := &openolt.Indication_OnuInd{OnuInd: &openolt.OnuIndication{
98 IntfId: onu.IntfID,
99 OnuId: onu.OnuID,
100 OperState: operState,
101 AdminState: adminState,
102 SerialNumber: onu.SerialNumber,
103 }}
104 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
105 logger.Error("Failed to send ONUInd [id: %d]: %v", onu.OnuID, err)
106 return err
Mahir Gunyel9897f6e2019-05-22 14:54:05 -0700107 }
108 utils.LoggerWithOnu(onu).Info("sendONUInd Onuid")
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200109 return nil
110}
Mahir Gunyel9897f6e2019-05-22 14:54:05 -0700111
Zdravko Bozakov7401ff22019-05-28 22:45:12 +0200112func sendDyingGaspInd(stream openolt.Openolt_EnableIndicationServer, intfID uint32, onuID uint32) error {
113 // Form DyingGasp Indication with ONU-ID and Intf-ID
114 alarmData := &openolt.AlarmIndication_DyingGaspInd{DyingGaspInd: &openolt.DyingGaspIndication{IntfId: intfID, OnuId: onuID, Status: "on"}}
115 data := &openolt.Indication_AlarmInd{AlarmInd: &openolt.AlarmIndication{Data: alarmData}}
116
117 // Send Indication to VOLTHA
118 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
119 logger.Error("Failed to send DyingGaspInd : %v", err)
120 return err
121 }
122 logger.Info("sendDyingGaspInd Intf-ID:%d ONU-ID:%d", intfID, onuID)
123 return nil
124}
125
126func startAlarmLoop(stream openolt.Openolt_EnableIndicationServer, alarmchan chan *openolt.Indication) {
127 logger.Debug("SendAlarm() Invoked")
128 for {
129 select {
130 case ind := <-alarmchan:
131 logger.Debug("Alarm recieved at alarm-channel to send to voltha %+v", ind)
132 err := stream.Send(ind)
133 if err != nil {
134 logger.Debug("Error occured while sending alarm indication %v", err)
135 }
136 }
137 }
Mahir Gunyel9897f6e2019-05-22 14:54:05 -0700138}