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