cint

Enter the C interpreter

cint

Run the C interpreter (Cint), interactively or on a file. See Cint: the C interpreter for how the interpreter works, The Cint language for the language and Cint recipes for ready-made programs.

Warning

Cint programs can call any SDK API function, so they can change anything on the switch behind the SAI’s back, and a wrong argument can crash syncd. Whether a program is safe depends entirely on what it calls.

Usage:

cint
cint [allow_file_info] <file> [<arg> …]
  • cint with no argument prints Entering C Interpreter. Type 'exit;' to quit. and switches to the cint> prompt. Leave it with exit; (or quit;). Through bcmcmd this leaves the session waiting at cint> until it times out, so use files there instead.

  • cint <file> [<arg> …] runs the file and returns to drivshell>. The file is read inside the syncd container; copy it there with sudo docker cp <file> syncd:/root/ (not into /tmp, see Cint: the C interpreter) and give an absolute path. The words after the file name are available to the program as ARGC and ARGV[0], ARGV[1], …. At most 16 are allowed (error: cannot pass more than 16 arguments, excluding the filename.). A file that cannot be opened prints error: could not open file '<file>'.

  • allow_file_info, as the first word (exact spelling), adds the file name and line number to run-time error messages. It is also passed to the program as ARGV[0].

cint always reports success to the shell, even when the program fails or the file is missing, so bcmcmd exits 0. Check the output for error lines (they start with ** or contain syntax error) and have programs print a completion line. The built-in help is only a placeholder (“cint usage goes here”).

Variables and functions defined by one run stay defined until cint_reset(); is called or syncd restarts; running the same file twice fails with identifier '<name>' redeclared unless it starts with cint_reset();.

The SAI’s own BCMSAI Cint is not available in this build; use this command.

Unvalidated

drivshell> cint /root/hello.c

Unvalidated

drivshell> cint allow_file_info /root/port_counters.c 5

Unvalidated

void hello_world() {
  bcm_info_t info;
  int unit = 0;
  int rv =  bcm_info_get(unit, &info);
  if (rv != BCM_E_NONE) {
    printf("Error in bcm_info_get: 0x%x, %s\n", rv, bcm_errmsg(rv));
    return;
  }
  print "Hello world from Cint! Here are some cool stats:";
  print info;
}
hello_world();

Hello world from Cint! Here are some cool stats:
bcm_info_t info = {
    unsigned int vendor = 5348 (0x14e4)
    unsigned int device = 47219 (0xb873)
    unsigned int revision = 1 (0x1)
    unsigned int capability = 13 (0xd)
    int num_pipes = 2 (0x2)
    int num_pp_pipes = 0 (0x0)
    int num_buffers = 0 (0x0)
}

Built-in help

cint usage goes here

Further reading

bcmsh.md (published as https://kamelnetworks.github.io/sonic/bcmsh.html), led.md (SONiC on Broadcom: LED debugging), SDK-6.5.20 HSDK Getting Started Guide (GS-SDK6520-R), plus SDK-6.5.20/21/22 Release Notes (RN-SDK65xx-R), OpenBCM sdk-6.5.27 CINT interpreter sources (src/appl/cint, src/appl/diag/cint) and Trident 3 CINT examples with logs (src/examples/xgs/TD3), OpenBCM sdk-6.5.27 SDK API headers (include/bcm/*.h) and the Cint registration data generated from them (bcm_cint_data.c), sonic-mgmt test suite files invoking bcmcmd (19 files), cPCI-6S10 Series 6U CompactPCI Switch Blade User’s Manual (50-15099-1000, Rev 1.0), 【交换芯片】硬件调测使用场景下的BMC交换常用命令说明, MPLS_cint脚本实现 (MPLS via CINT and diag commands).