Skip to content

Commit

Permalink
tests: match tests with modules
Browse files Browse the repository at this point in the history
Add a basic test for decapsulation.
  • Loading branch information
msantos committed Oct 21, 2013
1 parent 8d1ab44 commit 73e0535
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 36 deletions.
23 changes: 2 additions & 21 deletions test/pkt_sctp_tests.erl
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
-module(pkt_sctp_tests).

-include_lib("pkt/include/pkt.hrl").
-include("pkt_sctp_tests.hrl").
-include_lib("pkt/include/pkt_sctp.hrl").
-include_lib("eunit/include/eunit.hrl").

-define(SCTP_DATA_FILE(File), filename:join(["../test/sctp_data/", File])).
-define(SCTP_INIT_ACK_STATE_COOKIE,
<<111,57,134,27,172,92,166,97,56,253,90,104,24,26,148,109,
196,228,166,122,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,144,44,
102,191,246,253,10,177,0,0,0,0,0,0,0,0,79,232,54,82,0,0,
0,0,96,46,4,0,0,0,0,0,10,0,5,0,216,29,38,19,2,0,233,76,
127,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,214,7,
1,0,0,0,0,0,128,2,0,36,26,151,23,16,220,179,21,229,195,
65,68,131,135,26,132,69,196,12,196,122,243,64,140,241,54,
181,252,83,65,245,112,180,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,0,0,0,1,0,0,52,177,
10,253,246,0,0,5,220,0,5,255,255,176,137,244,165,0,5,0,8,
127,0,0,1,0,5,0,8,192,168,1,100,0,12,0,6,0,5,0,0,128,0,0,
4,192,0,0,4,0,5,0,8,127,0,0,1,0,6,0,20,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,1,0,5,0,8,192,168,1,100,0,6,0,20,254,128,0,0,
0,0,0,0,2,31,198,255,254,3,151,167,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0>>).

-define(SCTP_HEARTBEAT_INFO,
<<2,0,7,214,192,168,1,100,0,0,0,0,128,2,0,0,0,0,0,0,0,0,190,
191,0,136,255,255,20,239,108,1,1,0,0,0,208,159,244,147,185,42,232,28>>).

sctp_test_() ->
[
Expand Down
20 changes: 20 additions & 0 deletions test/pkt_sctp_tests.hrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-define(SCTP_INIT_ACK_STATE_COOKIE,
<<111,57,134,27,172,92,166,97,56,253,90,104,24,26,148,109,
196,228,166,122,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,144,44,
102,191,246,253,10,177,0,0,0,0,0,0,0,0,79,232,54,82,0,0,
0,0,96,46,4,0,0,0,0,0,10,0,5,0,216,29,38,19,2,0,233,76,
127,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,214,7,
1,0,0,0,0,0,128,2,0,36,26,151,23,16,220,179,21,229,195,
65,68,131,135,26,132,69,196,12,196,122,243,64,140,241,54,
181,252,83,65,245,112,180,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,0,0,0,1,0,0,52,177,
10,253,246,0,0,5,220,0,5,255,255,176,137,244,165,0,5,0,8,
127,0,0,1,0,5,0,8,192,168,1,100,0,12,0,6,0,5,0,0,128,0,0,
4,192,0,0,4,0,5,0,8,127,0,0,1,0,6,0,20,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,1,0,5,0,8,192,168,1,100,0,6,0,20,254,128,0,0,
0,0,0,0,2,31,198,255,254,3,151,167,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0>>).

-define(SCTP_HEARTBEAT_INFO,
<<2,0,7,214,192,168,1,100,0,0,0,0,128,2,0,0,0,0,0,0,0,0,190,
191,0,136,255,255,20,239,108,1,1,0,0,0,208,159,244,147,185,42,232,28>>).
28 changes: 28 additions & 0 deletions test/pkt_tcp_tests.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-module(pkt_tcp_tests).

-include_lib("pkt/include/pkt.hrl").
-include_lib("eunit/include/eunit.hrl").

tcp_test_() ->
[
tcp_decode_encode(),
tcp_checksum4()
].

tcp_decode_encode() ->
Packet = <<0,80,217,184,222,13,22,43,241,75,9,12,176,18,17,4,140,86,
0,0,2,4,5,172,1, 3,3,0,1,1,8,10,190,15,172,236,0,64,161,73,4,2,0,0>>,
{TCP, <<>>} = pkt:tcp(Packet),
TCP1 = TCP#tcp{opt = pkt:tcp_options(pkt:tcp_options(TCP#tcp.opt))},
?_assertEqual(Packet, pkt:tcp(TCP1)).

tcp_checksum4() ->
Frame = <<224,105,149,59,163,24,0,22,182,181,62,198,8,0,69,0,0,54,2,108,64,
0,53,6,172,243,173,192,82,195,192,168,213,54,0,80,143,166,75,154,
212,181,116,33,53,92,128,24,0,126,60,199,0,0,1,1,8,10,92,104,96,
16,22,69,237,136,137,0>>,

[#ether{}, IPv4, #tcp{sum = Sum} = TCP, Payload] = pkt:decapsulate(Frame),

Sum = pkt:makesum([IPv4, TCP#tcp{sum = 0}, Payload]),
?_assertEqual(0, pkt:makesum([IPv4, TCP, Payload])).
32 changes: 17 additions & 15 deletions test/pkt_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,28 @@
-include_lib("pkt/include/pkt.hrl").
-include_lib("eunit/include/eunit.hrl").

tcp_test_() ->
pkt_test_() ->
[
tcp_decode_encode(),
tcp_checksum4()
pkt_decapsulate()
].

tcp_decode_encode() ->
Packet = <<0,80,217,184,222,13,22,43,241,75,9,12,176,18,17,4,140,86,
0,0,2,4,5,172,1, 3,3,0,1,1,8,10,190,15,172,236,0,64,161,73,4,2,0,0>>,
{TCP, <<>>} = pkt:tcp(Packet),
TCP1 = TCP#tcp{opt = pkt:tcp_options(pkt:tcp_options(TCP#tcp.opt))},
?_assertEqual(Packet, pkt:tcp(TCP1)).

tcp_checksum4() ->
pkt_decapsulate() ->
Frame = <<224,105,149,59,163,24,0,22,182,181,62,198,8,0,69,0,0,54,2,108,64,
0,53,6,172,243,173,192,82,195,192,168,213,54,0,80,143,166,75,154,
212,181,116,33,53,92,128,24,0,126,60,199,0,0,1,1,8,10,92,104,96,
16,22,69,237,136,137,0>>,

[#ether{}, IPv4, #tcp{sum = Sum} = TCP, Payload] = pkt:decapsulate(Frame),

Sum = pkt:makesum([IPv4, TCP#tcp{sum = 0}, Payload]),
?_assertEqual(0, pkt:makesum([IPv4, TCP, Payload])).
?_assertEqual(
[{ether,<<224,105,149,59,163,24>>,
<<0,22,182,181,62,198>>,
2048,0},
{ipv4,4,5,0,54,620,1,0,0,53,6,44275,
{173,192,82,195},
{192,168,213,54},
<<>>},
{tcp,80,36774,1268438197,1948333404,8,0,0,0,1,1,0,0,0,126,
15559,0,
<<1,1,8,10,92,104,96,16,22,69,237,136>>},
<<137,0>>],
pkt:decapsulate(Frame)
).

0 comments on commit 73e0535

Please sign in to comment.