Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
33957f94
Commit
33957f94
authored
9 years ago
by
Martine Lenders
Browse files
Options
Downloads
Patches
Plain Diff
shell: xtimerfy sc_icmpv6
parent
7b059647
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
sys/shell/commands/Makefile
+1
-1
1 addition, 1 deletion
sys/shell/commands/Makefile
sys/shell/commands/sc_icmpv6_echo.c
+36
-52
36 additions, 52 deletions
sys/shell/commands/sc_icmpv6_echo.c
sys/shell/commands/shell_commands.c
+2
-2
2 additions, 2 deletions
sys/shell/commands/shell_commands.c
with
39 additions
and
55 deletions
sys/shell/commands/Makefile
+
1
−
1
View file @
33957f94
...
...
@@ -53,7 +53,7 @@ endif
ifneq
(,$(filter gnrc_ipv6_whitelist,$(USEMODULE)))
SRC
+=
sc_whitelist.c
endif
ifneq
(,$(filter gnrc_icmpv6_echo
v
timer,$(USEMODULE)))
ifneq
(,$(filter gnrc_icmpv6_echo
x
timer,$(USEMODULE)))
SRC
+=
sc_icmpv6_echo.c
endif
ifneq
(,$(filter gnrc_zep ipv6_addr,$(USEMODULE)))
...
...
This diff is collapsed.
Click to expand it.
sys/shell/commands/sc_icmpv6_echo.c
+
36
−
52
View file @
33957f94
...
...
@@ -29,7 +29,7 @@
#include
"net/gnrc.h"
#include
"thread.h"
#include
"utlist.h"
#include
"
v
timer.h"
#include
"
x
timer.h"
static
uint16_t
id
=
0x53
;
static
uint16_t
min_seq_expected
=
0
;
...
...
@@ -78,7 +78,7 @@ static inline bool _expected_seq(uint16_t seq)
}
}
int
_handle_reply
(
gnrc_pktsnip_t
*
pkt
,
uint
64
_t
time
)
int
_handle_reply
(
gnrc_pktsnip_t
*
pkt
,
uint
32
_t
time
)
{
gnrc_pktsnip_t
*
ipv6
,
*
icmpv6
;
ipv6_hdr_t
*
ipv6_hdr
;
...
...
@@ -102,13 +102,11 @@ int _handle_reply(gnrc_pktsnip_t *pkt, uint64_t time)
min_seq_expected
++
;
}
timex_t
rt
=
timex_from_uint64
(
time
);
printf
(
"%u bytes from %s: id=%"
PRIu16
" seq=%"
PRIu16
" hop limit=%"
PRIu8
" time = %"
PRIu32
".%03"
PRIu32
" ms
\n
"
,
(
unsigned
)
icmpv6
->
size
,
ipv6_addr_to_str
(
ipv6_str
,
&
(
ipv6_hdr
->
src
),
sizeof
(
ipv6_str
)),
byteorder_ntohs
(
icmpv6_hdr
->
id
),
seq
,
ipv6_hdr
->
hl
,
(
rt
.
seconds
*
SEC_IN_MS
)
+
(
rt
.
microseconds
/
MS_IN_USEC
),
rt
.
microseconds
%
MS_IN_USEC
);
time
/
MS_IN_USEC
,
time
%
MS_IN_USEC
);
gnrc_ipv6_nc_still_reachable
(
&
ipv6_hdr
->
src
);
}
else
{
...
...
@@ -119,38 +117,24 @@ int _handle_reply(gnrc_pktsnip_t *pkt, uint64_t time)
return
1
;
}
static
inline
void
_a_to_timex
(
timex_t
*
delay
,
const
char
*
a
)
{
int
ms
=
atoi
(
a
);
if
(
ms
>=
0
)
{
delay
->
seconds
=
0
;
delay
->
microseconds
=
ms
*
1000
;
timex_normalize
(
delay
);
}
}
static
void
_print_stats
(
char
*
addr_str
,
int
success
,
int
count
,
timex_t
stop
,
timex_t
sum_rtt
,
timex_t
min_rtt
,
timex_t
max_rtt
)
static
void
_print_stats
(
char
*
addr_str
,
int
success
,
int
count
,
uint64_t
total_time
,
uint64_t
sum_rtt
,
uint32_t
min_rtt
,
uint32_t
max_rtt
)
{
printf
(
"--- %s ping statistics ---
\n
"
,
addr_str
);
if
(
success
>
0
)
{
timex_normalize
(
&
sum_rtt
);
uint32_t
avg_rtt
=
(
uint32_t
)
sum_rtt
/
count
;
/* get average */
printf
(
"%d packets transmitted, %d received, %d%% packet loss, time %"
PRIu32
".06%"
PRIu32
" s
\n
"
,
count
,
success
,
(
100
-
((
success
*
100
)
/
count
)),
stop
.
seconds
,
stop
.
microseconds
);
timex_t
avg_rtt
=
timex_from_uint64
(
timex_uint64
(
sum_rtt
)
/
count
);
/* get average */
PRIu32
".06%"
PRIu32
" s
\n
"
,
count
,
success
,
(
100
-
((
success
*
100
)
/
count
)),
(
uint32_t
)
total_time
/
SEC_IN_USEC
,
(
uint32_t
)
total_time
%
SEC_IN_USEC
);
printf
(
"rtt min/avg/max = "
"%"
PRIu32
".%03"
PRIu32
"/"
"%"
PRIu32
".%03"
PRIu32
"/"
"%"
PRIu32
".%03"
PRIu32
" ms
\n
"
,
(
min_rtt
.
seconds
*
SEC_IN_MS
)
+
(
min_rtt
.
microseconds
/
MS_IN_USEC
),
min_rtt
.
microseconds
%
MS_IN_USEC
,
(
avg_rtt
.
seconds
*
SEC_IN_MS
)
+
(
avg_rtt
.
microseconds
/
MS_IN_USEC
),
avg_rtt
.
microseconds
%
MS_IN_USEC
,
(
max_rtt
.
seconds
*
SEC_IN_MS
)
+
(
max_rtt
.
microseconds
/
MS_IN_USEC
),
max_rtt
.
microseconds
%
MS_IN_USEC
);
"%"
PRIu32
".%03"
PRIu32
"/"
"%"
PRIu32
".%03"
PRIu32
"/"
"%"
PRIu32
".%03"
PRIu32
" ms
\n
"
,
min_rtt
/
MS_IN_USEC
,
min_rtt
%
MS_IN_USEC
,
avg_rtt
/
MS_IN_USEC
,
avg_rtt
%
MS_IN_USEC
,
max_rtt
/
MS_IN_USEC
,
max_rtt
%
MS_IN_USEC
);
}
else
{
printf
(
"%d packets transmitted, 0 received, 100%% packet loss
\n
"
,
count
);
...
...
@@ -161,16 +145,16 @@ int _icmpv6_ping(int argc, char **argv)
{
int
count
=
3
,
success
=
0
,
remaining
,
stat_interval
=
0
,
stat_counter
=
0
;
size_t
payload_len
=
4
;
timex
_t
delay
=
{
1
,
0
}
;
uint32
_t
delay
=
1
*
SEC_IN_MS
;
char
*
addr_str
;
ipv6_addr_t
addr
;
msg_t
msg
;
gnrc_netreg_entry_t
*
ipv6_entry
,
my_entry
=
{
NULL
,
ICMPV6_ECHO_REP
,
thread_getpid
()
};
timex
_t
min_rtt
=
{
UINT32_MAX
,
UINT32_MAX
},
max_rtt
=
{
0
,
0
}
;
timex
_t
sum_rtt
=
{
0
,
0
}
;
timex
_t
ping_start
;
uint32
_t
min_rtt
=
UINT32_MAX
,
max_rtt
=
0
;
uint64
_t
sum_rtt
=
0
;
uint64
_t
ping_start
;
int
param_offset
=
0
;
if
(
argc
<
2
)
{
...
...
@@ -196,7 +180,7 @@ int _icmpv6_ping(int argc, char **argv)
payload_len
=
atoi
(
argv
[
2
+
param_offset
]);
}
if
(
argc
>
(
3
+
param_offset
))
{
_a_to_timex
(
&
delay
,
argv
[
3
+
param_offset
]);
delay
=
atoi
(
argv
[
3
+
param_offset
]);
}
if
(
argc
>
(
4
+
param_offset
))
{
stat_interval
=
atoi
(
argv
[
4
+
param_offset
]);
...
...
@@ -221,11 +205,11 @@ int _icmpv6_ping(int argc, char **argv)
remaining
=
count
;
vtimer_now
(
&
ping_start
);
ping_start
=
xtimer_now64
(
);
while
((
remaining
--
)
>
0
)
{
gnrc_pktsnip_t
*
pkt
;
timex
_t
start
,
stop
,
timeout
=
{
1
,
0
}
;
uint32
_t
start
,
stop
,
timeout
=
1
*
SEC_IN_USEC
;
pkt
=
gnrc_icmpv6_echo_build
(
ICMPV6_ECHO_REQ
,
id
,
++
max_seq_expected
,
NULL
,
payload_len
);
...
...
@@ -245,32 +229,32 @@ int _icmpv6_ping(int argc, char **argv)
continue
;
}
v
timer_now
(
&
start
);
start
=
x
timer_now
();
if
(
gnrc_netapi_send
(
ipv6_entry
->
pid
,
pkt
)
<
1
)
{
puts
(
"error: unable to send ICMPv6 echo request
\n
"
);
gnrc_pktbuf_release
(
pkt
);
continue
;
}
if
(
vtimer_msg_receive_timeout
(
&
msg
,
timeout
)
>=
0
)
{
/* TODO: replace when #4219 was fixed */
if
(
xtimer_msg_receive_timeout64
(
&
msg
,
(
uint64_t
)
timeout
)
>=
0
)
{
switch
(
msg
.
type
)
{
case
GNRC_NETAPI_MSG_TYPE_RCV
:
vtimer_now
(
&
stop
);
stop
=
timex_sub
(
stop
,
start
);
stop
=
xtimer_now
()
-
start
;
gnrc_pktsnip_t
*
pkt
=
(
gnrc_pktsnip_t
*
)
msg
.
content
.
ptr
;
success
+=
_handle_reply
(
pkt
,
timex_uint64
(
stop
)
)
;
success
+=
_handle_reply
(
pkt
,
stop
);
gnrc_pktbuf_release
(
pkt
);
if
(
timex_cmp
(
stop
,
max_rtt
)
>
0
)
{
if
(
stop
>
max_rtt
)
{
max_rtt
=
stop
;
}
if
(
timex_cmp
(
stop
,
min_rtt
)
<
1
)
{
if
(
stop
<
min_rtt
)
{
min_rtt
=
stop
;
}
sum_rtt
=
timex_add
(
sum_rtt
,
stop
)
;
sum_rtt
+
=
stop
;
break
;
...
...
@@ -284,7 +268,7 @@ int _icmpv6_ping(int argc, char **argv)
puts
(
"ping timeout"
);
}
while
(
msg_try_receive
(
&
msg
)
>
0
)
{
while
(
msg_try_receive
(
&
msg
)
>
0
)
{
if
(
msg
.
type
==
GNRC_NETAPI_MSG_TYPE_RCV
)
{
printf
(
"dropping additional response packet (probably caused by duplicates)
\n
"
);
gnrc_pktsnip_t
*
pkt
=
(
gnrc_pktsnip_t
*
)
msg
.
content
.
ptr
;
...
...
@@ -293,12 +277,12 @@ int _icmpv6_ping(int argc, char **argv)
}
if
(
remaining
>
0
)
{
v
timer_sleep
(
delay
);
x
timer_
u
sleep
64
(
delay
*
MS_IN_USEC
);
}
if
((
++
stat_counter
==
stat_interval
)
||
(
remaining
==
0
))
{
vtimer_now
(
&
stop
)
;
stop
=
timex_sub
(
stop
,
p
in
g_start
);
_print_stats
(
addr_str
,
success
,
(
count
-
remaining
),
stop
,
sum_rtt
,
min_rtt
,
max_rtt
);
uint64_t
total_time
=
xtimer_now64
()
-
ping_start
;
_print_stats
(
addr_str
,
success
,
(
count
-
remaining
),
total_time
,
sum_rtt
,
m
in
_rtt
,
max_rtt
);
stat_counter
=
0
;
}
...
...
@@ -308,7 +292,7 @@ int _icmpv6_ping(int argc, char **argv)
id
++
;
gnrc_netreg_unregister
(
GNRC_NETTYPE_ICMPV6
,
&
my_entry
);
while
(
msg_try_receive
(
&
msg
)
>
0
)
{
while
(
msg_try_receive
(
&
msg
)
>
0
)
{
if
(
msg
.
type
==
GNRC_NETAPI_MSG_TYPE_RCV
)
{
printf
(
"dropping additional response packet (probably caused by duplicates)
\n
"
);
gnrc_pktsnip_t
*
pkt
=
(
gnrc_pktsnip_t
*
)
msg
.
content
.
ptr
;
...
...
This diff is collapsed.
Click to expand it.
sys/shell/commands/shell_commands.c
+
2
−
2
View file @
33957f94
...
...
@@ -90,7 +90,7 @@ extern int _read_bytes(int argc, char **argv);
#endif
#ifdef MODULE_GNRC_ICMPV6_ECHO
#ifdef MODULE_
V
TIMER
#ifdef MODULE_
X
TIMER
extern
int
_icmpv6_ping
(
int
argc
,
char
**
argv
);
#endif
#endif
...
...
@@ -182,7 +182,7 @@ const shell_command_t _shell_command_list[] = {
{
DISK_GET_BLOCK_SIZE
,
"Get the block size of inserted memory card"
,
_get_blocksize
},
#endif
#ifdef MODULE_GNRC_ICMPV6_ECHO
#ifdef MODULE_
V
TIMER
#ifdef MODULE_
X
TIMER
{
"ping6"
,
"Ping via ICMPv6"
,
_icmpv6_ping
},
#endif
#endif
...
...
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