#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include "rpcclt_openapi.h"
#include "proc_util.h"
{
uint32_t localFaultStatus = 0;
uint32_t remoteFaultStatus = 0;
{
printf("\n\nFiber port fault status for port %d : %s", ifNum,
(((localFaultStatus != 0) && (remoteFaultStatus != 0)) ?
"Local & Remote Faults\n" : ((localFaultStatus != 0) ?
"Local Fault\n" : ((remoteFaultStatus != 0) ? "Remote Fault\n" : "No Fault\n"))));
}
else
{
printf("Bad return code trying to get fiber ports optics fault status. (result = %d)\n", result);
}
}
{
uint32_t temperature = 0;
uint32_t voltage = 0;
uint32_t current = 0;
int32_t tNotSupported = (int32_t) (~0);
uint32_t vcNotSupported = (uint32_t) (~0);
uint64_t pNotSupported = (10 * log10((uint64_t)((uint32_t)(~0))/10000));
uint64_t powerIn;
uint64_t powerOut;
&powerIn, &powerOut, &txFault, &los);
{
printf("%d ", ifNum);
if (temperature == tNotSupported)
{
printf(" N/A");
}
else
{
printf(" %4d.%1.1d", temperature/1000, (abs(temperature)%1000)/100);
}
if (voltage == vcNotSupported)
{
printf(" N/A");
}
else
{
printf(" %1d.%3.3d", voltage / 1000, voltage % 1000);
}
if (current == vcNotSupported)
{
printf(" N/A");
}
else
{
printf(" %5d.%1.1d", current/1000, (current%1000)/100);
}
if (powerOut == pNotSupported)
{
printf(" N/A");
}
else
{
printf(" %lld ", powerOut);
}
if (powerIn == pNotSupported)
{
printf(" N/A");
}
else
{
printf(" %lld ", powerIn);
}
printf(
" %s %s\n", ((
OPEN_TRUE == txFault) ?
"Yes":
"No"), ((
OPEN_TRUE == los) ?
"Yes":
"No"));
}
{
printf("%d N/A N/A N/A N/A N/A N/A N/A\n", ifNum);
}
else
{
printf("Bad return code trying to get fiber ports optics. (result = %d)\n", result);
}
}
{
uint32_t ifNum = 0;
printf("\nPort Temperature Voltage Current Output Power Input Power TX Fault LOS\n");
{
do
{
{
printf("Bad Error code while getting link state(result = %d)\n", result);
}
{
continue;
}
{
printf("Failed to get module type(result = %d)\n", result);
break;
}
{
fiberPortsOpticsGet(clientHandle, ifNum);
fiberPortsOpticsFaultStatusGet(clientHandle, ifNum);
}
}
return;
}
{
OPEN_LED_CMD_t val = OPEN_LED_CMD_ON;
OPEN_LED_STATUS_t val1 = OPEN_LED_STATUS_ON;
{
printf("Bad return code trying to get port LED status (result = %d)\n", result);
}
else
{
printf("Port LED status :%s (%u) (result = %d)\n",
((val1 == OPEN_LED_STATUS_ON) ? "ON" : "OFF"), val1, result);
}
val = ((val == OPEN_LED_CMD_ON) ? OPEN_LED_CMD_OFF : OPEN_LED_CMD_ON);
{
printf("Bad return code trying to set port LED status (result = %d)\n", result);
}
else
{
printf("Port LED status set:%s (%u) (result = %d)\n",
((val == OPEN_LED_CMD_ON) ? "ON" : "OFF"), val, result);
}
{
printf("Bad return code trying to get system LED status (result = %d)\n", result);
}
else
{
printf("System LED status :%s (%u) (result = %d)\n",
((val1 == OPEN_LED_STATUS_ON) ? "ON" : "OFF"), val1, result);
}
val = ((val == OPEN_LED_CMD_ON) ? OPEN_LED_CMD_OFF : OPEN_LED_CMD_ON);
{
printf("Bad return code trying to set system LED status (result = %d)\n", result);
}
else
{
printf("System LED status set:%s (%u) (result = %d)\n",
((val == OPEN_LED_CMD_ON) ? "ON" : "OFF"), val, result);
}
return;
}
int
main (int argc, char **argv)
{
uint32_t i, numFans, fanSpeed, fanDuty, numPowSuplies, numOfTempSemsors, temperature;
uint32_t tempSensorDescSize, powSupplyDescSize, fanDescSize;
uint32_t genTemp, genFanSpeed, genFanDuty, genTempRangeMin, genTempRangeMax;
char switch_os_revision_string[100];
char cpld_version_string[OPEN_SYSTEM_PARAM_SIZE+1];
char buf[128];
open_buffdesc vendorNameDesc, serialNumberDesc, partNumberDesc, vendorRevDesc, complianceDesc;
char *sfpBuf, *str;
uint32_t vendorNameSize, serialNumberSize, partNumberSize, vendorRevSize, complianceSize;
uint32_t linkLength50um, linkLength62_5um, nominalSigRate;
uint32_t ifNum = 0;
uint32_t headerPrinted = 0;
uint32_t version = 0;
l7proc_crashlog_register ();
if ((result =
{
printf ("\nFailed to initialize RPC to OpEN. Exiting (result = %d)\n",
result);
exit (2);
}
{
sleep (1);
}
L7PROC_LOGF (L7PROC_LOG_SEVERITY_INFO, 0,
"Starting box services API example application");
printf ("\n");
switch_os_revision.
pstart = switch_os_revision_string;
switch_os_revision.
size =
sizeof (switch_os_revision_string);
printf ("Network OS version = %s\n", switch_os_revision_string);
else
printf ("Network OS version retrieve error\n");
printf ("Hardware version = 0x%d\n", version);
else
printf ("Hardware version retrieve error\n");
printf ("\n");
cpld_version.pstart = cpld_version_string;
cpld_version.size = sizeof (cpld_version_string);
printf ("CPLD version = %s\n", cpld_version_string);
else
printf ("Unable to get CPLD version. (result = %d)\n", result);
printf ("\n");
do
{
{
printf(" Bad return code trying to get general temperature in the unit. (result = %d)\n",result);
break;
}
else
{
printf("General temperature in the unit : %d\n", genTemp);
}
{
printf(" Bad return code trying to get allowed temperature range in the unit. (result = %d)\n",result);
break;
}
else
{
printf("Allowed temperature range in the unit : %d-%d\n", genTempRangeMin, genTempRangeMax);
}
{
printf(" Bad return code trying to get general fan speed in the unit. (result = %d)\n",result);
break;
}
else
{
printf("General fan speed in the unit : %d\n", genFanSpeed);
}
{
printf(" Bad return code trying to get general fan duty-level in the unit. (result = %d)\n",result);
break;
}
else
{
printf("General fan duty-level in the unit : %d\n", genFanDuty);
}
{
printf(" Bad return code trying to get number of FANs in the unit. (result = %d)\n",result);
break;
}
else
{
printf("Number of FANs in the unit : %d\n",numFans);
}
{
printf(" Bad return code trying to get the fan description size. (result = %d)\n",result);
break;
}
else
{
printf("Description size of fan in the unit %d\n", fanDescSize);
}
str = (char *)malloc(fanDescSize);
if (NULL == str)
{
printf("Error: Could not allocate memory.\n");
break;
}
for (i = 0; i< numFans; i++)
{
memset (str, 0, fanDescSize);
descrip.pstart = str;
descrip.size = fanDescSize;
{
printf(" Bad return code trying to description of fan %d. (result = %d)\n",(i + 1),result);
break;
}
else
{
printf("Fan %d description : %s\n",(i + 1),str);
}
}
free(str);
for (i = 0; i< numFans; i++)
{
{
printf(" Bad return code trying to get Speed of FAN %d. (result = %d)\n",(i + 1),result);
break;
}
else
{
printf("FAN number %d speed %d\n",(i + 1),fanSpeed);
}
}
for (i = 0; i< numFans; i++)
{
{
printf(" Bad return code trying to get state of FAN %d. (result = %d)\n",(i + 1),result);
break;
}
else
{
memset (buf, 0, sizeof(buf));
switch (fanState)
{
case OPEN_ITEMSTATE_NONE:
sprintf(buf,"NONE");
break;
case OPEN_ITEMSTATE_NOT_PRESENT:
sprintf(buf,"Not Present");
break;
case OPEN_ITEMSTATE_OPERATIONAL:
sprintf(buf,"Operational");
break;
case OPEN_ITEMSTATE_FAILED:
sprintf(buf,"Failed");
break;
default:
sprintf(buf,"NONE");
break;
}
printf("FAN number %d FAN state : %s\n",(i + 1),buf);
}
}
for (i = 0; i< numFans; i++)
{
{
printf(" Bad return code trying to get type of FAN %d. (result = %d)\n",(i + 1),result);
break;
}
else
{
memset (buf, 0, sizeof(buf));
switch (itemType)
{
case OPEN_TYPE_FIXED:
sprintf(buf,"Fixed");
break;
case OPEN_TYPE_REMOVABLE:
sprintf(buf,"Removable");
break;
default:
sprintf(buf,"NONE");
break;
}
printf("FAN number %d FAN Type : %s\n",(i + 1),buf);
}
}
for (i = 0; i< numFans; i++)
{
{
printf(" Bad return code trying to get Duty-Cycle of FAn %d. (result = %d)\n",(i + 1),result);
break;
}
else
{
printf("FAN number %d Duty-Cycle : %d\n",(i + 1),fanDuty);
}
}
{
printf(" Bad return code trying to get the number of power supplies in the unit. (result = %d)\n",result);
break;
}
else
{
printf("Number of power supplies in the unit %d\n",numPowSuplies);
}
{
printf(" Bad return code trying to get the power supply description size. (result = %d)\n",result);
break;
}
else
{
printf("Description size of power supply in the unit %d\n", powSupplyDescSize);
}
str = (char *)malloc(powSupplyDescSize);
if (NULL == str)
{
printf("Error: Could not allocate memory.\n");
break;
}
for (i = 0; i< numPowSuplies; i++)
{
memset (str, 0, powSupplyDescSize);
descrip.pstart = str;
descrip.size = powSupplyDescSize;
{
printf(" Bad return code trying to description of power supply %d. (result = %d)\n",(i + 1),result);
break;
}
else
{
printf("Power supply %d description : %s\n",(i + 1),str);
}
}
free(str);
for (i = 0; i<numPowSuplies; i++)
{
{
printf(" Bad return code trying to get state of the power supply %d. (result = %d)\n",(i + 1),result);
break;
}
else
{
memset (buf, 0, sizeof(buf));
switch (psState)
{
case OPEN_ITEMSTATE_NONE:
sprintf(buf,"NONE");
break;
case OPEN_ITEMSTATE_NOT_PRESENT:
sprintf(buf,"Not-Present");
break;
case OPEN_ITEMSTATE_OPERATIONAL:
sprintf(buf,"Operational");
break;
case OPEN_ITEMSTATE_FAILED:
sprintf(buf,"Failed");
break;
case OPEN_ITEMSTATE_POWERING:
sprintf(buf,"Powering");
break;
case OPEN_ITEMSTATE_NOPOWER:
sprintf(buf,"Not powered");
break;
default:
sprintf(buf,"-------");
break;
}
printf("Power supply %d state : %s\n",(i + 1),buf);
}
}
for (i = 0; i<numPowSuplies; i++)
{
{
printf(" Bad return code trying to get Type of the power supply %d. (result = %d)\n",(i + 1),result);
break;
}
else
{
memset (buf, 0, sizeof(buf));
switch (itemType)
{
case OPEN_TYPE_FIXED:
sprintf(buf,"Fixed");
break;
case OPEN_TYPE_REMOVABLE:
sprintf(buf,"Removable");
break;
default:
sprintf(buf,"-------");
break;
}
printf("Power supply %d Type : %s\n",(i + 1),buf);
}
}
{
printf(" Bad return code trying to get the number of thermal sensors. (result = %d)\n",result);
break;
}
else
{
printf("Number of thermal senosrs in the unit %d\n",numOfTempSemsors);
}
{
printf(" Bad return code trying to get the thermal sensors description size. (result = %d)\n",result);
break;
}
else
{
printf("Description size of thermal senosrs in the unit %d\n", tempSensorDescSize);
}
str = (char *)malloc(tempSensorDescSize);
if (NULL == str)
{
printf("Error: Could not allocate memory.\n");
break;
}
for (i = 0; i<numOfTempSemsors; i++)
{
memset (str, 0, tempSensorDescSize);
descrip.pstart = str;
descrip.size = tempSensorDescSize;
{
printf(" Bad return code trying to description of thermal sensor %d. (result = %d)\n",(i + 1),result);
break;
}
else
{
printf("Thermal sensor %d description : %s\n",(i + 1),str);
}
}
free(str);
for (i = 0; i<numOfTempSemsors; i++)
{
{
printf(" Bad return code trying to get temperature for thermal sensor %d. (result = %d)\n",(i + 1),result);
break;
}
else
{
printf("Thermal sensor %d temperature : %d\n",(i + 1),temperature);
}
}
for (i = 0; i<numOfTempSemsors; i++)
{
{
printf(" Bad return code trying to get the state of thermal sensor %d. (result = %d)\n",(i + 1),result);
break;
}
else
{
memset (buf, 0, sizeof(buf));
switch (state)
{
case OPEN_TEMPSENSOR_STATE_NORMAL:
sprintf(buf,"Normal");
break;
case OPEN_TEMPSENSOR_STATE_WARNING:
sprintf(buf,"Warning");
break;
case OPEN_TEMPSENSOR_STATE_CRITICAL:
sprintf(buf,"Critical");
break;
case OPEN_TEMPSENSOR_STATE_SHUTDOWN:
sprintf(buf,"Shutdown");
break;
case OPEN_TEMPSENSOR_STATE_NOTPRESENT:
sprintf(buf,"Not-Present");
break;
case OPEN_TEMPSENSOR_STATE_NOTOPERATIONAL:
sprintf(buf,"Non-Operational");
break;
default:
sprintf(buf,"--------");
break;
}
printf("Thermal sensor %d state : %s\n",(i + 1),buf);
}
}
printf("\n");
printf("SFP transceiver data:\n");
{
do
{
{
printf("Bad Error code while getting link state(result = %d)\n", result);
}
{
continue;
}
{
printf("Failed to get module type(result = %d)\n", result);
break;
}
{
if (headerPrinted == 0)
{
printf(" Link Length Nominal\n");
printf(" 50um 62.5um Signal Rate\n");
printf("Port Vendor Name Serial Number Part Number Revision [m] [m] [mbps] Compliance\n");
printf("----- ---------------- ---------------- ---------------- -------- ------ ------ ----------- ----------------\n");
headerPrinted = 1;
}
printf("%-5d ", ifNum);
{
printf("Bad error code getting sfp vendor name size.(result = %d)\n", result);
break;
}
if ((sfpBuf = (char*)malloc(vendorNameSize)) == NULL)
{
printf("Could not allocate memory for vendor name.\n");
return 0;
}
memset(sfpBuf, 0, vendorNameSize);
vendorNameDesc.pstart = sfpBuf;
vendorNameDesc.size = vendorNameSize;
{
printf("%-16s ", sfpBuf);
}
else
{
printf("Bad error code while getting vendor name on interface %d. (result = %d)\n", ifNum, result);
break;
}
free(sfpBuf);
{
printf("Bad error code getting sfp serial number size. (result = %d)\n", result);
break;
}
if ((sfpBuf = (char*)malloc(serialNumberSize)) == NULL)
{
printf("Could not allocate memory for serial number.\n");
return 0;
}
memset(sfpBuf, 0, serialNumberSize);
serialNumberDesc.pstart = sfpBuf;
serialNumberDesc.size = serialNumberSize;
{
printf("%-16s ", sfpBuf);
}
else
{
printf("Bad error code while getting serial number on interface %d. (result = %d)\n", ifNum, result);
break;
}
free(sfpBuf);
{
printf("Bad error code getting sfp part number size.(result = %d)\n", result);
break;
}
if ((sfpBuf = (char*)malloc(partNumberSize)) == NULL)
{
printf("Could not allocate memory for part number.\n");
return 0;
}
memset(sfpBuf, 0, partNumberSize);
partNumberDesc.pstart = sfpBuf;
partNumberDesc.size = partNumberSize;
{
printf("%-16s ", sfpBuf);
}
else
{
printf("Bad error code while getting part number on interface %d. (result = %d)\n", ifNum, result);
break;
}
free(sfpBuf);
{
printf("Bad error code getting sfp vendor revision.(result = %d)\n", result);
break;
}
if ((sfpBuf = (char*)malloc(vendorRevSize)) == NULL)
{
printf("Could not allocate memory for vendor Revision.\n");
return 0;
}
memset(sfpBuf, 0, vendorRevSize);
vendorRevDesc.pstart = sfpBuf;
vendorRevDesc.size = vendorRevSize;
{
printf("%-8s ", sfpBuf);
}
else
{
printf("Bad error code while getting vendor revision on interface %d. (result = %d)\n", ifNum, result);
break;
}
free(sfpBuf);
{
printf("%-6d ", linkLength50um);
}
else
{
printf("Bad error code while getting link length(50um) on interface %d. (result = %d)\n", ifNum, result);
break;
}
{
printf("%-6d ", linkLength62_5um);
}
else
{
printf("Bad error code while getting link length(62_5um) on interface %d. (result = %d)\n", ifNum, result);
break;
}
{
printf("%-11d ", nominalSigRate);
}
else
{
printf("Bad error code while getting nominalSigRate on interface %d. (result = %d)\n", ifNum, result);
break;
}
{
printf("Bad error code getting sfp compliance size.(result = %d)\n", result);
break;
}
if ((sfpBuf = (char*)malloc(complianceSize)) == NULL)
{
printf("Could not allocate memory for compliance.\n");
return 0;
}
memset(sfpBuf, 0, complianceSize);
complianceDesc.pstart = sfpBuf;
complianceDesc.size = complianceSize;
{
printf("%-16s\n", sfpBuf);
}
else
{
printf("Bad error code while getting compliance on interface %d. (result = %d)\n", ifNum, result);
break;
}
free(sfpBuf);
}
if (headerPrinted == 0)
{
printf("SFP modules not plugged in.\n");
}
}
printf("\n");
printSFPModuleInfo(&clientHandle);
printf("\n");
printSystemPortLEDStatus(&clientHandle);
printf("\n");
printf("Port Locator:\n");
printf("\nSetting locator on ports 1, 3 and 5");
sleep(2);
{
printf("Bad error code setting port 1 (result = %d)\n", result);
break;
}
{
printf("Bad error code setting port 1 (result = %d)\n", result);
break;
}
{
printf("Bad error code setting port 1 (result = %d)\n", result);
break;
}
printf("\nDisabling port locator on port 3");
sleep(2);
{
printf("Bad error code disabling port 3 (result = %d)\n", result);
break;
}
printf("\nGlobally disabling port locator");
sleep(2);
{
printf("Bad error code disabling port locator (result = %d)\n", result);
break;
}
}
while (0);
L7PROC_LOGF (L7PROC_LOG_SEVERITY_INFO, 0,
"Stopping environment API example application");
printf("\n");
return 0;
}