示例#1
0
def main():
    g = read_topology()
    switch_data = switch_data_generator(g)
    topo = create_network(switch_data)

    mininet_controller = Ryu('ruy_controller', 'RuyController.py')
    switch = partial(OVSSwitch, protocols='OpenFlow13')
    net = Mininet(topo=topo,
                  switch=switch,
                  build=True,
                  controller=mininet_controller)
    net.staticArp()
    config_file_path = 'config'
    pickle.dump(switch_data, open(config_file_path, 'w'))
    net.start()
    sleep(1.5)
    host = net.hosts[0]
    latency = defaultdict(dict)
    x = []
    y = []
    for dst in net.hosts:
        if dst != host:
            s = host.cmd('ping -c 1 %s' % dst.IP())
            time = s.split()[13].split('=')[1]
            start = host.name[2:]
            end = dst.name[2:]
            x.append(end)
            y.append(time)
            latency[start][end] = time
            print(start + ' -> ' + end + ' time : ' + time + ' ms')
    net.stop()

    data = [go.Bar(x=x, y=y)]

    py.offline.plot(data, filename='basic-bar.html')
示例#2
0
    def create_network(self):
        """
        Create topology, Ryu controller and build the network
        """

        # Cleanup old sessions before build a new one
        cleanup()

        # Create Topology
        topo = create_topology()

        # Set switch to use OpenFlow13
        OVSSwitch13 = partial(OVSSwitch, protocols='OpenFlow13')

        # Create Ryu Controller
        ryu = Ryu('ryu', RYU_APP_PATH, port=RYU_PORT)

        # Create Mininet
        net = Mininet(
            topo=topo,
            switch=OVSSwitch13,
            controller=ryu,
            autoSetMacs=True
        )

        return net
示例#3
0
def mwc():
    "Create network and run simple performance test"
    topo = SingleSwitchTopo(n=6)
    #
    # ryu=Ryu("simple","--observe-links /usr/local/lib/python2.7/dist-packages/ryu/app/gui_topology/gui_topology.py","/usr/local/lib/python2.7/dist-packages/ryu/app/simple_switch_websocket_13.py")

    ryu = Ryu("simple",
              "/usr/local/lib/python2.7/dist-packages/ryu/app/ofctl_rest.py")
    switch = partial(OVSSwitch, protocols='OpenFlow10,OpenFlow12,OpenFlow13')
    net = Mininet(topo=topo, link=TCLink, controller=ryu, switch=switch)
    net.start()
    # print "Dumping host connections"
    # dumpNodeConnections(net.hosts)
    # print "Testing network connectivity"
    # net.pingAll()
    # print "Testing bandwidth between h1 and h4"
    # h1, h4 = net.get('h1', 'h4')
    # net.iperf((h1, h4))
    print "start cdn"
    cdn = net.get('cdn')
    whilecdn = cdn.cmd(
        'while true; do  dd if=/dev/zero  count=$((1024+$RANDOM)) bs=1024 |nc -l 8080 ; done &'
    )

    # print "start vcdn"
    # vcdn = net.get('vcdn')
    # whilevcdn =vcdn.cmd('while true; do  dd if=/dev/zero  count=$((1024+$RANDOM)) bs=1024 |nc -l 8080 ; done &')

    hosts = net.hosts

    whileh = {}
    for h in hosts:
        if not (h.name in ("vcdn", "cdn")):
            print "start " + h.name
            whileh[h] = h.cmd(
                'while true; do curl http://' + cdn.IP() +
                ':8080/ >/dev/null 2>/dev/null && sleep 1  ; done &')

    # print "start ryu<ENTER>"
    # raw_input()
    # net.addController('rmController', controller=RemoteController, ip='127.0.0.1', port=6633)

    # sleep(10)
    CLI(net)
    # vcdn.cmd('kill %while')
    # cdn.cmd('kill %while')
    for h in hosts:
        h.cmd('kill %while')

    net.stop()
示例#4
0
    def run(self):

        log = self.__logger.get()

        controller_log_file = os.path.join(
            self.__logger.make_log_file_directory_path(), "controller.txt")

        controller_name = "ryu_" + self.__run_name
        controller_path_relative = "controllers/"
        if self.__run_name == "demo":
            controller_source_file_name = "Demo_SimpleSwitch.py"
        elif self.__run_name == "hub":
            controller_source_file_name = "DumbHub.py"
        elif self.__run_name == "switch":
            controller_source_file_name = "SimpleSwitch.py"
        elif self.__run_name == "qswitch":
            controller_source_file_name = "QSwitch.py"
        else:
            raise Exception("Invalid run name: " + str(self.__run_name))
        controller_path_relative += controller_source_file_name

        # Instantiate Mininet::Ryu(), which just launches ryu-manager for us
        controller = Ryu(
            controller_name,
            controller_path_relative,
            # "--verbose",
            "--log-file",
            controller_log_file)

        self.__logger.heading("Running with controller: " +
                              controller_source_file_name)

        log.info("Instantiating custom Topology class")
        self.__topo = Topology(self.__logger)
        log.info("Rendering graph of current topology")
        self.__topo.render_dotgraph()

        self.run_with_controller(controller)

        #
        log.info("Done")
示例#5
0
    def start_mininet(self, topo_file):

        topo_file = os.path.abspath("topologies/" + topo_file)

        chirouter_host, chirouter_port = "localhost", self.port

        command = "PYTHONPATH=src/python/ ryu-manager"

        params = ["chirouter.controller"]
        params += ["--user-flags src/python/chirouter/ryu_flags.py"]
        params += ["--chirouter-topology-file=" + topo_file]
        params += ["--chirouter-host=" + chirouter_host]
        params += ["--chirouter-port=" + str(chirouter_port)]

        controller = Ryu("c0", command=command, ryuArgs=params)

        self.mininet = simulator.run(topo_file=topo_file,
                                     controller=controller,
                                     run_cli=False)

        self.mininet_started = True
示例#6
0
 def __init__(self, port=6653):
     print("Creat")
     args = '--observe-links '
     app = 'ryu.app.ryu_anon ryu.app.gui_topology.gui_topology'
     ryu_args = args + ' ' + app
     Ryu.__init__(self, 'ryu', ryu_args, port=port)
示例#7
0
	def __init__(self, name, path=None, **kwargs):
		Ryu.__init__(self, name, path, **kwargs)
		self.popenTerms = []
示例#8
0
 def controller(self, name, **params):
     return Ryu(name, *self.ryuParams, **params)
示例#9
0
try:
    hosts = {}
    for h in host_config['vhosts']:
        host_ip = h['ip'] + '/24'
        host_mac = h['mac']
        host_name = h['name']
        hosts[host_name] = net.addHost(host_name, ip=host_ip, mac=host_mac)
    controllers = {}
    controllers_to_add = list()
    for c in host_config['controllers']:
        controller_ip = c['ip']
        controller_port = c['port']
        controller_name = c['name']
        print 'Creating controller:', controller_name
        if controller_ip == 'None':
            c0 = Ryu(controller_name, port=controller_port)
            controllers_to_add.append(c0)
        else:
            c0 = RemoteController(controller_name,
                                  ip=controller_ip,
                                  port=controller_port)
        controllers[controller_name] = c0
    devices = host_config['phys']
    for task in sorted(host_config['pre-scripts'], key=lambda x: x['prio']):
        if task['type'] == 'device':
            devices.append(task)
        print "Running pre-script", task['cmdline'].format(**task)
        if isinstance(task['vhost'], dict):
            host = hosts[task['vhost']['name']]
            host.cmd(task['cmdline'].format(**task))
        else:
