1 # Copyright (c) 2016-2017 Intel Corporation
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 """ Fixed traffic profile definitions """
16 from __future__ import absolute_import
18 from yardstick.network_services.traffic_profile.base import TrafficProfile
19 from trex_stl_lib.trex_stl_streams import STLTXCont
20 from trex_stl_lib.trex_stl_client import STLStream
21 from trex_stl_lib.trex_stl_packet_builder_scapy import STLPktBuilder
22 from trex_stl_lib import api as Pkt
25 class FixedProfile(TrafficProfile):
27 This profile adds a single stream at the beginning of the traffic session
29 def __init__(self, tp_config):
30 super(FixedProfile, self).__init__(tp_config)
33 def execute(self, traffic_generator):
35 for index, ports in enumerate(traffic_generator.my_ports):
37 traffic_generator.vnfd["vdu"][0]["external-interface"]
38 virtual_interface = ext_intf[index]["virtual-interface"]
39 src_ip = virtual_interface["local_ip"]
40 dst_ip = virtual_interface["dst_ip"]
42 traffic_generator.client.add_streams(
43 self._create_stream(src_ip, dst_ip),
46 traffic_generator.client.start(ports=traffic_generator.my_ports,
48 self.first_run = False
50 def _create_stream(self, src_ip, dst_ip):
52 Pkt.Ether() / Pkt.IP(src=src_ip, dst=dst_ip) / Pkt.UDP(dport=12,
55 frame_size = self.params["traffic_profile"]["frame_size"]
56 pad_size = max(0, frame_size - len(base_frame))
57 frame = base_frame / ("x" * max(0, pad_size))
59 frame_rate = self.params["traffic_profile"]["frame_rate"]
60 return STLStream(packet=STLPktBuilder(pkt=frame),
61 mode=STLTXCont(pps=frame_rate))