-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD2D10.cc
1506 lines (1237 loc) · 56.1 KB
/
D2D10.cc
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
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* NIST-developed software is provided by NIST as a public
* service. You may use, copy and distribute copies of the software in
* any medium, provided that you keep intact this entire notice. You
* may improve, modify and create derivative works of the software or
* any portion of the software, and you may copy and distribute such
* modifications or works. Modified works should carry a notice
* stating that you changed the software and should note the date and
* nature of any such change. Please explicitly acknowledge the
* National Institute of Standards and Technology as the source of the
* software.
*
* NIST-developed software is expressly provided "AS IS." NIST MAKES
* NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED, IN FACT OR ARISING BY
* OPERATION OF LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
* NON-INFRINGEMENT AND DATA ACCURACY. NIST NEITHER REPRESENTS NOR
* WARRANTS THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED
* OR ERROR-FREE, OR THAT ANY DEFECTS WILL BE CORRECTED. NIST DOES NOT
* WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF THE
* SOFTWARE OR THE RESULTS THEREOF, INCLUDING BUT NOT LIMITED TO THE
* CORRECTNESS, ACCURACY, RELIABILITY, OR USEFULNESS OF THE SOFTWARE.
*
* You are solely responsible for determining the appropriateness of
* using and distributing the software and you assume all risks
* associated with its use, including but not limited to the risks and
* costs of program errors, compliance with applicable laws, damage to
* or loss of data, programs or equipment, and the unavailability or
* interruption of operation. This software is not intended to be used
* in any situation where a failure could cause risk of injury or
* damage to property. The software developed by NIST employees is not
* subject to copyright protection within the United States.
*/
#include "ns3/lte-module.h"
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/mobility-module.h"
#include "ns3/applications-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/config-store.h"
#include <ns3/lte-ue-phy.h>
#include <cfloat>
#include <sstream>
#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace ns3;
// This trace will log packet transmissions and receptions from the application
// layer. The parameter 'localAddrs' is passed to this trace in case the
// address passed by the trace is not set (i.e., is '0.0.0.0' or '::'). The
// trace writes to a file stream provided by the first argument; by default,
// this trace file is 'UePacketTrace.tr'
void
UePacketTrace (Ptr<OutputStreamWrapper> stream, const Address &localAddrs, std::string context, Ptr<const Packet> p, const Address &srcAddrs, const Address &dstAddrs)
{
std::ostringstream oss;
*stream->GetStream () << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t" << context << "\t" << p->GetSize () << "\t";
if (InetSocketAddress::IsMatchingType (srcAddrs))
{
oss << InetSocketAddress::ConvertFrom (srcAddrs).GetIpv4 ();
if (!oss.str ().compare ("0.0.0.0")) //srcAddrs not set
{
*stream->GetStream () << Ipv4Address::ConvertFrom (localAddrs) << ":" << InetSocketAddress::ConvertFrom (srcAddrs).GetPort () << "\t" << InetSocketAddress::ConvertFrom (dstAddrs).GetIpv4 () << ":" << InetSocketAddress::ConvertFrom (dstAddrs).GetPort () << std::endl;
}
else
{
oss.str ("");
oss << InetSocketAddress::ConvertFrom (dstAddrs).GetIpv4 ();
if (!oss.str ().compare ("0.0.0.0")) //dstAddrs not set
{
*stream->GetStream () << InetSocketAddress::ConvertFrom (srcAddrs).GetIpv4 () << ":" << InetSocketAddress::ConvertFrom (srcAddrs).GetPort () << "\t" << Ipv4Address::ConvertFrom (localAddrs) << ":" << InetSocketAddress::ConvertFrom (dstAddrs).GetPort () << std::endl;
}
else
{
*stream->GetStream () << InetSocketAddress::ConvertFrom (srcAddrs).GetIpv4 () << ":" << InetSocketAddress::ConvertFrom (srcAddrs).GetPort () << "\t" << InetSocketAddress::ConvertFrom (dstAddrs).GetIpv4 () << ":" << InetSocketAddress::ConvertFrom (dstAddrs).GetPort () << std::endl;
}
}
}
else if (Inet6SocketAddress::IsMatchingType (srcAddrs))
{
oss << Inet6SocketAddress::ConvertFrom (srcAddrs).GetIpv6 ();
if (!oss.str ().compare ("::")) //srcAddrs not set
{
*stream->GetStream () << Ipv6Address::ConvertFrom (localAddrs) << ":" << Inet6SocketAddress::ConvertFrom (srcAddrs).GetPort () << "\t" << Inet6SocketAddress::ConvertFrom (dstAddrs).GetIpv6 () << ":" << Inet6SocketAddress::ConvertFrom (dstAddrs).GetPort () << std::endl;
}
else
{
oss.str ("");
oss << Inet6SocketAddress::ConvertFrom (dstAddrs).GetIpv6 ();
if (!oss.str ().compare ("::")) //dstAddrs not set
{
*stream->GetStream () << Inet6SocketAddress::ConvertFrom (srcAddrs).GetIpv6 () << ":" << Inet6SocketAddress::ConvertFrom (srcAddrs).GetPort () << "\t" << Ipv6Address::ConvertFrom (localAddrs) << ":" << Inet6SocketAddress::ConvertFrom (dstAddrs).GetPort () << std::endl;
}
else
{
*stream->GetStream () << Inet6SocketAddress::ConvertFrom (srcAddrs).GetIpv6 () << ":" << Inet6SocketAddress::ConvertFrom (srcAddrs).GetPort () << "\t" << Inet6SocketAddress::ConvertFrom (dstAddrs).GetIpv6 () << ":" << Inet6SocketAddress::ConvertFrom (dstAddrs).GetPort () << std::endl;
}
}
}
else
{
*stream->GetStream () << "Unknown address type!" << std::endl;
}
}
// class for d2d device
class d2d_user {
public :
NodeContainer d2dNodes;
int Node_id ;
int application_type;
int cluster_id;
Vector position;
int count = -1;
Ipv4Address address1, address2;
void store(Vector ue1, Vector ue2, int id) {
Node_id = id;
application_type = rand()%2+1;
position.x = (ue1.x + ue2.x)/2;
position.y = (ue1.y + ue2.y)/2;
position.z = (ue1.z + ue2.z)/2;
}
};
// class for cu device
class cu_users {
public :
NodeContainer Node;
int application_type;
int cluster_id;
Vector position;
Ipv4Address address;
int occupied = 0;
void store(Vector cu) {
position.x = cu.x;
position.y = cu.y;
position.z = cu.z;
}
};
// class for center
struct point {
double x, y;
int cluster = -1;
int application;
};
int shard1[10], shard2[10], shard3[10];
int size1=0, size2=0, size3=0;
// k means algorithm
std::vector<point> k_means(std::vector<d2d_user> init, int k, d2d_user* ptr)
{
auto tmp = std::max_element(init.begin(), init.end(), [](d2d_user a, d2d_user b) {return a.position.x < b.position.x; });
int max_x = tmp->position.x;
tmp = std::max_element(init.begin(), init.end(), [](d2d_user a, d2d_user b) {return a.position.y < b.position.y; });
int max_y = tmp->position.y;
tmp = std::min_element(init.begin(), init.end(), [](d2d_user a, d2d_user b) {return a.position.x < b.position.x; });
int min_x = tmp->position.x;
tmp = std::min_element(init.begin(), init.end(), [](d2d_user a, d2d_user b) {return a.position.y < b.position.y; });
int min_y = tmp->position.y;
std::vector<point> centers(k);
for (int i = 0; i < k; i++)
{
centers[i].x = (rand() + i*23) % (max_x - min_x + 1) + min_x;
centers[i].y = (rand() - i*17) % (max_y - min_y + 1) + min_y;
centers[i].cluster = i;
}
for (int i = 0; i < 1000; i++)
{
for (long unsigned int j = 0; j < init.size(); j++)
{
double* dists = new double[k];
for (int p = 0; p < k; p++)
{
double a = std::abs(init[j].position.y - centers[p].y);
double b = std::abs(init[j].position.x - centers[p].x);
dists[p] = std::sqrt(std::pow(a, 2) + std::pow(b, 2));
}
init[j].cluster_id = std::min_element(dists, dists + k) - dists;
ptr[init[j].Node_id].cluster_id = init[j].cluster_id;
delete[] dists;
}
std::unique_ptr<double[]> sum_x(new double[k], std::default_delete<double[]>());
std::unique_ptr<double[]> sum_y(new double[k], std::default_delete<double[]>());
int count[k];
for (int p = 0; p < k; p++)
{
sum_x[p] = 0;
sum_y[p] = 0;
count[p] = 0;
}
for (long unsigned int f = 0; f < init.size(); f++)
{
sum_x[init[f].cluster_id] += init[f].position.x;
sum_y[init[f].cluster_id] += init[f].position.y;
count[init[f].cluster_id]++;
ptr[init[f].Node_id].count = count[init[f].cluster_id];
}
for (int f = 0; f < k; f++)
{
centers[f].x = sum_x[f] / count[f];
centers[f].y = sum_y[f] / count[f];
}
}
return centers;
}
//print the shards
void print(d2d_user d2d[], cu_users cu[])
{
std::cout<<"\n";
for(int i=0; i<60 ; i++) std::cout<<"*";
std::cout<<"\n";
std::cout<< " SOCIAL_MEDIA"<<std::endl;
std::cout<<"\n";
std::cout<< " Shard 1 = { "<<std::endl;
for(int i=0;i<5;i++)
{
if(d2d[i].application_type == 1)
{
if(d2d[i].cluster_id == 0 )
{
std::cout<< " "<<"UE"<<2*i<<" "<<" , IP_Address : "<<d2d[i].address1<<std::endl;
std::cout<< " "<<"UE"<<2*i+1<<" "<<" , IP_Address : "<<d2d[i].address2<<std::endl;
}
}
}
for(int i=0;i<3;i++)
{
if(cu[i].application_type == 1)
{
if(cu[i].cluster_id == 0 )
{
std::cout<< " "<<"CU"<<i+1<<" , IP_Address : "<<cu[i].address<<std::endl;
}
}
}
std::cout<< " } "<<std::endl<<std::endl;
for(int i=0; i<60 ; i++) std::cout<<"*";
std::cout<<"\n";
std::cout<< " PUBLIC_SAFETY "<<std::endl;
std::cout<<"\n";
std::cout<<" Shard 1 = { " <<std::endl;
for(int i=0;i<5;i++)
{
if(d2d[i].application_type == 2)
{
if(d2d[i].cluster_id == 0 )
{
std::cout<< " "<<"UE"<<2*i<<" "<<" , IP_Address : "<<d2d[i].address1<<std::endl;
std::cout<< " "<<"UE"<<2*i+1<<" "<<" , IP_Address : "<<d2d[i].address2<<std::endl;
}
}
}
for(int i=0;i<3;i++)
{
if(cu[i].application_type == 2)
{
if(cu[i].cluster_id == 0)
{
std::cout<< " "<<"CU"<<i+1<<" , IP_Address : "<<cu[i].address<<std::endl;
}
}
}
std::cout<< " } "<<std::endl<<std::endl;
std::cout<<"\n";
std::cout<<" Shard 2 = { " <<std::endl;
for(int i=0;i<5;i++)
{
if(d2d[i].application_type == 2)
{
if(d2d[i].cluster_id == 1 )
{
std::cout<< " "<<"UE"<<2*i<<" "<<" , IP_Address : "<<d2d[i].address1<<std::endl;
std::cout<< " "<<"UE"<<2*i+1<<" "<<" , IP_Address : "<<d2d[i].address2<<std::endl;
}
}
}
for(int i=0;i<3;i++)
{
if(cu[i].application_type == 2)
{
if(cu[i].cluster_id == 1 )
{
std::cout<< " "<<"CU"<<i+1<<" , IP_Address : "<<cu[i].address<<std::endl;
}
}
}
std::cout<< " } "<<std::endl<<std::endl;
for(int i=0; i<60 ; i++) std::cout<<"*";
std::cout<<"\n";
}
NS_LOG_COMPONENT_DEFINE ("LteSlInCovrgCommMode1");
// function to print the SINR values
//print SINR value of first shard
void PhySnirTrace1 (std::string context ,uint16_t cellId, uint16_t rnti, double rsrp, double sinr, uint8_t componentCarrierId)
{
if(Simulator::Now().GetSeconds() >= 2.5 && Simulator::Now().GetSeconds() <= 2.50100 )
{
int nth=3; //looking for the second ocurrence of "/"
int cnt=0;
size_t pos=0;
while( cnt != nth )
{
pos = context.find("/", pos);
if ( pos == std::string::npos )
std::cout << nth << "th ocurrence not found!"<< std::endl;
pos+=1;
cnt++;
}
std::string str1;
str1 = context.substr(10,pos-11);
int ue= atoi(str1.c_str())-7;
for(int i=0; i< size1; i++)
{
if(2*shard1[i] == ue && i == 0)
{
std::cout<<" UE"<<ue<<" belonging to D2D"<<i+1<<"\n";
std::cout<<" Time : " <<Simulator::Now().GetSeconds()<<"\n";
std::cout<<" RNTI : "<<rnti<<" rsrp : "<<rsrp<<" SINR : "<<sinr<<std::endl;
std::cout<<"\n";
}
}
//std::cout<<" Time : " <<Simulator::Now().GetSeconds()<<"\n";
}
if(Simulator::Now().GetSeconds() >= 3.5 && Simulator::Now().GetSeconds() <= 3.50100 )
{
int nth=3; //looking for the second ocurrence of "/"
int cnt=0;
size_t pos=0;
while( cnt != nth )
{
pos = context.find("/", pos);
if ( pos == std::string::npos )
std::cout << nth << "th ocurrence not found!"<< std::endl;
pos+=1;
cnt++;
}
std::string str1;
str1 = context.substr(10,pos-11);
int ue= atoi(str1.c_str())-7;
for(int i=0; i< size1; i++)
{
if(2*shard1[i] == ue && (i == 0 || i == 1) )
{
//std::cout<<context<<std::endl;
std::cout<<" UE"<<ue<<" belonging to D2D"<<i+1<<"\n";
std::cout<<" Time : " <<Simulator::Now().GetSeconds()<<"\n";
std::cout<<" RNTI : "<<rnti<<" rsrp : "<<rsrp<<" SINR : "<<sinr<<std::endl;
std::cout<<"\n";
}
}
}
if(Simulator::Now().GetSeconds() >= 4.5 && Simulator::Now().GetSeconds() <= 4.50100)
{
int nth=3; //looking for the second ocurrence of "/"
int cnt=0;
size_t pos=0;
while( cnt != nth )
{
pos = context.find("/", pos);
if ( pos == std::string::npos )
std::cout << nth << "th ocurrence not found!"<< std::endl;
pos+=1;
cnt++;
}
std::string str1;
str1 = context.substr(10,pos-11);
int ue= atoi(str1.c_str())-7;
for(int i=0; i< size1; i++)
{
if(2*shard1[i] == ue && (i == 0 || i == 1 || i == 2))
{
//std::cout<<context<<std::endl;
std::cout<<" UE"<<ue<<" belonging to D2D"<<i+1<<"\n";
std::cout<<" Time : " <<Simulator::Now().GetSeconds()<<"\n";
std::cout<<" RNTI : "<<rnti<<" rsrp : "<<rsrp<<" SINR : "<<sinr<<std::endl;
std::cout<<"\n";
}
}
}
if(Simulator::Now().GetSeconds() >= 5.5 && Simulator::Now().GetSeconds() <= 5.50100)
{
int nth=3; //looking for the second ocurrence of "/"
int cnt=0;
size_t pos=0;
while( cnt != nth )
{
pos = context.find("/", pos);
if ( pos == std::string::npos )
std::cout << nth << "th ocurrence not found!"<< std::endl;
pos+=1;
cnt++;
}
std::string str1;
str1 = context.substr(10,pos-11);
int ue= atoi(str1.c_str())-7;
for(int i=0; i< size1; i++)
{
if(2*shard1[i] == ue && (i == 0 || i == 1 || i == 2))
{
//std::cout<<context<<std::endl;
std::cout<<" UE"<<ue<<" belonging to D2D"<<i+1<<"\n";
std::cout<<" Time : " <<Simulator::Now().GetSeconds()<<"\n";
std::cout<<" RNTI : "<<rnti<<" rsrp : "<<rsrp<<" SINR : "<<sinr<<std::endl;
std::cout<<"\n";
}
}
}
}
// printing the SINR value of second shard
void PhySnirTrace2 (std::string context ,uint16_t cellId, uint16_t rnti, double rsrp, double sinr, uint8_t componentCarrierId)
{
if(Simulator::Now().GetSeconds() >= 2.5 && Simulator::Now().GetSeconds() <= 2.50100 )
{
int nth=3; //looking for the second ocurrence of "/"
int cnt=0;
size_t pos=0;
while( cnt != nth )
{
pos = context.find("/", pos);
if ( pos == std::string::npos )
std::cout << nth << "th ocurrence not found!"<< std::endl;
pos+=1;
cnt++;
}
std::string str1;
str1 = context.substr(10,pos-11);
int ue= atoi(str1.c_str())-7;
for(int i=0; i< size2; i++)
{
if(2*shard2[i] == ue && i == 0)
{
std::cout<<" UE"<<ue<<" belonging to D2D"<<i+1<<"\n";
std::cout<<" Time : " <<Simulator::Now().GetSeconds()<<"\n";
std::cout<<" RNTI : "<<rnti<<" rsrp : "<<rsrp<<" SINR : "<<sinr<<std::endl;
std::cout<<"\n";
}
}
//std::cout<<" Time : " <<Simulator::Now().GetSeconds()<<"\n";
}
if(Simulator::Now().GetSeconds() >= 3.5 && Simulator::Now().GetSeconds() <= 3.50100 )
{
int nth=3; //looking for the second ocurrence of "/"
int cnt=0;
size_t pos=0;
while( cnt != nth )
{
pos = context.find("/", pos);
if ( pos == std::string::npos )
std::cout << nth << "th ocurrence not found!"<< std::endl;
pos+=1;
cnt++;
}
std::string str1;
str1 = context.substr(10,pos-11);
int ue= atoi(str1.c_str())-7;
for(int i=0; i< size2; i++)
{
if(2*shard2[i] == ue && (i == 0 || i == 1) )
{
//std::cout<<context<<std::endl;
std::cout<<" UE"<<ue<<" belonging to D2D"<<i+1<<"\n";
std::cout<<" Time : " <<Simulator::Now().GetSeconds()<<"\n";
std::cout<<" RNTI : "<<rnti<<" rsrp : "<<rsrp<<" SINR : "<<sinr<<std::endl;
std::cout<<"\n";
}
}
}
if(Simulator::Now().GetSeconds() >= 4.5 && Simulator::Now().GetSeconds() <= 4.50100)
{
int nth=3; //looking for the second ocurrence of "/"
int cnt=0;
size_t pos=0;
while( cnt != nth )
{
pos = context.find("/", pos);
if ( pos == std::string::npos )
std::cout << nth << "th ocurrence not found!"<< std::endl;
pos+=1;
cnt++;
}
std::string str1;
str1 = context.substr(10,pos-11);
int ue= atoi(str1.c_str())-7;
for(int i=0; i< size2; i++)
{
if(2*shard2[i] == ue && (i == 0 || i == 1 || i == 2))
{
//std::cout<<context<<std::endl;
std::cout<<" UE"<<ue<<" belonging to D2D"<<i+1<<"\n";
std::cout<<" Time : " <<Simulator::Now().GetSeconds()<<"\n";
std::cout<<" RNTI : "<<rnti<<" rsrp : "<<rsrp<<" SINR : "<<sinr<<std::endl;
std::cout<<"\n";
}
}
}
if(Simulator::Now().GetSeconds() >= 5.5 && Simulator::Now().GetSeconds() <= 5.50100)
{
int nth=3; //looking for the second ocurrence of "/"
int cnt=0;
size_t pos=0;
while( cnt != nth )
{
pos = context.find("/", pos);
if ( pos == std::string::npos )
std::cout << nth << "th ocurrence not found!"<< std::endl;
pos+=1;
cnt++;
}
std::string str1;
str1 = context.substr(10,pos-11);
int ue= atoi(str1.c_str())-7;
for(int i=0; i< size2; i++)
{
if(2*shard2[i] == ue && (i == 0 || i == 1 || i == 2))
{
//std::cout<<context<<std::endl;
std::cout<<" UE"<<ue<<" belonging to D2D"<<i+1<<"\n";
std::cout<<" Time : " <<Simulator::Now().GetSeconds()<<"\n";
std::cout<<" RNTI : "<<rnti<<" rsrp : "<<rsrp<<" SINR : "<<sinr<<std::endl;
std::cout<<"\n";
}
}
}
}
// print SINR value of third shard
void PhySnirTrace3 (std::string context ,uint16_t cellId, uint16_t rnti, double rsrp, double sinr, uint8_t componentCarrierId)
{
if(Simulator::Now().GetSeconds() >= 2.5 && Simulator::Now().GetSeconds() <= 2.50100 )
{
int nth=3; //looking for the second ocurrence of "/"
int cnt=0;
size_t pos=0;
while( cnt != nth )
{
pos = context.find("/", pos);
if ( pos == std::string::npos )
std::cout << nth << "th ocurrence not found!"<< std::endl;
pos+=1;
cnt++;
}
std::string str1;
str1 = context.substr(10,pos-11);
int ue= atoi(str1.c_str())-7;
for(int i=0; i< size3; i++)
{
if(2*shard3[i] == ue && i == 0)
{
std::cout<<" UE"<<ue<<" belonging to D2D"<<i+1<<"\n";
std::cout<<" Time : " <<Simulator::Now().GetSeconds()<<"\n";
std::cout<<" RNTI : "<<rnti<<" rsrp : "<<rsrp<<" SINR : "<<sinr<<std::endl;
std::cout<<"\n";
}
}
//std::cout<<" Time : " <<Simulator::Now().GetSeconds()<<"\n";
}
if(Simulator::Now().GetSeconds() >= 3.5 && Simulator::Now().GetSeconds() <= 3.50100 )
{
int nth=3; //looking for the second ocurrence of "/"
int cnt=0;
size_t pos=0;
while( cnt != nth )
{
pos = context.find("/", pos);
if ( pos == std::string::npos )
std::cout << nth << "th ocurrence not found!"<< std::endl;
pos+=1;
cnt++;
}
std::string str1;
str1 = context.substr(10,pos-11);
int ue= atoi(str1.c_str())-7;
for(int i=0; i< size3; i++)
{
if(2*shard3[i] == ue && (i == 0 || i == 1) )
{
//std::cout<<context<<std::endl;
std::cout<<" UE"<<ue<<" belonging to D2D"<<i+1<<"\n";
std::cout<<" Time : " <<Simulator::Now().GetSeconds()<<"\n";
std::cout<<" RNTI : "<<rnti<<" rsrp : "<<rsrp<<" SINR : "<<sinr<<std::endl;
std::cout<<"\n";
}
}
}
if(Simulator::Now().GetSeconds() >= 4.5 && Simulator::Now().GetSeconds() <= 4.50100)
{
int nth=3; //looking for the second ocurrence of "/"
int cnt=0;
size_t pos=0;
while( cnt != nth )
{
pos = context.find("/", pos);
if ( pos == std::string::npos )
std::cout << nth << "th ocurrence not found!"<< std::endl;
pos+=1;
cnt++;
}
std::string str1;
str1 = context.substr(10,pos-11);
int ue= atoi(str1.c_str())-7;
for(int i=0; i< size3; i++)
{
if(2*shard3[i] == ue && (i == 0 || i == 1 || i == 2))
{
//std::cout<<context<<std::endl;
std::cout<<" UE"<<ue<<" belonging to D2D"<<i+1<<"\n";
std::cout<<" Time : " <<Simulator::Now().GetSeconds()<<"\n";
std::cout<<" RNTI : "<<rnti<<" rsrp : "<<rsrp<<" SINR : "<<sinr<<std::endl;
std::cout<<"\n";
}
}
}
if(Simulator::Now().GetSeconds() >= 5.5 && Simulator::Now().GetSeconds() <= 5.50100)
{
int nth=3; //looking for the second ocurrence of "/"
int cnt=0;
size_t pos=0;
while( cnt != nth )
{
pos = context.find("/", pos);
if ( pos == std::string::npos )
std::cout << nth << "th ocurrence not found!"<< std::endl;
pos+=1;
cnt++;
}
std::string str1;
str1 = context.substr(10,pos-11);
int ue= atoi(str1.c_str())-7;
for(int i=0; i< size3; i++)
{
if(2*shard3[i] == ue && (i == 0 || i == 1 || i == 2))
{
//std::cout<<context<<std::endl;
std::cout<<" UE"<<ue<<" belonging to D2D"<<i+1<<"\n";
std::cout<<" Time : " <<Simulator::Now().GetSeconds()<<"\n";
std::cout<<" RNTI : "<<rnti<<" rsrp : "<<rsrp<<" SINR : "<<sinr<<std::endl;
std::cout<<"\n";
}
}
}
}
int main (int argc, char *argv[])
{
Time simTime = Seconds (6);
bool enableNsLogs = false;
bool useIPv6 = false;
CommandLine cmd;
cmd.AddValue ("simTime", "Total duration of the simulation", simTime);
cmd.AddValue ("enableNsLogs", "Enable ns-3 logging (debug builds)", enableNsLogs);
cmd.AddValue ("useIPv6", "Use IPv6 instead of IPv4", useIPv6);
cmd.Parse (argc, argv);
// Configure the scheduler
Config::SetDefault ("ns3::RrSlFfMacScheduler::Itrp", UintegerValue (0));
//The number of RBs allocated per UE for Sidelink
Config::SetDefault ("ns3::RrSlFfMacScheduler::SlGrantSize", UintegerValue (5));
//Set the frequency
Config::SetDefault ("ns3::LteEnbNetDevice::DlEarfcn", UintegerValue (100));
Config::SetDefault ("ns3::LteUeNetDevice::DlEarfcn", UintegerValue (100));
Config::SetDefault ("ns3::LteEnbNetDevice::UlEarfcn", UintegerValue (18100));
Config::SetDefault ("ns3::LteEnbNetDevice::DlBandwidth", UintegerValue (50));
Config::SetDefault ("ns3::LteEnbNetDevice::UlBandwidth", UintegerValue (50));
// Set error models
Config::SetDefault ("ns3::LteSpectrumPhy::SlCtrlErrorModelEnabled", BooleanValue (true));
Config::SetDefault ("ns3::LteSpectrumPhy::SlDataErrorModelEnabled", BooleanValue (true));
Config::SetDefault ("ns3::LteSpectrumPhy::DropRbOnCollisionEnabled", BooleanValue (false));
ConfigStore inputConfig;
inputConfig.ConfigureDefaults ();
// parse again so we can override input file default values via command line
cmd.Parse (argc, argv);
if (enableNsLogs)
{
LogLevel logLevel = (LogLevel)(LOG_PREFIX_FUNC | LOG_PREFIX_TIME | LOG_PREFIX_NODE | LOG_LEVEL_ALL);
LogComponentEnable ("LteUeRrc", logLevel);
LogComponentEnable ("LteUeMac", logLevel);
LogComponentEnable ("LteSpectrumPhy", logLevel);
LogComponentEnable ("LteUePhy", logLevel);
LogComponentEnable ("LteEnbPhy", logLevel);
}
//Set the UEs power in dBm
Config::SetDefault ("ns3::LteUePhy::TxPower", DoubleValue (10.0));
//Set the eNBs power in dBm
Config::SetDefault ("ns3::LteEnbPhy::TxPower", DoubleValue (30.0));
//Sidelink bearers activation time
Time slBearersActivationTime = Seconds (2.0);
//Create the helpers
Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
//Create and set the EPC helper
Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper> ();
lteHelper->SetEpcHelper (epcHelper);
////Create Sidelink helper and set lteHelper
Ptr<LteSidelinkHelper> proseHelper = CreateObject<LteSidelinkHelper> ();
proseHelper->SetLteHelper (lteHelper);
//Set pathloss model
lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::Cost231PropagationLossModel"));
//Enable Sidelink
lteHelper->SetAttribute ("UseSidelink", BooleanValue (true));
//Sidelink Round Robin scheduler
lteHelper->SetSchedulerType ("ns3::RrSlFfMacScheduler");
//Create nodes (eNb + UEs)
NodeContainer enbNode;
enbNode.Create (1);
NS_LOG_INFO ("eNb node id = [" << enbNode.Get (0)->GetId () << "]");
//d2d devices
d2d_user d2d[10];
for(int i=0 ; i<5; i++) d2d[i].d2dNodes.Create (2);
//CU devices
cu_users cu[10];
for(int i=0; i<3; i++) cu[i].Node.Create(1);
NS_LOG_INFO ("UE 1 node id = [" << d2d[1].d2dNodes.Get (0)->GetId () << "]");
NS_LOG_INFO ("UE 2 node id = [" << d2d[1].d2dNodes.Get (1)->GetId () << "]");
//Position of the nodes
Ptr<ListPositionAllocator> positionAllocEnb = CreateObject<ListPositionAllocator> ();
positionAllocEnb->Add (Vector (10.0, 0.0, 0.0));
//FOR CU
Ptr<ListPositionAllocator> positionAllocCu1 = CreateObject<ListPositionAllocator> ();
positionAllocCu1->Add (Vector (5.0, 5.0, 0.0));
Ptr<ListPositionAllocator> positionAllocCu2 = CreateObject<ListPositionAllocator> ();
positionAllocCu2->Add (Vector (15.0, 5.0, 0.0));
Ptr<ListPositionAllocator> positionAllocCu3 = CreateObject<ListPositionAllocator> ();
positionAllocCu3->Add (Vector (10.0, 2.0, 0.0));
//FOR UE
Ptr<ListPositionAllocator> positionAllocd2d1 = CreateObject<ListPositionAllocator> ();
positionAllocd2d1->Add (Vector (5.0, 6.0, 0.0));
Ptr<ListPositionAllocator> positionAllocd2d2 = CreateObject<ListPositionAllocator> ();
positionAllocd2d2->Add (Vector (6.0, 6.0, 0.0));
Ptr<ListPositionAllocator> positionAllocd2d3 = CreateObject<ListPositionAllocator> ();
positionAllocd2d3->Add (Vector (3.0, 3.0, 0.0));
Ptr<ListPositionAllocator> positionAllocd2d4 = CreateObject<ListPositionAllocator> ();
positionAllocd2d4->Add (Vector (4.0, 3.0, 0.0));
Ptr<ListPositionAllocator> positionAllocd2d5 = CreateObject<ListPositionAllocator> ();
positionAllocd2d5->Add (Vector (16.0, 5.0, 0.0));
Ptr<ListPositionAllocator> positionAllocd2d6 = CreateObject<ListPositionAllocator> ();
positionAllocd2d6->Add (Vector (17.0, 5.0, 0.0));
Ptr<ListPositionAllocator> positionAllocd2d7 = CreateObject<ListPositionAllocator> ();
positionAllocd2d7->Add (Vector (22.0, -4.0, 0.0));
Ptr<ListPositionAllocator> positionAllocd2d8 = CreateObject<ListPositionAllocator> ();
positionAllocd2d8->Add (Vector (24.0, -4.0, 0.0));
Ptr<ListPositionAllocator> positionAllocd2d9 = CreateObject<ListPositionAllocator> ();
positionAllocd2d9->Add (Vector (-23.0, 7.0, 0.0));
Ptr<ListPositionAllocator> positionAllocd2d10 = CreateObject<ListPositionAllocator> ();
positionAllocd2d10->Add (Vector (-19.0, 7.0, 0.0));
//Install mobility
MobilityHelper mobilityeNodeB;
mobilityeNodeB.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobilityeNodeB.SetPositionAllocator (positionAllocEnb);
mobilityeNodeB.Install (enbNode);
MobilityHelper mobilityCu1;
mobilityCu1.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobilityCu1.SetPositionAllocator (positionAllocCu1);
mobilityCu1.Install (cu[0].Node.Get (0));
MobilityHelper mobilityCu2;
mobilityCu2.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobilityCu2.SetPositionAllocator (positionAllocCu2);
mobilityCu2.Install (cu[1].Node.Get (0));
MobilityHelper mobilityCu3;
mobilityCu3.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobilityCu3.SetPositionAllocator (positionAllocCu3);
mobilityCu3.Install (cu[2].Node.Get (0));
MobilityHelper mobilityd2d1;
mobilityd2d1.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobilityd2d1.SetPositionAllocator (positionAllocd2d1);
mobilityd2d1.Install (d2d[0].d2dNodes.Get (0));
MobilityHelper mobilityd2d2;
mobilityd2d2.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobilityd2d2.SetPositionAllocator (positionAllocd2d2);
mobilityd2d2.Install (d2d[0].d2dNodes.Get (1));
MobilityHelper mobilityd2d3;
mobilityd2d3.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobilityd2d3.SetPositionAllocator (positionAllocd2d3);
mobilityd2d3.Install (d2d[1].d2dNodes.Get (0));
MobilityHelper mobilityd2d4;
mobilityd2d4.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobilityd2d4.SetPositionAllocator (positionAllocd2d4);
mobilityd2d4.Install (d2d[1].d2dNodes.Get (1));
MobilityHelper mobilityd2d5;
mobilityd2d5.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobilityd2d5.SetPositionAllocator (positionAllocd2d5);
mobilityd2d5.Install (d2d[2].d2dNodes.Get (0));
MobilityHelper mobilityd2d6;
mobilityd2d6.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobilityd2d6.SetPositionAllocator (positionAllocd2d6);
mobilityd2d6.Install (d2d[2].d2dNodes.Get (1));
MobilityHelper mobilityd2d7;
mobilityd2d7.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobilityd2d7.SetPositionAllocator (positionAllocd2d7);
mobilityd2d7.Install (d2d[3].d2dNodes.Get (0));
MobilityHelper mobilityd2d8;
mobilityd2d8.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobilityd2d8.SetPositionAllocator (positionAllocd2d8);
mobilityd2d8.Install (d2d[3].d2dNodes.Get (1));
MobilityHelper mobilityd2d9;
mobilityd2d9.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobilityd2d9.SetPositionAllocator (positionAllocd2d9);
mobilityd2d9.Install (d2d[4].d2dNodes.Get (0));
MobilityHelper mobilityd2d10;
mobilityd2d10.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobilityd2d10.SetPositionAllocator (positionAllocd2d10);
mobilityd2d10.Install (d2d[4].d2dNodes.Get (1));
Vector enb;
enb = positionAllocEnb->GetNext();
Vector cu_positions[10];
cu_positions[0] = positionAllocCu1->GetNext();
cu_positions[1] = positionAllocCu2->GetNext();
cu_positions[2] = positionAllocCu3->GetNext();
Vector d2d_positions[10];
d2d_positions[0] = positionAllocd2d1->GetNext();
d2d_positions[1] = positionAllocd2d2->GetNext();
d2d_positions[2] = positionAllocd2d3->GetNext();
d2d_positions[3] = positionAllocd2d4->GetNext();
d2d_positions[4] = positionAllocd2d5->GetNext();
d2d_positions[5] = positionAllocd2d6->GetNext();
d2d_positions[6] = positionAllocd2d7->GetNext();
d2d_positions[7] = positionAllocd2d8->GetNext();
d2d_positions[8] = positionAllocd2d9->GetNext();
d2d_positions[9] = positionAllocd2d10->GetNext();
for(int i=0 ; i<5 ; i++) d2d[i].store(d2d_positions[2*i], d2d_positions[2*i+1], i);
for(int i=0 ; i<3 ; i++) cu[i].store(cu_positions[i]);
//Install LTE devices to the nodes and fix the random number stream
int64_t randomStream = 1;
NetDeviceContainer enbDevs = lteHelper->InstallEnbDevice (enbNode);
randomStream += lteHelper->AssignStreams (enbDevs, randomStream);
NetDeviceContainer cuDevs1 = lteHelper->InstallUeDevice (cu[0].Node);
randomStream += lteHelper->AssignStreams (cuDevs1, randomStream);
NetDeviceContainer cuDevs2 = lteHelper->InstallUeDevice (cu[1].Node);
randomStream += lteHelper->AssignStreams (cuDevs2, randomStream);
NetDeviceContainer cuDevs3 = lteHelper->InstallUeDevice (cu[2].Node);
randomStream += lteHelper->AssignStreams (cuDevs3, randomStream);