1 # Copyright (c) 2020 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 """Traffic profile for T-rex advanced stateful (astf) traffic generator.
17 - Two streams sent in directions 0 --> 1 (client -> server, requests) and
18 1 --> 0 (server -> client, responses) at the same time.
19 - Packet: ETH / IP / TCP
21 - Source IP address range: 192.168.0.0 - 192.168.255.255
22 - Destination IP address range: 20.0.0.0 - 20.0.255.255
24 - Source IP address range: destination IP address from packet received
26 - Destination IP address range: source IP address from packet received
30 from trex.astf.api import *
31 from profile_trex_astf_base_class import TrafficProfileBaseClass
34 class TrafficProfile(TrafficProfileBaseClass):
35 """Traffic profile."""
38 """Initialization and setting of profile parameters."""
40 super(TrafficProfileBaseClass, self).__init__()
42 # IPs used in packet headers.
43 self.p1_src_start_ip = u"192.168.0.0"
44 self.p1_src_end_ip = u"192.168.255.255"
45 self.p1_dst_start_ip = u"20.0.0.0"
46 self.p1_dst_end_ip = u"20.0.255.255"
48 # Headers length; not used in this profile, just for the record of
49 # header length for TCP packet with 0B payload
50 self.headers_size = 58 # 14B l2 + 20B ipv4 + 24B tcp incl. 4B options
52 # Delay for keeping tcp sessions active
53 self.delay = 2000000 # delay 2s (2,000,000 usec)
55 def define_profile(self):
56 """Define profile to be used by advanced stateful traffic generator.
58 This method MUST return:
60 return ip_gen, templates, None
62 :returns: IP generator and profile templates for ASTFProfile().
66 prog_c = ASTFProgram()
69 # receive syn-ack (0B sent in tcp syn-ack packet) and send ack
71 # wait defined time, then send fin-ack
72 prog_c.delay(self.delay)
75 prog_s = ASTFProgram()
76 # receive syn, send syn-ack
78 # receive fin-ack, send ack + fin-ack
79 prog_s.wait_for_peer_close()
82 ip_gen_c = ASTFIPGenDist(
83 ip_range=[self.p1_src_start_ip, self.p1_src_end_ip],
86 ip_gen_s = ASTFIPGenDist(
87 ip_range=[self.p1_dst_start_ip, self.p1_dst_end_ip],
91 glob=ASTFIPGenGlobal(ip_offset=u"0.0.0.1"),
97 s_assoc = ASTFAssociation(rules=ASTFAssociationRule(port=8080))
100 temp_c = ASTFTCPClientTemplate(
103 limit=4128768, # TODO: set via input parameter
106 temp_s = ASTFTCPServerTemplate(program=prog_s, assoc=s_assoc)
107 template = ASTFTemplate(client_template=temp_c, server_template=temp_s)
109 return ip_gen, template, None
113 """Register this traffic profile to T-Rex.
115 Do not change this function.
117 :return: Traffic Profiles.
120 return TrafficProfile()