Exemple #1
0
def myNet():
    "Create network from scratch using Open vSwitch."
 
    info( "*** Creating nodes\n" )
    switch0 = Node( 's0', inNamespace=False )
 
    h0 = Node( 'h0' )
    h1 = Node( 'h1' )
    h2 = Node( 'h2' )
 
    info( "*** Creating links\n" )
    Link( h0, switch0)
    Link( h1, switch0)
    Link( h2, switch0)
 
    info( "*** Configuring hosts\n" )
    h0.setIP( '192.168.123.1/24' )
    h1.setIP( '192.168.123.2/24' )
    h2.setIP( '192.168.123.3/24' )
       
    info( "*** Starting network using Open vSwitch\n" )
    switch0.cmd( 'ovs-vsctl del-br dp0' )
    switch0.cmd( 'ovs-vsctl add-br dp0' )
 
    for intf in switch0.intfs.values():
        print intf
        print switch0.cmd( 'ovs-vsctl add-port dp0 %s' % intf )
 
    # Note: controller and switch are in root namespace, and we
    # can connect via loopback interface
    #switch0.cmd( 'ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633' )
  
    print switch0.cmd(r'ovs-vsctl show')
 
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=1,in_port=1,actions=flood' ) 
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=1,in_port=2,actions=flood' )
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=1,in_port=3,actions=flood' )
  
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.1,actions=output:1' ) 
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.2,actions=output:2' ) 
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.3,actions=output:3')
 
    #switch0.cmd('tcpdump -i s0-eth0 -U -w aaa &')
    #h0.cmd('tcpdump -i h0-eth0 -U -w aaa &')
    info( "*** Running test\n" )
    h0.cmdPrint( 'ping -c 3 ' + h1.IP() )
    h0.cmdPrint( 'ping -c 3 ' + h2.IP() )
 
    #print switch0.cmd( 'ovs-ofctl show dp0' )    
    #print switch0.cmd( 'ovs-ofctl dump-tables  dp0' )
    #print switch0.cmd( 'ovs-ofctl dump-ports   dp0' )
    #print switch0.cmd( 'ovs-ofctl dump-flows  dp0' )
    #print switch0.cmd( 'ovs-ofctl dump-aggregate  dp0' )
    #print switch0.cmd( 'ovs-ofctl queue-stats dp0' )
 
    info( "*** Stopping network\n" )
    switch0.cmd( 'ovs-vsctl del-br dp0' )
    switch0.deleteIntfs()
    info( '\n' )
def myNet(cname='controller', cargs='-v ptcp:'):
    "create network from scratch using Open vSwitch."
    info("*** Createing nodes\n")
    controller=Node('c0',inNamespace=False)
    switch=Node('s1',inNamespace=False)
    switch1=Node('s1',inNamespace=False)
    h0=Node('h0')
    h1=Node('h1')
    
    
def scratchNet(cname='controller', cargs='-v ptcp:'):
    "Create network from scratch using Open vSwitch."

    info("*** Creating nodes\n")
    controller = Node('c0', inNamespace=False)
    switch = Node('s0', inNamespace=False)
    h0 = Node('h0')
    h1 = Node('h1')

    info("*** Creating links\n")
    Link(h0, switch)
    Link(h1, switch)

    info("*** Configuring hosts\n")
    h0.setIP('192.168.123.1/24')
    h1.setIP('192.168.123.2/24')
    info(str(h0) + '\n')
    info(str(h1) + '\n')

    info("*** Starting network using Open vSwitch\n")
    controller.cmd(cname + ' ' + cargs + '&')
    switch.cmd('ovs-vsctl del-br dp0')
    switch.cmd(
        'ovs-vsctl add-br dp0 other-config:datapath-id={}'.format(datapath_id))
    for intf in switch.intfs.values():
        print switch.cmd('ovs-vsctl add-port dp0 %s' % intf)

    # Note: controller and switch are in root namespace, and we
    # can connect via loopback interface
    s_cmd = 'ovs-vsctl set-controller dp0 tcp:[{}]:{}'.format(
        CTLR_IP, CTLR_PRT)
    print s_cmd
    switch.cmd(s_cmd)
    ping_results = [
        'received,host,jitter,packet_loss,avgping,minping,time,sent,maxping\n'
    ]
    try:
        h0.cmd('echo "" > pings.txt')
        if mode == 0:
            step_wise_testing(h0, h1, ping_results)
        else:
            continuous_testing(h0, h1, ping_results)
    except KeyboardInterrupt:
        print "Warning: Caught KeyboardInterrupt, stopping network"
        tm_local = time.localtime()
        dt = time.gmtime()
        file_name = 'pings_{}_{}_{}-{}_{}_{}.csv'.format(
            dt.tm_year, dt.tm_mon, dt.tm_mday, tm_local.tm_hour,
            tm_local.tm_min, tm_local.tm_sec)
        f = open(file_name, 'w+')
        for item in ping_results:
            f.write(item)
        stop_net(controller, cname, switch)
