@@ -37,8 +37,9 @@ def protocol_next(self, config):
37
37
38
38
39
39
#################################
40
- # PAYLOAD protocols
40
+ # L7 protocols
41
41
#################################
42
+
42
43
class Empty (base_node ):
43
44
def __init__ (self ):
44
45
super ().__init__ ("Empty" )
@@ -66,25 +67,26 @@ def protocol_next(self, config):
66
67
return proto
67
68
68
69
69
- #################################
70
- # L7 protocols
71
- #################################
72
- class ICMPv4 (base_node ):
70
+ class VXLAN (base_node ):
73
71
def __init__ (self ):
74
- super ().__init__ ("ICMPv4 " )
72
+ super ().__init__ ("VXLAN " )
75
73
76
74
def protocol_add (self , config ):
77
- return scapy .all .ICMP ()
75
+ return scapy .all .VXLAN ()
78
76
77
+ def protocol_next (self , config ):
78
+ proto = {"ETH" : 1 }
79
79
80
- class ICMPv6 (base_node ):
81
- def __init__ (self ):
82
- super ().__init__ ("ICMPv6" )
80
+ if config .vxlan != 0 :
81
+ config .vxlan -= 1
83
82
84
- def protocol_add (self , config ):
85
- return scapy .all .ICMPv6Unknown ()
83
+ return proto
86
84
87
85
86
+ #################################
87
+ # L4 protocols
88
+ #################################
89
+
88
90
class UDP (base_node ):
89
91
def __init__ (self ):
90
92
super ().__init__ ("UDP" )
@@ -93,10 +95,14 @@ def protocol_add(self, config):
93
95
return scapy .all .UDP ()
94
96
95
97
def protocol_next (self , config ):
96
- proto = {"Empty" : 1 , "Payload" : 1 }
98
+ proto = {"Empty" : 1 , "Payload" : 1 , "VXLAN" : 1 }
97
99
cfg_obj = config .object_get ([self .name , "weight" ])
98
100
if cfg_obj is not None :
99
101
proto .update (cfg_obj )
102
+
103
+ if config .vxlan == 0 :
104
+ proto ["VXLAN" ] = 0
105
+
100
106
return proto
101
107
102
108
@@ -130,9 +136,29 @@ def protocol_next(self, config):
130
136
return proto
131
137
132
138
139
+ class GRE (base_node ):
140
+ def __init__ (self ):
141
+ super ().__init__ ("GRE" )
142
+
143
+ def protocol_add (self , config ):
144
+ return scapy .all .GRE (routing_present = 0 )
145
+
146
+ def protocol_next (self , config ):
147
+ proto = {"ETH" : 1 , "IPv4" : 1 , "IPv6" : 1 }
148
+ proto_weight = config .object_get ([self .name , "weight" ])
149
+ if proto_weight is not None :
150
+ proto .update (proto_weight )
151
+
152
+ if config .gre != 0 :
153
+ config .gre -= 1
154
+
155
+ return proto
156
+
157
+
133
158
#################################
134
- # IP protocols
159
+ # L3 protocols
135
160
#################################
161
+
136
162
class IPv4 (base_node ):
137
163
def __init__ (self ):
138
164
super ().__init__ ("IPv4" )
@@ -158,10 +184,14 @@ def protocol_add(self, config):
158
184
return scapy .all .IP (version = 4 , src = src , dst = dst )
159
185
160
186
def protocol_next (self , config ):
161
- proto = {"Payload" : 1 , "Empty" : 1 , "ICMPv4" : 1 , "UDP" : 1 , "TCP" : 1 , "SCTP" : 1 }
187
+ proto = {"Payload" : 1 , "Empty" : 1 , "ICMPv4" : 1 , "UDP" : 1 , "TCP" : 1 , "SCTP" : 1 , "GRE" : 1 }
162
188
proto_weight = config .object_get ([self .name , "weight" ])
163
189
if proto_weight is not None :
164
190
proto .update (proto_weight )
191
+
192
+ if config .gre == 0 :
193
+ proto ["GRE" ] = 0
194
+
165
195
return proto
166
196
167
197
@@ -174,7 +204,7 @@ def protocol_add(self, config):
174
204
return random .choice (possible_protocols )
175
205
176
206
def protocol_next (self , config ):
177
- proto = {"Payload" : 1 , "Empty" : 1 , "ICMPv4 " : 1 , "ICMPv6 " : 1 , "UDP " : 1 , "TCP " : 1 , "SCTP " : 1 , "IPv6Ext " : 1 }
207
+ proto = {"Payload" : 1 , "Empty" : 1 , "ICMPv6 " : 1 , "UDP " : 1 , "TCP " : 1 , "SCTP " : 1 , "IPv6Ext " : 1 , "GRE " : 1 }
178
208
proto_weight = config .object_get ([self .name , "weight" ])
179
209
if proto_weight is not None :
180
210
proto .update (proto_weight )
@@ -184,6 +214,9 @@ def protocol_next(self, config):
184
214
if (config .ipv6ext == 0 ):
185
215
proto ["IPv6Ext" ] = 0
186
216
217
+ if config .gre == 0 :
218
+ proto ["GRE" ] = 0
219
+
187
220
return proto
188
221
189
222
@@ -212,17 +245,37 @@ def protocol_add(self, config):
212
245
return scapy .all .IPv6 (version = 6 , src = src , dst = dst )
213
246
214
247
def protocol_next (self , config ):
215
- proto = {"Payload" : 1 , "Empty" : 1 , "ICMPv4 " : 1 , "ICMPv6 " : 1 , "UDP " : 1 , "TCP " : 1 , "SCTP " : 1 , "IPv6Ext " : 1 }
248
+ proto = {"Payload" : 1 , "Empty" : 1 , "ICMPv6 " : 1 , "UDP " : 1 , "TCP " : 1 , "SCTP " : 1 , "IPv6Ext " : 1 , "GRE " : 1 }
216
249
proto_weight = config .object_get ([self .name , "weight" ])
217
250
if proto_weight is not None :
218
251
proto .update (proto_weight )
252
+
253
+ if config .gre == 0 :
254
+ proto ["GRE" ] = 0
255
+
219
256
return proto
220
257
258
+
259
+ class ICMPv4 (base_node ):
260
+ def __init__ (self ):
261
+ super ().__init__ ("ICMPv4" )
262
+
263
+ def protocol_add (self , config ):
264
+ return scapy .all .ICMP ()
265
+
266
+
267
+ class ICMPv6 (base_node ):
268
+ def __init__ (self ):
269
+ super ().__init__ ("ICMPv6" )
270
+
271
+ def protocol_add (self , config ):
272
+ return scapy .all .ICMPv6Unknown ()
273
+
274
+
221
275
#################################
222
- # ETHERNET protocols
276
+ # L2 protocols
223
277
#################################
224
278
225
-
226
279
class MPLS (base_node ):
227
280
def __init__ (self ):
228
281
super ().__init__ ("MPLS" )
@@ -307,12 +360,16 @@ def protocol_next(self, config):
307
360
return proto
308
361
309
362
363
+ #################################
364
+ # Parser
365
+ #################################
366
+
310
367
class Parser :
311
368
def __init__ (self , pcap_file , cfg , seed ):
312
369
self .protocols = {
313
370
"ETH" : ETH (), "VLAN" : VLAN (), "TRILL" : TRILL (), "PPP" : PPP (), "MPLS" : MPLS (), "IPv6" : IPv6 (), "IPv6Ext" : IPv6Ext (),
314
371
"IPv4" : IPv4 (), "TCP" : TCP (), "UDP" : UDP (), "ICMPv6" : ICMPv6 (), "ICMPv4" : ICMPv4 (), "SCTP" : SCTP (),
315
- "Payload" : Payload (), "Empty" : Empty ()
372
+ "Payload" : Payload (), "Empty" : Empty (), "VXLAN" : VXLAN (), "GRE" : GRE ()
316
373
}
317
374
self .pcap_file = scapy .utils .PcapWriter (pcap_file , append = False , sync = True )
318
375
self .cfg = None
0 commit comments