Open Ethernet Networking (OpEN) API Guide and Reference Manual  3.6.0.3
sdkportregbyname.c
/*********************************************************************
*
* Copyright 2016-2018 Broadcom.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***********************************************************************
*
* @filename sdkportregbyname.c
*
* @purpose Direct access to SDK registers by their name
* @detail Example application that uses the OpEN API to directly
* access an SDK register (by name) and display its
* contents.
*
* @note none
*
* @create 11/26/2012
*
* @end
*
**********************************************************************/
#include <stdlib.h>
#include <unistd.h>
#include "rpcclt_openapi.h"
#include "proc_util.h"
#include "openapi_common.h"
/***************************************************************/
int
main(int argc, char *argv[])
{
open_error_t result;
open_buffdesc switch_os_revision;
open_buffdesc regName;
uint64_t val = 0;
uint32_t ifNum;
openapiClientHandle_t clientHandle;
char switch_os_revision_string[100];
char name [100];
if (argc != 3 || !argv[1])
{
printf("Usage: %s <regname> <port> \n", argv[0]);
exit(1);
}
memcpy(name, argv[1], sizeof(name));
regName.pstart = name;
regName.size = sizeof(name);
ifNum = atoi(argv[2]);
l7proc_crashlog_register ();
/* Register with OpEN */
if ((result = openapiClientRegister ("sdkportregbyname", &clientHandle)) != OPEN_E_NONE)
{
printf ("\nFailed to initialize RPC to OpEN. Exiting (result = %d)\n",
result);
exit (2);
}
/* RPC call can fail until server starts. Keep trying */
while (openapiConnectivityCheck (&clientHandle) != OPEN_E_NONE)
{
sleep (1);
}
L7PROC_LOGF (L7PROC_LOG_SEVERITY_INFO, 0,
"Starting SDK port register access by name API example application");
printf ("\n");
switch_os_revision.pstart = switch_os_revision_string;
switch_os_revision.size = sizeof (switch_os_revision_string);
if (openapiNetworkOSVersionGet (&clientHandle, &switch_os_revision) ==
printf ("Network OS version = %s\n", switch_os_revision_string);
else
printf ("Network OS version retrieve error\n");
printf ("\n");
if ((result = openapiSdkPortRegReadByName(&clientHandle, 0, &regName, ifNum, &val)) != OPEN_E_NONE)
{
printf(" Bad return code trying to read the register. (result = %d)\n",result);
return 0;
}
else
{
printf("reg = %s val = 0x%llx\n", name, val);
}
/* Log goodbye message with OPEN */
L7PROC_LOGF (L7PROC_LOG_SEVERITY_INFO, 0,
"Stopping SDK register read by name example application");
return 0;
}