Merge "Increasing timers for this test after stats mgr improvements"
[integration/test.git] / test / csit / libraries / SwitchClasses / BaseSwitch.py
1 """
2 Base Switch Object Definition
3 Authors: james.luhrsen@hp.com
4 Created: 2014-09-20
5 """
6 import string
7 import robot
8 import importlib
9 from xml.etree.ElementTree import *
10
11 class BaseSwitch(object):
12     '''
13     Switch Base Class
14     '''
15
16     make = ''
17     model = ''
18
19     mgmt_protocol = ''
20     ssh_key = ''
21     mgmt_ip = ''
22     mgmt_port = ''
23     mgmt_user = ''
24     mgmt_password = ''
25     mgmt_prompt = '' 
26
27     connection_index = ''
28
29     initialization_type = ''
30
31     of_controller_ip = ''
32
33     connection_configs = []
34
35     initialization_cmds = []
36
37     base_openflow_config = []
38
39     openflow_enable_config = []
40
41     openflow_enable_validations = []
42
43     openflow_disable_config = []
44     openflow_disable_validations = []
45
46     dump_all_flows = []
47
48     src_mac = ''
49     dst_mac = ''
50     ip_src = ''
51     ip_dst = ''
52     table_id = ''
53     action = ''
54
55     datapath_id_output_string = ''
56     datapath_id_output_command = ''
57     datapath_id = ''
58
59     def set_connection_index(self, idx):
60         self.connection_index = idx
61
62     def set_controller_ip(self, ip):
63         self.of_controller_ip = ip
64
65     def set_mgmt_ip(self, ip):
66         self.mgmt_ip = ip
67
68     def set_mgmt_user(self, user):
69         self.mgmt_user = user
70
71     def set_ssh_key(self, key):
72         self.ssh_key = key
73
74     def update_datapath_id(self):
75         raise NotImplementedError("Please implement this method")
76
77     def create_flow_match_elements(self, flow_xml):
78         flow_tree = fromstring(flow_xml)
79
80         self.table_id = flow_tree.find('{urn:opendaylight:flow:inventory}table_id').text
81
82         instructions_element = flow_tree.find('{urn:opendaylight:flow:inventory}instructions')
83         instruction_element = instructions_element.find('{urn:opendaylight:flow:inventory}instruction')
84         apply_actions = instruction_element.find('{urn:opendaylight:flow:inventory}apply-actions')
85         action = apply_actions.find('{urn:opendaylight:flow:inventory}action')
86         output_action = action.find('{urn:opendaylight:flow:inventory}output-action')
87         output_node_connector = output_action.find('{urn:opendaylight:flow:inventory}output-node-connector')
88         self.action = output_node_connector.text
89
90         match_element = flow_tree.find('{urn:opendaylight:flow:inventory}match')
91         ethernet_match_element = match_element.find('{urn:opendaylight:flow:inventory}ethernet-match')
92
93         ethernet_source = ethernet_match_element.find('{urn:opendaylight:flow:inventory}ethernet-source')
94         ethernet_source_address = ethernet_source.find('{urn:opendaylight:flow:inventory}address')
95         self.src_mac = ethernet_source_address.text
96
97         ethernet_destination = ethernet_match_element.find('{urn:opendaylight:flow:inventory}ethernet-destination')
98         ethernet_destination_address = ethernet_destination.find('{urn:opendaylight:flow:inventory}address')
99         self.dst_mac = ethernet_destination_address.text
100
101         self.ip_src = match_element.find('{urn:opendaylight:flow:inventory}ipv4-source').text
102         self.ip_dst = match_element.find('{urn:opendaylight:flow:inventory}ipv4-destination').text
103
104     def convert_hex_to_decimal_as_string(self, hex_string):
105         ##TODO: need to add error checking in case the hex_string is
106         ##not fully hex
107         return str(int(hex_string, 16))
108
109     def get_switch(self, switch_type):
110         '''
111         Generic method that will allow Robot Code to pass a string
112         to this "keyword - Get Switch" and create an object of that
113         type.  (EX: Get Switch  OVS)
114         '''
115
116         ##TODO:  what if the module "switch_type" does not exist.  Need some
117         ##error checking for that.
118         module = importlib.import_module(switch_type)
119         return getattr(module, switch_type)()