Last active
December 12, 2019 12:03
-
-
Save ryankshah/c53d967522aa91565e4219671734136d to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
from mininet.topo import Topo | |
from mininet.net import Mininet | |
from mininet.util import dumpNodeConnections, pmonitor | |
from mininet.log import setLogLevel | |
from mininet.node import RemoteController, OVSSwitch | |
#from mininet.node import OVSController | |
from signal import SIGINT | |
import math | |
import random | |
import time | |
def runExperiment( | |
policy, | |
port, | |
device_id, | |
level, | |
): | |
'''Run experiments with n clients and m servers''' | |
topo = NetworkTopology() | |
net = Mininet(topo) | |
net.start() | |
# Get hosts | |
hosts = net.hosts | |
# Separate hosts into clients and servers | |
clients = [] | |
servers = {} | |
i = 0 | |
for host in hosts: | |
# If its a server add to server list | |
# else add to client list | |
if 'server' in host.name: | |
servers[host] = str(int(port)+i) | |
i += 1 | |
else: | |
clients.append(host) | |
popens = {} | |
for server in servers: | |
popens[server] = \ | |
server.popen('java -jar server_with_conflict_sizes.jar ' + port + ' ' + policy + ' 1') | |
time.sleep(30) # Wait 30 seconds for servers to start | |
for client in clients: | |
# Get random server from servers list | |
server = random.choice(servers.items()) | |
popens[client] = \ | |
client.popen('java -jar client.jar ' | |
+ str(server[0].IP()) + ' ' + server[1] + ' report ' | |
+ device_id + ' ' + level) | |
endTime = time.time() + 60 # Run for 60 seconds | |
for (h, line) in pmonitor(popens, timeoutms=500): | |
if h: | |
with open('read_auth_time_conflict_size_50.txt', 'a') as myfile: | |
myfile.write(line) | |
if time.time() >= endTime: | |
for p in popens.values(): | |
p.send_signal(SIGINT) | |
net.stop() | |
# network with n hosts connected to one switch | |
class NetworkTopology(Topo): | |
clients = 10 | |
servers = 2 | |
def __init__(self): | |
# Initialize topology | |
Topo.__init__(self) | |
def build(self, k=(clients+servers)): | |
switch = self.addSwitch('s1') | |
for s in range(self.servers): | |
server = self.addHost('server%s' % (s + 1)) | |
self.addLink(server, switch) | |
for c in range(self.clients): | |
client = self.addHost('client%s' % (c + 1)) | |
self.addLink(client, switch) | |
topos = {'mytopo': lambda : NetworkTopology()} | |
if __name__ == '__main__': | |
setLogLevel('debug') | |
policy = 'RBIBA_BLP_CWall' | |
port = '4850' | |
id5_1 = 'ef4c2d86-e423-49ac-849b-e58deb971868' | |
id10_1 = 'fb4238a8-3515-47f0-a95b-a8e7e7a2c3d8' | |
id15_1 = 'fe2c351b-15a3-4613-a66f-12c8bb7e5ec2' | |
id20_1 = 'fd0426a9-1e23-45df-98ed-637c460fd004' | |
id25_1 = 'fd264f33-1f2b-441f-b8a5-f94ff93c0116' | |
id30_1 = 'fb6a8fd8-5d89-467c-9766-88a119cf2c57' | |
id35_1 = 'ffb9c884-3332-46b3-b16a-d57bcd82a0c9' | |
id40_1 = 'fd9c62c1-a7a0-4655-bc9d-509a0c151098' | |
id45_1 = 'ff9ede72-c592-4f40-9cc0-d60e9a1f8e4c' | |
id50_1 = 'ffe6019c-e6c5-48ca-84d2-a9d1b62733ad' | |
id5_2 = 'fbe718c7-8507-4930-a341-115158a2220c' | |
id10_2 = 'ff012eb7-04e7-458f-8110-b4e1da25ffa4' | |
id15_2 = 'fdd75380-8fa9-43b8-82d7-79e0a14f33ba' | |
id20_2 = 'f5808bc5-9b55-4380-9637-04bcb0e83a05' | |
id25_2 = 'f88acd2b-b442-4bc8-9e83-c8ccf7b645a1' | |
id30_2 = 'fbaa3e76-dd1f-4074-bdda-ac17dce24491' | |
id35_2 = 'ff7f1e10-94d2-464c-8427-ee8a5cc5829e' | |
id40_2 = 'ff515367-2bd5-46cc-9dca-8a3d9e855688' | |
id45_2 = 'fe7a3936-5e27-4223-8c10-dfa134bf4eca' | |
id50_2 = 'ff6dd701-fa3d-4683-beb3-3e8b4c617d39' | |
id5_4 = 'f743f8dc-5ab1-4093-9916-f255f6421045' | |
id10_4 = 'ffd40ea8-2ffc-415b-9be8-c5ef9d44b0ea' | |
id15_4 = 'e9d91967-9aa6-48ea-aa0f-46df0a4c0747' | |
id20_4 = 'f4880680-2d18-4021-a4c6-10ea8f439469' | |
id25_4 = 'f610665e-15cf-4d85-9677-d03ebc53b328' | |
id30_4 = 'e9c6c151-3794-4aaa-9ee2-9e8872bea580' | |
id35_4 = 'ff33feff-f6a5-4466-b475-e7d0193ef277' | |
id40_4 = 'e6a5026f-4586-409d-9c63-35411a789220' | |
id45_4 = 'faf30f13-2d92-4d02-ad68-51352a1f8067' | |
id50_4 = 'ffd91199-ff72-48f8-8c65-f6023166dd21' | |
id5_8 = 'f1d5dbbe-bca4-4505-a8c7-0e93f33a59a0' | |
id10_8 = 'e6381558-371a-46e7-ad17-faa98e28b860' | |
id15_8 = 'cb9b4c82-28af-48cf-afb3-9dbf32222528' | |
id20_8 = '93e7af7c-6075-464b-9e9f-9265dc1fd8a6' | |
id25_8 = 'fbec5bdc-06b7-4c63-aaee-62845aced8ac' | |
id30_8 = 'f51b7ec4-24e8-4b9c-8525-0175cbe009ce' | |
id35_8 = 'a3c5f699-8bd7-4d1e-a56c-947342062e80' | |
id40_8 = 'e833e5cb-23bb-493c-a3a1-6ecf8865643a' | |
id45_8 = '8f895c8b-8d87-42d4-b7d5-6490f036d6af' | |
id50_8 = '0050e126-8bad-41f6-8f9a-769849d720b7' | |
conflict_size_1 = '0a4e4e3e-f5cc-45a2-b873-be3106817806' | |
conflict_size_2 = '0a5ee0be-0760-487b-886e-5e3e6897f1f5' | |
conflict_size_5 = '0a05bdbf-9af0-4f79-be0a-1f6a1cdf3daa' | |
conflict_size_10 = '0a33dca3-cba9-49d6-bcb8-ec242690aef3' | |
conflict_size_25 = '0a054da9-fcb8-4a7d-aac0-c20926130305' | |
conflict_size_50 = '0a99ee8e-e407-4e56-a63c-0c411d371a04' | |
level = '45' | |
runExperiment(policy, port, conflict_size_50, level) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment