From 3dc72b8cff16ffcc9babab9a9892befda44d8c4e Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 9 Jul 2010 20:57:43 +0200 Subject: update to sualibrary-0.1.2 from 2002-11-26 * Contains Relaying functionality using hostnames. * Correct some bugs * Compiles and runs on Linux, FreeBSD, Max OS X .... * Tested on IPv4 and IPV6 networks * interoperable with other SUA implementations * corresponds to sua draft v13 * requires SCTP implementation sctplib-1.0.0-pre19 from www.sctp.de --- sualibrary/sua/sua_file.cpp | 213 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 192 insertions(+), 21 deletions(-) (limited to 'sualibrary/sua/sua_file.cpp') diff --git a/sualibrary/sua/sua_file.cpp b/sualibrary/sua/sua_file.cpp index c5ad667..a901992 100644 --- a/sualibrary/sua/sua_file.cpp +++ b/sualibrary/sua/sua_file.cpp @@ -15,9 +15,9 @@ * * ***************************************************************************/ /* - * $Id: sua_file.cpp,v 1.1.1.1 2002/02/04 14:30:41 p82609 Exp $ + * $Id: sua_file.cpp,v 1.3 2002/11/12 11:02:49 p82609 Exp $ * - * SUA implementation according to SUA draft issue 6. + * SUA implementation according to SUA draft issue 13. * * Author(s): Lode Coene * @@ -80,11 +80,13 @@ using namespace std; - +/***********************************************************************/ +/* get_argument */ +/***********************************************************************/ string get_argument(string line, - int& begin, - int& end, - unsigned int& num_of_char_in_line) + int& begin, + int& end, + unsigned int& num_of_char_in_line) { int len = 0; bool cont = true; @@ -125,7 +127,9 @@ string get_argument(string line, return(sua_arg); } - +/***********************************************************************/ +/* read sua file */ +/***********************************************************************/ int read_sua_file(string filename, db_Sua_LocalList& local_sua, db_Sua_RemoteList& remote_sua, @@ -149,17 +153,22 @@ int read_sua_file(string filename, cout << "file to read = " << filename << " \n"; #endif cout << "SUA local sua instantation parameters(mandatory) \n"; - cout << "-s x.x.x.x -l yyy [-u] \n"; + cout << "-s[n] x.x.x.x -l yyy [-7s 7777] [-gs tt-nat-np-digits][-u] \n"; cout << "-s : source address \n"; cout << "-l : source local sua portnumber \n"; + cout << "-sn: source name \n"; + cout << "-7s: source SS7 pointcode\n"; cout << "-u : listen on local port number \n"; cout << "SUA parameters of the sua tester (optional)\n"; cout << "Not supported yet (-b 1000 -o -v) \n"; cout << "SUA parameters of the SUA remote instantation(s) (optional)\n"; - cout << "-d x.x.x.x -r yyy [-g tt-nat-np-digits] [-a ASnumber] \n"; + cout << "-d[n] x.x.x.x -r yyy [-7d 7777] [-gd tt-nat-np-digits] [-a ASnumber] \n"; cout << "-d : destination address \n"; cout << "-r : destination sua portnumber \n"; - cout << "-g : global title(TTID-NAT-NUMPLAN-Digits) linked to destination address \n"; + cout << "-dn: destination name \n"; + cout << "-7d: destination SS7 pointcode\n"; + cout << "-gs: source global title(TTID-NAT-NUMPLAN-Digits) linked to -s address or -sn name \n"; + cout << "-gd: destination global title(TTID-NAT-NUMPLAN-Digits) linked to -d address or -dn name\n"; cout << "-a : Application Server(AS) this address belongs to \n"; ifstream infile(filename.c_str()); @@ -209,7 +218,7 @@ int read_sua_file(string filename, Assoc_sua.instance[Assoc_sua.num_of_instance].nr_of_outbound_streams = 1; if (ch2 == 'n') { - ip_addr_str = NameDB_sua.read_host_name(address_str); + ip_addr_str = Assoc_sua.read_host_name(NameDB_sua, address_str); Assoc_sua.read_Source_addr(ip_addr_str); } else { @@ -235,7 +244,7 @@ int read_sua_file(string filename, present_remote_instance = 0; } if (ch2 == 'n') { - ip_addr_str = NameDB_sua.read_host_name(address_str); + ip_addr_str = Assoc_sua.read_host_name(NameDB_sua, address_str); Assoc_sua.read_Dest_addr(ip_addr_str); } else { @@ -328,6 +337,36 @@ int read_sua_file(string filename, num_of_arg++; break; } + case 'g': + { + /* read global title */ + switch (ch2) + { + case 's': // read source Global Title for sua + { + num_of_arg++; + address_str = get_argument(sua_line,b,e,num_of_char_in_line); + + Assoc_sua.read_Source_GT(NameDB_sua, address_str); + + break; + } + case 'd': + { // read destination Global Title for sua + num_of_arg++; + address_str = get_argument(sua_line,b,e,num_of_char_in_line); + + Assoc_sua.read_Dest_GT(NameDB_sua, address_str); + + break; + } + default: + { + break; + } + } + break; + } case 'i': { // ignore character, is not a error, go to next argument @@ -341,16 +380,16 @@ int read_sua_file(string filename, { num_of_arg++; address_str = get_argument(sua_line,b,e,num_of_char_in_line); - + Assoc_sua.read_Source_pointcode(address_str); - + break; } case 'd': { // read destination pointcode for sua num_of_arg++; address_str = get_argument(sua_line,b,e,num_of_char_in_line); - + Assoc_sua.read_Dest_pointcode(address_str); break; @@ -375,27 +414,159 @@ int read_sua_file(string filename, break; } } - sua_arg = get_argument(sua_line,b,e,num_of_char_in_line); - num_of_arg++; + sua_arg = get_argument(sua_line,b,e,num_of_char_in_line); + num_of_arg++; } // finished reading the whole line num_of_char = num_of_char + num_of_char_in_line; cout << "Line " << num_of_lines << " : " << sua_line << "\n"; } - + #ifdef DEBUG cout << "End of file: statistics \n"; cout << "Number of lines = " << num_of_lines <<"\n"; cout << "Number of characters in file = " << num_of_char << "\n"; - + #endif - + return (0); - + } /* end of read_sua_file */ +/***********************************************************************/ +/* create host parameter handling */ +/***********************************************************************/ +void sua_cr_host( string host_parm_str, + db_Sua_LocalList& local_sua + ) +{ + int host_id; + /* get host id from param string, use as index in local_sua table */ + + host_id = 1; + + string ip_addr_str( host_parm_str, (host_parm_str.find("org_ip=")+7),host_parm_str.length()); + /* get all(=multihomed) addresses till next parameter */ + /* fill in IP address as string in local_sua */ + /*local_sua.instance[host_id].ip_addr_str = ip_addr_str;*/ + + /* get the local port number for this instance */ + /* local_sua.instance[host_id].portnumber=14001 */ + + /* get the local ssn for this local sua host instantiation */ + /* local_sua.instance[host_id].ssn = 5 */ + + /* get the number of streams supported for this sua instantiation */ + /* local_sua.instance[host_id].streams=16 */ + +} + +/***********************************************************************/ +/* create association parameter handling */ +/***********************************************************************/ +void sua_cr_assoc( string assoc_parm_str, + db_Sua_AssociationList& Assoc_sua, + db_Sua_LocalList& local_sua + ) +{ + int assoc_id; + /* get assoc id from param string, use as index in assoc_sua table */ + + assoc_id = 1; + + string ip_addr_str( assoc_parm_str, (assoc_parm_str.find("dest_ip=")+8),assoc_parm_str.length()); + /* get all(=multihomed) addresses till next parameter */ + /* fill in IP address as string & network in assoc_sua */ + /* Assoc_sua.instance[assoc_id].ip_addr_str = ip_addr_str;*/ + + /* get the local port number for this instance */ + /* Assoc_sua.instance[assoc_id].portnumber=14001 */ + + /* get the local ssn for this local sua host instantiation */ + /* local_sua.instance[host_id].ssn = 5 */ + + /* get the number of streams supported for this sua instantiation */ + /* local_sua.instance[host_id].streams=16 */ + +} + +/***********************************************************************/ +/* read sua configuration file */ +/***********************************************************************/ +int read_sua_conf_file( string filename, + db_Sua_DatabaseList sua + ) +{ + string sua_filename; + string sua_arg; + char readBuffer[256]; + + cout << "SUA configuration file to read = " << filename << " \n"; + + cout << "SUA local sua instantation parameters(mandatory) \n"; + cout << "cr host:host_id = j, org_ip= t.t.t.t, org_port= yyyyy \n"; + cout << "cr assoc:assoc_id= i, init= false, host_id = j, dest_ip = x.x.x.x, dest_port= yyyy \n"; + cout << "cr orgpc: pc = wwww, host_id = j\n"; + cout << "cr destpc: pc = wwww, rc = x \n"; + cout << "cr hostname: namegt_id= k name= www.sctp.be \n"; + cout << "cr gt:namegt_id = k,tt= tt, na= nn, np= ppp, digits= 123456789abcdef \n"; + cout << "cr route: dpc= www, assoc_id = i AND/OR\n"; + cout << "cr route: dest_ip = x.x.x.x, assoc_id = i AND/OR\n"; + cout << "cr route: namegt_id= k, assoc_id = i \n"; + + ifstream infile(filename.c_str()); + + while (infile.getline(readBuffer,256,'\n')) + { + string cmdline(readBuffer,strlen(readBuffer)); + + if (cmdline.length() == 0) + { + cout << "empty line?\n"; + } + else if (cmdline.find("/") != cmdline.npos) + { + /* comment line: do not execute */ + } + else if (cmdline.find("cr host:") != cmdline.npos) + { + string parm_str( cmdline, (cmdline.find("cr host:")+8),cmdline.length()); + sua_cr_host( parm_str, + sua.local_sua + ); + } + else if (cmdline.find("cr assoc:") != cmdline.npos) + { + string parm_str( cmdline, (cmdline.find("cr assoc:")+9),cmdline.length()); + sua_cr_assoc( parm_str, + sua.AssocDB, + sua.local_sua + ); + } + else if (cmdline.find("cr destpc:") != cmdline.npos) + { + + } + else if (cmdline.find("cr hostname:") != cmdline.npos) + { + + } + else if (cmdline.find("cr gt:") != cmdline.npos) + { + + } + else if (cmdline.find("cr xxxx:") != cmdline.npos) + { + + } + else + cout << "ERROR: Unknown " << cmdline << "command\n"; + } +} /* end of read_sua_conf_file */ // end of module sua_file.c + + -- cgit v1.2.3