Merge "trex_learning: Add learning packet option to T-Rex testing"
[vswitchperf.git] / tools / pkt_gen / xena / json / xena_json_pairs.py
1 # Copyright 2017 Red Hat Inc & Xena Networks.
2 #
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
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,
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
15 # Contributors:
16 #   Dan Amzulescu, Xena Networks
17 #   Christian Trautman, Red Hat Inc.
18 #
19 # Usage can be seen below in unit test. This implementation is designed for one
20 # module two port Xena chassis runs only.
21
22 """
23 Xena JSON module for pairs topology
24 """
25
26 from tools.pkt_gen.xena.json.xena_json import XenaJSON
27
28
29 class XenaJSONPairs(XenaJSON):
30     """
31     Class to modify and read Xena JSON configuration files. Topology will be set
32     as Blocks
33     """
34     def __init__(self):
35         super(XenaJSONPairs, self).__init__()
36         self.set_topology_pairs()
37
38     def set_topology_pairs(self):
39         """
40         Set the test topology to loopback pairs for packets that need to return
41         to the same port they are sent from
42         :return: None
43         """
44         self.json_data['TestOptions']['TopologyConfig']['Topology'] = 'PAIRS'
45         self.json_data['TestOptions']['TopologyConfig'][
46             'Direction'] = 'WEST_EAST'
47         self.json_data['PortHandler']['EntityList'][0][
48             'PortGroup'] = "WEST"
49         self.json_data['PortHandler']['EntityList'][1][
50             'PortGroup'] = "WEST"
51
52     def remove_port(self, port_number):
53         """
54         Remove a port from the config.
55         :param port_number: port to remove from json config as int
56         :return: None
57         """
58         del self.json_data['PortHandler']['EntityList'][port_number]
59         del self.json_data['StreamHandler']['StreamConnectionList'][0][
60             'Port{}Id'.format(port_number + 1)]