Skip to content

Commit 83b4989

Browse files
ZoltanBojthelevy
authored andcommitted
Ethernet: Allow bitrate setting in NIC module 'bitrate' parameter instead of specify bitrate on channel (fixed #949)
1 parent c159e3e commit 83b4989

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/inet/linklayer/ethernet/base/EthernetMacBase.cc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,8 @@ void EthernetMacBase::readChannelParameters(bool errorWhenAsymmetric)
398398
if (connected && ((!outTrChannel) || (!inTrChannel)))
399399
throw cRuntimeError("Ethernet phys gate must be connected using a transmission channel");
400400

401-
double txRate = outTrChannel ? outTrChannel->getNominalDatarate() : 0.0;
402-
double rxRate = inTrChannel ? inTrChannel->getNominalDatarate() : 0.0;
401+
double txRate = 0.0;
402+
double rxRate = 0.0;
403403

404404
bool rxDisabled = !inTrChannel || inTrChannel->isDisabled();
405405
bool txDisabled = !outTrChannel || outTrChannel->isDisabled();
@@ -425,6 +425,18 @@ void EthernetMacBase::readChannelParameters(bool errorWhenAsymmetric)
425425
else {
426426
if (outTrChannel && !transmissionChannel)
427427
outTrChannel->subscribe(POST_MODEL_CHANGE, this);
428+
429+
// TODO The NetworkInterface::computeDatarate() function does something similar to the following code:
430+
if (networkInterface && networkInterface->hasPar("bitrate"))
431+
txRate = rxRate = networkInterface->par("bitrate");
432+
double channelTxRate = outTrChannel->getNominalDatarate();
433+
if (txRate == 0.0) {
434+
txRate = channelTxRate;
435+
rxRate = inTrChannel ? inTrChannel->getNominalDatarate() : 0.0;
436+
}
437+
else if (channelTxRate != 0 && txRate != channelTxRate)
438+
throw cRuntimeError("Wired network interface datarate is set on both the network interface module and on the corresponding transmission channel and the two values are different");
439+
428440
transmissionChannel = outTrChannel;
429441
dataratesDiffer = (txRate != rxRate);
430442
}

src/inet/linklayer/ethernet/basic/EthernetMacPhy.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,11 @@ void EthernetMacPhy::startFrameTransmission()
130130
}
131131
signal->encapsulate(frame);
132132
ASSERT(curTxSignal == nullptr);
133-
curTxSignal = signal->dup();
133+
simtime_t duration = signal->getBitLength() / curEtherDescr.bitrate;
134+
signal->setDuration(duration);
134135
emit(transmissionStartedSignal, signal);
135-
send(signal, SendOptions().transmissionId(curTxSignal->getId()), physOutGate);
136+
curTxSignal = signal->dup();
137+
send(signal, SendOptions().transmissionId(curTxSignal->getId()).duration(duration), physOutGate);
136138
scheduleAt(transmissionChannel->getTransmissionFinishTime(), endTxTimer);
137139
changeTransmissionState(TRANSMITTING_STATE);
138140
}

0 commit comments

Comments
 (0)