Migrate Get Requests invocations(libraries)
[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 BaseSwitch
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 [
35             "/sbin/ifconfig -a | egrep '^s' | awk '{print \"sudo ovs-vsctl del-br\",$1}' | sh"
36         ]
37
38     @property
39     def initialization_cmds(self):
40         return [self.cleanup_cmds]
41
42     @property
43     def base_openflow_config(self):
44         return [
45             "sudo ovs-vsctl add-br s1",
46             "sudo ovs-vsctl set bridge s1 protocols=OpenFlow13",
47             "sudo ovs-vsctl set-controller s1 tcp:" + self.of_controller_ip,
48             "sudo ifconfig s1 up",
49         ]
50
51     @property
52     def openflow_validation_cmd(self):
53         return "sudo ovs-vsctl show"
54
55     @property
56     def openflow_enable_config(self):
57         return ["sudo ovs-vsctl set-controller s1 tcp:" + self.of_controller_ip]
58
59     @property
60     def openflow_enable_validations(self):
61         return ["is_connected: true"]
62
63     invalid_of_controller_ip = "1.1.1.1"
64
65     @property
66     def openflow_disable_config(self):
67         return ["sudo ovs-vsctl set-controller s1 tcp:" + self.invalid_of_controller_ip]
68
69     @property
70     def openflow_disable_validations(self):
71         return []
72
73     @property
74     def dump_all_flows(self):
75         return "sudo /usr/bin/ovs-ofctl dump-flows s1 -O OpenFlow13"
76
77     @property
78     def flow_validations(self):
79         return [
80             "dl_src="
81             + self.src_mac
82             + ",dl_dst="
83             + self.dst_mac
84             + ",nw_src="
85             + self.ip_src
86             + ",nw_dst="
87             + self.ip_dst
88             + " actions="
89             + self.action,
90             "table=" + self.table_id,
91         ]
92
93     def create_flow_match_elements(self, flow_xml):
94         super(Ovs, self).create_flow_match_elements(flow_xml)
95         if self.action == "INPORT":
96             self.action = "IN_PORT"
97
98     @property
99     def datapath_id_output_command(self):
100         """This regex will extract the macaddr of the ovs switch"""
101         return (
102             '/sbin/ifconfig s1 | grep -o -E "([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}"'
103         )
104
105     datapath_id_output_string = ""
106     datapath_id = ""
107
108     def update_datapath_id(self):
109         if not self.datapath_id_output_string:
110             self.datapath_id = "unknown"
111         else:
112             # 32:cc:bf:34:ed:4c
113             datapath_id_hex = re.sub(":", "", self.datapath_id_output_string)
114             self.datapath_id = self.convert_hex_to_decimal_as_string(datapath_id_hex)