예제 #1
0
def main():
    util.del_if_exist(result_file_name)
    try:
        """ direction: output"""
        util.flag_direction_output(result_file_name)
        # 1.eth
        # get_flow_from_eth_port(src_ip = vm_fixed_ip, dst_ip = remote_ip)
        ret = util.get_flow_from_eth_port(task_id,
                                          src_ip=cna_vtep_ip,
                                          dst_ip=vrouter_vtep_ip,
                                          file_name=result_file_name)
        if not ret:
            return
        # 2.OVS
        pkg, flow_table_records = util.calc_flow_table(src_ip=vm_fixed_ip,
                                                       dst_mac=sg_mg)
        tmp_src_ip = vm_fixed_ip
        tmp_dst_ip = None
        if 0 == pkg:
            pkg, flow_table_records = util.calc_flow_table(
                src_ip=cna_vtep_ip, dst_ip=vrouter_vtep_ip, tun_id=tun_id)
            tmp_src_ip = cna_vtep_ip
            tmp_dst_ip = vrouter_vtep_ip
        util.generate_path_record(result_file_name,
                                  DEV_T_OVS,
                                  dev_ovs,
                                  pkg,
                                  src_ip=tmp_src_ip,
                                  dst_ip=tmp_dst_ip)
        # eth
        ret = util.get_flow_from_eth_port(task_id,
                                          src_ip=vm_fixed_ip,
                                          dst_ip=remote_ip,
                                          file_name=result_file_name)
        if not ret:
            return
        """ direction: input"""
        util.flag_direction_input(result_file_name)
        # 1. eth
        # get_flow_from_eth_port(dst_ip = vm_fixed_ip,src_ip = remote_ip)
        ret = util.get_flow_from_eth_port(task_id,
                                          dst_ip=vm_fixed_ip,
                                          src_ip=remote_ip,
                                          file_name=result_file_name)
        if not ret:
            return
        # 2. ovs
        pkg, flow_table_records = util.calc_flow_table(dst_ip=vm_fixed_ip,
                                                       src_mac=sg_mg)
        util.generate_path_record(result_file_name,
                                  DEV_T_OVS,
                                  dev_ovs,
                                  pkg,
                                  dst_ip=vm_fixed_ip)
        util.flag_process_over(result_file_name)
    except Exception, e:
        util.flag_process_over(result_file_name, str(e))
예제 #2
0
def main():
    if not node_flag_str:
        print 'Please input exec node info!'
        return

    util.del_if_exist(result_file_name)
    try:
        if 'output' == node_flag_str:
            """ direction: output"""
            util.flag_direction_output(result_file_name)
            # 1. tunnel_bearing
            # l2_vtep_ip, cna_vtep_ip = get_ip_by_port_options(remote_vm_mac)
            l2_vtep_ip = l2_gateway_vtep_ip
            if l2_vtep_ip and src_vm_vtep_ip:
                ret = util.get_flow_from_eth_port \
                    (task_id=task_id, src_ip=src_vm_vtep_ip, dst_ip=l2_vtep_ip, file_name=result_file_name)
                if not ret:
                    return
            else:
                error_info = 'Can not find vtep ip(src_ip=%s,dst_ip=%s)' % (src_vm_vtep_ip, l2_vtep_ip)
                print error_info
                util.flag_process_over(result_file_name, error_info)
                return
            pkg = util.calc_flow_table_for_l2_gateway(src_ip=vm_ip, dst_ip=remote_vm_ip)
            tmp_src_ip = vm_ip
            tmp_dst_ip = remote_vm_ip
            if 0 == pkg:
                pkg = util.calc_flow_table_for_l2_gateway(src_ip=src_vm_vtep_ip, dst_ip=l2_vtep_ip, tun_id=tun_id_out)
                tmp_src_ip = src_vm_vtep_ip
                tmp_dst_ip = l2_vtep_ip
            # 2. ovs
            util.generate_path_record(result_file_name, DEV_T_OVS, dev_ovs, pkg, src_ip=tmp_src_ip, dst_ip=tmp_dst_ip)

        if 'input' == node_flag_str:
            # direction: input
            util.flag_direction_input(result_file_name)
            # l2_vtep_ip, cna_vtep_ip = get_ip_by_port_options(vm_mac)
            l2_vtep_ip = l2_gateway_vtep_ip
            # 1. tunnel_bearing
            if dst_vm_vtep_ip and l2_vtep_ip:
                ret = util.get_flow_from_eth_port \
                    (task_id=task_id, src_ip=dst_vm_vtep_ip, dst_ip=l2_vtep_ip, file_name=result_file_name)
                if not ret:
                    return
            else:
                error_info = 'Can not find vtep ip(src_ip=%s,dst_ip=%s)' % (dst_vm_vtep_ip, l2_vtep_ip)
                print error_info
                util.flag_process_over(result_file_name, error_info)
                return
            tmp_src_ip = remote_vm_ip
            tmp_dst_ip = l2_vtep_ip
            pkg = util.calc_flow_table_for_l2_gateway(src_ip=remote_vm_ip, dst_ip=l2_vtep_ip, tun_id=None)
            if 0 == pkg:
                pkg = util.calc_flow_table_for_l2_gateway(src_ip=dst_vm_vtep_ip, dst_ip=l2_vtep_ip, tun_id=tun_id_in)
                tmp_src_ip = dst_vm_vtep_ip
                tmp_dst_ip = l2_vtep_ip
            # 2. ovs
            util.generate_path_record(result_file_name, DEV_T_OVS, dev_ovs, pkg, dst_ip=tmp_dst_ip, src_ip=tmp_src_ip)

                # end
        util.flag_process_over(result_file_name)
    except Exception, e:
        util.flag_process_over(result_file_name, str(e))
