예제 #1
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()
예제 #2
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() == [])
    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()
예제 #4
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
예제 #5
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']))
예제 #6
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('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,
                                cfg.leaf1['portD'].name
                            ])).build())

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

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

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

        assert ('success' == h0.ping(host[1]['ip']))
        assert ('success' == h0.ping(host[2]['ip']))
예제 #7
0
    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()
예제 #8
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])
예제 #9
0
    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()
예제 #10
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()
예제 #11
0
    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()
예제 #12
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()
예제 #13
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)))
예제 #14
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)))
예제 #15
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()
예제 #16
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)
예제 #17
0
    def runTest(self):
        s1_vlan_id = 20
        ports = sorted(config["port_map"].keys())

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

        t1 = (Tenant('t1').segment(
            's1', 'vlan', [], 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())

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

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

        assert ('success' == h0.ping(host[2]['ip']))
예제 #18
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']))
예제 #19
0
    def runTest(self):
        ports = sorted(config["port_map"].keys())

        s1_vlan_id = 50
        s2_vlan_id = 100
        s3_vlan_id = 60
        s4_vlan_id = 200
        s1_vlan_ip = '192.168.50.1'
        s2_vlan_ip = '192.168.100.1'
        s3_vlan_ip = '192.168.60.1'
        s4_vlan_ip = '192.168.200.1'
        dhcp_server_ip = '192.168.200.10'
        allocated_ip = '192.168.50.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.leaf0['id']).ports([cfg.leaf0['portB'].name]))
            .build()
        )

        t2 = (
            Tenant('t2')
            .segment('s3', 'vlan', [s3_vlan_ip], s3_vlan_id)
            .segment_member(SegmentMember('s3', cfg.leaf1['id']).ports([cfg.leaf1['portA'].name]))
            .segment('s4', 'vlan', [s4_vlan_ip], s4_vlan_id)
            .segment_member(SegmentMember('s4', cfg.leaf1['id']).ports([cfg.leaf1['portB'].name]))
            .build()
        )

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

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

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

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

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

        cfg.dhcp_server['ip'] = dhcp_server_ip

        # TODO: this case needs VRF feature
        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, s4_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, s4_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_r1.destroy()
        lrouter_r2.destroy()
        lrouter_system.destroy()
        system_tenant.destroy()
        t1.destroy()
        t2.destroy()
예제 #20
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()
    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()