示例#10
0
def simpleTest():
    topo = MyTopod()
    path = "/home/shengliu/Workspace/mininet/custom/controllerConfig.txt"
    out_file = '/home/shengliu/Workspace/mininet/custom/dataResult.txt'
    for file in glob.glob("/home/shengliu/Workspace/mininet/custom/data1/*.txt"):
        with open(file) as fi:
            lines = fi.readlines()
            with open(path, 'w') as fo:
                fo.writelines(lines)

            net = Mininet( topo=topo, switch=OVSKernelSwitch, controller=Ryu('ryuController','/home/shengliu/Workspace/ryu/ryuApp/dummyRouter.py') )


            #c1 = net.addController('c1', controller=RemoteController, ip="127.0.0.1", port=6633)
            net.start()

            s1 = net.get('s1')
            s2 = net.get('s2')
            h1 = net.get('h1')
            h2 = net.get('h2')
            h3 = net.get('h3')
            h4 = net.get('h4')
            h5 = net.get('h5')
            h6 = net.get('h6')
            h7 = net.get('h7')
            h8 = net.get('h8')
            #s1 = net.hosts[9]
            #print "success!"
            am = 10
            #path = "/home/shengliu/Workspace/sdnsim/data1/8_12para1_50.txt"
            rdret = readFile(path, 8, 12)
            attackFlow = rdret['attackFlow']
            flowInterest = rdret['flowInterest']
            #for i in range(0, 10):
            #	CLI(net)
            #	print s1.cmd('ovs-ofctl -O openflow13 dump-flows s1')
            sumA = 0
            sumN = 0

            for ct in range(1, 100):

                for i in range(1, 9):
                    h10 = net.get('h%d' % i)
                    h10.cmd('python poissonProcess.py %d &' % i )


                sleep (1.5*am)

                ht = net.get('h%d' % flowInterest)
                is_shown = ht.cmd('echo')
               # print len(is_shown)
                is_shown = is_shown.strip().split('\n')
                #print is_shown
		is_shown = is_shown[1]
                is_shown = int(is_shown)
                print is_shown
                ha = net.get('h%d' % flowInterest)

        #result = ha.cmd('echo') #clean the output of & command
                ha.cmd('echo')
                result = ha.cmd('ping 10.0.1.8 -c1')
                print result
		#print len(result)
                result = result.strip().split('\n')
                if len(result) == 6:
			rtt = result[5].strip().split()
		else:
			rtt = result[7].strip().split()
                rtt = rtt[3].split('/')
        #print rtt[0]

                if float(rtt[0]) > 2.0:
                    attackResult = 0
                else:
                    attackResult = 1

        #print attackResult
        #print is_shown
                if is_shown == attackResult:
                    sumN = sumN + 1
            #print "attack succeed"
        #else:
            #print "attack failed"
                sleep (2 * am)


                for i in range(1, 9):
                    h10 = net.get('h%d' % i)
                    h10.cmd('python poissonProcess.py %d &' % i )

                sleep (1.5*am)

                ht = net.get('h%d' % flowInterest)
                is_shown = ht.cmd('echo')
                #print len(is_shown)
		is_shown = is_shown.strip().split('\n')
                #print is_shown
		is_shown = is_shown[1]
                is_shown = int(is_shown)
                print is_shown
                ha = net.get('h%d' % attackFlow)

                ha.cmd('echo')
                result = ha.cmd('ping 10.0.1.8 -c1')
                print result
		#print len(result)
                result = result.strip().split('\n')
                #print result
		if len(result) == 6:		
			rtt = result[5].strip().split()
		else:
			rtt = result[7].strip().split()
                rtt = rtt[3].split('/')

                if float(rtt[0]) > 2.0:
                    attackResult = 0
                else:
                    attackResult = 1

                if is_shown == attackResult:
                    sumA = sumA + 1

                sleep (2 * am)
                print ct


        #print sumA
        #print sumN
        with open(out_file, 'a') as fResult:
            fResult.write('%s,%d,%d\n' % (file[46:len(file)], sumA, sumN))

        print file
        #CLI(net)
        net.stop()
示例#11
0
 def __init__(self, port=6633, rest_port=8080):
     args = '--observe-links'
     apps = 'ryu.app.simple_switch_13 ryu.app.gui_topology.gui_topology'
     ryu_args = args + ' ' + apps
     Ryu.__init__(self, 'ryu', ryu_args, port=port)
     self.url = 'http://localhost:%d' % rest_port