Skip to content

Commit 7e64a10

Browse files
committed
MCB-0001: [Susana] Fixed random SCH per SCH interval
1 parent 50c5577 commit 7e64a10

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

vanets/src/Mac16094Metrics.cc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <../../veins/src/veins/modules/phy/DeciderResult80211.h>
1818
#include <../../veins/src/veins/base/phyLayer/PhyToMacControlInfo.h>
19+
#include <../../veins/src/veins/modules/utility/Consts80211p.h>
1920
#include "veins/modules/messages/PhyControlMessage_m.h"
2021
using namespace std;
2122
#define DBG_MAC EV
@@ -220,7 +221,19 @@ void Mac16094Metrics::handleUpperMsg(cMessage* message) {
220221
}
221222

222223
int Mac16094Metrics::randomizeSCH( int min, int max) {
223-
return rand()%( max - min + 1) + min;
224+
225+
srand((unsigned)time(NULL));
226+
int randomSCHNumber= rand()%( max - min) + min;
227+
int randomSCHEnum = 0;
228+
switch (randomSCHNumber) {
229+
case 1: randomSCHEnum = Channels::SCH1; break;
230+
case 2: randomSCHEnum = Channels::SCH2; break;
231+
case 3: randomSCHEnum = Channels::SCH3; break;
232+
case 4: randomSCHEnum = Channels::SCH4; break;
233+
default: throw cRuntimeError("Random Service Channel must be between 1 and 4"); break;
234+
}
235+
236+
return randomSCHEnum;
224237
}
225238

226239
void Mac16094Metrics::handleSelfMsg(cMessage* message) {
@@ -231,13 +244,15 @@ void Mac16094Metrics::handleSelfMsg(cMessage* message) {
231244
scheduleAt(simTime() + SWITCHING_INTERVAL_11P, nextChannelSwitch);
232245

233246
mySCH = randomizeSCH(1, 4);
247+
std::cout<<"Mac16094Metrics:: mySCH "<< mySCH << std::endl;
234248

235249
switch (activeChannel) {
236250
case type_CCH:
237251
DBG_MAC << "CCH --> SCH" << std::endl;
238252
channelBusySelf(false);
239253
setActiveChannel(type_SCH);
240254
channelIdle(true);
255+
std::cout<<"Mac16094Metrics:: frequency[mySCH] " << frequency[mySCH]<<std::endl;
241256
phy11p->changeListeningFrequency(frequency[mySCH]);
242257
break;
243258
case type_SCH:

vanets/src/omnetpp.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,4 +583,5 @@ description = "CCH & SCH BeaconLength 100Bytes, ServicePacketLength Safety, Queu
583583

584584
*.**.nic.mac1609_4.queueSize = 5
585585
*.**.nic.mac1609_4.useServiceChannel = true
586+
*.**.nic.mac1609_4.serviceChannel = 2
586587
*.manager.launchConfig = xmldoc("northampton/LowDenScenNorthampton.launchd.xml")

veins/src/veins/modules/phy/Decider80211p.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ enum Decider80211p::PACKET_OK_RESULT Decider80211p::packetOk(double snirMin, dou
297297

298298
double rand = RNGCONTEXT dblrand();
299299

300+
std::cout<<"Decider80211::collectCollisionStats - "<< collectCollisionStats << std::endl;
301+
std::cout<<"Decider80211::rand header "<< rand << std::endl;
302+
std::cout<<"Decider80211::headerNoError "<< headerNoError << std::endl;
303+
std::cout<<"Decider80211::headerNoErrorSnr "<< headerNoErrorSnr << std::endl;
304+
300305
if (!collectCollisionStats) {
301306
if (rand > headerNoError)
302307
notDecoded++;
@@ -305,11 +310,6 @@ enum Decider80211p::PACKET_OK_RESULT Decider80211p::packetOk(double snirMin, dou
305310
}
306311
else {
307312

308-
std::cout<<"headerNoErrorSnrOriginalValue: "<< headerNoErrorSnr<< std::endl;
309-
headerNoErrorSnr = 0 ;
310-
311-
std::cout<<"headerNoErrorSnrTestValue: "<< headerNoErrorSnr<< std::endl;
312-
std::cout<<"rand between [0,1]: "<< rand<< std::endl;
313313

314314
if (rand > headerNoError) {
315315
//ups, we have a header error. is that due to interference?
@@ -333,6 +333,10 @@ enum Decider80211p::PACKET_OK_RESULT Decider80211p::packetOk(double snirMin, dou
333333

334334
rand = RNGCONTEXT dblrand();
335335

336+
std::cout<<"Decider80211p::rand packet " << rand << std::endl;
337+
std::cout<<"Decider80211p::packetOkSinr " << packetOkSinr << std::endl;
338+
std::cout<<"Decider80211p::packetOkSnr " << packetOkSnr << std::endl;
339+
336340
if (!collectCollisionStats) {
337341
if (rand > packetOkSinr) {
338342
std::cout<<"packetOk !collectedCollisionsStats notDecoded Packet generated: "<< notDecoded<< std::endl;

0 commit comments

Comments
 (0)