def openstack_flavor_create(cpu, ram, bandwidth):
    flavor = "cpu_" + cpu + "_ram_" + ram + "_bandwidth_" + bandwidth
    temp = utils.execShellCommand("openstack flavor list | grep " + flavor)
    if len(temp) == 0:
        utils.execShellCommand("openstack flavor create --vcpus " + cpu +
                               " --ram " + ram + " --disk 10 " + flavor)
    return flavor
def project_create(project_num):
    for i in range(int(project_num)):
        project = "P" + str(i)
        cmd = "openstack project create --domain default   --description  Project" + \
            str(i)+" "+project
        utils.execShellCommand(cmd)
        cmd = "openstack role add --project " + project + " --user admin admin"
        utils.execShellCommand(cmd)
def project_iptable_create():
    ret = utils.execShellCommand("openstack server list |grep ubuntu").split(
        "\n")[0:-1]
    fout = open("iptable.txt", "a+")
    for i in range(len(ret)):
        name = ret[i].split("|")[2].strip()
        ip = ret[i].split("|")[4].strip()
        bandwidth = ret[i].split("|")[-2].strip()
        ip = ip.split("=")[1].strip()
        bandwidth = bandwidth.split("_")[-1].strip()
        fout.write(name + "," + ip + "," + bandwidth + "\n")

    fout.close()
def project_fcttable_create(project_name):
    iptable_project = utils.execShellCommand("cat iptable_all.txt | grep P" +
                                             project_name).split("\n")[0:-1]
    #print(iptable_project)
    #print(len(iptable_project))
    fout = open("fcttable_all.txt", "a+")
    task = []
    for i in range(len(iptable_project)):
        task.append([])
    #fct大包列表,随机数生成
    bigpkglist = [13, 43, 39, 3, 30, 14, 29, 36, 42, 32]
    for i in range(50):
        if i in bigpkglist:
            task[i % len(task)].append('b')
        else:
            task[i % len(task)].append('s')

    for i in range(len(iptable_project)):
        item = iptable_project[i] + "," + str(len(task[i]))
        for t in task[i]:
            item += "," + t
        fout.write(item + "\n")

    fout.close()
