openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

bst.c (5637B)


      1 /*  Feature  : BST
      2  *
      3  *  Usage    : BCM.0> cint bst.c
      4  *
      5  *  config   : bst_config.bcm
      6  *
      7  *  Log file : bst_log.txt
      8  *
      9  *  Test Topology : Single TH3 device
     10  *
     11  *  Summary:
     12  *  ========
     13  *  This cint example illustrates configuration of Buffer Statistics Tracking (BST) mechanism
     14  *  to aid in resource monitoring and buffer allocation tuning.
     15  *
     16  *    Detailed steps done in the CINT script:
     17  *    =======================================
     18  *    1) Step1 - Test Setup (Done in test_setup())
     19  *    ============================================
     20  *      a) Select one egress port on which bst has to be enabled.
     21  *    2) Step2 - Configuration (Done in bst_config())
     22  *    ===============================================
     23  *      a) Enable device level BST, BST tracking mode and snapshot view for
     24  *         THDO, THDI and CFAP using switch controls - bst_global_setup
     25  *      b) Set BST profile for specified mmu resource - bcmBstStatIdEgrPool in this
     26  *         example
     27  *    3) Step3 - Verification (Done in verify())
     28  *    ==========================================
     29  *      a) Check the Bst stats for the specified BST object - bcmBstStatIdEgrPool
     30  *      b) Expected Result:
     31  *         ================
     32  *         If profile threshold is exceeded we see non-zero stats in value1 and value2
     33  *         (It is assumed that traffic path setup between ingress and egress port and egress port is
     34  *         congested so that shared buffer usage exceeds the profile threshold in this example)
     35  */
     36 
     37 cint_reset();
     38 
     39 uint32 unit = 0;
     40 int rv=0;
     41 bcm_gport_t port_gport;	
     42 int port;
     43 uint64 value1 = "0x00000000:00000000";
     44 uint64 value2 = "0x00000000:00000000";
     45 
     46 /* This function is written so that hardcoding of port
     47    numbers in Cint scripts is removed. This function gives
     48    required number of ports
     49 */
     50 bcm_error_t portNumbersGet(int unit, int *port_list, int num_ports)
     51 {
     52 
     53   int i=0,port=0,rv=0;
     54   bcm_port_config_t configP;
     55   bcm_pbmp_t ports_pbmp;
     56 
     57   rv = bcm_port_config_get(unit,&configP);
     58   if(BCM_FAILURE(rv)) {
     59      printf("\nError in retrieving port configuration: %s.\n",bcm_errmsg(rv));
     60      return rv;
     61   }
     62 
     63   ports_pbmp = configP.e;
     64   for (i= 1; i < BCM_PBMP_PORT_MAX; i++) {
     65     if (BCM_PBMP_MEMBER(&ports_pbmp,i)&& (port < num_ports)) {
     66       port_list[port]=i;
     67       port++;
     68     }
     69   }
     70 
     71   if (( port == 0 ) || ( port != num_ports )) {
     72        printf("portNumbersGet() failed \n");
     73        return -1;
     74   }
     75 
     76   return BCM_E_NONE;
     77 }
     78 
     79 /*
     80  * This functions gets the port numbers and sets up ingress and
     81  * egress ports.
     82  */
     83 bcm_error_t test_setup(int unit)
     84 {
     85   int port_list[1], i;
     86 
     87   if (BCM_E_NONE != portNumbersGet(unit, port_list, 1)) {
     88       printf("portNumbersGet() failed\n");
     89       return -1;
     90   }
     91 
     92   /* Get port gport */
     93   port = port_list[0];
     94 
     95   if (BCM_E_NONE != bcm_port_gport_get(unit, port, &port_gport)) {
     96       printf("bcm_port_gport_get() failed.\n");
     97       return -1;
     98   }
     99   
    100   return BCM_E_NONE;
    101 }
    102 
    103 /* Enable BST, Set BST tracking mode, Enable snapshot view for 
    104  * THDO, THDI and CFAP
    105  */
    106 bcm_error_t bst_global_setup(int unit)
    107 {
    108    bcm_switch_control_set(unit, bcmSwitchBstEnable, TRUE);
    109    bcm_switch_control_set(unit, bcmSwitchBstTrackingMode , 0);
    110    bcm_switch_control_set(unit, bcmSwitchBstSnapshotEnable, 1); /* 1 - THDO */
    111    bcm_switch_control_set(unit, bcmSwitchBstSnapshotEnable, 2); /* 2 - THDI */
    112    bcm_switch_control_set(unit, bcmSwitchBstSnapshotEnable, 4); /* 4 - CFAP */
    113    return BCM_E_NONE;
    114 }
    115 
    116 /* Set BST profile for object bcmBstStatIdEgrPool */
    117 bcm_error_t bst_profile_set(int unit, bcm_gport_t port_gport)
    118 {
    119  bcm_cosq_bst_profile_t profile;
    120  profile.byte=400;
    121 
    122  /* Set BST profile for object bcmBstStatIdEgrPool for specified port */
    123  rv = bcm_cosq_bst_profile_set(unit, port_gport,-1, bcmBstStatIdEgrPool, profile);
    124  if (rv != BCM_E_NONE) {
    125       printf("Error in bcm_cosq_bst_profile_set:%s.\n", bcm_errmsg(rv));
    126       return rv;
    127  }
    128  return BCM_E_NONE;
    129 }
    130 
    131 bcm_error_t bst_stat_get(int unit, bcm_gport_t port_gport)
    132 { 
    133  rv = bcm_cosq_bst_stat_get(unit, port_gport, -1, bcmBstStatIdEgrPool, 0, &value1);
    134  if (rv != BCM_E_NONE) {
    135      printf("Error in bcm_cosq_bst_stat_get:%s.\n", bcm_errmsg(rv));
    136      return rv;
    137  }
    138 
    139  rv = bcm_cosq_bst_stat_sync(unit, bcmBstStatIdEgrPool);
    140  if (rv != BCM_E_NONE) {
    141      printf("Error in bcm_cosq_bst_stat_sync:%s.\n", bcm_errmsg(rv));
    142      return rv;
    143  }
    144 
    145  rv = bcm_cosq_bst_stat_get(unit, port_gport, -1, bcmBstStatIdEgrPool, 0, &value2);
    146  if (rv != BCM_E_NONE) {
    147      printf("Error in bcm_cosq_bst_stat_sync:%s.\n", bcm_errmsg(rv));
    148      return rv;
    149  }
    150  print value1;
    151  print value2;
    152  return BCM_E_NONE;
    153 }
    154 
    155 bcm_error_t bst_config(int unit, bcm_gport_t port_gport)
    156 {
    157   /* BST setup */
    158   if (BCM_FAILURE((rv = bst_global_setup(unit)))) {
    159       printf("bst_global_setup() failed. : %s. \n", bcm_errmsg(rv)); 
    160       return -1;
    161   }
    162 
    163   if (BCM_FAILURE((rv = bst_profile_set(unit, port_gport)))) {
    164       printf("bst_stat_get_on_port() failed. : %s. \n", bcm_errmsg(rv));
    165       return rv;
    166   }
    167   return BCM_E_NONE;
    168 }
    169 
    170 /* Function to verify the result */
    171 void verify(int unit)
    172 {
    173   bshell(unit, "show c");
    174   bst_stat_get(unit, port_gport);
    175 }
    176 
    177 bcm_error_t execute()
    178 {
    179   bcm_error_t rv;
    180   int unit =0;
    181   bshell(unit, "config show; a ; version");
    182 
    183   if (BCM_FAILURE((rv = test_setup(unit)))) {
    184       printf("test_setup() failed.\n");
    185       return -1;
    186   }
    187 
    188   /* BST setup */
    189   if (BCM_FAILURE((rv = bst_config(unit, port_gport)))) {
    190       printf("bst_config() failed.\n");
    191       return -1;
    192   }
    193 
    194   /* verify the result */
    195   verify(unit);
    196 
    197   return BCM_E_NONE;
    198 }
    199 const char *auto_execute = (ARGC == 1) ? ARGV[0] : "YES";
    200 if (!sal_strcmp(auto_execute, "YES")) {
    201   print execute();
    202 }
    203