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