Skip to content

Commit

Permalink
Pep8 reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jeb16157 committed Feb 18, 2021
1 parent 12dbcbe commit a0b4b69
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 66 deletions.
195 changes: 139 additions & 56 deletions Python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,119 @@
from . import router
from . import filegenerator

#skipsim and ouputFile aren't being used right now
# skipsim and ouputFile aren't being used right now
# Replaced outputFile with sumOut, logOut booleans.


def runSimulation(dddState,skipsim, sumOut, logOut, packetSize, resendSynAckTime, MaxQueueSize, DDDMappingDelay, PropDelay, NumbDDDPortsOpen, timeUntilNextDDDChange, overlapTime, simulationDuration, numbSynAckResends, clienttoRouter, routertoClient,routertoReflector,routertoNormal,normaltoRouter,reflectortoRouter,attackertoReflector, queueLimit, attackerType, amplification):
def runSimulation(dddState, skipsim, sumOut,
logOut, packetSize, resendSynAckTime,
MaxQueueSize, DDDMappingDelay, PropDelay,
NumbDDDPortsOpen, timeUntilNextDDDChange,
overlapTime, simulationDuration,
numbSynAckResends, clienttoRouter,
routertoClient, routertoReflector,
routertoNormal, normaltoRouter,
reflectortoRouter, attackertoReflector,
queueLimit, attackerType, amplification):
print(amplification)
print(attackerType)

bandwidths = [clienttoRouter, routertoClient, routertoReflector, routertoNormal, normaltoRouter, reflectortoRouter, attackertoReflector]
fileGen = filegenerator.filegenerator(logOut, sumOut, not skipsim, "LogWithFilter", "SummaryWithFilter", dddState, packetSize, resendSynAckTime, MaxQueueSize, DDDMappingDelay, PropDelay, NumbDDDPortsOpen, bandwidths, timeUntilNextDDDChange, overlapTime, numbSynAckResends, attackerType, amplification)
bandwidths = [clienttoRouter, routertoClient, routertoReflector,
routertoNormal, normaltoRouter, reflectortoRouter,
attackertoReflector]
fileGen = filegenerator.filegenerator(logOut, sumOut, not skipsim,
"LogWithFilter", "SummaryWithFilter",
dddState, packetSize, resendSynAckTime,
MaxQueueSize, DDDMappingDelay, PropDelay,
NumbDDDPortsOpen, bandwidths,
timeUntilNextDDDChange, overlapTime,
numbSynAckResends, attackerType, amplification)

debug_mode = False

connectionClientRouter = connectionObject.connectionObject(clienttoRouter,
PropDelay, None,
"1.0.0.0", None,
"2.0.0.0", fileGen,
"C-R")
connectionRouterMServer = connectionObject.connectionObject(routertoReflector,
PropDelay, None,
"2.0.0.0", None,
"3.0.0.0", fileGen,
"R-M")
connectionRouterNServer = connectionObject.connectionObject(routertoNormal,
PropDelay, None,
"2.0.0.0", None,
"4.0.0.0", fileGen,
"R-N")
connectionRouterClient = connectionObject.connectionObject(routertoClient,
PropDelay, None,
"2.0.0.0", None,
"1.0.0.0", fileGen,
"R-C")
connectionMServerRouter = connectionObject.connectionObject(reflectortoRouter,
PropDelay, None,
"3.0.0.0", None,
"2.0.0.0", fileGen,
"M-R")
connectionNServerRouter = connectionObject.connectionObject(normaltoRouter,
PropDelay, None,
"4.0.0.0", None,
"2.0.0.0", fileGen,
"N-R")
connectionAttackerRouter = connectionObject.connectionObject(attackertoReflector,
PropDelay, None,
"5.0.0.0", None,
"2.0.0.0", fileGen,
"A-R")
connectionAttackerMServer = connectionObject.connectionObject(attackertoReflector,
PropDelay, None,
"5.0.0.0", None,
"3.0.0.0", fileGen,
"A-R")
connectionRouterAttacker = connectionObject.connectionObject(routertoReflector,
PropDelay, None,
"2.0.0.0", None,
"5.0.0.0", fileGen,
"R-A")

