Пример #1
0
def checkCloud(src_level, dst_level_list):
    """ 根据LR的互联网云类型,计算到其他所有LR的联通性 """
    dst_level_list_copy = copy.deepcopy(dst_level_list)
    relationship_list = getAncestor(src_level, [])
    relationship_list.insert(0, src_level)
    src_lrc = lrCluster(src_level)
    src_lr_id = src_lrc.randomLr()
    src_lrtype = getLrProperty(src_lr_id, "lr_type")
    # 修改dlr可以联通的是父层所有,包括lr类型
    #  element_1 = src_lrtype == "dlr"
    #  element_2 = True
    #  p_level = getPlevel(src_level)
    #  p_src_lrc = lrCluster(p_level)
    #  p_src_lrid = p_src_lrc.randomLr()
    #  if p_src_lrid:
    #  p_src_lrtype = getLrProperty(p_src_lrid, "lr_type")
    #  element_2 = p_src_lrtype == "dlr"
    #
    #  if element_1 and element_2:
    if src_lrtype == "dlr":
        lr_conn_list = relationship_list
        #  lrtype = "dlr"
    else:
        for dst_level in dst_level_list:
            dst_lrc = lrCluster(dst_level)
            dst_lr_id = dst_lrc.randomLr()
            dst_lr_type = getLrProperty(dst_lr_id, "lr_type")
            if dst_lr_type == "dlr": dst_level_list_copy.remove(dst_level)
        lr_conn_list = dst_level_list_copy
        if src_level not in lr_conn_list: lr_conn_list.insert(0, src_level)
        #  lrtype = "lr"
    return (lr_conn_list, relationship_list)
Пример #2
0
 def getValidlr(self):
     level_list = self.getValidlevel()
     lr_valid_list = []
     for level in level_list:
         dst_lrc = lrCluster(level)
         dst_lr_id = dst_lrc.randomLr()
         #  ip = getLrProperty(dst_lr_id, "ip")
         #  port = getLrProperty(dst_lr_id, "port")
         #  lr_valid_list.append({"id": lr[0], "ip": ip, "port":port})
         lr_valid_list.append(dst_lr_id)
     return lr_valid_list
Пример #3
0
    def lrAddall(self):
        self.lrAddself()
        src_lrc = lrCluster(self.src_level)
        src_lr_id = src_lrc.randomLr()
        src_price = getLrProperty(src_lr_id, "price")
        dst_level_list = getAlllevel()
        sql_data = []
        for dst_level in dst_level_list:
            if dst_level == self.src_level: continue
            check_cloud_res, relationship_list = checkCloud(
                dst_level, [self.src_level])
            dlr_level_list = {}
            for k, v in enumerate(relationship_list):
                dlr_level_list[v] = k
            if dlr_level_list.has_key(self.src_level):
                layer_distance = dlr_level_list[self.src_level]
            else:
                layer_distance = 0

            if len(check_cloud_res) <= 1:
                weight = path = 0
            else:
                check_operator_res = checkOperator(dst_level, [self.src_level])
                if len(check_operator_res["conn_list"]) != 0: weight = 1
                elif len(check_operator_res["half_conn"]) != 0: weight = 0.5
                if src_price == 0:
                    if layer_distance:
                        path = layer_distance / weight
                    else:
                        impassable_num = len(dlr_level_list)
                        path = impassable_num / weight
                else:
                    if layer_distance:
                        path = math.sqrt(
                            src_price / 100) * layer_distance / weight
                    else:
                        impassable_num = len(dlr_level_list)
                        path = math.sqrt(
                            src_price / 100) * impassable_num / weight

            sql_data.append(
                (dst_level, self.src_level, weight, layer_distance, path))
            #  print "*"*40, dst_level, self.src_level, weight, layer_distance, path
            redis_client.hmset("qos:%s:%s" % (dst_level, self.src_level), {
                "weight": weight,
                "layer_distance": layer_distance,
                "path": path
            })

        if not sql_data: return 0
        else:
            sqli = """insert into net_qos (`level_src`, `level_dst`, `weight`, `layer_distance`, `path`) values (%s, %s, %s, %s, %s)"""

            return db.execOnly(sqli, sql_data)
