-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_data_templates.py
More file actions
1041 lines (897 loc) · 36.7 KB
/
test_data_templates.py
File metadata and controls
1041 lines (897 loc) · 36.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
Modular test data templates and components for scenario testing.
This module provides reusable, composable templates for creating NetGraph
test scenarios with consistent patterns. The templates reduce code duplication,
improve test maintainability, and enable rapid creation of test scenarios.
Key Template Categories:
- NetworkTemplates: Common network topologies (linear, star, mesh, ring, tree)
- BlueprintTemplates: Reusable blueprint patterns for hierarchies
- FailurePolicyTemplates: Standard failure scenario configurations
- TrafficDemandTemplates: Traffic demand patterns and distributions
- WorkflowTemplates: Common analysis workflow configurations
- ScenarioTemplateBuilder: High-level builder for complete scenarios
- CommonScenarios: Pre-built scenarios for typical use cases
Design Principles:
- Composability: Templates can be combined and layered
- Parameterization: All templates accept configuration parameters
- Consistency: Similar interfaces across all template types
- Reusability: Templates can be used across multiple test scenarios
- Maintainability: Centralized definitions reduce duplication
Usage Patterns:
1. Basic topology creation with NetworkTemplates
2. Hierarchies with BlueprintTemplates
3. Complete scenarios with ScenarioTemplateBuilder
4. Quick test setups with CommonScenarios
"""
from typing import Any, Dict, List, Optional
from .helpers import ScenarioDataBuilder
# Template configuration constants for consistent testing
DEFAULT_LINK_CAPACITY = 10.0 # Default capacity for template-generated links
DEFAULT_LINK_COST = 1 # Default cost for template-generated links
DEFAULT_TRAFFIC_DEMAND = 1.0 # Default traffic demand value
DEFAULT_BLUEPRINT_CAPACITY = 10.0 # Default capacity for blueprint links
# Network template size limits for safety
MAX_MESH_NODES = 20 # Prevent accidentally creating huge meshes
MAX_TREE_DEPTH = 10 # Prevent deep recursion in tree generation
MAX_BRANCHING_FACTOR = 20 # Prevent excessive tree branching
class NetworkTemplates:
"""Templates for common network topologies."""
@staticmethod
def linear_network(
node_names: List[str], link_capacity: float = 10.0
) -> Dict[str, Any]:
"""Create a linear network topology (A-B-C-D...)."""
network_data = {"nodes": {name: {} for name in node_names}, "links": []}
for i in range(len(node_names) - 1):
network_data["links"].append(
{
"source": node_names[i],
"target": node_names[i + 1],
"link_params": {"capacity": link_capacity, "cost": 1},
}
)
return network_data
@staticmethod
def star_network(
center_node: str, leaf_nodes: List[str], link_capacity: float = 10.0
) -> Dict[str, Any]:
"""Create a star network topology (center node connected to all leaf nodes)."""
all_nodes = [center_node] + leaf_nodes
network_data = {"nodes": {name: {} for name in all_nodes}, "links": []}
for leaf in leaf_nodes:
network_data["links"].append(
{
"source": center_node,
"target": leaf,
"link_params": {"capacity": link_capacity, "cost": 1},
}
)
return network_data
@staticmethod
def mesh_network(
node_names: List[str], link_capacity: float = 10.0
) -> Dict[str, Any]:
"""Create a full mesh network topology (all nodes connected to all others)."""
network_data = {"nodes": {name: {} for name in node_names}, "links": []}
for i, source in enumerate(node_names):
for j, target in enumerate(node_names):
if i != j: # Skip self-loops
network_data["links"].append(
{
"source": source,
"target": target,
"link_params": {"capacity": link_capacity, "cost": 1},
}
)
return network_data
@staticmethod
def ring_network(
node_names: List[str], link_capacity: float = 10.0
) -> Dict[str, Any]:
"""Create a ring network topology (nodes connected in a circle)."""
network_data = {"nodes": {name: {} for name in node_names}, "links": []}
for i in range(len(node_names)):
next_i = (i + 1) % len(node_names)
network_data["links"].append(
{
"source": node_names[i],
"target": node_names[next_i],
"link_params": {"capacity": link_capacity, "cost": 1},
}
)
return network_data
@staticmethod
def tree_network(
depth: int, branching_factor: int, link_capacity: float = 10.0
) -> Dict[str, Any]:
"""Create a tree network topology with specified depth and branching factor."""
nodes = {}
links = []
# Generate nodes
node_id = 0
queue = [(f"node_{node_id}", 0)] # (node_name, current_depth)
nodes[f"node_{node_id}"] = {}
node_id += 1
while queue:
parent_name, current_depth = queue.pop(0)
if current_depth < depth:
for _ in range(branching_factor):
child_name = f"node_{node_id}"
nodes[child_name] = {}
# Add link from parent to child
links.append(
{
"source": parent_name,
"target": child_name,
"link_params": {"capacity": link_capacity, "cost": 1},
}
)
queue.append((child_name, current_depth + 1))
node_id += 1
return {"nodes": nodes, "links": links}
class BlueprintTemplates:
"""Templates for common blueprint patterns."""
@staticmethod
def simple_group_blueprint(
group_name: str, node_count: int, name_template: Optional[str] = None
) -> Dict[str, Any]:
"""Create a simple blueprint with one group of nodes."""
if name_template is None:
name_template = f"{group_name}-{{node_num}}"
return {
"groups": {
group_name: {"node_count": node_count, "name_template": name_template}
}
}
@staticmethod
def two_tier_blueprint(
tier1_count: int = 4,
tier2_count: int = 4,
pattern: str = "mesh",
link_capacity: float = 10.0,
) -> Dict[str, Any]:
"""Create a two-tier blueprint (leaf-spine pattern)."""
return {
"groups": {
"tier1": {"node_count": tier1_count, "name_template": "t1-{node_num}"},
"tier2": {"node_count": tier2_count, "name_template": "t2-{node_num}"},
},
"adjacency": [
{
"source": "/tier1",
"target": "/tier2",
"pattern": pattern,
"link_params": {"capacity": link_capacity, "cost": 1},
}
],
}
@staticmethod
def three_tier_clos_blueprint(
leaf_count: int = 4,
spine_count: int = 4,
super_spine_count: int = 2,
link_capacity: float = 10.0,
) -> Dict[str, Any]:
"""Create a three-tier Clos blueprint."""
return {
"groups": {
"leaf": {"node_count": leaf_count, "name_template": "leaf-{node_num}"},
"spine": {
"node_count": spine_count,
"name_template": "spine-{node_num}",
},
"super_spine": {
"node_count": super_spine_count,
"name_template": "ss-{node_num}",
},
},
"adjacency": [
{
"source": "/leaf",
"target": "/spine",
"pattern": "mesh",
"link_params": {"capacity": link_capacity, "cost": 1},
},
{
"source": "/spine",
"target": "/super_spine",
"pattern": "mesh",
"link_params": {"capacity": link_capacity, "cost": 1},
},
],
}
@staticmethod
def nested_blueprint(
inner_blueprint_name: str,
wrapper_group_name: str = "wrapper",
additional_groups: Optional[Dict[str, Any]] = None,
) -> Dict[str, Any]:
"""Create a blueprint that wraps another blueprint with additional components."""
blueprint_data = {
"groups": {wrapper_group_name: {"use_blueprint": inner_blueprint_name}}
}
if additional_groups:
blueprint_data["groups"].update(additional_groups)
return blueprint_data
class FailurePolicyTemplates:
"""Templates for common failure policy patterns."""
@staticmethod
def single_link_failure() -> Dict[str, Any]:
"""Template for single link failure policy."""
return {
"attrs": {
"description": "Single link failure scenario",
},
"rules": [{"entity_scope": "link", "rule_type": "choice", "count": 1}],
}
@staticmethod
def single_node_failure() -> Dict[str, Any]:
"""Template for single node failure policy."""
return {
"attrs": {
"description": "Single node failure scenario",
},
"rules": [{"entity_scope": "node", "rule_type": "choice", "count": 1}],
}
@staticmethod
def multiple_failure(entity_scope: str, count: int) -> Dict[str, Any]:
"""Template for multiple simultaneous failures."""
return {
"attrs": {
"description": f"Multiple {entity_scope} failure scenario",
},
"rules": [
{"entity_scope": entity_scope, "rule_type": "choice", "count": count}
],
}
@staticmethod
def all_links_failure() -> Dict[str, Any]:
"""Template for all links failure policy."""
return {
"attrs": {
"description": "All links failure scenario",
},
"rules": [{"entity_scope": "link", "rule_type": "all"}],
}
@staticmethod
def risk_group_failure(risk_group_name: str) -> Dict[str, Any]:
"""Template for risk group-based failure policy."""
return {
"attrs": {
"description": f"Failure of risk group {risk_group_name}",
},
"fail_risk_groups": True,
"rules": [
{
"entity_scope": "link",
"rule_type": "conditional",
"conditions": [f"risk_groups.contains('{risk_group_name}')"],
}
],
}
class TrafficDemandTemplates:
"""Templates for common traffic demand patterns."""
@staticmethod
def all_to_all_uniform(
node_names: List[str], demand_value: float = 1.0
) -> List[Dict[str, Any]]:
"""Create uniform all-to-all traffic demands."""
demands = []
for source in node_names:
for sink in node_names:
if source != sink: # Skip self-demands
demands.append(
{
"source_path": source,
"sink_path": sink,
"demand": demand_value,
}
)
return demands
@staticmethod
def star_traffic(
center_node: str, leaf_nodes: List[str], demand_value: float = 1.0
) -> List[Dict[str, Any]]:
"""Create star traffic pattern (all traffic to/from center node)."""
demands = []
# Traffic from leaves to center
for leaf in leaf_nodes:
demands.append(
{"source_path": leaf, "sink_path": center_node, "demand": demand_value}
)
# Traffic from center to leaves
for leaf in leaf_nodes:
demands.append(
{"source_path": center_node, "sink_path": leaf, "demand": demand_value}
)
return demands
@staticmethod
def random_demands(
node_names: List[str],
num_demands: int,
min_demand: float = 1.0,
max_demand: float = 10.0,
seed: int = 42,
) -> List[Dict[str, Any]]:
"""Create random traffic demands between nodes."""
import random
random.seed(seed)
demands = []
for _ in range(num_demands):
source = random.choice(node_names)
sink = random.choice([n for n in node_names if n != source])
demand_value = random.uniform(min_demand, max_demand)
demands.append(
{"source_path": source, "sink_path": sink, "demand": demand_value}
)
return demands
@staticmethod
def hotspot_traffic(
hotspot_nodes: List[str],
other_nodes: List[str],
hotspot_demand: float = 10.0,
normal_demand: float = 1.0,
) -> List[Dict[str, Any]]:
"""Create traffic with hotspot patterns (high demand to/from certain nodes)."""
demands = []
# High demand traffic to hotspots
for source in other_nodes:
for hotspot in hotspot_nodes:
demands.append(
{
"source_path": source,
"sink_path": hotspot,
"demand": hotspot_demand,
}
)
# Normal demand for other traffic
for source in other_nodes:
for sink in other_nodes:
if source != sink:
demands.append(
{
"source_path": source,
"sink_path": sink,
"demand": normal_demand,
}
)
return demands
class WorkflowTemplates:
"""Templates for common workflow patterns."""
@staticmethod
def basic_build_workflow() -> List[Dict[str, Any]]:
"""Basic workflow that just builds the graph."""
return [{"step_type": "BuildGraph", "name": "build_graph"}]
@staticmethod
def capacity_analysis_workflow(
source_pattern: str, sink_pattern: str, modes: Optional[List[str]] = None
) -> List[Dict[str, Any]]:
"""Workflow for capacity analysis between source and sink patterns."""
if modes is None:
modes = ["combine", "pairwise"]
workflow = [{"step_type": "BuildGraph", "name": "build_graph"}]
for i, mode in enumerate(modes):
workflow.append(
{
"step_type": "CapacityProbe",
"name": f"capacity_probe_{i}",
"source_path": source_pattern,
"sink_path": sink_pattern,
"mode": mode,
"probe_reverse": True,
"shortest_path": True,
}
)
return workflow
@staticmethod
def failure_analysis_workflow(
source_pattern: str, sink_pattern: str, failure_policy_name: str = "default"
) -> List[Dict[str, Any]]:
"""Workflow for analyzing network under failures."""
return [
{"step_type": "BuildGraph", "name": "build_graph"},
{
"step_type": "CapacityEnvelopeAnalysis",
"name": "failure_analysis",
"source_path": source_pattern,
"sink_path": sink_pattern,
"iterations": 100,
"parallelism": 4,
},
]
@staticmethod
def comprehensive_analysis_workflow(
source_pattern: str, sink_pattern: str
) -> List[Dict[str, Any]]:
"""Comprehensive workflow with multiple analysis steps."""
return [
{"step_type": "BuildGraph", "name": "build_graph"},
{
"step_type": "CapacityProbe",
"name": "capacity_probe_combine",
"source_path": source_pattern,
"sink_path": sink_pattern,
"mode": "combine",
"probe_reverse": True,
},
{
"step_type": "CapacityProbe",
"name": "capacity_probe_pairwise",
"source_path": source_pattern,
"sink_path": sink_pattern,
"mode": "pairwise",
"shortest_path": True,
},
{
"step_type": "CapacityEnvelopeAnalysis",
"name": "envelope_analysis",
"source_path": source_pattern,
"sink_path": sink_pattern,
"iterations": 50,
},
]
class ScenarioTemplateBuilder:
"""High-level builder for complete scenario templates."""
def __init__(self, name: str, version: str = "1.0"):
"""Initialize with scenario metadata."""
self.builder = ScenarioDataBuilder()
self.name = name
self.version = version
def with_linear_backbone(
self,
cities: List[str],
link_capacity: float = 100.0,
add_coordinates: bool = True,
) -> "ScenarioTemplateBuilder":
"""Add a linear backbone network topology."""
network_data = NetworkTemplates.linear_network(cities, link_capacity)
if add_coordinates:
# Add some example coordinates for visualization
coords_map = {
"NYC": [40.7128, -74.0060],
"CHI": [41.8781, -87.6298],
"DEN": [39.7392, -104.9903],
"SFO": [37.7749, -122.4194],
"SEA": [47.6062, -122.3321],
"LAX": [34.0522, -118.2437],
"MIA": [25.7617, -80.1918],
"ATL": [33.7490, -84.3880],
}
for city in cities:
if city in coords_map:
network_data["nodes"][city]["attrs"] = {"coords": coords_map[city]}
network_data["name"] = self.name
network_data["version"] = self.version
self.builder.data["network"] = network_data
return self
def with_clos_fabric(
self,
fabric_name: str,
leaf_count: int = 4,
spine_count: int = 4,
link_capacity: float = 100.0,
) -> "ScenarioTemplateBuilder":
"""Add a Clos fabric using blueprints."""
# Create the Clos blueprint
clos_blueprint = BlueprintTemplates.two_tier_blueprint(
tier1_count=leaf_count, tier2_count=spine_count, link_capacity=link_capacity
)
self.builder.with_blueprint("clos_fabric", clos_blueprint)
# Add to network
if "network" not in self.builder.data:
self.builder.data["network"] = {"name": self.name, "version": self.version}
if "groups" not in self.builder.data["network"]:
self.builder.data["network"]["groups"] = {}
self.builder.data["network"]["groups"][fabric_name] = {
"use_blueprint": "clos_fabric"
}
return self
def with_uniform_traffic(
self, node_patterns: List[str], demand_value: float = 50.0
) -> "ScenarioTemplateBuilder":
"""Add uniform traffic demands between node patterns."""
demands = []
for source_pattern in node_patterns:
for sink_pattern in node_patterns:
if source_pattern != sink_pattern:
demands.append(
{
"source_path": source_pattern,
"sink_path": sink_pattern,
"demand": demand_value,
}
)
if "traffic_matrix_set" not in self.builder.data:
self.builder.data["traffic_matrix_set"] = {}
self.builder.data["traffic_matrix_set"]["default"] = demands
return self
def with_single_link_failures(self) -> "ScenarioTemplateBuilder":
"""Add single link failure policy."""
policy = FailurePolicyTemplates.single_link_failure()
self.builder.with_failure_policy("single_link_failure", policy)
return self
def with_capacity_analysis(
self, source_pattern: str, sink_pattern: str
) -> "ScenarioTemplateBuilder":
"""Add capacity analysis workflow."""
workflow = WorkflowTemplates.capacity_analysis_workflow(
source_pattern, sink_pattern
)
self.builder.data["workflow"] = workflow
return self
def build(self) -> str:
"""Build the complete scenario YAML."""
return self.builder.build_yaml()
# Pre-built scenario templates for common use cases
class CommonScenarios:
"""Pre-built scenario templates for common testing patterns."""
@staticmethod
def simple_linear_with_failures(node_count: int = 4) -> str:
"""Simple linear network with single link failure analysis."""
nodes = [f"Node{i}" for i in range(1, node_count + 1)]
return (
ScenarioTemplateBuilder("simple_linear", "1.0")
.with_linear_backbone(nodes, link_capacity=10.0, add_coordinates=False)
.with_uniform_traffic(nodes, demand_value=5.0)
.with_single_link_failures()
.with_capacity_analysis(nodes[0], nodes[-1])
.build()
)
@staticmethod
def dual_clos_interconnect() -> str:
"""Two Clos fabrics interconnected via spine links."""
return (
ScenarioTemplateBuilder("dual_clos", "1.0")
.with_clos_fabric("fabric_east", leaf_count=4, spine_count=4)
.with_clos_fabric("fabric_west", leaf_count=4, spine_count=4)
.with_uniform_traffic(["fabric_east", "fabric_west"], demand_value=25.0)
.with_single_link_failures()
.with_capacity_analysis("fabric_east/.*", "fabric_west/.*")
.build()
)
@staticmethod
def us_backbone_network() -> str:
"""US backbone network with major cities."""
cities = ["NYC", "CHI", "DEN", "SFO", "SEA", "LAX", "MIA", "ATL"]
return (
ScenarioTemplateBuilder("us_backbone", "1.0")
.with_linear_backbone(cities, link_capacity=200.0, add_coordinates=True)
.with_uniform_traffic(
cities[:4], demand_value=75.0
) # Focus on major routes
.with_single_link_failures()
.with_capacity_analysis("NYC|CHI", "SFO|SEA")
.build()
)
@staticmethod
def minimal_test_scenario() -> str:
"""Minimal scenario for basic functionality testing."""
from typing import Any, Dict
from .helpers import ScenarioDataBuilder
builder = ScenarioDataBuilder()
builder.with_simple_nodes(["A", "B", "C"])
builder.with_simple_links([("A", "B", 1.0), ("B", "C", 1.0)])
builder.with_workflow_step("BuildGraph", "build_graph")
# Set network metadata
network_data: Dict[str, Any] = builder.data["network"]
network_data["name"] = "minimal_test"
network_data["version"] = "1.0"
return builder.build_yaml()
class ErrorInjectionTemplates:
"""Templates for injecting common error conditions into scenarios."""
@staticmethod
def invalid_node_builder() -> ScenarioDataBuilder:
"""Create scenario builder with invalid node configuration."""
builder = ScenarioDataBuilder()
# Create nodes that will cause validation errors
return builder
@staticmethod
def missing_nodes_builder() -> ScenarioDataBuilder:
"""Create scenario builder with links referencing missing nodes."""
builder = ScenarioDataBuilder()
builder.with_simple_nodes(["NodeA"])
# Add link to nonexistent node - will cause error during execution
builder.data["network"]["links"] = [
{
"source": "NodeA",
"target": "NonexistentNode",
"link_params": {"capacity": 10, "cost": 1},
}
]
builder.with_workflow_step("BuildGraph", "build_graph")
return builder
@staticmethod
def circular_blueprint_builder() -> ScenarioDataBuilder:
"""Create scenario builder with circular blueprint references."""
builder = ScenarioDataBuilder()
builder.with_blueprint(
"blueprint_a", {"groups": {"group_a": {"use_blueprint": "blueprint_b"}}}
)
builder.with_blueprint(
"blueprint_b", {"groups": {"group_b": {"use_blueprint": "blueprint_a"}}}
)
builder.data["network"] = {
"name": "circular_test",
"groups": {"test_group": {"use_blueprint": "blueprint_a"}},
}
builder.with_workflow_step("BuildGraph", "build_graph")
return builder
@staticmethod
def invalid_failure_policy_builder() -> ScenarioDataBuilder:
"""Create scenario builder with invalid failure policy."""
builder = ScenarioDataBuilder()
builder.with_simple_nodes(["A", "B"])
builder.with_simple_links([("A", "B", 10.0)])
builder.with_failure_policy(
"invalid_policy",
{
"rules": [
{
"entity_scope": "invalid_scope", # Invalid scope
"rule_type": "choice",
"count": 1,
}
]
},
)
builder.with_workflow_step("BuildGraph", "build_graph")
return builder
@staticmethod
def negative_demand_builder() -> ScenarioDataBuilder:
"""Create scenario builder with negative traffic demands."""
builder = ScenarioDataBuilder()
builder.with_simple_nodes(["Source", "Sink"])
builder.with_simple_links([("Source", "Sink", 10.0)])
builder.with_traffic_demand("Source", "Sink", -50.0) # Negative demand
builder.with_workflow_step("BuildGraph", "build_graph")
return builder
@staticmethod
def missing_workflow_params_builder() -> ScenarioDataBuilder:
"""Create scenario builder with incomplete workflow step parameters."""
builder = ScenarioDataBuilder()
builder.with_simple_nodes(["A", "B"])
builder.with_simple_links([("A", "B", 10.0)])
# Add CapacityProbe without required parameters
builder.data["workflow"] = [
{
"step_type": "CapacityProbe",
"name": "incomplete_probe",
# Missing source_path and sink_path
}
]
return builder
@staticmethod
def large_network_builder(node_count: int = 1000) -> ScenarioDataBuilder:
"""Create scenario builder for stress testing with large networks."""
builder = ScenarioDataBuilder()
# Create many nodes
node_names = [f"Node_{i:04d}" for i in range(node_count)]
builder.with_simple_nodes(node_names)
# Create star topology to avoid O(n²) mesh complexity
if node_count > 1:
center_node = node_names[0]
leaf_nodes = node_names[1:]
links = [
(center_node, leaf, 1.0)
for leaf in leaf_nodes[: min(100, len(leaf_nodes))]
]
builder.with_simple_links(links)
builder.with_workflow_step("BuildGraph", "build_graph")
return builder
@staticmethod
def deep_blueprint_nesting_builder(depth: int = 15) -> ScenarioDataBuilder:
"""Create scenario builder with deeply nested blueprints."""
builder = ScenarioDataBuilder()
# Create nested blueprints
for i in range(depth):
if i == 0:
builder.with_blueprint(
f"level_{i}",
{
"groups": {
"nodes": {
"node_count": 1,
"name_template": f"level_{i}_node_{{node_num}}",
}
}
},
)
else:
builder.with_blueprint(
f"level_{i}",
{"groups": {"nested": {"use_blueprint": f"level_{i - 1}"}}},
)
# Use the deepest blueprint
builder.data["network"] = {
"name": "deep_nesting_test",
"groups": {"deep_group": {"use_blueprint": f"level_{depth - 1}"}},
}
builder.with_workflow_step("BuildGraph", "build_graph")
return builder
class EdgeCaseTemplates:
"""Templates for edge case scenarios and boundary conditions."""
@staticmethod
def empty_network_builder() -> ScenarioDataBuilder:
"""Create scenario builder with completely empty network."""
builder = ScenarioDataBuilder()
builder.data["network"] = {"name": "empty", "nodes": {}, "links": []}
builder.with_workflow_step("BuildGraph", "build_graph")
return builder
@staticmethod
def single_node_builder(node_name: str = "LonelyNode") -> ScenarioDataBuilder:
"""Create scenario builder with single isolated node."""
builder = ScenarioDataBuilder()
builder.with_simple_nodes([node_name])
builder.with_workflow_step("BuildGraph", "build_graph")
return builder
@staticmethod
def isolated_nodes_builder(node_count: int = 5) -> ScenarioDataBuilder:
"""Create scenario builder with multiple isolated nodes."""
builder = ScenarioDataBuilder()
node_names = [f"Isolated_{i}" for i in range(node_count)]
builder.with_simple_nodes(node_names)
# No links - all nodes isolated
builder.with_workflow_step("BuildGraph", "build_graph")
return builder
@staticmethod
def zero_capacity_links_builder() -> ScenarioDataBuilder:
"""Create scenario builder with zero-capacity links."""
builder = ScenarioDataBuilder()
builder.with_simple_nodes(["A", "B", "C"])
builder.data["network"]["links"] = [
{"source": "A", "target": "B", "link_params": {"capacity": 0, "cost": 1}},
{"source": "B", "target": "C", "link_params": {"capacity": 0, "cost": 1}},
]
builder.with_workflow_step("BuildGraph", "build_graph")
return builder
@staticmethod
def extreme_values_builder() -> ScenarioDataBuilder:
"""Create scenario builder with extreme numeric values."""
builder = ScenarioDataBuilder()
builder.with_simple_nodes(["NodeA", "NodeB"])
builder.data["network"]["links"] = [
{
"source": "NodeA",
"target": "NodeB",
"link_params": {
"capacity": 999999999999, # Very large capacity
"cost": 999999999999, # Very large cost
},
}
]
builder.with_traffic_demand("NodeA", "NodeB", 888888888888.0) # Large demand
builder.with_workflow_step("BuildGraph", "build_graph")
return builder
@staticmethod
def special_characters_builder() -> ScenarioDataBuilder:
"""Create scenario builder with special characters in names."""
builder = ScenarioDataBuilder()
special_names = ["node-with-dashes", "node.with.dots", "node_with_underscores"]
builder.with_simple_nodes(special_names)
# Add links between nodes with special characters
if len(special_names) >= 2:
builder.with_simple_links([(special_names[0], special_names[1], 10.0)])
builder.with_workflow_step("BuildGraph", "build_graph")
return builder
@staticmethod
def duplicate_links_builder() -> ScenarioDataBuilder:
"""Create scenario builder with multiple links between same nodes."""
builder = ScenarioDataBuilder()
builder.with_simple_nodes(["A", "B"])
# Add multiple links with different parameters
builder.data["network"]["links"] = [
{"source": "A", "target": "B", "link_params": {"capacity": 10, "cost": 1}},
{"source": "A", "target": "B", "link_params": {"capacity": 20, "cost": 2}},
{"source": "A", "target": "B", "link_params": {"capacity": 15, "cost": 3}},
]
builder.with_workflow_step("BuildGraph", "build_graph")
return builder
class PerformanceTestTemplates:
"""Templates for performance and stress testing scenarios."""
@staticmethod
def large_star_network_builder(leaf_count: int = 100) -> ScenarioDataBuilder:
"""Create large star network for performance testing."""
builder = ScenarioDataBuilder()
center = "HUB"
leaves = [f"LEAF_{i:03d}" for i in range(leaf_count)]
all_nodes = [center] + leaves
builder.with_simple_nodes(all_nodes)
# Create star links
star_links = [(center, leaf, 10.0) for leaf in leaves]
builder.with_simple_links(star_links)
# Add some traffic demands
demands = [(center, leaf, 1.0) for leaf in leaves[: min(10, len(leaves))]]
for source, sink, demand in demands:
builder.with_traffic_demand(source, sink, demand)
builder.with_workflow_step("BuildGraph", "build_graph")
return builder
@staticmethod
def large_mesh_blueprint_builder(side_size: int = 20) -> ScenarioDataBuilder:
"""Create large mesh using blueprints for performance testing."""
builder = ScenarioDataBuilder()
# Create large mesh blueprint
large_mesh_blueprint = {
"groups": {
"side_a": {"node_count": side_size, "name_template": "a-{node_num}"},
"side_b": {"node_count": side_size, "name_template": "b-{node_num}"},
},
"adjacency": [
{
"source": "/side_a",
"target": "/side_b",
"pattern": "mesh",
"link_params": {"capacity": 1, "cost": 1},
}
],
}
builder.with_blueprint("large_mesh", large_mesh_blueprint)
builder.data["network"] = {
"name": "large_mesh_test",
"groups": {"mesh_group": {"use_blueprint": "large_mesh"}},
}
builder.with_workflow_step("BuildGraph", "build_graph")
return builder
@staticmethod
def complex_multi_blueprint_builder() -> ScenarioDataBuilder:
"""Create complex scenario with multiple interacting blueprints."""
builder = ScenarioDataBuilder()
# Create basic building blocks
basic_brick = BlueprintTemplates.two_tier_blueprint(4, 4, "mesh", 10.0)
builder.with_blueprint("basic_brick", basic_brick)
# Create aggregation layer
agg_layer = {
"groups": {
"brick1": {"use_blueprint": "basic_brick"},
"brick2": {"use_blueprint": "basic_brick"},
"agg_spine": {"node_count": 8, "name_template": "agg-{node_num}"},
},
"adjacency": [
{
"source": "brick1/tier2",
"target": "agg_spine",
"pattern": "mesh",
"link_params": {"capacity": 20, "cost": 1},
},
{
"source": "brick2/tier2",
"target": "agg_spine",
"pattern": "mesh",
"link_params": {"capacity": 20, "cost": 1},
},