-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPERFTEST.PS1
More file actions
144 lines (123 loc) · 5.66 KB
/
PERFTEST.PS1
File metadata and controls
144 lines (123 loc) · 5.66 KB
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
#===============================================
# Script Input Parameters Enforcement
#===============================================
Param(
[parameter(Mandatory=$false)] [string] $Config = 'Default',
[parameter(Mandatory=$true)] [ValidateScript({-Not [String]::IsNullOrWhiteSpace($_)})] [string] $DestIp,
[parameter(Mandatory=$true)] [ValidateScript({-Not [String]::IsNullOrWhiteSpace($_)})] [string] $SrcIp,
[parameter(Mandatory=$true)] [String] $OutDir,
[parameter(Mandatory=$true)] [ValidateScript({-Not [String]::IsNullOrWhiteSpace($_)})] [string] $DestUserName,
[parameter(Mandatory=$true)] [ValidateScript({-Not [String]::IsNullOrWhiteSpace($_)})] [string] $SrcUserName,
[parameter(Mandatory=$true)] [ValidateScript({-Not [String]::IsNullOrWhiteSpace($_)})] [string] $TestUserName,
[parameter(Mandatory=$false)] [Array] $ToolList = @('ntttcp', 'lagscope', 'ncps', 'secnetperf', 'l4ping')
)
$scriptName = $MyInvocation.MyCommand.Name
function input_display {
$g_path = Get-Location
Write-Host "============================================"
Write-Host "$g_path\$scriptName"
Write-Host " Inputs:"
Write-Host " -Config = $Config"
Write-Host " -DestIp = $DestIp"
Write-Host " -SrcIp = $SrcIp"
Write-Host " -OutDir = $OutDir"
Write-Host "============================================"
} # 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."
}
}
$computername = hostname
$workDirName = "msdbg.$computername.perftest"
return (Join-Path $baseDir $workDirName).TrimEnd("\")
} # env_normalize()
function remote_env_normalize {
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)] [String] $OutDir
)
$computername = hostname
$workDirName = "msdbg.$computername.perftest"
return (Join-Path $OutDir $workDirName).TrimEnd("\")
} # remote_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 $OutDir and all its contents
Remove-Item $OutDir -Recurse -Force # Careful - Deletes $OutDir and all its contents
}
} # env_destroy()
#===============================================
# External Functions - Main Program
#===============================================
function test_main {
Param(
[parameter(Mandatory=$false)] [string] $Config = "Default",
[parameter(Mandatory=$true)] [ValidateScript({-Not [String]::IsNullOrWhiteSpace($_)})] [string] $DestIp,
[parameter(Mandatory=$true)] [ValidateScript({-Not [String]::IsNullOrWhiteSpace($_)})] [string] $SrcIp,
[parameter(Mandatory=$true)] [String] $OutDir,
[parameter(Mandatory=$true)] [ValidateScript({-Not [String]::IsNullOrWhiteSpace($_)})] [string] $DestUserName,
[parameter(Mandatory=$true)] [ValidateScript({-Not [String]::IsNullOrWhiteSpace($_)})] [string] $SrcUserName,
[parameter(Mandatory=$true)] [ValidateScript({-Not [String]::IsNullOrWhiteSpace($_)})] [string] $TestUserName,
[parameter(Mandatory=$false)] [Array] $ToolList = @('ntttcp', 'lagscope', 'ncps', 'secnetperf', 'l4ping')
)
Clear-Host 2>$null
input_display
$start = Get-Date
$version = '2020.09.28.0' # Version within date context
Write-Host $start
Write-Host $version
[string] $g_config = $Config
[string] $g_DestIp = $DestIp
[string] $g_SrcIp = $SrcIp
$DestDir = remote_env_normalize "/home/$DestUserName/$OutDir"
$SrcDir = remote_env_normalize "/home/$SrcUserName/$OutDir"
$OutDir = "/home/$TestUserName/$OutDir"
$workDir = env_normalize -OutDir $OutDir
Write-Host $workDir
env_destroy -OutDir $workDir
env_create -OutDir $workDir
# lagscope does not have detail
if ('lagscope' -in $ToolList) {
& "$PSScriptRoot/lagscope/lagscope.TESTGEN.ps1" -DestIp $g_DestIp -SrcIp $g_SrcIp -OutDir $workDir -DestDir $DestDir -SrcDir $SrcDir -Config $g_config
}
if ('ntttcp' -in $ToolList) {
& "$PSScriptRoot/ntttcp/ntttcp.TESTGEN.ps1" -DestIp $g_DestIp -SrcIp $g_SrcIp -OutDir $workDir -Config $g_config -DestDir $DestDir -SrcDir $SrcDir
}
if ('ncps' -in $ToolList) {
& "$PSScriptRoot/ncps/ncps.TESTGEN.ps1" -DestIp $g_DestIp -SrcIp $g_SrcIp -OutDir $workDir -Config $g_config -DestDir $DestDir -SrcDir $SrcDir
}
if ('secnetperf' -in $ToolList) {
& "$PSScriptRoot/secnetperf/secnetperf.TESTGEN.ps1" -DestIp $g_DestIp -SrcIp $g_SrcIp -OutDir $workDir -Config $g_config -DestDir $DestDir -SrcDir $SrcDir
}
if ('l4ping' -in $ToolList) {
& "$PSScriptRoot/l4ping/l4ping.TESTGEN.ps1" -DestIp $g_DestIp -SrcIp $g_SrcIp -OutDir $workDir -Config $g_config -DestDir $DestDir -SrcDir $SrcDir
}
} test_main @PSBoundParameters # Entry Point