Skip to content

Commit

Permalink
Fixed receivePacket() logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jeb16157 committed Mar 14, 2021
1 parent e5c6ce9 commit a8578c9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Python/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(self, queueBufferSize, dddState,
bandwidthToNServer, bandwidthToMserver,
packetSize, packet_ID_prefix="R-"):
self.queueSize = queueBufferSize # MB's
self.receiveBufferLength = 0
self.clientConnection = clientConnection
self.natIP = "10.0.0.0"
self.remoteServerConnection = remoteServerConnection
Expand Down Expand Up @@ -76,14 +77,16 @@ def __init__(self, queueBufferSize, dddState,

# Receive packets coming from different connections.
def receivePacket(self, synPacket):
if(len(self.receiveBuffer) < self.queueSize):
self.receiveBufferLength = self.receiveBufferLength + synPacket.packetSize
if(self.receiveBufferLength < self.queueSize):
self.receiveBuffer.append(synPacket)
self.packetsReceived += 1
self.fileGen.addToLog(synPacket.packetID, "Received at Router",
synPacket.sequenceNumber, synPacket.ackNumber,
synPacket.packetType, self.curTime)
else:
# print("Packet is getting Dropped")
self.receiveBufferLength = self.receiveBufferLength - synPacket.packetSize
self.fileGen.animateDrop(self.packetIDPrefix[0],
curPacket.packetType,
curPacket.sequenceNumber,
Expand All @@ -98,6 +101,7 @@ def receivePacket(self, synPacket):
# Adds the packets in receive buffer to destination queues.
def addToQueues(self):
for i in self.receiveBuffer:
self.receiveBufferLength = self.receiveBufferLength - i.packetSize
# Add to remote servers queue
if(i.dstIP == self.remoteServerIP):
self.currentQueueLoadNServer += i.packetSize
Expand Down

0 comments on commit a8578c9

Please sign in to comment.