/******************************************************************
 * @brief  Creates a JSON buffer using the supplied data for the 
 *         "get-bst-report" REST API - egress-port-service-pool.
 *
 *********************************************************************/
static BVIEW_STATUS _jsonencode_report_egress_epsp ( char *buffer, int asicId,
                                                    const BVIEW_BST_ASIC_SNAPSHOT_DATA_t *previous,
                                                    const BVIEW_BST_ASIC_SNAPSHOT_DATA_t *current,
                                                    const BSTJSON_REPORT_OPTIONS_t *options,
                                                    const BVIEW_ASIC_CAPABILITIES_t *asic,
                                                    int bufLen,
                                                    int *length)
{
    int remLength = bufLen;
    int actualLength  = 0;
    bool includePort = false;
    uint64_t val1 = 0, val2 = 0, val3 = 0;

    int includeServicePool[BVIEW_ASIC_MAX_SERVICE_POOLS] = { 0 };
    int port = 0, pool = 0;

    char *epspTemplate = " { \"realm\": \"egress-port-service-pool\", \"%s\": [ ";
    char *epspPortTemplate = " { \"port\": \"%s\", \"data\": [ ";
    char *epspServicePoolTemplate = " [  %d , %" PRIu64 " , %" PRIu64 " , %" PRIu64 " ] ,";
    char portStr[JSON_MAX_NODE_LENGTH] = { 0 };


    _JSONENCODE_LOG(_JSONENCODE_DEBUG_TRACE, "BST-JSON-Encoder : (Report) Encoding EGRESS - EPSP data \n");

    /* copying the header . Pointer and Length adjustments are handled by the macro */
    _JSONENCODE_COPY_FORMATTED_STRING_AND_ADVANCE(actualLength, buffer, remLength, length, epspTemplate, "data");

    /* For each port, and for each service pool in that port, 
     *  1. attempt to see if this port needs to be reported.
     *  2. create the report.
     */
    for (port = 1; port <= asic->numPorts; port++)
    {
        includePort = false;
        memset (&includeServicePool[0], 0, sizeof (includeServicePool));

        /* lets see if this port needs to be included in the report at all */
        for (pool = 1; pool <= asic->numServicePools; pool++)
        {
            /* By default, we plan to include the pool */
            includeServicePool[pool - 1] = 1;

            /* If there is no traffic reported for this priority group, ignore it */
            if ( (current->ePortSp.data[port - 1][pool - 1].umShareBufferCount == 0) &&
                (current->ePortSp.data[port - 1][pool - 1].ucShareBufferCount == 0) &&
                (current->ePortSp.data[port - 1][pool - 1].mcShareBufferCount == 0) &&
                (current->ePortSp.data[port - 1][pool - 1].mcShareQueueEntries == 0))
            {
                includeServicePool[pool - 1] = 0;
                continue;
            }

            /* If this is snapshot report, include the port in the data  */
            if (previous == NULL)
            {
                includePort = true;
                continue;
            }

            /* if there is traffic reported since the last snapshot, we can't ignore this pool */
            if ( (previous->ePortSp.data[port - 1][pool - 1].umShareBufferCount
                  != current->ePortSp.data[port - 1][pool - 1].umShareBufferCount) ||
                (previous->ePortSp.data[port - 1][pool - 1].ucShareBufferCount
                 != current->ePortSp.data[port - 1][pool - 1].ucShareBufferCount) ||
                (previous->ePortSp.data[port - 1][pool - 1].mcShareBufferCount
                 != current->ePortSp.data[port - 1][pool - 1].mcShareBufferCount) ||
                (previous->ePortSp.data[port - 1][pool - 1].mcShareQueueEntries
                 != current->ePortSp.data[port - 1][pool - 1].mcShareQueueEntries) )
            {
                includePort = true;
                continue;
            }

            /* since there is no reason to include the pool, we can ignore it*/
            includeServicePool[pool - 1] = 0;
        }

        /* if this port needs not be reported, then we move to next port */
        if (includePort == false)
        {
            continue;
        }

        /* convert the port to an external representation */
        memset(&portStr[0], 0, JSON_MAX_NODE_LENGTH);
        JSON_PORT_MAP_TO_NOTATION(port, asicId, &portStr[0]);

        /* Now that this port needs to be included in the report, copy the header */
        _JSONENCODE_COPY_FORMATTED_STRING_AND_ADVANCE(actualLength, buffer, remLength, length, epspPortTemplate, &portStr[0]);

        /* for each priority-group, prepare the data */
        for (pool = 1; pool <= asic->numServicePools; pool++)
        {
            /* we ignore if there is no data to be reported */
            if (includeServicePool[pool - 1] == 0)
                continue;

            val1 = current->ePortSp.data[port - 1][pool - 1].ucShareBufferCount;
            val2 = current->ePortSp.data[port - 1][pool - 1].umShareBufferCount;
            val3 = current->ePortSp.data[port - 1][pool - 1].mcShareBufferCount;

           /* check if we need to convert the data to cells */
             if ((true == options->statUnitsInCells) && 
                 (true == options->reportThreshold))
             {
               val1 = current->ePortSp.data[port - 1][pool - 1].ucShareBufferCount / (asic->cellToByteConv);
               val2 = current->ePortSp.data[port - 1][pool - 1].umShareBufferCount / (asic->cellToByteConv);
               val3 = current->ePortSp.data[port - 1][pool - 1].mcShareBufferCount / (asic->cellToByteConv);
             }
             /* check if we need to convert the data to cells
                the report always comes in cells from asic */
             else if ((false == options->statUnitsInCells) &&
                 (false == options->reportThreshold))
             {
               val1 = current->ePortSp.data[port - 1][pool - 1].ucShareBufferCount * (asic->cellToByteConv);
               val2 = current->ePortSp.data[port - 1][pool - 1].umShareBufferCount * (asic->cellToByteConv);
               val3 = current->ePortSp.data[port - 1][pool - 1].mcShareBufferCount * (asic->cellToByteConv);
             }
            /* add the data to the report */
            _JSONENCODE_COPY_FORMATTED_STRING_AND_ADVANCE(actualLength, buffer, remLength, length,
                                                          epspServicePoolTemplate, pool-1,
                                                          val1, val2, val3,
                                                          current->ePortSp.data[port - 1][pool - 1].mcShareQueueEntries
                                                          );
        }

        /* adjust the buffer to remove the last ',' */
        buffer = buffer - 1;
        remLength += 1;
        *length -= 1;

        /* add the "] } ," for the next port */
        _JSONENCODE_COPY_FORMATTED_STRING_AND_ADVANCE(actualLength, buffer, remLength, length,
                                                      "] } ," );
    }

    /* adjust the buffer to remove the last ',' */
    buffer = buffer - 1;
    remLength += 1;
    *length -= 1;

    /* add the "] } ," for the next 'realm' */
    _JSONENCODE_COPY_FORMATTED_STRING_AND_ADVANCE(actualLength, buffer, remLength, length,
                                                  "] } ," );

    _JSONENCODE_LOG(_JSONENCODE_DEBUG_TRACE, "BST-JSON-Encoder : (Report) Encoding EGRESS - EPSP data Complete \n");

    return BVIEW_STATUS_SUCCESS;

}
コード例 #2
0
/******************************************************************
 * @brief  Creates a JSON buffer using the supplied data for the 
 *         "get-bst-report" REST API - ingress-port-port-group.
 *
 *********************************************************************/
