d076d80ceecd7d67f110b161b5ccf3d189cd935a
[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 string
7 import robot
8 import re
9 from robot.libraries.BuiltIn import BuiltIn
10 from BaseSwitch import *
11
12 class Ovs(BaseSwitch):
13     '''
14     OpenVswitch Class
15     '''
16
17     make = 'OpenVswitch'
18     model = 'OVS'
19
20     mgmt_protocol = 'ssh'
21     mgmt_ip = ''
22     mgmt_port = ''
23     mgmt_user = 'mininet'
24     mgmt_password = 'mininet'
25
26     mgmt_prompt = '>'
27
28
29     initialization_type = 'cleanup'
30
31     @property
32     def connection_configs(self):
33         return \
34             ['pwd']
35
36     @property
37     def cleanup_cmds(self):
38         return \
39             ['/sbin/ifconfig | egrep \'^s\' | awk \'{print \"sudo ovs-vsctl del-br\",$1}\' | sh']
40
41     @property
42     def initialization_cmds(self):
43         return \
44             [self.cleanup_cmds]
45
46     @property
47     def base_openflow_config(self):
48         return \
49             ['sudo ovs-vsctl add-br s1', \
50              'sudo ovs-vsctl set bridge s1 protocols=OpenFlow13', \
51              'sudo ovs-vsctl set-controller s1 tcp:' + self.of_controller_ip]
52
53     @property
54     def openflow_validation_cmd(self):
55         return \
56             'sudo ovs-vsctl show'
57
58     @property
59     def openflow_enable_config(self):
60         return \
61             ['sudo ovs-vsctl set-controller s1 tcp:' + self.of_controller_ip]
62
63     @property
64     def openflow_enable_validations(self):
65         return \
66             ['is_connected: true']
67
68     invalid_of_controller_ip = '1.1.1.1'
69     @property
70     def openflow_disable_config(self):
71         return \
72             ['sudo ovs-vsctl set-controller s1 tcp:' + self.invalid_of_controller_ip]
73
74     @property
75     def openflow_disable_validations(self):
76         return \
77             []
78
79     @property
80     def dump_all_flows(self):
81         return \
82             'sudo /usr/bin/ovs-ofctl dump-flows s1 -O OpenFlow13'
83
84     @property
85     def flow_validations(self):
86         return \
87             ['dl_src=' + self.src_mac + \
88              ',dl_dst=' + self.dst_mac + \
89              ',nw_src=' + self.ip_src + \
90              ',nw_dst=' + self.ip_dst + \
91              ' actions=' + self.action, \
92              'table=' + self.table_id]
93
94     def create_flow_match_elements(self, flow_xml):
95         super(Ovs, self).create_flow_match_elements(flow_xml)
96         if (self.action == 'INPORT'):
97             self.action = 'IN_PORT'
98
99     @property
100     def datapath_id_output_command(self):
101         return \
102             '/sbin/ifconfig | egrep \'^s1\' | awk \'{print $5}\''
103
104     datapath_id_output_string = ''
105     datapath_id = ''
106
107     def update_datapath_id(self):
108         if not self.datapath_id_output_string:
109             self.datapath_id = 'unknown'
110         else:
111          #32:cc:bf:34:ed:4c
112          datapath_id_hex = re.sub(':', '', self.datapath_id_output_string)
113          self.datapath_id = self.convert_hex_to_decimal_as_string(datapath_id_hex)