-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapplication_local_simulation.cpp
More file actions
970 lines (896 loc) · 59.7 KB
/
application_local_simulation.cpp
File metadata and controls
970 lines (896 loc) · 59.7 KB
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: main.cpp
* Author: silas
*
* Created on February 21, 2018, 10:13 AM
*/
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <iomanip> // std::setprecision()
#include <random> //for std::ceil()
#include<unistd.h>
#include<chrono>
#include"boost/date_time/posix_time/posix_time.hpp"
#include "isa-l.h" //Intel library
#include "basicOperations.h" // basic GF(256) operations including reduced row echelon form and matrix printing
#include "codingOperations.h" // coding operations including block encoding and decoding
#include "Variable_Rate_FEC_Encoder.h"
#include "Variable_Rate_FEC_Decoder.h"
#include "FEC_Message.h"
#include "Parameter_Estimator.h"
#include "Payload_Simulator.h"
#include "Erasure_File_Generator.h"
#include "Erasure_Simulator.h"
#include "FEC_Macro.h"
#include "Application_Layer_Sender.h"
#include "Application_Layer_Receiver.h"
#include "basicOperations.h"
using std::cout;
using std::cerr;
using std::endl;
using namespace std::chrono;
int RELAYING_TYPE;
int N_INITIAL;
int N_INITIAL_2;
float EPSILON;
int var_header_size;
int fixed_header_size;
int main(int argc, const char *argv[]) {
std::string output_file_name = "results_summary.csv";
// int burst_length_1=3;
// int burst_length_2=4;
// int start_ind_B1=15;
//// remove("results_summary_B.csv");
// for (int start_ind_B2=start_ind_B1+1;start_ind_B2<start_ind_B1+15;start_ind_B2++){
// ofstream myfile;
// myfile.open(output_file_name, std::ios_base::app);
// myfile << "shift of start B2 from B2=" << start_ind_B2-start_ind_B1 <<",start_ind_B1=" << start_ind_B1 << " end_ind_B1=" <<start_ind_B1+burst_length_1-1 << " , start_ind_B2=" << start_ind_B2 << " end_ind_B2=" << start_ind_B2+burst_length_2-1 << endl;
// myfile.close();
// for (EPSILON=0.01;EPSILON<0.011;EPSILON=EPSILON+0.001) {
// ofstream myfile;
// myfile.open("results_summary_eps_2.csv", std::ios_base::app);
// myfile << "EPSILON=" << EPSILON <<endl;
// myfile.close();
N_INITIAL = -1;
N_INITIAL_2 = -1;
for (RELAYING_TYPE = 1; RELAYING_TYPE <= 3; RELAYING_TYPE++) {
var_header_size=0;
fixed_header_size=0;
if (RELAYING_TYPE == 1) {
remove("packet_loss_MWDF.txt");
remove("affected MWDF.txt");
} else if (RELAYING_TYPE == 2) {
remove("packet_loss_SWDF.txt");
remove("affected SWDF.txt");
} else if (RELAYING_TYPE == 3) {
remove("packet_loss_SD_SWDF.txt");
remove("affected SD-SWDF.txt");
}
int B = N_INITIAL; //if B=-1 and N=-1, then it is adaptive; otherwise, it is non-adaptive
int N = N_INITIAL;
int B2 = N_INITIAL_2; //if B=-1 and N=-1, then it is adaptive; otherwise, it is non-adaptive
int N2 = N_INITIAL_2;
EPSILON=0.0001;
bool adaptive_mode_MDS = false;
int erasure_type = ERASURE_TYPE;
int relaying_type = RELAYING_TYPE;
//*********************************************** fix the parameters below **********/
const char *Tx = "127.0.0.1";
const char *Rx = "127.0.0.1";
const char *Tx2 = "127.0.0.1";
const char *Rx2 = "127.0.0.1";
int packet_size = 300;
int seq_start = 0;
int T, T2, k;
unsigned char **received_data_vector;
if (relaying_type == 0) {
T = T_INITIAL;
T2 = 0;
} else if (relaying_type == 1) {
// message wise
T = T_INITIAL;
T2 = T_INITIAL_2;
} else if (relaying_type == 2 || relaying_type == 3) {
if (N_INITIAL == -1)
T = T_TOT;
else
T = T_TOT - N_INITIAL_2;
if (N_INITIAL_2 == -1)
T2 = T_TOT;
else
T2 = T_TOT - N_INITIAL;
// T=T_INITIAL;
// T2=T_INITIAL_2;
}
int stream_duration = NUMBER_OF_ITERATIONS;
int max_payload = packet_size;
Application_Layer_Sender application_layer_sender(Tx, Rx, packet_size, 0, T, B, N, 0);
Application_Layer_Sender application_layer_relay_sender(Tx2, Rx2, packet_size, 0, T2, B2, N2, 1);
application_layer_sender.variable_rate_FEC_encoder->T2 = T2;
if (N2 == -1) {
application_layer_sender.variable_rate_FEC_encoder->N2 = 0;
application_layer_sender.variable_rate_FEC_encoder->B2 = 0;
}
Application_Layer_Receiver *application_layer_relay_receiver = new Application_Layer_Receiver(Tx, Rx,
max_payload,
erasure_type,
adaptive_mode_MDS,
0);
Application_Layer_Receiver *application_layer_destination_receiver = new Application_Layer_Receiver(Tx2,
Rx2,
max_payload,
erasure_type,
adaptive_mode_MDS,
1);
application_layer_destination_receiver->set_receiver_index(1);
siphon::Erasure_File_Generator erasure_generator;
siphon::Erasure_File_Generator erasure_generator2;
switch (erasure_type) {
case 1:
// erasure_generator.generate_IID(stream_duration + T + T2, EPSILON, "erasure.bin", 0);
// erasure_generator2.generate_IID(stream_duration + T + T2, EPSILON, "erasure2.bin", 0);
erasure_generator.generate_three_sections_IID(30000, 0.05, 40000, 0,
stream_duration - 30000 - 40000 + T + T2,
0.05, "erasure.bin", 0);
erasure_generator2.generate_three_sections_IID(40000, 0.05, 40000, 0,
stream_duration - 40000 - 40000 + T + T2,
0.05, "erasure2.bin", 1);
break;
case 2:
erasure_generator.generate_GE(stream_duration + T, ALPHA, BETA, EPSILON, "erasure.bin", 0);
erasure_generator2.generate_GE(stream_duration + T, ALPHA, BETA, EPSILON, "erasure2.bin", 1);
break;
case 3:
// erasure_generator.generate_GE_varying(stream_duration + T + T2, ALPHA, BETA, EPSILON, "erasure.bin",0);
erasure_generator.generate_Fritchman_varying(stream_duration + T, ALPHA, BETA, EPSILON,NUMBER_OF_STATES, "erasure.bin", 0);
erasure_generator2.generate_Fritchman_varying(stream_duration + T, ALPHA, BETA, EPSILON,NUMBER_OF_STATES, "erasure2.bin", 1);
break;
case 4:
erasure_generator.generate_periodic(stream_duration + T, ERASURE_T, ERASURE_B, ERASURE_N,
"erasure.bin");
break;
case 5:
break; // In case 5, erasure.bin is assumed to be already present
case 6:
erasure_generator.generate_three_sections_IID(3000, EPSILON, 3000, EPSILON_2,
stream_duration - 3000 - 3000 + T + T2, EPSILON_3,
"erasure.bin", 0);
break;
default:
erasure_generator.generate_periodic(stream_duration + T, T, 0, 0, "erasure.bin");
}
//// erasure_generator.generate_three_sections_IID(4000,0,2000,0.33,stream_duration-4000-2000 + T+T2,0,"erasure.bin");
// erasure_generator2.generate_IID(stream_duration + T + T2, 0.1, "erasure2.bin", 2);
// erasure_generator.generate_GE(stream_duration + T, ALPHA, BETA, EPSILON, "erasure.bin", 0);
// erasure_generator2.generate_GE(stream_duration + T, ALPHA, BETA, EPSILON, "erasure2.bin", 1);
// erasure_generator.generate_GE_varying(stream_duration + T, ALPHA, BETA, EPSILON, "erasure.bin", 0);
// erasure_generator.generate_GE_varying(stream_duration + T, ALPHA, BETA, EPSILON, "erasure.bin", 1);
// siphon::Erasure_Simulator erasure_simulator("../Experimental_Logs/erasure70.bin");
// siphon::Erasure_Simulator erasure_simulator2("../Experimental_Logs/erasure80.bin");
siphon::Erasure_Simulator erasure_simulator("erasure.bin");
siphon::Erasure_Simulator erasure_simulator2("erasure2.bin");
auto start_time = high_resolution_clock::now();
// for (int i=360000;i<erasure_simulator2.number_of_erasure;i++) {
// erasure_simulator2.erasure_seq[i] = '\000';
// }
////
// for (int i=360000;i<erasure_simulator.number_of_erasure;i++) {
// erasure_simulator.erasure_seq[i] = '\000';
// }
//// for (int i=0;i<erasure_simulator2.number_of_erasure;i++) {
//// erasure_simulator2.erasure_seq[i] = '\000';
//// }
// for (int i=0;i<361000;i++) {
// erasure_simulator2.erasure_seq[i] = '\000';
// }
////
// for (int i=0;i<361000;i++) {
// erasure_simulator.erasure_seq[i] = '\000';
// }
// erasure_simulator.erasure_seq[2]='\001';
// erasure_simulator.erasure_seq[3]='\001';
// erasure_simulator.erasure_seq[4]='\001';
// erasure_simulator.erasure_seq[5]='\001';
// for (int i=0;i<erasure_simulator.number_of_erasure;i++) {
// erasure_simulator.erasure_seq[i] = '\000';
// }
//
// for (int i=0;i<erasure_simulator2.number_of_erasure;i++) {
// erasure_simulator2.erasure_seq[i] = '\000';
// }
// for (int i=start_ind_B1;i<start_ind_B1+burst_length_1;i++) {
// erasure_simulator.erasure_seq[i] = '\001';
// }
// for (int i=start_ind_B2;i<start_ind_B2+burst_length_2;i++) {
// erasure_simulator2.erasure_seq[i] = '\001';
// }
// erasure_simulator.erasure_seq[2] = '\001';
// erasure_simulator.erasure_seq[3] = '\001';
// erasure_simulator.erasure_seq[4] = '\001';
//
// erasure_simulator2.erasure_seq[7] = '\001';
// erasure_simulator2.erasure_seq[8] = '\001';
// erasure_simulator2.erasure_seq[9] = '\001';
////// erasure_simulator.erasure_seq[2] = '\001';
// erasure_simulator2.erasure_seq[4] = '\001';
// erasure_simulator2.erasure_seq[5] = '\001';
// erasure_simulator.erasure_seq[6] = '\001';
// erasure_simulator.erasure_seq[2] = '\001';
// erasure_simulator.erasure_seq[3] = '\001';
// erasure_simulator.erasure_seq[4]='\001';
// erasure_simulator.erasure_seq[5]='\001';
// erasure_simulator.erasure_seq[6]='\001';
// erasure_simulator.erasure_seq[13]='\001';
// erasure_simulator.erasure_seq[14]='\001';
// erasure_simulator.erasure_seq[15]='\001';
//
// erasure_simulator2.erasure_seq[8]='\001';
// erasure_simulator2.erasure_seq[11]='\001';
// erasure_simulator2.erasure_seq[12]='\001';
// erasure_simulator.erasure_seq[5]='\001';
// erasure_simulator.erasure_seq[6]='\001';
// erasure_simulator.erasure_seq[7]='\001';
// erasure_simulator2.erasure_seq[1]='\001';
// erasure_simulator2.erasure_seq[3]='\001';
// erasure_simulator2.erasure_seq[5]='\001';
// erasure_simulator.erasure_seq[7]='\001';
// erasure_simulator2.erasure_seq[8]='\001';
// erasure_simulator.erasure_seq[9]='\001';
// erasure_simulator.erasure_seq[10]='\001';
// erasure_simulator2.erasure_seq[10]='\001';
cout << "Iteration = " << stream_duration << endl;
int seq_number;
int seq_number2;
unsigned char *udp_parameters = nullptr;
unsigned char *udp_parameters2 = nullptr;
udp_parameters = (unsigned char *) malloc(sizeof(unsigned char) * 12);
udp_parameters2 = (unsigned char *) malloc(sizeof(unsigned char) * 6);
for (int j = 0; j < 12; j++)
udp_parameters[j] = '\000';
for (int j = 0; j < 6; j++)
udp_parameters2[j] = '\000';
int buffer_size;
int buffer_size2;
unsigned char buffer[30000];
unsigned char buffer2[30000];
unsigned char received_data[30000];
unsigned char data_to_transmit_in_relay[30000];
// unsigned char *zero_data=(unsigned char *)malloc(sizeof(unsigned char *) * 300); // Elad to change
// memset(zero_data,'\000',300);
unsigned char response_from_dest_buffer[6];
for (int i = 0; i < 6; i++)
response_from_dest_buffer[i] = 0;
int last_seq_received_from_srouce = -1;
// int n2=T2+1;
// int k2=T2-N_INITIAL_2+1;
int n2_new;
int k2_new;
if (N_INITIAL_2 == -1) {
n2_new = T2 + 1;
k2_new = n2_new;
} else {
n2_new = T2 + 1;
k2_new = T2 - N_INITIAL_2 + 1;
}
int input;
int packet_counter = 0;
float min_rate_debug_debug = 0;
int min_rate_debug_packet_count = 0;
float min_rate_affected_debug = 0;
int min_rate_affected_debug_packet_count = 0;
for (int i = 0;; i++) {
packet_counter++;
// application_layer_sender.generate_message_and_encode(udp_parameters, buffer, &buffer_size); //udp_codeword is
// sent;
if (relaying_type == 0) {// P2P (no relay)
// application_layer_sender.generate_message_and_encode(udp_parameters, buffer,
// &buffer_size); //udp_codeword is
// P2P
application_layer_sender.generate_message_and_encode(udp_parameters, buffer,
&buffer_size);
seq_number = application_layer_relay_receiver->receive_message_and_decode(udp_parameters, nullptr,
buffer,
&buffer_size,
&erasure_simulator,
false);
} else if (relaying_type == 1) {//Message-wise decode and forward
// 1. Currently there is no signalling from the relay to the destination about erased packets at the relay.
// This means that the destination may try to recover erased packets (resulting with false recovery)
// 2. Currently each hop performs adaptation separately and independently. Currently there is no shift in delay between hops.
// 3. Max burst size is MAX_BURST_SIZE_MWDF
// 4. Need to handle restart of reading from file in calc_missed_chars
application_layer_sender.generate_message_and_encode(udp_parameters, buffer,
&buffer_size);
//if (i >= T) {
// message wise DF
// for (int j = 0; j < 6; j++)
// application_layer_relay_receiver->response_from_dest_buffer[j] = udp_parameters2[j];
if (FLAG_FOR_CONSTANT_TRANS && (i < NUMBER_OF_ITERATIONS + T_INITIAL) &&
(erasure_simulator.is_erasure(i) == true)) {//artificial erasure
seq_number = application_layer_relay_receiver->receive_message_and_decode(udp_parameters,
udp_parameters2,
buffer,
&buffer_size,
&erasure_simulator,
true);
} else {
seq_number = application_layer_relay_receiver->receive_message_and_decode(udp_parameters,
udp_parameters2,
buffer,
&buffer_size,
&erasure_simulator,
false);
}
// if (i >= T) {
// if (seq_number >= -1) {
if (seq_number >= T) {
int numOfMessagesStored = application_layer_relay_receiver->fec_decoder->message_vector_to_transmit_stored_index;
int start_index;
if (FLAG_FOR_CONSTANT_TRANS)
if (numOfMessagesStored >= 0)
start_index = numOfMessagesStored;
else
start_index = numOfMessagesStored + 1;
else
start_index = 0;
// if (numOfMessagesStored>=0) {
for (int kk = start_index; kk <= numOfMessagesStored; kk++) {
// printMatrix(application_layer_relay_receiver->fec_decoder->message_vector_to_transmit_stored[kk],1,300);
// cout << application_layer_relay_receiver->fec_decoder->message_vector_to_transmit_stored_seq[kk] << endl;
application_layer_relay_sender.message_wise_encode_at_relay(
application_layer_relay_receiver->fec_decoder->message_vector_to_transmit_stored[kk],
application_layer_relay_receiver->fec_decoder->message_vector_to_transmit_stored_seq[kk],
udp_parameters2, buffer2,
&buffer_size2);
application_layer_destination_receiver->receive_message_and_decode(
udp_parameters2, nullptr, buffer2,
&buffer_size2,
&erasure_simulator2, false);
}
// }
}
// }
// if (i>=T) {
// if (application_layer_relay_receiver->fec_decoder->recovered_message_vector[0]->buffer != NULL) {//recover past messages
// // check if there are codewords recovered in the past
// for (int j = 0; j < T_INITIAL; j++) {
// if (application_layer_relay_receiver->fec_decoder->recovered_message_vector[j]->buffer !=
// NULL) {
// printMatrix(application_layer_relay_receiver->fec_decoder->recovered_message_vector[j]->buffer,1,300);
// cout<<application_layer_relay_receiver->fec_decoder->recovered_message_vector[j]->seq_number<<endl;
// application_layer_relay_sender.message_wise_encode_at_relay(
// application_layer_relay_receiver->fec_decoder->recovered_message_vector[j]->buffer,
// application_layer_relay_receiver->fec_decoder->recovered_message_vector[j]->seq_number,
// udp_parameters2, buffer2,
// &buffer_size2, response_from_dest_buffer);
// // after transmitting zero (in case next packet is lost...)
// application_layer_relay_receiver->fec_decoder->recovered_message_vector[j]->buffer=NULL;
// application_layer_destination_receiver->receive_message_and_decode(
// udp_parameters2, buffer2,
// &buffer_size2,
// &erasure_simulator2);
// } else {
// break;
// }
// }
// for (int j = 0; j < MAX_BURST_SIZE_MWDF; j++) {
// if (application_layer_relay_receiver->fec_decoder->burst_erased_message_vector[j]->buffer !=
// NULL) {
// printMatrix(application_layer_relay_receiver->fec_decoder->burst_erased_message_vector[j]->buffer,1,300);
// cout<<application_layer_relay_receiver->fec_decoder->burst_erased_message_vector[j]->seq_number<<endl;
// application_layer_relay_sender.message_wise_encode_at_relay(
// application_layer_relay_receiver->fec_decoder->burst_erased_message_vector[j]->buffer,
// application_layer_relay_receiver->fec_decoder->burst_erased_message_vector[j]->seq_number,
// udp_parameters2, buffer2,
// &buffer_size2, response_from_dest_buffer);
// // after transmitting zero (in case next packet is lost...)
// application_layer_relay_receiver->fec_decoder->burst_erased_message_vector[j]->buffer=NULL;
// application_layer_destination_receiver->receive_message_and_decode(
// udp_parameters2, buffer2,
// &buffer_size2,
// &erasure_simulator2);
// } else {
// break;
// }
// }
// }
// if (seq_number > -1) {
// if (application_layer_relay_receiver->fec_message->buffer != NULL) {
// printMatrix(application_layer_relay_receiver->fec_message->buffer,1,300);
// cout<<seq_number - T<<endl;
// application_layer_relay_sender.message_wise_encode_at_relay(
// application_layer_relay_receiver->fec_message->buffer, seq_number - T, udp_parameters2,
// buffer2,
// &buffer_size2, response_from_dest_buffer);
//// cout<<seq_number - T<<endl;
//// printMatrix(application_layer_relay_receiver->fec_message->buffer,1,300);
//// cout<<application_layer_relay_receiver->fec_decoder->message_vector_to_transmit_stored_seq[0]<<endl;
//// printMatrix(application_layer_relay_receiver->fec_decoder->message_vector_to_transmit_stored[0],1,300);
// application_layer_destination_receiver->receive_message_and_decode(
// udp_parameters2, buffer2,
// &buffer_size2,
// &erasure_simulator2);
// } else if (application_layer_relay_receiver->fec_decoder->message_old_encoder->buffer != NULL) {// if double coding extract from old encoder
// printMatrix(application_layer_relay_receiver->fec_decoder->message_old_encoder->buffer,1,300);
// cout<<seq_number - T<<endl;
// application_layer_relay_sender.message_wise_encode_at_relay(
// application_layer_relay_receiver->fec_decoder->message_old_encoder->buffer,
// seq_number - T, udp_parameters2, buffer2,
// &buffer_size2, response_from_dest_buffer);
// application_layer_destination_receiver->receive_message_and_decode(
// udp_parameters2, buffer2,
// &buffer_size2,
// &erasure_simulator2);
// }
// }
// }
min_rate_debug_packet_count += 1;
min_rate_debug_debug += std::min(
application_layer_sender.variable_rate_FEC_encoder->debug_rate_first_hop_curr,
application_layer_relay_sender.debug_rate_second_hop_curr);
if (application_layer_sender.variable_rate_FEC_encoder->debug_rate_first_hop_curr < 1 ||
application_layer_relay_sender.debug_rate_second_hop_curr < 1) {
min_rate_affected_debug_packet_count += 1;
min_rate_affected_debug += std::min(
application_layer_sender.variable_rate_FEC_encoder->debug_rate_first_hop_curr,
application_layer_relay_sender.debug_rate_second_hop_curr);
if (DEBUG_SAVE_SEQ_OF_AFFECTED_TOFILE == 1) {
ofstream myfile;
myfile.open("affected MWDF.txt", std::ios_base::app);
myfile << i << ","
<< application_layer_sender.variable_rate_FEC_encoder->debug_rate_first_hop_curr
<< "," << application_layer_relay_sender.debug_rate_second_hop_curr << " \n";
myfile.close();
}
}
} else if (relaying_type == 2 || relaying_type == 3) { // Symbol-wise decode and forward
application_layer_sender.generate_message_and_encode(udp_parameters, buffer,
&buffer_size); //udp_codeword is
float R1 = (float) ((int) buffer[4] - (int) buffer[6] + 1) / ((int) buffer[4] + 1);
float R2 = (float) ((int) buffer[8] - (int) buffer[10] + 1) / ((int) buffer[8] + 1);
if (R1 < 1 || R2 < 1) {
min_rate_affected_debug_packet_count += 1;
min_rate_affected_debug += std::min(R1, R2);
if (DEBUG_SAVE_SEQ_OF_AFFECTED_TOFILE == 1) {
ofstream myfile;
if (relaying_type == 3)
myfile.open("affected SD-SWDF.txt", std::ios_base::app);
else
myfile.open("affected SWDF.txt", std::ios_base::app);
myfile << i << "," << R1 << "," << R2 << " \n";
myfile.close();
}
}
// if (k2>n2)
// k2=n2;
int codeword_size_final = 0;
// for (int j = 0; j < 6; j++)
// application_layer_relay_receiver->response_from_dest_buffer[j] = udp_parameters2[j];
if (FLAG_FOR_CONSTANT_TRANS && (i < NUMBER_OF_ITERATIONS + T_INITIAL) &&
(erasure_simulator.is_erasure(i) == true)) {//artificial erasure
seq_number = application_layer_relay_receiver->receive_message_and_symbol_wise_encode(
udp_parameters,
udp_parameters2,
buffer,
&buffer_size,
&erasure_simulator,
k2_new,
n2_new,
&codeword_size_final,
&k2_new, &n2_new, true);
} else {
seq_number = application_layer_relay_receiver->receive_message_and_symbol_wise_encode(
udp_parameters,
udp_parameters2,
buffer,
&buffer_size,
&erasure_simulator,
k2_new,
n2_new,
&codeword_size_final,
&k2_new, &n2_new, false);
}
if (seq_number > -1) {
int numOfStoredCodeWords = application_layer_relay_receiver->fec_decoder->codeword_vector_to_transmit_stored_index;
int start_index;
if (FLAG_FOR_CONSTANT_TRANS)
if (numOfStoredCodeWords >= 0)
start_index = numOfStoredCodeWords;
else
start_index = numOfStoredCodeWords + 1;
else
start_index = 0;
for (int kk = start_index; kk <= numOfStoredCodeWords; kk++) {
int size_of_codeword = application_layer_relay_receiver->fec_decoder->codeword_vector_to_transmit_stored_word_size[kk];
int seq = application_layer_relay_receiver->fec_decoder->codeword_vector_to_transmit_stored_seq[kk];
int counter_for_start_and_end =
application_layer_relay_receiver->fec_decoder->codeword_vector_to_transmit_stored_counter_for_start_and_end[kk] -
numOfStoredCodeWords + kk;
if (counter_for_start_and_end < 0)
counter_for_start_and_end = 255 + counter_for_start_and_end;
// printMatrix(application_layer_relay_receiver->fec_decoder->codeword_vector_to_transmit_stored[kk],1,size_of_codeword);
// cout<<counter_for_start_and_end<<endl;
application_layer_relay_sender.send_sym_wise_message(
application_layer_relay_receiver->fec_decoder->codeword_vector_to_transmit_stored[kk],
size_of_codeword, udp_parameters2, buffer2, &buffer_size2, seq,
k2_new, n2_new,
counter_for_start_and_end);
application_layer_destination_receiver->receive_message_and_symbol_wise_decode(
udp_parameters2, buffer2,
&buffer_size2,
&erasure_simulator2, 0);
}
}
min_rate_debug_packet_count += 1;
min_rate_debug_debug += std::min(
application_layer_sender.variable_rate_FEC_encoder->debug_rate_first_hop_curr,
application_layer_destination_receiver->fec_decoder->debug_rate_second_hop_curr);
}
// } else if (relaying_type == 3) { // Symbol-wise decode and forward
// application_layer_sender.generate_message_and_encode(udp_parameters, buffer,
// &buffer_size); //udp_codeword is
//
//
//// if (k2>n2)
//// k2=n2;
// int codeword_size_final = 0;
//
//// for (int j = 0; j < 6; j++)
//// application_layer_relay_receiver->response_from_dest_buffer[j] = udp_parameters2[j];
//
// seq_number = application_layer_relay_receiver->receive_message_and_symbol_wise_encode(udp_parameters,udp_parameters2,
// buffer,
// &buffer_size,
// &erasure_simulator,
// k2_new,
// n2_new,
// &codeword_size_final,
// &k2_new, &n2_new);
// if (seq_number > -1) {
// int numOfStoredCodeWords = application_layer_relay_receiver->fec_decoder->codeword_vector_to_transmit_stored_index;
// for (int kk = 0; kk <= numOfStoredCodeWords; kk++) {
// int size_of_codeword = application_layer_relay_receiver->fec_decoder->codeword_vector_to_transmit_stored_word_size[kk];
// int seq = application_layer_relay_receiver->fec_decoder->codeword_vector_to_transmit_stored_seq[kk];
// int counter_for_start_and_end =
// application_layer_relay_receiver->fec_decoder->codeword_vector_to_transmit_stored_counter_for_start_and_end[kk] -
// numOfStoredCodeWords + kk;
// if (counter_for_start_and_end < 0)
// counter_for_start_and_end = 255 + counter_for_start_and_end;
//// printMatrix(application_layer_relay_receiver->fec_decoder->codeword_vector_to_transmit_stored[kk],1,size_of_codeword);
//// cout<<counter_for_start_and_end<<endl;
// application_layer_relay_sender.send_sym_wise_message(
// application_layer_relay_receiver->fec_decoder->codeword_vector_to_transmit_stored[kk],
// size_of_codeword, udp_parameters2, buffer2, &buffer_size2, seq, k2_new, n2_new,
// counter_for_start_and_end);
// application_layer_destination_receiver->receive_message_and_symbol_wise_decode(
// udp_parameters2,buffer2,
// &buffer_size2,
// &erasure_simulator2, 0);
// }
// }
// min_rate_debug_packet_count += 1;
// min_rate_debug_debug += std::min(
// application_layer_sender.variable_rate_FEC_encoder->debug_rate_first_hop_curr,
// application_layer_destination_receiver->fec_decoder->debug_rate_second_hop_curr);
// }
// bool flag_for_using_backup=false;
// int length_of_burst=0;
// if (seq_number>-1) {
//// if (seq_number-last_seq_received_from_srouce>n2_new) {
// length_of_burst=application_layer_relay_receiver->fec_decoder->flag_for_burst;
// if (length_of_burst>0){
// //Need to send all codeword_vector_store_in_burst
// int double_coding_sum=0;
// if (seq_number-last_seq_received_from_srouce>1){// packets erased in (s,r)
// // check if double-coding ended
// for (int kk=0;kk<seq_number-last_seq_received_from_srouce;kk++){
// if (application_layer_relay_receiver->fec_decoder->trans_vec[kk]==true)
// double_coding_sum++;
// }
// if (application_layer_relay_receiver->fec_decoder->trans_vec[0]==true && double_coding_sum>0 && double_coding_sum<seq_number-last_seq_received_from_srouce) {
// flag_for_using_backup = true;
// cout << "ELAD" << endl;
// }
// }
// int count=-1;
//
// for (int seq = 0; seq < length_of_burst; seq++) {
// count++;
// if (flag_for_using_backup==true && count<double_coding_sum) {
//// int burst_index_back;
//// burst_index_back=application_layer_relay_receiver->fec_decoder->decoder_Symbol_Backup->n-double_coding_sum_to_use+count;
// int n2_old_old=application_layer_relay_receiver->fec_decoder->decoder_Symbol_Backup->n;
// int double_coding_sum_to_use=std::min(double_coding_sum,n2_old_old);
// int burst_index=seq+n2_old_old-double_coding_sum_to_use;
//
// int size_of_codeword=application_layer_relay_receiver->fec_decoder->decoder_Symbol_Backup->burst_codeword_size_vector[burst_index];
// if (size_of_codeword>10000 || size_of_codeword<100) {
// cout << "Problem with codeword size line 368"<<endl;
// size_of_codeword=0;
// cin >> input;
// }
// printMatrix(application_layer_relay_receiver->fec_decoder->decoder_Symbol_Backup->codeword_vector_store_in_burst[burst_index],1,size_of_codeword);
// cout << application_layer_relay_receiver->fec_message->counter_for_start_and_end << endl;
// application_layer_relay_sender.send_sym_wise_message(
// application_layer_relay_receiver->fec_decoder->decoder_Symbol_Backup->codeword_vector_store_in_burst[burst_index],
// size_of_codeword, udp_parameters2, buffer2, &buffer_size2, 0,
// response_from_dest_buffer, k2_new, n2_new,
// application_layer_relay_receiver->fec_message->counter_for_start_and_end);
//// int size_of_codeword=application_layer_relay_receiver->fec_decoder->decoder_Symbol_Backup->codeword_size_vector[n2_old_old-double_coding_sum_to_use+count];
//// application_layer_relay_sender.send_sym_wise_message(
//// application_layer_relay_receiver->fec_decoder->decoder_Symbol_Backup->codeword_vector_store_in_burst[n2_old_old-double_coding_sum_to_use+count],
//// size_of_codeword, udp_parameters2, buffer2, &buffer_size2, 0,
//// response_from_dest_buffer, k2_new, n2_new,
//// application_layer_relay_receiver->fec_message->counter_for_start_and_end);
// }else {
// int burst_index;
// if (flag_for_using_backup==true)
//// burst_index=seq-double_coding_sum+application_layer_relay_receiver->fec_decoder->flag_for_burst_index-length_of_burst;
//// burst_index=seq-double_coding_sum+application_layer_relay_receiver->fec_decoder->flag_for_burst_index-1;
// burst_index=seq-length_of_burst+application_layer_relay_receiver->fec_decoder->flag_for_burst_index;
// else
// burst_index=seq+application_layer_relay_receiver->fec_decoder->flag_for_burst_index-length_of_burst;
//
// int size_of_codeword=application_layer_relay_receiver->fec_decoder->decoder_Symbol_Wise->burst_codeword_size_vector[burst_index];
// if (size_of_codeword>10000 || size_of_codeword<100) {
// cout << "Problem with codeword size line 393"<<endl;
// cin >> input;
// }
// int delta_for_counter_for_start_and_end=seq_number-last_seq_received_from_srouce-seq-1;
// int counter_for_start_and_end=application_layer_relay_receiver->fec_message->counter_for_start_and_end-delta_for_counter_for_start_and_end;
// if (counter_for_start_and_end<0)
// counter_for_start_and_end=255+counter_for_start_and_end;
// printMatrix(application_layer_relay_receiver->fec_decoder->decoder_Symbol_Wise->codeword_vector_store_in_burst[burst_index],1,size_of_codeword);
// cout << counter_for_start_and_end << endl;
// application_layer_relay_sender.send_sym_wise_message(
// application_layer_relay_receiver->fec_decoder->decoder_Symbol_Wise->codeword_vector_store_in_burst[burst_index],
// size_of_codeword, udp_parameters2, buffer2, &buffer_size2, 0,
// response_from_dest_buffer,
// k2_new, n2_new,
// counter_for_start_and_end);
// }
// application_layer_destination_receiver->receive_message_and_symbol_wise_decode(
// udp_parameters2, buffer2,
// &buffer_size2,
// &erasure_simulator2,0);
// }
// // send the message that was received after the burst
// int number_of_missing_packets_after_burst=seq_number-last_seq_received_from_srouce-length_of_burst-1; // correcting seq_number in the sent packet
// int index_to_use;
// if (application_layer_relay_receiver->fec_decoder->trans_vec[seq_number-last_seq_received_from_srouce-1]==true)
// index_to_use=application_layer_relay_receiver->fec_decoder->n2_old;
// else
// index_to_use=n2_new;
// printMatrix(application_layer_relay_receiver->fec_decoder->decoder_Symbol_Wise->codeword_vector_to_transmit[index_to_use-1],1,codeword_size_final);
// cout<<application_layer_relay_receiver->fec_message->counter_for_start_and_end<<endl;
// application_layer_relay_sender.send_sym_wise_message(
// application_layer_relay_receiver->fec_decoder->decoder_Symbol_Wise->codeword_vector_to_transmit[index_to_use-1],
// codeword_size_final, udp_parameters2, buffer2, &buffer_size2,
// number_of_missing_packets_after_burst,
// response_from_dest_buffer,k2_new,n2_new,application_layer_relay_receiver->fec_message->counter_for_start_and_end);
// application_layer_destination_receiver->receive_message_and_symbol_wise_decode(
// udp_parameters2, buffer2,
// &buffer_size2,
// &erasure_simulator2,seq_number-last_seq_received_from_srouce-length_of_burst-1);
// } // not in burst
// else {
// int double_coding_sum=0;
// if (seq_number-last_seq_received_from_srouce>1){// packets erased in (s,r)
// // check if double-coding ended
// for (int k=0;k<seq_number-last_seq_received_from_srouce;k++){
// if (application_layer_relay_receiver->fec_decoder->trans_vec[k]==true)
// double_coding_sum++;
// }
// if (application_layer_relay_receiver->fec_decoder->trans_vec[0]==true && double_coding_sum>0 && double_coding_sum<seq_number-last_seq_received_from_srouce) {
// flag_for_using_backup = true;
// cout << "ELAD" << endl;
// }
// }
// int count=-1;
//// int count=seq_number-last_seq_received_from_srouce-1;
// for (int seq = last_seq_received_from_srouce; seq < seq_number; seq++) {
// // int n=T_INITIAL+1;
//// count--;
// count++;
// int index = application_layer_relay_receiver->fec_decoder->n2_old - (seq_number - seq);
// if (flag_for_using_backup==true && count<double_coding_sum) {
// int n2_old_old=application_layer_relay_receiver->fec_decoder->decoder_Symbol_Backup->n2;
//// int index2=double_coding_sum-count;
// int size_of_codeword=application_layer_relay_receiver->fec_decoder->decoder_Symbol_Backup->codeword_size_vector[n2_old_old-double_coding_sum+count];
// if (size_of_codeword>10000 || size_of_codeword<100) {
// cout << "Problem with codeword size line 454"<<endl;
// cin >> input;
// }
// printMatrix(application_layer_relay_receiver->fec_decoder->decoder_Symbol_Backup->codeword_vector_to_transmit[n2_old_old-double_coding_sum+count],1,size_of_codeword);
// cout<<application_layer_relay_receiver->fec_message->counter_for_start_and_end<<endl;
// application_layer_relay_sender.send_sym_wise_message(
// application_layer_relay_receiver->fec_decoder->decoder_Symbol_Backup->codeword_vector_to_transmit[n2_old_old-double_coding_sum+count],
// size_of_codeword, udp_parameters2, buffer2, &buffer_size2, 0,
// response_from_dest_buffer, k2_new, n2_new,
// application_layer_relay_receiver->fec_message->counter_for_start_and_end);
// }else {
// int counter_for_start_and_end=application_layer_relay_receiver->fec_message->counter_for_start_and_end-(seq_number-seq-1);
// if (counter_for_start_and_end<0)
// counter_for_start_and_end=255+counter_for_start_and_end;
// int size_of_codeword=application_layer_relay_receiver->fec_decoder->decoder_Symbol_Wise->codeword_size_vector[index];
// if (size_of_codeword>10000 || size_of_codeword<100) {
// cout << "Problem with codeword size line 468"<<endl;
// cin >> input;
// }
// printMatrix(application_layer_relay_receiver->fec_decoder->decoder_Symbol_Wise->codeword_vector_to_transmit[index],1,size_of_codeword);
// cout<<counter_for_start_and_end<<endl;
// application_layer_relay_sender.send_sym_wise_message(
// application_layer_relay_receiver->fec_decoder->decoder_Symbol_Wise->codeword_vector_to_transmit[index],
// size_of_codeword, udp_parameters2, buffer2, &buffer_size2, 0,
// response_from_dest_buffer, k2_new, n2_new,
// counter_for_start_and_end);
// }
// application_layer_destination_receiver->receive_message_and_symbol_wise_decode(
// udp_parameters2, buffer2,
// &buffer_size2,
// &erasure_simulator2,0);
// }
// }
//
//
// last_seq_received_from_srouce=seq_number;
// }
// min_rate_debug_packet_count+=1;
// min_rate_debug_debug+=std::min(application_layer_sender.variable_rate_FEC_encoder->debug_rate_first_hop_curr,
// application_layer_destination_receiver->fec_decoder->debug_rate_second_hop_curr);
// }
if (i == 0)
start_time = high_resolution_clock::now();
if (seq_number >= stream_duration + T + T2 - 1) //Elad added T2
break;
}
auto stop = high_resolution_clock::now();
auto duration = duration_cast<minutes>(stop - start_time);
cout << "Time duration = " << duration.count() << " minutes" << endl;
cout << "Last sequence number received = " << seq_number << endl;
if (RELAYING_TYPE > 0) {
time_t now = time(0);
tm *ltm = localtime(&now);
std::string timeStamp =
std::to_string(1900 + ltm->tm_year) + "_" + std::to_string(1 + ltm->tm_mon) + "_" +
std::to_string(ltm->tm_mday) + "_" + std::to_string(ltm->tm_hour) + "_" +
std::to_string(1 + ltm->tm_min);
ofstream myfile;
myfile.open(output_file_name, std::ios_base::app);
myfile << timeStamp << ",";
// show type of run
if (RELAYING_TYPE == 3) {
if (N_INITIAL == -1 && N_INITIAL_2 == -1) {
DEBUG_MSG("\033[1;34m" << "adaptive SD-SWDF, T_TOT=" << T_TOT << " estimation window=" <<
ESTIMATION_WINDOW_SIZE / ESTIMATION_WINDOW_SIZE_REDUCTION_FACTOR <<
" multFactor=" << DOUBLE_ERAUSRE_NUM << " FLAG_FOR_CONSTANT_TRANS="
<< FLAG_FOR_CONSTANT_TRANS << "\033[0m");
myfile << "adaptive SD-SWDF, T_TOT=" << T_TOT << " estimation window=" <<
ESTIMATION_WINDOW_SIZE / ESTIMATION_WINDOW_SIZE_REDUCTION_FACTOR
<< " multFactor=" << DOUBLE_ERAUSRE_NUM << " FLAG_FOR_CONSTANT_TRANS="
<< FLAG_FOR_CONSTANT_TRANS << ",";
} else {
DEBUG_MSG(
"\033[1;34m" << "Fixed-rate SD-SWDF, hop1 (T1=" << T_TOT - N_INITIAL_2 << ", N1="
<< N_INITIAL
<< "), hop2 (T2=" << T_TOT - N_INITIAL << ", N2=" << N_INITIAL_2 << ")"
<< "\033[0m");
myfile << "Fixed-rate SD-SWDF, hop1 (T1=" << T_TOT - N_INITIAL_2 << "_N1=" << N_INITIAL
<< ") hop2 (T2=" << T_TOT - N_INITIAL << "_N2=" << N_INITIAL_2 << ")"
<< " FLAG_FOR_CONSTANT_TRANS=" << FLAG_FOR_CONSTANT_TRANS << ",";
}
} else if (RELAYING_TYPE == 2) {
if (N_INITIAL == -1 && N_INITIAL_2 == -1) {
DEBUG_MSG("\033[1;34m" << "adaptive SWDF, T_TOT=" << T_TOT << " estimation window=" <<
ESTIMATION_WINDOW_SIZE / ESTIMATION_WINDOW_SIZE_REDUCTION_FACTOR
<< "\033[0m");
myfile << "adaptive SWDF, T_TOT=" << T_TOT << " estimation window=" <<
ESTIMATION_WINDOW_SIZE / ESTIMATION_WINDOW_SIZE_REDUCTION_FACTOR
<< " multFactor=" << DOUBLE_ERAUSRE_NUM << " FLAG_FOR_CONSTANT_TRANS="
<< FLAG_FOR_CONSTANT_TRANS << ",";
} else {
DEBUG_MSG(
"\033[1;34m" << "Fixed-rate SWDF, hop1 (T1=" << T_TOT - N_INITIAL_2 << ", N1="
<< N_INITIAL
<< "), hop2 (T2=" << T_TOT - N_INITIAL << ", N2=" << N_INITIAL_2 << ")"
<< "\033[0m");
myfile << "Fixed-rate SWDF, hop1 (T1=" << T_TOT - N_INITIAL_2 << "_N1=" << N_INITIAL
<< ") hop2 (T2=" << T_TOT - N_INITIAL << "_N2=" << N_INITIAL_2 << ")"
<< " FLAG_FOR_CONSTANT_TRANS=" << FLAG_FOR_CONSTANT_TRANS << ",";
}
} else {
if (N_INITIAL == -1 && N_INITIAL_2 == -1) {
DEBUG_MSG("\033[1;34m" << "adaptive MWDF, T1=" << T_INITIAL << ", T2=" << T_INITIAL_2
<< "\033[0m");
myfile << "adaptive MWDF, T1=" << T_INITIAL << " T2=" << T_INITIAL_2
<< " FLAG_FOR_CONSTANT_TRANS=" << FLAG_FOR_CONSTANT_TRANS << ",";
} else {
DEBUG_MSG(
"\033[1;34m" << "Fixed-rate MWDF, hop1 (T1=" << T_INITIAL << ", N1=" << N_INITIAL
<< "), hop2 (T2=" << T_INITIAL_2 << ", N2=" << N_INITIAL_2 << ")"
<< " FLAG_FOR_CONSTANT_TRANS=" << FLAG_FOR_CONSTANT_TRANS
<< "\033[0m");
myfile << "Fixed-rate MWDF, hop1 (T1=" << T_INITIAL << "_N1=" << N_INITIAL
<< ") hop2 (T2=" << T_INITIAL_2 << "_N2=" << N_INITIAL_2 << ")"
<< " FLAG_FOR_CONSTANT_TRANS=" << FLAG_FOR_CONSTANT_TRANS
<< ",";
}
}
// show total char loss
int num_of_packets_lost =
application_layer_destination_receiver->fec_decoder->final_counter_loss_of_full_packet +
application_layer_destination_receiver->fec_decoder->final_counter_loss_of_packets_swdf;
if (DEBUG_CHAR == 1) {
float final_char_loss_in_per;
if (RELAYING_TYPE == 2 || RELAYING_TYPE == 3)
final_char_loss_in_per =
(float) (
application_layer_destination_receiver->fec_decoder->final_counter_loss_of_char +
application_layer_destination_receiver->fec_decoder->final_counter_loss_of_full_packet *
300) / (300 * (packet_counter - T_TOT)) * 100;
else
final_char_loss_in_per =
(float) (num_of_packets_lost *
300) / (300 * (packet_counter - T_INITIAL - T_INITIAL_2)) * 100;
// if (RELAYING_TYPE==2)
// num_of_packets_lost=application_layer_destination_receiver->fec_decoder->final_counter_loss_of_full_packet+
// application_layer_destination_receiver->fec_decoder->final_counter_loss_of_packets_swdf;
// else
// num_of_packets_lost=application_layer_destination_receiver->fec_decoder->final_counter_loss_of_full_packet;
DEBUG_MSG("\033[1;34m" << "Total Char loss " << final_char_loss_in_per << "% " << "\033[0m");
myfile << "Total Char loss, " << final_char_loss_in_per << "% " << ",";
}
// num_of_packets_lost=application_layer_destination_receiver->fec_decoder->final_counter_loss_of_full_packet+
// application_layer_destination_receiver->fec_decoder->final_counter_loss_of_packets_swdf;
DEBUG_MSG("\033[1;34m" << "Total number of erased packets " << num_of_packets_lost << "\033[0m");
myfile << "Total number of erased packets ," << num_of_packets_lost << ",";
DEBUG_MSG("\033[1;34m" << "Total occurrences of bug words "
<< application_layer_destination_receiver->fec_decoder->final_counter_loss_of_char_elad
<< "\033[0m");
if (RELAYING_TYPE > 0) {
float avg_rate_first_hop =
(float) (application_layer_sender.variable_rate_FEC_encoder->debug_rate_first_hop) /
(application_layer_sender.variable_rate_FEC_encoder->debug_rate_first_hop_num_packets);
float avg_rate_second_hop;
if (RELAYING_TYPE == 1)
avg_rate_second_hop = (float) (application_layer_relay_sender.debug_rate_second_hop) /
(application_layer_relay_sender.debug_rate_second_hop_num_packets);
else
avg_rate_second_hop =
(float) (application_layer_destination_receiver->fec_decoder->debug_rate_second_hop) /
(application_layer_destination_receiver->fec_decoder->debug_rate_second_hop_num_packets);
DEBUG_MSG("\033[1;34m" << "Average rate in first hop " << avg_rate_first_hop << "\033[0m");
myfile << "Average rate in first hop " << avg_rate_first_hop << ",";
DEBUG_MSG("\033[1;34m" << "Average rate in second hop " << avg_rate_second_hop << "\033[0m");
myfile << "Average rate in second hop " << avg_rate_second_hop << ",";
DEBUG_MSG("\033[1;34m" << "Average min rate " << min_rate_debug_debug / min_rate_debug_packet_count
<< "\033[0m");
myfile << "Average min rate, " << min_rate_debug_debug / min_rate_debug_packet_count << ",";
DEBUG_MSG("\033[1;34m" << "Average min affected rate "
<< min_rate_affected_debug / min_rate_affected_debug_packet_count
<< "\033[0m");
myfile << "Average min affected rate, "
<< min_rate_affected_debug / min_rate_affected_debug_packet_count << ",";
if (relaying_type==3)
myfile <<"fixed_header_size,"<<fixed_header_size<<",var_header_size,"<< var_header_size;
}
myfile << "\n";
myfile.close();
}
// cout << "Loss probability = " << calculateLossMessage(INPUTDATAFILE, OUTPUTDATAFILE);
free(udp_parameters);
delete application_layer_relay_receiver;
delete application_layer_destination_receiver;
}// for RELAYING_TYPE
// }//for EPSILON
// }//for start_index_B2
return 0;
}