From 45d3f6e4b61d5a49f1ef64d9a2b976219769c840 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 24 Mar 2021 21:59:25 +0000 Subject: [PATCH] demo scripts --- demo/create-l2-tunnel.sh | 62 +++++++ demo/curl-0.sh | 353 +++++++++++++++++++++++++++++++++++++++ demo/curl-1.sh | 15 ++ demo/curl-2.sh | 10 ++ demo/demo-1.sh | 1 + demo/demo-2.sh | 18 ++ demo/sdxrest.py | 344 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 803 insertions(+) create mode 100644 demo/create-l2-tunnel.sh create mode 100644 demo/curl-0.sh create mode 100644 demo/curl-1.sh create mode 100644 demo/curl-2.sh create mode 100644 demo/demo-1.sh create mode 100644 demo/demo-2.sh create mode 100644 demo/sdxrest.py diff --git a/demo/create-l2-tunnel.sh b/demo/create-l2-tunnel.sh new file mode 100644 index 00000000..dee1deb4 --- /dev/null +++ b/demo/create-l2-tunnel.sh @@ -0,0 +1,62 @@ +#!/bin/bash + + +PWD=`pwd` +FILE="${PWD}/config_file.txt" + +MIN=1 +MAX=120 +DIFF=$(($MAX-$MIN+1)) +RANDOM=$$ +NUMARRAY20="" +NUMARRAY50="" +NUMARRAY100="" + +for i in `seq 1 25`; do + R=$(($(($RANDOM%$DIFF))+$MIN)) + NUM_ARRAY20[$i]=$R +done + +for i in `seq 1 75`; do + R=$(($(($RANDOM%$DIFF))+$MIN)) + NUM_ARRAY50[$i]=$R +done + +for i in `seq 1 120`; do + R=$(($(($RANDOM%$DIFF))+$MIN)) + NUM_ARRAY100[$i]=$R +done + +eval a20=($(printf "%q\n" "${NUM_ARRAY20[@]}" | sort -u)) +eval a50=($(printf "%q\n" "${NUM_ARRAY50[@]}" | sort -u)) +eval a100=($(printf "%q\n" "${NUM_ARRAY100[@]}" | sort -u)) + +echo "--- NUMBERS: ${a50[@]}" + +for i in ${a50[@]}; do +#for i in `seq 91 120`; do + +# echo "--- SEQ = $i" +# echo "--- DATE = `date`" + LINE=`cat ${FILE} | grep -w ^${i}` + echo $LINE + + SRC_SW=`echo $LINE | awk '{print $2}'` + DST_SW=`echo $LINE | awk '{print $3}'` + SRC_PORT=`echo $LINE | awk '{print $4}'` + DST_PORT=`echo $LINE | awk '{print $5}'` + SRC_VLAN=`echo $LINE | awk '{print $6}'` + DST_VLAN=`echo $LINE | awk '{print $7}'` + BW=`echo $LINE | awk '{print $8}'` + + printf -v data '{"L2Tunnel":{"starttime":"2019-02-14T12:00:00","endtime":"2019-02-20T23:59:00","srcswitch":"%s","dstswitch":"%s","srcport":12,"dstport":12,"srcvlan":%i,"dstvlan":%i,"bandwidth":%i}}' ${SRC_SW} ${DST_SW} ${SRC_VLAN} ${DST_VLAN} ${BW} + +# echo "--- DATA: $data" + curl -s -X POST http://127.0.0.1:5000/api/v1/policies/type/L2Tunnel -b aw1.cookie -H "Content-Type: application/json" -d "$data" +# echo " " +# echo " " +# echo " " +# echo " " +# echo " " + +done diff --git a/demo/curl-0.sh b/demo/curl-0.sh new file mode 100644 index 00000000..c4485455 --- /dev/null +++ b/demo/curl-0.sh @@ -0,0 +1,353 @@ +#!/bin/bash + + +TEMP_FILE=/tmp/trap.txt +SDX_CONTROLLER_LOCAL="0" + + +function clean_up { + + echo "--- ERROR" > $TEMP_FILE 2>&1 + exit +} + +trap clean_up SIGHUP SIGINT SIGTERM + + +usage(){ + echo -e " Usage: $0 [-s ] [-b ] [-v ] [-c ] [-t ] [-p ] [-l ] [-o ] [-i ] [-j ] [-n netns] [-r resource] [-e eline_connection] [-h]" + echo -e "\t -s [renci|uc_1|uc_2|tacc]" + echo -e "\t -h: Usage" + echo +} + + +title(){ + echo "" + echo "============================================================================== " + echo "--- $1" + echo "============================================================================== " +} + + +function get1 +{ + URL=$1 + curl -s -k -H "Accept: application/json" --request GET ${URL} | python -m json.tool | jq '.' +} + +function get2 +{ + URL=$1 + COOKIE=$2 + curl -s -k -b ${COOKIE} -H "Accept: application/json" --request GET ${URL} | python -m json.tool | jq '.' +} + +function post1 +{ + URL=$1 + JSON=$2 + COOKIE=$3 + curl -k -b ${COOKIE}\ + -H "Content-Type:application/json" \ + -X POST ${URL} \ + -d ${JSON} | python -m json.tool | jq '.' + + +} + + +get(){ + HEADER="Accept: application/json" + URL=$1 + QUERY=$2 + if [[ -n ${QUERY} && ${QUERY} -eq 1 ]]; then + URL="${URL}?list=true" + curl -k -H ${HEADER} -X GET ${URL} | python -m json.tool | jq '.' + else + curl -k -H ${HEADER} -X GET ${URL} | python -m json.tool | jq '.' + fi +} + + +delete() +{ + URL=$1 + JSON=$2 + curl -k \ + -H "Content-Type:application/json" \ + -X DELETE ${URL} +} + + +generate_post_data_endpointconnection(){ + DEADLINE=$1 + SRCENDPOINT=$2 + DSTENDPOINT=$3 + DATAQUANTITY=$4 + cat << EOF +{ 'EndpointConnection': { 'deadline':'${DEADLINE}', 'srcendpoint':'${SRCENDPOINT}', 'dstendpoint':'${DSTENDPOINT}', 'dataquantity':${DATAQUANTITY} } } +EOF +} + + +generate_post_data_l2multipoint(){ + STARTTIME=$1 + ENDTIME=$2 + BANDWIDTH=$3 + ENDPOINT1=$4 + ENDPOINT2=$5 + ENDPOINT3=$6 + + IFS=':' read -ra E1 <<< "$ENDPOINT1" + IFS=':' read -ra E2 <<< "$ENDPOINT2" + IFS=':' read -ra E3 <<< "$ENDPOINT3" + + cat << EOF +{'L2Tunnel':{"starttime":"${STARTTIME}", "endtime":"${ENDTIME}", "endpoints":[ { "switch":"${E1[0]}", "port":"${E1[1]}", "vlan":"${E1[2]}" }, { "switch":"${E2[0]}", "port":"${E2[1]}", "vlan":"${E2[2]}" }, { "switch":"${E3[0]}", "port":"${E3[1]}", "vlan":"${E3[2]}" } ], "bandwidth":"${BANDWIDTH}"}} +EOF +} + + + +generate_post_data_l2tunnel(){ + STARTTIME=$1 + ENDTIME=$2 + BANDWIDTH=$3 + ENDPOINT1=$4 + ENDPOINT2=$5 + + IFS=':' read -ra E1 <<< "$ENDPOINT1" + IFS=':' read -ra E2 <<< "$ENDPOINT2" + + cat << EOF +{ + "L2Tunnel":{ + "starttime":"${STARTTIME}", + "endtime":"${ENDTIME}", + "srcswitch":"${E1[0]}", + "dstswitch":"${E2[0]}", + "srcport":${E1[1]}, + "dstport":${E2[1]}, + "srcvlan":${E1[2]}, + "dstvlan":${E2[2]}, + "bandwidth":${BANDWIDTH} + } +} +EOF +} + + +while getopts "o:c:t:s:d:q:1:2:3:a:b:w:L:S:P:N:U:Xh" opt; do + case $opt in + o) + OPERATION=$OPTARG + ;; + c) + COOKIE=$OPTARG + ;; + t) + DEADLINE=$OPTARG + ;; + s) + SRCENDPOINT=$OPTARG + ;; + d) + DSTENDPOINT=$OPTARG + ;; + q) + DATAQUANTITY=$OPTARG + ;; + 1) + ENDPOINT1=$OPTARG + ;; + 2) + ENDPOINT2=$OPTARG + ;; + 3) + ENDPOINT3=$OPTARG + ;; + a) + STARTTIME=$OPTARG + ;; + b) + ENDTIME=$OPTARG + ;; + w) + BANDWIDTH=$OPTARG + ;; + L) + LC=$OPTARG + ;; + S) + SWITCH=$OPTARG + ;; + P) + PORT=$OPTARG + ;; + N) + POLICYNUMBER=$OPTARG + ;; + U) + URL_INFO=$OPTARG + ;; + X) + SDX_CONTROLLER_LOCAL="1" + ;; + h) + usage + clean_up + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + usage + clean_up + ;; + :) + echo "Option -$OPTARG requires an argument." >&2 + usage + clean_up + ;; + esac +done + + +HEADER="Accept: application/json" + +endpoint='api/v1' + +ep_localcontrollers="${endpoint}/localcontrollers" # Local Controllers +ep_users="${endpoint}/users" # Users +ep_policies="${endpoint}/policies" # Policies + + +ep_policies_endpointconnection="${ep_policies}/type/EndpointConnection" +ep_policies_l2multipoint="${ep_policies}/type/L2Multipoint" +ep_policies_l2tunnel="${ep_policies}/type/L2Tunnel" + +ep_localcontrollers_lc="${ep_localcontrollers}/${LC}" +ep_localcontrollers_lc_internalconfig="${ep_localcontrollers_lc}/internalconfig" +ep_localcontrollers_lc_switches="${ep_localcontrollers_lc}/switches" +ep_localcontrollers_lc_switch_x="${ep_localcontrollers_lc_switches}/${SWITCH}" +ep_localcontrollers_lc_switch_ports="${ep_localcontrollers_lc_switch_x}/ports" +ep_localcontrollers_lc_switch_port_x="${ep_localcontrollers_lc_switch_ports}/${PORT}" + +ep_policies_type="${ep_policies}/type" +ep_policies_x="${ep_policies}/number/${POLICYNUMBER}" + + + + + +protocol_http="http://" +sdx_controller_ip="192.168.201.156" +sdx_controller_dns="atlanticwave-sdx-controller.renci.ben" +sdx_controller_localhost="127.0.0.1" + + + +sdx_controller_port="5000" +if [ ${SDX_CONTROLLER_LOCAL} == "1" ]; then + sdx_controller="${protocol_http}${sdx_controller_localhost}:${sdx_controller_port}" +else + sdx_controller="${protocol_http}${sdx_controller_dns}:${sdx_controller_port}" +fi + + +URL_ENDPOINTCONNECTION="${sdx_controller}/${ep_policies_endpointconnection}" +URL_L2MULTIPOINT="${sdx_controller}/${ep_policies_l2multipoint}" +URL_L2TUNNEL="${sdx_controller}/${ep_policies_l2tunnel}" + +URL_ALL_LC="${sdx_controller}/${ep_localcontrollers}" +URL_LC="${sdx_controller}/${ep_localcontrollers_lc}" +URL_LC_INTERNALCONFIG="${sdx_controller}/${ep_localcontrollers_lc_internalconfig}" +URL_LC_SWITCHES="${sdx_controller}/${ep_localcontrollers_lc_switches}" +URL_LC_SWITCH="${sdx_controller}/${ep_localcontrollers_lc_switch_x}" +URL_LC_SWITCH_PORTS="${sdx_controller}/${ep_localcontrollers_lc_switch_ports}" +URL_LC_SWITCH_PORT="${sdx_controller}/${ep_localcontrollers_lc_switch_port_x}" + +URL_POLICIES="${sdx_controller}/${ep_policies}" +URL_POLICY_TYPE="${sdx_controller}/${ep_policies_type}" +URL_POLICY_X="${sdx_controller}/${ep_policies_x}" + + + +case ${OPERATION} in + get_localcontrollers) + title "Get all bridge information - ${URL_ALL_LC}" + get1 ${URL_ALL_LC} + ;; + + get_lc) + title "Get LC - ${URL_LC}" + get1 ${URL_LC} + ;; + + get_lc_internalconfig) + title "Get LC - ${URL_LC_INTERNALCONFIG}" + get2 ${URL_LC_INTERNALCONFIG} ${COOKIE} + ;; + + get_lc_switches) + title "Get LC - ${URL_LC_SWITCHES}" + get2 ${URL_LC_SWITCHES} ${COOKIE} + ;; + get_lc_switch) + title "Get LC - ${URL_LC_SWITCH}" + get2 ${URL_LC_SWITCH} ${COOKIE} + ;; + get_lc_switch_ports) + title "Get LC - ${URL_LC_SWITCH_PORTS}" + get2 ${URL_LC_SWITCH_PORTS} ${COOKIE} + ;; + + get_lc_switch_port) + title "Get LC - ${URL_LC_SWITCH_PORT}" + get2 ${URL_LC_SWITCH_PORT} ${COOKIE} + ;; + get_policies) + title "Get POLICY - ${URL_POLICIES}" + get2 ${URL_POLICIES} ${COOKIE} + ;; + + get_policy_type) + title "Get POLICY - ${URL_POLICY_TYPE}" + get2 ${URL_POLICY_TYPE} ${COOKIE} + ;; + get_policy) + title "Get POLICY - ${URL_POLICY_X}" + get2 ${URL_POLICY_X} ${COOKIE} + ;; + get_info) + title "Get INFO - ${URL_INFO} " + get2 ${URL_INFO} ${COOKIE} + ;; + + create_endpointconnection) + title "ENDPOINTCONNECTION Create => Deadline: ${DEADLINE} - Srcendpoint: ${SRCENDPOINT} - Dstendpoint: ${DSTENDPOINT} - Dataquantity: ${DATAQUANTITY}" + DATA=$(generate_post_data_endpointconnection ${DEADLINE} ${SRCENDPOINT} ${DSTENDPOINT} ${DATAQUANTITY}) + echo -e "--- DATA: \n${DATA}" + curl -k -s \ + -b ${COOKIE} \ + -H "Content-Type: application/json"\ + -X POST ${URL_ENDPOINTCONNECTION} \ + -d "$( generate_post_data_endpointconnection ${DEADLINE} ${SRCENDPOINT} ${DSTENDPOINT} ${DATAQUANTITY} )" | python -m json.tool | jq '.' + ;; + create_l2tunnel) + title "L2TUNNEL Create => STARTIME: ${STARTTIME} - ENDTIME: ${ENDTIME} - BW: ${BANDWIDTH} - EP1: ${ENDPOINT1} - EP2: ${ENDPOINT2}" + DATA=$(generate_post_data_l2tunnel ${STARTTIME} ${ENDTIME} ${BANDWIDTH} ${ENDPOINT1} ${ENDPOINT2}) + echo -e "--- DATA: \n${DATA}" + curl -k -s \ + -b ${COOKIE} \ + -H "Content-Type: application/json"\ + -X POST ${URL_ENDPOINTCONNECTION} \ + -d "$( generate_post_data_l2tunnel ${STARTTIME} ${ENDTIME} ${BANDWIDTH} ${ENDPOINT1} ${ENDPOINT2} )" | python -m json.tool | jq '.' + ;; + + create_ep1) + JSON="'{\"EndpointConnection\":{\"deadline\":\"2018-21-12T23:59:59\",\"srcendpoint\":\"rencidtn\",\"dstendpoint\":\"dukedtn\",\"dataquantity\":800000000}}'" + title "${JSON}" + post1 ${URL_ENDPOINTCONNECTION} ${JSON} ${COOKIE} + ;; +esac + diff --git a/demo/curl-1.sh b/demo/curl-1.sh new file mode 100644 index 00000000..f8fe491b --- /dev/null +++ b/demo/curl-1.sh @@ -0,0 +1,15 @@ +curl \ +--header "Accept: application/json" \ +--request GET \ +"http://192.168.201.156:5000/api/v1/localcontrollers" +#"http://129.114.108.195:5000/api/v1/localcontrollers" + +curl \ +--header "Accept: application/json" \ +--request GET \ +"http://192.168.201.156:5000/api/v1/localcontrollers/ncsuctlr/switches/ncsus1" + +curl \ +--header "Accept: application/json" \ +--request GET \ +"http://192.168.201.156:5000/api/v1/users" diff --git a/demo/curl-2.sh b/demo/curl-2.sh new file mode 100644 index 00000000..05a32b77 --- /dev/null +++ b/demo/curl-2.sh @@ -0,0 +1,10 @@ +JSON="'{\"dstendpoint\":\"rencidtn\",\"srcendpoint\":\"uncdtn\",\"dataquantity\":1000000000,\"deadline\":\"2018-12-24T23:59:00\"}'" + +#(u'6', {'EndpointConnection': {'dstendpoint': u'rencidtn', 'srcendpoint': u'rencibm4', 'dataquantity': 1000000000, 'deadline': u'2018-12-24T23:59:00'}}, 'EndpointConnection', 'ACTIVE RULE', u'mcevik', ['rencictlr:VlanTunnelLCRule: switch 205, 6:4:23:1425:1:True:20662', 'rencictlr:VlanTunnelLCRule: switch 201, 6:12:23:1421:1:True:20662']) + + +curl \ +--header "Accept: application/json" \ +--request POST \ +-d ${JSON} \ +"http://192.168.201.156:5000/api/v1/policies/type/EndpointConnection" diff --git a/demo/demo-1.sh b/demo/demo-1.sh new file mode 100644 index 00000000..33c40327 --- /dev/null +++ b/demo/demo-1.sh @@ -0,0 +1 @@ +./l2tunnel-create.sh ncsus1 uncs1 1541 1531 diff --git a/demo/demo-2.sh b/demo/demo-2.sh new file mode 100644 index 00000000..24b51df7 --- /dev/null +++ b/demo/demo-2.sh @@ -0,0 +1,18 @@ +curl \ +-X POST http://atlanticwave-sdx-controller.renci.ben:5000/api/v1/policies/type/L2Multipoint \ +-b cookie-mcevik.txt \ +-H "Content-Type: application/json" \ +--data-binary @- <