Skip to content

Commit eedd3c6

Browse files
committed
Add leaf-spine topology parser
1 parent eb7f7fe commit eedd3c6

16 files changed

Lines changed: 319 additions & 72 deletions

configs/leaf-spine/network.yml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
topology_config_path: topology.yml
1+
topology_config_path: new-topology.yml
22

33
presets:
44
default-connection:
@@ -16,50 +16,50 @@ presets:
1616

1717
connections:
1818
conn_1--2:
19-
sender_id: host_1
20-
receiver_id: host_2
19+
sender_id: host-1
20+
receiver_id: host-2
2121
preset-name: default-connection
2222
conn_1--3:
23-
sender_id: host_1
24-
receiver_id: host_3
23+
sender_id: host-1
24+
receiver_id: host-3
2525
preset-name: default-connection
2626
conn_1--4:
27-
sender_id: host_1
28-
receiver_id: host_4
27+
sender_id: host-1
28+
receiver_id: host-4
2929
preset-name: default-connection
3030
conn_2--1:
31-
sender_id: host_2
32-
receiver_id: host_1
31+
sender_id: host-2
32+
receiver_id: host-1
3333
preset-name: default-connection
3434
conn_2--3:
35-
sender_id: host_2
36-
receiver_id: host_3
35+
sender_id: host-2
36+
receiver_id: host-3
3737
preset-name: default-connection
3838
conn_2--4:
39-
sender_id: host_2
40-
receiver_id: host_4
39+
sender_id: host-2
40+
receiver_id: host-4
4141
preset-name: default-connection
4242
conn_3--1:
43-
sender_id: host_3
44-
receiver_id: host_1
43+
sender_id: host-3
44+
receiver_id: host-1
4545
preset-name: default-connection
4646
conn_3--2:
47-
sender_id: host_3
48-
receiver_id: host_2
47+
sender_id: host-3
48+
receiver_id: host-2
4949
preset-name: default-connection
5050
conn_3--4:
51-
sender_id: host_3
52-
receiver_id: host_4
51+
sender_id: host-3
52+
receiver_id: host-4
5353
preset-name: default-connection
5454
conn_4--1:
55-
sender_id: host_4
56-
receiver_id: host_1
55+
sender_id: host-4
56+
receiver_id: host-1
5757
preset-name: default-connection
5858
conn_4--2:
59-
sender_id: host_4
60-
receiver_id: host_2
59+
sender_id: host-4
60+
receiver_id: host-2
6161
preset-name: default-connection
6262
conn_4--3:
63-
sender_id: host_4
64-
receiver_id: host_3
63+
sender_id: host-4
64+
receiver_id: host-3
6565
preset-name: default-connection
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
type: leaf-spine
2+
3+
presets:
4+
link:
5+
latency: 0ns
6+
throughput: 100Gbps
7+
ingress_buffer_size: 64KB
8+
egress_buffer_size: 64KB
9+
metrics_filters:
10+
queue_sizes: false
11+
12+
packet-spraying:
13+
type: random
14+
15+
switches:
16+
spine:
17+
count: 2
18+
19+
leaf:
20+
count: 4
21+
22+
hosts:
23+
24+
links:
25+
leaf-spine:
26+
preset-name: link
27+
28+
host-leaf:
29+
preset-name: link

configs/leaf-spine/topology.yml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ packet-spraying:
1212
type: random
1313

1414
hosts:
15-
host_1:
16-
host_2:
17-
host_3:
18-
host_4:
15+
host-1:
16+
host-2:
17+
host-3:
18+
host-4:
1919

2020
switches:
2121
spine_1:
@@ -94,38 +94,38 @@ links:
9494
to: spine_2
9595
preset-name: default-link
9696

97-
leaf_1--host_1:
97+
leaf_1--host-1:
9898
from: leaf_1
99-
to: host_1
99+
to: host-1
100100
preset-name: default-link
101-
host_1--leaf_1:
102-
from: host_1
101+
host-1--leaf_1:
102+
from: host-1
103103
to: leaf_1
104104
preset-name: default-link
105105

106-
leaf_2--host_2:
106+
leaf_2--host-2:
107107
from: leaf_2
108-
to: host_2
108+
to: host-2
109109
preset-name: default-link
110-
host_2--leaf_2:
111-
from: host_2
110+
host-2--leaf_2:
111+
from: host-2
112112
to: leaf_2
113113
preset-name: default-link
114114

115-
leaf_3--host_3:
115+
leaf_3--host-3:
116116
from: leaf_3
117-
to: host_3
117+
to: host-3
118118
preset-name: default-link
119-
host_3--leaf_3:
120-
from: host_3
119+
host-3--leaf_3:
120+
from: host-3
121121
to: leaf_3
122122
preset-name: default-link
123123

124-
leaf_4--host_4:
124+
leaf_4--host-4:
125125
from: leaf_4
126-
to: host_4
126+
to: host-4
127127
preset-name: default-link
128-
host_4--leaf_4:
129-
from: host_4
128+
host-4--leaf_4:
129+
from: host-4
130130
to: leaf_4
131131
preset-name: default-link