예제 #3
0
def main():
    util.del_if_exist(result_file_name)
    try:
        """ direction: output"""
        util.flag_direction_output(result_file_name)
        # 1. tap
        util.get_flow_by_tcpdump_from_vm_port(task_id,
                                              result_file_name,
                                              DEV_T_TAP,
                                              dev_tap,
                                              None,
                                              src_ip=vm_fixed_ip,
                                              dst_ip=remote_ip)
        # 2. qvm
        qvmPkg = util.get_flow_by_tcpdump_from_vm_port(task_id,
                                                       result_file_name,
                                                       DEV_T_QVM,
                                                       dev_qvm,
                                                       None,
                                                       src_ip=vm_fixed_ip,
                                                       dst_ip=remote_ip)
        # 3. br-int-bef-dvr
        pkg = get_flow_by_flowtable(src_ip=vm_fixed_ip, dst_mac=gateway_mac)
        if qvmPkg and pkg:
            util.generate_path_record(result_file_name,
                                      DEV_T_OVS,
                                      dev_ovs_bef_dvr,
                                      pkg,
                                      src_ip=vm_fixed_ip,
                                      dst_mac=gateway_mac)
        else:
            util.generate_path_record(result_file_name,
                                      DEV_T_OVS,
                                      dev_ovs_bef_dvr,
                                      0,
                                      src_ip=vm_fixed_ip,
                                      dst_mac=gateway_mac)

        # 4. dvr-in
        get_flow_by_tcpdump(DEV_T_DVR,
                            dev_dvr_2_ovs,
                            None,
                            src_ip=vm_fixed_ip,
                            dst_ip=remote_ip,
                            ns=ns_dvr,
                            timeout=INTERVAL_DUMP_FLOW)
        # 5. dvr-out
        get_flow_by_tcpdump(DEV_T_DVR,
                            dev_dvr_2_fip,
                            None,
                            src_ip=vm_fixed_ip,
                            dst_ip=remote_ip,
                            ns=ns_dvr,
                            timeout=INTERVAL_DUMP_FLOW)
        # 6. fip-in
        get_flow_by_tcpdump(DEV_T_FIP,
                            dev_fip_2_dvr,
                            None,
                            src_ip=vm_fixed_ip,
                            dst_ip=remote_ip,
                            ns=ns_fip,
                            timeout=INTERVAL_DUMP_FLOW)
        # 7. fip-out
        get_flow_by_tcpdump(DEV_T_FIP,
                            dev_fip_port,
                            None,
                            src_ip=vm_fixed_ip,
                            dst_ip=remote_ip,
                            ns=ns_fip,
                            timeout=INTERVAL_DUMP_FLOW)

        # 9. bond
        dev_bond = get_dev_bond()
        if isSnat:
            bond_pkg, rst = get_flow_by_tcpdump_not_write(
                DEV_T_V_BOND,
                dev_bond,
                None,
                src_ip=local_eip,
                dst_ip=remote_ip,
                timeout=TIME_OUT_TCPDUMP)
        else:
            bond_pkg, rst = get_flow_by_tcpdump_not_write(
                DEV_T_V_BOND,
                dev_bond,
                None,
                src_ip=floating_ip,
                dst_ip=remote_ip,
                timeout=TIME_OUT_TCPDUMP)
        # 8. br-int-aft-fip
        pkg = get_flow_by_flowtable(src_ip=vm_fixed_ip,
                                    dst_ip=remote_ip,
                                    in_action=True,
                                    src_mac=fg_mac)
        if not pkg:
            pkg = bond_pkg
        util.generate_path_record(result_file_name,
                                  DEV_T_OVS,
                                  dev_ovs_aft_fip,
                                  pkg,
                                  src_ip=vm_fixed_ip,
                                  dst_ip=remote_ip,
                                  src_mac=fg_mac)
        # 9. bond
        util.generate_path_record(result_file_name,
                                  DEV_T_V_BOND,
                                  dev_bond,
                                  bond_pkg,
                                  src_ip=floating_ip,
                                  dst_ip=remote_ip)
        """ direction: input"""
        util.flag_direction_input(result_file_name)
        # 1. bond
        bond_pkg, rst = get_flow_by_tcpdump(DEV_T_V_BOND,
                                            dev_bond,
                                            None,
                                            src_ip=remote_ip,
                                            dst_ip=floating_ip,
                                            timeout=TIME_OUT_TCPDUMP)
        # 2. br-int-bef-fip
        if rst:
            mac = get_mac_from_tcmpdump_flow(rst)
            pkg = get_flow_by_flowtable(src_mac=mac, dst_mac=fg_mac)

            if bond_pkg and pkg:
                util.generate_path_record(result_file_name,
                                          DEV_T_OVS,
                                          dev_ovs_bef_fip,
                                          pkg,
                                          src_ip=remote_ip,
                                          dst_ip=floating_ip,
                                          dst_mac=fg_mac)
            else:
                util.generate_path_record(result_file_name,
                                          DEV_T_OVS,
                                          dev_ovs_bef_fip,
                                          0,
                                          src_ip=remote_ip,
                                          dst_ip=floating_ip,
                                          dst_mac=fg_mac)
        else:
            util.generate_path_record(result_file_name,
                                      DEV_T_OVS,
                                      dev_ovs_bef_fip,
                                      0,
                                      src_ip=remote_ip,
                                      dst_ip=floating_ip,
                                      dst_mac=fg_mac)
        # 3. fip-in
        get_flow_by_tcpdump(DEV_T_FIP,
                            dev_fip_port,
                            None,
                            src_ip=remote_ip,
                            dst_ip=floating_ip,
                            ns=ns_fip,
                            timeout=INTERVAL_DUMP_FLOW)
        # 4. fip-out
        get_flow_by_tcpdump(DEV_T_FIP,
                            dev_fip_2_dvr,
                            None,
                            src_ip=remote_ip,
                            dst_ip=floating_ip,
                            ns=ns_fip,
                            timeout=INTERVAL_DUMP_FLOW)
        # 5. dvr-in
        get_flow_by_tcpdump(DEV_T_DVR,
                            dev_dvr_2_fip,
                            None,
                            src_ip=remote_ip,
                            dst_ip=floating_ip,
                            ns=ns_dvr,
                            timeout=INTERVAL_DUMP_FLOW)
        # 6. dvr-out
        get_flow_by_tcpdump(DEV_T_DVR,
                            dev_dvr_2_ovs,
                            None,
                            src_ip=remote_ip,
                            dst_ip=floating_ip,
                            ns=ns_dvr,
                            timeout=INTERVAL_DUMP_FLOW)

        pkg_vm_port = util.get_flow_by_tcpdump_from_vm_port_for_ovs(
            task_id, dev_qvm, None, src_ip=remote_ip, dst_ip=vm_fixed_ip)

        if pkg_vm_port:
            util.generate_path_record(result_file_name,
                                      DEV_T_OVS,
                                      dev_ovs_aft_dvr,
                                      1,
                                      src_ip=remote_ip,
                                      dst_ip=vm_fixed_ip,
                                      src_mac=gateway_mac)
        else:
            pkg = get_flow_by_flowtable(src_ip=remote_ip,
                                        dst_ip=vm_fixed_ip,
                                        src_mac=gateway_mac)
            util.generate_path_record(result_file_name,
                                      DEV_T_OVS,
                                      dev_ovs_aft_dvr,
                                      pkg,
                                      src_ip=remote_ip,
                                      dst_ip=vm_fixed_ip,
                                      src_mac=gateway_mac)
        util.generate_path_record(result_file_name,
                                  DEV_T_QVM,
                                  dev_qvm,
                                  pkg_vm_port,
                                  src_ip=remote_ip,
                                  dst_ip=vm_fixed_ip)

        # 9. tap
        util.get_flow_by_tcpdump_from_vm_port(task_id,
                                              result_file_name,
                                              DEV_T_TAP,
                                              dev_tap,
                                              None,
                                              src_ip=remote_ip,
                                              dst_ip=vm_fixed_ip)
        # end
        util.flag_process_over(result_file_name)
    except Exception, e:
        util.flag_process_over(result_file_name, str(e))