Exemple #4
0
    def __init__(self, numEdgeSwitches=4):

        super(FattreeTopology, self).__init__()

        # add switches
        numHosts = 4 * numEdgeSwitches
        numCoreSwitches = 2
        hosts = range(1, numHosts + 1)
        firstSwitch = max(101, numHosts + 1)
        edgeSwitches = range(firstSwitch, numEdgeSwitches + firstSwitch)
        self.edgeSwitches = edgeSwitches
        coreSwitches = range(numEdgeSwitches + firstSwitch,
                             numEdgeSwitches + firstSwitch + numCoreSwitches)
        self.coreSwitches = coreSwitches

        # Add switches
        for s in edgeSwitches:
            self.add_node(s, Node(is_switch=True))

        for s in coreSwitches:
            self.add_node(s, Node(is_switch=True))

        # Add hosts
        for h in hosts:
            self.add_node(h, Node(is_switch=False))

        # Add links
        for h in hosts:
            if h <= 4:
                self.add_edge(h, firstSwitch)
            elif h <= 8:
                self.add_edge(h, firstSwitch + 1)
            elif h <= 12:
                self.add_edge(h, firstSwitch + 2)
            else:
                self.add_edge(h, firstSwitch + 3)

        # Add monitoring host
        # self.add_node(99, Node(is_switch=False))

        for s1 in edgeSwitches:
            if (s1 - firstSwitch) < numEdgeSwitches / 2:
                self.add_edge(s1, coreSwitches[0])
            else:
                self.add_edge(s1, coreSwitches[1])
            # connect monitor to every edge switch
            # self.add_edge(99, s1)

        self.add_edge(coreSwitches[0], coreSwitches[1])

        self.enable_all()
Exemple #5
0
def scratchNet(cname='controller', cargs='-v ptcp:'):
    "Create network from scratch using Open vSwitch."

    info("*** Creating nodes\n")
    controller = Node('c0', inNamespace=False)
    switch = Node('s0', inNamespace=False)
    h0 = Node('h0')
    h1 = Node('h1')

    info("*** Creating links\n")
    Link(h0, switch)
    Link(h1, switch)

    info("*** Configuring hosts\n")
    h0.setIP('192.168.123.1/24')
    h1.setIP('192.168.123.2/24')
    info(str(h0) + '\n')
    info(str(h1) + '\n')

    info("*** Starting network using Open vSwitch\n")
    controller.cmd(cname + ' ' + cargs + '&')
    switch.cmd('ovs-vsctl del-br dp0')
    switch.cmd('ovs-vsctl add-br dp0')
    for intf in switch.intfs.values():
        print switch.cmd('ovs-vsctl add-port dp0 %s' % intf)

    # Note: controller and switch are in root namespace, and we
    # can connect via loopback interface
    s_cmd = 'ovs-vsctl set-controller dp0 tcp:[{}]:{}'.format(
        CTLR_IP, CTLR_PRT)
    print s_cmd
    switch.cmd(s_cmd)

    info('*** Waiting for switch to connect to controller')
    try:
        while 'is_connected' not in quietRun('ovs-vsctl show'):
            sleep(1)
            info('.')

        info('\n')

        while True:
            info("*** Running test\n")
            h0.cmdPrint('ping -c1 ' + h1.IP())
            info("*** Sleep\n")
            sleep(2)
    except KeyboardInterrupt:
        print "Warning: Caught KeyboardInterrupt, stopping network"
        stop_net(controller, cname, switch)
Exemple #6
0
def scratchNet(cname='controller', cargs='-v ptcp:'):
    "Create network from scratch using Open vSwitch."

    info("*** Creating nodes\n")
    controller = Node('c0', inNamespace=False)
    switch0 = Node('s0', inNamespace=False)
    h0 = Node('h0')
    h1 = Node('h1')

    info("*** Creating links\n")
    Link(h0, switch0)
    Link(h1, switch0)

    info("*** Configuring hosts\n")
    h0.setIP('192.168.123.1/24')
    h1.setIP('192.168.123.2/24')
    info(str(h0) + '\n')
    info(str(h1) + '\n')

    info("*** Starting network using Open vSwitch\n")
    controller.cmd(cname + ' ' + cargs + '&')
    switch0.cmd('ovs-vsctl del-br dp0')
    switch0.cmd('ovs-vsctl add-br dp0')

    for intf in switch0.intfs.values():
        print intf
        print switch0.cmd('ovs-vsctl add-port dp0 %s' % intf)

    # Note: controller and switch are in root namespace, and we
    # can connect via loopback interface
    switch0.cmd('ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633')
    switch0.cmd('ovs-ofctl add-flow dp0 \"in_port=1 actions=output:2\"')
    switch0.cmd('ovs-ofctl add-flow dp0 \"in_port=2 actions=output:1\"')

    info('*** Waiting for switch to connect to controller')
    while 'is_connected' not in quietRun('ovs-vsctl show'):
        sleep(1)
        info('.')
    info('\n')

    info("*** Running test\n")
    h0.cmdPrint('ping -c3 ' + h1.IP())
    h1.cmdPrint('ping -c3 ' + h0.IP())

    info("*** Stopping network\n")
    controller.cmd('kill %' + cname)
    switch0.cmd('ovs-vsctl del-br dp0')
    switch0.deleteIntfs()
    info('\n')
