|
@@ 154-181 (lines=28) @@
|
| 151 |
|
assert response.status_code == 200 |
| 152 |
|
assert len(response.json()) == 0 |
| 153 |
|
|
| 154 |
|
@patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id") |
| 155 |
|
async def test_bytes_count_per_flow(self, mock_from_flow): |
| 156 |
|
"""Test bytes_count_per_flow rest call.""" |
| 157 |
|
flow_info = { |
| 158 |
|
"byte_count": 10, |
| 159 |
|
"duration_sec": 20, |
| 160 |
|
"duration_nsec": 30, |
| 161 |
|
"packet_count": 40, |
| 162 |
|
"cookie": 12310228866111668291, |
| 163 |
|
"match": {"in_port": 1}, |
| 164 |
|
"priority": 32768 |
| 165 |
|
} |
| 166 |
|
flow_id = '6055f13593fad45e0b4699f49d56b105' |
| 167 |
|
flow_stats_dict_mock = {flow_id: flow_info} |
| 168 |
|
dpid = "00:00:00:00:00:00:00:01" |
| 169 |
|
flow_by_sw = {dpid: flow_stats_dict_mock} |
| 170 |
|
mock_from_flow.return_value = flow_by_sw |
| 171 |
|
|
| 172 |
|
self._patch_switch_flow(flow_id) |
| 173 |
|
|
| 174 |
|
endpoint = f"{self.base_endpoint}/bytes_count/per_flow/{dpid}" |
| 175 |
|
response = await self.api_client.get(endpoint) |
| 176 |
|
assert response.status_code == 200 |
| 177 |
|
|
| 178 |
|
json_response = response.json() |
| 179 |
|
assert json_response[0]["flow_id"] == flow_id |
| 180 |
|
assert json_response[0]["bytes_counter"] == 10 |
| 181 |
|
assert json_response[0]["bits_per_second"] == 4.0 |
| 182 |
|
|
| 183 |
|
@patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id") |
| 184 |
|
async def test_flows_counters_packet(self, mock_from_flow): |
|
@@ 119-144 (lines=26) @@
|
| 116 |
|
assert response.status_code == 200 |
| 117 |
|
assert len(response.json()) == 0 |
| 118 |
|
|
| 119 |
|
@patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id") |
| 120 |
|
async def test_packet_count_per_flow(self, mock_from_flow): |
| 121 |
|
"""Test packet_count_per_flow rest call.""" |
| 122 |
|
flow_info = { |
| 123 |
|
"byte_count": 10, |
| 124 |
|
"duration_sec": 20, |
| 125 |
|
"duration_nsec": 30, |
| 126 |
|
"packet_count": 40, |
| 127 |
|
"cookie": 12310228866111668291, |
| 128 |
|
"match": {"in_port": 1}, |
| 129 |
|
"priority": 32768 |
| 130 |
|
} |
| 131 |
|
flow_id = '6055f13593fad45e0b4699f49d56b105' |
| 132 |
|
flow_stats_dict_mock = {flow_id: flow_info} |
| 133 |
|
dpid = "00:00:00:00:00:00:00:01" |
| 134 |
|
flow_by_sw = {dpid: flow_stats_dict_mock} |
| 135 |
|
mock_from_flow.return_value = flow_by_sw |
| 136 |
|
|
| 137 |
|
self._patch_switch_flow(flow_id) |
| 138 |
|
endpoint = f"{self.base_endpoint}/packet_count/per_flow/{dpid}" |
| 139 |
|
response = await self.api_client.get(endpoint) |
| 140 |
|
|
| 141 |
|
json_response = response.json() |
| 142 |
|
assert json_response[0]["flow_id"] == flow_id |
| 143 |
|
assert json_response[0]["packet_counter"] == 40 |
| 144 |
|
assert json_response[0]["packet_per_second"] == 2.0 |
| 145 |
|
|
| 146 |
|
async def test_bytes_count_per_flow__empty(self): |
| 147 |
|
"""Test bytes_count rest call with a flow that does not exist .""" |