-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathPERFTEST.PS1
163 lines (134 loc) · 5.9 KB
/
PERFTEST.PS1
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#===============================================
# Script Input Parameters Enforcement
#===============================================
Param(
[parameter(Mandatory=$true)] [string] $SrcIp,
[parameter(Mandatory=$true)] [string] $DestIp,
[parameter(Mandatory=$true)] [ValidateScript({Test-Path $_ -PathType Container})] [String] $OutDir = "",
[parameter(Mandatory=$false)] [string] $Config = "Default",
[parameter(Mandatory=$false)] [Array] $ToolList = @("ntttcp", "latte", "l4ping", "cps", "ctstraffic", "ncps", "secnetperf"),
[parameter(Mandatory=$false)] [switch] $SamePort = $false
)
$scriptName = $MyInvocation.MyCommand.Name
$SupportedTools = @("ntttcp", "latte", "l4ping", "cps", "ctstraffic", "ncps", "secnetperf")
$start = Get-Date
$version = "2020.09.13.0" # Version within date context
function input_display {
$g_path = Get-Location
Write-Output "============================================"
Write-Output "$g_path\$scriptName"
Write-Output " Date: $start"
Write-Output " Version: $version"
Write-Output " Inputs:"
Write-Output " -Config = $Config"
Write-Output " -DestIp = $DestIp"
Write-Output " -SrcIp = $SrcIp"
Write-Output " -OutDir = $OutDir"
Write-Output "============================================"
} # input_display()
#===============================================
# Internal Functions
#===============================================
function env_normalize {
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)] [String] $OutDir
)
$baseDir = if (-not [String]::IsNullOrWhiteSpace($OutDir)) {
if (Test-Path $OutDir) {
(Resolve-Path $OutDir).Path # full path
}
else {
throw "-> The directory ""$OutDir"" does not exist."
}
}
$workDirName = "msdbg.$env:COMPUTERNAME.perftest"
return (Join-Path $baseDir $workDirName).TrimEnd("\")
} # env_normalize()
function env_create {
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)] [String] $OutDir
)
# Attempt to create working directory, fail gracefully otherwise
try {
New-Item -ItemType directory -Path $OutDir -ErrorAction Stop | Out-Null
} catch {
throw "-> Failed to create directory ""$OutDir"" because " + $error[0]
}
} # env_create()
function env_destroy {
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)] [String] $OutDir
)
If (Test-Path $OutDir) {
# Careful - Deletes $OurDir and all its contents
Remove-Item $OutDir -Recurse -Force # Careful - Deletes $OurDir and all its contents
}
} # env_destroy()
function normalize_toollist {
Param(
[Parameter(Mandatory=$true)] [Array] $ToolList
)
for ($i = 0; $i -lt $ToolList.Count; $i += 1) {
$ToolList[$i] = $ToolList[$i].ToLower()
if (-not ($ToolList[$i] -in $SupportedTools)) {
$toolstr = ""
foreach ($tool in $SupportedTools) {$toolstr += "`t$tool`n"}
Write-Error "NPT does not support the tool: $($ToolList[$i])`nSupported Tools:`n$($toolstr)"
Exit
}
}
return $ToolList
}
#===============================================
# External Functions - Main Program
#===============================================
function test_main {
Param(
[parameter(Mandatory=$false)] [string] $Config = "Default",
[parameter(Mandatory=$true)] [string] $DestIp,
[parameter(Mandatory=$true)] [string] $SrcIp,
[parameter(Mandatory=$true)] [ValidateScript({Test-Path $_ -PathType Container})] [String] $OutDir = "" ,
[parameter(Mandatory=$false)] [Array] $ToolList,
[parameter(Mandatory=$false)] [switch] $SamePort = $false
)
if (-not $silent) {input_display}
[string] $g_config = $Config
[string] $g_DestIp = $DestIp
[string] $g_SrcIp = $SrcIp
$workDir = env_normalize -OutDir $OutDir
env_destroy -OutDir $workDir
env_create -OutDir $workDir
$ToolList = normalize_toollist -ToolList $ToolList
if ("ctstraffic" -in $ToolList) {
& "$PSScriptRoot\ctsTraffic\ctsTraffic.TESTGEN.ps1" -DestIp $g_DestIp -SrcIp $g_SrcIp -OutDir $workDir -Config $g_config -SamePort:$SamePort.IsPresent
}
if ("cps" -in $ToolList) {
& "$PSScriptRoot\cps\cps.TESTGEN.ps1" -DestIp $g_DestIp -SrcIp $g_SrcIp -OutDir $workDir -Config $g_config -SamePort:$SamePort.IsPresent
}
if ("latte" -in $ToolList) {
& "$PSScriptRoot\latte\latte.TESTGEN.ps1" -DestIp $g_DestIp -SrcIp $g_SrcIp -OutDir $workDir -Config $g_config -SamePort:$SamePort.IsPresent
}
if ("l4ping" -in $ToolList) {
& "$PSScriptRoot\l4ping\l4ping.TESTGEN.ps1" -DestIp $g_DestIp -SrcIp $g_SrcIp -OutDir $workDir -Config $g_config -SamePort:$SamePort.IsPresent
}
if ("ntttcp" -in $ToolList) {
& "$PSScriptRoot\ntttcp\ntttcp.TESTGEN.ps1" -DestIp $g_DestIp -SrcIp $g_SrcIp -OutDir $workDir -Config $g_config -SamePort:$SamePort.IsPresent
}
if ("ncps" -in $ToolList) {
& "$PSScriptRoot\ncps\ncps.TESTGEN.ps1" -DestIp $g_DestIp -SrcIp $g_SrcIp -OutDir $workDir -Config $g_config -SamePort:$SamePort.IsPresent
}
if ("secnetperf" -in $ToolList) {
& "$PSScriptRoot\secnetperf\secnetperf.TESTGEN.ps1" -DestIp $g_DestIp -SrcIp $g_SrcIp -OutDir $workDir -Config $g_config -SamePort:$SamePort.IsPresent
}
} test_main -Config $Config -DestIp $DestIp -SrcIp $SrcIp -OutDir $OutDir -ToolList $ToolList
# TODO
# =============================================================
# - create a flag for command generation only
# - If files present, user is free to edit to rerun/reexecute or loop via edits
# - create a flag for command execution only
# - Capture Get-NetView before and after Test run
# - Zip results
# =============================================================