blob: b48666210e7c3324fd35556904083859d8ef17b4 [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"
18#include "server.h"
19#include "utils.h"
20extern "C"
21{
22#include <bcmos_system.h>
23#include <bal_api.h>
24#include <bal_api_end.h>
25}
26
27using grpc::Status;
28
29Queue<openolt::Indication> oltIndQ;
30//Queue<openolt::Indication*> oltIndQ;
31
32bool subscribed = false;
33
34bcmos_errno OmciIndication(bcmbal_obj *obj);
35
36bcmos_errno OltIndication(bcmbal_obj *obj) {
37 openolt::Indication ind;
38 openolt::OltIndication* olt_ind = new openolt::OltIndication;
39 Status status;
40
41 bcmbal_access_terminal_ind *acc_term_ind = (bcmbal_access_terminal_ind *)obj;
42 if (acc_term_ind->data.oper_status == BCMBAL_STATUS_UP) {
43 olt_ind->set_oper_state("up");
44 } else {
45 olt_ind->set_oper_state("down");
46 }
47 ind.set_allocated_olt_ind(olt_ind);
48 std::cout << "olt indication, oper_state:" << ind.olt_ind().oper_state() << std::endl;
49 oltIndQ.push(ind);
50
51 // Enable all PON interfaces.
52 for (int i = 0; i < MAX_SUPPORTED_INTF; i++) {
53 status = EnablePonIf_(i);
54 if (!status.ok()) {
55 // FIXME - raise alarm to report error in enabling PON
56 }
57 }
58
59 /* register for omci indication */
60 {
61 bcmbal_cb_cfg cb_cfg = {};
62 uint16_t ind_subgroup;
63
64 cb_cfg.module = BCMOS_MODULE_ID_NONE;
65 cb_cfg.obj_type = BCMBAL_OBJ_ID_PACKET;
66 ind_subgroup = BCMBAL_IND_SUBGROUP(packet, itu_omci_channel_rx);
67 cb_cfg.p_object_key_info = NULL;
68 cb_cfg.p_subgroup = &ind_subgroup;
69 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)OmciIndication;
70 bcmbal_subscribe_ind(0, &cb_cfg);
71 }
72
73 return BCM_ERR_OK;
74}
75
76bcmos_errno LosIndication(bcmbal_obj *obj) {
77 openolt::Indication ind;
78 std::cout << "LOS indication " << std::endl;
79 return BCM_ERR_OK;
80}
81
82bcmos_errno IfIndication(bcmbal_obj *obj) {
83 openolt::Indication ind;
84 openolt::IntfIndication* intf_ind = new openolt::IntfIndication;
85
86 std::cout << "intf indication, intf_id:"
87 << ((bcmbal_interface_ind *)obj)->key.intf_id << std::endl;
88
89 intf_ind->set_intf_id(((bcmbal_interface_ind *)obj)->key.intf_id);
90 if (((bcmbal_interface_ind *)obj)->data.oper_status == BCMBAL_STATUS_UP) {
91 intf_ind->set_oper_state("up");
92 } else {
93 intf_ind->set_oper_state("down");
94 }
95 ind.set_allocated_intf_ind(intf_ind);
96
97 oltIndQ.push(ind);
98
99 return BCM_ERR_OK;
100}
101
102bcmos_errno IfOperIndication(bcmbal_obj *obj) {
103 openolt::Indication ind;
104 openolt::IntfOperIndication* intf_oper_ind = new openolt::IntfOperIndication;
105 std::cout << "intf oper state indication, intf_id:"
106 << ((bcmbal_interface_ind *)obj)->key.intf_id
107 << " type:" << ((bcmbal_interface_oper_status_change *)obj)->key.intf_type
108 << " oper_state:" << ((bcmbal_interface_oper_status_change *)obj)->data.new_oper_status
109 << " admin_state:" << ((bcmbal_interface_oper_status_change *)obj)->data.admin_state
110 << std::endl;
111
112 intf_oper_ind->set_intf_id(((bcmbal_interface_oper_status_change *)obj)->key.intf_id);
113
114 if (((bcmbal_interface_oper_status_change *)obj)->key.intf_type == BCMBAL_INTF_TYPE_NNI) {
115 intf_oper_ind->set_type("nni");
116 } else if (((bcmbal_interface_oper_status_change *)obj)->key.intf_type == BCMBAL_INTF_TYPE_PON) {
117 intf_oper_ind->set_type("pon");
118 } else {
119 intf_oper_ind->set_type("unknown");
120 }
121
122 if (((bcmbal_interface_oper_status_change *)obj)->data.new_oper_status == BCMBAL_STATUS_UP) {
123 intf_oper_ind->set_oper_state("up");
124 } else {
125 intf_oper_ind->set_oper_state("down");
126 }
127
128 ind.set_allocated_intf_oper_ind(intf_oper_ind);
129
130 oltIndQ.push(ind);
131 return BCM_ERR_OK;
132}
133
134bcmos_errno OnuAlarmIndication(bcmbal_obj *obj) {
135 openolt::Indication ind;
136 std::cout << "onu alarm indication" << std::endl;
137 return BCM_ERR_OK;
138}
139
140bcmos_errno OnuDyingGaspIndication(bcmbal_obj *obj) {
141 openolt::Indication ind;
142 std::cout << "onu dying-gasp indication" << std::endl;
143 return BCM_ERR_OK;
144}
145
146bcmos_errno OnuDiscoveryIndication(bcmbal_cfg *obj) {
147 openolt::Indication ind;
148 openolt::OnuDiscIndication* onu_disc_ind = new openolt::OnuDiscIndication;
149 openolt::SerialNumber* serial_number = new openolt::SerialNumber;
150
151 bcmbal_subscriber_terminal_key *key =
152 &(((bcmbal_subscriber_terminal_sub_term_disc*)obj)->key);
153
154 bcmbal_subscriber_terminal_sub_term_disc_data *data =
155 &(((bcmbal_subscriber_terminal_sub_term_disc*)obj)->data);
156
157 bcmbal_serial_number *in_serial_number = &(data->serial_number);
158
159 std::cout << "onu discover indication, intf_id:"
160 << key->intf_id
161 << " serial_number:"
162 << serial_number_to_str(in_serial_number) << std::endl;
163
164 onu_disc_ind->set_intf_id(key->intf_id);
165 serial_number->set_vendor_id(reinterpret_cast<const char *>(in_serial_number->vendor_id), 4);
166 serial_number->set_vendor_specific(reinterpret_cast<const char *>(in_serial_number->vendor_specific), 8);
167 onu_disc_ind->set_allocated_serial_number(serial_number);
168 ind.set_allocated_onu_disc_ind(onu_disc_ind);
169
170 oltIndQ.push(ind);
171
172 return BCM_ERR_OK;
173}
174
175bcmos_errno OnuIndication(bcmbal_obj *obj) {
176 openolt::Indication ind;
177 openolt::OnuIndication* onu_ind = new openolt::OnuIndication;
178 openolt::SerialNumber* serial_number = new openolt::SerialNumber;
179
180 bcmbal_subscriber_terminal_key *key =
181 &(((bcmbal_subscriber_terminal_ind*)obj)->key);
182
183 bcmbal_subscriber_terminal_ind_data *data =
184 &(((bcmbal_subscriber_terminal_ind*)obj)->data);
185
186 bcmbal_serial_number *in_serial_number = &(data->serial_number);
187
188 std::cout << "onu indication, intf_id:"
189 << key->intf_id
190 << " serial_number:"
191 << serial_number_to_str(in_serial_number) << std::endl;
192
193 onu_ind->set_intf_id(key->intf_id);
194 onu_ind->set_onu_id(key->sub_term_id);
195 serial_number->set_vendor_id(reinterpret_cast<const char *>(in_serial_number->vendor_id), 4);
196 serial_number->set_vendor_specific(reinterpret_cast<const char *>(in_serial_number->vendor_specific), 8);
197 onu_ind->set_allocated_serial_number(serial_number);
198 ind.set_allocated_onu_ind(onu_ind);
199
200 oltIndQ.push(ind);
201 return BCM_ERR_OK;
202}
203
204bcmos_errno OnuOperIndication(bcmbal_obj *obj) {
205 openolt::Indication ind;
206 std::cout << "onu oper state indication" << std::endl;
207 return BCM_ERR_OK;
208}
209
210bcmos_errno OmciIndication(bcmbal_obj *obj) {
211 openolt::Indication ind;
212 openolt::OmciIndication* omci_ind = new openolt::OmciIndication;
Shad Ansari5fe93682018-04-26 05:24:19 +0000213 bcmbal_packet_itu_omci_channel_rx *in =
Shad Ansari01b0e652018-04-05 21:02:53 +0000214 (bcmbal_packet_itu_omci_channel_rx *)obj;
215
216 std::cout << "omci indication" << std::endl;
217
Shad Ansari5fe93682018-04-26 05:24:19 +0000218 omci_ind->set_intf_id(in->key.packet_send_dest.u.itu_omci_channel.intf_id);
219 omci_ind->set_onu_id(in->key.packet_send_dest.u.itu_omci_channel.sub_term_id);
220 omci_ind->set_pkt(in->data.pkt.val, in->data.pkt.len);
Shad Ansari01b0e652018-04-05 21:02:53 +0000221
222 ind.set_allocated_omci_ind(omci_ind);
223 oltIndQ.push(ind);
224
225 return BCM_ERR_OK;
226}
227
Shad Ansari5fe93682018-04-26 05:24:19 +0000228bcmos_errno PacketIndication(bcmbal_obj *obj) {
Shad Ansari01b0e652018-04-05 21:02:53 +0000229 openolt::Indication ind;
Shad Ansari5fe93682018-04-26 05:24:19 +0000230 openolt::PacketIndication* pkt_ind = new openolt::PacketIndication;
231 bcmbal_packet_bearer_channel_rx *in = (bcmbal_packet_bearer_channel_rx *)obj;
232
233 std::cout << "packet indication"
234 << " intf_id:" << in->data.intf_id
235 << " svc_port:" << in->data.svc_port
236 << " flow_id:" << in->data.flow_id
237 << std::endl;
238
239 pkt_ind->set_intf_id(in->data.intf_id);
240 pkt_ind->set_gemport_id(in->data.svc_port);
241 pkt_ind->set_flow_id(in->data.flow_id);
242 pkt_ind->set_pkt(in->data.pkt.val, in->data.pkt.len);
243
244 ind.set_allocated_pkt_ind(pkt_ind);
245 oltIndQ.push(ind);
246
Shad Ansari01b0e652018-04-05 21:02:53 +0000247 return BCM_ERR_OK;
248}
249
250bcmos_errno FlowOperIndication(bcmbal_obj *obj) {
251 openolt::Indication ind;
252 std::cout << "flow oper state indication" << std::endl;
253 return BCM_ERR_OK;
254}
255
256bcmos_errno FlowIndication(bcmbal_obj *obj) {
257 openolt::Indication ind;
258 std::cout << "flow indication" << std::endl;
259 return BCM_ERR_OK;
260}
261
262bcmos_errno TmQIndication(bcmbal_obj *obj) {
263 openolt::Indication ind;
264 std::cout << "traffic mgmt queue indication" << std::endl;
265 return BCM_ERR_OK;
266}
267
268bcmos_errno TmSchedIndication(bcmbal_obj *obj) {
269 openolt::Indication ind;
270 std::cout << "traffic mgmt sheduler indication" << std::endl;
271 return BCM_ERR_OK;
272}
273
274bcmos_errno McastGroupIndication(bcmbal_obj *obj) {
275 openolt::Indication ind;
276 std::cout << "mcast group indication" << std::endl;
277 return BCM_ERR_OK;
278}
279
280Status SubscribeIndication() {
281 bcmbal_cb_cfg cb_cfg = {};
282 uint16_t ind_subgroup;
283
284 if (subscribed) {
285 return Status::OK;
286 }
287
288 cb_cfg.module = BCMOS_MODULE_ID_NONE;
289
290
291 /* OLT device indication */
292 cb_cfg.obj_type = BCMBAL_OBJ_ID_ACCESS_TERMINAL;
293 ind_subgroup = bcmbal_access_terminal_auto_id_ind;
294 cb_cfg.p_subgroup = &ind_subgroup;
295 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)OltIndication;
296 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
297 return Status(grpc::StatusCode::INTERNAL, "Olt indication subscribe failed");
298 }
299
300 /* Interface LOS indication */
301 cb_cfg.obj_type = BCMBAL_OBJ_ID_INTERFACE;
302 ind_subgroup = bcmbal_interface_auto_id_los;
303 cb_cfg.p_subgroup = &ind_subgroup;
304 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)LosIndication;
305 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
306 return Status(grpc::StatusCode::INTERNAL, "LOS indication subscribe failed");
307 }
308
309 /* Interface indication */
310 cb_cfg.obj_type = BCMBAL_OBJ_ID_INTERFACE;
311 ind_subgroup = bcmbal_interface_auto_id_ind;
312 cb_cfg.p_subgroup = &ind_subgroup;
313 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)IfIndication;
314 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
315 return Status(grpc::StatusCode::INTERNAL, "Interface indication subscribe failed");
316 }
317
318 /* Interface operational state change indication */
319 cb_cfg.obj_type = BCMBAL_OBJ_ID_INTERFACE;
320 ind_subgroup = bcmbal_interface_auto_id_oper_status_change;
321 cb_cfg.p_subgroup = &ind_subgroup;
322 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)IfOperIndication;
323 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
324 return Status(grpc::StatusCode::INTERNAL, "Interface operations state change indication subscribe failed");
325 }
326
327 /* onu alarm indication */
328 cb_cfg.obj_type = BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL;
329 ind_subgroup = bcmbal_subscriber_terminal_auto_id_sub_term_alarm;
330 cb_cfg.p_subgroup = &ind_subgroup;
331 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)OnuAlarmIndication;
332 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
333 return Status(grpc::StatusCode::INTERNAL, "onu alarm indication subscribe failed");
334 }
335
336 /* onu dying-gasp indication */
337 cb_cfg.obj_type = BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL;
338 ind_subgroup = bcmbal_subscriber_terminal_auto_id_dgi;
339 cb_cfg.p_subgroup = &ind_subgroup;
340 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)OnuDyingGaspIndication;
341 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
342 return Status(grpc::StatusCode::INTERNAL, "onu dying-gasp indication subscribe failed");
343 }
344
345 /* onu discovery indication */
346 cb_cfg.obj_type = BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL;
347 ind_subgroup = bcmbal_subscriber_terminal_auto_id_sub_term_disc;
348 cb_cfg.p_subgroup = &ind_subgroup;
349 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)OnuDiscoveryIndication;
350 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
351 return Status(grpc::StatusCode::INTERNAL, "onu discovery indication subscribe failed");
352 }
353
354 /* onu indication */
355 cb_cfg.obj_type = BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL;
356 ind_subgroup = bcmbal_subscriber_terminal_auto_id_ind;
357 cb_cfg.p_subgroup = &ind_subgroup;
358 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)OnuIndication;
359 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
360 return Status(grpc::StatusCode::INTERNAL, "onu indication subscribe failed");
361 }
362 /* onu operational state change indication */
363 cb_cfg.obj_type = BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL;
364 ind_subgroup = bcmbal_subscriber_terminal_auto_id_oper_status_change;
365 cb_cfg.p_subgroup = &ind_subgroup;
366 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)OnuOperIndication;
367 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
368 return Status(grpc::StatusCode::INTERNAL, "onu operational state change indication subscribe failed");
369 }
370
Shad Ansari5fe93682018-04-26 05:24:19 +0000371 /* Packet (bearer) indication */
Shad Ansari01b0e652018-04-05 21:02:53 +0000372 cb_cfg.obj_type = BCMBAL_OBJ_ID_PACKET;
373 ind_subgroup = bcmbal_packet_auto_id_bearer_channel_rx;
374 cb_cfg.p_subgroup = &ind_subgroup;
Shad Ansari5fe93682018-04-26 05:24:19 +0000375 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)PacketIndication;
Shad Ansari01b0e652018-04-05 21:02:53 +0000376 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
Shad Ansari5fe93682018-04-26 05:24:19 +0000377 return Status(grpc::StatusCode::INTERNAL, "Packet indication subscribe failed");
Shad Ansari01b0e652018-04-05 21:02:53 +0000378 }
379
380 /* Flow Operational State Change */
381 cb_cfg.obj_type = BCMBAL_OBJ_ID_FLOW;
382 ind_subgroup = bcmbal_flow_auto_id_oper_status_change;
383 cb_cfg.p_subgroup = &ind_subgroup;
384 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)FlowOperIndication;
385 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
386 return Status(grpc::StatusCode::INTERNAL, "Flow operational state change indication subscribe failed");
387 }
388 /* Flow Indication */
389 cb_cfg.obj_type = BCMBAL_OBJ_ID_FLOW;
390 ind_subgroup = bcmbal_flow_auto_id_ind;
391 cb_cfg.p_subgroup = &ind_subgroup;
392 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)FlowIndication;
393 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
394 return Status(grpc::StatusCode::INTERNAL, "Flow indication subscribe failed");
395 }
396
397 /* TM queue indication */
398 cb_cfg.obj_type = BCMBAL_OBJ_ID_TM_QUEUE;
399 ind_subgroup = bcmbal_tm_queue_auto_id_ind;
400 cb_cfg.p_subgroup = &ind_subgroup;
401 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)TmQIndication;
402 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
403 return Status(grpc::StatusCode::INTERNAL, "Traffic mgmt queue indication subscribe failed");
404 }
405
406 /* TM sched indication */
407 cb_cfg.obj_type = BCMBAL_OBJ_ID_TM_SCHED;
408 ind_subgroup = bcmbal_tm_sched_auto_id_ind;
409 cb_cfg.p_subgroup = &ind_subgroup;
410 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)TmSchedIndication;
411 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
412 return Status(grpc::StatusCode::INTERNAL, "Traffic mgmt queue indication subscribe failed");
413 }
414
415 /* Multicast group indication */
416 cb_cfg.obj_type = BCMBAL_OBJ_ID_GROUP;
417 ind_subgroup = bcmbal_group_auto_id_ind;
418 cb_cfg.p_subgroup = &ind_subgroup;
419 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)McastGroupIndication;
420 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
421 return Status(grpc::StatusCode::INTERNAL, "Multicast group indication subscribe failed");
422 }
423
424 subscribed = true;
425
426 return Status::OK;
427}