1 """Script to Test the SFC scenarios in ONOS."""
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
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # ###########################################################################
13 # **** Scripted by Antony Silvester - antony.silvester@huawei.com ******
14 # ###########################################################################
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 # ###########################################################################
26 import functest.utils.functest_logger as ft_logger
27 import functest.utils.functest_utils as functest_utils
29 from Sfc_fun import Sfc_fun
33 """Script to Test the SFC scenarios in ONOS."""
34 logger = ft_logger.Logger("sfc").getLogger()
36 start_time = time.time()
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")
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")
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")
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")
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")
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")
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")
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")
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")
107 logger.error("\t\t : Floating Ip NOT attached to VM ")
108 print ("\n###########################################################\n")
109 ########################################################################
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")
118 logger.error("\t\t : Creation of Port pair is NOT successful")
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")
126 logger.error("\t\t : UnSuccessfully got Port Pair ID")
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")
134 logger.error("\t\t : Port Pair Group NOT successfully Created")
136 #########################################################################
137 logger.info("\t3.4 Getting Port Pair Group ID ")
139 if (Sfc_obj.getPortGroup() == 200):
140 logger.info("\t\tPort Pair Group ID successfully received")
143 logger.error("\t\t : Port Pair Group ID NOT successfully received")
145 #########################################################################
146 logger.info("\t3.5 Creation of Flow Classifier")
147 if (Sfc_obj.createFlowClassifier() == 201):
148 logger.info("\t\tFlow Classifier successfully Created")
151 logger.error("\t\t : Flow Classifier NOT successfully Created")
152 print ("\n###########################################################\n")
153 ########################################################################
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")
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")
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")
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):
184 "\t\tSFC configuration is deleted successfully")
187 logger.error("\t\t : Port pair configuration is NOT\
188 deleted successfully")
191 logger.error("\t\t : Port Group configuration is NOT \
192 deleted successfully")
195 logger.error("\t\t : Flow classifier configuration is NOT \
196 deleted successfully")
199 logger.error("\t\t:PortChain configuration is NOT deleted \
201 print ("\n###########################################################n")
202 #######################################################################
203 logger.info("Testcase 7 : Cleanup")
204 if (Sfc_obj.cleanup() == 204):
205 logger.info("\t\tCleanUp is successfull")
208 logger.error("\t\t : CleanUp is NOT successfull")
209 print ("###############################################################")
210 logger.info("Summary :")
212 logger.debug("Push ONOS SFC results into DB")
213 stop_time = time.time()
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",
224 details={'timestart': start_time,
225 'duration': duration,
228 logger.error("Error pushing results into Database")
234 print("############################END OF SCRIPT ######################")