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