blob: 364d0c3a03e7788f2121f9f692a3b3f595070732 [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 (
Matteo Scandolo88e91892018-11-06 16:29:19 -080020 "time"
21
22 "gerrit.opencord.org/voltha-bbsim/common/logger"
23 "gerrit.opencord.org/voltha-bbsim/common/utils"
Keita NISHIMOTO9708e042018-10-27 09:24:44 +090024 "gerrit.opencord.org/voltha-bbsim/device"
25 "gerrit.opencord.org/voltha-bbsim/protos"
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090026)
27
Keita NISHIMOTO9c6f6f12018-10-18 04:56:34 +090028func sendOltIndUp(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error {
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090029 data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "up"}}
30 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080031 logger.Error("Failed to send OLT UP indication: %v", err)
Keita NISHIMOTO9c6f6f12018-10-18 04:56:34 +090032 return err
33 }
34 return nil
35}
36
37func sendOltIndDown(stream openolt.Openolt_EnableIndicationServer) error {
38 data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "down"}}
39 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080040 logger.Error("Failed to send OLT DOWN indication: %v", err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090041 return err
42 }
43 return nil
44}
45
46func sendIntfInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error {
47 for i := uint32(0); i < olt.NumPonIntf+olt.NumNniIntf; i++ {
48 intf := olt.Intfs[i]
Matteo Scandolo4549d3f2018-10-19 12:48:20 -070049 if intf.Type == "pon" { // There is no need to send IntfInd for NNI
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +090050 data := &openolt.Indication_IntfInd{&openolt.IntfIndication{IntfId: intf.IntfID, OperState: intf.OperState}}
51 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080052 logger.Error("Failed to send Intf [id: %d] indication : %v", i, err)
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +090053 return err
54 }
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080055 logger.Info("SendIntfInd olt:%d intf:%d (%s)", olt.ID, intf.IntfID, intf.Type)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090056 }
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090057 }
58 return nil
59}
60
61func sendOperInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error {
62 for i := uint32(0); i < olt.NumPonIntf+olt.NumNniIntf; i++ {
63 intf := olt.Intfs[i]
64 data := &openolt.Indication_IntfOperInd{&openolt.IntfOperIndication{Type: intf.Type, IntfId: intf.IntfID, OperState: intf.OperState}}
65 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080066 logger.Error("Failed to send IntfOper [id: %d] indication : %v", i, err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090067 return err
68 }
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080069 logger.Info("SendOperInd olt:%d intf:%d (%s)", olt.ID, intf.IntfID, intf.Type)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090070 }
71 return nil
72}
73
74func sendOnuDiscInd(stream openolt.Openolt_EnableIndicationServer, onus []*device.Onu) error {
75 for i, onu := range onus {
76 data := &openolt.Indication_OnuDiscInd{&openolt.OnuDiscIndication{IntfId: onu.IntfID, SerialNumber: onu.SerialNumber}}
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090077 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080078 logger.Error("Failed to send ONUDiscInd [id: %d]: %v", i, err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090079 return err
80 }
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080081 utils.LoggerWithOnu(onu).Info("sendONUDiscInd Onuid")
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090082 }
83 return nil
84}
85
Matteo Scandolo4549d3f2018-10-19 12:48:20 -070086func sendOnuInd(stream openolt.Openolt_EnableIndicationServer, onus []*device.Onu, delay int) error {
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090087 for i, onu := range onus {
Matteo Scandolo4549d3f2018-10-19 12:48:20 -070088 time.Sleep(time.Duration(delay) * time.Second)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090089 data := &openolt.Indication_OnuInd{&openolt.OnuIndication{IntfId: onu.IntfID, OnuId: onu.OnuID, OperState: "up", AdminState: "up", SerialNumber: onu.SerialNumber}}
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090090 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080091 logger.Error("Failed to send ONUInd [id: %d]: %v", i, err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090092 return err
93 }
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080094 utils.LoggerWithOnu(onu).Info("sendONUInd Onuid")
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090095 }
96 return nil
97}