Skip to content

scenarios

Scenario

Source code in nebula/scenarios.py
 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
class Scenario:
    def __init__(
        self,
        scenario_title,
        scenario_description,
        deployment,
        federation,
        topology,
        nodes,
        nodes_graph,
        n_nodes,
        matrix,
        dataset,
        iid,
        partition_selection,
        partition_parameter,
        model,
        agg_algorithm,
        rounds,
        logginglevel,
        accelerator,
        network_subnet,
        network_gateway,
        epochs,
        attacks,
        poisoned_node_percent,
        poisoned_sample_percent,
        poisoned_noise_percent,
        with_reputation,
        is_dynamic_topology,
        is_dynamic_aggregation,
        target_aggregation,
        random_geo,
        latitude,
        longitude,
        mobility,
        mobility_type,
        radius_federation,
        scheme_mobility,
        round_frequency,
        mobile_participants_percent,
        additional_participants,
        schema_additional_participants,
    ):
        """
        Initialize the scenario.

        Args:
            scenario_title (str): Title of the scenario.
            scenario_description (str): Description of the scenario.
            deployment (str): Type of deployment (e.g., 'docker', 'process').
            federation (str): Type of federation.
            topology (str): Network topology.
            nodes (dict): Dictionary of nodes.
            nodes_graph (dict): Graph of nodes.
            n_nodes (int): Number of nodes.
            matrix (list): Matrix of connections.
            dataset (str): Dataset used.
            iid (bool): Indicator if data is independent and identically distributed.
            partition_selection (str): Method of partition selection.
            partition_parameter (float): Parameter for partition selection.
            model (str): Model used.
            agg_algorithm (str): Aggregation algorithm.
            rounds (int): Number of rounds.
            logginglevel (str): Logging level.
            accelerator (str): Accelerator used.
            network_subnet (str): Network subnet.
            network_gateway (str): Network gateway.
            epochs (int): Number of epochs.
            attacks (list): List of attacks.
            poisoned_node_percent (float): Percentage of poisoned nodes.
            poisoned_sample_percent (float): Percentage of poisoned samples.
            is_dynamic_topology (bool): Indicator if topology is dynamic.
            is_dynamic_aggregation (bool): Indicator if aggregation is dynamic.
            target_aggregation (str): Target aggregation method.
            random_geo (bool): Indicator if random geo is used.
            latitude (float): Latitude for mobility.
            longitude (float): Longitude for mobility.
            mobility (bool): Indicator if mobility is used.
            mobility_type (str): Type of mobility.
            radius_federation (float): Radius of federation.
            scheme_mobility (str): Scheme of mobility.
            round_frequency (int): Frequency of rounds.
            mobile_participants_percent (float): Percentage of mobile participants.
            additional_participants (list): List of additional participants.
            schema_additional_participants (str): Schema for additional participants.
        """
        self.scenario_title = scenario_title
        self.scenario_description = scenario_description
        self.deployment = deployment
        self.federation = federation
        self.topology = topology
        self.nodes = nodes
        self.nodes_graph = nodes_graph
        self.n_nodes = n_nodes
        self.matrix = matrix
        self.dataset = dataset
        self.iid = iid
        self.partition_selection = partition_selection
        self.partition_parameter = partition_parameter
        self.model = model
        self.agg_algorithm = agg_algorithm
        self.rounds = rounds
        self.logginglevel = logginglevel
        self.accelerator = accelerator
        self.network_subnet = network_subnet
        self.network_gateway = network_gateway
        self.epochs = epochs
        self.attacks = attacks
        self.poisoned_node_percent = poisoned_node_percent
        self.poisoned_sample_percent = poisoned_sample_percent
        self.poisoned_noise_percent = poisoned_noise_percent
        self.with_reputation = with_reputation
        self.is_dynamic_topology = is_dynamic_topology
        self.is_dynamic_aggregation = is_dynamic_aggregation
        self.target_aggregation = target_aggregation
        self.random_geo = random_geo
        self.latitude = latitude
        self.longitude = longitude
        self.mobility = mobility
        self.mobility_type = mobility_type
        self.radius_federation = radius_federation
        self.scheme_mobility = scheme_mobility
        self.round_frequency = round_frequency
        self.mobile_participants_percent = mobile_participants_percent
        self.additional_participants = additional_participants
        self.schema_additional_participants = schema_additional_participants

    def attack_node_assign(
        self,
        nodes,
        federation,
        attack,
        poisoned_node_percent,
        poisoned_sample_percent,
        poisoned_noise_percent,
    ):
        """Identify which nodes will be attacked"""
        import math
        import random

        nodes_index = []
        # Get the nodes index
        if federation == "DFL":
            nodes_index = list(nodes.keys())
        else:
            for node in nodes:
                if nodes[node]["role"] != "server":
                    nodes_index.append(node)

        mal_nodes_defined = any(nodes[node]["malicious"] for node in nodes)

        attacked_nodes = []

        if not mal_nodes_defined:
            n_nodes = len(nodes_index)
            # Number of attacked nodes, round up
            num_attacked = int(math.ceil(poisoned_node_percent / 100 * n_nodes))
            if num_attacked > n_nodes:
                num_attacked = n_nodes

            # Get the index of attacked nodes
            attacked_nodes = random.sample(nodes_index, num_attacked)

        # Assign the role of each node
        for node in nodes:
            node_att = "No Attack"
            malicious = False
            attack_sample_percent = 0
            poisoned_ratio = 0
            if (str(nodes[node]["id"]) in attacked_nodes) or (nodes[node]["malicious"]):
                malicious = True
                node_att = attack
                attack_sample_percent = poisoned_sample_percent / 100
                poisoned_ratio = poisoned_noise_percent / 100
            nodes[node]["malicious"] = malicious
            nodes[node]["attacks"] = node_att
            nodes[node]["poisoned_sample_percent"] = attack_sample_percent
            nodes[node]["poisoned_ratio"] = poisoned_ratio
        return nodes

    def mobility_assign(self, nodes, mobile_participants_percent):
        """Assign mobility to nodes"""
        import random

        # Number of mobile nodes, round down
        num_mobile = math.floor(mobile_participants_percent / 100 * len(nodes))
        if num_mobile > len(nodes):
            num_mobile = len(nodes)

        # Get the index of mobile nodes
        mobile_nodes = random.sample(list(nodes.keys()), num_mobile)

        # Assign the role of each node
        for node in nodes:
            node_mob = False
            if node in mobile_nodes:
                node_mob = True
            nodes[node]["mobility"] = node_mob
        return nodes

    @classmethod
    def from_dict(cls, data):
        return cls(**data)

__init__(scenario_title, scenario_description, deployment, federation, topology, nodes, nodes_graph, n_nodes, matrix, dataset, iid, partition_selection, partition_parameter, model, agg_algorithm, rounds, logginglevel, accelerator, network_subnet, network_gateway, epochs, attacks, poisoned_node_percent, poisoned_sample_percent, poisoned_noise_percent, with_reputation, is_dynamic_topology, is_dynamic_aggregation, target_aggregation, random_geo, latitude, longitude, mobility, mobility_type, radius_federation, scheme_mobility, round_frequency, mobile_participants_percent, additional_participants, schema_additional_participants)

Initialize the scenario.

Parameters:

Name Type Description Default
scenario_title str

Title of the scenario.

required
scenario_description str

Description of the scenario.

required
deployment str

Type of deployment (e.g., 'docker', 'process').

required
federation str

Type of federation.

required
topology str

Network topology.

required
nodes dict

Dictionary of nodes.

required
nodes_graph dict

Graph of nodes.

required
n_nodes int

Number of nodes.

required
matrix list

Matrix of connections.

required
dataset str

Dataset used.

required
iid bool

Indicator if data is independent and identically distributed.

required
partition_selection str

Method of partition selection.

required
partition_parameter float

Parameter for partition selection.

required
model str

Model used.

required
agg_algorithm str

