|
@@ 252-275 (lines=24) @@
|
| 249 |
|
expected = flow_by_sw |
| 250 |
|
assert response.json() == expected |
| 251 |
|
|
| 252 |
|
@patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id") |
| 253 |
|
async def test_flow_stats_by_dpid_flow_id_without_dpid(self, |
| 254 |
|
mock_from_flow): |
| 255 |
|
"""Test flow_stats rest call.""" |
| 256 |
|
flow_info = { |
| 257 |
|
"byte_count": 10, |
| 258 |
|
"duration_sec": 20, |
| 259 |
|
"duration_nsec": 30, |
| 260 |
|
"packet_count": 40, |
| 261 |
|
"cookie": 12310228866111668291, |
| 262 |
|
"match": {"in_port": 1}, |
| 263 |
|
"priority": 32768 |
| 264 |
|
} |
| 265 |
|
flow_stats_dict_mock = {'6055f13593fad45e0b4699f49d56b105': flow_info} |
| 266 |
|
flow_by_sw = {"00:00:00:00:00:00:00:01": flow_stats_dict_mock} |
| 267 |
|
mock_from_flow.return_value = flow_by_sw |
| 268 |
|
|
| 269 |
|
endpoint = "/flow/stats" |
| 270 |
|
url = f"{self.base_endpoint}{endpoint}" |
| 271 |
|
response = await self.api_client.get(url) |
| 272 |
|
assert response.status_code == 200 |
| 273 |
|
|
| 274 |
|
expected = flow_by_sw |
| 275 |
|
assert response.json() == expected |
| 276 |
|
|
| 277 |
|
@patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id") |
| 278 |
|
async def test_flow_stats_by_dpid_flow_id_with_dpid(self, mock_from_flow): |
|
@@ 277-299 (lines=23) @@
|
| 274 |
|
expected = flow_by_sw |
| 275 |
|
assert response.json() == expected |
| 276 |
|
|
| 277 |
|
@patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id") |
| 278 |
|
async def test_flow_stats_by_dpid_flow_id_with_dpid(self, mock_from_flow): |
| 279 |
|
"""Test flow_stats rest call.""" |
| 280 |
|
flow_info = { |
| 281 |
|
"byte_count": 10, |
| 282 |
|
"duration_sec": 20, |
| 283 |
|
"duration_nsec": 30, |
| 284 |
|
"packet_count": 40, |
| 285 |
|
"cookie": 12310228866111668291, |
| 286 |
|
"match": {"in_port": 1}, |
| 287 |
|
"priority": 32768 |
| 288 |
|
} |
| 289 |
|
flow_stats_dict_mock = {'6055f13593fad45e0b4699f49d56b105': flow_info} |
| 290 |
|
flow_by_sw = {"00:00:00:00:00:00:00:01": flow_stats_dict_mock} |
| 291 |
|
mock_from_flow.return_value = flow_by_sw |
| 292 |
|
|
| 293 |
|
endpoint = "/flow/stats?dpid=00:00:00:00:00:00:00:01" |
| 294 |
|
url = f"{self.base_endpoint}{endpoint}" |
| 295 |
|
response = await self.api_client.get(url) |
| 296 |
|
assert response.status_code == 200 |
| 297 |
|
|
| 298 |
|
expected = flow_by_sw |
| 299 |
|
assert response.json() == expected |
| 300 |
|
|
| 301 |
|
@patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id") |
| 302 |
|
async def test_flow_stats_by_dpid_flow_id_not_found(self, mock_from_flow): |
|
@@ 229-250 (lines=22) @@
|
| 226 |
|
assert response.status_code == 200 |
| 227 |
|
assert len(response.json()) == 1 |
| 228 |
|
|
| 229 |
|
@patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id") |
| 230 |
|
async def test_flow_stats_by_dpid_flow_id(self, mock_from_flow): |
| 231 |
|
"""Test flow_stats rest call.""" |
| 232 |
|
flow_info = { |
| 233 |
|
"byte_count": 10, |
| 234 |
|
"duration_sec": 20, |
| 235 |
|
"duration_nsec": 30, |
| 236 |
|
"packet_count": 40, |
| 237 |
|
"cookie": 12310228866111668291, |
| 238 |
|
"match": {"in_port": 1}, |
| 239 |
|
"priority": 32768 |
| 240 |
|
} |
| 241 |
|
flow_stats_dict_mock = {'6055f13593fad45e0b4699f49d56b105': flow_info} |
| 242 |
|
flow_by_sw = {"00:00:00:00:00:00:00:01": flow_stats_dict_mock} |
| 243 |
|
mock_from_flow.return_value = flow_by_sw |
| 244 |
|
|
| 245 |
|
endpoint = "/flow/stats?dpid=00:00:00:00:00:00:00:01" |
| 246 |
|
url = f"{self.base_endpoint}{endpoint}" |
| 247 |
|
response = await self.api_client.get(url) |
| 248 |
|
assert response.status_code == 200 |
| 249 |
|
expected = flow_by_sw |
| 250 |
|
assert response.json() == expected |
| 251 |
|
|
| 252 |
|
@patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id") |
| 253 |
|
async def test_flow_stats_by_dpid_flow_id_without_dpid(self, |
|
@@ 206-227 (lines=22) @@
|
| 203 |
|
assert response.status_code == 200 |
| 204 |
|
assert len(response.json()) == 1 |
| 205 |
|
|
| 206 |
|
@patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id") |
| 207 |
|
async def test_flows_counters_bytes(self, mock_from_flow): |
| 208 |
|
"""Test flows_counters function for bytes""" |
| 209 |
|
flow_info = { |
| 210 |
|
"byte_count": 10, |
| 211 |
|
"duration_sec": 20, |
| 212 |
|
"duration_nsec": 30, |
| 213 |
|
"packet_count": 40, |
| 214 |
|
"cookie": 12310228866111668291, |
| 215 |
|
"match": {"in_port": 1}, |
| 216 |
|
"priority": 32768 |
| 217 |
|
} |
| 218 |
|
flow_id = '6055f13593fad45e0b4699f49d56b105' |
| 219 |
|
flow_stats_dict_mock = {flow_id: flow_info} |
| 220 |
|
dpid = "00:00:00:00:00:00:00:01" |
| 221 |
|
flow_by_sw = {dpid: flow_stats_dict_mock} |
| 222 |
|
mock_from_flow.return_value = flow_by_sw |
| 223 |
|
|
| 224 |
|
endpoint = f"{self.base_endpoint}/bytes_count/per_flow/{dpid}" |
| 225 |
|
response = await self.api_client.get(endpoint) |
| 226 |
|
assert response.status_code == 200 |
| 227 |
|
assert len(response.json()) == 1 |
| 228 |
|
|
| 229 |
|
@patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id") |
| 230 |
|
async def test_flow_stats_by_dpid_flow_id(self, mock_from_flow): |
|
@@ 183-204 (lines=22) @@
|
| 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): |
| 185 |
|
"""Test flows_counters function for packet""" |
| 186 |
|
flow_info = { |
| 187 |
|
"byte_count": 10, |
| 188 |
|
"duration_sec": 20, |
| 189 |
|
"duration_nsec": 30, |
| 190 |
|
"packet_count": 40, |
| 191 |
|
"cookie": 12310228866111668291, |
| 192 |
|
"match": {"in_port": 1}, |
| 193 |
|
"priority": 32768 |
| 194 |
|
} |
| 195 |
|
flow_id = '6055f13593fad45e0b4699f49d56b105' |
| 196 |
|
flow_stats_dict_mock = {flow_id: flow_info} |
| 197 |
|
dpid = "00:00:00:00:00:00:00:01" |
| 198 |
|
flow_by_sw = {dpid: flow_stats_dict_mock} |
| 199 |
|
mock_from_flow.return_value = flow_by_sw |
| 200 |
|
|
| 201 |
|
endpoint = f"{self.base_endpoint}/packet_count/per_flow/{dpid}" |
| 202 |
|
response = await self.api_client.get(endpoint) |
| 203 |
|
assert response.status_code == 200 |
| 204 |
|
assert len(response.json()) == 1 |
| 205 |
|
|
| 206 |
|
@patch("napps.amlight.kytos_stats.main.Main.flow_stats_by_dpid_flow_id") |
| 207 |
|
async def test_flows_counters_bytes(self, mock_from_flow): |