Skip to content

Commit

Permalink
Ethernet: Allow bitrate setting in NIC module 'bitrate' parameter ins…
Browse files Browse the repository at this point in the history
…tead of specify bitrate on channel (fixed #949)
  • Loading branch information
ZoltanBojthe authored and levy committed Jan 7, 2025
1 parent c159e3e commit 83b4989
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/inet/linklayer/ethernet/base/EthernetMacBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ void EthernetMacBase::readChannelParameters(bool errorWhenAsymmetric)
if (connected && ((!outTrChannel) || (!inTrChannel)))
throw cRuntimeError("Ethernet phys gate must be connected using a transmission channel");

double txRate = outTrChannel ? outTrChannel->getNominalDatarate() : 0.0;
double rxRate = inTrChannel ? inTrChannel->getNominalDatarate() : 0.0;
double txRate = 0.0;
double rxRate = 0.0;

bool rxDisabled = !inTrChannel || inTrChannel->isDisabled();
bool txDisabled = !outTrChannel || outTrChannel->isDisabled();
Expand All @@ -425,6 +425,18 @@ void EthernetMacBase::readChannelParameters(bool errorWhenAsymmetric)
else {
if (outTrChannel && !transmissionChannel)
outTrChannel->subscribe(POST_MODEL_CHANGE, this);

// TODO The NetworkInterface::computeDatarate() function does something similar to the following code:
if (networkInterface && networkInterface->hasPar("bitrate"))
txRate = rxRate = networkInterface->par("bitrate");
double channelTxRate = outTrChannel->getNominalDatarate();
if (txRate == 0.0) {
txRate = channelTxRate;
rxRate = inTrChannel ? inTrChannel->getNominalDatarate() : 0.0;
}
else if (channelTxRate != 0 && txRate != channelTxRate)
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");

transmissionChannel = outTrChannel;
dataratesDiffer = (txRate != rxRate);
}
Expand Down
6 changes: 4 additions & 2 deletions src/inet/linklayer/ethernet/basic/EthernetMacPhy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ void EthernetMacPhy::startFrameTransmission()
}
signal->encapsulate(frame);
ASSERT(curTxSignal == nullptr);
curTxSignal = signal->dup();
simtime_t duration = signal->getBitLength() / curEtherDescr.bitrate;
signal->setDuration(duration);
emit(transmissionStartedSignal, signal);
send(signal, SendOptions().transmissionId(curTxSignal->getId()), physOutGate);
curTxSignal = signal->dup();
send(signal, SendOptions().transmissionId(curTxSignal->getId()).duration(duration), physOutGate);
scheduleAt(transmissionChannel->getTransmissionFinishTime(), endTxTimer);
changeTransmissionState(TRANSMITTING_STATE);
}
Expand Down

0 comments on commit 83b4989

Please sign in to comment.