blob: c1886e240ed1799404c1e76f333fe1019818a539 [file] [log] [blame]
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301/*
2** Copyright 2017-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
17#include <stdio.h>
18#include <bal_api.h>
19
20#undef _SYS_QUEUE_H_
21
22/* Includes related to proto buf */
23#include "asfvolt16_driver.h"
24#include "bal_group_hdlr.h"
25
26
27/********************************************************************\
28 * Function : bal_group_cfg_req *
29 * Description : Configures the OLT device *
30 ********************************************************************/
31
32uint32_t bal_group_cfg_set(BalGroupCfg *tm_group_cfg)
33{
34 bcmos_errno err = BCM_ERR_OK;
35 bcmbal_group_cfg grp_cfg_obj; /**< declare main API struct */
36 bcmbal_group_key key = { }; /**< declare key */
37 int grp_mem_idx;
38
39 if(tm_group_cfg->key->has_group_id)
40 {
41 key.group_id = tm_group_cfg->key->group_id;
42 }
43 else
44 {
Kim Kempfafa1ab42017-11-13 09:31:47 -080045 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to configure the group cfg(OLT): Group Id was not present");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053046 return BAL_ERRNO__BAL_ERR_NOENT;
47 }
48
Kim Kempfafa1ab42017-11-13 09:31:47 -080049 ASFVOLT_LOG(ASFVOLT_DEBUG, "Configuration of OLT(group cfg) starts");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053050
51 /* init the API struct */
52 BCMBAL_CFG_INIT(&grp_cfg_obj, group, key);
53
54 /* decode API parameters from GRPC */
55 if(tm_group_cfg->data->has_members_cmd)
56 {
Kim Kempfafa1ab42017-11-13 09:31:47 -080057 ASFVOLT_CFG_PROP_SET(grp_cfg_obj, group, members_cmd,
58 tm_group_cfg->data->has_members_cmd,
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053059 tm_group_cfg->data->members_cmd);
60 }
61
62 if(tm_group_cfg->data->has_cookie)
63 {
Kim Kempfafa1ab42017-11-13 09:31:47 -080064 ASFVOLT_CFG_PROP_SET(grp_cfg_obj, group, cookie,
65 tm_group_cfg->data->has_cookie,
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053066 tm_group_cfg->data->cookie);
67 }
68
69 BalIdList *balFlows = (BalIdList *)tm_group_cfg->data->flows;
70 bcmbal_flow_id_list_u32 valFlows = {};
71
72 valFlows.len = balFlows->n_val;
73 valFlows.val = (bcmbal_flow_id *)malloc((valFlows.len)*sizeof(bcmbal_flow_id));
74 if(!valFlows.val)
75 {
Kim Kempfafa1ab42017-11-13 09:31:47 -080076 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to configure the group cfg(OLT): Memory Exhausted");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053077 return BAL_ERRNO__BAL_ERR_NOMEM;
78 }
Kim Kempfafa1ab42017-11-13 09:31:47 -080079 memcpy((void *)valFlows.val, (const void *)balFlows->val,
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053080 (balFlows->n_val)*sizeof(bcmbal_flow_id));
Kim Kempfafa1ab42017-11-13 09:31:47 -080081 ASFVOLT_CFG_PROP_SET(grp_cfg_obj, group, flows, BCMOS_TRUE, valFlows);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053082
Girish Gowdru9ebd8b22018-09-26 03:21:03 -070083 if(tm_group_cfg->data->has_type)
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053084 {
Girish Gowdru9ebd8b22018-09-26 03:21:03 -070085 ASFVOLT_CFG_PROP_SET(grp_cfg_obj, group, type,
86 tm_group_cfg->data->has_type,
87 tm_group_cfg->data->type);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053088 }
89
Kim Kempfafa1ab42017-11-13 09:31:47 -080090 BalGroupMemberInfoList *balMembers =
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053091 (BalGroupMemberInfoList *)tm_group_cfg->data->members;
92 bcmbal_group_member_info_list_u16 valMembers = {};
93 /*if(balMembers->has_len)*/
94 {
95 valMembers.len = balMembers->n_val;
Kim Kempfafa1ab42017-11-13 09:31:47 -080096 valMembers.val =
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053097 (bcmbal_group_member_info *)malloc((valMembers.len)*sizeof(bcmbal_group_member_info));
98 if(!valMembers.val)
99 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800100 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to configure the group cfg(OLT): Memory Exhausted");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530101 return BAL_ERRNO__BAL_ERR_NOMEM;
102 }
103 //check
104 //valMembers.val = &balMembers->val;
105 for(grp_mem_idx = 0; grp_mem_idx < valMembers.len; grp_mem_idx++)
106 {
107 if(balMembers->val[grp_mem_idx]->has_intf_id)
108 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800109 valMembers.val[grp_mem_idx].intf_id
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530110 = balMembers->val[grp_mem_idx]->intf_id;
111 }
112 if(balMembers->val[grp_mem_idx]->has_svc_port_id)
113 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800114 valMembers.val[grp_mem_idx].svc_port_id
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530115 = balMembers->val[grp_mem_idx]->svc_port_id;
116 }
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700117 if(balMembers->val[grp_mem_idx]->has_intf_type)
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530118 {
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700119 valMembers.val[grp_mem_idx].intf_type
120 = balMembers->val[grp_mem_idx]->intf_type;
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530121 }
122 if(balMembers->val[grp_mem_idx]->queue->has_sched_id)
123 {
124 valMembers.val[grp_mem_idx].queue.sched_id
125 = balMembers->val[grp_mem_idx]->queue->sched_id;
126 }
127 if(balMembers->val[grp_mem_idx]->queue->has_queue_id)
128 {
129 valMembers.val[grp_mem_idx].queue.queue_id
130 = balMembers->val[grp_mem_idx]->queue->queue_id;
131 }
132 }
Kim Kempfafa1ab42017-11-13 09:31:47 -0800133 ASFVOLT_CFG_PROP_SET(grp_cfg_obj, group, members, BCMOS_TRUE, valMembers);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530134 }
135
136 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(grp_cfg_obj.hdr));
137
138 if(BCM_ERR_OK != err)
139 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800140 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to configure the group cfg(OLT)");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530141 return err;
142 }
143
Kim Kempfafa1ab42017-11-13 09:31:47 -0800144 ASFVOLT_LOG(ASFVOLT_INFO, "Set Group configuration sent to OLT for Group Id(%d)",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530145 key.group_id);
146 return err;
147}
148
149
150/********************************************************************\
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700151 * Function : bal_group_cfg_get *
152 * Description : get the OLT device group cfg *
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530153 ********************************************************************/
154
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700155uint32_t bal_group_cfg_get(BalGroupCfg *group_cfg)
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530156{
157 bcmos_errno err = BCM_ERR_OK;
158 bcmbal_group_cfg grp_cfg_obj; /**< declare main API struct */
159 bcmbal_group_key key = { }; /**< declare key */
160
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700161 if(group_cfg->key->has_group_id)
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530162 {
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700163 key.group_id = group_cfg->key->group_id;
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530164 }
165 else
166 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800167 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to get the group cfg(OLT): Group Id was not present");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530168 return BAL_ERRNO__BAL_ERR_NOENT;
169 }
170
Kim Kempfafa1ab42017-11-13 09:31:47 -0800171 ASFVOLT_LOG(ASFVOLT_DEBUG, "Get group cfg(for OLT) starts");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530172
173 /* init the API struct */
174 BCMBAL_CFG_INIT(&grp_cfg_obj, group, key);
175
176 /* request all properties, include everything */
177 BCMBAL_CFG_PROP_GET(&grp_cfg_obj, group, all_properties);
178
179 err = bcmbal_cfg_get(DEFAULT_ATERM_ID, &grp_cfg_obj.hdr);
180
181 if(BCM_ERR_OK != err)
182 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800183 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to get the group Cfg(OLT)");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530184 return err;
185 }
186
Kim Kempfafa1ab42017-11-13 09:31:47 -0800187 ASFVOLT_LOG(ASFVOLT_INFO, "Get Group cfg sent to OLT for Group Id(%d)",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530188 key.group_id);
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700189
190 memcpy(group_cfg->key, &key, sizeof(BalFlowKey));
191 memcpy(group_cfg->data, &grp_cfg_obj, sizeof(BalFlowCfgData));
192
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530193 return err;
194}
195
196/********************************************************************\
197 * Function : bal_group_clear_req *
198 * Description : clears the OLT device group cfg *
199 ********************************************************************/
200
201uint32_t bal_group_cfg_clear(BalGroupKey *tm_group_cfg_key)
202{
203 bcmos_errno err = BCM_ERR_OK;
204 bcmbal_group_cfg grp_cfg_obj; /**< declare main API struct */
205 bcmbal_group_key key = { }; /**< declare key */
206
207 if(tm_group_cfg_key->has_group_id)
208 {
209 key.group_id = tm_group_cfg_key->group_id;
210 }
211 else
212 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800213 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to clear the group cfg(OLT): Group Id was not present");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530214 return BAL_ERRNO__BAL_ERR_NOENT;
215 }
216
Kim Kempfafa1ab42017-11-13 09:31:47 -0800217 ASFVOLT_LOG(ASFVOLT_DEBUG, "Clearing of OLT(group cfg) starts");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530218
219 /* init the API struct */
220 BCMBAL_CFG_INIT(&grp_cfg_obj, group, key);
221
222 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &grp_cfg_obj.hdr);
223
224 if(BCM_ERR_OK != err)
225 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800226 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to clear the group Cfg(OLT)");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530227 return err;
228 }
229
Kim Kempfafa1ab42017-11-13 09:31:47 -0800230 ASFVOLT_LOG(ASFVOLT_INFO, "Clear Group cfg clear sent to OLT for Group Id(%d)",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530231 key.group_id);
232 return err;
233}
234
235/********************************************************************\
236 * Function : bal_group_cfg_indication_cb *
237 * Description : Call back function registered with BAL to handle *
238 * event related to access terminal *
239 ********************************************************************/
240bcmos_errno bal_group_cfg_indication_cb(bcmbal_obj *obj)
241{
242 bcmos_errno result = BCM_ERR_OK;
Kim Kempfafa1ab42017-11-13 09:31:47 -0800243 ASFVOLT_LOG(ASFVOLT_INFO, "Processing API ('%s)' IND callback status is (%s)",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530244 bcmbal_objtype_str(obj->obj_type),
245 bcmos_strerror(obj->status));
Kim Kempfafa1ab42017-11-13 09:31:47 -0800246
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530247 return result;
248}