Skip to content

Commit

Permalink
C: Add support for ATM AAL0 monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasl committed Feb 3, 2016
1 parent 4121820 commit 8b81d2f
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 4 deletions.
30 changes: 30 additions & 0 deletions c/gth_apilib.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,36 @@ int gth_install(GTH_api *api,
return result;
}

int gth_new_atm_aal0_monitor(GTH_api *api,
const int tag,
const char *span,
const int timeslots[],
const int n_timeslots,
char *job_id,
const char *ip,
const int port)
{
char command[MAX_COMMAND];
char sources[MAX_COMMAND];
int result;
const char* template;

assert(n_timeslots < 32 && n_timeslots > 0);

template = "<new><atm_aal0_monitor ip_addr='%s' ip_port='%d' tag='%d'>"
"%s</atm_aal0_monitor></new>";

format_sources(span, timeslots, n_timeslots, sources);

result = snprintf(command, MAX_COMMAND, template, ip, port, tag, sources);
assert(result < MAX_COMMAND);
api_write(api, command);
result = recv_job_id(api, job_id);

return result;
}


int gth_new_atm_aal2_monitor(GTH_api *api,
const int tag,
const char *span,
Expand Down
17 changes: 17 additions & 0 deletions c/gth_apilib.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,23 @@ int gth_map(GTH_api *api,
char *name,
int max_name);

// Start ATM AAL0 monitoring.
//
// The TCP port specified by (ip/port) is expected to be in a
// listening state before entering this function, e.g. by
// calling gth_make_listen_socket() first.
//
// This function writes the resulting job-id to job_id.
//
// Return: 0 on success
int gth_new_atm_aal0_monitor(GTH_api *api,
const int tag,
const char *span,
const int timeslots[],
const int n_timeslots,
char *job_id,
const char *ip,
const int port);

// Start ATM AAL2 monitoring.
//
Expand Down
59 changes: 55 additions & 4 deletions c/save_to_pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ struct GTH_mtp2_lapd {
char payload[MAX_SIGNAL_UNIT];
};

struct GTH_aal0 {
u32 gfc_vpi_vci;
char payload[MAX_SIGNAL_UNIT];
};

struct GTH_aal2 {
u32 gfc_vpi_vci;
// The first 3 bytes of the payload are the
Expand Down Expand Up @@ -212,6 +217,7 @@ enum Link_type {
enum Protocol {
MTP2,
LAPD,
AAL0,
AAL2,
AAL5
};
Expand Down Expand Up @@ -253,15 +259,15 @@ usage() {
"\n\nSave decoded signal units to a file in libpcap format, suitable for"
"\nexamining with wireshark, tshark or other network analyser software.\n"
"\n<options>: [-a vpi:vci] [-c] [-f <option>] [-m] [-n <rotation>]"
"\n [-p mtp2|lapd|aal2|aal5] [-v]\n"
"\n [-p mtp2|lapd|aal0|aal2|aal5] [-v]\n"
"\n-a <vpi:vci>: the ATM VPI and VCI (used together with -p AAL5)"
"\n-c: save in the classic Pcap format (default is the newer Pcap-NG)"
"\n-f fisu=no: remove all MTP-2 FISUs"
"\n-f esnf=yes: use MTP-2 extended sequence numbers"
"\n-m: tells the GTH that you are using a -20dB monitor point"
"\n-n <packets:c>: rotate the output file after <c> packets"
"\n-n <duration:s>: rotate the output file after <s> seconds"
"\n-p mtp2|lapd|aal2|aal5: select the signalling protocol"
"\n-p mtp2|lapd|aal0|aal2|aal5: select the signalling protocol"
"\n-v: print API commands and responses (verbose)"
"\n"
"\n<GTH-IP> is the GTH's IP address or hostname"
Expand Down Expand Up @@ -304,11 +310,15 @@ usage() {

fprintf(stderr,
"\nExample (ATM AAL5 in a VC-4 on SDH):\n"
"./save_to_pcap -p aal5 -a 0:5 172.16.1.10 sdh1:hop1_1 aal5_capture.pcapng\n\n");
"./save_to_pcap -p aal5 -a 0:5 172.16.1.10 sdh1:hop1_1 aal5_capture.pcapng\n");

fprintf(stderr,
"\nExample (ATM AAL2 on an E1):\n"
"./save_to_pcap -p aal2 -a 0:7 172.16.1.10 1A 1-15,17-31 aal2_capture.pcapng\n\n");
"./save_to_pcap -p aal2 -a 0:7 172.16.1.10 1A 1-15,17-31 aal2_capture.pcapng\n");

fprintf(stderr,
"\nExample (ATM AAL0 on an E1):\n"
"./save_to_pcap -p aal0 172.16.1.10 1A 1-15,17-31 aal0_capture.pcapng\n\n");

exit(-1);
}
Expand Down Expand Up @@ -591,6 +601,34 @@ monitor_lapd(GTH_api *api,
return;
}

// Start up AAL2 monitoring
static void
monitor_aal0(GTH_api *api,
const Channel_t *channel,
int tag,
int listen_port
)
{
int result;
char job_id[MAX_JOB_ID];

if (strstr(channel->source, "sdh")) {
die("AAL0 monitoring is not currently supported in a VC-4 or VC-3");
}

result = gth_new_atm_aal0_monitor(api, tag,
channel->source,
channel->timeslots,
channel->n_timeslots,
job_id, api->my_ip, listen_port);

if (result != 0)
die("Setting up AAL0 monitoring failed. (-v gives more information)");

return;
}


// Start up AAL2 monitoring
static void
monitor_aal2(GTH_api *api,
Expand Down Expand Up @@ -1110,6 +1148,13 @@ write_lapd(HANDLE_OR_FILEPTR file, struct GTH_su *signal_unit, int length)
write_mtp2(file, signal_unit, length - 2);
}

// Wireshark doesn't have anything for AAL0. So just dump the raw data.
static void
write_aal0(HANDLE_OR_FILEPTR file, struct GTH_su *signal_unit, int length)
{
write_mtp2(file, signal_unit, length);
}

static void
write_aal2(HANDLE_OR_FILEPTR file, struct GTH_su *signal_unit, int length)
{
Expand Down Expand Up @@ -1231,6 +1276,7 @@ convert_to_pcap(GTH_api *api, int data_socket)
read_exact(data_socket, (void*)&signal_unit, length);

switch (options.protocol) {
case AAL0: write_aal0(file, &signal_unit, length); break;
case AAL2: write_aal2(file, &signal_unit, length); break;
case AAL5: write_aal5(file, &signal_unit, length); break;
case MTP2: write_mtp2(file, &signal_unit, length); break;
Expand Down Expand Up @@ -1512,6 +1558,10 @@ process_arguments(char **argv,
opts->protocol = LAPD;
opts->link_type = LINK_TYPE_LAPD;
}
else if (!strcmp("aal0", argv[2])) {
opts->protocol = AAL0;
opts->link_type = 0;
}
else if (!strcmp("aal2", argv[2])) {
opts->protocol = AAL2;
opts->link_type = LINK_TYPE_NG40;
Expand Down Expand Up @@ -1561,6 +1611,7 @@ static Start_function
lookup_start_function(enum Protocol protocol)
{
switch (protocol) {
case AAL0: return &monitor_aal0; break;
case AAL2: return &monitor_aal2; break;
case AAL5: return &monitor_aal5; break;
case LAPD: return &monitor_lapd; break;
Expand Down

0 comments on commit 8b81d2f

Please sign in to comment.