예제 #22
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)
예제 #23
0
    def runTest(self):
        ports = sorted(config["port_map"].keys())

        d_ip1 = "192.168.1.111"
        t_ip1 = "192.168.1.10"
        vlan_id1 = 2

        tenant_name1 = 't1'
        segment_name1 = "s1"
        tenantData = Tenant(tenant_name1)
        tenantData.delete_tenant(tenant_name1)
        time.sleep(3)
        tenantData.build_tenant()
        segment_cfg = {
            "name": segment_name1,
            "type": "vlan",
            "vlan_id": "{}".format(vlan_id1),
            "ip_address": ["{}".format(d_ip1)]
        }
        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(3)
        segmentData = tenantData.get_segmentByTenant(tenant_name1)
        segmentData = segmentData["tenantSegments"][0]
        assert (segment_cfg['name'] == segmentData['name'])
        assert (segment_cfg['type'] == segmentData['type'])
        assert (segment_cfg['vlan_id'] == str(segmentData['value']))
        leaf0_a_name = cfg.leaf0['portA'].name.replace("untag", "tag")
        SegmentMemberData = tenantData.segment_member(
            SegmentMember(segment_name1,
                          cfg.leaf0['id']).ports([leaf0_a_name]))
        tenantData.build_segment()
        time.sleep(3)

        d_ip2 = "192.168.3.111"
        t_ip2 = "192.168.3.10"
        vlan_id2 = 3

        tenant_name2 = 't2'
        segment_name2 = "s2"
        tenantData = Tenant(tenant_name2)
        tenantData.delete_tenant(tenant_name2)
        time.sleep(3)
        tenantData.build_tenant()
        segment_cfg = {
            "name": segment_name2,
            "type": "vlan",
            "vlan_id": "{}".format(vlan_id2),
            "ip_address": ["{}".format(d_ip2)]
        }
        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(3)
        segmentData = tenantData.get_segmentByTenant(tenant_name2)
        segmentData = segmentData["tenantSegments"][0]
        assert (segment_cfg['name'] == segmentData['name'])
        assert (segment_cfg['type'] == segmentData['type'])
        assert (segment_cfg['vlan_id'] == str(segmentData['value']))
        leaf1_a_name = cfg.leaf1['portA'].name.replace("untag", "tag")
        SegmentMemberData = tenantData.segment_member(
            SegmentMember(segment_name2,
                          cfg.leaf1['id']).ports([leaf1_a_name]))
        tenantData.build_segment()
        time.sleep(3)

        tenant_logical_router_cfg1 = {"name": "r1", "interfaces": ["s1"]}
        tlr1 = TenantLogicalRouterApi(
            TenantLogicalRouterCfg(tenant_logical_router_cfg1))

        tenant_logical_router_cfg2 = {"name": "r2", "interfaces": ["s2"]}
        tlr2 = TenantLogicalRouterApi(
            TenantLogicalRouterCfg(tenant_logical_router_cfg2))

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

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

        tlr2.create(tenant='t2')
        result = tlr2.retrieve()
        for chkData in result:
            if chkData["name"] == tenant_logical_router_cfg2['name']:
                #assert(result[0]['name'] == tenant_logical_router_cfg2['name'])
                assert (chkData['interfaces'] ==
                        tenant_logical_router_cfg2['interfaces'])
                assert (chkData['tenant'] == 't2')
            elif chkData["name"] == result[len(result) - 1]["name"]:
                assert (False), "Not found logical route name"
        time.sleep(10)

        # host0 ping
        pkt_from_p0_to_dut = simple_arp_packet(pktlen=68,
                                               vlan_vid=vlan_id1,
                                               eth_dst="ff:ff:ff:ff:ff:ff",
                                               eth_src=cfg.host0['mac'],
                                               ip_snd=t_ip1,
                                               ip_tgt=d_ip1,
                                               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_id1,
            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])

        # host1 ping
        pkt_from_p2_to_dut = simple_arp_packet(pktlen=68,
                                               vlan_vid=vlan_id2,
                                               eth_dst="ff:ff:ff:ff:ff:ff",
                                               eth_src=cfg.host2['mac'],
                                               ip_snd=t_ip2,
                                               ip_tgt=d_ip2,
                                               hw_snd=cfg.host2['mac'],
                                               hw_tgt='00:00:00:00:00:00')

        expected_pkt = simple_eth_vlan_type_packet(
            pktlen=12,
            eth_type=0x0806,
            vlan_vid=vlan_id2,
            eth_dst=cfg.host2['mac'],
            eth_src=cfg.spine0['mac'],
        )

        for i in range(15):
            self.dataplane.send(ports[2], str(pkt_from_p2_to_dut))
            wait_for_seconds(1)
        verify_packet(self, str(expected_pkt), ports[2])
        verify_no_packet(self, str(expected_pkt), ports[3])

        egp_group_1 = "g1"
        egp_group_2 = "g2"
        egp_cfg = {}
        egpDelData = Egp(egp_cfg)
        egpDelData.delete_configByPolicy("p1")
        egpDelData.delete_configByPolicy("p2")
        egpDelData.delete_configByGroup(egp_group_1)
        egpDelData.delete_configByGroup(egp_group_2)

        egp_cfg['tenant'] = tenant_name1
        egp_cfg['name'] = egp_group_1
        egp_cfg['mac'] = ["{}/ff:ff:ff:ff:ff:ff".format(cfg.host0['mac'])]
        egpData = Egp(egp_cfg).build_group()
        actual_port = egpData.get_groupByName(egp_group_1)
        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['tenant'] = tenant_name2
        egp_cfg['name'] = egp_group_2
        egp_cfg['mac'] = ["{}/ff:ff:ff:ff:ff:ff".format(cfg.host2['mac'])]
        egpData = Egp(egp_cfg).build_group()
        actual_port = egpData.get_groupByName(egp_group_2)
        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_policy = "p1"
        egp_p_cfg = {}
        egp_p_cfg['tenant'] = tenant_name1
        egp_p_cfg['apply_to'] = egp_group_1
        egp_p_cfg['policy_name'] = egp_policy
        egp_p_cfg['timeRangeDays'] = 127
        egp_p_cfg['timeRangeStart'] = 0
        egp_p_cfg['timeRangeEnd'] = 23
        egp_p_cfg['rules'] = [{
            "match": {
                "dst_mac": "{}/FF:FF:FF:FF:FF:FF".format("ff:ff:ff:ff:ff:ff"),
                "vlan_id": "{}".format(vlan_id1),
                "ether_type": "0x0806"
            },
            "action": "deny"
        }]
        egpData = Egp(egp_p_cfg).build_policy()
        actual_port = egpData.get_policyByName(egp_policy)
        chkData = actual_port
        assert (egp_p_cfg['policy_name'] == chkData["name"]
                ), "Cannot get policy name of egp config"
        assert (egp_p_cfg['timeRangeDays'] == chkData["timeRangeDays"]
                ), "Cannot get timeRangeDays of policy config"
        assert (egp_p_cfg['timeRangeStart'] == chkData["timeRangeStart"]
                ), "Cannot get timeRangeStart of policy config"
        assert (egp_p_cfg['timeRangeEnd'] == chkData["timeRangeEnd"]
                ), "Cannot get timeRangeEnd of policy config"
        assert (egp_p_cfg['rules'][0]["match"]["vlan_id"] == chkData['rules']
                [0]["match"]["vid"]), "Cannot get vlan_id of policy config"
        assert (egp_p_cfg['rules'][0]["action"] == chkData['rules'][0]
                ["action"]), "Cannot get action of policy config"
        time.sleep(10)

        egp_policy = "p2"
        egp_p_cfg = {}
        egp_p_cfg['tenant'] = tenant_name2
        egp_p_cfg['apply_to'] = egp_group_2
        egp_p_cfg['policy_name'] = egp_policy
        egp_p_cfg['timeRangeDays'] = 127
        egp_p_cfg['timeRangeStart'] = 0
        egp_p_cfg['timeRangeEnd'] = 23
        egp_p_cfg['rules'] = [{
            "match": {
                "dst_mac": "{}/FF:FF:FF:FF:FF:FF".format("ff:ff:ff:ff:ff:ff"),
                "vlan_id": "{}".format(vlan_id2),
                "ether_type": "0x0806"
            },
            "action": "deny"
        }]
        egpData = Egp(egp_p_cfg).build_policy()
        actual_port = egpData.get_policyByName(egp_policy)
        chkData = actual_port
        assert (egp_p_cfg['policy_name'] == chkData["name"]
                ), "Cannot get policy name of egp config"
        assert (egp_p_cfg['timeRangeDays'] == chkData["timeRangeDays"]
                ), "Cannot get timeRangeDays of policy config"
        assert (egp_p_cfg['timeRangeStart'] == chkData["timeRangeStart"]
                ), "Cannot get timeRangeStart of policy config"
        assert (egp_p_cfg['timeRangeEnd'] == chkData["timeRangeEnd"]
                ), "Cannot get timeRangeEnd of policy config"
        assert (egp_p_cfg['rules'][0]["match"]["vlan_id"] == chkData['rules']
                [0]["match"]["vid"]), "Cannot get vlan_id of policy config"
        assert (egp_p_cfg['rules'][0]["action"] == chkData['rules'][0]
                ["action"]), "Cannot get action of policy config"
        time.sleep(10)

        # host0 ping
        pkt_from_p0_to_dut = simple_arp_packet(pktlen=68,
                                               vlan_vid=vlan_id1,
                                               eth_dst="ff:ff:ff:ff:ff:ff",
                                               eth_src=cfg.host0['mac'],
                                               ip_snd=t_ip1,
                                               ip_tgt=d_ip1,
                                               hw_snd=cfg.host0['mac'],
                                               hw_tgt='00:00:00:00:00:00')
        expected_pkt1 = simple_eth_vlan_type_packet(
            pktlen=12,
            eth_type=0x0806,
            vlan_vid=vlan_id1,
            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_no_packet(self, str(expected_pkt1), ports[0])

        # host2 ping
        pkt_from_p2_to_dut = simple_arp_packet(pktlen=68,
                                               vlan_vid=vlan_id2,
                                               eth_dst="ff:ff:ff:ff:ff:ff",
                                               eth_src=cfg.host2['mac'],
                                               ip_snd=t_ip2,
                                               ip_tgt=d_ip2,
                                               hw_snd=cfg.host2['mac'],
                                               hw_tgt='00:00:00:00:00:00')

        expected_pkt2 = simple_eth_vlan_type_packet(
            pktlen=12,
            eth_type=0x0806,
            vlan_vid=vlan_id2,
            eth_dst=cfg.host2['mac'],
            eth_src=cfg.spine0['mac'],
        )
        for i in range(15):
            self.dataplane.send(ports[2], str(pkt_from_p2_to_dut))
            wait_for_seconds(1)
        verify_no_packet(self, str(expected_pkt2), ports[2])

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

        # host0 ping
        for i in range(15):
            self.dataplane.send(ports[0], str(pkt_from_p0_to_dut))
            wait_for_seconds(1)
        verify_no_packet(self, str(expected_pkt1), ports[0])

        # host2 ping
        for i in range(15):
            self.dataplane.send(ports[2], str(pkt_from_p2_to_dut))
            wait_for_seconds(1)
        verify_no_packet(self, str(expected_pkt2), ports[2])

        tenantData = Tenant(tenant_name1)
        tenantData.delete_tenant(tenant_name1)
        tenantData = Tenant(tenant_name2)
        tenantData.delete_tenant(tenant_name2)
        egpDelData.delete_configByPolicy("p1")
        egpDelData.delete_configByPolicy("p2")
        egpDelData.delete_configByGroup(egp_group_1)
        egpDelData.delete_configByGroup(egp_group_2)
        tlr1.delete()
        tlr2.delete()
예제 #24
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()
예제 #25
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(3)
        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(3)

        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(30)

        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])

        egp_group = "g1"
        egp_policy = "p1"
        egp_cfg = {}
        egpDelData = Egp(egp_cfg)
        egpDelData.delete_configByPolicy(egp_policy)
        egpDelData.delete_configByGroup(egp_group)

        egp_cfg['tenant'] = tenant_name
        egp_cfg['name'] = egp_group
        #egp_cfg['mac'] = ["{}/ff:ff:ff:00:00:00".format(cfg.spine0['mac'])]
        egp_cfg['mac'] = ["{}/ff:ff:ff:00:00:00".format(cfg.host0['mac'])]
        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"

        egp_p_cfg = {}
        egp_p_cfg['tenant'] = tenant_name
        egp_p_cfg['apply_to'] = egp_group
        egp_p_cfg['policy_name'] = egp_policy
        egp_p_cfg['timeRangeDays'] = 127
        egp_p_cfg['timeRangeStart'] = 0
        egp_p_cfg['timeRangeEnd'] = 23
        egp_p_cfg['rules'] = [{
            "match": {
                # "src_ip": "{}".format(t_ip)
                # "dst_mac": "{}/FF:FF:FF:FF:FF:FF".format(cfg.host0['mac']),
                "dst_mac": "{}/FF:FF:FF:FF:FF:FF".format("ff:ff:ff:ff:ff:ff"),
                "vlan_id": "{}".format(vlan_id),
                "ether_type": "0x0806"
            },
            "action": "deny"
        }]
        egpData = Egp(egp_p_cfg).build_policy()
        actual_port = egpData.get_policy()
        chkData = actual_port["policies"][0]
        assert (egp_p_cfg['policy_name'] == chkData["name"]
                ), "Cannot get policy name of egp config"
        assert (egp_p_cfg['timeRangeDays'] == chkData["timeRangeDays"]
                ), "Cannot get timeRangeDays of policy config"
        assert (egp_p_cfg['timeRangeStart'] == chkData["timeRangeStart"]
                ), "Cannot get timeRangeStart of policy config"
        assert (egp_p_cfg['timeRangeEnd'] == chkData["timeRangeEnd"]
                ), "Cannot get timeRangeEnd of policy config"
        # assert(egp_p_cfg['rules'][0]["match"]["src_ip"] == chkData['rules'][0]["match"]["srcIp"]
        #       ), "Cannot get vlan_id of policy config"
        assert (egp_p_cfg['rules'][0]["action"] == chkData['rules'][0]
                ["action"]), "Cannot get action of policy config"
        time.sleep(30)

        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_no_packet(self, str(expected_pkt), ports[0])
        #verify_packet(self, str(expected_pkt), ports[0])
        tlr.delete()