示例#1
0
def main(argc, argv):
    home = os.environ['HOME']
    ovs_path, hostname, os_release, logfile, br, vlan_id = ovs_helper.set_defaults(
        home, progname)
    vm_uuid, vm_xml, vrf_id, evpn_id = vca_helper.set_vrf_defaults(home)
    logfd = logger.open_log(logfile)
    ovs_helper.print_defaults(ovs_path, os_release, hostname, logfile)

    try:
        opts, args = getopt.getopt(argv, "hu:C:V:cds:S")
    except getopt.GetoptError as err:
        print progname + ": invalid argument, " + str(err)
        usage()

    config_file = "/usr/local/openvswitch/templates/vm_ports_default_config.json"
    uplink_iface = "port1"
    configure = False
    deconfigure = False
    status = False
    status_arg = ""
    vstatus = False
    rc = 0
    for opt, arg in opts:
        if opt == "-c":
            configure = True
        elif opt == "-d":
            deconfigure = True
        elif opt == "-s":
            status = True
            status_arg = arg
        elif opt == "-S":
            vstatus = True
        elif opt == "-u":
            uplink_iface = arg
        elif opt == "-C":
            config_file = arg
        elif opt == "-h":
            usage()

    if (configure == False and deconfigure == False and status == False
            and vstatus == False):
        print progname + ": invalid usage"
        usage

    if (configure == True):
        rc = do_configure(progname, ovs_path, br, config_file, uplink_iface,
                          logfd)
    elif (deconfigure == True):
        rc = do_deconfigure(config_file, logfd)
    elif (status == True):
        rc = do_status(progname, ovs_path, br, config_file, status_arg, logfd)
    elif (vstatus == True):
        rc = do_vstatus(progname, ovs_path, br, config_file, logfd)
    sys.exit(rc)
示例#2
0
def main(argc, argv):
	ovs_path, hostname, os_release, logfile, br, vlan_id = ovs_helper.set_defaults(home, progname)
	try:
		opts, args = getopt.getopt(argv, "hs:i:t:T:l:r:");
	except getopt.GetoptError as err:
		print progname + ": invalid argument, " + str(err)
		usage()

	vm_ip_local = ""
	port_type = ""
	mgmt_iface = ""
	tnl_type = ""
	rtep_ip = ""
	for opt, arg in opts:
		if opt == "-s":
			ovs_sb = arg
			OVS_DIR = home + "/Linux/src/sandbox/" + ovs_sb + "/VCA"
			ovs_path = OVS_DIR + "/utilities"
		elif opt == "-i":
			mgmt_iface = arg
		elif opt == "-t":
			port_type = arg
		elif opt == "-l":
			vm_ip_local = arg
		elif opt == "-T":
			Topt_tok = arg.split(":")
			tnl_type = Topt_tok[0]
			rtep_ip = Topt_tok[1]
			tnl_key = ovs_helper.set_tnl_key(tnl_type)
		elif opt == "-r":
			vm_ip_remote = arg
		elif opt == "-h":
			usage()

	logfd = logger.open_log(logfile)
	bridge = ovs_bridge.Bridge(ovs_path, br, logfd)
	mgmt_ip = net.get_iface_ip(mgmt_iface)
	vm_iface = ovs_helper.set_vm_iface(mgmt_iface, port_type)

	if (len(vm_ip_local) == 0):
		print(progname + ": Need value of local VM IP address")
		usage()
	if (len(rtep_ip) == 0):
		print(progname + ": Need value of RTEP IP address")
		usage()
	if (len(port_type) == 0):
		print(progname + ": Need value of port type")
		usage()
	if (len(tnl_type) == 0):
		print(progname + ": Need value of tunnel type")
		usage()
	if (len(tnl_key) == 0):
		print(progname + ": Tunnel key not set, specify tunnel type")
		usage()
	if (len(mgmt_iface) == 0):
		print(progname + ": Need value of management interface")
		usage()
	if (port_type != "internal" and port_type != "vlan"):
		print(progname + ": Need a supported type of port")
		exit(1)

	ovs_helper.print_defaults(ovs_path, os_release, hostname, logfile)
	time.sleep(2)

	tap = ovs_vport_tap.Tap(ovs_path, port_type, br, vm_iface,
				vm_ip_local, logfd)
	time.sleep(2)

	rtep = ovs_vport_tnl.Tunnel(ovs_path, br, tnl_type, tnl_key, rtep_ip,
				    "rtep", logfd, True)
	rtep_port = rtep.get_tnl_name()
	time.sleep(2)
	ltep = ovs_vport_tnl.Tunnel(ovs_path, br, tnl_type, tnl_key, mgmt_ip,
				    "ltep", logfd, True)
	ltep_port = ltep.get_tnl_name()
	time.sleep(2)

	flow = vca_flows.Flows(ovs_path, br, logfd)
	flow.set_l2_flow(vm_iface, rtep_port)
	flow.set_l2_flow(ltep_port, vm_iface)
