2 Base Switch Object Definition
3 Authors: james.luhrsen@hp.com
7 from xml.etree.ElementTree import * # noqa
10 class BaseSwitch(object):
28 initialization_type = ''
32 connection_configs = []
34 initialization_cmds = []
36 base_openflow_config = []
38 openflow_enable_config = []
40 openflow_enable_validations = []
42 openflow_disable_config = []
43 openflow_disable_validations = []
54 datapath_id_output_string = ''
55 datapath_id_output_command = ''
58 def set_connection_index(self, idx):
59 self.connection_index = idx
61 def set_controller_ip(self, ip):
62 self.of_controller_ip = ip
64 def set_mgmt_ip(self, ip):
67 def set_mgmt_user(self, user):
70 def set_ssh_key(self, key):
73 def update_datapath_id(self):
74 raise NotImplementedError("Please implement this method")
76 def create_flow_match_elements(self, flow_xml):
77 flow_tree = fromstring(flow_xml)
78 self.table_id = flow_tree.\
79 find('{urn:opendaylight:flow:inventory}table_id').text
80 instructions_element = flow_tree.\
81 find('{urn:opendaylight:flow:inventory}instructions')
82 instruction_element = instructions_element.\
83 find('{urn:opendaylight:flow:inventory}instruction')
84 apply_actions = instruction_element.\
85 find('{urn:opendaylight:flow:inventory}apply-actions')
86 action = apply_actions.\
87 find('{urn:opendaylight:flow:inventory}action')
88 output_action = action.\
89 find('{urn:opendaylight:flow:inventory}output-action')
90 output_node_connector = \
91 output_action.find('{urn:opendaylight:'
92 'flow:inventory}output-node-connector')
93 self.action = output_node_connector.text
94 match_element = flow_tree.\
95 find('{urn:opendaylight:flow:inventory}match')
96 ethernet_match_element = match_element.\
97 find('{urn:opendaylight:flow:inventory}ethernet-match')
98 ethernet_source = ethernet_match_element.\
99 find('{urn:opendaylight:flow:inventory}ethernet-source')
100 ethernet_source_address = ethernet_source.\
101 find('{urn:opendaylight:flow:inventory}address')
102 self.src_mac = ethernet_source_address.text
103 ethernet_destination = ethernet_match_element.\
104 find('{urn:opendaylight:flow:inventory}ethernet-destination')
105 ethernet_destination_address = ethernet_destination.\
106 find('{urn:opendaylight:flow:inventory}address')
107 self.dst_mac = ethernet_destination_address.text
108 self.ip_src = match_element.\
109 find('{urn:opendaylight:flow:inventory}ipv4-source').text
110 self.ip_dst = match_element.\
111 find('{urn:opendaylight:flow:inventory}ipv4-destination').text
113 def convert_hex_to_decimal_as_string(self, hex_string):
114 # TODO: need to add error checking in case the hex_string is
116 return str(int(hex_string, 16))
118 def get_switch(self, switch_type):
120 Generic method that will allow Robot Code to pass a string
121 to this "keyword - Get Switch" and create an object of that
122 type. (EX: Get Switch OVS)
125 # TODO: what if the module "switch_type" does not exist. Need some
126 # error checking for that.
127 module = importlib.import_module(switch_type)
128 return getattr(module, switch_type)()