blob: 78eb3b2e458ae16f78d94e039c911ee8a014d08b [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;
213 bcmbal_packet_itu_omci_channel_rx *omci_channel =
214 (bcmbal_packet_itu_omci_channel_rx *)obj;
215
216 std::cout << "omci indication" << std::endl;
217
218 omci_ind->set_intf_id(
219 omci_channel->key.packet_send_dest.u.itu_omci_channel.intf_id);
220 omci_ind->set_onu_id(
221 omci_channel->key.packet_send_dest.u.itu_omci_channel.sub_term_id);
222 omci_ind->set_pkt(omci_channel->data.pkt.val, omci_channel->data.pkt.len);
223
224 ind.set_allocated_omci_ind(omci_ind);
225 oltIndQ.push(ind);
226
227 return BCM_ERR_OK;
228}
229
230bcmos_errno PacketInIndication(bcmbal_obj *obj) {
231 openolt::Indication ind;
232 std::cout << "packet-in indication" << std::endl;
233 return BCM_ERR_OK;
234}
235
236bcmos_errno FlowOperIndication(bcmbal_obj *obj) {
237 openolt::Indication ind;
238 std::cout << "flow oper state indication" << std::endl;
239 return BCM_ERR_OK;
240}
241
242bcmos_errno FlowIndication(bcmbal_obj *obj) {
243 openolt::Indication ind;
244 std::cout << "flow indication" << std::endl;
245 return BCM_ERR_OK;
246}
247
248bcmos_errno TmQIndication(bcmbal_obj *obj) {
249 openolt::Indication ind;
250 std::cout << "traffic mgmt queue indication" << std::endl;
251 return BCM_ERR_OK;
252}
253
254bcmos_errno TmSchedIndication(bcmbal_obj *obj) {
255 openolt::Indication ind;
256 std::cout << "traffic mgmt sheduler indication" << std::endl;
257 return BCM_ERR_OK;
258}
259
260bcmos_errno McastGroupIndication(bcmbal_obj *obj) {
261 openolt::Indication ind;
262 std::cout << "mcast group indication" << std::endl;
263 return BCM_ERR_OK;
264}
265
266Status SubscribeIndication() {
267 bcmbal_cb_cfg cb_cfg = {};
268 uint16_t ind_subgroup;
269
270 if (subscribed) {
271 return Status::OK;
272 }
273
274 cb_cfg.module = BCMOS_MODULE_ID_NONE;
275
276
277 /* OLT device indication */
278 cb_cfg.obj_type = BCMBAL_OBJ_ID_ACCESS_TERMINAL;
279 ind_subgroup = bcmbal_access_terminal_auto_id_ind;
280 cb_cfg.p_subgroup = &ind_subgroup;
281 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)OltIndication;
282 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
283 return Status(grpc::StatusCode::INTERNAL, "Olt indication subscribe failed");
284 }
285
286 /* Interface LOS indication */
287 cb_cfg.obj_type = BCMBAL_OBJ_ID_INTERFACE;
288 ind_subgroup = bcmbal_interface_auto_id_los;
289 cb_cfg.p_subgroup = &ind_subgroup;
290 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)LosIndication;
291 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
292 return Status(grpc::StatusCode::INTERNAL, "LOS indication subscribe failed");
293 }
294
295 /* Interface indication */
296 cb_cfg.obj_type = BCMBAL_OBJ_ID_INTERFACE;
297 ind_subgroup = bcmbal_interface_auto_id_ind;
298 cb_cfg.p_subgroup = &ind_subgroup;
299 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)IfIndication;
300 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
301 return Status(grpc::StatusCode::INTERNAL, "Interface indication subscribe failed");
302 }
303
304 /* Interface operational state change indication */
305 cb_cfg.obj_type = BCMBAL_OBJ_ID_INTERFACE;
306 ind_subgroup = bcmbal_interface_auto_id_oper_status_change;
307 cb_cfg.p_subgroup = &ind_subgroup;
308 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)IfOperIndication;
309 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
310 return Status(grpc::StatusCode::INTERNAL, "Interface operations state change indication subscribe failed");
311 }
312
313 /* onu alarm indication */
314 cb_cfg.obj_type = BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL;
315 ind_subgroup = bcmbal_subscriber_terminal_auto_id_sub_term_alarm;
316 cb_cfg.p_subgroup = &ind_subgroup;
317 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)OnuAlarmIndication;
318 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
319 return Status(grpc::StatusCode::INTERNAL, "onu alarm indication subscribe failed");
320 }
321
322 /* onu dying-gasp indication */
323 cb_cfg.obj_type = BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL;
324 ind_subgroup = bcmbal_subscriber_terminal_auto_id_dgi;
325 cb_cfg.p_subgroup = &ind_subgroup;
326 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)OnuDyingGaspIndication;
327 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
328 return Status(grpc::StatusCode::INTERNAL, "onu dying-gasp indication subscribe failed");
329 }
330
331 /* onu discovery indication */
332 cb_cfg.obj_type = BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL;
333 ind_subgroup = bcmbal_subscriber_terminal_auto_id_sub_term_disc;
334 cb_cfg.p_subgroup = &ind_subgroup;
335 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)OnuDiscoveryIndication;
336 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
337 return Status(grpc::StatusCode::INTERNAL, "onu discovery indication subscribe failed");
338 }
339
340 /* onu indication */
341 cb_cfg.obj_type = BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL;
342 ind_subgroup = bcmbal_subscriber_terminal_auto_id_ind;
343 cb_cfg.p_subgroup = &ind_subgroup;
344 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)OnuIndication;
345 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
346 return Status(grpc::StatusCode::INTERNAL, "onu indication subscribe failed");
347 }
348 /* onu operational state change indication */
349 cb_cfg.obj_type = BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL;
350 ind_subgroup = bcmbal_subscriber_terminal_auto_id_oper_status_change;
351 cb_cfg.p_subgroup = &ind_subgroup;
352 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)OnuOperIndication;
353 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
354 return Status(grpc::StatusCode::INTERNAL, "onu operational state change indication subscribe failed");
355 }
356
357 /* Packet-in indications */
358 cb_cfg.obj_type = BCMBAL_OBJ_ID_PACKET;
359 ind_subgroup = bcmbal_packet_auto_id_bearer_channel_rx;
360 cb_cfg.p_subgroup = &ind_subgroup;
361 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)PacketInIndication;
362 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
363 return Status(grpc::StatusCode::INTERNAL, "Packet-in indication subscribe failed");
364 }
365
366 /* Flow Operational State Change */
367 cb_cfg.obj_type = BCMBAL_OBJ_ID_FLOW;
368 ind_subgroup = bcmbal_flow_auto_id_oper_status_change;
369 cb_cfg.p_subgroup = &ind_subgroup;
370 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)FlowOperIndication;
371 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
372 return Status(grpc::StatusCode::INTERNAL, "Flow operational state change indication subscribe failed");
373 }
374 /* Flow Indication */
375 cb_cfg.obj_type = BCMBAL_OBJ_ID_FLOW;
376 ind_subgroup = bcmbal_flow_auto_id_ind;
377 cb_cfg.p_subgroup = &ind_subgroup;
378 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)FlowIndication;
379 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
380 return Status(grpc::StatusCode::INTERNAL, "Flow indication subscribe failed");
381 }
382
383 /* TM queue indication */
384 cb_cfg.obj_type = BCMBAL_OBJ_ID_TM_QUEUE;
385 ind_subgroup = bcmbal_tm_queue_auto_id_ind;
386 cb_cfg.p_subgroup = &ind_subgroup;
387 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)TmQIndication;
388 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
389 return Status(grpc::StatusCode::INTERNAL, "Traffic mgmt queue indication subscribe failed");
390 }
391
392 /* TM sched indication */
393 cb_cfg.obj_type = BCMBAL_OBJ_ID_TM_SCHED;
394 ind_subgroup = bcmbal_tm_sched_auto_id_ind;
395 cb_cfg.p_subgroup = &ind_subgroup;
396 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)TmSchedIndication;
397 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
398 return Status(grpc::StatusCode::INTERNAL, "Traffic mgmt queue indication subscribe failed");
399 }
400
401 /* Multicast group indication */
402 cb_cfg.obj_type = BCMBAL_OBJ_ID_GROUP;
403 ind_subgroup = bcmbal_group_auto_id_ind;
404 cb_cfg.p_subgroup = &ind_subgroup;
405 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)McastGroupIndication;
406 if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
407 return Status(grpc::StatusCode::INTERNAL, "Multicast group indication subscribe failed");
408 }
409
410 subscribed = true;
411
412 return Status::OK;
413}