sched_profile.c (6519B)
1 /* Feature : Scheduler Profile 2 * 3 * Usage : BCM.0> cint sched_profile.c 4 * 5 * config : sched_profile_config.bcm 6 * 7 * Log file : scheduler_profile_log.txt 8 * 9 * Test Topology : None 10 * 11 * Summary: 12 * ======== 13 * This cint example demonstrate creating a scheduler profile and attach it to a port 14 * 15 * Detailed steps done in the CINT script: 16 * ======================================= 17 * 1) Step1 - Test Setup (Done in test_setup()) 18 * ============================================ 19 * a) Select one egress port on which new scheduler profile has to be applied 20 * 2) Step2 - Configuration (Done in port_sched_config()) 21 * ====================================================== 22 * a) Create scheduler profile with queue to COS mapping, scheduler mode for 23 * each COS and attach created scheduler profile to port. 24 * 3) Step3 - Verification (Done in verify()) 25 * ========================================== 26 * a) Verify the profile attachment to port using 'dump sw cosq' 27 * b) Expected Result: 28 * ================ 29 * In 'dump sw cosq' output 30 * - UCQ0-7 should be mapped to COS0-7 31 * - MCQ0-3 should be mapped to COS0-3 32 */ 33 34 cint_reset(); 35 36 bcm_port_t port; 37 bcm_cosq_mapping_t cosq_mapping_arr[12]; 38 int profile_id=1; 39 int unit=0; 40 int rv; 41 42 /* This function is written so that hardcoding of port 43 numbers in Cint scripts is removed. This function gives 44 required number of ports 45 */ 46 47 bcm_error_t portNumbersGet(int unit, int *port_list, int num_ports) 48 { 49 50 int i=0,port=0,rv=0; 51 bcm_port_config_t configP; 52 bcm_pbmp_t ports_pbmp; 53 54 rv = bcm_port_config_get(unit,&configP); 55 if(BCM_FAILURE(rv)) { 56 printf("\nError in retrieving port configuration: %s.\n",bcm_errmsg(rv)); 57 return rv; 58 } 59 60 ports_pbmp = configP.e; 61 for (i= 1; i < BCM_PBMP_PORT_MAX; i++) { 62 if (BCM_PBMP_MEMBER(&ports_pbmp,i)&& (port < num_ports)) { 63 port_list[port]=i; 64 port++; 65 } 66 } 67 68 if (( port == 0 ) || ( port != num_ports )) { 69 printf("portNumbersGet() failed \n"); 70 return -1; 71 } 72 73 return BCM_E_NONE; 74 75 } 76 77 bcm_error_t test_setup(int unit) 78 { 79 int port_list[1], i; 80 if (BCM_E_NONE != portNumbersGet(unit, port_list, 1)) { 81 printf("portNumbersGet() failed\n"); 82 return -1; 83 } 84 85 port = port_list[0]; 86 return BCM_E_NONE; 87 } 88 89 90 bcm_error_t sched_profile_setup(int unit, int profile_id) 91 { 92 93 /* Configure Scheduler profile */ 94 cosq_mapping_arr[0].cosq=0; 95 cosq_mapping_arr[0].num_ucq=1; 96 cosq_mapping_arr[0].num_mcq=1; 97 cosq_mapping_arr[0].strict_priority=0; 98 cosq_mapping_arr[0].fc_is_uc_only=0; 99 cosq_mapping_arr[1].cosq=1; 100 cosq_mapping_arr[1].num_ucq=1; 101 cosq_mapping_arr[1].num_mcq=1; 102 cosq_mapping_arr[1].strict_priority=0; 103 cosq_mapping_arr[1].fc_is_uc_only=0; 104 cosq_mapping_arr[2].cosq=2; 105 cosq_mapping_arr[2].num_ucq=1; 106 cosq_mapping_arr[2].num_mcq=1; 107 cosq_mapping_arr[2].strict_priority=0; 108 cosq_mapping_arr[2].fc_is_uc_only=0; 109 cosq_mapping_arr[3].cosq=3; 110 cosq_mapping_arr[3].num_ucq=1; 111 cosq_mapping_arr[3].num_mcq=1; 112 cosq_mapping_arr[3].strict_priority=0; 113 cosq_mapping_arr[3].fc_is_uc_only=0; 114 cosq_mapping_arr[4].cosq=4; 115 cosq_mapping_arr[4].num_ucq=1; 116 cosq_mapping_arr[4].num_mcq=0; 117 cosq_mapping_arr[4].strict_priority=0; 118 cosq_mapping_arr[4].fc_is_uc_only=0; 119 cosq_mapping_arr[5].cosq=5; 120 cosq_mapping_arr[5].num_ucq=1; 121 cosq_mapping_arr[5].num_mcq=0; 122 cosq_mapping_arr[5].strict_priority=0; 123 cosq_mapping_arr[5].fc_is_uc_only=0; 124 cosq_mapping_arr[6].cosq=6; 125 cosq_mapping_arr[6].num_ucq=1; 126 cosq_mapping_arr[6].num_mcq=0; 127 cosq_mapping_arr[6].strict_priority=0; 128 cosq_mapping_arr[6].fc_is_uc_only=0; 129 cosq_mapping_arr[7].cosq=7; 130 cosq_mapping_arr[7].num_ucq=1; 131 cosq_mapping_arr[7].num_mcq=0; 132 cosq_mapping_arr[7].strict_priority=0; 133 cosq_mapping_arr[7].fc_is_uc_only=0; 134 cosq_mapping_arr[8].cosq=8; 135 cosq_mapping_arr[8].num_ucq=0; 136 cosq_mapping_arr[8].num_mcq=0; 137 cosq_mapping_arr[8].strict_priority=0; 138 cosq_mapping_arr[8].fc_is_uc_only=0; 139 cosq_mapping_arr[9].cosq=9; 140 cosq_mapping_arr[9].num_ucq=0; 141 cosq_mapping_arr[9].num_mcq=0; 142 cosq_mapping_arr[9].strict_priority=0; 143 cosq_mapping_arr[9].fc_is_uc_only=0; 144 cosq_mapping_arr[10].cosq=10; 145 cosq_mapping_arr[10].num_ucq=0; 146 cosq_mapping_arr[10].num_mcq=0; 147 cosq_mapping_arr[10].strict_priority=0; 148 cosq_mapping_arr[10].fc_is_uc_only=0; 149 cosq_mapping_arr[11].cosq=11; 150 cosq_mapping_arr[11].num_ucq=0; 151 cosq_mapping_arr[11].num_mcq=0; 152 cosq_mapping_arr[11].strict_priority=0; 153 cosq_mapping_arr[11].fc_is_uc_only=0; 154 155 /* create scheduler profile */ 156 rv = bcm_cosq_schedq_mapping_set(unit, profile_id, 12, cosq_mapping_arr); 157 if (rv != BCM_E_NONE) { 158 printf ("sched_profile_setup failed() :%s\n", bcm_errmsg(rv)); 159 return rv; 160 } 161 return BCM_E_NONE; 162 } 163 164 /* Attach scheduler profile to port */ 165 bcm_error_t attach_sched_profile_to_port(int unit, int port, int profile_id) 166 { 167 /* Attach sched profile to specified port */ 168 rv=bcm_cosq_port_profile_set(unit, port, bcmCosqProfilePFCAndQueueHierarchy, profile_id); 169 if (rv != BCM_E_NONE) { 170 printf("attach_sched_profile_to_port failed() :%s.\n", bcm_errmsg(rv)); 171 return rv; 172 } 173 return BCM_E_NONE; 174 } 175 176 bcm_error_t port_sched_config(int unit, int port, int profile_id) 177 { 178 /* create scheduler profile */ 179 if (BCM_FAILURE((rv = sched_profile_setup(unit, profile_id)))) { 180 printf("Error in sched_profile_setup() : %s.\n", bcm_errmsg(rv)); 181 return rv; 182 } 183 184 /* attach created scheduler profile to port */ 185 if (BCM_FAILURE((rv = attach_sched_profile_to_port(unit, port, profile_id)))) { 186 printf("Error in attach_sched_profile_to_port() : %s.\n", bcm_errmsg(rv)); 187 return rv; 188 } 189 return BCM_E_NONE; 190 } 191 192 /* Function to verify the result */ 193 void verify(int unit) 194 { 195 /*check output for port on which new scheduler profile is attached */ 196 bshell(unit, "dump sw cosq"); 197 } 198 199 bcm_error_t execute() 200 { 201 bcm_error_t rv; 202 int unit = 0; 203 204 bshell(unit, "config show; a ; version"); 205 206 /* select port */ 207 if (BCM_FAILURE((rv = test_setup(unit)))) { 208 printf("test_setup() failed.\n"); 209 return -1; 210 } 211 212 /* configure scheduler profile and attach it to port*/ 213 if (BCM_FAILURE((rv = port_sched_config(unit, port, profile_id)))) { 214 printf("port_sched_config() failed.\n"); 215 return -1; 216 } 217 218 /* verify the result */ 219 verify(unit); 220 return BCM_E_NONE; 221 } 222 223 const char *auto_execute = (ARGC == 1) ? ARGV[0] : "YES"; 224 if (!sal_strcmp(auto_execute, "YES")) { 225 print execute(); 226 } 227