Exemple #7
0
def myNet(cname='controller', cargs='-v ptcp:'):
    "Create network from scratch using Open vSwitch."
    info( "*** Creating nodes\n" )
    controller = Node( 'c0', inNamespace=False )
    switch = Node( 's0', inNamespace=False )
    h0 = Node( 'h0' )
    h1 = Node( 'h1' )
    h2 = Node( 'h2' )
 
    info( "*** Creating links\n" )
    linkopts0=dict(bw=100, delay='1ms', loss=0)
    TCLink( h0, switch, **linkopts0)
    TCLink( h1, switch, **linkopts0)
    TCLink( h2, switch, **linkopts0)
 
    info( "*** Configuring hosts\n" )
    h0.setIP( '192.168.123.1/24' )
    h1.setIP( '192.168.123.2/24' )
    h2.setIP( '192.168.123.3/24' )
       
    info( "*** Starting network using Open vSwitch\n" )
    switch.cmd( 'ovs-vsctl del-br dp0' )
    switch.cmd( 'ovs-vsctl add-br dp0' )
 
    controller.cmd( cname + ' ' + cargs + '&' )    
    for intf in switch.intfs.values():
        print intf
        print switch.cmd( 'ovs-vsctl add-port dp0 %s' % intf )
  
    # Note: controller and switch are in root namespace, and we
    # can connect via loopback interface
    switch.cmd( 'ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633' )
   
    info( '*** Waiting for switch to connect to controller' )
    while 'is_connected' not in quietRun( 'ovs-vsctl show' ):
        sleep( 1 )
        info( '.' )
    info( '\n' )
 
    #info( "*** Running test\n" )
    h0.cmdPrint( 'ping -c 3 ' + h1.IP() )
    h0.cmdPrint( 'ping -c 3 ' + h2.IP() )
    h2.cmdPrint( 'ping -c 3 ' + h1.IP() )
 
    info( "*** Stopping network\n" )
    controller.cmd( 'kill %' + cname )
    switch.cmd( 'ovs-vsctl del-br dp0' )
    switch.deleteIntfs()
    info( '\n' )
Exemple #8
0
    def fixEnvironment(self):

        mylog("*** Fix environment\n")

        for node in self.nodes_in_rn:
            fixIntf(node)
        root = Node('root', inNamespace=False)

        mylog("*** Stop unwanted traffic\n")
        root.cmd('stop avahi-daemon')
        #root.cmd('killall dhclient')

        mylog("*** Kill old processes\n")
        root.cmd('killall -r zebra')
        root.cmd('killall -r ospfd')
        root.cmd('killall sshd')

        cfile = '/etc/environment'
        line1 = 'VTYSH_PAGER=more\n'
        config = open(cfile).read()
        if (line1) not in config:
            mylog('*** Adding %s to %s\n' % (line1.strip(), cfile))
            with open(cfile, 'a') as f:
                f.write(line1)
            f.close()

        if os.path.exists(self.temp_cfg):
            os.remove(self.temp_cfg)
Exemple #9
0
    def cleanEnvironment(self):

        mylog("*** Clean environment!!!\n")
        subprocess.call(["sudo", "mn", "-c"], stdout=None, stderr=None)

        root = Node('root', inNamespace=False)

        mylog("*** Restart network-manager\n")
        root.cmd('/etc/init.d/network-manager restart')

        mylog("*** Kill all processes started\n")
        root.cmd('killall ovsdb-server')
        root.cmd('killall ovs-vswitchd')
        root.cmd('killall -r zebra')
        root.cmd('killall -r ospfd')
        root.cmd('killall sshd')

        mylog("*** Restart Avahi, Open vSwitch, and sshd\n")
        root.cmd('/etc/init.d/avahi-daemon start')

        #root.cmd('/etc/init.d/openvswitchd start')
        root.cmd('service openvswitch-switch start')

        root.cmd('/etc/init.d/ssh start')

        mylog('*** Unmounting host bind mounts\n')
        unmountAll()
