Conditions | 1 |
Total Lines | 175 |
Code Lines | 131 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | """Module to test the KytosGraph in graph.py.""" |
||
335 | @staticmethod |
||
336 | def generate_topology(): |
||
337 | """Generates a predetermined topology""" |
||
338 | switches = {} |
||
339 | interfaces = {} |
||
340 | links = {} |
||
341 | |||
342 | TestSearchResults.create_switch("S1", switches) |
||
343 | TestSearchResults.add_interfaces(2, switches["S1"], interfaces) |
||
344 | |||
345 | TestSearchResults.create_switch("S2", switches) |
||
346 | TestSearchResults.add_interfaces(2, switches["S2"], interfaces) |
||
347 | |||
348 | TestSearchResults.create_switch("S3", switches) |
||
349 | TestSearchResults.add_interfaces(6, switches["S3"], interfaces) |
||
350 | |||
351 | TestSearchResults.create_switch("S4", switches) |
||
352 | TestSearchResults.add_interfaces(2, switches["S4"], interfaces) |
||
353 | |||
354 | TestSearchResults.create_switch("S5", switches) |
||
355 | TestSearchResults.add_interfaces(6, switches["S5"], interfaces) |
||
356 | |||
357 | TestSearchResults.create_switch("S6", switches) |
||
358 | TestSearchResults.add_interfaces(5, switches["S6"], interfaces) |
||
359 | |||
360 | TestSearchResults.create_switch("S7", switches) |
||
361 | TestSearchResults.add_interfaces(2, switches["S7"], interfaces) |
||
362 | |||
363 | TestSearchResults.create_switch("S8", switches) |
||
364 | TestSearchResults.add_interfaces(8, switches["S8"], interfaces) |
||
365 | |||
366 | TestSearchResults.create_switch("S9", switches) |
||
367 | TestSearchResults.add_interfaces(4, switches["S9"], interfaces) |
||
368 | |||
369 | TestSearchResults.create_switch("S10", switches) |
||
370 | TestSearchResults.add_interfaces(3, switches["S10"], interfaces) |
||
371 | |||
372 | TestSearchResults.create_switch("S11", switches) |
||
373 | TestSearchResults.add_interfaces(3, switches["S11"], interfaces) |
||
374 | |||
375 | TestSearchResults.create_switch("User1", switches) |
||
376 | TestSearchResults.add_interfaces(4, switches["User1"], interfaces) |
||
377 | |||
378 | TestSearchResults.create_switch("User2", switches) |
||
379 | TestSearchResults.add_interfaces(2, switches["User2"], interfaces) |
||
380 | |||
381 | TestSearchResults.create_switch("User3", switches) |
||
382 | TestSearchResults.add_interfaces(2, switches["User3"], interfaces) |
||
383 | |||
384 | TestSearchResults.create_switch("User4", switches) |
||
385 | TestSearchResults.add_interfaces(3, switches["User4"], interfaces) |
||
386 | |||
387 | links["S1:1<->S2:1"] = Link(interfaces["S1:1"], interfaces["S2:1"]) |
||
388 | links["S1:1<->S2:1"].extend_metadata( |
||
389 | {"reliability": 5, "bandwidth": 100, "delay": 105}) |
||
390 | |||
391 | links["S1:2<->User1:1"] = Link(interfaces["S1:2"], |
||
392 | interfaces["User1:1"]) |
||
393 | links["S1:2<->User1:1"].extend_metadata( |
||
394 | {"reliability": 5, "bandwidth": 100, "delay": 1}) |
||
395 | |||
396 | links["S2:2<->User4:1"] = Link(interfaces["S2:2"], |
||
397 | interfaces["User4:1"]) |
||
398 | links["S2:2<->User4:1"].extend_metadata( |
||
399 | {"reliability": 5, "bandwidth": 100, "delay": 10}) |
||
400 | |||
401 | links["S3:1<->S5:1"] = Link(interfaces["S3:1"], interfaces["S5:1"]) |
||
402 | links["S3:1<->S5:1"].extend_metadata( |
||
403 | {"reliability": 5, "bandwidth": 10, "delay": 112}) |
||
404 | |||
405 | links["S3:2<->S7:1"] = Link(interfaces["S3:2"], interfaces["S7:1"]) |
||
406 | links["S3:2<->S7:1"].extend_metadata( |
||
407 | {"reliability": 5, "bandwidth": 100, "delay": 1}) |
||
408 | |||
409 | links["S3:3<->S8:1"] = Link(interfaces["S3:3"], interfaces["S8:1"]) |
||
410 | links["S3:3<->S8:1"].extend_metadata( |
||
411 | {"reliability": 5, "bandwidth": 100, "delay": 1}) |
||
412 | |||
413 | links["S3:4<->S11:1"] = Link(interfaces["S3:4"], interfaces["S11:1"]) |
||
414 | links["S3:4<->S11:1"].extend_metadata( |
||
415 | {"reliability": 3, "bandwidth": 100, "delay": 6}) |
||
416 | |||
417 | links["S3:5<->User3:1"] = Link(interfaces["S3:5"], |
||
418 | interfaces["User3:1"]) |
||
419 | links["S3:5<->User3:1"].extend_metadata( |
||
420 | {"reliability": 5, "bandwidth": 100, "delay": 1}) |
||
421 | |||
422 | links["S3:6<->User4:2"] = Link(interfaces["S3:6"], |
||
423 | interfaces["User4:2"]) |
||
424 | links["S3:6<->User4:2"].extend_metadata( |
||
425 | {"reliability": 5, "bandwidth": 100, "delay": 10}) |
||
426 | |||
427 | links["S4:1<->S5:2"] = Link(interfaces["S4:1"], interfaces["S5:2"]) |
||
428 | links["S4:1<->S5:2"].extend_metadata( |
||
429 | {"reliability": 1, "bandwidth": 100, "delay": 30, |
||
430 | "ownership": "A"}) |
||
431 | |||
432 | links["S4:2<->User1:2"] = Link(interfaces["S4:2"], |
||
433 | interfaces["User1:2"]) |
||
434 | links["S4:2<->User1:2"].extend_metadata( |
||
435 | {"reliability": 3, "bandwidth": 100, "delay": 110, |
||
436 | "ownership": "A"}) |
||
437 | |||
438 | links["S5:3<->S6:1"] = Link(interfaces["S5:3"], interfaces["S6:1"]) |
||
439 | links["S5:3<->S6:1"].extend_metadata( |
||
440 | {"reliability": 1, "bandwidth": 100, "delay": 40}) |
||
441 | |||
442 | links["S5:4<->S6:2"] = Link(interfaces["S5:4"], interfaces["S6:2"]) |
||
443 | links["S5:4<->S6:2"].extend_metadata( |
||
444 | {"reliability": 3, "bandwidth": 100, "delay": 40, |
||
445 | "ownership": "A"}) |
||
446 | |||
447 | links["S5:5<->S8:2"] = Link(interfaces["S5:5"], interfaces["S8:2"]) |
||
448 | links["S5:5<->S8:2"].extend_metadata( |
||
449 | {"reliability": 5, "bandwidth": 100, "delay": 112}) |
||
450 | |||
451 | links["S5:6<->User1:3"] = Link(interfaces["S5:6"], |
||
452 | interfaces["User1:3"]) |
||
453 | links["S5:6<->User1:3"].extend_metadata( |
||
454 | {"reliability": 3, "bandwidth": 100, "delay": 60}) |
||
455 | |||
456 | links["S6:3<->S9:1"] = Link(interfaces["S6:3"], interfaces["S9:1"]) |
||
457 | links["S6:3<->S9:1"].extend_metadata( |
||
458 | {"reliability": 3, "bandwidth": 100, "delay": 60}) |
||
459 | |||
460 | links["S6:4<->S9:2"] = Link(interfaces["S6:4"], interfaces["S9:2"]) |
||
461 | links["S6:4<->S9:2"].extend_metadata( |
||
462 | {"reliability": 5, "bandwidth": 100, "delay": 62}) |
||
463 | |||
464 | links["S6:5<->S10:1"] = Link(interfaces["S6:5"], interfaces["S10:1"]) |
||
465 | links["S6:5<->S10:1"].extend_metadata( |
||
466 | {"bandwidth": 100, "delay": 108, "ownership": "A"}) |
||
467 | |||
468 | links["S7:2<->S8:3"] = Link(interfaces["S7:2"], interfaces["S8:3"]) |
||
469 | links["S7:2<->S8:3"].extend_metadata( |
||
470 | {"reliability": 5, "bandwidth": 100, "delay": 1}) |
||
471 | |||
472 | links["S8:4<->S9:3"] = Link(interfaces["S8:4"], interfaces["S9:3"]) |
||
473 | links["S8:4<->S9:3"].extend_metadata( |
||
474 | {"reliability": 3, "bandwidth": 100, "delay": 32}) |
||
475 | |||
476 | links["S8:5<->S9:4"] = Link(interfaces["S8:5"], interfaces["S9:4"]) |
||
477 | links["S8:5<->S9:4"].extend_metadata( |
||
478 | {"reliability": 3, "bandwidth": 100, "delay": 110}) |
||
479 | |||
480 | links["S8:6<->S10:2"] = Link(interfaces["S8:6"], interfaces["S10:2"]) |
||
481 | links["S8:6<->S10:2"].extend_metadata( |
||
482 | {"reliability": 5, "bandwidth": 100, "ownership": "A"}) |
||
483 | |||
484 | links["S8:7<->S11:2"] = Link(interfaces["S8:7"], interfaces["S11:2"]) |
||
485 | links["S8:7<->S11:2"].extend_metadata( |
||
486 | {"reliability": 3, "bandwidth": 100, "delay": 7}) |
||
487 | |||
488 | links["S8:8<->User3:2"] = Link(interfaces["S8:8"], |
||
489 | interfaces["User3:2"]) |
||
490 | links["S8:8<->User3:2"].extend_metadata( |
||
491 | {"reliability": 5, "bandwidth": 100, "delay": 1}) |
||
492 | |||
493 | links["S10:3<->User2:1"] = Link(interfaces["S10:3"], |
||
494 | interfaces["User2:1"]) |
||
495 | links["S10:3<->User2:1"].extend_metadata( |
||
496 | {"reliability": 3, "bandwidth": 100, "delay": 10, |
||
497 | "ownership": "A"}) |
||
498 | |||
499 | links["S11:3<->User2:2"] = Link(interfaces["S11:3"], |
||
500 | interfaces["User2:2"]) |
||
501 | links["S11:3<->User2:2"].extend_metadata( |
||
502 | {"reliability": 3, "bandwidth": 100, "delay": 6}) |
||
503 | |||
504 | links["User1:4<->User4:3"] = Link(interfaces["User1:4"], |
||
505 | interfaces["User4:3"]) |
||
506 | links["User1:4<->User4:3"].extend_metadata( |
||
507 | {"reliability": 5, "bandwidth": 10, "delay": 105}) |
||
508 | |||
509 | return (switches, links) |
||
510 |