|
1 | 1 | import pytest |
2 | 2 |
|
3 | | -from ngraph.network import Network, Node, Link |
4 | | -from ngraph.traffic_demand import TrafficDemand |
| 3 | +from ngraph.lib.algorithms.base import MIN_FLOW |
5 | 4 | from ngraph.lib.flow_policy import FlowPolicyConfig |
6 | 5 | from ngraph.lib.graph import StrictMultiDiGraph |
7 | | -from ngraph.lib.algorithms.base import MIN_FLOW |
8 | | -from ngraph.lib.demand import Demand |
9 | | - |
| 6 | +from ngraph.network import Link, Network, Node |
| 7 | +from ngraph.traffic_demand import TrafficDemand |
10 | 8 | from ngraph.traffic_manager import TrafficManager |
11 | 9 |
|
12 | 10 |
|
@@ -411,3 +409,34 @@ def test_estimate_rounds_no_capacities(): |
411 | 409 | total_placed = tm.place_all_demands(placement_rounds="auto") |
412 | 410 | # The link has 0 capacity, so no actual flow can be placed. |
413 | 411 | assert total_placed == 0.0, "No capacity => no flow placed" |
| 412 | + |
| 413 | + |
| 414 | +def test_get_traffic_results_aggregated_and_detailed(small_network): |
| 415 | + """TrafficManager.get_traffic_results should summarize correctly.""" |
| 416 | + demands = [ |
| 417 | + TrafficDemand(source_path="A", sink_path="C", demand=10.0), |
| 418 | + TrafficDemand(source_path="B", sink_path="C", demand=5.0), |
| 419 | + ] |
| 420 | + tm = TrafficManager(network=small_network, traffic_demands=demands) |
| 421 | + tm.build_graph() |
| 422 | + tm.expand_demands() |
| 423 | + tm.place_all_demands() |
| 424 | + |
| 425 | + agg = tm.get_traffic_results(detailed=False) |
| 426 | + assert len(agg) == 2 |
| 427 | + for res in agg: |
| 428 | + assert res.total_volume == res.placed_volume |
| 429 | + |
| 430 | + detailed = tm.get_traffic_results(detailed=True) |
| 431 | + assert len(detailed) == len(tm.demands) |
| 432 | + for res in detailed: |
| 433 | + assert res.total_volume == res.placed_volume |
| 434 | + |
| 435 | + |
| 436 | +def test_estimate_rounds_typical_case(small_network): |
| 437 | + """_estimate_rounds should compute rounds based on demand/capacity ratio.""" |
| 438 | + demands = [TrafficDemand(source_path="A", sink_path="C", demand=20.0)] |
| 439 | + tm = TrafficManager(network=small_network, traffic_demands=demands) |
| 440 | + tm.build_graph() |
| 441 | + tm.expand_demands() |
| 442 | + assert tm._estimate_rounds() == 6 |
0 commit comments