7e977383c41edc0cc77f41bafbdd82f53e05e731
[integration/test.git] / test / csit / libraries / SwitchClasses / ProVision.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 ProVision(BaseSwitch):
13     '''
14     ProVision Super Class
15     '''
16
17     make = 'provision'
18     model = ''
19
20     mgmt_protocol = 'telnet'
21     mgmt_ip = ''
22     mgmt_port = ''
23     mgmt_prompt = model + '.*#'
24
25     initialization_type = 'reboot'
26
27     of_instance_id = '21'
28
29     @property
30     def connection_configs(self):
31         return \
32             ['\rend \
33              \rconfig \
34              \rconsole local-terminal none \
35              \rno page \
36              \rend\r']
37
38     @property
39     def initialization_cmds(self):
40         return \
41             ['\rend\rboot system flash primary config odl_test_startup_config\r', \
42              'y', \
43              'n']
44
45     @property
46     def cleanup_cmds(self):
47         return \
48             ['end', \
49              'config', \
50              'no openflow\r \
51              y']
52
53     @property
54     def base_openflow_config(self):
55         return \
56             'end', \
57             'config', \
58             'openflow', \
59             'controller-id ' + self.of_instance_id + ' ip ' + self.of_controller_ip + \
60                             ' controller-interface oobm', \
61             'instance ' + self.of_instance_id, \
62             'member vlan 10', \
63             'controller-id ' + self.of_instance_id + ' ', \
64             'version 1.3', \
65             'enable', \
66             'openflow enable', \
67             'end'
68
69     @property
70     def openflow_enable_config(self):
71         return \
72             ['end', \
73              'config', \
74              'openflow enable', \
75              'end']
76
77     @property
78     def openflow_validation_cmd(self):
79         return \
80             'show openflow'
81
82     @property
83     def openflow_enable_validations(self):
84         return \
85             ['OpenFlow +: Enabled', \
86              self.of_instance_id + ' +Up +2 +1 +1.3']
87
88     @property
89     def openflow_disable_config(self):
90         return \
91             ['end', \
92              'config', \
93              'openflow disable', \
94              'end']
95
96     @property
97     def openflow_disable_validations(self):
98         return \
99             ['OpenFlow +: Disabled', \
100              self.of_instance_id + ' +Down +0 +0 +1.3']
101
102     @property
103     def dump_all_flows(self):
104         return \
105             'show openflow instance ' + self.of_instance_id + ' flows'
106
107     @property
108     def flow_validations(self):
109         return \
110             ['(?ms)Flow Table ID : 0.*Flow Table ID : 100.*' + \
111              'Source Protocol Address : ' + self.ip_src + '.*' + \
112              'Target Protocol Address : ' + self.ip_dst + '.*' + \
113              'Flow Table ID : ' + self.table_id + '.*' + self.action, \
114              'Source MAC    : ' + self.src_mac, \
115              'Destination MAC  : ' + self.dst_mac]
116
117     def create_flow_match_elements(self, flow_xml):
118         super(ProVision, self).create_flow_match_elements(flow_xml)
119         self.src_mac = self.format_mac_with_no_hyphens_and_one_colon(self.src_mac)
120         self.dst_mac = self.format_mac_with_no_hyphens_and_one_colon(self.dst_mac)
121         self.action = self.convert_action_to_provision_format(self.action)
122
123     def format_mac_with_no_hyphens_and_one_colon(self, mac):
124         mac_no_colons = re.sub(':', '', mac)
125         mac_with_hyphen = mac_no_colons[:6] + '-' + mac_no_colons[6:]
126         return mac_with_hyphen
127
128     def convert_action_to_provision_format(self, action):
129         if (action == 'INPORT'):
130             return 'Ingress Port'
131         if (action == 'TABLE'):
132             return 'Table'
133         if (action == 'NORMAL'):
134             return 'Normal'
135         if (action == 'FLOOD'):
136             return 'Flood'
137         if (action == 'ALL'):
138             return 'All'
139         if (action == 'CONTROLLER'):
140             return 'Controller Port'
141         if (action == 'LOCAL'):
142             return 'Local'
143         return 'UNKNOWN'
144
145     @property
146     def datapath_id_output_command(self):
147         return \
148             'show openflow instance ' + self.of_instance_id + ' | include Datapath'
149
150     connection_index = ''
151
152     def set_connection_index(self, idx):
153         self.connection_index = idx
154
155     datapath_id_output_string = ''
156     datapath_id = ''
157
158     def update_datapath_id(self):
159         if not self.datapath_id_output_string:
160             self.datapath_id = 'unknown'
161         else:
162          #Datapath ID              : 000af0921c22bac0
163          #|-----------------(0)---------------------|
164          #|-----------(1)----------| |------(2)-----|
165          matches = re.search('(.*: )(\w+)', self.datapath_id_output_string)
166          datapath_id_hex = matches.group(2)
167          self.datapath_id = self.convert_hex_to_decimal_as_string(datapath_id_hex)