1: %% Copyright (c) 2015 Peter Morgan <peter.james.morgan@gmail.com>
    2: %%
    3: %% Licensed under the Apache License, Version 2.0 (the "License");
    4: %% you may not use this file except in compliance with the License.
    5: %% You may obtain a copy of the License at
    6: %%
    7: %% http://www.apache.org/licenses/LICENSE-2.0
    8: %%
    9: %% Unless required by applicable law or agreed to in writing, software
   10: %% distributed under the License is distributed on an "AS IS" BASIS,
   11: %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   12: %% See the License for the specific language governing permissions and
   13: %% limitations under the License.
   14: 
   15: -module(pcapng_SUITE).
   16: 
   17: -compile(export_all).
   18: -compile(nowarn_export_all).
   19: -include_lib("common_test/include/ct.hrl").
   20: 
   21: 
   22: all() ->
   23:         [{group, samples},
   24:          {group, wiki_wireshark_org},
   25:          {group, packetlife_net}].
   26: 
   27: groups() ->
   28:     [{samples, [parallel], [
   29:                             capture0000_test,
   30:                             capture0001_test,
   31:                             dns_test,
   32:                             dns_018_test
   33:                            ]},
   34: 
   35:      {packetlife_net, [parallel], [
   36:                                    open_network_connection_test,
   37:                                    gmail_test,
   38: %                                  address_withdrawal_ldp_test,
   39:                                    dns_question_and_answer_test
   40:                                   ]},
   41: 
   42:      {wiki_wireshark_org, [parallel], [
   43: %                                      http_littleendian_pcapng_test,
   44:                                        test001_test,
   45:                                        test002_test,
   46:                                        test003_test,
   47:                                        test004_test,
   48:                                        test005_test,
   49: %                                      test006_test,
   50: %                                      test007_test,
   51:                                        test008_test,
   52:                                        test009_test
   53: %                                      test010_test,
   54: %                                      icmp2_test
   55:                                       ]}].
   56: 
   57: init_per_suite(Config) ->
   58:     application:start(pcapng),
   59:     Config.
   60: 
   61: end_per_suite(Config) ->
   62:     Config.
   63: 
   64: parse(Config, Name) ->
   65:     pcapng:parse(read_file(Config, Name)).
   66: 
   67: read_file(Config, Name) ->
   68:     {ok, Packet} = file:read_file(filename:join(?config(data_dir, Config),
   69:                                                 Name)),
   70:     Packet.
   71: 
   72: capture0000_test(Config) ->
   73:     [#{type := section_header},
   74:      #{type := interface_description},
   75:      #{type := enhanced_packet_block},
   76:      #{type := interface_statistics}] = parse(Config, "capture0000.pcapng").
   77: 
   78: capture0001_test(Config) ->
   79:     [#{type := section_header},
   80:      #{type := interface_description} | _] = parse(Config,
   81:                                                    "capture0001.pcapng").
   82: 
   83: http_littleendian_pcapng_test(Config) ->
   84:     ok = parse(Config, "http.littleendian.pcapng").
   85: 
   86: test001_test(Config) ->
   87:     [#{major_version := 1,
   88:        minor_version := 0,
   89:        options := #{},
   90:        type := section_header}] = parse(Config, "test001.pcapng").
   91: 
   92: test002_test(Config) ->
   93:     [#{major_version := 1,
   94:        minor_version := 0,
   95:        options := #{},
   96:        type := section_header},
   97:      #{link_type := null,
   98:        options := #{},
   99:        snap_len := 0,
  100:        type := interface_description}] = parse(Config, "test002.pcapng").
  101: 
  102: test003_test(Config) ->
  103:     [#{major_version := 1,
  104:        minor_version := 0,
  105:        options := #{},
  106:        type := section_header},
  107:      #{link_type := 1240,
  108:        options := #{},
  109:        snap_len := 124,
  110:        type := interface_description}] = parse(Config, "test003.pcapng").
  111: 
  112: test004_test(Config) ->
  113:     [#{major_version := 1,
  114:        minor_version := 0,
  115:        options := #{shb_os := <<"Windows XP">>,
  116:                     shb_userappl := <<"Test004.exe">>},
  117:        type := section_header}] = parse(Config, "test004.pcapng").
  118: 
  119: test005_test(Config) ->
  120:     [#{major_version := 1,
  121:        minor_version := 0,
  122:        options := #{},
  123:        type := section_header},
  124:      #{link_type := 1240,
  125:        options := #{if_description := <<"Stupid ethernet interface">>,
  126:                     if_speed := <<0,228,11,84,2,0,0,0>>},
  127:        snap_len := 124,
  128:        type := interface_description}] = parse(Config, "test005.pcapng").
  129: 
  130: test006_test(Config) ->
  131:     ok = parse(Config, "test006.pcapng").
  132: 
  133: test007_test(Config) ->
  134:     ok = parse(Config, "test007.pcapng").
  135: 
  136: test008_test(Config) ->
  137:     [#{major_version := 1,
  138:        minor_version := 0,
  139:        options := #{opt_comment := <<"Hello world">>},
  140:        type := section_header},
  141:      #{link_type := 1240,
  142:        options := #{if_description := <<"Stupid ethernet interface">>,
  143:                     if_speed := <<0,228,11,84,2,0,0,0>>},
  144:        snap_len := 124,
  145:        type := interface_description},
  146:      #{major_version := 1,
  147:        minor_version := 0,
  148:        options := #{opt_comment := <<"Hello world">>},
  149:        type := section_header},
  150:      #{link_type := 1240,
  151:        options := #{if_description := <<"Stupid ethernet interface">>,
  152:                     if_speed := <<0,228,11,84,2,0,0,0>>},
  153:        snap_len := 124,
  154:        type := interface_description}] = parse(Config, "test008.pcapng").
  155: 
  156: test009_test(Config) ->
  157:     [#{major_version := 1,
  158:        minor_version := 0,
  159:        options := #{opt_comment := <<"Hello world">>},
  160:        type := section_header},
  161:      #{link_type := 1240,
  162:        options := #{if_description := <<"Stupid ethernet interface">>,
  163:                     if_speed := <<0,228,11,84,2,0,0,0>>},
  164:        snap_len := 124,
  165:        type := interface_description}] = parse(Config, "test009.pcapng").
  166: 
  167: test010_test(Config) ->
  168:     ok = parse(Config, "test010.pcapng").
  169: 
  170: open_network_connection_test(Config) ->
  171:     [#{type := section_header},
  172:      #{type := interface_description} | _] = parse(Config, "Open Network Connection.pcapng").
  173: 
  174: gmail_test(Config) ->
  175:     [#{type := section_header},
  176:      #{type := interface_description} | _] = parse(Config, "gmail.pcapng").
  177: 
  178: address_withdrawal_ldp_test(Config) ->
  179:     ok = parse(Config, "address withdrawal ldp.pcapng").
  180: 
  181: dns_question_and_answer_test(Config) ->
  182:     [#{type := section_header},
  183:      #{type := interface_description} | _]  = parse(Config, "DNS Question & Answer.pcapng").
  184: 
  185: icmp2_test(Config) ->
  186:     ok = parse(Config, "icmp2.pcapng").
  187: 
  188: dns_test(Config) ->
  189:     [#{type := section_header},
  190:      #{type := interface_description} | _] = parse(Config, "dns.pcapng").
  191: 
  192: dns_018_test(Config) ->
  193:     [#{type := section_header},
  194:      #{type := interface_description} | _] = parse(Config, "dns-018.pcapng").