def __init__(self, mode="emu", remote_base_url=""): """Init HAEC emulator :param remote_base_url: Base URL of the remote frontend """ self._load_config() self._remote_base_url = remote_base_url if mode not in EMU_MODES: logger.error("Invalid emulator mode.") self.cleanup() self._mode = mode # A cluster can run one Experiment at a time. Several experiment can be # run sequentially without destroy/recreating the cluster class self._default_cluster = maxinet.Cluster() # Current running self._cur_cluster = None self._cur_exp = None self._cur_topo = None self._exp_q = list() # A queue of experiments. logger.debug("API URLs: {}".format(",".join( [self._url_create_flow, self._url_push_processor_info]))) self._worker_procs = [] self._mon_proc_proc = multiprocessing.Process( name="processor monitor", target=self._monitor_processor) self._worker_procs.append(self._mon_proc_proc)
def _create_cluster(cluster): name = cluster['name'] minWorkers = cluster['minWorkers'] maxWorkers = cluster['maxWorkers'] logger.debug("creating cluster with minWorkers={}, maxWorkers={}".format( minWorkers, maxWorkers)) c = maxinet.Cluster(minWorkers=minWorkers, maxWorkers=maxWorkers) clusters[name] = c return name
def main(): # Dict for static mapping for i in range(3): for j in range(3): for k in range(3): pass # mapping = {"h1111": 0, # "h2": 0, # "h3": 1, # "h4": 1, # "s1": 0, # "s2": 0, # "s3": 1, # "s4": 1, # "s5": 0, # "s6": 1, # "s7": 1 # } # Create cluster and topology cluster = maxinet.Cluster() topo = MultilayerGrid() exp = maxinet.Experiment(cluster, topo) # exp = maxinet.Experiment(cluster, topo, nodemapping=mapping) exp.setup() if len(sys.argv) > 1: if sys.argv[1] == '-d': # Into the CLI mode, for debugging exp.CLI(locals(), globals()) exp.stop() # Start Iperf script on all hosts. else: time.sleep(1) # Loop over all hosts for i in range(3): for j in range(3): for k in range(3): hname = 'h%d%d%d' % (i + 1, j + 1, k + 1) # Run go script at background exp.get_node(hname).cmd( "~/bin/iperf-server-client-demo-pc -min 30 -max 40 &") # Enter infinite loop try: while 1: time.sleep(10) except KeyboardInterrupt: print('KeyboardInterrupt detected!') exp.stop()
def setupNetwork(hps, sw_ip_fname): topo = GeneratedTopo(hps=hps, sw_ip_fname=sw_ip_fname) print('*** Setup Maxinet Cluster') cluster = maxinet.Cluster() exp = maxinet.Experiment(cluster, topo, switch=OVSSwitch) exp.setup() print('*** Done setup Maxinet Cluster') return exp
def hello_world(): topo = Topo() topo.addHost("h1", cls=Docker, ip="10.0.0.251", dimage="ubuntu:trusty") topo.addHost("h2", cls=Docker, ip="10.0.0.252", dimage="ubuntu:trusty") topo.addSwitch("s1", dpid=Tools.makeDPID(1)) topo.addLink("h1", "s1") topo.addLink("h2", "s1") # start cluster cluster = maxinet.Cluster(minWorkers=1, maxWorkers=2) # start experiment with OVSSwitch on cluster exp = maxinet.Experiment(cluster, topo, switch=OVSSwitch) exp.setup() return 'Welcome to our Library!'
#!/usr/bin/python2 # # Minimal example showing how to use MaxiNet # import time from MaxiNet.Frontend import maxinet from MaxiNet.tools import FatTree from mininet.node import OVSSwitch topo = FatTree(30, 10, 0.1) cluster = maxinet.Cluster(minWorkers=7, maxWorkers=7) exp = maxinet.Experiment(cluster, topo, switch=OVSSwitch) exp.setup() print exp.get_node("h1").cmd("ifconfig") # call mininet cmd function of h1 print exp.get_node("h30").cmd("ifconfig") print "waiting 5 seconds for routing algorithms on the controller to converge" time.sleep(5) print exp.get_node("h30").cmd("ping -c 100 10.0.0.1") exp.stop()
#!/usr/bin/python2 # # This example shows how to use MaxiNet's CommandLineInterface (CLI). # Using the CLI, commands can be run interactively at emulated hosts. # Thanks to our build-in py command you can dynamically change the # topology. # from MaxiNet.Frontend import maxinet from MaxiNet.tools import FatTree topo = FatTree(4, 10, 0.1) cluster = maxinet.Cluster() exp = maxinet.Experiment(cluster, topo) exp.setup() exp.CLI(locals(), globals()) exp.stop()
from mininet.topo import Topo from mininet.node import OVSSwitch from MaxiNet.Frontend.container import Docker from MaxiNet.Frontend import maxinet from MaxiNet.tools import Tools topo = Topo() topo.addHost("h1", cls=Docker, ip="10.0.0.251", dimage="ubuntu:trusty") topo.addHost("h2", cls=Docker, ip="10.0.0.252", dimage="ubuntu:trusty") topo.addSwitch("s5", dpid=Tools.makeDPID(5)) ## set datapath id topo.addLink("h1", "s5") topo.addLink("h2", "s5") cluster = maxinet.Cluster(minWorkers=1, maxWorkers=2) # start experiment with OVSSwitch on cluster exp = maxinet.Experiment(cluster, topo, switch=OVSSwitch) exp.setup() exp.get_node("h1").cmd("ping -c 1 10.0.0.252") exp.get_node("h2").cmd("ping -c 1 10.0.0.251")
def main(): # app.exe > ../logs/save_to.log 2>&1 & cluster = maxinet.Cluster() mn = maxinet.Experiment(cluster, Topology(), switch=OVSSwitch, nodemapping=mapping, controller='10.0.0.4') mn.setup() auth = mn.get('auth') s1 = mn.get('s1') scada = mn.get('scada') evs = [] for h in mn.hosts: if 'ev' in h.name: evs.append(h) for sw in mn.switches: sw.cmd('rm -rf /var/run/wpa_supplicant') sw.cmd('rm -rf /home/arthurazs/git/3AS/logs/s*.log') sw.cmd('rm -rf /home/arthurazs/git/3AS/logs/auth') sw.cmd('rm -rf /home/arthurazs/git/3AS/logs/mms') sw.cmd('rm -rf /home/arthurazs/git/3AS/logs/pcap') logger.info("*** Disabling hosts ipv6\n") for h in mn.hosts: h.cmd("sysctl -w net.ipv6.conf.all.disable_ipv6=1") h.cmd("sysctl -w net.ipv6.conf.default.disable_ipv6=1") h.cmd("sysctl -w net.ipv6.conf.lo.disable_ipv6=1") if h.MAC() == scada.MAC(): for ev in evs: h.setARP(ev.IP(), ev.MAC()) else: h.setARP(scada.IP(), scada.MAC()) logger.info("*** Disabling switches ipv6\n") for sw in mn.switches: sw.cmd("sysctl -w net.ipv6.conf.all.disable_ipv6=1") sw.cmd("sysctl -w net.ipv6.conf.default.disable_ipv6=1") sw.cmd("sysctl -w net.ipv6.conf.lo.disable_ipv6=1") logger.info("*** Setting ARP tables\n") scada.setARP('10.0.1.1', '00:00:00:00:00:01') for ev in evs: ev.setARP('10.0.1.1', '00:00:00:00:00:01') logger.info("*** Creating log folders\n") for sw in mn.switches: sw.cmd('mkdir -p ' + PCAP_LOGS) sw.cmd('mkdir -p ' + AUTH_LOGS) sw.cmd('mkdir -p ' + MMS_LOGS) logger.info("*** Setting up traffic dumpers\n") pcap(s1, name='openflow', intf='lo', port='1812 and port not 53') pcap(auth, name='freeradius', intf='lo') pcap(auth, name='sdn-hostapd') pcap(scada) logger.info("*** Configuring bridge between 'auth' and 'controller'\n") s1.cmd('ifconfig s1 10.0.1.1 netmask 255.255.0.0') s1.cmd('ovs-vsctl set bridge s1 other-config:hwaddr=00:00:00:00:00:01') s1.setARP('10.0.1.2', '00:00:00:00:00:02') s1.setARP('10.0.1.3', '00:00:00:00:00:03') for ev in evs: s1.setARP(ev.IP(), ev.MAC()) auth.setARP('10.0.1.1', '00:00:00:00:00:01') pcap(s1, name='controller', intf='s1', port='53') logger.info("*** Starting RADIUS (freeradius) \n") logger.info("*** Starting Authenticator (hostapd)\n") freeradius(auth) hostapd(auth) logger.info("*** Starting SCADA\n") scada.cmd('screen -L -Logfile', MMS_LOGS + 'scada.log', '-S scada -dm python3 ' + IEDS_ROOT + 'scada.py') logger.info("*** Starting EVs\n") sleep(1, 'Starting EVs') for ev in evs: wpa(ev) sleep(1, 'Experiment') for ev in evs: wpa_cli(ev, 'ev.sh', ev.name) logger.info("*** Running experiment\n") sleep(5, 'Experiment') logger.info("*** Finishing experiment\n") for sw in mn.switches: sw.cmd('screen -S scada -X quit') sw.cmd("kill -2 $(ps aux | grep '[w]ired' | awk '{print $2}')") sw.cmd('pkill -2 hostapd') sw.cmd('pkill -2 freeradius') sw.cmd('pkill -2 server_ied') sw.cmd('ovs-ofctl dump-flows ' + sw.name + ' > ' + LOGS + sw.name + '.log') sw.cmd('chmod +r ' + AUTH_LOGS + 'freeradius.log') sw.cmd('pkill -2 tcpdump') sleep(5, 'Experiment') mn.stop()
def topology(self, clusterNodesLength): print('\nCreating Mininet network...\n') topo = Topo() cluster = maxinet.Cluster(minWorkers=1, maxWorkers=clusterNodesLength) self.exp = maxinet.Experiment(cluster, topo, switch=OVSSwitch) self.exp.setup()