static BVIEW_STATUS _jsonencode_report_ingress_ippg ( char *buffer, int asicId,
                                                     const BVIEW_BST_ASIC_SNAPSHOT_DATA_t *previous,
                                                     const BVIEW_BST_ASIC_SNAPSHOT_DATA_t *current,
                                                     const BSTJSON_REPORT_OPTIONS_t *options,
                                                     const BVIEW_ASIC_CAPABILITIES_t *asic,
                                                     int bufLen,
                                                     int *length)
{
    int remLength = bufLen;
    int actualLength  = 0;
    bool includePort = false;
    uint64_t val1 = 0;
    uint64_t val2 = 0;
    uint64_t defaultVal = 0;
    int sendIncrReport = options->sendIncrementalReport;


    int includePriorityGroups[BVIEW_ASIC_MAX_PRIORITY_GROUPS] = { 0 };
    int port = 0, priGroup = 0;
    char portStr[JSON_MAX_NODE_LENGTH] = { 0 };

    char *ippgTemplate = " { \"realm\": \"ingress-port-priority-group\", \"%s\": [ ";
    char *ippgPortTemplate = " { \"port\": \"%s\", \"data\": [ ";
    char *ippgPortGroupTemplate = " [  %d , %" PRIu64 " , %" PRIu64 " ] ,";

    _JSONENCODE_LOG(_JSONENCODE_DEBUG_TRACE, "BST-JSON-Encoder : (Report) Encoding INGRESS - IPPG data \n");

    /* copying the header . Pointer and Length adjustments are handled by the macro */
    _JSONENCODE_COPY_FORMATTED_STRING_AND_ADVANCE(actualLength, buffer, remLength, length, ippgTemplate, "data");

    /* For each port, and for each priority group in that port, 
     *  1. attempt to see if this port needs to be reported.
     *  2. create the report.
     */
    for (port = 1; port <= asic->numPorts; port++)
    {
      /* check if the trigger report request should contain snap shot */
        if ((port-1 != options->triggerInfo.port) && 
            (false == options->sendSnapShotOnTrigger) && 
            (true == options->reportTrigger))
        {
          continue;
        }
        includePort = false;
        memset (&includePriorityGroups[0], 0, sizeof (includePriorityGroups));

        /* lets see if this port needs to be included in the report at all */
        for (priGroup = 1; priGroup <= asic->numPriorityGroups; priGroup++)
        {
      /* check if the trigger report request should contain snap shot */
           if ((priGroup-1 != options->triggerInfo.queue) && 
            (false == options->sendSnapShotOnTrigger) && 
            (true == options->reportTrigger))
           {
             continue;
           }
            /* By default, we plan to include the pri-group */
            includePriorityGroups[priGroup - 1] = 1;
   
            if (true == sendIncrReport)
            {
            /* If there is no traffic reported for this priority group, ignore it */
            if ((previous == NULL) && 
                (current->iPortPg.data[port - 1][priGroup - 1].umShareBufferCount == 0) &&
                (current->iPortPg.data[port - 1][priGroup - 1].umHeadroomBufferCount == 0) )
            {
                includePriorityGroups[priGroup - 1] = 0;
                continue;
            }
           }

            /* If this is snapshot report, include the port in the data  */
            if (previous == NULL)
            {
                includePort = true;
                continue;
            }

            /* if there is traffic reported since the last snapshot, we can't ignore this priority group */
            if (previous->iPortPg.data[port - 1][priGroup - 1].umShareBufferCount
                != current->iPortPg.data[port - 1][priGroup - 1].umShareBufferCount)
            {
                includePort = true;
                continue;
            }

            if (previous->iPortPg.data[port - 1][priGroup - 1].umHeadroomBufferCount
                != current->iPortPg.data[port - 1][priGroup - 1].umHeadroomBufferCount)
            {
                includePort = true;
                continue;
            }

            /* since there is no reason to include the group, we can ignore it*/
            includePriorityGroups[priGroup - 1] = 0;
        }

        /* if this port needs not be reported, then we move to next port */
        if (includePort == false)
        {
            continue;
        }

          /* convert the port to an external representation */
          memset(&portStr[0], 0, JSON_MAX_NODE_LENGTH);
          JSON_PORT_MAP_TO_NOTATION(port, asicId, &portStr[0]);

          /* Now that this port needs to be included in the report, copy the header */
          _JSONENCODE_COPY_FORMATTED_STRING_AND_ADVANCE(actualLength, buffer, remLength, length, ippgPortTemplate, &portStr[0]);

        /* for each priority-group, prepare the data */
        for (priGroup = 1; priGroup <= asic->numPriorityGroups; priGroup++)
        {
            /* we ignore if there is no data to be reported */
            if (includePriorityGroups[priGroup - 1] == 0)
                continue;

            val1 = current->iPortPg.data[port - 1][priGroup - 1].umShareBufferCount;
            defaultVal = options->bst_defaults_ptr->iPortPg.data[port - 1][priGroup - 1].umShareBufferCount;
            bst_json_convert_data(options, asic, &val1, defaultVal);

            val2 = current->iPortPg.data[port - 1][priGroup - 1].umHeadroomBufferCount;
            defaultVal = options->bst_defaults_ptr->iPortPg.data[port - 1][priGroup - 1].umHeadroomBufferCount;
            bst_json_convert_data(options, asic, &val2, defaultVal);

            /* add the data to the report */
            _JSONENCODE_COPY_FORMATTED_STRING_AND_ADVANCE(actualLength, buffer, remLength, length,
                                                          ippgPortGroupTemplate, priGroup-1, val1, val2);
        }

          /* adjust the buffer to remove the last ',' */
          buffer = buffer - 1;
          remLength += 1;
          *length -= 1;

        /* add the "] } ," for the next port */
        _JSONENCODE_COPY_FORMATTED_STRING_AND_ADVANCE(actualLength, buffer, remLength, length,
                                                      "] } ," );
    }

    /* adjust the buffer to remove the last ',' */
    buffer = buffer - 1;
    remLength += 1;
    *length -= 1;

    /* add the "] } ," for the next 'realm' */
    _JSONENCODE_COPY_FORMATTED_STRING_AND_ADVANCE(actualLength, buffer, remLength, length,
                                                  "] } ," );

    _JSONENCODE_LOG(_JSONENCODE_DEBUG_TRACE, "BST-JSON-Encoder : (Report) Encoding INGRESS - IPPG data Complete \n");

    return BVIEW_STATUS_SUCCESS;

}
/******************************************************************
 * @brief  Creates a JSON buffer using the supplied data for the 
 *         "get-bst-report" REST API - egress UC Queue.
 *
 *********************************************************************/
