Probe generators
diamond_miner.generators
probe_generator(prefixes, flow_ids, ttls, *, prefix_len_v4=DEFAULT_PREFIX_LEN_V4, prefix_len_v6=DEFAULT_PREFIX_LEN_V6, probe_src_port=DEFAULT_PROBE_SRC_PORT, probe_dst_port=DEFAULT_PROBE_DST_PORT, mapper_v4=SequentialFlowMapper(DEFAULT_PREFIX_SIZE_V4), mapper_v6=SequentialFlowMapper(DEFAULT_PREFIX_SIZE_V6), seed=None)
Generate a probe for each prefix, flow ID and TTL, in a random order.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prefixes |
Sequence[tuple[str, str]]
|
A list of (prefix, protocol) tuples. The protocol can be |
required |
flow_ids |
Sequence[int]
|
The flow IDs to probe. |
required |
ttls |
Sequence[int]
|
The TTLs to probe. |
required |
prefix_len_v4 |
int
|
The prefix length to which the IPv4 prefixes will be split to. |
DEFAULT_PREFIX_LEN_V4
|
prefix_len_v6 |
int
|
The prefix length to which the IPv6 prefixes will be split to. |
DEFAULT_PREFIX_LEN_V6
|
probe_src_port |
int
|
The minimum source port of the probes (can be incremented by the flow mapper). |
DEFAULT_PROBE_SRC_PORT
|
probe_dst_port |
int
|
The destination port of the probes (constant). |
DEFAULT_PROBE_DST_PORT
|
mapper_v4 |
FlowMapper
|
The flow mapper for IPv4 probes. |
SequentialFlowMapper(DEFAULT_PREFIX_SIZE_V4)
|
mapper_v6 |
FlowMapper
|
The flow mapper for IPv6 probes. |
SequentialFlowMapper(DEFAULT_PREFIX_SIZE_V6)
|
seed |
int | None
|
The seed of the random permutation (two calls with the same seed will yield the probes in the same order). |
None
|
Examples:
This function is very versatile, it can generate Tokyo-Ping[@pelsser2013paris], Paris-Traceroute[@augustin2006avoiding] or Yarrp-like[@beverly2016yarrp] probes.
For ICMP probes, the source port is encoded by caracal in the checksum field of the ICMP header which is generally used by routers for per-flow load-balancing.
prefixes = [("8.8.8.8/32", "icmp"), ("2001:4860:4860::8888/128", "icmp6")]
prefix_len_v4 = 32
prefix_len_v6 = 128
flow_ids = range(2)
ttls = [32]
# When given a prefix size of 1, the sequential flow mapper will only vary the port.
mapper_v4 = SequentialFlowMapper(prefix_size=1)
mapper_v6 = SequentialFlowMapper(prefix_size=1)
prefixes = [("1.0.0.0/24", "icmp")]
prefix_len_v4 = 32 # The generator will cut the /24 in 256 /32.
flow_ids = range(1)
ttls = [32]
# Same flow mappers as above.
# 256 addresses * 2 flows * 30 TTLs = 15,360 probes.
prefixes = [("1.0.0.0/24", "udp")]
prefix_len_v4 = 32 # The generator will cut the /24 in 256 /32.
flow_ids = range(2)
ttls = range(2, 32)
# Same flow mappers as above.
# 1 prefix * 6 flows * 30 TTLs = 180 probes.
prefixes = [("1.0.0.0/24", "udp")]
prefix_len_v4 = 24 # We want to target the prefix, not its individual addresses.
flow_ids = range(6)
ttls = range(2, 32)
# The random flow mapper will assign a random destination (in the /24) to each flow.
mapper_v4 = RandomFlowMapper(prefix_size=256)
Source code in diamond_miner/generators/standalone.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
probe_generator_by_flow(prefixes, flow_ids, *, prefix_len_v4=DEFAULT_PREFIX_LEN_V4, prefix_len_v6=DEFAULT_PREFIX_LEN_V6, probe_src_port=DEFAULT_PROBE_SRC_PORT, probe_dst_port=DEFAULT_PROBE_DST_PORT, mapper_v4=SequentialFlowMapper(DEFAULT_PREFIX_SIZE_V4), mapper_v6=SequentialFlowMapper(DEFAULT_PREFIX_SIZE_V6), seed=None)
Generate a probe for each prefix, flow id and TTL, in a random order. This function differs from probe_generator in two aspects:
- The TTLs are specified for each prefixes, and not globally.
- All the probes for a given prefix and flow id are generated sequentially.
The parameters and output are identical to probe_generator,
excepted for prefixes
which is a list of (prefix, protocol, TTLs) tuples,
and the absence of the ttls
parameter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prefixes |
Iterable[tuple[str, str, Iterable[int]]]
|
TODO |
required |
Source code in diamond_miner/generators/standalone.py
probe_generator_from_database(client, measurement_id, round_, *, mapper_v4=SequentialFlowMapper(DEFAULT_PREFIX_SIZE_V4), mapper_v6=SequentialFlowMapper(DEFAULT_PREFIX_SIZE_V6), probe_src_port=DEFAULT_PROBE_SRC_PORT, probe_dst_port=DEFAULT_PROBE_DST_PORT, probe_ttl_geq=None, probe_ttl_leq=None, subsets=(UNIVERSE_SUBSET))
TODO: Doctest, note that this doesn't randomize probes.
Examples:
>>> from ipaddress import ip_address
>>> from diamond_miner.insert import insert_probe_counts
>>> from diamond_miner.test import client, create_tables
>>> create_tables(client, "test_probe_gen")
>>> insert_probe_counts(client, "test_probe_gen", 1, [("8.8.0.0/23", "icmp", [1, 2], 2)])
>>> probes = list(probe_generator_from_database(client, "test_probe_gen", 1))
>>> len(probes)
8
>>> (str(ip_address(probes[0][0])), *probes[0][1:])
('::ffff:808:100', 24000, 33434, 1, 'icmp')
Source code in diamond_miner/generators/database.py
probe_generator_parallel(filepath, client, measurement_id, round_, *, mapper_v4=SequentialFlowMapper(DEFAULT_PREFIX_SIZE_V4), mapper_v6=SequentialFlowMapper(DEFAULT_PREFIX_SIZE_V6), probe_src_port=DEFAULT_PROBE_SRC_PORT, probe_dst_port=DEFAULT_PROBE_DST_PORT, probe_ttl_geq=None, probe_ttl_leq=None, max_open_files=8192, n_workers=max(available_cpus() // 8, 1))
Compute the probes to send given the previously discovered links. This function shuffle the probes on-disk: External-memory shuffling in linear time?
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath |
Path
|
Output file (Zstd-compressed CSV file); will be overwritten. |
required |
client |
ClickHouseClient
|
ClickHouse client. |
required |
measurement_id |
str
|
Measurement id. |
required |
round_ |
int
|
Number of the round for which to generate the probes. |
required |
mapper_v4 |
FlowMapper
|
The flow mapper for IPv4 probes. |
SequentialFlowMapper(DEFAULT_PREFIX_SIZE_V4)
|
mapper_v6 |
FlowMapper
|
The flow mapper for IPv6 probes. |
SequentialFlowMapper(DEFAULT_PREFIX_SIZE_V6)
|
probe_src_port |
int
|
The minimum source port of the probes (can be incremented by the flow mapper). |
DEFAULT_PROBE_SRC_PORT
|
probe_dst_port |
int
|
The destination port of the probes (constant). |
DEFAULT_PROBE_DST_PORT
|