build.proxy_port   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 57
ccs 21
cts 24
cp 0.875
rs 10
c 0
b 0
f 0
wmc 12

4 Methods

Rating   Name   Duplication   Size   Complexity  
B ProxyPort.destination() 0 18 6
A ProxyPort.status() 0 10 4
A ProxyPort.__init__() 0 4 1
A ProxyPort.__repr__() 0 3 1
1
""" This class helps to handle multi-home physical loops (two ports). """
2
3 1
from typing import Optional
4
5 1
from kytos.core.common import EntityStatus
6 1
from kytos.core.controller import Controller
7 1
from kytos.core.interface import Interface
8
9
10 1
class ProxyPort:
11
    """This class helps to handle multi-home physical loops (two ports).
12
13
    source interface is where the loop starts
14
    destination interface is where the loop ends
15
    evc_ids are which evc ids this proxy port is being used by
16
17
    """
18
19 1
    def __init__(self, controller: Controller, source: Interface):
20 1
        self.controller = controller
21 1
        self.source = source
22 1
        self.evc_ids: set[str] = set()
23
24 1
    @property
25 1
    def destination(self) -> Optional[Interface]:
26
        """Destination interface of the loop."""
27 1
        if (
28
            "looped" not in self.source.metadata
29
            or "port_numbers" not in self.source.metadata["looped"]
30
            or not self.source.metadata["looped"]["port_numbers"]
31
            or len(self.source.metadata["looped"]["port_numbers"]) < 2
32
        ):
33 1
            return None
34
35 1
        destination = self.source.switch.get_interface_by_port_no(
36
            self.source.metadata["looped"]["port_numbers"][1]
37
        )
38 1
        if not destination:
39
            return None
40
41 1
        return destination
42
43 1
    @property
44 1
    def status(self) -> EntityStatus:
45
        """ProxyPort status."""
46 1
        if (
47
            self.source.status == EntityStatus.UP
48
            and self.destination
49
            and self.destination.status == EntityStatus.UP
50
        ):
51 1
            return EntityStatus.UP
52
        return EntityStatus.DOWN
53
54 1
    def __repr__(self) -> str:
55
        """Repr method."""
56
        return f"ProxyPort({self.source}, {self.destination}, {self.status})"
57