netrun-sim 0.1.0__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/Cargo.lock +2 -65
  2. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/PKG-INFO +1 -1
  3. netrun_sim-0.1.2/core/Cargo.toml +18 -0
  4. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/core/examples/diamond_flow.rs +105 -46
  5. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/core/examples/linear_flow.rs +65 -35
  6. netrun_sim-0.1.2/core/src/graph.rs +632 -0
  7. netrun_sim-0.1.2/core/src/graph_tests.rs +363 -0
  8. netrun_sim-0.1.2/core/src/net.rs +2173 -0
  9. netrun_sim-0.1.2/core/src/net_tests.rs +2027 -0
  10. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/core/src/test_fixtures.rs +56 -33
  11. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/core/tests/common/mod.rs +19 -28
  12. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/core/tests/graph_api.rs +112 -44
  13. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/core/tests/net_api.rs +66 -60
  14. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/core/tests/workflow.rs +126 -67
  15. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/pyproject.toml +12 -1
  16. netrun_sim-0.1.2/python/.envrc +3 -0
  17. netrun_sim-0.1.2/python/CHANGELOG.md +19 -0
  18. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/python/Cargo.toml +1 -2
  19. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/python/README.md +10 -14
  20. netrun_sim-0.1.2/python/examples/nbs/00_basic_net.ipynb +421 -0
  21. {netrun_sim-0.1.0/python/examples → netrun_sim-0.1.2/python/examples/nbs}/diamond_flow.ipynb +87 -221
  22. {netrun_sim-0.1.0/python/examples → netrun_sim-0.1.2/python/examples/nbs}/linear_flow.ipynb +74 -194
  23. netrun_sim-0.1.2/python/examples/pts/00_basic_net.pct.py +224 -0
  24. netrun_sim-0.1.2/python/examples/pts/diamond_flow.pct.py +337 -0
  25. netrun_sim-0.1.2/python/examples/pts/linear_flow.pct.py +293 -0
  26. netrun_sim-0.1.2/python/nblite.toml +10 -0
  27. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/python/netrun_sim/__init__.py +7 -2
  28. netrun_sim-0.1.2/python/netrun_sim/__init__.pyi +901 -0
  29. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/python/python/netrun_sim/__init__.py +7 -2
  30. netrun_sim-0.1.2/python/python/netrun_sim/__init__.pyi +901 -0
  31. netrun_sim-0.1.2/python/src/errors.rs +279 -0
  32. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/python/src/graph.rs +398 -218
  33. netrun_sim-0.1.2/python/src/net.rs +1251 -0
  34. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/python/uv.lock +411 -1947
  35. netrun_sim-0.1.0/core/Cargo.toml +0 -14
  36. netrun_sim-0.1.0/core/src/graph.rs +0 -912
  37. netrun_sim-0.1.0/core/src/net.rs +0 -1612
  38. netrun_sim-0.1.0/python/.envrc +0 -2
  39. netrun_sim-0.1.0/python/CHANGELOG.md +0 -6
  40. netrun_sim-0.1.0/python/examples/diamond_flow.py +0 -222
  41. netrun_sim-0.1.0/python/examples/graph_serialization.ipynb +0 -542
  42. netrun_sim-0.1.0/python/examples/linear_flow.py +0 -164
  43. netrun_sim-0.1.0/python/netrun_sim/__init__.pyi +0 -486
  44. netrun_sim-0.1.0/python/python/netrun_sim/__init__.pyi +0 -486
  45. netrun_sim-0.1.0/python/src/errors.rs +0 -156
  46. netrun_sim-0.1.0/python/src/net.rs +0 -818
  47. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/Cargo.toml +0 -0
  48. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/core/src/_utils.rs +0 -0
  49. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/core/src/lib.rs +0 -0
  50. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/python/netrun_sim/py.typed +0 -0
  51. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/python/publish_new_version.sh +0 -0
  52. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/python/python/netrun_sim/py.typed +0 -0
  53. {netrun_sim-0.1.0 → netrun_sim-0.1.2}/python/src/lib.rs +0 -0
@@ -90,12 +90,6 @@ dependencies = [
90
90
  "rustversion",
91
91
  ]
