blob: dc75317ea365c512e09ad420bb206ad7b81c3a38 [file] [log] [blame]
Shad Ansari01b0e652018-04-05 21:02:53 +00001/*
2 Copyright (C) 2018 Open Networking Foundation
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#include "indications.h"
Shad Ansarib7b0ced2018-05-11 21:53:32 +000018#include "core.h"
Shad Ansari01b0e652018-04-05 21:02:53 +000019#include "utils.h"
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040020#include "stats_collection.h"
Nicolas Palpacuera32f4c32018-06-28 12:55:10 -040021#include "translation.h"
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -040022#include "state.h"
23
Nicolas Palpacuera32f4c32018-06-28 12:55:10 -040024#include <string>
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -040025
Shad Ansari01b0e652018-04-05 21:02:53 +000026extern "C"
27{
28#include <bcmos_system.h>
Jason Huangd33b4d82019-05-15 18:22:57 +080029#include <bcmolt_api.h>
30#include <bcmolt_host_api.h>
31#include <bcmolt_api_model_api_structs.h>
Shad Ansari01b0e652018-04-05 21:02:53 +000032}
33
34using grpc::Status;
35
Shad Ansari627b5782018-08-13 22:49:32 +000036extern Queue<openolt::Indication> oltIndQ;
Shad Ansari01b0e652018-04-05 21:02:53 +000037//Queue<openolt::Indication*> oltIndQ;
38
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -040039
Shad Ansari01b0e652018-04-05 21:02:53 +000040bool subscribed = false;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -080041uint32_t nni_intf_id = 0;
Jason Huangd33b4d82019-05-15 18:22:57 +080042#define current_device 0
Shad Ansari01b0e652018-04-05 21:02:53 +000043
Jason Huangd33b4d82019-05-15 18:22:57 +080044static void OmciIndication(bcmolt_devid olt, bcmolt_msg *msg);
Shad Ansari01b0e652018-04-05 21:02:53 +000045
Jason Huangd33b4d82019-05-15 18:22:57 +080046#define INTERFACE_STATE_IF_DOWN(state) \
47 ((state == BCMOLT_INTERFACE_STATE_INACTIVE || \
48 state == BCMOLT_INTERFACE_STATE_PROCESSING || \
49 state == BCMOLT_INTERFACE_STATE_ACTIVE_STANDBY) ? BCMOS_TRUE : BCMOS_FALSE)
50#define INTERFACE_STATE_IF_UP(state) \
51 ((state == BCMOLT_INTERFACE_STATE_ACTIVE_WORKING) ? BCMOS_TRUE : BCMOS_FALSE)
52#define ONU_STATE_IF_DOWN(state) \
53 ((state == BCMOLT_ONU_OPERATION_INACTIVE || \
54 state == BCMOLT_ONU_OPERATION_DISABLE || \
55 state == BCMOLT_ONU_OPERATION_ACTIVE_STANDBY) ? BCMOS_TRUE : BCMOS_FALSE)
56#define ONU_STATE_IF_UP(state) \
57 ((state == BCMOLT_ONU_OPERATION_ACTIVE) ? BCMOS_TRUE : BCMOS_FALSE)
Jason Huangb1fad572019-05-28 19:02:30 +080058#define ONU_RANGING_STATE_IF_UP(state) \
59 ((state == BCMOLT_RESULT_SUCCESS) ? BCMOS_TRUE : BCMOS_FALSE)
60#define ONU_RANGING_STATE_IF_DOWN(state) \
61 ((state != BCMOLT_RESULT_SUCCESS) ? BCMOS_TRUE : BCMOS_FALSE)
Jason Huang88795222019-06-13 19:28:44 +080062#define SET_OPER_STATE(indication,state) \
63 (INTERFACE_STATE_IF_UP(state)) ? indication->set_oper_state("up") : \
64 indication->set_oper_state("down")
Jason Huang439d24f2019-06-26 03:25:05 +080065#define GET_FLOW_TYPE(type) \
66 (type == BCMOLT_FLOW_TYPE_UPSTREAM) ? "upstream" : \
67 (type == BCMOLT_FLOW_TYPE_DOWNSTREAM) ? "downstream" : \
68 (type == BCMOLT_FLOW_TYPE_MULTICAST) ? "multicast" : "unknown"
Jason Huangd33b4d82019-05-15 18:22:57 +080069
Jason Huang439d24f2019-06-26 03:25:05 +080070std::string bcmolt_to_grpc_intf_type(bcmolt_interface_type intf_type)
Craig Lutgen88a22ad2018-10-04 12:30:46 -050071{
Jason Huangd33b4d82019-05-15 18:22:57 +080072 if (intf_type == BCMOLT_INTERFACE_TYPE_NNI) {
Craig Lutgen88a22ad2018-10-04 12:30:46 -050073 return "nni";
Jason Huangd33b4d82019-05-15 18:22:57 +080074 } else if (intf_type == BCMOLT_INTERFACE_TYPE_PON) {
Craig Lutgen88a22ad2018-10-04 12:30:46 -050075 return "pon";
Jason Huangb6843dc2019-07-22 17:46:06 +080076 } else if (intf_type == BCMOLT_INTERFACE_TYPE_HOST) {
77 return "host";
78 }
79 return "unknown";
80}
81
82std::string bcmolt_to_grpc_flow_intf_type(bcmolt_flow_interface_type intf_type)
83{
84 if (intf_type == BCMOLT_FLOW_INTERFACE_TYPE_NNI) {
85 return "nni";
86 } else if (intf_type == BCMOLT_FLOW_INTERFACE_TYPE_PON) {
87 return "pon";
88 } else if (intf_type == BCMOLT_FLOW_INTERFACE_TYPE_HOST) {
89 return "host";
Craig Lutgen88a22ad2018-10-04 12:30:46 -050090 }
91 return "unknown";
92}
93
Jason Huangd33b4d82019-05-15 18:22:57 +080094static void OltOperIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Shad Ansari01b0e652018-04-05 21:02:53 +000095 openolt::Indication ind;
96 openolt::OltIndication* olt_ind = new openolt::OltIndication;
97 Status status;
Craig Lutgen88a22ad2018-10-04 12:30:46 -050098 std::string admin_state;
Craig Lutgen88a22ad2018-10-04 12:30:46 -050099
Jason Huangd33b4d82019-05-15 18:22:57 +0800100 switch (msg->subgroup) {
101 case BCMOLT_DEVICE_AUTO_SUBGROUP_CONNECTION_COMPLETE:
Jason Huangd33b4d82019-05-15 18:22:57 +0800102 admin_state = "up";
103 olt_ind->set_oper_state("up");
104 break;
105 case BCMOLT_DEVICE_AUTO_SUBGROUP_DISCONNECTION_COMPLETE:
106 admin_state = "down";
107 olt_ind->set_oper_state("down");
108 break;
109 case BCMOLT_DEVICE_AUTO_SUBGROUP_CONNECTION_FAILURE:
110 admin_state = "failure";
111 olt_ind->set_oper_state("failure");
112 break;
Shad Ansari01b0e652018-04-05 21:02:53 +0000113 }
114 ind.set_allocated_olt_ind(olt_ind);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500115
Jason Huangd33b4d82019-05-15 18:22:57 +0800116 if (msg->subgroup == BCMOLT_DEVICE_AUTO_SUBGROUP_CONNECTION_COMPLETE) {
Jason Huangd33b4d82019-05-15 18:22:57 +0800117 /* register for omci indication */
118 {
119 bcmolt_rx_cfg rx_cfg = {};
120 rx_cfg.obj_type = BCMOLT_OBJ_ID_ONU;
121 rx_cfg.rx_cb = OmciIndication;
122 rx_cfg.subgroup = bcmolt_onu_auto_subgroup_omci_packet;
123 rx_cfg.module = BCMOS_MODULE_ID_OMCI_TRANSPORT;
124 bcmolt_ind_subscribe(current_device, &rx_cfg);
125 }
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500126 state.activate();
127 }
128 else {
129 state.deactivate();
130 }
131
Jason Huangd33b4d82019-05-15 18:22:57 +0800132 oltIndQ.push(ind);
133 bcmolt_msg_free(msg);
Shad Ansari01b0e652018-04-05 21:02:53 +0000134}
135
Jason Huangd33b4d82019-05-15 18:22:57 +0800136static void LosIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Shad Ansari01b0e652018-04-05 21:02:53 +0000137 openolt::Indication ind;
Nicolas Palpacuera32f4c32018-06-28 12:55:10 -0400138 openolt::AlarmIndication* alarm_ind = new openolt::AlarmIndication;
139 openolt::LosIndication* los_ind = new openolt::LosIndication;
140
Jason Huangd33b4d82019-05-15 18:22:57 +0800141 switch (msg->obj_type) {
142 case BCMOLT_OBJ_ID_PON_INTERFACE:
143 switch (msg->subgroup) {
144 case BCMOLT_PON_INTERFACE_AUTO_SUBGROUP_LOS:
145 {
146 bcmolt_pon_interface_los* bcm_los_ind = (bcmolt_pon_interface_los *) msg;
147 int intf_id = interface_key_to_port_no(bcm_los_ind->key.pon_ni,
148 BCMOLT_INTERFACE_TYPE_PON);
149 std::string status = alarm_status_to_string(bcm_los_ind->data.status);
Nicolas Palpacuera32f4c32018-06-28 12:55:10 -0400150
Jason Huangb6843dc2019-07-22 17:46:06 +0800151 OPENOLT_LOG(INFO, openolt_log_id, "LOS indication : intf_id: %d port: %d status %s\n",
Jason Huangd33b4d82019-05-15 18:22:57 +0800152 bcm_los_ind->key.pon_ni, intf_id, status.c_str());
Nicolas Palpacuera32f4c32018-06-28 12:55:10 -0400153
Jason Huangd33b4d82019-05-15 18:22:57 +0800154 los_ind->set_intf_id(intf_id);
155 los_ind->set_status(status);
Nicolas Palpacuera32f4c32018-06-28 12:55:10 -0400156
Jason Huangd33b4d82019-05-15 18:22:57 +0800157 alarm_ind->set_allocated_los_ind(los_ind);
158 ind.set_allocated_alarm_ind(alarm_ind);
159 break;
160 }
161 }
162 }
Nicolas Palpacuera32f4c32018-06-28 12:55:10 -0400163
164 oltIndQ.push(ind);
Jason Huangd33b4d82019-05-15 18:22:57 +0800165 bcmolt_msg_free(msg);
Shad Ansari01b0e652018-04-05 21:02:53 +0000166}
167
Jason Huangd33b4d82019-05-15 18:22:57 +0800168static void IfIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700169 openolt::Indication ind;
170 openolt::IntfIndication* intf_ind = new openolt::IntfIndication;
171
Jason Huangd33b4d82019-05-15 18:22:57 +0800172 switch (msg->obj_type) {
173 case BCMOLT_OBJ_ID_PON_INTERFACE:
174 switch (msg->subgroup) {
175 case BCMOLT_PON_INTERFACE_AUTO_SUBGROUP_STATE_CHANGE_COMPLETED:
176 {
Jason Huangd33b4d82019-05-15 18:22:57 +0800177 bcmolt_pon_interface_key *key =
178 &((bcmolt_pon_interface_state_change_completed*)msg)->key;
179 bcmolt_pon_interface_state_change_completed_data *data =
180 &((bcmolt_pon_interface_state_change_completed*)msg)->data;
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700181
Jason Huangd33b4d82019-05-15 18:22:57 +0800182 intf_ind->set_intf_id(key->pon_ni);
Jason Huang88795222019-06-13 19:28:44 +0800183 SET_OPER_STATE(intf_ind, data->new_state);
Jason Huangd33b4d82019-05-15 18:22:57 +0800184 ind.set_allocated_intf_ind(intf_ind);
185 break;
186 }
187 }
188 break;
189 case BCMOLT_OBJ_ID_NNI_INTERFACE:
190 switch (msg->subgroup) {
191 case BCMOLT_NNI_INTERFACE_AUTO_SUBGROUP_STATE_CHANGE:
192 {
Jason Huangb6843dc2019-07-22 17:46:06 +0800193 OPENOLT_LOG(INFO, openolt_log_id, "intf indication, intf_id: %d\n",
Jason Huangd33b4d82019-05-15 18:22:57 +0800194 ((bcmolt_nni_interface_state_change *)msg)->key.id);
195 bcmolt_nni_interface_key *key =
196 &((bcmolt_nni_interface_state_change *)msg)->key;
197 bcmolt_nni_interface_state_change_data *data =
198 &((bcmolt_nni_interface_state_change *)msg)->data;
199
200 intf_ind->set_intf_id(key->id);
Jason Huang88795222019-06-13 19:28:44 +0800201 SET_OPER_STATE(intf_ind, data->new_state);
Jason Huangd33b4d82019-05-15 18:22:57 +0800202 ind.set_allocated_intf_ind(intf_ind);
203 break;
204 }
205 }
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700206 }
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700207
208 oltIndQ.push(ind);
Jason Huangd33b4d82019-05-15 18:22:57 +0800209 bcmolt_msg_free(msg);
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700210}
211
Jason Huangd33b4d82019-05-15 18:22:57 +0800212static void IfOperIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Shad Ansari01b0e652018-04-05 21:02:53 +0000213 openolt::Indication ind;
214 openolt::IntfOperIndication* intf_oper_ind = new openolt::IntfOperIndication;
Shad Ansari01b0e652018-04-05 21:02:53 +0000215
Jason Huangd33b4d82019-05-15 18:22:57 +0800216 switch (msg->obj_type) {
217 case BCMOLT_OBJ_ID_PON_INTERFACE:
218 switch (msg->subgroup) {
219 case BCMOLT_PON_INTERFACE_AUTO_SUBGROUP_STATE_CHANGE_COMPLETED:
220 {
221 bcmolt_pon_interface_key *key = &((bcmolt_pon_interface_state_change_completed*)msg)->key;
222 bcmolt_pon_interface_state_change_completed_data *data = &((bcmolt_pon_interface_state_change_completed*)msg)->data;
223 intf_oper_ind->set_intf_id(key->pon_ni);
Jason Huang439d24f2019-06-26 03:25:05 +0800224 intf_oper_ind->set_type(bcmolt_to_grpc_intf_type(BCMOLT_INTERFACE_TYPE_PON));
Jason Huang88795222019-06-13 19:28:44 +0800225 SET_OPER_STATE(intf_oper_ind, data->new_state);
Jason Huangb6843dc2019-07-22 17:46:06 +0800226 OPENOLT_LOG(INFO, openolt_log_id, "intf oper state indication, intf_type %s, intf_id %d, oper_state %s\n",
Jason Huangd33b4d82019-05-15 18:22:57 +0800227 intf_oper_ind->type().c_str(), key->pon_ni, intf_oper_ind->oper_state().c_str());
228 ind.set_allocated_intf_oper_ind(intf_oper_ind);
229 break;
230 }
231 }
232 case BCMOLT_OBJ_ID_NNI_INTERFACE:
233 switch (msg->subgroup) {
234 case BCMOLT_NNI_INTERFACE_AUTO_SUBGROUP_STATE_CHANGE:
235 {
236 bcmolt_nni_interface_key *key = &((bcmolt_nni_interface_state_change *)msg)->key;
237 bcmolt_nni_interface_state_change_data *data = &((bcmolt_nni_interface_state_change *)msg)->data;
238 bcmolt_interface intf_id = key->id;
239 bcmolt_interface_type intf_type = BCMOLT_INTERFACE_TYPE_NNI;
240 intf_oper_ind->set_intf_id(key->id);
Jason Huang439d24f2019-06-26 03:25:05 +0800241 intf_oper_ind->set_type(bcmolt_to_grpc_intf_type(BCMOLT_INTERFACE_TYPE_NNI));
Jason Huang88795222019-06-13 19:28:44 +0800242 SET_OPER_STATE(intf_oper_ind, data->new_state);
Jason Huangb6843dc2019-07-22 17:46:06 +0800243 OPENOLT_LOG(INFO, openolt_log_id, "intf oper state indication, intf_type %s, intf_id %d, oper_state %s\n",
Jason Huangd33b4d82019-05-15 18:22:57 +0800244 intf_oper_ind->type().c_str(), key->id, intf_oper_ind->oper_state().c_str());
245 ind.set_allocated_intf_oper_ind(intf_oper_ind);
246 break;
247 }
248 }
Shad Ansari01b0e652018-04-05 21:02:53 +0000249 }
250
Shad Ansari01b0e652018-04-05 21:02:53 +0000251 oltIndQ.push(ind);
Jason Huangd33b4d82019-05-15 18:22:57 +0800252 bcmolt_msg_free(msg);
Shad Ansari01b0e652018-04-05 21:02:53 +0000253}
254
Jason Huangd33b4d82019-05-15 18:22:57 +0800255static void OnuAlarmIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Shad Ansari01b0e652018-04-05 21:02:53 +0000256 openolt::Indication ind;
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400257 openolt::AlarmIndication* alarm_ind = new openolt::AlarmIndication;
258 openolt::OnuAlarmIndication* onu_alarm_ind = new openolt::OnuAlarmIndication;
259
Jason Huangd33b4d82019-05-15 18:22:57 +0800260 switch (msg->obj_type) {
261 case BCMOLT_OBJ_ID_ONU:
262 switch (msg->subgroup) {
263 case BCMOLT_ONU_AUTO_SUBGROUP_XGPON_ALARM:
264 {
265 bcmolt_xgpon_onu_alarms *onu_alarms =
266 &((bcmolt_onu_xgpon_alarm_data *)msg)->xgpon_onu_alarm;
267 onu_alarm_ind->set_los_status(alarm_status_to_string(onu_alarms->losi));
268 onu_alarm_ind->set_lob_status(alarm_status_to_string(onu_alarms->lobi));
269 onu_alarm_ind->set_lopc_miss_status(alarm_status_to_string(
270 onu_alarms->lopci_miss));
271 onu_alarm_ind->set_lopc_mic_error_status(alarm_status_to_string(
272 onu_alarms->lopci_mic_error));
Jason Huangb6843dc2019-07-22 17:46:06 +0800273
Jason Huangd33b4d82019-05-15 18:22:57 +0800274 alarm_ind->set_allocated_onu_alarm_ind(onu_alarm_ind);
275 ind.set_allocated_alarm_ind(alarm_ind);
276 break;
277 }
278 case BCMOLT_ONU_AUTO_SUBGROUP_GPON_ALARM:
279 {
280 bcmolt_gpon_onu_alarms *onu_alarms =
281 &((bcmolt_onu_gpon_alarm_data *)msg)->gpon_onu_alarm;
282 onu_alarm_ind->set_los_status(alarm_status_to_string(onu_alarms->losi));
Jason Huangb6843dc2019-07-22 17:46:06 +0800283 /* TODO: need to set lofi and loami
284 onu_alarm_ind->set_lof_status(alarm_status_to_string(onu_alarms->lofi));
285 onu_alarm_ind->set_loami_status(alarm_status_to_string(
Jason Huangd33b4d82019-05-15 18:22:57 +0800286 onu_alarms->loami));
287 */
288 alarm_ind->set_allocated_onu_alarm_ind(onu_alarm_ind);
289 ind.set_allocated_alarm_ind(alarm_ind);
290 break;
291 }
292 }
293 }
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400294
295 oltIndQ.push(ind);
Jason Huangd33b4d82019-05-15 18:22:57 +0800296 bcmolt_msg_free(msg);
Shad Ansari01b0e652018-04-05 21:02:53 +0000297}
298
Jason Huangd33b4d82019-05-15 18:22:57 +0800299static void OnuDyingGaspIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Shad Ansari01b0e652018-04-05 21:02:53 +0000300 openolt::Indication ind;
Nicolas Palpacuera32f4c32018-06-28 12:55:10 -0400301 openolt::AlarmIndication* alarm_ind = new openolt::AlarmIndication;
Jason Huangd33b4d82019-05-15 18:22:57 +0800302 openolt::DyingGaspIndication* dgi_ind = new openolt::DyingGaspIndication;
nickc063ffd2018-05-22 14:35:28 -0400303
Jason Huangd33b4d82019-05-15 18:22:57 +0800304 switch (msg->obj_type) {
305 case BCMOLT_OBJ_ID_ONU:
306 switch (msg->subgroup) {
307 case BCMOLT_ONU_AUTO_SUBGROUP_DGI:
308 {
309 bcmolt_onu_dgi_data* dgi_data = (bcmolt_onu_dgi_data *)msg;
310 dgi_ind->set_status(alarm_status_to_string(dgi_data->alarm_status));
nickc063ffd2018-05-22 14:35:28 -0400311
Jason Huangd33b4d82019-05-15 18:22:57 +0800312 alarm_ind->set_allocated_dying_gasp_ind(dgi_ind);
313 ind.set_allocated_alarm_ind(alarm_ind);
314 break;
315 }
316 }
317 }
nickc063ffd2018-05-22 14:35:28 -0400318
319 oltIndQ.push(ind);
Jason Huangd33b4d82019-05-15 18:22:57 +0800320 bcmolt_msg_free(msg);
Shad Ansari01b0e652018-04-05 21:02:53 +0000321}
322
Jason Huangd33b4d82019-05-15 18:22:57 +0800323static void OnuDiscoveryIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Shad Ansari01b0e652018-04-05 21:02:53 +0000324 openolt::Indication ind;
325 openolt::OnuDiscIndication* onu_disc_ind = new openolt::OnuDiscIndication;
326 openolt::SerialNumber* serial_number = new openolt::SerialNumber;
327
Jason Huangd33b4d82019-05-15 18:22:57 +0800328 switch (msg->obj_type) {
329 case BCMOLT_OBJ_ID_PON_INTERFACE:
330 switch (msg->subgroup) {
331 case BCMOLT_PON_INTERFACE_AUTO_SUBGROUP_ONU_DISCOVERED:
332 {
333 bcmolt_pon_interface_key *key =
334 &((bcmolt_pon_interface_onu_discovered *)msg)->key;
Shad Ansari01b0e652018-04-05 21:02:53 +0000335
Jason Huangd33b4d82019-05-15 18:22:57 +0800336 bcmolt_pon_interface_onu_discovered_data *data =
337 &((bcmolt_pon_interface_onu_discovered *)msg)->data;
Shad Ansari01b0e652018-04-05 21:02:53 +0000338
Jason Huangd33b4d82019-05-15 18:22:57 +0800339 bcmolt_serial_number *in_serial_number = &(data->serial_number);
Shad Ansari01b0e652018-04-05 21:02:53 +0000340
Jason Huangb6843dc2019-07-22 17:46:06 +0800341 OPENOLT_LOG(INFO, openolt_log_id, "onu discover indication, pon_ni %d, serial_number %s\n",
Jason Huangd33b4d82019-05-15 18:22:57 +0800342 key->pon_ni, serial_number_to_str(in_serial_number).c_str());
Shad Ansari01b0e652018-04-05 21:02:53 +0000343
Jason Huangd33b4d82019-05-15 18:22:57 +0800344 onu_disc_ind->set_intf_id(key->pon_ni);
345 serial_number->set_vendor_id(reinterpret_cast<const char *>(in_serial_number->vendor_id.arr), 4);
346 serial_number->set_vendor_specific(reinterpret_cast<const char *>(in_serial_number->vendor_specific.arr), 8);
347 onu_disc_ind->set_allocated_serial_number(serial_number);
348 ind.set_allocated_onu_disc_ind(onu_disc_ind);
349 break;
350 }
351 }
352 }
Shad Ansari01b0e652018-04-05 21:02:53 +0000353
354 oltIndQ.push(ind);
Jason Huangd33b4d82019-05-15 18:22:57 +0800355 bcmolt_msg_free(msg);
Shad Ansari01b0e652018-04-05 21:02:53 +0000356}
357
Jason Huangd33b4d82019-05-15 18:22:57 +0800358static void OnuIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700359 openolt::Indication ind;
360 openolt::OnuIndication* onu_ind = new openolt::OnuIndication;
361
Jason Huangd33b4d82019-05-15 18:22:57 +0800362 switch (msg->obj_type) {
363 case BCMOLT_OBJ_ID_ONU:
364 switch (msg->subgroup) {
Jason Huangb1fad572019-05-28 19:02:30 +0800365 case BCMOLT_ONU_AUTO_SUBGROUP_RANGING_COMPLETED:
Jason Huangd33b4d82019-05-15 18:22:57 +0800366 {
Jason Huangb1fad572019-05-28 19:02:30 +0800367 bcmolt_onu_key *key = &((bcmolt_onu_ranging_completed*)msg)->key;
368 bcmolt_onu_ranging_completed_data *data = &((bcmolt_onu_ranging_completed*)msg)->data;
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700369
Jason Huangd33b4d82019-05-15 18:22:57 +0800370 onu_ind->set_intf_id(key->pon_ni);
371 onu_ind->set_onu_id(key->onu_id);
Jason Huangb1fad572019-05-28 19:02:30 +0800372 if (ONU_RANGING_STATE_IF_UP(data->status))
Jason Huangd33b4d82019-05-15 18:22:57 +0800373 onu_ind->set_oper_state("up");
Jason Huangb1fad572019-05-28 19:02:30 +0800374 if (ONU_RANGING_STATE_IF_DOWN(data->status))
Jason Huangd33b4d82019-05-15 18:22:57 +0800375 onu_ind->set_oper_state("down");
Jason Huang88795222019-06-13 19:28:44 +0800376 (key->onu_id)?onu_ind->set_admin_state("up"):onu_ind->set_admin_state("down");
Jason Huangd33b4d82019-05-15 18:22:57 +0800377 ind.set_allocated_onu_ind(onu_ind);
Jason Huangb6843dc2019-07-22 17:46:06 +0800378 OPENOLT_LOG(INFO, openolt_log_id, "onu indication, pon_ni %d, onu_id %d, onu_state %s, onu_admin %s\n",
Jason Huang88795222019-06-13 19:28:44 +0800379 key->pon_ni, key->onu_id, (data->status==BCMOLT_RESULT_SUCCESS)?"up":"down",
380 (key->onu_id)?"up":"down");
Jason Huangd33b4d82019-05-15 18:22:57 +0800381 }
382 }
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700383 }
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700384
385 oltIndQ.push(ind);
Jason Huangd33b4d82019-05-15 18:22:57 +0800386 bcmolt_msg_free(msg);
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700387}
388
Jason Huangd33b4d82019-05-15 18:22:57 +0800389static void OnuOperIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Shad Ansari01b0e652018-04-05 21:02:53 +0000390 openolt::Indication ind;
nickc063ffd2018-05-22 14:35:28 -0400391 openolt::OnuIndication* onu_ind = new openolt::OnuIndication;
nickc063ffd2018-05-22 14:35:28 -0400392
Jason Huangd33b4d82019-05-15 18:22:57 +0800393 switch (msg->obj_type) {
394 case BCMOLT_OBJ_ID_ONU:
395 switch (msg->subgroup) {
396 case BCMOLT_ONU_AUTO_SUBGROUP_STATE_CHANGE:
397 {
398 bcmolt_onu_key *key = &((bcmolt_onu_state_change*)msg)->key;
399 bcmolt_onu_state_change_data *data = &((bcmolt_onu_state_change*)msg)->data;
nickc063ffd2018-05-22 14:35:28 -0400400
Jason Huangd33b4d82019-05-15 18:22:57 +0800401 onu_ind->set_intf_id(key->pon_ni);
402 onu_ind->set_onu_id(key->onu_id);
403 if (ONU_STATE_IF_UP(data->new_onu_state))
404 onu_ind->set_oper_state("up");
405 if (ONU_STATE_IF_DOWN(data->new_onu_state))
406 onu_ind->set_oper_state("down");
407 ind.set_allocated_onu_ind(onu_ind);
nickc063ffd2018-05-22 14:35:28 -0400408
Jason Huangb6843dc2019-07-22 17:46:06 +0800409 OPENOLT_LOG(INFO, openolt_log_id, "onu oper state indication, intf_id %d, onu_id %d, old oper state %d, new oper state %s\n",
Jason Huangd33b4d82019-05-15 18:22:57 +0800410 key->pon_ni, key->onu_id, data->new_onu_state, onu_ind->oper_state().c_str());
411 }
412 }
nickc063ffd2018-05-22 14:35:28 -0400413 }
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500414
nickc063ffd2018-05-22 14:35:28 -0400415 oltIndQ.push(ind);
Jason Huangd33b4d82019-05-15 18:22:57 +0800416 bcmolt_msg_free(msg);
Shad Ansari01b0e652018-04-05 21:02:53 +0000417}
418
Jason Huangd33b4d82019-05-15 18:22:57 +0800419static void OmciIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Shad Ansari01b0e652018-04-05 21:02:53 +0000420 openolt::Indication ind;
421 openolt::OmciIndication* omci_ind = new openolt::OmciIndication;
Shad Ansari01b0e652018-04-05 21:02:53 +0000422
Jason Huangd33b4d82019-05-15 18:22:57 +0800423 switch (msg->obj_type) {
424 case BCMOLT_OBJ_ID_ONU:
425 switch (msg->subgroup) {
426 case BCMOLT_ONU_AUTO_SUBGROUP_OMCI_PACKET:
427 {
428 bcmolt_onu_key *key = &((bcmolt_onu_omci_packet*)msg)->key;
429 bcmolt_onu_omci_packet_data *data = &((bcmolt_onu_omci_packet*)msg)->data;
Shad Ansari01b0e652018-04-05 21:02:53 +0000430
Jason Huangb6843dc2019-07-22 17:46:06 +0800431 OPENOLT_LOG(DEBUG, omci_log_id, "OMCI indication: pon_ni %d, onu_id %d\n",
Jason Huangd33b4d82019-05-15 18:22:57 +0800432 key->pon_ni, key->onu_id);
Shad Ansari01b0e652018-04-05 21:02:53 +0000433
Jason Huangd33b4d82019-05-15 18:22:57 +0800434 omci_ind->set_intf_id(key->pon_ni);
435 omci_ind->set_onu_id(key->onu_id);
436 omci_ind->set_pkt(data->buffer.arr, data->buffer.len);
437
438 ind.set_allocated_omci_ind(omci_ind);
439 break;
440 }
441 }
442 }
443
Shad Ansari01b0e652018-04-05 21:02:53 +0000444 oltIndQ.push(ind);
Jason Huangd33b4d82019-05-15 18:22:57 +0800445 bcmolt_msg_free(msg);
Shad Ansari01b0e652018-04-05 21:02:53 +0000446}
447
Jason Huangd33b4d82019-05-15 18:22:57 +0800448static void PacketIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Shad Ansari01b0e652018-04-05 21:02:53 +0000449 openolt::Indication ind;
Shad Ansari5fe93682018-04-26 05:24:19 +0000450 openolt::PacketIndication* pkt_ind = new openolt::PacketIndication;
Shad Ansari5fe93682018-04-26 05:24:19 +0000451
Jason Huangd33b4d82019-05-15 18:22:57 +0800452 switch (msg->obj_type) {
Jason Huang439d24f2019-06-26 03:25:05 +0800453 case BCMOLT_OBJ_ID_FLOW:
Jason Huangd33b4d82019-05-15 18:22:57 +0800454 switch (msg->subgroup) {
455 case BCMOLT_FLOW_AUTO_SUBGROUP_RECEIVE_ETH_PACKET:
456 {
Jason Huang439d24f2019-06-26 03:25:05 +0800457 bcmolt_flow_receive_eth_packet *pkt =
458 (bcmolt_flow_receive_eth_packet*)msg;
Jason Huangd33b4d82019-05-15 18:22:57 +0800459 bcmolt_flow_receive_eth_packet_data *pkt_data =
460 &((bcmolt_flow_receive_eth_packet*)msg)->data;
Shad Ansari5fe93682018-04-26 05:24:19 +0000461
Jason Huang439d24f2019-06-26 03:25:05 +0800462 uint32_t port_no = GetPortNum_(pkt->key.flow_id);
Jason Huangb6843dc2019-07-22 17:46:06 +0800463 pkt_ind->set_intf_type(bcmolt_to_grpc_flow_intf_type((bcmolt_flow_interface_type)get_flow_status(pkt->key.flow_id, pkt->key.flow_type, INGRESS_INTF_TYPE)));
464 pkt_ind->set_intf_id(get_flow_status(pkt->key.flow_id, pkt->key.flow_type, INGRESS_INTF_ID));
465 pkt_ind->set_gemport_id(get_flow_status(pkt->key.flow_id, pkt->key.flow_type, SVC_PORT_ID));
Jason Huang439d24f2019-06-26 03:25:05 +0800466 pkt_ind->set_flow_id(pkt->key.flow_id);
Jason Huangd33b4d82019-05-15 18:22:57 +0800467 pkt_ind->set_pkt(pkt_data->buffer.arr, pkt_data->buffer.len);
468 pkt_ind->set_port_no(port_no);
Jason Huangb6843dc2019-07-22 17:46:06 +0800469 pkt_ind->set_cookie(get_flow_status(pkt->key.flow_id, pkt->key.flow_type, COOKIE));
Jason Huangd33b4d82019-05-15 18:22:57 +0800470 ind.set_allocated_pkt_ind(pkt_ind);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500471
Jason Huangb6843dc2019-07-22 17:46:06 +0800472 OPENOLT_LOG(INFO, openolt_log_id, "packet indication, ingress intf_type %s, ingress intf_id %d, egress intf_type %s, egress intf_id %lu, svc_port %d, flow_type %s, flow_id %d, port_no %d, cookie %"PRIu64"\n",
473 pkt_ind->intf_type().c_str(), pkt_ind->intf_id(),
474 bcmolt_to_grpc_flow_intf_type((bcmolt_flow_interface_type)get_flow_status(pkt->key.flow_id, pkt->key.flow_type, EGRESS_INTF_TYPE)).c_str(),
475 get_flow_status(pkt->key.flow_id, pkt->key.flow_type, EGRESS_INTF_ID),
476 pkt_ind->gemport_id(), GET_FLOW_TYPE(pkt->key.flow_type),
Jason Huang439d24f2019-06-26 03:25:05 +0800477 pkt_ind->flow_id(), port_no, pkt_ind->cookie());
Jason Huangd33b4d82019-05-15 18:22:57 +0800478 }
479 }
480 }
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500481
Shad Ansari5fe93682018-04-26 05:24:19 +0000482 oltIndQ.push(ind);
Jason Huangd33b4d82019-05-15 18:22:57 +0800483 bcmolt_msg_free(msg);
Shad Ansari01b0e652018-04-05 21:02:53 +0000484}
485
Jason Huangd33b4d82019-05-15 18:22:57 +0800486static void FlowOperIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Shad Ansari01b0e652018-04-05 21:02:53 +0000487 openolt::Indication ind;
Jason Huangb6843dc2019-07-22 17:46:06 +0800488 OPENOLT_LOG(DEBUG, openolt_log_id, "flow oper state indication\n");
Jason Huangd33b4d82019-05-15 18:22:57 +0800489 bcmolt_msg_free(msg);
Shad Ansari01b0e652018-04-05 21:02:53 +0000490}
491
Jason Huangd33b4d82019-05-15 18:22:57 +0800492static void FlowIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Shad Ansari01b0e652018-04-05 21:02:53 +0000493 openolt::Indication ind;
Jason Huangb6843dc2019-07-22 17:46:06 +0800494 OPENOLT_LOG(DEBUG, openolt_log_id, "flow indication\n");
Jason Huangd33b4d82019-05-15 18:22:57 +0800495 bcmolt_msg_free(msg);
Shad Ansari01b0e652018-04-05 21:02:53 +0000496}
497
Jason Huangd33b4d82019-05-15 18:22:57 +0800498static void TmQIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Shad Ansari01b0e652018-04-05 21:02:53 +0000499 openolt::Indication ind;
Jason Huangb6843dc2019-07-22 17:46:06 +0800500 OPENOLT_LOG(DEBUG, openolt_log_id, "traffic mgmt queue indication\n");
Jason Huangd33b4d82019-05-15 18:22:57 +0800501 bcmolt_msg_free(msg);
Shad Ansari01b0e652018-04-05 21:02:53 +0000502}
503
Jason Huangd33b4d82019-05-15 18:22:57 +0800504static void TmSchedIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Shad Ansari01b0e652018-04-05 21:02:53 +0000505 openolt::Indication ind;
Jason Huangb6843dc2019-07-22 17:46:06 +0800506 OPENOLT_LOG(DEBUG, openolt_log_id, "traffic mgmt sheduler indication\n");
Jason Huangd33b4d82019-05-15 18:22:57 +0800507 bcmolt_msg_free(msg);
Shad Ansari01b0e652018-04-05 21:02:53 +0000508}
509
Jason Huangd33b4d82019-05-15 18:22:57 +0800510static void McastGroupIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Shad Ansari01b0e652018-04-05 21:02:53 +0000511 openolt::Indication ind;
Jason Huangb6843dc2019-07-22 17:46:06 +0800512 OPENOLT_LOG(DEBUG, openolt_log_id, "mcast group indication\n");
Jason Huangd33b4d82019-05-15 18:22:57 +0800513 bcmolt_msg_free(msg);
Shad Ansari01b0e652018-04-05 21:02:53 +0000514}
515
Jason Huangd33b4d82019-05-15 18:22:57 +0800516static void OnuStartupFailureIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400517 openolt::Indication ind;
518 openolt::AlarmIndication* alarm_ind = new openolt::AlarmIndication;
519 openolt::OnuStartupFailureIndication* sufi_ind = new openolt::OnuStartupFailureIndication;
520
Jason Huangd33b4d82019-05-15 18:22:57 +0800521 switch (msg->obj_type) {
522 case BCMOLT_OBJ_ID_ONU:
523 switch (msg->subgroup) {
524 case BCMOLT_ONU_AUTO_SUBGROUP_SUFI:
525 {
526 bcmolt_onu_key *key = &((bcmolt_onu_sufi*)msg)->key;
527 bcmolt_onu_sufi_data *data = &((bcmolt_onu_sufi*)msg)->data;
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400528
Jason Huangb6843dc2019-07-22 17:46:06 +0800529 OPENOLT_LOG(WARNING, openolt_log_id, "onu startup failure indication, intf_id %d, onu_id %d, alarm %d\n",
Jason Huangd33b4d82019-05-15 18:22:57 +0800530 key->pon_ni, key->onu_id, data->alarm_status);
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400531
Jason Huangd33b4d82019-05-15 18:22:57 +0800532 sufi_ind->set_intf_id(key->pon_ni);
533 sufi_ind->set_onu_id(key->onu_id);
534 sufi_ind->set_status(alarm_status_to_string(data->alarm_status));
535 alarm_ind->set_allocated_onu_startup_fail_ind(sufi_ind);
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400536
Jason Huangd33b4d82019-05-15 18:22:57 +0800537 ind.set_allocated_alarm_ind(alarm_ind);
538 }
539 }
540 }
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400541
542 oltIndQ.push(ind);
Jason Huangd33b4d82019-05-15 18:22:57 +0800543 bcmolt_msg_free(msg);
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400544}
545
Jason Huangd33b4d82019-05-15 18:22:57 +0800546static void OnuSignalDegradeIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400547 openolt::Indication ind;
548 openolt::AlarmIndication* alarm_ind = new openolt::AlarmIndication;
549 openolt::OnuSignalDegradeIndication* sdi_ind = new openolt::OnuSignalDegradeIndication;
550
Jason Huangd33b4d82019-05-15 18:22:57 +0800551 switch (msg->obj_type) {
552 case BCMOLT_OBJ_ID_ONU:
553 switch (msg->subgroup) {
554 case BCMOLT_ONU_AUTO_SUBGROUP_SDI:
555 {
556 bcmolt_onu_key *key = &((bcmolt_onu_sdi*)msg)->key;
557 bcmolt_onu_sdi_data *data = &((bcmolt_onu_sdi*)msg)->data;
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400558
Jason Huangb6843dc2019-07-22 17:46:06 +0800559 OPENOLT_LOG(WARNING, openolt_log_id, "onu signal degrade indication, intf_id %d, onu_id %d, alarm %d, BER %d\n",
Jason Huangd33b4d82019-05-15 18:22:57 +0800560 key->pon_ni, key->onu_id, data->alarm_status, data->ber);
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400561
Jason Huangd33b4d82019-05-15 18:22:57 +0800562 sdi_ind->set_intf_id(key->pon_ni);
563 sdi_ind->set_onu_id(key->onu_id);
564 sdi_ind->set_status(alarm_status_to_string(data->alarm_status));
565 sdi_ind->set_inverse_bit_error_rate(data->ber);
566 alarm_ind->set_allocated_onu_signal_degrade_ind(sdi_ind);
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400567
Jason Huangd33b4d82019-05-15 18:22:57 +0800568 ind.set_allocated_alarm_ind(alarm_ind);
569 }
570 }
571 }
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400572
573 oltIndQ.push(ind);
Jason Huangd33b4d82019-05-15 18:22:57 +0800574 bcmolt_msg_free(msg);
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400575}
576
Jason Huangd33b4d82019-05-15 18:22:57 +0800577static void OnuDriftOfWindowIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400578 openolt::Indication ind;
579 openolt::AlarmIndication* alarm_ind = new openolt::AlarmIndication;
580 openolt::OnuDriftOfWindowIndication* dowi_ind = new openolt::OnuDriftOfWindowIndication;
581
Jason Huangd33b4d82019-05-15 18:22:57 +0800582 switch (msg->obj_type) {
583 case BCMOLT_OBJ_ID_ONU:
584 switch (msg->subgroup) {
585 case BCMOLT_ONU_AUTO_SUBGROUP_DOWI:
586 {
587 bcmolt_onu_key *key = &((bcmolt_onu_dowi*)msg)->key;
588 bcmolt_onu_dowi_data *data = &((bcmolt_onu_dowi*)msg)->data;
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400589
Jason Huangb6843dc2019-07-22 17:46:06 +0800590 OPENOLT_LOG(WARNING, openolt_log_id, "onu drift of window indication, intf_id %d, onu_id %d, alarm %d, drift %d, new_eqd %d\n",
Jason Huangd33b4d82019-05-15 18:22:57 +0800591 key->pon_ni, key->onu_id, data->alarm_status, data->drift_value, data->new_eqd);
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400592
Jason Huangd33b4d82019-05-15 18:22:57 +0800593 dowi_ind->set_intf_id(key->pon_ni);
594 dowi_ind->set_onu_id(key->onu_id);
595 dowi_ind->set_status(alarm_status_to_string(data->alarm_status));
596 dowi_ind->set_drift(data->drift_value);
597 dowi_ind->set_new_eqd(data->new_eqd);
598 alarm_ind->set_allocated_onu_drift_of_window_ind(dowi_ind);
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400599
Jason Huangd33b4d82019-05-15 18:22:57 +0800600 ind.set_allocated_alarm_ind(alarm_ind);
601 }
602 }
603 }
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400604
605 oltIndQ.push(ind);
Jason Huangd33b4d82019-05-15 18:22:57 +0800606 bcmolt_msg_free(msg);
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400607}
608
Jason Huangd33b4d82019-05-15 18:22:57 +0800609static void OnuLossOfOmciChannelIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400610 openolt::Indication ind;
611 openolt::AlarmIndication* alarm_ind = new openolt::AlarmIndication;
612 openolt::OnuLossOfOmciChannelIndication* looci_ind = new openolt::OnuLossOfOmciChannelIndication;
613
Jason Huangd33b4d82019-05-15 18:22:57 +0800614 switch (msg->obj_type) {
615 case BCMOLT_OBJ_ID_ONU:
616 switch (msg->subgroup) {
617 case BCMOLT_ONU_AUTO_SUBGROUP_LOOCI:
618 {
619 bcmolt_onu_key *key = &((bcmolt_onu_looci*)msg)->key;
620 bcmolt_onu_looci_data *data = &((bcmolt_onu_looci*)msg)->data;
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400621
Jason Huangb6843dc2019-07-22 17:46:06 +0800622 OPENOLT_LOG(WARNING, openolt_log_id, "onu loss of OMCI channel indication, intf_id %d, onu_id %d, alarm %d\n",
Jason Huangd33b4d82019-05-15 18:22:57 +0800623 key->pon_ni, key->onu_id, data->alarm_status);
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400624
Jason Huangd33b4d82019-05-15 18:22:57 +0800625 looci_ind->set_intf_id(key->pon_ni);
626 looci_ind->set_onu_id(key->onu_id);
627 looci_ind->set_status(alarm_status_to_string(data->alarm_status));
628 alarm_ind->set_allocated_onu_loss_omci_ind(looci_ind);
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400629
Jason Huangd33b4d82019-05-15 18:22:57 +0800630 ind.set_allocated_alarm_ind(alarm_ind);
631 }
632 }
633 }
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400634
635 oltIndQ.push(ind);
Jason Huangd33b4d82019-05-15 18:22:57 +0800636 bcmolt_msg_free(msg);
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400637}
638
Jason Huangd33b4d82019-05-15 18:22:57 +0800639static void OnuSignalsFailureIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400640 openolt::Indication ind;
641 openolt::AlarmIndication* alarm_ind = new openolt::AlarmIndication;
642 openolt::OnuSignalsFailureIndication* sfi_ind = new openolt::OnuSignalsFailureIndication;
643
Jason Huangd33b4d82019-05-15 18:22:57 +0800644 switch (msg->obj_type) {
645 case BCMOLT_OBJ_ID_ONU:
646 switch (msg->subgroup) {
647 case BCMOLT_ONU_AUTO_SUBGROUP_SFI:
648 {
649 bcmolt_onu_key *key = &((bcmolt_onu_sfi*)msg)->key;
650 bcmolt_onu_sfi_data *data = &((bcmolt_onu_sfi*)msg)->data;
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400651
Jason Huangb6843dc2019-07-22 17:46:06 +0800652 OPENOLT_LOG(WARNING, openolt_log_id, "onu signals failure indication, intf_id %d, onu_id %d, alarm %d, BER %d\n",
Jason Huangd33b4d82019-05-15 18:22:57 +0800653 key->pon_ni, key->onu_id, data->alarm_status, data->ber);
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400654
655
Jason Huangd33b4d82019-05-15 18:22:57 +0800656 sfi_ind->set_intf_id(key->pon_ni);
657 sfi_ind->set_onu_id(key->onu_id);
658 sfi_ind->set_status(alarm_status_to_string(data->alarm_status));
659 sfi_ind->set_inverse_bit_error_rate(data->ber);
660 alarm_ind->set_allocated_onu_signals_fail_ind(sfi_ind);
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400661
Jason Huangd33b4d82019-05-15 18:22:57 +0800662 ind.set_allocated_alarm_ind(alarm_ind);
663 }
664 }
665 }
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400666
667 oltIndQ.push(ind);
Jason Huangd33b4d82019-05-15 18:22:57 +0800668 bcmolt_msg_free(msg);
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400669}
670
Jason Huangd33b4d82019-05-15 18:22:57 +0800671static void OnuTransmissionInterferenceWarningIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400672 openolt::Indication ind;
673 openolt::AlarmIndication* alarm_ind = new openolt::AlarmIndication;
674 openolt::OnuTransmissionInterferenceWarning* tiwi_ind = new openolt::OnuTransmissionInterferenceWarning;
675
Jason Huangd33b4d82019-05-15 18:22:57 +0800676 switch (msg->obj_type) {
677 case BCMOLT_OBJ_ID_ONU:
678 switch (msg->subgroup) {
679 case BCMOLT_ONU_AUTO_SUBGROUP_TIWI:
680 {
681 bcmolt_onu_key *key = &((bcmolt_onu_tiwi*)msg)->key;
682 bcmolt_onu_tiwi_data *data = &((bcmolt_onu_tiwi*)msg)->data;
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400683
Jason Huangb6843dc2019-07-22 17:46:06 +0800684 OPENOLT_LOG(WARNING, openolt_log_id, "onu transmission interference warning indication, intf_id %d, onu_id %d, alarm %d, drift %d\n",
Jason Huangd33b4d82019-05-15 18:22:57 +0800685 key->pon_ni, key->onu_id, data->alarm_status, data->drift_value);
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400686
Jason Huangd33b4d82019-05-15 18:22:57 +0800687 tiwi_ind->set_intf_id(key->pon_ni);
688 tiwi_ind->set_onu_id(key->onu_id);
689 tiwi_ind->set_status(alarm_status_to_string(data->alarm_status));
690 tiwi_ind->set_drift(data->drift_value);
691 alarm_ind->set_allocated_onu_tiwi_ind(tiwi_ind);
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400692
Jason Huangd33b4d82019-05-15 18:22:57 +0800693 ind.set_allocated_alarm_ind(alarm_ind);
694 }
695 }
696 }
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400697
698 oltIndQ.push(ind);
Jason Huangd33b4d82019-05-15 18:22:57 +0800699 bcmolt_msg_free(msg);
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400700}
701
Jason Huangd33b4d82019-05-15 18:22:57 +0800702static void OnuActivationFailureIndication(bcmolt_devid olt, bcmolt_msg *msg) {
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400703 openolt::Indication ind;
704 openolt::AlarmIndication* alarm_ind = new openolt::AlarmIndication;
705 openolt::OnuActivationFailureIndication* activation_fail_ind = new openolt::OnuActivationFailureIndication;
706
Jason Huangd33b4d82019-05-15 18:22:57 +0800707 switch (msg->obj_type) {
708 case BCMOLT_OBJ_ID_ONU:
709 switch (msg->subgroup) {
Jason Huangb1fad572019-05-28 19:02:30 +0800710 case BCMOLT_ONU_AUTO_SUBGROUP_ONU_DEACTIVATION_COMPLETED:
Jason Huangd33b4d82019-05-15 18:22:57 +0800711 {
712 bcmolt_onu_key *key = &((bcmolt_onu_onu_activation_completed*)msg)->key;
713 bcmolt_onu_onu_activation_completed_data *data =
714 &((bcmolt_onu_onu_activation_completed*)msg)->data;
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400715
Jason Huangb6843dc2019-07-22 17:46:06 +0800716 OPENOLT_LOG(INFO, openolt_log_id, "Got onu deactivation, intf_id %d, onu_id %d, fail_reason %d\n",
Jason Huangd33b4d82019-05-15 18:22:57 +0800717 key->pon_ni, key->onu_id, data->fail_reason);
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400718
Jason Huangd33b4d82019-05-15 18:22:57 +0800719 activation_fail_ind->set_intf_id(key->pon_ni);
720 activation_fail_ind->set_onu_id(key->onu_id);
Jason Huangb1fad572019-05-28 19:02:30 +0800721 activation_fail_ind->set_fail_reason(data->fail_reason);
Jason Huangd33b4d82019-05-15 18:22:57 +0800722 alarm_ind->set_allocated_onu_activation_fail_ind(activation_fail_ind);
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400723
Jason Huangd33b4d82019-05-15 18:22:57 +0800724 ind.set_allocated_alarm_ind(alarm_ind);
725 }
726 }
727 }
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400728
729 oltIndQ.push(ind);
Jason Huangd33b4d82019-05-15 18:22:57 +0800730 bcmolt_msg_free(msg);
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400731}
732
Jason Huangd33b4d82019-05-15 18:22:57 +0800733/* removed by BAL v3.0
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400734bcmos_errno OnuProcessingErrorIndication(bcmbal_obj *obj) {
735 openolt::Indication ind;
736 openolt::AlarmIndication* alarm_ind = new openolt::AlarmIndication;
737 openolt::OnuProcessingErrorIndication* onu_proc_error_ind = new openolt::OnuProcessingErrorIndication;
738
739 bcmbal_subscriber_terminal_key *key =
740 &(((bcmbal_subscriber_terminal_processing_error*)obj)->key);
741
Jason Huangb6843dc2019-07-22 17:46:06 +0800742 OPENOLT_LOG(WARNING, openolt_log_id, "onu processing error indication, intf_id %d, onu_id %d\n",
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400743 key->intf_id, key->sub_term_id);
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400744
745
746 onu_proc_error_ind->set_intf_id(key->intf_id);
747 onu_proc_error_ind->set_onu_id(key->sub_term_id);
748
749 alarm_ind->set_allocated_onu_processing_error_ind(onu_proc_error_ind);
750 ind.set_allocated_alarm_ind(alarm_ind);
751
752 oltIndQ.push(ind);
753 return BCM_ERR_OK;
754}
Jason Huangd33b4d82019-05-15 18:22:57 +0800755*/
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400756
Shad Ansari01b0e652018-04-05 21:02:53 +0000757Status SubscribeIndication() {
Jason Huangd33b4d82019-05-15 18:22:57 +0800758 bcmolt_rx_cfg rx_cfg = {};
759 bcmos_errno rc;
Shad Ansari01b0e652018-04-05 21:02:53 +0000760
761 if (subscribed) {
762 return Status::OK;
763 }
764
Jason Huangd33b4d82019-05-15 18:22:57 +0800765 rx_cfg.obj_type = BCMOLT_OBJ_ID_DEVICE;
766 rx_cfg.rx_cb = OltOperIndication;
767 rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
768 rx_cfg.subgroup = bcmolt_device_auto_subgroup_connection_complete;
769 rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
770 if(rc != BCM_ERR_OK)
771 return Status(grpc::StatusCode::INTERNAL,
772 "Olt connection complete state indication subscribe failed");
Shad Ansari01b0e652018-04-05 21:02:53 +0000773
Jason Huangd33b4d82019-05-15 18:22:57 +0800774 rx_cfg.obj_type = BCMOLT_OBJ_ID_DEVICE;
775 rx_cfg.rx_cb = OltOperIndication;
776 rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
777 rx_cfg.subgroup = bcmolt_device_auto_subgroup_disconnection_complete;
778 rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
779 if(rc != BCM_ERR_OK)
780 return Status(grpc::StatusCode::INTERNAL,
781 "Olt disconnection complete state indication subscribe failed");
782
783 rx_cfg.obj_type = BCMOLT_OBJ_ID_DEVICE;
784 rx_cfg.rx_cb = OltOperIndication;
785 rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
786 rx_cfg.subgroup = bcmolt_device_auto_subgroup_connection_failure;
787 rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
788 if(rc != BCM_ERR_OK)
789 return Status(grpc::StatusCode::INTERNAL,
790 "Olt connection failure state indication subscribe failed");
Shad Ansari01b0e652018-04-05 21:02:53 +0000791
792 /* Interface LOS indication */
Jason Huangd33b4d82019-05-15 18:22:57 +0800793 rx_cfg.obj_type = BCMOLT_OBJ_ID_PON_INTERFACE;
794 rx_cfg.rx_cb = LosIndication;
795 rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
796 rx_cfg.subgroup = bcmolt_pon_interface_auto_subgroup_los;
797 rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
798 if(rc != BCM_ERR_OK)
Shad Ansari01b0e652018-04-05 21:02:53 +0000799 return Status(grpc::StatusCode::INTERNAL, "LOS indication subscribe failed");
Shad Ansari01b0e652018-04-05 21:02:53 +0000800
Jason Huangd33b4d82019-05-15 18:22:57 +0800801 rx_cfg.obj_type = BCMOLT_OBJ_ID_PON_INTERFACE;
802 rx_cfg.rx_cb = IfOperIndication;
803 rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
804 rx_cfg.subgroup = bcmolt_pon_interface_auto_subgroup_state_change_completed;
805 rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
806 if(rc != BCM_ERR_OK)
807 return Status(grpc::StatusCode::INTERNAL,
808 "PON Interface operations state change indication subscribe failed");
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700809
Jason Huangd33b4d82019-05-15 18:22:57 +0800810 rx_cfg.obj_type = BCMOLT_OBJ_ID_NNI_INTERFACE;
811 rx_cfg.rx_cb = IfOperIndication;
812 rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
813 rx_cfg.subgroup = bcmolt_nni_interface_auto_subgroup_state_change;
814 rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
815 if(rc != BCM_ERR_OK)
816 return Status(grpc::StatusCode::INTERNAL,
817 "NNI Interface operations state change indication subscribe failed");
818
Jason Huangd33b4d82019-05-15 18:22:57 +0800819 rx_cfg.obj_type = BCMOLT_OBJ_ID_ONU;
820 rx_cfg.rx_cb = OnuAlarmIndication;
821 rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
822 rx_cfg.subgroup = bcmolt_onu_auto_subgroup_xgpon_alarm;
823 rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
824 if(rc != BCM_ERR_OK)
Shad Ansari01b0e652018-04-05 21:02:53 +0000825 return Status(grpc::StatusCode::INTERNAL, "onu alarm indication subscribe failed");
Shad Ansari01b0e652018-04-05 21:02:53 +0000826
Jason Huangd33b4d82019-05-15 18:22:57 +0800827 rx_cfg.obj_type = BCMOLT_OBJ_ID_ONU;
828 rx_cfg.rx_cb = OnuAlarmIndication;
829 rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
830 rx_cfg.subgroup = bcmolt_onu_auto_subgroup_gpon_alarm;
831 rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
832 if(rc != BCM_ERR_OK)
833 return Status(grpc::StatusCode::INTERNAL, "onu alarm indication subscribe failed");
Jason Huangb6843dc2019-07-22 17:46:06 +0800834
Jason Huangd33b4d82019-05-15 18:22:57 +0800835 rx_cfg.obj_type = BCMOLT_OBJ_ID_ONU;
836 rx_cfg.rx_cb = OnuDyingGaspIndication;
837 rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
838 rx_cfg.subgroup = bcmolt_onu_auto_subgroup_dgi;
839 rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
840 if(rc != BCM_ERR_OK)
Shad Ansari01b0e652018-04-05 21:02:53 +0000841 return Status(grpc::StatusCode::INTERNAL, "onu dying-gasp indication subscribe failed");
Shad Ansari01b0e652018-04-05 21:02:53 +0000842
Jason Huangd33b4d82019-05-15 18:22:57 +0800843 rx_cfg.obj_type = BCMOLT_OBJ_ID_PON_INTERFACE;
844 rx_cfg.rx_cb = OnuDiscoveryIndication;
845 rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
846 rx_cfg.subgroup = bcmolt_pon_interface_auto_subgroup_onu_discovered;
847 rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
848 if(rc != BCM_ERR_OK)
Shad Ansari01b0e652018-04-05 21:02:53 +0000849 return Status(grpc::StatusCode::INTERNAL, "onu discovery indication subscribe failed");
Shad Ansari01b0e652018-04-05 21:02:53 +0000850
Jason Huangd33b4d82019-05-15 18:22:57 +0800851 rx_cfg.obj_type = BCMOLT_OBJ_ID_ONU;
852 rx_cfg.rx_cb = OnuIndication;
853 rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
Jason Huangb1fad572019-05-28 19:02:30 +0800854 rx_cfg.subgroup = bcmolt_onu_auto_subgroup_ranging_completed;
855
Jason Huangd33b4d82019-05-15 18:22:57 +0800856 rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
857 if(rc != BCM_ERR_OK)
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700858 return Status(grpc::StatusCode::INTERNAL, "onu indication subscribe failed");
Shad Ansari01b0e652018-04-05 21:02:53 +0000859
Jason Huangd33b4d82019-05-15 18:22:57 +0800860 rx_cfg.obj_type = BCMOLT_OBJ_ID_ONU;
Jason Huangd33b4d82019-05-15 18:22:57 +0800861 rx_cfg.rx_cb = OnuStartupFailureIndication;
862 rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
863 rx_cfg.subgroup = bcmolt_onu_auto_subgroup_sufi;
864 rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
865 if(rc != BCM_ERR_OK)
866 return Status(grpc::StatusCode::INTERNAL,
867 "onu startup failure indication subscribe failed");
Shad Ansari01b0e652018-04-05 21:02:53 +0000868
Jason Huangd33b4d82019-05-15 18:22:57 +0800869 rx_cfg.obj_type = BCMOLT_OBJ_ID_ONU;
870 rx_cfg.rx_cb = OnuSignalDegradeIndication;
871 rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
872 rx_cfg.subgroup = bcmolt_onu_auto_subgroup_sdi;
873 rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
874 if(rc != BCM_ERR_OK)
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400875 return Status(grpc::StatusCode::INTERNAL, "onu sdi indication subscribe failed");
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400876
Jason Huangd33b4d82019-05-15 18:22:57 +0800877 rx_cfg.obj_type = BCMOLT_OBJ_ID_ONU;
878 rx_cfg.rx_cb = OnuDriftOfWindowIndication;
879 rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
880 rx_cfg.subgroup = bcmolt_onu_auto_subgroup_dowi;
881 rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
882 if(rc != BCM_ERR_OK)
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400883 return Status(grpc::StatusCode::INTERNAL, "onu dowi indication subscribe failed");
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400884
885 /* LOOCI indication */
Jason Huangd33b4d82019-05-15 18:22:57 +0800886 rx_cfg.obj_type = BCMOLT_OBJ_ID_ONU;
887 rx_cfg.rx_cb = OnuLossOfOmciChannelIndication;
888 rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
889 rx_cfg.subgroup = bcmolt_onu_auto_subgroup_looci;
890 rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
891 if(rc != BCM_ERR_OK)
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400892 return Status(grpc::StatusCode::INTERNAL, "onu looci indication subscribe failed");
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400893
894 /* SFI indication */
Jason Huangd33b4d82019-05-15 18:22:57 +0800895 rx_cfg.obj_type = BCMOLT_OBJ_ID_ONU;
896 rx_cfg.rx_cb = OnuSignalsFailureIndication;
897 rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
898 rx_cfg.subgroup = bcmolt_onu_auto_subgroup_sfi;
899 rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
900 if(rc != BCM_ERR_OK)
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400901 return Status(grpc::StatusCode::INTERNAL, "onu sfi indication subscribe failed");
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400902
903 /* TIWI indication */
Jason Huangd33b4d82019-05-15 18:22:57 +0800904 rx_cfg.obj_type = BCMOLT_OBJ_ID_ONU;
905 rx_cfg.rx_cb = OnuTransmissionInterferenceWarningIndication;
906 rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
907 rx_cfg.subgroup = bcmolt_onu_auto_subgroup_tiwi;
908 rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
909 if(rc != BCM_ERR_OK)
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400910 return Status(grpc::StatusCode::INTERNAL, "onu tiwi indication subscribe failed");
Jason Huangb6843dc2019-07-22 17:46:06 +0800911
Jason Huangd33b4d82019-05-15 18:22:57 +0800912 /* ONU Activation Failure Indiction */
913 rx_cfg.obj_type = BCMOLT_OBJ_ID_ONU;
914 rx_cfg.rx_cb = OnuActivationFailureIndication;
915 rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
Jason Huangb1fad572019-05-28 19:02:30 +0800916 rx_cfg.subgroup = bcmolt_onu_auto_subgroup_onu_deactivation_completed;
Jason Huangd33b4d82019-05-15 18:22:57 +0800917 rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
918 if(rc != BCM_ERR_OK)
919 return Status(grpc::StatusCode::INTERNAL,
920 "onu activation falaire indication subscribe failed");
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400921
Jason Huangd33b4d82019-05-15 18:22:57 +0800922 rx_cfg.obj_type = BCMOLT_OBJ_ID_FLOW;
923 rx_cfg.rx_cb = PacketIndication;
924 rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
925 rx_cfg.subgroup = bcmolt_flow_auto_subgroup_receive_eth_packet;
926 rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
927 if(rc != BCM_ERR_OK)
928 return Status(grpc::StatusCode::INTERNAL, "Packet indication subscribe failed");
Nicolas Palpacuerde4325b2018-07-03 11:18:42 -0400929
Shad Ansari01b0e652018-04-05 21:02:53 +0000930 subscribed = true;
931
932 return Status::OK;
933}