@@ -29,7 +29,7 @@ def __init__(self, name):
2929 def name_get (self ):
3030 return self .name
3131
32- def protocol_add (self , config ):
32+ def protocol_add (self , config , packet ):
3333 return None
3434
3535 def protocol_next (self , config ):
@@ -49,15 +49,26 @@ class Payload(base_node):
4949 def __init__ (self ):
5050 super ().__init__ ("Payload" )
5151
52- def protocol_add (self , config ):
53- return scapy .all .Raw ()
52+ def protocol_add (self , config , packet ):
53+ min_size = config .object_get (["packet" , "size_min" ])
54+ max_size = config .object_get (["packet" , "size_max" ])
55+
56+ if not min_size :
57+ min_size = 60
58+ if not max_size :
59+ max_size = 1500
60+
61+ enlarged_size = random .randint (min_size , max_size )
62+ if len (packet ) < enlarged_size :
63+ payload_size = enlarged_size - len (packet )
64+ return scapy .all .Raw (random .randbytes (payload_size ))
5465
5566
5667class TRILL (base_node ):
5768 def __init__ (self ):
5869 super ().__init__ ("TRILL" )
5970
60- def protocol_add (self , config ):
71+ def protocol_add (self , config , packet ):
6172 return trill .Trill (version = 0 , res = 0 )
6273
6374 def protocol_next (self , config ):
@@ -71,7 +82,7 @@ class VXLAN(base_node):
7182 def __init__ (self ):
7283 super ().__init__ ("VXLAN" )
7384
74- def protocol_add (self , config ):
85+ def protocol_add (self , config , packet ):
7586 return scapy .all .VXLAN ()
7687
7788 def protocol_next (self , config ):
@@ -91,7 +102,7 @@ class UDP(base_node):
91102 def __init__ (self ):
92103 super ().__init__ ("UDP" )
93104
94- def protocol_add (self , config ):
105+ def protocol_add (self , config , packet ):
95106 return scapy .all .UDP ()
96107
97108 def protocol_next (self , config ):
@@ -110,7 +121,7 @@ class TCP(base_node):
110121 def __init__ (self ):
111122 super ().__init__ ("TCP" )
112123
113- def protocol_add (self , config ):
124+ def protocol_add (self , config , packet ):
114125 return scapy .all .TCP ()
115126
116127 def protocol_next (self , config ):
@@ -125,7 +136,7 @@ class SCTP(base_node):
125136 def __init__ (self ):
126137 super ().__init__ ("SCTP" )
127138
128- def protocol_add (self , config ):
139+ def protocol_add (self , config , packet ):
129140 return scapy .all .SCTP ()
130141
131142 def protocol_next (self , config ):
@@ -140,7 +151,7 @@ class GRE(base_node):
140151 def __init__ (self ):
141152 super ().__init__ ("GRE" )
142153
143- def protocol_add (self , config ):
154+ def protocol_add (self , config , packet ):
144155 return scapy .all .GRE (routing_present = 0 )
145156
146157 def protocol_next (self , config ):
@@ -163,7 +174,7 @@ class IPv4(base_node):
163174 def __init__ (self ):
164175 super ().__init__ ("IPv4" )
165176
166- def protocol_add (self , config ):
177+ def protocol_add (self , config , packet ):
167178 src = None
168179 dst = None
169180
@@ -199,7 +210,7 @@ class IPv6Ext(base_node):
199210 def __init__ (self ):
200211 super ().__init__ ("IPv6Ext" )
201212
202- def protocol_add (self , config ):
213+ def protocol_add (self , config , packet ):
203214 possible_protocols = [scapy .all .IPv6ExtHdrDestOpt (), scapy .all .IPv6ExtHdrFragment (id = random .randint (0 , 2 ** 32 - 1 )), scapy .all .IPv6ExtHdrHopByHop (), scapy .all .IPv6ExtHdrRouting ()]
204215 return random .choice (possible_protocols )
205216
@@ -224,7 +235,7 @@ class IPv6(base_node):
224235 def __init__ (self ):
225236 super ().__init__ ("IPv6" )
226237
227- def protocol_add (self , config ):
238+ def protocol_add (self , config , packet ):
228239 src = None
229240 dst = None
230241
@@ -260,15 +271,15 @@ class ICMPv4(base_node):
260271 def __init__ (self ):
261272 super ().__init__ ("ICMPv4" )
262273
263- def protocol_add (self , config ):
274+ def protocol_add (self , config , packet ):
264275 return scapy .all .ICMP ()
265276
266277
267278class ICMPv6 (base_node ):
268279 def __init__ (self ):
269280 super ().__init__ ("ICMPv6" )
270281
271- def protocol_add (self , config ):
282+ def protocol_add (self , config , packet ):
272283 return scapy .all .ICMPv6Unknown ()
273284
274285
@@ -280,7 +291,7 @@ class MPLS(base_node):
280291 def __init__ (self ):
281292 super ().__init__ ("MPLS" )
282293
283- def protocol_add (self , config ):
294+ def protocol_add (self , config , packet ):
284295 return scapy .contrib .mpls .MPLS ()
285296
286297 def protocol_next (self , config ):
@@ -305,7 +316,7 @@ class PPP(base_node):
305316 def __init__ (self ):
306317 super ().__init__ ("PPP" )
307318
308- def protocol_add (self , config ):
319+ def protocol_add (self , config , packet ):
309320 return scapy .all .PPPoE () / scapy .all .PPP ()
310321
311322 def protocol_next (self , config ):
@@ -321,7 +332,7 @@ class VLAN(base_node):
321332 def __init__ (self ):
322333 super ().__init__ ("VLAN" )
323334
324- def protocol_add (self , config ):
335+ def protocol_add (self , config , packet ):
325336 possible_protocols = [scapy .all .Dot1Q (), scapy .all .Dot1AD ()]
326337 return random .choice (possible_protocols )
327338
@@ -345,7 +356,7 @@ class ETH(base_node):
345356 def __init__ (self ):
346357 super ().__init__ ("ETH" )
347358
348- def protocol_add (self , config ):
359+ def protocol_add (self , config , packet ):
349360 return scapy .all .Ether (src = scapy .volatile .RandMAC (), dst = scapy .volatile .RandMAC ())
350361
351362 def protocol_next (self , config ):
0 commit comments