簡體   English   中英

使用帶權重的路徑列表檢測網絡上的問題節點

[英]Detect problematic nodes on network using a list of paths with weight

我正在嘗試檢測網絡中有問題/緩慢的節點,為此,我有一個節點之間的路徑列表以及將消息發送到目的地所花費的錯誤或重傳次數。 例如:

[
    {'path':['a', 'c', 'e', 'z'], 'errors': 0},
    ...
    {'path':['a', 'b', 'd', 'z'], 'errors': 4},
    {'path':['a', 'c', 'd', 'z'], 'errors': 4},
    ...
    {'path':['a', 'b', 'e', 'z'], 'errors': 0}
]

理論上,我擁有節點之間的所有可能路徑及其各自的延遲。 因此,使用這些數據,我想檢測“有問題的節點”。 在前面的例子中,有幾個路徑,但是所有通過d節點的路徑都會有更多的延遲,所以這個節點(和其他類似的)必須被查明有問題。

有沒有已知的算法來解決這個問題?

我天真的方法是對每條路徑使用錯誤計數器並將這些計數器添加到路徑上的每個節點,然后當所有路徑/節點都被處理時,將錯誤計數器除以該節點的鄰居數。 但這並沒有給我一個好的結果,將不同的節點顯示為有問題。

一個代碼示例:

import networkx as nx
import matplotlib.pyplot as plt
import random


def get_problematic_nodes(path_list):
    node_connections = {}
    node_counter_dict = {}
    for e in path_list:
        value = 0
        if e['retransmits'] > 1:
            value = 1

        path_len = len(e['path'])
        for i in xrange(path_len):
            node = e['path'][i]
            if node not in node_counter_dict:
                node_counter_dict[node] = value
            else:
                node_counter_dict[node] += value

            if node not in node_connections:
                node_connections[node] = set()

            # previous node
            if i - 1 >= 0:
                node_connections[node].add(e['path'][i - 1])

            # next node
            if i + 1 <= path_len - 1:
                node_connections[node].add(e['path'][i + 1])

    nodes_score = {}

    print "Link size for every node:"
    for k, v in node_connections.items():
        link_number = len(v)
        print "Node: {} links:{}".format(k, link_number)
        nodes_score[k] = node_counter_dict[k]/link_number

    print "\nHeuristic score for every node:"
    for k,v in nodes_score.items():
        print "Node: {} score:{}".format(k, v)

    max_score_node_key = max(node_counter_dict.iterkeys(), key=(lambda key: node_counter_dict[key]/len(node_connections[key]) ))
    print "\nMax scored node: {}".format(max_score_node_key)

edge_list = [
    ('host1', 'leaf1'),
    ('host2', 'leaf2'),
    ('leaf1', 'spine1'),
    ('leaf1', 'spine2'),
    ('leaf2', 'spine1'),
    ('leaf2', 'spine2'),
    ('spine1', 'vmx8'),
    ('spine1', 'vmx9'),
    ('spine2', 'vmx8'),
    ('spine2', 'vmx9'),
    ('vmx8', 'vmx7'),
    ('vmx9', 'vmx7'),
    ('spine3', 'vmx8'),
    ('spine3', 'vmx9'),
    ('spine4', 'vmx8'),
    ('spine4', 'vmx9'),
    ('leaf3', 'spine3'),
    ('leaf3', 'spine4'),
    ('leaf4', 'spine3'),
    ('leaf4', 'spine4'),
    ('host3', 'leaf3'),
    ('host4', 'leaf4'),
]

# prepare graph
G = nx.Graph()
for e in edge_list:
    G.add_edge(*e)

# define problematic nodes
test_problem_nodes = ['spine3']

# generate the paths. Paths that touches problematic nodes have more retransmits
test_path_list = []
hosts = ['host1', 'host2', 'host3', 'host4']
for h1 in hosts:
    for h2 in hosts:
        if h1 == h2:
            continue

        all_paths = nx.all_simple_paths(G, h1, h2)
        for path in all_paths:
            retransmits = 0
            if len(set(path).intersection(set(test_problem_nodes))) > 0:
                retransmits = 10

            test_path_list.append({
                'src': h1,
                'dst': h2,
                'path': path,
                'retransmits': retransmits
                })

# nx.draw(G, with_labels=True)
# plt.draw()
# plt.show()

get_problematic_nodes(test_path_list)

我認為您想通過觀察到的路徑數量來規范您的錯誤計數。 get_problematic_nodes更改為

def get_problematic_nodes(event_list):
    numerator = dict()
    denominator = dict()
    for event in event_list:
        for node in event['path']:
            try:
                numerator[node] += event['retransmits']
                denominator[node] += 1
            except KeyError:
                numerator[node] = event['retransmits']
                denominator[node] = 1

    node_score = {node : numerator[node] / denominator[node] for node in numerator.keys()}

    print "\nHeuristic score for every node:"
    for k,v in node_score.items():
        print "Node: {} score:{}".format(k, v)

    max_score = None
    for k,v in node_score.items():
        if v > max_score:
            max_score_node_key = k
            max_score = v
    print "\nMax scored node: {}".format(max_score_node_key)

產量:

Heuristic score for every node:
Node: vmx9 score:8
Node: vmx8 score:8
Node: host1 score:7
Node: vmx7 score:7
Node: spine1 score:7
Node: leaf4 score:8
Node: spine3 score:10
Node: spine2 score:7
Node: leaf1 score:7
Node: spine4 score:7
Node: leaf3 score:8
Node: leaf2 score:7
Node: host3 score:8
Node: host4 score:8
Node: host2 score:7

Max scored node: spine3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM