コード例 #1
0
    def runTest(self):
        s1_vlan_id = 10
        s2_vlan_id = 20
        s1_ip = '192.168.10.254'
        s2_ip = '192.168.20.254'
        ports = sorted(config["port_map"].keys())

        t1 = (Tenant('t1').segment(
            's1', 'vlan', [s1_ip], s1_vlan_id).segment_member(
                SegmentMember('s1',
                              cfg.leaf0['id']).ports([cfg.leaf0['portC'].name
                                                      ])).build())

        t2 = (Tenant('t2').segment(
            's2', 'vlan', [s2_ip], s2_vlan_id).segment_member(
                SegmentMember('s2',
                              cfg.leaf1['id']).ports([cfg.leaf1['portC'].name
                                                      ])).build())

        system_tenant = (Tenant('system', 'System').build())

        lrouter_r1 = (LogicalRouter('r1', 't1').interfaces(['s1']).build())

        lrouter_r2 = (LogicalRouter('r2', 't2').interfaces(['s2']).build())

        lrouter_system = (LogicalRouter('system').tenant_routers(
            ['t1/r1', 't2/r2']).build())

        host[0]['ip'] = '192.168.10.118'
        host[2]['ip'] = '192.168.20.103'

        h0 = Host(host[0]).set_ip()
        h2 = Host(host[2]).set_ip()

        assert ('success' == h0.ping(host[2]['ip']))
コード例 #2
0
    def runTest(self):
        s1_vlan_id = 10
        s2_vlan_id = 20
        s1_ip = '192.168.10.254'
        s2_ip = '192.168.20.254'
        ports = sorted(config["port_map"].keys())

        t1 = (Tenant('t1').segment(
            's1', 'vlan', [s1_ip], s1_vlan_id).segment_member(
                SegmentMember('s1', cfg.leaf0['id']).ports(
                    [cfg.leaf0['portC'].name])).segment_member(
                        SegmentMember('s1', cfg.leaf1['id']).ports(
                            [cfg.leaf1['portC'].name])).build())

        t2 = (Tenant('t2').segment(
            's2', 'vlan', [s2_ip], s2_vlan_id).segment_member(
                SegmentMember('s2',
                              cfg.leaf1['id']).ports([cfg.leaf0['portD'].name
                                                      ])).build())

        host[0]['ip'] = '192.168.10.118'
        host[1]['ip'] = '192.168.20.117'
        host[2]['ip'] = '192.168.10.103'

        h0 = Host(host[0]).set_ip()
        h1 = Host(host[1]).set_ip()
        h2 = Host(host[2]).set_ip()

        assert ('success' == h0.ping(host[2]['ip']))
        assert ('failure' == h0.ping(host[1]['ip']))
コード例 #3
0
ファイル: test_vrf.py プロジェクト: charleschou56/oftest
    def runTest(self):
        ports = sorted(config["port_map"].keys())

        s1_ip = '192.168.10.1'
        s2_ip = '192.168.20.1'
        ports = sorted(config["port_map"].keys())

        t1 = (Tenant('t1').segment('s1', 'vlan', [s1_ip], 100).segment_member(
            SegmentMember('s1', cfg.leaf0['id']).ports([
                cfg.leaf0['portC'].name
            ])).segment('s2', 'vlan', [s2_ip], 200).segment_member(
                SegmentMember('s2',
                              cfg.leaf1['id']).ports([cfg.leaf1['portC'].name
                                                      ])).build())

        t2 = (Tenant('t2').segment('s1', 'vlan', [s1_ip], 101).segment_member(
            SegmentMember('s1', cfg.leaf0['id']).ports([
                cfg.leaf0['portD'].name
            ])).segment('s2', 'vlan', [s2_ip], 201).segment_member(
                SegmentMember('s2',
                              cfg.leaf1['id']).ports([cfg.leaf1['portD'].name
                                                      ])).build())

        wait_for_system_stable()

        lrouter_r1 = (LogicalRouter('r1', 't1').interfaces(['s1',
                                                            's2']).build())

        wait_for_system_stable()

        lrouter_r2 = (LogicalRouter('r2', 't2').interfaces(['s1',
                                                            's2']).build())

        wait_for_system_stable()

        cfg.host0['ip'] = '192.168.10.10'
        cfg.host1['ip'] = '192.168.20.10'
        cfg.host2['ip'] = '192.168.10.20'
        cfg.host3['ip'] = '192.168.20.20'

        testhost_configuration()

        route_add(cfg.host0, '192.168.20.0', s1_ip)
        route_add(cfg.host1, '192.168.10.0', s2_ip)
        route_add(cfg.host2, '192.168.20.0', s1_ip)
        route_add(cfg.host3, '192.168.10.0', s2_ip)

        ping_result = ping_test(cfg.host0, cfg.host1['ip'])

        assert (ping_verify('64 bytes from ' + cfg.host1['ip'], ping_result))

        ping_result1 = ping_test(cfg.host2, cfg.host3['ip'])

        assert (ping_verify('64 bytes from ' + cfg.host3['ip'], ping_result1))

        lrouter_r1.destroy()
        lrouter_r2.destroy()
        t1.destroy()
        t2.destroy()
コード例 #4
0
def clear_tenant():
    response = requests.get(URL+"v1/tenants/v1",
                            cookies=COOKIES, headers=GET_HEADER)
    assert(response.status_code == 200)

    # {"tenants":[{"name":"t1","type":"Normal"}]}
    # {"tenants":[]}

    if response.json()['tenants']:
        for t in response.json()['tenants']:
            tmp_tenant = Tenant(t['name'])
            tmp_tenant.destroy()
コード例 #5
0
    def runTest(self):
        s1_vlan_id = 50
        s2_vlan_id = 100
        s1_vlan_ip = '192.168.50.1'
        s2_vlan_ip = '192.168.100.1'
        dhcp_server_ip = '192.168.100.10'
        ports = sorted(config["port_map"].keys())

        t1 = (
            Tenant('t1')
            .segment('s1', 'vlan', [s1_vlan_ip], s1_vlan_id)
            .segment_member(SegmentMember('s1', cfg.leaf0['id']).ports([cfg.leaf0['portA'].name]))
            .segment('s2', 'vlan', [s2_vlan_ip], s2_vlan_id)
            .segment_member(SegmentMember('s2', cfg.leaf1['id']).ports([cfg.leaf1['portA'].name, cfg.leaf1['portB'].name]))
            .build()
        )

        lrouter = (
            LogicalRouter('r1', 't1')
            .interfaces(['s1', 's2'])
            .build()
        )

        dhcp_relay = (
            DHCPRelay('t1', 's1')
            .servers([dhcp_server_ip])
            .build()
        )

        cfg.dhcp_server['ip'] = dhcp_server_ip
コード例 #6
0
    def runTest(self):
        s1_vlan_id = 10
        s2_vlan_id = 30
        ports = sorted(config["port_map"].keys())
        segment_ip_list = [(['192.168.10.254'], ['192.168.30.254'])]

        for (s1_ip, s2_ip) in segment_ip_list:
            t1 = (Tenant('t1').segment(
                's1', 'vlan', s1_ip, s1_vlan_id).segment_member(
                    SegmentMember('s1', cfg.leaf0['id']).ports([
                        cfg.leaf0['portC'].name
                    ])).segment('s2', 'vlan', s2_ip,
                                s2_vlan_id).segment_member(
                                    SegmentMember('s2', cfg.leaf1['id']).ports(
                                        [cfg.leaf1['portC'].name])).build())

            lrouter = (LogicalRouter('r1', 't1').interfaces(['s1',
                                                             's2']).build())

            host[0]['ip'] = '192.168.10.118'
            host[2]['ip'] = '192.168.30.63'

            h0 = Host(host[0]).set_ip()
            h2 = Host(host[2]).set_ip()

            assert ('success' == h0.ping(host[2]['ip']))
