dabdc7195935cc618c624b699a1e48a2d64dc53e
[nfvbench.git] / nfvbench / traffic_gen / dummy.py
1 # Copyright 2016 Cisco Systems, Inc.  All rights reserved.
2 #
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
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
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
13 #    under the License.
14
15 from nfvbench.log import LOG
16
17 from traffic_base import AbstractTrafficGenerator
18 import traffic_utils as utils
19
20
21
22 class DummyTG(AbstractTrafficGenerator):
23     """Experimental dummy traffic generator.
24
25     This traffic generator will pretend to generate traffic and return fake data.
26     Useful for unit testing without actually generating any traffic.
27     """
28
29     def __init__(self, runner):
30         AbstractTrafficGenerator.__init__(self, runner)
31         self.port_handle = []
32         self.rates = []
33
34     def get_version(self):
35         return "0.1"
36
37     def init(self):
38         pass
39
40     def connect(self):
41         ports = list(self.config.generator_config.ports)
42         self.port_handle = ports
43
44     def is_arp_successful(self):
45         return True
46
47     def config_interface(self):
48         pass
49
50     def create_traffic(self, l2frame_size, rates, bidirectional, latency=True):
51         pass
52
53     def modify_rate(self, rate, reverse):
54         port_index = int(reverse)
55         port = self.port_handle[port_index]
56         self.rates[port_index] = utils.to_rate_str(rate)
57         LOG.info('Modified traffic stream for %s, new rate=%s.' % (port, utils.to_rate_str(rate)))
58
59     def clear_streamblock(self):
60         pass
61
62     def get_stats(self):
63         result = {}
64         for ph in self.port_handle:
65             result[ph] = {
66                 'tx': {
67                     'total_pkts': 1000,
68                     'total_pkt_bytes': 100000,
69                     'pkt_rate': 100,
70                     'pkt_bit_rate': 1000000
71                 },
72                 'rx': {
73                     'total_pkts': 1000,
74                     'total_pkt_bytes': 100000,
75                     'pkt_rate': 100,
76                     'pkt_bit_rate': 1000000,
77                     'dropped_pkts': 0
78                 }
79             }
80             result[ph]['rx']['max_delay_usec'] = 10.0
81             result[ph]['rx']['min_delay_usec'] = 1.0
82             result[ph]['rx']['avg_delay_usec'] = 2.0
83         return result
84
85     def clear_stats(self):
86         pass
87
88     def start_traffic(self):
89         pass
90
91     def stop_traffic(self):
92         pass
93
94     def cleanup(self):
95         pass