File: norm_protolib.pr.cpp

package info (click to toggle)
norm 1.5.9%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 9,664 kB
  • sloc: cpp: 123,494; xml: 7,536; tcl: 5,460; makefile: 3,441; python: 1,898; java: 1,750; ansic: 642; sh: 21; csh: 8
file content (1527 lines) | stat: -rw-r--r-- 50,881 bytes parent folder | download | duplicates (4)
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
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
/* Process model C++ form file: norm_protolib.pr.cpp */
/* Portions of this file copyright 1992-2006 by OPNET Technologies, Inc. */

/* This variable carries the header into the object file */
const char norm_protolib_pr_cpp [] = "MIL_3_Tfile_Hdr_ 120A 30A modeler 7 464DEF85 464DEF85 1 wn12jh Jim@Hauser 0 0 none none 0 0 none 0 0 0 0 0 0 0 0 10de 3                                                                                                                                                                                                                                                                                                                                                                                                        ";
#include <string.h>



/* OPNET system definitions */
#include <opnet.h>



/* Header Block */

#include <OpnetNormProcess.h>
#include <oms_pr.h>
#include <oms_tan.h>
#include <udp_api.h>
#include <ip_rte_v4.h>
#include <ip_addr_v4.h>
#include <mgenVersion.h>

/* Define packet streams  */
#define INSTRM_FROM_UDP		0
#define INSTRM_FROM_MGEN	1
#define OUTSTRM_TO_MGEN		1

/*	Define a transition conditions              	*/
#define	SELF_NOTIF		(intrpt_type == OPC_INTRPT_SELF)
#define	END_SIM			(intrpt_type == OPC_INTRPT_ENDSIM)
#define	MSG_FROM_LOWER_LAYER	((intrpt_type == OPC_INTRPT_STRM) && (intrpt_strm == INSTRM_FROM_UDP)) 
#define	MSG_FROM_HIGHER_LAYER	((intrpt_type == OPC_INTRPT_STRM) && (intrpt_strm == INSTRM_FROM_MGEN)) 
#define TIMEOUT_EVENT	((intrpt_type == OPC_INTRPT_SELF) && (intrpt_code == SELF_INTRT_CODE_TIMEOUT_EVENT))

/* Forward Declarations */
void norm_conf_udp ();
void norm_host_addr ();

static const int MAX_SCRIPT = 128;
static const int MAX_LOG = 128;
static const int MAX_COMMAND = 256;
static const int MAXSTATFLOWS = 25;

/* End of Header Block */

#if !defined (VOSD_NO_FIN)
#undef	BIN
#undef	BOUT
#define	BIN		FIN_LOCAL_FIELD(_op_last_line_passed) = __LINE__ - _op_block_origin;
#define	BOUT	BIN
#define	BINIT	FIN_LOCAL_FIELD(_op_last_line_passed) = 0; _op_block_origin = __LINE__;
#else
#define	BINIT
#endif /* #if !defined (VOSD_NO_FIN) */



/* State variable definitions */
class norm_protolib_state
	{
	private:
		/* Internal state tracking for FSM */
		FSM_SYS_STATE

	public:
		norm_protolib_state (void);

		/* Destructor contains Termination Block */
		~norm_protolib_state (void);

		/* State Variables */
		OpnetNormProcess	       		norm_proc                                       ;
		Objid	                  		my_id                                           ;
		Objid	                  		my_node_id                                      ;
		Objid	                  		my_pro_id                                       ;
		Objid	                  		my_udp_id                                       ;
		Objid	                  		my_tcp_id                                       ;
		Objid	                  		my_mgen_id                                      ;
		IpT_Address	            		my_ip_addr                                      ;
		IpT_Address	            		my_ip_mask                                      ;
		Prohandle	              		own_prohandle                                   ;
		OmsT_Pr_Handle	         		own_process_record_handle                       ;
		char	                   		pid_string [512]                                ;
		char	                   		node_name [40]                                  ;
		ProtoTimerMgr	          		timer                                           ;
		ProtoSocket*	           		udpsocket                                       ;
		ProtoSocket*	           		tcpsocket                                       ;
		ProtoSocket::Notifier*	 		udpnotifier                                     ;
		ProtoSocket::Notifier*	 		tcpnotifier                                     ;
		ProtoAddress	           		host_ipv4_addr                                  ;
		Stathandle	             		bits_rcvd_stathandle                            ;
		Stathandle	             		bitssec_rcvd_flow_stathandle[MAXSTATFLOWS]      ;
		Stathandle	             		bitssec_sent_flow_stathandle[MAXSTATFLOWS]      ;
		Stathandle	             		bitssec_rcvd_stathandle                         ;
		Stathandle	             		pkts_rcvd_stathandle                            ;
		Stathandle	             		pktssec_rcvd_flow_stathandle[MAXSTATFLOWS]      ;
		Stathandle	             		pktssec_sent_flow_stathandle[MAXSTATFLOWS]      ;
		Stathandle	             		pktssec_rcvd_stathandle                         ;
		Stathandle	             		bits_sent_stathandle                            ;
		Stathandle	             		bitssec_sent_stathandle                         ;
		Stathandle	             		pkts_sent_stathandle                            ;
		Stathandle	             		pktssec_sent_stathandle                         ;
		Stathandle	             		ete_delay_stathandle                            ;
		Stathandle	             		ete_delay_flow_stathandle[MAXSTATFLOWS]         ;
		Stathandle	             		bits_rcvd_gstathandle                           ;
		Stathandle	             		bitssec_rcvd_gstathandle                        ;
		Stathandle	             		pkts_rcvd_gstathandle                           ;
		Stathandle	             		pktssec_rcvd_gstathandle                        ;
		Stathandle	             		bits_sent_gstathandle                           ;
		Stathandle	             		bitssec_sent_gstathandle                        ;
		Stathandle	             		pkts_sent_gstathandle                           ;
		Stathandle	             		pktssec_sent_gstathandle                        ;
		Stathandle	             		ete_delay_gstathandle                           ;
		int	                    		udp_outstream_index                             ;
		int	                    		local_port                                      ;
		IpT_Address	            		dest_ip_addr                                    ;
		FILE*	                  		script_fp                                       ;
		int	                    		source                                          ;
		Ici*	                   		app_ici_ptr                                     ;

		/* FSM code */
		void norm_protolib (OP_SIM_CONTEXT_ARG_OPT);
		/* Diagnostic Block */
		void _op_norm_protolib_diag (OP_SIM_CONTEXT_ARG_OPT);

#if defined (VOSD_NEW_BAD_ALLOC)
		void * operator new (size_t) throw (VOSD_BAD_ALLOC);
#else
		void * operator new (size_t);
#endif
		void operator delete (void *);

		/* Memory management */
		static VosT_Obtype obtype;
	};

VosT_Obtype norm_protolib_state::obtype = (VosT_Obtype)OPC_NIL;

