#!/bin/bash # # Script example for many flows testing # # Number of simultaneous flows limited by variable $FLOWS # and number of packets per flow controlled by variable $FLOWLEN # global basedir := $[dirname $0] source $(basedir)/functions.sh root_check_run_with_sudo @Argv # Parameter parsing via include source $(basedir)/parameters.sh # Set some default params, if they didn't get set test -z $DEST_IP && global DEST_IP := '"198.18.0.42'" test -z $DST_MAC && global DST_MAC := '"90:e2:ba:ff:ff:ff'" test -z $CLONE_SKB && global CLONE_SKB := '"0'" # NOTICE: Script specific settings # ======= # Limiting the number of concurrent flows ($FLOWS) # and also set how many packets each flow contains ($FLOWLEN) # test -z $FLOWS && global FLOWS := '"8000'" test -z $FLOWLEN && global FLOWLEN := '"10'" # Base Config global DELAY := '"0'" # Zero means max speed global COUNT := '"0'" # Zero means indefinitely if [[ -n "$BURST" ]] { err 1 "Bursting not supported for this mode" } # General cleanup everything since last run pg_ctrl "reset" # Threads are specified with parameter -t value in $THREADS for ((thread = 0; thread < $THREADS; thread++)); do dev=${DEV}@${thread} # Add remove all other devices and add_device $dev to thread pg_thread $thread "rem_device_all" pg_thread $thread "add_device" $dev # Base config pg_set $dev "flag QUEUE_MAP_CPU" pg_set $dev "count $COUNT" pg_set $dev "clone_skb $CLONE_SKB" pg_set $dev "pkt_size $PKT_SIZE" pg_set $dev "delay $DELAY" pg_set $dev "flag NO_TIMESTAMP" # Single destination pg_set $dev "dst_mac $DST_MAC" pg_set $dev "dst $DEST_IP" # Randomize source IP-addresses pg_set $dev "flag IPSRC_RND" pg_set $dev "src_min 198.18.0.0" pg_set $dev "src_max 198.19.255.255" # Limit number of flows (max 65535) pg_set $dev "flows $FLOWS" # # How many packets a flow will send, before flow "entry" is # re-generated/setup. pg_set $dev "flowlen $FLOWLEN" # # Flag FLOW_SEQ will cause $FLOWLEN packets from the same flow # being send back-to-back, before next flow is selected # incrementally. This helps lookup caches, and is more realistic. # pg_set $dev "flag FLOW_SEQ" done # Run if user hits control-c proc print_result { # Print results for ((thread = 0; thread < $THREADS; thread++)); do dev=${DEV}@${thread} echo "Device: $dev" cat /proc/net/pktgen/$dev | grep -A2 "Result:" done } # trap keyboard interrupt (Ctrl-C) trap true SIGINT echo "Running... ctrl^C to stop" > !2 pg_ctrl "start" print_result (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:basedir) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(dirname)} {($ VSub_Number "$0")})]) left_token: spids: [22 26] ) } spids: [21] ) ] spids: [21] ) (C {(source)} {(${ VSub_Name basedir) (/functions.sh)}) (C {(root_check_run_with_sudo)} {(DQ ($ VSub_At "$@"))}) (C {(source)} {(${ VSub_Name basedir) (/parameters.sh)}) (AndOr children: [ (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$DEST_IP"))} {(Lit_Other "]")}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:DEST_IP) op: Equal rhs: {(DQ (198.18.0.42))} spids: [67] ) ] spids: [67] ) ] op_id: Op_DAmp ) (AndOr children: [ (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$DST_MAC"))} {(Lit_Other "]")}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:DST_MAC) op: Equal rhs: {(DQ ("90:e2:ba:ff:ff:ff"))} spids: [84] ) ] spids: [84] ) ] op_id: Op_DAmp ) (AndOr children: [ (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$CLONE_SKB"))} {(Lit_Other "]")}) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:CLONE_SKB) op:Equal rhs:{(DQ (0))} spids:[101])] spids: [101] ) ] op_id: Op_DAmp ) (AndOr children: [ (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$FLOWS"))} {(Lit_Other "]")}) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:FLOWS) op:Equal rhs:{(DQ (8000))} spids:[134])] spids: [134] ) ] op_id: Op_DAmp ) (AndOr children: [ (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$FLOWLEN"))} {(Lit_Other "]")}) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:FLOWLEN) op:Equal rhs:{(DQ (10))} spids:[151])] spids: [151] ) ] op_id: Op_DAmp ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:DELAY) op:Equal rhs:{(DQ (0))} spids:[160])] spids: [160] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:COUNT) op:Equal rhs:{(DQ (0))} spids:[168])] spids: [168] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr:(BoolUnary op_id:BoolUnary_n child:{(DQ ($ VSub_Name "$BURST"))})) terminator: ) ] action: [(C {(err)} {(1)} {(DQ ("Bursting not supported for this mode"))})] spids: [-1 190] ) ] spids: [-1 201] ) (C {(pg_ctrl)} {(DQ (reset))}) (ForExpr init: (BinaryAssign op_id: Arith_Equal left: (LhsName name:thread) right: (ArithWord w:{(Lit_Digits 0)}) ) cond: (ArithBinary op_id: Arith_Less left: (ArithVarRef name:thread) right: (ArithWord w:{($ VSub_Name "$THREADS")}) ) update: (UnaryAssign op_id:Node_PostDPlus child:(LhsName name:thread)) body: (DoGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:dev) op: Equal rhs: {(${ VSub_Name DEV) (Lit_Other "@") (${ VSub_Name thread)} spids: [243] ) ] spids: [243] ) (C {(pg_thread)} {($ VSub_Name "$thread")} {(DQ (rem_device_all))}) (C {(pg_thread)} {($ VSub_Name "$thread")} {(DQ (add_device))} {($ VSub_Name "$dev")}) (C {(pg_set)} {($ VSub_Name "$dev")} {(DQ ("flag QUEUE_MAP_CPU"))}) (C {(pg_set)} {($ VSub_Name "$dev")} {(DQ ("count ") ($ VSub_Name "$COUNT"))}) (C {(pg_set)} {($ VSub_Name "$dev")} {(DQ ("clone_skb ") ($ VSub_Name "$CLONE_SKB"))}) (C {(pg_set)} {($ VSub_Name "$dev")} {(DQ ("pkt_size ") ($ VSub_Name "$PKT_SIZE"))}) (C {(pg_set)} {($ VSub_Name "$dev")} {(DQ ("delay ") ($ VSub_Name "$DELAY"))}) (C {(pg_set)} {($ VSub_Name "$dev")} {(DQ ("flag NO_TIMESTAMP"))}) (C {(pg_set)} {($ VSub_Name "$dev")} {(DQ ("dst_mac ") ($ VSub_Name "$DST_MAC"))}) (C {(pg_set)} {($ VSub_Name "$dev")} {(DQ ("dst ") ($ VSub_Name "$DEST_IP"))}) (C {(pg_set)} {($ VSub_Name "$dev")} {(DQ ("flag IPSRC_RND"))}) (C {(pg_set)} {($ VSub_Name "$dev")} {(DQ ("src_min 198.18.0.0"))}) (C {(pg_set)} {($ VSub_Name "$dev")} {(DQ ("src_max 198.19.255.255"))}) (C {(pg_set)} {($ VSub_Name "$dev")} {(DQ ("flows ") ($ VSub_Name "$FLOWS"))}) (C {(pg_set)} {($ VSub_Name "$dev")} {(DQ ("flowlen ") ($ VSub_Name "$FLOWLEN"))}) (C {(pg_set)} {($ VSub_Name "$dev")} {(DQ ("flag FLOW_SEQ"))}) ] spids: [240 464] ) ) (FuncDef name: print_result body: (BraceGroup children: [ (ForExpr init: (BinaryAssign op_id: Arith_Equal left: (LhsName name:thread) right: (ArithWord w:{(Lit_Digits 0)}) ) cond: (ArithBinary op_id: Arith_Less left: (ArithVarRef name:thread) right: (ArithWord w:{($ VSub_Name "$THREADS")}) ) update: (UnaryAssign op_id:Node_PostDPlus child:(LhsName name:thread)) body: (DoGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:dev) op: Equal rhs: {(${ VSub_Name DEV) (Lit_Other "@") (${ VSub_Name thread)} spids: [509] ) ] spids: [509] ) (C {(echo)} {(DQ ("Device: ") ($ VSub_Name "$dev"))}) (Pipeline children: [ (C {(cat)} {(/proc/net/pktgen/) ($ VSub_Name "$dev")}) (C {(grep)} {(-A2)} {(DQ ("Result:"))}) ] negated: False ) ] spids: [506 543] ) ) ] spids: [476] ) spids: [470 475] ) (C {(trap)} {(true)} {(SIGINT)}) (SimpleCommand words: [{(echo)} {(DQ ("Running... ctrl^C to stop"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[563])] ) (C {(pg_ctrl)} {(DQ (start))}) (C {(print_result)}) ] )