代码拉取完成,页面将自动刷新
function [devState, newSimEvent, isNew] = handleNextPkt(devState, curTime, isBackoffMandatory)
%handle the next packet to send, if exists
% check if we have more packets to send in our queue; assume the sent
% packet is not in the queue anymore
% if there are packets in the queue, start its transmitting attempt
newSimEvent = [];
isNew = 0;
if(devState.curPkt.type ~= packetType.NONE)
% there is a non-empty current packet, so we have to continue
% transmitting it (we stopped a carrier sensing procedure to
% receive a packt so we have to continue the procedure)
if(devState.medCtr == 0)
% medium is free from our point of view
devState = changeDevState(devState, devStateType.WAIT_DIFS); % TODO: insure it has to be WAIT_DIFS state... to continue backoff or start a new one
% creare a 'SET_TIMER' event after DIFS time
opts = createOpts(devState.curPkt, timerType.DIFS);
newSimEvent = createEvent(simEventType.SET_TIMER, curTime + devState.DIFS, devState.dev, opts);
isNew = 1;
else
% medium is busy!
devState = changeDevState(devState, devStateType.WAIT_FOR_IDLE);
end
elseif(devState.queue.tail == 1)
% we are not trying to send a packet now and our queue is empty
devState = changeDevState(devState, devStateType.IDLE);
devState.curPkt = emptyPacket();
else
% there is another packet to send! immediately start
% the sensing process
[devState.curPkt, devState.queue] = getPktFromQueue(devState.queue); % the packet which we have to send
% disp(['queue size of dev ',int2str(devState.dev),'is: ', int2str(devState.queue.tail),' curCWND is:',int2str(devState.curCWND)]);
% there is a packet to send
if(devState.medCtr == 0)
% medium is free from our point of view, we have to change state
% to WAIT_DIFS if it is the end of a successful transmission,
% and to START_CSMA otherwise
if(isBackoffMandatory ==1)
devState = changeDevState(devState, devStateType.WAIT_DIFS); % it has to be WAIT_DIFS state... because we must excecute a new backoff process
else
devState = changeDevState(devState, devStateType.START_CSMA); % it has to be START_CSMA otherwise
end
% creare a 'SET_TIMER' event after DIFS time - we need it
% anyway
opts = createOpts(devState.curPkt, timerType.DIFS);
newSimEvent = createEvent(simEventType.SET_TIMER, curTime + devState.DIFS, devState.dev, opts);
isNew = 1;
else
% medium is busy!
devState = changeDevState(devState, devStateType.WAIT_FOR_IDLE);
end
end
devState.curRecPkt = emptyPacket();
end
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。