source/parser/config_reader/config_node_with_preset_.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,9 @@ const std::optional<ConfigNode> ConfigNodeWithPreset::get_presets_node()
105105
return m_presets_node;
106106
}
107107

108+
ConfigNodeWithPreset load_file_with_presets(std::filesystem::path path) {
109+
ConfigNode node = load_file(path);
110+
return ConfigNodeWithPreset(node, node["presets"].to_optional());
111+
}
112+
108113
} // namespace sim

source/parser/config_reader/config_node_with_preset_.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,6 @@ class ConfigNodeWithPreset {
5252
mutable std::optional<ConfigNode> m_preset;
5353
};
5454

55+
ConfigNodeWithPreset load_file_with_presets(std::filesystem::path path);
56+
5557
} // namespace sim

source/parser/network/network_parser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Network parse_network(const std::filesystem::path& path) {
1212
std::string topology_config_path =
1313
parse_relative_path(node, "topology_config_path", path.parent_path());
1414

15-
const ConfigNode topology_config = load_file(topology_config_path);
15+
const ConfigNodeWithPreset topology_config =
16+
load_file_with_presets(topology_config_path);
1617

1718
Topology topology = parse_topology(topology_config);
1819

source/parser/topology/common.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "common.hpp"
2+
3+
#include "link/link_parser.hpp"
4+
5+
namespace sim {
6+
7+
void add_directed_link(std::shared_ptr<IDevice> from,
8+
std::shared_ptr<IDevice> to,
9+
const ConfigNodeWithPreset& preset,
10+
utils::IdTable<ILink>& links_table) {
11+
std::shared_ptr<ILink> link = parse_i_link(from, to, preset);
12+
if (!links_table.emplace(link->get_id(), link).second) {
13+
throw std::runtime_error(
14+
fmt::format("Duplicate of link with name {} ", link->get_id()));
15+
}
16+
};
17+
18+
void add_links_between(std::shared_ptr<IDevice> from,
19+
std::shared_ptr<IDevice> to,
20+
const ConfigNodeWithPreset& preset,
21+
utils::IdTable<ILink>& links_table) {
22+
add_directed_link(from, to, preset, links_table);
23+
add_directed_link(to, from, preset, links_table);
24+
};
25+
26+
} // namespace sim

source/parser/topology/common.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
#include "parser/config_reader/config_node_with_preset_.hpp"
3+
#include "topology/link/i_link.hpp"
4+
#include "utils/id_table.hpp"
5+
6+
namespace sim {
7+
8+
void add_directed_link(std::shared_ptr<IDevice> from,
9+
std::shared_ptr<IDevice> to,
10+
const ConfigNodeWithPreset& preset,
11+
utils::IdTable<ILink>& links_table);
12+
13+
void add_links_between(std::shared_ptr<IDevice> device_1,
14+
std::shared_ptr<IDevice> device_2,
15+
const ConfigNodeWithPreset& preset,
16+
utils::IdTable<ILink>& links_table);
17+
18+
} // namespace sim

source/parser/topology/incast_topology_parser.cpp

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "incast_topology_parser.hpp"
22

3+
#include "common.hpp"
34
#include "host/host_parser.hpp"
4-
#include "link/link_parser.hpp"
55
#include "switch/switch_parser.hpp"
66

77
namespace sim {
@@ -43,32 +43,16 @@ Topology parse_incast_topology(const ConfigNode& node) {
4343
node_with_preset["links"].value_or_throw();
4444

4545
utils::IdTable<ILink> links;
46-
auto add_two_way_link = [&links](const ConfigNodeWithPreset& preset,
47-
std::shared_ptr<IDevice> from,
48-
std::shared_ptr<IDevice> to) {
49-
auto add_directed_link = [&preset, &links](
50-
std::shared_ptr<IDevice> from,
51-
std::shared_ptr<IDevice> to) {
52-
std::shared_ptr<ILink> link = parse_i_link(from, to, preset);
53-
if (!links.emplace(link->get_id(), link).second) {
54-
throw std::runtime_error(fmt::format(
55-
"Duplicate of link with name {} ", link->get_id()));
56-
}
57-
};
58-
59-
add_directed_link(from, to);
60-
add_directed_link(to, from);
61-
};
6246

6347
// create links from between senders and switch
6448
for (const auto& [_, sender] : senders) {
65-
add_two_way_link(links_preset, sender, swtch);
49+
add_links_between(sender, swtch, links_preset, links);
6650
}
6751

6852
const ConfigNodeWithPreset& bottleneck_link_preset =
6953
ConfigNodeWithPreset(node)["bottleneck-link"].value_or(links_preset);
7054

71-
add_two_way_link(bottleneck_link_preset, swtch, receiver);
55+
add_links_between(swtch, receiver, bottleneck_link_preset, links);
7256

7357
TopologyContext ctx;
7458

0 commit comments

Comments
 (0)