blob: ffded4d7e490f719ed752c0a1a8cf867a9b927cc [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
25func 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
34func 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 NISHIMOTOca4da5f2018-10-15 22:48:52 +090037 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 NISHIMOTO3b8b9c02018-10-09 09:40:01 +090044 }
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090045 }
46 return nil
47}
48
49func 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
62func 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
74func 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}