Skip to content

Commit

Permalink
Updates #85
Browse files Browse the repository at this point in the history
Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
  • Loading branch information
manoelcampos committed Jun 29, 2018
1 parent 48aa5bb commit 5a4592b
Showing 1 changed file with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,22 @@ private void addPacketsToBeSentFromVm(final NetworkCloudlet sourceCloudlet) {
}

/**
* Check for packets to be received by a given cloudlet
* Checks if there are packets to be received by a given cloudlet
* and deliver them to it.
*
* @param sourceCloudlet cloudlet to check if there are packets to be received from.
* @param candidateDestinationCloudlet a {@link NetworkCloudlet} that is waiting for packets,
* which is going to be checked if there are packets targeting it.
*/
private void receivePackets(final NetworkCloudlet sourceCloudlet) {
final Optional<CloudletReceiveTask> optional = getCloudletCurrentTask(sourceCloudlet);
private void receivePackets(final NetworkCloudlet candidateDestinationCloudlet) {
final Optional<CloudletReceiveTask> optional = getCloudletCurrentTask(candidateDestinationCloudlet);
optional.ifPresent(task -> {
final List<VmPacket> receivedPkts = getPacketsSentToGivenTask(task);
final List<VmPacket> receivedPkts = getPacketsSentToCloudlet(task);
// Assumption: packet will not arrive in the same cycle
receivedPkts.forEach(task::receivePacket);
receivedPkts.forEach(pkt ->
logger.trace(
"{}: {}: {} in {} received pkt with {} bytes from {} in {}",
sourceCloudlet.getSimulation().clock(), getClass().getSimpleName(),
candidateDestinationCloudlet.getSimulation().clock(), getClass().getSimpleName(),
pkt.getReceiverCloudlet(),
pkt.getDestination(),
pkt.getSize(),
Expand All @@ -179,7 +180,7 @@ private void receivePackets(final NetworkCloudlet sourceCloudlet) {
* of the expected packets up to a given timeout.
* After that, the task has to stop waiting and fail.
*/
scheduleNextTaskIfCurrentIsFinished(sourceCloudlet);
scheduleNextTaskIfCurrentIsFinished(candidateDestinationCloudlet);
});
}

Expand All @@ -194,17 +195,21 @@ private <T extends CloudletTask> Optional<T> getCloudletCurrentTask(final Networ
}

/**
* Gets the list of packets sent to a given CloudletReceiveTask.
* @param destinationTask The task that is waiting for packets
* @return
* Checks if there are packets sent to a given {@link NetworkCloudlet},
* to be processed by a {@link CloudletReceiveTask}, and returns them to be
* delivered for that Cloudlet.
*
* @param receiveTask the {@link CloudletReceiveTask} that is waiting for packets
* @return the list of packets targeting the {@link NetworkCloudlet} or an empty list
* if there are no packets received that are targeting such a Cloudlet.
*/
private List<VmPacket> getPacketsSentToGivenTask(final CloudletReceiveTask destinationTask) {
final List<VmPacket> pktsFromExpectedSenderVm =
getListOfPacketsSentFromVm(destinationTask.getSourceVm());
private List<VmPacket> getPacketsSentToCloudlet(final CloudletReceiveTask receiveTask) {
final List<VmPacket> pktsFromExpectedSenderVm = getListOfPacketsSentFromVm(receiveTask.getSourceVm());

return pktsFromExpectedSenderVm
.stream()
.filter(pkt -> pkt.getDestination().getId() == destinationTask.getCloudlet().getVm().getId())
.filter(pkt -> pkt.getDestination().equals(receiveTask.getCloudlet().getVm()))
.filter(pkt -> pkt.getReceiverCloudlet().equals(receiveTask.getCloudlet()))
.collect(Collectors.toList());
}

Expand Down

0 comments on commit 5a4592b

Please sign in to comment.