Exemple #10
0
def connectToInternet(network, switch='s1', rootip='10.254', subnet='10.0/8'):
    """Connect the network to the internet
       switch: switch to connect to root namespace
       rootip: address for interface in root namespace
       subnet: Mininet subnet"""
    switch = network.get(switch)
    prefixLen = subnet.split('/')[1]
    routes = [subnet]  # host networks to route to

    # Create a node in root namespace
    root = Node('root', inNamespace=False)

    # Prevent network-manager from interfering with our interface
    fixNetworkManager(root, 'root-eth0')

    # Create link between root NS and switch
    link = network.addLink(root, switch)
    link.intf1.setIP(rootip, prefixLen)

    # Start network that now includes link to root namespace
    network.start()

    # Start NAT and establish forwarding
    startNAT(root)

    # Establish routes from end hosts
    for host in network.hosts:
        host.cmd('ip route flush root 0/0')
        host.cmd('route add -net', subnet, 'dev', host.defaultIntf())
        host.cmd('route add default gw', rootip)

    return root
Exemple #11
0
def connectToRootNS(net,
                    ip='10.123.123.1',
                    mac='00123456789A',
                    prefixLen=8,
                    routes=['10.0.0.0/8']):
    print "*** Creating controller"
    c0 = net.addController('c0', ip='127.0.0.1', port=6633)
    rootswitch = net.addSwitch('roots1', )
    rootswitch.dpid = 'FFFFFFFFFFFFFFFF'
    # Connect hosts to root namespace via switch. Starts network.
    # network: Mininet() network object
    # ip: IP address for root namespace node
    # prefixLen: IP address prefix length (e.g. 8, 16, 24)
    # routes: host networks to route to"
    # Create a node in root namespace and link to switch 0
    root = Node('root', inNamespace=False)
    intf = Link(root, rootswitch).intf1
    intf.setMAC(mac)
    root.setIP(ip, prefixLen, intf)
    print "*** Added Interface", str(intf), "Connected To Root-NameSpace"
    fixNetworkManager(str(intf))
    for host in net.hosts:
        net.addLink(host, rootswitch)
    # Add routes from root ns to hosts
    for route in routes:
        root.cmd('route add -net ' + route + ' dev ' + str(intf))
    root.cmd('service network-manager restart')
    return rootswitch
Exemple #12
0
    def init_floating_network(self):
        """
        Initialize the floating network component for the emulator.
        Will not do anything if already initialized.
        """
        if self.net is not None and self.floating_switch is None:
            # create a floating network
            fn = self.floating_network = Net("default")
            fn.id = str(uuid.uuid4())
            fn.set_cidr(self.floating_netmask)

            # create a subnet
            fn.subnet_id = str(uuid.uuid4())
            fn.subnet_name = fn.name + "-sub"

            # create a port for the host
            port = Port("root-port")
            #port.id = str(uuid.uuid4())
            port.net_name = fn.name

            # get next free ip
            root_ip = fn.get_new_ip_address(port.name)
            port.ip_address = root_ip
            # floating ip network setup
            # wierd way of getting a datacenter object
            first_dc = self.net.dcs.values()[0]
            # set a dpid for the switch. for this we have to get the id of the next possible dc
            self.floating_switch = self.net.addSwitch("fs1", dpid=hex(first_dc._get_next_dc_dpid())[2:])
            # this is the interface appearing on the physical host
            self.floating_root = Node('root', inNamespace=False)
            self.net.hosts.append(self.floating_root)
            self.net.nameToNode['root'] = self.floating_root
            self.floating_intf = self.net.addLink(self.floating_root, self.floating_switch).intf1
            self.floating_root.setIP(root_ip, intf=self.floating_intf)
            self.floating_nodes[(self.floating_root.name, root_ip)] = self.floating_root
Exemple #13
0
def connectToGateway(network,
                     switch='s1',
                     rootip='10.128.0.254',
                     subnet='10.128.0.0/9'):
    """Connect the network to the internet
       switch: switch to connect to root namespace
       rootip: address for interface in root namespace
       subnet: Mininet subnet"""
    switch = network.get(switch)
    prefixLen = subnet.split('/')[1]

    # Create a node in root namespace
    root = Node('root', inNamespace=False)

    # Prevent network-manager from interfering with our interface
    fixNetworkManager(root, 'root-eth0')

    # Create link between root NS and switch
    link = network.addLink(root, switch)
    link.intf1.setIP(rootip, prefixLen)

    # Start network that now includes link to root namespace
    #    network.start()

    return root
