""",
description="Example for TRex HLTAPI",
- epilog=" based on hhaim's stl_run_udp_simple example");
+ epilog=" based on hhaim's stl_run_udp_simple example")
parser.add_argument("--ip",
dest="ip",
help='dst MAC',
default='00:50:56:b9:34:f3')
- args = parser.parse_args();
+ args = parser.parse_args()
hltapi = CTRexHltApi()
print 'Connecting to TRex'
def create_stream (self):
# create a base packet and pad it to size
- size = self.fsize - 4; # no FCS
+ size = self.fsize - 4 # no FCS
base_pkt = Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025) <1>
base_pkt1 = Ether()/IP(src="16.0.0.2",dst="48.0.0.1")/UDP(dport=12,sport=1025)
base_pkt2 = Ether()/IP(src="16.0.0.3",dst="48.0.0.1")/UDP(dport=12,sport=1025)
def create_stream (self):
# create a base packet and pad it to size
- size = self.fsize - 4; # no FCS
+ size = self.fsize - 4 # no FCS
base_pkt = Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025)
base_pkt1 = Ether()/IP(src="16.0.0.2",dst="48.0.0.1")/UDP(dport=12,sport=1025)
base_pkt2 = Ether()/IP(src="16.0.0.3",dst="48.0.0.1")/UDP(dport=12,sport=1025)
def create_stream (self):
# create a base packet and pad it to size
- size = self.fsize - 4; # no FCS
+ size = self.fsize - 4 # no FCS
base_pkt = Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025)
base_pkt1 = Ether()/IP(src="16.0.0.2",dst="48.0.0.1")/UDP(dport=12,sport=1025)
pad = max(0, size - len(base_pkt)) * 'x'
def create_stream (self):
# create a base packet and pad it to size
- size = self.fsize - 4; # no FCS
+ size = self.fsize - 4 # no FCS
base_pkt = Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025)
base_pkt1 = Ether()/IP(src="16.0.0.2",dst="48.0.0.1")/UDP(dport=12,sport=1025)
base_pkt2 = Ether()/IP(src="16.0.0.3",dst="48.0.0.1")/UDP(dport=12,sport=1025)
pad = max(0, size - len(base_pkt)) * 'x'
- return STLProfile( [ STLStream( isg = 10.0, # star in delay
+ return STLProfile( [ STLStream( isg = 10.0, # start in delay
name ='S0',
packet = STLPktBuilder(pkt = base_pkt/pad),
mode = STLTXSingleBurst( pps = 10, total_pkts = 1),
next = 'S1'), # point to next stream
- STLStream( self_start = False, # stream is disabled. Enabled by S0
+ STLStream( self_start = False, # stream is disabled. Enabled by S0
name ='S1',
packet = STLPktBuilder(pkt = base_pkt1/pad),
mode = STLTXSingleBurst( pps = 10, total_pkts = 2),
packet = STLPktBuilder(pkt = base_pkt2/pad),
mode = STLTXSingleBurst( pps = 10, total_pkts = 3 ),
action_count = 2, # loop 2 times <1>
- next = 'S0' # back to S0 loop
+ next = 'S0' # loop back to S0
)
]).get_streams()
<1> go back to S0 but limit it to 2 loops
-==== Tutorial: IMIX with UDP packets directional
+==== Tutorial: IMIX with UDP packets, bi-directional
-*Goal* : Demonstrate how to create IMIX
+*Goal* : Demonstrate how to create an IMIX traffic profile.
-This profile has 3 streams each with different size packet. The rate is different for each stream/size see link:https://en.wikipedia.org/wiki/Internet_Mix[here]
+This profile has 3 streams, each with different size packet. The rate is different for each stream/size. See link:https://en.wikipedia.org/wiki/Internet_Mix[here]
*file*:: link:{github_stl_path}/imix.py[stl/imix.py]
# default IMIX properties
self.imix_table = [ {'size': 60, 'pps': 28, 'isg':0 },
- {'size': 590, 'pps': 20, 'isg':0.1 },
+ {'size': 590, 'pps': 16, 'isg':0.1 },
{'size': 1514, 'pps': 4, 'isg':0.2 } ]
----
<1> Base on the direction, we will construct a diffrent stream (replace src and dest)
<2> Even port id has direction==0 and odd has direction==1
-<3> We didn't explain this yet. but this is a Field Engine program to change fields inside the packets
+<3> We didn't explain this yet. This is a Field Engine program to change fields inside the packets
==== Tutorial: Field Engine, Syn attack
The following example demonstrates changing packet fields.
-The Field Engine (FE) has limited number of instructions/operation for supporting most use cases. There is a plan to add LuaJIT to be more flexiable in the cost of performance.
-The FE can allocate stream variable in Stream context. Write a stream variable to a packet offset, change packet size etc.
+The Field Engine (FE) has limited number of instructions/operation for supporting most use cases. There is a plan to add LuaJIT to be more flexible at the cost of performance.
+The FE can allocate stream variables in a Stream context, write a stream variable to a packet offset, change packet size, etc.
*Some examples for what can be done:*
* Change ipv4.tos 1-10
-* Change packet size to be random in range 64-9K
-* Create range of flows (change src_ip,dest_ip,src_port,dest_port)
+* Change packet size to be random in the range 64-9K
+* Create range of flows (change src_ip, dest_ip, src_port, dest_port)
* Update IPv4 checksum
for more info see link:trex_rpc_server_spec.html#_object_type_em_vm_em_a_id_vm_obj_a[here]
STLVmFixIpv4(offset = "IP"), # fix checksum <5>
STLVmWrFlowVar(fv_name="src_port", <6>
- pkt_offset= "TCP.sport") # fix udp len
+ pkt_offset= "TCP.sport") # U
]
)
<1> Create SYN packet using Scapy
<2> Define stream variable name=ip_src, 4 bytes size for IPv4.
<3> Define stream variable name=src_port, 2 bytes size for port.
-<4> Write ip_src stream var into `IP.src` packet offset. Scapy calculate the offset. We could gave `IP:1.src" for second IP header in the packet
+<4> Write ip_src stream var into `IP.src` packet offset. Scapy calculates the offset. We could gave `IP:1.src" for second IP header in the packet
<5> Fix IPv4 checksum. here we provide the header name `IP` we could gave `IP:1` for second IP
-<6> Update TCP src port- TCP checksum is not updated here
+<6> Write src_port stream var into `TCP.sport` packet offset. TCP checksum is not updated here
WARNING: Original Scapy does not have the capability to calculate offset for a header/field by name. This offset capability won't work for all the cases because there could be complex cases that Scapy rebuild the header. In such cases put offset as a number
==== Tutorial: Field Engine, Tuple Generator
The following example demonstrates creating multiply flows from the same packet template.
-The TupleGenerator instructions are used to create two stream variables with IP, port see link:trex_rpc_server_spec.html#_object_type_em_vm_em_a_id_vm_obj_a[here]
+The Tuple Generator instructions are used to create two stream variables for IP, port. See link:trex_rpc_server_spec.html#_object_type_em_vm_em_a_id_vm_obj_a[here]
*file*:: link:{github_stl_path}/udp_1pkt_tuple_gen.py[stl/udp_1pkt_tuple_gen.py]
STLVmFixIpv4(offset = "IP"),
STLVmWrFlowVar (fv_name="tuple.port", pkt_offset= "UDP.sport" ) <3>
]
- );
+ )
pkt = STLPktBuilder(pkt = base_pkt/pad,
vm = vm)
----
-<1> Define struct with two dependent varibles tuple.ip tuple.port
-<2> Write tuple.ip to IPv4 src field offset
-<3> Write tuple.port to UDP header. You should set UDP.checksum to zero
+<1> Define struct with two dependent variables: tuple.ip, tuple.port
+<2> Write tuple.ip variable to `IPv4.src` field offset
+<3> Write tuple.port variable to `UDP.sport` field offset. You should set UDP.checksum to zero
.Pcap file output
|=================
* Number of clients are two. 16.0.0.1 and 16.0.0.2
-* Number of flows is limited to 129020 (2*65535-1025)
+* Number of flows is limited to 129020 (2 * (65535-1025))
* The stream variable size should match the size of the FlowVarWr instruction
==== Tutorial: Field Engine, write to a bit-field packet
def create_stream (self):
# pkt
- p_l2 = Ether();
+ p_l2 = Ether()
p_l3 = IP(src="16.0.0.1",dst="48.0.0.1")
p_l4 = UDP(dport=12,sport=1025)
- pyld_size = max(0, self.max_pkt_size_l3 - len(p_l3/p_l4));
+ pyld_size = max(0, self.max_pkt_size_l3 - len(p_l3/p_l4))
base_pkt = p_l2/p_l3/p_l4/('\x55'*(pyld_size))
- l3_len_fix =-(len(p_l2));
- l4_len_fix =-(len(p_l2/p_l3));
+ l3_len_fix =-(len(p_l2))
+ l4_len_fix =-(len(p_l2/p_l3))
# vm
class STLS1(object):
def __init__ (self):
- pass;
+ pass
def create_stream (self):
pkt = Ether()/IP()/UDP(sport=1337,dport=4789)/VXLAN(vni=42)/Ether()/IP()/('x'*20) <2>
class STLS1(object):
def __init__ (self):
- self.num_clients =30000; # max is 16bit
+ self.num_clients =30000 # max is 16bit
self.fsize =64
def create_stream (self):
# create a base packet and pad it to size
- size = self.fsize - 4; # no FCS
+ size = self.fsize - 4 # no FCS
base_pkt = Ether(src="00:00:dd:dd:00:01")/
IP(src="55.55.1.1",dst="58.55.1.1")/UDP(dport=12,sport=1025)
pad = max(0, size - len(base_pkt)) * 'x'
"""
def __init__ (self):
- self.max_pkt_size_l3 =9*1024;
+ self.max_pkt_size_l3 =9*1024
def create_stream (self):
"""
def __init__ (self):
- self.max_pkt_size_l3 =9*1024;
+ self.max_pkt_size_l3 =9*1024
def create_stream (self):
.Pseudocode
[source,bash]
----
- uint32_t val=(cast_to_size)rd_from_varible("name"); # read flow-var
- val+=m_add_value; # add value
+ uint32_t val=(cast_to_size)rd_from_varible("name") # read flow-var
+ val+=m_add_value # add value
if (m_shift>0) { # shift
- val=val<<m_shift;
+ val=val<<m_shift
}else{
if (m_shift<0) {
- val=val>>(-m_shift);
+ val=val>>(-m_shift)
}
}
port_id = args.get('port_id')
if port_id==None:
- port_id=0;
+ port_id=0
if port_id == 0:
return [STLHltStream(tcp_src_port_mode = 'decrement',
class STLS1(object):
def __init__ (self):
- self.num_clients =30000; # max is 16bit <1>
+ self.num_clients =30000 # max is 16bit <1>
self.fsize =64
def create_stream (self):
# create a base packet and pad it to size
- size = self.fsize - 4; # no FCS
+ size = self.fsize - 4 # no FCS
base_pkt = Ether(src="00:00:dd:dd:00:01")/IP(src="55.55.1.1",dst="58.0.0.1")/UDP(dport=12,sport=1025)
pad = max(0, size - len(base_pkt)) * 'x'