trema 0.4.7 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +33 -54
- data/.hound.yml +3 -0
- data/.rspec +3 -0
- data/.rubocop.yml +17 -1
- data/.travis.yml +14 -18
- data/CHANGELOG.md +10 -0
- data/Gemfile +1 -26
- data/README.md +25 -241
- data/Rakefile +4 -1056
- data/bin/.gitignore +3 -0
- data/bin/trema +163 -237
- data/features/cleanup_on_failure.feature +118 -0
- data/features/logging.feature +73 -0
- data/features/open_flow13.feature +21 -0
- data/features/step_definitions/.gitignore +35 -0
- data/features/step_definitions/.rubocop.yml +5 -0
- data/features/step_definitions/.travis.yml +19 -0
- data/features/step_definitions/Gemfile +9 -0
- data/features/step_definitions/Guardfile +4 -0
- data/features/step_definitions/LICENSE +675 -0
- data/features/step_definitions/README.md +7 -0
- data/features/step_definitions/Rakefile +10 -0
- data/features/step_definitions/show_stats_steps.rb +56 -0
- data/features/step_definitions/virtual_link_steps.rb +8 -0
- data/features/support/env.rb +0 -73
- data/features/support/hooks.rb +6 -50
- data/features/trema_delete_link.feature +30 -0
- data/features/trema_killall.feature +56 -0
- data/features/trema_run.feature +47 -0
- data/features/trema_start.feature +73 -0
- data/features/trema_stop.feature +50 -0
- data/lib/trema.rb +4 -0
- data/lib/trema/command.rb +184 -0
- data/lib/trema/controller.rb +289 -0
- data/lib/trema/dirs.rb +14 -0
- data/lib/trema/drb.rb +32 -0
- data/lib/trema/logger.rb +63 -0
- data/lib/trema/monkey_patch/integer.rb +8 -0
- data/lib/trema/monkey_patch/integer/base_conversions.rb +12 -0
- data/lib/trema/monkey_patch/integer/durations.rb +12 -0
- data/lib/trema/switch.rb +83 -0
- data/lib/trema/version.rb +5 -0
- data/spec/spec_helper.rb +9 -178
- data/spec/trema/controller_spec.rb +4 -53
- data/tasks/.gitignore +34 -0
- data/tasks/LICENSE +675 -0
- data/tasks/README.md +6 -0
- data/tasks/cucumber.rake +14 -0
- data/tasks/flay.rake +15 -0
- data/tasks/flog.rake +25 -0
- data/tasks/gem.rake +15 -0
- data/tasks/reek.rake +11 -0
- data/tasks/relish.rake +8 -0
- data/tasks/rspec.rake +8 -0
- data/tasks/rubocop.rake +2 -16
- data/tasks/yard.rake +11 -0
- data/trema.gemspec +24 -23
- metadata +180 -720
- data/.yardopts +0 -4
- data/Doxyfile +0 -1679
- data/Guardfile +0 -14
- data/bin/quality +0 -31
- data/bin/trema-config +0 -59
- data/build.rb +0 -32
- data/cruise.rb +0 -409
- data/features/.nav +0 -50
- data/features/README.md +0 -7
- data/features/core/get_pid_by_trema_name.feature +0 -137
- data/features/core/packetin_filter.feature +0 -55
- data/features/core/switch_manager.feature +0 -41
- data/features/core/trema-config.feature +0 -55
- data/features/dsl/switch_port_specifier.feature +0 -15
- data/features/examples/dumper.feature +0 -35
- data/features/examples/hello_trema.feature +0 -23
- data/features/examples/learning_switch.feature +0 -37
- data/features/examples/list_switches.feature +0 -24
- data/features/examples/message.set_config.feature +0 -27
- data/features/examples/message.vendor-action.feature +0 -25
- data/features/examples/message.vendor-stats-request.feature +0 -20
- data/features/examples/multi_learning_switch.feature +0 -107
- data/features/examples/openflow_message.echo.feature +0 -59
- data/features/examples/openflow_message.features_request.feature +0 -35
- data/features/examples/openflow_message.hello.feature +0 -59
- data/features/examples/packet_in.feature +0 -33
- data/features/examples/packetin_filter_config.feature +0 -95
- data/features/examples/patch_panel.feature +0 -29
- data/features/examples/repeater_hub.feature +0 -52
- data/features/examples/switch_info.feature +0 -51
- data/features/examples/switch_monitor.feature +0 -35
- data/features/examples/transparent_firewall.feature +0 -73
- data/features/handlers/switch_ready.feature +0 -40
- data/features/step_definitions/misc_steps.rb +0 -85
- data/features/step_definitions/send_packets_steps.rb +0 -33
- data/features/step_definitions/stats_steps.rb +0 -39
- data/features/switch_event/C-add_forward_entry.feature +0 -114
- data/features/switch_event/C-delete_forward_entry.feature +0 -85
- data/features/switch_event/C-dump_forward_entries.feature +0 -72
- data/features/switch_event/C-set_forward_entries.feature +0 -77
- data/features/switch_event/README.md +0 -40
- data/features/switch_event/add_forward_entry.feature +0 -160
- data/features/switch_event/delete_forward_entry.feature +0 -160
- data/features/switch_event/dump_forward_entries.feature +0 -103
- data/features/switch_event/set_forward_entries.feature +0 -102
- data/features/trema_commands/README.md +0 -8
- data/features/trema_commands/dump_flows.feature +0 -41
- data/features/trema_commands/help.feature +0 -27
- data/features/trema_commands/help_option.feature +0 -20
- data/features/trema_commands/kill.feature +0 -56
- data/features/trema_commands/killall.feature +0 -32
- data/features/trema_commands/port_down.feature +0 -71
- data/features/trema_commands/port_up.feature +0 -75
- data/features/trema_commands/reset_stats.feature +0 -56
- data/features/trema_commands/run.feature +0 -56
- data/features/trema_commands/send_packets.feature +0 -46
- data/features/trema_commands/show_stats.feature +0 -66
- data/features/trema_commands/up.feature +0 -34
- data/features/trema_commands/version.feature +0 -10
- data/features/trema_commands/version_option.feature +0 -8
- data/rubocop-todo.yml +0 -159
- data/ruby/.gitignore +0 -4
- data/ruby/blocker.rb +0 -74
- data/ruby/extconf.rb +0 -80
- data/ruby/sub-process.rb +0 -289
- data/ruby/trema/action-common.c +0 -46
- data/ruby/trema/action-common.h +0 -38
- data/ruby/trema/action.rb +0 -33
- data/ruby/trema/aggregate-stats-reply.rb +0 -68
- data/ruby/trema/app.rb +0 -114
- data/ruby/trema/barrier-reply.c +0 -98
- data/ruby/trema/barrier-reply.h +0 -44
- data/ruby/trema/barrier-request.c +0 -135
- data/ruby/trema/barrier-request.h +0 -42
- data/ruby/trema/cli.rb +0 -267
- data/ruby/trema/command.rb +0 -41
- data/ruby/trema/command/dump_flows.rb +0 -43
- data/ruby/trema/command/kill.rb +0 -75
- data/ruby/trema/command/killall.rb +0 -38
- data/ruby/trema/command/netns.rb +0 -38
- data/ruby/trema/command/port_down.rb +0 -43
- data/ruby/trema/command/port_up.rb +0 -43
- data/ruby/trema/command/reset_stats.rb +0 -41
- data/ruby/trema/command/ruby.rb +0 -38
- data/ruby/trema/command/run.rb +0 -110
- data/ruby/trema/command/send_packets.rb +0 -46
- data/ruby/trema/command/shell.rb +0 -57
- data/ruby/trema/command/show_stats.rb +0 -65
- data/ruby/trema/command/up.rb +0 -44
- data/ruby/trema/command/version.rb +0 -35
- data/ruby/trema/compat.h +0 -36
- data/ruby/trema/controller.c +0 -691
- data/ruby/trema/controller.h +0 -42
- data/ruby/trema/controller.rb +0 -255
- data/ruby/trema/custom-switch.rb +0 -56
- data/ruby/trema/daemon.rb +0 -184
- data/ruby/trema/default-logger.c +0 -161
- data/ruby/trema/default-logger.h +0 -42
- data/ruby/trema/default-logger.rb +0 -29
- data/ruby/trema/default_openflow_channel_port.rb +0 -26
- data/ruby/trema/desc-stats-reply.rb +0 -75
- data/ruby/trema/dsl.rb +0 -32
- data/ruby/trema/dsl/configuration.rb +0 -145
- data/ruby/trema/dsl/context.rb +0 -69
- data/ruby/trema/dsl/custom-switch.rb +0 -44
- data/ruby/trema/dsl/link.rb +0 -39
- data/ruby/trema/dsl/netns.rb +0 -78
- data/ruby/trema/dsl/parser.rb +0 -70
- data/ruby/trema/dsl/rswitch.rb +0 -47
- data/ruby/trema/dsl/run.rb +0 -47
- data/ruby/trema/dsl/runner.rb +0 -178
- data/ruby/trema/dsl/stanza.rb +0 -51
- data/ruby/trema/dsl/switch.rb +0 -76
- data/ruby/trema/dsl/syntax-error.rb +0 -31
- data/ruby/trema/dsl/syntax.rb +0 -128
- data/ruby/trema/dsl/vhost.rb +0 -106
- data/ruby/trema/dsl/vswitch.rb +0 -45
- data/ruby/trema/echo-reply.c +0 -122
- data/ruby/trema/echo-reply.h +0 -40
- data/ruby/trema/echo-request.c +0 -117
- data/ruby/trema/echo-request.h +0 -40
- data/ruby/trema/echo.c +0 -99
- data/ruby/trema/echo.h +0 -39
- data/ruby/trema/enqueue.rb +0 -87
- data/ruby/trema/error.c +0 -262
- data/ruby/trema/error.h +0 -42
- data/ruby/trema/exact-match.rb +0 -34
- data/ruby/trema/executables.rb +0 -99
- data/ruby/trema/features-reply.c +0 -330
- data/ruby/trema/features-reply.h +0 -54
- data/ruby/trema/features-request.c +0 -134
- data/ruby/trema/features-request.h +0 -42
- data/ruby/trema/flow-mod.c +0 -150
- data/ruby/trema/flow-mod.h +0 -42
- data/ruby/trema/flow-removed.c +0 -280
- data/ruby/trema/flow-removed.h +0 -44
- data/ruby/trema/flow-stats-reply.rb +0 -107
- data/ruby/trema/flow.rb +0 -65
- data/ruby/trema/get-config-reply.c +0 -158
- data/ruby/trema/get-config-reply.h +0 -50
- data/ruby/trema/get-config-request.c +0 -136
- data/ruby/trema/get-config-request.h +0 -42
- data/ruby/trema/hardware-switch.rb +0 -86
- data/ruby/trema/hello.c +0 -133
- data/ruby/trema/hello.h +0 -42
- data/ruby/trema/host.rb +0 -263
- data/ruby/trema/link.rb +0 -177
- data/ruby/trema/list-switches-reply.c +0 -44
- data/ruby/trema/list-switches-reply.h +0 -38
- data/ruby/trema/mac.rb +0 -29
- data/ruby/trema/match.c +0 -621
- data/ruby/trema/match.h +0 -34
- data/ruby/trema/monkey-patch/integer.rb +0 -35
- data/ruby/trema/monkey-patch/integer/base-conversions.rb +0 -34
- data/ruby/trema/monkey-patch/integer/ranges.rb +0 -49
- data/ruby/trema/monkey-patch/integer/validators.rb +0 -36
- data/ruby/trema/monkey-patch/module.rb +0 -33
- data/ruby/trema/monkey-patch/module/class-method.rb +0 -38
- data/ruby/trema/monkey-patch/module/deprecation.rb +0 -39
- data/ruby/trema/monkey-patch/string.rb +0 -31
- data/ruby/trema/monkey-patch/string/inflectors.rb +0 -52
- data/ruby/trema/netns.rb +0 -127
- data/ruby/trema/network-component.rb +0 -151
- data/ruby/trema/ofctl.rb +0 -70
- data/ruby/trema/open-vswitch.rb +0 -160
- data/ruby/trema/openflow-error.c +0 -193
- data/ruby/trema/openflow-error.h +0 -51
- data/ruby/trema/openflow-switch.rb +0 -35
- data/ruby/trema/ordered-hash.rb +0 -75
- data/ruby/trema/packet-in.c +0 -1365
- data/ruby/trema/packet-in.h +0 -44
- data/ruby/trema/packet-queue.rb +0 -181
- data/ruby/trema/packetin-filter.rb +0 -124
- data/ruby/trema/path.rb +0 -85
- data/ruby/trema/phost.rb +0 -76
- data/ruby/trema/port-mod.c +0 -232
- data/ruby/trema/port-mod.h +0 -34
- data/ruby/trema/port-stats-reply.rb +0 -109
- data/ruby/trema/port-status-add.rb +0 -60
- data/ruby/trema/port-status-delete.rb +0 -60
- data/ruby/trema/port-status-modify.rb +0 -60
- data/ruby/trema/port-status.c +0 -192
- data/ruby/trema/port-status.h +0 -41
- data/ruby/trema/port.c +0 -398
- data/ruby/trema/port.h +0 -45
- data/ruby/trema/process.rb +0 -103
- data/ruby/trema/queue-get-config-reply.c +0 -205
- data/ruby/trema/queue-get-config-reply.h +0 -45
- data/ruby/trema/queue-get-config-request.c +0 -141
- data/ruby/trema/queue-get-config-request.h +0 -42
- data/ruby/trema/queue-stats-reply.rb +0 -76
- data/ruby/trema/ruby-switch.rb +0 -62
- data/ruby/trema/send-out-port.rb +0 -113
- data/ruby/trema/set-config.c +0 -174
- data/ruby/trema/set-config.h +0 -42
- data/ruby/trema/set-eth-addr.rb +0 -54
- data/ruby/trema/set-eth-dst-addr.rb +0 -52
- data/ruby/trema/set-eth-src-addr.rb +0 -53
- data/ruby/trema/set-ip-addr.rb +0 -54
- data/ruby/trema/set-ip-dst-addr.rb +0 -53
- data/ruby/trema/set-ip-src-addr.rb +0 -52
- data/ruby/trema/set-ip-tos.rb +0 -64
- data/ruby/trema/set-transport-dst-port.rb +0 -53
- data/ruby/trema/set-transport-port.rb +0 -53
- data/ruby/trema/set-transport-src-port.rb +0 -54
- data/ruby/trema/set-vlan-priority.rb +0 -66
- data/ruby/trema/set-vlan-vid.rb +0 -65
- data/ruby/trema/shell.rb +0 -37
- data/ruby/trema/shell/down.rb +0 -37
- data/ruby/trema/shell/killall.rb +0 -38
- data/ruby/trema/shell/link.rb +0 -59
- data/ruby/trema/shell/reset_stats.rb +0 -49
- data/ruby/trema/shell/run.rb +0 -67
- data/ruby/trema/shell/send_packets.rb +0 -40
- data/ruby/trema/shell/show_stats.rb +0 -47
- data/ruby/trema/shell/up.rb +0 -41
- data/ruby/trema/shell/vhost.rb +0 -42
- data/ruby/trema/shell/vswitch.rb +0 -47
- data/ruby/trema/stats-helper.rb +0 -63
- data/ruby/trema/stats-reply.c +0 -540
- data/ruby/trema/stats-reply.h +0 -51
- data/ruby/trema/stats-request.c +0 -715
- data/ruby/trema/stats-request.h +0 -40
- data/ruby/trema/strip-vlan-header.rb +0 -41
- data/ruby/trema/switch-daemon.rb +0 -90
- data/ruby/trema/switch-disconnected.c +0 -38
- data/ruby/trema/switch-disconnected.h +0 -36
- data/ruby/trema/switch-event.c +0 -648
- data/ruby/trema/switch-event.h +0 -27
- data/ruby/trema/switch-manager.rb +0 -119
- data/ruby/trema/switch.c +0 -197
- data/ruby/trema/switch.h +0 -40
- data/ruby/trema/switch.rb +0 -56
- data/ruby/trema/table-stats-reply.rb +0 -85
- data/ruby/trema/timers.rb +0 -95
- data/ruby/trema/trema-ruby-utils.c +0 -66
- data/ruby/trema/trema-ruby-utils.h +0 -42
- data/ruby/trema/trema.c +0 -126
- data/ruby/trema/tremashark.rb +0 -46
- data/ruby/trema/util.rb +0 -116
- data/ruby/trema/vendor-action.rb +0 -82
- data/ruby/trema/vendor-stats-reply.rb +0 -64
- data/ruby/trema/vendor.c +0 -230
- data/ruby/trema/vendor.h +0 -48
- data/ruby/trema/version.rb +0 -28
- data/spec/support/action.rb +0 -49
- data/spec/support/mandatory-option.rb +0 -53
- data/spec/support/matchers/constant.rb +0 -25
- data/spec/support/openflow-message.rb +0 -173
- data/spec/support/port-status.rb +0 -35
- data/spec/trema/app_spec.rb +0 -88
- data/spec/trema/barrier-reply_spec.rb +0 -43
- data/spec/trema/barrier-request_spec.rb +0 -92
- data/spec/trema/cli_spec.rb +0 -156
- data/spec/trema/default-logger_spec.rb +0 -46
- data/spec/trema/dsl/configuration_spec.rb +0 -120
- data/spec/trema/dsl/link_spec.rb +0 -50
- data/spec/trema/dsl/run_spec.rb +0 -72
- data/spec/trema/dsl/runner_spec.rb +0 -247
- data/spec/trema/dsl/switch_spec.rb +0 -69
- data/spec/trema/dsl/syntax_spec.rb +0 -110
- data/spec/trema/dsl/vhost_spec.rb +0 -144
- data/spec/trema/dsl/vswitch_spec.rb +0 -80
- data/spec/trema/echo-reply_spec.rb +0 -84
- data/spec/trema/echo-request_spec.rb +0 -128
- data/spec/trema/enqueue_spec.rb +0 -76
- data/spec/trema/error_spec.rb +0 -81
- data/spec/trema/executables_spec.rb +0 -54
- data/spec/trema/features-reply_spec.rb +0 -91
- data/spec/trema/features-request_spec.rb +0 -93
- data/spec/trema/flow-mod_spec.rb +0 -99
- data/spec/trema/flow-removed_spec.rb +0 -144
- data/spec/trema/get-config-reply_spec.rb +0 -43
- data/spec/trema/get-config-request_spec.rb +0 -92
- data/spec/trema/hardware-switch_spec.rb +0 -54
- data/spec/trema/hello_spec.rb +0 -63
- data/spec/trema/host_spec.rb +0 -191
- data/spec/trema/link_spec.rb +0 -62
- data/spec/trema/list-switches-reply_spec.rb +0 -46
- data/spec/trema/match_spec.rb +0 -111
- data/spec/trema/open-vswitch_spec.rb +0 -121
- data/spec/trema/openflow-error_spec.rb +0 -141
- data/spec/trema/packet-in_spec.rb +0 -717
- data/spec/trema/packet-out_spec.rb +0 -125
- data/spec/trema/packetin-filter_spec.rb +0 -39
- data/spec/trema/port-mod_spec.rb +0 -98
- data/spec/trema/port-status-add_spec.rb +0 -32
- data/spec/trema/port-status-delete_spec.rb +0 -32
- data/spec/trema/port-status-modify_spec.rb +0 -71
- data/spec/trema/port-status_spec.rb +0 -38
- data/spec/trema/port_spec.rb +0 -59
- data/spec/trema/process_spec.rb +0 -69
- data/spec/trema/queue-get-config-reply_spec.rb +0 -65
- data/spec/trema/queue-get-config-request_spec.rb +0 -67
- data/spec/trema/send-out-port_spec.rb +0 -106
- data/spec/trema/set-config_spec.rb +0 -78
- data/spec/trema/set-eth-addr_spec.rb +0 -62
- data/spec/trema/set-ip-addr_spec.rb +0 -81
- data/spec/trema/set-ip-tos_spec.rb +0 -70
- data/spec/trema/set-transport-dst-port_spec.rb +0 -65
- data/spec/trema/set-transport-src-port_spec.rb +0 -65
- data/spec/trema/set-vlan-priority_spec.rb +0 -65
- data/spec/trema/set-vlan-vid_spec.rb +0 -65
- data/spec/trema/shell/vhost_spec.rb +0 -58
- data/spec/trema/shell/vswitch_spec.rb +0 -87
- data/spec/trema/stats-reply_spec.rb +0 -363
- data/spec/trema/stats-request_spec.rb +0 -166
- data/spec/trema/strip-vlan-header_spec.rb +0 -44
- data/spec/trema/switch-daemon_spec.rb +0 -81
- data/spec/trema/switch-disconnected_spec.rb +0 -56
- data/spec/trema/switch-manager_spec.rb +0 -41
- data/spec/trema/tremashark_spec.rb +0 -39
- data/spec/trema/util_spec.rb +0 -88
- data/spec/trema/vendor-action_spec.rb +0 -75
- data/spec/trema/vendor_spec.rb +0 -76
- data/spec/trema_spec.rb +0 -94
- data/src/examples/cbench_switch/README +0 -21
- data/src/examples/cbench_switch/cbench-switch.rb +0 -38
- data/src/examples/cbench_switch/cbench_switch.c +0 -66
- data/src/examples/dumper/dumper.c +0 -362
- data/src/examples/dumper/dumper.conf +0 -7
- data/src/examples/dumper/dumper.rb +0 -195
- data/src/examples/hello_trema/.gitignore +0 -2
- data/src/examples/hello_trema/README.md +0 -2
- data/src/examples/hello_trema/hello-trema.rb +0 -30
- data/src/examples/hello_trema/hello_trema.c +0 -48
- data/src/examples/hello_trema/sample.conf +0 -1
- data/src/examples/learning_switch/README +0 -15
- data/src/examples/learning_switch/fdb.rb +0 -110
- data/src/examples/learning_switch/learning-switch.rb +0 -90
- data/src/examples/learning_switch/learning_switch.c +0 -217
- data/src/examples/learning_switch/learning_switch.conf +0 -18
- data/src/examples/list_switches/README +0 -19
- data/src/examples/list_switches/list-switches.rb +0 -43
- data/src/examples/list_switches/list_switches.c +0 -79
- data/src/examples/list_switches/list_switches.conf +0 -15
- data/src/examples/match_compare/match-compare.conf +0 -30
- data/src/examples/match_compare/match-compare.rb +0 -97
- data/src/examples/multi_learning_switch/README +0 -14
- data/src/examples/multi_learning_switch/multi-learning-switch.rb +0 -94
- data/src/examples/multi_learning_switch/multi_learning_switch.c +0 -294
- data/src/examples/multi_learning_switch/multi_learning_switch.conf +0 -17
- data/src/examples/openflow_message/README +0 -11
- data/src/examples/openflow_message/echo.c +0 -80
- data/src/examples/openflow_message/echo.rb +0 -56
- data/src/examples/openflow_message/example.rb +0 -60
- data/src/examples/openflow_message/features-request.rb +0 -96
- data/src/examples/openflow_message/features_request.c +0 -167
- data/src/examples/openflow_message/hello.c +0 -68
- data/src/examples/openflow_message/hello.rb +0 -43
- data/src/examples/openflow_message/set-config.rb +0 -57
- data/src/examples/openflow_message/set_config.c +0 -68
- data/src/examples/openflow_message/vendor-action.rb +0 -43
- data/src/examples/openflow_message/vendor-stats-request.rb +0 -66
- data/src/examples/openflow_message/vendor_action.c +0 -103
- data/src/examples/openflow_switch/echo_switch.c +0 -89
- data/src/examples/openflow_switch/hello_switch.c +0 -85
- data/src/examples/packet_in/README +0 -15
- data/src/examples/packet_in/packet-in.rb +0 -37
- data/src/examples/packet_in/packet_in.c +0 -53
- data/src/examples/packet_in/packet_in.conf +0 -15
- data/src/examples/packetin_filter_config/README +0 -12
- data/src/examples/packetin_filter_config/add_filter.c +0 -71
- data/src/examples/packetin_filter_config/delete_filter.c +0 -63
- data/src/examples/packetin_filter_config/delete_filter_strict.c +0 -73
- data/src/examples/packetin_filter_config/dump_filter.c +0 -63
- data/src/examples/packetin_filter_config/dump_filter_strict.c +0 -73
- data/src/examples/packetin_filter_config/packetin_filter_config.c +0 -132
- data/src/examples/packetin_filter_config/packetin_filter_config.conf +0 -7
- data/src/examples/packetin_filter_config/utils.c +0 -100
- data/src/examples/packetin_filter_config/utils.h +0 -40
- data/src/examples/patch_panel/network.conf +0 -14
- data/src/examples/patch_panel/patch-panel.conf +0 -1
- data/src/examples/patch_panel/patch-panel.rb +0 -59
- data/src/examples/repeater_hub/README +0 -8
- data/src/examples/repeater_hub/repeater-hub.rb +0 -41
- data/src/examples/repeater_hub/repeater-hub_spec.rb +0 -154
- data/src/examples/repeater_hub/repeater_hub.c +0 -81
- data/src/examples/repeater_hub/repeater_hub.conf +0 -28
- data/src/examples/simple_router/README +0 -18
- data/src/examples/simple_router/arp-table.rb +0 -81
- data/src/examples/simple_router/interface.rb +0 -90
- data/src/examples/simple_router/routing-table.rb +0 -60
- data/src/examples/simple_router/simple-router.rb +0 -191
- data/src/examples/simple_router/simple_router.conf +0 -24
- data/src/examples/simple_router/simple_router_netns.conf +0 -15
- data/src/examples/simple_router/simple_router_network.conf +0 -6
- data/src/examples/switch_event_config/.gitignore +0 -6
- data/src/examples/switch_event_config/add_forward_entry.c +0 -227
- data/src/examples/switch_event_config/delete_forward_entry.c +0 -226
- data/src/examples/switch_event_config/dump_forward_entries.c +0 -190
- data/src/examples/switch_event_config/network.conf +0 -2
- data/src/examples/switch_event_config/set_forward_entries.c +0 -210
- data/src/examples/switch_info/README +0 -13
- data/src/examples/switch_info/switch-info.rb +0 -44
- data/src/examples/switch_info/switch_info.c +0 -78
- data/src/examples/switch_info/switch_info.conf +0 -3
- data/src/examples/switch_monitor/switch-monitor.conf +0 -3
- data/src/examples/switch_monitor/switch-monitor.rb +0 -56
- data/src/examples/switch_monitor/switch_monitor.c +0 -152
- data/src/examples/traffic_monitor/counter.c +0 -72
- data/src/examples/traffic_monitor/counter.h +0 -46
- data/src/examples/traffic_monitor/counter.rb +0 -44
- data/src/examples/traffic_monitor/fdb.c +0 -74
- data/src/examples/traffic_monitor/fdb.h +0 -48
- data/src/examples/traffic_monitor/fdb.rb +0 -42
- data/src/examples/traffic_monitor/traffic-monitor.rb +0 -98
- data/src/examples/traffic_monitor/traffic_monitor.c +0 -161
- data/src/examples/traffic_monitor/traffic_monitor.conf +0 -16
- data/src/examples/transparent_firewall/README.md +0 -61
- data/src/examples/transparent_firewall/aggregated-delegated-afrinic.txt +0 -713
- data/src/examples/transparent_firewall/aggregated-delegated-apnic.txt +0 -3440
- data/src/examples/transparent_firewall/aggregated-delegated-arin.txt +0 -11342
- data/src/examples/transparent_firewall/aggregated-delegated-lacnic.txt +0 -1937
- data/src/examples/transparent_firewall/aggregated-delegated-ripencc.txt +0 -7329
- data/src/examples/transparent_firewall/block-rfc1918.rb +0 -86
- data/src/examples/transparent_firewall/pass-delegated.rb +0 -178
- data/src/examples/transparent_firewall/regen_aggregated.sh +0 -53
- data/src/examples/transparent_firewall/stats-to-cidrs.rb +0 -59
- data/src/lib/arp.h +0 -64
- data/src/lib/bool.h +0 -47
- data/src/lib/buffer.c +0 -304
- data/src/lib/buffer.h +0 -54
- data/src/lib/byteorder.c +0 -571
- data/src/lib/byteorder.h +0 -108
- data/src/lib/checks.h +0 -40
- data/src/lib/chibach.c +0 -392
- data/src/lib/chibach.h +0 -69
- data/src/lib/chibach_private.c +0 -168
- data/src/lib/chibach_private.h +0 -50
- data/src/lib/daemon.c +0 -429
- data/src/lib/daemon.h +0 -40
- data/src/lib/doubly_linked_list.c +0 -284
- data/src/lib/doubly_linked_list.h +0 -86
- data/src/lib/ether.c +0 -47
- data/src/lib/ether.h +0 -92
- data/src/lib/etherip.h +0 -44
- data/src/lib/event_forward_interface.c +0 -788
- data/src/lib/event_forward_interface.h +0 -138
- data/src/lib/event_handler.c +0 -419
- data/src/lib/event_handler.h +0 -57
- data/src/lib/external_callback.c +0 -126
- data/src/lib/external_callback.h +0 -46
- data/src/lib/hash_table.c +0 -415
- data/src/lib/hash_table.h +0 -136
- data/src/lib/icmp.h +0 -72
- data/src/lib/igmp.h +0 -48
- data/src/lib/ipv4.h +0 -64
- data/src/lib/ipv6.h +0 -46
- data/src/lib/linked_list.c +0 -244
- data/src/lib/linked_list.h +0 -84
- data/src/lib/log.c +0 -636
- data/src/lib/log.h +0 -77
- data/src/lib/management_interface.c +0 -359
- data/src/lib/management_interface.h +0 -40
- data/src/lib/management_service_interface.c +0 -102
- data/src/lib/management_service_interface.h +0 -134
- data/src/lib/match.h +0 -82
- data/src/lib/match_table.c +0 -606
- data/src/lib/match_table.h +0 -49
- data/src/lib/message_queue.c +0 -143
- data/src/lib/message_queue.h +0 -59
- data/src/lib/messenger.c +0 -1821
- data/src/lib/messenger.h +0 -145
- data/src/lib/openflow_application_interface.c +0 -1800
- data/src/lib/openflow_application_interface.h +0 -359
- data/src/lib/openflow_message.c +0 -4240
- data/src/lib/openflow_message.h +0 -291
- data/src/lib/openflow_service_interface.h +0 -58
- data/src/lib/openflow_switch_interface.c +0 -1378
- data/src/lib/openflow_switch_interface.h +0 -262
- data/src/lib/packet_info.c +0 -336
- data/src/lib/packet_info.h +0 -233
- data/src/lib/packet_parser.c +0 -522
- data/src/lib/packetin_filter_interface.c +0 -292
- data/src/lib/packetin_filter_interface.h +0 -125
- data/src/lib/persistent_storage.c +0 -478
- data/src/lib/persistent_storage.h +0 -44
- data/src/lib/secure_channel.c +0 -496
- data/src/lib/secure_channel.h +0 -43
- data/src/lib/stat.c +0 -248
- data/src/lib/stat.h +0 -51
- data/src/lib/tcp.h +0 -62
- data/src/lib/timer.c +0 -349
- data/src/lib/timer.h +0 -51
- data/src/lib/trema.c +0 -776
- data/src/lib/trema.h +0 -80
- data/src/lib/trema.hpp +0 -49
- data/src/lib/trema_private.c +0 -175
- data/src/lib/trema_private.h +0 -64
- data/src/lib/trema_wrapper.c +0 -59
- data/src/lib/trema_wrapper.h +0 -66
- data/src/lib/udp.h +0 -41
- data/src/lib/utility.c +0 -625
- data/src/lib/utility.h +0 -84
- data/src/lib/wrapper.c +0 -121
- data/src/lib/wrapper.h +0 -76
- data/src/management/application.c +0 -222
- data/src/management/echo.c +0 -183
- data/src/management/set_logging_level.c +0 -151
- data/src/management/show_stats.c +0 -148
- data/src/management/trema_manager +0 -184
- data/src/packetin_filter/README +0 -17
- data/src/packetin_filter/packetin_filter.c +0 -575
- data/src/switch_manager/README +0 -20
- data/src/switch_manager/cookie_table.c +0 -290
- data/src/switch_manager/cookie_table.h +0 -70
- data/src/switch_manager/dpid_table.c +0 -108
- data/src/switch_manager/dpid_table.h +0 -43
- data/src/switch_manager/event_forward_entry_manipulation.c +0 -120
- data/src/switch_manager/event_forward_entry_manipulation.h +0 -31
- data/src/switch_manager/ofpmsg_recv.c +0 -497
- data/src/switch_manager/ofpmsg_recv.h +0 -39
- data/src/switch_manager/ofpmsg_send.c +0 -274
- data/src/switch_manager/ofpmsg_send.h +0 -51
- data/src/switch_manager/secure_channel_listener.c +0 -296
- data/src/switch_manager/secure_channel_listener.h +0 -40
- data/src/switch_manager/secure_channel_receiver.c +0 -129
- data/src/switch_manager/secure_channel_receiver.h +0 -40
- data/src/switch_manager/secure_channel_sender.c +0 -131
- data/src/switch_manager/secure_channel_sender.h +0 -41
- data/src/switch_manager/service_interface.c +0 -180
- data/src/switch_manager/service_interface.h +0 -44
- data/src/switch_manager/switch.c +0 -988
- data/src/switch_manager/switch.h +0 -50
- data/src/switch_manager/switch_manager.c +0 -643
- data/src/switch_manager/switch_manager.h +0 -65
- data/src/switch_manager/switch_option.c +0 -30
- data/src/switch_manager/switch_option.h +0 -41
- data/src/switch_manager/switchinfo.h +0 -81
- data/src/switch_manager/xid_table.c +0 -182
- data/src/switch_manager/xid_table.h +0 -53
- data/src/tremashark/README +0 -79
- data/src/tremashark/packet_capture.c +0 -358
- data/src/tremashark/pcap_private.h +0 -45
- data/src/tremashark/pcap_queue.c +0 -195
- data/src/tremashark/pcap_queue.h +0 -56
- data/src/tremashark/plugin/.gitignore +0 -6
- data/src/tremashark/plugin/packet-trema/.gitignore +0 -5
- data/src/tremashark/plugin/packet-trema/Makefile +0 -77
- data/src/tremashark/plugin/packet-trema/Makefile.am +0 -110
- data/src/tremashark/plugin/packet-trema/Makefile.common +0 -29
- data/src/tremashark/plugin/packet-trema/moduleinfo.h +0 -39
- data/src/tremashark/plugin/packet-trema/packet-trema.c +0 -1671
- data/src/tremashark/plugin/packet-trema/plugin.c +0 -31
- data/src/tremashark/plugin/user_dlts +0 -2
- data/src/tremashark/queue.c +0 -167
- data/src/tremashark/queue.h +0 -58
- data/src/tremashark/stdin_relay.c +0 -257
- data/src/tremashark/syslog_relay.c +0 -247
- data/src/tremashark/tremashark.c +0 -554
- data/trema +0 -11
- data/trema-config +0 -11
- data/unittests/buffer_stubs.c +0 -72
- data/unittests/cmockery_trema.c +0 -121
- data/unittests/cmockery_trema.h +0 -95
- data/unittests/lib/buffer_test.c +0 -368
- data/unittests/lib/byteorder_test.c +0 -1798
- data/unittests/lib/daemon_test.c +0 -804
- data/unittests/lib/doubly_linked_list_test.c +0 -348
- data/unittests/lib/ether_test.c +0 -125
- data/unittests/lib/event_forward_interface_test.c +0 -1676
- data/unittests/lib/external_callback_test.c +0 -282
- data/unittests/lib/hash_table_test.c +0 -278
- data/unittests/lib/linked_list_test.c +0 -434
- data/unittests/lib/log_test.c +0 -672
- data/unittests/lib/management_interface_test.c +0 -238
- data/unittests/lib/management_service_interface_test.c +0 -317
- data/unittests/lib/match_table_test.c +0 -1507
- data/unittests/lib/message_queue_test.c +0 -381
- data/unittests/lib/messenger_test.c +0 -623
- data/unittests/lib/openflow_application_interface_test.c +0 -3713
- data/unittests/lib/openflow_message_test.c +0 -8047
- data/unittests/lib/packet_info_test.c +0 -558
- data/unittests/lib/packet_parser_test.c +0 -784
- data/unittests/lib/packetin_filter_interface_test.c +0 -721
- data/unittests/lib/persistent_storage_test.c +0 -800
- data/unittests/lib/stat_test.c +0 -433
- data/unittests/lib/test_packets/arp_rep.cap +0 -0
- data/unittests/lib/test_packets/arp_req.cap +0 -0
- data/unittests/lib/test_packets/icmp6_echo_rep.cap +0 -0
- data/unittests/lib/test_packets/icmp6_echo_req.cap +0 -0
- data/unittests/lib/test_packets/icmp_echo_rep.cap +0 -0
- data/unittests/lib/test_packets/icmp_echo_req.cap +0 -0
- data/unittests/lib/test_packets/igmp_query_v2.cap +0 -0
- data/unittests/lib/test_packets/ipx.cap +0 -0
- data/unittests/lib/test_packets/lldp.cap +0 -0
- data/unittests/lib/test_packets/lldp_over_ip.cap +0 -0
- data/unittests/lib/test_packets/rarp_req.cap +0 -0
- data/unittests/lib/test_packets/tcp.cap +0 -0
- data/unittests/lib/test_packets/tcp_syn.cap +0 -0
- data/unittests/lib/test_packets/udp.cap +0 -0
- data/unittests/lib/test_packets/udp_frag_head.cap +0 -0
- data/unittests/lib/test_packets/udp_frag_next.cap +0 -0
- data/unittests/lib/test_packets/vtag_icmp_echo_rep.cap +0 -0
- data/unittests/lib/test_packets/vtag_icmp_echo_req.cap +0 -0
- data/unittests/lib/timer_test.c +0 -246
- data/unittests/lib/trema_private_test.c +0 -321
- data/unittests/lib/trema_test.c +0 -1030
- data/unittests/lib/utility_test.c +0 -711
- data/unittests/lib/wrapper_test.c +0 -228
- data/unittests/packetin_filter/packetin_filter_test.c +0 -476
- data/unittests/switch_manager/switch_manager_test.c +0 -1183
- data/unittests/wrapper_stubs.c +0 -37
- data/vendor/.gitignore +0 -6
- data/vendor/README.md +0 -29
- data/vendor/cmockery-20110428.tar.gz +0 -0
- data/vendor/oflops-0.03.trema1.tar.gz +0 -0
- data/vendor/oflops_no_snmp+1.0.0.diff +0 -340
- data/vendor/openflow-1.0.0.tar.gz +0 -0
- data/vendor/openflow.git.tar.gz +0 -0
- data/vendor/openvswitch-1.2.2.trema1.tar.gz +0 -0
- data/vendor/openvswitch-1.2.2_librt-check.diff +0 -21
- data/vendor/packet-openflow.diff +0 -13
- data/vendor/ruby-ifconfig-1.2/COPYING +0 -340
- data/vendor/ruby-ifconfig-1.2/Changelog +0 -16
- data/vendor/ruby-ifconfig-1.2/INSTALL +0 -239
- data/vendor/ruby-ifconfig-1.2/README +0 -38
- data/vendor/ruby-ifconfig-1.2/Rakefile +0 -14
- data/vendor/ruby-ifconfig-1.2/TODO +0 -8
- data/vendor/ruby-ifconfig-1.2/ifconfig_examples/darwin.txt +0 -17
- data/vendor/ruby-ifconfig-1.2/ifconfig_examples/dragonflybsd.txt +0 -10
- data/vendor/ruby-ifconfig-1.2/ifconfig_examples/dragonflybsd_netstat.txt +0 -14
- data/vendor/ruby-ifconfig-1.2/ifconfig_examples/freebsd.txt +0 -17
- data/vendor/ruby-ifconfig-1.2/ifconfig_examples/freebsd_netstat.txt +0 -24
- data/vendor/ruby-ifconfig-1.2/ifconfig_examples/linux.txt +0 -60
- data/vendor/ruby-ifconfig-1.2/ifconfig_examples/linux_ethernet.txt +0 -20
- data/vendor/ruby-ifconfig-1.2/ifconfig_examples/netbsd.txt +0 -10
- data/vendor/ruby-ifconfig-1.2/ifconfig_examples/openbsd.txt +0 -36
- data/vendor/ruby-ifconfig-1.2/ifconfig_examples/sunos.txt +0 -10
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig.rb +0 -71
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/bsd/ifconfig.rb +0 -72
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/bsd/interface_types.rb +0 -69
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/bsd/network_types.rb +0 -3
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/common/ifconfig.rb +0 -84
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/common/interface_types.rb +0 -130
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/common/network_types.rb +0 -49
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/linux/ifconfig.rb +0 -43
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/linux/interface_types.rb +0 -112
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/linux/network_types.rb +0 -55
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/sunos/ifconfig.rb +0 -38
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/sunos/interface_types.rb +0 -77
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/sunos/network_types.rb +0 -4
- data/vendor/ruby-ifconfig-1.2/setup.rb +0 -1306
- data/vendor/ruby-ifconfig-1.2/test/test_bsd.rb +0 -35
- data/vendor/ruby-ifconfig-1.2/test/test_darwin.rb +0 -33
- data/vendor/ruby-ifconfig-1.2/test/test_dragonflybsd.rb +0 -35
- data/vendor/ruby-ifconfig-1.2/test/test_helper.rb +0 -4
- data/vendor/ruby-ifconfig-1.2/test/test_linux.rb +0 -31
- data/vendor/ruby-ifconfig-1.2/test/test_netbsd.rb +0 -33
- data/vendor/ruby-ifconfig-1.2/test/test_openbsd.rb +0 -33
- data/vendor/ruby-ifconfig-1.2/test/test_sunos.rb +0 -35
- data/vendor/ruby-ifconfig-1.2/test/unit/tc_darwin.rb +0 -40
- data/vendor/ruby-ifconfig-1.2/test/unit/tc_dragonflybsd.rb +0 -39
- data/vendor/ruby-ifconfig-1.2/test/unit/tc_freebsd.rb +0 -40
- data/vendor/ruby-ifconfig-1.2/test/unit/tc_linux.rb +0 -49
- data/vendor/ruby-ifconfig-1.2/test/unit/tc_netbsd.rb +0 -39
- data/vendor/ruby-ifconfig-1.2/test/unit/tc_openbsd.rb +0 -39
- data/vendor/ruby-ifconfig-1.2/test/unit/tc_sunos.rb +0 -44
@@ -1,3713 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Unit tests for OpenFlow Application Interface.
|
3
|
-
*
|
4
|
-
* Copyright (C) 2008-2013 NEC Corporation
|
5
|
-
*
|
6
|
-
* This program is free software; you can redistribute it and/or modify
|
7
|
-
* it under the terms of the GNU General Public License, version 2, as
|
8
|
-
* published by the Free Software Foundation.
|
9
|
-
*
|
10
|
-
* This program is distributed in the hope that it will be useful,
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
-
* GNU General Public License for more details.
|
14
|
-
*
|
15
|
-
* You should have received a copy of the GNU General Public License along
|
16
|
-
* with this program; if not, write to the Free Software Foundation, Inc.,
|
17
|
-
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
18
|
-
*/
|
19
|
-
|
20
|
-
|
21
|
-
#include <openflow.h>
|
22
|
-
#include <stdio.h>
|
23
|
-
#include <stdlib.h>
|
24
|
-
#include <string.h>
|
25
|
-
#include "bool.h"
|
26
|
-
#include "checks.h"
|
27
|
-
#include "cmockery_trema.h"
|
28
|
-
#include "hash_table.h"
|
29
|
-
#include "linked_list.h"
|
30
|
-
#include "log.h"
|
31
|
-
#include "messenger.h"
|
32
|
-
#include "openflow_application_interface.h"
|
33
|
-
#include "openflow_message.h"
|
34
|
-
#include "stat.h"
|
35
|
-
#include "wrapper.h"
|
36
|
-
|
37
|
-
|
38
|
-
/********************************************************************************
|
39
|
-
* Helpers.
|
40
|
-
********************************************************************************/
|
41
|
-
|
42
|
-
extern bool openflow_application_interface_initialized;
|
43
|
-
extern openflow_event_handlers_t event_handlers;
|
44
|
-
extern char service_name[ MESSENGER_SERVICE_NAME_LENGTH ];
|
45
|
-
extern hash_table *stats;
|
46
|
-
|
47
|
-
extern void assert_if_not_initialized();
|
48
|
-
extern void handle_error( const uint64_t datapath_id, buffer *data );
|
49
|
-
extern void handle_echo_reply( const uint64_t datapath_id, buffer *data );
|
50
|
-
extern void handle_vendor( const uint64_t datapath_id, buffer *data );
|
51
|
-
extern void handle_features_reply( const uint64_t datapath_id, buffer *data );
|
52
|
-
extern void handle_get_config_reply( const uint64_t datapath_id, buffer *data );
|
53
|
-
extern void handle_packet_in( const uint64_t datapath_id, buffer *data );
|
54
|
-
extern void handle_flow_removed( const uint64_t datapath_id, buffer *data );
|
55
|
-
extern void handle_port_status( const uint64_t datapath_id, buffer *data );
|
56
|
-
extern void handle_stats_reply( const uint64_t datapath_id, buffer *data );
|
57
|
-
extern void handle_barrier_reply( const uint64_t datapath_id, buffer *data );
|
58
|
-
extern void handle_queue_get_config_reply( const uint64_t datapath_id, buffer *data );
|
59
|
-
extern void dump_buf( const buffer *data );
|
60
|
-
extern void handle_switch_events( uint16_t type, void *data, size_t length );
|
61
|
-
extern void handle_openflow_message( void *data, size_t length );
|
62
|
-
extern void handle_message( uint16_t type, void *data, size_t length );
|
63
|
-
extern void insert_dpid( list_element **head, uint64_t *dpid );
|
64
|
-
extern void handle_list_switches_reply( uint16_t message_type, void *data, size_t length, void *user_data );
|
65
|
-
|
66
|
-
|
67
|
-
#define SWITCH_READY_HANDLER ( ( void * ) 0x00020001 )
|
68
|
-
#define SWITCH_READY_USER_DATA ( ( void * ) 0x00020011 )
|
69
|
-
#define SWITCH_DISCONNECTED_HANDLER ( ( void * ) 0x00020002 )
|
70
|
-
#define SWITCH_DISCONNECTED_USER_DATA ( ( void * ) 0x00020021 )
|
71
|
-
#define ERROR_HANDLER ( ( void * ) 0x00010001 )
|
72
|
-
#define ERROR_USER_DATA ( ( void * ) 0x00010011 )
|
73
|
-
#define ECHO_REPLY_HANDLER ( ( void * ) 0x00010002 )
|
74
|
-
#define ECHO_REPLY_USER_DATA ( ( void * ) 0x00010021 )
|
75
|
-
#define VENDOR_HANDLER ( ( void * ) 0x00010003 )
|
76
|
-
#define VENDOR_USER_DATA ( ( void * ) 0x00010031 )
|
77
|
-
#define FEATURES_REPLY_HANDLER ( ( void * ) 0x00010004 )
|
78
|
-
#define FEATURES_REPLY_USER_DATA ( ( void * ) 0x00010041 )
|
79
|
-
#define GET_CONFIG_REPLY_HANDLER ( ( void * ) 0x00010005 )
|
80
|
-
#define GET_CONFIG_REPLY_USER_DATA ( ( void * ) 0x00010051 )
|
81
|
-
#define PACKET_IN_HANDLER ( ( void * ) 0x00010006 )
|
82
|
-
#define PACKET_IN_USER_DATA ( ( void * ) 0x00010061 )
|
83
|
-
#define FLOW_REMOVED_HANDLER ( ( void * ) 0x00010007 )
|
84
|
-
#define FLOW_REMOVED_USER_DATA ( ( void * ) 0x00010071 )
|
85
|
-
#define PORT_STATUS_HANDLER ( ( void * ) 0x00010008 )
|
86
|
-
#define PORT_STATUS_USER_DATA ( ( void * ) 0x00010081 )
|
87
|
-
#define STATS_REPLY_HANDLER ( ( void * ) 0x00010009 )
|
88
|
-
#define STATS_REPLY_USER_DATA ( ( void * ) 0x00010091 )
|
89
|
-
#define BARRIER_REPLY_HANDLER ( ( void * ) 0x0001000a )
|
90
|
-
#define BARRIER_REPLY_USER_DATA ( ( void * ) 0x000100a1 )
|
91
|
-
#define QUEUE_GET_CONFIG_REPLY_HANDLER ( ( void * ) 0x0001000b )
|
92
|
-
#define QUEUE_GET_CONFIG_REPLY_USER_DATA ( ( void * ) 0x000100b1 )
|
93
|
-
#define LIST_SWITCHES_REPLY_HANDLER ( ( void * ) 0x0001000c )
|
94
|
-
#define LIST_SWITCHES_REPLY_USER_DATA ( ( void * ) 0x000100c1 )
|
95
|
-
|
96
|
-
static const pid_t PID = 12345;
|
97
|
-
static char SERVICE_NAME[] = "learning switch application 0";
|
98
|
-
static openflow_event_handlers_t NULL_EVENT_HANDLERS = { false, ( void * ) 0, ( void * ) 0,
|
99
|
-
( void * ) 0, ( void * ) 0,
|
100
|
-
( void * ) 0, ( void * ) 0,
|
101
|
-
( void * ) 0, ( void * ) 0,
|
102
|
-
( void * ) 0, ( void * ) 0,
|
103
|
-
( void * ) 0, ( void * ) 0,
|
104
|
-
false, ( void * ) 0, ( void * ) 0,
|
105
|
-
false, ( void * ) 0, ( void * ) 0,
|
106
|
-
( void * ) 0, ( void * ) 0,
|
107
|
-
( void * ) 0, ( void * ) 0,
|
108
|
-
( void * ) 0, ( void * ) 0,
|
109
|
-
( void * ) 0, ( void * ) 0,
|
110
|
-
( void * ) 0, ( void * ) 0,
|
111
|
-
( void * ) 0 };
|
112
|
-
static openflow_event_handlers_t EVENT_HANDLERS = {
|
113
|
-
false, SWITCH_READY_HANDLER, SWITCH_READY_USER_DATA,
|
114
|
-
SWITCH_DISCONNECTED_HANDLER, SWITCH_DISCONNECTED_USER_DATA,
|
115
|
-
ERROR_HANDLER, ERROR_USER_DATA,
|
116
|
-
ECHO_REPLY_HANDLER, ECHO_REPLY_USER_DATA,
|
117
|
-
VENDOR_HANDLER, VENDOR_USER_DATA,
|
118
|
-
FEATURES_REPLY_HANDLER, FEATURES_REPLY_USER_DATA,
|
119
|
-
GET_CONFIG_REPLY_HANDLER, GET_CONFIG_REPLY_USER_DATA,
|
120
|
-
false, PACKET_IN_HANDLER, PACKET_IN_USER_DATA,
|
121
|
-
false, FLOW_REMOVED_HANDLER, FLOW_REMOVED_USER_DATA,
|
122
|
-
PORT_STATUS_HANDLER, PORT_STATUS_USER_DATA,
|
123
|
-
STATS_REPLY_HANDLER, STATS_REPLY_USER_DATA,
|
124
|
-
BARRIER_REPLY_HANDLER, BARRIER_REPLY_USER_DATA,
|
125
|
-
QUEUE_GET_CONFIG_REPLY_HANDLER, QUEUE_GET_CONFIG_REPLY_USER_DATA,
|
126
|
-
LIST_SWITCHES_REPLY_HANDLER
|
127
|
-
};
|
128
|
-
static uint64_t DATAPATH_ID = 0x0102030405060708ULL;
|
129
|
-
static char REMOTE_SERVICE_NAME[] = "switch.0x102030405060708";
|
130
|
-
static const uint32_t TRANSACTION_ID = 0x04030201;
|
131
|
-
static const uint32_t VENDOR_ID = 0xccddeeff;
|
132
|
-
static const uint8_t MAC_ADDR_X[ OFP_ETH_ALEN ] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x07 };
|
133
|
-
static const uint8_t MAC_ADDR_Y[ OFP_ETH_ALEN ] = { 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d };
|
134
|
-
static const char *PORT_NAME = "port 1";
|
135
|
-
static const uint32_t PORT_FEATURES = ( OFPPF_10MB_HD | OFPPF_10MB_FD | OFPPF_100MB_HD |
|
136
|
-
OFPPF_100MB_FD | OFPPF_1GB_HD | OFPPF_1GB_FD |
|
137
|
-
OFPPF_COPPER | OFPPF_AUTONEG | OFPPF_PAUSE );
|
138
|
-
static struct ofp_match MATCH = { OFPFW_ALL, 1,
|
139
|
-
{ 0x01, 0x02, 0x03, 0x04, 0x05, 0x07 },
|
140
|
-
{ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d },
|
141
|
-
1, 1, { 0 }, 0x800, 0xfc, 0x6, { 0, 0 },
|
142
|
-
0x0a090807, 0x0a090807, 1024, 2048 };
|
143
|
-
#define USER_DATA_LEN 64
|
144
|
-
static uint8_t USER_DATA[ USER_DATA_LEN ];
|
145
|
-
|
146
|
-
|
147
|
-
static bool packet_in_handler_called = false;
|
148
|
-
|
149
|
-
|
150
|
-
/********************************************************************************
|
151
|
-
* Mocks.
|
152
|
-
********************************************************************************/
|
153
|
-
|
154
|
-
const char *
|
155
|
-
mock_get_trema_name() {
|
156
|
-
return "TEST_SERVICE_NAME";
|
157
|
-
}
|
158
|
-
|
159
|
-
|
160
|
-
pid_t
|
161
|
-
mock_getpid() {
|
162
|
-
return PID;
|
163
|
-
}
|
164
|
-
|
165
|
-
|
166
|
-
bool
|
167
|
-
mock_init_openflow_message() {
|
168
|
-
return ( bool ) mock();
|
169
|
-
}
|
170
|
-
|
171
|
-
|
172
|
-
bool
|
173
|
-
mock_add_message_received_callback( char *service_name,
|
174
|
-
void ( *callback )( uint16_t tag, void *data, size_t len ) ) {
|
175
|
-
check_expected( service_name );
|
176
|
-
check_expected( callback );
|
177
|
-
|
178
|
-
return ( bool ) mock();
|
179
|
-
}
|
180
|
-
|
181
|
-
|
182
|
-
bool
|
183
|
-
mock_add_message_replied_callback( char *service_name,
|
184
|
-
void ( *callback )( uint16_t tag, void *data, size_t len, void *user_data ) ) {
|
185
|
-
check_expected( service_name );
|
186
|
-
check_expected( callback );
|
187
|
-
|
188
|
-
return ( bool ) mock();
|
189
|
-
}
|
190
|
-
|
191
|
-
|
192
|
-
bool
|
193
|
-
mock_send_message( char *service_name, uint16_t tag, void *data, size_t len ) {
|
194
|
-
uint32_t tag32 = tag;
|
195
|
-
|
196
|
-
check_expected( service_name );
|
197
|
-
check_expected( tag32 );
|
198
|
-
check_expected( data );
|
199
|
-
check_expected( len );
|
200
|
-
|
201
|
-
return ( bool ) mock();
|
202
|
-
}
|
203
|
-
|
204
|
-
|
205
|
-
bool
|
206
|
-
mock_send_request_message( char *to_service_name, char *from_service_name, uint16_t tag,
|
207
|
-
void *data, size_t len, void *user_data ) {
|
208
|
-
uint32_t tag32 = tag;
|
209
|
-
|
210
|
-
check_expected( to_service_name );
|
211
|
-
check_expected( from_service_name );
|
212
|
-
check_expected( tag32 );
|
213
|
-
check_expected( data );
|
214
|
-
check_expected( len );
|
215
|
-
check_expected( user_data );
|
216
|
-
|
217
|
-
return ( bool ) mock();
|
218
|
-
}
|
219
|
-
|
220
|
-
|
221
|
-
bool
|
222
|
-
mock_delete_message_received_callback( char *service_name,
|
223
|
-
void ( *callback )( uint16_t tag, void *data, size_t len ) ) {
|
224
|
-
check_expected( service_name );
|
225
|
-
check_expected( callback );
|
226
|
-
|
227
|
-
return ( bool ) mock();
|
228
|
-
}
|
229
|
-
|
230
|
-
|
231
|
-
bool
|
232
|
-
mock_delete_message_replied_callback( char *service_name,
|
233
|
-
void ( *callback )( uint16_t tag, void *data, size_t len, void *user_data ) ) {
|
234
|
-
check_expected( service_name );
|
235
|
-
check_expected( callback );
|
236
|
-
|
237
|
-
return ( bool ) mock();
|
238
|
-
}
|
239
|
-
|
240
|
-
|
241
|
-
bool
|
242
|
-
mock_clear_send_queue( const char *service_name ) {
|
243
|
-
check_expected( service_name );
|
244
|
-
|
245
|
-
return ( bool ) mock();
|
246
|
-
}
|
247
|
-
|
248
|
-
|
249
|
-
bool
|
250
|
-
mock_parse_packet( buffer *buf ) {
|
251
|
-
calloc_packet_info( buf );
|
252
|
-
return ( bool ) mock();
|
253
|
-
}
|
254
|
-
|
255
|
-
|
256
|
-
static void
|
257
|
-
mock_switch_disconnected_handler( uint64_t datapath_id, void *user_data ) {
|
258
|
-
check_expected( &datapath_id );
|
259
|
-
check_expected( user_data );
|
260
|
-
}
|
261
|
-
|
262
|
-
|
263
|
-
static void
|
264
|
-
mock_error_handler( uint64_t datapath_id, uint32_t transaction_id, uint16_t type, uint16_t code,
|
265
|
-
const buffer *data, void *user_data ) {
|
266
|
-
uint32_t type32 = type;
|
267
|
-
uint32_t code32 = code;
|
268
|
-
|
269
|
-
check_expected( &datapath_id );
|
270
|
-
check_expected( transaction_id );
|
271
|
-
check_expected( type32 );
|
272
|
-
check_expected( code32 );
|
273
|
-
check_expected( data->length );
|
274
|
-
check_expected( data->data );
|
275
|
-
check_expected( user_data );
|
276
|
-
}
|
277
|
-
|
278
|
-
|
279
|
-
static void
|
280
|
-
mock_echo_reply_handler( uint64_t datapath_id, uint32_t transaction_id, const buffer *data,
|
281
|
-
void *user_data ) {
|
282
|
-
void *data_uc;
|
283
|
-
|
284
|
-
check_expected( &datapath_id );
|
285
|
-
check_expected( transaction_id );
|
286
|
-
if ( data != NULL ) {
|
287
|
-
check_expected( data->length );
|
288
|
-
check_expected( data->data );
|
289
|
-
}
|
290
|
-
else {
|
291
|
-
data_uc = ( void * ) ( unsigned long ) data;
|
292
|
-
check_expected( data_uc );
|
293
|
-
}
|
294
|
-
check_expected( user_data );
|
295
|
-
}
|
296
|
-
|
297
|
-
|
298
|
-
static void
|
299
|
-
mock_vendor_handler( uint64_t datapath_id, uint32_t transaction_id, uint32_t vendor,
|
300
|
-
const buffer *data, void *user_data ) {
|
301
|
-
void *data_uc;
|
302
|
-
|
303
|
-
check_expected( &datapath_id );
|
304
|
-
check_expected( transaction_id );
|
305
|
-
check_expected( vendor );
|
306
|
-
if ( data != NULL ) {
|
307
|
-
check_expected( data->length );
|
308
|
-
check_expected( data->data );
|
309
|
-
}
|
310
|
-
else {
|
311
|
-
data_uc = ( void * ) ( unsigned long ) data;
|
312
|
-
check_expected( data_uc );
|
313
|
-
}
|
314
|
-
check_expected( user_data );
|
315
|
-
}
|
316
|
-
|
317
|
-
|
318
|
-
static void
|
319
|
-
mock_features_reply_handler( uint64_t datapath_id, uint32_t transaction_id,
|
320
|
-
uint32_t n_buffers, uint8_t n_tables, uint32_t capabilities,
|
321
|
-
uint32_t actions, const list_element *phy_ports,
|
322
|
-
void *user_data ) {
|
323
|
-
uint32_t n_tables32 = n_tables;
|
324
|
-
|
325
|
-
check_expected( &datapath_id );
|
326
|
-
check_expected( transaction_id );
|
327
|
-
check_expected( n_buffers );
|
328
|
-
check_expected( n_tables32 );
|
329
|
-
check_expected( capabilities );
|
330
|
-
check_expected( actions );
|
331
|
-
if ( phy_ports != NULL ) {
|
332
|
-
struct ofp_phy_port *port1 = phy_ports->data;
|
333
|
-
struct ofp_phy_port *port2 = phy_ports->next->data;
|
334
|
-
check_expected( port1 );
|
335
|
-
check_expected( port2 );
|
336
|
-
}
|
337
|
-
else {
|
338
|
-
void *phy_ports_uc = ( void * ) ( unsigned long ) phy_ports;
|
339
|
-
check_expected( phy_ports_uc );
|
340
|
-
}
|
341
|
-
check_expected( user_data );
|
342
|
-
}
|
343
|
-
|
344
|
-
|
345
|
-
static void
|
346
|
-
mock_get_config_reply_handler( uint64_t datapath_id, uint32_t transaction_id,
|
347
|
-
uint16_t flags, uint16_t miss_send_len, void *user_data ) {
|
348
|
-
uint32_t flags32 = flags;
|
349
|
-
uint32_t miss_send_len32 = miss_send_len;
|
350
|
-
|
351
|
-
check_expected( &datapath_id );
|
352
|
-
check_expected( transaction_id );
|
353
|
-
check_expected( flags32 );
|
354
|
-
check_expected( miss_send_len32 );
|
355
|
-
check_expected( user_data );
|
356
|
-
}
|
357
|
-
|
358
|
-
|
359
|
-
static void
|
360
|
-
mock_flow_removed_handler( uint64_t datapath_id, uint32_t transaction_id, struct ofp_match match,
|
361
|
-
uint64_t cookie, uint16_t priority, uint8_t reason, uint32_t duration_sec,
|
362
|
-
uint32_t duration_nsec, uint16_t idle_timeout, uint64_t packet_count,
|
363
|
-
uint64_t byte_count, void *user_data ) {
|
364
|
-
uint32_t priority32 = priority;
|
365
|
-
uint32_t reason32 = reason;
|
366
|
-
uint32_t idle_timeout32 = idle_timeout;
|
367
|
-
|
368
|
-
check_expected( &datapath_id );
|
369
|
-
check_expected( transaction_id );
|
370
|
-
check_expected( &match );
|
371
|
-
check_expected( &cookie );
|
372
|
-
check_expected( priority32 );
|
373
|
-
check_expected( reason32 );
|
374
|
-
check_expected( duration_sec );
|
375
|
-
check_expected( duration_nsec );
|
376
|
-
check_expected( idle_timeout32 );
|
377
|
-
check_expected( &packet_count );
|
378
|
-
check_expected( &byte_count );
|
379
|
-
check_expected( user_data );
|
380
|
-
}
|
381
|
-
|
382
|
-
|
383
|
-
static void
|
384
|
-
mock_port_status_handler( uint64_t datapath_id, uint32_t transaction_id, uint8_t reason,
|
385
|
-
struct ofp_phy_port phy_port, void *user_data ) {
|
386
|
-
uint32_t reason32 = reason;
|
387
|
-
|
388
|
-
check_expected( &datapath_id );
|
389
|
-
check_expected( transaction_id );
|
390
|
-
check_expected( reason32 );
|
391
|
-
check_expected( &phy_port );
|
392
|
-
check_expected( user_data );
|
393
|
-
}
|
394
|
-
|
395
|
-
|
396
|
-
static void
|
397
|
-
mock_stats_reply_handler( uint64_t datapath_id, uint32_t transaction_id, uint16_t type,
|
398
|
-
uint16_t flags, const buffer *data, void *user_data ) {
|
399
|
-
uint32_t type32 = type;
|
400
|
-
uint32_t flags32 = flags;
|
401
|
-
|
402
|
-
check_expected( &datapath_id );
|
403
|
-
check_expected( transaction_id );
|
404
|
-
check_expected( type32 );
|
405
|
-
check_expected( flags32 );
|
406
|
-
check_expected( data->length );
|
407
|
-
check_expected( data->data );
|
408
|
-
check_expected( user_data );
|
409
|
-
}
|
410
|
-
|
411
|
-
|
412
|
-
static void
|
413
|
-
mock_barrier_reply_handler( uint64_t datapath_id, uint32_t transaction_id, void *user_data ) {
|
414
|
-
check_expected( &datapath_id );
|
415
|
-
check_expected( transaction_id );
|
416
|
-
check_expected( user_data );
|
417
|
-
}
|
418
|
-
|
419
|
-
|
420
|
-
static void
|
421
|
-
mock_queue_get_config_reply_handler( uint64_t datapath_id, uint32_t transaction_id,
|
422
|
-
uint16_t port, const list_element *queues, void *user_data ) {
|
423
|
-
uint32_t port32 = port;
|
424
|
-
struct ofp_packet_queue *queue1, *queue2;
|
425
|
-
|
426
|
-
queue1 = queues->data;
|
427
|
-
queue2 = queues->next->data;
|
428
|
-
|
429
|
-
check_expected( &datapath_id );
|
430
|
-
check_expected( transaction_id );
|
431
|
-
check_expected( port32 );
|
432
|
-
check_expected( queue1 );
|
433
|
-
check_expected( queue2 );
|
434
|
-
check_expected( user_data );
|
435
|
-
}
|
436
|
-
|
437
|
-
|
438
|
-
static void
|
439
|
-
mock_handle_list_switches_reply( const list_element *switches, void *user_data ) {
|
440
|
-
uint64_t *dpid1, *dpid2, *dpid3;
|
441
|
-
|
442
|
-
if ( switches != NULL ) {
|
443
|
-
dpid1 = switches->data;
|
444
|
-
check_expected( *dpid1 );
|
445
|
-
if ( switches->next != NULL ) {
|
446
|
-
dpid2 = switches->next->data;
|
447
|
-
check_expected( *dpid2 );
|
448
|
-
if ( switches->next->next != NULL ) {
|
449
|
-
dpid3 = switches->next->next->data;
|
450
|
-
check_expected( *dpid3 );
|
451
|
-
}
|
452
|
-
}
|
453
|
-
}
|
454
|
-
check_expected( user_data );
|
455
|
-
}
|
456
|
-
|
457
|
-
|
458
|
-
void
|
459
|
-
mock_die( char *format, ... ) {
|
460
|
-
check_expected( format );
|
461
|
-
mock_assert( false, "die", __FILE__, __LINE__ );
|
462
|
-
}
|
463
|
-
|
464
|
-
|
465
|
-
void
|
466
|
-
mock_debug( char *format, ... ) {
|
467
|
-
UNUSED( format );
|
468
|
-
}
|
469
|
-
|
470
|
-
|
471
|
-
void
|
472
|
-
mock_info( char *format, ... ) {
|
473
|
-
UNUSED( format );
|
474
|
-
}
|
475
|
-
|
476
|
-
|
477
|
-
void
|
478
|
-
mock_warn( char *format, ... ) {
|
479
|
-
UNUSED( format );
|
480
|
-
}
|
481
|
-
|
482
|
-
|
483
|
-
void
|
484
|
-
mock_error( char *format, ... ) {
|
485
|
-
UNUSED( format );
|
486
|
-
}
|
487
|
-
|
488
|
-
|
489
|
-
void
|
490
|
-
mock_critical( char *format, ... ) {
|
491
|
-
UNUSED( format );
|
492
|
-
}
|
493
|
-
|
494
|
-
|
495
|
-
static int
|
496
|
-
mock_get_logging_level() {
|
497
|
-
return LOG_DEBUG;
|
498
|
-
}
|
499
|
-
|
500
|
-
|
501
|
-
/********************************************************************************
|
502
|
-
* Setup and teardown function.
|
503
|
-
********************************************************************************/
|
504
|
-
|
505
|
-
static void
|
506
|
-
cleanup() {
|
507
|
-
openflow_application_interface_initialized = false;
|
508
|
-
packet_in_handler_called = false;
|
509
|
-
|
510
|
-
memset( service_name, 0, sizeof( service_name ) );
|
511
|
-
memset( &event_handlers, 0, sizeof( event_handlers ) );
|
512
|
-
memset( USER_DATA, 'Z', sizeof( USER_DATA ) );
|
513
|
-
if ( stats != NULL ) {
|
514
|
-
delete_hash( stats );
|
515
|
-
stats = NULL;
|
516
|
-
}
|
517
|
-
}
|
518
|
-
|
519
|
-
|
520
|
-
static void
|
521
|
-
init() {
|
522
|
-
bool ret;
|
523
|
-
|
524
|
-
get_logging_level = mock_get_logging_level;
|
525
|
-
|
526
|
-
cleanup();
|
527
|
-
|
528
|
-
will_return( mock_init_openflow_message, true );
|
529
|
-
|
530
|
-
expect_string( mock_add_message_received_callback, service_name, SERVICE_NAME );
|
531
|
-
expect_value( mock_add_message_received_callback, callback, handle_message );
|
532
|
-
will_return( mock_add_message_received_callback, true );
|
533
|
-
|
534
|
-
expect_string( mock_add_message_replied_callback, service_name, SERVICE_NAME );
|
535
|
-
expect_value( mock_add_message_replied_callback, callback, handle_list_switches_reply );
|
536
|
-
will_return( mock_add_message_replied_callback, true );
|
537
|
-
|
538
|
-
init_stat();
|
539
|
-
|
540
|
-
ret = init_openflow_application_interface( SERVICE_NAME );
|
541
|
-
|
542
|
-
assert_true( ret );
|
543
|
-
assert_true( openflow_application_interface_initialized );
|
544
|
-
assert_string_equal( service_name, SERVICE_NAME );
|
545
|
-
assert_memory_equal( &event_handlers, &NULL_EVENT_HANDLERS, sizeof( event_handlers ) );
|
546
|
-
}
|
547
|
-
|
548
|
-
|
549
|
-
/********************************************************************************
|
550
|
-
* init_openflow_application_interface() tests.
|
551
|
-
********************************************************************************/
|
552
|
-
|
553
|
-
static void
|
554
|
-
test_init_openflow_application_interface_with_valid_custom_service_name() {
|
555
|
-
bool ret;
|
556
|
-
|
557
|
-
will_return( mock_init_openflow_message, true );
|
558
|
-
|
559
|
-
expect_string( mock_add_message_received_callback, service_name, SERVICE_NAME );
|
560
|
-
expect_value( mock_add_message_received_callback, callback, handle_message );
|
561
|
-
will_return( mock_add_message_received_callback, true );
|
562
|
-
|
563
|
-
expect_string( mock_add_message_replied_callback, service_name, SERVICE_NAME );
|
564
|
-
expect_value( mock_add_message_replied_callback, callback, handle_list_switches_reply );
|
565
|
-
will_return( mock_add_message_replied_callback, true );
|
566
|
-
|
567
|
-
ret = init_openflow_application_interface( SERVICE_NAME );
|
568
|
-
|
569
|
-
assert_true( ret );
|
570
|
-
assert_true( openflow_application_interface_initialized );
|
571
|
-
assert_string_equal( service_name, SERVICE_NAME );
|
572
|
-
assert_memory_equal( &event_handlers, &NULL_EVENT_HANDLERS, sizeof( event_handlers ) );
|
573
|
-
}
|
574
|
-
|
575
|
-
|
576
|
-
static void
|
577
|
-
test_init_openflow_application_interface_with_too_long_custom_service_name() {
|
578
|
-
bool ret;
|
579
|
-
char too_long_service_name[ MESSENGER_SERVICE_NAME_LENGTH + 1 ];
|
580
|
-
char expected_service_name[ MESSENGER_SERVICE_NAME_LENGTH ];
|
581
|
-
|
582
|
-
memset( too_long_service_name, 'a', sizeof( too_long_service_name ) );
|
583
|
-
too_long_service_name[ MESSENGER_SERVICE_NAME_LENGTH ] = '\0';
|
584
|
-
|
585
|
-
memset( expected_service_name, '\0', sizeof( expected_service_name ) );
|
586
|
-
|
587
|
-
ret = init_openflow_application_interface( too_long_service_name );
|
588
|
-
|
589
|
-
assert_true( ret == false );
|
590
|
-
assert_true( openflow_application_interface_initialized == false );
|
591
|
-
assert_string_equal( service_name, expected_service_name );
|
592
|
-
assert_memory_equal( &event_handlers, &NULL_EVENT_HANDLERS, sizeof( event_handlers ) );
|
593
|
-
}
|
594
|
-
|
595
|
-
|
596
|
-
static void
|
597
|
-
test_init_openflow_application_interface_if_already_initialized() {
|
598
|
-
bool ret;
|
599
|
-
|
600
|
-
ret = set_openflow_event_handlers( EVENT_HANDLERS );
|
601
|
-
|
602
|
-
assert_true( ret );
|
603
|
-
assert_memory_equal( &event_handlers, &EVENT_HANDLERS, sizeof( event_handlers ) );
|
604
|
-
|
605
|
-
ret = init_openflow_application_interface( SERVICE_NAME );
|
606
|
-
|
607
|
-
assert_true( ret == false );
|
608
|
-
assert_true( openflow_application_interface_initialized == true );
|
609
|
-
assert_string_equal( service_name, SERVICE_NAME );
|
610
|
-
assert_memory_equal( &event_handlers, &EVENT_HANDLERS, sizeof( event_handlers ) );
|
611
|
-
}
|
612
|
-
|
613
|
-
|
614
|
-
/********************************************************************************
|
615
|
-
* init_openflow_application_interface() tests.
|
616
|
-
********************************************************************************/
|
617
|
-
|
618
|
-
static void
|
619
|
-
test_finalize_openflow_application_interface() {
|
620
|
-
bool ret;
|
621
|
-
char expected_service_name[ MESSENGER_SERVICE_NAME_LENGTH ];
|
622
|
-
|
623
|
-
memset( expected_service_name, '\0', sizeof( expected_service_name ) );
|
624
|
-
|
625
|
-
expect_string( mock_delete_message_received_callback, service_name, SERVICE_NAME );
|
626
|
-
expect_value( mock_delete_message_received_callback, callback, handle_message );
|
627
|
-
will_return( mock_delete_message_received_callback, true );
|
628
|
-
|
629
|
-
expect_string( mock_delete_message_replied_callback, service_name, SERVICE_NAME );
|
630
|
-
expect_value( mock_delete_message_replied_callback, callback, handle_list_switches_reply );
|
631
|
-
will_return( mock_delete_message_replied_callback, true );
|
632
|
-
|
633
|
-
ret = finalize_openflow_application_interface();
|
634
|
-
|
635
|
-
assert_true( ret );
|
636
|
-
assert_true( openflow_application_interface_initialized == false );
|
637
|
-
assert_string_equal( service_name, expected_service_name );
|
638
|
-
assert_memory_equal( &event_handlers, &NULL_EVENT_HANDLERS, sizeof( event_handlers ) );
|
639
|
-
}
|
640
|
-
|
641
|
-
|
642
|
-
static void
|
643
|
-
test_finalize_openflow_application_interface_if_not_initialized() {
|
644
|
-
char expected_service_name[ MESSENGER_SERVICE_NAME_LENGTH ];
|
645
|
-
|
646
|
-
memset( expected_service_name, '\0', sizeof( expected_service_name ) );
|
647
|
-
|
648
|
-
expect_assert_failure( finalize_openflow_application_interface() );
|
649
|
-
|
650
|
-
assert_true( openflow_application_interface_initialized == false );
|
651
|
-
assert_string_equal( service_name, expected_service_name );
|
652
|
-
assert_memory_equal( &event_handlers, &NULL_EVENT_HANDLERS, sizeof( event_handlers ) );
|
653
|
-
}
|
654
|
-
|
655
|
-
|
656
|
-
/********************************************************************************
|
657
|
-
* set_openflow_event_handlers() tests.
|
658
|
-
********************************************************************************/
|
659
|
-
|
660
|
-
static void
|
661
|
-
test_set_openflow_event_handlers() {
|
662
|
-
bool ret;
|
663
|
-
|
664
|
-
ret = set_openflow_event_handlers( EVENT_HANDLERS );
|
665
|
-
|
666
|
-
assert_true( ret );
|
667
|
-
assert_memory_equal( &event_handlers, &EVENT_HANDLERS, sizeof( event_handlers ) );
|
668
|
-
}
|
669
|
-
|
670
|
-
|
671
|
-
/********************************************************************************
|
672
|
-
* Switch ready handler tests.
|
673
|
-
********************************************************************************/
|
674
|
-
|
675
|
-
static void
|
676
|
-
mock_switch_ready_handler( uint64_t datapath_id, void *user_data ) {
|
677
|
-
check_expected( &datapath_id );
|
678
|
-
check_expected( user_data );
|
679
|
-
}
|
680
|
-
|
681
|
-
|
682
|
-
static void
|
683
|
-
mock_simple_switch_ready_handler( switch_ready event ) {
|
684
|
-
uint64_t datapath_id = event.datapath_id;
|
685
|
-
void *user_data = event.user_data;
|
686
|
-
|
687
|
-
check_expected( &datapath_id );
|
688
|
-
check_expected( user_data );
|
689
|
-
}
|
690
|
-
|
691
|
-
|
692
|
-
static void
|
693
|
-
test_set_switch_ready_handler() {
|
694
|
-
char user_data[] = "Ready!";
|
695
|
-
set_switch_ready_handler( mock_switch_ready_handler, user_data );
|
696
|
-
assert_true( event_handlers.switch_ready_callback == mock_switch_ready_handler );
|
697
|
-
assert_string_equal( event_handlers.switch_ready_user_data, user_data );
|
698
|
-
}
|
699
|
-
|
700
|
-
|
701
|
-
static void
|
702
|
-
test_set_simple_switch_ready_handler() {
|
703
|
-
char user_data[] = "Ready!";
|
704
|
-
set_switch_ready_handler( mock_simple_switch_ready_handler, user_data );
|
705
|
-
assert_true( event_handlers.switch_ready_callback == mock_simple_switch_ready_handler );
|
706
|
-
assert_string_equal( event_handlers.switch_ready_user_data, user_data );
|
707
|
-
}
|
708
|
-
|
709
|
-
|
710
|
-
static void
|
711
|
-
test_set_switch_ready_handler_should_die_if_handler_is_NULL() {
|
712
|
-
char user_data[] = "Ready!";
|
713
|
-
expect_string( mock_die, format, "Invalid callback function for switch_ready event." );
|
714
|
-
expect_assert_failure( set_switch_ready_handler( NULL, user_data ) );
|
715
|
-
assert_memory_equal( &event_handlers, &NULL_EVENT_HANDLERS, sizeof( event_handlers ) );
|
716
|
-
}
|
717
|
-
|
718
|
-
|
719
|
-
static void
|
720
|
-
test_handle_switch_ready() {
|
721
|
-
char user_data[] = "Ready!";
|
722
|
-
buffer *data = alloc_buffer_with_length( sizeof( openflow_service_header_t ) );
|
723
|
-
uint64_t *datapath_id = append_back_buffer( data, sizeof( openflow_service_header_t ) );
|
724
|
-
*datapath_id = htonll( DATAPATH_ID );
|
725
|
-
|
726
|
-
expect_memory( mock_switch_ready_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
727
|
-
expect_string( mock_switch_ready_handler, user_data, user_data );
|
728
|
-
|
729
|
-
set_switch_ready_handler( mock_switch_ready_handler, user_data );
|
730
|
-
handle_message( MESSENGER_OPENFLOW_READY, data->data, data->length );
|
731
|
-
|
732
|
-
stat_entry *stat = lookup_hash_entry( stats, "openflow_application_interface.switch_ready_receive_succeeded" );
|
733
|
-
assert_int_equal( ( int ) stat->value, 1 );
|
734
|
-
|
735
|
-
free_buffer( data );
|
736
|
-
xfree( delete_hash_entry( stats, "openflow_application_interface.switch_ready_receive_succeeded" ) );
|
737
|
-
}
|
738
|
-
|
739
|
-
|
740
|
-
static void
|
741
|
-
test_handle_switch_ready_with_simple_handler() {
|
742
|
-
char user_data[] = "Ready!";
|
743
|
-
buffer *data = alloc_buffer_with_length( sizeof( openflow_service_header_t ) );
|
744
|
-
uint64_t *datapath_id = append_back_buffer( data, sizeof( openflow_service_header_t ) );
|
745
|
-
*datapath_id = htonll( DATAPATH_ID );
|
746
|
-
|
747
|
-
expect_memory( mock_simple_switch_ready_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
748
|
-
expect_string( mock_simple_switch_ready_handler, user_data, user_data );
|
749
|
-
|
750
|
-
set_switch_ready_handler( mock_simple_switch_ready_handler, user_data );
|
751
|
-
handle_message( MESSENGER_OPENFLOW_READY, data->data, data->length );
|
752
|
-
|
753
|
-
stat_entry *stat = lookup_hash_entry( stats, "openflow_application_interface.switch_ready_receive_succeeded" );
|
754
|
-
assert_int_equal( ( int ) stat->value, 1 );
|
755
|
-
|
756
|
-
free_buffer( data );
|
757
|
-
xfree( delete_hash_entry( stats, "openflow_application_interface.switch_ready_receive_succeeded" ) );
|
758
|
-
}
|
759
|
-
|
760
|
-
|
761
|
-
/********************************************************************************
|
762
|
-
* set_switch_disconnected_handler() tests.
|
763
|
-
********************************************************************************/
|
764
|
-
|
765
|
-
static void
|
766
|
-
test_set_switch_disconnected_handler() {
|
767
|
-
assert_true( set_switch_disconnected_handler( SWITCH_DISCONNECTED_HANDLER, SWITCH_DISCONNECTED_USER_DATA ) );
|
768
|
-
assert_int_equal( event_handlers.switch_disconnected_callback, SWITCH_DISCONNECTED_HANDLER );
|
769
|
-
assert_int_equal( event_handlers.switch_disconnected_user_data, SWITCH_DISCONNECTED_USER_DATA );
|
770
|
-
}
|
771
|
-
|
772
|
-
|
773
|
-
static void
|
774
|
-
test_set_switch_disconnected_handler_if_handler_is_NULL() {
|
775
|
-
expect_string( mock_die, format, "Callback function ( switch_disconnected_handler ) must not be NULL." );
|
776
|
-
expect_assert_failure( set_switch_disconnected_handler( NULL, NULL ) );
|
777
|
-
assert_memory_equal( &event_handlers, &NULL_EVENT_HANDLERS, sizeof( event_handlers ) );
|
778
|
-
}
|
779
|
-
|
780
|
-
|
781
|
-
/********************************************************************************
|
782
|
-
* set_error_handler() tests.
|
783
|
-
********************************************************************************/
|
784
|
-
|
785
|
-
static void
|
786
|
-
test_set_error_handler() {
|
787
|
-
assert_true( set_error_handler( ERROR_HANDLER, ERROR_USER_DATA ) );
|
788
|
-
assert_int_equal( event_handlers.error_callback, ERROR_HANDLER );
|
789
|
-
assert_int_equal( event_handlers.error_user_data, ERROR_USER_DATA );
|
790
|
-
}
|
791
|
-
|
792
|
-
|
793
|
-
static void
|
794
|
-
test_set_error_handler_if_handler_is_NULL() {
|
795
|
-
expect_string( mock_die, format, "Callback function ( error_handler ) must not be NULL." );
|
796
|
-
expect_assert_failure( set_error_handler( NULL, NULL ) );
|
797
|
-
assert_memory_equal( &event_handlers, &NULL_EVENT_HANDLERS, sizeof( event_handlers ) );
|
798
|
-
}
|
799
|
-
|
800
|
-
|
801
|
-
/********************************************************************************
|
802
|
-
* set_echo_reply_handler() tests.
|
803
|
-
********************************************************************************/
|
804
|
-
|
805
|
-
static void
|
806
|
-
test_set_echo_reply_handler() {
|
807
|
-
assert_true( set_echo_reply_handler( ECHO_REPLY_HANDLER, ECHO_REPLY_USER_DATA ) );
|
808
|
-
assert_int_equal( event_handlers.echo_reply_callback, ECHO_REPLY_HANDLER );
|
809
|
-
assert_int_equal( event_handlers.echo_reply_user_data, ECHO_REPLY_USER_DATA );
|
810
|
-
}
|
811
|
-
|
812
|
-
|
813
|
-
static void
|
814
|
-
test_set_echo_reply_handler_if_handler_is_NULL() {
|
815
|
-
expect_string( mock_die, format, "Callback function ( echo_reply_handler ) must not be NULL." );
|
816
|
-
expect_assert_failure( set_echo_reply_handler( NULL, NULL ) );
|
817
|
-
assert_memory_equal( &event_handlers, &NULL_EVENT_HANDLERS, sizeof( event_handlers ) );
|
818
|
-
}
|
819
|
-
|
820
|
-
|
821
|
-
/********************************************************************************
|
822
|
-
* set_vendor_handler() tests.
|
823
|
-
********************************************************************************/
|
824
|
-
|
825
|
-
static void
|
826
|
-
test_set_vendor_handler() {
|
827
|
-
assert_true( set_vendor_handler( VENDOR_HANDLER, VENDOR_USER_DATA ) );
|
828
|
-
assert_int_equal( event_handlers.vendor_callback, VENDOR_HANDLER );
|
829
|
-
assert_int_equal( event_handlers.vendor_user_data, VENDOR_USER_DATA );
|
830
|
-
}
|
831
|
-
|
832
|
-
|
833
|
-
static void
|
834
|
-
test_set_vendor_handler_if_handler_is_NULL() {
|
835
|
-
expect_string( mock_die, format, "Callback function ( vendor_handler ) must not be NULL." );
|
836
|
-
expect_assert_failure( set_vendor_handler( NULL, NULL ) );
|
837
|
-
assert_memory_equal( &event_handlers, &NULL_EVENT_HANDLERS, sizeof( event_handlers ) );
|
838
|
-
}
|
839
|
-
|
840
|
-
|
841
|
-
/********************************************************************************
|
842
|
-
* set_features_reply_handler() tests.
|
843
|
-
********************************************************************************/
|
844
|
-
|
845
|
-
static void
|
846
|
-
test_set_features_reply_handler() {
|
847
|
-
assert_true( set_features_reply_handler( FEATURES_REPLY_HANDLER, FEATURES_REPLY_USER_DATA ) );
|
848
|
-
assert_int_equal( event_handlers.features_reply_callback, FEATURES_REPLY_HANDLER );
|
849
|
-
assert_int_equal( event_handlers.features_reply_user_data, FEATURES_REPLY_USER_DATA );
|
850
|
-
}
|
851
|
-
|
852
|
-
|
853
|
-
static void
|
854
|
-
test_set_features_reply_handler_if_handler_is_NULL() {
|
855
|
-
expect_string( mock_die, format, "Callback function ( features_reply_handler ) must not be NULL." );
|
856
|
-
expect_assert_failure( set_features_reply_handler( NULL, NULL ) );
|
857
|
-
assert_memory_equal( &event_handlers, &NULL_EVENT_HANDLERS, sizeof( event_handlers ) );
|
858
|
-
}
|
859
|
-
|
860
|
-
|
861
|
-
/********************************************************************************
|
862
|
-
* set_get_config_reply_handler() tests.
|
863
|
-
********************************************************************************/
|
864
|
-
|
865
|
-
static void
|
866
|
-
test_set_get_config_reply_handler() {
|
867
|
-
assert_true( set_get_config_reply_handler( GET_CONFIG_REPLY_HANDLER, GET_CONFIG_REPLY_USER_DATA ) );
|
868
|
-
assert_int_equal( event_handlers.get_config_reply_callback, GET_CONFIG_REPLY_HANDLER );
|
869
|
-
assert_int_equal( event_handlers.get_config_reply_user_data, GET_CONFIG_REPLY_USER_DATA );
|
870
|
-
}
|
871
|
-
|
872
|
-
|
873
|
-
static void
|
874
|
-
test_set_get_config_reply_handler_if_handler_is_NULL() {
|
875
|
-
expect_string( mock_die, format, "Callback function ( get_config_reply_handler ) must not be NULL." );
|
876
|
-
expect_assert_failure( set_get_config_reply_handler( NULL, NULL ) );
|
877
|
-
assert_memory_equal( &event_handlers, &NULL_EVENT_HANDLERS, sizeof( event_handlers ) );
|
878
|
-
}
|
879
|
-
|
880
|
-
|
881
|
-
/********************************************************************************
|
882
|
-
* Packet in handler tests.
|
883
|
-
********************************************************************************/
|
884
|
-
|
885
|
-
static void
|
886
|
-
mock_packet_in_handler(
|
887
|
-
uint64_t datapath_id,
|
888
|
-
uint32_t transaction_id,
|
889
|
-
uint32_t buffer_id,
|
890
|
-
uint16_t total_len,
|
891
|
-
uint16_t in_port,
|
892
|
-
uint8_t reason,
|
893
|
-
const buffer *data,
|
894
|
-
void *user_data
|
895
|
-
) {
|
896
|
-
uint32_t total_len32 = total_len;
|
897
|
-
uint32_t in_port32 = in_port;
|
898
|
-
uint32_t reason32 = reason;
|
899
|
-
|
900
|
-
check_expected( &datapath_id );
|
901
|
-
check_expected( transaction_id );
|
902
|
-
check_expected( buffer_id );
|
903
|
-
check_expected( total_len32 );
|
904
|
-
check_expected( in_port32 );
|
905
|
-
check_expected( reason32 );
|
906
|
-
if ( data != NULL ) {
|
907
|
-
check_expected( data->length );
|
908
|
-
check_expected( data->data );
|
909
|
-
}
|
910
|
-
else {
|
911
|
-
void *data_uc = ( void * ) ( unsigned long ) data;
|
912
|
-
check_expected( data_uc );
|
913
|
-
}
|
914
|
-
check_expected( user_data );
|
915
|
-
|
916
|
-
packet_in_handler_called = true;
|
917
|
-
}
|
918
|
-
|
919
|
-
|
920
|
-
static void
|
921
|
-
mock_simple_packet_in_handler( uint64_t dpid, packet_in event ) {
|
922
|
-
uint64_t datapath_id = dpid;
|
923
|
-
uint32_t transaction_id = event.transaction_id;
|
924
|
-
uint32_t buffer_id = event.buffer_id;
|
925
|
-
uint32_t total_len32 = event.total_len;
|
926
|
-
uint32_t in_port32 = event.in_port;
|
927
|
-
uint32_t reason32 = event.reason;
|
928
|
-
const buffer *data = event.data;
|
929
|
-
void *user_data = event.user_data;
|
930
|
-
|
931
|
-
check_expected( &datapath_id );
|
932
|
-
check_expected( transaction_id );
|
933
|
-
check_expected( buffer_id );
|
934
|
-
check_expected( total_len32 );
|
935
|
-
check_expected( in_port32 );
|
936
|
-
check_expected( reason32 );
|
937
|
-
check_expected( data->length );
|
938
|
-
check_expected( user_data );
|
939
|
-
|
940
|
-
packet_in_handler_called = true;
|
941
|
-
}
|
942
|
-
|
943
|
-
|
944
|
-
static void
|
945
|
-
test_set_packet_in_handler() {
|
946
|
-
set_packet_in_handler( mock_packet_in_handler, PACKET_IN_USER_DATA );
|
947
|
-
assert_true( event_handlers.packet_in_callback == mock_packet_in_handler );
|
948
|
-
assert_true( event_handlers.packet_in_user_data == PACKET_IN_USER_DATA );
|
949
|
-
}
|
950
|
-
|
951
|
-
|
952
|
-
static void
|
953
|
-
test_set_simple_packet_in_handler() {
|
954
|
-
set_packet_in_handler( mock_simple_packet_in_handler, PACKET_IN_USER_DATA );
|
955
|
-
assert_true( event_handlers.packet_in_callback == mock_simple_packet_in_handler );
|
956
|
-
assert_true( event_handlers.packet_in_user_data == PACKET_IN_USER_DATA );
|
957
|
-
}
|
958
|
-
|
959
|
-
|
960
|
-
static void
|
961
|
-
test_set_packet_in_handler_should_die_if_handler_is_NULL() {
|
962
|
-
expect_string( mock_die, format, "Callback function (packet_in_handler) must not be NULL." );
|
963
|
-
expect_assert_failure( set_packet_in_handler( NULL, PACKET_IN_USER_DATA ) );
|
964
|
-
assert_memory_equal( &event_handlers, &NULL_EVENT_HANDLERS, sizeof( event_handlers ) );
|
965
|
-
}
|
966
|
-
|
967
|
-
|
968
|
-
static void
|
969
|
-
test_handle_packet_in() {
|
970
|
-
uint8_t reason = OFPR_NO_MATCH;
|
971
|
-
uint16_t in_port = 1;
|
972
|
-
uint32_t buffer_id = 0x01020304;
|
973
|
-
buffer *data = alloc_buffer_with_length( 64 );
|
974
|
-
calloc_packet_info( data );
|
975
|
-
append_back_buffer( data, 64 );
|
976
|
-
memset( data->data, 0x01, 64 );
|
977
|
-
uint16_t total_len = ( uint16_t ) data->length;
|
978
|
-
|
979
|
-
will_return( mock_parse_packet, true );
|
980
|
-
expect_memory( mock_packet_in_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
981
|
-
expect_value( mock_packet_in_handler, transaction_id, TRANSACTION_ID );
|
982
|
-
expect_value( mock_packet_in_handler, buffer_id, buffer_id );
|
983
|
-
expect_value( mock_packet_in_handler, total_len32, ( uint32_t ) total_len );
|
984
|
-
expect_value( mock_packet_in_handler, in_port32, ( uint32_t ) in_port );
|
985
|
-
expect_value( mock_packet_in_handler, reason32, ( uint32_t ) reason );
|
986
|
-
expect_value( mock_packet_in_handler, data->length, data->length );
|
987
|
-
expect_memory( mock_packet_in_handler, data->data, data->data, data->length );
|
988
|
-
expect_memory( mock_packet_in_handler, user_data, USER_DATA, USER_DATA_LEN );
|
989
|
-
|
990
|
-
set_packet_in_handler( mock_packet_in_handler, USER_DATA );
|
991
|
-
|
992
|
-
buffer *buffer = create_packet_in( TRANSACTION_ID, buffer_id, total_len, in_port, reason, data );
|
993
|
-
handle_packet_in( DATAPATH_ID, buffer );
|
994
|
-
|
995
|
-
free_buffer( buffer );
|
996
|
-
}
|
997
|
-
|
998
|
-
|
999
|
-
static void
|
1000
|
-
test_handle_packet_in_with_simple_handler() {
|
1001
|
-
uint8_t reason = OFPR_NO_MATCH;
|
1002
|
-
uint16_t in_port = 1;
|
1003
|
-
uint32_t buffer_id = 0x01020304;
|
1004
|
-
buffer *data = alloc_buffer_with_length( 64 );
|
1005
|
-
calloc_packet_info( data );
|
1006
|
-
append_back_buffer( data, 64 );
|
1007
|
-
memset( data->data, 0x01, 64 );
|
1008
|
-
uint16_t total_len = ( uint16_t ) data->length;
|
1009
|
-
|
1010
|
-
will_return( mock_parse_packet, true );
|
1011
|
-
expect_memory( mock_simple_packet_in_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
1012
|
-
expect_value( mock_simple_packet_in_handler, transaction_id, TRANSACTION_ID );
|
1013
|
-
expect_value( mock_simple_packet_in_handler, buffer_id, buffer_id );
|
1014
|
-
expect_value( mock_simple_packet_in_handler, total_len32, ( uint32_t ) total_len );
|
1015
|
-
expect_value( mock_simple_packet_in_handler, in_port32, ( uint32_t ) in_port );
|
1016
|
-
expect_value( mock_simple_packet_in_handler, reason32, ( uint32_t ) reason );
|
1017
|
-
expect_value( mock_simple_packet_in_handler, data->length, data->length );
|
1018
|
-
expect_memory( mock_simple_packet_in_handler, user_data, USER_DATA, USER_DATA_LEN );
|
1019
|
-
|
1020
|
-
set_packet_in_handler( mock_simple_packet_in_handler, USER_DATA );
|
1021
|
-
|
1022
|
-
buffer *buffer = create_packet_in( TRANSACTION_ID, buffer_id, total_len, in_port, reason, data );
|
1023
|
-
handle_packet_in( DATAPATH_ID, buffer );
|
1024
|
-
|
1025
|
-
free_buffer( buffer );
|
1026
|
-
}
|
1027
|
-
|
1028
|
-
|
1029
|
-
static void
|
1030
|
-
test_handle_packet_in_with_malformed_packet() {
|
1031
|
-
uint8_t reason = OFPR_NO_MATCH;
|
1032
|
-
uint16_t in_port = 1;
|
1033
|
-
uint32_t buffer_id = 0x01020304;
|
1034
|
-
buffer *data = alloc_buffer_with_length( 64 );
|
1035
|
-
calloc_packet_info( data );
|
1036
|
-
append_back_buffer( data, 64 );
|
1037
|
-
memset( data->data, 0x01, 64 );
|
1038
|
-
uint16_t total_len = ( uint16_t ) data->length;
|
1039
|
-
buffer *buffer = create_packet_in( TRANSACTION_ID, buffer_id, total_len, in_port, reason, data );
|
1040
|
-
|
1041
|
-
will_return( mock_parse_packet, false );
|
1042
|
-
|
1043
|
-
set_packet_in_handler( mock_packet_in_handler, USER_DATA );
|
1044
|
-
handle_packet_in( DATAPATH_ID, buffer );
|
1045
|
-
|
1046
|
-
assert_false( packet_in_handler_called );
|
1047
|
-
|
1048
|
-
free_buffer( buffer );
|
1049
|
-
}
|
1050
|
-
|
1051
|
-
|
1052
|
-
static void
|
1053
|
-
test_handle_packet_in_without_data() {
|
1054
|
-
uint8_t reason = OFPR_NO_MATCH;
|
1055
|
-
uint16_t in_port = 1;
|
1056
|
-
uint32_t buffer_id = 0x01020304;
|
1057
|
-
buffer *data = alloc_buffer_with_length( 64 );
|
1058
|
-
append_back_buffer( data, 64 );
|
1059
|
-
memset( data->data, 0x01, 64 );
|
1060
|
-
uint16_t total_len = ( uint16_t ) data->length;
|
1061
|
-
|
1062
|
-
expect_memory( mock_packet_in_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
1063
|
-
expect_value( mock_packet_in_handler, transaction_id, TRANSACTION_ID );
|
1064
|
-
expect_value( mock_packet_in_handler, buffer_id, buffer_id );
|
1065
|
-
expect_value( mock_packet_in_handler, total_len32, ( uint32_t ) total_len );
|
1066
|
-
expect_value( mock_packet_in_handler, in_port32, ( uint32_t ) in_port );
|
1067
|
-
expect_value( mock_packet_in_handler, reason32, ( uint32_t ) reason );
|
1068
|
-
expect_value( mock_packet_in_handler, data_uc, NULL );
|
1069
|
-
expect_memory( mock_packet_in_handler, user_data, USER_DATA, USER_DATA_LEN );
|
1070
|
-
|
1071
|
-
set_packet_in_handler( mock_packet_in_handler, USER_DATA );
|
1072
|
-
|
1073
|
-
buffer *buffer = create_packet_in( TRANSACTION_ID, buffer_id, total_len, in_port, reason, NULL );
|
1074
|
-
handle_packet_in( DATAPATH_ID, buffer );
|
1075
|
-
|
1076
|
-
free_buffer( data );
|
1077
|
-
free_buffer( buffer );
|
1078
|
-
}
|
1079
|
-
|
1080
|
-
|
1081
|
-
static void
|
1082
|
-
test_handle_packet_in_without_handler() {
|
1083
|
-
uint8_t reason = OFPR_NO_MATCH;
|
1084
|
-
uint16_t in_port = 1;
|
1085
|
-
uint32_t buffer_id = 0x01020304;
|
1086
|
-
buffer *data = alloc_buffer_with_length( 64 );
|
1087
|
-
append_back_buffer( data, 64 );
|
1088
|
-
memset( data->data, 0x01, 64 );
|
1089
|
-
uint16_t total_len = ( uint16_t ) data->length;
|
1090
|
-
buffer *buffer = create_packet_in( TRANSACTION_ID, buffer_id, total_len, in_port, reason, data );
|
1091
|
-
|
1092
|
-
handle_packet_in( DATAPATH_ID, buffer );
|
1093
|
-
assert_false( packet_in_handler_called );
|
1094
|
-
|
1095
|
-
free_buffer( data );
|
1096
|
-
free_buffer( buffer );
|
1097
|
-
}
|
1098
|
-
|
1099
|
-
|
1100
|
-
static void
|
1101
|
-
test_handle_packet_in_should_die_if_message_is_NULL() {
|
1102
|
-
expect_string( mock_die, format, "handle_packet_in(): packet_in message should not be empty." );
|
1103
|
-
set_packet_in_handler( mock_packet_in_handler, USER_DATA );
|
1104
|
-
expect_assert_failure( handle_packet_in( DATAPATH_ID, NULL ) );
|
1105
|
-
}
|
1106
|
-
|
1107
|
-
|
1108
|
-
static void
|
1109
|
-
test_handle_packet_in_should_die_if_message_length_is_zero() {
|
1110
|
-
buffer *buffer = alloc_buffer_with_length( 32 );
|
1111
|
-
|
1112
|
-
expect_string( mock_die, format, "handle_packet_in(): packet_in message should not be empty." );
|
1113
|
-
set_packet_in_handler( mock_packet_in_handler, USER_DATA );
|
1114
|
-
expect_assert_failure( handle_packet_in( DATAPATH_ID, buffer ) );
|
1115
|
-
|
1116
|
-
free_buffer( buffer );
|
1117
|
-
}
|
1118
|
-
|
1119
|
-
|
1120
|
-
/********************************************************************************
|
1121
|
-
* set_flow_removed_handler() tests.
|
1122
|
-
********************************************************************************/
|
1123
|
-
|
1124
|
-
static void
|
1125
|
-
mock_simple_flow_removed_handler( uint64_t datapath_id, flow_removed message ) {
|
1126
|
-
uint32_t transaction_id = message.transaction_id;
|
1127
|
-
struct ofp_match match = message.match;
|
1128
|
-
uint64_t cookie = message.cookie;
|
1129
|
-
uint32_t priority32 = message.priority;
|
1130
|
-
uint32_t reason32 = message.reason;
|
1131
|
-
uint32_t duration_sec = message.duration_sec;
|
1132
|
-
uint32_t duration_nsec = message.duration_nsec;
|
1133
|
-
uint32_t idle_timeout32 = message.idle_timeout;
|
1134
|
-
uint64_t packet_count = message.packet_count;
|
1135
|
-
uint64_t byte_count = message.byte_count;
|
1136
|
-
void *user_data = message.user_data;
|
1137
|
-
|
1138
|
-
check_expected( &datapath_id );
|
1139
|
-
check_expected( transaction_id );
|
1140
|
-
check_expected( &match );
|
1141
|
-
check_expected( &cookie );
|
1142
|
-
check_expected( priority32 );
|
1143
|
-
check_expected( reason32 );
|
1144
|
-
check_expected( duration_sec );
|
1145
|
-
check_expected( duration_nsec );
|
1146
|
-
check_expected( idle_timeout32 );
|
1147
|
-
check_expected( &packet_count );
|
1148
|
-
check_expected( &byte_count );
|
1149
|
-
check_expected( user_data );
|
1150
|
-
}
|
1151
|
-
|
1152
|
-
|
1153
|
-
static void
|
1154
|
-
test_set_flow_removed_handler() {
|
1155
|
-
set_flow_removed_handler( mock_flow_removed_handler, FLOW_REMOVED_USER_DATA );
|
1156
|
-
assert_true( event_handlers.flow_removed_callback == mock_flow_removed_handler );
|
1157
|
-
assert_true( event_handlers.flow_removed_user_data == FLOW_REMOVED_USER_DATA );
|
1158
|
-
}
|
1159
|
-
|
1160
|
-
|
1161
|
-
static void
|
1162
|
-
test_set_simple_flow_removed_handler() {
|
1163
|
-
set_flow_removed_handler( mock_simple_flow_removed_handler, FLOW_REMOVED_USER_DATA );
|
1164
|
-
assert_true( event_handlers.flow_removed_callback == mock_simple_flow_removed_handler );
|
1165
|
-
assert_true( event_handlers.flow_removed_user_data == FLOW_REMOVED_USER_DATA );
|
1166
|
-
}
|
1167
|
-
|
1168
|
-
|
1169
|
-
static void
|
1170
|
-
test_set_flow_removed_handler_if_handler_is_NULL() {
|
1171
|
-
expect_string( mock_die, format, "Callback function (flow_removed_handler) must not be NULL." );
|
1172
|
-
expect_assert_failure( set_flow_removed_handler( NULL, NULL ) );
|
1173
|
-
assert_memory_equal( &event_handlers, &NULL_EVENT_HANDLERS, sizeof( event_handlers ) );
|
1174
|
-
}
|
1175
|
-
|
1176
|
-
|
1177
|
-
/********************************************************************************
|
1178
|
-
* set_port_status_handler() tests.
|
1179
|
-
********************************************************************************/
|
1180
|
-
|
1181
|
-
static void
|
1182
|
-
test_set_port_status_handler() {
|
1183
|
-
assert_true( set_port_status_handler( PORT_STATUS_HANDLER, PORT_STATUS_USER_DATA ) );
|
1184
|
-
assert_int_equal( event_handlers.port_status_callback, PORT_STATUS_HANDLER );
|
1185
|
-
assert_int_equal( event_handlers.port_status_user_data, PORT_STATUS_USER_DATA );
|
1186
|
-
}
|
1187
|
-
|
1188
|
-
|
1189
|
-
static void
|
1190
|
-
test_set_port_status_handler_if_handler_is_NULL() {
|
1191
|
-
expect_string( mock_die, format, "Callback function ( port_status_handler ) must not be NULL." );
|
1192
|
-
expect_assert_failure( set_port_status_handler( NULL, NULL ) );
|
1193
|
-
assert_memory_equal( &event_handlers, &NULL_EVENT_HANDLERS, sizeof( event_handlers ) );
|
1194
|
-
}
|
1195
|
-
|
1196
|
-
|
1197
|
-
/********************************************************************************
|
1198
|
-
* set_stats_reply_handler() tests.
|
1199
|
-
********************************************************************************/
|
1200
|
-
|
1201
|
-
static void
|
1202
|
-
test_set_stats_reply_handler() {
|
1203
|
-
assert_true( set_stats_reply_handler( STATS_REPLY_HANDLER, STATS_REPLY_USER_DATA ) );
|
1204
|
-
assert_int_equal( event_handlers.stats_reply_callback, STATS_REPLY_HANDLER );
|
1205
|
-
assert_int_equal( event_handlers.stats_reply_user_data, STATS_REPLY_USER_DATA );
|
1206
|
-
}
|
1207
|
-
|
1208
|
-
|
1209
|
-
static void
|
1210
|
-
test_set_stats_reply_handler_if_handler_is_NULL() {
|
1211
|
-
expect_string( mock_die, format, "Callback function ( stats_reply_handler ) must not be NULL." );
|
1212
|
-
expect_assert_failure( set_stats_reply_handler( NULL, NULL ) );
|
1213
|
-
assert_memory_equal( &event_handlers, &NULL_EVENT_HANDLERS, sizeof( event_handlers ) );
|
1214
|
-
}
|
1215
|
-
|
1216
|
-
|
1217
|
-
/********************************************************************************
|
1218
|
-
* set_barrier_reply_handler() tests.
|
1219
|
-
********************************************************************************/
|
1220
|
-
|
1221
|
-
static void
|
1222
|
-
test_set_barrier_reply_handler() {
|
1223
|
-
assert_true( set_barrier_reply_handler( BARRIER_REPLY_HANDLER, BARRIER_REPLY_USER_DATA ) );
|
1224
|
-
assert_int_equal( event_handlers.barrier_reply_callback, BARRIER_REPLY_HANDLER );
|
1225
|
-
assert_int_equal( event_handlers.barrier_reply_user_data, BARRIER_REPLY_USER_DATA );
|
1226
|
-
}
|
1227
|
-
|
1228
|
-
|
1229
|
-
static void
|
1230
|
-
test_set_barrier_reply_handler_if_handler_is_NULL() {
|
1231
|
-
expect_string( mock_die, format, "Callback function ( barrier_reply_handler ) must not be NULL." );
|
1232
|
-
expect_assert_failure( set_barrier_reply_handler( NULL, NULL ) );
|
1233
|
-
assert_memory_equal( &event_handlers, &NULL_EVENT_HANDLERS, sizeof( event_handlers ) );
|
1234
|
-
}
|
1235
|
-
|
1236
|
-
|
1237
|
-
/********************************************************************************
|
1238
|
-
* set_queue_get_config_reply_handler() tests.
|
1239
|
-
********************************************************************************/
|
1240
|
-
|
1241
|
-
static void
|
1242
|
-
test_set_queue_get_config_reply_handler() {
|
1243
|
-
assert_true( set_queue_get_config_reply_handler( QUEUE_GET_CONFIG_REPLY_HANDLER, QUEUE_GET_CONFIG_REPLY_USER_DATA ) );
|
1244
|
-
assert_int_equal( event_handlers.queue_get_config_reply_callback, QUEUE_GET_CONFIG_REPLY_HANDLER );
|
1245
|
-
assert_int_equal( event_handlers.queue_get_config_reply_user_data, QUEUE_GET_CONFIG_REPLY_USER_DATA );
|
1246
|
-
}
|
1247
|
-
|
1248
|
-
|
1249
|
-
static void
|
1250
|
-
test_set_queue_get_config_reply_handler_if_handler_is_NULL() {
|
1251
|
-
expect_string( mock_die, format, "Callback function ( queue_get_config_reply_handler ) must not be NULL." );
|
1252
|
-
expect_assert_failure( set_queue_get_config_reply_handler( NULL, NULL ) );
|
1253
|
-
assert_memory_equal( &event_handlers, &NULL_EVENT_HANDLERS, sizeof( event_handlers ) );
|
1254
|
-
}
|
1255
|
-
|
1256
|
-
|
1257
|
-
/********************************************************************************
|
1258
|
-
* set_list_switches_reply_handler() tests.
|
1259
|
-
********************************************************************************/
|
1260
|
-
|
1261
|
-
|
1262
|
-
static void
|
1263
|
-
test_set_list_switches_reply_handler() {
|
1264
|
-
assert_true( set_list_switches_reply_handler( LIST_SWITCHES_REPLY_HANDLER ) );
|
1265
|
-
assert_int_equal( event_handlers.list_switches_reply_callback, LIST_SWITCHES_REPLY_HANDLER );
|
1266
|
-
}
|
1267
|
-
|
1268
|
-
|
1269
|
-
static void
|
1270
|
-
test_set_list_switches_reply_handler_if_handler_is_NULL() {
|
1271
|
-
expect_string( mock_die, format, "Callback function ( list_switches_reply_handler ) must not be NULL." );
|
1272
|
-
expect_assert_failure( set_list_switches_reply_handler( NULL ) );
|
1273
|
-
assert_memory_equal( &event_handlers, &NULL_EVENT_HANDLERS, sizeof( event_handlers ) );
|
1274
|
-
}
|
1275
|
-
|
1276
|
-
|
1277
|
-
/********************************************************************************
|
1278
|
-
* send_openflow_message() tests.
|
1279
|
-
********************************************************************************/
|
1280
|
-
|
1281
|
-
static void
|
1282
|
-
test_send_openflow_message() {
|
1283
|
-
void *expected_data;
|
1284
|
-
bool ret;
|
1285
|
-
size_t expected_length, header_length;
|
1286
|
-
buffer *buffer;
|
1287
|
-
openflow_service_header_t *header;
|
1288
|
-
|
1289
|
-
buffer = create_hello( TRANSACTION_ID );
|
1290
|
-
|
1291
|
-
assert_true( buffer != NULL );
|
1292
|
-
|
1293
|
-
header_length = ( size_t ) ( sizeof( openflow_service_header_t ) +
|
1294
|
-
strlen( SERVICE_NAME ) + 1 );
|
1295
|
-
expected_length = ( size_t ) ( header_length + sizeof( struct ofp_header ) );
|
1296
|
-
|
1297
|
-
expected_data = xcalloc( 1, expected_length );
|
1298
|
-
|
1299
|
-
header = expected_data;
|
1300
|
-
header->datapath_id = htonll( DATAPATH_ID );
|
1301
|
-
header->service_name_length = htons( ( uint16_t ) ( strlen( SERVICE_NAME ) + 1 ) );
|
1302
|
-
|
1303
|
-
memcpy( ( char * ) expected_data + sizeof( openflow_service_header_t ),
|
1304
|
-
SERVICE_NAME, strlen( SERVICE_NAME ) + 1 );
|
1305
|
-
memcpy( ( char * ) expected_data + header_length, buffer->data, buffer->length );
|
1306
|
-
|
1307
|
-
expect_string( mock_send_message, service_name, REMOTE_SERVICE_NAME );
|
1308
|
-
expect_value( mock_send_message, tag32, MESSENGER_OPENFLOW_MESSAGE );
|
1309
|
-
expect_value( mock_send_message, len, expected_length );
|
1310
|
-
expect_memory( mock_send_message, data, expected_data, expected_length );
|
1311
|
-
will_return( mock_send_message, true );
|
1312
|
-
|
1313
|
-
ret = send_openflow_message( DATAPATH_ID, buffer );
|
1314
|
-
|
1315
|
-
assert_true( ret );
|
1316
|
-
stat_entry *stat = lookup_hash_entry( stats, "openflow_application_interface.hello_send_succeeded" );
|
1317
|
-
assert_int_equal( ( int ) stat->value, 1 );
|
1318
|
-
|
1319
|
-
free_buffer( buffer );
|
1320
|
-
xfree( expected_data );
|
1321
|
-
xfree( delete_hash_entry( stats, "openflow_application_interface.hello_send_succeeded" ) );
|
1322
|
-
}
|
1323
|
-
|
1324
|
-
|
1325
|
-
static void
|
1326
|
-
test_send_openflow_message_if_message_is_NULL() {
|
1327
|
-
expect_assert_failure( send_openflow_message( DATAPATH_ID, NULL ) );
|
1328
|
-
}
|
1329
|
-
|
1330
|
-
|
1331
|
-
static void
|
1332
|
-
test_send_openflow_message_if_message_length_is_zero() {
|
1333
|
-
buffer *buffer;
|
1334
|
-
|
1335
|
-
buffer = alloc_buffer_with_length( 128 );
|
1336
|
-
|
1337
|
-
assert_true( buffer != NULL );
|
1338
|
-
|
1339
|
-
expect_assert_failure( send_openflow_message( DATAPATH_ID, NULL ) );
|
1340
|
-
|
1341
|
-
free_buffer( buffer );
|
1342
|
-
}
|
1343
|
-
|
1344
|
-
|
1345
|
-
/********************************************************************************
|
1346
|
-
* handle_error() tests.
|
1347
|
-
********************************************************************************/
|
1348
|
-
|
1349
|
-
static void
|
1350
|
-
test_handle_error() {
|
1351
|
-
buffer *buffer, *data;
|
1352
|
-
|
1353
|
-
data = alloc_buffer_with_length( 16 );
|
1354
|
-
append_back_buffer( data, 16 );
|
1355
|
-
memset( data->data, 'a', 16 );
|
1356
|
-
|
1357
|
-
buffer = create_error( TRANSACTION_ID, OFPET_HELLO_FAILED, OFPHFC_INCOMPATIBLE, data );
|
1358
|
-
|
1359
|
-
expect_memory( mock_error_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
1360
|
-
expect_value( mock_error_handler, transaction_id, TRANSACTION_ID );
|
1361
|
-
expect_value( mock_error_handler, type32, OFPET_HELLO_FAILED );
|
1362
|
-
expect_value( mock_error_handler, code32, OFPHFC_INCOMPATIBLE );
|
1363
|
-
expect_value( mock_error_handler, data->length, data->length );
|
1364
|
-
expect_memory( mock_error_handler, data->data, data->data, data->length );
|
1365
|
-
expect_memory( mock_error_handler, user_data, USER_DATA, USER_DATA_LEN );
|
1366
|
-
|
1367
|
-
set_error_handler( mock_error_handler, USER_DATA );
|
1368
|
-
handle_error( DATAPATH_ID, buffer );
|
1369
|
-
|
1370
|
-
free_buffer( data );
|
1371
|
-
free_buffer( buffer );
|
1372
|
-
}
|
1373
|
-
|
1374
|
-
|
1375
|
-
static void
|
1376
|
-
test_handle_error_if_handler_is_not_registered() {
|
1377
|
-
buffer *buffer, *data;
|
1378
|
-
|
1379
|
-
data = alloc_buffer_with_length( 16 );
|
1380
|
-
append_back_buffer( data, 16 );
|
1381
|
-
memset( data->data, 'a', 16 );
|
1382
|
-
|
1383
|
-
buffer = create_error( TRANSACTION_ID, OFPET_HELLO_FAILED, OFPHFC_INCOMPATIBLE, data );
|
1384
|
-
|
1385
|
-
// FIXME
|
1386
|
-
|
1387
|
-
handle_error( DATAPATH_ID, buffer );
|
1388
|
-
|
1389
|
-
free_buffer( data );
|
1390
|
-
free_buffer( buffer );
|
1391
|
-
}
|
1392
|
-
|
1393
|
-
|
1394
|
-
static void
|
1395
|
-
test_handle_error_if_message_is_NULL() {
|
1396
|
-
set_error_handler( mock_error_handler, USER_DATA );
|
1397
|
-
expect_assert_failure( handle_error( DATAPATH_ID, NULL ) );
|
1398
|
-
}
|
1399
|
-
|
1400
|
-
|
1401
|
-
static void
|
1402
|
-
test_handle_error_if_message_length_is_zero() {
|
1403
|
-
buffer *buffer;
|
1404
|
-
|
1405
|
-
buffer = alloc_buffer_with_length( 32 );
|
1406
|
-
|
1407
|
-
set_error_handler( mock_error_handler, USER_DATA );
|
1408
|
-
expect_assert_failure( handle_error( DATAPATH_ID, buffer ) );
|
1409
|
-
|
1410
|
-
free_buffer( buffer );
|
1411
|
-
}
|
1412
|
-
|
1413
|
-
|
1414
|
-
/********************************************************************************
|
1415
|
-
* handle_echo_request() tests.
|
1416
|
-
********************************************************************************/
|
1417
|
-
|
1418
|
-
static void
|
1419
|
-
test_handle_echo_reply() {
|
1420
|
-
buffer *buffer, *data;
|
1421
|
-
|
1422
|
-
data = alloc_buffer_with_length( 16 );
|
1423
|
-
append_back_buffer( data, 16 );
|
1424
|
-
memset( data->data, 'a', 16 );
|
1425
|
-
|
1426
|
-
buffer = create_echo_reply( TRANSACTION_ID, data );
|
1427
|
-
|
1428
|
-
expect_memory( mock_echo_reply_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
1429
|
-
expect_value( mock_echo_reply_handler, transaction_id, TRANSACTION_ID );
|
1430
|
-
expect_value( mock_echo_reply_handler, data->length, data->length );
|
1431
|
-
expect_memory( mock_echo_reply_handler, data->data, data->data, data->length );
|
1432
|
-
expect_memory( mock_echo_reply_handler, user_data, USER_DATA, USER_DATA_LEN );
|
1433
|
-
|
1434
|
-
set_echo_reply_handler( mock_echo_reply_handler, USER_DATA );
|
1435
|
-
handle_echo_reply( DATAPATH_ID, buffer );
|
1436
|
-
|
1437
|
-
free_buffer( data );
|
1438
|
-
free_buffer( buffer );
|
1439
|
-
}
|
1440
|
-
|
1441
|
-
|
1442
|
-
static void
|
1443
|
-
test_handle_echo_reply_without_data() {
|
1444
|
-
buffer *buffer;
|
1445
|
-
|
1446
|
-
buffer = create_echo_reply( TRANSACTION_ID, NULL );
|
1447
|
-
|
1448
|
-
expect_memory( mock_echo_reply_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
1449
|
-
expect_value( mock_echo_reply_handler, transaction_id, TRANSACTION_ID );
|
1450
|
-
expect_value( mock_echo_reply_handler, data_uc, NULL );
|
1451
|
-
expect_memory( mock_echo_reply_handler, user_data, USER_DATA, USER_DATA_LEN );
|
1452
|
-
|
1453
|
-
set_echo_reply_handler( mock_echo_reply_handler, USER_DATA );
|
1454
|
-
handle_echo_reply( DATAPATH_ID, buffer );
|
1455
|
-
|
1456
|
-
free_buffer( buffer );
|
1457
|
-
}
|
1458
|
-
|
1459
|
-
|
1460
|
-
static void
|
1461
|
-
test_handle_echo_reply_if_handler_is_not_registered() {
|
1462
|
-
buffer *buffer, *data;
|
1463
|
-
|
1464
|
-
data = alloc_buffer_with_length( 16 );
|
1465
|
-
append_back_buffer( data, 16 );
|
1466
|
-
memset( data->data, 'a', 16 );
|
1467
|
-
|
1468
|
-
buffer = create_echo_reply( TRANSACTION_ID, data );
|
1469
|
-
|
1470
|
-
// FIXME
|
1471
|
-
|
1472
|
-
handle_echo_reply( DATAPATH_ID, buffer );
|
1473
|
-
|
1474
|
-
free_buffer( data );
|
1475
|
-
free_buffer( buffer );
|
1476
|
-
}
|
1477
|
-
|
1478
|
-
|
1479
|
-
static void
|
1480
|
-
test_handle_echo_reply_if_message_is_NULL() {
|
1481
|
-
set_echo_reply_handler( mock_echo_reply_handler, USER_DATA );
|
1482
|
-
expect_assert_failure( handle_echo_reply( DATAPATH_ID, NULL ) );
|
1483
|
-
}
|
1484
|
-
|
1485
|
-
|
1486
|
-
static void
|
1487
|
-
test_handle_echo_reply_if_message_length_is_zero() {
|
1488
|
-
buffer *buffer;
|
1489
|
-
|
1490
|
-
buffer = alloc_buffer_with_length( 32 );
|
1491
|
-
|
1492
|
-
set_echo_reply_handler( mock_echo_reply_handler, USER_DATA );
|
1493
|
-
expect_assert_failure( handle_echo_reply( DATAPATH_ID, buffer ) );
|
1494
|
-
|
1495
|
-
free_buffer( buffer );
|
1496
|
-
}
|
1497
|
-
|
1498
|
-
|
1499
|
-
/********************************************************************************
|
1500
|
-
* handle_vendor() tests.
|
1501
|
-
********************************************************************************/
|
1502
|
-
|
1503
|
-
static void
|
1504
|
-
test_handle_vendor() {
|
1505
|
-
buffer *buffer, *data;
|
1506
|
-
|
1507
|
-
data = alloc_buffer_with_length( 16 );
|
1508
|
-
append_back_buffer( data, 16 );
|
1509
|
-
memset( data->data, 'a', 16 );
|
1510
|
-
|
1511
|
-
buffer = create_vendor( TRANSACTION_ID, VENDOR_ID, data );
|
1512
|
-
|
1513
|
-
expect_memory( mock_vendor_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
1514
|
-
expect_value( mock_vendor_handler, transaction_id, TRANSACTION_ID );
|
1515
|
-
expect_value( mock_vendor_handler, vendor, VENDOR_ID );
|
1516
|
-
expect_value( mock_vendor_handler, data->length, data->length );
|
1517
|
-
expect_memory( mock_vendor_handler, data->data, data->data, data->length );
|
1518
|
-
expect_memory( mock_vendor_handler, user_data, USER_DATA, USER_DATA_LEN );
|
1519
|
-
|
1520
|
-
set_vendor_handler( mock_vendor_handler, USER_DATA );
|
1521
|
-
handle_vendor( DATAPATH_ID, buffer );
|
1522
|
-
|
1523
|
-
free_buffer( data );
|
1524
|
-
free_buffer( buffer );
|
1525
|
-
}
|
1526
|
-
|
1527
|
-
|
1528
|
-
static void
|
1529
|
-
test_handle_vendor_without_data() {
|
1530
|
-
buffer *buffer;
|
1531
|
-
|
1532
|
-
buffer = create_vendor( TRANSACTION_ID, VENDOR_ID, NULL );
|
1533
|
-
|
1534
|
-
expect_memory( mock_vendor_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
1535
|
-
expect_value( mock_vendor_handler, transaction_id, TRANSACTION_ID );
|
1536
|
-
expect_value( mock_vendor_handler, vendor, VENDOR_ID );
|
1537
|
-
expect_value( mock_vendor_handler, data_uc, NULL );
|
1538
|
-
expect_memory( mock_vendor_handler, user_data, USER_DATA, USER_DATA_LEN );
|
1539
|
-
|
1540
|
-
set_vendor_handler( mock_vendor_handler, USER_DATA );
|
1541
|
-
handle_vendor( DATAPATH_ID, buffer );
|
1542
|
-
|
1543
|
-
free_buffer( buffer );
|
1544
|
-
}
|
1545
|
-
|
1546
|
-
|
1547
|
-
static void
|
1548
|
-
test_handle_vendor_if_handler_is_not_registered() {
|
1549
|
-
buffer *buffer, *data;
|
1550
|
-
|
1551
|
-
data = alloc_buffer_with_length( 16 );
|
1552
|
-
append_back_buffer( data, 16 );
|
1553
|
-
memset( data->data, 'a', 16 );
|
1554
|
-
|
1555
|
-
buffer = create_vendor( TRANSACTION_ID, VENDOR_ID, data );
|
1556
|
-
|
1557
|
-
// FIXME
|
1558
|
-
|
1559
|
-
handle_vendor( DATAPATH_ID, buffer );
|
1560
|
-
|
1561
|
-
free_buffer( data );
|
1562
|
-
free_buffer( buffer );
|
1563
|
-
}
|
1564
|
-
|
1565
|
-
|
1566
|
-
static void
|
1567
|
-
test_handle_vendor_if_message_is_NULL() {
|
1568
|
-
set_vendor_handler( mock_vendor_handler, USER_DATA );
|
1569
|
-
expect_assert_failure( handle_vendor( DATAPATH_ID, NULL ) );
|
1570
|
-
}
|
1571
|
-
|
1572
|
-
|
1573
|
-
static void
|
1574
|
-
test_handle_vendor_if_message_length_is_zero() {
|
1575
|
-
buffer *buffer;
|
1576
|
-
|
1577
|
-
buffer = alloc_buffer_with_length( 32 );
|
1578
|
-
|
1579
|
-
set_vendor_handler( mock_vendor_handler, USER_DATA );
|
1580
|
-
expect_assert_failure( handle_vendor( DATAPATH_ID, buffer ) );
|
1581
|
-
|
1582
|
-
free_buffer( buffer );
|
1583
|
-
}
|
1584
|
-
|
1585
|
-
|
1586
|
-
/********************************************************************************
|
1587
|
-
* handle_features_reply() tests.
|
1588
|
-
********************************************************************************/
|
1589
|
-
|
1590
|
-
static void
|
1591
|
-
test_handle_features_reply() {
|
1592
|
-
uint8_t n_tables = 2;
|
1593
|
-
uint32_t n_buffers = 1024;
|
1594
|
-
uint32_t capabilities;
|
1595
|
-
uint32_t actions;
|
1596
|
-
struct ofp_phy_port *phy_port[ 2 ];
|
1597
|
-
buffer *buffer;
|
1598
|
-
list_element *ports;
|
1599
|
-
|
1600
|
-
capabilities = ( OFPC_FLOW_STATS | OFPC_TABLE_STATS | OFPC_PORT_STATS |
|
1601
|
-
OFPC_QUEUE_STATS | OFPC_ARP_MATCH_IP );
|
1602
|
-
actions = ( ( 1 << OFPAT_OUTPUT ) | ( 1 << OFPAT_SET_VLAN_VID ) |
|
1603
|
-
( 1 << OFPAT_SET_TP_SRC ) | ( 1 << OFPAT_SET_TP_DST ) );
|
1604
|
-
|
1605
|
-
phy_port[ 0 ] = xcalloc( 1, sizeof( struct ofp_phy_port ) );
|
1606
|
-
phy_port[ 1 ] = xcalloc( 1, sizeof( struct ofp_phy_port ) );
|
1607
|
-
|
1608
|
-
phy_port[ 0 ]->port_no = 1;
|
1609
|
-
memcpy( phy_port[ 0 ]->hw_addr, MAC_ADDR_X, sizeof( phy_port[ 0 ]->hw_addr ) );
|
1610
|
-
memset( phy_port[ 0 ]->name, '\0', OFP_MAX_PORT_NAME_LEN );
|
1611
|
-
memcpy( phy_port[ 0 ]->name, PORT_NAME, strlen( PORT_NAME ) );
|
1612
|
-
phy_port[ 0 ]->config = OFPPC_PORT_DOWN;
|
1613
|
-
phy_port[ 0 ]->state = OFPPS_LINK_DOWN;
|
1614
|
-
phy_port[ 0 ]->curr = ( OFPPF_1GB_FD | OFPPF_COPPER | OFPPF_PAUSE );
|
1615
|
-
phy_port[ 0 ]->advertised = PORT_FEATURES;
|
1616
|
-
phy_port[ 0 ]->supported = PORT_FEATURES;
|
1617
|
-
phy_port[ 0 ]->peer = PORT_FEATURES;
|
1618
|
-
|
1619
|
-
memcpy( phy_port[ 1 ], phy_port [ 0 ], sizeof( struct ofp_phy_port ) );
|
1620
|
-
|
1621
|
-
phy_port[ 1 ]->port_no = 2;
|
1622
|
-
memcpy( phy_port[ 1 ]->hw_addr, MAC_ADDR_Y, sizeof( phy_port[ 1 ]->hw_addr ) );
|
1623
|
-
|
1624
|
-
create_list( &ports );
|
1625
|
-
append_to_tail( &ports, phy_port[ 0 ] );
|
1626
|
-
append_to_tail( &ports, phy_port[ 1 ] );
|
1627
|
-
|
1628
|
-
buffer = create_features_reply( TRANSACTION_ID, DATAPATH_ID, n_buffers, n_tables,
|
1629
|
-
capabilities, actions, ports );
|
1630
|
-
|
1631
|
-
expect_memory( mock_features_reply_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
1632
|
-
expect_value( mock_features_reply_handler, transaction_id, TRANSACTION_ID );
|
1633
|
-
expect_value( mock_features_reply_handler, n_buffers, n_buffers );
|
1634
|
-
expect_value( mock_features_reply_handler, n_tables32, ( uint32_t ) n_tables );
|
1635
|
-
expect_value( mock_features_reply_handler, capabilities, capabilities );
|
1636
|
-
expect_value( mock_features_reply_handler, actions, actions );
|
1637
|
-
expect_memory( mock_features_reply_handler, port1, ports->data, sizeof( struct ofp_phy_port ) );
|
1638
|
-
expect_memory( mock_features_reply_handler, port2, ports->next->data, sizeof( struct ofp_phy_port ) );
|
1639
|
-
expect_memory( mock_features_reply_handler, user_data, USER_DATA, USER_DATA_LEN );
|
1640
|
-
|
1641
|
-
set_features_reply_handler( mock_features_reply_handler, USER_DATA );
|
1642
|
-
handle_features_reply( DATAPATH_ID, buffer );
|
1643
|
-
|
1644
|
-
xfree( phy_port[ 0 ] );
|
1645
|
-
xfree( phy_port[ 1 ] );
|
1646
|
-
delete_list( ports );
|
1647
|
-
free_buffer( buffer );
|
1648
|
-
}
|
1649
|
-
|
1650
|
-
|
1651
|
-
static void
|
1652
|
-
test_handle_features_reply_without_phy_port() {
|
1653
|
-
uint8_t n_tables = 2;
|
1654
|
-
uint32_t n_buffers = 1024;
|
1655
|
-
uint32_t capabilities;
|
1656
|
-
uint32_t actions;
|
1657
|
-
buffer *buffer;
|
1658
|
-
|
1659
|
-
capabilities = ( OFPC_FLOW_STATS | OFPC_TABLE_STATS | OFPC_PORT_STATS |
|
1660
|
-
OFPC_QUEUE_STATS | OFPC_ARP_MATCH_IP );
|
1661
|
-
actions = ( ( 1 << OFPAT_OUTPUT ) | ( 1 << OFPAT_SET_VLAN_VID ) |
|
1662
|
-
( 1 << OFPAT_SET_TP_SRC ) | ( 1 << OFPAT_SET_TP_DST ) );
|
1663
|
-
|
1664
|
-
buffer = create_features_reply( TRANSACTION_ID, DATAPATH_ID, n_buffers, n_tables,
|
1665
|
-
capabilities, actions, NULL );
|
1666
|
-
|
1667
|
-
expect_memory( mock_features_reply_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
1668
|
-
expect_value( mock_features_reply_handler, transaction_id, TRANSACTION_ID );
|
1669
|
-
expect_value( mock_features_reply_handler, n_buffers, n_buffers );
|
1670
|
-
expect_value( mock_features_reply_handler, n_tables32, ( uint32_t ) n_tables );
|
1671
|
-
expect_value( mock_features_reply_handler, capabilities, capabilities );
|
1672
|
-
expect_value( mock_features_reply_handler, actions, actions );
|
1673
|
-
expect_value( mock_features_reply_handler, phy_ports_uc, NULL );
|
1674
|
-
expect_memory( mock_features_reply_handler, user_data, USER_DATA, USER_DATA_LEN );
|
1675
|
-
|
1676
|
-
set_features_reply_handler( mock_features_reply_handler, USER_DATA );
|
1677
|
-
handle_features_reply( DATAPATH_ID, buffer );
|
1678
|
-
|
1679
|
-
free_buffer( buffer );
|
1680
|
-
}
|
1681
|
-
|
1682
|
-
|
1683
|
-
static void
|
1684
|
-
test_handle_features_reply_if_handler_is_not_registered() {
|
1685
|
-
uint8_t n_tables = 2;
|
1686
|
-
uint32_t n_buffers = 1024;
|
1687
|
-
uint32_t capabilities;
|
1688
|
-
uint32_t actions;
|
1689
|
-
struct ofp_phy_port *phy_port[ 2 ];
|
1690
|
-
buffer *buffer;
|
1691
|
-
list_element *ports;
|
1692
|
-
|
1693
|
-
capabilities = ( OFPC_FLOW_STATS | OFPC_TABLE_STATS | OFPC_PORT_STATS |
|
1694
|
-
OFPC_QUEUE_STATS | OFPC_ARP_MATCH_IP );
|
1695
|
-
actions = ( ( 1 << OFPAT_OUTPUT ) | ( 1 << OFPAT_SET_VLAN_VID ) |
|
1696
|
-
( 1 << OFPAT_SET_TP_SRC ) | ( 1 << OFPAT_SET_TP_DST ) );
|
1697
|
-
|
1698
|
-
phy_port[ 0 ] = xcalloc( 1, sizeof( struct ofp_phy_port ) );
|
1699
|
-
phy_port[ 1 ] = xcalloc( 1, sizeof( struct ofp_phy_port ) );
|
1700
|
-
|
1701
|
-
phy_port[ 0 ]->port_no = 1;
|
1702
|
-
memcpy( phy_port[ 0 ]->hw_addr, MAC_ADDR_X, sizeof( phy_port[ 0 ]->hw_addr ) );
|
1703
|
-
memset( phy_port[ 0 ]->name, '\0', OFP_MAX_PORT_NAME_LEN );
|
1704
|
-
memcpy( phy_port[ 0 ]->name, PORT_NAME, strlen( PORT_NAME ) );
|
1705
|
-
phy_port[ 0 ]->config = OFPPC_PORT_DOWN;
|
1706
|
-
phy_port[ 0 ]->state = OFPPS_LINK_DOWN;
|
1707
|
-
phy_port[ 0 ]->curr = ( OFPPF_1GB_FD | OFPPF_COPPER | OFPPF_PAUSE );
|
1708
|
-
phy_port[ 0 ]->advertised = PORT_FEATURES;
|
1709
|
-
phy_port[ 0 ]->supported = PORT_FEATURES;
|
1710
|
-
phy_port[ 0 ]->peer = PORT_FEATURES;
|
1711
|
-
|
1712
|
-
memcpy( phy_port[ 1 ], phy_port [ 0 ], sizeof( struct ofp_phy_port ) );
|
1713
|
-
|
1714
|
-
phy_port[ 1 ]->port_no = 2;
|
1715
|
-
memcpy( phy_port[ 1 ]->hw_addr, MAC_ADDR_Y, sizeof( phy_port[ 1 ]->hw_addr ) );
|
1716
|
-
|
1717
|
-
create_list( &ports );
|
1718
|
-
append_to_tail( &ports, phy_port[ 0 ] );
|
1719
|
-
append_to_tail( &ports, phy_port[ 1 ] );
|
1720
|
-
|
1721
|
-
buffer = create_features_reply( TRANSACTION_ID, DATAPATH_ID, n_buffers, n_tables,
|
1722
|
-
capabilities, actions, ports );
|
1723
|
-
|
1724
|
-
// FIXME
|
1725
|
-
|
1726
|
-
handle_features_reply( DATAPATH_ID, buffer );
|
1727
|
-
|
1728
|
-
xfree( phy_port[ 0 ] );
|
1729
|
-
xfree( phy_port[ 1 ] );
|
1730
|
-
delete_list( ports );
|
1731
|
-
free_buffer( buffer );
|
1732
|
-
}
|
1733
|
-
|
1734
|
-
|
1735
|
-
static void
|
1736
|
-
test_handle_features_reply_if_message_is_NULL() {
|
1737
|
-
set_features_reply_handler( mock_features_reply_handler, USER_DATA );
|
1738
|
-
expect_assert_failure( handle_features_reply( DATAPATH_ID, NULL ) );
|
1739
|
-
}
|
1740
|
-
|
1741
|
-
|
1742
|
-
static void
|
1743
|
-
test_handle_features_reply_if_message_length_is_zero() {
|
1744
|
-
buffer *buffer;
|
1745
|
-
|
1746
|
-
buffer = alloc_buffer_with_length( 32 );
|
1747
|
-
|
1748
|
-
set_features_reply_handler( mock_features_reply_handler, USER_DATA );
|
1749
|
-
expect_assert_failure( handle_features_reply( DATAPATH_ID, buffer ) );
|
1750
|
-
|
1751
|
-
free_buffer( buffer );
|
1752
|
-
}
|
1753
|
-
|
1754
|
-
|
1755
|
-
/********************************************************************************
|
1756
|
-
* handle_get_config_reply() tests.
|
1757
|
-
********************************************************************************/
|
1758
|
-
|
1759
|
-
static void
|
1760
|
-
test_handle_get_config_reply() {
|
1761
|
-
uint16_t flags = OFPC_FRAG_NORMAL;
|
1762
|
-
uint16_t miss_send_len = 128;
|
1763
|
-
buffer *buffer;
|
1764
|
-
|
1765
|
-
buffer = create_get_config_reply( TRANSACTION_ID, flags, miss_send_len );
|
1766
|
-
|
1767
|
-
expect_memory( mock_get_config_reply_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
1768
|
-
expect_value( mock_get_config_reply_handler, transaction_id, TRANSACTION_ID );
|
1769
|
-
expect_value( mock_get_config_reply_handler, flags32, ( uint32_t ) flags );
|
1770
|
-
expect_value( mock_get_config_reply_handler, miss_send_len32, ( uint32_t ) miss_send_len );
|
1771
|
-
expect_memory( mock_get_config_reply_handler, user_data, USER_DATA, USER_DATA_LEN );
|
1772
|
-
|
1773
|
-
set_get_config_reply_handler( mock_get_config_reply_handler, USER_DATA );
|
1774
|
-
handle_get_config_reply( DATAPATH_ID, buffer );
|
1775
|
-
|
1776
|
-
free_buffer( buffer );
|
1777
|
-
}
|
1778
|
-
|
1779
|
-
|
1780
|
-
static void
|
1781
|
-
test_handle_get_config_reply_if_handler_is_not_registered() {
|
1782
|
-
uint16_t flags = OFPC_FRAG_NORMAL;
|
1783
|
-
uint16_t miss_send_len = 128;
|
1784
|
-
buffer *buffer;
|
1785
|
-
|
1786
|
-
buffer = create_get_config_reply( TRANSACTION_ID, flags, miss_send_len );
|
1787
|
-
|
1788
|
-
// FIXME
|
1789
|
-
|
1790
|
-
handle_get_config_reply( DATAPATH_ID, buffer );
|
1791
|
-
|
1792
|
-
free_buffer( buffer );
|
1793
|
-
}
|
1794
|
-
|
1795
|
-
|
1796
|
-
static void
|
1797
|
-
test_handle_get_config_reply_if_message_is_NULL() {
|
1798
|
-
set_get_config_reply_handler( mock_get_config_reply_handler, USER_DATA );
|
1799
|
-
expect_assert_failure( handle_get_config_reply( DATAPATH_ID, NULL ) );
|
1800
|
-
}
|
1801
|
-
|
1802
|
-
|
1803
|
-
static void
|
1804
|
-
test_handle_get_config_reply_if_message_length_is_zero() {
|
1805
|
-
buffer *buffer;
|
1806
|
-
|
1807
|
-
buffer = alloc_buffer_with_length( 32 );
|
1808
|
-
|
1809
|
-
set_get_config_reply_handler( mock_get_config_reply_handler, USER_DATA );
|
1810
|
-
expect_assert_failure( handle_get_config_reply( DATAPATH_ID, buffer ) );
|
1811
|
-
|
1812
|
-
free_buffer( buffer );
|
1813
|
-
}
|
1814
|
-
|
1815
|
-
|
1816
|
-
/********************************************************************************
|
1817
|
-
* handle_flow_removed() tests.
|
1818
|
-
********************************************************************************/
|
1819
|
-
|
1820
|
-
static void
|
1821
|
-
test_handle_flow_removed() {
|
1822
|
-
uint8_t reason = OFPRR_IDLE_TIMEOUT;
|
1823
|
-
uint16_t idle_timeout = 60;
|
1824
|
-
uint16_t priority = UINT16_MAX;
|
1825
|
-
uint32_t duration_sec = 180;
|
1826
|
-
uint32_t duration_nsec = 10000;
|
1827
|
-
uint64_t cookie = 0x0102030405060708ULL;
|
1828
|
-
uint64_t packet_count = 1000;
|
1829
|
-
uint64_t byte_count = 100000;
|
1830
|
-
buffer *buffer = create_flow_removed(
|
1831
|
-
TRANSACTION_ID,
|
1832
|
-
MATCH,
|
1833
|
-
cookie,
|
1834
|
-
priority,
|
1835
|
-
reason,
|
1836
|
-
duration_sec,
|
1837
|
-
duration_nsec,
|
1838
|
-
idle_timeout,
|
1839
|
-
packet_count,
|
1840
|
-
byte_count
|
1841
|
-
);
|
1842
|
-
|
1843
|
-
expect_memory( mock_flow_removed_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
1844
|
-
expect_value( mock_flow_removed_handler, transaction_id, TRANSACTION_ID );
|
1845
|
-
expect_memory( mock_flow_removed_handler, &match, &MATCH, sizeof( struct ofp_match ) );
|
1846
|
-
expect_memory( mock_flow_removed_handler, &cookie, &cookie, sizeof( uint64_t ) );
|
1847
|
-
expect_value( mock_flow_removed_handler, priority32, ( uint32_t ) priority );
|
1848
|
-
expect_value( mock_flow_removed_handler, reason32, ( uint32_t ) reason );
|
1849
|
-
expect_value( mock_flow_removed_handler, duration_sec, duration_sec );
|
1850
|
-
expect_value( mock_flow_removed_handler, duration_nsec, duration_nsec );
|
1851
|
-
expect_value( mock_flow_removed_handler, idle_timeout32, ( uint32_t ) idle_timeout );
|
1852
|
-
expect_memory( mock_flow_removed_handler, &packet_count, &packet_count, sizeof( uint64_t ) );
|
1853
|
-
expect_memory( mock_flow_removed_handler, &byte_count, &byte_count, sizeof( uint64_t ) );
|
1854
|
-
expect_memory( mock_flow_removed_handler, user_data, USER_DATA, USER_DATA_LEN );
|
1855
|
-
|
1856
|
-
set_flow_removed_handler( mock_flow_removed_handler, USER_DATA );
|
1857
|
-
handle_flow_removed( DATAPATH_ID, buffer );
|
1858
|
-
|
1859
|
-
free_buffer( buffer );
|
1860
|
-
}
|
1861
|
-
|
1862
|
-
|
1863
|
-
static void
|
1864
|
-
test_handle_flow_removed_with_simple_handler() {
|
1865
|
-
uint8_t reason = OFPRR_IDLE_TIMEOUT;
|
1866
|
-
uint16_t idle_timeout = 60;
|
1867
|
-
uint16_t priority = UINT16_MAX;
|
1868
|
-
uint32_t duration_sec = 180;
|
1869
|
-
uint32_t duration_nsec = 10000;
|
1870
|
-
uint64_t cookie = 0x0102030405060708ULL;
|
1871
|
-
uint64_t packet_count = 1000;
|
1872
|
-
uint64_t byte_count = 100000;
|
1873
|
-
buffer *buffer = create_flow_removed(
|
1874
|
-
TRANSACTION_ID,
|
1875
|
-
MATCH,
|
1876
|
-
cookie,
|
1877
|
-
priority,
|
1878
|
-
reason,
|
1879
|
-
duration_sec,
|
1880
|
-
duration_nsec,
|
1881
|
-
idle_timeout,
|
1882
|
-
packet_count,
|
1883
|
-
byte_count
|
1884
|
-
);
|
1885
|
-
|
1886
|
-
expect_memory( mock_simple_flow_removed_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
1887
|
-
expect_value( mock_simple_flow_removed_handler, transaction_id, TRANSACTION_ID );
|
1888
|
-
expect_memory( mock_simple_flow_removed_handler, &match, &MATCH, sizeof( struct ofp_match ) );
|
1889
|
-
expect_memory( mock_simple_flow_removed_handler, &cookie, &cookie, sizeof( uint64_t ) );
|
1890
|
-
expect_value( mock_simple_flow_removed_handler, priority32, ( uint32_t ) priority );
|
1891
|
-
expect_value( mock_simple_flow_removed_handler, reason32, ( uint32_t ) reason );
|
1892
|
-
expect_value( mock_simple_flow_removed_handler, duration_sec, duration_sec );
|
1893
|
-
expect_value( mock_simple_flow_removed_handler, duration_nsec, duration_nsec );
|
1894
|
-
expect_value( mock_simple_flow_removed_handler, idle_timeout32, ( uint32_t ) idle_timeout );
|
1895
|
-
expect_memory( mock_simple_flow_removed_handler, &packet_count, &packet_count, sizeof( uint64_t ) );
|
1896
|
-
expect_memory( mock_simple_flow_removed_handler, &byte_count, &byte_count, sizeof( uint64_t ) );
|
1897
|
-
expect_memory( mock_simple_flow_removed_handler, user_data, USER_DATA, USER_DATA_LEN );
|
1898
|
-
|
1899
|
-
set_flow_removed_handler( mock_simple_flow_removed_handler, USER_DATA );
|
1900
|
-
handle_flow_removed( DATAPATH_ID, buffer );
|
1901
|
-
|
1902
|
-
free_buffer( buffer );
|
1903
|
-
}
|
1904
|
-
|
1905
|
-
|
1906
|
-
static void
|
1907
|
-
test_handle_flow_removed_if_handler_is_not_registered() {
|
1908
|
-
uint8_t reason = OFPRR_IDLE_TIMEOUT;
|
1909
|
-
uint16_t idle_timeout = 60;
|
1910
|
-
uint16_t priority = UINT16_MAX;
|
1911
|
-
uint32_t duration_sec = 180;
|
1912
|
-
uint32_t duration_nsec = 10000;
|
1913
|
-
uint64_t cookie = 0x0102030405060708ULL;
|
1914
|
-
uint64_t packet_count = 1000;
|
1915
|
-
uint64_t byte_count = 100000;
|
1916
|
-
buffer *buffer;
|
1917
|
-
|
1918
|
-
buffer = create_flow_removed( TRANSACTION_ID, MATCH, cookie, priority,
|
1919
|
-
reason, duration_sec, duration_nsec,
|
1920
|
-
idle_timeout, packet_count, byte_count );
|
1921
|
-
|
1922
|
-
// FIXME
|
1923
|
-
handle_flow_removed( DATAPATH_ID, buffer );
|
1924
|
-
|
1925
|
-
free_buffer( buffer );
|
1926
|
-
}
|
1927
|
-
|
1928
|
-
|
1929
|
-
static void
|
1930
|
-
test_handle_flow_removed_if_message_is_NULL() {
|
1931
|
-
set_flow_removed_handler( mock_flow_removed_handler, USER_DATA );
|
1932
|
-
expect_assert_failure( handle_flow_removed( DATAPATH_ID, NULL ) );
|
1933
|
-
}
|
1934
|
-
|
1935
|
-
|
1936
|
-
static void
|
1937
|
-
test_handle_flow_removed_if_message_length_is_zero() {
|
1938
|
-
buffer *buffer;
|
1939
|
-
|
1940
|
-
buffer = alloc_buffer_with_length( 32 );
|
1941
|
-
|
1942
|
-
set_flow_removed_handler( mock_flow_removed_handler, USER_DATA );
|
1943
|
-
expect_assert_failure( handle_flow_removed( DATAPATH_ID, buffer ) );
|
1944
|
-
|
1945
|
-
free_buffer( buffer );
|
1946
|
-
}
|
1947
|
-
|
1948
|
-
|
1949
|
-
/********************************************************************************
|
1950
|
-
* handle_port_status() tests.
|
1951
|
-
********************************************************************************/
|
1952
|
-
|
1953
|
-
static void
|
1954
|
-
test_handle_port_status() {
|
1955
|
-
uint8_t reason = OFPPR_MODIFY;
|
1956
|
-
buffer *buffer;
|
1957
|
-
struct ofp_phy_port desc;
|
1958
|
-
|
1959
|
-
desc.port_no = 1;
|
1960
|
-
memcpy( desc.hw_addr, MAC_ADDR_X, sizeof( desc.hw_addr ) );
|
1961
|
-
memset( desc.name, '\0', OFP_MAX_PORT_NAME_LEN );
|
1962
|
-
memcpy( desc.name, PORT_NAME, strlen( PORT_NAME ) );
|
1963
|
-
desc.config = OFPPC_PORT_DOWN;
|
1964
|
-
desc.state = OFPPS_LINK_DOWN;
|
1965
|
-
desc.curr = ( OFPPF_1GB_FD | OFPPF_COPPER | OFPPF_PAUSE );
|
1966
|
-
desc.advertised = PORT_FEATURES;
|
1967
|
-
desc.supported = PORT_FEATURES;
|
1968
|
-
desc.peer = PORT_FEATURES;
|
1969
|
-
|
1970
|
-
buffer = create_port_status( TRANSACTION_ID, reason, desc );
|
1971
|
-
|
1972
|
-
expect_memory( mock_port_status_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
1973
|
-
expect_value( mock_port_status_handler, transaction_id, TRANSACTION_ID );
|
1974
|
-
expect_value( mock_port_status_handler, reason32, ( uint32_t ) reason );
|
1975
|
-
expect_memory( mock_port_status_handler, &phy_port, &desc, sizeof( struct ofp_phy_port ) );
|
1976
|
-
expect_memory( mock_port_status_handler, user_data, USER_DATA, USER_DATA_LEN );
|
1977
|
-
|
1978
|
-
set_port_status_handler( mock_port_status_handler, USER_DATA );
|
1979
|
-
handle_port_status( DATAPATH_ID, buffer );
|
1980
|
-
|
1981
|
-
free_buffer( buffer );
|
1982
|
-
}
|
1983
|
-
|
1984
|
-
|
1985
|
-
static void
|
1986
|
-
test_handle_port_status_if_handler_is_not_registered() {
|
1987
|
-
uint8_t reason = OFPPR_MODIFY;
|
1988
|
-
buffer *buffer;
|
1989
|
-
struct ofp_phy_port desc;
|
1990
|
-
|
1991
|
-
desc.port_no = 1;
|
1992
|
-
memcpy( desc.hw_addr, MAC_ADDR_X, sizeof( desc.hw_addr ) );
|
1993
|
-
memset( desc.name, '\0', OFP_MAX_PORT_NAME_LEN );
|
1994
|
-
memcpy( desc.name, PORT_NAME, strlen( PORT_NAME ) );
|
1995
|
-
desc.config = OFPPC_PORT_DOWN;
|
1996
|
-
desc.state = OFPPS_LINK_DOWN;
|
1997
|
-
desc.curr = ( OFPPF_1GB_FD | OFPPF_COPPER | OFPPF_PAUSE );
|
1998
|
-
desc.advertised = PORT_FEATURES;
|
1999
|
-
desc.supported = PORT_FEATURES;
|
2000
|
-
desc.peer = PORT_FEATURES;
|
2001
|
-
|
2002
|
-
buffer = create_port_status( TRANSACTION_ID, reason, desc );
|
2003
|
-
|
2004
|
-
// FIXME
|
2005
|
-
handle_port_status( DATAPATH_ID, buffer );
|
2006
|
-
|
2007
|
-
free_buffer( buffer );
|
2008
|
-
}
|
2009
|
-
|
2010
|
-
|
2011
|
-
static void
|
2012
|
-
test_handle_port_status_if_message_is_NULL() {
|
2013
|
-
set_port_status_handler( mock_port_status_handler, USER_DATA );
|
2014
|
-
expect_assert_failure( handle_port_status( DATAPATH_ID, NULL ) );
|
2015
|
-
}
|
2016
|
-
|
2017
|
-
|
2018
|
-
static void
|
2019
|
-
test_handle_port_status_if_message_length_is_zero() {
|
2020
|
-
buffer *buffer;
|
2021
|
-
|
2022
|
-
buffer = alloc_buffer_with_length( 32 );
|
2023
|
-
|
2024
|
-
set_port_status_handler( mock_port_status_handler, USER_DATA );
|
2025
|
-
expect_assert_failure( handle_port_status( DATAPATH_ID, buffer ) );
|
2026
|
-
|
2027
|
-
free_buffer( buffer );
|
2028
|
-
}
|
2029
|
-
|
2030
|
-
|
2031
|
-
/********************************************************************************
|
2032
|
-
* handle_stats_reply() tests.
|
2033
|
-
********************************************************************************/
|
2034
|
-
|
2035
|
-
static void
|
2036
|
-
test_handle_stats_reply_if_type_is_OFPST_DESC() {
|
2037
|
-
char mfr_desc[ DESC_STR_LEN ];
|
2038
|
-
char hw_desc[ DESC_STR_LEN ];
|
2039
|
-
char sw_desc[ DESC_STR_LEN ];
|
2040
|
-
char serial_num[ SERIAL_NUM_LEN ];
|
2041
|
-
char dp_desc[ DESC_STR_LEN ];
|
2042
|
-
uint16_t flags = 0;
|
2043
|
-
uint32_t body_len;
|
2044
|
-
buffer *buffer;
|
2045
|
-
struct ofp_stats_reply *stats_reply;
|
2046
|
-
|
2047
|
-
memset( mfr_desc, '\0', DESC_STR_LEN );
|
2048
|
-
memset( hw_desc, '\0', DESC_STR_LEN );
|
2049
|
-
memset( sw_desc, '\0', DESC_STR_LEN );
|
2050
|
-
memset( serial_num, '\0', SERIAL_NUM_LEN );
|
2051
|
-
memset( dp_desc, '\0', DESC_STR_LEN );
|
2052
|
-
sprintf( mfr_desc, "NEC Coporation" );
|
2053
|
-
sprintf( hw_desc, "OpenFlow Switch Hardware" );
|
2054
|
-
sprintf( sw_desc, "OpenFlow Switch Software" );
|
2055
|
-
sprintf( serial_num, "123456" );
|
2056
|
-
sprintf( dp_desc, "Datapath 0" );
|
2057
|
-
|
2058
|
-
buffer = create_desc_stats_reply( TRANSACTION_ID, flags, mfr_desc, hw_desc,
|
2059
|
-
sw_desc, serial_num, dp_desc );
|
2060
|
-
|
2061
|
-
stats_reply = buffer->data;
|
2062
|
-
body_len = ( uint32_t ) ( ntohs( stats_reply->header.length ) -
|
2063
|
-
offsetof( struct ofp_stats_reply, body ) );
|
2064
|
-
|
2065
|
-
expect_memory( mock_stats_reply_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
2066
|
-
expect_value( mock_stats_reply_handler, transaction_id, TRANSACTION_ID );
|
2067
|
-
expect_value( mock_stats_reply_handler, type32, OFPST_DESC );
|
2068
|
-
expect_value( mock_stats_reply_handler, flags32, ( uint32_t ) flags );
|
2069
|
-
expect_value( mock_stats_reply_handler, data->length, body_len );
|
2070
|
-
expect_memory( mock_stats_reply_handler, data->data, stats_reply->body, body_len );
|
2071
|
-
expect_memory( mock_stats_reply_handler, user_data, USER_DATA, USER_DATA_LEN );
|
2072
|
-
|
2073
|
-
set_stats_reply_handler( mock_stats_reply_handler, USER_DATA );
|
2074
|
-
handle_stats_reply( DATAPATH_ID, buffer );
|
2075
|
-
|
2076
|
-
free_buffer( buffer );
|
2077
|
-
}
|
2078
|
-
|
2079
|
-
|
2080
|
-
static void
|
2081
|
-
test_handle_stats_reply_if_type_is_OFPST_FLOW() {
|
2082
|
-
void *expected_data;
|
2083
|
-
uint16_t flags = OFPSF_REPLY_MORE;
|
2084
|
-
uint16_t stats_len;
|
2085
|
-
uint32_t body_len;
|
2086
|
-
buffer *buffer;
|
2087
|
-
list_element *flow_stats;
|
2088
|
-
struct ofp_stats_reply *stats_reply;
|
2089
|
-
struct ofp_flow_stats *stats[ 2 ];
|
2090
|
-
struct ofp_action_output *action;
|
2091
|
-
|
2092
|
-
stats_len = offsetof( struct ofp_flow_stats, actions ) + sizeof( struct ofp_action_output );
|
2093
|
-
|
2094
|
-
stats[ 0 ] = xcalloc( 1, stats_len );
|
2095
|
-
stats[ 1 ] = xcalloc( 1, stats_len );
|
2096
|
-
|
2097
|
-
stats[ 0 ]->length = stats_len;
|
2098
|
-
stats[ 0 ]->table_id = 1;
|
2099
|
-
stats[ 0 ]->pad = 0;
|
2100
|
-
stats[ 0 ]->match = MATCH;
|
2101
|
-
stats[ 0 ]->duration_sec = 60;
|
2102
|
-
stats[ 0 ]->duration_nsec = 10000;
|
2103
|
-
stats[ 0 ]->priority = 1024;
|
2104
|
-
stats[ 0 ]->idle_timeout = 60;
|
2105
|
-
stats[ 0 ]->hard_timeout = 3600;
|
2106
|
-
stats[ 0 ]->cookie = 0x0102030405060708ULL;
|
2107
|
-
stats[ 0 ]->packet_count = 1000;
|
2108
|
-
stats[ 0 ]->byte_count = 100000;
|
2109
|
-
action = ( struct ofp_action_output * ) stats[ 0 ]->actions;
|
2110
|
-
action->type = OFPAT_OUTPUT;
|
2111
|
-
action->len = 8;
|
2112
|
-
action->port = 1;
|
2113
|
-
action->max_len = 2048;
|
2114
|
-
|
2115
|
-
memcpy( stats[ 1 ], stats[ 0 ], stats_len );
|
2116
|
-
stats[ 1 ]->cookie = 0x0203040506070809ULL;
|
2117
|
-
action = ( struct ofp_action_output * ) stats[ 1 ]->actions;
|
2118
|
-
action->port = 2;
|
2119
|
-
|
2120
|
-
create_list( &flow_stats );
|
2121
|
-
append_to_tail( &flow_stats, stats[ 0 ] );
|
2122
|
-
append_to_tail( &flow_stats, stats[ 1 ] );
|
2123
|
-
|
2124
|
-
expected_data = xcalloc( 1, ( size_t ) ( stats_len * 2 ) );
|
2125
|
-
memcpy( expected_data, stats[ 0 ], stats_len );
|
2126
|
-
memcpy( ( char * ) expected_data + stats_len, stats[ 1 ], stats_len );
|
2127
|
-
|
2128
|
-
buffer = create_flow_stats_reply( TRANSACTION_ID, flags, flow_stats );
|
2129
|
-
|
2130
|
-
stats_reply = buffer->data;
|
2131
|
-
body_len = ( uint32_t ) ( ntohs( stats_reply->header.length ) -
|
2132
|
-
offsetof( struct ofp_stats_reply, body ) );
|
2133
|
-
|
2134
|
-
expect_memory( mock_stats_reply_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
2135
|
-
expect_value( mock_stats_reply_handler, transaction_id, TRANSACTION_ID );
|
2136
|
-
expect_value( mock_stats_reply_handler, type32, OFPST_FLOW );
|
2137
|
-
expect_value( mock_stats_reply_handler, flags32, ( uint32_t ) flags );
|
2138
|
-
expect_value( mock_stats_reply_handler, data->length, body_len );
|
2139
|
-
expect_memory( mock_stats_reply_handler, data->data, expected_data, stats_len );
|
2140
|
-
expect_memory( mock_stats_reply_handler, user_data, USER_DATA, USER_DATA_LEN );
|
2141
|
-
|
2142
|
-
set_stats_reply_handler( mock_stats_reply_handler, USER_DATA );
|
2143
|
-
handle_stats_reply( DATAPATH_ID, buffer );
|
2144
|
-
|
2145
|
-
xfree( stats[ 0 ] );
|
2146
|
-
xfree( stats[ 1 ] );
|
2147
|
-
delete_list( flow_stats );
|
2148
|
-
xfree( expected_data );
|
2149
|
-
free_buffer( buffer );
|
2150
|
-
}
|
2151
|
-
|
2152
|
-
|
2153
|
-
static void
|
2154
|
-
test_handle_stats_reply_if_type_is_OFPST_AGGREGATE() {
|
2155
|
-
uint16_t flags = 0;
|
2156
|
-
uint32_t body_len;
|
2157
|
-
uint32_t flow_count = 1000;
|
2158
|
-
uint64_t packet_count = 1000;
|
2159
|
-
uint64_t byte_count = 10000;
|
2160
|
-
buffer *buffer;
|
2161
|
-
struct ofp_stats_reply *stats_reply;
|
2162
|
-
struct ofp_aggregate_stats_reply aggregate_stats_reply;
|
2163
|
-
|
2164
|
-
buffer = create_aggregate_stats_reply( TRANSACTION_ID, flags, packet_count,
|
2165
|
-
byte_count, flow_count );
|
2166
|
-
|
2167
|
-
stats_reply = buffer->data;
|
2168
|
-
body_len = ( uint32_t ) ( ntohs( stats_reply->header.length ) -
|
2169
|
-
offsetof( struct ofp_stats_reply, body ) );
|
2170
|
-
|
2171
|
-
expect_memory( mock_stats_reply_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
2172
|
-
expect_value( mock_stats_reply_handler, transaction_id, TRANSACTION_ID );
|
2173
|
-
expect_value( mock_stats_reply_handler, type32, OFPST_AGGREGATE );
|
2174
|
-
expect_value( mock_stats_reply_handler, flags32, ( uint32_t ) flags );
|
2175
|
-
expect_value( mock_stats_reply_handler, data->length, body_len );
|
2176
|
-
ntoh_aggregate_stats( &aggregate_stats_reply,
|
2177
|
-
( struct ofp_aggregate_stats_reply * ) stats_reply->body );
|
2178
|
-
expect_memory( mock_stats_reply_handler, data->data, &aggregate_stats_reply, body_len );
|
2179
|
-
expect_memory( mock_stats_reply_handler, user_data, USER_DATA, USER_DATA_LEN );
|
2180
|
-
|
2181
|
-
set_stats_reply_handler( mock_stats_reply_handler, USER_DATA );
|
2182
|
-
handle_stats_reply( DATAPATH_ID, buffer );
|
2183
|
-
|
2184
|
-
free_buffer( buffer );
|
2185
|
-
}
|
2186
|
-
|
2187
|
-
|
2188
|
-
static void
|
2189
|
-
test_handle_stats_reply_if_type_is_OFPST_TABLE() {
|
2190
|
-
void *expected_data;
|
2191
|
-
uint16_t flags = OFPSF_REPLY_MORE;
|
2192
|
-
uint16_t stats_len;
|
2193
|
-
uint32_t body_len;
|
2194
|
-
buffer *buffer;
|
2195
|
-
list_element *table_stats;
|
2196
|
-
struct ofp_stats_reply *stats_reply;
|
2197
|
-
struct ofp_table_stats *stats[ 2 ];
|
2198
|
-
|
2199
|
-
stats_len = sizeof( struct ofp_table_stats );
|
2200
|
-
|
2201
|
-
stats[ 0 ] = xcalloc( 1, stats_len );
|
2202
|
-
stats[ 1 ] = xcalloc( 1, stats_len );
|
2203
|
-
|
2204
|
-
stats[ 0 ]->table_id = 1;
|
2205
|
-
sprintf( stats[ 0 ]->name, "Table 1" );
|
2206
|
-
stats[ 0 ]->wildcards = OFPFW_ALL;
|
2207
|
-
stats[ 0 ]->max_entries = 10000;
|
2208
|
-
stats[ 0 ]->active_count = 1000;
|
2209
|
-
stats[ 0 ]->lookup_count = 100000;
|
2210
|
-
stats[ 0 ]->matched_count = 10000;
|
2211
|
-
|
2212
|
-
memcpy( stats[ 1 ], stats[ 0 ], stats_len );
|
2213
|
-
stats[ 1 ]->table_id = 2;
|
2214
|
-
sprintf( stats[ 1 ]->name, "Table 2" );
|
2215
|
-
|
2216
|
-
create_list( &table_stats );
|
2217
|
-
append_to_tail( &table_stats, stats[ 0 ] );
|
2218
|
-
append_to_tail( &table_stats, stats[ 1 ] );
|
2219
|
-
|
2220
|
-
expected_data = xcalloc( 1, ( size_t ) ( stats_len * 2 ) );
|
2221
|
-
memcpy( expected_data, stats[ 0 ], stats_len );
|
2222
|
-
memcpy( ( char * ) expected_data + stats_len, stats[ 1 ], stats_len );
|
2223
|
-
|
2224
|
-
buffer = create_table_stats_reply( TRANSACTION_ID, flags, table_stats );
|
2225
|
-
|
2226
|
-
stats_reply = buffer->data;
|
2227
|
-
body_len = ( uint32_t ) ( ntohs( stats_reply->header.length ) -
|
2228
|
-
offsetof( struct ofp_stats_reply, body ) );
|
2229
|
-
|
2230
|
-
expect_memory( mock_stats_reply_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
2231
|
-
expect_value( mock_stats_reply_handler, transaction_id, TRANSACTION_ID );
|
2232
|
-
expect_value( mock_stats_reply_handler, type32, OFPST_TABLE );
|
2233
|
-
expect_value( mock_stats_reply_handler, flags32, ( uint32_t ) flags );
|
2234
|
-
expect_value( mock_stats_reply_handler, data->length, body_len );
|
2235
|
-
expect_memory( mock_stats_reply_handler, data->data, expected_data, stats_len );
|
2236
|
-
expect_memory( mock_stats_reply_handler, user_data, USER_DATA, USER_DATA_LEN );
|
2237
|
-
|
2238
|
-
set_stats_reply_handler( mock_stats_reply_handler, USER_DATA );
|
2239
|
-
handle_stats_reply( DATAPATH_ID, buffer );
|
2240
|
-
|
2241
|
-
xfree( stats[ 0 ] );
|
2242
|
-
xfree( stats[ 1 ] );
|
2243
|
-
delete_list( table_stats );
|
2244
|
-
xfree( expected_data );
|
2245
|
-
free_buffer( buffer );
|
2246
|
-
}
|
2247
|
-
|
2248
|
-
|
2249
|
-
static void
|
2250
|
-
test_handle_stats_reply_if_type_is_OFPST_PORT() {
|
2251
|
-
void *expected_data;
|
2252
|
-
uint16_t flags = OFPSF_REPLY_MORE;
|
2253
|
-
uint16_t stats_len;
|
2254
|
-
uint32_t body_len;
|
2255
|
-
buffer *buffer;
|
2256
|
-
list_element *port_stats;
|
2257
|
-
struct ofp_stats_reply *stats_reply;
|
2258
|
-
struct ofp_port_stats *stats[ 2 ];
|
2259
|
-
|
2260
|
-
stats_len = sizeof( struct ofp_port_stats );
|
2261
|
-
|
2262
|
-
stats[ 0 ] = xcalloc( 1, stats_len );
|
2263
|
-
stats[ 1 ] = xcalloc( 1, stats_len );
|
2264
|
-
|
2265
|
-
stats[ 0 ]->port_no = 1;
|
2266
|
-
stats[ 0 ]->rx_packets = 10000;
|
2267
|
-
stats[ 0 ]->tx_packets = 20000;
|
2268
|
-
stats[ 0 ]->rx_bytes = 30000;
|
2269
|
-
stats[ 0 ]->tx_bytes = 40000;
|
2270
|
-
stats[ 0 ]->rx_dropped = 50000;
|
2271
|
-
stats[ 0 ]->tx_dropped = 60000;
|
2272
|
-
stats[ 0 ]->rx_errors = 70000;
|
2273
|
-
stats[ 0 ]->tx_errors = 80000;
|
2274
|
-
stats[ 0 ]->rx_frame_err = 1;
|
2275
|
-
stats[ 0 ]->rx_over_err = 2;
|
2276
|
-
stats[ 0 ]->rx_crc_err = 1;
|
2277
|
-
stats[ 0 ]->collisions = 3;
|
2278
|
-
|
2279
|
-
memcpy( stats[ 1 ], stats[ 0 ], stats_len );
|
2280
|
-
stats[ 1 ]->port_no = 2;
|
2281
|
-
|
2282
|
-
create_list( &port_stats );
|
2283
|
-
append_to_tail( &port_stats, stats[ 0 ] );
|
2284
|
-
append_to_tail( &port_stats, stats[ 1 ] );
|
2285
|
-
|
2286
|
-
expected_data = xcalloc( 1, ( size_t ) ( stats_len * 2 ) );
|
2287
|
-
memcpy( expected_data, stats[ 0 ], stats_len );
|
2288
|
-
memcpy( ( char * ) expected_data + stats_len, stats[ 1 ], stats_len );
|
2289
|
-
|
2290
|
-
buffer = create_port_stats_reply( TRANSACTION_ID, flags, port_stats );
|
2291
|
-
|
2292
|
-
stats_reply = buffer->data;
|
2293
|
-
body_len = ( uint32_t ) ( ntohs( stats_reply->header.length ) -
|
2294
|
-
offsetof( struct ofp_stats_reply, body ) );
|
2295
|
-
|
2296
|
-
expect_memory( mock_stats_reply_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
2297
|
-
expect_value( mock_stats_reply_handler, transaction_id, TRANSACTION_ID );
|
2298
|
-
expect_value( mock_stats_reply_handler, type32, OFPST_PORT );
|
2299
|
-
expect_value( mock_stats_reply_handler, flags32, ( uint32_t ) flags );
|
2300
|
-
expect_value( mock_stats_reply_handler, data->length, body_len );
|
2301
|
-
expect_memory( mock_stats_reply_handler, data->data, expected_data, stats_len );
|
2302
|
-
expect_memory( mock_stats_reply_handler, user_data, USER_DATA, USER_DATA_LEN );
|
2303
|
-
|
2304
|
-
set_stats_reply_handler( mock_stats_reply_handler, USER_DATA );
|
2305
|
-
handle_stats_reply( DATAPATH_ID, buffer );
|
2306
|
-
|
2307
|
-
xfree( stats[ 0 ] );
|
2308
|
-
xfree( stats[ 1 ] );
|
2309
|
-
delete_list( port_stats );
|
2310
|
-
xfree( expected_data );
|
2311
|
-
free_buffer( buffer );
|
2312
|
-
}
|
2313
|
-
|
2314
|
-
|
2315
|
-
static void
|
2316
|
-
test_handle_stats_reply_if_type_is_OFPST_QUEUE() {
|
2317
|
-
void *expected_data;
|
2318
|
-
uint16_t flags = OFPSF_REPLY_MORE;
|
2319
|
-
uint16_t stats_len;
|
2320
|
-
uint32_t body_len;
|
2321
|
-
buffer *buffer;
|
2322
|
-
list_element *queue_stats;
|
2323
|
-
struct ofp_stats_reply *stats_reply;
|
2324
|
-
struct ofp_queue_stats *stats[ 2 ];
|
2325
|
-
|
2326
|
-
stats_len = sizeof( struct ofp_queue_stats );
|
2327
|
-
|
2328
|
-
stats[ 0 ] = xcalloc( 1, stats_len );
|
2329
|
-
stats[ 1 ] = xcalloc( 1, stats_len );
|
2330
|
-
|
2331
|
-
stats[ 0 ]->port_no = 1;
|
2332
|
-
stats[ 0 ]->queue_id = 2;
|
2333
|
-
stats[ 0 ]->tx_bytes = 100000;
|
2334
|
-
stats[ 0 ]->tx_packets = 60000;
|
2335
|
-
stats[ 0 ]->tx_errors = 80;
|
2336
|
-
|
2337
|
-
memcpy( stats[ 1 ], stats[ 0 ], stats_len );
|
2338
|
-
stats[ 1 ]->queue_id = 3;
|
2339
|
-
|
2340
|
-
create_list( &queue_stats );
|
2341
|
-
append_to_tail( &queue_stats, stats[ 0 ] );
|
2342
|
-
append_to_tail( &queue_stats, stats[ 1 ] );
|
2343
|
-
|
2344
|
-
expected_data = xcalloc( 1, ( size_t ) ( stats_len * 2 ) );
|
2345
|
-
memcpy( expected_data, stats[ 0 ], stats_len );
|
2346
|
-
memcpy( ( char * ) expected_data + stats_len, stats[ 1 ], stats_len );
|
2347
|
-
|
2348
|
-
buffer = create_queue_stats_reply( TRANSACTION_ID, flags, queue_stats );
|
2349
|
-
|
2350
|
-
stats_reply = buffer->data;
|
2351
|
-
body_len = ( uint32_t ) ( ntohs( stats_reply->header.length ) -
|
2352
|
-
offsetof( struct ofp_stats_reply, body ) );
|
2353
|
-
|
2354
|
-
expect_memory( mock_stats_reply_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
2355
|
-
expect_value( mock_stats_reply_handler, transaction_id, TRANSACTION_ID );
|
2356
|
-
expect_value( mock_stats_reply_handler, type32, OFPST_QUEUE );
|
2357
|
-
expect_value( mock_stats_reply_handler, flags32, ( uint32_t ) flags );
|
2358
|
-
expect_value( mock_stats_reply_handler, data->length, body_len );
|
2359
|
-
expect_memory( mock_stats_reply_handler, data->data, expected_data, stats_len );
|
2360
|
-
expect_memory( mock_stats_reply_handler, user_data, USER_DATA, USER_DATA_LEN );
|
2361
|
-
|
2362
|
-
set_stats_reply_handler( mock_stats_reply_handler, USER_DATA );
|
2363
|
-
handle_stats_reply( DATAPATH_ID, buffer );
|
2364
|
-
|
2365
|
-
xfree( stats[ 0 ] );
|
2366
|
-
xfree( stats[ 1 ] );
|
2367
|
-
delete_list( queue_stats );
|
2368
|
-
xfree( expected_data );
|
2369
|
-
free_buffer( buffer );
|
2370
|
-
}
|
2371
|
-
|
2372
|
-
|
2373
|
-
static void
|
2374
|
-
test_handle_stats_reply_if_type_is_OFPST_VENDOR() {
|
2375
|
-
void *expected_data;
|
2376
|
-
uint16_t flags = 0;
|
2377
|
-
uint32_t body_len;
|
2378
|
-
uint32_t vendor = VENDOR_ID;
|
2379
|
-
buffer *buffer, *body;
|
2380
|
-
struct ofp_stats_reply *stats_reply;
|
2381
|
-
|
2382
|
-
body = alloc_buffer_with_length( 128 );
|
2383
|
-
append_back_buffer( body, 128 );
|
2384
|
-
memset( body->data, 0xa1, body->length );
|
2385
|
-
|
2386
|
-
expected_data = xcalloc( 1, ( size_t ) ( body->length + sizeof( uint32_t ) ) );
|
2387
|
-
memcpy( expected_data, &vendor, sizeof( uint32_t ) );
|
2388
|
-
memcpy( ( char * ) expected_data + sizeof( uint32_t ), body->data, body->length );
|
2389
|
-
|
2390
|
-
buffer = create_vendor_stats_reply( TRANSACTION_ID, flags, vendor, body );
|
2391
|
-
|
2392
|
-
stats_reply = buffer->data;
|
2393
|
-
body_len = ( uint32_t ) ( ntohs( stats_reply->header.length ) -
|
2394
|
-
offsetof( struct ofp_stats_reply, body ) );
|
2395
|
-
|
2396
|
-
expect_memory( mock_stats_reply_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
2397
|
-
expect_value( mock_stats_reply_handler, transaction_id, TRANSACTION_ID );
|
2398
|
-
expect_value( mock_stats_reply_handler, type32, OFPST_VENDOR );
|
2399
|
-
expect_value( mock_stats_reply_handler, flags32, ( uint32_t ) flags );
|
2400
|
-
expect_value( mock_stats_reply_handler, data->length, body_len );
|
2401
|
-
expect_memory( mock_stats_reply_handler, data->data, expected_data, body_len );
|
2402
|
-
expect_memory( mock_stats_reply_handler, user_data, USER_DATA, USER_DATA_LEN );
|
2403
|
-
|
2404
|
-
set_stats_reply_handler( mock_stats_reply_handler, USER_DATA );
|
2405
|
-
handle_stats_reply( DATAPATH_ID, buffer );
|
2406
|
-
|
2407
|
-
xfree( expected_data );
|
2408
|
-
free_buffer( body );
|
2409
|
-
free_buffer( buffer );
|
2410
|
-
}
|
2411
|
-
|
2412
|
-
|
2413
|
-
static void
|
2414
|
-
test_handle_stats_reply_with_undefined_type() {
|
2415
|
-
uint16_t flags = 0;
|
2416
|
-
uint32_t vendor = VENDOR_ID;
|
2417
|
-
buffer *buffer;
|
2418
|
-
struct ofp_stats_reply *stats_reply;
|
2419
|
-
|
2420
|
-
buffer = create_vendor_stats_reply( TRANSACTION_ID, flags, vendor, NULL );
|
2421
|
-
|
2422
|
-
stats_reply = buffer->data;
|
2423
|
-
stats_reply->type = htons( 0xfffe );
|
2424
|
-
|
2425
|
-
set_stats_reply_handler( mock_stats_reply_handler, USER_DATA );
|
2426
|
-
expect_assert_failure( handle_stats_reply( DATAPATH_ID, buffer ) );
|
2427
|
-
|
2428
|
-
free_buffer( buffer );
|
2429
|
-
}
|
2430
|
-
|
2431
|
-
|
2432
|
-
static void
|
2433
|
-
test_handle_stats_reply_if_handler_is_not_registered() {
|
2434
|
-
char mfr_desc[ DESC_STR_LEN ];
|
2435
|
-
char hw_desc[ DESC_STR_LEN ];
|
2436
|
-
char sw_desc[ DESC_STR_LEN ];
|
2437
|
-
char serial_num[ SERIAL_NUM_LEN ];
|
2438
|
-
char dp_desc[ DESC_STR_LEN ];
|
2439
|
-
uint16_t flags = 0;
|
2440
|
-
buffer *buffer;
|
2441
|
-
|
2442
|
-
memset( mfr_desc, '\0', DESC_STR_LEN );
|
2443
|
-
memset( hw_desc, '\0', DESC_STR_LEN );
|
2444
|
-
memset( sw_desc, '\0', DESC_STR_LEN );
|
2445
|
-
memset( serial_num, '\0', SERIAL_NUM_LEN );
|
2446
|
-
memset( dp_desc, '\0', DESC_STR_LEN );
|
2447
|
-
sprintf( mfr_desc, "NEC Coporation" );
|
2448
|
-
sprintf( hw_desc, "OpenFlow Switch Hardware" );
|
2449
|
-
sprintf( sw_desc, "OpenFlow Switch Software" );
|
2450
|
-
sprintf( serial_num, "123456" );
|
2451
|
-
sprintf( dp_desc, "Datapath 0" );
|
2452
|
-
|
2453
|
-
buffer = create_desc_stats_reply( TRANSACTION_ID, flags, mfr_desc, hw_desc,
|
2454
|
-
sw_desc, serial_num, dp_desc );
|
2455
|
-
|
2456
|
-
// FIXME
|
2457
|
-
handle_stats_reply( DATAPATH_ID, buffer );
|
2458
|
-
|
2459
|
-
free_buffer( buffer );
|
2460
|
-
}
|
2461
|
-
|
2462
|
-
|
2463
|
-
static void
|
2464
|
-
test_handle_stats_reply_if_message_is_NULL() {
|
2465
|
-
set_stats_reply_handler( mock_stats_reply_handler, USER_DATA );
|
2466
|
-
expect_assert_failure( handle_stats_reply( DATAPATH_ID, NULL ) );
|
2467
|
-
}
|
2468
|
-
|
2469
|
-
|
2470
|
-
static void
|
2471
|
-
test_handle_stats_reply_if_message_length_is_zero() {
|
2472
|
-
buffer *buffer;
|
2473
|
-
|
2474
|
-
buffer = alloc_buffer_with_length( 32 );
|
2475
|
-
|
2476
|
-
set_stats_reply_handler( mock_stats_reply_handler, USER_DATA );
|
2477
|
-
expect_assert_failure( handle_stats_reply( DATAPATH_ID, buffer ) );
|
2478
|
-
|
2479
|
-
free_buffer( buffer );
|
2480
|
-
}
|
2481
|
-
|
2482
|
-
|
2483
|
-
/********************************************************************************
|
2484
|
-
* handle_barrier_reply() tests.
|
2485
|
-
********************************************************************************/
|
2486
|
-
|
2487
|
-
static void
|
2488
|
-
test_handle_barrier_reply() {
|
2489
|
-
buffer *buffer;
|
2490
|
-
|
2491
|
-
buffer = create_barrier_reply( TRANSACTION_ID );
|
2492
|
-
|
2493
|
-
expect_memory( mock_barrier_reply_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
2494
|
-
expect_value( mock_barrier_reply_handler, transaction_id, TRANSACTION_ID );
|
2495
|
-
expect_memory( mock_barrier_reply_handler, user_data, USER_DATA, USER_DATA_LEN );
|
2496
|
-
|
2497
|
-
set_barrier_reply_handler( mock_barrier_reply_handler, USER_DATA );
|
2498
|
-
handle_barrier_reply( DATAPATH_ID, buffer );
|
2499
|
-
|
2500
|
-
free_buffer( buffer );
|
2501
|
-
}
|
2502
|
-
|
2503
|
-
|
2504
|
-
static void
|
2505
|
-
test_handle_barrier_reply_if_handler_is_not_registered() {
|
2506
|
-
buffer *buffer;
|
2507
|
-
|
2508
|
-
buffer = create_barrier_reply( TRANSACTION_ID );
|
2509
|
-
|
2510
|
-
// FIXME
|
2511
|
-
handle_barrier_reply( DATAPATH_ID, buffer );
|
2512
|
-
|
2513
|
-
free_buffer( buffer );
|
2514
|
-
}
|
2515
|
-
|
2516
|
-
|
2517
|
-
static void
|
2518
|
-
test_handle_barrier_reply_if_message_is_NULL() {
|
2519
|
-
set_barrier_reply_handler( mock_barrier_reply_handler, USER_DATA );
|
2520
|
-
expect_assert_failure( handle_barrier_reply( DATAPATH_ID, NULL ) );
|
2521
|
-
}
|
2522
|
-
|
2523
|
-
|
2524
|
-
static void
|
2525
|
-
test_handle_barrier_reply_if_message_length_is_zero() {
|
2526
|
-
buffer *buffer;
|
2527
|
-
|
2528
|
-
buffer = alloc_buffer_with_length( 32 );
|
2529
|
-
|
2530
|
-
set_barrier_reply_handler( mock_barrier_reply_handler, USER_DATA );
|
2531
|
-
expect_assert_failure( handle_barrier_reply( DATAPATH_ID, buffer ) );
|
2532
|
-
|
2533
|
-
free_buffer( buffer );
|
2534
|
-
}
|
2535
|
-
|
2536
|
-
|
2537
|
-
/********************************************************************************
|
2538
|
-
* handle_queue_get_config_reply() tests.
|
2539
|
-
********************************************************************************/
|
2540
|
-
|
2541
|
-
static void
|
2542
|
-
test_handle_queue_get_config_reply() {
|
2543
|
-
size_t queue_len;
|
2544
|
-
uint16_t port = 1;
|
2545
|
-
list_element *queues;
|
2546
|
-
buffer *buffer;
|
2547
|
-
struct ofp_packet_queue *queue[ 2 ];
|
2548
|
-
struct ofp_queue_prop_header *prop_header;
|
2549
|
-
|
2550
|
-
queue_len = offsetof( struct ofp_packet_queue, properties ) + sizeof( struct ofp_queue_prop_header );
|
2551
|
-
queue[ 0 ] = xcalloc( 1, queue_len );
|
2552
|
-
queue[ 1 ] = xcalloc( 1, queue_len );
|
2553
|
-
|
2554
|
-
queue[ 0 ]->queue_id = 1;
|
2555
|
-
queue[ 0 ]->len = 16;
|
2556
|
-
prop_header = queue[ 0 ]->properties;
|
2557
|
-
prop_header->property = OFPQT_NONE;
|
2558
|
-
prop_header->len = 8;
|
2559
|
-
|
2560
|
-
queue[ 1 ]->queue_id = 2;
|
2561
|
-
queue[ 1 ]->len = 16;
|
2562
|
-
prop_header = queue[ 1 ]->properties;
|
2563
|
-
prop_header->property = OFPQT_NONE;
|
2564
|
-
prop_header->len = 8;
|
2565
|
-
|
2566
|
-
create_list( &queues );
|
2567
|
-
append_to_tail( &queues, queue[ 0 ] );
|
2568
|
-
append_to_tail( &queues, queue[ 1 ] );
|
2569
|
-
|
2570
|
-
buffer = create_queue_get_config_reply( TRANSACTION_ID, port, queues );
|
2571
|
-
|
2572
|
-
expect_memory( mock_queue_get_config_reply_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
2573
|
-
expect_value( mock_queue_get_config_reply_handler, transaction_id, TRANSACTION_ID );
|
2574
|
-
expect_value( mock_queue_get_config_reply_handler, port32, ( uint32_t ) port );
|
2575
|
-
expect_memory( mock_queue_get_config_reply_handler, queue1, queue[ 0 ], queue_len );
|
2576
|
-
expect_memory( mock_queue_get_config_reply_handler, queue2, queue[ 1 ], queue_len );
|
2577
|
-
expect_memory( mock_queue_get_config_reply_handler, user_data, USER_DATA, USER_DATA_LEN );
|
2578
|
-
|
2579
|
-
set_queue_get_config_reply_handler( mock_queue_get_config_reply_handler, USER_DATA );
|
2580
|
-
handle_queue_get_config_reply( DATAPATH_ID, buffer );
|
2581
|
-
|
2582
|
-
xfree( queue[ 0 ] );
|
2583
|
-
xfree( queue[ 1 ] );
|
2584
|
-
delete_list( queues );
|
2585
|
-
free_buffer( buffer );
|
2586
|
-
}
|
2587
|
-
|
2588
|
-
|
2589
|
-
static void
|
2590
|
-
test_handle_queue_get_config_reply_without_queues() {
|
2591
|
-
uint16_t port = 1;
|
2592
|
-
buffer *buffer;
|
2593
|
-
|
2594
|
-
buffer = create_queue_get_config_reply( TRANSACTION_ID, port, NULL );
|
2595
|
-
|
2596
|
-
set_queue_get_config_reply_handler( mock_queue_get_config_reply_handler, USER_DATA );
|
2597
|
-
expect_assert_failure( handle_queue_get_config_reply( DATAPATH_ID, buffer ) );
|
2598
|
-
|
2599
|
-
free_buffer( buffer );
|
2600
|
-
}
|
2601
|
-
|
2602
|
-
|
2603
|
-
static void
|
2604
|
-
test_handle_queue_get_config_reply_if_handler_is_not_registered() {
|
2605
|
-
size_t queue_len;
|
2606
|
-
uint16_t port = 1;
|
2607
|
-
list_element *queues;
|
2608
|
-
buffer *buffer;
|
2609
|
-
struct ofp_packet_queue *queue[ 2 ];
|
2610
|
-
struct ofp_queue_prop_header *prop_header;
|
2611
|
-
|
2612
|
-
queue_len = offsetof( struct ofp_packet_queue, properties ) + sizeof( struct ofp_queue_prop_header );
|
2613
|
-
queue[ 0 ] = xcalloc( 1, queue_len );
|
2614
|
-
queue[ 1 ] = xcalloc( 1, queue_len );
|
2615
|
-
|
2616
|
-
queue[ 0 ]->queue_id = 1;
|
2617
|
-
queue[ 0 ]->len = 16;
|
2618
|
-
prop_header = queue[ 0 ]->properties;
|
2619
|
-
prop_header->property = OFPQT_NONE;
|
2620
|
-
prop_header->len = 8;
|
2621
|
-
|
2622
|
-
queue[ 1 ]->queue_id = 2;
|
2623
|
-
queue[ 1 ]->len = 16;
|
2624
|
-
prop_header = queue[ 1 ]->properties;
|
2625
|
-
prop_header->property = OFPQT_NONE;
|
2626
|
-
prop_header->len = 8;
|
2627
|
-
|
2628
|
-
create_list( &queues );
|
2629
|
-
append_to_tail( &queues, queue[ 0 ] );
|
2630
|
-
append_to_tail( &queues, queue[ 1 ] );
|
2631
|
-
|
2632
|
-
buffer = create_queue_get_config_reply( TRANSACTION_ID, port, queues );
|
2633
|
-
|
2634
|
-
// FIXME
|
2635
|
-
handle_queue_get_config_reply( DATAPATH_ID, buffer );
|
2636
|
-
|
2637
|
-
xfree( queue[ 0 ] );
|
2638
|
-
xfree( queue[ 1 ] );
|
2639
|
-
delete_list( queues );
|
2640
|
-
free_buffer( buffer );
|
2641
|
-
}
|
2642
|
-
|
2643
|
-
|
2644
|
-
static void
|
2645
|
-
test_handle_queue_get_config_reply_if_message_is_NULL() {
|
2646
|
-
set_queue_get_config_reply_handler( mock_queue_get_config_reply_handler, USER_DATA );
|
2647
|
-
expect_assert_failure( handle_queue_get_config_reply( DATAPATH_ID, NULL ) );
|
2648
|
-
}
|
2649
|
-
|
2650
|
-
|
2651
|
-
static void
|
2652
|
-
test_handle_queue_get_config_reply_if_message_length_is_zero() {
|
2653
|
-
buffer *buffer;
|
2654
|
-
|
2655
|
-
buffer = alloc_buffer_with_length( 32 );
|
2656
|
-
|
2657
|
-
set_queue_get_config_reply_handler( mock_queue_get_config_reply_handler, USER_DATA );
|
2658
|
-
expect_assert_failure( handle_queue_get_config_reply( DATAPATH_ID, buffer ) );
|
2659
|
-
|
2660
|
-
free_buffer( buffer );
|
2661
|
-
}
|
2662
|
-
|
2663
|
-
|
2664
|
-
/********************************************************************************
|
2665
|
-
* handle_list_switches_reply() tests.
|
2666
|
-
********************************************************************************/
|
2667
|
-
|
2668
|
-
static void
|
2669
|
-
test_insert_dpid() {
|
2670
|
-
list_element *head;
|
2671
|
-
create_list( &head );
|
2672
|
-
uint64_t alice = 0x1;
|
2673
|
-
uint64_t bob = 0x2;
|
2674
|
-
uint64_t carol = 0x3;
|
2675
|
-
|
2676
|
-
insert_dpid( &head, &carol );
|
2677
|
-
insert_dpid( &head, &alice );
|
2678
|
-
insert_dpid( &head, &bob );
|
2679
|
-
|
2680
|
-
list_element *element = head;
|
2681
|
-
assert_true( element != NULL );
|
2682
|
-
assert_true( element->data != NULL );
|
2683
|
-
assert_true( alice == *( uint64_t * ) element->data );
|
2684
|
-
|
2685
|
-
element = element->next;
|
2686
|
-
assert_true( element != NULL );
|
2687
|
-
assert_true( element->data != NULL );
|
2688
|
-
assert_true( bob == *( uint64_t * ) element->data );
|
2689
|
-
|
2690
|
-
element = element->next;
|
2691
|
-
assert_true( element != NULL );
|
2692
|
-
assert_true( element->data != NULL );
|
2693
|
-
assert_true( carol == *( uint64_t * ) element->data );
|
2694
|
-
|
2695
|
-
element = element->next;
|
2696
|
-
assert_true( element == NULL );
|
2697
|
-
|
2698
|
-
delete_list( head );
|
2699
|
-
}
|
2700
|
-
|
2701
|
-
|
2702
|
-
static void
|
2703
|
-
test_insert_dpid_if_head_is_NULL() {
|
2704
|
-
uint64_t dpid = 0x1;
|
2705
|
-
|
2706
|
-
expect_assert_failure( insert_dpid( NULL, &dpid ) );
|
2707
|
-
}
|
2708
|
-
|
2709
|
-
|
2710
|
-
static void
|
2711
|
-
test_insert_dpid_if_dpid_is_NULL() {
|
2712
|
-
list_element *head;
|
2713
|
-
create_list( &head );
|
2714
|
-
|
2715
|
-
expect_assert_failure( insert_dpid( &head, NULL ) );
|
2716
|
-
|
2717
|
-
delete_list( head );
|
2718
|
-
}
|
2719
|
-
|
2720
|
-
|
2721
|
-
static void
|
2722
|
-
test_handle_list_switches_reply() {
|
2723
|
-
uint16_t message_type = 0;
|
2724
|
-
uint64_t alice = 0x1;
|
2725
|
-
uint64_t bob = 0x2;
|
2726
|
-
uint64_t carol = 0x3;
|
2727
|
-
uint64_t dpid[] = { htonll( bob ), htonll( carol ), htonll( alice ) };
|
2728
|
-
size_t length = sizeof( dpid );
|
2729
|
-
void *user_data = LIST_SWITCHES_REPLY_USER_DATA;
|
2730
|
-
|
2731
|
-
expect_value( mock_handle_list_switches_reply, *dpid1, alice );
|
2732
|
-
expect_value( mock_handle_list_switches_reply, *dpid2, bob );
|
2733
|
-
expect_value( mock_handle_list_switches_reply, *dpid3, carol );
|
2734
|
-
expect_value( mock_handle_list_switches_reply, user_data, LIST_SWITCHES_REPLY_USER_DATA );
|
2735
|
-
|
2736
|
-
set_list_switches_reply_handler( mock_handle_list_switches_reply );
|
2737
|
-
handle_list_switches_reply( message_type, dpid, length, user_data );
|
2738
|
-
}
|
2739
|
-
|
2740
|
-
|
2741
|
-
static void
|
2742
|
-
test_handle_list_switches_reply_if_data_is_NULL() {
|
2743
|
-
uint16_t message_type = 0;
|
2744
|
-
size_t length = 64;
|
2745
|
-
void *user_data = LIST_SWITCHES_REPLY_USER_DATA;
|
2746
|
-
|
2747
|
-
set_list_switches_reply_handler( mock_handle_list_switches_reply );
|
2748
|
-
expect_assert_failure( handle_list_switches_reply( message_type, NULL, length, user_data ) );
|
2749
|
-
}
|
2750
|
-
|
2751
|
-
|
2752
|
-
static void
|
2753
|
-
test_handle_list_switches_reply_if_length_is_zero() {
|
2754
|
-
uint16_t message_type = 0;
|
2755
|
-
uint64_t dpid[] = { 0 };
|
2756
|
-
void *user_data = LIST_SWITCHES_REPLY_USER_DATA;
|
2757
|
-
|
2758
|
-
expect_value( mock_handle_list_switches_reply, user_data, LIST_SWITCHES_REPLY_USER_DATA );
|
2759
|
-
|
2760
|
-
set_list_switches_reply_handler( mock_handle_list_switches_reply );
|
2761
|
-
handle_list_switches_reply( message_type, dpid, 0, user_data );
|
2762
|
-
}
|
2763
|
-
|
2764
|
-
|
2765
|
-
/********************************************************************************
|
2766
|
-
* handle_switch_events() tests.
|
2767
|
-
********************************************************************************/
|
2768
|
-
|
2769
|
-
static void
|
2770
|
-
test_handle_switch_events_if_type_is_MESSENGER_OPENFLOW_CONNECTED() {
|
2771
|
-
buffer *data = alloc_buffer_with_length( sizeof( openflow_service_header_t ) );
|
2772
|
-
append_back_buffer( data, sizeof( openflow_service_header_t ) );
|
2773
|
-
|
2774
|
-
handle_switch_events( MESSENGER_OPENFLOW_CONNECTED, data->data, data->length );
|
2775
|
-
|
2776
|
-
stat_entry *stat = lookup_hash_entry( stats, "openflow_application_interface.switch_connected_receive_succeeded" );
|
2777
|
-
assert_int_equal( ( int ) stat->value, 1 );
|
2778
|
-
|
2779
|
-
free_buffer( data );
|
2780
|
-
xfree( delete_hash_entry( stats, "openflow_application_interface.switch_connected_receive_succeeded" ) );
|
2781
|
-
}
|
2782
|
-
|
2783
|
-
|
2784
|
-
static void
|
2785
|
-
test_handle_switch_events_if_type_is_MESSENGER_OPENFLOW_DISCONNECTED() {
|
2786
|
-
uint64_t *datapath_id;
|
2787
|
-
buffer *data;
|
2788
|
-
|
2789
|
-
data = alloc_buffer_with_length( sizeof( openflow_service_header_t ) );
|
2790
|
-
datapath_id = append_back_buffer( data, sizeof( openflow_service_header_t ) );
|
2791
|
-
|
2792
|
-
*datapath_id = htonll( DATAPATH_ID );
|
2793
|
-
|
2794
|
-
expect_memory( mock_switch_disconnected_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
2795
|
-
expect_value( mock_switch_disconnected_handler, user_data, SWITCH_DISCONNECTED_USER_DATA );
|
2796
|
-
|
2797
|
-
expect_string( mock_clear_send_queue, service_name, REMOTE_SERVICE_NAME );
|
2798
|
-
will_return( mock_clear_send_queue, true );
|
2799
|
-
|
2800
|
-
set_switch_disconnected_handler( mock_switch_disconnected_handler, SWITCH_DISCONNECTED_USER_DATA );
|
2801
|
-
handle_switch_events( MESSENGER_OPENFLOW_DISCONNECTED, data->data, data->length );
|
2802
|
-
|
2803
|
-
stat_entry *stat = lookup_hash_entry( stats, "openflow_application_interface.switch_disconnected_receive_succeeded" );
|
2804
|
-
assert_int_equal( ( int ) stat->value, 1 );
|
2805
|
-
|
2806
|
-
free_buffer( data );
|
2807
|
-
xfree( delete_hash_entry( stats, "openflow_application_interface.switch_disconnected_receive_succeeded" ) );
|
2808
|
-
}
|
2809
|
-
|
2810
|
-
|
2811
|
-
static void
|
2812
|
-
test_handle_switch_events_if_message_is_NULL() {
|
2813
|
-
expect_assert_failure( handle_switch_events( MESSENGER_OPENFLOW_READY, NULL, 1 ) );
|
2814
|
-
}
|
2815
|
-
|
2816
|
-
|
2817
|
-
static void
|
2818
|
-
test_handle_switch_events_if_message_length_is_zero() {
|
2819
|
-
buffer *data;
|
2820
|
-
|
2821
|
-
data = alloc_buffer_with_length( sizeof( openflow_service_header_t ) );
|
2822
|
-
|
2823
|
-
expect_assert_failure( handle_switch_events( MESSENGER_OPENFLOW_READY, data->data, 0 ) );
|
2824
|
-
|
2825
|
-
free_buffer( data );
|
2826
|
-
}
|
2827
|
-
|
2828
|
-
|
2829
|
-
static void
|
2830
|
-
test_handle_switch_events_if_message_length_is_too_big() {
|
2831
|
-
buffer *data;
|
2832
|
-
|
2833
|
-
data = alloc_buffer_with_length( sizeof( openflow_service_header_t ) );
|
2834
|
-
|
2835
|
-
expect_assert_failure( handle_switch_events( MESSENGER_OPENFLOW_READY, data->data,
|
2836
|
-
data->length + 1 ) );
|
2837
|
-
|
2838
|
-
free_buffer( data );
|
2839
|
-
}
|
2840
|
-
|
2841
|
-
|
2842
|
-
static void
|
2843
|
-
test_handle_switch_events_if_unhandled_message_type() {
|
2844
|
-
buffer *data;
|
2845
|
-
|
2846
|
-
data = alloc_buffer_with_length( sizeof( openflow_service_header_t ) );
|
2847
|
-
append_back_buffer( data, sizeof( openflow_service_header_t ) );
|
2848
|
-
|
2849
|
-
// FIXME
|
2850
|
-
handle_switch_events( MESSENGER_OPENFLOW_MESSAGE, data->data, data->length );
|
2851
|
-
|
2852
|
-
stat_entry *stat = lookup_hash_entry( stats, "openflow_application_interface.undefined_switch_event_receive_succeeded" );
|
2853
|
-
assert_int_equal( ( int ) stat->value, 1 );
|
2854
|
-
|
2855
|
-
free_buffer( data );
|
2856
|
-
xfree( delete_hash_entry( stats, "openflow_application_interface.undefined_switch_event_receive_succeeded" ) );
|
2857
|
-
}
|
2858
|
-
|
2859
|
-
|
2860
|
-
/********************************************************************************
|
2861
|
-
* handle_openflow_message() tests.
|
2862
|
-
********************************************************************************/
|
2863
|
-
|
2864
|
-
static void
|
2865
|
-
test_handle_openflow_message() {
|
2866
|
-
openflow_service_header_t messenger_header;
|
2867
|
-
stat_entry *stat;
|
2868
|
-
|
2869
|
-
messenger_header.datapath_id = htonll( DATAPATH_ID );
|
2870
|
-
messenger_header.service_name_length = 0;
|
2871
|
-
|
2872
|
-
// error
|
2873
|
-
{
|
2874
|
-
buffer *buffer, *data;
|
2875
|
-
|
2876
|
-
data = alloc_buffer_with_length( 16 );
|
2877
|
-
append_back_buffer( data, 16 );
|
2878
|
-
memset( data->data, 'a', 16 );
|
2879
|
-
|
2880
|
-
buffer = create_error( TRANSACTION_ID, OFPET_HELLO_FAILED, OFPHFC_INCOMPATIBLE, data );
|
2881
|
-
append_front_buffer( buffer, sizeof( openflow_service_header_t ) );
|
2882
|
-
memcpy( buffer->data, &messenger_header, sizeof( openflow_service_header_t ) );
|
2883
|
-
expect_memory( mock_error_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
2884
|
-
expect_value( mock_error_handler, transaction_id, TRANSACTION_ID );
|
2885
|
-
expect_value( mock_error_handler, type32, OFPET_HELLO_FAILED );
|
2886
|
-
expect_value( mock_error_handler, code32, OFPHFC_INCOMPATIBLE );
|
2887
|
-
expect_value( mock_error_handler, data->length, data->length );
|
2888
|
-
expect_memory( mock_error_handler, data->data, data->data, data->length );
|
2889
|
-
expect_memory( mock_error_handler, user_data, USER_DATA, USER_DATA_LEN );
|
2890
|
-
|
2891
|
-
set_error_handler( mock_error_handler, USER_DATA );
|
2892
|
-
handle_openflow_message( buffer->data, buffer->length );
|
2893
|
-
|
2894
|
-
stat = lookup_hash_entry( stats, "openflow_application_interface.error_receive_succeeded" );
|
2895
|
-
assert_int_equal( ( int ) stat->value, 1 );
|
2896
|
-
|
2897
|
-
free_buffer( data );
|
2898
|
-
free_buffer( buffer );
|
2899
|
-
xfree( delete_hash_entry( stats, "openflow_application_interface.error_receive_succeeded" ) );
|
2900
|
-
}
|
2901
|
-
|
2902
|
-
// vendor
|
2903
|
-
{
|
2904
|
-
buffer *buffer, *data;
|
2905
|
-
|
2906
|
-
data = alloc_buffer_with_length( 16 );
|
2907
|
-
append_back_buffer( data, 16 );
|
2908
|
-
memset( data->data, 'a', 16 );
|
2909
|
-
|
2910
|
-
buffer = create_vendor( TRANSACTION_ID, VENDOR_ID, data );
|
2911
|
-
append_front_buffer( buffer, sizeof( openflow_service_header_t ) );
|
2912
|
-
memcpy( buffer->data, &messenger_header, sizeof( openflow_service_header_t ) );
|
2913
|
-
|
2914
|
-
expect_memory( mock_vendor_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
2915
|
-
expect_value( mock_vendor_handler, transaction_id, TRANSACTION_ID );
|
2916
|
-
expect_value( mock_vendor_handler, vendor, VENDOR_ID );
|
2917
|
-
expect_value( mock_vendor_handler, data->length, data->length );
|
2918
|
-
expect_memory( mock_vendor_handler, data->data, data->data, data->length );
|
2919
|
-
expect_memory( mock_vendor_handler, user_data, USER_DATA, USER_DATA_LEN );
|
2920
|
-
|
2921
|
-
set_vendor_handler( mock_vendor_handler, USER_DATA );
|
2922
|
-
handle_openflow_message( buffer->data, buffer->length );
|
2923
|
-
|
2924
|
-
stat = lookup_hash_entry( stats, "openflow_application_interface.vendor_receive_succeeded" );
|
2925
|
-
assert_int_equal( ( int ) stat->value, 1 );
|
2926
|
-
|
2927
|
-
free_buffer( data );
|
2928
|
-
free_buffer( buffer );
|
2929
|
-
xfree( delete_hash_entry( stats, "openflow_application_interface.vendor_receive_succeeded" ) );
|
2930
|
-
}
|
2931
|
-
|
2932
|
-
// features_reply
|
2933
|
-
{
|
2934
|
-
uint8_t n_tables = 2;
|
2935
|
-
uint32_t n_buffers = 1024;
|
2936
|
-
uint32_t capabilities;
|
2937
|
-
uint32_t actions;
|
2938
|
-
struct ofp_phy_port *phy_port[ 2 ];
|
2939
|
-
buffer *buffer;
|
2940
|
-
list_element *ports;
|
2941
|
-
|
2942
|
-
capabilities = ( OFPC_FLOW_STATS | OFPC_TABLE_STATS | OFPC_PORT_STATS |
|
2943
|
-
OFPC_QUEUE_STATS | OFPC_ARP_MATCH_IP );
|
2944
|
-
actions = ( ( 1 << OFPAT_OUTPUT ) | ( 1 << OFPAT_SET_VLAN_VID ) |
|
2945
|
-
( 1 << OFPAT_SET_TP_SRC ) | ( 1 << OFPAT_SET_TP_DST ) );
|
2946
|
-
|
2947
|
-
phy_port[ 0 ] = xcalloc( 1, sizeof( struct ofp_phy_port ) );
|
2948
|
-
phy_port[ 1 ] = xcalloc( 1, sizeof( struct ofp_phy_port ) );
|
2949
|
-
|
2950
|
-
phy_port[ 0 ]->port_no = 1;
|
2951
|
-
memcpy( phy_port[ 0 ]->hw_addr, MAC_ADDR_X, sizeof( phy_port[ 0 ]->hw_addr ) );
|
2952
|
-
memset( phy_port[ 0 ]->name, '\0', OFP_MAX_PORT_NAME_LEN );
|
2953
|
-
memcpy( phy_port[ 0 ]->name, PORT_NAME, strlen( PORT_NAME ) );
|
2954
|
-
phy_port[ 0 ]->config = OFPPC_PORT_DOWN;
|
2955
|
-
phy_port[ 0 ]->state = OFPPS_LINK_DOWN;
|
2956
|
-
phy_port[ 0 ]->curr = ( OFPPF_1GB_FD | OFPPF_COPPER | OFPPF_PAUSE );
|
2957
|
-
phy_port[ 0 ]->advertised = PORT_FEATURES;
|
2958
|
-
phy_port[ 0 ]->supported = PORT_FEATURES;
|
2959
|
-
phy_port[ 0 ]->peer = PORT_FEATURES;
|
2960
|
-
|
2961
|
-
memcpy( phy_port[ 1 ], phy_port [ 0 ], sizeof( struct ofp_phy_port ) );
|
2962
|
-
|
2963
|
-
phy_port[ 1 ]->port_no = 2;
|
2964
|
-
memcpy( phy_port[ 1 ]->hw_addr, MAC_ADDR_Y, sizeof( phy_port[ 1 ]->hw_addr ) );
|
2965
|
-
|
2966
|
-
create_list( &ports );
|
2967
|
-
append_to_tail( &ports, phy_port[ 0 ] );
|
2968
|
-
append_to_tail( &ports, phy_port[ 1 ] );
|
2969
|
-
|
2970
|
-
buffer = create_features_reply( TRANSACTION_ID, DATAPATH_ID, n_buffers, n_tables,
|
2971
|
-
capabilities, actions, ports );
|
2972
|
-
append_front_buffer( buffer, sizeof( openflow_service_header_t ) );
|
2973
|
-
memcpy( buffer->data, &messenger_header, sizeof( openflow_service_header_t ) );
|
2974
|
-
|
2975
|
-
expect_memory( mock_features_reply_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
2976
|
-
expect_value( mock_features_reply_handler, transaction_id, TRANSACTION_ID );
|
2977
|
-
expect_value( mock_features_reply_handler, n_buffers, n_buffers );
|
2978
|
-
expect_value( mock_features_reply_handler, n_tables32, ( uint32_t ) n_tables );
|
2979
|
-
expect_value( mock_features_reply_handler, capabilities, capabilities );
|
2980
|
-
expect_value( mock_features_reply_handler, actions, actions );
|
2981
|
-
expect_memory( mock_features_reply_handler, port1, ports->data, sizeof( struct ofp_phy_port ) );
|
2982
|
-
expect_memory( mock_features_reply_handler, port2, ports->next->data, sizeof( struct ofp_phy_port ) );
|
2983
|
-
expect_memory( mock_features_reply_handler, user_data, USER_DATA, USER_DATA_LEN );
|
2984
|
-
|
2985
|
-
set_features_reply_handler( mock_features_reply_handler, USER_DATA );
|
2986
|
-
handle_openflow_message( buffer->data, buffer->length );
|
2987
|
-
|
2988
|
-
stat = lookup_hash_entry( stats, "openflow_application_interface.features_reply_receive_succeeded" );
|
2989
|
-
assert_int_equal( ( int ) stat->value, 1 );
|
2990
|
-
|
2991
|
-
xfree( phy_port[ 0 ] );
|
2992
|
-
xfree( phy_port[ 1 ] );
|
2993
|
-
delete_list( ports );
|
2994
|
-
free_buffer( buffer );
|
2995
|
-
xfree( delete_hash_entry( stats, "openflow_application_interface.features_reply_receive_succeeded" ) );
|
2996
|
-
}
|
2997
|
-
|
2998
|
-
// get_config_reply
|
2999
|
-
{
|
3000
|
-
uint16_t flags = OFPC_FRAG_NORMAL;
|
3001
|
-
uint16_t miss_send_len = 128;
|
3002
|
-
buffer *buffer;
|
3003
|
-
|
3004
|
-
buffer = create_get_config_reply( TRANSACTION_ID, flags, miss_send_len );
|
3005
|
-
append_front_buffer( buffer, sizeof( openflow_service_header_t ) );
|
3006
|
-
memcpy( buffer->data, &messenger_header, sizeof( openflow_service_header_t ) );
|
3007
|
-
|
3008
|
-
expect_memory( mock_get_config_reply_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
3009
|
-
expect_value( mock_get_config_reply_handler, transaction_id, TRANSACTION_ID );
|
3010
|
-
expect_value( mock_get_config_reply_handler, flags32, ( uint32_t ) flags );
|
3011
|
-
expect_value( mock_get_config_reply_handler, miss_send_len32, ( uint32_t ) miss_send_len );
|
3012
|
-
expect_memory( mock_get_config_reply_handler, user_data, USER_DATA, USER_DATA_LEN );
|
3013
|
-
|
3014
|
-
set_get_config_reply_handler( mock_get_config_reply_handler, USER_DATA );
|
3015
|
-
handle_openflow_message( buffer->data, buffer->length );
|
3016
|
-
|
3017
|
-
stat = lookup_hash_entry( stats, "openflow_application_interface.get_config_reply_receive_succeeded" );
|
3018
|
-
assert_int_equal( ( int ) stat->value, 1 );
|
3019
|
-
|
3020
|
-
free_buffer( buffer );
|
3021
|
-
xfree( delete_hash_entry( stats, "openflow_application_interface.get_config_reply_receive_succeeded" ) );
|
3022
|
-
}
|
3023
|
-
|
3024
|
-
// packet_in
|
3025
|
-
{
|
3026
|
-
uint8_t reason = OFPR_NO_MATCH;
|
3027
|
-
uint16_t total_len;
|
3028
|
-
uint16_t in_port = 1;
|
3029
|
-
uint32_t buffer_id = 0x01020304;
|
3030
|
-
buffer *buffer, *data;
|
3031
|
-
|
3032
|
-
data = alloc_buffer_with_length( 64 );
|
3033
|
-
append_back_buffer( data, 64 );
|
3034
|
-
memset( data->data, 0x01, 64 );
|
3035
|
-
|
3036
|
-
total_len = ( uint16_t ) data->length;
|
3037
|
-
|
3038
|
-
buffer = create_packet_in( TRANSACTION_ID, buffer_id, total_len, in_port,
|
3039
|
-
reason, data );
|
3040
|
-
append_front_buffer( buffer, sizeof( openflow_service_header_t ) );
|
3041
|
-
memcpy( buffer->data, &messenger_header, sizeof( openflow_service_header_t ) );
|
3042
|
-
|
3043
|
-
will_return( mock_parse_packet, true );
|
3044
|
-
|
3045
|
-
expect_memory( mock_packet_in_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
3046
|
-
expect_value( mock_packet_in_handler, transaction_id, TRANSACTION_ID );
|
3047
|
-
expect_value( mock_packet_in_handler, buffer_id, buffer_id );
|
3048
|
-
expect_value( mock_packet_in_handler, total_len32, ( uint32_t ) total_len );
|
3049
|
-
expect_value( mock_packet_in_handler, in_port32, ( uint32_t ) in_port );
|
3050
|
-
expect_value( mock_packet_in_handler, reason32, ( uint32_t ) reason );
|
3051
|
-
expect_value( mock_packet_in_handler, data->length, data->length );
|
3052
|
-
expect_memory( mock_packet_in_handler, data->data, data->data, data->length );
|
3053
|
-
expect_memory( mock_packet_in_handler, user_data, USER_DATA, USER_DATA_LEN );
|
3054
|
-
|
3055
|
-
set_packet_in_handler( mock_packet_in_handler, USER_DATA );
|
3056
|
-
handle_openflow_message( buffer->data, buffer->length );
|
3057
|
-
|
3058
|
-
stat = lookup_hash_entry( stats, "openflow_application_interface.packet_in_receive_succeeded" );
|
3059
|
-
assert_int_equal( ( int ) stat->value, 1 );
|
3060
|
-
|
3061
|
-
free_buffer( data );
|
3062
|
-
free_buffer( buffer );
|
3063
|
-
xfree( delete_hash_entry( stats, "openflow_application_interface.packet_in_receive_succeeded" ) );
|
3064
|
-
}
|
3065
|
-
|
3066
|
-
// flow_removed
|
3067
|
-
{
|
3068
|
-
uint8_t reason = OFPRR_IDLE_TIMEOUT;
|
3069
|
-
uint16_t idle_timeout = 60;
|
3070
|
-
uint16_t priority = UINT16_MAX;
|
3071
|
-
uint32_t duration_sec = 180;
|
3072
|
-
uint32_t duration_nsec = 10000;
|
3073
|
-
uint64_t cookie = 0x0102030405060708ULL;
|
3074
|
-
uint64_t packet_count = 1000;
|
3075
|
-
uint64_t byte_count = 100000;
|
3076
|
-
buffer *buffer;
|
3077
|
-
|
3078
|
-
buffer = create_flow_removed( TRANSACTION_ID, MATCH, cookie, priority,
|
3079
|
-
reason, duration_sec, duration_nsec,
|
3080
|
-
idle_timeout, packet_count, byte_count );
|
3081
|
-
append_front_buffer( buffer, sizeof( openflow_service_header_t ) );
|
3082
|
-
memcpy( buffer->data, &messenger_header, sizeof( openflow_service_header_t ) );
|
3083
|
-
|
3084
|
-
expect_memory( mock_flow_removed_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
3085
|
-
expect_value( mock_flow_removed_handler, transaction_id, TRANSACTION_ID );
|
3086
|
-
expect_memory( mock_flow_removed_handler, &match, &MATCH, sizeof( struct ofp_match ) );
|
3087
|
-
expect_memory( mock_flow_removed_handler, &cookie, &cookie, sizeof( uint64_t ) );
|
3088
|
-
expect_value( mock_flow_removed_handler, priority32, ( uint32_t ) priority );
|
3089
|
-
expect_value( mock_flow_removed_handler, reason32, ( uint32_t ) reason );
|
3090
|
-
expect_value( mock_flow_removed_handler, duration_sec, duration_sec );
|
3091
|
-
expect_value( mock_flow_removed_handler, duration_nsec, duration_nsec );
|
3092
|
-
expect_value( mock_flow_removed_handler, idle_timeout32, ( uint32_t ) idle_timeout );
|
3093
|
-
expect_memory( mock_flow_removed_handler, &packet_count, &packet_count, sizeof( uint64_t ) );
|
3094
|
-
expect_memory( mock_flow_removed_handler, &byte_count, &byte_count, sizeof( uint64_t ) );
|
3095
|
-
expect_memory( mock_flow_removed_handler, user_data, USER_DATA, USER_DATA_LEN );
|
3096
|
-
|
3097
|
-
set_flow_removed_handler( mock_flow_removed_handler, USER_DATA );
|
3098
|
-
handle_openflow_message( buffer->data, buffer->length );
|
3099
|
-
|
3100
|
-
stat = lookup_hash_entry( stats, "openflow_application_interface.flow_removed_receive_succeeded" );
|
3101
|
-
assert_int_equal( ( int ) stat->value, 1 );
|
3102
|
-
|
3103
|
-
free_buffer( buffer );
|
3104
|
-
xfree( delete_hash_entry( stats, "openflow_application_interface.flow_removed_receive_succeeded" ) );
|
3105
|
-
}
|
3106
|
-
|
3107
|
-
// port_status
|
3108
|
-
{
|
3109
|
-
uint8_t reason = OFPPR_MODIFY;
|
3110
|
-
buffer *buffer;
|
3111
|
-
struct ofp_phy_port desc;
|
3112
|
-
|
3113
|
-
desc.port_no = 1;
|
3114
|
-
memcpy( desc.hw_addr, MAC_ADDR_X, sizeof( desc.hw_addr ) );
|
3115
|
-
memset( desc.name, '\0', OFP_MAX_PORT_NAME_LEN );
|
3116
|
-
memcpy( desc.name, PORT_NAME, strlen( PORT_NAME ) );
|
3117
|
-
desc.config = OFPPC_PORT_DOWN;
|
3118
|
-
desc.state = OFPPS_LINK_DOWN;
|
3119
|
-
desc.curr = ( OFPPF_1GB_FD | OFPPF_COPPER | OFPPF_PAUSE );
|
3120
|
-
desc.advertised = PORT_FEATURES;
|
3121
|
-
desc.supported = PORT_FEATURES;
|
3122
|
-
desc.peer = PORT_FEATURES;
|
3123
|
-
|
3124
|
-
buffer = create_port_status( TRANSACTION_ID, reason, desc );
|
3125
|
-
append_front_buffer( buffer, sizeof( openflow_service_header_t ) );
|
3126
|
-
memcpy( buffer->data, &messenger_header, sizeof( openflow_service_header_t ) );
|
3127
|
-
|
3128
|
-
expect_memory( mock_port_status_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
3129
|
-
expect_value( mock_port_status_handler, transaction_id, TRANSACTION_ID );
|
3130
|
-
expect_value( mock_port_status_handler, reason32, ( uint32_t ) reason );
|
3131
|
-
expect_memory( mock_port_status_handler, &phy_port, &desc, sizeof( struct ofp_phy_port ) );
|
3132
|
-
expect_memory( mock_port_status_handler, user_data, USER_DATA, USER_DATA_LEN );
|
3133
|
-
|
3134
|
-
set_port_status_handler( mock_port_status_handler, USER_DATA );
|
3135
|
-
handle_openflow_message( buffer->data, buffer->length );
|
3136
|
-
|
3137
|
-
stat = lookup_hash_entry( stats, "openflow_application_interface.port_status_receive_succeeded" );
|
3138
|
-
assert_int_equal( ( int ) stat->value, 1 );
|
3139
|
-
|
3140
|
-
free_buffer( buffer );
|
3141
|
-
xfree( delete_hash_entry( stats, "openflow_application_interface.port_status_receive_succeeded" ) );
|
3142
|
-
}
|
3143
|
-
|
3144
|
-
// stats_reply
|
3145
|
-
{
|
3146
|
-
char mfr_desc[ DESC_STR_LEN ];
|
3147
|
-
char hw_desc[ DESC_STR_LEN ];
|
3148
|
-
char sw_desc[ DESC_STR_LEN ];
|
3149
|
-
char serial_num[ SERIAL_NUM_LEN ];
|
3150
|
-
char dp_desc[ DESC_STR_LEN ];
|
3151
|
-
uint16_t flags = 0;
|
3152
|
-
uint32_t body_len;
|
3153
|
-
buffer *buffer;
|
3154
|
-
struct ofp_stats_reply *stats_reply;
|
3155
|
-
|
3156
|
-
memset( mfr_desc, '\0', DESC_STR_LEN );
|
3157
|
-
memset( hw_desc, '\0', DESC_STR_LEN );
|
3158
|
-
memset( sw_desc, '\0', DESC_STR_LEN );
|
3159
|
-
memset( serial_num, '\0', SERIAL_NUM_LEN );
|
3160
|
-
memset( dp_desc, '\0', DESC_STR_LEN );
|
3161
|
-
sprintf( mfr_desc, "NEC Coporation" );
|
3162
|
-
sprintf( hw_desc, "OpenFlow Switch Hardware" );
|
3163
|
-
sprintf( sw_desc, "OpenFlow Switch Software" );
|
3164
|
-
sprintf( serial_num, "123456" );
|
3165
|
-
sprintf( dp_desc, "Datapath 0" );
|
3166
|
-
|
3167
|
-
buffer = create_desc_stats_reply( TRANSACTION_ID, flags, mfr_desc, hw_desc,
|
3168
|
-
sw_desc, serial_num, dp_desc );
|
3169
|
-
|
3170
|
-
append_front_buffer( buffer, sizeof( openflow_service_header_t ) );
|
3171
|
-
memcpy( buffer->data, &messenger_header, sizeof( openflow_service_header_t ) );
|
3172
|
-
|
3173
|
-
stats_reply = ( struct ofp_stats_reply * ) ( ( char * ) buffer->data +
|
3174
|
-
sizeof( openflow_service_header_t ) );
|
3175
|
-
body_len = ( uint32_t ) ( ntohs( stats_reply->header.length ) -
|
3176
|
-
offsetof( struct ofp_stats_reply, body ) );
|
3177
|
-
|
3178
|
-
|
3179
|
-
expect_memory( mock_stats_reply_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
3180
|
-
expect_value( mock_stats_reply_handler, transaction_id, TRANSACTION_ID );
|
3181
|
-
expect_value( mock_stats_reply_handler, type32, OFPST_DESC );
|
3182
|
-
expect_value( mock_stats_reply_handler, flags32, ( uint32_t ) flags );
|
3183
|
-
expect_value( mock_stats_reply_handler, data->length, body_len );
|
3184
|
-
expect_memory( mock_stats_reply_handler, data->data, stats_reply->body, body_len );
|
3185
|
-
expect_memory( mock_stats_reply_handler, user_data, USER_DATA, USER_DATA_LEN );
|
3186
|
-
|
3187
|
-
set_stats_reply_handler( mock_stats_reply_handler, USER_DATA );
|
3188
|
-
handle_openflow_message( buffer->data, buffer->length );
|
3189
|
-
|
3190
|
-
stat = lookup_hash_entry( stats, "openflow_application_interface.stats_reply_receive_succeeded" );
|
3191
|
-
assert_int_equal( ( int ) stat->value, 1 );
|
3192
|
-
|
3193
|
-
free_buffer( buffer );
|
3194
|
-
xfree( delete_hash_entry( stats, "openflow_application_interface.stats_reply_receive_succeeded" ) );
|
3195
|
-
}
|
3196
|
-
|
3197
|
-
// barrier_reply
|
3198
|
-
{
|
3199
|
-
buffer *buffer;
|
3200
|
-
|
3201
|
-
buffer = create_barrier_reply( TRANSACTION_ID );
|
3202
|
-
append_front_buffer( buffer, sizeof( openflow_service_header_t ) );
|
3203
|
-
memcpy( buffer->data, &messenger_header, sizeof( openflow_service_header_t ) );
|
3204
|
-
|
3205
|
-
expect_memory( mock_barrier_reply_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
3206
|
-
expect_value( mock_barrier_reply_handler, transaction_id, TRANSACTION_ID );
|
3207
|
-
expect_memory( mock_barrier_reply_handler, user_data, USER_DATA, USER_DATA_LEN );
|
3208
|
-
|
3209
|
-
set_barrier_reply_handler( mock_barrier_reply_handler, USER_DATA );
|
3210
|
-
handle_openflow_message( buffer->data, buffer->length );
|
3211
|
-
|
3212
|
-
stat = lookup_hash_entry( stats, "openflow_application_interface.barrier_reply_receive_succeeded" );
|
3213
|
-
assert_int_equal( ( int ) stat->value, 1 );
|
3214
|
-
|
3215
|
-
free_buffer( buffer );
|
3216
|
-
xfree( delete_hash_entry( stats, "openflow_application_interface.barrier_reply_receive_succeeded" ) );
|
3217
|
-
}
|
3218
|
-
|
3219
|
-
// queue_get_config_reply
|
3220
|
-
{
|
3221
|
-
size_t queue_len;
|
3222
|
-
uint16_t port = 1;
|
3223
|
-
list_element *queues;
|
3224
|
-
buffer *buffer;
|
3225
|
-
struct ofp_packet_queue *queue[ 2 ];
|
3226
|
-
struct ofp_queue_prop_header *prop_header;
|
3227
|
-
|
3228
|
-
queue_len = offsetof( struct ofp_packet_queue, properties ) + sizeof( struct ofp_queue_prop_header );
|
3229
|
-
queue[ 0 ] = xcalloc( 1, queue_len );
|
3230
|
-
queue[ 1 ] = xcalloc( 1, queue_len );
|
3231
|
-
|
3232
|
-
queue[ 0 ]->queue_id = 1;
|
3233
|
-
queue[ 0 ]->len = 16;
|
3234
|
-
prop_header = queue[ 0 ]->properties;
|
3235
|
-
prop_header->property = OFPQT_NONE;
|
3236
|
-
prop_header->len = 8;
|
3237
|
-
|
3238
|
-
queue[ 1 ]->queue_id = 2;
|
3239
|
-
queue[ 1 ]->len = 16;
|
3240
|
-
prop_header = queue[ 1 ]->properties;
|
3241
|
-
prop_header->property = OFPQT_NONE;
|
3242
|
-
prop_header->len = 8;
|
3243
|
-
|
3244
|
-
create_list( &queues );
|
3245
|
-
append_to_tail( &queues, queue[ 0 ] );
|
3246
|
-
append_to_tail( &queues, queue[ 1 ] );
|
3247
|
-
|
3248
|
-
buffer = create_queue_get_config_reply( TRANSACTION_ID, port, queues );
|
3249
|
-
|
3250
|
-
append_front_buffer( buffer, sizeof( openflow_service_header_t ) );
|
3251
|
-
memcpy( buffer->data, &messenger_header, sizeof( openflow_service_header_t ) );
|
3252
|
-
|
3253
|
-
expect_memory( mock_queue_get_config_reply_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
3254
|
-
expect_value( mock_queue_get_config_reply_handler, transaction_id, TRANSACTION_ID );
|
3255
|
-
expect_value( mock_queue_get_config_reply_handler, port32, ( uint32_t ) port );
|
3256
|
-
expect_memory( mock_queue_get_config_reply_handler, queue1, queue[ 0 ], queue_len );
|
3257
|
-
expect_memory( mock_queue_get_config_reply_handler, queue2, queue[ 1 ], queue_len );
|
3258
|
-
expect_memory( mock_queue_get_config_reply_handler, user_data, USER_DATA, USER_DATA_LEN );
|
3259
|
-
|
3260
|
-
set_queue_get_config_reply_handler( mock_queue_get_config_reply_handler, USER_DATA );
|
3261
|
-
handle_openflow_message( buffer->data, buffer->length );
|
3262
|
-
|
3263
|
-
stat = lookup_hash_entry( stats, "openflow_application_interface.queue_get_config_reply_receive_succeeded" );
|
3264
|
-
assert_int_equal( ( int ) stat->value, 1 );
|
3265
|
-
|
3266
|
-
xfree( queue[ 0 ] );
|
3267
|
-
xfree( queue[ 1 ] );
|
3268
|
-
delete_list( queues );
|
3269
|
-
free_buffer( buffer );
|
3270
|
-
xfree( delete_hash_entry( stats, "openflow_application_interface.queue_get_config_reply_receive_succeeded" ) );
|
3271
|
-
}
|
3272
|
-
|
3273
|
-
// unhandled message
|
3274
|
-
{
|
3275
|
-
buffer *buffer;
|
3276
|
-
|
3277
|
-
buffer = create_hello( TRANSACTION_ID );
|
3278
|
-
struct ofp_header *header = buffer->data;
|
3279
|
-
header->type = OFPT_QUEUE_GET_CONFIG_REPLY + 1;
|
3280
|
-
append_front_buffer( buffer, sizeof( openflow_service_header_t ) );
|
3281
|
-
memcpy( buffer->data, &messenger_header, sizeof( openflow_service_header_t ) );
|
3282
|
-
|
3283
|
-
// FIXME
|
3284
|
-
handle_openflow_message( buffer->data, buffer->length );
|
3285
|
-
|
3286
|
-
free_buffer( buffer );
|
3287
|
-
}
|
3288
|
-
}
|
3289
|
-
|
3290
|
-
|
3291
|
-
static void
|
3292
|
-
test_handle_openflow_message_with_malformed_message() {
|
3293
|
-
buffer *buffer;
|
3294
|
-
openflow_service_header_t messenger_header;
|
3295
|
-
struct ofp_header *header;
|
3296
|
-
|
3297
|
-
messenger_header.datapath_id = htonll( DATAPATH_ID );
|
3298
|
-
messenger_header.service_name_length = 0;
|
3299
|
-
|
3300
|
-
buffer = create_hello( TRANSACTION_ID );
|
3301
|
-
header = buffer->data;
|
3302
|
-
header->length = htons( UINT16_MAX );
|
3303
|
-
append_front_buffer( buffer, sizeof( openflow_service_header_t ) );
|
3304
|
-
memcpy( buffer->data, &messenger_header, sizeof( openflow_service_header_t ) );
|
3305
|
-
|
3306
|
-
handle_openflow_message( buffer->data, buffer->length );
|
3307
|
-
|
3308
|
-
free_buffer( buffer );
|
3309
|
-
}
|
3310
|
-
|
3311
|
-
|
3312
|
-
static void
|
3313
|
-
test_handle_openflow_message_if_message_is_NULL() {
|
3314
|
-
expect_assert_failure( handle_openflow_message( NULL, 1 ) );
|
3315
|
-
}
|
3316
|
-
|
3317
|
-
|
3318
|
-
static void
|
3319
|
-
test_handle_openflow_message_if_message_length_is_zero() {
|
3320
|
-
buffer *data;
|
3321
|
-
|
3322
|
-
data = alloc_buffer_with_length( 32 );
|
3323
|
-
|
3324
|
-
expect_assert_failure( handle_openflow_message( data, 0 ) );
|
3325
|
-
|
3326
|
-
free_buffer( data );
|
3327
|
-
}
|
3328
|
-
|
3329
|
-
|
3330
|
-
static void
|
3331
|
-
test_handle_openflow_message_if_unhandled_message_type() {
|
3332
|
-
buffer *data;
|
3333
|
-
|
3334
|
-
data = alloc_buffer_with_length( 32 );
|
3335
|
-
append_back_buffer( data, 32 );
|
3336
|
-
|
3337
|
-
// FIXME
|
3338
|
-
handle_openflow_message( data, data->length );
|
3339
|
-
|
3340
|
-
free_buffer( data );
|
3341
|
-
}
|
3342
|
-
|
3343
|
-
|
3344
|
-
/********************************************************************************
|
3345
|
-
* handle_message() tests.
|
3346
|
-
********************************************************************************/
|
3347
|
-
|
3348
|
-
static void
|
3349
|
-
test_handle_message_if_type_is_MESSENGER_OPENFLOW_MESSAGE() {
|
3350
|
-
buffer *data;
|
3351
|
-
openflow_service_header_t *header;
|
3352
|
-
|
3353
|
-
data = create_barrier_reply( TRANSACTION_ID );
|
3354
|
-
|
3355
|
-
assert_true( data != NULL );
|
3356
|
-
|
3357
|
-
append_front_buffer( data, sizeof( openflow_service_header_t ) );
|
3358
|
-
|
3359
|
-
header = data->data;
|
3360
|
-
header->datapath_id = htonll( DATAPATH_ID );
|
3361
|
-
header->service_name_length = 0;
|
3362
|
-
|
3363
|
-
expect_memory( mock_barrier_reply_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
3364
|
-
expect_value( mock_barrier_reply_handler, transaction_id, TRANSACTION_ID );
|
3365
|
-
expect_value( mock_barrier_reply_handler, user_data, BARRIER_REPLY_USER_DATA );
|
3366
|
-
|
3367
|
-
set_barrier_reply_handler( mock_barrier_reply_handler, BARRIER_REPLY_USER_DATA );
|
3368
|
-
handle_message( MESSENGER_OPENFLOW_MESSAGE, data->data, data->length );
|
3369
|
-
|
3370
|
-
stat_entry *stat = lookup_hash_entry( stats, "openflow_application_interface.barrier_reply_receive_succeeded" );
|
3371
|
-
assert_int_equal( ( int ) stat->value, 1 );
|
3372
|
-
|
3373
|
-
|
3374
|
-
free_buffer( data );
|
3375
|
-
xfree( delete_hash_entry( stats, "openflow_application_interface.barrier_reply_receive_succeeded" ) );
|
3376
|
-
}
|
3377
|
-
|
3378
|
-
|
3379
|
-
static void
|
3380
|
-
test_handle_message_if_type_is_MESSENGER_OPENFLOW_CONNECTED() {
|
3381
|
-
buffer *data = alloc_buffer_with_length( sizeof( openflow_service_header_t ) );
|
3382
|
-
append_back_buffer( data, sizeof( openflow_service_header_t ) );
|
3383
|
-
|
3384
|
-
handle_message( MESSENGER_OPENFLOW_CONNECTED, data->data, data->length );
|
3385
|
-
|
3386
|
-
stat_entry *stat = lookup_hash_entry( stats, "openflow_application_interface.switch_connected_receive_succeeded" );
|
3387
|
-
assert_int_equal( ( int ) stat->value, 1 );
|
3388
|
-
|
3389
|
-
free_buffer( data );
|
3390
|
-
xfree( delete_hash_entry( stats, "openflow_application_interface.switch_connected_receive_succeeded" ) );
|
3391
|
-
}
|
3392
|
-
|
3393
|
-
|
3394
|
-
static void
|
3395
|
-
test_handle_message_if_type_is_MESSENGER_OPENFLOW_DISCONNECTED() {
|
3396
|
-
uint64_t *datapath_id;
|
3397
|
-
buffer *data;
|
3398
|
-
|
3399
|
-
data = alloc_buffer_with_length( sizeof( openflow_service_header_t ) );
|
3400
|
-
datapath_id = append_back_buffer( data, sizeof( openflow_service_header_t ) );
|
3401
|
-
|
3402
|
-
*datapath_id = htonll( DATAPATH_ID );
|
3403
|
-
|
3404
|
-
expect_memory( mock_switch_disconnected_handler, &datapath_id, &DATAPATH_ID, sizeof( uint64_t ) );
|
3405
|
-
expect_value( mock_switch_disconnected_handler, user_data, SWITCH_DISCONNECTED_USER_DATA );
|
3406
|
-
|
3407
|
-
expect_string( mock_clear_send_queue, service_name, REMOTE_SERVICE_NAME );
|
3408
|
-
will_return( mock_clear_send_queue, true );
|
3409
|
-
|
3410
|
-
set_switch_disconnected_handler( mock_switch_disconnected_handler, SWITCH_DISCONNECTED_USER_DATA );
|
3411
|
-
handle_message( MESSENGER_OPENFLOW_DISCONNECTED, data->data, data->length );
|
3412
|
-
|
3413
|
-
stat_entry *stat = lookup_hash_entry( stats, "openflow_application_interface.switch_disconnected_receive_succeeded" );
|
3414
|
-
assert_int_equal( ( int ) stat->value, 1 );
|
3415
|
-
|
3416
|
-
free_buffer( data );
|
3417
|
-
xfree( delete_hash_entry( stats, "openflow_application_interface.switch_disconnected_receive_succeeded" ) );
|
3418
|
-
}
|
3419
|
-
|
3420
|
-
|
3421
|
-
static void
|
3422
|
-
test_handle_message_if_message_is_NULL() {
|
3423
|
-
expect_assert_failure( handle_message( MESSENGER_OPENFLOW_MESSAGE, NULL, 1 ) );
|
3424
|
-
}
|
3425
|
-
|
3426
|
-
|
3427
|
-
static void
|
3428
|
-
test_handle_message_if_message_length_is_zero() {
|
3429
|
-
buffer *data;
|
3430
|
-
|
3431
|
-
data = alloc_buffer_with_length( sizeof( openflow_service_header_t ) );
|
3432
|
-
|
3433
|
-
expect_assert_failure( handle_message( MESSENGER_OPENFLOW_MESSAGE, data->data, 0 ) );
|
3434
|
-
|
3435
|
-
free_buffer( data );
|
3436
|
-
}
|
3437
|
-
|
3438
|
-
|
3439
|
-
static void
|
3440
|
-
test_handle_message_if_unhandled_message_type() {
|
3441
|
-
buffer *data;
|
3442
|
-
|
3443
|
-
data = alloc_buffer_with_length( sizeof( openflow_service_header_t ) );
|
3444
|
-
append_back_buffer( data, sizeof( openflow_service_header_t ) );
|
3445
|
-
|
3446
|
-
// FIXME
|
3447
|
-
handle_message( MESSENGER_OPENFLOW_DISCONNECTED + 1, data->data, data->length );
|
3448
|
-
|
3449
|
-
stat_entry *stat = lookup_hash_entry( stats, "openflow_application_interface.undefined_switch_event_receive_succeeded" );
|
3450
|
-
assert_int_equal( ( int ) stat->value, 1 );
|
3451
|
-
|
3452
|
-
free_buffer( data );
|
3453
|
-
xfree( delete_hash_entry( stats, "openflow_application_interface.undefined_switch_event_receive_succeeded" ) );
|
3454
|
-
}
|
3455
|
-
|
3456
|
-
|
3457
|
-
/********************************************************************************
|
3458
|
-
* delete_openflow_messages() tests.
|
3459
|
-
********************************************************************************/
|
3460
|
-
|
3461
|
-
static void
|
3462
|
-
test_delete_openflow_messages() {
|
3463
|
-
expect_string( mock_clear_send_queue, service_name, REMOTE_SERVICE_NAME );
|
3464
|
-
will_return( mock_clear_send_queue, true );
|
3465
|
-
|
3466
|
-
assert_true( delete_openflow_messages( DATAPATH_ID ) );
|
3467
|
-
}
|
3468
|
-
|
3469
|
-
|
3470
|
-
static void
|
3471
|
-
test_delete_openflow_messages_if_clear_send_queue_fails() {
|
3472
|
-
expect_string( mock_clear_send_queue, service_name, REMOTE_SERVICE_NAME );
|
3473
|
-
will_return( mock_clear_send_queue, false );
|
3474
|
-
|
3475
|
-
assert_false( delete_openflow_messages( DATAPATH_ID ) );
|
3476
|
-
}
|
3477
|
-
|
3478
|
-
|
3479
|
-
/********************************************************************************
|
3480
|
-
* disconnect_switch() tests.
|
3481
|
-
********************************************************************************/
|
3482
|
-
|
3483
|
-
static void
|
3484
|
-
test_disconnect_switch() {
|
3485
|
-
size_t expected_length = ( size_t ) ( sizeof( openflow_service_header_t ) + strlen( SERVICE_NAME ) + 1 );
|
3486
|
-
void *expected_data = xcalloc( 1, expected_length );
|
3487
|
-
openflow_service_header_t *header = expected_data;
|
3488
|
-
header->datapath_id = htonll( DATAPATH_ID );
|
3489
|
-
header->service_name_length = htons( ( uint16_t ) ( strlen( SERVICE_NAME ) + 1 ) );
|
3490
|
-
memcpy( ( char * ) expected_data + sizeof( openflow_service_header_t ), SERVICE_NAME, strlen( SERVICE_NAME ) + 1 );
|
3491
|
-
|
3492
|
-
expect_string( mock_send_message, service_name, REMOTE_SERVICE_NAME );
|
3493
|
-
expect_value( mock_send_message, tag32, MESSENGER_OPENFLOW_DISCONNECT_REQUEST );
|
3494
|
-
expect_value( mock_send_message, len, expected_length );
|
3495
|
-
expect_memory( mock_send_message, data, expected_data, expected_length );
|
3496
|
-
will_return( mock_send_message, true );
|
3497
|
-
|
3498
|
-
assert_true( disconnect_switch( DATAPATH_ID ) );
|
3499
|
-
|
3500
|
-
xfree( expected_data );
|
3501
|
-
}
|
3502
|
-
|
3503
|
-
|
3504
|
-
static void
|
3505
|
-
test_disconnect_switch_if_send_message_fails() {
|
3506
|
-
size_t expected_length = ( size_t ) ( sizeof( openflow_service_header_t ) + strlen( SERVICE_NAME ) + 1 );
|
3507
|
-
void *expected_data = xcalloc( 1, expected_length );
|
3508
|
-
openflow_service_header_t *header = expected_data;
|
3509
|
-
header->datapath_id = htonll( DATAPATH_ID );
|
3510
|
-
header->service_name_length = htons( ( uint16_t ) ( strlen( SERVICE_NAME ) + 1 ) );
|
3511
|
-
memcpy( ( char * ) expected_data + sizeof( openflow_service_header_t ), SERVICE_NAME, strlen( SERVICE_NAME ) + 1 );
|
3512
|
-
|
3513
|
-
expect_string( mock_send_message, service_name, REMOTE_SERVICE_NAME );
|
3514
|
-
expect_value( mock_send_message, tag32, MESSENGER_OPENFLOW_DISCONNECT_REQUEST );
|
3515
|
-
expect_value( mock_send_message, len, expected_length );
|
3516
|
-
expect_memory( mock_send_message, data, expected_data, expected_length );
|
3517
|
-
will_return( mock_send_message, false );
|
3518
|
-
|
3519
|
-
assert_false( disconnect_switch( DATAPATH_ID ) );
|
3520
|
-
|
3521
|
-
xfree( expected_data );
|
3522
|
-
}
|
3523
|
-
|
3524
|
-
|
3525
|
-
/********************************************************************************
|
3526
|
-
* Run tests.
|
3527
|
-
********************************************************************************/
|
3528
|
-
|
3529
|
-
int
|
3530
|
-
main() {
|
3531
|
-
const UnitTest tests[] = {
|
3532
|
-
// initialization and finalization tests.
|
3533
|
-
unit_test_setup_teardown( test_init_openflow_application_interface_with_valid_custom_service_name, cleanup, cleanup ),
|
3534
|
-
unit_test_setup_teardown( test_init_openflow_application_interface_with_too_long_custom_service_name, cleanup, cleanup ),
|
3535
|
-
unit_test_setup_teardown( test_init_openflow_application_interface_if_already_initialized, init, cleanup ),
|
3536
|
-
|
3537
|
-
unit_test_setup_teardown( test_finalize_openflow_application_interface, init, cleanup ),
|
3538
|
-
unit_test_setup_teardown( test_finalize_openflow_application_interface_if_not_initialized, cleanup, cleanup ),
|
3539
|
-
|
3540
|
-
unit_test_setup_teardown( test_set_openflow_event_handlers, init, cleanup ),
|
3541
|
-
|
3542
|
-
// switch ready handler tests.
|
3543
|
-
unit_test_setup_teardown( test_set_switch_ready_handler, init, cleanup ),
|
3544
|
-
unit_test_setup_teardown( test_set_simple_switch_ready_handler, init, cleanup ),
|
3545
|
-
unit_test_setup_teardown( test_set_switch_ready_handler_should_die_if_handler_is_NULL, init, cleanup ),
|
3546
|
-
unit_test_setup_teardown( test_handle_switch_ready, init, cleanup ),
|
3547
|
-
unit_test_setup_teardown( test_handle_switch_ready_with_simple_handler, init, cleanup ),
|
3548
|
-
|
3549
|
-
// switch disconnected handler tests.
|
3550
|
-
unit_test_setup_teardown( test_set_switch_disconnected_handler, init, cleanup ),
|
3551
|
-
unit_test_setup_teardown( test_set_switch_disconnected_handler_if_handler_is_NULL, init, cleanup ),
|
3552
|
-
|
3553
|
-
// error handler tests.
|
3554
|
-
unit_test_setup_teardown( test_set_error_handler, init, cleanup ),
|
3555
|
-
unit_test_setup_teardown( test_set_error_handler_if_handler_is_NULL, init, cleanup ),
|
3556
|
-
unit_test_setup_teardown( test_handle_error, init, cleanup ),
|
3557
|
-
unit_test_setup_teardown( test_handle_error_if_handler_is_not_registered, init, cleanup ),
|
3558
|
-
unit_test_setup_teardown( test_handle_error_if_message_is_NULL, init, cleanup ),
|
3559
|
-
unit_test_setup_teardown( test_handle_error_if_message_length_is_zero, init, cleanup ),
|
3560
|
-
|
3561
|
-
// echo_reply handler tests.
|
3562
|
-
unit_test_setup_teardown( test_set_echo_reply_handler, init, cleanup ),
|
3563
|
-
unit_test_setup_teardown( test_set_echo_reply_handler_if_handler_is_NULL, init, cleanup ),
|
3564
|
-
unit_test_setup_teardown( test_handle_echo_reply, init, cleanup ),
|
3565
|
-
unit_test_setup_teardown( test_handle_echo_reply_without_data, init, cleanup ),
|
3566
|
-
unit_test_setup_teardown( test_handle_echo_reply_if_handler_is_not_registered, init, cleanup ),
|
3567
|
-
unit_test_setup_teardown( test_handle_echo_reply_if_message_is_NULL, init, cleanup ),
|
3568
|
-
unit_test_setup_teardown( test_handle_echo_reply_if_message_length_is_zero, init, cleanup ),
|
3569
|
-
|
3570
|
-
// vendor handler tests.
|
3571
|
-
unit_test_setup_teardown( test_set_vendor_handler, init, cleanup ),
|
3572
|
-
unit_test_setup_teardown( test_set_vendor_handler_if_handler_is_NULL, init, cleanup ),
|
3573
|
-
|
3574
|
-
unit_test_setup_teardown( test_handle_vendor, init, cleanup ),
|
3575
|
-
unit_test_setup_teardown( test_handle_vendor_without_data, init, cleanup ),
|
3576
|
-
unit_test_setup_teardown( test_handle_vendor_if_handler_is_not_registered, init, cleanup ),
|
3577
|
-
unit_test_setup_teardown( test_handle_vendor_if_message_is_NULL, init, cleanup ),
|
3578
|
-
unit_test_setup_teardown( test_handle_vendor_if_message_length_is_zero, init, cleanup ),
|
3579
|
-
|
3580
|
-
// features reply handler tests.
|
3581
|
-
unit_test_setup_teardown( test_set_features_reply_handler, init, cleanup ),
|
3582
|
-
unit_test_setup_teardown( test_set_features_reply_handler_if_handler_is_NULL, init, cleanup ),
|
3583
|
-
unit_test_setup_teardown( test_handle_features_reply, init, cleanup ),
|
3584
|
-
unit_test_setup_teardown( test_handle_features_reply_without_phy_port, init, cleanup ),
|
3585
|
-
unit_test_setup_teardown( test_handle_features_reply_if_handler_is_not_registered, init, cleanup ),
|
3586
|
-
unit_test_setup_teardown( test_handle_features_reply_if_message_is_NULL, init, cleanup ),
|
3587
|
-
unit_test_setup_teardown( test_handle_features_reply_if_message_length_is_zero, init, cleanup ),
|
3588
|
-
|
3589
|
-
// get config reply handler tests.
|
3590
|
-
unit_test_setup_teardown( test_set_get_config_reply_handler, init, cleanup ),
|
3591
|
-
unit_test_setup_teardown( test_set_get_config_reply_handler_if_handler_is_NULL, init, cleanup ),
|
3592
|
-
unit_test_setup_teardown( test_handle_get_config_reply, init, cleanup ),
|
3593
|
-
unit_test_setup_teardown( test_handle_get_config_reply_if_handler_is_not_registered, init, cleanup ),
|
3594
|
-
unit_test_setup_teardown( test_handle_get_config_reply_if_message_is_NULL, init, cleanup ),
|
3595
|
-
unit_test_setup_teardown( test_handle_get_config_reply_if_message_length_is_zero, init, cleanup ),
|
3596
|
-
|
3597
|
-
// flow removed handler tests.
|
3598
|
-
unit_test_setup_teardown( test_set_flow_removed_handler, init, cleanup ),
|
3599
|
-
unit_test_setup_teardown( test_set_flow_removed_handler_if_handler_is_NULL, init, cleanup ),
|
3600
|
-
unit_test_setup_teardown( test_handle_flow_removed, init, cleanup ),
|
3601
|
-
unit_test_setup_teardown( test_handle_flow_removed_with_simple_handler, init, cleanup ),
|
3602
|
-
unit_test_setup_teardown( test_set_simple_flow_removed_handler, init, cleanup ),
|
3603
|
-
unit_test_setup_teardown( test_handle_flow_removed_if_handler_is_not_registered, init, cleanup ),
|
3604
|
-
unit_test_setup_teardown( test_handle_flow_removed_if_message_is_NULL, init, cleanup ),
|
3605
|
-
unit_test_setup_teardown( test_handle_flow_removed_if_message_length_is_zero, init, cleanup ),
|
3606
|
-
|
3607
|
-
// port status handler tests.
|
3608
|
-
unit_test_setup_teardown( test_set_port_status_handler, init, cleanup ),
|
3609
|
-
unit_test_setup_teardown( test_set_port_status_handler_if_handler_is_NULL, init, cleanup ),
|
3610
|
-
unit_test_setup_teardown( test_handle_port_status, init, cleanup ),
|
3611
|
-
unit_test_setup_teardown( test_handle_port_status_if_handler_is_not_registered, init, cleanup ),
|
3612
|
-
unit_test_setup_teardown( test_handle_port_status_if_message_is_NULL, init, cleanup ),
|
3613
|
-
unit_test_setup_teardown( test_handle_port_status_if_message_length_is_zero, init, cleanup ),
|
3614
|
-
|
3615
|
-
// stats reply handler tests.
|
3616
|
-
unit_test_setup_teardown( test_set_stats_reply_handler, init, cleanup ),
|
3617
|
-
unit_test_setup_teardown( test_set_stats_reply_handler_if_handler_is_NULL, init, cleanup ),
|
3618
|
-
unit_test_setup_teardown( test_handle_stats_reply_if_type_is_OFPST_DESC, init, cleanup ),
|
3619
|
-
unit_test_setup_teardown( test_handle_stats_reply_if_type_is_OFPST_FLOW, init, cleanup ),
|
3620
|
-
unit_test_setup_teardown( test_handle_stats_reply_if_type_is_OFPST_AGGREGATE, init, cleanup ),
|
3621
|
-
unit_test_setup_teardown( test_handle_stats_reply_if_type_is_OFPST_TABLE, init, cleanup ),
|
3622
|
-
unit_test_setup_teardown( test_handle_stats_reply_if_type_is_OFPST_PORT, init, cleanup ),
|
3623
|
-
unit_test_setup_teardown( test_handle_stats_reply_if_type_is_OFPST_QUEUE, init, cleanup ),
|
3624
|
-
unit_test_setup_teardown( test_handle_stats_reply_if_type_is_OFPST_VENDOR, init, cleanup ),
|
3625
|
-
unit_test_setup_teardown( test_handle_stats_reply_with_undefined_type, init, cleanup ),
|
3626
|
-
unit_test_setup_teardown( test_handle_stats_reply_if_handler_is_not_registered, init, cleanup ),
|
3627
|
-
unit_test_setup_teardown( test_handle_stats_reply_if_message_is_NULL, init, cleanup ),
|
3628
|
-
unit_test_setup_teardown( test_handle_stats_reply_if_message_length_is_zero, init, cleanup ),
|
3629
|
-
|
3630
|
-
// barrier reply handler tests.
|
3631
|
-
unit_test_setup_teardown( test_set_barrier_reply_handler, init, cleanup ),
|
3632
|
-
unit_test_setup_teardown( test_set_barrier_reply_handler_if_handler_is_NULL, init, cleanup ),
|
3633
|
-
unit_test_setup_teardown( test_handle_barrier_reply, init, cleanup ),
|
3634
|
-
unit_test_setup_teardown( test_handle_barrier_reply_if_handler_is_not_registered, init, cleanup ),
|
3635
|
-
unit_test_setup_teardown( test_handle_barrier_reply_if_message_is_NULL, init, cleanup ),
|
3636
|
-
unit_test_setup_teardown( test_handle_barrier_reply_if_message_length_is_zero, init, cleanup ),
|
3637
|
-
|
3638
|
-
// queue get config reply handler tests.
|
3639
|
-
unit_test_setup_teardown( test_set_queue_get_config_reply_handler, init, cleanup ),
|
3640
|
-
unit_test_setup_teardown( test_set_queue_get_config_reply_handler_if_handler_is_NULL, init, cleanup ),
|
3641
|
-
unit_test_setup_teardown( test_handle_queue_get_config_reply, init, cleanup ),
|
3642
|
-
unit_test_setup_teardown( test_handle_queue_get_config_reply_without_queues, init, cleanup ),
|
3643
|
-
unit_test_setup_teardown( test_handle_queue_get_config_reply_if_handler_is_not_registered, init, cleanup ),
|
3644
|
-
unit_test_setup_teardown( test_handle_queue_get_config_reply_if_message_is_NULL, init, cleanup ),
|
3645
|
-
unit_test_setup_teardown( test_handle_queue_get_config_reply_if_message_length_is_zero, init, cleanup ),
|
3646
|
-
|
3647
|
-
// list switches reply handler tests.
|
3648
|
-
unit_test_setup_teardown( test_set_list_switches_reply_handler, init, cleanup ),
|
3649
|
-
unit_test_setup_teardown( test_set_list_switches_reply_handler_if_handler_is_NULL, init, cleanup ),
|
3650
|
-
unit_test_setup_teardown( test_handle_list_switches_reply, init, cleanup ),
|
3651
|
-
unit_test_setup_teardown( test_handle_list_switches_reply_if_data_is_NULL, init, cleanup ),
|
3652
|
-
unit_test_setup_teardown( test_handle_list_switches_reply_if_length_is_zero, init, cleanup ),
|
3653
|
-
|
3654
|
-
// packet-in handler tests.
|
3655
|
-
unit_test_setup_teardown( test_set_packet_in_handler, init, cleanup ),
|
3656
|
-
unit_test_setup_teardown( test_set_simple_packet_in_handler, init, cleanup ),
|
3657
|
-
unit_test_setup_teardown( test_set_packet_in_handler_should_die_if_handler_is_NULL, init, cleanup ),
|
3658
|
-
unit_test_setup_teardown( test_handle_packet_in, init, cleanup ),
|
3659
|
-
unit_test_setup_teardown( test_handle_packet_in_with_simple_handler, init, cleanup ),
|
3660
|
-
unit_test_setup_teardown( test_handle_packet_in_with_malformed_packet, init, cleanup ),
|
3661
|
-
unit_test_setup_teardown( test_handle_packet_in_without_data, init, cleanup ),
|
3662
|
-
unit_test_setup_teardown( test_handle_packet_in_without_handler, init, cleanup ),
|
3663
|
-
unit_test_setup_teardown( test_handle_packet_in_should_die_if_message_is_NULL, init, cleanup ),
|
3664
|
-
unit_test_setup_teardown( test_handle_packet_in_should_die_if_message_length_is_zero, init, cleanup ),
|
3665
|
-
|
3666
|
-
// miscellaneous tests.
|
3667
|
-
unit_test_setup_teardown( test_insert_dpid, init, cleanup ),
|
3668
|
-
unit_test_setup_teardown( test_insert_dpid_if_head_is_NULL, init, cleanup ),
|
3669
|
-
unit_test_setup_teardown( test_insert_dpid_if_dpid_is_NULL, init, cleanup ),
|
3670
|
-
|
3671
|
-
unit_test_setup_teardown( test_handle_switch_events_if_type_is_MESSENGER_OPENFLOW_CONNECTED, init, cleanup ),
|
3672
|
-
unit_test_setup_teardown( test_handle_switch_events_if_type_is_MESSENGER_OPENFLOW_DISCONNECTED, init, cleanup ),
|
3673
|
-
unit_test_setup_teardown( test_handle_switch_events_if_message_is_NULL, init, cleanup ),
|
3674
|
-
unit_test_setup_teardown( test_handle_switch_events_if_message_length_is_zero, init, cleanup ),
|
3675
|
-
unit_test_setup_teardown( test_handle_switch_events_if_message_length_is_too_big, init, cleanup ),
|
3676
|
-
unit_test_setup_teardown( test_handle_switch_events_if_unhandled_message_type, init, cleanup ),
|
3677
|
-
|
3678
|
-
unit_test_setup_teardown( test_handle_openflow_message, init, cleanup ),
|
3679
|
-
unit_test_setup_teardown( test_handle_openflow_message_with_malformed_message, init, cleanup ),
|
3680
|
-
unit_test_setup_teardown( test_handle_openflow_message_if_message_is_NULL, init, cleanup ),
|
3681
|
-
unit_test_setup_teardown( test_handle_openflow_message_if_message_length_is_zero, init, cleanup ),
|
3682
|
-
unit_test_setup_teardown( test_handle_openflow_message_if_unhandled_message_type, init, cleanup ),
|
3683
|
-
|
3684
|
-
unit_test_setup_teardown( test_handle_message_if_type_is_MESSENGER_OPENFLOW_MESSAGE, init, cleanup ),
|
3685
|
-
unit_test_setup_teardown( test_handle_message_if_type_is_MESSENGER_OPENFLOW_CONNECTED, init, cleanup ),
|
3686
|
-
unit_test_setup_teardown( test_handle_message_if_type_is_MESSENGER_OPENFLOW_DISCONNECTED, init, cleanup ),
|
3687
|
-
unit_test_setup_teardown( test_handle_message_if_message_is_NULL, init, cleanup ),
|
3688
|
-
unit_test_setup_teardown( test_handle_message_if_message_length_is_zero, init, cleanup ),
|
3689
|
-
unit_test_setup_teardown( test_handle_message_if_unhandled_message_type, init, cleanup ),
|
3690
|
-
|
3691
|
-
// send_openflow_message() tests.
|
3692
|
-
unit_test_setup_teardown( test_send_openflow_message, init, cleanup ),
|
3693
|
-
unit_test_setup_teardown( test_send_openflow_message_if_message_is_NULL, init, cleanup ),
|
3694
|
-
unit_test_setup_teardown( test_send_openflow_message_if_message_length_is_zero, init, cleanup ),
|
3695
|
-
|
3696
|
-
// delete_openflow_messages() tests.
|
3697
|
-
unit_test_setup_teardown( test_delete_openflow_messages, init, cleanup ),
|
3698
|
-
unit_test_setup_teardown( test_delete_openflow_messages_if_clear_send_queue_fails, init, cleanup ),
|
3699
|
-
|
3700
|
-
// disconnect_switch() tests.
|
3701
|
-
unit_test_setup_teardown( test_disconnect_switch, init, cleanup ),
|
3702
|
-
unit_test_setup_teardown( test_disconnect_switch_if_send_message_fails, init, cleanup ),
|
3703
|
-
};
|
3704
|
-
return run_tests( tests );
|
3705
|
-
}
|
3706
|
-
|
3707
|
-
|
3708
|
-
/*
|
3709
|
-
* Local variables:
|
3710
|
-
* c-basic-offset: 2
|
3711
|
-
* indent-tabs-mode: nil
|
3712
|
-
* End:
|
3713
|
-
*/
|