static BVIEW_STATUS _jsonencode_report_egress_ucq ( char *buffer, int asicId,
                                                   const BVIEW_BST_ASIC_SNAPSHOT_DATA_t *previous,
                                                   const BVIEW_BST_ASIC_SNAPSHOT_DATA_t *current,
                                                   const BSTJSON_REPORT_OPTIONS_t *options,
                                                   const BVIEW_ASIC_CAPABILITIES_t *asic,
                                                   int bufLen,
                                                   int *length)
{
    int remLength = bufLen;
    int actualLength  = 0;
    int queue = 0;
    uint64_t val = 0;

    char *realmTemplate = " { \"realm\": \"egress-uc-queue\", \"%s\": [ ";
    char *dataTemplate = " [  %d , \"%s\" , %" PRIu64 " ] ,";
    char portStr[JSON_MAX_NODE_LENGTH] = { 0 };


    _JSONENCODE_LOG(_JSONENCODE_DEBUG_TRACE, "BST-JSON-Encoder : (Report) Encoding EGRESS - UC Queue data \n");

    /* copying the header . Pointer and Length adjustments are handled by the macro */
    _JSONENCODE_COPY_FORMATTED_STRING_AND_ADVANCE(actualLength, buffer, remLength, length, realmTemplate, "data");

    /* For each unicast queues, check if there is a difference, and create the report. */
    for (queue = 1; queue <= asic->numUnicastQueues; queue++)
    {
        /* lets see if this queue needs to be included in the report at all */
        /* if this queue needs not be reported, then we move to next queue */
        if (current->eUcQ.data[queue - 1].ucBufferCount == 0)
            continue;

        if ((previous != NULL) &&
            (previous->eUcQ.data[queue - 1].ucBufferCount == current->eUcQ.data[queue - 1].ucBufferCount))
            continue;

        /* convert the port to an external representation */
        memset(&portStr[0], 0, JSON_MAX_NODE_LENGTH);
        JSON_PORT_MAP_TO_NOTATION(current->eUcQ.data[queue - 1].port, asicId, &portStr[0]);

        val = current->eUcQ.data[queue - 1].ucBufferCount;
           /* check if we need to convert the data to cells */
             if ((true == options->statUnitsInCells) && 
                 (true == options->reportThreshold))
             {
               val = current->eUcQ.data[queue - 1].ucBufferCount / (asic->cellToByteConv);
             }
             /* check if we need to convert the data to cells
                the report always comes in cells from asic */
             else if ((false == options->statUnitsInCells) &&
                 (false == options->reportThreshold))
             {
               val = current->eUcQ.data[queue - 1].ucBufferCount * (asic->cellToByteConv);
             }
        /* Now that this ucq needs to be included in the report, add the data to report */
        _JSONENCODE_COPY_FORMATTED_STRING_AND_ADVANCE(actualLength, buffer, remLength, length,
                                                      dataTemplate, queue-1,
                                                      &portStr[0],
                                                      val 
                                                      );
    }

    /* adjust the buffer to remove the last ',' */
    buffer = buffer - 1;
    remLength += 1;
    *length -= 1;

    /* add the "] } ," for the next 'realm' */
    _JSONENCODE_COPY_FORMATTED_STRING_AND_ADVANCE(actualLength, buffer, remLength, length,
                                                  "] } ," );

    _JSONENCODE_LOG(_JSONENCODE_DEBUG_TRACE, "BST-JSON-Encoder : (Report) Encoding EGRESS - UC Queue data Complete \n");

    return BVIEW_STATUS_SUCCESS;
}