92
92
 
93
- [[package]]
94
- name = "itoa"
95
- version = "1.0.16"
96
- source = "registry+https://github.com/rust-lang/crates.io-index"
97
- checksum = "7ee5b5339afb4c41626dde77b7a611bd4f2c202b897852b4bcf5d03eddc61010"
98
-
99
93
  [[package]]
100
94
  name = "js-sys"
101
95
  version = "0.3.83"
@@ -118,12 +112,6 @@ version = "0.4.15"
118
112
  source = "registry+https://github.com/rust-lang/crates.io-index"
119
113
  checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab"
120
114
 
121
- [[package]]
122
- name = "memchr"
123
- version = "2.7.6"
124
- source = "registry+https://github.com/rust-lang/crates.io-index"
125
- checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
126
-
127
115
  [[package]]
128
116
  name = "memoffset"
129
117
  version = "0.9.1"
@@ -135,11 +123,10 @@ dependencies = [
135
123
 
136
124
  [[package]]
137
125
  name = "netrun-sim"
138
- version = "0.1.0"
126
+ version = "0.1.2"
139
127
  dependencies = [
140
128
  "indexmap",
141
- "serde",
142
- "serde_json",
129
+ "pyo3",
143
130
  "thiserror",
144
131
  "ulid",
145
132
  "utcnow",
@@ -151,7 +138,6 @@ version = "0.1.0"
151
138
  dependencies = [
152
139
  "netrun-sim",
153
140
  "pyo3",
154
- "serde_json",
155
141
  "ulid",
156
142
  ]
157
143
 
@@ -306,49 +292,6 @@ version = "1.0.22"
306
292
  source = "registry+https://github.com/rust-lang/crates.io-index"
307
293
  checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
308
294
 
309
- [[package]]
310
- name = "serde"
311
- version = "1.0.228"
312
- source = "registry+https://github.com/rust-lang/crates.io-index"
313
- checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
314
- dependencies = [
315
- "serde_core",
316
- "serde_derive",
317
- ]
318
-
319
- [[package]]
320
- name = "serde_core"
321
- version = "1.0.228"
322
- source = "registry+https://github.com/rust-lang/crates.io-index"
323
- checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
324
- dependencies = [
325
- "serde_derive",
326
- ]
327
-
328
- [[package]]
329
- name = "serde_derive"
330
- version = "1.0.228"
331
- source = "registry+https://github.com/rust-lang/crates.io-index"
332
- checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
333
- dependencies = [
334
- "proc-macro2",
335
- "quote",
336
- "syn",
337
- ]
338
-
339
- [[package]]
340
- name = "serde_json"
341
- version = "1.0.147"
342
- source = "registry+https://github.com/rust-lang/crates.io-index"
343
- checksum = "6af14725505314343e673e9ecb7cd7e8a36aa9791eb936235a3567cc31447ae4"
344
- dependencies = [
345
- "itoa",
346
- "memchr",
347
- "serde",
348
- "serde_core",
349
- "zmij",
350
- ]
351
-
352
295
  [[package]]
353
296
  name = "syn"
354
297
  version = "2.0.111"
@@ -604,9 +547,3 @@ dependencies = [
604
547
  "quote",
605
548
  "syn",
606
549
  ]
607
-
608
- [[package]]
609
- name = "zmij"
610
- version = "0.1.8"
611
- source = "registry+https://github.com/rust-lang/crates.io-index"
612
- checksum = "f1dccf46b25b205e4bebe1d5258a991df1cc17801017a845cb5b3fe0269781aa"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: netrun-sim
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Requires-Dist: python-ulid>=1.0
@@ -0,0 +1,18 @@
1
+ [package]
2
+ name = "netrun-sim"
3
+ description = "A flow-based development (FBD) simulation engine."
4
+ version = "0.1.2"
5
+ edition = "2024"
6
+ license-file = "../../LICENSE"
7
+ repository = "https://github.com/lukastk/netrun/"
8
+
9
+ [features]
10
+ default = []
11
+ python = ["pyo3"]
12
+
13
+ [dependencies]
14
+ indexmap = "2.12.1"
15
+ thiserror = "2.0"
16
+ ulid = "=1.1.0"
17
+ utcnow = "0.2.7"
18
+ pyo3 = { version = "0.23", features = ["abi3-py38"], optional = true }
@@ -13,11 +13,11 @@
13
13
  //! - Synchronization: D's epoch only triggers when both inputs are present
14
14
 
15
15
  use netrun_sim::graph::{
16
- Edge, EdgeRef, Graph, Node, Port, PortRef, PortSlotSpec, PortState, PortType,
16
+ Edge, Graph, MaxSalvos, Node, PacketCount, Port, PortRef, PortSlotSpec, PortState, PortType,
17
17
  SalvoCondition, SalvoConditionTerm,
18
18
  };
19
19
  use netrun_sim::net::{
20
- Net, NetAction, NetActionResponse, NetActionResponseData, PacketLocation,
20
+ NetAction, NetActionResponse, NetActionResponseData, NetSim, PacketLocation,
21
21
  };
22
22
  use std::collections::HashMap;
23
23
 
@@ -27,7 +27,7 @@ fn main() {
27
27
  println!("Created diamond graph: A -> B,C -> D");
28
28
  println!("D requires inputs from BOTH B and C\n");
29
29
 
30
- let mut net = Net::new(graph);
30
+ let mut net = NetSim::new(graph);
31
31
 
32
32
  // Create two packets and place them on edges from A
33
33
  let packet1 = create_packet(&mut net);
@@ -36,19 +36,28 @@ fn main() {
36
36
 
37
37
  // Place packet1 on edge A -> B
38
38
  let edge_a_b = edge_location("A", "out1", "B", "in");
39
- net.do_action(&NetAction::TransportPacketToLocation(packet1.clone(), edge_a_b));
39
+ net.do_action(&NetAction::TransportPacketToLocation(
40
+ packet1.clone(),
41
+ edge_a_b,
42
+ ));
40
43
  println!("Placed packet1 on edge A -> B");
41
44
 
42
45
  // Place packet2 on edge A -> C
43
46
  let edge_a_c = edge_location("A", "out2", "C", "in");
44
- net.do_action(&NetAction::TransportPacketToLocation(packet2.clone(), edge_a_c));
47
+ net.do_action(&NetAction::TransportPacketToLocation(
48
+ packet2.clone(),
49
+ edge_a_c,
50
+ ));
45
51
  println!("Placed packet2 on edge A -> C");
46
52
 
47
53
  // Run network - packets move to B and C, triggering epochs
48
- net.do_action(&NetAction::RunNetUntilBlocked);
54
+ net.run_until_blocked();
49
55
 
50
56
  let startable = net.get_startable_epochs();
51
- println!("\nAfter first run: {} startable epochs (B and C)", startable.len());
57
+ println!(
58
+ "\nAfter first run: {} startable epochs (B and C)",
59
+ startable.len()
60
+ );
52
61
 
53
62
  // Process B and C, sending outputs to D
54
63
  for epoch_id in startable {
@@ -70,8 +79,14 @@ fn main() {
70
79
  let output = create_packet_in_epoch(&mut net, &started.id);
71
80
 
72
81
  // Load into output port and send
73
- net.do_action(&NetAction::LoadPacketIntoOutputPort(output, "out".to_string()));
74
- net.do_action(&NetAction::SendOutputSalvo(started.id.clone(), "default".to_string()));
82
+ net.do_action(&NetAction::LoadPacketIntoOutputPort(
83
+ output,
84
+ "out".to_string(),
85
+ ));
86
+ net.do_action(&NetAction::SendOutputSalvo(
87
+ started.id.clone(),
88
+ "default".to_string(),
89
+ ));
75
90
 
76
91
  // Finish epoch
77
92
  net.do_action(&NetAction::FinishEpoch(started.id));
@@ -79,7 +94,7 @@ fn main() {
79
94
  }
80
95
 
81
96
  // Run network - packets move from B->D and C->D edges to D's input ports
82
- net.do_action(&NetAction::RunNetUntilBlocked);
97
+ net.run_until_blocked();
83
98
 
84
99
  // Check D's input ports
85
100
  let d_in1 = PacketLocation::InputPort("D".to_string(), "in1".to_string());
@@ -94,7 +109,10 @@ fn main() {
94
109
 
95
110
  if let Some(d_epoch_id) = startable_d.first() {
96
111
  let d_epoch = net.get_epoch(d_epoch_id).unwrap();
97
- println!("D's epoch received {} packets from both branches!", d_epoch.in_salvo.packets.len());
112
+ println!(
113
+ "D's epoch received {} packets from both branches!",
114
+ d_epoch.in_salvo.packets.len()
115
+ );
98
116
  }
99
117
 
100
118
  println!("\nDiamond flow example complete!");
@@ -106,9 +124,20 @@ fn create_diamond_graph() -> Graph {
106
124
  name: "A".to_string(),
107
125
  in_ports: HashMap::new(),
108
126
  out_ports: [
109
- ("out1".to_string(), Port { slots_spec: PortSlotSpec::Infinite }),
110
- ("out2".to_string(), Port { slots_spec: PortSlotSpec::Infinite }),
111
- ].into(),
127
+ (
128
+ "out1".to_string(),
129
+ Port {
130
+ slots_spec: PortSlotSpec::Infinite,
131
+ },
132
+ ),
133
+ (
134
+ "out2".to_string(),
135
+ Port {
136
+ slots_spec: PortSlotSpec::Infinite,
137
+ },
138
+ ),
139
+ ]
140
+ .into(),
112
141
  in_salvo_conditions: HashMap::new(),
113
142
  out_salvo_conditions: HashMap::new(),
114
143
  };
@@ -123,15 +152,31 @@ fn create_diamond_graph() -> Graph {
123
152
  let node_d = Node {
124
153
  name: "D".to_string(),
125
154
  in_ports: [
126
- ("in1".to_string(), Port { slots_spec: PortSlotSpec::Infinite }),
127
- ("in2".to_string(), Port { slots_spec: PortSlotSpec::Infinite }),
128
- ].into(),
155
+ (
156
+ "in1".to_string(),
157
+ Port {
158
+ slots_spec: PortSlotSpec::Infinite,
159
+ },
160
+ ),
161
+ (
162
+ "in2".to_string(),
163
+ Port {
164
+ slots_spec: PortSlotSpec::Infinite,
165
+ },
166
+ ),
167
+ ]
168
+ .into(),
129
169
  out_ports: HashMap::new(),
130
170
  in_salvo_conditions: [(
131
171
  "default".to_string(),
132
172
  SalvoCondition {
133
- max_salvos: 1,
134
- ports: vec!["in1".to_string(), "in2".to_string()],
173
+ max_salvos: MaxSalvos::Finite(1),
174
+ ports: [
175
+ ("in1".to_string(), PacketCount::All),
176
+ ("in2".to_string(), PacketCount::All),
177
+ ]
178
+ .into_iter()
179
+ .collect(),
135
180
  // Require BOTH inputs to be non-empty
136
181
  term: SalvoConditionTerm::And(vec![
137
182
  SalvoConditionTerm::Port {
@@ -144,7 +189,8 @@ fn create_diamond_graph() -> Graph {
144
189
  },
145
190
  ]),
146
191
  },
147
- )].into(),
192
+ )]
193
+ .into(),
148
194
  out_salvo_conditions: HashMap::new(),
149
195
  };
150
196
 
@@ -163,53 +209,66 @@ fn create_diamond_graph() -> Graph {
163
209
  fn create_simple_node(name: &str) -> Node {
164
210
  Node {
165
211
  name: name.to_string(),
166
- in_ports: [("in".to_string(), Port { slots_spec: PortSlotSpec::Infinite })].into(),
167
- out_ports: [("out".to_string(), Port { slots_spec: PortSlotSpec::Infinite })].into(),
212
+ in_ports: [(
213
+ "in".to_string(),
214
+ Port {
215
+ slots_spec: PortSlotSpec::Infinite,
216
+ },
217
+ )]
218
+ .into(),
219
+ out_ports: [(
220
+ "out".to_string(),
221
+ Port {
222
+ slots_spec: PortSlotSpec::Infinite,
223
+ },
224
+ )]
225
+ .into(),
168
226
  in_salvo_conditions: [(
169
227
  "default".to_string(),
170
228
  SalvoCondition {
171
- max_salvos: 1,
172
- ports: vec!["in".to_string()],
229
+ max_salvos: MaxSalvos::Finite(1),
230
+ ports: [("in".to_string(), PacketCount::All)].into_iter().collect(),
173
231
  term: SalvoConditionTerm::Port {
174
232
  port_name: "in".to_string(),
175
233
  state: PortState::NonEmpty,
176
234
  },
177
235
  },
178
- )].into(),
236
+ )]
237
+ .into(),
179
238
  out_salvo_conditions: [(
180
239
  "default".to_string(),
181
240
  SalvoCondition {
182
- max_salvos: 0,
183
- ports: vec!["out".to_string()],
241
+ max_salvos: MaxSalvos::Infinite,
242
+ ports: [("out".to_string(), PacketCount::All)]
243
+ .into_iter()
244
+ .collect(),
184
245
  term: SalvoConditionTerm::Port {
185
246
  port_name: "out".to_string(),
186
247
  state: PortState::NonEmpty,
187
248
  },
188
249
  },
189
- )].into(),
250
+ )]
251
+ .into(),
190
252
  }
191
253
  }
192
254
 
193
- fn create_edge(src_node: &str, src_port: &str, tgt_node: &str, tgt_port: &str) -> (EdgeRef, Edge) {
194
- (
195
- EdgeRef {
196
- source: PortRef {
197
- node_name: src_node.to_string(),
198
- port_type: PortType::Output,
199
- port_name: src_port.to_string(),
200
- },
201
- target: PortRef {
202
- node_name: tgt_node.to_string(),
203
- port_type: PortType::Input,
204
- port_name: tgt_port.to_string(),
205
- },
255
+ fn create_edge(src_node: &str, src_port: &str, tgt_node: &str, tgt_port: &str) -> Edge {
256
+ Edge {
257
+ source: PortRef {
258
+ node_name: src_node.to_string(),
259
+ port_type: PortType::Output,
260
+ port_name: src_port.to_string(),
206
261
  },
207
- Edge {},
208
- )
262
+ target: PortRef {
263
+ node_name: tgt_node.to_string(),
264
+ port_type: PortType::Input,
265
+ port_name: tgt_port.to_string(),
266
+ },
267
+ }
209
268
  }
210
269
 
211
270
  fn edge_location(src_node: &str, src_port: &str, tgt_node: &str, tgt_port: &str) -> PacketLocation {
212
- PacketLocation::Edge(EdgeRef {
271
+ PacketLocation::Edge(Edge {
213
272
  source: PortRef {
214
273
  node_name: src_node.to_string(),
215
274
  port_type: PortType::Output,
@@ -223,14 +282,14 @@ fn edge_location(src_node: &str, src_port: &str, tgt_node: &str, tgt_port: &str)
223
282
  })
224
283
  }
225
284
 
226
- fn create_packet(net: &mut Net) -> ulid::Ulid {
285
+ fn create_packet(net: &mut NetSim) -> ulid::Ulid {
227
286
  match net.do_action(&NetAction::CreatePacket(None)) {
228
287
  NetActionResponse::Success(NetActionResponseData::Packet(id), _) => id,
229
288
  _ => panic!("Failed to create packet"),
230
289
  }
231
290
  }
232
291
 
233
- fn create_packet_in_epoch(net: &mut Net, epoch_id: &ulid::Ulid) -> ulid::Ulid {
292
+ fn create_packet_in_epoch(net: &mut NetSim, epoch_id: &ulid::Ulid) -> ulid::Ulid {
234
293
  match net.do_action(&NetAction::CreatePacket(Some(epoch_id.clone()))) {
235
294
  NetActionResponse::Success(NetActionResponseData::Packet(id), _) => id,
236
295
  _ => panic!("Failed to create packet in epoch"),
@@ -8,11 +8,11 @@
8
8
  //! - Sending output salvos to continue flow
9
9
 
10
10
  use netrun_sim::graph::{
11
- Edge, EdgeRef, Graph, Node, Port, PortRef, PortSlotSpec, PortState, PortType,
11
+ Edge, Graph, MaxSalvos, Node, PacketCount, Port, PortRef, PortSlotSpec, PortState, PortType,
12
12
  SalvoCondition, SalvoConditionTerm,
13
13
  };
14
14
  use netrun_sim::net::{
15
- Net, NetAction, NetActionResponse, NetActionResponseData, PacketLocation,
15
+ NetAction, NetActionResponse, NetActionResponseData, NetSim, PacketLocation,
16
16
  };
17
17
  use std::collections::HashMap;
18
18
 
@@ -22,7 +22,7 @@ fn main() {
22
22
  println!("Created graph with {} nodes", graph.nodes().len());
23
23
 
24
24
  // Create a network from the graph
25
- let mut net = Net::new(graph);
25
+ let mut net = NetSim::new(graph);
26
26
 
27
27
  // Create a packet outside the network
28
28
  let packet_id = match net.do_action(&NetAction::CreatePacket(None)) {
@@ -34,7 +34,7 @@ fn main() {
34
34
  };
35
35
 
36
36
  // Transport packet to the edge A -> B
37
- let edge_a_b = PacketLocation::Edge(EdgeRef {
37
+ let edge_a_b = PacketLocation::Edge(Edge {
38
38
  source: PortRef {
39
39
  node_name: "A".to_string(),
40
40
  port_type: PortType::Output,
@@ -46,11 +46,14 @@ fn main() {
46
46
  port_name: "in".to_string(),
47
47
  },
48
48
  });
49
- net.do_action(&NetAction::TransportPacketToLocation(packet_id.clone(), edge_a_b));
49
+ net.do_action(&NetAction::TransportPacketToLocation(
50
+ packet_id.clone(),
51
+ edge_a_b,
52
+ ));
50
53
  println!("Placed packet on edge A -> B");
51
54
 
52
55
  // Run the network - packet moves to B's input port and triggers an epoch
53
- net.do_action(&NetAction::RunNetUntilBlocked);
56
+ net.run_until_blocked();
54
57
  println!("Ran network until blocked");
55
58
 
56
59
  // Check for startable epochs
@@ -71,18 +74,25 @@ fn main() {
71
74
  println!("Consumed input packet");
72
75
 
73
76
  // Create an output packet
74
- let output_packet = match net.do_action(&NetAction::CreatePacket(Some(epoch.id.clone()))) {
75
- NetActionResponse::Success(NetActionResponseData::Packet(id), _) => id,
76
- _ => panic!("Failed to create output packet"),
77
- };
77
+ let output_packet =
78
+ match net.do_action(&NetAction::CreatePacket(Some(epoch.id.clone()))) {
79
+ NetActionResponse::Success(NetActionResponseData::Packet(id), _) => id,
80
+ _ => panic!("Failed to create output packet"),
81
+ };
78
82
  println!("Created output packet: {}", output_packet);
79
83
 
80
84
  // Load it into the output port
81
- net.do_action(&NetAction::LoadPacketIntoOutputPort(output_packet.clone(), "out".to_string()));
85
+ net.do_action(&NetAction::LoadPacketIntoOutputPort(
86
+ output_packet.clone(),
87
+ "out".to_string(),
88
+ ));
82
89
  println!("Loaded packet into output port");
83
90
 
84
91
  // Send the output salvo
85
- net.do_action(&NetAction::SendOutputSalvo(epoch.id.clone(), "default".to_string()));
92
+ net.do_action(&NetAction::SendOutputSalvo(
93
+ epoch.id.clone(),
94
+ "default".to_string(),
95
+ ));
86
96
  println!("Sent output salvo - packet is now on edge B -> C");
87
97
 
88
98
  // Finish the epoch
@@ -90,12 +100,15 @@ fn main() {
90
100
  println!("Finished epoch");
91
101
 
92
102
  // Run the network again - packet moves to C
93
- net.do_action(&NetAction::RunNetUntilBlocked);
103
+ net.run_until_blocked();
94
104
  println!("Ran network until blocked again");
95
105
 
96
106
  // Check for new startable epochs at C
97
107
  let startable_c = net.get_startable_epochs();
98
- println!("New startable epochs (should be at C): {}", startable_c.len());
108
+ println!(
109
+ "New startable epochs (should be at C): {}",
110
+ startable_c.len()
111
+ );
99
112
  }
100
113
  _ => panic!("Failed to start epoch"),
101
114
  }
@@ -125,12 +138,26 @@ fn create_linear_graph() -> Graph {
125
138
  fn create_node(name: &str, in_ports: Vec<&str>, out_ports: Vec<&str>) -> Node {
126
139
  let in_ports_map: HashMap<String, Port> = in_ports
127
140
  .iter()
128
- .map(|p| (p.to_string(), Port { slots_spec: PortSlotSpec::Infinite }))
141
+ .map(|p| {
142
+ (
143
+ p.to_string(),
144
+ Port {
145
+ slots_spec: PortSlotSpec::Infinite,
146
+ },
147
+ )
148
+ })
129
149
  .collect();
130
150
 
131
151
  let out_ports_map: HashMap<String, Port> = out_ports
132
152
  .iter()
133
- .map(|p| (p.to_string(), Port { slots_spec: PortSlotSpec::Infinite }))
153
+ .map(|p| {
154
+ (
155
+ p.to_string(),
156
+ Port {
157
+ slots_spec: PortSlotSpec::Infinite,
158
+ },
159
+ )
160
+ })
134
161
  .collect();
135
162
 
136
163
  // Default input salvo condition: trigger when any input port is non-empty
@@ -139,8 +166,11 @@ fn create_node(name: &str, in_ports: Vec<&str>, out_ports: Vec<&str>) -> Node {
139
166
  in_salvo_conditions.insert(
140
167
  "default".to_string(),
141
168
  SalvoCondition {
142
- max_salvos: 1,
143
- ports: in_ports.iter().map(|s| s.to_string()).collect(),
169
+ max_salvos: MaxSalvos::Finite(1),
170
+ ports: in_ports
171
+ .iter()
172
+ .map(|s| (s.to_string(), PacketCount::All))
173
+ .collect(),
144
174
  term: SalvoConditionTerm::Port {
145
175
  port_name: in_ports[0].to_string(),
146
176
  state: PortState::NonEmpty,
@@ -155,8 +185,11 @@ fn create_node(name: &str, in_ports: Vec<&str>, out_ports: Vec<&str>) -> Node {
155
185
  out_salvo_conditions.insert(
156
186
  "default".to_string(),
157
187
  SalvoCondition {
158
- max_salvos: 0, // unlimited
159
- ports: out_ports.iter().map(|s| s.to_string()).collect(),
188
+ max_salvos: MaxSalvos::Infinite,
189
+ ports: out_ports
190
+ .iter()
191
+ .map(|s| (s.to_string(), PacketCount::All))
192
+ .collect(),
160
193
  term: SalvoConditionTerm::Port {
161
194
  port_name: out_ports[0].to_string(),
162
195
  state: PortState::NonEmpty,
@@ -174,20 +207,17 @@ fn create_node(name: &str, in_ports: Vec<&str>, out_ports: Vec<&str>) -> Node {
174
207
  }
175
208
  }
176
209
 
177
- fn create_edge(src_node: &str, src_port: &str, tgt_node: &str, tgt_port: &str) -> (EdgeRef, Edge) {
178
- (
179
- EdgeRef {
180
- source: PortRef {
181
- node_name: src_node.to_string(),
182
- port_type: PortType::Output,
183
- port_name: src_port.to_string(),
184
- },
185
- target: PortRef {
186
- node_name: tgt_node.to_string(),
187
- port_type: PortType::Input,
188
- port_name: tgt_port.to_string(),
189
- },
210
+ fn create_edge(src_node: &str, src_port: &str, tgt_node: &str, tgt_port: &str) -> Edge {
211
+ Edge {
212
+ source: PortRef {
213
+ node_name: src_node.to_string(),
214
+ port_type: PortType::Output,
215
+ port_name: src_port.to_string(),
190
216
  },
191
- Edge {},
192
- )
217
+ target: PortRef {
218
+ node_name: tgt_node.to_string(),
219
+ port_type: PortType::Input,
220
+ port_name: tgt_port.to_string(),
221
+ },
222
+ }
193
223
  }