2.0 beta NFVBENCH-91 Allow multi-chaining with separate edge networks
[nfvbench.git] / test / mock_trex.py
1 # Copyright 2018 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 """This module creates the missing Trex library classes when they are not installed."""
15
16 import sys
17
18 # Because trex_stl_lib may not be installed when running unit test
19 # nfvbench.traffic_client will try to import STLError:
20 # from trex_stl_lib.api import STLError
21 # will raise ImportError: No module named trex_stl_lib.api
22 # trex.py will also try to import a number of trex_stl_lib classes
23 try:
24     import trex_stl_lib.api
25     assert trex_stl_lib.api
26 except ImportError:
27     from types import ModuleType
28
29     # Make up a trex_stl_lib.api.STLError class
30     class STLDummy(Exception):
31         """Dummy class."""
32
33         pass
34
35     stl_lib_mod = ModuleType('trex_stl_lib')
36     sys.modules['trex_stl_lib'] = stl_lib_mod
37     api_mod = ModuleType('trex_stl_lib.api')
38     stl_lib_mod.api = api_mod
39     sys.modules['trex_stl_lib.api'] = api_mod
40     api_mod.STLError = STLDummy
41     api_mod.STLxyz = STLDummy
42     api_mod.CTRexVmInsFixHwCs = STLDummy
43     api_mod.Dot1Q = STLDummy
44     api_mod.Ether = STLDummy
45     api_mod.IP = STLDummy
46     api_mod.STLClient = STLDummy
47     api_mod.STLFlowLatencyStats = STLDummy
48     api_mod.STLFlowStats = STLDummy
49     api_mod.STLPktBuilder = STLDummy
50     api_mod.STLScVmRaw = STLDummy
51     api_mod.STLStream = STLDummy
52     api_mod.STLTXCont = STLDummy
53     api_mod.STLVmFixChecksumHw = STLDummy
54     api_mod.STLVmFlowVar = STLDummy
55     api_mod.STLVmFlowVarRepetableRandom = STLDummy
56     api_mod.STLVmWrFlowVar = STLDummy
57     api_mod.UDP = STLDummy
58
59     services_mod = ModuleType('trex_stl_lib.services')
60     stl_lib_mod.services = services_mod
61     sys.modules['trex_stl_lib.services'] = services_mod
62
63     arp_mod = ModuleType('trex_stl_lib.services.trex_stl_service_arp')
64     services_mod.trex_stl_service_arp = arp_mod
65     sys.modules['trex_stl_lib.services.trex_stl_service_arp'] = arp_mod
66     arp_mod.STLServiceARP = STLDummy
67
68 def no_op():
69     """Empty function."""
70     pass