aboutsummaryrefslogtreecommitdiffstats
path: root/sualibrary/sua/sua_file.cpp
blob: c5ad66702b72235f797f12b84d7fe37ecda7dc2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
/***************************************************************************
                          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 <unistd.h>
#endif

#include "sua_debug.h"
#include "sua_database.h"

#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream>

#include <netinet/in_systm.h>
#include <netinet/ip.h>         /* includes <netinet/in.h> also ! */
#include <netinet/ip_icmp.h>
#include <netdb.h>
#include <arpa/inet.h>

#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