• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

atlanticwave-sdx / pce / 3696789509

pending completion
3696789509

Pull #81

github

GitHub
<a href="https://github.com/atlanticwave-sdx/pce/commit/<a class=hub.com/atlanticwave-sdx/pce/commit/<a class="double-link" href="https://git"><a class=hub.com/atlanticwave-sdx/pce/commit/<a class="double-link" href="https://git"><a class=hub.com/atlanticwave-sdx/pce/commit/<a class="double-link" href="https://git"><a class=hub.com/atlanticwave-sdx/pce/commit/<a class="double-link" href="https://git"><a class=hub.com/atlanticwave-sdx/pce/commit/ff0d020164dd0bf2808d409fdfccaf947aaeeadd">ff0d02016">&lt;a href=&quot;https://github.com/atlanticwave-sdx/pce/commit/</a><a class="double-link" href="https://github.com/atlanticwave-sdx/pce/commit/&lt;a class=&quot;double-link&quot; href=&quot;https://git">&lt;a class=</a>hub.com/atlanticwave-sdx/pce/commit/&lt;a class=&quot;double-link&quot; href=&quot;https://git">&lt;a class=</a>hub.com/atlanticwave-sdx/pce/commit/&lt;a class=&quot;double-link&quot; href=&quot;https://git">&lt;a class=</a>hub.com/atlanticwave-sdx/pce/commit/&lt;a class=&quot;double-link&quot; href=&quot;https://git">&lt;a class=</a>hub.com/atlanticwave-sdx/pce/commit/&lt;a class=&quot;double-link&quot; href=&quot;https://git">&lt;a class=</a>hub.com/atlanticwave-sdx/pce/commit/ff0d020164dd0bf2808d409fdfccaf947aaeeadd">ff0d02016</a><a href="https://github.com/atlanticwave-sdx/pce/commit/ff0d020164dd0bf2808d409fdfccaf947aaeeadd">&quot;&gt;&amp;lt;a href=&amp;quot;https://github.com/atlanticwave-sdx/pce/commit/&lt;/a&gt;&lt;a class=&quot;double-link&quot; href=&quot;https://github.com/atlanticwave-sdx/pce/commit/&amp;lt;a class=&amp;quot;double-link&amp;quot; href=&amp;quot;https://git&quot;&gt;&amp;lt;a class=&lt;/a&gt;hub.com/atlanticwave-sdx/pce/commit/&amp;lt;a class=&amp;quot;double-link&amp;quot; href=&amp;quot;https://git&quot;&gt;&amp;lt;a class=&lt;/a&gt;hub.com/atlanticwave-sdx/pce/commit/&amp;lt;a class=&amp;quot;double-link&amp;quot; href=&amp;quot;https://git&quot;&gt;&amp;lt;a class=&lt;/a&gt;hub.com/atlanticwave-sdx/pce/commit/ff0d020164dd0bf2808d409fdfccaf947aaeeadd&quot;&gt;ff0d02016&lt;/a&gt;&lt;a href=&quot;https://github.com/atlanticwave-sdx/pce/commit/ff0d020164dd0bf2808d409fdfccaf947aaeeadd&quot;&gt;&amp;lt;a href=&amp;quot;https://github.com/atlanticwave-sdx/pce/commit/ff0d020164dd0bf2808d409fdfccaf947aaeeadd&amp;quot;&amp;gt;&amp;amp;quot;&amp;amp;gt;&amp;amp;amp;lt;a href=&amp;amp;amp;quot;https://github.com/atlanti... (continued)
Pull Request #81: Update coveralls.io configuration

845 of 1796 relevant lines covered (47.05%)

1.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.0
/src/Utility/randomTopologyGenerator.py
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
"""
3✔
4
Created on Tue Mar  8 13:34:06 2022
5

6
@author: Yufeng Xin (yxin@renci.org)
7
"""
8
import copy
3✔
9
import json
3✔
10
import operator
3✔
11
import random
3✔
12
import re
3✔
13
import time
3✔
14

15
import networkx as nx
3✔
16
import numpy as np
3✔
17
import pylab as plt
3✔
18
from networkx.algorithms import approximation as approx
3✔
19
from networkx.generators.random_graphs import erdos_renyi_graph
3✔
20

21
import Utility.global_name as global_name
3✔
22
from Utility.functions import GraphFunction
3✔
23

24

25
class RandomTopologyGenerator:
3✔
26
    # inputs:
27
    #   N: Total number of the random network's nodes
28
    #   P: link creation probability
29
    def __init__(
3✔
30
        self,
31
        N,
32
        P=0.2,
33
        l_bw=global_name.Min_L_BW,
34
        u_bw=global_name.Max_L_BW,
35
        l_lat=global_name.Min_L_LAT,
36
        u_lat=global_name.Max_L_LAT,
37
        seed=2022,
38
    ):
39
        random.seed(seed)
3✔
40
        self.seed = seed
3✔
41

42
        self.num_node = N
3✔
43
        self.link_probability = P
3✔
44

45
        self.low_bw = l_bw
3✔
46
        self.upper_bw = u_bw
3✔
47
        self.low_latency = l_lat
3✔
48
        self.upper_latency = u_lat
3✔
49

50
        self.graphFunction = GraphFunction()
3✔
51

52
    def bw_range(self, l_bw, u_bw):
3✔
53
        self.low_bw = l_bw
×
54
        self.upper_bw = u_bw
×
55

56
    def latency_range(self, l_lat, u_lat):
3✔
57
        self.low_latency = l_lat
×
58
        self.upper_latency = u_lat
×
59

60
    def set_graph(self, g):
3✔
61
        self.graph = g
×
62

63
    def get_graph(self):
3✔
64
        return self.graph
×
65

66
    def get_latency_list(self):
