blob: 75f26ce582510007b3a23d5985457a12ab3bce1f [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_tmqueue_hdlr.h"
25
26
27/********************************************************************\
28 * Function : bal_tm_queue_cfg_set *
29 * Description : Configures the tm queue for OLT device *
30 ********************************************************************/
31
32uint32_t bal_tm_queue_cfg_set(BalTmQueueCfg *tm_queue_cfg)
33{
34 bcmos_errno err = BCM_ERR_OK;
35 bcmbal_tm_queue_cfg tm_queue_obj; /**< declare main API struct */
36 bcmbal_tm_queue_key key = { }; /**< declare key */
37
38 if((tm_queue_cfg->key->has_id) && (tm_queue_cfg->key->has_sched_id) && (tm_queue_cfg->key->has_sched_dir))
39 {
40 key.id = tm_queue_cfg->key->id;
41 key.sched_id = tm_queue_cfg->key->sched_id;
42 key.sched_dir = tm_queue_cfg->key->sched_dir;
43 }
44 else
45 {
46 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to configure the tm queue cfg(OLT): Missing Key values\
47 Recevied key values Id(%d), Sched-Dir(%d), Sched-Id(%d) \n",
48 tm_queue_cfg->key->sched_id, tm_queue_cfg->key->sched_dir, tm_queue_cfg->key->id);
49 return BAL_ERRNO__BAL_ERR_NOENT;
50 }
51
52 ASFVOLT_LOG(ASFVOLT_DEBUG, "Configuration of OLT(tm Queue) starts\n");
53
54 /* init the API struct */
55 BCMBAL_CFG_INIT(&tm_queue_obj, tm_queue, key);
56
57 /* decode API parameters from GRPC */
58 ASFVOLT_CFG_PROP_SET(tm_queue_obj, tm_queue, priority,
59 tm_queue_cfg->data->has_priority,
60 tm_queue_cfg->data->priority);
61 ASFVOLT_CFG_PROP_SET(tm_queue_obj, tm_queue, weight,
62 tm_queue_cfg->data->has_weight,
63 tm_queue_cfg->data->weight);
64 ASFVOLT_CFG_PROP_SET(tm_queue_obj, tm_queue, creation_mode,
65 tm_queue_cfg->data->has_creation_mode,
66 tm_queue_cfg->data->creation_mode);
67 ASFVOLT_CFG_PROP_SET(tm_queue_obj, tm_queue, ref_count,
68 tm_queue_cfg->data->has_ref_count,
69 tm_queue_cfg->data->ref_count);
70
71 /* rating/shaping */
72 BalTmShaping *balShaping = (BalTmShaping *)tm_queue_cfg->data->rate;
73 bcmbal_tm_shaping val = {};
74 if (balShaping->has_presence_mask)
75 {
76 val.presence_mask = balShaping->presence_mask;
77 if (balShaping->has_cir)
78 {
79 val.cir = balShaping->cir;
80 }
81 if (balShaping->has_pir)
82 {
83 val.pir = balShaping->pir;
84 }
85 if (balShaping->has_burst)
86 {
87 val.burst = balShaping->burst;
88 }
89 ASFVOLT_CFG_PROP_SET(tm_queue_obj, tm_queue, rate, BCMOS_TRUE, val);
90 }
91
92 /* bac - Buffer addmission Control */
93 BalTmBac *balBac = (BalTmBac *)tm_queue_cfg->data->bac;
94 bcmbal_tm_bac valBac = {};
95 if(balBac->has_type)
96 {
97 valBac.type = balBac->type;
98 switch(valBac.type)
99 {
100 case BAL_TM_BAC__U_TAILDROP:
101 if(balBac->taildrop->has_max_size)
102 {
103 valBac.u.taildrop.max_size = balBac->taildrop->max_size;
104 }
105 break;
106 case BAL_TM_BAC__U_RED:
107 if(balBac->red->red->has_min_threshold)
108 {
109 valBac.u.red.red.min_threshold = balBac->red->red->min_threshold;
110 }
111 if(balBac->red->red->has_max_threshold)
112 {
113 valBac.u.red.red.max_threshold = balBac->red->red->max_threshold;
114 }
115 if(balBac->red->red->has_max_probability)
116 {
117 valBac.u.red.red.max_probability = balBac->red->red->max_probability;
118 }
119 break;
120 case BAL_TM_BAC__U_WRED:
121 if(balBac->wred->red->has_min_threshold)
122 {
123 valBac.u.wred.red.min_threshold = balBac->wred->red->min_threshold;
124 }
125 if(balBac->wred->red->has_max_threshold)
126 {
127 valBac.u.wred.red.max_threshold = balBac->wred->red->max_threshold;
128 }
129 if(balBac->wred->red->has_max_probability)
130 {
131 valBac.u.wred.red.max_probability= balBac->wred->red->max_probability;
132 }
133 if(balBac->wred->green->has_min_threshold)
134 {
135 valBac.u.wred.green.min_threshold = balBac->wred->green->min_threshold;
136 }
137 if(balBac->wred->green->has_max_threshold)
138 {
139 valBac.u.wred.green.max_threshold = balBac->wred->green->max_threshold;
140 }
141 if(balBac->wred->green->has_max_probability)
142 {
143 valBac.u.wred.green.max_probability= balBac->wred->green->max_probability;
144 }
145 if(balBac->wred->yellow->has_min_threshold)
146 {
147 valBac.u.wred.yellow.min_threshold = balBac->wred->yellow->min_threshold;
148 }
149 if(balBac->wred->yellow->has_max_threshold)
150 {
151 valBac.u.wred.yellow.max_threshold = balBac->wred->yellow->max_threshold;
152 }
153 if(balBac->wred->yellow->has_max_probability)
154 {
155 valBac.u.wred.yellow.max_probability= balBac->wred->yellow->max_probability;
156 }
157 break;
158 default:
159 break;
160 }
161 ASFVOLT_CFG_PROP_SET(tm_queue_obj, tm_queue, bac, BCMOS_TRUE, valBac);
162 }
163
164 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(tm_queue_obj.hdr));
165
166 if(BCM_ERR_OK != err)
167 {
168 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to configure the tm Queue Cfg(OLT)\n");
169 return err;
170 }
171
172 ASFVOLT_LOG(ASFVOLT_INFO, "\nSet tm Queue configuration sent to OLT. \
173 Queue ID(%d) Sched ID(%d) Sched Dir(%d)\n",
174 key.id, key.sched_id, key.sched_dir );
175 return err;
176}
177
178
179/********************************************************************\
180 * Function : bal_tm_queue_cfg_clear *
181 * Description : clear the OLT device tm queue configuration *
182 ********************************************************************/
183
184uint32_t bal_tm_queue_cfg_clear(BalTmQueueKey *tm_queue_key)
185{
186 bcmos_errno err = BCM_ERR_OK;
187 bcmbal_tm_queue_cfg tm_queue_obj; /**< declare main API struct */
188 bcmbal_tm_queue_key key = { }; /**< declare key */
189
190 if((tm_queue_key->has_id) && (tm_queue_key->has_sched_id) && (tm_queue_key->has_sched_dir))
191 {
192 key.id = tm_queue_key->id;
193 key.sched_id = tm_queue_key->sched_id;
194 key.sched_dir = tm_queue_key->sched_dir;
195 }
196 else
197 {
198 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to clear the tm queue cfg(OLT): Missing Key values\
199 Recevied key values Id(%d), Sched-Dir(%d), Sched-Id(%d) \n",
200 tm_queue_key->sched_id, tm_queue_key->sched_dir, tm_queue_key->id);
201 return BAL_ERRNO__BAL_ERR_NOENT;
202 }
203
204 ASFVOLT_LOG(ASFVOLT_DEBUG, "Clearing of OLT(tm Queue) starts\n");
205
206 /* init the API struct */
207 BCMBAL_CFG_INIT(&tm_queue_obj, tm_queue, key);
208
209 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &tm_queue_obj.hdr);
210
211 if(BCM_ERR_OK != err)
212 {
213 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to clear the tm Queue Cfg(OLT)\n");
214 return err;
215 }
216
217 ASFVOLT_LOG(ASFVOLT_INFO, "\nClear tm Queue sent to OLT. \
218 Queue ID(%d) Sched ID(%d) Sched Dir(%d)\n",
219 key.id, key.sched_id, key.sched_dir );
220 return err;
221}
222
223
224/********************************************************************\
225 * Function : bal_tm_queue_cfg_get *
226 * Description : Get the OLT device tm queue configuration *
227 ********************************************************************/
228
229uint32_t bal_tm_queue_cfg_get(BalTmQueueKey *tm_queue_key, BalTmQueueCfg *tm_queue_cfg)
230{
231 bcmos_errno err = BCM_ERR_OK;
232 bcmbal_tm_queue_cfg tm_queue_obj; /**< declare main API struct */
233 bcmbal_tm_queue_key key = { }; /**< declare key */
234
235 if((tm_queue_key->has_id) && (tm_queue_key->has_sched_id) && (tm_queue_key->has_sched_dir))
236 {
237 key.id = tm_queue_key->id;
238 key.sched_id = tm_queue_key->sched_id;
239 key.sched_dir = tm_queue_key->sched_dir;
240 }
241 else
242 {
243 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to get the tm queue cfg(OLT): Missing Key values\
244 Recevied key values Id(%d), Sched-Dir(%d), Sched-Id(%d) \n",
245 tm_queue_key->sched_id, tm_queue_key->sched_dir, tm_queue_key->id);
246 return BAL_ERRNO__BAL_ERR_NOENT;
247 }
248
249 ASFVOLT_LOG(ASFVOLT_DEBUG, "Get tm queue cfg(for OLT) starts\n");
250
251 /* init the API struct */
252 BCMBAL_CFG_INIT(&tm_queue_obj, tm_queue, key);
253
254 /* request all properties, include everything */
255 BCMBAL_CFG_PROP_GET(&tm_queue_obj, tm_queue, all_properties);
256
257 err = bcmbal_cfg_get(DEFAULT_ATERM_ID, &tm_queue_obj.hdr);
258
259 if(BCM_ERR_OK != err)
260 {
261 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to get the tm Queue Cfg(OLT)\n");
262 return err;
263 }
264
265 ASFVOLT_LOG(ASFVOLT_INFO, "\nGet tm Queue sent to OLT. \
266 Queue ID(%d) Sched ID(%d) Sched Dir(%d)\n",
267 key.id, key.sched_id, key.sched_dir );
268 return err;
269}
270
271
272/********************************************************************\
273 * Function : bal_tm_queue_indication_cb *
274 * Description : Call back function registered with BAL to handle *
275 * event related to access terminal *
276 ********************************************************************/
277bcmos_errno bal_tm_queue_cfg_indication_cb(bcmbal_obj *obj)
278{
279 bcmos_errno result = BCM_ERR_OK;
280 ASFVOLT_LOG(ASFVOLT_INFO, "Processing API \'%s\' IND callback (status is %s)\n",
281 bcmbal_objtype_str(obj->obj_type),
282 bcmos_strerror(obj->status));
283
284 return result;
285}
286
287