Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
CSEGroup22SDP/Python/main.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
344 lines (317 sloc)
18.8 KB
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
import uuid | |
from . import packet | |
from . import connectionObject | |
from . import attacker | |
from . import server | |
from . import client | |
from . import dddController | |
from . import dddPortMapping | |
from . import router | |
from . import filegenerator | |
from . import nat | |
# 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, | |
storageFolder): | |
# For a simulation session, we create a unique session id for it using GUID. | |
sessionGuid = uuid.uuid4() # Generate a GUID/UUID for this session | |
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, storageFolder, sessionGuid) | |
debug_mode = False | |
#connectionClientRouter = connectionObject.connectionObject(clienttoRouter, | |
# PropDelay, None, | |
# "1.0.0.0", None, | |
# "2.0.0.0", fileGen, | |
# "C-R") | |
connectionClientNat = connectionObject.connectionObject(clienttoRouter, PropDelay, | |
None, "1.0.0.0", None, | |
"10.0.0.0", fileGen, "C-T") # Addition for Nat | |
connectionNatClient = connectionObject.connectionObject(routertoClient, PropDelay, | |
None, "10.0.0.0", None, | |
"1.0.0.0", fileGen, "T-C") # Addition for Nat | |
connectionRouterNat = connectionObject.connectionObject(routertoClient, PropDelay, | |
None, "2.0.0.0", None, | |
"10.0.0.0", fileGen, "R-T") # Addition for Nat | |
connectionNatRouter = connectionObject.connectionObject(clienttoRouter, PropDelay, None, | |
"10.0.0.0", None, "2.0.0.0", | |
fileGen, "T-R") # Addition for Nat | |
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(connectionClientNat, "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, connectionRouterNat, | |
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, | |
"10.0.0.0", "3.0.0.0", fileGen, | |
packetSize, attackertoReflector, | |
"5.0.0.0", "A-", attackerType, 1) | |
else: | |
simAttacker = attacker.attacker(connectionAttackerMServer, | |
connectionAttackerRouter, | |
"10.0.0.0", "3.0.0.0", fileGen, | |
packetSize, attackertoReflector, | |
"5.0.0.0", "A-", attackerType, 0) | |
simNat = nat.nat(connectionNatRouter, connectionNatClient, | |
1000, fileGen, queueLimit, clienttoRouter, routertoClient) # Addition for Nat | |
# connectionClientRouter.device1 = simClient | |
# connectionClientRouter.device2 = simRouter | |
connectionClientNat.device1 = simClient # Addition for Nat | |
connectionClientNat.device2 = simNat # Addition for Nat | |
connectionNatClient.device1 = simNat # Addition for Nat | |
connectionNatClient.device2 = simClient # Addition for Nat | |
connectionRouterNat.device1 = simRouter # Addition for Nat | |
connectionRouterNat.device2 = simNat # Addition for Nat | |
connectionNatRouter.device1 = simNat # Addition for Nat | |
connectionNatRouter.device2 = simRouter # Addition for Nat | |
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 | |
connectionAttackerMServer.device1 = simAttacker | |
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): | |
simClient.updateTime() | |
simRouter.updateTime() | |
simNServer.updateTime() | |
simMServer.updateTime() | |
simAttacker.updateTime() | |
simDddController.updateTime() | |
simNat.updateTime() # Addition for nat | |
#connectionClientRouter.updateTime() | |
connectionRouterMServer.updateTime() | |
connectionRouterNServer.updateTime() | |
connectionNatClient.updateTime() # Addition for nat | |
connectionClientNat.updateTime() # Addition for nat | |
connectionNatRouter.updateTime() # Addition for nat | |
connectionRouterNat.updateTime() # Addition for nat | |
#connectionRouterClient.updateTime() | |
connectionNServerRouter.updateTime() | |
connectionMServerRouter.updateTime() | |
connectionAttackerMServer.updateTime() | |
connectionAttackerRouter.updateTime() | |
connectionRouterAttacker.updateTime() | |
# 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 | |
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 | |
fileGen.animateData(animationDataClient, animationDataMServer, | |
animationDataNServer, animationDataRouter, | |
animationDataAttacker, animationDataNat) | |
fileGen.updateTime() | |
fileGen.updateSummary(simClient, simAttacker, simMServer, | |
simNServer, simRouter, simNat, | |
connectionClientNat, connectionNatClient, | |
connectionRouterMServer, connectionMServerRouter, | |
connectionRouterNServer, connectionNServerRouter, | |
connectionRouterNat, connectionNatRouter, | |
connectionAttackerMServer, | |
connectionAttackerRouter, connectionRouterAttacker) | |
fileGen.addSummaryDataToLog(simClient, simAttacker, simMServer, | |
simNServer, simRouter, simNat, | |
connectionClientNat, connectionNatClient, | |
connectionRouterMServer, connectionMServerRouter, | |
connectionRouterNServer, connectionNServerRouter, | |
connectionRouterNat, connectionNatRouter, | |
connectionAttackerMServer, | |
connectionAttackerRouter, connectionRouterAttacker) | |
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(simRouter.queueClient) | |
print(simRouter.queueNServer) | |
print(simRouter.queueMServer) | |
print(simRouter.queueAttacker) | |
print(simRouter.sendClient) | |
print(simRouter.sendNServer) | |
print(simRouter.sendMServer) | |
print(simRouter.sendAttacker) | |
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("NAT Device, Queue, Send Client, Send Router") | |
print(simNat.queueRouter) | |
print(simNat.queueClient) | |
print(simNat.sendClient) | |
print(simNat.sendRouter) | |
print("CONNECTIONS") | |
print("Connection: connectionAttackerMServer" | |
+ str(connectionAttackerMServer.packetsInTransit)) | |
print("Connection: connectionRouterMServer" | |
+ str(connectionRouterMServer.packetsInTransit)) | |
print("Connection: connectionRouterNServer" | |
+ str(connectionRouterNServer.packetsInTransit)) | |
print("Connection: connectionNatRouter" | |
+ str(connectionNatRouter.packetsInTransit)) | |
print("Connection: connectionRouterNat" | |
+ str(connectionRouterNat.packetsInTransit)) | |
print("Connection: connectionClientNat" | |
+ str(connectionClientNat.packetsInTransit)) | |
print("Connection: connectionNatClient" | |
+ str(connectionNatClient.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("-------------------------------------------------------------------") | |
input() | |
fileGen.outputFile() | |
# Return value will be the animateInstructions | |
response = fileGen.instructions if hasattr(fileGen, 'instructions') else [] | |
response.append(str(sessionGuid)) | |
return response |