Exemple #14
0
def connectToInternet(network, switch='s2', rootip='10.254', subnet='10.0/8'):
    """Connect the network to the internet
switch: switch to connect to root namespace
rootip: address for interface in root namespace
subnet: Mininet subnet"""
    switch = network.get(switch)
    prefixLen = subnet.split('/')[1]

    # Create a node in root namespace
    root = Node('root', inNamespace=False)

    # Prevent network-manager from interfering with our interface
    fixNetworkManager(root, 'root-eth0')

    # Create link between root NS and switch
    link = network.addLink(root, switch)
    #,bw=100,max_queue_size=500,use_htb=True)
    link.intf1.setIP(rootip, prefixLen)
    # Start network that now includes link to root namespace
    network.start()

    # Start NAT and establish forwarding
    startNAT(root)

    # Setting up DHCP
    print "IF 0 ROOT ->" + str(os.getuid())
    out = network.hosts[0].cmd('sudo dhcpd')
    print "DHCPD = " + out

    # Establish routes from end hosts
    for host in network.hosts:
        host.cmd('ip route flush root 0/0')
        host.cmd('route add -net', subnet, 'dev', host.defaultIntf())
        host.cmd('route add default gw', rootip)
    return root
Exemple #15
0
def connectToInternet(network, switch='s1', rootip='10.254', subnet='10.0/8'):
    """Connect the network to the internet
       switch: switch to connect to root namespace
       rootip: address for interface in root namespace
       subnet: Mininet subnet"""
    switch = network.get(switch)
    prefixLen = subnet.split('/')[1]

    # Criando node no namespace raiz
    root = Node('root', inNamespace=False)

    # Interface gerenciador prevencao
    fixNetworkManager(root, 'root-eth0')

    # Criando link
    link = network.addLink(root, switch)
    link.intf1.setIP(rootip, prefixLen)

    # Start network
    network.start()

    # Start NAT
    startNAT(root)

    # Estabelecendo rotas entre hosts
    for host in network.hosts:
        host.cmd('ip route flush root 0/0')
        host.cmd('route add -net', subnet, 'dev', host.defaultIntf())
        host.cmd('route add default gw', rootip)

    return root
    def checkOVS(self):
        root = Node('root', inNamespace=False)
        modinfo = root.cmd(
            "modinfo openvswitch | grep version: |awk -F':' '{print $2}' | awk '{ gsub (\" \", \"\", $0); print}'"
        )
        versions = modinfo.split("\n")
        version = versions[0]
        print "modinfo openviswitch : " + version
        # SS 2017-10-21 I've disabled the version check because in the packaged openvswitch there is no version info
        # modversion = float(version[:3])
        # if modversion < 2.3:
        # 	error( 'OVS Kernel Module does not respect version requirement\nPlease check your OVS installation\n' )
        # 	exit( 1 )

        vswitchdinfo = root.cmd(
            "ovs-vswitchd --version | grep ovs-vswitchd |awk -F')' '{print $2}' | awk '{ gsub (\" \", \"\", $0); print}'"
        )
        versions = vswitchdinfo.split("\n")
        version = versions[0]
        print "ovs-vswitchd --version : " + version
        vswitchdversion = float(version[:3])
        if vswitchdversion < 2.3:
            error(
                'OVS vswitchd does not respect version requirement\nPlease check your OVS installation\n'
            )
            exit(1)

        # SS 2017-10-21 I've disabled the version check because in the packaged openvswitch there is no version info
        # if modversion != vswitchdversion:
        # 	error( 'OVS Kernel module version and OVS vswitchd version are different\nPlease check your OVS installation\n' )
        # 	exit( 1)

        openvswitchd = root.cmd('ls %s 2> /dev/null | wc -l' % self.ovs_initd)
Exemple #17
0
def connectToRootNS(network, switch, ip, routes):
    root = Node('root', inNamespace=False)
    intf = network.addLink(root, switch).intf1
    root.setIP(ip, intf=intf)
    network.start()

    for route in routes:
        root.cmd('route add -net ' + route + ' dev ' + str(intf))
Exemple #18
0
def scratchNet(cname='controller', cargs='-v ptcp:'):
    #create network from scratch using Open vswitch
    info("***Creating nodes\n")
    controller = Node('c0', inNamespace=False)
    switch0 = Node('s0', inNamespace=False)
    h0 = Node('h0')
    h1 = Node('h1')

    info("***Creating links\n")
    Link(h0, switch0)
    Link(h1, switch0)

    info(" ***Configuring hosts\n")
    h0.setIP('192.168.123.1/24')
    h1.setIP('192.168.123.2/24')
    info(str(h0) + '\n')
    info(str(h1) + '\n')
