blob: 5c05425506e4fba5176f9ade572877fb682105e3 [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 {
45 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to configure the group cfg(OLT): Group Id was not present \n");
46 return BAL_ERRNO__BAL_ERR_NOENT;
47 }
48
49 ASFVOLT_LOG(ASFVOLT_DEBUG, "Configuration of OLT(group cfg) starts\n");
50
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 {
57 ASFVOLT_CFG_PROP_SET(grp_cfg_obj, group, members_cmd,
58 tm_group_cfg->data->has_members_cmd,
59 tm_group_cfg->data->members_cmd);
60 }
61
62 if(tm_group_cfg->data->has_cookie)
63 {
64 ASFVOLT_CFG_PROP_SET(grp_cfg_obj, group, cookie,
65 tm_group_cfg->data->has_cookie,
66 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 {
76 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to configure the group cfg(OLT): Memory Exhausted\n");
77 return BAL_ERRNO__BAL_ERR_NOMEM;
78 }
79 memcpy((void *)valFlows.val, (const void *)balFlows->val,
80 (balFlows->n_val)*sizeof(bcmbal_flow_id));
81 ASFVOLT_CFG_PROP_SET(grp_cfg_obj, group, flows, BCMOS_TRUE, valFlows);
82
83 if(tm_group_cfg->data->has_owner)
84 {
85 ASFVOLT_CFG_PROP_SET(grp_cfg_obj, group, owner,
86 tm_group_cfg->data->has_owner,
87 tm_group_cfg->data->owner);
88 }
89
90 BalGroupMemberInfoList *balMembers =
91 (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;
96 valMembers.val =
97 (bcmbal_group_member_info *)malloc((valMembers.len)*sizeof(bcmbal_group_member_info));
98 if(!valMembers.val)
99 {
100 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to configure the group cfg(OLT): Memory Exhausted\n");
101 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 {
109 valMembers.val[grp_mem_idx].intf_id
110 = balMembers->val[grp_mem_idx]->intf_id;
111 }
112 if(balMembers->val[grp_mem_idx]->has_svc_port_id)
113 {
114 valMembers.val[grp_mem_idx].svc_port_id
115 = balMembers->val[grp_mem_idx]->svc_port_id;
116 }
117 if(balMembers->val[grp_mem_idx]->action->has_presence_mask)
118 {
119 valMembers.val[grp_mem_idx].action.presence_mask
120 = 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 }
168 ASFVOLT_CFG_PROP_SET(grp_cfg_obj, group, members, BCMOS_TRUE, valMembers);
169 }
170
171 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(grp_cfg_obj.hdr));
172
173 if(BCM_ERR_OK != err)
174 {
175 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to configure the group cfg(OLT)\n");
176 return err;
177 }
178
179 ASFVOLT_LOG(ASFVOLT_INFO, "\nSet Group configuration sent to OLT for Group Id(%d)\n",
180 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
190uint32_t bal_group_cfg_get(BalGroupKey *tm_group_cfg_key,
191 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 {
203 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to get the group cfg(OLT): Group Id was not present\n");
204 return BAL_ERRNO__BAL_ERR_NOENT;
205 }
206
207 ASFVOLT_LOG(ASFVOLT_DEBUG, "Get group cfg(for OLT) starts\n");
208
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 {
219 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to get the group Cfg(OLT)\n");
220 return err;
221 }
222
223 ASFVOLT_LOG(ASFVOLT_INFO, "\nGet Group cfg sent to OLT for Group Id(%d)\n",
224 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 {
245 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to clear the group cfg(OLT): Group Id was not present\n");
246 return BAL_ERRNO__BAL_ERR_NOENT;
247 }
248
249 ASFVOLT_LOG(ASFVOLT_DEBUG, "Clearing of OLT(group cfg) starts\n");
250
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 {
258 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to clear the group Cfg(OLT)\n");
259 return err;
260 }
261
262 ASFVOLT_LOG(ASFVOLT_INFO, "\nClear Group cfg clear sent to OLT for Group Id(%d) \n",
263 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;
275 ASFVOLT_LOG(ASFVOLT_INFO, "Processing API ('%s)\n' IND callback status is (%s)\n",
276 bcmbal_objtype_str(obj->obj_type),
277 bcmos_strerror(obj->status));
278
279 return result;
280}
281
282