示例#3
0
def main(argc, argv):
    ovs_path, hostname, os_release, logfile, br, vlan_id = ovs_helper.set_defaults(
        home, progname)
    try:
        opts, args = getopt.getopt(argv, "Chs:i:t:T:l:r:n:")
    except getopt.GetoptError as err:
        print progname + ": invalid argument, " + str(err)
        usage()

    vm_ip_local = ""
    port_type = ""
    mgmt_iface = ""
    tnl_type = ""
    rtep_ip = ""
    n_tunnels = 0
    for opt, arg in opts:
        if opt == "-s":
            ovs_sb = arg
            OVS_DIR = home + "/Linux/src/sandbox/" + ovs_sb + "/VCA"
            ovs_path = OVS_DIR + "/utilities"
        elif opt == "-C":
            cmd = "ovs-vsctl show | grep Port | grep -v alubr0 | grep -v svc | awk '{print $2}' | sed 's/\"//g'"
            port_list = shell.call_prog_as_is(cmd)
            for port in port_list.splitlines():
                cmd = "ovs-vsctl del-port " + port
                print "Running " + cmd
                shell.call_prog_as_is(cmd)
            sys.exit(1)
        elif opt == "-i":
            mgmt_iface = arg
        elif opt == "-t":
            port_type = arg
        elif opt == "-l":
            vm_ip_local = arg
        elif opt == "-T":
            Topt_tok = arg.split(":")
            tnl_type = Topt_tok[0]
            rtep_ip = Topt_tok[1]
            tnl_key = ovs_helper.set_tnl_key(tnl_type)
        elif opt == "-r":
            vm_ip_remote = arg
        elif opt == "-n":
            n_tunnels = int(arg)
        elif opt == "-h":
            usage()

    logfd = logger.open_log(logfile)
    bridge = ovs_bridge.Bridge(ovs_path, br, logfd)
    mgmt_ip = net.get_iface_ip(mgmt_iface)
    vm_iface = ovs_helper.set_vm_iface(mgmt_iface, port_type)

    if (len(vm_ip_local) == 0):
        print(progname + ": Need value of local VM IP address")
        usage()
    if (len(rtep_ip) == 0):
        print(progname + ": Need value of RTEP IP address")
        usage()
    if (len(port_type) == 0):
        print(progname + ": Need value of port type")
        usage()
    if (len(tnl_type) == 0):
        print(progname + ": Need value of tunnel type")
        usage()
    if (len(tnl_key) == 0):
        print(progname + ": Tunnel key not set, specify tunnel type")
        usage()
    if (len(mgmt_iface) == 0):
        print(progname + ": Need value of management interface")
        usage()
    if (port_type != "internal" and port_type != "vlan"):
        print(progname + ": Need a supported type of port")
        exit(1)

    ovs_helper.print_defaults(ovs_path, os_release, hostname, logfile)
    time.sleep(2)

    for x in range(0, n_tunnels):
        key = tnl_key + str(x)
        print "ITERATION: " + str(x) + ", key: " + key
        rtep = ovs_vport_tnl.Tunnel(ovs_path, br, tnl_type, key, rtep_ip,
                                    "rtep", logfd, True)
        rtep_port = rtep.get_tnl_name()
        ltep = ovs_vport_tnl.Tunnel(ovs_path, br, tnl_type, key, mgmt_ip,
                                    "ltep", logfd, True)
        ltep_port = ltep.get_tnl_name()
        print "Created rtep_port " + rtep_port + " ltep_port " + ltep_port + " with tnl_key " + key
        if (x % 2) == 0:
            print "Deleting rtep_port " + rtep_port
            rtep.destroy()
            print "Deleting ltep_port " + ltep_port
            ltep.destroy()
        if (process.proc_exists("ovs-vswitchd") == False
                or process.n_procs_by_name("ovs-vswitchd") < 2):
            print "ovs-vswitchd not found, exitting"
            sys.exit(1)
        print
        time.sleep(2)