3✔
67
        return self.latency_list
×
68

69
    def get_distance_list(self):
3✔
70
        return self.distance_list
×
71

72
    def generate_graph(self, plot=True, g=None):
3✔
73
        # generate a random graph
74
        if g is None:
3✔
75
            while True:
1✔
76
                g = erdos_renyi_graph(self.num_node, self.link_probability, self.seed)
3✔
77
                if nx.is_connected(g):
3✔
78
                    connectivity = approx.node_connectivity(g)
3✔
79
                    if connectivity > 1:
3✔
80
                        print("Connectivity:" + str(connectivity))
3✔
81
                        print("Min edge cut:" + str(len(nx.minimum_edge_cut(g))))
3✔
82
                        break
3✔
83
                    else:
84
                        self.seed += 1
3✔
85
                else:
86
                    self.seed += 1
3✔
87

88
        self.graph = g
3✔
89

90
        if plot:
3✔
91
            nx.draw(g, with_labels=True)
3✔
92
            plt.savefig("rg.png")
3✔
93
            plt.clf()
3✔
94

95
        self.link_property_assign()
3✔
96

97
        self.graphFunction.set_graph(g)
3✔
98

99
        self.graphFunction.weight_assign()
3✔
100

101
        return self.graph
3✔
102

103
    # set the random bw and latency per link
104
    def link_property_assign(self):  ## pass in the bw name
3✔
105
        self.latency_list = []
3✔
106
        for (u, v, w) in self.graph.edges(data=True):
3✔
107
            w[global_name.bandwidth] = random.randint(self.low_bw, self.upper_bw)
3✔
108
            w[global_name.original_bandwidth] = w[global_name.bandwidth]
3✔
109
            latency = random.randint(self.low_latency, self.upper_latency)
3✔
110
            w[global_name.latency] = latency
3✔
111
            self.latency_list.append(latency)
3✔
112

113
        return self.latency_list
3✔
114

115
    # set weight (cost) per link, assuming the objective is minizing a function of weight
116
    #   flag:
117
    #       1: bw: weight = alpha*(1.0/bw)
118
    #       2: latency: weight = latency
119
    #       2: random: weight = random cost
120
    #       3: cost: given from outside (static) definition
121
    #       default: hop: weight =1
122
    def weight_assign(self, flag=5, cost=None):
3✔
123
        random.seed(self.seed)
×
124
        distance_list = []
×
125

126
        if flag == 1:
×
127
            for (u, v, w) in self.graph.edges(data=True):
×
128
                w[global_name.weight] = global_name.alpha * (
×
129
                    1.0 / w[global_name.bandwidth]
130
                )
131
                distance_list.append(w[global_name.weight])
×
132
        elif flag == 2:
×
133
            for (u, v, w) in self.graph.edges(data=True):
×
134
                w[global_name.weight] = w[global_name.latency]
×
135
                distance_list.append(w[global_name.weight])
×
136
        elif flag == 3:
×
137
            for (u, v, w) in self.graph.edges(data=True):
×
138
                w[global_name.weight] = random.randint(1, 2**24)
×
139
                distance_list.append(w[global_name.weight])
×
140
        elif flag == 4:
×
141
            for (u, v, w) in self.graph.edges(data=True):
×
142
                w[global_name.weight] = cost[u, v]
×
143
                distance_list.append(w[global_name.weight])
×
144
        else:
145
            for (u, v, w) in self.graph.edges(data=True):
×
146
                w[global_name.weight] = 1.0
×
147
                distance_list.append(w[global_name.weight])
×
148
        self.distance_list = distance_list
×
149
        return distance_list
×
150

151
    # if u and v connected
152
    def nodes_connected(g, u, v):
3✔
153
        return u in g.neighbors(v)
×
154

155
    def get_connectivity(self):
3✔
156
        con = approx.node_connectivity(self.graph)
×
157
        return con
×
158

159

160
def dot_file(topology_file, te_file=None):
3✔
161
    graph = nx.Graph(nx.nx_pydot.read_dot(topology_file))
3✔
162
    # graph = nx.Graph(nx.nx_agraph.read_dot(topology_file))
163
    num_nodes = graph.number_of_nodes()
3✔
164
    mapping = dict(zip(graph, range(num_nodes)))
3✔
165
    graph = nx.relabel_nodes(graph, mapping)
3✔
166

167
    for (u, v, w) in graph.edges(data=True):
3✔
168
        if not "capacity" in w.keys():
3✔
169
            bandwidth = 1000.0
×
170
        else:
171
            capacity = w["capacity"].strip('"')
3✔
172
            bw = re.split(r"(\D+)", capacity)
3✔
173
            bandwidth = bw[0]
3✔
174
            if bw[1].startswith("G"):
3✔
175
                bandwidth = float(bw[0]) * 1000
3✔
176

177
        w[global_name.original_bandwidth] = float(bandwidth)
3✔
178
        w[global_name.bandwidth] = float(bandwidth)
3✔
179
        w[global_name.weight] = float(w["cost"])
3✔
180
        if not "latency" in w.keys():
3✔
181
            latency = 10
3✔
182
            w[global_name.latency] = latency
3✔
183

184
    connectivity = approx.node_connectivity(graph)
3✔
185
    print("Connectivity:" + str(connectivity))
3✔
186

187
    with open(te_file) as f:
3✔
188
        tm = json.load(f)
3✔
189
    o_tm = []
3✔
190
    for t in tm:
3✔
191
        tr = tuple(t)
3✔
192
        o_tm.append(tr)
3✔
193

194
    return graph, o_tm
3✔
195
    # connection = GetConnection('../test/data/test_connection.json')
196
    # g = GetNetworkToplogy(25,0.4)
197
    # print(lbnxgraphgenerator(25, 0.4,connection,g))
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc