1 # Copyright 2018 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
14 """This module creates the missing Trex library classes when they are not installed."""
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.api import STLError
21 # will raise ImportError: No module named trex.stl.api
22 # trex_gen.py will also try to import a number of trex.stl.api classes
27 from types import ModuleType
29 # Make up a trex.stl.api.STLError class
30 class STLDummy(Exception):
33 trex_lib_mod = ModuleType('trex')
34 sys.modules['trex'] = trex_lib_mod
35 stl_lib_mod = ModuleType('trex.stl')
36 trex_lib_mod.stl = stl_lib_mod
37 sys.modules['trex.stl'] = stl_lib_mod
38 api_mod = ModuleType('trex.stl.api')
39 stl_lib_mod.api = api_mod
40 sys.modules['trex.stl.api'] = api_mod
41 api_mod.STLError = STLDummy
42 api_mod.STLxyz = STLDummy
43 api_mod.CTRexVmInsFixHwCs = STLDummy
44 api_mod.Dot1Q = STLDummy
45 api_mod.Ether = STLDummy
46 api_mod.ARP = STLDummy
48 api_mod.ARP = STLDummy
49 api_mod.STLClient = STLDummy
50 api_mod.STLFlowLatencyStats = STLDummy
51 api_mod.STLFlowStats = STLDummy
52 api_mod.STLPktBuilder = STLDummy
53 api_mod.STLScVmRaw = STLDummy
54 api_mod.STLStream = STLDummy
55 api_mod.STLTXCont = STLDummy
56 api_mod.STLTXMultiBurst = STLDummy
57 api_mod.STLVmFixChecksumHw = STLDummy
58 api_mod.STLVmFixIpv4 = STLDummy
59 api_mod.STLVmFlowVar = STLDummy
60 api_mod.STLVmFlowVarRepeatableRandom = STLDummy
61 api_mod.STLVmTupleGen = STLDummy
62 api_mod.STLVmWrFlowVar = STLDummy
63 api_mod.UDP = STLDummy
64 api_mod.bind_layers = STLDummy
65 api_mod.FlagsField = STLDummy
66 api_mod.Packet = STLDummy
67 api_mod.ThreeBytesField = STLDummy
68 api_mod.XByteField = STLDummy
70 common_mod = ModuleType('trex.common')
71 trex_lib_mod.common = common_mod
72 sys.modules['trex.common'] = common_mod
73 services_mod = ModuleType('trex.common.services')
74 common_mod.services = services_mod
75 sys.modules['trex.common.services'] = services_mod
76 arp_mod = ModuleType('trex.common.services.trex_service_arp')
77 services_mod.trex_stl_service_arp = arp_mod
78 sys.modules['trex.common.services.trex_service_arp'] = arp_mod
79 arp_mod.ServiceARP = STLDummy