Skip to content

Documentation for Neighborpolicy Module

NeighborPolicy

Bases: ABC

Source code in nebula/core/situationalawareness/awareness/sanetwork/neighborpolicies/neighborpolicy.py
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
class NeighborPolicy(ABC):
    @abstractmethod
    async def set_config(self, config):
        """Set internal configuration parameters for the neighbor policy, typically from a shared configuration object."""
        pass

    @abstractmethod
    async def need_more_neighbors(self):
        """Return True if the current node requires additional neighbors to fulfill its connectivity policy."""
        pass

    @abstractmethod
    async def get_posible_neighbors(self):
        """Return set of posible neighbors to connect to."""
        pass

    @abstractmethod
    async def any_leftovers_neighbors(self):
        """Return True if there are any neighbors that are no longer needed or should be replaced."""
        pass

    @abstractmethod
    async def get_neighbors_to_remove(self):
        """Return a list of neighbors that should be removed based on current policy constraints or evaluation."""
        pass

    @abstractmethod
    async def accept_connection(self, source, joining=False):
        """
        Determine whether to accept a connection request from a given node.

        Parameters:
            source: The identifier of the node requesting the connection.
            joining (bool): Whether this is an initial joining request.

        Returns:
            bool: True if the connection is accepted, False otherwise.
        """
        pass

    @abstractmethod
    async def get_actions(self):
        """Return a list of actions (e.g., add or remove neighbors) that should be executed to maintain the policy."""
        pass

    @abstractmethod
    async def meet_node(self, node):
        """
        Register the discovery or interaction with a new node.

        Parameters:
            node: The node being encountered or added to internal memory.
        """
        pass

    @abstractmethod
    async def forget_nodes(self, nodes, forget_all=False):
        """
        Remove the specified nodes from internal memory.

        Parameters:
            nodes: A list of node identifiers to forget.
            forget_all (bool): If True, forget all nodes.
        """
        pass

    @abstractmethod
    async def get_nodes_known(self, neighbors_too=False, neighbors_only=False):
        """
        Retrieve a list of nodes known by the current policy.

        Parameters:
            neighbors_too (bool): If True, include current neighbors in the result.
            neighbors_only (bool): If True, return only current neighbors.

        Returns:
            list: A list of node identifiers.
        """
        pass

    @abstractmethod
    async def update_neighbors(self, node, remove=False):
        """
        Add or remove a neighbor in the current neighbor set.

        Parameters:
            node: The node to be added or removed.
            remove (bool): If True, remove the node instead of adding.
        """
        pass

    @abstractmethod
    async def stricted_topology_status(stricted_topology: bool):
        """
        Update the policy with the current strict topology status.

        Parameters:
            stricted_topology (bool): True if the topology should be preserved.
        """
        pass

accept_connection(source, joining=False) abstractmethod async

Determine whether to accept a connection request from a given node.

Parameters:

Name Type Description Default
source

The identifier of the node requesting the connection.

required
joining bool

Whether this is an initial joining request.

False

Returns:

Name Type Description
bool

True if the connection is accepted, False otherwise.

Source code in nebula/core/situationalawareness/awareness/sanetwork/neighborpolicies/neighborpolicy.py
30
31
32
33
34
35
36
37
38
39
40
41
42
@abstractmethod
async def accept_connection(self, source, joining=False):
    """
    Determine whether to accept a connection request from a given node.

    Parameters:
        source: The identifier of the node requesting the connection.
        joining (bool): Whether this is an initial joining request.

    Returns:
        bool: True if the connection is accepted, False otherwise.
    """
    pass

any_leftovers_neighbors() abstractmethod async

Return True if there are any neighbors that are no longer needed or should be replaced.

Source code in nebula/core/situationalawareness/awareness/sanetwork/neighborpolicies/neighborpolicy.py
20
21
22
23
@abstractmethod
async def any_leftovers_neighbors(self):
    """Return True if there are any neighbors that are no longer needed or should be replaced."""
    pass

forget_nodes(nodes, forget_all=False) abstractmethod async

Remove the specified nodes from internal memory.

Parameters:

Name Type Description Default
nodes

A list of node identifiers to forget.

required
forget_all bool

If True, forget all nodes.

False
Source code in nebula/core/situationalawareness/awareness/sanetwork/neighborpolicies/neighborpolicy.py
59
60
61
62
63
64
65
66
67
68
@abstractmethod
async def forget_nodes(self, nodes, forget_all=False):
    """
    Remove the specified nodes from internal memory.

    Parameters:
        nodes: A list of node identifiers to forget.
        forget_all (bool): If True, forget all nodes.
    """
    pass

get_actions() abstractmethod async

Return a list of actions (e.g., add or remove neighbors) that should be executed to maintain the policy.

Source code in nebula/core/situationalawareness/awareness/sanetwork/neighborpolicies/neighborpolicy.py
44
45
46
47
@abstractmethod
async def get_actions(self):
    """Return a list of actions (e.g., add or remove neighbors) that should be executed to maintain the policy."""
    pass

get_neighbors_to_remove() abstractmethod async

Return a list of neighbors that should be removed based on current policy constraints or evaluation.

Source code in nebula/core/situationalawareness/awareness/sanetwork/neighborpolicies/neighborpolicy.py
25
26
27
28
@abstractmethod
async def get_neighbors_to_remove(self):
    """Return a list of neighbors that should be removed based on current policy constraints or evaluation."""
    pass

get_nodes_known(neighbors_too=False, neighbors_only=False) abstractmethod async

Retrieve a list of nodes known by the current policy.

Parameters:

Name Type Description Default
neighbors_too bool

If True, include current neighbors in the result.

False
neighbors_only bool

If True, return only current neighbors.

False

Returns:

Name Type Description
list

A list of node identifiers.

Source code in nebula/core/situationalawareness/awareness/sanetwork/neighborpolicies/neighborpolicy.py
70
71
72
73
74
75
76
77
78
79
80
81
82
@abstractmethod
async def get_nodes_known(self, neighbors_too=False, neighbors_only=False):
    """
    Retrieve a list of nodes known by the current policy.

    Parameters:
        neighbors_too (bool): If True, include current neighbors in the result.
        neighbors_only (bool): If True, return only current neighbors.

    Returns:
        list: A list of node identifiers.
    """
    pass

get_posible_neighbors() abstractmethod async

Return set of posible neighbors to connect to.

Source code in nebula/core/situationalawareness/awareness/sanetwork/neighborpolicies/neighborpolicy.py
15
16
17
18
@abstractmethod
async def get_posible_neighbors(self):
    """Return set of posible neighbors to connect to."""
    pass

meet_node(node) abstractmethod async

Register the discovery or interaction with a new node.

Parameters:

Name Type Description Default
node

The node being encountered or added to internal memory.

required
Source code in nebula/core/situationalawareness/awareness/sanetwork/neighborpolicies/neighborpolicy.py
49
50
51
52
53
54
55
56
57
@abstractmethod
async def meet_node(self, node):
    """
    Register the discovery or interaction with a new node.

    Parameters:
        node: The node being encountered or added to internal memory.
    """
    pass

need_more_neighbors() abstractmethod async

Return True if the current node requires additional neighbors to fulfill its connectivity policy.

Source code in nebula/core/situationalawareness/awareness/sanetwork/neighborpolicies/neighborpolicy.py
10
11
12
13
@abstractmethod
async def need_more_neighbors(self):
    """Return True if the current node requires additional neighbors to fulfill its connectivity policy."""
    pass

set_config(config) abstractmethod async

Set internal configuration parameters for the neighbor policy, typically from a shared configuration object.

Source code in nebula/core/situationalawareness/awareness/sanetwork/neighborpolicies/neighborpolicy.py
5
6
7
8
@abstractmethod
async def set_config(self, config):
    """Set internal configuration parameters for the neighbor policy, typically from a shared configuration object."""
    pass

stricted_topology_status(stricted_topology) abstractmethod async

Update the policy with the current strict topology status.

Parameters:

Name Type Description Default
stricted_topology bool

True if the topology should be preserved.

required
Source code in nebula/core/situationalawareness/awareness/sanetwork/neighborpolicies/neighborpolicy.py
 95
 96
 97
 98
 99
100
101
102
103
@abstractmethod
async def stricted_topology_status(stricted_topology: bool):
    """
    Update the policy with the current strict topology status.

    Parameters:
        stricted_topology (bool): True if the topology should be preserved.
    """
    pass

update_neighbors(node, remove=False) abstractmethod async

Add or remove a neighbor in the current neighbor set.

Parameters:

Name Type Description Default
node

The node to be added or removed.

required
remove bool

If True, remove the node instead of adding.

False
Source code in nebula/core/situationalawareness/awareness/sanetwork/neighborpolicies/neighborpolicy.py
84
85
86
87
88
89
90
91
92
93
@abstractmethod
async def update_neighbors(self, node, remove=False):
    """
    Add or remove a neighbor in the current neighbor set.

    Parameters:
        node: The node to be added or removed.
        remove (bool): If True, remove the node instead of adding.
    """
    pass