2 Open vSwitch Object Definition
3 Authors: james.luhrsen@hp.com
7 from BaseSwitch import BaseSwitch
10 class Ovs(BaseSwitch):
22 mgmt_password = 'mininet'
26 initialization_type = 'cleanup'
29 def connection_configs(self):
33 def cleanup_cmds(self):
34 return ['/sbin/ifconfig -a | egrep \'^s\' | awk \'{print \"sudo ovs-vsctl del-br\",$1}\' | sh']
37 def initialization_cmds(self):
38 return [self.cleanup_cmds]
41 def base_openflow_config(self):
42 return ['sudo ovs-vsctl add-br s1',
43 'sudo ovs-vsctl set bridge s1 protocols=OpenFlow13',
44 'sudo ovs-vsctl set-controller s1 tcp:' + self.of_controller_ip,
45 'sudo ifconfig s1 up']
48 def openflow_validation_cmd(self):
49 return 'sudo ovs-vsctl show'
52 def openflow_enable_config(self):
53 return ['sudo ovs-vsctl set-controller s1 tcp:' + self.of_controller_ip]
56 def openflow_enable_validations(self):
57 return ['is_connected: true']
59 invalid_of_controller_ip = '1.1.1.1'
62 def openflow_disable_config(self):
63 return ['sudo ovs-vsctl set-controller s1 tcp:' + self.invalid_of_controller_ip]
66 def openflow_disable_validations(self):
70 def dump_all_flows(self):
71 return 'sudo /usr/bin/ovs-ofctl dump-flows s1 -O OpenFlow13'
74 def flow_validations(self):
75 return ['dl_src=' + self.src_mac +
76 ',dl_dst=' + self.dst_mac +
77 ',nw_src=' + self.ip_src +
78 ',nw_dst=' + self.ip_dst +
79 ' actions=' + self.action,
80 'table=' + self.table_id]
82 def create_flow_match_elements(self, flow_xml):
83 super(Ovs, self).create_flow_match_elements(flow_xml)
84 if (self.action == 'INPORT'):
85 self.action = 'IN_PORT'
88 def datapath_id_output_command(self):
89 '''This regex will extract the macaddr of the ovs switch'''
90 return '/sbin/ifconfig s1 | grep -o -E "([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}"'
92 datapath_id_output_string = ''
95 def update_datapath_id(self):
96 if not self.datapath_id_output_string:
97 self.datapath_id = 'unknown'
100 datapath_id_hex = re.sub(':', '', self.datapath_id_output_string)
101 self.datapath_id = self.convert_hex_to_decimal_as_string(datapath_id_hex)