Step 2: Move test folder to root
[integration/test.git] / csit / libraries / SwitchClasses / Ovs.py
1 """
2 Open vSwitch Object Definition
3 Authors: james.luhrsen@hp.com
4 Created: 2014-10-02
5 """
6 import re
7 from BaseSwitch import *  # noqa
8
9
10 class Ovs(BaseSwitch):
11     '''
12     OpenVswitch Class
13     '''
14
15     make = 'OpenVswitch'
16     model = 'OVS'
17
18     mgmt_protocol = 'ssh'
19     mgmt_ip = ''
20     mgmt_port = ''
21     mgmt_user = 'mininet'
22     mgmt_password = 'mininet'
23
24     mgmt_prompt = '>'
25
26     initialization_type = 'cleanup'
27
28     @property
29     def connection_configs(self):
30         return ['pwd']
31
32     @property
33     def cleanup_cmds(self):
34         return ['/sbin/ifconfig -a | egrep \'^s\' | awk \'{print \"sudo ovs-vsctl del-br\",$1}\' | sh']
35
36     @property
37     def initialization_cmds(self):
38         return [self.cleanup_cmds]
39
40     @property
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']
46
47     @property
48     def openflow_validation_cmd(self):
49         return 'sudo ovs-vsctl show'
50
51     @property
52     def openflow_enable_config(self):
53         return ['sudo ovs-vsctl set-controller s1 tcp:' + self.of_controller_ip]
54
55     @property
56     def openflow_enable_validations(self):
57         return ['is_connected: true']
58
59     invalid_of_controller_ip = '1.1.1.1'
60
61     @property
62     def openflow_disable_config(self):
63         return ['sudo ovs-vsctl set-controller s1 tcp:' + self.invalid_of_controller_ip]
64
65     @property
66     def openflow_disable_validations(self):
67         return []
68
69     @property
70     def dump_all_flows(self):
71         return 'sudo /usr/bin/ovs-ofctl dump-flows s1 -O OpenFlow13'
72
73     @property
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]
81
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'
86
87     @property
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}"'
91
92     datapath_id_output_string = ''
93     datapath_id = ''
94
95     def update_datapath_id(self):
96         if not self.datapath_id_output_string:
97             self.datapath_id = 'unknown'
98         else:
99             # 32:cc:bf:34:ed:4c
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)