1 # Copyright 2015-2016 Intel Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain 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,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 """Helper methods collection.
16 Collection of helper methods used by traffic generators
20 from collections import namedtuple
22 CMD_PREFIX = 'gencmd : '
24 'traffic_type' : 'rfc2544',
26 'bidir' : 'False', # will be passed as string in title format to tgen
29 'pre_installed_flows' : 'No', # used by vswitch implementation
30 'flow_type' : 'port', # used by vswitch implementation
34 'srcmac': '00:00:00:00:00:00',
35 'dstmac': '00:00:00:00:00:00',
40 'dstip': '90.90.90.90',
54 #TODO remove namedtuples and implement results through IResult interface found
57 BurstResult = namedtuple(
59 'frames_tx frames_rx bytes_tx bytes_rx payload_err seq_err')
60 Back2BackResult = namedtuple(
62 'rx_fps rx_mbps tx_percent rx_percent tx_count b2b_frames '
63 'frame_loss_frames frame_loss_percent')
66 def merge_spec(orig, new):
67 """Merges ``new`` dict with ``orig`` dict, and return orig.
69 This takes into account nested dictionaries. Example:
71 >>> old = {'foo': 1, 'bar': {'foo': 2, 'bar': 3}}
72 >>> new = {'foo': 6, 'bar': {'foo': 7}}
73 >>> merge_spec(old, new)
74 {'foo': 6, 'bar': {'foo': 7, 'bar': 3}}
76 You'll notice that ``bar.bar`` is not removed. This is the desired result.
82 # Not allowing derived dictionary types for now
83 # pylint: disable=unidiomatic-typecheck
84 if type(orig[key]) == dict:
85 orig[key] = merge_spec(orig[key], new[key])