Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
D0020E-projekt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Henrik Tjäder
D0020E-projekt
Commits
bea02796
Commit
bea02796
authored
10 years ago
by
Mat
Browse files
Options
Downloads
Patches
Plain Diff
Wrong files, proper port this time
parent
d18c8fb6
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
UDP-client-server.py
+18
-17
18 additions, 17 deletions
UDP-client-server.py
UDP-reflector.py
+6
-5
6 additions, 5 deletions
UDP-reflector.py
with
24 additions
and
22 deletions
UDP-client-server.py
+
18
−
17
View file @
bea02796
...
...
@@ -44,13 +44,14 @@ def udp_client_receive(UDP_RECEIVE_IP, UDP_RECEIVE_PORT):
try
:
rcv_sock
.
bind
(
ADDR
)
print
'
Server Listening on
'
,
ADDR
print
(
'
Server Listening on
'
,
ADDR
)
except
Exception
:
print
'
***ERROR: Server Port Binding Failed
'
print
(
'
***ERROR: Server Port Binding Failed
'
)
#FIRE UP THE LISTENER ENGINES
while
True
:
data
,
addr
=
rcv_sock
.
recvfrom
(
BUFFER
)
data
=
data
.
decode
(
"
utf-8
"
)
splitdata
=
data
.
split
(
'
,
'
)
timecount
=
splitdata
[
0
].
strip
(
"
(
'"
)
rt_delay
=
(
time
.
time
()
-
float
(
timecount
))
...
...
@@ -65,8 +66,8 @@ def udp_client_receive(UDP_RECEIVE_IP, UDP_RECEIVE_PORT):
rt_delay_array
.
append
(
rt_delay
)
print
(
time
.
ctime
()
+
'
,
'
+
'
received ,
'
+
packet_number
+
'
,
'
+
str
(
rt_delay
))
print
(
(
time
.
ctime
()
+
'
,
'
+
'
received ,
'
+
packet_number
+
'
,
'
+
str
(
rt_delay
))
)
# Store minimum and maximum delay
if
rt_delay
>
max_delay
:
...
...
@@ -87,10 +88,10 @@ def udp_client_send(UDP_DEST_IP, UDP_DEST_PORT,
inter_departure_time
=
1.
/
PACKETS_PER_SEC
packet_count_snd
=
0
print
"
UDP Client Started
"
print
"
UDP target IP:
"
,
UDP_DEST_IP
print
"
UDP target port:
"
,
UDP_DEST_PORT
print
"
UDP Packets to Send:
"
,
NR_OF_PACKETS
print
(
"
UDP Client Started
"
)
print
(
"
UDP target IP:
"
,
UDP_DEST_IP
)
print
(
"
UDP target port:
"
,
UDP_DEST_PORT
)
print
(
"
UDP Packets to Send:
"
,
NR_OF_PACKETS
)
#IF IPv6
if
'
:
'
in
UDP_DEST_IP
:
...
...
@@ -115,7 +116,7 @@ def udp_client_send(UDP_DEST_IP, UDP_DEST_PORT,
time
.
sleep
(
inter_departure_time
)
snd_sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
snd_sock
.
sendto
(
str
((
"
%.5f
"
%
time
.
time
(),
str
(
'
%08d
'
%
i
),
padding
)),
(
UDP_DEST_IP
,
UDP_DEST_PORT
))
padding
))
.
encode
(
"
utf-8
"
)
,
(
UDP_DEST_IP
,
UDP_DEST_PORT
))
packet_count_snd
=
packet_count_snd
+
1
#WAIT 5SEC FOR ALL PACKETS TO ARRIVE
...
...
@@ -126,18 +127,18 @@ def udp_client_send(UDP_DEST_IP, UDP_DEST_PORT,
PLR
=
100
-
((
packet_count_rcvd
*
100.
)
/
packet_count_snd
)
print
'
\n
'
,
packet_count_snd
,
'
packets sent
'
print
packet_count_rcvd
,
'
packets received
'
print
'
packet loss ratio =
'
,
round
(
PLR
,
3
),
'
%
'
print
(
'
\n
'
,
packet_count_snd
,
'
packets sent
'
)
print
(
packet_count_rcvd
,
'
packets received
'
)
print
(
'
packet loss ratio =
'
,
round
(
PLR
,
3
),
'
%
'
)
if
(
max_delay
-
min_delay
!=
-
100
):
print
'
max_delay =
'
,
max_delay
print
'
min_delay =
'
,
min_delay
print
'
range =
'
,
(
max_delay
-
min_delay
)
print
(
'
max_delay =
'
,
max_delay
)
print
(
'
min_delay =
'
,
min_delay
)
print
(
'
range =
'
,
(
max_delay
-
min_delay
)
)
#CALCULATE THE STANDARD DEVIATION
if
rt_delay_array
:
print
'
std.dev =
'
,
np
.
std
(
rt_delay_array
)
print
(
'
std.dev =
'
,
np
.
std
(
rt_delay_array
)
)
#NETWORK STABILITY BASED ON PACKET LOSS AND DELAY, VALUE 0-100
network_stability
=
0
...
...
@@ -147,7 +148,7 @@ def udp_client_send(UDP_DEST_IP, UDP_DEST_PORT,
avg_packet_delay
=
cumulative_delay
/
packet_count_rcvd
#CALCULATE STABILITY
network_stability
=
int
(((
packet_count_rcvd
/
packet_count_snd
)
*
(
avg_packet_delay
/
packet_wait_time
)
*
100
)
+
0.5
)
print
'
avg.rtt =
'
,
avg_packet_delay
print
(
'
avg.rtt =
'
,
avg_packet_delay
)
#START THE THREADS FOR SENDER AND RECEIVER
...
...
This diff is collapsed.
Click to expand it.
UDP-reflector.py
+
6
−
5
View file @
bea02796
...
...
@@ -22,16 +22,17 @@ else:
#BINDING, PROCESSING AND WRITING TO CSV
try
:
EchoServer
.
bind
(
ADDR
)
print
'
echo server started on port
'
,
ADDR
print
(
'
echo server started on port
'
,
ADDR
)
except
Exception
:
print
'
***ERROR: Port Binding Failed
'
print
(
'
***ERROR: Port Binding Failed
'
)
while
True
:
data
,
addr
=
EchoServer
.
recvfrom
(
BUFFER
)
data
=
data
.
decode
(
"
utf-8
"
)
addlst
=
addr
[
0
],
REMOTE_PORT
if
REFLECT_SWITCH
==
1
:
EchoServer
.
sendto
(
'
%s
'
%
(
data
),
addlst
)
EchoServer
.
sendto
(
data
.
encode
(
"
utf-8
"
),
addlst
)
splitdata
=
data
.
split
(
'
,
'
)
timecount
=
splitdata
[
0
].
strip
(
"
(
'"
)
...
...
@@ -44,8 +45,8 @@ while True:
'
,
'
+
'
received ,
'
+
packet_number
+
'
,
'
+
str
(
one_way_delay
)
+
'
\n
'
))
print
(
time
.
ctime
()
+
'
,
'
+
'
received ,
'
+
packet_number
+
'
,
'
+
str
(
one_way_delay
))
print
(
(
time
.
ctime
()
+
'
,
'
+
'
received ,
'
+
packet_number
+
'
,
'
+
str
(
one_way_delay
))
)
outfile
.
close
()
EchoServer
.
close
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment