Exemple #1
0
def test_tc_example(topo, delay, bw):
    """
    :param topo: The topology class
    :param delay: The delay between host h1 and h2 in ms
    :param bw: The bandwidth between h1 and h2 in Mbps
    """
    try:
        net = IPNet(topo=topo())
        net.start()

        # Check connectivity
        assert_connectivity(net, v6=False)
        assert_connectivity(net, v6=True)

        # Check delay
        assert_delay(net["h1"], net["h2"], delay, v6=False)
        assert_delay(net["h1"], net["h2"], delay, v6=True)

        # Check bandwidth
        assert_bw(net["h1"], net["h2"], bw, v6=False, tolerance=bw // 10)
        assert_bw(net["h1"], net["h2"], bw, v6=True, tolerance=bw // 10)

        net.stop()
    finally:
        cleanup()
Exemple #2
0
def test_dns_network(named_cfg, zone_args, exp_named_cfg, exp_zone_cfg):
    try:
        net = IPNet(topo=CustomDNSNetwork(named_cfg, zone_args))
        net.start()

        # Check generated configurations
        with open("/tmp/named_master2.cfg") as fileobj:
            cfg = fileobj.readlines()
            for line in exp_named_cfg:
                assert line + "\n" in cfg,\
                    "Cannot find the line '%s' in the generated " \
                    "main configuration:\n%s" % (line, "".join(cfg))
        with open("/tmp/named_master2.test.org.zone.cfg") as fileobj:
            cfg = fileobj.readlines()
            for line in exp_zone_cfg:
                assert line + "\n" in cfg,\
                    "Cannot find the line '%s' in the generated zone " \
                    "configuration:\n%s" % (line, "".join(cfg))

        # Check port number configuration
        dns_server_port = named_cfg.get("dns_server_port", 53)
        assert_dns_record(net["master2"],
                          "localhost",
                          AAAARecord("master2.test.org",
                                     net["master2"].defaultIntf().ip6),
                          port=dns_server_port)

        # Check connectivity
        assert_connectivity(net, v6=False)
        assert_connectivity(net, v6=True)

        # Check generated DNS record
        records = [
            NSRecord("mydomain.org", "master"),
            NSRecord("mydomain.org", "slave"),
            ARecord("master.mydomain.org", net["master"].defaultIntf().ip),
            AAAARecord("master.mydomain.org", net["master"].defaultIntf().ip6),
            ARecord("slave.mydomain.org", net["slave"].defaultIntf().ip),
            AAAARecord("slave.mydomain.org", net["slave"].defaultIntf().ip6),
            ARecord("server.mydomain.org", net["server"].defaultIntf().ip),
            AAAARecord("server.mydomain.org",
                       net["server"].defaultIntf().ip6,
                       ttl=120),
            PTRRecord(net["master"].defaultIntf().ip, "master.mydomain.org"),
            PTRRecord(net["master"].defaultIntf().ip6, "master.mydomain.org"),
            PTRRecord(net["slave"].defaultIntf().ip, "slave.mydomain.org"),
            PTRRecord(net["slave"].defaultIntf().ip6, "slave.mydomain.org"),
            PTRRecord(net["server"].defaultIntf().ip, "server.mydomain.org"),
            PTRRecord(net["server"].defaultIntf().ip6,
                      "server.mydomain.org",
                      ttl=120)
        ]
        for node in [net["master"], net["slave"]]:
            for record in records:
                assert_dns_record(node, "localhost", record)
            time.sleep(10)

        net.stop()
    finally:
        cleanup()
Exemple #3
0
def test_partial_static_example():
    try:
        net = IPNet(topo=PartialStaticAddressNet())
        net.start()

        # Check allocated addresses
        assert net["h3"].intf("h3-eth0").ip == "192.168.1.2"
        assert net["h3"].intf("h3-eth0").ip6 == "fc00:1::2"

        assert net["r1"].intf("lo").ip6 == "2042:1::1"
        assert net["r1"].intf("r1-eth1").ip == "192.168.0.1"
        assert net["r1"].intf("r1-eth1").ip6 == "fc00::1"

        assert net["r2"].intf("r2-eth0").ip == "192.168.0.2"
        assert net["r2"].intf("r2-eth0").ip6 == "fc00::2"
        assert net["r2"].intf("r2-eth1").ip == "192.168.1.1"
        assert net["r2"].intf("r2-eth1").ip6 == "fc00:1::1"

        # Check connectivity
        assert_connectivity(net, v6=False)
        assert_connectivity(net, v6=True)

        net.stop()
    finally:
        cleanup()
Exemple #4
0
def test_openr_connectivity():
    try:
        net = IPNet(topo=SimpleOpenrTopo())
        net.start()
        assert_connectivity(net, v6=True)
        net.stop()
    finally:
        cleanup()
def test_ospf6_example():
    try:
        net = IPNet(topo=SimpleOSPFv3Net())
        net.start()
        assert_connectivity(net, v6=True)
        net.stop()
    finally:
        cleanup()
Exemple #6
0
def test_ospf6_example():
    try:
        net = IPNet(topo=SimpleOSPFv3Net())
        net.start()
        assert_connectivity(net, v6=True)
        net.stop()
    finally:
        cleanup()
def test_radvd_example():
    try:
        net = IPNet(topo=RouterAdvNet(), use_v4=False, use_v6=True, allocate_IPs=False)
        net.start()
        assert_connectivity(net, v6=True)
        net.stop()
    finally:
        cleanup()
Exemple #8
0
def test_bgp_example():
    try:
        net = IPNet(topo=SimpleBGPTopo())
        net.start()
        assert_connectivity(net, v6=False)
        assert_connectivity(net, v6=True)
        net.stop()
    finally:
        cleanup()
Exemple #9
0
def test_bgp_example():
    try:
        net = IPNet(topo=SimpleBGPTopo())
        net.start()
        assert_connectivity(net, v6=False)
        assert_connectivity(net, v6=True)
        net.stop()
    finally:
        cleanup()
Exemple #10
0
def test_radvd_example():
    try:
        net = IPNet(topo=RouterAdvNet(), use_v4=False, use_v6=True,
                    allocate_IPs=False)
        net.start()
        assert_connectivity(net, v6=True)
        net.stop()
    finally:
        cleanup()
Exemple #11
0
def test_bgp_policies_adjust():
    try:
        # Adding this new peering link should enable all hosts
        # to ping each others
        net = IPNet(topo=BGPPoliciesAdjustTopo(
            as_start="as5r", as_end="as2r", bgp_policy=CLIENT_PROVIDER))
        net.start()
        assert_connectivity(net, v6=True)
        net.stop()
    finally:
        cleanup()
Exemple #12
0
def test_etc_hosts(topo):
    try:
        net = IPNet(topo=topo())
        net.start()

        assert_connectivity(net, v6=True, translate_address=False)
        assert_connectivity(net, v6=False, translate_address=False)

        net.stop()
    finally:
        cleanup()
Exemple #13
0
def test_ripng_adjust():
    try:
        net = IPNet(topo=RIPngNetworkAdjust(lr1r5_cost=5))
        net.start()
        assert_connectivity(net, v6=True)
        for path in expected_paths["RIPngNetworkAdjust-mod"]:
            assert_path(net, path, v6=True)

        net.stop()
    finally:
        cleanup()
Exemple #14
0
def test_ripng_examples(topo):
    try:
        net = IPNet(topo=topo())
        net.start()
        assert_connectivity(net, v6=True)
        for path in expected_paths[topo.__name__]:
            assert_path(net, path, v6=True)

        net.stop()
    finally:
        cleanup()
Exemple #15
0
def test_ripng():
    try:
        net = IPNet(topo=MinimalRIPngNet())
        net.start()
        assert_connectivity(net, v6=True)
        for path in expected_paths:
            assert_path(net, path, v6=True)

        net.stop()
    finally:
        cleanup()
Exemple #16
0
def test_stp_example():
    try:
        net = IPNet(topo=SpanningTreeNet())
        net.start()

        assert_connectivity(net, v6=False)
        assert_connectivity(net, v6=True)

        net.stop()
    finally:
        cleanup()
Exemple #17
0
def test_stp(topo):
    try:
        net = IPNet(topo=topo())
        net.start()

        assert_connectivity(net, v6=False)
        assert_connectivity(net, v6=True)

        for switch, states in expected_states[topo.__name__].items():
            assert_stp_state(net[switch], states)
        net.stop()
    finally:
        cleanup()
Exemple #18
0
def test_static_examples(routes, paths, through):
    try:
        topo = SRv6TestTopo(new_routes=routes)
        net = IPNet(topo=topo)
        net.start()

        assert_connectivity(net, v6=False)
        for i, p in enumerate(paths):
            assert_path(net, p, v6=True, traceroute_fun=sr_path,
                        through=through[i], timeout=1, retry=30)

        topo.clean()
        net.stop()
    finally:
        cleanup()
Exemple #19
0
def test_stp_adjust():
    try:
        net = IPNet(topo=SpanningTreeAdjust(l1_start="s2-eth1",
                                            l1_end="s1-eth1", l1_cost=2,
                                            l2_start="s1-eth3",
                                            l2_end="s3-eth1", l2_cost=3))
        net.start()

        assert_connectivity(net, v6=False)
        assert_connectivity(net, v6=True)

        for switch, states in expected_states["SpanningTreeAdjust-mod"].items():
            assert_stp_state(net[switch], states)
        net.stop()
    finally:
        cleanup()
Exemple #20
0
def test_staticd_example():
    try:
        net = IPNet(topo=StaticRoutingNet())
        net.start()

        assert_connectivity(net, v6=False)
        assert_connectivity(net, v6=True)

        paths = [["h1", "r1", "r2", "h2"], ["h2", "r2", "r1", "h1"]]
        for p in paths:
            assert_path(net, p, v6=False)
            assert_path(net, p, v6=True)

        net.stop()
    finally:
        cleanup()
Exemple #21
0
def test_bgp_daemon_params(bgp_params, expected_cfg):
    try:
        net = IPNet(topo=BGPTopo(bgp_params), allocate_IPs=False)
        net.start()

        # Check generated configuration
        with open("/tmp/bgpd_as2r1.cfg") as fileobj:
            cfg = fileobj.readlines()
            for line in expected_cfg:
                assert (line + "\n") in cfg, "Cannot find the line '%s' in the generated configuration:\n%s"\
                                             % (line, "".join(cfg))

        # Check reachability
        assert_connectivity(net, v6=False)
        net.stop()
    finally:
        cleanup()
Exemple #22
0
def test_zone_delegation():
    try:
        net = IPNet(topo=DNSAdvancedNetwork())
        net.start()

        # Check connectivity
        assert_connectivity(net, v6=False)
        assert_connectivity(net, v6=True)

        # Check zone delegation and root hinting
        root_hints = [
            NSRecord("", "rootdns"),
            ARecord("rootdns", net["rootdns"].defaultIntf().ip),
            AAAARecord("rootdns", net["rootdns"].defaultIntf().ip6)
        ]
        mydomain_delegation_records = [
            NSRecord("mydomain.org", "master"),
            NSRecord("mydomain.org", "slave"),
            ARecord("master.mydomain.org", net["master"].defaultIntf().ip),
            AAAARecord("master.mydomain.org", net["master"].defaultIntf().ip6),
            ARecord("slave.mydomain.org", net["slave"].defaultIntf().ip),
            AAAARecord("slave.mydomain.org", net["slave"].defaultIntf().ip6),
        ]
        org_delegation_records = [
            NSRecord("org", "orgdns"),
            ARecord("orgdns.org", net["orgdns"].defaultIntf().ip),
            AAAARecord("orgdns.org", net["orgdns"].defaultIntf().ip6),
        ]
        records = [([
            net["master"], net["slave"]
        ], mydomain_delegation_records + [
            ARecord("server.mydomain.org", net["server"].defaultIntf().ip),
            AAAARecord("server.mydomain.org", net["server"].defaultIntf().ip6)
        ] + root_hints),
                   ([net["orgdns"]], org_delegation_records +
                    mydomain_delegation_records + root_hints),
                   ([net['rootdns']], root_hints + org_delegation_records)]
        for nodes, zone_records in records:
            for node in nodes:
                for record in zone_records:
                    assert_dns_record(node, "localhost", record)
                time.sleep(10)

        net.stop()
    finally:
        cleanup()
Exemple #23
0
def test_bgp_daemon_params(bgp_params, expected_cfg):
    try:
        net = IPNet(topo=BGPTopo(bgp_params), allocate_IPs=False)
        net.start()

        # Check generated configuration
        with open("/tmp/bgpd_as2r1.cfg") as fileobj:
            cfg = fileobj.readlines()
            for line in expected_cfg:
                assert (line + "\n") in cfg, "Cannot find the line '%s' in the generated configuration:\n%s"\
                                             % (line, "".join(cfg))

        # Check reachability
        assert_connectivity(net, v6=False)
        assert_connectivity(net, v6=True)
        net.stop()
    finally:
        cleanup()
Exemple #24
0
def test_radvd_daemon_params(link_params, expected_cfg):
    try:
        net = IPNet(topo=CustomRouterAdvNet(link_params), use_v4=False, use_v6=True, allocate_IPs=False)
        net.start()

        # Check generated configuration
        with open("/tmp/radvd_r.cfg") as fileobj:
            cfg = fileobj.readlines()
            for line in expected_cfg:
                assert (line + "\n") in cfg, "Cannot find the line '%s' in the generated configuration:\n%s"\
                                             % (line, "".join(cfg))

        # Check reachability
        assert_connectivity(net, v6=True)

        net.stop()
    finally:
        cleanup()
Exemple #25
0
def test_static_examples(topo, connected, v4, v6):
    try:
        net = IPNet(topo=topo())
        net.start()

        if connected and v4:
            assert_connectivity(net, v6=False)
        if connected and v6:
            assert_connectivity(net, v6=True)

        for p in static_paths[topo.__name__]:
            if v4:
                assert_path(net, p, v6=False)
            if v6:
                assert_path(net, p, v6=True)

        net.stop()
    finally:
        cleanup()
Exemple #26
0
def net(request):
    cleanup()
    net = IPNet(topo=StaticAddressNet())
    net.start()

    assert_connectivity(net, v6=False)
    assert_connectivity(net, v6=True)

    paths = [
        ["h1", "r1", "r2", "h3"],
        ["h3", "r2", "r1", "h1"],
        ["h3", "r2", "r1", "h2"],
        ["h3", "r2", "r1", "h4"],
    ]
    for p in paths:
        assert_path(net, p, v6=False)
        assert_path(net, p, v6=True)

    request.addfinalizer(cleanup)
    return net
Exemple #27
0
def test_radvd_daemon_params(link_params, expected_cfg):
    try:
        net = IPNet(topo=CustomRouterAdvNet(link_params), use_v4=False,
                    use_v6=True, allocate_IPs=False)
        net.start()

        # Check generated configuration
        with open("/tmp/radvd_r.cfg") as fileobj:
            cfg = fileobj.readlines()
            for line in expected_cfg:
                assert line + "\n" in cfg,\
                    "Cannot find the line '%s' in the generated" \
                    " configuration:\n%s" % (line, "".join(cfg))

        # Check reachability
        assert_connectivity(net, v6=True)

        net.stop()
    finally:
        cleanup()
def test_ospf6_daemon_params(ospf6_params, link_params, expected_cfg, expected_paths):
    try:
        net = IPNet(topo=MinimalOSPFv3Net(ospf6_params, link_params))
        net.start()

        # Check generated configuration
        with open("/tmp/ospf6d_r1.cfg") as fileobj:
            cfg = fileobj.readlines()
            for line in expected_cfg:
                assert (line + "\n") in cfg, "Cannot find the line '%s' in the generated configuration:\n%s"\
                                             % (line, "".join(cfg))

        # Check reachability
        assert_connectivity(net, v6=True)
        for path in expected_paths:
            assert_path(net, path, v6=True)

        net.stop()
    finally:
        cleanup()
def test_ospf6_daemon_params(ospf6_params, link_params, expected_cfg, expected_paths):
    try:
        net = IPNet(topo=MinimalOSPFv3Net(ospf6_params, link_params))
        net.start()

        # Check generated configuration
        with open("/tmp/ospf6d_r1.cfg") as fileobj:
            cfg = fileobj.readlines()
            for line in expected_cfg:
                assert (line + "\n") in cfg, "Cannot find the line '%s' in the generated configuration:\n%s"\
                                             % (line, "".join(cfg))

        # Check reachability
        assert_connectivity(net, v6=True)
        for path in expected_paths:
            assert_path(net, path, v6=True)

        net.stop()
    finally:
        cleanup()
Exemple #30
0
def test_static_example():
    try:
        net = IPNet(topo=StaticAddressNet())
        net.start()

        # Check allocated addresses
        assert net["h1"].intf("h1-eth0").ip == "10.0.0.2"
        assert net["h1"].intf("h1-eth0").ip6 == "2001:1a::2"

        assert net["h2"].intf("h2-eth0").ip == "10.2.0.2"
        assert net["h2"].intf("h2-eth0").ip6 == "2001:12b::2"

        assert net["h3"].intf("h3-eth0").ip == "10.0.3.2"
        assert net["h3"].intf("h3-eth0").ip6 == "2001:3c::2"

        assert net["h4"].intf("h4-eth0").ip == "10.2.0.3"
        assert net["h4"].intf("h4-eth0").ip6 == "2001:12b::3"

        assert net["r1"].intf("lo").ip == "10.1.1.1"
        assert net["r1"].intf("lo").ip6 == "2042:1::1"
        assert net["r1"].intf("r1-eth0").ip == "10.0.0.1"
        assert net["r1"].intf("r1-eth0").ip6 == "2001:1a::1"
        assert net["r1"].intf("r1-eth1").ip == "10.1.0.1"
        assert net["r1"].intf("r1-eth1").ip6 == "2001:12::1"
        assert net["r1"].intf("r1-eth2").ip == "10.2.0.1"
        assert net["r1"].intf("r1-eth2").ip6 == "2001:12b::1"

        assert net["r2"].intf("lo").ip == "10.2.2.1"
        assert net["r2"].intf("lo").ip6 == "2042:2::1"
        assert net["r2"].intf("r2-eth0").ip == "10.1.0.2"
        assert net["r2"].intf("r2-eth0").ip6 == "2001:12::2"
        assert net["r2"].intf("r2-eth1").ip == "10.0.3.1"
        assert net["r2"].intf("r2-eth1").ip6 == "2001:3c::1"

        # Check connectivity
        assert_connectivity(net, v6=False)
        assert_connectivity(net, v6=True)

        net.stop()
    finally:
        cleanup()
Exemple #31
0
def test_ospf_daemon_params(ospf_params, link_params, exp_cfg, exp_paths):
    try:
        net = IPNet(topo=MinimalOSPFNet(ospf_params, link_params),
                    allocate_IPs=False)
        net.start()

        # Check generated configuration
        with open("/tmp/ospfd_r1.cfg") as fileobj:
            cfg = fileobj.readlines()
            for line in exp_cfg:
                assert line + "\n" in cfg,\
                    "Cannot find the line '%s' in the generated " \
                    "configuration:\n%s" % (line, "".join(cfg))

        # Check reachability and paths
        assert_connectivity(net)
        for path in exp_paths:
            assert_path(net, path)

        net.stop()
    finally:
        cleanup()