Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package core |
| 18 | |
| 19 | import ( |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 20 | |
Zack Williams | 2abf393 | 2019-08-05 14:07:05 -0700 | [diff] [blame] | 21 | "github.com/opencord/voltha-bbsim/common/logger" |
| 22 | "github.com/opencord/voltha-bbsim/device" |
| 23 | openolt "github.com/opencord/voltha-bbsim/protos" |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 24 | ) |
| 25 | |
Keita NISHIMOTO | 9c6f6f1 | 2018-10-18 04:56:34 +0900 | [diff] [blame] | 26 | func sendOltIndUp(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 27 | data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "up"}} |
| 28 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 29 | logger.Error("Failed to send OLT UP indication: %v", err) |
Keita NISHIMOTO | 9c6f6f1 | 2018-10-18 04:56:34 +0900 | [diff] [blame] | 30 | return err |
| 31 | } |
| 32 | return nil |
| 33 | } |
| 34 | |
| 35 | func sendOltIndDown(stream openolt.Openolt_EnableIndicationServer) error { |
| 36 | data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "down"}} |
| 37 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 38 | logger.Error("Failed to send OLT DOWN indication: %v", err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 39 | return err |
| 40 | } |
| 41 | return nil |
| 42 | } |
| 43 | |
| 44 | func sendIntfInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error { |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 45 | // There is no need to send IntfInd for NNI |
| 46 | for i := uint32(0); i < olt.NumPonIntf; i++ { |
| 47 | intf := olt.PonIntfs[i] |
| 48 | data := &openolt.Indication_IntfInd{&openolt.IntfIndication{IntfId: intf.IntfID, OperState: intf.OperState}} |
| 49 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 50 | logger.Error("Failed to send Intf [id: %d] indication : %v", i, err) |
| 51 | return err |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 52 | } |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 53 | logger.Info("SendIntfInd olt:%d intf:%d (%s)", olt.ID, intf.IntfID, intf.Type) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 54 | } |
| 55 | return nil |
| 56 | } |
| 57 | |
| 58 | func sendOperInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error { |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 59 | // Send OperInd for Nni |
| 60 | for i := uint32(0); i < olt.NumNniIntf; i++ { |
| 61 | intf := olt.NniIntfs[i] |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 62 | data := &openolt.Indication_IntfOperInd{&openolt.IntfOperIndication{Type: intf.Type, IntfId: intf.IntfID, OperState: intf.OperState}} |
| 63 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 64 | logger.Error("Failed to send NNI IntfOper [id: %d] indication : %v", i, err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 65 | return err |
| 66 | } |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 67 | logger.Info("SendOperInd NNI olt:%d intf:%d (%s)", olt.ID, intf.IntfID, intf.Type) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 68 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 69 | |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 70 | // Send OperInd for Pon |
| 71 | for i := uint32(0); i < olt.NumPonIntf; i++ { |
| 72 | intf := olt.PonIntfs[i] |
| 73 | data := &openolt.Indication_IntfOperInd{&openolt.IntfOperIndication{Type: intf.Type, IntfId: intf.IntfID, OperState: intf.OperState}} |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 74 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 75 | logger.Error("Failed to send PON IntfOper [id: %d] indication : %v", i, err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 76 | return err |
| 77 | } |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 78 | logger.Info("SendOperInd PON olt:%d intf:%d (%s)", olt.ID, intf.IntfID, intf.Type) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 79 | } |
| 80 | return nil |
| 81 | } |
| 82 | |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 83 | func sendOnuDiscInd(stream openolt.Openolt_EnableIndicationServer, onu *device.Onu) error { |
| 84 | data := &openolt.Indication_OnuDiscInd{OnuDiscInd: &openolt.OnuDiscIndication{IntfId: onu.IntfID, SerialNumber: onu.SerialNumber}} |
Mahir Gunyel | 9897f6e | 2019-05-22 14:54:05 -0700 | [diff] [blame] | 85 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 86 | logger.Error("Failed to send ONUDiscInd [id: %d]: %v", onu.OnuID, err) |
| 87 | return err |
| 88 | } |
Keita NISHIMOTO | 9617c85 | 2019-06-17 21:46:44 +0900 | [diff] [blame] | 89 | device.LoggerWithOnu(onu).Info("sendONUDiscInd Onuid") |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 90 | return nil |
| 91 | } |
| 92 | |
Mahir Gunyel | 32dfd72 | 2019-08-05 16:18:06 +0300 | [diff] [blame] | 93 | func sendOnuInd(stream openolt.Openolt_EnableIndicationServer, onu *device.Onu, operState string, adminState string) error { |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 94 | data := &openolt.Indication_OnuInd{OnuInd: &openolt.OnuIndication{ |
Keita NISHIMOTO | 9617c85 | 2019-06-17 21:46:44 +0900 | [diff] [blame] | 95 | IntfId: onu.IntfID, |
| 96 | OnuId: onu.OnuID, |
| 97 | OperState: operState, |
| 98 | AdminState: adminState, |
| 99 | SerialNumber: onu.SerialNumber, |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 100 | }} |
| 101 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 102 | logger.Error("Failed to send ONUInd [id: %d]: %v", onu.OnuID, err) |
| 103 | return err |
Mahir Gunyel | 9897f6e | 2019-05-22 14:54:05 -0700 | [diff] [blame] | 104 | } |
Keita NISHIMOTO | 9617c85 | 2019-06-17 21:46:44 +0900 | [diff] [blame] | 105 | device.LoggerWithOnu(onu).Info("sendONUInd Onuid") |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 106 | return nil |
| 107 | } |
Mahir Gunyel | 9897f6e | 2019-05-22 14:54:05 -0700 | [diff] [blame] | 108 | |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 109 | func sendDyingGaspInd(stream openolt.Openolt_EnableIndicationServer, intfID uint32, onuID uint32) error { |
| 110 | // Form DyingGasp Indication with ONU-ID and Intf-ID |
| 111 | alarmData := &openolt.AlarmIndication_DyingGaspInd{DyingGaspInd: &openolt.DyingGaspIndication{IntfId: intfID, OnuId: onuID, Status: "on"}} |
| 112 | data := &openolt.Indication_AlarmInd{AlarmInd: &openolt.AlarmIndication{Data: alarmData}} |
| 113 | |
| 114 | // Send Indication to VOLTHA |
| 115 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 116 | logger.Error("Failed to send DyingGaspInd : %v", err) |
| 117 | return err |
| 118 | } |
| 119 | logger.Info("sendDyingGaspInd Intf-ID:%d ONU-ID:%d", intfID, onuID) |
| 120 | return nil |
| 121 | } |
| 122 | |
| 123 | func startAlarmLoop(stream openolt.Openolt_EnableIndicationServer, alarmchan chan *openolt.Indication) { |
| 124 | logger.Debug("SendAlarm() Invoked") |
| 125 | for { |
| 126 | select { |
| 127 | case ind := <-alarmchan: |
| 128 | logger.Debug("Alarm recieved at alarm-channel to send to voltha %+v", ind) |
| 129 | err := stream.Send(ind) |
| 130 | if err != nil { |
| 131 | logger.Debug("Error occured while sending alarm indication %v", err) |
| 132 | } |
| 133 | } |
| 134 | } |
Mahir Gunyel | 9897f6e | 2019-05-22 14:54:05 -0700 | [diff] [blame] | 135 | } |