/*************************************************************************** sua_file.cpp - description ------------------- begin : Tue Jan 8 2002 copyright : (C) 2002 by Lode Coene email : lode.coene@siemens.atea.be ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /* * $Id: sua_file.cpp,v 1.1.1.1 2002/02/04 14:30:41 p82609 Exp $ * * SUA implementation according to SUA draft issue 6. * * Author(s): Lode Coene * * * Copyright (C) 2001 by Siemens Atea, Herentals, Belgium. * * Realized in co-operation between Siemens Atea and * Siemens AG, Munich, Germany. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Contact: gery.verwimp@siemens.atea.be * lode.coene@siemens.atea.be * * The alternative comment * inspiration : Martine * "This is the module of the fallen function with the big files by * "Von Craenendonck!" * "This module contains some real schoftware" * * Purpose: This code-file defines the SUA file access functions for: * - get a argument in the line(delimited by a space) * - read the sua file(containing arguments for the SUA database) */ #ifdef LINUX #include #endif #include "sua_debug.h" #include "sua_database.h" #include #include #include #include #include #include #include /* includes also ! */ #include #include #include #define SUA_PORT 14001 #define SUA_PPI 4 using namespace std; string get_argument(string line, int& begin, int& end, unsigned int& num_of_char_in_line) { int len = 0; bool cont = true; while ((num_of_char_in_line <= line.length()) && (cont)) { if ((line[num_of_char_in_line] == ' ') || (num_of_char_in_line >= line.length())) { end = num_of_char_in_line - 1; len = num_of_char_in_line - begin; cont = false; } num_of_char_in_line++; } char *temp = new char[len]; // convert to lowercase characters for easier processing int i=0; for(i = 0; i < len ; i++) temp[i] = tolower(line[begin+i]); string sua_arg(temp, len); #ifdef DEBUGFILE cout << "indexes = "<< begin << " , " << end << " , " << len << "\n"; cout << temp << "\n"; cout << "got argument = " << sua_arg << " \n"; char v; cin >> v; #endif begin = end + 2; end = 0; delete temp; return(sua_arg); } int read_sua_file(string filename, db_Sua_LocalList& local_sua, db_Sua_RemoteList& remote_sua, db_Sua_AssociationList& Assoc_sua, db_Sua_NameList& NameDB_sua, db_Sua_ASList& ApplicServ_sua ) { string sua_filename; string sua_arg; string address_str,ip_addr_str; char ch1, ch2; string sua_line; int num_of_char = 0; int num_of_arg = 0; int num_of_lines = 0; int present_local_instance = 0; int present_remote_instance = 0; #ifdef DEBUG 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 : source address \n"; cout << "-l : source local sua portnumber \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 : destination address \n"; cout << "-r : destination sua portnumber \n"; cout << "-g : global title(TTID-NAT-NUMPLAN-Digits) linked to destination address \n"; cout << "-a : Application Server(AS) this address belongs to \n"; ifstream infile(filename.c_str()); while (getline(infile, sua_line)) { num_of_lines++; // analyse input line and split up in arguments according to // the spaces in the line: each argument is then processed unsigned int num_of_char_in_line = 0; int b=0, e=0; bool next_arg; sua_arg = get_argument(sua_line,b,e,num_of_char_in_line); next_arg = false; // make selection on cmd argument while (num_of_char_in_line < sua_line.length()) { ch2 = ' '; if (sua_arg[0] == '-') { ch1 = sua_arg[1]; ch2 = sua_arg[2]; } else if (sua_arg[0] == '/') ch1 = sua_arg[0]; else { cout << "weird option \n"; ch1 = ' '; } switch (ch1) { case 's': // read source addresses for sua { num_of_arg++; address_str = get_argument(sua_line,b,e,num_of_char_in_line); if (present_local_instance > 0) { present_local_instance= 0; } local_sua.increase_instance(); Assoc_sua.increase_instance(); present_remote_instance = 0; Assoc_sua.instance[Assoc_sua.num_of_instance].local_sua_id = local_sua.num_of_instance; Assoc_sua.instance[Assoc_sua.num_of_instance].nr_of_inbound_streams = 1; 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); Assoc_sua.read_Source_addr(ip_addr_str); } else { Assoc_sua.read_Source_addr(address_str); } present_local_instance++; break; } case 'd': { // read destination addresses for sua num_of_arg++; address_str = get_argument(sua_line,b,e,num_of_char_in_line); remote_sua.increase_instance(); if (present_remote_instance > 0) { Assoc_sua.increase_instance(); Assoc_sua.instance[Assoc_sua.num_of_instance].Source = Assoc_sua.instance[Assoc_sua.num_of_instance-1].Source; Assoc_sua.instance[Assoc_sua.num_of_instance].local_sua_id = Assoc_sua.instance[Assoc_sua.num_of_instance-1].local_sua_id; Assoc_sua.instance[Assoc_sua.num_of_instance].nr_of_inbound_streams = 1; Assoc_sua.instance[Assoc_sua.num_of_instance].nr_of_outbound_streams = 1; present_remote_instance = 0; } if (ch2 == 'n') { ip_addr_str = NameDB_sua.read_host_name(address_str); Assoc_sua.read_Dest_addr(ip_addr_str); } else { Assoc_sua.read_Dest_addr(address_str); } Assoc_sua.instance[Assoc_sua.num_of_instance].remote_sua_id = remote_sua.num_of_instance; present_remote_instance++; break; } case 'l': { // read local portnumber for sua num_of_arg++; address_str = get_argument(sua_line,b,e,num_of_char_in_line); Assoc_sua.read_Source_port(address_str); break; } case 'r': { // read remote portnumber for sua num_of_arg++; address_str = get_argument(sua_line,b,e,num_of_char_in_line); Assoc_sua.read_Dest_port(address_str); break; } case 'a': { // read Application Server number this remote ASP belongs to num_of_arg++; address_str = get_argument(sua_line,b,e,num_of_char_in_line); Assoc_sua.instance[Assoc_sua.num_of_instance].asp.linked_to_AS[0] = ApplicServ_sua.read_AS(address_str, Assoc_sua.num_of_instance ); break; } case 'b': { num_of_arg++; address_str = get_argument(sua_line,b,e,num_of_char_in_line); #ifdef DEBUG cout << "discard option b \n"; #endif } case 'n': { // read sybsytem number = SSN (valid for both local and remote) num_of_arg++; address_str = get_argument(sua_line,b,e,num_of_char_in_line); remote_sua.read_ssn(address_str); local_sua.read_ssn(address_str); break; } case 'q': // read QOS fields for sua { num_of_arg++; address_str = get_argument(sua_line,b,e,num_of_char_in_line); break; } case 'u': { // break; } case 'm': { // break; } case 'o': { // break; } case 't': { // number of streams incoming AND outgoing num_of_arg++; address_str = get_argument(sua_line,b,e,num_of_char_in_line); Assoc_sua.read_stream_number(address_str); break; } case 'v': { // break; } case 'f': { // file option: we are in file mode could later be used for // recursive filereading. Ignore for the moment num_of_arg++; break; } case 'i': { // ignore character, is not a error, go to next argument break; } case '7': { /* read SS7 pointcodes */ switch (ch2) { case 's': // read source pointcode for sua { 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; } default: { break; } } break; } case '/': { // comment: skip this line num_of_char_in_line = num_of_char_in_line + sua_line.length(); b=0; e=0; break; } default: { break; } } 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 */ // end of module sua_file.c