-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,55 @@ | ||
class connectionObject: | ||
def __init__(self, bandwidth, propagation_time, device_1, device_1_IP, device_2, device_2_IP, fileGen, connection_name): | ||
self.bandwidth = bandwidth #MB per sec | ||
self.propagationTime = propagation_time #latency of the connection | ||
self.device1 = device_1 #device at end of connection | ||
self.device1IP = device_1_IP #Its IP address | ||
self.device2 = device_2 #device at end of connection | ||
self.device2IP = device_2_IP #Its IP address | ||
self.packetsInTransit = [] #list for storing packets in the connection | ||
def __init__(self, bandwidth, propagation_time, | ||
device_1, device_1_IP, device_2, | ||
device_2_IP, fileGen, connection_name): | ||
self.bandwidth = bandwidth # MB per sec | ||
self.propagationTime = propagation_time # latency of the connection | ||
self.device1 = device_1 # device at end of connection | ||
self.device1IP = device_1_IP # Its IP address | ||
self.device2 = device_2 # device at end of connection | ||
self.device2IP = device_2_IP # Its IP address | ||
self.packetsInTransit = [] # list for storing packets in the connection | ||
self.numberOfPacketsInTransit = 0 | ||
self.curTime = 0 #currentTime | ||
self.totalBandwidthUtilized = 0 #MB's | ||
self.curTime = 0 # currentTime | ||
self.totalBandwidthUtilized = 0 # MB's | ||
|
||
self.packetsReceived = 0 #counter for the summary/log (total number of packets that arrive at the connection) | ||
self.packetsAccepted = 0 #counter for the summary/log (total number of packets that are transported) | ||
self.packetsDropped = 0 #counter for the summary/log (total number of packets that are dropped) | ||
self.packetsDelivered = 0 #counter for the summary/log (total number of packets that are delivered) | ||
self.packetsReceived = 0 # counter for the summary/log | ||
self.packetsAccepted = 0 # counter for the summary/log | ||
self.packetsDropped = 0 # counter for the summary/log | ||
self.packetsDelivered = 0 # counter for the summary/log | ||
|
||
self.fileGen = fileGen #File management object | ||
self.connectionName = connection_name #Name of the connection. Needed for the summary file. Convention should be "A-B" where A is the letter of device1's packetID prefix, and B is the letter of device2's packetID prefix | ||
self.fileGen = fileGen # File management object | ||
self.connectionName = connection_name # Name of the connection. | ||
|
||
def transferPacketOut(self, packet): #function used for accepting a packet from a source to be delivered to a destination | ||
# function used for accepting a packet from a source to be delivered to a destination | ||
def transferPacketOut(self, packet): | ||
self.packetsReceived += 1 | ||
self.totalBandwidthUtilized += (packet.packetSize) | ||
#if (self.totalBandwidthUtilized < self.bandwidth): #if there's space on the connection, accept the packet, otherwise drop it | ||
self.packetsInTransit.append((packet, self.curTime + self.propagationTime)) | ||
self.numberOfPacketsInTransit += 1 | ||
self.packetsAccepted += 1 | ||
self.fileGen.animateTransit(self.device1.packetIDPrefix[0], self.device2.packetIDPrefix[0], packet.packetType, packet.sequenceNumber, packet.ackNumber, packet.dstPortNumber, self.propagationTime) | ||
self.fileGen.addToLog(packet.packetID, "In transit between " + str(self.device1IP) + " and " + str(self.device2IP), packet.sequenceNumber, packet.ackNumber, packet.packetType, self.curTime) | ||
#PENDING REMOVAL 26JAN2021 | ||
# else: | ||
# self.totalBandwidthUtilized -= (packet.packetSize) | ||
# self.packetsDropped += 1 | ||
# #animate the drop depending on the device #dw - technically this causes the packet to be dropped at the device. | ||
# self.device1.packetsDroppedOnConnection += 1 #increment the number of packets dropped due to bandwidth for the device that sent the packet //dw - 16JAN2020 - Abhinna see this for your update. Delete everything after the // when you are done | ||
# self.fileGen.animateDrop(self.device1.packetIDPrefix[0], packet.packetType, packet.sequenceNumber, packet.ackNumber, packet.dstPortNumber) | ||
# self.fileGen.addToLog(packet.packetID, "Dropped between " + str(self.device1IP) + " and " + str(self.device2IP), packet.sequenceNumber, packet.ackNumber, packet.packetType, self.curTime) | ||
|
||
self.fileGen.animateTransit(self.device1.packetIDPrefix[0], | ||
self.device2.packetIDPrefix[0], | ||
packet.packetType, packet.sequenceNumber, | ||
packet.ackNumber, packet.dstPortNumber, | ||
self.propagationTime) | ||
self.fileGen.addToLog(packet.packetID, | ||
"In transit between " + str(self.device1IP) + " and " + str(self.device2IP), | ||
packet.sequenceNumber, packet.ackNumber, packet.packetType, self.curTime) | ||
|
||
def deliverPackets(self): | ||
i = 0 #loop over the list of packets and decide where to send them | ||
i = 0 # loop over the list of packets and decide where to send them | ||
while(i < len(self.packetsInTransit)): | ||
if(self.packetsInTransit[i][1] <= self.curTime): | ||
self.device2.receivePacket(self.packetsInTransit[i][0]) | ||
self.totalBandwidthUtilized -= self.packetsInTransit[i][0].packetSize | ||
del self.packetsInTransit[i] | ||
self.numberOfPacketsInTransit -= 1 | ||
#i -= 1 | ||
self.packetsDelivered += 1 | ||
|
||
else: | ||
i += 1 | ||
def updateTime(self): #update the clock of the device | ||
|
||
def updateTime(self): # update the clock of the device | ||
self.curTime += 1 | ||
self.deliverPackets() |