Exemple #19
0
def topology():

    "Create a network."
    net = Mininet( controller=RemoteController, link=TCLink, switch=OVSKernelSwitch )
    staList = []

    print "*** Creating nodes"
    for n in range(10):
	staList.append(n)
	staList[n] = net.addStation( 'sta%s' % (n+1), wlans=2, mac='00:00:00:00:00:%s' % (n+1), ip='192.168.0.%s/24' % (n+1) )
    phyap1 = net.addPhysicalBaseStation( 'phyap1', ssid= 'SBRC16-MininetWiFi', mode= 'g', channel= '1', position='50,115,0', phywlan='wlan11' )
    sta11 = net.addStation( 'sta11', ip='10.0.0.111/8', position='120,200,0')
    ap2 = net.addAccessPoint( 'ap2', ssid= 'ap2', mode= 'g', channel= '11', position='100,175,0' )
    ap3 = net.addAccessPoint( 'ap3', ssid= 'ap3', mode= 'g', channel= '6', position='150,50,0' )
    ap4 = net.addAccessPoint( 'ap4', ssid= 'ap4', mode= 'g', channel= '1', position='175,150,0' )
    c1 = net.addController( 'c1', controller=Controller, port=6653 )
    root = Node( 'root', inNamespace=False )

    print "*** Configuring wifi nodes"
    net.configureWifiNodes()

    """uncomment to plot graph"""
    net.plotGraph(max_x=240, max_y=240)

    """Routing"""
    net.meshRouting('custom')

    """Seed"""
    net.seed(20)

    print "*** Associating and Creating links"
    for sta in staList:
        net.addMesh(sta, ssid='meshNet')
    net.addLink(phyap1, ap2)
    net.addLink(ap2, ap3)
    net.addLink(ap3, ap4)

    print "*** Starting network"
    net.build()
    c1.start()
    phyap1.start( [c1] )
    ap2.start( [c1] )
    ap3.start( [c1] )
    ap4.start( [c1] )

    ip = 201
    for sta in staList:
        sta.setIP('10.0.0.%s/8' % ip, intf="%s-wlan1" % sta)
        ip+=1

    "*** Available models: RandomWalk, TruncatedLevyWalk, RandomDirection, RandomWayPoint, GaussMarkov, ReferencePoint, TimeVariantCommunity ***"
    net.startMobility(startTime=0, model='RandomWalk', max_x=200, max_y=220, min_v=0.1, max_v=0.2)

    print "*** Running CLI"
    CLI( net )

    print "*** Stopping network"
    net.stop()
def scratchNetUser(cname='controller', cargs='ptcp:'):
    "Create network from scratch using user switch."

    # It's not strictly necessary for the controller and switches
    # to be in separate namespaces. For performance, they probably
    # should be in the root namespace. However, it's interesting to
    # see how they could work even if they are in separate namespaces.

    info('*** Creating Network\n')
    controller = Node('c0')
    switch = Node('s0')
    h0 = Node('h0')
    h1 = Node('h1')
    cintf, sintf = createLink(controller, switch)
    h0intf, sintf1 = createLink(h0, switch)
    h1intf, sintf2 = createLink(h1, switch)

    info('*** Configuring control network\n')
    controller.setIP(cintf, '10.0.123.1', 24)
    switch.setIP(sintf, '10.0.123.2', 24)

    info('*** Configuring hosts\n')
    h0.setIP(h0intf, '192.168.123.1', 24)
    h1.setIP(h1intf, '192.168.123.2', 24)

    info('*** Network state:\n')
    for node in controller, switch, h0, h1:
        info(str(node) + '\n')

    info('*** Starting controller and user datapath\n')
    controller.cmd(cname + ' ' + cargs + '&')
    switch.cmd('ifconfig lo 127.0.0.1')
    intfs = [sintf1, sintf2]
    switch.cmd('ofdatapath -i ' + ','.join(intfs) + ' ptcp: &')
    switch.cmd('ofprotocol tcp:' + controller.IP() + ' tcp:localhost &')

    info('*** Running test\n')
    h0.cmdPrint('ping -c1 ' + h1.IP())

    info('*** Stopping network\n')
    controller.cmd('kill %' + cname)
    switch.cmd('kill %ofdatapath')
    switch.cmd('kill %ofprotocol')
    switch.deleteIntfs()
    info('\n')
Exemple #21
0
def start():

    global net, attacker, running

    if running:
        return '\nServer already running.\n'

    setLogLevel('info')

    topo = MixTopo()
    net = Mininet(topo=topo)

    s1 = net['s1']
    plc2 = net['plc2']
    plc3 = net['plc3']

    s2, rtu2a, scada = net.get('s2', 'rtu2a', 'scada')
    rtu2b, attacker2 = net.get('rtu2b', 'attacker2')
    s3 = net.get('s3')

    # NOTE: root-eth0 interface on the host
    root = Node('root', inNamespace=False)
    intf = net.addLink(root, s3).intf1
    print('DEBUG root intf: {}'.format(intf))
    root.setIP('10.0.0.30', intf=intf)
    # NOTE: all packet from root to the 10.0.0.0 network
    root.cmd('route add -net ' + '10.0.0.0' + ' dev ' + str(intf))


    net.start()
    info('Welcome')

    # NOTE: use for debugging
    #s1.cmd('tcpdump -i s1-eth1 -w /tmp/s1-eth1.pcap &')
    #s1.cmd('tcpdump -i s1-eth2 -w /tmp/s1-eth2.pcap &')

    SLEEP = 0.5

    # NOTE: swat challenge 1 and 2
    plc3.cmd(sys.executable + ' plc3.py &')
    sleep(SLEEP)
    plc2.cmd(sys.executable + ' plc2.py &')
    sleep(SLEEP)

    # NOTE: wadi challenge 1
    scada.cmd(sys.executable + ' scada.py &')
    sleep(SLEEP)
    rtu2a.cmd(sys.executable + ' rtu2a.py &')
    sleep(SLEEP)
    # NOTE: wadi challenge 2
    rtu2b.cmd(sys.executable + ' rtu2b.py &')
    sleep(SLEEP)


    running = True
    return '\nServer started.\n'