예제 #4
0
def main():
    util.del_if_exist(result_file_name)
    try:
        """ direction: output"""
        util.flag_direction_output(result_file_name)
        # tap
        util.get_flow_by_tcpdump_from_vm_port(task_id,
                                              result_file_name,
                                              DEV_T_TAP,
                                              dev_tap,
                                              None,
                                              src_ip=vm1_ip,
                                              dst_ip=vm2_ip)
        # qvm
        qvm_pkg = util.get_flow_by_tcpdump_from_vm_port(task_id,
                                                        result_file_name,
                                                        DEV_T_QVM,
                                                        dev_qvm,
                                                        None,
                                                        src_ip=vm1_ip,
                                                        dst_ip=vm2_ip)

        if flag_same_subnet:
            pkg = get_flow_by_flowtable(src_ip=vm1_ip, dst_ip=vm2_ip)
            util.generate_path_record(result_file_name,
                                      DEV_T_OVS,
                                      dev_ovs,
                                      pkg,
                                      src_ip=vm1_ip,
                                      dst_ip=vm2_ip)
        else:
            """ New demand. Do not show DVR and OVS before DVR."""
            # ovs-bef-dvr
            pkg = get_flow_by_flowtable(src_mac=vm1_mac,
                                        src_ip=vm1_ip,
                                        dst_mac=port1_id_dvr_mac)
            if qvm_pkg and pkg:
                util.generate_path_record(result_file_name,
                                          DEV_T_OVS,
                                          dev_ovs_bef_dvr,
                                          pkg,
                                          src_mac=vm1_mac,
                                          src_ip=vm1_ip,
                                          dst_mac=port1_id_dvr_mac)
            else:
                util.generate_path_record(result_file_name,
                                          DEV_T_OVS,
                                          dev_ovs_bef_dvr,
                                          0,
                                          src_mac=vm1_mac,
                                          src_ip=vm1_ip,
                                          dst_mac=port1_id_dvr_mac)
            # dvr-in
            get_flow_by_tcpdump(DEV_T_DVR,
                                dev_dvr_2_ovs_1,
                                None,
                                src_ip=vm1_ip,
                                dst_ip=vm2_ip,
                                ns=ns_dvr)
            # dvr-out
            get_flow_by_tcpdump(DEV_T_DVR,
                                dev_dvr_2_ovs_2,
                                None,
                                src_ip=vm1_ip,
                                dst_ip=vm2_ip,
                                ns=ns_dvr)
            # ovs-aft-dvr
            pkg = get_flow_by_flowtable(src_mac=port2_id_dvr_mac,
                                        src_ip=vm1_ip,
                                        dst_ip=vm2_ip,
                                        dst_mac=vm2_mac)
            util.generate_path_record(result_file_name,
                                      DEV_T_OVS,
                                      dev_ovs_aft_dvr,
                                      pkg,
                                      src_ip=vm1_ip,
                                      dst_ip=vm2_ip)
        # v_bond
        dev_vbond = get_dev_vbond()
        if not flag_same_az:
            """ New demand. Use flow table replace v_bond flow info. """
            get_flow_by_tcpdump(DEV_T_V_BOND,
                                dev_vbond,
                                'udp',
                                src_ip=cna_vtep_ip,
                                dst_ip=out_gateay_vtep_ip,
                                timeout=TIME_OUT_TCPDUMP)
        if flag_same_az and not flag_same_host:
            get_flow_by_tcpdump(DEV_T_V_BOND,
                                dev_vbond,
                                'udp',
                                src_ip=cna_vtep_ip,
                                dst_ip=cna2_vtep_ip,
                                timeout=TIME_OUT_TCPDUMP)
        """ direction: input"""
        util.flag_direction_input(result_file_name)
        # tap
        util.get_flow_by_tcpdump_from_vm_port(task_id,
                                              result_file_name,
                                              DEV_T_TAP,
                                              dev_tap,
                                              None,
                                              src_ip=vm2_ip,
                                              dst_ip=vm1_ip)
        # qvm
        util.get_flow_by_tcpdump_from_vm_port(task_id,
                                              result_file_name,
                                              DEV_T_QVM,
                                              dev_qvm,
                                              None,
                                              src_ip=vm2_ip,
                                              dst_ip=vm1_ip)

        # ovs
        pkg = get_flow_by_flowtable(src_ip=vm2_ip,
                                    dst_ip=vm1_ip,
                                    dst_mac=vm1_mac)
        util.generate_path_record(result_file_name,
                                  DEV_T_OVS,
                                  dev_ovs,
                                  pkg,
                                  src_ip=vm2_ip,
                                  dst_ip=vm1_ip)

        if not flag_same_az:
            get_flow_by_tcpdump(DEV_T_V_BOND,
                                dev_vbond,
                                'udp',
                                src_ip=in_gateway_vtep_ip,
                                dst_ip=cna_vtep_ip,
                                timeout=TIME_OUT_TCPDUMP)

        if flag_same_az and not flag_same_host:
            get_flow_by_tcpdump(DEV_T_V_BOND,
                                dev_vbond,
                                'udp',
                                src_ip=cna2_vtep_ip,
                                dst_ip=cna_vtep_ip,
                                timeout=TIME_OUT_TCPDUMP)
        # end
        util.flag_process_over(result_file_name)
    except Exception, e:
        util.flag_process_over(result_file_name, str(e))
