aboutsummaryrefslogtreecommitdiffstats
path: root/sualibrary/sua/sua_database.cpp
blob: ce953e126f51eaf9e1aa0fe0738a51a1c26029aa (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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
/***************************************************************************
                          sua_database.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_database.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 : Ann V.
 * "What does reuse of code mean if the code is NOT even used yet."
 *
 * Purpose: This code-file defines the SUA database access functions for:
 *          - dummy Indication Notifications
 *          - dummy DISxx indciation Notifications
 *          Sybsystem Number(SSN) Object:
 *          - read SSN
 *          Address Object:
 *          - read IP address parameter
 *          - read IP portnumber
 *          Local SUA Object:
 *          - initialise Local SUA Object
 *          Local SUA List:
 *          - initialise Local SUA List
 *          - read SSN
 *          - increase instance
 *          - unregister instance
 *          - register instance
 *          Remote SUA object:  
 *          - initialise Remote SUA Object
 *          Remote SUA List      
 *          - initialise Remote SUA list
 *          - read SSN   
 *          - increase instance
 *          SUA Application Server list
 *          - initialise AS List
 *
 */

#include "sctp.h"

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

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

#include "unistd.h"



using namespace std;


/***********************************************************************/
/*Initialisation dummy functions for the object class SUA List & Object*/
/***********************************************************************/
void db_dummy_xxxxIndNotif ( unsigned int   local_sua_Id,
			     unsigned int   primitive,
			     unsigned int   datalen
			   )
{
  cout << "You've just called the dummy_xxxxIndNotif function ! \n";
  cout << "Better check youre initialisation and registration !! \n";
}

void db_dummy_DisxIndNotif ( unsigned int   local_sua_Id,
			     unsigned int   primitive,
			     unsigned int   cause,
			     unsigned int   datalen
			   )
{
  cout << "You've just called the dummy_DisxIndNotif function ! \n";
  cout << "Better check youre initialisation and registration !! \n";
}
/***********************************************************************/
/* functions of the object class SUA SSN Object                        */
/***********************************************************************/

/***********************************************************************/
/* Sua_SSNObject::read_ssn                                             */
/***********************************************************************/
void db_Sua_SSNObject::read_ssn(string ssn_str){

  char *tokstr = new char[ssn_str.length()+1];
  short sua_ssn;


  ssn_str.copy(tokstr,ssn_str.length());
  tokstr[ssn_str.length()] = '\0';
  sua_ssn = atoi(tokstr);
 
  ssn = sua_ssn;

#ifdef DEBUG
  //cout << "SSN value = " << sua_ssn << "\n";
#endif
};

/***********************************************************************/
/* functions of the object class SUA Address Object                    */
/***********************************************************************/

/***********************************************************************/
/* Sua_AddressObject::read_addr_param                                  */
/***********************************************************************/
void db_Sua_AddressObject::read_addr_param(string address_str){
  int b=0,len=0,count_punct=0, count_colon=0;
  unsigned int i=0;
  int tokstr_len = 0;
  char *tokstr;
  int result;

#ifdef DEBUG
  cout << "address = " << address_str << " len = " <<address_str.length() << "\n";
#endif

  while ((i  <= address_str.length()))
     {
       if (address_str[i] == '.') count_punct++;
       if (address_str[i] == ':') count_colon++;
       if ((address_str[i] == ',') || (i == address_str.length()))
	 {
	   len = i - b;
	   string dest(address_str,b,len);    
	   
	   tokstr_len = dest.length()+1;
	   tokstr = new char[tokstr_len];
	   
	   dest.copy(tokstr,dest.length());
	   // we are dealing with char arrays, so....
	   tokstr[dest.length()] = '\0';
	   short k;
	   for(k=0; k < tokstr_len; k++)
	     address_string[nr_of_addrs][k] = tokstr[k];
	   if (count_punct == 3)
	     { // IPv4 address parameters
	       addrs[nr_of_addrs].sa.sa_family = AF_INET;
	       addrs[nr_of_addrs].sin.sin_port = SUA_PORT;
	       result = inet_pton(AF_INET, tokstr,&addrs[nr_of_addrs].sin.sin_addr);
	       if (result != 1)
		 cout << "IPvx address conversion returned "<< result << " \n";
#ifdef DEBUG
	       cout << "IPv4 = " << addrs[nr_of_addrs].sin.sin_addr.s_addr << " \n";
#endif	 
	     }
	   if (count_colon >= 2)
	     { // IPv6 address parameters
	       addrs[nr_of_addrs].sa.sa_family = AF_INET6;
	       addrs[nr_of_addrs].sin6.sin6_port = SUA_PORT;
	       result = inet_pton(AF_INET6, tokstr,&addrs[nr_of_addrs].sin6.sin6_addr);
	       if (result != 1)
		 cout << "IPvx address conversion returned "<< result << " \n";
#ifdef DEBUG
	       cout << "IPv6 = " << &addrs[nr_of_addrs].sin6.sin6_addr << " \n";
#endif	 
	     }
	   
	   nr_of_addrs++;
	   b = i + 1;
	   count_punct = 0;
	   count_colon = 0;
	   
	 }
      
       i++;
       
     }
#ifdef DEBUG
  cout << "number of address = " << nr_of_addrs  << " \n";
#endif
}

/***********************************************************************/
/* Sua_AddressObject::read_pointcode                                   */
/***********************************************************************/
void db_Sua_AddressObject::read_pointcode_param(string pointcode_str) {
  int b=0,len=0;
  unsigned int i=0;
  int tokstr_len = 0;
  char *tokstr;

#ifdef DEBUG
  cout << "Pointcode string = " << pointcode_str << " len = " << pointcode_str.length() << "\n";
#endif

  while ((i  <= pointcode_str.length()))
     {
       if (i == pointcode_str.length())
	 {
	   len = i - b;
	   string dest(pointcode_str,b,len);    
	   
	   tokstr_len = dest.length()+1;
	   tokstr = new char[tokstr_len];
	   
	   dest.copy(tokstr,dest.length());
	   // we are dealing with char arrays, so....
	   tokstr[dest.length()] = '\0';

	   pc.ITU24.family = ITU24bit;
	   pc.ITU24.pc = atoi(tokstr);
	   
#ifdef DEBUG
	   cout << "Pointcode value = " << pc.ITU24.pc << " \n";
#endif	 
	   b = i + 1;
	 }
       i++;
     }
       
#ifdef DEBUG
  cout << "Only 1 pointcode per association allowed \n";
#endif
}

/***********************************************************************/
/* Sua_AddressObject::read_port_num                                    */
/***********************************************************************/
void db_Sua_AddressObject::read_port_num(string port_str){
  int i=0;
  char *tokstr = new char[port_str.length()+1];
  int sua_port_number;


  port_str.copy(tokstr,port_str.length());
  tokstr[port_str.length()] = '\0';
  sua_port_number = atoi(tokstr);
 
  for(i = 0; i < nr_of_addrs ; i++)
    addrs[i].sin6.sin6_port = sua_port_number;

#ifdef DEBUG
  //cout << "Portnumber = " << sua_port_number  << " * " << nr_of_addrs << " times  \n";
#endif
}

/***********************************************************************/
/* functions of the object class SUA Local Object                      */
/***********************************************************************/

/***********************************************************************/
/* Sua_LocalObject::initalize                                          */
/***********************************************************************/
void db_Sua_LocalObject::initialize(){

  
  SUA_APLCallBack.ulp_ClDataIndNotif = &db_dummy_xxxxIndNotif;
  SUA_APLCallBack.ulp_ConnIndNotif =  &db_dummy_xxxxIndNotif;
  SUA_APLCallBack.ulp_ConnConfIndNotif =  &db_dummy_xxxxIndNotif; 
  SUA_APLCallBack.ulp_ConnDataIndNotif =  &db_dummy_xxxxIndNotif; 
  SUA_APLCallBack.ulp_DisConnIndNotif =  &db_dummy_DisxIndNotif;     

}

/***********************************************************************/
/* functions of the object class SUA LocalList                         */
/***********************************************************************/
/***********************************************************************/
/* Sua_LocalList::initialize                                           */
/***********************************************************************/
void db_Sua_LocalList::initialize(){
 short i;
 num_of_instance = 0;   
 for (i=0; i < db_MAX_LOCAL_SUA; i++)
  {
    instance[i].initialize();  
  }
}

/***********************************************************************/
/* Sua_LocalList::read_ssn                                             */
/***********************************************************************/
void db_Sua_LocalList:: read_ssn(string ssn_str){

  instance[num_of_instance].ssn.read_ssn(ssn_str);
};

/***********************************************************************/
/* Sua_LocalList::increase_instance                                    */
/***********************************************************************/
void db_Sua_LocalList:: increase_instance(){

  num_of_instance++;
#ifdef DEBUG
    cout << "New instance nr " << (num_of_instance - 1) << " \n";
#endif
  char logstring[100];
  sprintf(logstring, "New instance nr %d", num_of_instance - 1);
  event_log("sua_database.c",logstring);
   
};


/***********************************************************************/
/* Sua_LocalList::unregister_instance                                  */
/***********************************************************************/
short db_Sua_LocalList:: unregister_instance(){

  int i;

  for(i=0; i < num_of_instance; i++)
    {
#ifdef DEBUG
       cout << "UnRegister SUA(& SCTP) local instance nr " << i << " \n";
#endif
       char logstring[100];
       sprintf(logstring, "Unregister SUA(& SCTP) local instance nr %d", i);
       event_log("sua_database.c",logstring);
       /* result = sctp_unregisterSCTP_instance ( instance[i].assoc_id ); 
       */
    }
	return(0);
};

/***********************************************************************/
/* Sua_LocalList::register_instance                              */
/***********************************************************************/
short db_Sua_LocalList:: 
register_instance( unsigned int       local_sua_id,
		   Sua_ULP_CallBacks  SUACallbackFunctions,
		   unsigned int       init_association
		 ){


  instance[local_sua_id].SUA_APLCallBack.ulp_ClDataIndNotif = SUACallbackFunctions.ulp_ClDataIndNotif; 
  instance[local_sua_id].SUA_APLCallBack.ulp_ConnIndNotif = SUACallbackFunctions.ulp_ConnIndNotif;
  instance[local_sua_id].SUA_APLCallBack.ulp_ConnConfIndNotif = SUACallbackFunctions.ulp_ConnConfIndNotif; 
  instance[local_sua_id].SUA_APLCallBack.ulp_ConnDataIndNotif = SUACallbackFunctions.ulp_ConnDataIndNotif; 
  instance[local_sua_id].SUA_APLCallBack.ulp_DisConnIndNotif = SUACallbackFunctions.ulp_DisConnIndNotif; 
  
  instance[local_sua_id].init_assoc_id = init_association;

  return(0);
}

/***********************************************************************/
/* functions of the object class SUA Remote Object                     */
/***********************************************************************/
/***********************************************************************/
/* Sua_RemoteObject::initalize                                          */
/***********************************************************************/
void db_Sua_RemoteObject::initialize(){
  
  ;
}

/***********************************************************************/
/* functions of the object class SUA RemoteList                        */
/***********************************************************************/

/***********************************************************************/
/* Sua_RemoteList::initialize                                           */
/***********************************************************************/
void db_Sua_RemoteList::initialize(){
 short i;
 num_of_instance = 0;
 for (i=0; i < db_MAX_REMOTE_SUA; i++)
  {
    instance[i].initialize();  
  }
}

/***********************************************************************/
/* Sua_RemoteList::read_ssn                                            */
/***********************************************************************/
void db_Sua_RemoteList:: read_ssn(string ssn_str){

  instance[num_of_instance].ssn.read_ssn(ssn_str);
};

/***********************************************************************/
/* Sua_RemoteList::increase_instance                                    */
/***********************************************************************/
void db_Sua_RemoteList:: increase_instance(){

  num_of_instance++;
#ifdef DEBUG
  cout << "New instance nr " << (num_of_instance - 1) << " \n";
#endif
  char logstring[100];
  sprintf(logstring, "New instance nr %d", num_of_instance - 1);
  event_log("sua_database.c",logstring);
   
};
/***********************************************************************/
/* functions of the object class SUA Application Server Process (ASP)  */
/***********************************************************************/
/***********************************************************************/
/* Sua_ASPObject::initalize                                            */
/***********************************************************************/
void db_Sua_ASPObject::initialize(){
  short j;
    
  status = asp_idle;  
  for (j=0; j < db_MAX_1ASP_IN_AS ; j++)
    linked_to_AS[j] = 0;
}

/***********************************************************************/
/* Sua_ASPObject::Activate ASP                                         */
/***********************************************************************/
bool db_Sua_ASPObject::activate(unsigned int sua_assoc_id,
				short mode 
			       )
{  
  bool traf_hold=FALSE;
  short i;
  

  switch ( status) 
    {
    case (asp_inactive):
      {
	switch (mode)
	  {
	  case (tmt_override ):
	    {
	      cout << "ASP in override mode\n";
	      /* this node becomes the override node for processing */
	      /* all other ASP of this AS must be put in standby */
	      i = 0;
	      /*while (i <= db_MAX_1ASP_IN_AS)
		{
		  if ((linked_to_AS[i] > 0) && 
		      (linked_to_AS[i] <= db_MAX_SUA_AS))
		    Asp_mngt_standby ( linked_to_AS[i],
				       sua_assoc_id,
				       mode
				     );
				     }*/
	    }
	  case (tmt_loadshare):
	    {
	      cout << "ASP in loadshare mode\n";
	    }
	  case (tmt_max/*broadcast*/):
	    {
	      cout << "ASP in broadcast -> very dangerous\n";
	    }
	  default:
	    {
	      cout << "default mode in activation\n";
	    }
	  }
	status = asp_active;
      }
    case (asp_inactive_traf_hold):
      {
	status = asp_active;
	traf_hold = TRUE;
      }
    default:
      {
	/* remain in same state */
	/* depdending on the mode of the ASPAC */
	;
      }
    }
  return(traf_hold);
}

/***********************************************************************/
/* Sua_ASPObject::inactivate ASP                                       */
/***********************************************************************/
void db_Sua_ASPObject::deactivate( unsigned int sua_assoc_id,
				   short mode 
				 )
{
 if( status == asp_active)
   status = asp_inactive;
}

/***********************************************************************/
/* Sua_ASPObject::put ASP up = inactive                                */
/***********************************************************************/
void db_Sua_ASPObject::up( unsigned int sua_assoc_id,
			   short mode 
			 )
{
  switch(status)
    {
    case( asp_down):
      {
	status = asp_inactive;
      }
    case (asp_down_traf_hold):
      {
	status = asp_inactive_traf_hold;
      }
    default:
      {
	// do nothing , state is not changed
      }
    }
}

/***********************************************************************/
/* Sua_ASPObject::put ASP in down mode                                 */
/***********************************************************************/
void db_Sua_ASPObject::down( unsigned int sua_assoc_id,
			     short mode 
			   )
{
  status = asp_down;  
}

/***********************************************************************/
/* functions of the object class SUA Application Server List           */
/***********************************************************************/
/***********************************************************************/
/* Sua_ASList::initalize                                               */
/***********************************************************************/
void db_Sua_ASList::initialize(){
  
  short i,j;
  num_of_instance = 0;   
  for (i=0; i <  db_MAX_SUA_AS; i++)
    {
      instance[i].status = as_idle;  
      for (j=0; j <  db_MAX_ASP_IN_1AS; j++)
	instance[i].ASP_linked_to_this_AS[j] = 0;
    }
}

/***********************************************************************/
/* Sua_ASList::read_AS string                                          */
/***********************************************************************/
short db_Sua_ASList::read_AS( string       as_str, 
			      unsigned int sua_id 
			      ){
  int i=0;
  char *tokstr = new char[as_str.length()+1];
  int as_number;
  bool cont_loop;


  as_str.copy(tokstr,as_str.length());
  tokstr[as_str.length()] = '\0';
  as_number = atoi(tokstr);
 
  if ( instance[as_number].status == as_idle)
    instance[as_number].status = as_down;

  i= 0;
  cont_loop = (i  <  db_MAX_ASP_IN_1AS); 
  while (cont_loop)  
   {  
     if (instance[as_number].ASP_linked_to_this_AS[i] == 0)
       {
	 instance[as_number].ASP_linked_to_this_AS[i] = sua_id;
	 cont_loop = false;
       }  
    }
#ifdef DEBUG
  cout << "Application Server number used " << as_number  << " for ASP " << sua_id << "\n";
#endif

  return(as_number);

}

/***********************************************************************/
/* AS_override_ASP                                                     */
/***********************************************************************/
void  db_Sua_ASList::override_ASP( unsigned int  asp_sua_assoc_id,
				   unsigned int  AS_id,
				   short         mode
				 )
{
  short i;
  short asp_present_nr = 0;
  unsigned short processed_ASP = 0;

  for (i=0; i <= db_MAX_ASP_IN_1AS; i++){
    processed_ASP = instance[AS_id].ASP_linked_to_this_AS[i];
    if (processed_ASP == asp_sua_assoc_id )
      { 
	asp_present_nr++;
	asp_activate_override(asp_sua_assoc_id);
      }
    else if ((processed_ASP > 0) &&
	     (processed_ASP <= db_MAX_REMOTE_SUA))
      {
	asp_present_nr++;
	asp_deactivate(asp_sua_assoc_id);
      }
    /*else nothing to do */
      
  }
  //if (asp_present_nr = 0)
  //  instance(AS_id).status = as_
}
  
// end of module sua_database.c