Initial code drop from Cisco
[nfvbench.git] / nfvbench / traffic_gen / traffic_base.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 import abc
16
17 class TrafficGeneratorException(Exception):
18     pass
19
20
21 class AbstractTrafficGenerator(object):
22
23     # src_mac (6) + dst_mac (6) + mac_type (2) + frame_check (4) = 18
24     l2_header_size = 18
25
26     imix_l2_sizes = [64, 594, 1518]
27     imix_l3_sizes = [size - l2_header_size for size in imix_l2_sizes]
28     imix_ratios = [7, 4, 1]
29     imix_avg_l2_size = sum(map(
30         lambda imix: 1.0 * imix[0] * imix[1],
31         zip(imix_l2_sizes, imix_ratios))) / sum(imix_ratios)
32
33     def __init__(self, config):
34         self.config = config
35
36     @abc.abstractmethod
37     def get_version():
38         # Must be implemented by sub classes
39         return None
40
41     @abc.abstractmethod
42     def init():
43         # Must be implemented by sub classes
44         return None
45
46     @abc.abstractmethod
47     def connect():
48         # Must be implemented by sub classes
49         return None
50
51     @abc.abstractmethod
52     def config_interface():
53         # Must be implemented by sub classes
54         return None
55
56     @abc.abstractmethod
57     def create_traffic():
58         # Must be implemented by sub classes
59         return None
60
61     @abc.abstractmethod
62     def modify_traffic():
63         # Must be implemented by sub classes
64         return None
65
66     @abc.abstractmethod
67     def get_stats():
68         # Must be implemented by sub classes
69         return None
70
71     @abc.abstractmethod
72     def clear_traffic():
73         # Must be implemented by sub classes
74         return None
75
76     @abc.abstractmethod
77     def start_traffic():
78         # Must be implemented by sub classes
79         return None
80
81     @abc.abstractmethod
82     def stop_traffic():
83         # Must be implemented by sub classes
84         return None
85
86     @abc.abstractmethod
87     def cleanup():
88         # Must be implemented by sub classes
89         return None