Commit bedf2482 authored by shengjh's avatar shengjh 🇨🇳
Browse files

correct getHeaderSize function.

parent 8712a4e6
......@@ -44,7 +44,9 @@ WorkloadSynthesizer::WorkloadSynthesizer()
//
//
maxDataBytesPerEthFrame = MAX_ETHERNET_PAYLOAD_BYTES - IP_HEADER_SIZE - UDP_HEADER_SIZE;
maxDataBytesPerPkt = maxDataBytesPerEthFrame - HomaPktHelper::getHomaPktHeaderSize(PktType::UNSCHED_DATA);
const auto& payload = makeShared<HomaPkt>();
payload->setPktType(PktType::UNSCHED_DATA);
maxDataBytesPerPkt = maxDataBytesPerEthFrame - HomaPktHelper::getHeaderSize(payload);
}
......
......@@ -16,14 +16,14 @@ HomaPktHelper::HomaPktHelper() {
HomaPktHelper::~HomaPktHelper() {
// TODO Auto-generated destructor stub
}
uint32_t HomaPktHelper::getHomaPktHeaderSize(PktType pktType) {
HomaPkt homaPkt = HomaPkt();
homaPkt.setPktType(pktType);
uint32_t size = sizeof(homaPkt.getMsgId());
auto& unschedFields = homaPkt.getUnschedFields();
auto& grantFields = homaPkt.getGrantFields();
auto& schedDataFields = homaPkt.getSchedDataFields();
switch(pktType) {
uint32_t HomaPktHelper::getHeaderSize(Ptr<const HomaPkt> homaChunk) {
// HomaPkt homaPkt = HomaPkt();
// homaPkt.setPktType(pktType);
uint32_t size = sizeof(homaChunk->getMsgId());
auto& unschedFields = homaChunk->getUnschedFields();
auto& grantFields = homaChunk->getGrantFields();
auto& schedDataFields = homaChunk->getSchedDataFields();
switch(homaChunk->getPktType()) {
case PktType::REQUEST:
case PktType::UNSCHED_DATA:
size += (sizeof(unschedFields.msgByteLen) +
......@@ -95,7 +95,11 @@ uint32_t HomaPktHelper::getBytesOnWire(uint32_t numDataBytes, PktType homaPktTyp
// pkt and uses the real header size of the packet to do calcualtion when
// possible. This requires to find all invokations of this function and
// replace them with the new function when possible.
uint32_t homaPktHdrSize = getHomaPktHeaderSize(PktType::UNSCHED_DATA);
// HomaPkt homaPkt = HomaPkt();
// homaPkt.setPktType(homaPktType);
const auto& payload = makeShared<HomaPkt>();
payload->setPktType(homaPktType);
uint32_t homaPktHdrSize = getHeaderSize(payload);
uint32_t bytesOnWire = 0;
......
......@@ -14,7 +14,7 @@ using namespace inet;
class HomaPktHelper {
public:
HomaPktHelper();
static uint32_t getHomaPktHeaderSize(PktType pktType);
static uint32_t getHeaderSize(Ptr<const HomaPkt> homaChunk);
static uint32_t getBytesOnWire(uint32_t numDataBytes, PktType homaPktType);
static uint32_t getDataBytes(Ptr<const HomaPkt> homaChunk);
static uint32_t getFirstByte(Ptr<const HomaPkt> homaChunk);
......
......@@ -144,8 +144,10 @@ void HomaTransport::initialize()
// dataPkt.setPktType(PktType::SCHED_DATA);
// uint32_t maxDataBytes = MAX_ETHERNET_PAYLOAD_BYTES -
// IP_HEADER_SIZE - UDP_HEADER_SIZE - dataPkt.headerSize();
const auto& payload = makeShared<HomaPkt>();
payload->setPktType(PktType::UNSCHED_DATA);
uint32_t maxDataBytes = MAX_ETHERNET_PAYLOAD_BYTES - IP_HEADER_SIZE - UDP_HEADER_SIZE
- HomaPktHelper::getHomaPktHeaderSize(PktType::SCHED_DATA);
- HomaPktHelper::getHeaderSize(payload);
if (homaConfig->grantMaxBytes > maxDataBytes) {
homaConfig->grantMaxBytes = maxDataBytes;
}
......@@ -733,7 +735,7 @@ HomaTransport::SendController::sendPktAndScheduleNext(Packet* sxPkt)
void
HomaTransport::SendController::msgTransmitComplete(OutboundMessage* msg)
{
uint32_t destIp = msg->destAddr.toIPv4().getInt();
uint32_t destIp = msg->destAddr.toIpv4().getInt();
rxAddrMsgMap.at(destIp).erase(msg);
if (rxAddrMsgMap.at(destIp).empty()) {
rxAddrMsgMap.erase(destIp);
......@@ -778,19 +780,20 @@ HomaTransport::SendController::OutbndMsgSorter::operator()(
} else if (q1.empty()) {
return false;
} else {
HomaPkt* pkt1 = q1.top();
HomaPkt* pkt2 = q2.top();
return (pkt1->getPriority() < pkt2->getPriority()) ||
(pkt1->getPriority() == pkt2->getPriority() &&
auto pkt1 = q1.top();
auto pkt2 = q2.top();
auto pkt1Chunk = pkt1->peekAtFront<HomaPkt>();
auto pkt2Chunk = pkt2->peekAtFront<HomaPkt>();
//SJH: Why pkt is same with msg here?
return (pkt1Chunk->getPriority() < pkt2Chunk->getPriority()) ||
(pkt1Chunk->getPriority() == pkt2Chunk->getPriority() &&
pkt1->getCreationTime() < pkt2->getCreationTime()) ||
(pkt1->getPriority() == pkt2->getPriority() &&
(pkt1Chunk->getPriority() == pkt2Chunk->getPriority() &&
pkt1->getCreationTime() == pkt2->getCreationTime() &&
msg1->getMsgCreationTime() <
msg2->getMsgCreationTime()) ||
(pkt1->getPriority() == pkt2->getPriority() &&
msg1->getMsgCreationTime() < msg2->getMsgCreationTime()) ||
(pkt1Chunk->getPriority() == pkt2Chunk->getPriority() &&
pkt1->getCreationTime() == pkt2->getCreationTime() &&
msg1->getMsgCreationTime() ==
msg2->getMsgCreationTime() &&
msg1->getMsgCreationTime() == msg2->getMsgCreationTime() &&
msg1->getMsgId() < msg2->getMsgId());
}
}
......@@ -824,9 +827,9 @@ HomaTransport::OutboundMessage::OutboundMessage(Ptr<const AppMessage> outMsg,
SendController* sxController, uint64_t msgId,
std::vector<uint16_t> reqUnschedDataVec)
: msgId(msgId)
, msgSize(outMsg->getByteLength())
, bytesToSched(outMsg->getByteLength())
, bytesLeft(outMsg->getByteLength())
, msgSize(B(outMsg->getChunkLength()).get())
, bytesToSched(B(outMsg->getChunkLength()).get())
, bytesLeft(B(outMsg->getChunkLength()).get())
, unschedBytesLeft(0)
, nextExpectedUnschedTxTime(SIMTIME_ZERO)
, reqUnschedDataVec(reqUnschedDataVec)
......@@ -877,7 +880,7 @@ HomaTransport::OutboundMessage::OutboundMessage(const OutboundMessage& other)
HomaTransport::OutboundMessage::~OutboundMessage()
{
while (!txPkts.empty()) {
HomaPkt* head = txPkts.top();
auto head = txPkts.top();
txPkts.pop();
delete head;
}
......@@ -975,7 +978,7 @@ HomaTransport::OutboundMessage::prepareRequestAndUnsched()
unschedDataPart->setSrcAddr(this->srcAddr);
unschedDataPart->setMsgId(this->msgId);
unschedDataPart->setPriority(unschedPrioVec[i]);
EV_DEBUG << "Attaching UserPriorityReq" << EV_FIELD(packet) << EV_ENDL;
// EV_DEBUG << "Attaching UserPriorityReq" << EV_FIELD(packet) << EV_ENDL;
packet->addTagIfAbsent<UserPriorityReq>()->setUserPriority(unschedPrioVec[i]);
// fill up unschedFields
......@@ -987,7 +990,7 @@ HomaTransport::OutboundMessage::prepareRequestAndUnsched()
unschedFields.lastByte = nextByteToSched + this->reqUnschedDataVec[i] - 1;
unschedFields.prioUnschedBytes = prioUnschedBytes;
for (size_t j = 0; j < unschedFields.prioUnschedBytes.size(); j += 2) {
if (unschedFields.prioUnschedBytes[j]==unschedPkt->getPriority()) {
if (unschedFields.prioUnschedBytes[j]==unschedDataPart->getPriority()) {
// find the two elements in this prioUnschedBytes vec that
// corresponds to the priority of this packet and subtract
// the bytes in this packet from prioUnschedBytes.
......@@ -1003,7 +1006,7 @@ HomaTransport::OutboundMessage::prepareRequestAndUnsched()
}
}
unschedDataPart->setUnschedFields(unschedFields);
unschedDataPart->setByteLength(HomaPktHelper::getHomaPktHeaderSize(pktType) + HomaPktHelper::getDataBytes(pktType));
unschedDataPart->setChunkLength(b(HomaPktHelper::getHeaderSize(unschedDataPart) + HomaPktHelper::getDataBytes(unschedDataPart)));
packet->insertAtBack(unschedDataPart);
txPkts.push(packet);
/**
......@@ -1013,8 +1016,8 @@ HomaTransport::OutboundMessage::prepareRequestAndUnsched()
**/
// update the OutboundMsg for the bytes sent in this iteration of loop
this->bytesToSched -= unschedDataPart->getDataBytes();
nextByteToSched += unschedDataPart->getDataBytes();
this->bytesToSched -= HomaPktHelper::getDataBytes(unschedDataPart);
nextByteToSched += this->bytesToSched;
// all packet except the first one are UNSCHED
pktType = PktType::UNSCHED_DATA;
......@@ -1042,7 +1045,7 @@ HomaTransport::OutboundMessage::prepareSchedPkt(uint32_t offset, uint16_t numByt
// create a data pkt and push it txPkts queue for
//HomaPkt* dataPkt = new HomaPkt(sxController->transport);
Packet *packet = new Packet();
auto &dataPkt = makeShared<HomaPkt>();
const auto &dataPkt = makeShared<HomaPkt>();
dataPkt->setPktType(PktType::SCHED_DATA);
dataPkt->setSrcAddr(this->srcAddr);
dataPkt->setDestAddr(this->destAddr);
......@@ -1052,17 +1055,17 @@ HomaTransport::OutboundMessage::prepareSchedPkt(uint32_t offset, uint16_t numByt
dataFields.firstByte = offset;
dataFields.lastByte = dataFields.firstByte + bytesToSend - 1;
dataPkt->setSchedDataFields(dataFields);
dataPkt->setByteLength(bytesToSend + dataPkt->headerSize());
dataPkt->setChunkLength(b(bytesToSend + HomaPktHelper::getHeaderSize(dataPkt)));
packet->insertAtBack(dataPkt);
txPkts.push(packet);
txSchedPkts.insert(packet);
// update outbound messgae
this->bytesToSched -= bytesToSend;
EV << "Prepared " << bytesToSend << " bytes for transmission from"
<< " msgId " << this->msgId << " to destination " <<
this->destAddr.str() << " (" << this->bytesToSched <<
" bytes left.)" << endl;
// EV << "Prepared " << bytesToSend << " bytes for transmission from"
// << " msgId " << this->msgId << " to destination " <<
// this->destAddr.str() << " (" << this->bytesToSched <<
// " bytes left.)" << endl;
return this->bytesToSched;
}
......@@ -1083,7 +1086,7 @@ HomaTransport::OutboundMessage::getTransmitReadyPkt(Packet** outPkt)
{
ASSERT(!txPkts.empty());
Packet* head = txPkts.top();
auto chunk = head->peekAtFront<AppMessage>();
auto chunk = head->peekAtFront<HomaPkt>();
PktType outPktType = (PktType)chunk->getPktType();
txPkts.pop();
if (outPktType == PktType::SCHED_DATA) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment