Skip to content

Commit 58a3afd

Browse files
committed
Small changes and added a verification in the scada node
1 parent 9c0bb6c commit 58a3afd

File tree

3 files changed

+17
-25
lines changed

3 files changed

+17
-25
lines changed

dhalsim/python2/generic_scada.py

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -82,33 +82,20 @@ def __init__(self, intermediate_yaml_path):
8282

8383
# Simple data has PLC tags, without the index (T101, 1) becomes T101
8484
self.plc_data, self.simple_plc_data = self.generate_plcs()
85-
#self.saved_values = [['iteration', 'timestamp']]
8685

8786
for PLC in self.intermediate_yaml['plcs']:
8887
if 'sensors' not in PLC:
8988
PLC['sensors'] = list()
9089

9190
if 'actuators' not in PLC:
9291
PLC['actuators'] = list()
93-
#self.saved_values[0].extend(PLC['sensors'])
94-
#self.saved_values[0].extend(PLC['actuators'])
9592

9693
self.update_cache_flag = False
9794
self.plcs_ready = False
9895

99-
100-
#self.previous_cache = {}
101-
#for ip in self.plc_data:
102-
# self.previous_cache[ip] = [0] * len(self.plc_data[ip])
103-
104-
105-
#self.cache = {}
106-
#for ip in self.plc_data:
107-
# self.cache[ip] = [0] * len(self.plc_data[ip])
108-
10996
columns_list = ['iteration', 'timestamp']
11097
columns_list.extend(self.get_scada_tags())
111-
# self.cache = dict.fromkeys(self.get_scada_tags())
98+
11299

113100
self.cache = pd.DataFrame(columns=columns_list)
114101
self.cache.loc[0] = 0
@@ -272,7 +259,6 @@ def sigint_handler(self, sig, frame):
272259
Shutdown protocol for the scada, writes the output before exiting.
273260
"""
274261
self.stop_cache_update()
275-
#self.cache_thread.join()
276262
self.write_output()
277263
self.scada_run = False
278264
self.logger.debug("SCADA shutdown")
@@ -285,10 +271,6 @@ def write_output(self):
285271
results = self.cache
286272
results.to_csv(self.output_path, index=False)
287273

288-
#with self.output_path.open(mode='w') as output:
289-
# writer = csv.writer(output)
290-
# writer.writerows(self.saved_values)
291-
292274
def generate_plcs(self):
293275
"""
294276
Generates a list of tuples, the first part being the ip of a PLC,
@@ -341,11 +323,12 @@ def update_cache(self, lock, cache_update_time):
341323
try:
342324
values = self.receive_multiple(self.plc_data[plc_ip], plc_ip)
343325
values_float = [float(x) for x in values]
344-
with lock:
345-
clock = int(self.get_master_clock())
346-
self.cache.loc[clock, self.simple_plc_data[plc_ip]] = values_float
347-
self.cache.loc[clock, 'iteration'] = clock
348-
self.updated_plc[plc_ip] = True
326+
if len(values_float) == len(self.simple_plc_data[plc_ip]):
327+
with lock:
328+
clock = int(self.get_master_clock())
329+
self.cache.loc[clock, self.simple_plc_data[plc_ip]] = values_float
330+
self.cache.loc[clock, 'iteration'] = clock
331+
self.updated_plc[plc_ip] = True
349332
except Exception as e:
350333
self.logger.error(
351334
"PLC receive_multiple with tags {tags} from {ip} failed with exception '{e}'".format(
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
inp_file: ctown_map.inp
2+
iterations: 2880
3+
network_topology_type: complex
4+
plcs: !include ctown_plcs.yaml
5+
simulator: epynet
6+
demand: pdd
7+
output_path: attack_output_13
8+
demand_patterns: events/demands_ctown_01.csv
9+
initial_tank_data: events/tanks_ctown_01.csv
10+
attacks: !include dataset_attacks/attack_13.yaml

examples/ctown_topology/dataset/dataset_normal_operating_conditions/ctown_config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ network_loss_data: network_loss_data.csv
99
network_delay_data: network_delay_data.csv
1010
simulator: epynet
1111
demand: pdd
12-
#log_level: debug

0 commit comments

Comments
 (0)