Aggregation algorithm.

required
rounds int

Number of rounds.

required
logginglevel str

Logging level.

required
accelerator str

Accelerator used.

required
network_subnet str

Network subnet.

required
network_gateway str

Network gateway.

required
epochs int

Number of epochs.

required
attacks list

List of attacks.

required
poisoned_node_percent float

Percentage of poisoned nodes.

required
poisoned_sample_percent float

Percentage of poisoned samples.

required
is_dynamic_topology bool

Indicator if topology is dynamic.

required
is_dynamic_aggregation bool

Indicator if aggregation is dynamic.

required
target_aggregation str

Target aggregation method.

required
random_geo bool

Indicator if random geo is used.

required
latitude float

Latitude for mobility.

required
longitude float

Longitude for mobility.

required
mobility bool

Indicator if mobility is used.

required
mobility_type str

Type of mobility.

required
radius_federation float

Radius of federation.

required
scheme_mobility str

Scheme of mobility.

required
round_frequency int

Frequency of rounds.

required
mobile_participants_percent float

Percentage of mobile participants.

required
additional_participants list

List of additional participants.

required
schema_additional_participants str

Schema for additional participants.

required
Source code in nebula/scenarios.py
 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
def __init__(
    self,
    scenario_title,
    scenario_description,
    deployment,
    federation,
    topology,
    nodes,
    nodes_graph,
    n_nodes,
    matrix,
    dataset,
    iid,
    partition_selection,
    partition_parameter,
    model,
    agg_algorithm,
    rounds,
    logginglevel,
    accelerator,
    network_subnet,
    network_gateway,
    epochs,
    attacks,
    poisoned_node_percent,
    poisoned_sample_percent,
    poisoned_noise_percent,
    with_reputation,
    is_dynamic_topology,
    is_dynamic_aggregation,
    target_aggregation,
    random_geo,
    latitude,
    longitude,
    mobility,
    mobility_type,
    radius_federation,
    scheme_mobility,
    round_frequency,
    mobile_participants_percent,
    additional_participants,
    schema_additional_participants,
):
    """
    Initialize the scenario.

    Args:
        scenario_title (str): Title of the scenario.
        scenario_description (str): Description of the scenario.
        deployment (str): Type of deployment (e.g., 'docker', 'process').
        federation (str): Type of federation.
        topology (str): Network topology.
        nodes (dict): Dictionary of nodes.
        nodes_graph (dict): Graph of nodes.
        n_nodes (int): Number of nodes.
        matrix (list): Matrix of connections.
        dataset (str): Dataset used.
        iid (bool): Indicator if data is independent and identically distributed.
        partition_selection (str): Method of partition selection.
        partition_parameter (float): Parameter for partition selection.
        model (str): Model used.
        agg_algorithm (str): Aggregation algorithm.
        rounds (int): Number of rounds.
        logginglevel (str): Logging level.
        accelerator (str): Accelerator used.
        network_subnet (str): Network subnet.
        network_gateway (str): Network gateway.
        epochs (int): Number of epochs.
        attacks (list): List of attacks.
        poisoned_node_percent (float): Percentage of poisoned nodes.
        poisoned_sample_percent (float): Percentage of poisoned samples.
        is_dynamic_topology (bool): Indicator if topology is dynamic.
        is_dynamic_aggregation (bool): Indicator if aggregation is dynamic.
        target_aggregation (str): Target aggregation method.
        random_geo (bool): Indicator if random geo is used.
        latitude (float): Latitude for mobility.
        longitude (float): Longitude for mobility.
        mobility (bool): Indicator if mobility is used.
        mobility_type (str): Type of mobility.
        radius_federation (float): Radius of federation.
        scheme_mobility (str): Scheme of mobility.
        round_frequency (int): Frequency of rounds.
        mobile_participants_percent (float): Percentage of mobile participants.
        additional_participants (list): List of additional participants.
        schema_additional_participants (str): Schema for additional participants.
    """
    self.scenario_title = scenario_title
    self.scenario_description = scenario_description
    self.deployment = deployment
    self.federation = federation
    self.topology = topology
    self.nodes = nodes
    self.nodes_graph = nodes_graph
    self.n_nodes = n_nodes
    self.matrix = matrix
    self.dataset = dataset
    self.iid = iid
    self.partition_selection = partition_selection
    self.partition_parameter = partition_parameter
    self.model = model
    self.agg_algorithm = agg_algorithm
    self.rounds = rounds
    self.logginglevel = logginglevel
    self.accelerator = accelerator
    self.network_subnet = network_subnet
    self.network_gateway = network_gateway
    self.epochs = epochs
    self.attacks = attacks
    self.poisoned_node_percent = poisoned_node_percent
    self.poisoned_sample_percent = poisoned_sample_percent
    self.poisoned_noise_percent = poisoned_noise_percent
    self.with_reputation = with_reputation
    self.is_dynamic_topology = is_dynamic_topology
    self.is_dynamic_aggregation = is_dynamic_aggregation
    self.target_aggregation = target_aggregation
    self.random_geo = random_geo
    self.latitude = latitude
    self.longitude = longitude
    self.mobility = mobility
    self.mobility_type = mobility_type
    self.radius_federation = radius_federation
    self.scheme_mobility = scheme_mobility
    self.round_frequency = round_frequency
    self.mobile_participants_percent = mobile_participants_percent
    self.additional_participants = additional_participants
    self.schema_additional_participants = schema_additional_participants