コード例 #7
0
    def runTest(self):
        s1_vlan_id = 90
        ports = sorted(config["port_map"].keys())

        cfg.leaf1['portA'].tagged(True)

        t1 = (
            Tenant('t1')
            .segment('s1', 'vlan', [], s1_vlan_id)
            .segment_member(
                SegmentMember('s1', cfg.leaf0['id'])
                .mac_based_vlan(['{}/48'.format(cfg.host0['mac'])])
            )
            .segment_member(
                SegmentMember('s1', cfg.leaf1['id'])
                .ports([cfg.leaf1['portA'].name])
            )
            .build()
        )

        pkt_from_p0_to_p2 = str(simple_tcp_packet(
            dl_vlan_enable=True,
            vlan_vid=s1_vlan_id,
            eth_dst=cfg.host2['mac'],
            eth_src=cfg.host0['mac'],
            ip_dst=cfg.host2['ip'],
            ip_src=cfg.host0['ip']
        ))

        self.dataplane.send(ports[0], pkt_from_p0_to_p2)
        verify_packet(self, pkt_from_p0_to_p2, ports[2])

        t1.destroy()
コード例 #8
0
    def runTest(self):
        t2 = (Tenant('t2').segment(
            's100', 'vlan', ["192.168.100.254"], 100).segment_member(
                SegmentMember('s1', cfg.leaf0['id']).ports([
                    cfg.leaf0['portC'].name
                ])).segment('s200', 'vlan', ["192.168.200.254"],
                            200).segment_member(
                                SegmentMember('s2', cfg.leaf0['id']).ports(
                                    [cfg.leaf1['portD'].name])).build())

        tenant_logical_router_cfg = {
            "name": "r2",
            "interfaces": ["s100", "s200"]
        }

        tlr = TenantLogicalRouterApi(
            TenantLogicalRouterCfg(tenant_logical_router_cfg))

        assert (tlr.retrieve() == [])

        tlr.create(tenant='t2')

        result = tlr.retrieve()

        assert (result[0]['name'] == tenant_logical_router_cfg['name'])
        assert (set(result[0]['interfaces']) == set(
            tenant_logical_router_cfg['interfaces']))
        assert (result[0]['tenant'] == 't2')

        tlr.delete()

        assert (tlr.retrieve() == [])
コード例 #9
0
    def runTest(self):
        s1_vlan_id = 50
        s2_vlan_id = 60
        s1_ip = '192.168.50.254'
        s2_ip = '192.168.60.254'
        ports = sorted(config["port_map"].keys())
        match_ip = '10.10.10.10'

        t1 = (Tenant('t1').segment(
            's1', 'vlan', [s1_ip], s1_vlan_id).segment_member(
                SegmentMember('s1', cfg.leaf0['id']).ports([
                    cfg.leaf0['portC'].name, cfg.leaf0['portD'].name
                ])).segment('s2', 'vlan', [s2_ip], s2_vlan_id).build())

        pr1 = (PolicyRoute('pr1').ingress_segments(['s1']).ingress_ports([
            '{}/{}'.format(cfg.leaf0['id'], cfg.leaf0['portC'].number)
        ]).action('permit').sequence_no('1').protocols(
            ['icmp']).match_ip(match_ip + '/32').nexthop('192.168.50.120'))

        lrouter = (LogicalRouter('r1', 't1').interfaces(
            ['s1', 's2']).policy_route(pr1).build())

        host[0]['ip'] = '192.168.50.118'
        host[1]['ip'] = '192.168.50.120'

        h0 = Host(host[0]).set_ip()
        h1 = Host(host[1]).set_ip()

        sr = SenderReceiver(h0, h1)

        assert ('success' == sr.sender_ping(
            match_ip,
            expected_str='{} \xe2\x86\x92 {}  ICMP 98 Echo \(ping\) request'.
            format(host[0]['ip'], match_ip)))
コード例 #10
0
ファイル: test_tenants.py プロジェクト: charleschou56/oftest
    def runTest(self):
        tenant_name = 't1'
        t1 = (Tenant(tenant_name).build())

        # query tenants
        response = requests.get(URL + 'v1/tenants/v1',
                                cookies=COOKIES,
                                headers=GET_HEADER)
        assert (response.status_code == 200)
        found = False
        for t in response.json()['tenants']:
            if t['name'] == tenant_name:
                found = True
                break
        assert (found)

        t1.destroy()

        # query and check
        response = requests.get(URL + 'v1/tenants/v1',
                                cookies=COOKIES,
                                headers=GET_HEADER)
        assert (response.status_code == 200)
        not_exist = True
        if len(response.json()) > 0:
            for t in response.json()['tenants']:
                if t['name'] == tenant_name:
                    not_exist = False
                    break
        assert (not_exist)
コード例 #11
0
    def runTest(self):
        s1_vlan_id = 50
        s2_vlan_id = 60
        s1_ip = '192.168.50.254'
        s2_ip = '192.168.60.254'
        ports = sorted(config["port_map"].keys())

        t1 = (Tenant('t1').segment(
            's1', 'vlan', [s1_ip], s1_vlan_id).segment_member(
                SegmentMember('s1', cfg.leaf0['id']).ports([
                    cfg.leaf0['portC'].name, cfg.leaf0['portD'].name
                ])).segment('s2', 'vlan', [s2_ip], s2_vlan_id).build())

        cfg.external_router0['ip'] = '192.168.50.100'
        nexthop_ip = '10.10.10.1'

        lrouter = (LogicalRouter('r1', 't1').interfaces([
            's1', 's2'
        ]).nexthop_group('n1', [cfg.external_router0['ip']]).static_route(
            'static-r1', nexthop_ip, 24, 'n1').build())

        host[0]['ip'] = '192.168.50.118'
        host[1]['ip'] = cfg.external_router0['ip']

        h0 = Host(host[0]).set_ip()
        h1 = Host(host[1]).set_ip()

        sr = SenderReceiver(h0, h1)

        assert ('success' == sr.sender_ping(
            nexthop_ip,
            expected_str='{} \xe2\x86\x92 {}   ICMP 98 Echo \(ping\) request'.
            format(host[0]['ip'], nexthop_ip)))
コード例 #12
0
    def runTest(self):
        s1_vlan_id = 22
        ports = sorted(config["port_map"].keys())

        cfg.leaf0['portA'].tagged(True)
        cfg.leaf1['portA'].tagged(True)

        t1 = (Tenant('t1').segment(
            's1', 'vlan', [], s1_vlan_id).segment_member(
                SegmentMember('s1', cfg.leaf0['id']).ports(
                    [cfg.leaf0['portA'].name])).segment_member(
                        SegmentMember('s1', cfg.leaf1['id']).ports(
                            [cfg.leaf1['portA'].name])).build())

        def test_by_packet():
            pkt_from_p0_to_p2 = str(
                simple_tcp_packet(
                    dl_vlan_enable=True,
                    vlan_vid=s1_vlan_id,
                ))

            self.dataplane.send(ports[0], pkt_from_p0_to_p2)
            verify_packet(self, pkt_from_p0_to_p2, ports[2])

        self.spine_link_down_up_verify(test_by_packet)

        t1.destroy()