예제 #5
0
def main():
    util.del_if_exist(result_file_name)
    try:
        """ direction: output"""
        util.flag_direction_output(result_file_name)
        # 1. tap
        util.get_flow_by_tcpdump_from_vm_port(task_id,
                                              result_file_name,
                                              DEV_T_TAP,
                                              dev_tap,
                                              None,
                                              src_ip=vm_fixed_ip,
                                              dst_ip=remote_ip)
        # 2. qvm
        util.get_flow_by_tcpdump_from_vm_port(task_id,
                                              result_file_name,
                                              DEV_T_QVM,
                                              dev_qvm,
                                              None,
                                              src_ip=vm_fixed_ip,
                                              dst_ip=remote_ip)
        # 3. ovs : qvm -> qr
        # ip, qrdev_mac = util.get_gateway_info(task_id, ns_dvr, dev_dvr_2_ovs[0:9])
        # 4. qr : dvr-in
        get_flow_by_tcpdump(DEV_T_DVR,
                            dev_dvr_2_ovs,
                            None,
                            src_ip=vm_fixed_ip,
                            dst_ip=remote_ip,
                            dst_mac=dvr_port_mac,
                            ns=ns_dvr,
                            timeout=INTERVAL_DUMP_FLOW)
        # 5. dvr-out
        get_flow_by_tcpdump(DEV_T_DVR,
                            dev_dvr_2_ovs,
                            None,
                            src_ip=vm_fixed_ip,
                            dst_ip=remote_ip,
                            src_mac=dvr_port_mac,
                            ns=ns_dvr,
                            timeout=INTERVAL_DUMP_FLOW)
        # 6. ovs : qr->veth
        get_flow_by_flowtable(DEV_T_OVS,
                              dev_ovs,
                              src_ip=vm_fixed_ip,
                              dst_ip=remote_ip,
                              src_mac=dvr_port_mac,
                              timeout=INTERVAL_DUMP_FLOW)
        # 7. v_eth1
        dev_veth = get_dev_veth()
        get_flow_by_tcpdump(DEV_T_V_BOND,
                            dev_veth,
                            None,
                            src_ip=cna_vtep_ip,
                            dst_ip=vrouter_vtep_ip,
                            timeout=TIME_OUT_TCPDUMP)
        """ direction: input"""
        util.flag_direction_input(result_file_name)
        # 1. tap
        util.get_flow_by_tcpdump_from_vm_port(task_id,
                                              result_file_name,
                                              DEV_T_TAP,
                                              dev_tap,
                                              None,
                                              src_ip=remote_ip,
                                              dst_ip=vm_fixed_ip)
        # 2. qvm
        util.get_flow_by_tcpdump_from_vm_port(task_id,
                                              result_file_name,
                                              DEV_T_QVM,
                                              dev_qvm,
                                              None,
                                              src_ip=remote_ip,
                                              dst_ip=vm_fixed_ip)
        # 3.ovs
        get_flow_by_flowtable(DEV_T_OVS,
                              dev_ovs,
                              src_mac=sg_mac,
                              dst_ip=vm_fixed_ip)
        # 4.v_eth1
        dev_veth = get_dev_veth()
        get_flow_by_tcpdump(DEV_T_V_BOND,
                            dev_veth,
                            None,
                            src_ip=l2_gateway_vtep_ip,
                            dst_ip=cna_vtep_ip,
                            timeout=TIME_OUT_TCPDUMP)
        util.flag_process_over(result_file_name)
    except Exception, e:
        util.flag_process_over(result_file_name, str(e))