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

atlanticwave-sdx / pce / 10605525519

28 Aug 2024 10:45PM CUT 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

92.86
/src/sdx_pce/utils/random_connection_generator.py
1
import numpy as np
4✔
2

3
from sdx_pce.models import ConnectionRequest, TrafficMatrix
4✔
4

5

6
class RandomConnectionGenerator:
4✔
7
    def __init__(self, num_nodes):
4✔
8
        """
9
        :param num_nodes: Number of nodes of the topology.
10
        """
11
        self.num_nodes = num_nodes
4✔
12

13
    # Output: list of tuples of request
14
    def generate(self, querynum, l_bw, u_bw, l_lat, u_lat, seed=2022) -> TrafficMatrix:
4✔
15
        """
16
        Create a random traffic matrix.
17

18
        :param querynum: Number of connections.
19

20
        :return: A connection matrix.  A connection matrix is list of
21
                 connections, and each item in the list is of the
22
                 format (source, destination, bandwidth, latency).
23
        """
24
        np.random.seed(seed)
4✔
25
        connection_requests = []
4✔
26

27
        bw = self.lognormal((l_bw + u_bw) / 2.0, 1, querynum)
4✔
28
        if querynum <= self.num_nodes:
4✔
29
            for i in range(querynum):
4✔
30
                source = np.random.randint(1, (self.num_nodes + 1) / 2.0)
4✔
31
                destination = np.random.randint(
4✔
32
                    (self.num_nodes + 1) / 2.0, self.num_nodes
33
                )
34
                required_bandwidth = bw[i]
4✔
35
                required_latency = np.random.randint(l_lat, u_lat)
4✔
36

37
                request = ConnectionRequest(
4✔
38
                    source=source,
39
                    destination=destination,
40
                    required_bandwidth=required_bandwidth,
41
                    required_latency=required_latency,
42
                )
43

44
                connection_requests.append(request)
4✔
45
        else:
46
            for i in range(querynum):
4✔
47
                source = np.random.randint(0, self.num_nodes)
4✔
48
                destination = np.random.randint(0, self.num_nodes)
4✔
49
                while destination == source:
4✔
50
                    destination = np.random.randint(0, self.num_nodes)
×
51
                # query.append(np.random.randint(l_bw, u_bw))
52
                required_bandwidth = bw[i]
4✔
53
                required_latency = np.random.randint(l_lat, u_lat)
4✔
54

55
                request = ConnectionRequest(
4✔
56
                    source=source,
57
                    destination=destination,
58
                    required_bandwidth=required_bandwidth,
59
                    required_latency=required_latency,
60
                )
61

62
                connection_requests.append(request)
4✔
63

64
        request_id = f"request-{np.random.randint(1, 100)}"
4✔
65

66
        return TrafficMatrix(
4✔
67
            connection_requests=connection_requests, request_id=request_id
68
        )
69

70
    def lognormal(self, mu, sigma, size):
4✔
71
        normal_std = 0.5
4✔
72
        # normal_std = np.sqrt(np.log(1 + (sigma/mu)**2))
73
        normal_mean = np.log(mu) - normal_std**2 / 2
4✔
74
        return np.random.lognormal(normal_mean, normal_std, size)
4✔
75

76
    def random(self, min, mx, size):
4✔
77
        return np.random.randint(min, max, 1000)
×
78

79

80
# tm = RandomConnectionGenerator(20)
81
# connection = tm.generate(3, 100, 1000, 1000, 1500, 2022)
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