Fix pep8 violations in csit/libraries/SwitchClasses/Ovs.py
[integration/test.git] / test / csit / libraries / SwitchClasses / Ovs.py
1 """
2 Provision 3800 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 | 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
46     @property
47     def openflow_validation_cmd(self):
48         return 'sudo ovs-vsctl show'
49
50     @property
51     def openflow_enable_config(self):
52         return ['sudo ovs-vsctl set-controller s1 tcp:' + self.of_controller_ip]
53
54     @property
55     def openflow_enable_validations(self):
56         return ['is_connected: true']
57
58     invalid_of_controller_ip = '1.1.1.1'
59
60     @property
61     def openflow_disable_config(self):
62         return ['sudo ovs-vsctl set-controller s1 tcp:' + self.invalid_of_controller_ip]
63
64     @property
65     def openflow_disable_validations(self):
66         return []
67
68     @property
69     def dump_all_flows(self):
70         return 'sudo /usr/bin/ovs-ofctl dump-flows s1 -O OpenFlow13'
71
72     @property
73     def flow_validations(self):
74         return ['dl_src=' + self.src_mac +
75                 ',dl_dst=' + self.dst_mac +
76                 ',nw_src=' + self.ip_src +
77                 ',nw_dst=' + self.ip_dst +
78                 ' actions=' + self.action,
79                 'table=' + self.table_id]
80
81     def create_flow_match_elements(self, flow_xml):
82         super(Ovs, self).create_flow_match_elements(flow_xml)
83         if (self.action == 'INPORT'):
84             self.action = 'IN_PORT'
85
86     @property
87     def datapath_id_output_command(self):
88         return '/sbin/ifconfig | egrep \'^s1\' | awk \'{print $5}\''
89
90     datapath_id_output_string = ''
91     datapath_id = ''
92
93     def update_datapath_id(self):
94         if not self.datapath_id_output_string:
95             self.datapath_id = 'unknown'
96         else:
97             # 32:cc:bf:34:ed:4c
98             datapath_id_hex = re.sub(':', '', self.datapath_id_output_string)
99             self.datapath_id = self.convert_hex_to_decimal_as_string(datapath_id_hex)