connectionClientRouter = connectionObject.connectionObject(clienttoRouter, PropDelay, None, "1.0.0.0", None, "2.0.0.0", fileGen, "C-R")
connectionRouterMServer = connectionObject.connectionObject(routertoReflector, PropDelay, None, "2.0.0.0", None, "3.0.0.0", fileGen, "R-M")
connectionRouterNServer = connectionObject.connectionObject(routertoNormal, PropDelay, None, "2.0.0.0", None, "4.0.0.0", fileGen, "R-N")
connectionRouterClient = connectionObject.connectionObject(routertoClient, PropDelay, None, "2.0.0.0", None, "1.0.0.0", fileGen, "R-C")
connectionMServerRouter = connectionObject.connectionObject(reflectortoRouter, PropDelay, None, "3.0.0.0", None, "2.0.0.0", fileGen, "M-R")
connectionNServerRouter = connectionObject.connectionObject(normaltoRouter, PropDelay, None, "4.0.0.0", None, "2.0.0.0", fileGen, "N-R")
connectionAttackerRouter = connectionObject.connectionObject(attackertoReflector, PropDelay,None, "5.0.0.0", None, "2.0.0.0", fileGen, "A-R")
connectionAttackerMServer = connectionObject.connectionObject(attackertoReflector, PropDelay,None, "5.0.0.0", None, "3.0.0.0", fileGen, "A-R")
connectionRouterAttacker = connectionObject.connectionObject(routertoReflector, PropDelay, None, "2.0.0.0", None, "5.0.0.0", fileGen, "R-A")

simClient = client.client(connectionClientRouter, "1.0.0.0", "4.0.0.0", "3.0.0.0", "5.0.0.0", 2, fileGen, packetSize, NumbDDDPortsOpen, queueLimit, clienttoRouter, "C-")
simDddController = dddController.dddController(timeUntilNextDDDChange, overlapTime, NumbDDDPortsOpen, fileGen)
simRouter = router.router(1000,dddState, "2.0.0.0", 0, DDDMappingDelay, connectionRouterClient, connectionRouterNServer, connectionRouterMServer,connectionRouterAttacker, simDddController, simDddController.dddPortMapper, fileGen, queueLimit, routertoClient, routertoNormal, routertoReflector,packetSize, "R-")
simNServer = server.Server(connectionNServerRouter, "4.0.0.0", MaxQueueSize, resendSynAckTime, numbSynAckResends, fileGen, packetSize, queueLimit, normaltoRouter, "N-",)
simMServer = server.Server(connectionMServerRouter, "3.0.0.0", MaxQueueSize, resendSynAckTime, numbSynAckResends, fileGen, packetSize, queueLimit, reflectortoRouter, "M-")
simClient = client.client(connectionClientRouter, "1.0.0.0",
"4.0.0.0", "3.0.0.0", "5.0.0.0", 2,
fileGen, packetSize, NumbDDDPortsOpen,
queueLimit, clienttoRouter, "C-")
simDddController = dddController.dddController(timeUntilNextDDDChange,
overlapTime, NumbDDDPortsOpen,
fileGen)
simRouter = router.router(1000, dddState, "2.0.0.0", 0,
DDDMappingDelay, connectionRouterClient,
connectionRouterNServer,
connectionRouterMServer,
connectionRouterAttacker, simDddController,
simDddController.dddPortMapper, fileGen,
queueLimit, routertoClient, routertoNormal,
routertoReflector, packetSize, "R-")
simNServer = server.Server(connectionNServerRouter, "4.0.0.0",
MaxQueueSize, resendSynAckTime,
numbSynAckResends, fileGen,
packetSize, queueLimit, normaltoRouter,
"N-",)
simMServer = server.Server(connectionMServerRouter, "3.0.0.0",
MaxQueueSize, resendSynAckTime,
numbSynAckResends, fileGen, packetSize,
queueLimit, reflectortoRouter, "M-")
if(amplification == 1):
simAttacker = attacker.attacker(connectionAttackerMServer,connectionAttackerRouter, "1.0.0.0", "3.0.0.0", fileGen, packetSize, attackertoReflector, "5.0.0.0", "A-",attackerType, 1)
simAttacker = attacker.attacker(connectionAttackerMServer,
connectionAttackerRouter,
"1.0.0.0", "3.0.0.0", fileGen,
packetSize, attackertoReflector,
"5.0.0.0", "A-", attackerType, 1)
else:
simAttacker = attacker.attacker(connectionAttackerMServer,connectionAttackerRouter, "1.0.0.0", "3.0.0.0", fileGen, packetSize, attackertoReflector, "5.0.0.0", "A-", attackerType, 0)
simAttacker = attacker.attacker(connectionAttackerMServer,
connectionAttackerRouter,
"1.0.0.0", "3.0.0.0", fileGen,
packetSize, attackertoReflector,
"5.0.0.0", "A-", attackerType, 0)

#self,connectionToServer, client_IP, server_IP, fileGen, packetSize, bandwidthToMserver, ipAddress="", packet_ID_prefix = "A-"):
connectionClientRouter.device1 = simClient
connectionClientRouter.device2 = simRouter

