Skip to content

Commit adb1912

Browse files
committed
Streamline cybernodes and add cyberlink sections in EpanetCPA class
1 parent 33b6325 commit adb1912

File tree

3 files changed

+60
-40
lines changed

3 files changed

+60
-40
lines changed

epanetCPA/EpanetCPA.m

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
% TO DO: should IDEALLY raise error if first line doesn't start with ; (header)
162162

163163
if size(section_text,1) == 1
164-
% EXIT< no cybernodes has been defined
164+
% EXIT< no cybernodes have been defined
165165
error('ERROR: no cybernodes defined in %s. Did you include the header for this section?', cpaFile)
166166
end
167167

@@ -196,28 +196,13 @@
196196
temp(nsep+1:3) = length(section_text{j});
197197
end
198198

199-
% get sensors...
200-
sensors = strtrim(section_text{j}(temp(1):temp(2)));
201-
202-
if ~isempty(sensors)
203-
sensors = regexp(sensors,',','split');
204-
end
205-
206-
for k = 1 : numel(sensors)
207-
thisNode.sensors(k) = strtrim(sensors(k));
208-
end
199+
% get sensors...
200+
sensors = section_text{j}(temp(1):temp(2));
201+
thisNode.sensors = strsplit(sensors(~isspace(sensors)),',');
209202

210203
% ... actuators...
211-
if temp(2) ~= length(section_text{j})
212-
actuators = strtrim(section_text{j}(temp(2):end));
213-
if ~isempty(actuators)
214-
actuators = regexp(actuators,',','split');
215-
end
216-
217-
for k = 1 : numel(actuators)
218-
thisNode.actuators(k) = strtrim(actuators(k));
219-
end
220-
end
204+
actuators = section_text{j}(temp(2):end);
205+
thisNode.actuators = strsplit(actuators(~isspace(actuators)),',');
221206

222207
% concatenate
223208
cybernodes = cat(1,cybernodes,thisNode);
@@ -226,7 +211,40 @@
226211
end
227212

228213
case 'CYBERLINKS'
229-
warning('THIS WILL BE REMOVED!')
214+
215+
if size(section_text,1) == 1
216+
% EXIT< no cyberlinks have been defined
217+
error('ERROR: no cyberlinks defined in %s. Did you include the header for this section?', cpaFile)
218+
end
219+
220+
% initialize array of cyberlinks
221+
cyberlinks = [];
222+
% loop through all cybernodes
223+
for j = 2 : size(section_text,1)
224+
225+
% check if comment first...
226+
temp = strtrim(section_text{j});
227+
if temp(1)~= ';'
228+
% get \t separator positions
229+
temp = regexp(section_text{j},'\t');
230+
nsep = numel(temp);
231+
if isempty(temp)
232+
error('Cyberlink string %d in %s file has no details.', j-1, self.cpaFile);
233+
elseif nsep > 2
234+
error('Problem with format of cyberlink string %d in %s file. Check README.md',...
235+
j-1, self.cpaFile);
236+
else
237+
238+
% initialize cybernode struct
239+
thisLink.sender = strtrim(section_text{j}(1:temp(1)));
240+
thisLink.receiver = strtrim(section_text{j}(temp(1):temp(2)));
241+
thisLink.signals = strsplit(strtrim(section_text{j}(temp(2):end)),',');
242+
243+
% concatenate
244+
cyberlinks = cat(1,cyberlinks,thisLink);
245+
end
246+
end
247+
end
230248

231249
case 'CYBERATTACKS'
232250
% TO DO: should IDEALLY raise error if first line doesn't start with ; (header)

plot_results.ipynb

Lines changed: 9 additions & 9 deletions
Large diffs are not rendered by default.
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
[CYBERNODES]
22
; Name Sensors Actuators
3-
PLC1 PU1, PU2, PU3
3+
PLC1 PU1, PU2
44
PLC2 T1
5-
PLC3 T2 PU4, PU5, PU6, PU7, V2
6-
PLC4 T3
7-
PLC5 PU8, PU9, PU10, PU11
8-
PLC6 T4
9-
PLC7 T5
10-
PLC8 T6
11-
PLC9 T7
125
; SCADA
136

7+
[CYBERLINKS]
8+
; Source Destination Variables
9+
PLC1 SCADA F_PU1, F_PU2, P_J269, P_J280
10+
PLC2 SCADA P_T1
11+
PLC2 PLC1 P_T1
12+
1413
[CYBERATTACKS]
1514
; Type Target Init_cond End_cond Arguments
15+
; Denial-of-service of the connection link between PLC2 and PLC1. PLC1 fails to receive updated readings water level data for tank T1 and keeps the pumps (PU1,PU2) ON. This causes a surge in the tank T1.
16+
1617

1718
[CYBEROPTIONS]
1819
verbosity 1
19-
initial_conditions 4,3.75,3.25,3.75,3.5,3.5,3
20+
what_to_store T1, PU1, PU2, J269, J280 PRESSURE FLOW
21+
initial_conditions 4
2022
patterns_file ./minitown_patterns.csv

0 commit comments

Comments
 (0)