Skip to content

Commit

Permalink
Updated animation code to support nat on the back end. Front end need…
Browse files Browse the repository at this point in the history
…s to be completed
  • Loading branch information
dvw16101 committed Feb 27, 2021
1 parent 09fa2af commit 30935ea
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Python/filegenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def initializeSummary(self): # initializer for the summary file

def initializeAnimationInstructions(self):
# self.currentAnimations = "" #used to hold the instructions for the current line of the animation instructions
self.prefix_map = {'C': 'client', 'A': 'attacker', 'R': 'router', 'M': 'mserver', 'N': 'nserver'}
self.prefix_map = {'C': 'client', 'A': 'attacker', 'R': 'router', 'M': 'mserver', 'N': 'nserver', 'T': 'nat'}
self.instructions = []
self.tempInstructions = []

Expand Down Expand Up @@ -321,7 +321,7 @@ def animateDrop(self, source, packet_type,

def animateData(self, clientData, MServerData,
NServerData, routerData,
attackerData): # function for generating data instructions.
attackerData, natData): # function for generating data instructions.
if (self.makeAnimation):
for entity in [clientData, MServerData, NServerData, routerData, attackerData]:
instruction = ['data', entity]
Expand Down
13 changes: 10 additions & 3 deletions Python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,51 +211,58 @@ def runSimulation(dddState, skipsim, sumOut,
animationDataNServer = ['0'] * 7
animationDataRouter = ['0'] * 7
animationDataAttacker = ['0'] * 7
animationDataNat = ['0'] * 7
# Index 0 is the number of enqueued packets
animationDataClient[0] = str(len(simClient.queue))
animationDataMServer[0] = str(len(simMServer.queue))
animationDataNServer[0] = str(len(simNServer.queue))
animationDataRouter[0] = str(len(simRouter.queueClient) + len(simRouter.queueNServer) + len(simRouter.queueMServer))
animationDataNat[0] = str(simNat.currentQueueLoadClient + simNat.currentQueueLoadRouter)
# animationDataAttacker[0] = The attacker never receives packets, so it's value is unchanged
# Index 1 is the number of packets the device has received
animationDataClient[1] = str(simClient.packetsReceived)
animationDataMServer[1] = str(simMServer.packetsReceived)
animationDataNServer[1] = str(simNServer.packetsReceived)
animationDataRouter[1] = str(simRouter.packetsReceived)
animationDataAttacker[1] = str(simAttacker.packetsReceived)
animationDataNat[1] = str(simNat.packetsReceived)
# Index 2 is the number of packets the device has dropped
animationDataClient[2] = str(simClient.packetsDropped)
animationDataMServer[2] = str(simMServer.packetsDropped)
animationDataNServer[2] = str(simNServer.packetsDropped)
animationDataRouter[2] = str(simRouter.packetsDropped)
animationDataAttacker[2] = str(simAttacker.packetsDropped)
animationDataNat[2] = str(simNat.packetsDropped)
# Index 3 is the number of packets the device has generated
animationDataClient[3] = str(simClient.packetsGenerated)
animationDataMServer[3] = str(simMServer.packetsGenerated)
animationDataNServer[3] = str(simNServer.packetsGenerated)
animationDataRouter[3] = str(simRouter.packetsGenerated)
animationDataAttacker[3] = str(simAttacker.packetsGenerated)
# animationDataNat[3] Nothing to be done here, the NAT does not independently generate packets
# Index 4 is the number of packets the device has sent
animationDataClient[4] = str(simClient.packetsSent)
animationDataMServer[4] = str(simMServer.packetsSent)
animationDataNServer[4] = str(simNServer.packetsSent)
animationDataRouter[4] = str(simRouter.packetsSent)
animationDataAttacker[4] = str(simAttacker.packetsSent)
animationDataNat[4] = str(simNat.packetsSent)
# Index 5 is the string of the device
animationDataClient[5] = 'client'
animationDataMServer[5] = 'mserver'
animationDataNServer[5] = 'nserver'
animationDataRouter[5] = 'router'
animationDataAttacker[5] = 'attacker'
animationDataNat[5] = 'nat'
# Index 6 is the number of outbound packets that get dropped due to the bandwidth
animationDataClient[6] = str(simClient.packetsDroppedOnConnection)
animationDataMServer[6] = str(simMServer.packetsDroppedOnConnection)
animationDataNServer[6] = str(simNServer.packetsDroppedOnConnection)
animationDataRouter[6] = str(simRouter.packetsDroppedOnConnection)
animationDataAttacker[6] = str(simAttacker.packetsDroppedOnConnection)
#fileGen.animateData(animationDataClient, animationDataMServer,
# animationDataNServer, animationDataRouter,
# animationDataAttacker)
fileGen.animateData(animationDataClient, animationDataMServer,
animationDataNServer, animationDataRouter,
animationDataAttacker, animationDataNat)
fileGen.updateTime()
fileGen.updateSummary(simClient, simAttacker, simMServer,
simNServer, simRouter, simNat,
Expand Down
18 changes: 12 additions & 6 deletions Python/nat.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ def receivePacket(self, packet):
packet.sequenceNumber, packet.ackNumber,
packet.packetType, self.curTime)
else:
# print("Packet is getting Dropped")
# self.fileGen.animateDrop(self.packetIDPrefix[0],
# curPacket.packetType,
# curPacket.sequenceNumber,
# curPacket.ackNumber,
# curPacket.dstPortNumber)
print("Packet is getting Dropped")
self.fileGen.animateDrop(curPacket.packetID[0],
curPacket.packetType,
curPacket.sequenceNumber,
curPacket.ackNumber,
curPacket.dstPortNumber)
self.packetsDropped += 1
self.fileGen.addToLog(packet.packetID,
"Dropped at Router: No space in receiveBuffer",
Expand All @@ -74,6 +74,9 @@ def addtoQueues(self):
else:
self.currentQueueLoadRouter -= i.packetSize
# Drop Packet
self.fileGen.animateDrop(i.packetID[0], i.packetType,
i.sequenceNumber, i.ackNumber,
i.dstPortNumber)
self.receiveBuffer.remove(i)

def mapPacket(self, packet, dst):
Expand All @@ -90,6 +93,9 @@ def mapPacket(self, packet, dst):
else:
# Drop Packet
print("Mapping not found")
self.fileGen.animateDrop(packet.packetID[0], packet.packetType,
packet.sequenceNumber, packet.ackNumber,
packet.dstPortNumber)
return False
else:
print("Router packet getting mapped")
Expand Down

0 comments on commit 30935ea

Please sign in to comment.