Coverage for flexnetsim/connection.py: 100%

30 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-22 20:03 +0000

1class Connection(): 

2 """ 

3 This class contains the information regarding the connections that are made between the nodes on a network during the allocation process. 

4 

5 Args: 

6 id (int): the id of the new connection object. 

7 """ 

8 

9 def __init__(self, id: int = None): 

10 self.__id = id 

11 self.__links = [] 

12 self.__slots = [] 

13 if id == None: 

14 raise AttributeError( 

15 "You must pass a list of slots, or a from_slot and to slot integers.") 

16 

17 def __add_link_from_vector(self, id: int, slots: list): 

18 """ 

19 Adds a new link to the Connection object. The link id is added to the links vector, and the slots to the slots vector. 

20 

21 Args: 

22 id (int): the id of the new link added to the connection object. 

23 slots (list): the vector that contains the position of the slots. 

24 """ 

25 self.__links.append(id) 

26 self.__slots.append(slots) 

27 

28 def __add_link_from_from_to(self, id: int, from_slot: int, to_slot: int): 

29 """ 

30 Adds a new link to the Connection object. The link id is added to the links vector, and the slots in the range fromSlot-toSlot are added to the slots vector. 

31 

32 Args: 

33 id (int): the id of the new link added to the connection object. 

34 from_slot (int): the position of the first slot to be taken on the link. 

35 to_slot (int): the position of the last slot to be taken on the link. 

36 """ 

37 self.__links.append(id) 

38 self.__slots.append([]) 

39 for i in range(from_slot, to_slot): 

40 self.__slots[-1].append(i) 

41 

42 def add_link(self, id: int, *, slots: list = None, from_slot: int = None, to_slot: int = None): 

43 """ 

44 Adds a new link to the Connection object. The link id is added to the links vector, and the slotsare added to the slots vector. You must use one of these two options: 

45 * Use only slots parameter 

46 * Use only from_slot and to_slot parameters 

47 

48 Args: 

49 id (int): the id of the new link added to the connection object. 

50 slots (list): the vector that contains the position of the slots. 

51 from_slot (int): the position of the first slot to be taken on the link. 

52 to_slot (int): the position of the last slot to be taken on the link. 

53 """ 

54 if from_slot == None and to_slot == None and slots != None: 

55 self.__add_link_from_vector(id, slots) 

56 elif from_slot != None and to_slot != None and slots == None: 

57 self.__add_link_from_from_to(id, from_slot, to_slot) 

58 else: 

59 raise AttributeError( 

60 "You must pass a list of slots, or a from_slot and to slot integers separately.") 

61 

62 @property 

63 def links(self): 

64 """ 

65 A list with the link IDs belonging to this connection. 

66 """ 

67 return self.__links 

68 

69 @property 

70 def slots(self): 

71 """ 

72 A 2D-list with the slot IDs belonging to this connection. First dimension represents the link, whilst second dimension the slots used. 

73 """ 

74 return self.__slots 

75 

76 @property 

77 def id(self): 

78 """ 

79 The ID of this connection. 

80 """ 

81 return self.__id