d8c01e9a4072e1624f693c9713fce3fd684268df
[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 traffic_base import AbstractTrafficGenerator
16
17
18 class DummyTG(AbstractTrafficGenerator):
19     """Experimental dummy traffic generator.
20
21     This traffic generator will pretend to generate traffic and return fake data.
22     Useful for unit testing without actually generating any traffic.
23     """
24
25     def __init__(self, runner):
26         AbstractTrafficGenerator.__init__(self, runner)
27         self.port_handle = []
28         self.rates = []
29
30     def get_version(self):
31         return "0.1"
32
33     def init(self):
34         pass
35
36     def connect(self):
37         ports = list(self.config.generator_config.ports)
38         self.port_handle = ports
39
40     def is_arp_successful(self):
41         return True
42
43     def config_interface(self):
44         pass
45
46     def create_traffic(self, l2frame_size, rates, bidirectional, latency=True):
47         pass
48
49     def clear_streamblock(self):
50         pass
51
52     def get_stats(self):
53         result = {}
54         for ph in self.port_handle:
55             result[ph] = {
56                 'tx': {
57                     'total_pkts': 1000,
58                     'total_pkt_bytes': 100000,
59                     'pkt_rate': 100,
60                     'pkt_bit_rate': 1000000
61                 },
62                 'rx': {
63                     'total_pkts': 1000,
64                     'total_pkt_bytes': 100000,
65                     'pkt_rate': 100,
66                     'pkt_bit_rate': 1000000,
67                     'dropped_pkts': 0
68                 }
69             }
70             result[ph]['rx']['max_delay_usec'] = 10.0
71             result[ph]['rx']['min_delay_usec'] = 1.0
72             result[ph]['rx']['avg_delay_usec'] = 2.0
73         return result
74
75     def clear_stats(self):
76         pass
77
78     def start_traffic(self):
79         pass
80
81     def stop_traffic(self):
82         pass
83
84     def cleanup(self):
85         pass