#define norm_proc               		op_sv_ptr->norm_proc
#define my_id                   		op_sv_ptr->my_id
#define my_node_id              		op_sv_ptr->my_node_id
#define my_pro_id               		op_sv_ptr->my_pro_id
#define my_udp_id               		op_sv_ptr->my_udp_id
#define my_tcp_id               		op_sv_ptr->my_tcp_id
#define my_mgen_id              		op_sv_ptr->my_mgen_id
#define my_ip_addr              		op_sv_ptr->my_ip_addr
#define my_ip_mask              		op_sv_ptr->my_ip_mask
#define own_prohandle           		op_sv_ptr->own_prohandle
#define own_process_record_handle		op_sv_ptr->own_process_record_handle
#define pid_string              		op_sv_ptr->pid_string
#define node_name               		op_sv_ptr->node_name
#define timer                   		op_sv_ptr->timer
#define udpsocket               		op_sv_ptr->udpsocket
#define tcpsocket               		op_sv_ptr->tcpsocket
#define udpnotifier             		op_sv_ptr->udpnotifier
#define tcpnotifier             		op_sv_ptr->tcpnotifier
#define host_ipv4_addr          		op_sv_ptr->host_ipv4_addr
#define bits_rcvd_stathandle    		op_sv_ptr->bits_rcvd_stathandle
#define bitssec_rcvd_flow_stathandle		op_sv_ptr->bitssec_rcvd_flow_stathandle
#define bitssec_sent_flow_stathandle		op_sv_ptr->bitssec_sent_flow_stathandle
#define bitssec_rcvd_stathandle 		op_sv_ptr->bitssec_rcvd_stathandle
#define pkts_rcvd_stathandle    		op_sv_ptr->pkts_rcvd_stathandle
#define pktssec_rcvd_flow_stathandle		op_sv_ptr->pktssec_rcvd_flow_stathandle
#define pktssec_sent_flow_stathandle		op_sv_ptr->pktssec_sent_flow_stathandle
#define pktssec_rcvd_stathandle 		op_sv_ptr->pktssec_rcvd_stathandle
#define bits_sent_stathandle    		op_sv_ptr->bits_sent_stathandle
#define bitssec_sent_stathandle 		op_sv_ptr->bitssec_sent_stathandle
#define pkts_sent_stathandle    		op_sv_ptr->pkts_sent_stathandle
#define pktssec_sent_stathandle 		op_sv_ptr->pktssec_sent_stathandle
#define ete_delay_stathandle    		op_sv_ptr->ete_delay_stathandle
#define ete_delay_flow_stathandle		op_sv_ptr->ete_delay_flow_stathandle
#define bits_rcvd_gstathandle   		op_sv_ptr->bits_rcvd_gstathandle
#define bitssec_rcvd_gstathandle		op_sv_ptr->bitssec_rcvd_gstathandle
#define pkts_rcvd_gstathandle   		op_sv_ptr->pkts_rcvd_gstathandle
#define pktssec_rcvd_gstathandle		op_sv_ptr->pktssec_rcvd_gstathandle
#define bits_sent_gstathandle   		op_sv_ptr->bits_sent_gstathandle
#define bitssec_sent_gstathandle		op_sv_ptr->bitssec_sent_gstathandle
#define pkts_sent_gstathandle   		op_sv_ptr->pkts_sent_gstathandle
#define pktssec_sent_gstathandle		op_sv_ptr->pktssec_sent_gstathandle
#define ete_delay_gstathandle   		op_sv_ptr->ete_delay_gstathandle
#define udp_outstream_index     		op_sv_ptr->udp_outstream_index
#define local_port              		op_sv_ptr->local_port
#define dest_ip_addr            		op_sv_ptr->dest_ip_addr
#define script_fp               		op_sv_ptr->script_fp
#define source                  		op_sv_ptr->source
#define app_ici_ptr             		op_sv_ptr->app_ici_ptr

/* These macro definitions will define a local variable called	*/
/* "op_sv_ptr" in each function containing a FIN statement.	*/
/* This variable points to the state variable data structure,	*/
/* and can be used from a C debugger to display their values.	*/
#undef FIN_PREAMBLE_DEC
#undef FIN_PREAMBLE_CODE
#define FIN_PREAMBLE_DEC	norm_protolib_state *op_sv_ptr;
#define FIN_PREAMBLE_CODE	\
		op_sv_ptr = ((norm_protolib_state *)(OP_SIM_CONTEXT_PTR->_op_mod_state_ptr));


/* Function Block */

#if !defined (VOSD_NO_FIN)
enum { _op_block_origin = __LINE__ + 2};
#endif

/* Initialization function */

