1 /**
2  * @file sample.c
3  * @brief This is a small demo of the high-performance NetX Duo TCP/IP stack.
4  *        This program demonstrates link packet sending and receiving with a simulated Ethernet driver.
5  *
6  */
7 #include   "tx_api.h"
8 #include   "nx_api.h"
9 #include    "netxtestcontrol.h"
10 
11 extern void test_control_return(UINT);
12 
13 #if defined(NX_ENABLE_VLAN)
14 #include   "nx_link.h"
15 #include   "nx_shaper.h"
16 #define PORT_RATE 100
17 /* Define demo stack size.   */
18 #define                 PACKET_SIZE             1536
19 #define                 NX_PACKET_POOL_SIZE     ((PACKET_SIZE + sizeof(NX_PACKET)) * 30)
20 #define                 DEMO_STACK_SIZE         2048
21 #define                 HTTP_STACK_SIZE         2048
22 #define                 IPERF_STACK_SIZE        2048
23 #define                 VLAN_ID                 100
24 
25 /* Define the ThreadX and NetX object control blocks...  */
26 TX_THREAD               thread_0;
27 NX_PACKET_POOL          pool_0;
28 NX_IP                   ip_0;
29 
30 UCHAR                   *pointer;
31 UCHAR                   *http_stack;
32 UCHAR                   *iperf_stack;
33 #ifdef FEATURE_NX_IPV6
34 NXD_ADDRESS             ipv6_address;
35 #endif
36 UCHAR                   pool_area[NX_PACKET_POOL_SIZE];
37 
38 /* Define the counters used in the demo application...  */
39 ULONG                   error_counter;
40 NX_SHAPER               shaper;
41 
42 /* Define thread prototypes.  */
43 VOID    thread_0_entry(ULONG thread_input);
44 extern  VOID nx_iperf_entry(NX_PACKET_POOL *pool_ptr, NX_IP *ip_ptr, UCHAR* http_stack, ULONG http_stack_size, UCHAR *iperf_stack, ULONG iperf_stack_size);
45 extern void    test_control_return(UINT status);
46 
47 /***** Substitute your ethernet driver entry function here *********/
48 void _nx_ram_network_driver(struct NX_IP_DRIVER_STRUCT *driver_req);
49 
50 /* Define what the initial system looks like.  */
51 #ifdef CTEST
test_application_define(void * first_unused_memory)52 VOID test_application_define(void *first_unused_memory)
53 #else
54 void netx_shaper_cbs_test_application_define(void *first_unused_memory)
55 #endif
56 {
57 
58 UINT    status;
59 
60     /* Setup the working pointer.  */
61     pointer = (UCHAR *) first_unused_memory;
62 
63     /* Initialize the NetX system.  */
64     nx_system_initialize();
65 
66     /* Create a packet pool.  */
67     status = nx_packet_pool_create(&pool_0, "NetX Main Packet Pool",
68                                    PACKET_SIZE, pool_area, NX_PACKET_POOL_SIZE);
69 
70     /* Check for packet pool create errors.  */
71     if (status)
72         error_counter++;
73 
74     /* Create an IP instance.  */
75     status = nx_ip_create(&ip_0, "NetX IP Instance 0", IP_ADDRESS(192, 168, 0, 15), 0xFFFFFF00UL, &pool_0, _nx_ram_network_driver,
76                           pointer, DEMO_STACK_SIZE, 1);
77     pointer =  pointer + DEMO_STACK_SIZE;
78 
79     /* Check for IP create errors.  */
80     if (status)
81         error_counter++;
82 
83     /* Attach second interface.  */
84     status = nx_ip_interface_attach(&ip_0, "NetX IP Interface 0:2",
85                                     IP_ADDRESS(192, 168, 100, 15), 0xFFFFFFFFUL, _nx_ram_network_driver);
86 
87     if (status)
88     {
89         error_counter++;
90     }
91 
92     /* Enable ARP and supply ARP cache memory for IP Instance 0.  */
93     status =  nx_arp_enable(&ip_0, (void *) pointer, 1024);
94     pointer = pointer + 1024;
95 
96     /* Check for ARP enable errors.  */
97     if (status)
98         error_counter++;
99 
100     /* Enable ICMP */
101     status = nx_icmp_enable(&ip_0);
102 
103     /* Check for ICMP enable errors.  */
104     if(status)
105         error_counter++;
106 
107     /* Enable UDP traffic.  */
108     status =  nx_udp_enable(&ip_0);
109 
110     /* Check for UDP enable errors.  */
111     if (status)
112         error_counter++;
113 
114     /* Enable TCP traffic.  */
115     status =  nx_tcp_enable(&ip_0);
116 
117     /* Check for TCP enable errors.  */
118     if (status)
119         error_counter++;
120 
121     /* Create the main thread.  */
122     tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
123                      pointer, DEMO_STACK_SIZE,
124                      4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
125     pointer =  pointer + DEMO_STACK_SIZE;
126 
127 #ifdef FEATURE_NX_IPV6
128     /* Set up the IPv6 address here. */
129     ipv6_address.nxd_ip_address.v6[3] = 0x3;
130     ipv6_address.nxd_ip_address.v6[2] = 0x0;
131     ipv6_address.nxd_ip_address.v6[1] = 0x0;
132     ipv6_address.nxd_ip_address.v6[0] = 0xfe800000;
133     ipv6_address.nxd_ip_version = NX_IP_VERSION_V6;
134 
135     /* Enable ICMPv6 services. */
136     status = nxd_icmp_enable(&ip_0);
137     if (status)
138         error_counter++;
139 
140     /* Enable IPv6 services. */
141     status = nxd_ipv6_enable(&ip_0);
142     if (status)
143         error_counter++;
144 
145     status = nxd_ipv6_address_set(&ip_0, 0, &ipv6_address, 10, NX_NULL);
146     if (status)
147         error_counter++;
148 #endif
149 
150     status = nx_link_vlan_set(&ip_0, 1, VLAN_ID);
151     if (status)
152         error_counter++;
153 
154 }
155 
demo_cbs_set(void * cbs_param,UCHAR shaper_type)156 UINT demo_cbs_set(void* cbs_param, UCHAR shaper_type)
157 {
158     return NX_SUCCESS;
159 }
160 
nx_cbs_driver(struct NX_SHAPER_DRIVER_PARAMETER_STRUCT * parameter)161 UINT nx_cbs_driver(struct NX_SHAPER_DRIVER_PARAMETER_STRUCT *parameter)
162 {
163     switch (parameter -> nx_shaper_driver_command)
164     {
165         case NX_SHAPER_COMMAND_INIT:
166             break;
167 
168         case NX_SHAPER_COMMAND_CONFIG:
169             break;
170 
171         case NX_SHAPER_COMMAND_PARAMETER_SET:
172             break;
173 
174         default:
175             break;
176     }
177 
178     return (NX_SUCCESS);
179 }
180 
181 /* Define the test threads.  */
thread_0_entry(ULONG thread_input)182 void    thread_0_entry(ULONG thread_input)
183 {
184 UINT status;
185 ULONG actual_status;
186 ULONG interface_index;
187 NX_INTERFACE *interface_ptr;
188 NX_SHAPER_CBS_PARAMETER cbs_param;
189 USHORT pcp;
190 UCHAR i;
191 UCHAR pcp_list[8];
192 UCHAR queue_id_list[8];
193 UCHAR hw_queue_number, hw_cbs_queue_number;
194 UINT port_rate;
195 
196 NX_SHAPER_CONTAINER shaper_container;
197 NX_SHAPER cbs_shaper;
198 NX_SHAPER_CBS_PARAMETER cbs_config;
199 UCHAR shaper_capability;
200 NX_SHAPER_HW_QUEUE hw_queue[8];
201 UINT index;
202 
203     NX_PARAMETER_NOT_USED(thread_input);
204 
205     /* Ensure the IP instance has been initialized.  */
206     nx_ip_status_check(&ip_0, NX_IP_INITIALIZE_DONE, &actual_status, NX_WAIT_FOREVER);
207 
208     /* Set the HTTP stack and IPerf stack.  */
209     http_stack = pointer;
210     pointer += HTTP_STACK_SIZE;
211     iperf_stack = pointer;
212     pointer += IPERF_STACK_SIZE;
213 
214     /* Call entry function to start iperf test.  */
215     nx_iperf_entry(&pool_0, &ip_0, http_stack, HTTP_STACK_SIZE, iperf_stack, IPERF_STACK_SIZE);
216 
217     interface_index = 0;
218     interface_ptr = &(ip_0.nx_ip_interface[interface_index]);
219 
220     memset(&shaper_container , 0, sizeof(NX_SHAPER_CONTAINER));
221     /* Case 1: init shaper with 3 hw queue, 2 cbs hw queue */
222     status = nx_shaper_create(interface_ptr, &shaper_container, &cbs_shaper, NX_SHAPER_TYPE_CBS, nx_cbs_driver);
223     if (status != NX_SUCCESS)
224     {
225 
226         error_counter++;
227         return;
228     }
229 
230     shaper_capability = NX_SHAPER_CAPABILITY_CBS_SUPPORTED | \
231                         NX_SHAPER_CAPABILITY_TAS_SUPPORTED | \
232                         NX_SHAPER_CAPABILITY_PREEMPTION_SUPPORTED;
233 
234     index = 0;
235     hw_queue[index].hw_queue_id = 0;
236     hw_queue[index].priority = 1;
237     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
238 
239     hw_queue[index].hw_queue_id = 1;
240     hw_queue[index].priority = 2;
241     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_CBS;
242 
243     hw_queue[index].hw_queue_id = 2;
244     hw_queue[index].priority = 3;
245     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_CBS;
246 
247     status = nx_shaper_config(interface_ptr, PORT_RATE, shaper_capability, 3, hw_queue);
248     if (status != NX_SUCCESS)
249     {
250 
251         error_counter++;
252         return;
253     }
254 
255     status = nx_shaper_default_mapping_get(interface_ptr, pcp_list, queue_id_list, 8);
256     if (status != NX_SUCCESS)
257     {
258 
259         error_counter++;
260         return;
261     }
262 
263     /* Case 2: init shaper with 4 hw queue, 2 cbs hw queue */
264     memset(interface_ptr -> shaper_container -> hw_queue, 0, sizeof(interface_ptr -> shaper_container -> hw_queue));
265     index = 0;
266     hw_queue[index].hw_queue_id = 0;
267     hw_queue[index].priority = 1;
268     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
269 
270     hw_queue[index].hw_queue_id = 3;
271     hw_queue[index].priority = 4;
272     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_CBS;
273 
274     hw_queue[index].hw_queue_id = 2;
275     hw_queue[index].priority = 3;
276     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_CBS;
277 
278     hw_queue[index].hw_queue_id = 1;
279     hw_queue[index].priority = 2;
280     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
281 
282     status = nx_shaper_config(interface_ptr, PORT_RATE, shaper_capability, 4, hw_queue);
283     if (status != NX_SUCCESS)
284     {
285 
286         error_counter++;
287         return;
288     }
289 
290     status = nx_shaper_default_mapping_get(interface_ptr, pcp_list, queue_id_list, 8);
291     if (status != NX_SUCCESS)
292     {
293 
294         error_counter++;
295         return;
296     }
297 
298     /* Case 3: init shaper with 5 hw queue, 2 cbs hw queue */
299     memset(interface_ptr -> shaper_container -> hw_queue, 0, sizeof(interface_ptr -> shaper_container -> hw_queue));
300     index = 0;
301     hw_queue[index].hw_queue_id = 0;
302     hw_queue[index].priority = 1;
303     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
304 
305     hw_queue[index].hw_queue_id = 4;
306     hw_queue[index].priority = 5;
307     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_CBS;
308 
309     hw_queue[index].hw_queue_id = 3;
310     hw_queue[index].priority = 4;
311     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_CBS;
312 
313     hw_queue[index].hw_queue_id = 2;
314     hw_queue[index].priority = 3;
315     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
316 
317     hw_queue[index].hw_queue_id = 1;
318     hw_queue[index].priority = 2;
319     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
320 
321     status = nx_shaper_config(interface_ptr, PORT_RATE, shaper_capability, 5, hw_queue);
322     if (status != NX_SUCCESS)
323     {
324 
325         error_counter++;
326         return;
327     }
328 
329     status = nx_shaper_default_mapping_get(interface_ptr, pcp_list, queue_id_list, 8);
330     if (status != NX_SUCCESS)
331     {
332 
333         error_counter++;
334         return;
335     }
336 
337     /* Case 4: init shaper with 6 hw queue, 2 cbs hw queue */
338     memset(interface_ptr -> shaper_container -> hw_queue, 0, sizeof(interface_ptr -> shaper_container -> hw_queue));
339     index = 0;
340     hw_queue[index].hw_queue_id = 0;
341     hw_queue[index].priority = 1;
342     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
343 
344     hw_queue[index].hw_queue_id = 4;
345     hw_queue[index].priority = 5;
346     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_CBS;
347 
348     hw_queue[index].hw_queue_id = 5;
349     hw_queue[index].priority = 6;
350     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_CBS;
351 
352     hw_queue[index].hw_queue_id = 3;
353     hw_queue[index].priority = 4;
354     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
355 
356     hw_queue[index].hw_queue_id = 2;
357     hw_queue[index].priority = 3;
358     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
359 
360     hw_queue[index].hw_queue_id = 1;
361     hw_queue[index].priority = 2;
362     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
363 
364     status = nx_shaper_config(interface_ptr, PORT_RATE, shaper_capability, 6, hw_queue);
365     if (status != NX_SUCCESS)
366     {
367 
368         error_counter++;
369         return;
370     }
371 
372     status = nx_shaper_default_mapping_get(interface_ptr, pcp_list, queue_id_list, 8);
373     if (status != NX_SUCCESS)
374     {
375 
376         error_counter++;
377         return;
378     }
379 
380     /* Case 5: init shaper with 7 hw queue, 2 cbs hw queue */
381     memset(interface_ptr -> shaper_container -> hw_queue, 0, sizeof(interface_ptr -> shaper_container -> hw_queue));
382     index = 0;
383     hw_queue[index].hw_queue_id = 0;
384     hw_queue[index].priority = 1;
385     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
386 
387     hw_queue[index].hw_queue_id = 4;
388     hw_queue[index].priority = 5;
389     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
390 
391     hw_queue[index].hw_queue_id = 5;
392     hw_queue[index].priority = 6;
393     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_CBS;
394 
395     hw_queue[index].hw_queue_id = 6;
396     hw_queue[index].priority = 7;
397     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_CBS;
398 
399     hw_queue[index].hw_queue_id = 3;
400     hw_queue[index].priority = 4;
401     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
402 
403     hw_queue[index].hw_queue_id = 2;
404     hw_queue[index].priority = 3;
405     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
406 
407     hw_queue[index].hw_queue_id = 1;
408     hw_queue[index].priority = 2;
409     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
410 
411     status = nx_shaper_config(interface_ptr, PORT_RATE, shaper_capability, 7, hw_queue);
412     if (status != NX_SUCCESS)
413     {
414 
415         error_counter++;
416         return;
417     }
418 
419     status = nx_shaper_default_mapping_get(interface_ptr, pcp_list, queue_id_list, 8);
420     if (status != NX_SUCCESS)
421     {
422 
423         error_counter++;
424         return;
425     }
426 
427     /* Case 6: init shaper with 8 hw queue, 2 cbs hw queue */
428     memset(interface_ptr -> shaper_container -> hw_queue, 0, sizeof(interface_ptr -> shaper_container -> hw_queue));
429     index = 0;
430     hw_queue[index].hw_queue_id = 0;
431     hw_queue[index].priority = 1;
432     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
433 
434     hw_queue[index].hw_queue_id = 4;
435     hw_queue[index].priority = 5;
436     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
437 
438     hw_queue[index].hw_queue_id = 5;
439     hw_queue[index].priority = 6;
440     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
441 
442     hw_queue[index].hw_queue_id = 6;
443     hw_queue[index].priority = 7;
444     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_CBS;
445 
446     hw_queue[index].hw_queue_id = 7;
447     hw_queue[index].priority = 8;
448     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_CBS;
449 
450     hw_queue[index].hw_queue_id = 3;
451     hw_queue[index].priority = 4;
452     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
453 
454     hw_queue[index].hw_queue_id = 2;
455     hw_queue[index].priority = 3;
456     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
457 
458     hw_queue[index].hw_queue_id = 1;
459     hw_queue[index].priority = 2;
460     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
461 
462     status = nx_shaper_config(interface_ptr, PORT_RATE, shaper_capability, 8, hw_queue);
463     if (status != NX_SUCCESS)
464     {
465 
466         error_counter++;
467         return;
468     }
469 
470     status = nx_shaper_default_mapping_get(interface_ptr, pcp_list, queue_id_list, 8);
471     if (status != NX_SUCCESS)
472     {
473 
474         error_counter++;
475         return;
476     }
477 
478     /* Case 7: init shaper with 2 hw queue, 1 cbs hw queue */
479     memset(interface_ptr -> shaper_container -> hw_queue, 0, sizeof(interface_ptr -> shaper_container -> hw_queue));
480     index = 0;
481 
482     hw_queue[index].hw_queue_id = 0;
483     hw_queue[index].priority = 1;
484     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
485 
486     hw_queue[index].hw_queue_id = 1;
487     hw_queue[index].priority = 2;
488     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_CBS;
489 
490     status = nx_shaper_config(interface_ptr, PORT_RATE, shaper_capability, index, hw_queue);
491     if (status != NX_SUCCESS)
492     {
493 
494         error_counter++;
495         return;
496     }
497 
498     /* Case 8: init shaper with 3 hw queue, 1 cbs hw queue */
499     memset(interface_ptr -> shaper_container -> hw_queue, 0, sizeof(interface_ptr -> shaper_container -> hw_queue));
500     index = 0;
501 
502     hw_queue[index].hw_queue_id = 0;
503     hw_queue[index].priority = 1;
504     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
505 
506     hw_queue[index].hw_queue_id = 1;
507     hw_queue[index].priority = 2;
508     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
509 
510     hw_queue[index].hw_queue_id = 2;
511     hw_queue[index].priority = 3;
512     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_CBS;
513 
514     status = nx_shaper_config(interface_ptr, PORT_RATE, shaper_capability, index, hw_queue);
515     if (status != NX_SUCCESS)
516     {
517 
518         error_counter++;
519         return;
520     }
521 
522 
523     /* Case 9: init shaper with 4 hw queue, 1 cbs hw queue */
524     memset(interface_ptr -> shaper_container -> hw_queue, 0, sizeof(interface_ptr -> shaper_container -> hw_queue));
525     index = 0;
526 
527     hw_queue[index].hw_queue_id = 0;
528     hw_queue[index].priority = 1;
529     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
530 
531     hw_queue[index].hw_queue_id = 1;
532     hw_queue[index].priority = 2;
533     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
534 
535     hw_queue[index].hw_queue_id = 2;
536     hw_queue[index].priority = 3;
537     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
538 
539     hw_queue[index].hw_queue_id = 3;
540     hw_queue[index].priority = 4;
541     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_CBS;
542 
543     status = nx_shaper_config(interface_ptr, PORT_RATE, shaper_capability, index, hw_queue);
544     if (status != NX_SUCCESS)
545     {
546 
547         error_counter++;
548         return;
549     }
550 
551     /* Case 10: init shaper with 5 hw queue, 1 cbs hw queue */
552     memset(interface_ptr -> shaper_container -> hw_queue, 0, sizeof(interface_ptr -> shaper_container -> hw_queue));
553     index = 0;
554 
555     hw_queue[index].hw_queue_id = 0;
556     hw_queue[index].priority = 1;
557     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
558 
559     hw_queue[index].hw_queue_id = 1;
560     hw_queue[index].priority = 2;
561     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
562 
563     hw_queue[index].hw_queue_id = 2;
564     hw_queue[index].priority = 3;
565     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
566 
567     hw_queue[index].hw_queue_id = 3;
568     hw_queue[index].priority = 4;
569     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
570 
571     hw_queue[index].hw_queue_id = 4;
572     hw_queue[index].priority = 5;
573     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_CBS;
574 
575     status = nx_shaper_config(interface_ptr, PORT_RATE, shaper_capability, index, hw_queue);
576     if (status != NX_SUCCESS)
577     {
578 
579         error_counter++;
580         return;
581     }
582 
583     /* Case 10.1: init shaper with 5 hw queue, 1 cbs hw queue */
584     memset(interface_ptr -> shaper_container -> hw_queue, 0, sizeof(interface_ptr -> shaper_container -> hw_queue));
585     index = 0;
586 
587     hw_queue[index].hw_queue_id = 0;
588     hw_queue[index].priority = 1;
589     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
590 
591     hw_queue[index].hw_queue_id = 1;
592     hw_queue[index].priority = 2;
593     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
594 
595     hw_queue[index].hw_queue_id = 2;
596     hw_queue[index].priority = 3;
597     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
598 
599     hw_queue[index].hw_queue_id = 1;
600     hw_queue[index].priority = 4;
601     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
602 
603     hw_queue[index].hw_queue_id = 4;
604     hw_queue[index].priority = 5;
605     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_CBS;
606 
607     status = nx_shaper_config(interface_ptr, PORT_RATE, shaper_capability, index, hw_queue);
608     if (status != NX_INVALID_PARAMETERS)
609     {
610 
611         error_counter++;
612         return;
613     }
614 
615     /* Case 10.2: init shaper with 5 hw queue, 1 cbs hw queue */
616     memset(interface_ptr -> shaper_container -> hw_queue, 0, sizeof(interface_ptr -> shaper_container -> hw_queue));
617     index = 0;
618 
619     hw_queue[index].hw_queue_id = 0;
620     hw_queue[index].priority = 1;
621     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
622 
623     hw_queue[index].hw_queue_id = 1;
624     hw_queue[index].priority = 2;
625     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
626 
627     hw_queue[index].hw_queue_id = 2;
628     hw_queue[index].priority = 3;
629     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
630 
631     hw_queue[index].hw_queue_id = 3;
632     hw_queue[index].priority = 4;
633     hw_queue[index].type = NX_SHAPER_HW_QUEUE_NORMAL;
634 
635     hw_queue[index].hw_queue_id = 3;
636     hw_queue[index].priority = 4;
637     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
638 
639     hw_queue[index].hw_queue_id = 4;
640     hw_queue[index].priority = 5;
641     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_CBS;
642 
643     status = nx_shaper_config(interface_ptr, PORT_RATE, shaper_capability, index, hw_queue);
644     if (status != NX_SUCCESS)
645     {
646 
647         error_counter++;
648         return;
649     }
650 
651     /* Case 11: init shaper with 6 hw queue, 1 cbs hw queue */
652     memset(interface_ptr -> shaper_container -> hw_queue, 0, sizeof(interface_ptr -> shaper_container -> hw_queue));
653     index = 0;
654 
655     hw_queue[index].hw_queue_id = 0;
656     hw_queue[index].priority = 1;
657     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
658 
659     hw_queue[index].hw_queue_id = 1;
660     hw_queue[index].priority = 2;
661     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
662 
663     hw_queue[index].hw_queue_id = 2;
664     hw_queue[index].priority = 3;
665     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
666 
667     hw_queue[index].hw_queue_id = 3;
668     hw_queue[index].priority = 4;
669     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
670 
671     hw_queue[index].hw_queue_id = 4;
672     hw_queue[index].priority = 5;
673     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
674 
675     hw_queue[index].hw_queue_id = 5;
676     hw_queue[index].priority = 6;
677     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_CBS;
678     status = nx_shaper_config(interface_ptr, PORT_RATE, shaper_capability, index, hw_queue);
679     if (status != NX_SUCCESS)
680     {
681 
682         error_counter++;
683         return;
684     }
685 
686     /* Case 12: init shaper with 7 hw queue, 1 cbs hw queue */
687     memset(interface_ptr -> shaper_container -> hw_queue, 0, sizeof(interface_ptr -> shaper_container -> hw_queue));
688     index = 0;
689 
690     hw_queue[index].hw_queue_id = 0;
691     hw_queue[index].priority = 1;
692     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
693 
694     hw_queue[index].hw_queue_id = 1;
695     hw_queue[index].priority = 2;
696     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
697 
698     hw_queue[index].hw_queue_id = 2;
699     hw_queue[index].priority = 3;
700     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
701 
702     hw_queue[index].hw_queue_id = 3;
703     hw_queue[index].priority = 4;
704     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
705 
706     hw_queue[index].hw_queue_id = 4;
707     hw_queue[index].priority = 5;
708     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
709 
710     hw_queue[index].hw_queue_id = 5;
711     hw_queue[index].priority = 6;
712     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
713 
714     hw_queue[index].hw_queue_id = 6;
715     hw_queue[index].priority = 7;
716     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_CBS;
717     status = nx_shaper_config(interface_ptr, PORT_RATE, shaper_capability, index, hw_queue);
718     if (status != NX_SUCCESS)
719     {
720 
721         error_counter++;
722         return;
723     }
724 
725     /* Case 13 init shaper with 8 hw queue, 1 cbs hw queue */
726     memset(interface_ptr -> shaper_container -> hw_queue, 0, sizeof(interface_ptr -> shaper_container -> hw_queue));
727     index = 0;
728 
729     hw_queue[index].hw_queue_id = 0;
730     hw_queue[index].priority = 1;
731     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
732 
733     hw_queue[index].hw_queue_id = 1;
734     hw_queue[index].priority = 2;
735     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
736 
737     hw_queue[index].hw_queue_id = 2;
738     hw_queue[index].priority = 3;
739     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
740 
741     hw_queue[index].hw_queue_id = 3;
742     hw_queue[index].priority = 4;
743     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
744 
745     hw_queue[index].hw_queue_id = 4;
746     hw_queue[index].priority = 5;
747     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
748 
749     hw_queue[index].hw_queue_id = 5;
750     hw_queue[index].priority = 6;
751     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
752 
753     hw_queue[index].hw_queue_id = 6;
754     hw_queue[index].priority = 7;
755     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_NORMAL;
756 
757     hw_queue[index].hw_queue_id = 7;
758     hw_queue[index].priority = 8;
759     hw_queue[index++].type = NX_SHAPER_HW_QUEUE_CBS;
760     status = nx_shaper_config(interface_ptr, PORT_RATE, shaper_capability, index, hw_queue);
761     if (status != NX_SUCCESS)
762     {
763 
764         error_counter++;
765         return;
766     }
767 
768     /* Case 14: set default mapping */
769     memset(pcp_list, 0, sizeof(pcp_list));
770     memset(queue_id_list, 0, sizeof(queue_id_list));
771     status = nx_shaper_default_mapping_get(interface_ptr, pcp_list, queue_id_list, 8);
772     if (status != NX_SUCCESS)
773     {
774 
775         error_counter++;
776         return;
777     }
778 
779     status = nx_shaper_mapping_set(interface_ptr, pcp_list, queue_id_list, 8);
780     if (status != NX_SUCCESS)
781     {
782 
783         error_counter++;
784         return;
785     }
786 
787     /* Case 15: get current mapping */
788     memset(pcp_list, 0, sizeof(pcp_list));
789     memset(queue_id_list, 0, sizeof(queue_id_list));
790     status = nx_shaper_current_mapping_get(interface_ptr, pcp_list, queue_id_list, 8);
791     if (status != NX_SUCCESS)
792     {
793 
794         error_counter++;
795         return;
796     }
797 
798     /* Case 17: set the cbs parameters */
799     status = nx_shaper_port_rate_get(interface_ptr, &port_rate);
800     cbs_param.idle_slope = 30; // 30Mbps, 30 percent bandwidth reserve for cbs queue
801     cbs_param.send_slope = 30 - port_rate;
802     cbs_param.hi_credit = 463;
803     cbs_param.low_credit = -1079;
804     status = nx_shaper_cbs_parameter_set(interface_ptr, &cbs_param, NX_SHAPER_CLASS_B_PCP);
805     /* Check status...  */
806     if (status != NX_SUCCESS)
807     {
808 
809         error_counter++;
810         return;
811     }
812 
813     /*Check the status. */
814     if (error_counter == 0)
815     {
816         printf("SUCCESS!\n");
817         test_control_return(0);
818     }
819     else
820     {
821         printf("ERROR!\n");
822         test_control_return(1);
823     }
824 }
825 
826 #else
827 
828 #ifdef CTEST
test_application_define(void * first_unused_memory)829 VOID test_application_define(void *first_unused_memory)
830 #else
831 void netx_shaper_cbs_test_application_define(void *first_unused_memory)
832 #endif
833 {
834 
835     /* Print out test information banner.  */
836     printf("NetX Test:   Shaper CBS Test.......................................N/A\n");
837     test_control_return(3);
838 }
839 
840 #endif