blob: dbb764486447771250e975ae1d0b89472ca2c710 [file] [log] [blame]
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +09001/*
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
17package core
18
19import (
20 "gerrit.opencord.org/voltha-bbsim/protos"
21 "gerrit.opencord.org/voltha-bbsim/device"
22 "log"
23)
24
Keita NISHIMOTO9c6f6f12018-10-18 04:56:34 +090025func sendOltIndUp(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error {
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090026 data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "up"}}
27 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Keita NISHIMOTO9c6f6f12018-10-18 04:56:34 +090028 log.Printf("Failed to send OLT UP indication: %v\n", err)
29 return err
30 }
31 return nil
32}
33
34func 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 NISHIMOTO3b8b9c02018-10-09 09:40:01 +090038 return err
39 }
40 return nil
41}
42
43func 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 NISHIMOTOca4da5f2018-10-15 22:48:52 +090046 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 NISHIMOTO3b8b9c02018-10-09 09:40:01 +090053 }
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090054 }
55 return nil
56}
57
58func 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
71func 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
83func 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}