OpenNSL API Guide and Reference Manual
example_rpc_app.c
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * (C) Copyright Broadcom Corporation 2013-2017
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  **********************************************************************
18  * \file example_rpc_app.c
19  *
20  * \brief Example code for testing OpenNSL client library
21  *
22  * \details This example demonstrates the OpenNSL client library usage
23  ************************************************************************/
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <opennsl/types.h>
29 #include <opennsl/error.h>
30 #include <opennsl/init.h>
31 #include <opennsl/port.h>
32 #include <sal/driver.h>
33 
34 char example_usage[] =
35 "Syntax: example_rpc_app \n\r"
36 " \n\r"
37 "Paramaters: None. \n\r"
38 " \n\r"
39 "Example: The following command is used to start the \n\r"
40 "opennsl RPC application. \n\r"
41 " example_rpc_app \n\r"
42 " \n\r"
43 "Usage Guidelines: None. \n\r";
44 
45 
46 /*****************************************************************/
54 int main(int argc, char *argv[])
55 {
56  int unit = 0, index = 0;
57  opennsl_error_t rval;
58  opennsl_info_t info;
59  opennsl_gport_t gport;
60  int max_units;
61  opennsl_port_config_t port_config;
62 
63  if(strcmp(argv[0], "gdb") == 0)
64  {
65  index = 1;
66  }
67 
68  if((argc != (index + 1)) || ((argc > (index + 1))
69  && (strcmp(argv[index + 1], "--help") == 0))) {
70  printf("%s\n\r", example_usage);
71  return OPENNSL_E_PARAM;
72  }
73 
74  /* Initialize the client library */
76 
77  printf("Invoking opennsl_info_get()\n");
78  rval = opennsl_info_get(unit, &info);
79  if (rval != OPENNSL_E_NONE)
80  {
81  printf("Failed to get the unit info:%d\n",rval);
82  }
83  else
84  {
85  printf("Device Info:%d %d\n",info.device,info.revision);
86  }
87 
88  printf("Invoking opennsl_port_gport_get()\n");
89  rval = opennsl_port_gport_get(unit, 2, &gport);
90  if (rval != OPENNSL_E_NONE)
91  {
92  printf("Failed to get the gport:%d\n",rval);
93  }
94  else
95  {
96  printf("local port:2 gport:%d\n", gport);
97  }
98 
99  printf("Invoking opennsl_attach_max()\n");
100  rval = opennsl_attach_max(&max_units);
101  if (rval != OPENNSL_E_NONE)
102  {
103  printf("Failed to get the max-units:%d\n",rval);
104  }
105  else
106  {
107  printf("max-units:%d\n", max_units);
108  }
109 
110  printf("Invoking opennsl_port_config_get()\n");
111  rval = opennsl_port_config_get(unit, &port_config);
112  if (rval != OPENNSL_E_NONE)
113  {
114  printf("Failed to get the port-config:%d\n",rval);
115  }
116  else
117  {
118  printf("%s:%d:\n \
119  ge-bmp: [%u, %u, %u, %u, %u, %u, %u, %u]\n \
120  xe-bmp: [%u, %u, %u, %u, %u, %u, %u, %u]\n \
121  ce-bmp: [%u, %u, %u, %u, %u, %u, %u, %u]\n \
122  port-bmp: [%u, %u, %u, %u, %u, %u, %u, %u]\n \
123  cpu-bmp: [%u, %u, %u, %u, %u, %u, %u, %u]\n \
124  all-bmp: [%u, %u, %u, %u, %u, %u, %u, %u]\n \
125  \n",__FUNCTION__,__LINE__,
126  port_config.ge.pbits[0],port_config.ge.pbits[1],port_config.ge.pbits[2],port_config.ge.pbits[3],
127  port_config.ge.pbits[4],port_config.ge.pbits[5],port_config.ge.pbits[6],port_config.ge.pbits[7],
128  port_config.xe.pbits[0],port_config.xe.pbits[1],port_config.xe.pbits[2],port_config.xe.pbits[3],
129  port_config.xe.pbits[4],port_config.xe.pbits[5],port_config.xe.pbits[6],port_config.xe.pbits[7],
130  port_config.ce.pbits[0],port_config.ce.pbits[1],port_config.ce.pbits[2],port_config.ce.pbits[3],
131  port_config.ce.pbits[4],port_config.ce.pbits[5],port_config.ce.pbits[6],port_config.ce.pbits[7],
132  port_config.port.pbits[0],port_config.port.pbits[1],port_config.port.pbits[2],port_config.port.pbits[3],
133  port_config.port.pbits[4],port_config.port.pbits[5],port_config.port.pbits[6],port_config.port.pbits[7],
134  port_config.cpu.pbits[0],port_config.cpu.pbits[1],port_config.cpu.pbits[2],port_config.cpu.pbits[3],
135  port_config.cpu.pbits[4],port_config.cpu.pbits[5],port_config.cpu.pbits[6],port_config.cpu.pbits[7],
136  port_config.all.pbits[0],port_config.all.pbits[1],port_config.all.pbits[2],port_config.all.pbits[3],
137  port_config.all.pbits[4],port_config.all.pbits[5],port_config.all.pbits[6],port_config.all.pbits[7]
138  );
139  }
140  return OPENNSL_E_NONE;
141 }
142 /* __doxy_func_body_end__ */
143