aboutsummaryrefslogtreecommitdiffstats
path: root/sualibrary/testup/testuser.cpp
blob: 0d7facf841718e714b8e25eb07a37b7e2ad8fd6d (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
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
/***************************************************************************
                          testuser.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: testuser.cpp,v 1.7 2002/11/14 15:29:24 p82609 Exp $
 *
 * SUA Test user part implementation.
 *
 * 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
 *
 * Purpose: This code-file defines the SUA Test User Part application and  
 *          has definitions for:
 *          - Do pingpong with remote TESTUP
 *          - Handle pong
 *          - initialise the Test User part application 
 *          - Test User Part STDIN function -> reading keyboard and 
 *            sending the info to SUA
 *          - Handle TESTUP expired timers
 *          - TESTUP Connectionless Data Ind Notification(from SUA)
 *          - TESTUP CO Connection Ind Notification(from SUA)
 *          - TESTUP CO Connection Confirmation Ind Notification(from SUA)
 *          - TESTUP CO Data Ind Notification(from SUA)
 *          - TESTUP CO DisConnection Ind Notification(from SUA)
 */

#include "sctp.h"
#include "sua.h"

#ifdef LINUX
    #include <unistd.h>
#endif

#include <iostream>
#include <string>




using namespace std;

#include <sys/time.h>
#define MAX_DATA_LENGTH 2000
#define MAX_DATACHUNK_PDU_LENGTH 251

extern char own_hostname[512];

//global variable for ULP instance(one connection only)
unsigned int timerID = 0;
unsigned int refID = 0;
unsigned int sendNo = 10;
unsigned int sendcnt = 0;
unsigned int timeoutval= 1000;
unsigned int rep_timer = 0;

sua_Path_str pathinfo;  
sccp_addr_str calling_pty_addr,called_pty_addr;
short network_app = 0;
short seq_control_num = 0;
boolean return_option = FALSE;

/***********************************************************************/
/* Test User Part : doPingPong                                         */
/***********************************************************************/
int doPingPong(unsigned int Sua_ConnId )
{
    int length;
    sccp_addr_str co_clg, co_cld;
    sccp_QOS_str co_QOS;
    unsigned int xsxx;
    string cmdline= "ping";

    co_QOS.prot_class = class2;
    co_QOS.in_sequence = false;
    co_QOS.sequence_number = 0;
    co_QOS.return_msg_on_error = 0;
    co_QOS.importance = 0;
    
    co_clg.address_fields_present.pc = no_pc_present;
    co_clg.address_fields_present.name_gt = no_name_present;
    co_clg.address_fields_present.ssn_port = no_sap_present;
    co_clg.address_fields_present.field_in_header = include_nothing;
    
    co_cld.address_fields_present.pc = no_pc_present;
    co_cld.address_fields_present.name_gt = no_name_present;
    co_cld.address_fields_present.ssn_port = no_sap_present;
    co_cld.address_fields_present.field_in_header = include_nothing;
    
    
    char *databuffer =  new char[cmdline.length()];
    cmdline.copy(databuffer, cmdline.length());
    length = cmdline.length();
    
    xsxx = Send_sua_primitive(N_DATA_REQ,
			      Sua_ConnId,
			      co_QOS,
			      co_cld,
			      co_clg,
			      databuffer,
			      length 
			     );

#ifdef DEBUG
    cout << "testuser.c++: Returned "<< xsxx <<" from the send (1==association error, 0==success, -1==could not send)\n";
#endif
    
    delete databuffer; 
    return(xsxx);
}

/***********************************************************************/
/* Test User Part : handle_Pong                                        */
/***********************************************************************/
int handlePong()
{


    return(0);
}
/***********************************************************************/
/* Test User Part : init_testip_stdin                                  */
/***********************************************************************/
void init_testip_stdin()
{
  unsigned int xsxx;

  xsxx=  sua_getPath( 1,
		      pathinfo
		    );

  /*cout << "result getpath = " << xsxx << "\n"; */

  calling_pty_addr.address_fields_present.pc = ipvx_pc_present;
  calling_pty_addr.address_fields_present.name_gt = no_name_present;
  calling_pty_addr.address_fields_present.ssn_port = ssn_present;
  calling_pty_addr.address_fields_present.field_in_header = include_nothing;
  calling_pty_addr.pc.ipvx = pathinfo.local_addr.pc.ipvx;
  calling_pty_addr.pc.ss7 = pathinfo.local_addr.pc.ss7;
  calling_pty_addr.ssn = pathinfo.local_addr.ssn;
  calling_pty_addr.routing_ind = route_on_ssn;
  calling_pty_addr.network_apperance = network_app;
   
  called_pty_addr.address_fields_present.pc = ipvx_pc_present;
  called_pty_addr.address_fields_present.name_gt = no_name_present;
  called_pty_addr.address_fields_present.ssn_port = ssn_present;
  called_pty_addr.address_fields_present.field_in_header = include_nothing;
  called_pty_addr.pc.ipvx = pathinfo.remote_addr.pc.ipvx;
  called_pty_addr.pc.ss7 = pathinfo.remote_addr.pc.ss7;
  called_pty_addr.ssn = pathinfo.remote_addr.ssn;
  called_pty_addr.routing_ind = route_on_ssn;
  called_pty_addr.network_apperance = network_app;
}

/***********************************************************************/
/* Test User Part : testip_stdin_cb                                    */
/***********************************************************************/
void testip_stdin_cb( int        fd, 
		      short int  revents,
		      short int  *gotevents,
		      void       *dummy
                    )
{
  int i,length;
  unsigned int k, outstr_len;
  char readBuffer[256];
  char output_str[INET6_ADDRSTRLEN];
  const char *ptr;
  unsigned int xsxx;
  
  sccp_QOS_str udt_QOS, co_QOS;
  unsigned int Sua_ConnId=0;

  cin.getline(readBuffer,256,'\n');
  string cmdline(readBuffer,strlen(readBuffer));

  if (cmdline.length() == 0) 
    {
      cout << ">>";
      cout << flush;

      return;
    }
  else if (cmdline.find("help") != cmdline.npos)
    {
      cout << "Available commands are:\n";
      cout << " help - display this page\n";
      cout << " quit/exit - exit the program\n";
      cout << " destaddr6: - set destination ipv6 address \n";
      cout << " destaddr4: - set destination ipv4 address \n";
      cout << " destname: - set destination hostname\n";
      cout << " destpc: - set destination SS7 pointcode(decimal)\n";
      cout << " some-other-string - send this Connectionless to destaddrx\n";
      cout << " co:some-other-string - send this Connection-oriented\n";
      cout << " disp mngt - display ASP status of remote nodes\n";
      cout << " return-option: - change return-option(toggle) on/off\n";
      //cout << " rep:x - repeat sending x CLDT/CODT msg to remote\n";
      //cout << " term - terminate all the present associations(SCTP & SUA)\n";
      //cout << " restart - restart all the present associations(SCTP & SUA)\n";
    } 
  else if ((cmdline.find("quit") != cmdline.npos) ||
	   (cmdline.find("exit") != cmdline.npos))
    {
      /* add some cleanups */
      sua_terminate();
      cout << "exiting the Test User program\n";
      /* exit program */
      exit(0);
    } 
  else if (cmdline.find("term") != cmdline.npos)
    {
      /* add some cleanups */
      sua_shutdown();
      cout << "Closing down the SCTP & SUA associations\n";
    } 
  else if ((cmdline.find("rep:") != cmdline.npos))
    {
      cout << "Repeat sending CL/CO data to remote end every " << rep_timer << " sec\n";
    } 
  else if ((cmdline.find("return-option:") != cmdline.npos))
    {
      return_option = !return_option;
      cout << "Return option = " << return_option << " (0= FALSE, 1= TRUE)\n";
    } 
  else if (cmdline.find("lock") != cmdline.npos)
    {
      /* lock up all SUA instances for ASP management */
      cout << "SUA mgnt administratived locked\n";
    } 
  else if (cmdline.find("disp mngt") != cmdline.npos)
    {
      /* Display the management status of all  SUA instances */
      cout << "Display SUA administration and Mangagement data of all associations\n";
      cout << "|-------+--------+--------------------+--------------------+-----|\n";
      cout << "| Assoc | status |    local IP addr   |   Remote IP addr   | SSN |\n";
      cout << "|-------+--------+--------------------+--------------------+-----|\n";
      i = 1;
      while ( SUA_PATH_NO_ERROR ==  sua_getPath(i,pathinfo) )
	{
	  cout << "|   " << i <<"   |   "<< pathinfo.ASP_status << "    |   ";
	  if (pathinfo.local_addr.pc.ipvx.sa.sa_family == AF_INET)
	    { /* ipv4 */
	      ptr = inet_ntop( pathinfo.local_addr.pc.ipvx.sa.sa_family,
			       &pathinfo.local_addr.pc.ipvx.sin.sin_addr,
			       output_str,
			       sizeof(output_str)
			       );
	      cout << output_str;
	      outstr_len = strlen(output_str);
	      for(k=0; k < (20 - 3 - outstr_len); k++)
		cout << " ";
	      cout << "|   ";
	      ptr = inet_ntop( pathinfo.remote_addr.pc.ipvx.sa.sa_family,
			       &pathinfo.remote_addr.pc.ipvx.sin.sin_addr,
			       output_str,
			       sizeof(output_str)
			       );
	      cout << output_str;
	      for(k=0; k < /*(20 -*/ 3 /*- outstr_len)*/; k++)
		cout << " ";
	      cout << "| ";
	      cout << pathinfo.remote_addr.ssn << " |\n";						
	    }
	  else
	    {	/* ipv6 */
	      ptr = inet_ntop( pathinfo.local_addr.pc.ipvx.sa.sa_family,
			       &pathinfo.local_addr.pc.ipvx.sin6.sin6_addr,
			       output_str,
			       sizeof(output_str)
			       );
	      cout << output_str << "   |   ";
	      ptr = inet_ntop( pathinfo.remote_addr.pc.ipvx.sa.sa_family,
			       &pathinfo.remote_addr.pc.ipvx.sin6.sin6_addr,
			       output_str,
			       sizeof(output_str)
			       );								
	      cout << output_str << "   | ";
	      cout << pathinfo.remote_addr.ssn << " |\n";	
	    }						   			
	  
	  i++;
	}
      cout << "|-------+--------+--------------------+--------------------+-----|\n";
      cout << "ASP status values: see sua_asp_mgnt.h\n";
    } 
  else if (cmdline.find("term") != cmdline.npos)
    {
      /* Terminate the following associations */
      cout << "| Association | SUA management status |\n";
      
    } 
  else if (cmdline.find("destaddr6:") != cmdline.npos)
    {
      /* get destination address, convert it and store in cld */
      string addr_str(cmdline, (cmdline.find("destaddr6:")+10),cmdline.length());
      cout << "dest address = " << addr_str << "\n";
      char *addr_char = new char [addr_str.length()+1];
      addr_str.copy(addr_char, addr_str.length());
      addr_char[addr_str.length()] = '\0';
      called_pty_addr.address_fields_present.pc = ipvx_pc_present;
      called_pty_addr.address_fields_present.name_gt = no_name_present;
      called_pty_addr.address_fields_present.ssn_port = ssn_present;
      called_pty_addr.address_fields_present.field_in_header = include_nothing;
      called_pty_addr.pc.ipvx.sa.sa_family = AF_INET6;
      called_pty_addr.pc.ipvx.sin6.sin6_port = SUA_PORT;
      inet_pton( AF_INET6,
		 addr_char,
		 &called_pty_addr.pc.ipvx.sin6.sin6_addr
	       );
      called_pty_addr.ssn = 255;
      called_pty_addr.routing_ind = route_on_ssn;
      
      calling_pty_addr.ssn = 255;
      calling_pty_addr.routing_ind = route_on_ssn;

      cout << "Address of remote end stored. Msg will be sent to this one\n";
    } 
  else if (cmdline.find("destaddr4:") != cmdline.npos)
    {
      /* get destination address, convert it and store in cld */
      string addr_str( cmdline, (cmdline.find("destaddr4:")+10),cmdline.length());
      cout << "dest address " << addr_str << "\n";
      char *addr_char = new char [addr_str.length()+1];
      addr_str.copy(addr_char, addr_str.length());
      addr_char[addr_str.length()] = '\0';
      called_pty_addr.address_fields_present.pc = ipvx_pc_present;
      called_pty_addr.address_fields_present.name_gt = no_name_present;
      called_pty_addr.address_fields_present.ssn_port = ssn_present;
      called_pty_addr.address_fields_present.field_in_header = include_nothing;
      called_pty_addr.pc.ipvx.sa.sa_family = AF_INET;
      called_pty_addr.pc.ipvx.sin.sin_port = SUA_PORT;
      inet_pton( AF_INET,
		 addr_char,
		 &called_pty_addr.pc.ipvx.sin.sin_addr
	       );
      called_pty_addr.ssn = 255;
      called_pty_addr.routing_ind = route_on_ssn;

      calling_pty_addr.ssn = 255;
      calling_pty_addr.routing_ind = route_on_ssn;
     
      cout << "Address of remote end stored. Msg will be sent to this one\n";
    } 
  else if (cmdline.find("destname:") != cmdline.npos)
    {
      /* get destination hostname, convert it and store in cld */
      string addr_str(cmdline, (cmdline.find("destname:")+9),cmdline.length());

      called_pty_addr.address_fields_present.pc = no_pc_present;
      called_pty_addr.address_fields_present.name_gt = hostname_present;
      called_pty_addr.address_fields_present.ssn_port = ssn_present;
      called_pty_addr.address_fields_present.field_in_header = include_nothing;
      strcpy(called_pty_addr.name.HostName,addr_str.c_str());
      called_pty_addr.ssn =  calling_pty_addr.ssn;
      called_pty_addr.routing_ind = route_on_name_gt;
     
      cout << "DNS/SUA dest hostname = " << addr_str << "\n";
      cout << "Address of remote end stored. Msg will be sent to this one\n";

      string addr2_str = own_hostname;
      /*char *name2_char = new char [addr2_str.length()+1]; */
      /*name2_char  = shost_to_suaname ( addr2_str ); */
     
      calling_pty_addr.address_fields_present.name_gt = hostname_present;
      strcpy(calling_pty_addr.name.HostName, own_hostname);
      calling_pty_addr.ssn = 5;
      calling_pty_addr.routing_ind = route_on_name_gt;
      cout << "DNS/SUA source hostname = " << addr2_str << "\n";
     
    } 
 else if (cmdline.find("destpc:") != cmdline.npos)
    {
      /* get destination address, convert it and store in cld */
      string addr_str(cmdline, (cmdline.find("destpc:")+7),cmdline.length());
      cout << "dest address = " << addr_str << "\n";
      char *addr_char = new char [addr_str.length()+1];
      addr_str.copy(addr_char, addr_str.length());
      addr_char[addr_str.length()] = '\0';
      called_pty_addr.address_fields_present.pc = ss7_pc_present;
      called_pty_addr.address_fields_present.name_gt = no_name_present;
      called_pty_addr.address_fields_present.ssn_port = ssn_present;
      called_pty_addr.address_fields_present.field_in_header = include_nothing;
      called_pty_addr.pc.ss7.ITU24.family = ITU24bit;
      called_pty_addr.pc.ss7.ITU24.pc = atoi(addr_char);
      called_pty_addr.ssn = calling_pty_addr.ssn;     
      called_pty_addr.routing_ind = route_on_ssn;

      calling_pty_addr.ssn = 5;
      calling_pty_addr.routing_ind = route_on_ssn;
      
      cout << "Address of remote end stored. Msg will be sent to this one\n";
    } 
  else if (cmdline.find("co:") != cmdline.npos)
    {
     
      co_QOS.prot_class = class2;
      co_QOS.in_sequence = false;
      co_QOS.sequence_number = 0;
      co_QOS.return_msg_on_error = return_option;
      co_QOS.importance = 0;

      xsxx=  sua_getPath( 1,
			  pathinfo
			);

      //cout << "result getpath = " << xsxx << "\n";

      calling_pty_addr.address_fields_present.pc =  called_pty_addr.address_fields_present.pc;
      calling_pty_addr.address_fields_present.name_gt =  called_pty_addr.address_fields_present.name_gt;
      calling_pty_addr.routing_ind = called_pty_addr.routing_ind;
      calling_pty_addr.address_fields_present.ssn_port =  called_pty_addr.address_fields_present.ssn_port;
      calling_pty_addr.address_fields_present.field_in_header = called_pty_addr.address_fields_present.field_in_header ;

      string addr3_str = own_hostname;
      /*char *name3_char = new char [addr3_str.length()+1];*/
      /*name3_char  = shost_to_suaname ( addr3_str );*/
      strcpy(calling_pty_addr.name.HostName, own_hostname);


      calling_pty_addr.pc.ipvx = pathinfo.local_addr.pc.ipvx;
      calling_pty_addr.ssn = pathinfo.local_addr.ssn;
      calling_pty_addr.pc.ss7 = pathinfo.local_addr.pc.ss7 ;

      char *databuffer =  new char[cmdline.length()];
      cmdline.copy(databuffer, cmdline.length());
      length = cmdline.length();

      xsxx = Send_sua_primitive(N_CONNECT_REQ,
				Sua_ConnId,
				co_QOS,
				called_pty_addr,
				calling_pty_addr,
				databuffer,
				length 
				);

      refID = Sua_ConnId;

#ifdef DEBUG
      cout << "testuser.c++: Returned "<< xsxx <<" from the send (1==association error, 0==success, -1==could not send)\n";
#endif
	
      delete databuffer; 
    } 
  else 
    {

      udt_QOS.prot_class = class0;
      udt_QOS.in_sequence = false;
      udt_QOS.sequence_number = seq_control_num++;
      udt_QOS.return_msg_on_error = return_option;
      udt_QOS.importance = 0;

      xsxx=  sua_getPath( 1,
			  pathinfo
			);

#ifdef DEBUG
      cout << "Sequence control parameter = " << udt_QOS.sequence_number << "\n";
#endif

      calling_pty_addr.address_fields_present.pc =  called_pty_addr.address_fields_present.pc;
      calling_pty_addr.address_fields_present.name_gt =  called_pty_addr.address_fields_present.name_gt;
      calling_pty_addr.routing_ind = called_pty_addr.routing_ind;
      calling_pty_addr.address_fields_present.ssn_port =  called_pty_addr.address_fields_present.ssn_port;
      calling_pty_addr.address_fields_present.field_in_header =  called_pty_addr.address_fields_present.field_in_header;

      string addr4_str = own_hostname;
      strcpy(calling_pty_addr.name.HostName, own_hostname);

      calling_pty_addr.pc.ipvx = pathinfo.local_addr.pc.ipvx;
      calling_pty_addr.ssn = pathinfo.local_addr.ssn;    
      calling_pty_addr.pc.ss7 = pathinfo.local_addr.pc.ss7 ;

      char *databuffer =  new char[cmdline.length()];
      cmdline.copy(databuffer, cmdline.length());
      length = cmdline.length();

      xsxx = Send_sua_primitive(N_UNITDATA,
				Sua_ConnId,
				udt_QOS,
				called_pty_addr,
				calling_pty_addr,
				databuffer,
				length 
				);

#ifdef DEBUG
      cout << "testuser.c++: Returned "<< xsxx <<" from the send (1==association error, 0==success, -1==could not send)\n";
#endif	

      delete databuffer;
    }
  cout << ">";
  cout << flush;

}


#define SEND_EVENTS_WHEN_TIMER_EXPIRES  1
/***********************************************************************/
/* Test user part : timer_expired                                      */
/***********************************************************************/
void timer_expired(unsigned int tID,
		   void         *associationIDvoid, 
		   void         *unused
		  )
{
    int length;
    sccp_addr_str co_clg, co_cld;
    sccp_QOS_str co_QOS;
    string cmdline= "ping";

    unsigned int Sua_ConnId=refID;
    
    cout << "************************************************************\n";
    cout << "**                    Timer expired                       **\n";
    if (sendcnt < sendNo) {
      sendcnt++;
      cout << "Send a PING\n";
      doPingPong(Sua_ConnId);
      timerID = sctp_startTimer( 10,      /* seconds */
				 0,       /* microseconds */
				 &timer_expired,
				 NULL,
				 NULL
			       );
    }
    else
      {
	cout << "Terminate the SUA connection\n";
	unsigned int xsxx;
      
	co_QOS.prot_class = class2;
	co_QOS.in_sequence = false;
	co_QOS.sequence_number = 0;
	co_QOS.return_msg_on_error = 0;
	co_QOS.importance = 0;
       

	char *databuffer =  new char[cmdline.length()];
	cmdline.copy(databuffer, cmdline.length());
	length = cmdline.length();
       
	xsxx = Send_sua_primitive( N_RELEASE_REQ,
				   Sua_ConnId,
				   co_QOS,
				   co_cld,
				   co_clg,
				   databuffer,
				   length 
				 );

#ifdef DEBUG
	cout << "testuser.c++: Returned "<< xsxx <<" from the send (1==association error, 0==success, -1==could not send)\n";
#endif
	
	delete databuffer;
      }
}

/***********************************************************************/
/* Test user part: ulp_ClDataIndNotif                                  */
/***********************************************************************/
void ulp_ClDataIndNotif( unsigned int   local_sua_Id,
			 unsigned int   primitive,
			 unsigned int   datalen
			)
{
  int length=datalen;
  int index;
  unsigned int Sua_ConnId;
  char databuffer[MAX_DATA_LENGTH];
  sccp_QOS_str QOS;
  sccp_addr_str clg,cld;
  
  Receive_sua_primitive ( primitive,
			  Sua_ConnId,
			  QOS,
			  cld,
			  clg,  
			  databuffer,
			  length 
			);
  	
  index = 0;

  cout << "testuser.c++: Hey, we received ClDataIndNotif \n";

  //check for primitive, receive only unitdata's up till know
  switch (primitive)
    {
    case (N_UNITDATA):
      called_pty_addr = clg;
      cout << "************************************************************\n";
      cout << "**              UNITDATA message received                 **\n";
      break;
    default:
      break;
    }

 
  string disp_output(databuffer,index, (length - index));
  cout << "************************************************************\n";
  cout << disp_output << "\n";
  cout << "************************************************************\n";
  cout << ">";
  cout << flush;
   
}


/***********************************************************************/
/* Test user part: ulp_ConnIndNotif                                  */
/***********************************************************************/
void ulp_ConnIndNotif( unsigned int   local_sua_Id,
		       unsigned int   ConnId,
		       unsigned int   datalen
		     )
{
  int length=datalen;
  int index;
  unsigned int Sua_ConnId, primitive;
  char databuffer[MAX_DATA_LENGTH];
  sccp_QOS_str QOS;
  sccp_addr_str clg,cld;
  
  Receive_sua_primitive ( primitive,
			  Sua_ConnId,
			  QOS,
			  cld,
			  clg,  
			  databuffer,
			  length 
			);
  	
  index = 0;

  string cmdline(databuffer,index, (length - index));

  cout << "testuser.c++: Hey, we received ConnIndNotif \n";

  //check for primitive
  switch (primitive)
    {
    case (N_CONNECT_IND):
      called_pty_addr = clg;
      cld = called_pty_addr;
      clg = calling_pty_addr;
      cout << "************************************************************\n";
      cout << "**           CONNECT REQ IND message received             **\n";
      // send Connect confirm back 
      // this is the responding side of the connection

      sccp_QOS_str co_QOS;
      unsigned int xsxx;
     
      co_QOS.prot_class = class2;
      co_QOS.in_sequence = false;
      co_QOS.sequence_number = 0;
      co_QOS.return_msg_on_error = 0;
      co_QOS.importance = 0;

      if (cmdline.find("refused") != cmdline.npos)
	{	  
	  // mirror received data back to initiator
	  cout << "length = " << length << "\n";
	  
	  xsxx = Send_sua_primitive(N_CONNECT_REFUSED,
				    Sua_ConnId,
				    QOS,
				    cld,
				    clg,
				    databuffer,
				    length 
				  );
	}
      else 
	{
	  xsxx = Send_sua_primitive(N_CONNECT_RESP,
				    Sua_ConnId,
				    QOS,
				    cld,
				    clg,
				    databuffer,
				    length 
				  );  
	}
      
      cout << "testuser.c++: Returned "<< xsxx <<" from the send (1==association error, 0==success, -1==could not send)\n";
    
     
      break;
    default:
      break;
    }

 
  string disp_output(databuffer,index, (length - index));
  cout << "************************************************************\n";
  cout << disp_output << "\n";
  cout << "************************************************************\n";
  cout << ">";
  cout << flush;

}



/***********************************************************************/
/* Test user part: ulp_ConnConfIndNotif                                */
/***********************************************************************/
void ulp_ConnConfIndNotif( unsigned int   local_sua_Id,
			   unsigned int   ConnId,
			   unsigned int   datalen
			 )
{
  int length=datalen;
  int index;
  unsigned int Sua_ConnId, primitive;
  char databuffer[MAX_DATA_LENGTH];
  sccp_QOS_str QOS;
  sccp_addr_str clg,cld;
  
  Receive_sua_primitive ( primitive,
			  Sua_ConnId,
			  QOS,
			  cld,
			  clg,  
			  databuffer,
			  length 
			);
  	
  index = 0;

  cout << "testuser.c++: Hey, we received ConnConfIndNotif\n";

  //check for primitive, receive only unitdata's up till know
  switch (primitive)
    {
    case (N_CONNECT_CONF):
      
      cout << "************************************************************\n";
      cout << "**         CONNECT CONFIRM IND message received           **\n";
      // received the connection confirmed msg
      // this is the initiator of the connection
      // start a timer for sending the data to the responder
      timerID = sctp_startTimer( 15,            /* seconds */
				 0,             /* microseconds */
				 &timer_expired,
				 NULL,
				 NULL
			       );
      
      break;
    default:
      break;
    }

 
  string disp_output(databuffer,index, (length - index));
  cout << "************************************************************\n";
  cout << disp_output << "\n";
  cout << "************************************************************\n";
  cout << ">";
  cout << flush;
   
}


/***********************************************************************/
/* Test user part: ulp_ConnDataIndNotif                                */
/***********************************************************************/
void ulp_ConnDataIndNotif( unsigned int   local_sua_Id,
			   unsigned int   ConnId,
			   unsigned int   datalen
			 )
{
  int length=datalen;
  int index;
  unsigned int Sua_ConnId, primitive;
  char databuffer[MAX_DATA_LENGTH];
  sccp_QOS_str QOS;
  sccp_addr_str clg,cld;
  
  Receive_sua_primitive ( primitive,
			  Sua_ConnId,
			  QOS,
			  cld,
			  clg,  
			  databuffer,
			  length 
			);
  	
  index = 0;
  string cmdline(databuffer,length);

  cout << "testuser.c++: Hey, we received ConnDataIndNotif \n";

  //check for primitive, receive only unitdata's up till know
  switch (primitive)
    {
    case (N_DATA_IND):
      
      cout << "************************************************************\n";
      cout << "**              CO DATA  message received                 **\n";
      // received a connection oriented data
      // if it is a ping send back a pong
      // if it is a pong, start timer for the next data or disconnect
      
      if (cmdline.find("ping") != cmdline.npos)
	{}
      else if (cmdline.find("pong") != cmdline.npos)
	{
	  cout << "End: pong received\n";
	}
      else
	cout << "Not in ping-pong mode\n";

      break;
    default:
      break;
    }

 
  string disp_output(databuffer,index, (length - index));
  cout << "************************************************************\n";
  cout << disp_output << "\n";
  cout << "************************************************************\n";
  cout << ">";
  cout << flush;
   
}


/***********************************************************************/
/* Test user part: ulp_DisconnIndNotif                                  */
/***********************************************************************/
void ulp_DisConnIndNotif( unsigned int   local_sua_Id,
			  unsigned int   ConnId,
			  unsigned int   cause,
			  unsigned int   datalen
			)
{
  int length=datalen;
  int index;
  unsigned int Sua_ConnId, primitive;
  char databuffer[MAX_DATA_LENGTH];
  sccp_QOS_str QOS;
  sccp_addr_str clg,cld;

  Receive_sua_primitive ( primitive,
			  Sua_ConnId,
			  QOS,
			  cld,
			  clg,  
			  databuffer,
			  length 
			);
  	
  index = 0;

  cout << "testuser.c++: Hey, we received DisConnIndNotif\n";

  //check for primitive, receive only unitdata's up till know
  switch (primitive)
    {
    case (N_RELEASE_REQ):
      
      cout << "************************************************************\n";
      cout << "**    RELEASE REQUEST:DISCONNECT IND message received     **\n";
      break;
    case (N_RELEASE_CONF):
      
      cout << "************************************************************\n";
      cout << "**    RELEASE CONFIRM:DISCONNECT IND message received     **\n";
      break;
    default:
      break;
    }

 
  string disp_output(databuffer,index, (length - index));
  cout << "************************************************************\n";
  cout << disp_output << "\n";
  cout << "************************************************************\n";
  cout << ">";
  cout << flush;
   
}

// end of module testuser.c++