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 | |
| 25 | func sendOltInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error { |
| 26 | data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "up"}} |
| 27 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 28 | log.Printf("Failed to send OLT indication: %v\n", err) |
| 29 | return err |
| 30 | } |
| 31 | return nil |
| 32 | } |
| 33 | |
| 34 | func sendIntfInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error { |
| 35 | for i := uint32(0); i < olt.NumPonIntf+olt.NumNniIntf; i++ { |
| 36 | intf := olt.Intfs[i] |
| 37 | data := &openolt.Indication_IntfInd{&openolt.IntfIndication{IntfId: intf.IntfID, OperState: intf.OperState}} |
| 38 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 39 | log.Printf("Failed to send Intf [id: %d] indication : %v\n", i, err) |
| 40 | return err |
| 41 | } |
| 42 | log.Printf("SendIntfInd olt:%d intf:%d (%s)\n", olt.ID, intf.IntfID, intf.Type) |
| 43 | } |
| 44 | return nil |
| 45 | } |
| 46 | |
| 47 | func sendOperInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error { |
| 48 | for i := uint32(0); i < olt.NumPonIntf+olt.NumNniIntf; i++ { |
| 49 | intf := olt.Intfs[i] |
| 50 | data := &openolt.Indication_IntfOperInd{&openolt.IntfOperIndication{Type: intf.Type, IntfId: intf.IntfID, OperState: intf.OperState}} |
| 51 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 52 | log.Printf("Failed to send IntfOper [id: %d] indication : %v\n", i, err) |
| 53 | return err |
| 54 | } |
| 55 | log.Printf("SendOperInd olt:%d intf:%d (%s)\n", olt.ID, intf.IntfID, intf.Type) |
| 56 | } |
| 57 | return nil |
| 58 | } |
| 59 | |
| 60 | func sendOnuDiscInd(stream openolt.Openolt_EnableIndicationServer, onus []*device.Onu) error { |
| 61 | for i, onu := range onus { |
| 62 | data := &openolt.Indication_OnuDiscInd{&openolt.OnuDiscIndication{IntfId: onu.IntfID, SerialNumber: onu.SerialNumber}} |
| 63 | log.Printf("sendONUDiscInd Onuid: %d\n", i) |
| 64 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 65 | log.Printf("Failed to send ONUDiscInd [id: %d]: %v\n", i, err) |
| 66 | return err |
| 67 | } |
| 68 | } |
| 69 | return nil |
| 70 | } |
| 71 | |
| 72 | func sendOnuInd(stream openolt.Openolt_EnableIndicationServer, onus []*device.Onu) error { |
| 73 | for i, onu := range onus { |
| 74 | data := &openolt.Indication_OnuInd{&openolt.OnuIndication{IntfId: onu.IntfID, OnuId: onu.OnuID, OperState: "up", AdminState: "up", SerialNumber: onu.SerialNumber}} |
| 75 | log.Printf("sendONUInd Onuid: %d\n", i) |
| 76 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 77 | log.Printf("Failed to send ONUInd [id: %d]: %v\n", i, err) |
| 78 | return err |
| 79 | } |
| 80 | } |
| 81 | return nil |
| 82 | } |