Expand All @@ -60,13 +138,13 @@ def runSimulation(dddState,skipsim, sumOut, logOut, packetSize, resendSynAckTime

connectionNServerRouter.device1 = simNServer
connectionNServerRouter.device2 = simRouter

connectionAttackerMServer.device1 = simAttacker
connectionAttackerMServer.device2 = simMServer
connectionAttackerMServer.device2 = simMServer

connectionAttackerRouter.device1 = simAttacker
connectionAttackerRouter.device2 = simRouter

connectionRouterAttacker.device1 = simRouter
connectionRouterAttacker.device2 = simAttacker

Expand All @@ -88,39 +166,38 @@ def runSimulation(dddState,skipsim, sumOut, logOut, packetSize, resendSynAckTime
connectionAttackerMServer.updateTime()
connectionAttackerRouter.updateTime()
connectionRouterAttacker.updateTime()
#To avoid having the animateData function from filegenerator be a massive line of 25 detailed arguments, I opted to consolidate them into five lists (one per each device).
#This enhances readability and will allow for ease of modification if we need to modify animateData again in the future

# Five lists for the animateData function(one per each device).
animationDataClient = ['0'] * 7
animationDataMServer = ['0'] * 7
animationDataNServer = ['0'] * 7
animationDataRouter = ['0'] * 7
animationDataAttacker = ['0'] * 7
#Index 0 is the number of enqueued packets #Note that everything is converted to strings first. It could've been done in the animateData function, I just want to keep that function clean
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))
#animationDataAttacker[0] = The attacker never receives packets, so it's value is unchanged
#Index 1 is the number of packets the device has received
# 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))
# 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)
#Index 2 is the number of packets the device has dropped
# 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)
#Index 3 is the number of packets the device has generated
# 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)
#Index 4 is the number of packets the device has sent
# 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)
Expand All @@ -141,13 +218,19 @@ def runSimulation(dddState,skipsim, sumOut, logOut, packetSize, resendSynAckTime
animationDataRouter[6] = str(simRouter.packetsDroppedOnConnection)
animationDataAttacker[6] = str(simAttacker.packetsDroppedOnConnection)


fileGen.animateData(animationDataClient, animationDataMServer, animationDataNServer, animationDataRouter, animationDataAttacker)
fileGen.animateData(animationDataClient, animationDataMServer,
animationDataNServer, animationDataRouter,
animationDataAttacker)

fileGen.updateTime()
fileGen.updateSummary(simClient, simAttacker, simMServer, simNServer, simRouter, connectionClientRouter, connectionRouterMServer, connectionRouterNServer, connectionAttackerMServer)
fileGen.addSummaryDataToLog(simClient, simAttacker, simMServer, simNServer, simRouter, connectionClientRouter, connectionRouterMServer, connectionRouterNServer, connectionAttackerMServer)

fileGen.updateSummary(simClient, simAttacker, simMServer,
simNServer, simRouter, connectionClientRouter,
connectionRouterMServer, connectionRouterNServer,
connectionAttackerMServer)
fileGen.addSummaryDataToLog(simClient, simAttacker, simMServer,
simNServer, simRouter, connectionClientRouter,
connectionRouterMServer, connectionRouterNServer,
connectionAttackerMServer)

if debug_mode:
print(i)
Expand Down Expand Up @@ -178,24 +261,24 @@ def runSimulation(dddState,skipsim, sumOut, logOut, packetSize, resendSynAckTime
print("ATTACKER, Sending Packet")
print(simAttacker.sendingPacket)
print("CONNECTIONS")
print("Connection: connectionAttackerMServer" + str(connectionAttackerMServer.packetsInTransit))
print("Connection: connectionRouterMServer" + str(connectionRouterMServer.packetsInTransit))
print("Connection: connectionRouterNServer" + str(connectionRouterNServer.packetsInTransit))
print("Connection: connectionClientRouter" + str(connectionClientRouter.packetsInTransit))
print("Ports that are open to Map: " + str(simDddController.currentUsablePorts))
print("Connection: connectionAttackerMServer"
+ str(connectionAttackerMServer.packetsInTransit))
print("Connection: connectionRouterMServer"
+ str(connectionRouterMServer.packetsInTransit))
print("Connection: connectionRouterNServer"
+ str(connectionRouterNServer.packetsInTransit))
print("Connection: connectionClientRouter"
+ str(connectionClientRouter.packetsInTransit))
print("Ports that are open to Map: "
+ str(simDddController.currentUsablePorts))
print("Old ports: " + str(simDddController.oldPorts))
print("Time to next Change: " + str(simDddController.toNextChange))
print("Current Mappings are: " + str(simDddController.dddPortMapper.portMappings))
print("Time to next Change: "
+ str(simDddController.toNextChange))
print("Current Mappings are: "
+ str(simDddController.dddPortMapper.portMappings))
print("-------------------------------------------------------------------")

input()

#fileGen.updateSummary(simClient, simAttacker, simMServer, simNServer, simRouter, connectionClientRouter, connectionRouterMServer, connectionRouterNServer, connectionAttackerMServer)
fileGen.outputFile()


# Return value will be the animateInstructions
return fileGen.instructions if hasattr(fileGen, 'instructions') else []

#runSimulation()

Loading

0 comments on commit a0b4b69

Please sign in to comment.