Project

General

Profile

Actions

Feature #1680

closed

OsmoNITB - Bug #1604: Easier / more direct SIP integration

osmo-sip-connector: Add show VTY commands

Added by zecke almost 8 years ago. Updated over 5 years ago.

Status:
Resolved
Priority:
High
Assignee:
Target version:
-
Start date:
03/31/2016
Due date:
% Done:

100%

Resolution:
Spec Reference:

Description

Add show calls and maybe other commands to list calls and legs and their individual state.

Actions #1

Updated by laforge almost 8 years ago

  • Category set to osmo-sip-connector
Actions #2

Updated by laforge about 7 years ago

  • Project changed from OsmoNITB to osmo-sip-connector
  • Category deleted (osmo-sip-connector)
Actions #3

Updated by laforge over 6 years ago

Actions #4

Updated by laforge about 6 years ago

  • Assignee changed from zecke to 4368
Actions #5

Updated by laforge over 5 years ago

  • Assignee changed from 4368 to osmith
Actions #6

Updated by laforge over 5 years ago

  • Priority changed from Normal to High
Actions #7

Updated by neels over 5 years ago

little VTY code intro:

example from osmo-bsc: osmo-bsc.git/src/osmo-bsc/bsc_vty.c

DEFUN(show_bts, show_bts_cmd, "show bts [<0-255>]",
        SHOW_STR "Display information about a BTS\n" 
                "BTS number")
{
        struct gsm_network *net = gsmnet_from_vty(vty);
        int bts_nr;

        if (argc != 0) {
                /* use the BTS number that the user has specified */
                bts_nr = atoi(argv[0]);
                if (bts_nr >= net->num_bts) {
                        vty_out(vty, "%% can't find BTS '%s'%s", argv[0],
                                VTY_NEWLINE);
                        return CMD_WARNING;
                }
                bts_dump_vty(vty, gsm_bts_num(net, bts_nr));
                return CMD_SUCCESS;
        }
        /* print all BTS's */
        for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++)
                bts_dump_vty(vty, gsm_bts_num(net, bts_nr));

        return CMD_SUCCESS;
}

[...]

        install_element_ve(&show_bts_cmd);

The DEFUN comes from libosmocore/include/osmocom/vty/command.h.

DEFUN(my_invented_name, my_invented_name_cmd,
      "my invented name (with|options)",
      "Documentation for 'my' keyword\n"  // <-- for the docs, no comma! just a str separated by newlines
      "Documentation for 'invented' keyword\n" 
      "Doc for 'name'\n" 
      "Doc for 'with'\n" 
      "Doc for 'options'\n")
{
    vty_out(vty, "selected option was '%s'.%s", argv[0], VTY_NEWLINE); // <-- always use VTY_NEWLINE!
    return CMD_SUCCESS;
}

then, in some init func, place the _cmd at the VTY nodes, e.g. on the VIEW and ENABLE nodes with

  install_element_ve(&my_invented_name_cmd);

In the VTY, you typically don't do input validation, since the command description already ensures that the input matches. In above example, just strcmp("option", argv[0 ]), no need to do something like 'else vty_out(vty, "unknown command!%s", VTY_NEWLINE);'.

braces indicate (alternatives|...), <numbers>, [args-that-can-be-omitted], and all-caps means unvalidated arbitrary argument.

my command (keyword|choices) <0-9> [(optional|arg)] [optional_arg2]
my command2 FREE_FORMAT_STR

So, the example above is a VTY command invoked as one of

show bts
show bts 0

Often, it makes sense to not use optional [args], but instead create two separate DEFUN, one with and one without the arg.

Actions #8

Updated by neels over 5 years ago

and btw, each of our manuals has an introductory chapter describing the vty interaction and nodes... e.g. chapter 8 in https://ftp.osmocom.org/docs/latest/osmobsc-usermanual.pdf

There are also separate auto-generated VTY reference manuals; less interesting / identical to the VTY cmdline online help.

Actions #9

Updated by osmith over 5 years ago

  • Status changed from New to In Progress
Actions #10

Updated by osmith over 5 years ago

Thanks for the detailed intro neels! I was quite surprised to see that the show calls command is already available. From what I can tell, it shows the call legs and their states, see the example output below.

No active calls gives no output:

OsmoSIPcon> show calls

Phone ringing:

OsmoSIPcon> show calls
Call(5002) from 101 to 100
 Initial leg of type: SIP
 SIP nua_handle(0x562e70121080)
 SIP state(CONFIRMED)
 SIP dir(MO)
 SIP wanted_codec((null))
 Remote leg of type: MNCC
 MNCC state(INITIAL)
 MNCC dir(MT)
 MNCC callref(5002)
 MNCC called TON(0) NPI(0) NUM()
 MNCC calling TON(0) NPI(0) NUM()
 MNCC imsi()
 MNCC timer pending(0)
