summaryrefslogtreecommitdiffstats
path: root/robot/resources/stack_validation/packet_generator_interface.robot
blob: 2a30ba2ad54a65bc0983b1a8b599cd5aaf9ea88a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
*** Settings ***
Documentation     The main interface for interacting with A&AI. It handles low level stuff like managing the http request library and A&AI required fields
Library         RequestsLibrary
Library           StringTemplater
Library           ONAPLibrary.Utilities
Library           OperatingSystem
Resource          ../global_properties.robot
Resource          ../json_templater.robot

*** Variables ***
${PGN_URL_TEMPLATE}     http://\${host}:\${port}
${PGN_PATH}    /restconf/config/sample-plugin:sample-plugin
${PGN_PATH_V2}    /restconf/config/stream-count:stream-count
${PGN_ENABLE_STREAM_TEMPLATE}    robot/assets/templates/vfw_pg_stream_enable.template
${PGN_ENABLE_STREAMS_TEMPLATE}    robot/assets/templates/vfw_pg_streams_enable.template
${PGN_ENABLE_STREAMS_V2_TEMPLATE}    robot/assets/templates/vfw_pg_streams_v2.template

*** Keywords ***
Connect To Packet Generator
    [Documentation]    Enables packet generator for the passed stream on the passed host
    [Arguments]    ${host}    ${alias}=pgn
    ${map}=  Create Dictionary     host=${host}    port=${GLOBAL_PACKET_GENERATOR_PORT}    path=${PGN_PATH}
    ${url}=    Template String    ${PGN_URL_TEMPLATE}    ${map}
    ${auth}=  Create List     ${GLOBAL_PACKET_GENERATOR_USERNAME}    ${GLOBAL_PACKET_GENERATOR_PASSWORD}
    ${session}=    Create Session   ${alias}  ${url}    auth=${auth}
    [Return]     ${session}

Enable Stream
    [Documentation]    Enable a single stream on the passed packet generator host IP
    [Arguments]    ${host}    ${stream}=udp1    ${alias}=pgn
    Connect To Packet Generator    ${host}    alias=${alias}
    ${headers}=  Create Headers
    ${data_path}=    Catenate    ${PGN_PATH}/pg-streams
    ${map}=    Create Dictionary    stream=${stream}
    ${streams}=   Fill JSON Template File    ${PGN_ENABLE_STREAM_TEMPLATE}    ${map}
    ${streams}=    evaluate    json.dumps(${streams})    json
    ${map}=    Create Dictionary    pgstreams=${streams}
    ${data}=   Fill JSON Template File    ${PGN_ENABLE_STREAMS_TEMPLATE}    ${map}
    ${resp}=  Put Request   ${alias}  ${data_path}     data=${data}     headers=${headers}
    Should Be Equal As Strings    ${resp.status_code}    200
    [Return]    ${resp}

Enable Streams
    [Documentation]    Enable <stream_count> number of streams on the passed packet generator host IP
    [Arguments]    ${host}    ${stream_count}=5    ${alias}=pgn    ${prefix}=fw_udp
    Connect To Packet Generator    ${host}    alias=${alias}
    ${headers}=  Create Headers
    ${data_path}=    Catenate    ${PGN_PATH}/pg-streams
    ${streams}=    Set Variable
    ${comma}=      Set Variable
    ${stream_count}=    Evaluate    ${stream_count}+1
    :FOR    ${i}    IN RANGE     1    ${stream_count}
    \    ${name}=    Catenate    ${prefix}${i}
    \    ${map}=    Create Dictionary    stream=${name}
    \    ${one}=   Fill JSON Template File    ${PGN_ENABLE_STREAM_TEMPLATE}    ${map}
    \    ${one}=    evaluate    json.dumps(${one})    json
    \    ${streams}=    Set Variable    ${streams}${comma}${one}
    \    ${comma}=      Set Variable    ,
    ${map}=    Create Dictionary    pgstreams=${streams}
    ${data}=   Fill JSON Template File    ${PGN_ENABLE_STREAMS_TEMPLATE}    ${map}
    ${resp}=  Put Request   ${alias}  ${data_path}     data=${data}     headers=${headers}
    Should Be Equal As Strings    ${resp.status_code}    200
    [Return]    ${resp}


Enable Streams V2
    [Documentation]    V2 is for new honeycomb steams interface
    ...  Enable <stream_count> number of streams on the passed packet generator host IP
    [Arguments]    ${host}    ${stream_count}=5    ${alias}=pgn    ${prefix}=fw_udp
    Connect To Packet Generator    ${host}    alias=${alias}
    ${headers}=  Create Headers
    ${data_path}=    Catenate    ${PGN_PATH_V2}/streams
    ${map}=    Create Dictionary    number_streams=${stream_count}
    ${data}=   Fill JSON Template File    ${PGN_ENABLE_STREAMS_V2_TEMPLATE}    ${map}
    ${resp}=  Put Request   ${alias}  ${data_path}     data=${data}     headers=${headers}
    Should Be Equal As Strings    ${resp.status_code}    200


Disable All Streams
    [Documentation]    Disable all streams on the passed packet generator host IP
    [Arguments]    ${host}    ${stream}=udp1    ${alias}=pgn
    Connect To Packet Generator    ${host}    alias=${alias}
    ${headers}=  Create Headers
    ${data_path}=    Catenate    ${PGN_PATH}/pg-streams
    ${data}=   Catenate    {"pg-streams":{"pg-stream": []}}
    ${resp}=  Put Request   ${alias}  ${data_path}     data=${data}     headers=${headers}
    Should Be Equal As Strings    ${resp.status_code}    200
    [Return]    ${resp}

 Disable Stream
    [Documentation]    Disables packet generator for the passed stream
    [Arguments]    ${host}    ${stream}=udp1    ${alias}=pgn
    ${session}=    Connect To Packet Generator    ${host}    alias=${alias}
    ${headers}=  Create Headers
    ${data_path}=    Catenate    ${PGN_PATH}/pg-streams/pg-stream/${stream}
    ${resp}=  Delete Request  ${alias}  ${data_path}     headers=${headers}
    Should Be Equal As Strings    ${resp.status_code}    200
    [Return]    ${resp}

Get List Of Enabled Streams
    [Documentation]     Get a list of streams on the passed packet generator host IP
    [Arguments]    ${host}    ${alias}=pgn
    ${session}=    Connect To Packet Generator    ${host}    alias=${alias}
    ${headers}=  Create Headers
    ${data_path}=    Catenate    /
    ${resp}=  Get Request   ${alias}  ${PGN_PATH}     headers=${headers}
    Should Be Equal As Strings    ${resp.status_code}    200
    [Return]    ${resp.json()}

Get List Of Enabled Streams V2
    [Documentation]     V2 Get a list of streams on the passed packet generator host IP
    [Arguments]    ${host}    ${alias}=pgn
    ${session}=    Connect To Packet Generator    ${host}    alias=${alias}
    ${headers}=  Create Headers
    ${data_path}=    Catenate    /
    ${resp}=  Get Request   ${alias}  ${PGN_PATH_V2}     headers=${headers}
    Should Be Equal As Strings    ${resp.status_code}    200
    [Return]    ${resp.json()}

Create Headers
    ${uuid}=    Generate UUID4
    ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
    [Return]    ${headers}