Ejemplo n.º 1
0
def startNetwork():
    "instantiates a topo, then starts the network and prints debug information"

    info('** Creating Quagga network topology\n')
    topo = QuaggaTopo()

    info('** Starting the network\n')
    global net
    net = MiniNExT(topo, controller=OVSController)
    net.start()

    info('** Dumping host connections\n')
    dumpNodeConnections(net.hosts)

    info('** Testing network connectivity\n')
    net.ping(net.hosts)

    info('** Dumping host processes\n')

    h2IPAddress = "192.0.0.213"

    for i in range(2, 6):
        if i == 2:
            net.hosts[i].cmdPrint("ip addr add 192.0.0.201/30 dev R1-eth2")
            net.hosts[i].cmdPrint("ip addr add 192.0.0.197/30 dev R1-eth1")
        elif i == 3:
            net.hosts[i].cmdPrint("ip addr add 192.0.0.209/30 dev R2-eth1")
        elif i == 4:
            net.hosts[i].cmdPrint("ip addr add 192.0.0.205/30 dev R3-eth1")
        elif i == 5:
            net.hosts[i].cmdPrint("ip addr add 192.0.0.206/30 dev R4-eth1")
            net.hosts[i].cmdPrint("ip addr add 192.0.0.214/30 dev R4-eth2")

    for host in net.hosts:
        host.cmdPrint("ps aux")
        host.cmdPrint("echo 1 > /proc/sys/net/ipv4/ip_forward")

    for i in range(len(net.hosts)):
        if i == 0:
            net.hosts[i].cmdPrint("route add default gw 192.0.0.194")
        elif i == 1:
            net.hosts[i].cmdPrint("route add default gw 192.0.0.214")

    if argument == "1":
        startTime = time.time()
        check = 'random'
        print("Checking Time taken by H1 to ping H2...Wait")

        while ' 0% packet loss' not in check:
            check = net.hosts[0].cmdPrint('ping -c10 ' + h2IPAddress)
            if ' 0% packet loss' not in check:
                print("Not able to ping in this ping..Trying again")

        print(check)
        endTime = time.time()
        print('H1 to H2 pinging time= ', (endTime - startTime), 'sec')

    if argument == "2":
        startTime = time.time()

        check = 1
        print("Checking Convergence Time....Wait")
        while check != 0:
            check = net.pingAll()
            if check != 0:
                print("Not converged in this ping...Trying again")

        endTime = time.time()
        print('Convergence time= ', (endTime - startTime), 'sec')

        print('Do R1-R2 Link down')
        startTime = time.time()
        net.configLinkStatus('R1', 'R2', 'down')
        print("Link Down...Checking convergence Time")
        check = 'random'
        while ' 0% packet loss' not in check:
            check = net.hosts[0].cmdPrint('ping -c10 ' + h2IPAddress)
            if ' 0% packet loss' not in check:
                print("Not able to ping in this ping..Trying again")

        print(check)
        endTime = time.time()
        print('H1 to H2 pinging time= ', (endTime - startTime), 'sec')

    info('** Running CLI\n')
    CLI(net)
Ejemplo n.º 2
0
def startNetwork(static_routes):
    "instantiates a topo, then starts the network and prints debug information"

    info('** Creating Quagga network topology\n')
    topo = QuaggaTopo()

    info('** Starting the network\n')
    global net
    net = MiniNExT(topo, controller=OVSController)
    net.start()
    t_start = datetime.now()
    info('** Dumping host connections\n')
    dumpNodeConnections(net.hosts)

    net.get('H1').cmd('sysctl -w net.ipv4.ip_forward=1')
    net.get('H2').cmd('sysctl -w net.ipv4.ip_forward=1')
    net.get("R1").cmd("sysctl -w net.ipv4.ip_forward=1")
    net.get("R2").cmd("sysctl -w net.ipv4.ip_forward=1")
    net.get("R3").cmd("sysctl -w net.ipv4.ip_forward=1")
    net.get("R4").cmd("sysctl -w net.ipv4.ip_forward=1")

    net.get("R1").cmd("ifconfig R1-eth1 172.0.2.2/24")
    net.get("R1").cmd("ifconfig R1-eth2 172.0.3.2/24")
    net.get("R2").cmd("ifconfig R2-eth0 172.0.2.1/24")
    net.get("R2").cmd("ifconfig R2-eth1 172.0.5.1/24")
    net.get("R3").cmd("ifconfig R3-eth0 172.0.3.1/24")
    net.get("R3").cmd("ifconfig R3-eth1 172.0.6.1/24")
    net.get("R4").cmd("ifconfig R4-eth0 172.0.4.1/24")
    net.get("R4").cmd("ifconfig R4-eth1 172.0.5.2/24")
    net.get("R4").cmd("ifconfig R4-eth2 172.0.6.2/24")
    net.get("H2").cmd("ifconfig H2-eth0 172.0.4.2/24")

    if static_routes:
        net.get("R1").cmd("ip route add 172.0.5.0/24 via 172.0.2.1 dev R1-eth1")
        net.get("R1").cmd("ip route add 172.0.4.0/24 via 172.0.2.1 dev R1-eth1")
        net.get("R1").cmd("ip route add 172.0.4.0/24 via 172.0.3.1 dev R1-eth2")
        net.get("R1").cmd("ip route add 172.0.6.0/24 via 172.0.3.1 dev R1-eth2")
        net.get("R2").cmd("ip route add 172.0.1.0/24 via 172.0.2.2 dev R2-eth0")
        net.get("R2").cmd("ip route add 172.0.4.0/24 via 172.0.5.2 dev R2-eth1")
        net.get("R2").cmd("ip route add 172.0.3.0/24 via 172.0.2.2 dev R2-eth0")
        net.get("R3").cmd("ip route add 172.0.1.0/24 via 172.0.3.2 dev R3-eth0")
        net.get("R3").cmd("ip route add 172.0.2.0/24 via 172.0.3.2 dev R3-eth0")
        net.get("R3").cmd("ip route add 172.0.4.0/24 via 172.0.6.2 dev R3-eth1")
        net.get("R4").cmd("ip route add 172.0.2.0/24 via 172.0.5.1 dev R4-eth1")
        net.get("R4").cmd("ip route add 172.0.3.0/24 via 172.0.6.1 dev R4-eth2")
        net.get("R4").cmd("ip route add 172.0.1.0/24 via 172.0.5.1 dev R4-eth1")
        net.get("R4").cmd("ip route add 172.0.1.0/24 via 172.0.6.1 dev R4-eth2")
    
    net.get("R1").cmd("iptables -t nat -A POSTROUTING -o R1-eth0 -j MASQUERADE")
    net.get("R1").cmd("iptables -A FORWARD -i R1-eth0 -o R1-eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT")
    net.get("R1").cmd("iptables -A FORWARD -i R1-eth1 -o R1-eth0 -j ACCEPT")
    
    net.get("R2").cmd("iptables -t nat -A POSTROUTING -o R2-eth0 -j MASQUERADE")
    net.get("R2").cmd("iptables -A FORWARD -i R2-eth0 -o R2-eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT")
    net.get("R2").cmd("iptables -A FORWARD -i R2-eth1 -o R2-eth0 -j ACCEPT")
    
    net.get("R3").cmd("iptables -t nat -A POSTROUTING -o R3-eth1 -j MASQUERADE")
    net.get("R3").cmd("iptables -A FORWARD -i R3-eth1 -o R3-eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT")
    net.get("R3").cmd("iptables -A FORWARD -i R3-eth0 -o R3-eth1 -j ACCEPT")
    
    net.get("R4").cmd("iptables -t nat -A POSTROUTING -o R4-eth0 -j MASQUERADE")
    net.get("R4").cmd("iptables -A FORWARD -i R4-eth0 -o R4-eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT")
    net.get("R4").cmd("iptables -A FORWARD -i R4-eth1 -o R4-eth0 -j ACCEPT")
    net.get("R4").cmd("iptables -A FORWARD -i R4-eth2 -o R4-eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT")
    net.get("R4").cmd("iptables -A FORWARD -i R4-eth0 -o R4-eth2 -j ACCEPT")
    
    info('** Testing network connectivity\n')

    info('** Dumping host processes\n')
    for host in net.hosts:
        host.cmdPrint("ps aux")

    info('** Running CLI\n')
    loss = 100
    while (loss > 0):
        loss = net.pingAll()
    t_end = datetime.now() - t_start
    print "Percentage Loss: " + str(loss)
    print "Route Convergence Time: " + str(t_end.total_seconds()) + "seconds"
    
    if static_routes:
        print ("[MESSAGE:] Enabling Static Routes...")
    else:
        print ("[MESSAGE:] Disabling Static Routes...")
    
    CLI(net)