attack_node_assign(nodes, federation, attack, poisoned_node_percent, poisoned_sample_percent, poisoned_noise_percent)

Identify which nodes will be attacked

Source code in nebula/scenarios.py
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
def attack_node_assign(
    self,
    nodes,
    federation,
    attack,
    poisoned_node_percent,
    poisoned_sample_percent,
    poisoned_noise_percent,
):
    """Identify which nodes will be attacked"""
    import math
    import random

    nodes_index = []
    # Get the nodes index
    if federation == "DFL":
        nodes_index = list(nodes.keys())
    else:
        for node in nodes:
            if nodes[node]["role"] != "server":
                nodes_index.append(node)

    mal_nodes_defined = any(nodes[node]["malicious"] for node in nodes)

    attacked_nodes = []

    if not mal_nodes_defined:
        n_nodes = len(nodes_index)
        # Number of attacked nodes, round up
        num_attacked = int(math.ceil(poisoned_node_percent / 100 * n_nodes))
        if num_attacked > n_nodes:
            num_attacked = n_nodes

        # Get the index of attacked nodes
        attacked_nodes = random.sample(nodes_index, num_attacked)

    # Assign the role of each node
    for node in nodes:
        node_att = "No Attack"
        malicious = False
        attack_sample_percent = 0
        poisoned_ratio = 0
        if (str(nodes[node]["id"]) in attacked_nodes) or (nodes[node]["malicious"]):
            malicious = True
            node_att = attack
            attack_sample_percent = poisoned_sample_percent / 100
            poisoned_ratio = poisoned_noise_percent / 100
        nodes[node]["malicious"] = malicious
        nodes[node]["attacks"] = node_att
        nodes[node]["poisoned_sample_percent"] = attack_sample_percent
        nodes[node]["poisoned_ratio"] = poisoned_ratio
    return nodes

mobility_assign(nodes, mobile_participants_percent)

Assign mobility to nodes

Source code in nebula/scenarios.py
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def mobility_assign(self, nodes, mobile_participants_percent):
    """Assign mobility to nodes"""
    import random

    # Number of mobile nodes, round down
    num_mobile = math.floor(mobile_participants_percent / 100 * len(nodes))
    if num_mobile > len(nodes):
        num_mobile = len(nodes)

    # Get the index of mobile nodes
    mobile_nodes = random.sample(list(nodes.keys()), num_mobile)

    # Assign the role of each node
    for node in nodes:
        node_mob = False
        if node in mobile_nodes:
            node_mob = True
        nodes[node]["mobility"] = node_mob
    return nodes