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 ( |
| 20 | "gerrit.opencord.org/voltha-bbsim/protos" |
| 21 | "gerrit.opencord.org/voltha-bbsim/device" |
| 22 | "log" |
| 23 | ) |
| 24 | |
Keita NISHIMOTO | 9c6f6f1 | 2018-10-18 04:56:34 +0900 | [diff] [blame] | 25 | func sendOltIndUp(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 26 | data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "up"}} |
| 27 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
Keita NISHIMOTO | 9c6f6f1 | 2018-10-18 04:56:34 +0900 | [diff] [blame] | 28 | log.Printf("Failed to send OLT UP indication: %v\n", err) |
| 29 | return err |
| 30 | } |
| 31 | return nil |
| 32 | } |
| 33 | |
| 34 | func sendOltIndDown(stream openolt.Openolt_EnableIndicationServer) error { |
| 35 | data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "down"}} |
| 36 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 37 | log.Printf("Failed to send OLT DOWN indication: %v\n", err) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 38 | return err |
| 39 | } |
| 40 | return nil |
| 41 | } |
| 42 | |
| 43 | func sendIntfInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error { |
| 44 | for i := uint32(0); i < olt.NumPonIntf+olt.NumNniIntf; i++ { |
| 45 | intf := olt.Intfs[i] |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 46 | if intf.Type == "pon"{ // There is no need to send IntfInd for NNI |
| 47 | data := &openolt.Indication_IntfInd{&openolt.IntfIndication{IntfId: intf.IntfID, OperState: intf.OperState}} |
| 48 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 49 | log.Printf("Failed to send Intf [id: %d] indication : %v\n", i, err) |
| 50 | return err |
| 51 | } |
| 52 | log.Printf("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] | 53 | } |
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 { |
| 59 | for i := uint32(0); i < olt.NumPonIntf+olt.NumNniIntf; i++ { |
| 60 | intf := olt.Intfs[i] |
| 61 | data := &openolt.Indication_IntfOperInd{&openolt.IntfOperIndication{Type: intf.Type, IntfId: intf.IntfID, OperState: intf.OperState}} |
| 62 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 63 | log.Printf("Failed to send IntfOper [id: %d] indication : %v\n", i, err) |
| 64 | return err |
| 65 | } |
| 66 | log.Printf("SendOperInd olt:%d intf:%d (%s)\n", olt.ID, intf.IntfID, intf.Type) |
| 67 | } |
| 68 | return nil |
| 69 | } |
| 70 | |
| 71 | func sendOnuDiscInd(stream openolt.Openolt_EnableIndicationServer, onus []*device.Onu) error { |
| 72 | for i, onu := range onus { |
| 73 | data := &openolt.Indication_OnuDiscInd{&openolt.OnuDiscIndication{IntfId: onu.IntfID, SerialNumber: onu.SerialNumber}} |
| 74 | log.Printf("sendONUDiscInd Onuid: %d\n", i) |
| 75 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 76 | log.Printf("Failed to send ONUDiscInd [id: %d]: %v\n", i, err) |
| 77 | return err |
| 78 | } |
| 79 | } |
| 80 | return nil |
| 81 | } |
| 82 | |
| 83 | func sendOnuInd(stream openolt.Openolt_EnableIndicationServer, onus []*device.Onu) error { |
| 84 | for i, onu := range onus { |
| 85 | data := &openolt.Indication_OnuInd{&openolt.OnuIndication{IntfId: onu.IntfID, OnuId: onu.OnuID, OperState: "up", AdminState: "up", SerialNumber: onu.SerialNumber}} |
| 86 | log.Printf("sendONUInd Onuid: %d\n", i) |
| 87 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 88 | log.Printf("Failed to send ONUInd [id: %d]: %v\n", i, err) |
| 89 | return err |
| 90 | } |
| 91 | } |
| 92 | return nil |
| 93 | } |