Exemple #22
0
def sshd(net):
    root = Node('root', inNamespace=False)
    intf = net.addLink(root, net['s3']).intf1
    root.setIP('10.0.0.4/24', intf=intf)

    net.start()
    root.cmd('route add -net 10.0.0.0/24 dev ' + str(intf))

    for host in net.hosts:
        host.cmd('/usr/sbin/sshd -D -o UseDNS=no -u0&')
Exemple #23
0
 def checkSR(self):
     root = Node('root', inNamespace=False)
     sr = root.cmd('ls %s 2> /dev/null | wc -l' % self.SR_exec)
     if '1' not in sr:
         error(
             'Cannot find required executable fpm-of.bin\nPlease make sure that fpm-of.bin is properly installed in '
             + self.SR_path + '\n'
             'Otherwise change sr_path variable according to your configuration\n'
         )
         exit(1)
Exemple #24
0
def fixSwitchIntf(swi):
    for i in range(0, len(swi)):
        for obj in swi[i].nameToIntf:
            if 'lo' not in obj:
                fixNetworkManager(obj)
        fixNetworkManager(swi[i])
    root = Node('root', inNamespace=False)
    print "Restarting Network Manager"
    time.sleep(10)
    root.cmd('service network-manager restart')
    time.sleep(2)
Exemple #25
0
    def __init__(self, numSwitches=6):

        super(WattsStrogatzTopology, self).__init__()

        # add switches
        numHosts = numSwitches
        hosts = range(1, numHosts + 1)
        firstSwitch = max(101, numHosts + 1)
        switches = range(firstSwitch, numSwitches + firstSwitch)

        # Add switches
        for s in switches:
            self.add_node(s, Node(is_switch=True))

        # Add hosts
        for h in hosts:
            self.add_node(h, Node(is_switch=False))

        # Add links
        for h in hosts:
            self.add_edge(h, switches[h - 1])

        rev_switches = list(switches)
        rev_switches.reverse()
        [last] = rev_switches[-1:]
        for s in rev_switches:
            self.add_edge(s, last)
            last = s

        # Add "magic" links

        self.add_edge(101, 103)
        self.add_edge(102, 105)

        # Add monitoring host
        # self.add_node(99, Node(is_switch=False))

        # for s in switches:
        #     self.add_edge(s, 99)

        self.enable_all()
Exemple #26
0
def DeltaNetwork():
    #Make topology
    net = Mininet(topo=None, controller=None, build=False)

    #Add switch
    proto = sys.argv[5]
    s0 = net.addSwitch('s0', dpid='00:00:00:00:00:01', protocols=proto)
    s1 = net.addSwitch('s1', dpid='00:00:00:00:00:02',
                       protocols=proto)  # for connections with DELTA

    #Add hosts
    h1 = net.addHost('h1', ip='10.0.0.1/24', mac='00:00:00:00:00:11')
    h2 = net.addHost('h2', ip='10.0.0.2/24', mac='00:00:00:00:00:22')

    #Add links
    net.addLink(s0, h1)
    net.addLink(s0, h2)

    net.addLink(s1, h1, intfName2='host-eth')

    root = Node('root', inNamespace=False)
    intf = net.addLink(root, s1).intf1
    root.setIP('10.0.1.1', intf=intf)

    #       net.build()
    net.start()

    f = os.popen(
        'ifconfig eth0 | grep "inet\ addr" | cut -d: -f2 | cut -d" " -f1')
    ip = f.read()[:-1]

    root.cmd('route add -net 10.0.1.0/24 dev ' + str(intf))
    h1.cmd("ifconfig host-eth 10.0.1.2/24 netmask 255.255.255.0")
    h1.cmd('route add -net 10.0.3.0/24 dev host-eth')
    h1.cmd('route add -net 10.0.3.0/24 gw ' + str(ip) + ' dev host-eth')

    #Set ip
    os.system(
        "sudo ovs-ofctl -O OpenFlow13 add-flow s1 in_port=1,actions=output:2")
    os.system(
        "sudo ovs-ofctl -O OpenFlow13 add-flow s1 in_port=2,actions=output:1")

    #h1.cmd("dhclient eth0")

    #connect a controller
    os.system("sudo ovs-vsctl set-controller s0 tcp:" + sys.argv[1] + ":" +
              sys.argv[2])

    h1.cmd("java -jar $HOME/delta-agent-host-1.0-SNAPSHOT.jar " + sys.argv[3] +
           " " + sys.argv[4])
    CLI(net)
    net.stop()