Call(5001) from 101 to 100
 Initial leg of type: MNCC
 MNCC state(PROCEEDING)
 MNCC dir(MO)
 MNCC callref(2147483649)
 MNCC called TON(0) NPI(1) NUM(100)
 MNCC calling TON(0) NPI(0) NUM(101)
 MNCC imsi(9017000000xxxxx)
 MNCC timer pending(0)
 Remote leg of type: SIP
 SIP nua_handle(0x562e7011bbd0)
 SIP state(CONFIRMED)
 SIP dir(MT)
 SIP wanted_codec(GSM)

Ongoing phone call:

OsmoSIPcon> show calls
Call(5004) from 100 to 101
 Initial leg of type: SIP
 SIP nua_handle(0x562e70121110)
 SIP state(CONNECTED)
 SIP dir(MO)
 SIP wanted_codec(GSM)
 Remote leg of type: MNCC
 MNCC state(CONNECTED)
 MNCC dir(MT)
 MNCC callref(5004)
 MNCC called TON(0) NPI(0) NUM()
 MNCC calling TON(0) NPI(0) NUM()
 MNCC imsi()
 MNCC timer pending(0)
Call(5003) from 100 to 101
 Initial leg of type: MNCC
 MNCC state(CONNECTED)
 MNCC dir(MO)
 MNCC callref(2147483650)
 MNCC called TON(0) NPI(1) NUM(101)
 MNCC calling TON(0) NPI(0) NUM(100)
 MNCC imsi(9017000000xxxxx)
 MNCC timer pending(0)
 Remote leg of type: SIP
 SIP nua_handle(0x562e7011bbd0)
 SIP state(CONNECTED)
 SIP dir(MT)
 SIP wanted_codec(GSM)


Is there anything left to do here?

Actions #11

Updated by laforge over 5 years ago

Actions #14

Updated by osmith over 5 years ago

Laforge gave the following feedback:
  • show calls should provide better output, imagine a huge network with many calls at once
    • maybe a table with one call per line
    • maybe filters for phone number prefixes
  • update the documentation to mention how to use the feature there
Actions #15

Updated by osmith over 5 years ago

  • % Done changed from 0 to 10
Actions #16

Updated by osmith over 5 years ago

  • % Done changed from 10 to 0

After looking at the code, I found that there's also a show calls summary command.
It prints two lines for each call (one for each leg), in the following format:

Call(%u) initial(type=%s,state=%s) remote(type=%s,state=%s)

(I did not save example output this time, but I can do it if someone's curious.)
The call ID is an internal ID (e.g. 5002).

Regarding documentation, both show calls and show calls summary are in the VTY reference. But it doesn't talk about the format in detail, so I guess it should be fine if we change it to something more useful.

I'm working on only displaying one line now, and displaying the actual phone numbers of who is calling who by going through the structs. As a first success, one number was correctly picked out here:

OsmoSIPcon> show calls summary                         
Call(5002): mncc leg is remote leg
number:
Call(5001): mncc leg is initial leg   
number: 101

WIP branch (not ready for review): osmith/add-show-calls-commands

Actions #17

Updated by osmith over 5 years ago

  • % Done changed from 0 to 90
Actions #18

Updated by osmith over 5 years ago

laforge asked me to align the commits, and I did that (see the gerrit review). The ID is aligned to 5 characters now. But it is an unsigned int, which means it can have up to 20 characters (len(str(2 ** 64))) on x86_64.

laforge added:
  • "you could print it everywhere in hex to reduce it to 16 digits"
  • "or alternatively we'd have to recycle the numbers faster by restricting the range"
  • the maximum width of the output must be 80 characters (we are at 82 already with the short ID column)

So changing to hex won't make it small enough, leaving only the two options of making the number range smaller or ignoring the 80 character limit.

I would recommend to ignore the 80 character limit in this case to be honest, because changing the program logic just to work around that limit doesn't seem worth it in my opinion. We would also run into the same problem as soon as we added a new column, for example for the duration of the call.

For what it's worth, the output of osmo-bsc --version and other programs also does not fit the 80 characters.

Actions #19

Updated by osmith over 5 years ago

  • Status changed from In Progress to Resolved
  • % Done changed from 90 to 100

Patch was merged.

Actions

Also available in: Atom PDF

Add picture from clipboard (Maximum size: 48.8 MB)