Exemple #5
0
#!/usr/bin/python3
# -*- coding:utf-8 -*-
import os
import utils
#utils.execShellCommand("rm -rf *.txt")
algs = ['LLF', 'SJF', 'WRR', 'OUR']
syss = ['sys0', 'sys1', 'sys2']
forms = ['fct_tcp_out_1']
projects = ['P0', 'P1', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7']
debug = False
offline_syss = ['S0', 'S1', 'S2']
offline_time = 60
offline_when = 30
utils.execShellCommand("mkdir fct_offline_analysis")
for form in forms:
    for alg in algs:
        outpath = "fct_offline_analysis/fct_offline_analysis_" + alg + ".txt"
        fout = open(outpath, "w+")
        for offline_sys in offline_syss:
            for project in projects:
                fct_collect = []
                # 拿到三个系统的同一个用户的所有数据
                project_iperf3_file_list = []
                for sys in syss:
                    path = "./" + alg + "/" + sys + "/" + form + "/out/dat/1"
                    # print(path)

                    raw_file_list = os.listdir(path)  # 得到文件夹下的所有文件名称
                    # print(raw_file_list)

                    for raw_file in raw_file_list:  # 遍历文件夹
def openstack_delete_instance():
    ret = utils.execShellCommand("openstack server list |grep ubuntu").split(
        "\n")[0:-1]
    for i in range(len(ret)):
        id = ret[i].split("|")[1].strip()
        utils.execShellCommand("openstack server delete " + id)
def openstack_create_instance(info, my_id):
    flavor = openstack_flavor_create(info[0][0], info[0][1], info[0][2])
    cmd = "openstack server create --flavor " + flavor + " --image ubuntu_sdnlab "
    cmd += "--nic net-id=private --user-data config/ubuntu.config --availability-zone " + \
        zone[int(info[1][0])] + " "+my_id
    utils.execShellCommand(cmd)

def openstack_delete_instance():
    ret = utils.execShellCommand("openstack server list |grep ubuntu").split(
        "\n")[0:-1]
    for i in range(len(ret)):
        id = ret[i].split("|")[1].strip()
        utils.execShellCommand("openstack server delete " + id)


if __name__ == "__main__":

    print("******************************************************************")
    print("***                 project: P" + sys.argv[2])
    print("******************************************************************")
    computer_name = utils.execShellCommand("uname -n").strip()
    if sys.argv[1] == "create":
        raw_str = utils.read_file_as_str(sys.argv[3])
        pd_list = raw_str_parse(raw_str)
        instance_id = 0
        for i in range(len(pd_list)):
            info = pd_list[i]
            if int(info[1]
                   [1]) == sysId[computer_name] and sys.argv[2] == info[1][2]:
                #租户ID,实例ID,sysID,zoneID,vCPU,RAM,带宽
                my_id = "P" + str(
                    sys.argv[2]) + "I" + str(instance_id) + "_S" + str(
                        info[1][1]) + "Z" + str(info[1][0]) + "_C" + str(
                            info[0][0]) + "R" + str(info[0][1]) + "_B" + str(
                                info[0][2])
                openstack_create_instance(info, my_id)
def project_sg(project_name):
    ret = utils.execShellCommand("openstack project list |grep P" +
                                 project_name)
    if len(ret):
        project_id = ret.split("|")[1].strip()
        sg = utils.execShellCommand("openstack security group list | grep " +
                                    project_id)
        if (len(sg)):
            sg_id = sg.split("|")[1].strip()
            utils.execShellCommand(
                "openstack security group rule create --proto icmp " + sg_id)
            utils.execShellCommand(
                "openstack security group rule create --proto tcp --dst-port 22 "
                + sg_id)
            utils.execShellCommand(
                "openstack security group rule create --proto tcp --dst-port 25000 "
                + sg_id)
            utils.execShellCommand(
                "openstack security group rule create --proto tcp --dst-port 25001 "
                + sg_id)
            utils.execShellCommand(
                "openstack security group rule create --proto tcp --dst-port 25002 "
                + sg_id)
            utils.execShellCommand(
                "openstack security group rule create --proto tcp --dst-port 25003 "
                + sg_id)
            utils.execShellCommand(
                "openstack security group rule create --proto tcp --dst-port 25004 "
                + sg_id)
            utils.execShellCommand(
                "openstack security group rule create --proto tcp --dst-port 25005 "
                + sg_id)
            utils.execShellCommand(
                "openstack security group rule create --proto udp --dst-port 25000 "
                + sg_id)
            utils.execShellCommand(
                "openstack security group rule create --proto udp --dst-port 25001 "
                + sg_id)
            utils.execShellCommand(
                "openstack security group rule create --proto udp --dst-port 25002 "
                + sg_id)
            utils.execShellCommand(
                "openstack security group rule create --proto udp --dst-port 25003 "
                + sg_id)
            utils.execShellCommand(
                "openstack security group rule create --proto udp --dst-port 25004 "
                + sg_id)
            utils.execShellCommand(
                "openstack security group rule create --proto udp --dst-port 25005 "
                + sg_id)
def project_delete():
    utils.execShellCommand("rm -rf iptable.txt")
    ret = utils.execShellCommand("openstack project list |grep P").split(
        "\n")[0:-1]
    for i in range(len(ret)):
        ret[i] = ret[i].split("|")[1].strip()
        utils.execShellCommand("openstack project delete " + ret[i])
        sg = utils.execShellCommand("openstack security group list | grep " +
                                    ret[i])
        if (len(sg)):
            sg = sg.split("|")[1].strip()
            utils.execShellCommand("openstack security group delete " + sg)

    ret = utils.execShellCommand("openstack flavor list | grep cpu").split(
        "\n")[0:-1]
    for i in range(len(ret)):
        ret[i] = ret[i].split("|")[1].strip()
        utils.execShellCommand("openstack flavor delete " + ret[i])
Exemple #11
0
#!/usr/bin/python3
# -*- coding:utf-8 -*-
import os
import utils
from numpy import *
#utils.execShellCommand("rm -rf *.txt")
algs = ['LLF', 'SJF', 'WRR', 'OUR']
syss = ['sys0', 'sys1', 'sys2']
#forms = ['common_hack_tcp_out','common_hack_udp_out']
forms = ['common_hack_tcp_out']
projects = ['p0', 'p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7']
debug = False
utils.execShellCommand("mkdir bd_hack_analysis")
for form in forms:
    for alg in algs:
        outpath = "bd_hack_analysis/bd_hack_analysis_" + alg + ".txt"
        fout = open(outpath, "w+")
        for sys in syss:
            for project in projects:
                path = "./" + alg + "/" + sys + "/" + form + "/" + project + "_" + form + "/dat/1"
                #path = "./LLF/sys0/common_hack_tcp_out/p0_common_hack_tcp_out/dat/1" #文件夹目录
                raw_file_list = os.listdir(path)  #得到文件夹下的所有文件名称
                iperf3_file_list = []
                for raw_file in raw_file_list:  #遍历文件夹
                    if not os.path.isdir(raw_file):  #判断是否是文件夹,不是文件夹才打开
                        if "iperf3" in raw_file:
                            iperf3_file_list.append(path + "/" + raw_file)

                raw_dat = []
                for iperf3_file in iperf3_file_list:
                    raw_dat.append(