def main(argc, argv):
    ovs_path, hostname, os_release, logfile, br, vlan_id = ovs_helper.set_defaults(
        home, progname)
    vm_uuid, vm_xml, vrf_id, evpn_id = vca_helper.set_vrf_defaults(home)
    try:
        opts, args = getopt.getopt(argv, "Chs:i:t:T:l:r:m:FV:")
    except getopt.GetoptError as err:
        print progname + ": invalid argument, " + str(err)
        usage()

    vm_ip_local = ""
    vm_ip_remote = ""
    vm_mac_remote = ""
    port_type = ""
    mgmt_iface = ""
    tnl_type = ""
    rtep_ip = ""
    add_flows = False
    vm_type = "vm"
    for opt, arg in opts:
        if opt == "-s":
            ovs_sb = arg
            OVS_DIR = home + "/Linux/src/sandbox/" + ovs_sb + "/VCA"
            ovs_path = OVS_DIR + "/utilities"
        elif opt == "-i":
            mgmt_iface = arg
        elif opt == "-t":
            port_type = arg
        elif opt == "-l":
            vm_ip_local = arg
        elif opt == "-V":
            vm_type = arg
        elif opt == "-T":
            Topt_tok = arg.split(":")
            tnl_type = Topt_tok[0]
            rtep_ip = Topt_tok[1]
            tnl_key = ovs_helper.set_tnl_key(tnl_type)
            vrf_tnl_key = str(int(tnl_key))
            evpn_tnl_key = str(int(tnl_key) + 1)
        elif opt == "-r":
            vm_ip_remote = arg
        elif opt == "-m":
            vm_mac_remote = arg
        elif opt == "-F":
            add_flows = True
        elif opt == "-h":
            usage()

    logfd = logger.open_log(logfile)
    bridge = ovs_bridge.Bridge(ovs_path, br, logfd)
    mgmt_ip = net.get_iface_ip(mgmt_iface)
    vm_iface = ovs_helper.set_vm_iface(mgmt_iface, port_type)

    if (len(vm_ip_local) == 0):
        print(progname + ": Need value of local VM IP address")
        usage()
    if (len(vm_ip_remote) == 0):
        print(progname + ": Need value of remote VM IP address")
        usage()
    if (len(vm_mac_remote) == 0):
        print(progname + ": Need value of remote VM mac address")
        usage()
    if (len(rtep_ip) == 0):
        print(progname + ": Need value of RTEP IP address")
        usage()
    if (len(port_type) == 0):
        print(progname + ": Need value of port type")
        usage()
    if (len(tnl_type) == 0):
        print(progname + ": Need value of tunnel type")
        usage()
    if ((len(vrf_tnl_key) == 0) and (len(evpn_tnl_key) == 0)):
        print(progname + ": Tunnel key not set, specify tunnel type")
        usage()
    if (len(mgmt_iface) == 0):
        print(progname + ": Need value of management interface")
        usage()
    if (port_type != "internal" and port_type != "vlan"):
        print(progname + ": Need a supported type of port")
        exit(1)

    ovs_helper.print_defaults(ovs_path, os_release, hostname, logfile)
    time.sleep(2)

    tap = ovs_vport_tap.Tap(ovs_path, port_type, br, vm_iface, vm_ip_local,
                            logfd)
    vm_netmask = tap.get_netmask()
    vm_subnet = tap.get_subnet()
    vm_mac = tap.get_mac()
    vm_gw_ip = tap.get_gw_ip()
    ofp_port_no = tap.get_ofp_port()
    time.sleep(2)

    vm = vca_vm.VM(ovs_path, br, vm_uuid, vm_iface, vm_ip_local, vm_subnet,
                   vm_netmask, vm_gw_ip, vm_mac, vm_xml, vm_type, logfd)
    vm.define()
    time.sleep(2)
    vm.start()
    time.sleep(2)

    evpn = vca_evpn.EVPN(ovs_path, br, logfd, vrf_id, tnl_type, vrf_tnl_key,
                         evpn_id, evpn_tnl_key, mgmt_ip, vm_ip_local)
    time.sleep(2)
    if (add_flows == True):
        evpn.set_flows(vm_iface, vm_ip_local, vm_netmask, vm_subnet, vm_mac,
                       vm_gw_ip, vm_uuid, rtep_ip, vm_ip_remote, vm_mac_remote,
                       vm_type)

    vm_port_no = vm.vm_port()
    port_str = "VM port: " + str(vm_port_no) + ", OFP port: " + str(
        ofp_port_no)
    if (vm_port_no > 0 and ofp_port_no > 0 and vm_port_no == ofp_port_no):
        print("VM " + vm_uuid + " is resolved, " + port_str)
    else:
        print("VM " + vm_uuid + " is NOT resolved, " + port_str)
        exit(1)
