blob: c00b1a3f372de4e64fd319d548de4b1733b9ffb0 [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
83 if(tm_group_cfg->data->has_owner)
84 {
Kim Kempfafa1ab42017-11-13 09:31:47 -080085 ASFVOLT_CFG_PROP_SET(grp_cfg_obj, group, owner,
86 tm_group_cfg->data->has_owner,
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053087 tm_group_cfg->data->owner);
88 }
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 }
117 if(balMembers->val[grp_mem_idx]->action->has_presence_mask)
118 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800119 valMembers.val[grp_mem_idx].action.presence_mask
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530120 = balMembers->val[grp_mem_idx]->action->presence_mask;
121 }
122 if(balMembers->val[grp_mem_idx]->action->has_cmds_bitmask)
123 {
124 valMembers.val[grp_mem_idx].action.cmds_bitmask
125 = balMembers->val[grp_mem_idx]->action->cmds_bitmask;
126 }
127 if(balMembers->val[grp_mem_idx]->action->has_o_vid)
128 {
129 valMembers.val[grp_mem_idx].action.o_vid
130 = balMembers->val[grp_mem_idx]->action->o_vid;
131 }
132 if(balMembers->val[grp_mem_idx]->action->has_o_pbits)
133 {
134 valMembers.val[grp_mem_idx].action.o_pbits
135 = balMembers->val[grp_mem_idx]->action->o_pbits;
136 }
137 if(balMembers->val[grp_mem_idx]->action->has_o_tpid)
138 {
139 valMembers.val[grp_mem_idx].action.o_tpid
140 = balMembers->val[grp_mem_idx]->action->o_tpid;
141 }
142 if(balMembers->val[grp_mem_idx]->action->has_i_vid)
143 {
144 valMembers.val[grp_mem_idx].action.i_vid
145 = balMembers->val[grp_mem_idx]->action->i_vid;
146 }
147 if(balMembers->val[grp_mem_idx]->action->has_i_pbits)
148 {
149 valMembers.val[grp_mem_idx].action.i_pbits
150 = balMembers->val[grp_mem_idx]->action->i_pbits;
151 }
152 if(balMembers->val[grp_mem_idx]->action->has_i_tpid)
153 {
154 valMembers.val[grp_mem_idx].action.i_tpid
155 = balMembers->val[grp_mem_idx]->action->i_tpid;
156 }
157 if(balMembers->val[grp_mem_idx]->queue->has_sched_id)
158 {
159 valMembers.val[grp_mem_idx].queue.sched_id
160 = balMembers->val[grp_mem_idx]->queue->sched_id;
161 }
162 if(balMembers->val[grp_mem_idx]->queue->has_queue_id)
163 {
164 valMembers.val[grp_mem_idx].queue.queue_id
165 = balMembers->val[grp_mem_idx]->queue->queue_id;
166 }
167 }
Kim Kempfafa1ab42017-11-13 09:31:47 -0800168 ASFVOLT_CFG_PROP_SET(grp_cfg_obj, group, members, BCMOS_TRUE, valMembers);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530169 }
170
171 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(grp_cfg_obj.hdr));
172
173 if(BCM_ERR_OK != err)
174 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800175 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to configure the group cfg(OLT)");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530176 return err;
177 }
178
Kim Kempfafa1ab42017-11-13 09:31:47 -0800179 ASFVOLT_LOG(ASFVOLT_INFO, "Set Group configuration sent to OLT for Group Id(%d)",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530180 key.group_id);
181 return err;
182}
183
184
185/********************************************************************\
186 * Function : bal_group_get_req *
187 * Description : get the OLT device group cfg *
188 ********************************************************************/
189
Kim Kempfafa1ab42017-11-13 09:31:47 -0800190uint32_t bal_group_cfg_get(BalGroupKey *tm_group_cfg_key,
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530191 BalGroupCfg *tm_group_cfg)
192{
193 bcmos_errno err = BCM_ERR_OK;
194 bcmbal_group_cfg grp_cfg_obj; /**< declare main API struct */
195 bcmbal_group_key key = { }; /**< declare key */
196
197 if(tm_group_cfg_key->has_group_id)
198 {
199 key.group_id = tm_group_cfg_key->group_id;
200 }
201 else
202 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800203 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to get the group cfg(OLT): Group Id was not present");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530204 return BAL_ERRNO__BAL_ERR_NOENT;
205 }
206
Kim Kempfafa1ab42017-11-13 09:31:47 -0800207 ASFVOLT_LOG(ASFVOLT_DEBUG, "Get group cfg(for OLT) starts");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530208
209 /* init the API struct */
210 BCMBAL_CFG_INIT(&grp_cfg_obj, group, key);
211
212 /* request all properties, include everything */
213 BCMBAL_CFG_PROP_GET(&grp_cfg_obj, group, all_properties);
214
215 err = bcmbal_cfg_get(DEFAULT_ATERM_ID, &grp_cfg_obj.hdr);
216
217 if(BCM_ERR_OK != err)
218 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800219 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to get the group Cfg(OLT)");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530220 return err;
221 }
222
Kim Kempfafa1ab42017-11-13 09:31:47 -0800223 ASFVOLT_LOG(ASFVOLT_INFO, "Get Group cfg sent to OLT for Group Id(%d)",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530224 key.group_id);
225 return err;
226}
227
228/********************************************************************\
229 * Function : bal_group_clear_req *
230 * Description : clears the OLT device group cfg *
231 ********************************************************************/
232
233uint32_t bal_group_cfg_clear(BalGroupKey *tm_group_cfg_key)
234{
235 bcmos_errno err = BCM_ERR_OK;
236 bcmbal_group_cfg grp_cfg_obj; /**< declare main API struct */
237 bcmbal_group_key key = { }; /**< declare key */
238
239 if(tm_group_cfg_key->has_group_id)
240 {
241 key.group_id = tm_group_cfg_key->group_id;
242 }
243 else
244 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800245 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to clear the group cfg(OLT): Group Id was not present");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530246 return BAL_ERRNO__BAL_ERR_NOENT;
247 }
248
Kim Kempfafa1ab42017-11-13 09:31:47 -0800249 ASFVOLT_LOG(ASFVOLT_DEBUG, "Clearing of OLT(group cfg) starts");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530250
251 /* init the API struct */
252 BCMBAL_CFG_INIT(&grp_cfg_obj, group, key);
253
254 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &grp_cfg_obj.hdr);
255
256 if(BCM_ERR_OK != err)
257 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800258 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to clear the group Cfg(OLT)");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530259 return err;
260 }
261
Kim Kempfafa1ab42017-11-13 09:31:47 -0800262 ASFVOLT_LOG(ASFVOLT_INFO, "Clear Group cfg clear sent to OLT for Group Id(%d)",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530263 key.group_id);
264 return err;
265}
266
267/********************************************************************\
268 * Function : bal_group_cfg_indication_cb *
269 * Description : Call back function registered with BAL to handle *
270 * event related to access terminal *
271 ********************************************************************/
272bcmos_errno bal_group_cfg_indication_cb(bcmbal_obj *obj)
273{
274 bcmos_errno result = BCM_ERR_OK;
Kim Kempfafa1ab42017-11-13 09:31:47 -0800275 ASFVOLT_LOG(ASFVOLT_INFO, "Processing API ('%s)' IND callback status is (%s)",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530276 bcmbal_objtype_str(obj->obj_type),
277 bcmos_strerror(obj->status));
Kim Kempfafa1ab42017-11-13 09:31:47 -0800278
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530279 return result;
280}