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] |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame^] | 37 | if intf.Type == "pon"{ // There is no need to send IntfInd for NNI |
| 38 | data := &openolt.Indication_IntfInd{&openolt.IntfIndication{IntfId: intf.IntfID, OperState: intf.OperState}} |
| 39 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 40 | log.Printf("Failed to send Intf [id: %d] indication : %v\n", i, err) |
| 41 | return err |
| 42 | } |
| 43 | 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] | 44 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 45 | } |
| 46 | return nil |
| 47 | } |
| 48 | |
| 49 | func sendOperInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error { |
| 50 | for i := uint32(0); i < olt.NumPonIntf+olt.NumNniIntf; i++ { |
| 51 | intf := olt.Intfs[i] |
| 52 | data := &openolt.Indication_IntfOperInd{&openolt.IntfOperIndication{Type: intf.Type, IntfId: intf.IntfID, OperState: intf.OperState}} |
| 53 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 54 | log.Printf("Failed to send IntfOper [id: %d] indication : %v\n", i, err) |
| 55 | return err |
| 56 | } |
| 57 | log.Printf("SendOperInd olt:%d intf:%d (%s)\n", olt.ID, intf.IntfID, intf.Type) |
| 58 | } |
| 59 | return nil |
| 60 | } |
| 61 | |
| 62 | func sendOnuDiscInd(stream openolt.Openolt_EnableIndicationServer, onus []*device.Onu) error { |
| 63 | for i, onu := range onus { |
| 64 | data := &openolt.Indication_OnuDiscInd{&openolt.OnuDiscIndication{IntfId: onu.IntfID, SerialNumber: onu.SerialNumber}} |
| 65 | log.Printf("sendONUDiscInd Onuid: %d\n", i) |
| 66 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 67 | log.Printf("Failed to send ONUDiscInd [id: %d]: %v\n", i, err) |
| 68 | return err |
| 69 | } |
| 70 | } |
| 71 | return nil |
| 72 | } |
| 73 | |
| 74 | func sendOnuInd(stream openolt.Openolt_EnableIndicationServer, onus []*device.Onu) error { |
| 75 | for i, onu := range onus { |
| 76 | data := &openolt.Indication_OnuInd{&openolt.OnuIndication{IntfId: onu.IntfID, OnuId: onu.OnuID, OperState: "up", AdminState: "up", SerialNumber: onu.SerialNumber}} |
| 77 | log.Printf("sendONUInd Onuid: %d\n", i) |
| 78 | if err := stream.Send(&openolt.Indication{Data: data}); err != nil { |
| 79 | log.Printf("Failed to send ONUInd [id: %d]: %v\n", i, err) |
| 80 | return err |
| 81 | } |
| 82 | } |
| 83 | return nil |
| 84 | } |