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 | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 20 | "time" |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 21 | "gerrit.opencord.org/voltha-bbsim/protos" |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 22 | "gerrit.opencord.org/voltha-bbsim/device" |
| 23 | "gerrit.opencord.org/voltha-bbsim/common" |
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 { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 29 | logger.Error("Failed to send OLT UP indication: %v\n", 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 { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 38 | logger.Error("Failed to send OLT DOWN indication: %v\n", 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 { |
| 45 | for i := uint32(0); i < olt.NumPonIntf+olt.NumNniIntf; i++ { |
| 46 | intf := olt.Intfs[i] |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 47 | 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] | 48 | data := &openolt.Indication_IntfInd{&openolt.IntfIndication{IntfId: intf.IntfID, OperState: intf.OperState}} |
| 49 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 50 | 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] | 51 | return err |
| 52 | } |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 53 | 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] | 54 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 55 | } |
| 56 | return nil |
| 57 | } |
| 58 | |
| 59 | func sendOperInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error { |
| 60 | for i := uint32(0); i < olt.NumPonIntf+olt.NumNniIntf; i++ { |
| 61 | intf := olt.Intfs[i] |
| 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 { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 64 | 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] | 65 | return err |
| 66 | } |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 67 | 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] | 68 | } |
| 69 | return nil |
| 70 | } |
| 71 | |
| 72 | func sendOnuDiscInd(stream openolt.Openolt_EnableIndicationServer, onus []*device.Onu) error { |
| 73 | for i, onu := range onus { |
| 74 | data := &openolt.Indication_OnuDiscInd{&openolt.OnuDiscIndication{IntfId: onu.IntfID, SerialNumber: onu.SerialNumber}} |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 75 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 76 | logger.Error("Failed to send ONUDiscInd [id: %d]: %v\n", i, err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 77 | return err |
| 78 | } |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 79 | logger.Info("sendONUDiscInd Onuid: %d\n", i) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 80 | } |
| 81 | return nil |
| 82 | } |
| 83 | |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 84 | func sendOnuInd(stream openolt.Openolt_EnableIndicationServer, onus []*device.Onu, delay int) error { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 85 | for i, onu := range onus { |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame] | 86 | time.Sleep(time.Duration(delay) * time.Second) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 87 | 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] | 88 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 89 | logger.Error("Failed to send ONUInd [id: %d]: %v\n", i, err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 90 | return err |
| 91 | } |
Keita NISHIMOTO | c66b8eb | 2018-10-20 07:19:39 +0900 | [diff] [blame^] | 92 | logger.Info("sendONUInd Onuid: %d\n", i) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 93 | } |
| 94 | return nil |
| 95 | } |