ambidexter 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ambidexter +1 -1
- data/lib/client.rb +151 -73
- data/lib/server.rb +70 -1
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5823985b4ba3efee7ad6a50729a78acfe14fc338
|
4
|
+
data.tar.gz: 336c463a66e592593055f5903cffb42897c02ab2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7209ee97bfa810984cb3acfb38f4fa893d30567a288a30935531aebc94cc818867d01d3997864161e6feea52e474fc54545ae4da4ad6fe012c32679257a98abd
|
7
|
+
data.tar.gz: ca83b536b52b6363b3816eb13d2c814fb5c48e5ea368698036c05c5698db87894b33927b038fcaf8bcdb9aee378c281e2b2aed67d1a1ca46455eda8c5281c781
|
data/bin/ambidexter
CHANGED
data/lib/client.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "application"
|
2
2
|
require "curb"
|
3
3
|
require "colorize"
|
4
|
+
require "pry"
|
4
5
|
|
5
6
|
class Client < Application
|
6
7
|
def initialize
|
@@ -24,12 +25,19 @@ class Client < Application
|
|
24
25
|
@threads_count = $stdin.gets.chomp.to_i
|
25
26
|
@threads_count = 1 if @threads_count.zero?
|
26
27
|
|
28
|
+
# Setting eterations count
|
29
|
+
print "Input timeout: ".green
|
30
|
+
@http_timeout = $stdin.gets.chomp.to_f
|
31
|
+
@http_timeout = 10 if @http_timeout.zero?
|
32
|
+
|
27
33
|
# Building link
|
28
34
|
@uri = "http://#{@ip}:#{@port}"
|
29
35
|
|
30
36
|
# Thread and time arrays
|
31
37
|
@req_times = []
|
32
38
|
@threads = []
|
39
|
+
@package_loss = 0
|
40
|
+
@package_rec = 0
|
33
41
|
end
|
34
42
|
|
35
43
|
def test
|
@@ -37,102 +45,172 @@ class Client < Application
|
|
37
45
|
@threads << Thread.new do
|
38
46
|
@each_count.times do
|
39
47
|
# Raw root GET
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
48
|
+
begin
|
49
|
+
t = Time.now
|
50
|
+
response = Curl.get(@uri) do |http|
|
51
|
+
http.timeout = @http_timeout
|
52
|
+
end
|
53
|
+
@req_times << Time.now - t
|
54
|
+
if response.status == '200 OK'
|
55
|
+
print '.'.green
|
56
|
+
else
|
57
|
+
print '!'.red
|
58
|
+
end
|
59
|
+
@package_rec += 1
|
60
|
+
rescue Curl::Err::TimeoutError
|
61
|
+
print '#'.yellow
|
62
|
+
@package_loss += 1
|
47
63
|
end
|
48
64
|
|
49
65
|
# Root POST with correct params
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
66
|
+
begin
|
67
|
+
t = Time.now
|
68
|
+
response = Curl.post(@uri, { name: 'Oleg', github_nickname: 'sorefull' }) do |http|
|
69
|
+
http.timeout = @http_timeout
|
70
|
+
end
|
71
|
+
@req_times << Time.now - t
|
72
|
+
if response.status == '202 Accepted'
|
73
|
+
print '.'.green
|
74
|
+
else
|
75
|
+
print '!'.red
|
76
|
+
end
|
77
|
+
@package_rec += 1
|
78
|
+
rescue Curl::Err::TimeoutError
|
79
|
+
print '#'.yellow
|
80
|
+
@package_loss += 1
|
57
81
|
end
|
58
82
|
|
59
83
|
# Root POST with wrong params
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
84
|
+
begin
|
85
|
+
t = Time.now
|
86
|
+
response = Curl.post(@uri, { name: '', github_nickname: '' }) do |http|
|
87
|
+
http.timeout = @http_timeout
|
88
|
+
end
|
89
|
+
@req_times << Time.now - t
|
90
|
+
if response.status == '401 Unauthorized'
|
91
|
+
print '.'.green
|
92
|
+
else
|
93
|
+
print '!'.red
|
94
|
+
end
|
95
|
+
@package_rec += 1
|
96
|
+
rescue Curl::Err::TimeoutError
|
97
|
+
print '#'.yellow
|
98
|
+
@package_loss += 1
|
67
99
|
end
|
68
100
|
|
69
101
|
# Lorem GET with body check
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
102
|
+
begin
|
103
|
+
t = Time.now
|
104
|
+
response = Curl.get(@uri + '/lorem') do |http|
|
105
|
+
http.timeout = @http_timeout
|
106
|
+
end
|
107
|
+
@req_times << Time.now - t
|
108
|
+
if response.body == LoremIpsum.lorem
|
109
|
+
print '.'.green
|
110
|
+
else
|
111
|
+
print '!'.red
|
112
|
+
end
|
113
|
+
@package_rec += 1
|
114
|
+
rescue Curl::Err::TimeoutError
|
115
|
+
print '#'.yellow
|
116
|
+
@package_loss += 1
|
77
117
|
end
|
78
118
|
|
79
119
|
# Lorem GET with params
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
120
|
+
begin
|
121
|
+
t = Time.now
|
122
|
+
response = Curl.get(@uri + '/lorem', { length: 10 }) do |http|
|
123
|
+
http.timeout = @http_timeout
|
124
|
+
end
|
125
|
+
@req_times << Time.now - t
|
126
|
+
if response.body == LoremIpsum.lorem[0..10]
|
127
|
+
print '.'.green
|
128
|
+
else
|
129
|
+
print '!'.red
|
130
|
+
end
|
131
|
+
@package_rec += 1
|
132
|
+
rescue Curl::Err::TimeoutError
|
133
|
+
print '#'.yellow
|
134
|
+
@package_loss += 1
|
87
135
|
end
|
88
136
|
|
89
137
|
# Cookie GET with correct cookies
|
138
|
+
begin
|
90
139
|
t = Time.now
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
140
|
+
response = Curl.get(@uri + '/cookie') do |http|
|
141
|
+
http.headers['Cookie'] = 'private=asdfg; public=gijj'
|
142
|
+
http.timeout = @http_timeout
|
143
|
+
end
|
144
|
+
@req_times << Time.now - t
|
145
|
+
if response.status == '200 OK'
|
146
|
+
print '.'.green
|
147
|
+
else
|
148
|
+
print '!'.red
|
149
|
+
end
|
150
|
+
@package_rec += 1
|
151
|
+
rescue Curl::Err::TimeoutError
|
152
|
+
print '#'.yellow
|
153
|
+
@package_loss += 1
|
99
154
|
end
|
100
155
|
|
101
156
|
# Cookie GET with wrong cookies
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
157
|
+
begin
|
158
|
+
t = Time.now
|
159
|
+
response = Curl.get(@uri + '/cookie') do |http|
|
160
|
+
http.headers['Cookie'] = 'private=wrong; public=wrong'
|
161
|
+
http.timeout = @http_timeout
|
162
|
+
end
|
163
|
+
@req_times << Time.now - t
|
164
|
+
if response.status == '401 Unauthorized'
|
165
|
+
print '.'.green
|
166
|
+
else
|
167
|
+
print '!'.red
|
168
|
+
end
|
169
|
+
@package_rec += 1
|
170
|
+
rescue Curl::Err::TimeoutError
|
171
|
+
print '#'.yellow
|
172
|
+
@package_loss += 1
|
111
173
|
end
|
112
174
|
|
113
175
|
# File GET
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
176
|
+
begin
|
177
|
+
file_name = '/file.txt'
|
178
|
+
t = Time.now
|
179
|
+
response = Curl.get(@uri + file_name) do |http|
|
180
|
+
http.timeout = @http_timeout
|
181
|
+
end
|
182
|
+
@req_times << Time.now - t
|
183
|
+
file = File.open("#{__dir__}/../files#{file_name}", 'r')
|
184
|
+
if response.body == file.read && response.status == '200 OK'
|
185
|
+
print '.'.green
|
186
|
+
else
|
187
|
+
print '!'.red
|
188
|
+
end
|
189
|
+
@package_rec += 1
|
190
|
+
rescue Curl::Err::TimeoutError
|
191
|
+
print '#'.yellow
|
192
|
+
@package_loss += 1
|
123
193
|
end
|
124
194
|
|
125
195
|
# File POST
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
196
|
+
begin
|
197
|
+
file_name = 'image.jpeg'
|
198
|
+
response = Curl::Easy.new(@uri + '/file') do |http|
|
199
|
+
http.timeout = @http_timeout
|
200
|
+
end
|
201
|
+
response.multipart_form_post = true
|
202
|
+
t = Time.now
|
203
|
+
response.http_post(Curl::PostField.file('uploaded_image', "#{__dir__}/../files/#{file_name}"))
|
204
|
+
@req_times << Time.now - t
|
205
|
+
if response.status == '200 OK'
|
206
|
+
print '.'.green
|
207
|
+
else
|
208
|
+
print '!'.red
|
209
|
+
end
|
210
|
+
@package_rec += 1
|
211
|
+
rescue Curl::Err::TimeoutError
|
212
|
+
print '#'.yellow
|
213
|
+
@package_loss += 1
|
136
214
|
end
|
137
215
|
end
|
138
216
|
end
|
@@ -142,7 +220,7 @@ class Client < Application
|
|
142
220
|
@threads.each {|thread| thread.join}
|
143
221
|
end
|
144
222
|
|
145
|
-
def
|
146
|
-
@req_times
|
223
|
+
def send_results
|
224
|
+
Curl.post(@uri + '/exit', { results: @req_times.join(' '), package_loss: @package_loss, package_rec: @package_rec })
|
147
225
|
end
|
148
226
|
end
|
data/lib/server.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
require "pry"
|
1
2
|
require "application"
|
2
3
|
require "webrick"
|
3
4
|
include WEBrick
|
4
5
|
require 'securerandom'
|
6
|
+
require 'usagewatch'
|
5
7
|
|
6
8
|
class Server < Application
|
7
9
|
class RootPath < WEBrick::HTTPServlet::AbstractServlet
|
@@ -49,6 +51,27 @@ class Server < Application
|
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
54
|
+
class ExitPath < WEBrick::HTTPServlet::AbstractServlet
|
55
|
+
def do_POST(request, response)
|
56
|
+
@@req_results = request.query['results'].split(' ').map{|r| r.to_f}
|
57
|
+
@@package_loss = request.query['package_loss'].to_i
|
58
|
+
@@package_rec = request.query['package_rec'].to_i
|
59
|
+
response.status = 200
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.results
|
63
|
+
@@req_results ||= []
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.loss
|
67
|
+
@@package_loss ||= 0
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.rec
|
71
|
+
@@package_rec ||= 0
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
52
75
|
def initialize
|
53
76
|
print "Input Port of servrer: ".green
|
54
77
|
@port = $stdin.gets.chomp
|
@@ -64,12 +87,58 @@ class Server < Application
|
|
64
87
|
@server.mount "/cookie", CookiePath
|
65
88
|
@server.mount "/file", FilePath
|
66
89
|
@server.mount('/file.txt', WEBrick::HTTPServlet::DefaultFileHandler, "#{__dir__}/../files/file.txt")
|
90
|
+
@server.mount '/exit', ExitPath
|
67
91
|
end
|
68
92
|
|
69
93
|
def start
|
94
|
+
@usw = Usagewatch
|
95
|
+
@new0 = @usw.bandrx
|
96
|
+
@time0 = Time.now
|
97
|
+
|
70
98
|
['TERM', 'INT'].each do |signal|
|
71
|
-
trap(signal){
|
99
|
+
trap(signal){
|
100
|
+
@server.shutdown
|
101
|
+
statistics
|
102
|
+
}
|
72
103
|
end
|
73
104
|
@server.start
|
74
105
|
end
|
106
|
+
|
107
|
+
def statistics
|
108
|
+
new1 = @usw.bandrx
|
109
|
+
time1 = Time.now
|
110
|
+
|
111
|
+
bytesreceived = new1[0].to_i - @new0[0].to_i
|
112
|
+
bitsreceived = bytesreceived * 8
|
113
|
+
bandwidth = (bitsreceived.to_f / 1024 / 1024).round(3)
|
114
|
+
time = (time1 - @time0).round(3)
|
115
|
+
sum_req_times = ExitPath.results.sum.round(3)
|
116
|
+
package_loss = ExitPath.loss
|
117
|
+
package_rec = ExitPath.rec
|
118
|
+
average_req_times = begin
|
119
|
+
if ExitPath.results.empty?
|
120
|
+
0
|
121
|
+
else
|
122
|
+
(ExitPath.results.inject{ |sum, el| sum + el } / ExitPath.results.size).round(3)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
bandwidth_per_time = (bandwidth / time).round(3)
|
126
|
+
|
127
|
+
puts
|
128
|
+
puts '------------------------------------------------------------------'.green
|
129
|
+
puts "~> AMBIDEXTER's SUMMARY".yellow
|
130
|
+
puts
|
131
|
+
puts "#{time} seconds Server sesion time".yellow
|
132
|
+
puts "#{bandwidth} Mbit Current Bandwidth Received".yellow
|
133
|
+
puts "#{bandwidth_per_time} Mbit/s Average Bandwidth Received".yellow
|
134
|
+
puts "#{sum_req_times} seconds Summary request time".yellow
|
135
|
+
puts "#{average_req_times} seconds Average request time".yellow
|
136
|
+
if package_loss > 0
|
137
|
+
puts "#{package_loss} Packages lost".red
|
138
|
+
end
|
139
|
+
puts "#{package_rec} Packages received".yellow
|
140
|
+
puts
|
141
|
+
puts "Made by Oleg Cherednichenko 2017, KNURE".rjust 66
|
142
|
+
puts '------------------------------------------------------------------'.green
|
143
|
+
end
|
75
144
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ambidexter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleg Cherednichenko
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.8.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: usagewatch
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.0.7
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.0.7
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.10.4
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.10.4
|
41
69
|
description: Ambidexter hands two hands and will give bouth to help you in testing
|
42
70
|
your network for HTTP stuff
|
43
71
|
email: olegh.cherednichenko@gmail.com
|
@@ -72,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
100
|
version: '0'
|
73
101
|
requirements: []
|
74
102
|
rubyforge_project:
|
75
|
-
rubygems_version: 2.
|
103
|
+
rubygems_version: 2.6.8
|
76
104
|
signing_key:
|
77
105
|
specification_version: 4
|
78
106
|
summary: Gem for testing network for HTML stuff
|