Skip to content

Commit

Permalink
Refractoring and debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
jeb16157 committed Feb 16, 2021
1 parent 6b12edd commit 69c4696
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 185 deletions.
201 changes: 22 additions & 179 deletions Python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@


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)
Expand All @@ -27,15 +28,20 @@ def runSimulation(dddState,skipsim, sumOut, logOut, packetSize, resendSynAckTime
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")
connectionAttackerMServer = connectionObject.connectionObject(attackertoReflector, PropDelay,None, "5.0.0.0", None, "3.0.0.0", fileGen, "A-M")

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, "3.0.0.0", None, "5.0.0.0", fileGen, "R-A")

simClient = client.client(connectionClientRouter, "1.0.0.0", "4.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, simDddController, simDddController.dddPortMapper, fileGen, queueLimit, routertoClient, routertoNormal, routertoReflector, "R-")
simRouter = router.router(1000,dddState, "2.0.0.0", 0, DDDMappingDelay, connectionRouterClient, connectionRouterNServer, connectionRouterMServer,connectionRouterAttacker, simDddController, simDddController.dddPortMapper, fileGen, queueLimit, routertoClient, routertoNormal, routertoReflector, "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-")
simAttacker = attacker.attacker(connectionAttackerMServer, "1.0.0.0", "4.0.0.0", fileGen, packetSize, attackertoReflector,simDddController, "5.0.0.0", "A-", 1)
if(amplification == 1):
simAttacker = attacker.attacker(connectionAttackerMServer,connectionAttackerRouter, "1.0.0.0", "4.0.0.0", fileGen, packetSize, attackertoReflector,simDddController, "5.0.0.0", "A-",attackerType, 1)
else:
simAttacker = attacker.attacker(connectionAttackerMServer,connectionAttackerRouter, "1.0.0.0", "4.0.0.0", fileGen, packetSize, attackertoReflector,simDddController, "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 @@ -54,9 +60,15 @@ 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

simulationDuration = int(simulationDuration * 1000)
for i in range(1, simulationDuration):
Expand All @@ -66,13 +78,16 @@ def runSimulation(dddState,skipsim, sumOut, logOut, packetSize, resendSynAckTime
simMServer.updateTime()
simAttacker.updateTime()
simDddController.updateTime()

connectionClientRouter.updateTime()
connectionRouterMServer.updateTime()
connectionRouterNServer.updateTime()
connectionRouterClient.updateTime()
connectionNServerRouter.updateTime()
connectionMServerRouter.updateTime()
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

Expand Down Expand Up @@ -182,175 +197,3 @@ def runSimulation(dddState,skipsim, sumOut, logOut, packetSize, resendSynAckTime

#runSimulation()










def runNoAmpSimulation(dddState,skipsim, sumOut, logOut, packetSize, resendSynAckTime, MaxQueueSize, DDDMappingDelay, PropDelay, NumbDDDPortsOpen, timeUntilNextDDDChange, overlapTime, simulationDuration, numbSynAckResends, clienttoRouter, routertoClient,routertoReflector,routertoNormal,normaltoRouter,reflectortoRouter,attackertoReflector, queueLimit, 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, "3.0.0.0", fileGen, "A-R")
connectionAttackerMServer = connectionObject.connectionObject(attackertoReflector, PropDelay,None, "5.0.0.0", None, "3.0.0.0", fileGen, "A-R")

simClient = client.client(connectionClientRouter, "1.0.0.0", "4.0.0.0", "5.0.0.0", 50, 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, simDddController, simDddController.dddPortMapper, fileGen, queueLimit, routertoClient, routertoNormal, routertoReflector, "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-")
simAttacker = attacker.attacker(connectionAttackerRouter, "1.0.0.0", "4.0.0.0", fileGen, packetSize, attackertoReflector,simDddController, "5.0.0.0", "A-", 1, 0)
#self,connectionToServer, client_IP, server_IP, fileGen, packetSize, bandwidthToMserver, ipAddress="", packet_ID_prefix = "A-"):
connectionClientRouter.device1 = simClient
connectionClientRouter.device2 = simRouter

connectionRouterMServer.device1 = simRouter
connectionRouterMServer.device2 = simMServer

connectionRouterNServer.device1 = simRouter
connectionRouterNServer.device2 = simNServer

connectionRouterClient.device1 = simRouter
connectionRouterClient.device2 = simClient

connectionMServerRouter.device1 = simMServer
connectionMServerRouter.device2 = simRouter

connectionNServerRouter.device1 = simNServer
connectionNServerRouter.device2 = simRouter

connectionAttackerRouter.device1 = simAttacker
connectionAttackerRouter.device2 = simRouter

simulationDuration = int(simulationDuration * 1000)
for i in range(1, simulationDuration):
simClient.updateTime()
simRouter.updateTime()
simNServer.updateTime()
simMServer.updateTime()
simAttacker.updateTime()
simDddController.updateTime()
connectionClientRouter.updateTime()
connectionRouterMServer.updateTime()
connectionRouterNServer.updateTime()
connectionRouterClient.updateTime()
connectionNServerRouter.updateTime()
connectionMServerRouter.updateTime()
connectionAttackerRouter.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

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
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
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
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
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)

# Index 5 is the string of the device
animationDataClient[5] = 'client'
animationDataMServer[5] = 'mserver'
animationDataNServer[5] = 'nserver'
animationDataRouter[5] = 'router'
animationDataAttacker[5] = 'attacker'

# 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.updateTime()
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)
print("CLIENT: QUEUE, Sending Packet")
print("-----------------------------------------")
print(simClient.queue)
print(simClient.sendingPacket)
print("-----------------------------------------")
print("ROUTER: Client, Remote server, and Mal Server queues; Sending packets")
print(simRouter.receiveBuffer)
print("Client queue: " + str(simRouter.queueClient))
print(simRouter.queueNServer)
print(simRouter.queueMServer)
print(simRouter.sendClient)
print(simRouter.sendNServer)
print(simRouter.sendMServer)
print("-----------------------------------------")
print("N SERVER: Queue, Sending Packet")
print(simNServer.queue)
print(simNServer.sendingPacket)
print("-----------------------------------------")
print("M SERVER BUFFER, QUEUE")
print(simMServer.queue)
print(simMServer.sendingPacket)
print("-----------------------------------------")
print("ATTACKER, Sending Packet")
print(simAttacker.sendingPacket)
print("CONNECTIONS")
print("Connection: connectionAttackerRouter" + str(connectionAttackerRouter.packetsInTransit))
print("Connection: connectionRouterMServer" + str(connectionRouterMServer.packetsInTransit))
print("Connection: connectionRouterNServer" + str(connectionRouterNServer.packetsInTransit))
print("Connection: connectionClientRouter" + str(connectionClientRouter.packetsInTransit))
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 []
9 changes: 3 additions & 6 deletions pserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@ def runSimulation(input1):
attackerType = float(Param[22]);
amplification = float(Param[23]);

# Reply the client with a JSON including what it'd sent.
#response = main.runSimulation(True, False, True, True, 100000, 40, 100, 20, 1, 2, 20, 100000, 100, 50, .05)
if (amplification == 1):
response = main.runSimulation(ddd_state, skip_sim, sumOut, logOut, packet_size,rtsa,max_queue_size,ddd_mapping_delay,propagation_delay,number_of_ddd_ports, time_to_next_ddd_port,overlap_time_old_ddd, durationSim, numbSynAckResends, clienttoRouter, routertoClient,routertoReflector,routertoNormal,normaltoRouter,reflectortoRouter,attackertoReflector, queueLimit, attackerType, amplification)
else:
response = main.runNoAmpSimulation(ddd_state, skip_sim, sumOut, logOut, packet_size,rtsa,max_queue_size,ddd_mapping_delay,propagation_delay,number_of_ddd_ports, time_to_next_ddd_port,overlap_time_old_ddd, durationSim, numbSynAckResends, clienttoRouter, routertoClient,routertoReflector,routertoNormal,normaltoRouter,reflectortoRouter,attackertoReflector, queueLimit, attackerType, amplification)

response = main.runSimulation(ddd_state, skip_sim, sumOut, logOut, packet_size,rtsa,max_queue_size,ddd_mapping_delay,propagation_delay,number_of_ddd_ports, time_to_next_ddd_port,overlap_time_old_ddd, durationSim, numbSynAckResends, clienttoRouter, routertoClient,routertoReflector,routertoNormal,normaltoRouter,reflectortoRouter,attackertoReflector, queueLimit, attackerType, amplification)

print('Backend Simulation Total Elapsed Time:', time.time() - start_time, 'seconds')

# Converting response data structure into json string
Expand Down

0 comments on commit 69c4696

Please sign in to comment.