blob: 41e6548c1325a1cdca1ff1ea1570582e3b9df55a [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"
Matteo Scandolo88e91892018-11-06 16:29:19 -080026 log "github.com/sirupsen/logrus"
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090027)
28
Keita NISHIMOTO9c6f6f12018-10-18 04:56:34 +090029func sendOltIndUp(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error {
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090030 data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "up"}}
31 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090032 logger.Error("Failed to send OLT UP indication: %v\n", err)
Keita NISHIMOTO9c6f6f12018-10-18 04:56:34 +090033 return err
34 }
35 return nil
36}
37
38func sendOltIndDown(stream openolt.Openolt_EnableIndicationServer) error {
39 data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "down"}}
40 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090041 logger.Error("Failed to send OLT DOWN indication: %v\n", err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090042 return err
43 }
44 return nil
45}
46
47func sendIntfInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error {
48 for i := uint32(0); i < olt.NumPonIntf+olt.NumNniIntf; i++ {
49 intf := olt.Intfs[i]
Matteo Scandolo4549d3f2018-10-19 12:48:20 -070050 if intf.Type == "pon" { // There is no need to send IntfInd for NNI
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +090051 data := &openolt.Indication_IntfInd{&openolt.IntfIndication{IntfId: intf.IntfID, OperState: intf.OperState}}
52 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090053 logger.Error("Failed to send Intf [id: %d] indication : %v\n", i, err)
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +090054 return err
55 }
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090056 logger.Info("SendIntfInd olt:%d intf:%d (%s)\n", olt.ID, intf.IntfID, intf.Type)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090057 }
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090058 }
59 return nil
60}
61
62func sendOperInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error {
63 for i := uint32(0); i < olt.NumPonIntf+olt.NumNniIntf; i++ {
64 intf := olt.Intfs[i]
65 data := &openolt.Indication_IntfOperInd{&openolt.IntfOperIndication{Type: intf.Type, IntfId: intf.IntfID, OperState: intf.OperState}}
66 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090067 logger.Error("Failed to send IntfOper [id: %d] indication : %v\n", i, err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090068 return err
69 }
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090070 logger.Info("SendOperInd olt:%d intf:%d (%s)\n", olt.ID, intf.IntfID, intf.Type)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090071 }
72 return nil
73}
74
75func sendOnuDiscInd(stream openolt.Openolt_EnableIndicationServer, onus []*device.Onu) error {
76 for i, onu := range onus {
77 data := &openolt.Indication_OnuDiscInd{&openolt.OnuDiscIndication{IntfId: onu.IntfID, SerialNumber: onu.SerialNumber}}
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090078 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090079 logger.Error("Failed to send ONUDiscInd [id: %d]: %v\n", i, err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090080 return err
81 }
Matteo Scandolo88e91892018-11-06 16:29:19 -080082 logger.WithFields(log.Fields{
83 "serial_number": utils.OnuToSn(onu),
84 "interfaceId": onu.IntfID,
85 "onuId": onu.OnuID,
86 "oltId": onu.OltID,
87 }).Info("sendONUDiscInd Onuid")
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090088 }
89 return nil
90}
91
Matteo Scandolo4549d3f2018-10-19 12:48:20 -070092func sendOnuInd(stream openolt.Openolt_EnableIndicationServer, onus []*device.Onu, delay int) error {
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090093 for i, onu := range onus {
Matteo Scandolo4549d3f2018-10-19 12:48:20 -070094 time.Sleep(time.Duration(delay) * time.Second)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090095 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 +090096 if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
Keita NISHIMOTOc66b8eb2018-10-20 07:19:39 +090097 logger.Error("Failed to send ONUInd [id: %d]: %v\n", i, err)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090098 return err
99 }
Matteo Scandolo88e91892018-11-06 16:29:19 -0800100 logger.WithFields(log.Fields{
101 "serial_number": utils.OnuToSn(onu),
102 "interfaceId": onu.IntfID,
103 "onuId": onu.OnuID,
104 "oltId": onu.OltID,
105 }).Info("sendONUInd Onuid")
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900106 }
107 return nil
108}