6b1973ef05c54d1ccbd3da203d4e909ff2159115
[functest.git] / testcases / Controllers / ONOS / Sfc / Sfc.py
1 """Script to Test the SFC scenarios in ONOS."""
2 # !/usr/bin/python
3 #
4 # Copyright (c) 2015 All rights reserved
5 # This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # ###########################################################################
12 #                          OPNFV SFC Script
13 # **** Scripted by Antony Silvester  - antony.silvester@huawei.com ******
14 # ###########################################################################
15
16 # Testcase 1 : Prerequisites configuration for SFC
17 # Testcase 2 : Creation of 3 VNF Nodes and Attaching Ports
18 # TestCase 3 : Configure  SFC [Port pair,Port Group ,Flow classifer
19 # TestCase 4 : Configure Port Chain and verify the flows are added.
20 # TestCase 5 : Verify  traffic with VNF node.
21 # TestCase 6 : Remove the Port Chain and Verify the traffic.
22 # Testcase 7 : Cleanup
23 # ###########################################################################
24 #
25
26 import functest.utils.functest_logger as ft_logger
27 import functest.utils.functest_utils as functest_utils
28 import time
29 from Sfc_fun import Sfc_fun
30
31
32 class Sfc:
33     """Script to Test the SFC scenarios in ONOS."""
34     logger = ft_logger.Logger("sfc").getLogger()
35     Sfc_obj = Sfc_fun()
36     start_time = time.time()
37     status = "PASS"
38     print("################################################################")
39     print("                    OPNFV SFC Script             ")
40     print("################################################################")
41     logger.info("Testcase 1 : Prerequisites configuration for SFC")
42     #########################################################################
43     logger.info("\t1.1 Creation of Auth-Token")
44     if (Sfc_obj.getToken() == 200):
45         logger.info("\t\tCreation of Token is successfull")
46     else:
47         status = "FAIL"
48         logger.error("\t\t  :  Creation of Token is NOT successfull")
49     #########################################################################
50     logger.info("\t1.2 Creation of Network")
51     if (Sfc_obj.createNetworks() == 201):
52         logger.info("\t\tCreation of network is successfull")
53     else:
54         status = "FAIL"
55         logger.error("\t\t  :  Creation of network is NOT successfull")
56     #########################################################################
57     logger.info("\t1.3 Creation of Subnetwork")
58     if (Sfc_obj.createSubnets() == 201):
59         logger.info("\t\tCreation of Subnetwork is successfull")
60     else:
61         status = "FAIL"
62         logger.error("\t\t  :  Creation of Subnetwork is NOT successfull")
63     print ("\n###########################################################\n")
64     ########################################################################
65     logger.info("Testcase 2 : Creation of 3 VNF Nodes and Attaching Ports")
66     #########################################################################
67     logger.info("\t2.1 Creation of Ports")
68     if (Sfc_obj.createPorts() == 201):
69         logger.info("\t\tCreation of Port is successfull")
70     else:
71         status = "FAIL"
72         logger.error("\t\t  :  Creation of Port is NOT successfull")
73     #########################################################################
74     logger.info("\t2.2 Creation of VM-Compute-Node")
75     if (Sfc_obj.createVm() == 202):
76         logger.info("\t\tCreation of VM is successfull")
77     else:
78         status = "FAIL"
79         logger.error("\t\t  :  Creation of VM is NOT successfull")
80     #########################################################################
81     logger.info("\t2.3 Check VM Status")
82     if (Sfc_obj.checkVmState() == 200):
83         logger.info("\t\tVM are in active state")
84     else:
85         status = "FAIL"
86         logger.error("\t\t  :   VM is NOT Active")
87     #########################################################################
88     logger.info("\t\t2.4 Router Creation")
89     if (Sfc_obj.createRouter() == 201):
90         logger.info("\t\t Router Creation is Successful")
91     else:
92         status = "FAIL"
93         logger.error("\t\t  :   Router Creation is NOT Successful")
94     #########################################################################
95     logger.info("\t\t2.5 Attachement of Interface to VM")
96     if (Sfc_obj.attachInterface() == 200):
97         logger.info("\t\t Interface attached to VM")
98     else:
99         status = "FAIL"
100         logger.error("\t\t  :   Interface NOT attached to VM")
101     #########################################################################
102     logger.info("\t\t2.6 Attachement of FLoating Ip to VM")
103     if (Sfc_obj.addFloatingIp() == 202):
104         logger.info("\t\t Floating Ip attached to VM SUccessful")
105     else:
106         status = "FAIL"
107         logger.error("\t\t  :   Floating Ip NOT attached to VM ")
108     print ("\n###########################################################\n")
109     ########################################################################
110     logger.info(
111         "TestCase 3 : Configure SFC [Portair,PortGroup,Flow classifer]")
112     #########################################################################
113     logger.info("\t3.1 Creation of Port Pair")
114     if (Sfc_obj.createPortPair() == 201):
115         logger.info("\t\tCreation of Port pair is successful")
116     else:
117         status = "FAIL"
118         logger.error("\t\t  :  Creation of Port pair is NOT successful")
119
120     #########################################################################
121     logger.info("\t3.2 Getting the  Port Pair ID")
122     if (Sfc_obj.getPortPair() == 200):
123         logger.info("\t\tSuccessfully got Port Pair ID")
124     else:
125         status = "FAIL"
126         logger.error("\t\t  :  UnSuccessfully got Port Pair ID")
127
128     #########################################################################
129     logger.info("\t3.3 Creation of Port Pair Group")
130     if (Sfc_obj.createPortGroup() == 201):
131         logger.info("\t\tPort Pair Group successfully Created")
132     else:
133         status = "FAIL"
134         logger.error("\t\t  :  Port Pair Group NOT successfully Created")
135
136     #########################################################################
137     logger.info("\t3.4 Getting Port Pair Group ID ")
138
139     if (Sfc_obj.getPortGroup() == 200):
140         logger.info("\t\tPort Pair Group ID successfully received")
141     else:
142         status = "FAIL"
143         logger.error("\t\t  :  Port Pair Group ID NOT successfully received")
144
145     #########################################################################
146     logger.info("\t3.5 Creation of Flow Classifier")
147     if (Sfc_obj.createFlowClassifier() == 201):
148         logger.info("\t\tFlow Classifier successfully Created")
149     else:
150         status = "FAIL"
151         logger.error("\t\t  :  Flow Classifier NOT successfully Created")
152     print ("\n###########################################################\n")
153     ########################################################################
154     logger.info(
155         "TestCase 4 : Configure Port Chain and verify flows are added")
156     #########################################################################
157     logger.info("\t4.1 Creation of PortChain")
158     if (Sfc_obj.createPortChain() == 201):
159         logger.info("\t\tPortChain successfully Created")
160     else:
161         status = "FAIL"
162         logger.error("\t\tPortChain NOT successfully Created")
163     print ("\n###########################################################\n")
164     #########################################################################
165     logger.info("\tTestCase 5 : Verify  traffic with VNF node.")
166     if (Sfc_obj.loginToVM() == "1"):
167         logger.info("\t\tSFC function Working")
168     else:
169         status = "FAIL"
170         logger.error("\t\t  :  SFC function not working")
171     print ("\n###########################################################\n")
172     #########################################################################
173     logger.info("TestCase 6 : Remove the Port Chain and Verify the traffic")
174     if (Sfc_obj.deletePortChain() == 204):
175         if (Sfc_obj.loginToVM() == "0"):
176             logger.info("\t\tSFC function is removed Successfully")
177         else:
178             status = "FAIL"
179             logger.error("\t\t:SFC function not Removed.Have some problem")
180         if (Sfc_obj.deleteFlowClassifier() == 204):
181             if (Sfc_obj.deletePortGroup() == 204):
182                 if (Sfc_obj.deletePortPair() == 204):
183                     logger.info(
184                         "\t\tSFC configuration is deleted successfully")
185                 else:
186                     status = "FAIL"
187                     logger.error("\t\t  :  Port pair configuration is NOT\
188                                   deleted successfully")
189             else:
190                 status = "FAIL"
191                 logger.error("\t\t  :  Port Group configuration is NOT \
192                              deleted successfully")
193         else:
194                 status = "FAIL"
195                 logger.error("\t\t  :  Flow classifier configuration is NOT \
196                              deleted successfully")
197     else:
198         status = "FAIL"
199         logger.error("\t\t:PortChain configuration is NOT deleted \
200                      successfully")
201     print ("\n###########################################################n")
202     #######################################################################
203     logger.info("Testcase 7 : Cleanup")
204     if (Sfc_obj.cleanup() == 204):
205         logger.info("\t\tCleanUp is successfull")
206     else:
207         status = "FAIL"
208         logger.error("\t\t  :  CleanUp is NOT successfull")
209     print ("###############################################################")
210     logger.info("Summary :")
211     try:
212         logger.debug("Push ONOS SFC results into DB")
213         stop_time = time.time()
214
215         # ONOS SFC success criteria = all tests OK
216         duration = round(stop_time - start_time, 1)
217         logger.info("Result is " + status)
218         functest_utils.push_results_to_db("functest",
219                                           "onos_sfc",
220                                           logger,
221                                           start_time,
222                                           stop_time,
223                                           status,
224                                           details={'timestart': start_time,
225                                                    'duration': duration,
226                                                    'status': status})
227     except:
228         logger.error("Error pushing results into Database")
229     print("############################END OF SCRIPT ######################")