示例#5
0
def main(argc, argv):
    ovs_path, hostname, os_release, logfile, br, vlan_id = ovs_helper.set_defaults(
        home, progname)
    try:
        opts, args = getopt.getopt(argv, "hs:t:l:i:n:v:d:")
    except getopt.GetoptError as err:
        print progname + ": invalid argument, " + str(err)
        usage()
    vm_iface = ""
    vm_ip_local = ""
    vport_type = ""
    n_vports = 0
    dpdk_vendor_name = ""
    dpdk_device_list = ""
    ovs_sb = ""
    for opt, arg in opts:
        if opt == "-s":
            ovs_sb = arg
            OVS_DIR = home + "/Linux/src/sandbox/" + ovs_sb + "/VCA"
            ovs_path = OVS_DIR + "/utilities"
            ovs_vswitchd_path = OVS_DIR + "/vswitchd"
        elif opt == "-t":
            vport_type = arg
        elif opt == "-l":
            vm_ip_local = arg
        elif opt == "-i":
            vm_iface = arg
        elif opt == "-n":
            n_vports = arg
        elif opt == "-v":
            dpdk_vendor_name = arg
        elif opt == "-d":
            dpdk_device_list = arg
        else:
            usage()
    if (len(ovs_sb) == 0):
        ovs_vswitchd_path = ovs_path
    if (len(vm_iface) == 0):
        print(progname + ": Need value of VM interface name")
        usage()
    if (len(vm_ip_local) == 0):
        print(progname + ": Need value of local VM IP address")
        usage()
    if (len(vport_type) == 0):
        print(progname + ": Need value of port type")
        usage()
    if ((len(dpdk_device_list) != 0) and (len(dpdk_vendor_name) == 0)):
        print(progname + ": device list requires a valid DPDK vendor")
        usage()
    if ((len(dpdk_vendor_name) != 0) and (len(dpdk_device_list) == 0)):
        print(progname +
              ": DPDK vendor requires DPDK device list specification")
        usage()
    ovs_helper.print_defaults(ovs_path, os_release, hostname, logfile)
    logfd = logger.open_log(logfile)
    bridge = ovs_bridge.Bridge(ovs_path, br, logfd)
    if ((len(dpdk_vendor_name) != 0) and (len(dpdk_device_list) != 0)):
        ovs_dpdk_switch = ovs_dpdk_vendor_switch.SDK_OVS_Switch()
        ovs_dpdk_obj = ovs_dpdk_switch.alloc_SDK_OVS(dpdk_vendor_name,
                                                     ovs_vswitchd_path, br,
                                                     dpdk_device_list)
        print ovs_dpdk_obj.get_vswitchd_cmdline()
        sys.exit(0)
    tap = ovs_vport_tap.Tap(ovs_path, vport_type, br, vm_iface, vm_ip_local,
                            logfd)
    vm_mac = tap.get_mac()
    print "VM port mac address: " + vm_mac
    exit(0)