Skip to content

Commit 5a4c76a

Browse files
committed
dc network scenario
1 parent 487a179 commit 5a4c76a

File tree

2 files changed

+277
-0
lines changed

2 files changed

+277
-0
lines changed

ngraph/network.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,15 @@ def find_links(
430430
self,
431431
source_regex: Optional[str] = None,
432432
target_regex: Optional[str] = None,
433+
any_direction: bool = False,
433434
) -> List[Link]:
434435
"""
435436
Search for links using optional regex patterns for source or target node names.
436437
437438
Args:
438439
source_regex: Regex pattern to match link.source. If None, matches all.
439440
target_regex: Regex pattern to match link.target. If None, matches all.
441+
any_direction: If True, also match links where source and target are reversed.
440442
441443
Returns:
442444
List[Link]: A list of Link objects that match the provided criteria.
@@ -458,4 +460,13 @@ def find_links(
458460
if tgt_pat and not tgt_pat.search(link.target):
459461
continue
460462
results.append(link)
463+
464+
if any_direction:
465+
for link in self.links.values():
466+
if src_pat and not src_pat.search(link.target):
467+
continue
468+
if tgt_pat and not tgt_pat.search(link.source):
469+
continue
470+
results.append(link)
471+
461472
return results

notebooks/scenario_2.ipynb

Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"from ngraph.scenario import Scenario\n",
10+
"from ngraph.traffic_demand import TrafficDemand\n",
11+
"from ngraph.traffic_manager import TrafficManager\n",
12+
"from ngraph.lib.flow_policy import FlowPolicyConfig, FlowPolicy, FlowPlacement\n",
13+
"from ngraph.lib.algorithms.base import PathAlg, EdgeSelect\n",
14+
"from ngraph.failure_manager import FailureManager\n",
15+
"from ngraph.failure_policy import FailurePolicy, FailureRule, FailureCondition"
16+
]
17+
},
18+
{
19+
"cell_type": "code",
20+
"execution_count": null,
21+
"metadata": {},
22+
"outputs": [],
23+
"source": [
24+
"scenario_yaml = \"\"\"\n",
25+
"blueprints:\n",
26+
" server_pod:\n",
27+
" rsw:\n",
28+
" node_count: 48\n",
29+
" \n",
30+
" f16_2tier:\n",
31+
" groups:\n",
32+
" ssw:\n",
33+
" node_count: 36\n",
34+
" fsw:\n",
35+
" node_count: 36\n",
36+
"\n",
37+
" adjacency:\n",
38+
" - source: /ssw\n",
39+
" target: /fsw\n",
40+
" pattern: mesh\n",
41+
" link_params:\n",
42+
" capacity: 200\n",
43+
" cost: 1\n",
44+
" \n",
45+
" hgrid_2tier:\n",
46+
" groups:\n",
47+
" fauu:\n",
48+
" node_count: 8\n",
49+
" fadu:\n",
50+
" node_count: 36\n",
51+
"\n",
52+
" adjacency:\n",
53+
" - source: /fauu\n",
54+
" target: /fadu\n",
55+
" pattern: mesh\n",
56+
" link_params:\n",
57+
" capacity: 400\n",
58+
" cost: 1\n",
59+
"\n",
60+
" fa:\n",
61+
" groups:\n",
62+
" fa1:\n",
63+
" use_blueprint: hgrid_2tier\n",
64+
" fa2:\n",
65+
" use_blueprint: hgrid_2tier\n",
66+
" fa3:\n",
67+
" use_blueprint: hgrid_2tier\n",
68+
" fa4:\n",
69+
" use_blueprint: hgrid_2tier\n",
70+
" fa5:\n",
71+
" use_blueprint: hgrid_2tier\n",
72+
" fa6:\n",
73+
" use_blueprint: hgrid_2tier\n",
74+
" fa7:\n",
75+
" use_blueprint: hgrid_2tier\n",
76+
" fa8:\n",
77+
" use_blueprint: hgrid_2tier\n",
78+
" \n",
79+
" dc_fabric:\n",
80+
" groups:\n",
81+
" plane1:\n",
82+
" use_blueprint: f16_2tier\n",
83+
" plane2:\n",
84+
" use_blueprint: f16_2tier\n",
85+
" plane3:\n",
86+
" use_blueprint: f16_2tier\n",
87+
" plane4:\n",
88+
" use_blueprint: f16_2tier\n",
89+
" plane5:\n",
90+
" use_blueprint: f16_2tier\n",
91+
" plane6:\n",
92+
" use_blueprint: f16_2tier\n",
93+
" plane7:\n",
94+
" use_blueprint: f16_2tier\n",
95+
" plane8:\n",
96+
" use_blueprint: f16_2tier\n",
97+
"\n",
98+
" pod1:\n",
99+
" use_blueprint: server_pod\n",
100+
" pod36:\n",
101+
" use_blueprint: server_pod\n",
102+
" \n",
103+
" adjacency:\n",
104+
" - source: /pod1/rsw\n",
105+
" target: /plane[0-9]*/fsw/fsw-1\n",
106+
" pattern: mesh\n",
107+
" link_params:\n",
108+
" capacity: 200\n",
109+
" cost: 1\n",
110+
" - source: /pod36/rsw\n",
111+
" target: /plane[0-9]*/fsw/fsw-36\n",
112+
" pattern: mesh\n",
113+
" link_params:\n",
114+
" capacity: 200\n",
115+
" cost: 1\n",
116+
" \n",
117+
"network:\n",
118+
" name: \"fb_region\"\n",
119+
" version: 1.0\n",
120+
"\n",
121+
" groups:\n",
122+
" dc1:\n",
123+
" use_blueprint: dc_fabric\n",
124+
" dc2:\n",
125+
" use_blueprint: dc_fabric\n",
126+
" dc3:\n",
127+
" use_blueprint: dc_fabric\n",
128+
" dc4:\n",
129+
" use_blueprint: dc_fabric\n",
130+
" dc5:\n",
131+
" use_blueprint: dc_fabric\n",
132+
" dc6:\n",
133+
" use_blueprint: dc_fabric\n",
134+
"\n",
135+
" fa:\n",
136+
" use_blueprint: fa\n",
137+
"\n",
138+
" adjacency:\n",
139+
" - source: .*/ssw/.*\n",
140+
" target: .*/fa1/fadu/.*\n",
141+
" pattern: one_to_one\n",
142+
" link_params:\n",
143+
" capacity: 200\n",
144+
" cost: 1 \n",
145+
" - source: .*/ssw/.*\n",
146+
" target: .*/fa2/fadu/.*\n",
147+
" pattern: one_to_one\n",
148+
" link_params:\n",
149+
" capacity: 200\n",
150+
" cost: 1 \n",
151+
" - source: .*/ssw/.*\n",
152+
" target: .*/fa3/fadu/.*\n",
153+
" pattern: one_to_one\n",
154+
" link_params:\n",
155+
" capacity: 200\n",
156+
" cost: 1\n",
157+
" - source: .*/ssw/.*\n",
158+
" target: .*/fa4/fadu/.*\n",
159+
" pattern: one_to_one\n",
160+
" link_params:\n",
161+
" capacity: 200\n",
162+
" cost: 1 \n",
163+
" - source: .*/ssw/.*\n",
164+
" target: .*/fa5/fadu/.*\n",
165+
" pattern: one_to_one\n",
166+
" link_params:\n",
167+
" capacity: 200\n",
168+
" cost: 1 \n",
169+
" - source: .*/ssw/.*\n",
170+
" target: .*/fa6/fadu/.*\n",
171+
" pattern: one_to_one\n",
172+
" link_params:\n",
173+
" capacity: 200\n",
174+
" cost: 1 \n",
175+
" - source: .*/ssw/.*\n",
176+
" target: .*/fa7/fadu/.*\n",
177+
" pattern: one_to_one\n",
178+
" link_params:\n",
179+
" capacity: 200\n",
180+
" cost: 1 \n",
181+
" - source: .*/ssw/.*\n",
182+
" target: .*/fa8/fadu/.*\n",
183+
" pattern: one_to_one\n",
184+
" link_params:\n",
185+
" capacity: 200\n",
186+
" cost: 1 \n",
187+
"\"\"\"\n",
188+
"scenario = Scenario.from_yaml(scenario_yaml)\n",
189+
"network = scenario.network"
190+
]
191+
},
192+
{
193+
"cell_type": "code",
194+
"execution_count": 9,
195+
"metadata": {},
196+
"outputs": [
197+
{
198+
"data": {
199+
"text/plain": [
200+
"13824"
201+
]
202+
},
203+
"execution_count": 9,
204+
"metadata": {},
205+
"output_type": "execute_result"
206+
}
207+
],
208+
"source": [
209+
"len(network.find_links(\".*/fadu/.*\", \".*/ssw/.*\", any_direction=True))"
210+
]
211+
},
212+
{
213+
"cell_type": "code",
214+
"execution_count": 10,
215+
"metadata": {},
216+
"outputs": [
217+
{
218+
"data": {
219+
"text/plain": [
220+
"{('.*/fsw.*', '.*/fauu.*'): 2304.0}"
221+
]
222+
},
223+
"execution_count": 10,
224+
"metadata": {},
225+
"output_type": "execute_result"
226+
}
227+
],
228+
"source": [
229+
"network.max_flow(\n",
230+
" source_path=\".*/fsw.*\",\n",
231+
" sink_path=\".*/fauu.*\",\n",
232+
" mode=\"combine\",\n",
233+
" shortest_path=True,\n",
234+
")"
235+
]
236+
},
237+
{
238+
"cell_type": "code",
239+
"execution_count": null,
240+
"metadata": {},
241+
"outputs": [],
242+
"source": []
243+
}
244+
],
245+
"metadata": {
246+
"kernelspec": {
247+
"display_name": "ngraph-venv",
248+
"language": "python",
249+
"name": "python3"
250+
},
251+
"language_info": {
252+
"codemirror_mode": {
253+
"name": "ipython",
254+
"version": 3
255+
},
256+
"file_extension": ".py",
257+
"mimetype": "text/x-python",
258+
"name": "python",
259+
"nbconvert_exporter": "python",
260+
"pygments_lexer": "ipython3",
261+
"version": "3.13.1"
262+
}
263+
},
264+
"nbformat": 4,
265+
"nbformat_minor": 2
266+
}

0 commit comments

Comments
 (0)