Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 32 | uint32_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 Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 45 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to configure the group cfg(OLT): Group Id was not present"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 46 | return BAL_ERRNO__BAL_ERR_NOENT; |
| 47 | } |
| 48 | |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 49 | ASFVOLT_LOG(ASFVOLT_DEBUG, "Configuration of OLT(group cfg) starts"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 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 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 57 | ASFVOLT_CFG_PROP_SET(grp_cfg_obj, group, members_cmd, |
| 58 | tm_group_cfg->data->has_members_cmd, |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 59 | tm_group_cfg->data->members_cmd); |
| 60 | } |
| 61 | |
| 62 | if(tm_group_cfg->data->has_cookie) |
| 63 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 64 | ASFVOLT_CFG_PROP_SET(grp_cfg_obj, group, cookie, |
| 65 | tm_group_cfg->data->has_cookie, |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 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 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 76 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to configure the group cfg(OLT): Memory Exhausted"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 77 | return BAL_ERRNO__BAL_ERR_NOMEM; |
| 78 | } |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 79 | memcpy((void *)valFlows.val, (const void *)balFlows->val, |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 80 | (balFlows->n_val)*sizeof(bcmbal_flow_id)); |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 81 | ASFVOLT_CFG_PROP_SET(grp_cfg_obj, group, flows, BCMOS_TRUE, valFlows); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 82 | |
Girish Gowdru | 9ebd8b2 | 2018-09-26 03:21:03 -0700 | [diff] [blame^] | 83 | if(tm_group_cfg->data->has_type) |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 84 | { |
Girish Gowdru | 9ebd8b2 | 2018-09-26 03:21:03 -0700 | [diff] [blame^] | 85 | ASFVOLT_CFG_PROP_SET(grp_cfg_obj, group, type, |
| 86 | tm_group_cfg->data->has_type, |
| 87 | tm_group_cfg->data->type); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 88 | } |
| 89 | |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 90 | BalGroupMemberInfoList *balMembers = |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 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; |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 96 | valMembers.val = |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 97 | (bcmbal_group_member_info *)malloc((valMembers.len)*sizeof(bcmbal_group_member_info)); |
| 98 | if(!valMembers.val) |
| 99 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 100 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to configure the group cfg(OLT): Memory Exhausted"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 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 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 109 | valMembers.val[grp_mem_idx].intf_id |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 110 | = balMembers->val[grp_mem_idx]->intf_id; |
| 111 | } |
| 112 | if(balMembers->val[grp_mem_idx]->has_svc_port_id) |
| 113 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 114 | valMembers.val[grp_mem_idx].svc_port_id |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 115 | = balMembers->val[grp_mem_idx]->svc_port_id; |
| 116 | } |
Girish Gowdru | 9ebd8b2 | 2018-09-26 03:21:03 -0700 | [diff] [blame^] | 117 | if(balMembers->val[grp_mem_idx]->has_intf_type) |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 118 | { |
Girish Gowdru | 9ebd8b2 | 2018-09-26 03:21:03 -0700 | [diff] [blame^] | 119 | valMembers.val[grp_mem_idx].intf_type |
| 120 | = balMembers->val[grp_mem_idx]->intf_type; |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 121 | } |
| 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 Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 133 | ASFVOLT_CFG_PROP_SET(grp_cfg_obj, group, members, BCMOS_TRUE, valMembers); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(grp_cfg_obj.hdr)); |
| 137 | |
| 138 | if(BCM_ERR_OK != err) |
| 139 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 140 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to configure the group cfg(OLT)"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 141 | return err; |
| 142 | } |
| 143 | |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 144 | ASFVOLT_LOG(ASFVOLT_INFO, "Set Group configuration sent to OLT for Group Id(%d)", |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 145 | key.group_id); |
| 146 | return err; |
| 147 | } |
| 148 | |
| 149 | |
| 150 | /********************************************************************\ |
Girish Gowdru | 9ebd8b2 | 2018-09-26 03:21:03 -0700 | [diff] [blame^] | 151 | * Function : bal_group_cfg_get * |
| 152 | * Description : get the OLT device group cfg * |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 153 | ********************************************************************/ |
| 154 | |
Girish Gowdru | 9ebd8b2 | 2018-09-26 03:21:03 -0700 | [diff] [blame^] | 155 | uint32_t bal_group_cfg_get(BalGroupCfg *group_cfg) |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 156 | { |
| 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 Gowdru | 9ebd8b2 | 2018-09-26 03:21:03 -0700 | [diff] [blame^] | 161 | if(group_cfg->key->has_group_id) |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 162 | { |
Girish Gowdru | 9ebd8b2 | 2018-09-26 03:21:03 -0700 | [diff] [blame^] | 163 | key.group_id = group_cfg->key->group_id; |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 164 | } |
| 165 | else |
| 166 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 167 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to get the group cfg(OLT): Group Id was not present"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 168 | return BAL_ERRNO__BAL_ERR_NOENT; |
| 169 | } |
| 170 | |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 171 | ASFVOLT_LOG(ASFVOLT_DEBUG, "Get group cfg(for OLT) starts"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 172 | |
| 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 Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 183 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to get the group Cfg(OLT)"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 184 | return err; |
| 185 | } |
| 186 | |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 187 | ASFVOLT_LOG(ASFVOLT_INFO, "Get Group cfg sent to OLT for Group Id(%d)", |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 188 | key.group_id); |
Girish Gowdru | 9ebd8b2 | 2018-09-26 03:21:03 -0700 | [diff] [blame^] | 189 | |
| 190 | memcpy(group_cfg->key, &key, sizeof(BalFlowKey)); |
| 191 | memcpy(group_cfg->data, &grp_cfg_obj, sizeof(BalFlowCfgData)); |
| 192 | |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 193 | return err; |
| 194 | } |
| 195 | |
| 196 | /********************************************************************\ |
| 197 | * Function : bal_group_clear_req * |
| 198 | * Description : clears the OLT device group cfg * |
| 199 | ********************************************************************/ |
| 200 | |
| 201 | uint32_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 Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 213 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to clear the group cfg(OLT): Group Id was not present"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 214 | return BAL_ERRNO__BAL_ERR_NOENT; |
| 215 | } |
| 216 | |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 217 | ASFVOLT_LOG(ASFVOLT_DEBUG, "Clearing of OLT(group cfg) starts"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 218 | |
| 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 Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 226 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to clear the group Cfg(OLT)"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 227 | return err; |
| 228 | } |
| 229 | |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 230 | ASFVOLT_LOG(ASFVOLT_INFO, "Clear Group cfg clear sent to OLT for Group Id(%d)", |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 231 | 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 | ********************************************************************/ |
| 240 | bcmos_errno bal_group_cfg_indication_cb(bcmbal_obj *obj) |
| 241 | { |
| 242 | bcmos_errno result = BCM_ERR_OK; |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 243 | ASFVOLT_LOG(ASFVOLT_INFO, "Processing API ('%s)' IND callback status is (%s)", |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 244 | bcmbal_objtype_str(obj->obj_type), |
| 245 | bcmos_strerror(obj->status)); |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame] | 246 | |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 247 | return result; |
| 248 | } |