Пример #4
0
def checkOperator(src_level, dst_level_list):
    """ 根据网络运营商类型,计算出一个LR 到其他所有LR的联通性 """
    src_lrc = lrCluster(src_level)
    src_lr_id = src_lrc.randomLr()
    src_operator = getLrProperty(src_lr_id, "operator").lower()
    operators_outer = nc_config.operators["outer"]
    conn_list = []
    not_conn_list = []
    half_conn_list = []
    for dst_level in dst_level_list:
        dst_lrc = lrCluster(dst_level)
        dst_lr_id = dst_lrc.randomLr()
        dst_operator = getLrProperty(dst_lr_id, "operator").lower()
        if src_operator == dst_operator: conn_list.append(dst_level)
        else:
            comp_res = set(operators_outer) & set([src_operator, dst_operator])
            if len(comp_res) > 0: half_conn_list.append(dst_level)
            else: not_conn_list.append(dst_level)
    return {
        "conn_list": conn_list,
        "half_conn": half_conn_list,
        "not_conn": not_conn_list
    }
Пример #5
0
    def lrAddself(self):

        dst_level_list = getAlllevel()
        #  dst_level_list.remove(self.src_level)
        level_conn_list, relationship_list = checkCloud(
            self.src_level, dst_level_list)
        operator_res = checkOperator(self.src_level, dst_level_list)
        operator_half_conn_list = set(operator_res["half_conn"])
        operator_not_conn_list = set(operator_res["not_conn"])
        res_half_list = list(set(level_conn_list) & operator_half_conn_list)
        res_conn_list = list(
            set(level_conn_list) - set(res_half_list) - operator_not_conn_list)
        self.logger.info("level_id: %s - connlist: %s - halflist: %s " %
                         (self.src_level, res_conn_list, res_half_list))
        dlr_level_list = {}
        for k, v in enumerate(relationship_list):
            dlr_level_list[v] = k

        sql_data_1 = []
        for dst_level in dst_level_list:
            if dst_level == self.src_level:
                weight = 1
                layer_distance = 0
                path = weight
                sql_data_1.append(
                    (self.src_level, dst_level, weight, layer_distance, path))
                redis_client.hmset(
                    "qos:%s:%s" % (self.src_level, dst_level), {
                        "weight": weight,
                        "layer_distance": layer_distance,
                        "path": path
                    })
                continue
            dst_lrc = lrCluster(dst_level)
            dst_lr_id = dst_lrc.randomLr()
            dst_price = getLrProperty(dst_lr_id, "price")
            if dlr_level_list.has_key(dst_level):
                layer_distance = dlr_level_list[dst_level]
            else:
                layer_distance = 0

            if (dst_level not in res_conn_list) and (dst_level
                                                     not in res_half_list):
                weight = 0
                path = 0
            else:
                if dst_level in res_conn_list: weight = 1
                elif dst_level in res_half_list: weight = 0.5
                if dst_price == 0:
                    if layer_distance:
                        path = layer_distance / weight
                    else:
                        impassable_num = len(dlr_level_list)
                        path = impassable_num / weight
                else:
                    if layer_distance:
                        path = math.sqrt(
                            dst_price / 100) * layer_distance / weight
                    else:
                        impassable_num = len(dlr_level_list)
                        path = math.sqrt(
                            dst_price / 100) * impassable_num / weight
            sql_data_1.append(
                (self.src_level, dst_level, weight, layer_distance, path))
            redis_client.hmset("qos:%s:%s" % (self.src_level, dst_level), {
                "weight": weight,
                "layer_distance": layer_distance,
                "path": path
            })

        if not sql_data_1: return 0
        else:
            sqli = """insert into net_qos (`level_src`, `level_dst`, `weight`, `layer_distance`, `path`) values (%s, %s, %s, %s, %s)"""
            return db.execOnly(sqli, sql_data_1)