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 ( |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 20 | "gerrit.opencord.org/voltha-bbsim/common/logger" |
| 21 | "gerrit.opencord.org/voltha-bbsim/common/utils" |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 22 | "gerrit.opencord.org/voltha-bbsim/device" |
| 23 | "gerrit.opencord.org/voltha-bbsim/protos" |
Keita NISHIMOTO | 2f8a6a4 | 2019-02-08 09:47:07 +0900 | [diff] [blame] | 24 | "time" |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 25 | ) |
| 26 | |
Keita NISHIMOTO | 9c6f6f1 | 2018-10-18 04:56:34 +0900 | [diff] [blame] | 27 | func sendOltIndUp(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 28 | data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "up"}} |
| 29 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 30 | logger.Error("Failed to send OLT UP indication: %v", err) |
Keita NISHIMOTO | 9c6f6f1 | 2018-10-18 04:56:34 +0900 | [diff] [blame] | 31 | return err |
| 32 | } |
| 33 | return nil |
| 34 | } |
| 35 | |
| 36 | func 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 Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 39 | logger.Error("Failed to send OLT DOWN indication: %v", err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 40 | return err |
| 41 | } |
| 42 | return nil |
| 43 | } |
| 44 | |
| 45 | func sendIntfInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error { |
| 46 | for i := uint32(0); i < olt.NumPonIntf+olt.NumNniIntf; i++ { |
| 47 | intf := olt.Intfs[i] |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 48 | if intf.Type == "pon" { // There is no need to send IntfInd for NNI |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 49 | data := &openolt.Indication_IntfInd{&openolt.IntfIndication{IntfId: intf.IntfID, OperState: intf.OperState}} |
| 50 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 51 | logger.Error("Failed to send Intf [id: %d] indication : %v", i, err) |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 52 | return err |
| 53 | } |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 54 | 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] | 55 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 56 | } |
| 57 | return nil |
| 58 | } |
| 59 | |
| 60 | func sendOperInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error { |
| 61 | for i := uint32(0); i < olt.NumPonIntf+olt.NumNniIntf; i++ { |
| 62 | intf := olt.Intfs[i] |
| 63 | 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 { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 65 | logger.Error("Failed to send IntfOper [id: %d] indication : %v", i, err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 66 | return err |
| 67 | } |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 68 | logger.Info("SendOperInd olt:%d intf:%d (%s)", olt.ID, intf.IntfID, intf.Type) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 69 | } |
| 70 | return nil |
| 71 | } |
| 72 | |
Mahir Gunyel | 9897f6e | 2019-05-22 14:54:05 -0700 | [diff] [blame^] | 73 | func sendOnuDiscInd(stream openolt.Openolt_EnableIndicationServer, onus []*device.Onu, delay int) error { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 74 | for i, onu := range onus { |
| 75 | data := &openolt.Indication_OnuDiscInd{&openolt.OnuDiscIndication{IntfId: onu.IntfID, SerialNumber: onu.SerialNumber}} |
Mahir Gunyel | 9897f6e | 2019-05-22 14:54:05 -0700 | [diff] [blame^] | 76 | time.Sleep(time.Duration(delay) * time.Millisecond) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 77 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 78 | logger.Error("Failed to send ONUDiscInd [id: %d]: %v", i, err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 79 | return err |
| 80 | } |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 81 | utils.LoggerWithOnu(onu).Info("sendONUDiscInd Onuid") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 82 | } |
| 83 | return nil |
| 84 | } |
| 85 | |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 86 | func sendOnuInd(stream openolt.Openolt_EnableIndicationServer, onus []*device.Onu, delay int) error { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 87 | for i, onu := range onus { |
Mahir Gunyel | 9897f6e | 2019-05-22 14:54:05 -0700 | [diff] [blame^] | 88 | // time.Sleep(time.Duration(delay) * time.Millisecond) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 89 | data := &openolt.Indication_OnuInd{&openolt.OnuIndication{IntfId: onu.IntfID, OnuId: onu.OnuID, OperState: "up", AdminState: "up", SerialNumber: onu.SerialNumber}} |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 90 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 91 | logger.Error("Failed to send ONUInd [id: %d]: %v", i, err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 92 | return err |
| 93 | } |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame] | 94 | utils.LoggerWithOnu(onu).Info("sendONUInd Onuid") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 95 | } |
| 96 | return nil |
| 97 | } |
Mahir Gunyel | 9897f6e | 2019-05-22 14:54:05 -0700 | [diff] [blame^] | 98 | |
| 99 | func sendOnuIndtoONU(stream openolt.Openolt_EnableIndicationServer, onu *device.Onu ) { |
| 100 | time.Sleep(time.Duration(10000) * time.Millisecond) //TODO:This sleep added because of a known race condition in VOLTHA. Can be removed after fix. |
| 101 | data := &openolt.Indication_OnuInd{&openolt.OnuIndication{IntfId: onu.IntfID, OnuId: onu.OnuID, OperState: "up", AdminState: "up", SerialNumber: onu.SerialNumber}} |
| 102 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 103 | logger.Error("Failed to send ONUInd [id: %d]: %v", onu.OnuID, err) |
| 104 | } |
| 105 | utils.LoggerWithOnu(onu).Info("sendONUInd Onuid") |
| 106 | |
| 107 | } |