1 # Copyright 2016 Cisco Systems, Inc. All rights reserved.
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # 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, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
17 from nfvbench.log import LOG
21 class TrafficGeneratorException(Exception):
25 class AbstractTrafficGenerator(object):
26 # src_mac (6) + dst_mac (6) + mac_type (2) + frame_check (4) = 18
29 imix_l2_sizes = [64, 594, 1518]
30 imix_l3_sizes = [size - l2_header_size for size in imix_l2_sizes]
31 imix_ratios = [7, 4, 1]
32 imix_avg_l2_size = sum(
33 [1.0 * imix[0] * imix[1] for imix in zip(imix_l2_sizes, imix_ratios)]) / sum(imix_ratios)
35 traffic_utils.imix_avg_l2_size = imix_avg_l2_size
37 def __init__(self, config):
41 def get_version(self):
42 # Must be implemented by sub classes
47 # Must be implemented by sub classes
52 # Must be implemented by sub classes
56 def config_interface(self):
57 # Must be implemented by sub classes
61 def create_traffic(self):
62 # Must be implemented by sub classes
65 def modify_rate(self, rate, reverse):
66 port_index = int(reverse)
67 port = self.port_handle[port_index]
68 self.rates[port_index] = traffic_utils.to_rate_str(rate)
69 LOG.info('Modified traffic stream for %s, new rate=%s.', port,
70 traffic_utils.to_rate_str(rate))
72 def modify_traffic(self):
73 # Must be implemented by sub classes
78 # Must be implemented by sub classes
81 def clear_traffic(self):
82 # Must be implemented by sub classes
86 def start_traffic(self):
87 # Must be implemented by sub classes
91 def stop_traffic(self):
92 # Must be implemented by sub classes
97 # Must be implemented by sub classes