Exemple #27
0
    def __init__(self, num_switches=5, seed=100):

        super(WaxmanTopology, self).__init__()

        num_hosts_per_switch = 2
        # Needed so that subsequent calls will generate the same graph
        random.seed(seed)
        num_hosts = num_switches * num_hosts_per_switch
        # build waxman graph
        wax = nx.waxman_graph(num_switches, .9, .9)

        # Add switches
        for s in wax.nodes():
            self.add_node(s + 1, Node(is_switch=True))

        # Add edges
        for s1, s2 in wax.edges():
            print "new edge"
            self.add_edge(s1 + 1, s2 + 1)

        # Add hosts
        hostoffset = num_switches + 2
        for s in wax:
            # Add host
            host_base = num_hosts_per_switch * s + hostoffset
            for host in range(0, num_hosts_per_switch):
                self.add_node(host_base + host, Node(is_switch=False))
                self.add_edge(host_base + host, s + 1)

        # # Globally connected host
        # self.add_host(9999)
        # for switch in wax:
        #     self.add_link(9999, switch)

        # f = open('/home/openflow/workspace/foo.log', 'w')
        # f.write('hosts: %d\n' % len(self.hosts()))
        # f.close()
        # assert(False)
        self.enable_all()
Exemple #28
0
 def enableSSH(self, net):
     print 'Enabling ssh'
     routes = ['10.0.0.0/24']
     ip = '10.123.123.1/32'
     switch = self.CoreSwitchList[0]
     print switch
     switch = net[switch]
     root = Node('root', inNamespace=False)
     intf = Link(root, switch).intf1
     root.setIP(ip, intf=intf)
     net.start()
     for route in routes:
         root.cmd('route add -net ' + route + ' dev ' + str(intf))
Exemple #29
0
def net():

    "Create a network with 5 hosts."

    net = Mininet(controller=Controller)

    info('*** Adding controller\n')
    net.addController('c0')

    info('*** Adding hosts\n')
    h1 = net.addHost('h1', ip='10.0.0.1')
    h2 = net.addHost('h2', ip='10.0.0.2')
    h3 = net.addHost('h3', ip='10.0.0.3')
    h4 = net.addHost('h4', ip='10.0.0.4')
    h5 = net.addHost('h5', ip='10.0.0.5')

    info('*** Adding switch\n')
    s1 = net.addSwitch('s1')

    info('*** Creating links\n')
    # host 1-4 connect to ports 1-4 on the switch
    net.addLink(h1, s1)
    net.addLink(h2, s1)
    net.addLink(h3, s1)
    net.addLink(h4, s1)
    net.addLink(
        h5, s1, port1=1, port2=9
    )  # specify a different port to connect host 5 to on the switch.

    root = Node('root', inNamespace=False)
    info('*** Starting network\n')
    net.start()

    # print the interfaces and their port numbers
    info('\n*** printing and validating the ports running on each interface\n')
    for intfs in s1.intfList():
        if not intfs.name == "lo":
            info(intfs, ': ', s1.ports[intfs], '\n')
            info('Validating that', intfs, 'is actually on port',
                 s1.ports[intfs], '... ')
            if validatePort(s1, intfs):
                info('Validated.\n')
    print '\n'

    # test the network with pingall
    net.pingAll()
    print '\n'

    info('*** Stopping network')
    net.stop()
Exemple #30
0
    def __init__(self, verbose=False):

        self.checkPATHs()

        Mininet.__init__(self, build=False)

        self.cr_oshis = []
        self.pe_oshis = []
        self.ce_routers = []
        self.ctrls = []
        self.nodes_in_rn = []
        self.node_to_data = defaultdict(list)
        self.node_to_node = {}
        self.node_to_default_via = {}
        self.coex = {}

        self.verbose = verbose
        lg.setLogLevel('info')

        self.vlls = []

        self.node_to_pw_data = defaultdict(list)
        self.pws = []

        self.cer_to_customer = {}
        self.customer_to_vtepallocator = {}

        self.vsfs = []
        self.pe_cer_to_vsf = {}

        self.is_vs = False
        self.vss = []
        self.vss_data = []
        self.id_peo_to_vs = {}
        self.last_ipnet = IPv4Network(u'0.0.0.0/24')

        self.id_to_node = {}
        self.ip_to_mac = {}

        self.overall_info = {}

        self.mgmt = None

        root = Node('root', inNamespace=False)
        root.cmd('/etc/init.d/network-manager stop')
        mylog("*** Stop Network Manager\n")

        self.cluster_to_ctrl = defaultdict(list)
        self.cluster_to_nodes = defaultdict(list)
        self.nodes_to_cluster = {}