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 | "time" |
| 21 | |
| 22 | "gerrit.opencord.org/voltha-bbsim/common/logger" |
| 23 | "gerrit.opencord.org/voltha-bbsim/common/utils" |
Keita NISHIMOTO | 9708e04 | 2018-10-27 09:24:44 +0900 | [diff] [blame] | 24 | "gerrit.opencord.org/voltha-bbsim/device" |
| 25 | "gerrit.opencord.org/voltha-bbsim/protos" |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame^] | 26 | log "github.com/sirupsen/logrus" |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 27 | ) |
| 28 | |
Keita NISHIMOTO | 9c6f6f1 | 2018-10-18 04:56:34 +0900 | [diff] [blame] | 29 | func sendOltIndUp(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 30 | data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "up"}} |
| 31 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 32 | logger.Error("Failed to send OLT UP indication: %v\n", err) |
Keita NISHIMOTO | 9c6f6f1 | 2018-10-18 04:56:34 +0900 | [diff] [blame] | 33 | return err |
| 34 | } |
| 35 | return nil |
| 36 | } |
| 37 | |
| 38 | func sendOltIndDown(stream openolt.Openolt_EnableIndicationServer) error { |
| 39 | data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "down"}} |
| 40 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 41 | logger.Error("Failed to send OLT DOWN indication: %v\n", err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 42 | return err |
| 43 | } |
| 44 | return nil |
| 45 | } |
| 46 | |
| 47 | func sendIntfInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error { |
| 48 | for i := uint32(0); i < olt.NumPonIntf+olt.NumNniIntf; i++ { |
| 49 | intf := olt.Intfs[i] |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 50 | 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] | 51 | data := &openolt.Indication_IntfInd{&openolt.IntfIndication{IntfId: intf.IntfID, OperState: intf.OperState}} |
| 52 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 53 | logger.Error("Failed to send Intf [id: %d] indication : %v\n", i, err) |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 54 | return err |
| 55 | } |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 56 | logger.Info("SendIntfInd olt:%d intf:%d (%s)\n", olt.ID, intf.IntfID, intf.Type) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 57 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 58 | } |
| 59 | return nil |
| 60 | } |
| 61 | |
| 62 | func sendOperInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error { |
| 63 | for i := uint32(0); i < olt.NumPonIntf+olt.NumNniIntf; i++ { |
| 64 | intf := olt.Intfs[i] |
| 65 | data := &openolt.Indication_IntfOperInd{&openolt.IntfOperIndication{Type: intf.Type, IntfId: intf.IntfID, OperState: intf.OperState}} |
| 66 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 67 | logger.Error("Failed to send IntfOper [id: %d] indication : %v\n", i, err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 68 | return err |
| 69 | } |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 70 | logger.Info("SendOperInd olt:%d intf:%d (%s)\n", olt.ID, intf.IntfID, intf.Type) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 71 | } |
| 72 | return nil |
| 73 | } |
| 74 | |
| 75 | func sendOnuDiscInd(stream openolt.Openolt_EnableIndicationServer, onus []*device.Onu) error { |
| 76 | for i, onu := range onus { |
| 77 | data := &openolt.Indication_OnuDiscInd{&openolt.OnuDiscIndication{IntfId: onu.IntfID, SerialNumber: onu.SerialNumber}} |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 78 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 79 | logger.Error("Failed to send ONUDiscInd [id: %d]: %v\n", i, err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 80 | return err |
| 81 | } |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame^] | 82 | logger.WithFields(log.Fields{ |
| 83 | "serial_number": utils.OnuToSn(onu), |
| 84 | "interfaceId": onu.IntfID, |
| 85 | "onuId": onu.OnuID, |
| 86 | "oltId": onu.OltID, |
| 87 | }).Info("sendONUDiscInd Onuid") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 88 | } |
| 89 | return nil |
| 90 | } |
| 91 | |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 92 | func sendOnuInd(stream openolt.Openolt_EnableIndicationServer, onus []*device.Onu, delay int) error { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 93 | for i, onu := range onus { |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 94 | time.Sleep(time.Duration(delay) * time.Second) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 95 | 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] | 96 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame] | 97 | logger.Error("Failed to send ONUInd [id: %d]: %v\n", i, err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 98 | return err |
| 99 | } |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame^] | 100 | logger.WithFields(log.Fields{ |
| 101 | "serial_number": utils.OnuToSn(onu), |
| 102 | "interfaceId": onu.IntfID, |
| 103 | "onuId": onu.OnuID, |
| 104 | "oltId": onu.OltID, |
| 105 | }).Info("sendONUInd Onuid") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 106 | } |
| 107 | return nil |
| 108 | } |