Suite for TCPMD5 added, suite for PCEP expanded.
[integration/test.git] / test / csit / libraries / FlowLib.txt
1 *** Settings ***
2 Documentation     Keywords used to create/modify flow objects. The object is defined in the
3 ...               corresponding FlowLib.py library and contains pertinent fields and methods (e.g.,
4 ...               cookie and barrier fields, string formatted xml that can be used to push to
5 ...               controller)
6 Library           ./FlowLib.py
7 Library           XML
8
9 *** Variables ***
10
11 *** Keywords ***
12 Create Inventory Flow
13     [Documentation]    Calls FlowLib.Make_Inventory_Flow function and initializes and sanitizes
14     ...    the basic flow elements that can be given to flow:inventory
15     ${flow}=    Make Inventory Flow
16     [Return]    ${flow}
17
18 Create Service Flow
19     [Documentation]    Used for creating an object that will use an XML format that
20     ...    can be given to flow:service.
21     ${flow}=    Make Service Flow
22     [Return]    ${flow}
23
24 Set "${flow}" "${property}" With "${property_val}"
25     [Documentation]    Embedded variables to make higher level keywords more readable.
26     ...    There are some cases where the python attribute uses an underscore,
27     ...    but a hyphen needs to be used. This seems inconsistent, and may need
28     ...    to be looked at from the openflow plugin perspective.
29     ...
30     ...    At this point, this library will remove the element ${property} from the
31     ...    xml representation of the flow and reset with the given value. \ It's not
32     ...    possible, yet, to have multiple elements with the same name. \ That will
33     ...    likely be needed in the future.
34     ${property}    Run Keyword If    "table_id" != "${property}" and "cookie_mask" != "${property}"    Replace String    ${property}    _    -
35     ...    ELSE    Set Variable    ${property}
36     Remove Flow XML Element    ${flow}    ${property}
37     Add Flow XML Element    ${flow}    ${property}    ${property_val}
38     Set Flow Field    ${flow}    ${property}    ${property_val}
39     [Return]    ${flow}
40
41 Set Flow Action
42     [Arguments]    ${flow}    ${instruction_order}    ${action_order}    ${action}    ${action_val}=${EMPTY}
43     [Documentation]    Will remove the instruction element first, then add the proper xml structure
44     ...    to implement the action as given in the arguments
45     ##For the case that any of the instruction/apply-actions/action elements are not there we need to add them'
46     Remove Flow XML Element    ${flow}    instruction
47     Add Flow XML Element    ${flow}    instruction    ${EMPTY}    instructions
48     Add Flow XML Element    ${flow}    order    ${instruction_order}    instructions/instruction
49     Add Flow XML Element    ${flow}    apply-actions    ${EMPTY}    instructions/instruction
50     Add Flow XML Element    ${flow}    action    ${EMPTY}    instructions/instruction/apply-actions
51     Add Flow XML Element    ${flow}    order    ${action_order}    instructions/instruction/apply-actions/action
52     Add Flow XML Element    ${flow}    ${action}    ${action_val}    instructions/instruction/apply-actions/action
53     [Return]    ${flow}
54
55 Set Flow Output Action
56     [Arguments]    ${flow}    ${instruction_order}    ${action_order}    ${output_port}
57     Set Flow Action    ${flow}    ${instruction_order}    ${action_order}    output-action
58     Add Flow XML Element    ${flow}    output-node-connector    ${output_port}    instructions/instruction/apply-actions/action/output-action
59     [Return]    ${flow}
60
61 Set Flow Ethernet Match
62     [Arguments]    ${flow}    ${match_value_dict}
63     [Documentation]    Specific keyword for adding an ethernet match rules where the elements are given
64     ...    in key/value pairs inside the ${match_value_dict} argument. This keyword will also remove any
65     ...    existing ethernet-match elements from the flow before adding
66     Clear Flow Matches    ${flow}    match/ethernet-match
67     Add Flow XML Element    ${flow}    ethernet-match    ${EMPTY}    match
68     ${type}=    Get From Dictionary    ${match_value_dict}    type
69     Add Flow XML Element    ${flow}    ethernet-type    ${EMPTY}    match/ethernet-match
70     Add Flow XML Element    ${flow}    type    ${type}    match/ethernet-match/ethernet-type
71     ${src}=    Get From Dictionary    ${match_value_dict}    source
72     Add Flow XML Element    ${flow}    ethernet-source    ${EMPTY}    match/ethernet-match
73     Add Flow XML Element    ${flow}    address    ${src}    match/ethernet-match/ethernet-source
74     ${dst}=    Get From Dictionary    ${match_value_dict}    destination
75     Add Flow XML Element    ${flow}    ethernet-destination    ${EMPTY}    match/ethernet-match
76     Add Flow XML Element    ${flow}    address    ${dst}    match/ethernet-match/ethernet-destination
77     [Return]    ${flow}
78
79 Set Flow IPv4 Match
80     [Arguments]    ${flow}    ${match_value_dict}
81     [Documentation]    Specific keyword for adding an ipv4 match rules where the elements are given
82     ...    in key/value pairs inside the ${match_value_dict} argument. This keyword will also remove any
83     ...    existing ipv4 match elements from the flow before adding
84     Clear Flow Matches    ${flow}    match/ipv4-source
85     Clear Flow Matches    ${flow}    match/ipv4-destination
86     ${src}=    Get From Dictionary    ${match_value_dict}    source
87     Add Flow XML Element    ${flow}    ipv4-source    ${src}    match
88     ${dst}=    Get From Dictionary    ${match_value_dict}    destination
89     Add Flow XML Element    ${flow}    ipv4-destination    ${dst}    match
90     [Return]    ${flow}
91
92 Clear Flow Actions
93     [Arguments]    ${flow}
94     [Documentation]    Will clean out any existing flow actions in the given ${flow} object
95     Remove Flow XML Element    ${flow}    instructions/instruction
96     [Return]    ${flow}
97
98 Clear Flow Matches
99     [Arguments]    ${flow}    ${match_element}
100     [Documentation]    Will clean out any existing flow matches in the given ${flow} object
101     Remove Flow XML Element    ${flow}    match/${match_element}
102     [Return]    ${flow}
103
104 Set Flow XML Element Attribute
105     [Arguments]    ${flow}    ${element}    ${id}    ${value}
106     [Documentation]    Will set the given id/value pair to the given to the element provided
107     ...    and make the proper changes to the ${flow} object also provided.
108     ${flow_xml}=    Parse XML    ${flow.xml}
109     Set Element Attribute    ${flow_xml}    ${id}    ${value}    xpath=${element}
110     ${xml_string}=    Element To String    ${flow_xml}
111     Set Flow Field    ${flow}    xml    ${xml_string}
112     Log    ${flow.xml}
113     [Return]    ${flow}
114
115 Add Flow XML Element
116     [Arguments]    ${flow}    ${element}    ${element_val}=${EMPTY}    ${xpath}=.
117     [Documentation]    Will modify the current xml representation of the ${flow} object to contain
118     ...    the given ${element} at the given ${xpath}. If the ${element} uses a value, that can be
119     ...    passed eith the ${element_val} which defaults to ${EMPTY} if not used. NOTE: since there
120     ...    are two default parameters to this keyword, if you have an ${xpath} to use, but no ${element_val}
121     ...    you will still need to pass ${EMPTY} when invoking so that ${xpath} will end up at the right
122     ...    location in the parameter list
123     ${flow_xml}=    Parse XML    ${flow.xml}
124     Add Element    ${flow_xml}    <${element}>${element_val}</${element}>    xpath=${xpath}
125     ${xml_string}=    Element To String    ${flow_xml}
126     Set Flow Field    ${flow}    xml    ${xml_string}
127     Log    ${flow.xml}
128     [Return]    ${flow}
129
130 Remove Flow XML Element
131     [Arguments]    ${flow}    ${element_xpath}
132     [Documentation]    Removes the element at the given ${element_xpath} within the given ${flow}
133     ...    object. The ${flow} object's xml representation will be updated to reflect this removal.
134     ${flow_xml}=    Parse XML    ${flow.xml}
135     Run Keyword And Ignore Error    Remove Elements    ${flow_xml}    xpath=${element_xpath}
136     ${xml_string}=    Element To String    ${flow_xml}
137     Set Flow Field    ${flow}    xml    ${xml_string}
138     [Return]    ${flow}
139
140 Add Flow To Controller And Verify
141     [Arguments]    ${flow_body}    ${node_id}    ${table_id}    ${flow_id}
142     [Documentation]    Push flow through REST-API and verify in data-store
143     ${resp}    Put Xml    session    ${REST_CON}/node/${node_id}/table/${table_id}/flow/${flow_id}    data=${flow_body}
144     Log    ${resp.content}
145     Should Be Equal As Strings    ${resp.status_code}    200
146     ${resp}    RequestsLibrary.Get    session    ${REST_CON}/node/${node_id}/table/${table_id}/flow/${flow_id}    headers=${ACCEPT_XML}
147     Log    ${resp.content}
148     Should Be Equal As Strings    ${resp.status_code}    200
149     compare xml    ${flow_body}    ${resp.content}
150
151 Verify Flow On Mininet Switch
152     [Arguments]    ${flow_elements}
153     [Documentation]    Checking flow on switch
154     sleep    1
155     write    dpctl dump-flows -O OpenFlow13
156     ${switchoutput}    Read Until    >
157     : FOR    ${flowElement}    IN    @{flow_elements}
158     \    should Contain    ${switchoutput}    ${flowElement}
159
160 Remove Flow From Controller And Verify
161     [Arguments]    ${flow_body}    ${node_id}    ${table_id}    ${flow_id}
162     [Documentation]    Remove flow
163     ${resp}    RequestsLibrary.Delete    session    ${REST_CON}/node/${node_id}/table/${table_id}/flow/${flow_id}
164     Log    ${resp.content}
165     Should Be Equal As Strings    ${resp.status_code}    200
166     ${resp}    RequestsLibrary.Get    session    ${REST_CON}/node/${node_id}/table/${table_id}
167     Log    ${resp.content}
168     Should Not Contain    ${resp.content}    ${flow_id}
169
170 Verify Flow Does Not Exist On Mininet Switch
171     [Arguments]    ${flow_elements}
172     [Documentation]    Checking flow on switch is removed
173     sleep    1
174     write    dpctl dump-flows -O OpenFlow13
175     ${switchoutput}    Read Until    >
176     : FOR    ${flowElement}    IN    @{flow_elements}
177     \    should Not Contain    ${switchoutput}    ${flowElement}
178
179 Remove Default Flows
180     [Arguments]    ${node_id}
181     [Documentation]    Removes any flows considered "default". one such flow is
182     ...    to forward all traffic to the CONTROLLER with priority 0 at flow-table 0
183     ...    If/When others are implemented this keyword can be updated to include those.
184     ${flow}=    Make Service Flow
185     Set "${flow}" "priority" With "0"
186     Set "${flow}" "flow-table" With "0"
187     Add Flow XML Element    ${flow}    node    /inv:nodes/inv:node[inv:id="${node_id}"]
188     Set Flow XML Element Attribute    ${flow}    node    xmlns:inv    urn:opendaylight:inventory
189     Log    Flow XML is ${flow.xml}
190     write    dpctl dump-flows -O OpenFlow13
191     ${switchoutput}    Read Until    >
192     ${headers}=    Create Dictionary    Content-Type    application/yang.data+xml
193     ${resp}    RequestsLibrary.Post    session    restconf/operations/sal-flow:remove-flow    data=${flow.xml}    headers=${headers}
194     Log    ${resp.content}
195     Should Be Equal As Strings    ${resp.status_code}    200
196     ${resp}=    RequestsLibrary.Get    session    ${REST_OPR}
197     Log    ${resp.content}
198     Should Not Contain    ${resp.content}    "output-node-connector": "CONTROLLER",
199     ${strings_to_check_for}=    Create List    CONTROLLER
200     Verify Flow Does Not Exist On Mininet Switch    ${strings_to_check_for}