-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulator.cpp
1645 lines (1463 loc) · 61.6 KB
/
simulator.cpp
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
#include "spectrum.hpp"
#include "light_path.hpp"
#include "graph.hpp"
#include "traffic.hpp"
#include "auxiliary.hpp"
#include <cfloat>
#include <ctime>
#include <queue>
#include <unordered_map>
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <list>
#include <climits>
using namespace std;
clock_t start_clk;
clock_t start_clk_finding;
double clk_finding = 0;
clock_t start_clk_construction;
double clk_construction = 0;
clock_t start_clk_parsing;
double clk_parsing = 0;
int num_batch = 10;
int hop_limit = 7;
float unicast_percentage = 1.0;
int num_requests = 1000;
int num_slots = 320;
int num_nodes;
int traffic_lambda = 1000;
int traffic_mu = 1;
int num_transceiver = 800;
int num_OTDM_transceiver = 400;
int num_OFDM_transceiver = 400;
int slot_capacity = 250;
int transceiver_slot_limit = 10;
int transceiver_connection_limit = 10;
int num_guardband_slot = 1;
int enable_OTDM = 1;
int OTDM_threshold = 18;
int transmission_distance_16QAM = 1800;
int transmission_distance_8QAM = 3600;
int transmission_distance_QPSK = 7200;
// request bandwidth share
int OC1_share = 0;
int OC3_share = 0;
int OC9_share = 0;
int OC12_share = 0;
int OC18_share = 2;
int OC24_share = 2;
int OC36_share = 2;
int OC48_share = 2;
int OC192_share = 1;
int OC768_share = 1;
int OC3072_share = 1;
//random_variables
long long aTime_seed = 1491701989;
long long hTime_seed = 82684867;
long long s_seed = 176028846;
long long d_seed = 1244571654;
long long numD_seed = 2029305454;
long long b_seed = 453424686;
//result variable
int accepted_requests = 0;
int blocked_requests = 0;
int blocked_bandwidth = 0;
int num_OEO = 0;
int num_OFDM_lightpath_use = 0;
int num_OTDM_lightpath_use = 0;
int total_bandwidth = 0;
int total_network_bandwidth=0;
vector<int> accepted_requests_BM;
vector<int> blocked_requests_BM;
vector<int> blocked_bandwidth_BM;
vector<int> num_OEO_BM;
vector<int> num_OFDM_lightpath_use_BM;
vector<int> num_OTDM_lightpath_use_BM;
double total_bandwidth_utilization;
double used_bandwidth_utilization;
double wasted_bandwidth_utilization;
double guardband_bandwidth_utilization;
double end_time;
// edge weight
double eps = 0.03;
double transceiver_weight = (1-eps) * 0.1;
double used_transceiver_weight = (1-eps) * 0.01;
double OFDM_transceiver_weight = (1-eps) * 0.1;
double used_OFDM_transceiver_weight = (1-eps) * 0.01;
double OEO_weight = (1-eps) * 0.1;
// police coeffcient
double reserved_coefficent = 1;
double cut_coeffcient = 1;
double align_coeffcient = 1;
list<LightPath*> candidate_light_path_list;
list<LightPath*> exist_OTDM_light_path_list;
list<LightPath*> exist_OFDM_light_path_list;
vector< vector<LightPath*> > request2lightpath;
char* graph_file = (char*) "NSFnet.txt";
char* source_file = (char*) "NSFnet_source.txt";
char* traffic_file = (char*) "NSFnet_traffic.txt";
typedef unordered_map<Aux_node*, double> Aux_node2Double;
typedef unordered_map<Aux_node*, Aux_link*> Aux_node2Aux_link;
typedef unordered_map<Aux_node*, bool> Aux_node2Bool;
void construct_exist_path(Event& event, Phy_graph& p_graph, Aux_graph& a_graph);
void construct_candidate_path(Event& event, Phy_graph& p_graph, Aux_graph& a_graph);
void reset_auxiliary_graph();
void build_candidate_link(Aux_graph& a_graph, LightPath* lpath);
void build_light_path(Phy_graph& p_graph, LightPath* candidate_path, Aux_node* aux_source, Aux_node* aux_destination, Event& event);
void path_parsing(Phy_graph& p_graph, Aux_node2Aux_link& result, Aux_node* aux_source, Aux_node* aux_destination, Event& event);
int num_spectrum_available(Phy_link& link, int slot_st, int slot_ed);
int spectrum_available(Phy_link& link, int slot_st, int slot_ed);
int path_spectrum_available(Path& path, int slot_st, int slot_ed, Phy_graph& p_graph);
int get_distance(Path& path, int slot_st, int slot_ed, Phy_graph& p_graph);
int get_cut_num(Path& path, int slot_st, int slot_ed, Phy_graph& p_graph);
int get_align_num(Path& path, int slot_st, int slot_ed, Phy_graph& p_graph);
double weigh_path_spectrum(Path& path, int slot_st, int slot_ed, Phy_graph& p_graph);
Spectrum find_best_spectrum(Path& path, int require_slots, Phy_graph& p_graph);
int get_available_OFDM_transceiver(vector<OFDMTransceiver>& transceivers);
LightPath* get_best_OTDM_light_path(int source, int destination, Event& event, Phy_graph& p_graph);
LightPath* get_best_OFDM_light_path(int source, int destination, Event& event, Phy_graph& p_graph);
LightPath* get_best_OFDM_WB_light_path(int source, int destination, Event& event, Phy_graph& p_graph);
LightPath* get_best_OFDM_WOB_light_path(int source, int destination, Event& event, Phy_graph& p_graph);
Aux_node2Aux_link BellmanFordSP(Aux_node* s);
double get_dist(Aux_node2Double& distTo, Aux_node* node);
void relax(Aux_node* v, Aux_node2Double& distTo, Aux_node2Aux_link& edgeTo, Aux_node2Bool& onQueue, queue<Aux_node*>& queue);
void print_result(Traffic traffic);
int main(int argc, char *argv[])
{
if( argc > 6 )
{
cout << "\nToo many arguments,EX: simulation labmda rquest_number" << "\n";
return 1;
}
if( argc > 1 )
{
if( atoi( argv[ 1 ] ) > 0 )
{
traffic_lambda = atoi( argv[ 1 ] );
}
else
{
cout << "\nError parameter: 1" << "\n";
return 1;
}
}
if( argc > 2 )
{
if( atoi( argv[ 2 ] ) > 0 )
{
num_requests = atoi( argv[ 2 ] );
}
else
{
cout << "\nError parameter: 2" << "\n";
return 1;
}
}
if( argc > 3 )
{
if( atoi( argv[ 3 ] ) == 0 )
{
enable_OTDM = 0;
}
}
if( argc > 4 )
{
if( atoi( argv[ 4 ] ) > 0 )
{
num_transceiver = atoi( argv[ 4 ] );
}
else
{
cout << "\nError parameter: 4" << "\n";
return 1;
}
}
if( argc > 5 )
{
switch( atoi( argv[5] ) )
{
case 1:
graph_file = (char*) "USnet.txt";
source_file = (char*) "USnet_source.txt";
traffic_file = (char*) "USnet_traffic.txt";
break;
default:
break;
}
}
if(num_transceiver < 800)
{
OEO_weight = hop_limit;
}
if(enable_OTDM)
{
num_OFDM_transceiver = num_transceiver / 2;
num_OTDM_transceiver = num_transceiver / 2;
}
else
{
num_OFDM_transceiver = num_transceiver;
num_OTDM_transceiver = 0;
}
start_clk = clock();
accepted_requests_BM.resize(num_batch, 0);
blocked_requests_BM.resize(num_batch, 0);
blocked_bandwidth_BM.resize(num_batch, 0);
num_OEO_BM.resize(num_batch, 0);
num_OFDM_lightpath_use_BM.resize(num_batch, 0);
num_OTDM_lightpath_use_BM.resize(num_batch, 0);
Graph_info g_info;
g_info.graph_file = graph_file;
g_info.num_slots = num_slots;
g_info.num_OTDM_transceiver = num_OTDM_transceiver;
g_info.num_OFDM_transceiver = num_OFDM_transceiver;
g_info.slot_capacity = slot_capacity;
g_info.transceiver_slot_limit = transceiver_slot_limit;
g_info.transceiver_connection_limit = transceiver_connection_limit;
g_info.transmission_distance_16QAM = transmission_distance_16QAM;
g_info.transmission_distance_8QAM = transmission_distance_8QAM;
g_info.transmission_distance_QPSK = transmission_distance_QPSK;
Phy_graph p_graph(g_info);
cout << "num_nodes : " << p_graph.node_list.size() << "\n";
num_nodes = p_graph.node_list.size();
Traffic_info t_info;
t_info.source_file = source_file;
t_info.traffic_file = traffic_file;
t_info.num_nodes = p_graph.node_list.size();
t_info.num_requests = num_requests;
t_info.OC1_share = OC1_share;
t_info.OC3_share = OC3_share;
t_info.OC9_share = OC9_share;
t_info.OC12_share = OC12_share;
t_info.OC18_share = OC18_share;
t_info.OC24_share = OC24_share;
t_info.OC36_share = OC36_share;
t_info.OC48_share = OC48_share;
t_info.OC192_share = OC192_share;
t_info.OC768_share = OC768_share;
t_info.OC3072_share = OC3072_share;
t_info.traffic_lambda = traffic_lambda;
t_info.traffic_mu = traffic_mu;
t_info.unicast_percentage = unicast_percentage;
t_info.aTime_seed = aTime_seed;
t_info.hTime_seed = hTime_seed;
t_info.s_seed = s_seed;
t_info.d_seed = d_seed;
t_info.numD_seed = numD_seed;
t_info.b_seed = b_seed;
Traffic traffic (t_info);
request2lightpath.resize(num_requests);
Auxiliary_info a_info;
a_info.num_nodes = num_nodes;
a_info.num_slots = num_slots;
a_info.transceiver_weight = transceiver_weight;
a_info.used_transceiver_weight = used_transceiver_weight;
a_info.OFDM_transceiver_weight = OFDM_transceiver_weight;
a_info.used_OFDM_transceiver_weight = used_OFDM_transceiver_weight;
a_info.OEO_weight = OEO_weight;
Aux_graph a_graph(a_info);
while( !traffic.empty() )
{
Event event = traffic.next_event();
if(event.type == Event::arrival)
{
cout << "arrival :\nid = " << event.request_id << "\nsource = " << event.source << "\ndest = " << *event.destination.begin() << "\nbandwidth = " << event.bandwidth << "\narrivaltime = " << event.arrival_time << "\n\n";
start_clk_construction = clock();
construct_candidate_path(event, p_graph, a_graph);
construct_exist_path(event, p_graph, a_graph);
clk_construction += (double) ( clock() - start_clk_construction ) / CLOCKS_PER_SEC;
start_clk_finding = clock();
Aux_node* aux_source = a_graph.get_adding_node(event.source);
Aux_node* aux_destination = a_graph.get_dropping_node(*(event.destination.begin()));
Aux_node2Aux_link result = BellmanFordSP(aux_source);
clk_finding += (double) ( clock() - start_clk_finding ) / CLOCKS_PER_SEC;
start_clk_parsing = clock();
if(result[aux_destination] != NULL) // Accepted
{
path_parsing(p_graph, result, aux_source, aux_destination, event);
accepted_requests++;
accepted_requests_BM[(int)event.request_id/(num_requests/num_batch)]++;
}
else
{
blocked_requests++;
blocked_requests_BM[(int)event.request_id/(num_requests/num_batch)]++;
blocked_bandwidth += event.bandwidth;
blocked_bandwidth_BM[(int)event.request_id/(num_requests/num_batch)] += event.bandwidth;
}
clk_parsing += (double) ( clock() - start_clk_parsing ) / CLOCKS_PER_SEC;
total_bandwidth += event.bandwidth;
start_clk_construction = clock();
reset_auxiliary_graph();
clk_construction += (double) ( clock() - start_clk_construction ) / CLOCKS_PER_SEC;
}
else // if(event.type == Event::departure)
{
cout << "departure :\nid = " << event.request_id << "\nsource = " << event.source << "\ndest = " << *event.destination.begin() << "\nbandwidth = " << event.bandwidth << "\narrivaltime = " << event.arrival_time << "\n\n";
for(auto &lp : request2lightpath[event.request_id])
{
lp->requests.erase(event.request_id);
if(lp->requests.empty())
{
int slot_st;
int slot_ed;
Path& path = lp->p_path;
switch(lp->type)
{
case LightPath::OTDM:
slot_st = lp->spectrum.slot_st;
slot_ed = lp->spectrum.slot_ed;
for(unsigned int node_i = 0; node_i < path.size() - 1; node_i++)
{
int from = path[node_i];
int to = path[node_i + 1];
Phy_link& link = p_graph.get_link(from, to);
for(int i = slot_st; i <= slot_ed; i++)
{
link.slot[i] = -1;
}
}
for(unsigned int i = 0; i < lp->transmitter_index.size(); i++)
{
if(lp->transmitter_index[i] != -1)
{
p_graph.get_node(path[i]).num_available_transmitter++;
}
}
for(unsigned int i = 0; i < lp->receiver_index.size(); i++)
{
if(lp->receiver_index[i] != -1)
{
p_graph.get_node(path[i]).num_available_receiver++;
}
}
delete lp;
exist_OTDM_light_path_list.remove(lp);
break;
case LightPath::OFDM_WOB:
case LightPath::OFDM_WB:
case LightPath::OFDM:
slot_st = lp->spectrum.slot_st;
slot_ed = lp->spectrum.slot_ed;
Phy_node& src_node = p_graph.get_node(path.front());
Phy_node& dst_node = p_graph.get_node(path.back());
src_node.OFDMtransmitter[lp->transmitter_index.front()].num_available_sub_transceiver++;
dst_node.OFDMreceiver[lp->receiver_index.back()].num_available_sub_transceiver++;
for(unsigned int node_i = 0; node_i < path.size() - 1; node_i++)
{
int from = path[node_i];
int to = path[node_i + 1];
Phy_link& link = p_graph.get_link(from, to);
for(int i = slot_st; i <= slot_ed; i++)
{
link.slot[i] = -1;
}
}
if(src_node.OFDMtransmitter[lp->transmitter_index.front()].num_available_sub_transceiver >= transceiver_connection_limit)
{
src_node.OFDMtransmitter[lp->transmitter_index.front()].spectrum.slot_st = -1;
src_node.OFDMtransmitter[lp->transmitter_index.front()].spectrum.slot_ed = -1;
src_node.OFDMtransmitter[lp->transmitter_index.front()].in_used = false;
src_node.OFDMtransmitter[lp->transmitter_index.front()].num_available_sub_transceiver = transceiver_connection_limit;
src_node.num_available_OFDM_transmitter++;
}
if(dst_node.OFDMreceiver[lp->receiver_index.back()].num_available_sub_transceiver >= transceiver_connection_limit)
{
dst_node.OFDMreceiver[lp->receiver_index.back()].spectrum.slot_st = -1;
dst_node.OFDMreceiver[lp->receiver_index.back()].spectrum.slot_ed = -1;
dst_node.OFDMreceiver[lp->receiver_index.back()].in_used = false;
dst_node.OFDMreceiver[lp->receiver_index.back()].num_available_sub_transceiver = transceiver_connection_limit;
dst_node.num_available_OFDM_receiver++;
}
delete lp;
exist_OFDM_light_path_list.remove(lp);
break;
}
}
else
{
lp->available_bitrate += event.bandwidth;
}
}
end_time = event.arrival_time;
}
}
total_network_bandwidth = slot_capacity * num_slots * p_graph.link_list.size();
print_result(traffic);
return 0;
}
void construct_exist_path(Event& event, Phy_graph& p_graph, Aux_graph& a_graph)
{
for(auto &lp : exist_OTDM_light_path_list)
{
if(lp->available_bitrate < event.bandwidth)
{
continue;
}
Aux_node* a_node;
Aux_node* d_node;
Aux_node* t_node;
Aux_node* r_node;
Aux_link* aux_link;
lp->transmitting_node_list.reserve(lp->p_path.size());
lp->receiving_node_list.reserve(lp->p_path.size());
int n = lp->p_path.size() - 1;
double weight = (double)n * (1 - eps) * lp->weight;
for(unsigned int i = 0; i < lp->p_path.size(); i++)
{
int phy_node_id = lp->p_path[i];
a_node = a_graph.get_adding_node(phy_node_id);
d_node = a_graph.get_dropping_node(phy_node_id);
t_node = a_graph.create_aux_node(phy_node_id, Aux_node::transmitting_node);
lp->transmitting_node_list.push_back(t_node);
r_node = a_graph.create_aux_node(phy_node_id, Aux_node::receiving_node);
lp->receiving_node_list.push_back(r_node);
aux_link = a_graph.create_aux_link(r_node, t_node, -weight, Aux_link::pass_through_link);
lp->aux_link_list.push_back(aux_link);
aux_link->light_path = lp; // make aux_link track light path
if(lp->transmitter_index[i] != -1)
{
aux_link = a_graph.create_aux_link(a_node, t_node, used_transceiver_weight, Aux_link::adding_link);
}
else if(p_graph.get_node(lp->p_path[i]).num_available_transmitter > 0)
{
aux_link = a_graph.create_aux_link(a_node, t_node, transceiver_weight, Aux_link::virtual_adding_link);
}
lp->aux_link_list.push_back(aux_link);
aux_link->light_path = lp; // make aux_link track light path
if(lp->receiver_index[i] != -1)
{
aux_link = a_graph.create_aux_link(r_node, d_node, used_transceiver_weight, Aux_link::dropping_link);
}
else if(p_graph.get_node(lp->p_path[i]).num_available_receiver > 0)
{
aux_link = a_graph.create_aux_link(r_node, d_node, transceiver_weight, Aux_link::virtual_dropping_link);
}
lp->aux_link_list.push_back(aux_link);
aux_link->light_path = lp; // make aux_link track light path
}
for(unsigned int i = 0; i < lp->p_path.size() - 1; i++)
{
t_node = lp->transmitting_node_list[i];
r_node = lp->receiving_node_list[i + 1];
aux_link = a_graph.create_aux_link(t_node, r_node, weight, Aux_link::spectrum_link);
// cout << "lp : " << lp << " link: " << aux_link << "\n";
lp->aux_link_list.push_back(aux_link);
aux_link->light_path = lp; // make aux_link track light path
}
}
}
void construct_candidate_path(Event& event, Phy_graph& p_graph, Aux_graph& a_graph)
{
for(int source = 0; source < num_nodes; source++)
{
for(int destination = 0; destination < num_nodes; destination++)
{
if(source == destination)
{
continue;
}
if(enable_OTDM)
{
LightPath* OTDM_lp = get_best_OTDM_light_path(source, destination, event, p_graph);
build_candidate_link(a_graph, OTDM_lp);
}
LightPath* OFDM_lp = get_best_OFDM_light_path(source, destination, event, p_graph);
build_candidate_link(a_graph, OFDM_lp);
LightPath* OFDM_WB_lp = get_best_OFDM_WB_light_path(source, destination, event, p_graph);
build_candidate_link(a_graph, OFDM_WB_lp);
LightPath* OFDM_WOB_lp = get_best_OFDM_WOB_light_path(source, destination, event, p_graph);
build_candidate_link(a_graph, OFDM_WOB_lp);
}
}
}
void reset_auxiliary_graph()
{
for(auto &lp : exist_OTDM_light_path_list)
{
for(auto &aux_node : lp->transmitting_node_list)
{
delete aux_node;
}
lp->transmitting_node_list.clear();
for(auto &aux_node : lp->receiving_node_list)
{
delete aux_node;
}
lp->receiving_node_list.clear();
lp->aux_link_list.clear();
}
for(auto &lp : candidate_light_path_list)
{
for(auto &aux_link : lp->aux_link_list)
{
delete aux_link;
}
delete lp;
}
candidate_light_path_list.clear();
}
void build_candidate_link(Aux_graph& a_graph, LightPath* lpath)
{
if(lpath == NULL)
{
return;
}
int source = lpath->p_path.front();
int destination = lpath->p_path.back();
Aux_node* v_t_node = NULL;
Aux_node* v_r_node = NULL;
switch (lpath->type)
{
case LightPath::OTDM:
v_t_node = a_graph.get_OTDM_virtual_transmitting_node(source);
v_r_node = a_graph.get_OTDM_virtual_receiving_node(destination);
if(lpath->available_bitrate >= OTDM_threshold)
{
lpath->weight = lpath->weight * 0.1;
}
break;
case LightPath::OFDM:
v_t_node = a_graph.get_OFDM_virtual_transmitting_node(source);
v_r_node = a_graph.get_OFDM_virtual_receiving_node(destination);
break;
case LightPath::OFDM_WB:
v_t_node = a_graph.get_OFDM_WB_virtual_transmitting_node(source);
v_r_node = a_graph.get_OFDM_WB_virtual_receiving_node(destination);
break;
case LightPath::OFDM_WOB:
v_t_node = a_graph.get_OFDM_WOB_virtual_transmitting_node(source);
v_r_node = a_graph.get_OFDM_WOB_virtual_receiving_node(destination);
break;
default:
cerr << "undefined LightPath type\n";
break;
}
Aux_link* c_link = a_graph.create_aux_link(v_t_node, v_r_node, lpath->weight, Aux_link::candidate_link);
c_link->light_path = lpath; // make aux_link track light path
lpath->aux_link_list.push_back(c_link); // make light path track aux_link
candidate_light_path_list.push_back(lpath);
}
void build_light_path(Phy_graph& p_graph, LightPath* candidate_path, Aux_node* aux_source, Aux_node* aux_destination, Event& event)
{
Phy_node& src_node = p_graph.get_node(aux_source->phy_id);
Phy_node& dst_node = p_graph.get_node(aux_destination->phy_id);
LightPath* new_path = new LightPath();
request2lightpath[event.request_id].push_back(new_path);
new_path->requests.insert(event.request_id);
new_path->modulation_level = candidate_path->modulation_level;
new_path->available_bitrate = candidate_path->available_bitrate;
new_path->weight = candidate_path->weight;
new_path->spectrum = candidate_path->spectrum;
new_path->p_path = candidate_path->p_path;
new_path->type = candidate_path->type;
int slot_st = new_path->spectrum.slot_st;
int slot_ed = new_path->spectrum.slot_ed;
Path& path = new_path->p_path;
double used_bandwidth;
double wasted_bandwidth;
double guardband_bandwidth;
double total_bandwidth;
double num_links;
switch(candidate_path->type)
{
case LightPath::OTDM:
new_path->transmitter_index.resize(path.size(), -1);
new_path->receiver_index.resize(path.size(), -1);
new_path->transmitter_index.front() = 1;
new_path->receiver_index.back() = 1;
src_node.num_available_transmitter--;
dst_node.num_available_receiver--;
for(unsigned int node_i = 0; node_i < path.size() - 1; node_i++)
{
int from = path[node_i];
int to = path[node_i + 1];
Phy_link& link = p_graph.get_link(from, to);
link.slot[slot_st] = 0;
link.slot[slot_ed] = 0;
for(int i = slot_st + 1; i <= slot_ed - 1; i++)
{
link.slot[i] = 1;
}
}
exist_OTDM_light_path_list.push_back(new_path);
num_OTDM_lightpath_use++;
num_OTDM_lightpath_use_BM[(int)event.request_id/(num_requests/num_batch)]++;
num_links = 1.0 * new_path->p_path.size() - 1;
used_bandwidth = num_links * event.bandwidth / new_path->modulation_level;
wasted_bandwidth = 0;
guardband_bandwidth = num_links * 2 * slot_capacity;
total_bandwidth = used_bandwidth + wasted_bandwidth + guardband_bandwidth;
total_bandwidth_utilization += total_bandwidth * event.holding_time;
used_bandwidth_utilization += used_bandwidth * event.holding_time;
wasted_bandwidth_utilization += wasted_bandwidth * event.holding_time;
guardband_bandwidth_utilization += guardband_bandwidth * event.holding_time;
break;
case LightPath:: OFDM:
new_path->transmitter_index.resize(path.size(), -1);
new_path->receiver_index.resize(path.size(), -1);
new_path->transmitter_index.front() = get_available_OFDM_transceiver(src_node.OFDMtransmitter);
src_node.num_available_OFDM_transmitter--;
new_path->receiver_index.back() = get_available_OFDM_transceiver(dst_node.OFDMreceiver);
dst_node.num_available_OFDM_receiver--;
src_node.OFDMtransmitter[new_path->transmitter_index.front()].spectrum = candidate_path->spectrum;
src_node.OFDMtransmitter[new_path->transmitter_index.front()].num_available_sub_transceiver--;
src_node.OFDMtransmitter[new_path->transmitter_index.front()].in_used = true;
dst_node.OFDMreceiver[new_path->receiver_index.back()].spectrum = candidate_path->spectrum;
dst_node.OFDMreceiver[new_path->receiver_index.back()].num_available_sub_transceiver--;
dst_node.OFDMreceiver[new_path->receiver_index.back()].in_used = true;
for(unsigned int node_i = 0; node_i < path.size() - 1; node_i++)
{
int from = path[node_i];
int to = path[node_i + 1];
Phy_link& link = p_graph.get_link(from, to);
link.slot[slot_st] = 0;
link.slot[slot_ed] = 0;
for(int i = slot_st + 1; i <= slot_ed - 1; i++)
{
link.slot[i] = 1;
}
}
exist_OFDM_light_path_list.push_back(new_path);
num_OFDM_lightpath_use++;
num_OFDM_lightpath_use_BM[(int)event.request_id/(num_requests/num_batch)]++;
num_links = 1.0 * new_path->p_path.size() - 1;
used_bandwidth = num_links * event.bandwidth / new_path->modulation_level;
wasted_bandwidth = num_links * (slot_capacity - (used_bandwidth - slot_capacity * ((int)used_bandwidth / slot_capacity)));
guardband_bandwidth = num_links * 2 * slot_capacity;
total_bandwidth = used_bandwidth + wasted_bandwidth + guardband_bandwidth;
total_bandwidth_utilization += total_bandwidth * event.holding_time;
used_bandwidth_utilization += used_bandwidth * event.holding_time;
wasted_bandwidth_utilization += wasted_bandwidth * event.holding_time;
guardband_bandwidth_utilization += guardband_bandwidth * event.holding_time;
break;
case LightPath:: OFDM_WB:
new_path->transmitter_index = candidate_path->transmitter_index;
new_path->receiver_index.resize(path.size(), -1);
new_path->receiver_index.back() = get_available_OFDM_transceiver(dst_node.OFDMreceiver);
dst_node.OFDMreceiver[new_path->receiver_index.back()].spectrum = candidate_path->spectrum;
dst_node.OFDMreceiver[new_path->receiver_index.back()].num_available_sub_transceiver--;
dst_node.OFDMreceiver[new_path->receiver_index.back()].in_used = true;
dst_node.num_available_OFDM_receiver--;
src_node.OFDMtransmitter[new_path->transmitter_index.front()].num_available_sub_transceiver--;
if(src_node.OFDMtransmitter[new_path->transmitter_index.front()].spectrum.slot_st > slot_st)
{
src_node.OFDMtransmitter[new_path->transmitter_index.front()].spectrum.slot_st = slot_st;
}
if(src_node.OFDMtransmitter[new_path->transmitter_index.front()].spectrum.slot_ed < slot_ed)
{
src_node.OFDMtransmitter[new_path->transmitter_index.front()].spectrum.slot_ed = slot_ed;
}
for(unsigned int node_i = 0; node_i < path.size() - 1; node_i++)
{
int from = path[node_i];
int to = path[node_i + 1];
Phy_link& link = p_graph.get_link(from, to);
link.slot[slot_st] = 0;
link.slot[slot_ed] = 0;
for(int i = slot_st + 1; i <= slot_ed - 1; i++)
{
link.slot[i] = 1;
}
}
exist_OFDM_light_path_list.push_back(new_path);
num_OFDM_lightpath_use++;
num_OFDM_lightpath_use_BM[(int)event.request_id/(num_requests/num_batch)]++;
num_links = 1.0 * new_path->p_path.size() - 1;
used_bandwidth = num_links * event.bandwidth / new_path->modulation_level;
wasted_bandwidth = num_links * (slot_capacity - (used_bandwidth - slot_capacity * ((int)used_bandwidth / slot_capacity)));
guardband_bandwidth = num_links * slot_capacity;
total_bandwidth = used_bandwidth + wasted_bandwidth + guardband_bandwidth;
total_bandwidth_utilization += total_bandwidth * event.holding_time;
used_bandwidth_utilization += used_bandwidth * event.holding_time;
wasted_bandwidth_utilization += wasted_bandwidth * event.holding_time;
guardband_bandwidth_utilization += guardband_bandwidth * event.holding_time;
break;
case LightPath:: OFDM_WOB:
new_path->transmitter_index = candidate_path->transmitter_index;
new_path->receiver_index = candidate_path->receiver_index;
src_node.OFDMtransmitter[new_path->transmitter_index.front()].num_available_sub_transceiver--;
dst_node.OFDMreceiver[new_path->receiver_index.back()].num_available_sub_transceiver--;
if(src_node.OFDMtransmitter[new_path->transmitter_index.front()].spectrum.slot_st > slot_st)
{
src_node.OFDMtransmitter[new_path->transmitter_index.front()].spectrum.slot_st = slot_st;
}
if(src_node.OFDMtransmitter[new_path->transmitter_index.front()].spectrum.slot_ed < slot_ed)
{
src_node.OFDMtransmitter[new_path->transmitter_index.front()].spectrum.slot_ed = slot_ed;
}
if(dst_node.OFDMreceiver[new_path->receiver_index.back()].spectrum.slot_st > slot_st)
{
dst_node.OFDMreceiver[new_path->receiver_index.back()].spectrum.slot_st = slot_st;
}
if(dst_node.OFDMreceiver[new_path->receiver_index.back()].spectrum.slot_ed < slot_ed)
{
dst_node.OFDMreceiver[new_path->receiver_index.back()].spectrum.slot_ed = slot_ed;
}
for(unsigned int node_i = 0; node_i < path.size() - 1; node_i++)
{
int from = path[node_i];
int to = path[node_i + 1];
Phy_link& link = p_graph.get_link(from, to);
link.slot[slot_st] = 0;
link.slot[slot_ed] = 0;
for(int i = slot_st + 1; i <= slot_ed - 1; i++)
{
link.slot[i] = 1;
}
}
exist_OFDM_light_path_list.push_back(new_path);
num_OFDM_lightpath_use++;
num_OFDM_lightpath_use_BM[(int)event.request_id/(num_requests/num_batch)]++;
num_links = 1.0 * new_path->p_path.size() - 1;
used_bandwidth = num_links * event.bandwidth / new_path->modulation_level;
wasted_bandwidth = num_links * (slot_capacity - (used_bandwidth - slot_capacity * ((int)used_bandwidth / slot_capacity)));
guardband_bandwidth = num_links * slot_capacity;
total_bandwidth = used_bandwidth + wasted_bandwidth + guardband_bandwidth;
total_bandwidth_utilization += total_bandwidth * event.holding_time;
used_bandwidth_utilization += used_bandwidth * event.holding_time;
wasted_bandwidth_utilization += wasted_bandwidth * event.holding_time;
guardband_bandwidth_utilization += guardband_bandwidth * event.holding_time;
break;
default:
cerr << "light path type error\n";
break;
}
}
void path_parsing(Phy_graph& p_graph, Aux_node2Aux_link& result, Aux_node* aux_source, Aux_node* aux_destination, Event& event)
{
Aux_link* aux_link = result[aux_destination];
Aux_node* aux_node = aux_link->from;
double used_bandwidth;
double wasted_bandwidth;
double guardband_bandwidth;
double total_bandwidth;
double num_links = 0;
double num_links_a_lp;
while(aux_node != aux_source)
{
switch(aux_link->type)
{
case Aux_link::candidate_link:
build_light_path(p_graph, aux_link->light_path, aux_link->from, aux_link->to, event);
break;
case Aux_link::spectrum_link:
if(aux_link->light_path->requests.find(event.request_id) == aux_link->light_path->requests.end())
{
request2lightpath[event.request_id].push_back(aux_link->light_path);
aux_link->light_path->requests.insert(event.request_id);
aux_link->light_path->available_bitrate -= event.bandwidth;
num_OTDM_lightpath_use++;
num_OTDM_lightpath_use_BM[(int)event.request_id/(num_requests/num_batch)]++;
}
num_links += 1;
break;
case Aux_link::grooming_link:
num_OEO++;
num_OEO_BM[(int)event.request_id/(num_requests/num_batch)]++;
break;
case Aux_link::adding_link:
if(aux_link->light_path == NULL) // not aux_link for candidate light path layer
{
break;
}
if(aux_link->light_path->type == LightPath::OTDM) // aux_link to OTDM grooming layer
{
num_links = 0;
}
break;
case Aux_link::dropping_link:
if(aux_link->light_path == NULL) // not aux_link for candidate light path layer
{
break;
}
if(aux_link->light_path->type == LightPath::OTDM) // aux_link to OTDM grooming layer
{
num_links_a_lp = 1.0 * (aux_link->light_path->p_path.size() - 1);
used_bandwidth = num_links * event.bandwidth / aux_link->light_path->modulation_level;
wasted_bandwidth = num_links_a_lp * (event.bandwidth / aux_link->light_path->modulation_level) - used_bandwidth;
guardband_bandwidth = 0;
total_bandwidth = used_bandwidth + wasted_bandwidth + guardband_bandwidth;
total_bandwidth_utilization += total_bandwidth * event.holding_time;
used_bandwidth_utilization += used_bandwidth * event.holding_time;
wasted_bandwidth_utilization += wasted_bandwidth * event.holding_time;
guardband_bandwidth_utilization += guardband_bandwidth * event.holding_time;
}
break;
case Aux_link::pass_through_link:
break;
case Aux_link::virtual_adding_link:
if(aux_link->light_path == NULL) // not aux_link for candidate light path layer
{
break;
}
if(aux_link->light_path->type == LightPath::OTDM) // aux_link to OTDM grooming layer
{
unsigned int i;
for(i = 0; i < aux_link->light_path->p_path.size(); i++)
{
if(aux_node->phy_id == aux_link->light_path->p_path[i])
{
break;
}
}
aux_link->light_path->transmitter_index[i] = 1;
p_graph.get_node(aux_node->phy_id).num_available_transmitter--;
num_links = 0;
}
break;
case Aux_link::virtual_dropping_link:
if(aux_link->light_path == NULL) // not aux_link for candidate light path layer
{
break;
}
if(aux_link->light_path->type == LightPath::OTDM) // aux_link to OTDM grooming layer
{
unsigned int i;
for(i = 0; i < aux_link->light_path->p_path.size(); i++)
{
if(aux_node->phy_id == aux_link->light_path->p_path[i])
{
break;
}
}
aux_link->light_path->receiver_index[i] = 1;
p_graph.get_node(aux_node->phy_id).num_available_receiver--;
num_links_a_lp = 1.0 * (aux_link->light_path->p_path.size() - 1);
used_bandwidth = num_links * event.bandwidth / aux_link->light_path->modulation_level;
wasted_bandwidth = num_links_a_lp * (event.bandwidth / aux_link->light_path->modulation_level) - used_bandwidth;
guardband_bandwidth = 0;
total_bandwidth = used_bandwidth + wasted_bandwidth + guardband_bandwidth;
total_bandwidth_utilization += total_bandwidth * event.holding_time;
used_bandwidth_utilization += used_bandwidth * event.holding_time;
wasted_bandwidth_utilization += wasted_bandwidth * event.holding_time;
guardband_bandwidth_utilization += guardband_bandwidth * event.holding_time;
}
break;
default:
cerr << "aux_link type error\n";
break;
}
aux_link = result[aux_node];
aux_node = aux_link->from;
}
}
int num_spectrum_available(Phy_link& link, int slot_st, int slot_ed)
{
int num_available = 0;
for(int i = slot_st; i <= slot_ed; i++)
{
if(link.slot[i] == -1)
{
num_available++;
}
}
return num_available;
}
int spectrum_available(Phy_link& link, int slot_st, int slot_ed)
{
int i = slot_ed;
if(link.slot[i] != -1)
{
while(i < num_slots)
{
i++;
if(link.slot[i] == -1)
{
return i; // index of first free slot
}
}
return num_slots + 1;
}
for(i = slot_ed - 1; i >= slot_st; i--)
{
if(link.slot[i] != -1)
{
return i + 1; // index of first free slot
}
}
return -1; // specturm available
}
int path_spectrum_available(Path& path, int slot_st, int slot_ed, Phy_graph& p_graph)
{
for(unsigned int node_i = 0; node_i < path.size() - 1; node_i++)
{
int from = path[node_i];
int to = path[node_i + 1];
Phy_link& link = p_graph.get_link(from, to);
int next_start = spectrum_available(link, slot_st, slot_ed);
if(next_start > 0)
{
return next_start;
}
}
return -1; // specturn available
}
int get_distance(Path& path, int slot_st, int slot_ed, Phy_graph& p_graph)
{
bool zone_clear = true;
int distance = 0;
int search_scope = transceiver_slot_limit - (slot_ed - slot_st + 1) + transceiver_slot_limit - 1;