blob: 40d14e5d538ec72449986b19735ef97a56296627 [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 "gerrit.opencord.org/voltha-bbsim/common/logger"
21 "gerrit.opencord.org/voltha-bbsim/common/utils"
Keita NISHIMOTO9708e042018-10-27 09:24:44 +090022 "gerrit.opencord.org/voltha-bbsim/device"
23 "gerrit.opencord.org/voltha-bbsim/protos"
Keita NISHIMOTO2f8a6a42019-02-08 09:47:07 +090024 "time"
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090025)
26
Keita NISHIMOTO9c6f6f12018-10-18 04:56:34 +090027func sendOltIndUp(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error {
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090028 data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "up"}}
29 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080030 logger.Error("Failed to send OLT UP indication: %v", err)
Keita NISHIMOTO9c6f6f12018-10-18 04:56:34 +090031 return err
32 }
33 return nil
34}
35
36func sendOltIndDown(stream openolt.Openolt_EnableIndicationServer) error {
37 data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "down"}}
38 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080039 logger.Error("Failed to send OLT DOWN indication: %v", err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090040 return err
41 }
42 return nil
43}
44
45func sendIntfInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error {
46 for i := uint32(0); i < olt.NumPonIntf+olt.NumNniIntf; i++ {
47 intf := olt.Intfs[i]
Matteo Scandolo4549d3f2018-10-19 12:48:20 -070048 if intf.Type == "pon" { // There is no need to send IntfInd for NNI
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +090049 data := &openolt.Indication_IntfInd{&openolt.IntfIndication{IntfId: intf.IntfID, OperState: intf.OperState}}
50 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080051 logger.Error("Failed to send Intf [id: %d] indication : %v", i, err)
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +090052 return err
53 }
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080054 logger.Info("SendIntfInd olt:%d intf:%d (%s)", olt.ID, intf.IntfID, intf.Type)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090055 }
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090056 }
57 return nil
58}
59
60func sendOperInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error {
61 for i := uint32(0); i < olt.NumPonIntf+olt.NumNniIntf; i++ {
62 intf := olt.Intfs[i]
63 data := &openolt.Indication_IntfOperInd{&openolt.IntfOperIndication{Type: intf.Type, IntfId: intf.IntfID, OperState: intf.OperState}}
64 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080065 logger.Error("Failed to send IntfOper [id: %d] indication : %v", i, err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090066 return err
67 }
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080068 logger.Info("SendOperInd olt:%d intf:%d (%s)", olt.ID, intf.IntfID, intf.Type)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090069 }
70 return nil
71}
72
73func sendOnuDiscInd(stream openolt.Openolt_EnableIndicationServer, onus []*device.Onu) error {
74 for i, onu := range onus {
75 data := &openolt.Indication_OnuDiscInd{&openolt.OnuDiscIndication{IntfId: onu.IntfID, SerialNumber: onu.SerialNumber}}
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090076 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080077 logger.Error("Failed to send ONUDiscInd [id: %d]: %v", i, err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090078 return err
79 }
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080080 utils.LoggerWithOnu(onu).Info("sendONUDiscInd Onuid")
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090081 }
82 return nil
83}
84
Matteo Scandolo4549d3f2018-10-19 12:48:20 -070085func sendOnuInd(stream openolt.Openolt_EnableIndicationServer, onus []*device.Onu, delay int) error {
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090086 for i, onu := range onus {
Mahir Gunyel0fc2b742019-02-20 16:45:30 -080087 time.Sleep(time.Duration(delay) * time.Millisecond)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090088 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 +090089 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080090 logger.Error("Failed to send ONUInd [id: %d]: %v", i, err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090091 return err
92 }
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080093 utils.LoggerWithOnu(onu).Info("sendONUInd Onuid")
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090094 }
95 return nil
96}