1
|
|
|
"""Module to help to create tests.""" |
2
|
|
|
from unittest.mock import MagicMock |
3
|
|
|
|
4
|
|
|
from kytos.lib.helpers import (get_interface_mock, get_link_mock, |
5
|
|
|
get_switch_mock) |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
def get_topology_mock(): |
9
|
|
|
"""Create a default topology.""" |
10
|
|
|
switch_a = get_switch_mock("00:00:00:00:00:00:00:01", 0x04) |
11
|
|
|
switch_b = get_switch_mock("00:00:00:00:00:00:00:02", 0x04) |
12
|
|
|
switch_c = get_switch_mock("00:00:00:00:00:00:00:03", 0x01) |
13
|
|
|
|
14
|
|
|
interface_a1 = get_interface_mock("s1-eth1", 1, switch_a) |
15
|
|
|
interface_a2 = get_interface_mock("s1-eth2", 2, switch_a) |
16
|
|
|
|
17
|
|
|
interface_b1 = get_interface_mock("s2-eth1", 1, switch_b) |
18
|
|
|
interface_b2 = get_interface_mock("s2-eth2", 2, switch_b) |
19
|
|
|
|
20
|
|
|
interface_c1 = get_interface_mock("s3-eth1", 1, switch_c) |
21
|
|
|
interface_c2 = get_interface_mock("s3-eth2", 2, switch_c) |
22
|
|
|
|
23
|
|
|
switch_a.interfaces = {interface_a1.id: interface_a1, |
24
|
|
|
interface_a2.id: interface_a2} |
25
|
|
|
switch_b.interfaces = {interface_b1.id: interface_b1, |
26
|
|
|
interface_b2.id: interface_b2} |
27
|
|
|
switch_c.interfaces = {interface_c1.id: interface_c1, |
28
|
|
|
interface_c2.id: interface_c2} |
29
|
|
|
|
30
|
|
|
link_1 = get_link_mock(interface_a1, interface_b1) |
31
|
|
|
link_2 = get_link_mock(interface_a2, interface_c1) |
32
|
|
|
link_3 = get_link_mock(interface_b2, interface_c2) |
33
|
|
|
|
34
|
|
|
topology = MagicMock() |
35
|
|
|
topology.links = {"1": link_1, "2": link_2, "3": link_3} |
36
|
|
|
topology.switches = {switch_a.dpid: switch_a, |
37
|
|
|
switch_b.dpid: switch_b, |
38
|
|
|
switch_c.dpid: switch_c} |
39
|
|
|
return topology |
40
|
|
|
|