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

atlanticwave-sdx / pce / 10605525519

28 Aug 2024 10:45PM UTC coverage: 86.016%. Remained the same
10605525519

Pull #220

github

web-flow
Merge f2e578eec into de3e571a4
Pull Request #220: add an unittest for concurrent connections in a request in SDX format

586 of 717 branches covered (81.73%)

Branch coverage included in aggregate %.

1124 of 1271 relevant lines covered (88.43%)

3.53 hits per line

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

84.44
/src/sdx_pce/utils/graphviz.py
1
"""
4✔
2
Handlers for topology description in Graphviz dot format.
3

4
Topology description in dot format used to be popular.  There exist
5
dot files for several well-known networks like Geant, and they were
6
used for the algorithm performance study, and of course it extended
7
SDX to support one more topology description format potentially from
8
OXPs.
9

10
This is optional since this needs's networkx's support for dot file
11
format is changing -- networkx's dot file support used pydot, but
12
pydot is being deprecated in favor of pygraphviz:
13

14
https://github.com/networkx/networkx/issues/5723
15

16
Pydot is "pure" Python, and pygraphviz is implemented as bindings to
17
graphviz C library, so installing the latter is a little more work.
18
"""
19

20
import re
4✔
21
from pathlib import Path
4✔
22
from typing import Union
4✔
23

24
import networkx as nx
4✔
25
from networkx.algorithms import approximation as approx
4✔
26

27
from sdx_pce.utils.constants import Constants
4✔
28

29
__all__ = ["can_read_dot_file", "read_dot_file"]
4✔
30

31

32
def can_read_dot_file() -> bool:
4✔
33
    """
34
    See if we have pygraphviz or pydot installed.
35
    """
36
    try:
4✔
37
        # try to read dot file using pygraphviz
38
        nx.nx_agraph.read_dot(None)
4✔
39
        return True
4✔
40
    except ImportError as e:
×
41
        print(f"pygraphviz doesn't seem to be available: {e}")
×
42
        return False
×
43

44

45
def read_dot_file(topology_file: Union[str, Path]) -> nx.Graph:
4✔
46
    """
47
    Read a Graphviz dot file and return a graph.
48
    """
49
    # try to read dot file using pygraphviz
50
    graph = nx.Graph(nx.nx_agraph.read_dot(topology_file))
4✔
51

52
    # If we must use pydot, use the line below:
53
    # graph = nx.Graph(nx.nx_pydot.read_dot(topology_file))
54

55
    num_nodes = graph.number_of_nodes()
4✔
56
    mapping = dict(zip(graph, range(num_nodes)))
4✔
57
    graph = nx.relabel_nodes(graph, mapping)
4✔
58

59
    for u, v, w in graph.edges(data=True):
4!
60
        if "capacity" not in w.keys():
4✔
61
            bandwidth = 1000.0
×
62
        else:
63
            capacity = w["capacity"].strip('"')
4✔
64
            bw = re.split(r"(\D+)", capacity)
4✔
65
            bandwidth = float(bw[0])
4✔
66
            if bw[1].startswith("G"):
4✔
67
                bandwidth = float(bw[0]) * 1000
4✔
68

69
        w[Constants.ORIGINAL_BANDWIDTH] = float(bandwidth)
4!
70
        w[Constants.BANDWIDTH] = float(bandwidth)
4✔
71
        w[Constants.WEIGHT] = float(w["cost"])
4✔
72
        if Constants.LATENCY not in w.keys():
4✔
73
            latency = 10
4✔
74
            w[Constants.LATENCY] = latency
4✔
75

76
    connectivity = approx.node_connectivity(graph)
4✔
77
    print(f"Connectivity: {connectivity}")
4✔
78

79
    return graph
4✔
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