コード例 #13
0
    def runTest(self):
        s1_vlan_id = 130
        s2_vlan_id = 140
        s1_ip = '192.168.130.1'
        s2_ip = '192.168.140.1'
        ports = sorted(config["port_map"].keys())

        t1 = (
            Tenant('t1')
            .segment('s1', 'vlan', [s1_ip], s1_vlan_id)
            .segment_member(
                SegmentMember('s1', cfg.leaf0['id'])
                .mac_based_vlan(['{}/48'.format(cfg.host0['mac'])])
            )
            .segment('s2', 'vlan', [s2_ip], s2_vlan_id)
            .segment_member(
                SegmentMember('s2', cfg.leaf1['id'])
                .ports([cfg.leaf1['portB'].name])
            )
            .build()
        )

        lrouter = (
            LogicalRouter('r1', 't1')
            .interfaces(['s1', 's2'])
            .build()
        )

        cfg.host0['ip'] = '192.168.130.30'
        cfg.host3['ip'] = '192.168.140.30'

        master_spine = get_master_spine(
            self.dataplane, cfg.host3, s2_ip, ports[3])
        send_icmp_echo_request(self.dataplane, cfg.host3,
                               master_spine, s2_ip, ports[3])

        pkt_from_p0_to_p3 = simple_tcp_packet(
            pktlen=68,
            dl_vlan_enable=True,
            vlan_vid=s1_vlan_id,
            eth_dst=master_spine['mac'],
            eth_src=cfg.host0['mac'],
            ip_dst=cfg.host3['ip'],
            ip_src=cfg.host0['ip']
        )

        # check connection between 2 segments
        self.dataplane.send(ports[0], str(pkt_from_p0_to_p3))

        pkt_expected = simple_tcp_packet(
            pktlen=64,
            eth_dst=cfg.host3['mac'],
            eth_src=master_spine['mac'],
            ip_dst=cfg.host3['ip'],
            ip_src=cfg.host0['ip'],
            ip_ttl=63
        )

        verify_packet(self, str(pkt_expected), ports[3])
コード例 #14
0
ファイル: test_span.py プロジェクト: charleschou56/oftest
    def runTest(self):
        ports = sorted(config["port_map"].keys())

        s1_vlan_id = 10

        t1 = (Tenant('t1').segment(
            's1', 'vlan', [], s1_vlan_id).segment_member(
                SegmentMember('s1', cfg.leaf0['id']).ports(
                    [cfg.leaf0['portB'].name])).segment_member(
                        SegmentMember('s1', cfg.leaf1['id']).ports(
                            [cfg.leaf1['portB'].name])).build())

        session_id = 1
        source_port = cfg.leaf0['portB'].number
        target_port = cfg.leaf0['portA'].number

        for direction in ['tx', 'both']:
            span = (SPAN(session_id).source(cfg.leaf0['id'], source_port,
                                            direction).target(
                                                cfg.leaf0['id'],
                                                target_port).build())

            wait_for_system_stable()

            cfg.host1['ip'] = '192.168.10.10'
            cfg.host3['ip'] = '192.168.10.20'

            pkt_from_p3_to_p1 = simple_tcp_packet(pktlen=68,
                                                  dl_vlan_enable=True,
                                                  vlan_vid=s1_vlan_id,
                                                  eth_dst=cfg.host1['mac'],
                                                  eth_src=cfg.host3['mac'],
                                                  ip_dst=cfg.host1['ip'],
                                                  ip_src=cfg.host3['ip'])

            expected_pkt_from_p1 = simple_tcp_packet(pktlen=64,
                                                     eth_dst=cfg.host1['mac'],
                                                     eth_src=cfg.host3['mac'],
                                                     ip_dst=cfg.host1['ip'],
                                                     ip_src=cfg.host3['ip'])

            # check monitor status from source to target
            self.dataplane.send(ports[3], str(pkt_from_p3_to_p1))
            # monitor port shall receive the packet
            verify_packet(self, str(pkt_from_p3_to_p1), ports[0])
            verify_packet(self, str(expected_pkt_from_p1), ports[1])

            # clear queue packet
            self.dataplane.flush()

            span.destroy()

            wait_for_system_process()

        t1.destroy()
コード例 #15
0
    def runTest(self):
        s1_vlan_id = 15
        s2_vlan_id = 25
        ports = sorted(config["port_map"].keys())

        s1_ip = ['192.168.15.1']
        s2_ip = ['192.168.25.1']

        t1 = (Tenant('t1').segment(
            's1', 'vlan', s1_ip, s1_vlan_id).segment_member(
                SegmentMember('s1', cfg.leaf0['id']).ports([
                    cfg.leaf0['portA'].name
                ])).segment('s2', 'vlan', s2_ip, s2_vlan_id).segment_member(
                    SegmentMember('s2', cfg.leaf1['id']).ports(
                        [cfg.leaf1['portA'].name])).build())

        lrouter = (LogicalRouter('r1', 't1').interfaces(['s1', 's2']).build())

        cfg.host0['ip'] = '192.168.15.30'
        cfg.host2['ip'] = '192.168.25.30'

        def test_by_packet():
            master_spine = get_master_spine(self.dataplane, cfg.host2, s2_ip,
                                            ports[2])
            send_icmp_echo_request(self.dataplane, cfg.host2, master_spine,
                                   s2_ip, ports[2])

            pkt_from_p0_to_p2 = simple_tcp_packet(pktlen=68,
                                                  dl_vlan_enable=True,
                                                  vlan_vid=s1_vlan_id,
                                                  eth_dst=master_spine['mac'],
                                                  eth_src=cfg.host0['mac'],
                                                  ip_dst=cfg.host2['ip'],
                                                  ip_src=cfg.host0['ip'])

            # check connection between 2 segments
            self.dataplane.send(ports[0], str(pkt_from_p0_to_p2))

            pkt_expected = simple_tcp_packet(pktlen=64,
                                             eth_dst=cfg.host2['mac'],
                                             eth_src=master_spine['mac'],
                                             ip_dst=cfg.host2['ip'],
                                             ip_src=cfg.host0['ip'],
                                             ip_ttl=63)

            verify_packet(self, str(pkt_expected), ports[2])

        test_by_packet()

        self.reboot_switch()

        test_by_packet()

        lrouter.destroy()
        t1.destroy()
コード例 #16
0
ファイル: test_egp_api.py プロジェクト: charleschou56/oftest
    def runTest(self):
        tenant_name = 't1'
        tenantData = Tenant(tenant_name)
        tenantData.delete_tenant(tenant_name)
        tenantData.build_tenant()

        egp_group = "g1"
        egp_cfg = {}
        egpDelData = Egp(egp_cfg)
        egpDelData.delete_configByGroup(egp_group)
        egp_cfg = {}
        egp_cfg['tenant'] = tenant_name
        egp_cfg['name'] = egp_group
        egp_cfg['mac'] = ["46:E4:3C:A4:17:C8/ff:ff:ff:ff:ff:ff"]
        egpData = Egp(egp_cfg).build_group()

        actual_port = egpData.get_group()
        chkData = actual_port["groups"][0]
        egp_mac = egp_cfg['mac'][0]
        chk_mac = chkData["macAddresses"][0]
        assert(egp_mac.lower() == chk_mac.lower()
               ), "Cannot get mac of egp config"
        assert(egp_cfg['name'] == chkData["name"]
               ), "Cannot get name of egp config"

        egpDelData.delete_configByGroup(egp_group)
        actual_port = egpData.get_group()
        assert([] == actual_port["groups"]
               ), "Cannot delete group of EGP config"
コード例 #17
0
ファイル: test_tenants.py プロジェクト: charleschou56/oftest
    def runTest(self):
        vlan_id = 3000
        ports = sorted(config["port_map"].keys())

        t1 = (Tenant('t1').segment(
            's1', 'vlan', ['192.168.1.1'], vlan_id).segment_member(
                SegmentMember('s1', cfg.leaf0['id']).ports(
                    [cfg.leaf0['portA'].name,
                     cfg.leaf0['portB'].name])).segment_member(
                         SegmentMember('s1', cfg.leaf1['id']).ports(
                             [cfg.leaf1['portA'].name])).build())

        utils.wait_for_system_stable()

        pkt_from_p0_to_p1 = simple_tcp_packet(pktlen=100,
                                              dl_vlan_enable=True,
                                              vlan_vid=vlan_id,
                                              eth_dst='90:e2:ba:24:78:12',
                                              eth_src='00:00:00:11:22:33',
                                              ip_src='192.168.1.100',
                                              ip_dst='192.168.1.101')

        pkt_from_p0_to_p2 = simple_tcp_packet(pktlen=100,
                                              dl_vlan_enable=True,
                                              vlan_vid=vlan_id,
                                              eth_dst='90:e2:ba:24:a2:70',
                                              eth_src='00:00:00:11:22:33',
                                              ip_src='192.168.1.100',
                                              ip_dst='192.168.1.110')

        pkt_from_p0_to_p3 = simple_tcp_packet(pktlen=100,
                                              dl_vlan_enable=True,
                                              vlan_vid=vlan_id,
                                              eth_dst='90:e2:ba:24:a2:72',
                                              eth_src='00:00:00:11:22:33',
                                              ip_src='192.168.1.100',
                                              ip_dst='192.168.1.111')

        self.dataplane.send(ports[0], str(pkt_from_p0_to_p1))
        verify_packet(self, str(pkt_from_p0_to_p1), ports[1])

        self.dataplane.send(ports[0], str(pkt_from_p0_to_p2))
        verify_packet(self, str(pkt_from_p0_to_p2), ports[2])

        self.dataplane.send(ports[0], str(pkt_from_p0_to_p3))
        verify_no_packet(self, str(pkt_from_p0_to_p3), ports[3])

        t1.delete_segment('s1')
        t1.destroy()
コード例 #18
0
    def runTest(self):

        t1 = (Tenant('t1').segment('s1', 'vlan', ['192.168.50.1'],
                                   '50').build())

        dhcp_relay = (DHCPRelay('t1',
                                's1').servers(['192.168.200.10']).build())

        actual_dhcp_relay = dhcp_relay.get_content()
        assert (dhcp_relay._tenant == actual_dhcp_relay['dhcpRelayServers'][0]
                ['tenant'])
        assert (dhcp_relay._segment == actual_dhcp_relay['dhcpRelayServers'][0]
                ['segment'])
        assert (dhcp_relay._servers_list ==
                actual_dhcp_relay['dhcpRelayServers'][0]['servers'])
コード例 #19
0
    def runTest(self):
        s1_vlan_id = 200
        ports = sorted(config["port_map"].keys())

        cfg.leaf1['portA'].tagged(True)

        t1 = (
            Tenant('t1')
            .segment('s1', 'vlan', [], s1_vlan_id)
            .segment_member(
                SegmentMember('s1', cfg.leaf0['id'])
                .mac_based_vlan(['{}/48'.format(cfg.host0['mac'])])
            )
            .segment_member(
                SegmentMember('s1', cfg.leaf1['id'])
                .ports([cfg.leaf1['portA'].name])
            )
            .build()
        )

        def test_by_packet():
            pkt_from_p0_to_p2 = str(simple_tcp_packet(
                dl_vlan_enable=True,
                vlan_vid=s1_vlan_id,
                eth_dst=cfg.host2['mac'],
                eth_src=cfg.host0['mac'],
                ip_dst=cfg.host2['ip'],
                ip_src=cfg.host0['ip']
            ))

            self.dataplane.send(ports[0], pkt_from_p0_to_p2)
            verify_packet(self, pkt_from_p0_to_p2, ports[2])

        test_by_packet()

        d0 = Device(cfg.leaf0['id'])
        rp_leaf0 = RemotePower(cfg.leaf0_power)
        rp_leaf0.OffOn()

        wait_for_seconds(60)

        assert d0.available == False, "d0 device's avaiable shall be false"

        links_inspect(cfg.spines, cfg.leaves)

        test_by_packet()

        t1.destroy()
コード例 #20
0
    def runTest(self):
        s1_vlan_id = 210
        ports = sorted(config["port_map"].keys())

        cfg.leaf1['portA'].tagged(True)

        t1 = (
            Tenant('t1')
            .segment('s1', 'vlan', [], s1_vlan_id)
            .segment_member(
                SegmentMember('s1', cfg.leaf0['id'])
                .mac_based_vlan(['{}/48'.format(cfg.host0['mac'])])
            )
            .segment_member(
                SegmentMember('s1', cfg.leaf1['id'])
                .ports([cfg.leaf1['portA'].name])
            )
            .build()
        )

        def test_by_packet():
            pkt_from_p0_to_p2 = str(simple_tcp_packet(
                dl_vlan_enable=True,
                vlan_vid=s1_vlan_id,
                eth_dst=cfg.host2['mac'],
                eth_src=cfg.host0['mac'],
                ip_dst=cfg.host2['ip'],
                ip_src=cfg.host0['ip']
            ))

            self.dataplane.send(ports[0], pkt_from_p0_to_p2)
            verify_packet(self, pkt_from_p0_to_p2, ports[2])

        test_by_packet()

        # save current config
        conf = Configuration()
        conf.save_as_boot_default_config(conf.get_current_json())

        os.system('docker restart mars > /dev/null')
        wait_for_seconds(100)

        test_by_packet()
コード例 #21
0
    def runTest(self):
        s1_vlan_id = 10
        ports = sorted(config["port_map"].keys())

        cfg.leaf0['portC'].tagged(True)
        cfg.leaf0['portD'].tagged(True)

        t1 = (Tenant('t1').segment(
            's1', 'vlan', [], s1_vlan_id).segment_member(
                SegmentMember('s1', cfg.leaf0['id']).ports(
                    [cfg.leaf0['portC'].name,
                     cfg.leaf0['portD'].name])).build())

        host[0]['ip'] = '192.168.2.118'
        host[1]['ip'] = '192.168.2.119'

        h0 = Host(host[0]).set_ip(vlan=10)
        h1 = Host(host[1]).set_ip(vlan=10)

        assert ('success' == h0.ping(host[1]['ip']))
コード例 #22
0
    def runTest(self):
        s1_vlan_id = 10
        s2_vlan_id = 20
        s3_vlan_id = 30
        s1_ip = '192.168.10.254'
        s2_ip = '192.168.20.254'
        s3_ip = '192.168.30.254'

        t1 = (Tenant('t1').segment(
            's1', 'vlan', [s1_ip], s1_vlan_id).segment_member(
                SegmentMember('s1', cfg.leaf0['id']).ports([
                    cfg.leaf0['portC'].name
                ])).segment('s2', 'vlan', [s2_ip], s2_vlan_id).segment_member(
                    SegmentMember('s2', cfg.leaf0['id']).ports([
                        cfg.leaf0['portD'].name
                    ])).segment_member(
                        SegmentMember('s2', cfg.leaf1['id']).ports([
                            cfg.leaf1['portC'].name
                        ])).segment(
                            's3', 'vlan', [s3_ip], s3_vlan_id).segment_member(
                                SegmentMember('s3', cfg.leaf1['id']).ports(
                                    [cfg.leaf1['portD'].name])).build())

        lrouter = (LogicalRouter('r1', 't1').interfaces(['s1', 's2',
                                                         's3']).build())

        host[0]['ip'] = '192.168.10.118'
        host[1]['ip'] = '192.168.20.117'
        host[2]['ip'] = '192.168.20.103'
        host[3]['ip'] = '192.168.30.83'

        h0 = Host(host[0]).set_ip()
        h1 = Host(host[1]).set_ip()
        h2 = Host(host[2]).set_ip()
        h3 = Host(host[3]).set_ip()

        assert ('success' == h0.ping(host[1]['ip']))
        assert ('success' == h0.ping(host[2]['ip']))
        assert ('success' == h0.ping(host[3]['ip']))
コード例 #23
0
    def runTest(self):
        vlan_id = 30
        ports = sorted(config["port_map"].keys())

        t1 = (
            Tenant('t1')
            .segment('s1', 'vlan', ['192.168.30.254'], vlan_id)
            .segment_member(SegmentMember('s1', cfg.leaf0['id']).ports([cfg.leaf0['portC'].name, cfg.leaf0['portD'].name]))
            .segment_member(SegmentMember('s1', cfg.leaf1['id']).ports([cfg.leaf1['portC'].name]))
            .build()
        )

        host[0]['ip'] = '192.168.30.1'
        host[1]['ip'] = '192.168.30.2'
        host[2]['ip'] = '192.168.30.3'

        h0 = Host(host[0]).set_ip(vlan=vlan_id)
        h1 = Host(host[1]).set_ip(vlan=vlan_id)
        h2 = Host(host[2]).set_ip(vlan=vlan_id)

        assert('success' == h0.ping(host[1]['ip']))
        assert('success' == h0.ping(host[2]['ip']))
        assert('success' == h2.ping(host[1]['ip']))
コード例 #24
0
ファイル: test_egp_api.py プロジェクト: charleschou56/oftest
    def runTest(self):
        tenant_name = 't1'
        tenantData = Tenant(tenant_name)
        tenantData.delete_tenant(tenant_name)
        tenantData.build_tenant()

        egp_group1 = "g1"
        egp_group2 = "g2"
        egp_cfg = {}
        egpDelData = Egp(egp_cfg)
        egpDelData.delete_configByGroup(egp_group1)
        egpDelData.delete_configByGroup(egp_group2)
        egp_cfg = {}
        egp_cfg['tenant'] = tenant_name
        egp_cfg['name'] = egp_group1
        egp_cfg['mac'] = ["46:E4:3C:A4:17:C8/ff:ff:ff:ff:ff:ff"]
        egpData = Egp(egp_cfg).build_group()
        actual_port = egpData.get_groupByName(egp_group1)
        egp_mac = egp_cfg['mac'][0]
        chk_mac = actual_port["macAddresses"][0]
        assert(egp_mac.lower() == chk_mac.lower()
               ), "Cannot get mac of egp config"
        assert(egp_cfg['name'] == actual_port["name"]
               ), "Cannot get name of egp config"

        egp_cfg = {}
        egp_cfg['tenant'] = tenant_name
        egp_cfg['name'] = egp_group2
        egp_cfg['mac'] = ["00:00:00:11:22:33/FF:FF:FF:FF:FF:FF"]
        egpData = Egp(egp_cfg).build_group()
        actual_port = egpData.get_groupByName(egp_group2)
        egp_mac = egp_cfg['mac'][0]
        chk_mac = actual_port["macAddresses"][0]
        assert(egp_mac.lower() == chk_mac.lower()
               ), "Cannot get mac of egp config"
        assert(egp_cfg['name'] == actual_port["name"]
               ), "Cannot get name of egp config"
コード例 #25
0
    def runTest(self):
        ports = sorted(config["port_map"].keys())

        s1_vlan_id = 58
        s2_vlan_id = 108
        s1_vlan_ip = '192.168.58.1'
        s2_vlan_ip = '192.168.108.1'
        dhcp_server_ip = '192.168.108.20'
        allocated_ip = '192.168.58.51'

        t1 = (Tenant('t1').segment(
            's1', 'vlan', [s1_vlan_ip], s1_vlan_id).segment_member(
                SegmentMember('s1', cfg.leaf0['id']).ports([
                    cfg.leaf0['portA'].name
                ])).segment('s2', 'vlan', [s2_vlan_ip],
                            s2_vlan_id).segment_member(
                                SegmentMember('s2', cfg.leaf1['id']).ports([
                                    cfg.leaf1['portA'].name,
                                    cfg.leaf1['portB'].name
                                ])).build())

        lrouter = (LogicalRouter('r1', 't1').interfaces(['s1', 's2']).build())

        dhcp_relay = (DHCPRelay('t1', 's1').servers([dhcp_server_ip]).build())

        cfg.dhcp_server['ip'] = dhcp_server_ip

        def test_by_packet():
            spine = get_master_spine(self.dataplane, cfg.dhcp_server,
                                     s1_vlan_ip, ports[3])
            send_icmp_echo_request(self.dataplane, cfg.dhcp_server, spine,
                                   s2_vlan_ip, ports[3])

            dhcp_pkt = DHCP_PKT()

            # verify dhcp discover
            dhcp_discover = dhcp_pkt.generate_discover_pkt(cfg.host0)
            expected_dhcp_discover = dhcp_pkt.generate_expected_discover_pkt(
                spine, cfg.dhcp_server, cfg.host0, s1_vlan_ip, s2_vlan_ip)

            self.dataplane.send(ports[0], str(dhcp_discover))
            verify_packet(self, str(expected_dhcp_discover), ports[3])

            # verify dhcp offer
            dhcp_offer = dhcp_pkt.generate_offer_pkt(spine, cfg.dhcp_server,
                                                     cfg.host0, s1_vlan_ip,
                                                     allocated_ip)
            expected_dhcp_offer = dhcp_pkt.generate_expected_offer_pkt(
                spine, cfg.dhcp_server, cfg.host0, s1_vlan_ip, allocated_ip)

            self.dataplane.send(ports[3], str(dhcp_offer))
            verify_packet(self, str(expected_dhcp_offer), ports[0])

            # verify dhcp request
            dhcp_request = dhcp_pkt.generate_request_pkt(
                cfg.dhcp_server, cfg.host0, allocated_ip)
            expected_dhcp_request = dhcp_pkt.generate_expected_request_pkt(
                spine, cfg.dhcp_server, cfg.host0, s1_vlan_ip, s2_vlan_ip,
                allocated_ip)

            self.dataplane.send(ports[0], str(dhcp_request))
            verify_packet(self, str(expected_dhcp_request), ports[3])

            # verify dhcp ack
            dhcp_ack = dhcp_pkt.generate_ack_pkt(spine, cfg.dhcp_server,
                                                 cfg.host0, s1_vlan_ip,
                                                 allocated_ip)
            expected_dhcp_ack = dhcp_pkt.generate_expected_ack_pkt(
                spine, cfg.dhcp_server, cfg.host0, s1_vlan_ip, allocated_ip)

            self.dataplane.send(ports[3], str(dhcp_ack))
            verify_packet(self, str(expected_dhcp_ack), ports[0])

        self.spine_link_down_up_verify(test_by_packet)

        dhcp_relay.destroy()
        lrouter.destroy()
        t1.destroy()
コード例 #26
0
    def runTest(self):
        tenant_name = 't1'
        segment_name = "s2"
        tenantData = Tenant(tenant_name)
        tenantData.delete_tenant(tenant_name)
        time.sleep(5)
        tenantData.build_tenant()
        segment_cfg = {
            "name": segment_name,
            "type": "vlan",
            "vlan_id": "2",
            "ip_address": []
        }
        tenantData.segment(name=segment_cfg["name"],
                           type=segment_cfg["type"],
                           vlan_id=segment_cfg["vlan_id"],
                           ip_address=segment_cfg["ip_address"])
        tenantData.build_segment()
        segmentData = tenantData.get_segmentByTenant(tenant_name)
        segmentData = segmentData["tenantSegments"][0]
        assert (segment_cfg['name'] == segmentData['name'])
        assert (segment_cfg['type'] == segmentData['type'])
        assert (segment_cfg['vlan_id'] == str(segmentData['value']))
        #print("debug: cfg.leaf0['portA'].name ", cfg.leaf0['portA'].name)
        SegmentMemberData = tenantData.segment_member(
            SegmentMember(segment_name,
                          cfg.leaf0['id']).ports([cfg.leaf0['portA'].name]))
        ## SegmentMemberData = tenantData.segment_member(SegmentMemberData)
        tenantData.build_segment()

        actual_port = tenantData.get_segmentMemberById(tenant_name,
                                                       segment_name,
                                                       cfg.leaf0['id'])
        assert (cfg.leaf0['portA'].name == actual_port["segment_members"][0]
                ["ports"][0])
        endpoint_cfg = {}
        endpoint_cfg['tenant'] = tenant_name
        endpoint_cfg['segment'] = segment_name
        endpoint_cfg['mac'] = "46:E4:3C:A4:17:C8"
        endpoint_cfg['ip_addresses'] = ["127.0.0.1"]
        endpoint_cfg['locations'] = [{
            "device_id": cfg.leaf0['id'],
            "port": str(cfg.leaf0["front_port_A"])
        }]
        endpointData = Endpoint(endpoint_cfg).build()
        time.sleep(5)
        actual_port = endpointData.get_configBySegment_Mac(
            segment_name, endpoint_cfg['mac'])

        chkData = actual_port["hosts"][0]
        assert (endpoint_cfg['mac'] == chkData["mac"]
                ), "Cannot get mac of endpoint config"
        assert (endpoint_cfg['ip_addresses'] == chkData["ip_addresses"]
                ), "Cannot get ip_addresses of endpoint config"
        tenantData.delete_tenant(tenant_name)
コード例 #27
0
    def runTest(self):
        ports = sorted(config["port_map"].keys())

        d_ip = "192.168.1.111"
        t_ip = "192.168.1.10"
        vlan_id = 2
        tenant_name = 't1'
        segment_name = "s1"
        tenantData = Tenant(tenant_name)
        tenantData.delete_tenant(tenant_name)
        time.sleep(3)
        tenantData.build_tenant()
        segment_cfg = {
            "name": segment_name,
            "type": "vlan",
            "vlan_id": "{}".format(vlan_id),
            "ip_address": ["{}".format(d_ip)]
        }
        tenantData.segment(name=segment_cfg["name"],
                           type=segment_cfg["type"],
                           vlan_id=segment_cfg["vlan_id"],
                           ip_address=segment_cfg["ip_address"])
        tenantData.build_segment()
        time.sleep(5)
        segmentData = tenantData.get_segmentByTenant(tenant_name)
        segmentData = segmentData["tenantSegments"][0]
        assert (segment_cfg['name'] == segmentData['name'])
        assert (segment_cfg['type'] == segmentData['type'])
        assert (segment_cfg['vlan_id'] == str(segmentData['value']))
        a_name = cfg.leaf0['portA'].name.replace("untag", "tag")
        b_name = cfg.leaf0['portB'].name.replace("untag", "tag")
        SegmentMemberData = tenantData.segment_member(
            SegmentMember(segment_name,
                          cfg.leaf0['id']).ports([a_name, b_name]))
        tenantData.build_segment()
        time.sleep(5)

        actual_port = tenantData.get_segmentMemberById(tenant_name,
                                                       segment_name,
                                                       cfg.leaf0['id'])
        assert (
            a_name
            in actual_port["segment_members"][0]["ports"]), "Not found port A"
        assert (
            b_name
            in actual_port["segment_members"][0]["ports"]), "Not found port A"

        # manual setup mac
        manualMac = "46:E4:3C:A4:17:C8"
        manualIp = ["127.0.0.1"]
        endpoint_cfg = {}
        endpoint_cfg['tenant'] = tenant_name
        endpoint_cfg['segment'] = segment_name
        endpoint_cfg['mac'] = manualMac
        endpoint_cfg['ip_addresses'] = manualIp
        endpoint_cfg['locations'] = [{
            "device_id": cfg.leaf0['id'],
            "port": str(cfg.leaf0["front_port_A"])
        }]
        endpointData = Endpoint(endpoint_cfg).build()
        time.sleep(3)
        actual_port = endpointData.get_configBySegment_Mac(
            segment_name, endpoint_cfg['mac'])
        chkData = actual_port["hosts"][0]
        assert (endpoint_cfg['mac'] == chkData["mac"]
                ), "Cannot get mac of endpoint config(before reboot)"
        assert (endpoint_cfg['ip_addresses'] == chkData["ip_addresses"]
                ), "Cannot get ip_addresses of endpoint config(before reboot)"

        tenant_logical_router_cfg = {"name": "r1", "interfaces": ["s1"]}
        tlr = TenantLogicalRouterApi(
            TenantLogicalRouterCfg(tenant_logical_router_cfg))
        assert (tlr.retrieve() == [])

        tlr.create(tenant='t1')
        result = tlr.retrieve()
        assert (result[0]['name'] == tenant_logical_router_cfg['name'])
        assert (
            result[0]['interfaces'] == tenant_logical_router_cfg['interfaces'])
        assert (result[0]['tenant'] == 't1')
        # tlr.delete()
        time.sleep(10)

        pkt_from_p0_to_dut = simple_arp_packet(
            pktlen=68,
            vlan_vid=vlan_id,
            eth_dst="ff:ff:ff:ff:ff:ff",
            eth_src=cfg.host0['mac'],
            ip_snd=t_ip,
            ip_tgt=d_ip,
            hw_snd=cfg.host0['mac'],
            hw_tgt='00:00:00:00:00:00',
        )
        expected_pkt = simple_eth_vlan_type_packet(
            pktlen=12,
            eth_type=0x0806,
            vlan_vid=vlan_id,
            eth_dst=cfg.host0['mac'],
            eth_src=cfg.spine0['mac'],
        )
        for i in range(15):
            self.dataplane.send(ports[0], str(pkt_from_p0_to_dut))
            wait_for_seconds(1)
        verify_packet(self, str(expected_pkt), ports[0])
        # verify_no_packet(self, str(expected_pkt), ports[1])
        time.sleep(50)

        endpoint_cfg = {}
        endpointData = Endpoint(endpoint_cfg)
        actual_port = endpointData.get()
        for portNum in actual_port["hosts"]:
            if portNum["mac"] == cfg.host0['mac']:
                # assert(t_ip == portNum["ip_addresses"][0]
                #       ), "Cannot get ip_addresses of endpoint config"
                if t_ip == portNum["ip_addresses"][0]:
                    break
            elif portNum["mac"] == actual_port["hosts"][
                    len(actual_port["hosts"]) - 1]["mac"]:
                assert (False), "Not found endpoint mac error"

        expected_pkt = simple_eth_vlan_packet(
            pktlen=64,
            vlan_vid=vlan_id,
            eth_dst="ff:ff:ff:ff:ff:ff",
            eth_src=cfg.host1['mac'],
        )
        for i in range(15):
            self.dataplane.send(ports[1], str(expected_pkt))
            wait_for_seconds(1)
        verify_packet(self, str(expected_pkt), ports[0])
        time.sleep(50)
        actual_port = endpointData.get()
        for portNum in actual_port["hosts"]:
            if portNum["mac"] == cfg.host1['mac']:
                # assert('0.0.0.0' == portNum["ip_addresses"][0]
                #       ), "Cannot get ip_addresses of endpoint config"
                if '0.0.0.0' == portNum["ip_addresses"][0]:
                    break
            elif portNum["mac"] == actual_port["hosts"][
                    len(actual_port["hosts"]) - 1]["mac"]:
                assert (False), "Not found endpoint mac error(no ip)"

        # reboot
        rebootTest = RebootSwitch(cfg.leaf0['id'])
        rebootTest.reboot()
        rebootTest = RebootSwitch(cfg.leaf1['id'])
        rebootTest.reboot()
        time.sleep(330)

        expected_pkt = simple_eth_vlan_packet(
            pktlen=64,
            vlan_vid=vlan_id,
            eth_dst="ff:ff:ff:ff:ff:ff",
            eth_src=cfg.host1['mac'],
        )
        for i in range(15):
            self.dataplane.send(ports[1], str(expected_pkt))
            wait_for_seconds(1)
        verify_packet(self, str(expected_pkt), ports[0])
        time.sleep(50)
        actual_port = endpointData.get()
        for portNum in actual_port["hosts"]:
            if portNum["mac"] == cfg.host1['mac']:
                assert ('0.0.0.0' == portNum["ip_addresses"][0]
                        ), "Cannot get ip_addresses of endpoint config"
                break
            elif portNum["mac"] == actual_port["hosts"][
                    len(actual_port["hosts"]) - 1]["mac"]:
                assert (False), "Not found endpoint mac error(no ip)"

        actual_port = endpointData.get_configBySegment_Mac(
            segment_name, manualMac)
        chkData = actual_port["hosts"][0]
        assert (manualMac == chkData["mac"]
                ), "Cannot get mac of endpoint config(after reboot)"
        assert (manualIp == chkData["ip_addresses"]
                ), "Cannot get ip_addresses of endpoint config(after reboot)"

        # sned packet
        pkt_from_p0_to_dut = simple_arp_packet(
            pktlen=68,
            vlan_vid=vlan_id,
            eth_dst="ff:ff:ff:ff:ff:ff",
            eth_src=cfg.host0['mac'],
            ip_snd=t_ip,
            ip_tgt=d_ip,
            hw_snd=cfg.host0['mac'],
            hw_tgt='00:00:00:00:00:00',
        )

        expected_pkt = simple_eth_vlan_type_packet(
            pktlen=12,
            eth_type=0x0806,
            vlan_vid=vlan_id,
            eth_dst=cfg.host0['mac'],
            eth_src=cfg.spine0['mac'],
        )
        for i in range(15):
            self.dataplane.send(ports[0], str(pkt_from_p0_to_dut))
            wait_for_seconds(1)
        #verify_packet(self, str(expected_pkt), ports[0])
        #verify_no_packet(self, str(expected_pkt), ports[1])
        time.sleep(50)

        endpoint_cfg = {}
        endpointData = Endpoint(endpoint_cfg)
        actual_port = endpointData.get()
        for portNum in actual_port["hosts"]:
            if portNum["mac"] == cfg.host0['mac']:
                assert (
                    t_ip == portNum["ip_addresses"][0]
                ), "Cannot get ip_addresses of endpoint config(after reboot)"
                break
            elif portNum["mac"] == actual_port["hosts"][
                    len(actual_port["hosts"]) - 1]["mac"]:
                assert (False), "Not found endpoint mac error(after reboot)"

        endpoint_cfg = {}
        endpointData = Endpoint(endpoint_cfg)
        endpointData.delete_configByTenant_Segment_Mac(tenant_name,
                                                       segment_name,
                                                       cfg.host0['mac'])
        endpointData.delete_configByTenant_Segment_Mac(tenant_name,
                                                       segment_name,
                                                       cfg.host1['mac'])
        endpointData.delete_configByTenant_Segment_Mac("unknown", "unknown",
                                                       cfg.host0['mac'])
        endpointData.delete_configByTenant_Segment_Mac("unknown", "unknown",
                                                       cfg.host1['mac'])

        tlr.delete()
        tenantData = Tenant(tenant_name)
        tenantData.delete_segment(segment_name)
        tenantData.delete_tenant(tenant_name)
コード例 #28
0
ファイル: test_tenants.py プロジェクト: charleschou56/oftest
    def runTest(self):
        access_vlan_id_pairs_list = [(20, 20), (20, 30)]
        for leaf0_access_vlan_id, leaf1_access_vlan_id in access_vlan_id_pairs_list:
            setup_configuration()

            uplink_segment_name = ['leaf0spine0', 'leaf1spine0']
            access_vlan_id = 20
            vni = 1000
            ports = sorted(config["port_map"].keys())

            uplink_segment_leaf0spine0 = (UplinkSegment(
                'leaf0spine0').device_id(cfg.leaf0['id']).vlan(200).ports([
                    "49/tag"
                ]).gateway("192.168.200.2").gateway_mac(
                    cfg.spine0['mac']).ip_address("192.168.200.1/24").build())

            uplink_segment_leaf1spine0 = (UplinkSegment(
                'leaf1spine0').device_id(cfg.leaf1['id']).vlan(100).ports([
                    "49/tag"
                ]).gateway("192.168.100.2").gateway_mac(
                    cfg.spine0['mac']).ip_address("192.168.100.1/24").build())

            utils.wait_for_system_stable()

            t1 = (Tenant('t1').segment('s1', 'vxlan', [], vni).access_port(
                's1', 'leaf0access',
                cfg.leaf0['id'], 48, leaf0_access_vlan_id).access_port(
                    's1', 'leaf1access', cfg.leaf1['id'],
                    48, leaf1_access_vlan_id).network_port(
                        's1', 'leaf0network', ['192.168.100.1'],
                        uplink_segment_name[0]).network_port(
                            's1', 'leaf1network', ['192.168.200.1'],
                            uplink_segment_name[1]).build())

            utils.wait_for_system_stable()
            # utils.wait_for_system_stable()

            utils.wait_for_system_stable()

            pkt_from_p1_to_p3 = simple_tcp_packet(
                pktlen=100,
                dl_vlan_enable=True,
                vlan_vid=leaf0_access_vlan_id,
                eth_dst='00:00:00:44:55:66',
                eth_src='00:00:00:11:22:33',
                ip_src='192.168.10.10',
                ip_dst='192.168.10.20')

            # TODO: check test procedure for vlan 30
            if leaf1_access_vlan_id == 30:
                for i in range(5):
                    self.dataplane.send(ports[1], str(pkt_from_p1_to_p3))
                    wait_for_system_process()
                    print i
            else:
                self.dataplane.send(ports[1], str(pkt_from_p1_to_p3))

            verify_packet(self, str(pkt_from_p1_to_p3), ports[3])

            uplink_segment_leaf0spine0.destroy()
            uplink_segment_leaf1spine0.destroy()

            t1.delete_segment('s1')
            t1.destroy()

            # clear queue packet
            self.dataplane.flush()
コード例 #29
0
    def runTest(self):
        ports = sorted(config["port_map"].keys())

        d_ip = "192.168.1.111"
        t_ip = "192.168.1.10"
        vlan_id = 2

        tenant_name = 't1'
        segment_name = "s1"
        tenantData = Tenant(tenant_name)
        tenantData.delete_tenant(tenant_name)
        time.sleep(3)
        tenantData.build_tenant()
        segment_cfg = {
            "name": segment_name,
            "type": "vlan",
            "vlan_id": "{}".format(vlan_id),
            "ip_address": ["{}".format(d_ip)]
        }
        tenantData.segment(name=segment_cfg["name"],
                           type=segment_cfg["type"],
                           vlan_id=segment_cfg["vlan_id"],
                           ip_address=segment_cfg["ip_address"])
        tenantData.build_segment()
        time.sleep(5)
        segmentData = tenantData.get_segmentByTenant(tenant_name)
        segmentData = segmentData["tenantSegments"][0]
        assert (segment_cfg['name'] == segmentData['name'])
        assert (segment_cfg['type'] == segmentData['type'])
        assert (segment_cfg['vlan_id'] == str(segmentData['value']))
        a_name = cfg.leaf0['portA'].name.replace("untag", "tag")
        b_name = cfg.leaf0['portB'].name.replace("untag", "tag")
        SegmentMemberData = tenantData.segment_member(
            SegmentMember(segment_name,
                          cfg.leaf0['id']).ports([a_name, b_name]))
        tenantData.build_segment()
        time.sleep(5)

        tenant_logical_router_cfg = {"name": "r1", "interfaces": ["s1"]}
        tlr = TenantLogicalRouterApi(
            TenantLogicalRouterCfg(tenant_logical_router_cfg))
        assert (tlr.retrieve() == [])

        tlr.create(tenant='t1')
        result = tlr.retrieve()
        assert (result[0]['name'] == tenant_logical_router_cfg['name'])
        assert (
            result[0]['interfaces'] == tenant_logical_router_cfg['interfaces'])
        assert (result[0]['tenant'] == 't1')
        time.sleep(10)

        pkt_from_p0_to_dut = simple_arp_packet(
            pktlen=68,
            vlan_vid=vlan_id,
            eth_dst="ff:ff:ff:ff:ff:ff",
            eth_src=cfg.host0['mac'],
            ip_snd=t_ip,
            ip_tgt=d_ip,
            hw_snd=cfg.host0['mac'],
            hw_tgt='00:00:00:00:00:00',
        )
        expected_pkt = simple_eth_vlan_type_packet(
            pktlen=12,
            eth_type=0x0806,
            vlan_vid=vlan_id,
            eth_dst=cfg.host0['mac'],
            eth_src=cfg.spine0['mac'],
        )
        for i in range(15):
            self.dataplane.send(ports[0], str(pkt_from_p0_to_dut))
            wait_for_seconds(1)
        verify_packet(self, str(expected_pkt), ports[0])
        # verify_no_packet(self, str(expected_pkt), ports[1])
        time.sleep(50)

        endpoint_cfg = {}
        endpointData = Endpoint(endpoint_cfg)
        actual_port = endpointData.get()
        for portNum in actual_port["hosts"]:
            if portNum["mac"] == cfg.host0['mac']:
                assert (t_ip == portNum["ip_addresses"][0]
                        ), "Cannot get ip_addresses of endpoint config"
                break
            elif portNum["mac"] == actual_port["hosts"][
                    len(actual_port["hosts"]) - 1]["mac"]:
                assert (False), "Not found endpoint mac error"

        expected_pkt = simple_eth_vlan_packet(
            pktlen=64,
            vlan_vid=vlan_id,
            eth_dst="ff:ff:ff:ff:ff:ff",
            eth_src=cfg.host1['mac'],
        )
        for i in range(15):
            self.dataplane.send(ports[1], str(expected_pkt))
            wait_for_seconds(1)
        verify_packet(self, str(expected_pkt), ports[0])
        time.sleep(50)
        actual_port = endpointData.get()
        for portNum in actual_port["hosts"]:
            if portNum["mac"] == cfg.host1['mac']:
                assert ('0.0.0.0' == portNum["ip_addresses"][0]
                        ), "Cannot get ip_addresses of endpoint config"
                break
            elif portNum["mac"] == actual_port["hosts"][
                    len(actual_port["hosts"]) - 1]["mac"]:
                assert (False), "Not found endpoint mac error(no ip)"

        endpoint_cfg = {}
        endpointData = Endpoint(endpoint_cfg)
        endpointData.delete_configByTenant_Segment_Mac(tenant_name,
                                                       segment_name,
                                                       cfg.host0['mac'])
        endpointData.delete_configByTenant_Segment_Mac(tenant_name,
                                                       segment_name,
                                                       cfg.host1['mac'])
        tlr.delete()
コード例 #30
0
    def runTest(self):
        ports = sorted(config["port_map"].keys())

        case_item_list = [
            # s1_vlan_id s2_vlan_id  s1_vlan_ip       s2_vlan_ip         dhcp_server_ip      allocated_ip
            (50,        100,        '192.168.50.1', '192.168.100.1',
             '192.168.100.20',   '192.168.50.51'),
            (60,        200,        '192.168.60.1',
             '192.168.200.1',    '192.168.200.20',   '192.168.60.51')
        ]

        for case_item in case_item_list:
            s1_vlan_id = case_item[0]
            s2_vlan_id = case_item[1]
            s1_vlan_ip = case_item[2]
            s2_vlan_ip = case_item[3]
            dhcp_server_ip = case_item[4]
            allocated_ip = case_item[5]

            t1 = (
                Tenant('t1')
                .segment('s1', 'vlan', [s1_vlan_ip], s1_vlan_id)
                .segment_member(SegmentMember('s1', cfg.leaf0['id']).ports([cfg.leaf0['portA'].name]))
                .segment('s2', 'vlan', [s2_vlan_ip], s2_vlan_id)
                .segment_member(SegmentMember('s2', cfg.leaf1['id']).ports([cfg.leaf1['portA'].name, cfg.leaf1['portB'].name]))
                .build()
            )

            lrouter = (
                LogicalRouter('r1', 't1')
                .interfaces(['s1', 's2'])
                .build()
            )

            dhcp_relay = (
                DHCPRelay('t1', 's1')
                .servers([dhcp_server_ip])
                .build()
            )

            cfg.dhcp_server['ip'] = dhcp_server_ip

            spine = get_master_spine(
                self.dataplane, cfg.dhcp_server, s1_vlan_ip, ports[3])
            send_icmp_echo_request(
                self.dataplane, cfg.dhcp_server, spine, s2_vlan_ip, ports[3])

            dhcp_pkt = DHCP_PKT()

            # verify dhcp discover
            dhcp_discover = dhcp_pkt.generate_discover_pkt(cfg.host0)
            expected_dhcp_discover = dhcp_pkt.generate_expected_discover_pkt(
                spine, cfg.dhcp_server, cfg.host0, s1_vlan_ip, s2_vlan_ip)

            self.dataplane.send(ports[0], str(dhcp_discover))
            verify_packet(self, str(expected_dhcp_discover), ports[3])

            # verify dhcp offer
            dhcp_offer = dhcp_pkt.generate_offer_pkt(
                spine, cfg.dhcp_server, cfg.host0, s1_vlan_ip, allocated_ip)
            expected_dhcp_offer = dhcp_pkt.generate_expected_offer_pkt(
                spine, cfg.dhcp_server, cfg.host0, s1_vlan_ip, allocated_ip)

            self.dataplane.send(ports[3], str(dhcp_offer))
            verify_packet(self, str(expected_dhcp_offer), ports[0])

            # verify dhcp request
            dhcp_request = dhcp_pkt.generate_request_pkt(
                cfg.dhcp_server, cfg.host0, allocated_ip)
            expected_dhcp_request = dhcp_pkt.generate_expected_request_pkt(
                spine, cfg.dhcp_server, cfg.host0, s1_vlan_ip, s2_vlan_ip, allocated_ip)

            self.dataplane.send(ports[0], str(dhcp_request))
            verify_packet(self, str(expected_dhcp_request), ports[3])

            # verify dhcp ack
            dhcp_ack = dhcp_pkt.generate_ack_pkt(
                spine, cfg.dhcp_server, cfg.host0, s1_vlan_ip, allocated_ip)
            expected_dhcp_ack = dhcp_pkt.generate_expected_ack_pkt(
                spine, cfg.dhcp_server, cfg.host0, s1_vlan_ip, allocated_ip)

            self.dataplane.send(ports[3], str(dhcp_ack))
            verify_packet(self, str(expected_dhcp_ack), ports[0])

            dhcp_relay.destroy()
            lrouter.destroy()
            t1.destroy()

            # clear queue packet
            self.dataplane.flush()

            wait_for_system_stable()