Migrate 030_bgp_functional_evpn.robot
[integration/test.git] / csit / libraries / FlowLib.py
1 """
2 Library for dynamic flow construction.
3 Authors: james.luhrsen@hp.com
4 Updated: 2014-08-29
5 """
6 """
7 xmltodict and json libs not needed at this point, but may be useful in
8 the future.
9 """
10
11 # bare bones xml for building a flow xml for flow:inventory
12 flow_xml_skeleton = (
13     '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'
14     + '<flow xmlns="urn:opendaylight:flow:inventory">'
15     + "<instructions></instructions>"
16     + "<match></match>"
17     + "</flow>"
18 )
19
20 input_xml_skeleton = (
21     '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'
22     + '<input xmlns="urn:opendaylight:flow:service">'
23     + "</input>"
24 )
25
26
27 class Flow:
28     """
29     Flow class for creating and interacting with OpenFlow flows
30     """
31
32     strict = "false"
33     instruction_xmls = ""
34     match_xmls = ""
35     cookie = 0
36     cookie_mask = 0
37     table_id = 0
38     id = 1
39     hard_timeout = 60
40     idle_timeout = 30
41     flow_name = "No Name"
42     priority = 0
43     barrier = "false"
44
45     xml = ""
46
47     json = ""
48
49     def set_field(self, field, value):
50         """
51         allows for generically setting any attribute in this
52         class based on the 'field' passed in.  In the future,
53         adding a new attribute only requires that single line
54         addition.  no need for additional setter.
55         """
56         setattr(self, field, value)
57
58
59 def Make_Inventory_Flow():
60     """
61     Robot Keyword to create and return an instance of the Flow
62     class.
63     """
64     flow = Flow()
65     flow.xml = flow_xml_skeleton
66     return flow
67
68
69 def Make_Service_Flow():
70     """
71     Robot Keyword to create an input XML that can be used to
72     directly send to flow:service for things like accessing
73     the remove-flow RPC via restconf
74     """
75     flow = Flow()
76     flow.xml = input_xml_skeleton
77     return flow
78
79
80 def Set_Flow_Field(flow, field, value):
81     """
82     Robot Keyword to allow the modification (setting) of the
83     flow object attributes
84     """
85     flow.set_field(field, value)
86     return flow
87
88
89 # def Convert_Flow_XML_To_Json(flow):
90 #    '''
91 #       There may be a need in the future to use json to push
92 #       flows, as opposed to xml format that is prevalent in
93 #       test code at this point.  This function will give a
94 #       conversion, but unsure if it's proper.  Also, unsure
95 #       if the xmltodict library is viable in the CSIT environment
96 #    '''
97 #    flowXmlDict = xmltodict.parse(flow.xml)
98 #    flow.json = json.dumps(flowXmlDict)
99 #    return flow