3 # Copyright (c) CREATED5 All rights reserved
4 # This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # ###########################################################################
12 # **** Scripted by Antony Silvester - antony.silvester@huawei.com ******
13 # ###########################################################################
15 # Testcase 1 : Prerequisites configuration for SFC
16 # Testcase 2 : Creation of 3 VNF Nodes and Attaching Ports
17 # Testcase 3 : Configure SFC [Port pair,Port Group ,Flow classifer
18 # Testcase 4 : Configure Port Chain and verify the flows are added.
19 # Testcase 5 : Verify traffic with VNF node.
20 # Testcase 6 : Remove the Port Chain and Verify the traffic.
21 # Testcase 7 : Cleanup
22 # ###########################################################################
24 """Script to Test the SFC scenarios in ONOS."""
28 import functest.utils.functest_utils as ft_utils
29 from sfc_onos import SfcOnos
31 logger = logging.getLogger(__name__)
39 start_time = time.time()
43 logger.info("Testcase 1 : Prerequisites configuration for SFC")
44 logger.info("1.1 Creation of Auth-Token")
45 check(Sfc_obj.getToken, OK, "Creation of Token")
46 logger.info("1.2 Creation of Network")
47 check(Sfc_obj.createNetworks, CREATED, "Creation of network")
48 logger.info("1.3 Creation of Subnetwork")
49 check(Sfc_obj.createSubnets, CREATED, "Creation of Subnetwork")
53 logger.info("Testcase 2 : Creation of 3 VNF Nodes and Attaching Ports")
54 logger.info("2.1 Creation of Ports")
55 check(Sfc_obj.createPorts, CREATED, "Creation of Port")
56 logger.info("2.2 Creation of VM-Compute-Node")
57 check(Sfc_obj.createVm, ACCEPTED, "Creation of VM")
58 logger.info("2.3 Check VM Status")
59 check(Sfc_obj.checkVmState, OK, "Vm statue check")
60 logger.info("2.4 Router Creation")
61 check(Sfc_obj.createRouter, CREATED, "Creation of Router")
62 logger.info("2.5 Attachement of Interface to VM")
63 check(Sfc_obj.attachInterface, OK, "Interface attached to VM")
64 logger.info("2.6 Attachement of FLoating Ip to VM")
65 check(Sfc_obj.addFloatingIp, ACCEPTED, "Floating Ip attached to VM")
70 "Testcase 3 : Configure SFC [Portair,PortGroup,Flow classifer]")
71 logger.info("3.1 Creation of Port Pair")
72 check(Sfc_obj.createPortPair, CREATED, "Creation of Port Pair")
73 logger.info("3.2 Getting the Port Pair ID")
74 check(Sfc_obj.getPortPair, OK, "Getting Port Pair ID")
75 logger.info("3.3 Creation of Port Pair Group")
76 check(Sfc_obj.createPortGroup, CREATED, "Creation of Port Pair Group")
77 logger.info("3.4 Getting Port Pair Group ID ")
78 check(Sfc_obj.getPortGroup, OK, "Getting Port Pair Group ID")
79 logger.info("3.5 Creation of Flow Classifier")
80 check(Sfc_obj.createFlowClassifier, CREATED, "Creation of Flow Classifier")
82 "Testcase 4 : Configure Port Chain and verify flows are added")
83 logger.info("4.1 Creation of Port Chain")
84 check(Sfc_obj.createPortChain, CREATED, "Creation of Port Chain")
87 def VerifySfcTraffic():
89 logger.info("Testcase 5 : Verify traffic with VNF node.")
90 if (Sfc_obj.loginToVM() == "1"):
91 logger.info("SFC function Working")
93 logger.error("SFC function not working")
96 logger.info("Testcase 6 : Remove the Port Chain and Verify the traffic")
97 if (Sfc_obj.deletePortChain() == NO_CONTENT):
98 if (Sfc_obj.loginToVM() == "0"):
99 logger.info("SFC function is removed Successfully")
101 logger.error("SFC function not Removed. Have some problem")
103 if (Sfc_obj.deleteFlowClassifier() == NO_CONTENT):
104 if (Sfc_obj.deletePortGroup() == NO_CONTENT):
105 if (Sfc_obj.deletePortPair() == NO_CONTENT):
107 "SFC configuration is deleted successfully")
109 logger.error("Port pair is deleted successfully")
112 logger.error("Port Group is NOT deleted successfully")
115 logger.error("Flow classifier is NOT deleted successfully")
118 logger.error("PortChain configuration is NOT deleted successfully")
120 if (status == "FAIL"):
121 fail("Traffic for SFC is NOT verified successfully")
125 logger.info("Testcase 7 : Cleanup")
126 if (Sfc_obj.cleanup() == NO_CONTENT):
127 logger.info("CleanUp is successfull")
129 logger.error("CleanUp is NOT successfull")
132 def check(method, criteria, msg):
133 if (method() == criteria):
134 logger.info(msg + 'is Successful')
136 fail(msg + 'is not successful')
140 logger.error(fail_info)
142 PushDB("FAIL", fail_info)
146 def PushDB(status, info):
147 logger.info("Summary :")
149 logger.debug("Push ONOS SFC results into DB")
150 stop_time = time.time()
152 # ONOS SFC success criteria = all tests OK
153 duration = round(stop_time - start_time, 1)
154 logger.info("Result is " + status)
155 ft_utils.push_results_to_db("functest",
160 details={'duration': duration,
163 logger.error("Error pushing results into Database")
167 """Script to Test the SFC scenarios in ONOS."""
176 if __name__ == '__main__':
177 logging.basicConfig()