-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathML2_Demo_PingPong_Blackbox.thingml
193 lines (149 loc) · 4.21 KB
/
ML2_Demo_PingPong_Blackbox.thingml
1
2
3
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
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
// Armin Moin, moin@in.tum.de
// A sample model instance illustrating the Blackbox-ML (hybrid/mixed MDSE/Non-MDSE) mode for the smart ping-pong use case
object String
@type_checker "String"
@c_type "char *"
@java_type "String"
@js_type "String";
datatype Boolean<1>
@type_checker "Boolean"
@c_type "uint8_t"
@java_type "boolean"
@js_type "boolean";
datatype Int32<4>
@type_checker "Integer"
@c_type "int32_t"
@java_type "int"
@js_type "int";
thing fragment PingPongMsgs {
message ping(ip: String, code: Int32);
message pong();
message query(client_ip: String, client_code: Int32);
message prediction_positive();
message prediction_negative();
}
thing PingClient includes PingPongMsgs {
required port ping_service {
sends ping
receives pong
}
property my_ip_address: String = "192.168.1.1"
property my_code: Int32 = 10
statechart PingClientBehavior init Ping {
on entry print "Ping/Pong Client Started!\n"
state Ping {
on entry do
print "Sending Ping...\n"
ping_service!ping(my_ip_address,my_code)
end
transition -> Pong
event ping_service?pong
}
state Pong {
on entry print "Got pong!\n"
transition -> Stop
}
state Stop {
on entry print "Bye.\n"
}
}
}
thing PingServer includes PingPongMsgs {
provided port ping_service {
receives ping
sends pong
}
required port da_service {
sends query
receives prediction_positive, prediction_negative
}
property client_ip_address: String
property client_code: Int32
property malicious_client: Boolean
statechart PongServerBehavior init GetPing {
on entry print "Ping/Pong Server Started!\n"
state GetPing {
internal event e: ping_service?ping
action
do
client_ip_address = e.ip
client_code = e.code
print("Checking if the client is a malicious one...\n")
da_service!query(client_ip_address, client_code)
end
transition -> Pong
event da_service?prediction_negative
transition -> Ignore
event da_service?prediction_positive
}
state Pong {
on entry do
print "Got ping from: " + client_ip_address + " code: " + client_code + "\n"
print "Sending Pong...\n"
ping_service!pong()
malicious_client = false
end
transition -> GetPing
}
state Ignore {
on entry do
print "Got ping from: " + client_ip_address + "\n"
print "Ignoring the ping message, since the client is probably a malicious one...\n"
malicious_client = true
end
transition -> GetPing
}
}
}
thing PingPongDataAnalytics includes PingPongMsgs {
provided port da_service {
receives query
sends prediction_positive, prediction_negative
}
property client_ip_address: String
property client_code: Int32
property prediction: Boolean = false
data_analytics da1
@dalib "scikit-learn" {
labels ON
features client_ip_address,client_code,prediction
prediction_results prediction
blackbox_ml true
blackbox_ml_model "pre_trained/pre_trained_ml_model.pickle"
blackbox_import_algorithm "from sklearn.neural_network import MLPClassifier"
//blackbox_label_encoder "pre_trained/pre_trained_label_encoder.pickle"
}
statechart PingPongDataAnalyticsBehavior init Ready {
on entry print "Ping Pong Data Analytics Started!\n"
state Ready {
on entry do
print "Ping Pong Data Analytics: Ready for Prediction using the pre-trained ML model.\n"
end
transition -> Predict
event m: da_service?query
action do
client_ip_address = m.client_ip
client_code = m.client_code
end
}
state Predict {
on entry do
print "Ping Pong Data Analytics: Predicting using the pre-trained ML model...\n"
da_pre_trained_predict da1(client_ip_address, client_code)
if(prediction==false)
da_service!prediction_negative()
else
da_service!prediction_positive()
end
transition -> Ready
on exit da_save da1
}
}
}
configuration ML2_Demo_PingPong_Blackbox_Cfg @compiler "python_java" {
instance pingClient : PingClient
instance pingServer : PingServer
instance pingPongDataAnalytics : PingPongDataAnalytics
connector pingClient.ping_service => pingServer.ping_service
connector pingServer.da_service => pingPongDataAnalytics.da_service
}