void norm_init ()
	{
	FIN (norm_init ())

	/* Initilaize the statistic handles to keep	*/
	/* track of traffic sent and sinked by this process.	*/
	bits_rcvd_stathandle 		= op_stat_reg ("NORM.Traffic Received (bits)",			OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
	bitssec_rcvd_stathandle 	= op_stat_reg ("NORM.Traffic Received (bits/sec)",		OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
	pkts_rcvd_stathandle 		= op_stat_reg ("NORM.Traffic Received (packets)",		OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
	pktssec_rcvd_stathandle 	= op_stat_reg ("NORM.Traffic Received (packets/sec)",	OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
	bits_sent_stathandle 		= op_stat_reg ("NORM.Traffic Sent (bits)",			OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
	bitssec_sent_stathandle 	= op_stat_reg ("NORM.Traffic Sent (bits/sec)",		OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
	pkts_sent_stathandle 		= op_stat_reg ("NORM.Traffic Sent (packets)",		OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
	pktssec_sent_stathandle 	= op_stat_reg ("NORM.Traffic Sent (packets/sec)",	OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
	ete_delay_stathandle		= op_stat_reg ("NORM.End-to-End Delay (seconds)",		OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);

	bits_rcvd_gstathandle 		= op_stat_reg ("NORM.Traffic Received (bits)",			OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
	bitssec_rcvd_gstathandle 	= op_stat_reg ("NORM.Traffic Received (bits/sec)",		OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
	pkts_rcvd_gstathandle 		= op_stat_reg ("NORM.Traffic Received (packets)",		OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
	pktssec_rcvd_gstathandle 	= op_stat_reg ("NORM.Traffic Received (packets/sec)",	OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
	bits_sent_gstathandle 		= op_stat_reg ("NORM.Traffic Sent (bits)",			OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
	bitssec_sent_gstathandle 	= op_stat_reg ("NORM.Traffic Sent (bits/sec)",		OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
	pkts_sent_gstathandle 		= op_stat_reg ("NORM.Traffic Sent (packets)",		OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
	pktssec_sent_gstathandle 	= op_stat_reg ("NORM.Traffic Sent (packets/sec)",	OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
	ete_delay_gstathandle		= op_stat_reg ("NORM.End-to-End Delay (seconds)",	OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);

	/* Read norm comands specified via opnet model attributes */
	printf("NORM settings for %s:\n",node_name);
	char val[128];
	int tog;
	op_ima_obj_attr_get_str(my_id,"debug",128,val);		// debug level
	if (val[0])
		{
		printf(" debug =  %s\n",val);
		norm_proc.ProcessCommand("debug",val);
		}
	op_ima_obj_attr_get_str(my_id,"log",128,val);		// log file name
	if (val[0])
		{
		printf(" log =  %s\n",val);
		norm_proc.ProcessCommand("log",val);
		}
	op_ima_obj_attr_get_toggle(my_id,"trace",&tog);		// message tracing
	if (tog)
		{
		printf(" trace on\n",val);
		norm_proc.ProcessCommand("trace",NULL);
		}
	op_ima_obj_attr_get_str(my_id,"txloss",128,val);	// tx packet loss percent
	if (val[0])
		{
		printf(" txloss =  %s\n",val);
		norm_proc.ProcessCommand("txloss",val);
		}
	op_ima_obj_attr_get_str(my_id,"rxloss",128,val);	// rx packet loss percent
	if (val[0])
		{
		printf(" rxloss =  %s\n",val);
		norm_proc.ProcessCommand("rxloss",val);
		}
	op_ima_obj_attr_get_str(my_id,"address",128,val);	// session dest address
	if (val[0])
		{
		List* 	fieldlist;		
		printf(" address =  %s\n",val);
		norm_proc.ProcessCommand("address",val);
		fieldlist = op_prg_str_decomp ( val , "/" );
		dest_ip_addr = ip_address_create((const char *)op_prg_list_access(fieldlist, 0));
		local_port = atoi ((const char *)op_prg_list_access(fieldlist, 1));
		op_prg_list_free ( fieldlist ); 
		op_prg_mem_free ( fieldlist );
		}
	op_ima_obj_attr_get_str(my_id,"ttl",128,val);		// multicast ttl
	if (val[0])
		{
		printf(" ttl =  %s\n",val);
		norm_proc.ProcessCommand("ttl",val); // maybe shouldn't use norm_proc code
		}
	op_ima_obj_attr_get_str(my_id,"rate",128,val);		// tx rate
	if (val[0])
		{
		printf(" rate =  %s\n",val);
		norm_proc.ProcessCommand("rate",val);
		}
	op_ima_obj_attr_get_str(my_id,"cc",128,val);		// congestion control on/off
	if (val[0])
		{
		printf(" cc =  %s\n",val);
		norm_proc.ProcessCommand("cc",val);
		}
	op_ima_obj_attr_get_str(my_id,"backoff",128,val);	// backoff factor 'k' (maxBackoff = k * GRTT)
	if (val[0])
		{
		printf(" backoff =  %s\n",val);
		norm_proc.ProcessCommand("backoff",val);
		}
	op_ima_obj_attr_get_str(my_id,"interval",128,val);	// delay between tx objects
	if (val[0])
		{
		printf(" interval =  %s\n",val);
		norm_proc.ProcessCommand("interval",val);
		}
	op_ima_obj_attr_get_str(my_id,"repeat",128,val);	// number of times to repeat tx object set
	if (val[0])
		{
		printf(" repeat =  %s\n",val);
		norm_proc.ProcessCommand("repeat",val);
		}
	op_ima_obj_attr_get_str(my_id,"segment",128,val);	// server segment size
	if (val[0])
		{
		printf(" segment =  %s\n",val);
		norm_proc.ProcessCommand("segment",val);
		}
	op_ima_obj_attr_get_str(my_id,"block",128,val);		// server blocking size
	if (val[0])
		{
		printf(" block =  %s\n",val);
		norm_proc.ProcessCommand("block",val);
		}
	op_ima_obj_attr_get_str(my_id,"parity",128,val);	// server parity segments calculated per block
	if (val[0])
		{
		printf(" parity =  %s\n",val);
		norm_proc.ProcessCommand("parity",val);
		}
	op_ima_obj_attr_get_str(my_id,"auto",128,val);		// server auto parity count
	if (val[0])
		{
		printf(" auto =  %s\n",val);
		norm_proc.ProcessCommand("auto",val);
		}
	op_ima_obj_attr_get_str(my_id,"extra",128,val);		// server extra parity count
	if (val[0])
		{
		printf(" extra =  %s\n",val);
		norm_proc.ProcessCommand("extra",val);
		}
	op_ima_obj_attr_get_str(my_id,"gsize",128,val);		// group size estimate
	if (val[0])
		{
		printf(" gsize =  %s\n",val);
		norm_proc.ProcessCommand("gsize",val);
		}
	op_ima_obj_attr_get_str(my_id,"grtt",128,val);		// grtt estimate
	if (val[0])
		{
		printf(" grtt =  %s\n",val);
		norm_proc.ProcessCommand("grtt",val);
		}
	op_ima_obj_attr_get_str(my_id,"txbuffer",128,val);	// tx buffer size (bytes)
	if (val[0])
		{
		printf(" txbuffer =  %s\n",val);
		norm_proc.ProcessCommand("txbuffer",val);
		}
	op_ima_obj_attr_get_str(my_id,"rxbuffer",128,val);	// rx buffer size (bytes)
	if (val[0])
		{
		printf(" rxbuffer =  %s\n",val);
		norm_proc.ProcessCommand("rxbuffer",val);
		}
	op_ima_obj_attr_get_str(my_id,"sendRandomFile",128,val);	// queue random-size file size range <sizeMin>:<sizeMax>
	if (val[0])
		{
		printf(" sendRandomFile =  %s\n",val);
		norm_proc.ProcessCommand("sendRandomFile",val);
		}
	op_ima_obj_attr_get_str(my_id,"push",128,val);	// "on" means real-time push stream advancement (non-blocking) on|off
	if (val[0])
		{
		printf(" push =  %s\n",val);
		norm_proc.ProcessCommand("push",val);
		}
	op_ima_obj_attr_get_str(my_id,"flush",128,val);	// stream flush mode (none|passive|active)
	if (val[0])
		{
		printf(" flush =  %s\n",val);
		norm_proc.ProcessCommand("flush",val);
		}
	op_ima_obj_attr_get_str(my_id,"unicastNacks",128,val);	// clients will unicast feedback
	if (val[0])
		{
		printf(" unicastNacks =  %s\n",val);
		norm_proc.ProcessCommand("unicastNacks",val);
		}
	op_ima_obj_attr_get_str(my_id,"silentClient",128,val);	// clients will not transmit
	if (val[0])
		{
		printf(" silentClient =  %s\n",val);
		norm_proc.ProcessCommand("silentClient",val);
		}
	
	norm_conf_udp ();

	FOUT;
	}


void norm_stop()
	{
	FIN(norm_stop());
	norm_proc.OnShutdown();
	FOUT;
	}


void
norm_fatal_error (char *emsg)
	{
	char info[40];
	/** Abort the simulation with the given message. **/
	FIN (norm_fatal_error (emsg));
   
	sprintf(info, "NORM Error(%s):", node_name);
	op_sim_end (info, emsg, OPC_NIL, OPC_NIL);

	FOUT;
	}


void
norm_warn_error (char *wmsg)
	{
	char info[40];
	
	/** Issue an warning (used for potentially inconsistent situations). **/
	FIN (norm_warn_error (wmsg));
	
	sprintf(info, "NORM Warning(%s):", node_name);

	if (op_prg_odb_ltrace_active ("norm warn"))
		op_prg_odb_print_minor (info, wmsg, OPC_NIL);

	FOUT;
	}



/*  Function to configure the proper input/output streams to the udp process 
    and setup the udp port numbers via the ICI facility  */
void
norm_conf_udp()
	{
	int					outstrm_count;
	Objid				outstrm_objid;
    List*			 	proc_record_handle_list_ptr;
    OmsT_Pr_Handle		temp_process_record_handle;

	FIN(norm_conf_udp());
	
	/*                                                         */
	/* Get the outgoing packet stream index to the UDP process */
	/*                                                         */
	
    /* First, get the number of output streams for the NORM process. */
    outstrm_count = op_topo_assoc_count (my_id, OPC_TOPO_ASSOC_OUT, OPC_OBJTYPE_STRM);
    /* Then, make sure there's two outgoing streams from NORM. */
    if (outstrm_count != 2)
    	norm_fatal_error ("NORM does not have two outgoing streams - one to MGEN & one to UDP.");
	/* Then, get the outgoing stream Objid */
    outstrm_objid = op_topo_assoc (my_id, OPC_TOPO_ASSOC_OUT, OPC_OBJTYPE_STRM, 0);
	/* Retrieve the index of the stream. */
	op_ima_obj_attr_get (outstrm_objid, "src stream", &udp_outstream_index);

    /* 						                                                    */
    /* Locate the UDP module. It must have registered in the process registry.  */
    /* 						                                                    */
	
    /* Obtain the process handles by matching the specific descriptors			*/
    proc_record_handle_list_ptr = op_prg_list_create ();
    oms_pr_process_discover (OPC_OBJID_INVALID, proc_record_handle_list_ptr,
    	"node objid",	OMSC_PR_OBJID,		my_node_id,
    	"protocol",		OMSC_PR_STRING,		"udp",
    	OPC_NIL);

    /* Each node can have only one UDP module.	*/
    if (op_prg_list_size (proc_record_handle_list_ptr) != 1)
    	{
    	/* Having more than one UDP module is a serious error.  End simulation. */
	    norm_fatal_error ("Error: either zero or several UDP processes found in the local node"); 
    	}
    temp_process_record_handle = (OmsT_Pr_Handle) op_prg_list_access (proc_record_handle_list_ptr, OPC_LISTPOS_TAIL);

    /* Obtain the module objid of the udp module	*/
    oms_pr_attr_get (temp_process_record_handle, "module objid",OMSC_PR_OBJID, &my_udp_id);
	
	norm_proc.SetUdpProcessId(my_udp_id);  /*  - OpnetProtoSimProcess.h */

    /* Deallocate the memory allocated for holding the record handle	*/
    while (op_prg_list_size (proc_record_handle_list_ptr) > 0)
    	op_prg_list_remove (proc_record_handle_list_ptr, OPC_LISTPOS_HEAD);

    /* Deallocate the temporary list pointer. */
    op_prg_mem_free (proc_record_handle_list_ptr);	
		
	FOUT;
	}


void norm_host_addr ()
	{
	FIN (norm_host_addr());

    /* Obtain a pointer to the process record handle list of any 
       IP processes residing in the local node.
	*/
    List* proc_record_handle_list_ptr = op_prg_list_create();
    oms_pr_process_discover(OPC_OBJID_INVALID, proc_record_handle_list_ptr,
	                        "protocol", OMSC_PR_STRING, "ip",
	                        "node objid", OMSC_PR_OBJID, my_node_id, 
	                        OPC_NIL);

    /* An error should be created if there are zero or more than     
       one IP processes in the local node.
	*/
    int record_handle_list_size = op_prg_list_size (proc_record_handle_list_ptr);
    IpT_Info* ip_info_ptr;
    if (1 != record_handle_list_size)
		{
	    /* Generate an error and end simulation. */
	    op_sim_end("Error: either zero or more than one ip processes in local node.", "", "", "");
		}
    else
		{
        /* Obtain the process record handle of the IP process. */
	    OmsT_Pr_Handle process_record_handle = (OmsT_Pr_Handle) op_prg_list_access(proc_record_handle_list_ptr, OPC_LISTPOS_HEAD);
	    /* Obtain the pointer to the interface info structure. */
	    oms_pr_attr_get(process_record_handle, "interface information", OMSC_PR_ADDRESS, &ip_info_ptr);
		}

    /* Deallocate the list pointer. */
    while (op_prg_list_size(proc_record_handle_list_ptr) > 0)
	    op_prg_list_remove(proc_record_handle_list_ptr, OPC_LISTPOS_HEAD);
    op_prg_mem_free(proc_record_handle_list_ptr);

    /* Obtain the pointer to the IP interface table.
	   Note that the ip_info_ptr->ip_iface_table_ptr is the same list
	     as module_data->interface_table_ptr as shown in ip_dispatch.pr.c->ip_dispatch_do_int()
	*/
    List* ip_iface_table_ptr = ip_info_ptr->ip_iface_table_ptr;

    /* Obtain the size of the IP interface table. */
    int ip_iface_table_size = op_prg_list_size(ip_iface_table_ptr);

	int interface_info_index = 0;  /* LP */
	
    /* For now, an error should be created if there are zero or more than 
       one IP interface attached to this node.  Loopback interfaces
	   and Tunnel interfaces are OK.
	*/
	
	/* In the future, we should allow more than 1 IP interface for the
	   case of IP routers. LP 3-4-04
	*/
	
    if (1 != ip_iface_table_size)
		{

		/* check to see if there is any loopback interface or tunnel interface.  (LP 3-1-04 - added) */
		int i, ip_intf_count = 0;
		bool dumb_intf = OPC_FALSE;
		for (i = 0; i < ip_iface_table_size; i++)
			{
   			IpT_Interface_Info* intf_ptr = (IpT_Interface_Info*) op_prg_list_access(ip_iface_table_ptr, OPC_LISTPOS_HEAD + i);
			if ((intf_ptr->phys_intf_info_ptr->intf_status == IpC_Intf_Status_Tunnel) ||
				(intf_ptr->phys_intf_info_ptr->intf_status == IpC_Intf_Status_Loopback))
				{
				dumb_intf = OPC_TRUE;
				break;
				} /* end if tunnel || loop back */
			else
				{
				interface_info_index = i;
				ip_intf_count ++;
				}
			} /* end for i */

	    /* Generate an error and end simulation. */
	    if ((dumb_intf == OPC_FALSE) || (ip_intf_count > 1))  /* end LP */
			op_sim_end("Error: either zero or more than one ip interface on this node.", "", "", "");
		}  /* end if ip_iface_table-size != 1 */
	
    	
	/* Obtain a pointer to the IP interface data structure. */	
	IpT_Interface_Info* interface_info_pnt = (IpT_Interface_Info*) op_prg_list_access(ip_iface_table_ptr, OPC_LISTPOS_HEAD + interface_info_index);
	my_ip_addr = interface_info_pnt->addr_range_ptr->address;
	my_ip_mask = interface_info_pnt->addr_range_ptr->subnet_mask;
	host_ipv4_addr.SimSetAddress(my_ip_addr);
//	norm_proc.SetHostAddress(host_ipv4_addr);
		
	FOUT;
	}

OpnetNormProcess::OpnetNormProcess()
 : NormSimAgent(GetTimerMgr(), GetSocketNotifier())
{
 printf("OpnetNormProcess::OpnetNormProcess():  this = %x\n", this);
}  

OpnetNormProcess::~OpnetNormProcess()
{    
}


IpT_Address OpnetNormProcess::addr()
	{
	FIN(OpnetNormProcess());
	FRET (my_ip_addr);
	}


bool OpnetNormProcess::OnStartup(int argc, const char*const* argv)
{
	char val[128];
	
	FIN (OnStartup(argc,argv));
	norm_proc.SetSink(new OpnetProtoMessageSink(app_ici_ptr,OUTSTRM_TO_MGEN,local_port));
	norm_host_addr();
	op_ima_obj_attr_get_str(my_id,"start",128,val);	// clients will unicast feedback
	if (val[0])
		{
		printf(" NORM start =  %s\n",val);
		ProcessCommand("start",val);
		}
	op_ima_obj_attr_get_str(my_id,"sendStream",128,val);	// send a simulated NORM stream
	if (val[0])
		{
		printf(" NORM sendStream =  %s\n",val);
		ProcessCommand("sendStream",val);
		}
	op_ima_obj_attr_get_str(my_id,"openStream",128,val);	// open a stream object for messaging
	if (val[0])
		{
		printf(" NORM openStream =  %s\n",val);
		ProcessCommand("openStream",val);
		/* JPH 4/11/06  fake attachment of mgen instance */
		//AttachMgen((Mgen*)true);
		}
	op_ima_obj_attr_get_str(my_id,"sendFile",128,val);	// queue a "sim" file of <size> bytes for transmission
	if (val[0])
		{
		printf(" sendFile =  %s\n",val);
		ProcessCommand("sendFile",val);
		}
	FRET (true);
} // end OpnetNormProcess::OnStartup()

void OpnetNormProcess::OnShutdown()
{
	ProcessCommand("stop",NULL);
}  // end OpnetNormProcess::OnShutdown()

bool OpnetNormProcess::ProcessCommands(int argc, const char*const* argv) 
{   
    // Process commands, passing unknown commands to base Agent class
    int i = 1;
    while (i < argc)
    {
        NormSimAgent::CmdType cmdType = CommandType(argv[i]);
        switch (cmdType)
        {
            case NormSimAgent::CMD_NOARG:
                if (!ProcessCommand(argv[i], NULL))
                {
                    DMSG(0, "OpnetNormProcess::ProcessCommands() ProcessCommand(%s) error\n", 
                            argv[i]);
                    return false;
                }
                i++;
                break;
                
            case NormSimAgent::CMD_ARG:
                if (!ProcessCommand(argv[i], argv[i+1]))
                {
                    DMSG(0, "OpnetNormProcess::ProcessCommands() ProcessCommand(%s, %s) error\n", 
                            argv[i], argv[i+1]);
                    return false;
                }
                i += 2;
                break;
                
            case NormSimAgent::CMD_INVALID:
                return false;
        }
    }
    return true; 
}  // end OpnetNormProcess::ProcessCommands()


/* This function not used at present.  */
/* SendMessage called directly from send_msg state. */
// JPH 5/25/06 - revert from mgen 42b8 to 42b6
//bool OpnetNormProcess::SendMgenMessage(MgenMsg& theMsg,
//				     bool checksum_enable,
//				     char* txBuffer)
//{
//	int len = 0;
//    return SendMessage(len, txBuffer);
//}  // end OpnetNormProcess::SendMgenMessage()
bool OpnetNormProcess::SendMgenMessage(const char*           txBuffer,
                                  unsigned int          len,
                                  const ProtoAddress&   /*dstAddr*/)
{
    return SendMessage(len, txBuffer);
}  // end OpnetNormProcess::SendMgenMessage()
 


void OpnetNormProcess::ReceivePacketMonitor(Ici* iciptr, Packet* pkptr)
	{
	FIN (ReceivePacketMonitor(iciptr,pkptr));
	/* Caclulate metrics to be updated.		*/
	double pk_size = (double) op_pk_total_size_get (pkptr);
	double ete_delay = op_sim_time () - op_pk_creation_time_get (pkptr);

	/* Update local statistics.				*/
	op_stat_write (bits_rcvd_stathandle, 		pk_size);
	op_stat_write (pkts_rcvd_stathandle, 		1.0);
	op_stat_write (ete_delay_stathandle, 		ete_delay);

	op_stat_write (bitssec_rcvd_stathandle, 	pk_size);
	op_stat_write (bitssec_rcvd_stathandle, 	0.0);
	op_stat_write (pktssec_rcvd_stathandle, 	1.0);
	op_stat_write (pktssec_rcvd_stathandle, 	0.0);

	/* Update global statistics.	*/
	op_stat_write (bits_rcvd_gstathandle, 		pk_size);
	op_stat_write (pkts_rcvd_gstathandle, 		1.0);
	op_stat_write (ete_delay_gstathandle, 		ete_delay);

	op_stat_write (bitssec_rcvd_gstathandle, 	pk_size);
	op_stat_write (bitssec_rcvd_gstathandle, 	0.0);
	op_stat_write (pktssec_rcvd_gstathandle, 	1.0);
	op_stat_write (pktssec_rcvd_gstathandle, 	0.0);
	FOUT;
	}



void OpnetNormProcess::TransmitPacketMonitor(Ici* ici, Packet* pkptr) 
	{
	FIN (TransmitPacketMonitor(ici,pkptr));
	/* Caclulate metrics to be updated.		*/
	double pk_size = (double) op_pk_total_size_get (pkptr);

	/* Update local statistics.				*/
	op_stat_write (bits_sent_stathandle, 		pk_size);
	op_stat_write (pkts_sent_stathandle, 		1.0);

	op_stat_write (bitssec_sent_stathandle, 	pk_size);
	op_stat_write (bitssec_sent_stathandle, 	0.0);
	op_stat_write (pktssec_sent_stathandle, 	1.0);
	op_stat_write (pktssec_sent_stathandle, 	0.0);

	/* Update global statistics.	*/
	op_stat_write (bits_sent_gstathandle, 		pk_size);
	op_stat_write (pkts_sent_gstathandle, 		1.0);

	op_stat_write (bitssec_sent_gstathandle, 	pk_size);
	op_stat_write (bitssec_sent_gstathandle, 	0.0);
	op_stat_write (pktssec_sent_gstathandle, 	1.0);
	op_stat_write (pktssec_sent_gstathandle, 	0.0);
	FOUT;
	}


/* End of Function Block */

/* Undefine optional tracing in FIN/FOUT/FRET */
/* The FSM has its own tracing code and the other */
/* functions should not have any tracing.		  */
#undef FIN_TRACING
#define FIN_TRACING

#undef FOUTRET_TRACING
#define FOUTRET_TRACING

/* Undefine shortcuts to state variables because the */
/* following functions are part of the state class */
#undef norm_proc
#undef my_id
#undef my_node_id
#undef my_pro_id
#undef my_udp_id
#undef my_tcp_id
#undef my_mgen_id
#undef my_ip_addr
#undef my_ip_mask
#undef own_prohandle
#undef own_process_record_handle
#undef pid_string
#undef node_name
#undef timer
#undef udpsocket
#undef tcpsocket
#undef udpnotifier
#undef tcpnotifier
#undef host_ipv4_addr
#undef bits_rcvd_stathandle
#undef bitssec_rcvd_flow_stathandle
#undef bitssec_sent_flow_stathandle
#undef bitssec_rcvd_stathandle
#undef pkts_rcvd_stathandle
#undef pktssec_rcvd_flow_stathandle
#undef pktssec_sent_flow_stathandle
#undef pktssec_rcvd_stathandle
#undef bits_sent_stathandle
#undef bitssec_sent_stathandle
#undef pkts_sent_stathandle
#undef pktssec_sent_stathandle
#undef ete_delay_stathandle
#undef ete_delay_flow_stathandle
#undef bits_rcvd_gstathandle
#undef bitssec_rcvd_gstathandle
#undef pkts_rcvd_gstathandle
#undef pktssec_rcvd_gstathandle
#undef bits_sent_gstathandle
#undef bitssec_sent_gstathandle
#undef pkts_sent_gstathandle
#undef pktssec_sent_gstathandle
#undef ete_delay_gstathandle
#undef udp_outstream_index
#undef local_port
#undef dest_ip_addr
#undef script_fp
#undef source
#undef app_ici_ptr

/* Access from C kernel using C linkage */
extern "C"
{
	VosT_Obtype _op_norm_protolib_init (int * init_block_ptr);
	VosT_Address _op_norm_protolib_alloc (VosT_Obtype, int);
	void norm_protolib (OP_SIM_CONTEXT_ARG_OPT)
		{
		((norm_protolib_state *)(OP_SIM_CONTEXT_PTR->_op_mod_state_ptr))->norm_protolib (OP_SIM_CONTEXT_PTR_OPT);
		}

	void _op_norm_protolib_svar (void *, const char *, void **);

	void _op_norm_protolib_diag (OP_SIM_CONTEXT_ARG_OPT)
		{
		((norm_protolib_state *)(OP_SIM_CONTEXT_PTR->_op_mod_state_ptr))->_op_norm_protolib_diag (OP_SIM_CONTEXT_PTR_OPT);
		}

	void _op_norm_protolib_terminate (OP_SIM_CONTEXT_ARG_OPT)
		{
		/* The destructor is the Termination Block */
		delete (norm_protolib_state *)(OP_SIM_CONTEXT_PTR->_op_mod_state_ptr);
		}


	VosT_Obtype Vos_Define_Object_Prstate (const char * _op_name, size_t _op_size);
	VosT_Address Vos_Alloc_Object (VosT_Obtype _op_ob_hndl);
	VosT_Fun_Status Vos_Poolmem_Dealloc (VosT_Address _op_ob_ptr);
} /* end of 'extern "C"' */




/* Process model interrupt handling procedure */


void
norm_protolib_state::norm_protolib (OP_SIM_CONTEXT_ARG_OPT)
	{
#if !defined (VOSD_NO_FIN)
	int _op_block_origin = 0;
#endif
	FIN_MT (norm_protolib_state::norm_protolib ());
	try
		{
		/* Temporary Variables */
		Packet*			data_pkptr;
		Ici*			ici_ptr;
		int				intrpt_type;
		int				intrpt_strm;
		int				intrpt_code;
		
		int				pk_size;
		InetT_Address*	rem_addr_ptr;
		InetT_Address*	intf_addr_ptr;
		InetT_Address	temp_ip_addr;
		InetT_Address	intf_addr;
		int				type_of_service; 
		int				inet_address_supported;
		IpT_Address		rem_ipv4_addr;
		IpT_Address		ipv4_intf_addr;
		UdpT_Port		rem_port;
		int				local_minor_port;
		int				conn_class;
		int				intf_num;
		
		
		
		
		/* End of Temporary Variables */


		FSM_ENTER ("norm_protolib")

		FSM_BLOCK_SWITCH
			{
			/*---------------------------------------------------------*/
			/** state (idle) enter executives **/
			FSM_STATE_ENTER_UNFORCED (0, "idle", state0_enter_exec, "norm_protolib [idle enter execs]")

			/** blocking after enter executives of unforced state. **/
			FSM_EXIT (1,"norm_protolib")


			/** state (idle) exit executives **/
			FSM_STATE_EXIT_UNFORCED (0, "idle", "norm_protolib [idle exit execs]")
				FSM_PROFILE_SECTION_IN ("norm_protolib [idle exit execs]", state0_exit_exec)
				{
				intrpt_type = op_intrpt_type ();
				if (intrpt_type == OPC_INTRPT_STRM)
					intrpt_strm = op_intrpt_strm ();
				else
					intrpt_code = op_intrpt_code ();
				ici_ptr = op_intrpt_ici ();
				}
				FSM_PROFILE_SECTION_OUT (state0_exit_exec)


			/** state (idle) transition processing **/
			FSM_PROFILE_SECTION_IN ("norm_protolib [idle trans conditions]", state0_trans_conds)
			FSM_INIT_COND (END_SIM)
			FSM_TEST_COND (MSG_FROM_LOWER_LAYER)
			FSM_TEST_COND (TIMEOUT_EVENT)
			FSM_TEST_COND (MSG_FROM_HIGHER_LAYER)
			FSM_DFLT_COND
			FSM_TEST_LOGIC ("idle")
			FSM_PROFILE_SECTION_OUT (state0_trans_conds)

			FSM_TRANSIT_SWITCH
				{
				FSM_CASE_TRANSIT (0, 0, state0_enter_exec, norm_stop();, "END_SIM", "norm_stop()", "idle", "idle", "norm_protolib [idle -> idle : END_SIM / norm_stop()]")
				FSM_CASE_TRANSIT (1, 3, state3_enter_exec, ;, "MSG_FROM_LOWER_LAYER", "", "idle", "proc_msg", "norm_protolib [idle -> proc_msg : MSG_FROM_LOWER_LAYER / ]")
				FSM_CASE_TRANSIT (2, 4, state4_enter_exec, ;, "TIMEOUT_EVENT", "", "idle", "itimer", "norm_protolib [idle -> itimer : TIMEOUT_EVENT / ]")
				FSM_CASE_TRANSIT (3, 5, state5_enter_exec, ;, "MSG_FROM_HIGHER_LAYER", "", "idle", "send_msg", "norm_protolib [idle -> send_msg : MSG_FROM_HIGHER_LAYER / ]")
				FSM_CASE_TRANSIT (4, 0, state0_enter_exec, ;, "default", "", "idle", "idle", "norm_protolib [idle -> idle : default / ]")
				}
				/*---------------------------------------------------------*/



			/** state (init) enter executives **/
			FSM_STATE_ENTER_UNFORCED_NOLABEL (1, "init", "norm_protolib [init enter execs]")
				FSM_PROFILE_SECTION_IN ("norm_protolib [init enter execs]", state1_enter_exec)
				{
				app_ici_ptr = op_ici_create ("sink_command");
				
				/* Obtain the object ID of the surrounding norm processor. 	*/
				my_id = op_id_self ();
				
				/* Also obtain the object ID of the surrounding node.		*/
				my_node_id = op_topo_parent (my_id);
				
				/* Obtain the prohandle for this process.					*/
				own_prohandle = op_pro_self ();
				
				/**	Register the process in the model-wide registry.				**/
				own_process_record_handle = (OmsT_Pr_Handle) oms_pr_process_register 
					(my_node_id, my_id, own_prohandle, "NORM");
				
				/*	Register the protocol attribute in the registry. No other	*/
				/*	process should use the string "norm" as the value for its	*/
				/*	"protocol" attribute!										*/
				oms_pr_attr_set (own_process_record_handle, 
					"protocol", 	OMSC_PR_STRING, 	"norm",
					OPC_NIL);
				
				/*	Initialize the state variable used to keep track of the	*/
				/*	NORM module object ID and to generate trace/debugging 	*/
				/*	string information. Obtain process ID of this process. 	*/
				my_pro_id = op_pro_id (op_pro_self ());
				
				/* 	Set the process ID string, to be later used for trace	*/
				/*	and debugging information.								*/
				sprintf (pid_string, "NORM PID (%d)", my_pro_id);
				
				/* Get the name of the surrounding node object */
				op_ima_obj_attr_get (my_node_id, "name", &node_name);
				
				/* 	Schedule a self interrupt to allow  additional initialization. */
				op_intrpt_schedule_self (op_sim_time (), 0);
				}
				FSM_PROFILE_SECTION_OUT (state1_enter_exec)

			/** blocking after enter executives of unforced state. **/
			FSM_EXIT (3,"norm_protolib")


			/** state (init) exit executives **/
			FSM_STATE_EXIT_UNFORCED (1, "init", "norm_protolib [init exit execs]")
				FSM_PROFILE_SECTION_IN ("norm_protolib [init exit execs]", state1_exit_exec)
				{
				norm_init();
				op_intrpt_schedule_self (0.0,0);
				}
				FSM_PROFILE_SECTION_OUT (state1_exit_exec)


			/** state (init) transition processing **/
			FSM_TRANSIT_FORCE (2, state2_enter_exec, ;, "default", "", "init", "init2", "norm_protolib [init -> init2 : default / ]")
				/*---------------------------------------------------------*/



			/** state (init2) enter executives **/
			FSM_STATE_ENTER_UNFORCED (2, "init2", state2_enter_exec, "norm_protolib [init2 enter execs]")
				FSM_PROFILE_SECTION_IN ("norm_protolib [init2 enter execs]", state2_enter_exec)
				{
				
				}
				FSM_PROFILE_SECTION_OUT (state2_enter_exec)

			/** blocking after enter executives of unforced state. **/
			FSM_EXIT (5,"norm_protolib")


			/** state (init2) exit executives **/
			FSM_STATE_EXIT_UNFORCED (2, "init2", "norm_protolib [init2 exit execs]")
				FSM_PROFILE_SECTION_IN ("norm_protolib [init2 exit execs]", state2_exit_exec)
				{
				norm_proc.OnStartup(0,NULL);
				}
				FSM_PROFILE_SECTION_OUT (state2_exit_exec)


			/** state (init2) transition processing **/
			FSM_TRANSIT_FORCE (0, state0_enter_exec, ;, "default", "", "init2", "idle", "norm_protolib [init2 -> idle : default / ]")
				/*---------------------------------------------------------*/



			/** state (proc_msg) enter executives **/
			FSM_STATE_ENTER_FORCED (3, "proc_msg", state3_enter_exec, "norm_protolib [proc_msg enter execs]")
				FSM_PROFILE_SECTION_IN ("norm_protolib [proc_msg enter execs]", state3_enter_exec)
				{
				norm_proc.OnReceive(op_intrpt_strm());
				}
				FSM_PROFILE_SECTION_OUT (state3_enter_exec)

			/** state (proc_msg) exit executives **/
			FSM_STATE_EXIT_FORCED (3, "proc_msg", "norm_protolib [proc_msg exit execs]")


			/** state (proc_msg) transition processing **/
			FSM_TRANSIT_FORCE (0, state0_enter_exec, ;, "default", "", "proc_msg", "idle", "norm_protolib [proc_msg -> idle : default / ]")
				/*---------------------------------------------------------*/



			/** state (itimer) enter executives **/
			FSM_STATE_ENTER_FORCED (4, "itimer", state4_enter_exec, "norm_protolib [itimer enter execs]")
				FSM_PROFILE_SECTION_IN ("norm_protolib [itimer enter execs]", state4_enter_exec)
				{
				norm_proc.OnSystemTimeout();
				}
				FSM_PROFILE_SECTION_OUT (state4_enter_exec)

			/** state (itimer) exit executives **/
			FSM_STATE_EXIT_FORCED (4, "itimer", "norm_protolib [itimer exit execs]")


			/** state (itimer) transition processing **/
			FSM_TRANSIT_FORCE (0, state0_enter_exec, ;, "default", "", "itimer", "idle", "norm_protolib [itimer -> idle : default / ]")
				/*---------------------------------------------------------*/



			/** state (send_msg) enter executives **/
			FSM_STATE_ENTER_FORCED (5, "send_msg", state5_enter_exec, "norm_protolib [send_msg enter execs]")
				FSM_PROFILE_SECTION_IN ("norm_protolib [send_msg enter execs]", state5_enter_exec)
				{
				data_pkptr = op_pk_get (intrpt_strm);
				
				/* The total payload size in bits */
				pk_size = (double) op_pk_total_size_get (data_pkptr);
				
				/* ici processing may have some future use for mgen control of norm */
				/********************************************************************/
				op_ici_attr_get (ici_ptr, "inet_support", &inet_address_supported);
				
				if (inet_address_supported)
					{
					/* This is a udp_command_inet ici.				*/
					op_ici_attr_get (ici_ptr, "rem_addr", &rem_addr_ptr);
				
					op_ici_attr_get (ici_ptr, "src_addr", &intf_addr_ptr);
					}
				else
					{
					/* This is a udp_command_v3 ici.				*/
					op_ici_attr_get (ici_ptr, "rem_addr", &rem_ipv4_addr);
				
					/* Convert the address into InetT_Address form.	*/
					temp_ip_addr = inet_address_from_ipv4_address_create (rem_ipv4_addr);
					rem_addr_ptr = &temp_ip_addr;
				
					/* Get the other fields in the ici.				*/
					op_ici_attr_get (ici_ptr, "src_addr", &ipv4_intf_addr);
					intf_addr = inet_address_from_ipv4_address_create_invalid_check (ipv4_intf_addr);
					intf_addr_ptr = &intf_addr;
					}
				 
				op_ici_attr_get (ici_ptr, "rem_port", &rem_port);
				op_ici_attr_get (ici_ptr, "local_port", &local_port);
				op_ici_attr_get (ici_ptr, "local_minor_port", &local_minor_port);
				op_ici_attr_get (ici_ptr, "connection_class", &conn_class);
				op_ici_attr_get (ici_ptr, "Type of Service", &type_of_service);
				
				/* Using the "strm_index" to identify the outgoing IP interface	*/
				/* to allow sending multicast by setting multicast major port	*/
				op_ici_attr_get (ici_ptr, "strm_index", &intf_num);
				/********************************************************************/
				
				char* txBuffer = (char*)op_prg_mem_alloc(pk_size/8);
				op_pk_fd_get (data_pkptr, 0, &txBuffer);
				//int len = pk_size/8;
				//printf("norm_protolib:send_msg:  txBuffer =\n");
				//for (int i = 0; i<len; i+=8)
				//	printf(" %x %x %x %x %x %x %x %x\n",txBuffer[i],txBuffer[i+1],txBuffer[i+2],txBuffer[i+3],txBuffer[i+4],txBuffer[i+5],txBuffer[i+6],txBuffer[i+7]);		
				norm_proc.SendMessage(pk_size/8, txBuffer);
				
				op_pk_destroy (data_pkptr);
				
				
				
				}
				FSM_PROFILE_SECTION_OUT (state5_enter_exec)

			/** state (send_msg) exit executives **/
			FSM_STATE_EXIT_FORCED (5, "send_msg", "norm_protolib [send_msg exit execs]")


			/** state (send_msg) transition processing **/
			FSM_TRANSIT_FORCE (0, state0_enter_exec, ;, "default", "", "send_msg", "idle", "norm_protolib [send_msg -> idle : default / ]")
				/*---------------------------------------------------------*/



			}


		FSM_EXIT (1,"norm_protolib")
		}
	catch (...)
		{
		Vos_Error_Print (VOSC_ERROR_ABORT,
			(const char *)VOSC_NIL,
			"Unhandled C++ exception in process model (norm_protolib)",
			(const char *)VOSC_NIL, (const char *)VOSC_NIL);
		}
	}




void
norm_protolib_state::_op_norm_protolib_diag (OP_SIM_CONTEXT_ARG_OPT)
	{
	/* No Diagnostic Block */
	}

void
norm_protolib_state::operator delete (void* ptr)
	{
	FIN (norm_protolib_state::operator delete (ptr));
	Vos_Poolmem_Dealloc (ptr);
	FOUT
	}

norm_protolib_state::~norm_protolib_state (void)
	{

	FIN (norm_protolib_state::~norm_protolib_state ())


	/* No Termination Block */


	FOUT
	}


#undef FIN_PREAMBLE_DEC
#undef FIN_PREAMBLE_CODE

#define FIN_PREAMBLE_DEC
#define FIN_PREAMBLE_CODE

void *
norm_protolib_state::operator new (size_t)
#if defined (VOSD_NEW_BAD_ALLOC)
		throw (VOSD_BAD_ALLOC)
#endif
	{
	void * new_ptr;

	FIN_MT (norm_protolib_state::operator new ());

	new_ptr = Vos_Alloc_Object (norm_protolib_state::obtype);
#if defined (VOSD_NEW_BAD_ALLOC)
	if (new_ptr == VOSC_NIL) throw VOSD_BAD_ALLOC();
#endif
	FRET (new_ptr)
	}

/* State constructor initializes FSM handling */
/* by setting the initial state to the first */
/* block of code to enter. */

norm_protolib_state::norm_protolib_state (void) :
		_op_current_block (2)
	{
#if defined (OPD_ALLOW_ODB)
		_op_current_state = "norm_protolib [init enter execs]";
#endif
	}

VosT_Obtype
_op_norm_protolib_init (int * init_block_ptr)
	{
	FIN_MT (_op_norm_protolib_init (init_block_ptr))

	norm_protolib_state::obtype = Vos_Define_Object_Prstate ("proc state vars (norm_protolib)",
		sizeof (norm_protolib_state));
	*init_block_ptr = 2;

	FRET (norm_protolib_state::obtype)
	}

VosT_Address
_op_norm_protolib_alloc (VosT_Obtype, int)
	{
#if !defined (VOSD_NO_FIN)
	int _op_block_origin = 0;
#endif
	norm_protolib_state * ptr;
	FIN_MT (_op_norm_protolib_alloc ())

	/* New instance will have FSM handling initialized */
#if defined (VOSD_NEW_BAD_ALLOC)
	try {
		ptr = new norm_protolib_state;
	} catch (const VOSD_BAD_ALLOC &) {
		ptr = VOSC_NIL;
	}
#else
	ptr = new norm_protolib_state;
#endif
	FRET ((VosT_Address)ptr)
	}



void
_op_norm_protolib_svar (void * gen_ptr, const char * var_name, void ** var_p_ptr)
	{
	norm_protolib_state		*prs_ptr;

	FIN_MT (_op_norm_protolib_svar (gen_ptr, var_name, var_p_ptr))

	if (var_name == OPC_NIL)
		{
		*var_p_ptr = (void *)OPC_NIL;
		FOUT
		}
	prs_ptr = (norm_protolib_state *)gen_ptr;

	if (strcmp ("norm_proc" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->norm_proc);
		FOUT
		}
	if (strcmp ("my_id" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->my_id);
		FOUT
		}
	if (strcmp ("my_node_id" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->my_node_id);
		FOUT
		}
	if (strcmp ("my_pro_id" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->my_pro_id);
		FOUT
		}
	if (strcmp ("my_udp_id" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->my_udp_id);
		FOUT
		}
	if (strcmp ("my_tcp_id" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->my_tcp_id);
		FOUT
		}
	if (strcmp ("my_mgen_id" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->my_mgen_id);
		FOUT
		}
	if (strcmp ("my_ip_addr" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->my_ip_addr);
		FOUT
		}
	if (strcmp ("my_ip_mask" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->my_ip_mask);
		FOUT
		}
	if (strcmp ("own_prohandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->own_prohandle);
		FOUT
		}
	if (strcmp ("own_process_record_handle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->own_process_record_handle);
		FOUT
		}
	if (strcmp ("pid_string" , var_name) == 0)
		{
		*var_p_ptr = (void *) (prs_ptr->pid_string);
		FOUT
		}
	if (strcmp ("node_name" , var_name) == 0)
		{
		*var_p_ptr = (void *) (prs_ptr->node_name);
		FOUT
		}
	if (strcmp ("timer" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->timer);
		FOUT
		}
	if (strcmp ("udpsocket" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->udpsocket);
		FOUT
		}
	if (strcmp ("tcpsocket" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->tcpsocket);
		FOUT
		}
	if (strcmp ("udpnotifier" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->udpnotifier);
		FOUT
		}
	if (strcmp ("tcpnotifier" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->tcpnotifier);
		FOUT
		}
	if (strcmp ("host_ipv4_addr" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->host_ipv4_addr);
		FOUT
		}
	if (strcmp ("bits_rcvd_stathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->bits_rcvd_stathandle);
		FOUT
		}
	if (strcmp ("bitssec_rcvd_flow_stathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (prs_ptr->bitssec_rcvd_flow_stathandle);
		FOUT
		}
	if (strcmp ("bitssec_sent_flow_stathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (prs_ptr->bitssec_sent_flow_stathandle);
		FOUT
		}
	if (strcmp ("bitssec_rcvd_stathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->bitssec_rcvd_stathandle);
		FOUT
		}
	if (strcmp ("pkts_rcvd_stathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->pkts_rcvd_stathandle);
		FOUT
		}
	if (strcmp ("pktssec_rcvd_flow_stathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (prs_ptr->pktssec_rcvd_flow_stathandle);
		FOUT
		}
	if (strcmp ("pktssec_sent_flow_stathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (prs_ptr->pktssec_sent_flow_stathandle);
		FOUT
		}
	if (strcmp ("pktssec_rcvd_stathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->pktssec_rcvd_stathandle);
		FOUT
		}
	if (strcmp ("bits_sent_stathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->bits_sent_stathandle);
		FOUT
		}
	if (strcmp ("bitssec_sent_stathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->bitssec_sent_stathandle);
		FOUT
		}
	if (strcmp ("pkts_sent_stathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->pkts_sent_stathandle);
		FOUT
		}
	if (strcmp ("pktssec_sent_stathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->pktssec_sent_stathandle);
		FOUT
		}
	if (strcmp ("ete_delay_stathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->ete_delay_stathandle);
		FOUT
		}
	if (strcmp ("ete_delay_flow_stathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (prs_ptr->ete_delay_flow_stathandle);
		FOUT
		}
	if (strcmp ("bits_rcvd_gstathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->bits_rcvd_gstathandle);
		FOUT
		}
	if (strcmp ("bitssec_rcvd_gstathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->bitssec_rcvd_gstathandle);
		FOUT
		}
	if (strcmp ("pkts_rcvd_gstathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->pkts_rcvd_gstathandle);
		FOUT
		}
	if (strcmp ("pktssec_rcvd_gstathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->pktssec_rcvd_gstathandle);
		FOUT
		}
	if (strcmp ("bits_sent_gstathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->bits_sent_gstathandle);
		FOUT
		}
	if (strcmp ("bitssec_sent_gstathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->bitssec_sent_gstathandle);
		FOUT
		}
	if (strcmp ("pkts_sent_gstathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->pkts_sent_gstathandle);
		FOUT
		}
	if (strcmp ("pktssec_sent_gstathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->pktssec_sent_gstathandle);
		FOUT
		}
	if (strcmp ("ete_delay_gstathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->ete_delay_gstathandle);
		FOUT
		}
	if (strcmp ("udp_outstream_index" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->udp_outstream_index);
		FOUT
		}
	if (strcmp ("local_port" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->local_port);
		FOUT
		}
	if (strcmp ("dest_ip_addr" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->dest_ip_addr);
		FOUT
		}
	if (strcmp ("script_fp" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->script_fp);
		FOUT
		}
	if (strcmp ("source" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->source);
		FOUT
		}
	if (strcmp ("app_ici_ptr" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->app_ici_ptr);
		FOUT
		}
	*var_p_ptr = (void *)OPC_NIL;

	FOUT
	}