trema 0.4.7 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +33 -54
- data/.hound.yml +3 -0
- data/.rspec +3 -0
- data/.rubocop.yml +17 -1
- data/.travis.yml +14 -18
- data/CHANGELOG.md +10 -0
- data/Gemfile +1 -26
- data/README.md +25 -241
- data/Rakefile +4 -1056
- data/bin/.gitignore +3 -0
- data/bin/trema +163 -237
- data/features/cleanup_on_failure.feature +118 -0
- data/features/logging.feature +73 -0
- data/features/open_flow13.feature +21 -0
- data/features/step_definitions/.gitignore +35 -0
- data/features/step_definitions/.rubocop.yml +5 -0
- data/features/step_definitions/.travis.yml +19 -0
- data/features/step_definitions/Gemfile +9 -0
- data/features/step_definitions/Guardfile +4 -0
- data/features/step_definitions/LICENSE +675 -0
- data/features/step_definitions/README.md +7 -0
- data/features/step_definitions/Rakefile +10 -0
- data/features/step_definitions/show_stats_steps.rb +56 -0
- data/features/step_definitions/virtual_link_steps.rb +8 -0
- data/features/support/env.rb +0 -73
- data/features/support/hooks.rb +6 -50
- data/features/trema_delete_link.feature +30 -0
- data/features/trema_killall.feature +56 -0
- data/features/trema_run.feature +47 -0
- data/features/trema_start.feature +73 -0
- data/features/trema_stop.feature +50 -0
- data/lib/trema.rb +4 -0
- data/lib/trema/command.rb +184 -0
- data/lib/trema/controller.rb +289 -0
- data/lib/trema/dirs.rb +14 -0
- data/lib/trema/drb.rb +32 -0
- data/lib/trema/logger.rb +63 -0
- data/lib/trema/monkey_patch/integer.rb +8 -0
- data/lib/trema/monkey_patch/integer/base_conversions.rb +12 -0
- data/lib/trema/monkey_patch/integer/durations.rb +12 -0
- data/lib/trema/switch.rb +83 -0
- data/lib/trema/version.rb +5 -0
- data/spec/spec_helper.rb +9 -178
- data/spec/trema/controller_spec.rb +4 -53
- data/tasks/.gitignore +34 -0
- data/tasks/LICENSE +675 -0
- data/tasks/README.md +6 -0
- data/tasks/cucumber.rake +14 -0
- data/tasks/flay.rake +15 -0
- data/tasks/flog.rake +25 -0
- data/tasks/gem.rake +15 -0
- data/tasks/reek.rake +11 -0
- data/tasks/relish.rake +8 -0
- data/tasks/rspec.rake +8 -0
- data/tasks/rubocop.rake +2 -16
- data/tasks/yard.rake +11 -0
- data/trema.gemspec +24 -23
- metadata +180 -720
- data/.yardopts +0 -4
- data/Doxyfile +0 -1679
- data/Guardfile +0 -14
- data/bin/quality +0 -31
- data/bin/trema-config +0 -59
- data/build.rb +0 -32
- data/cruise.rb +0 -409
- data/features/.nav +0 -50
- data/features/README.md +0 -7
- data/features/core/get_pid_by_trema_name.feature +0 -137
- data/features/core/packetin_filter.feature +0 -55
- data/features/core/switch_manager.feature +0 -41
- data/features/core/trema-config.feature +0 -55
- data/features/dsl/switch_port_specifier.feature +0 -15
- data/features/examples/dumper.feature +0 -35
- data/features/examples/hello_trema.feature +0 -23
- data/features/examples/learning_switch.feature +0 -37
- data/features/examples/list_switches.feature +0 -24
- data/features/examples/message.set_config.feature +0 -27
- data/features/examples/message.vendor-action.feature +0 -25
- data/features/examples/message.vendor-stats-request.feature +0 -20
- data/features/examples/multi_learning_switch.feature +0 -107
- data/features/examples/openflow_message.echo.feature +0 -59
- data/features/examples/openflow_message.features_request.feature +0 -35
- data/features/examples/openflow_message.hello.feature +0 -59
- data/features/examples/packet_in.feature +0 -33
- data/features/examples/packetin_filter_config.feature +0 -95
- data/features/examples/patch_panel.feature +0 -29
- data/features/examples/repeater_hub.feature +0 -52
- data/features/examples/switch_info.feature +0 -51
- data/features/examples/switch_monitor.feature +0 -35
- data/features/examples/transparent_firewall.feature +0 -73
- data/features/handlers/switch_ready.feature +0 -40
- data/features/step_definitions/misc_steps.rb +0 -85
- data/features/step_definitions/send_packets_steps.rb +0 -33
- data/features/step_definitions/stats_steps.rb +0 -39
- data/features/switch_event/C-add_forward_entry.feature +0 -114
- data/features/switch_event/C-delete_forward_entry.feature +0 -85
- data/features/switch_event/C-dump_forward_entries.feature +0 -72
- data/features/switch_event/C-set_forward_entries.feature +0 -77
- data/features/switch_event/README.md +0 -40
- data/features/switch_event/add_forward_entry.feature +0 -160
- data/features/switch_event/delete_forward_entry.feature +0 -160
- data/features/switch_event/dump_forward_entries.feature +0 -103
- data/features/switch_event/set_forward_entries.feature +0 -102
- data/features/trema_commands/README.md +0 -8
- data/features/trema_commands/dump_flows.feature +0 -41
- data/features/trema_commands/help.feature +0 -27
- data/features/trema_commands/help_option.feature +0 -20
- data/features/trema_commands/kill.feature +0 -56
- data/features/trema_commands/killall.feature +0 -32
- data/features/trema_commands/port_down.feature +0 -71
- data/features/trema_commands/port_up.feature +0 -75
- data/features/trema_commands/reset_stats.feature +0 -56
- data/features/trema_commands/run.feature +0 -56
- data/features/trema_commands/send_packets.feature +0 -46
- data/features/trema_commands/show_stats.feature +0 -66
- data/features/trema_commands/up.feature +0 -34
- data/features/trema_commands/version.feature +0 -10
- data/features/trema_commands/version_option.feature +0 -8
- data/rubocop-todo.yml +0 -159
- data/ruby/.gitignore +0 -4
- data/ruby/blocker.rb +0 -74
- data/ruby/extconf.rb +0 -80
- data/ruby/sub-process.rb +0 -289
- data/ruby/trema/action-common.c +0 -46
- data/ruby/trema/action-common.h +0 -38
- data/ruby/trema/action.rb +0 -33
- data/ruby/trema/aggregate-stats-reply.rb +0 -68
- data/ruby/trema/app.rb +0 -114
- data/ruby/trema/barrier-reply.c +0 -98
- data/ruby/trema/barrier-reply.h +0 -44
- data/ruby/trema/barrier-request.c +0 -135
- data/ruby/trema/barrier-request.h +0 -42
- data/ruby/trema/cli.rb +0 -267
- data/ruby/trema/command.rb +0 -41
- data/ruby/trema/command/dump_flows.rb +0 -43
- data/ruby/trema/command/kill.rb +0 -75
- data/ruby/trema/command/killall.rb +0 -38
- data/ruby/trema/command/netns.rb +0 -38
- data/ruby/trema/command/port_down.rb +0 -43
- data/ruby/trema/command/port_up.rb +0 -43
- data/ruby/trema/command/reset_stats.rb +0 -41
- data/ruby/trema/command/ruby.rb +0 -38
- data/ruby/trema/command/run.rb +0 -110
- data/ruby/trema/command/send_packets.rb +0 -46
- data/ruby/trema/command/shell.rb +0 -57
- data/ruby/trema/command/show_stats.rb +0 -65
- data/ruby/trema/command/up.rb +0 -44
- data/ruby/trema/command/version.rb +0 -35
- data/ruby/trema/compat.h +0 -36
- data/ruby/trema/controller.c +0 -691
- data/ruby/trema/controller.h +0 -42
- data/ruby/trema/controller.rb +0 -255
- data/ruby/trema/custom-switch.rb +0 -56
- data/ruby/trema/daemon.rb +0 -184
- data/ruby/trema/default-logger.c +0 -161
- data/ruby/trema/default-logger.h +0 -42
- data/ruby/trema/default-logger.rb +0 -29
- data/ruby/trema/default_openflow_channel_port.rb +0 -26
- data/ruby/trema/desc-stats-reply.rb +0 -75
- data/ruby/trema/dsl.rb +0 -32
- data/ruby/trema/dsl/configuration.rb +0 -145
- data/ruby/trema/dsl/context.rb +0 -69
- data/ruby/trema/dsl/custom-switch.rb +0 -44
- data/ruby/trema/dsl/link.rb +0 -39
- data/ruby/trema/dsl/netns.rb +0 -78
- data/ruby/trema/dsl/parser.rb +0 -70
- data/ruby/trema/dsl/rswitch.rb +0 -47
- data/ruby/trema/dsl/run.rb +0 -47
- data/ruby/trema/dsl/runner.rb +0 -178
- data/ruby/trema/dsl/stanza.rb +0 -51
- data/ruby/trema/dsl/switch.rb +0 -76
- data/ruby/trema/dsl/syntax-error.rb +0 -31
- data/ruby/trema/dsl/syntax.rb +0 -128
- data/ruby/trema/dsl/vhost.rb +0 -106
- data/ruby/trema/dsl/vswitch.rb +0 -45
- data/ruby/trema/echo-reply.c +0 -122
- data/ruby/trema/echo-reply.h +0 -40
- data/ruby/trema/echo-request.c +0 -117
- data/ruby/trema/echo-request.h +0 -40
- data/ruby/trema/echo.c +0 -99
- data/ruby/trema/echo.h +0 -39
- data/ruby/trema/enqueue.rb +0 -87
- data/ruby/trema/error.c +0 -262
- data/ruby/trema/error.h +0 -42
- data/ruby/trema/exact-match.rb +0 -34
- data/ruby/trema/executables.rb +0 -99
- data/ruby/trema/features-reply.c +0 -330
- data/ruby/trema/features-reply.h +0 -54
- data/ruby/trema/features-request.c +0 -134
- data/ruby/trema/features-request.h +0 -42
- data/ruby/trema/flow-mod.c +0 -150
- data/ruby/trema/flow-mod.h +0 -42
- data/ruby/trema/flow-removed.c +0 -280
- data/ruby/trema/flow-removed.h +0 -44
- data/ruby/trema/flow-stats-reply.rb +0 -107
- data/ruby/trema/flow.rb +0 -65
- data/ruby/trema/get-config-reply.c +0 -158
- data/ruby/trema/get-config-reply.h +0 -50
- data/ruby/trema/get-config-request.c +0 -136
- data/ruby/trema/get-config-request.h +0 -42
- data/ruby/trema/hardware-switch.rb +0 -86
- data/ruby/trema/hello.c +0 -133
- data/ruby/trema/hello.h +0 -42
- data/ruby/trema/host.rb +0 -263
- data/ruby/trema/link.rb +0 -177
- data/ruby/trema/list-switches-reply.c +0 -44
- data/ruby/trema/list-switches-reply.h +0 -38
- data/ruby/trema/mac.rb +0 -29
- data/ruby/trema/match.c +0 -621
- data/ruby/trema/match.h +0 -34
- data/ruby/trema/monkey-patch/integer.rb +0 -35
- data/ruby/trema/monkey-patch/integer/base-conversions.rb +0 -34
- data/ruby/trema/monkey-patch/integer/ranges.rb +0 -49
- data/ruby/trema/monkey-patch/integer/validators.rb +0 -36
- data/ruby/trema/monkey-patch/module.rb +0 -33
- data/ruby/trema/monkey-patch/module/class-method.rb +0 -38
- data/ruby/trema/monkey-patch/module/deprecation.rb +0 -39
- data/ruby/trema/monkey-patch/string.rb +0 -31
- data/ruby/trema/monkey-patch/string/inflectors.rb +0 -52
- data/ruby/trema/netns.rb +0 -127
- data/ruby/trema/network-component.rb +0 -151
- data/ruby/trema/ofctl.rb +0 -70
- data/ruby/trema/open-vswitch.rb +0 -160
- data/ruby/trema/openflow-error.c +0 -193
- data/ruby/trema/openflow-error.h +0 -51
- data/ruby/trema/openflow-switch.rb +0 -35
- data/ruby/trema/ordered-hash.rb +0 -75
- data/ruby/trema/packet-in.c +0 -1365
- data/ruby/trema/packet-in.h +0 -44
- data/ruby/trema/packet-queue.rb +0 -181
- data/ruby/trema/packetin-filter.rb +0 -124
- data/ruby/trema/path.rb +0 -85
- data/ruby/trema/phost.rb +0 -76
- data/ruby/trema/port-mod.c +0 -232
- data/ruby/trema/port-mod.h +0 -34
- data/ruby/trema/port-stats-reply.rb +0 -109
- data/ruby/trema/port-status-add.rb +0 -60
- data/ruby/trema/port-status-delete.rb +0 -60
- data/ruby/trema/port-status-modify.rb +0 -60
- data/ruby/trema/port-status.c +0 -192
- data/ruby/trema/port-status.h +0 -41
- data/ruby/trema/port.c +0 -398
- data/ruby/trema/port.h +0 -45
- data/ruby/trema/process.rb +0 -103
- data/ruby/trema/queue-get-config-reply.c +0 -205
- data/ruby/trema/queue-get-config-reply.h +0 -45
- data/ruby/trema/queue-get-config-request.c +0 -141
- data/ruby/trema/queue-get-config-request.h +0 -42
- data/ruby/trema/queue-stats-reply.rb +0 -76
- data/ruby/trema/ruby-switch.rb +0 -62
- data/ruby/trema/send-out-port.rb +0 -113
- data/ruby/trema/set-config.c +0 -174
- data/ruby/trema/set-config.h +0 -42
- data/ruby/trema/set-eth-addr.rb +0 -54
- data/ruby/trema/set-eth-dst-addr.rb +0 -52
- data/ruby/trema/set-eth-src-addr.rb +0 -53
- data/ruby/trema/set-ip-addr.rb +0 -54
- data/ruby/trema/set-ip-dst-addr.rb +0 -53
- data/ruby/trema/set-ip-src-addr.rb +0 -52
- data/ruby/trema/set-ip-tos.rb +0 -64
- data/ruby/trema/set-transport-dst-port.rb +0 -53
- data/ruby/trema/set-transport-port.rb +0 -53
- data/ruby/trema/set-transport-src-port.rb +0 -54
- data/ruby/trema/set-vlan-priority.rb +0 -66
- data/ruby/trema/set-vlan-vid.rb +0 -65
- data/ruby/trema/shell.rb +0 -37
- data/ruby/trema/shell/down.rb +0 -37
- data/ruby/trema/shell/killall.rb +0 -38
- data/ruby/trema/shell/link.rb +0 -59
- data/ruby/trema/shell/reset_stats.rb +0 -49
- data/ruby/trema/shell/run.rb +0 -67
- data/ruby/trema/shell/send_packets.rb +0 -40
- data/ruby/trema/shell/show_stats.rb +0 -47
- data/ruby/trema/shell/up.rb +0 -41
- data/ruby/trema/shell/vhost.rb +0 -42
- data/ruby/trema/shell/vswitch.rb +0 -47
- data/ruby/trema/stats-helper.rb +0 -63
- data/ruby/trema/stats-reply.c +0 -540
- data/ruby/trema/stats-reply.h +0 -51
- data/ruby/trema/stats-request.c +0 -715
- data/ruby/trema/stats-request.h +0 -40
- data/ruby/trema/strip-vlan-header.rb +0 -41
- data/ruby/trema/switch-daemon.rb +0 -90
- data/ruby/trema/switch-disconnected.c +0 -38
- data/ruby/trema/switch-disconnected.h +0 -36
- data/ruby/trema/switch-event.c +0 -648
- data/ruby/trema/switch-event.h +0 -27
- data/ruby/trema/switch-manager.rb +0 -119
- data/ruby/trema/switch.c +0 -197
- data/ruby/trema/switch.h +0 -40
- data/ruby/trema/switch.rb +0 -56
- data/ruby/trema/table-stats-reply.rb +0 -85
- data/ruby/trema/timers.rb +0 -95
- data/ruby/trema/trema-ruby-utils.c +0 -66
- data/ruby/trema/trema-ruby-utils.h +0 -42
- data/ruby/trema/trema.c +0 -126
- data/ruby/trema/tremashark.rb +0 -46
- data/ruby/trema/util.rb +0 -116
- data/ruby/trema/vendor-action.rb +0 -82
- data/ruby/trema/vendor-stats-reply.rb +0 -64
- data/ruby/trema/vendor.c +0 -230
- data/ruby/trema/vendor.h +0 -48
- data/ruby/trema/version.rb +0 -28
- data/spec/support/action.rb +0 -49
- data/spec/support/mandatory-option.rb +0 -53
- data/spec/support/matchers/constant.rb +0 -25
- data/spec/support/openflow-message.rb +0 -173
- data/spec/support/port-status.rb +0 -35
- data/spec/trema/app_spec.rb +0 -88
- data/spec/trema/barrier-reply_spec.rb +0 -43
- data/spec/trema/barrier-request_spec.rb +0 -92
- data/spec/trema/cli_spec.rb +0 -156
- data/spec/trema/default-logger_spec.rb +0 -46
- data/spec/trema/dsl/configuration_spec.rb +0 -120
- data/spec/trema/dsl/link_spec.rb +0 -50
- data/spec/trema/dsl/run_spec.rb +0 -72
- data/spec/trema/dsl/runner_spec.rb +0 -247
- data/spec/trema/dsl/switch_spec.rb +0 -69
- data/spec/trema/dsl/syntax_spec.rb +0 -110
- data/spec/trema/dsl/vhost_spec.rb +0 -144
- data/spec/trema/dsl/vswitch_spec.rb +0 -80
- data/spec/trema/echo-reply_spec.rb +0 -84
- data/spec/trema/echo-request_spec.rb +0 -128
- data/spec/trema/enqueue_spec.rb +0 -76
- data/spec/trema/error_spec.rb +0 -81
- data/spec/trema/executables_spec.rb +0 -54
- data/spec/trema/features-reply_spec.rb +0 -91
- data/spec/trema/features-request_spec.rb +0 -93
- data/spec/trema/flow-mod_spec.rb +0 -99
- data/spec/trema/flow-removed_spec.rb +0 -144
- data/spec/trema/get-config-reply_spec.rb +0 -43
- data/spec/trema/get-config-request_spec.rb +0 -92
- data/spec/trema/hardware-switch_spec.rb +0 -54
- data/spec/trema/hello_spec.rb +0 -63
- data/spec/trema/host_spec.rb +0 -191
- data/spec/trema/link_spec.rb +0 -62
- data/spec/trema/list-switches-reply_spec.rb +0 -46
- data/spec/trema/match_spec.rb +0 -111
- data/spec/trema/open-vswitch_spec.rb +0 -121
- data/spec/trema/openflow-error_spec.rb +0 -141
- data/spec/trema/packet-in_spec.rb +0 -717
- data/spec/trema/packet-out_spec.rb +0 -125
- data/spec/trema/packetin-filter_spec.rb +0 -39
- data/spec/trema/port-mod_spec.rb +0 -98
- data/spec/trema/port-status-add_spec.rb +0 -32
- data/spec/trema/port-status-delete_spec.rb +0 -32
- data/spec/trema/port-status-modify_spec.rb +0 -71
- data/spec/trema/port-status_spec.rb +0 -38
- data/spec/trema/port_spec.rb +0 -59
- data/spec/trema/process_spec.rb +0 -69
- data/spec/trema/queue-get-config-reply_spec.rb +0 -65
- data/spec/trema/queue-get-config-request_spec.rb +0 -67
- data/spec/trema/send-out-port_spec.rb +0 -106
- data/spec/trema/set-config_spec.rb +0 -78
- data/spec/trema/set-eth-addr_spec.rb +0 -62
- data/spec/trema/set-ip-addr_spec.rb +0 -81
- data/spec/trema/set-ip-tos_spec.rb +0 -70
- data/spec/trema/set-transport-dst-port_spec.rb +0 -65
- data/spec/trema/set-transport-src-port_spec.rb +0 -65
- data/spec/trema/set-vlan-priority_spec.rb +0 -65
- data/spec/trema/set-vlan-vid_spec.rb +0 -65
- data/spec/trema/shell/vhost_spec.rb +0 -58
- data/spec/trema/shell/vswitch_spec.rb +0 -87
- data/spec/trema/stats-reply_spec.rb +0 -363
- data/spec/trema/stats-request_spec.rb +0 -166
- data/spec/trema/strip-vlan-header_spec.rb +0 -44
- data/spec/trema/switch-daemon_spec.rb +0 -81
- data/spec/trema/switch-disconnected_spec.rb +0 -56
- data/spec/trema/switch-manager_spec.rb +0 -41
- data/spec/trema/tremashark_spec.rb +0 -39
- data/spec/trema/util_spec.rb +0 -88
- data/spec/trema/vendor-action_spec.rb +0 -75
- data/spec/trema/vendor_spec.rb +0 -76
- data/spec/trema_spec.rb +0 -94
- data/src/examples/cbench_switch/README +0 -21
- data/src/examples/cbench_switch/cbench-switch.rb +0 -38
- data/src/examples/cbench_switch/cbench_switch.c +0 -66
- data/src/examples/dumper/dumper.c +0 -362
- data/src/examples/dumper/dumper.conf +0 -7
- data/src/examples/dumper/dumper.rb +0 -195
- data/src/examples/hello_trema/.gitignore +0 -2
- data/src/examples/hello_trema/README.md +0 -2
- data/src/examples/hello_trema/hello-trema.rb +0 -30
- data/src/examples/hello_trema/hello_trema.c +0 -48
- data/src/examples/hello_trema/sample.conf +0 -1
- data/src/examples/learning_switch/README +0 -15
- data/src/examples/learning_switch/fdb.rb +0 -110
- data/src/examples/learning_switch/learning-switch.rb +0 -90
- data/src/examples/learning_switch/learning_switch.c +0 -217
- data/src/examples/learning_switch/learning_switch.conf +0 -18
- data/src/examples/list_switches/README +0 -19
- data/src/examples/list_switches/list-switches.rb +0 -43
- data/src/examples/list_switches/list_switches.c +0 -79
- data/src/examples/list_switches/list_switches.conf +0 -15
- data/src/examples/match_compare/match-compare.conf +0 -30
- data/src/examples/match_compare/match-compare.rb +0 -97
- data/src/examples/multi_learning_switch/README +0 -14
- data/src/examples/multi_learning_switch/multi-learning-switch.rb +0 -94
- data/src/examples/multi_learning_switch/multi_learning_switch.c +0 -294
- data/src/examples/multi_learning_switch/multi_learning_switch.conf +0 -17
- data/src/examples/openflow_message/README +0 -11
- data/src/examples/openflow_message/echo.c +0 -80
- data/src/examples/openflow_message/echo.rb +0 -56
- data/src/examples/openflow_message/example.rb +0 -60
- data/src/examples/openflow_message/features-request.rb +0 -96
- data/src/examples/openflow_message/features_request.c +0 -167
- data/src/examples/openflow_message/hello.c +0 -68
- data/src/examples/openflow_message/hello.rb +0 -43
- data/src/examples/openflow_message/set-config.rb +0 -57
- data/src/examples/openflow_message/set_config.c +0 -68
- data/src/examples/openflow_message/vendor-action.rb +0 -43
- data/src/examples/openflow_message/vendor-stats-request.rb +0 -66
- data/src/examples/openflow_message/vendor_action.c +0 -103
- data/src/examples/openflow_switch/echo_switch.c +0 -89
- data/src/examples/openflow_switch/hello_switch.c +0 -85
- data/src/examples/packet_in/README +0 -15
- data/src/examples/packet_in/packet-in.rb +0 -37
- data/src/examples/packet_in/packet_in.c +0 -53
- data/src/examples/packet_in/packet_in.conf +0 -15
- data/src/examples/packetin_filter_config/README +0 -12
- data/src/examples/packetin_filter_config/add_filter.c +0 -71
- data/src/examples/packetin_filter_config/delete_filter.c +0 -63
- data/src/examples/packetin_filter_config/delete_filter_strict.c +0 -73
- data/src/examples/packetin_filter_config/dump_filter.c +0 -63
- data/src/examples/packetin_filter_config/dump_filter_strict.c +0 -73
- data/src/examples/packetin_filter_config/packetin_filter_config.c +0 -132
- data/src/examples/packetin_filter_config/packetin_filter_config.conf +0 -7
- data/src/examples/packetin_filter_config/utils.c +0 -100
- data/src/examples/packetin_filter_config/utils.h +0 -40
- data/src/examples/patch_panel/network.conf +0 -14
- data/src/examples/patch_panel/patch-panel.conf +0 -1
- data/src/examples/patch_panel/patch-panel.rb +0 -59
- data/src/examples/repeater_hub/README +0 -8
- data/src/examples/repeater_hub/repeater-hub.rb +0 -41
- data/src/examples/repeater_hub/repeater-hub_spec.rb +0 -154
- data/src/examples/repeater_hub/repeater_hub.c +0 -81
- data/src/examples/repeater_hub/repeater_hub.conf +0 -28
- data/src/examples/simple_router/README +0 -18
- data/src/examples/simple_router/arp-table.rb +0 -81
- data/src/examples/simple_router/interface.rb +0 -90
- data/src/examples/simple_router/routing-table.rb +0 -60
- data/src/examples/simple_router/simple-router.rb +0 -191
- data/src/examples/simple_router/simple_router.conf +0 -24
- data/src/examples/simple_router/simple_router_netns.conf +0 -15
- data/src/examples/simple_router/simple_router_network.conf +0 -6
- data/src/examples/switch_event_config/.gitignore +0 -6
- data/src/examples/switch_event_config/add_forward_entry.c +0 -227
- data/src/examples/switch_event_config/delete_forward_entry.c +0 -226
- data/src/examples/switch_event_config/dump_forward_entries.c +0 -190
- data/src/examples/switch_event_config/network.conf +0 -2
- data/src/examples/switch_event_config/set_forward_entries.c +0 -210
- data/src/examples/switch_info/README +0 -13
- data/src/examples/switch_info/switch-info.rb +0 -44
- data/src/examples/switch_info/switch_info.c +0 -78
- data/src/examples/switch_info/switch_info.conf +0 -3
- data/src/examples/switch_monitor/switch-monitor.conf +0 -3
- data/src/examples/switch_monitor/switch-monitor.rb +0 -56
- data/src/examples/switch_monitor/switch_monitor.c +0 -152
- data/src/examples/traffic_monitor/counter.c +0 -72
- data/src/examples/traffic_monitor/counter.h +0 -46
- data/src/examples/traffic_monitor/counter.rb +0 -44
- data/src/examples/traffic_monitor/fdb.c +0 -74
- data/src/examples/traffic_monitor/fdb.h +0 -48
- data/src/examples/traffic_monitor/fdb.rb +0 -42
- data/src/examples/traffic_monitor/traffic-monitor.rb +0 -98
- data/src/examples/traffic_monitor/traffic_monitor.c +0 -161
- data/src/examples/traffic_monitor/traffic_monitor.conf +0 -16
- data/src/examples/transparent_firewall/README.md +0 -61
- data/src/examples/transparent_firewall/aggregated-delegated-afrinic.txt +0 -713
- data/src/examples/transparent_firewall/aggregated-delegated-apnic.txt +0 -3440
- data/src/examples/transparent_firewall/aggregated-delegated-arin.txt +0 -11342
- data/src/examples/transparent_firewall/aggregated-delegated-lacnic.txt +0 -1937
- data/src/examples/transparent_firewall/aggregated-delegated-ripencc.txt +0 -7329
- data/src/examples/transparent_firewall/block-rfc1918.rb +0 -86
- data/src/examples/transparent_firewall/pass-delegated.rb +0 -178
- data/src/examples/transparent_firewall/regen_aggregated.sh +0 -53
- data/src/examples/transparent_firewall/stats-to-cidrs.rb +0 -59
- data/src/lib/arp.h +0 -64
- data/src/lib/bool.h +0 -47
- data/src/lib/buffer.c +0 -304
- data/src/lib/buffer.h +0 -54
- data/src/lib/byteorder.c +0 -571
- data/src/lib/byteorder.h +0 -108
- data/src/lib/checks.h +0 -40
- data/src/lib/chibach.c +0 -392
- data/src/lib/chibach.h +0 -69
- data/src/lib/chibach_private.c +0 -168
- data/src/lib/chibach_private.h +0 -50
- data/src/lib/daemon.c +0 -429
- data/src/lib/daemon.h +0 -40
- data/src/lib/doubly_linked_list.c +0 -284
- data/src/lib/doubly_linked_list.h +0 -86
- data/src/lib/ether.c +0 -47
- data/src/lib/ether.h +0 -92
- data/src/lib/etherip.h +0 -44
- data/src/lib/event_forward_interface.c +0 -788
- data/src/lib/event_forward_interface.h +0 -138
- data/src/lib/event_handler.c +0 -419
- data/src/lib/event_handler.h +0 -57
- data/src/lib/external_callback.c +0 -126
- data/src/lib/external_callback.h +0 -46
- data/src/lib/hash_table.c +0 -415
- data/src/lib/hash_table.h +0 -136
- data/src/lib/icmp.h +0 -72
- data/src/lib/igmp.h +0 -48
- data/src/lib/ipv4.h +0 -64
- data/src/lib/ipv6.h +0 -46
- data/src/lib/linked_list.c +0 -244
- data/src/lib/linked_list.h +0 -84
- data/src/lib/log.c +0 -636
- data/src/lib/log.h +0 -77
- data/src/lib/management_interface.c +0 -359
- data/src/lib/management_interface.h +0 -40
- data/src/lib/management_service_interface.c +0 -102
- data/src/lib/management_service_interface.h +0 -134
- data/src/lib/match.h +0 -82
- data/src/lib/match_table.c +0 -606
- data/src/lib/match_table.h +0 -49
- data/src/lib/message_queue.c +0 -143
- data/src/lib/message_queue.h +0 -59
- data/src/lib/messenger.c +0 -1821
- data/src/lib/messenger.h +0 -145
- data/src/lib/openflow_application_interface.c +0 -1800
- data/src/lib/openflow_application_interface.h +0 -359
- data/src/lib/openflow_message.c +0 -4240
- data/src/lib/openflow_message.h +0 -291
- data/src/lib/openflow_service_interface.h +0 -58
- data/src/lib/openflow_switch_interface.c +0 -1378
- data/src/lib/openflow_switch_interface.h +0 -262
- data/src/lib/packet_info.c +0 -336
- data/src/lib/packet_info.h +0 -233
- data/src/lib/packet_parser.c +0 -522
- data/src/lib/packetin_filter_interface.c +0 -292
- data/src/lib/packetin_filter_interface.h +0 -125
- data/src/lib/persistent_storage.c +0 -478
- data/src/lib/persistent_storage.h +0 -44
- data/src/lib/secure_channel.c +0 -496
- data/src/lib/secure_channel.h +0 -43
- data/src/lib/stat.c +0 -248
- data/src/lib/stat.h +0 -51
- data/src/lib/tcp.h +0 -62
- data/src/lib/timer.c +0 -349
- data/src/lib/timer.h +0 -51
- data/src/lib/trema.c +0 -776
- data/src/lib/trema.h +0 -80
- data/src/lib/trema.hpp +0 -49
- data/src/lib/trema_private.c +0 -175
- data/src/lib/trema_private.h +0 -64
- data/src/lib/trema_wrapper.c +0 -59
- data/src/lib/trema_wrapper.h +0 -66
- data/src/lib/udp.h +0 -41
- data/src/lib/utility.c +0 -625
- data/src/lib/utility.h +0 -84
- data/src/lib/wrapper.c +0 -121
- data/src/lib/wrapper.h +0 -76
- data/src/management/application.c +0 -222
- data/src/management/echo.c +0 -183
- data/src/management/set_logging_level.c +0 -151
- data/src/management/show_stats.c +0 -148
- data/src/management/trema_manager +0 -184
- data/src/packetin_filter/README +0 -17
- data/src/packetin_filter/packetin_filter.c +0 -575
- data/src/switch_manager/README +0 -20
- data/src/switch_manager/cookie_table.c +0 -290
- data/src/switch_manager/cookie_table.h +0 -70
- data/src/switch_manager/dpid_table.c +0 -108
- data/src/switch_manager/dpid_table.h +0 -43
- data/src/switch_manager/event_forward_entry_manipulation.c +0 -120
- data/src/switch_manager/event_forward_entry_manipulation.h +0 -31
- data/src/switch_manager/ofpmsg_recv.c +0 -497
- data/src/switch_manager/ofpmsg_recv.h +0 -39
- data/src/switch_manager/ofpmsg_send.c +0 -274
- data/src/switch_manager/ofpmsg_send.h +0 -51
- data/src/switch_manager/secure_channel_listener.c +0 -296
- data/src/switch_manager/secure_channel_listener.h +0 -40
- data/src/switch_manager/secure_channel_receiver.c +0 -129
- data/src/switch_manager/secure_channel_receiver.h +0 -40
- data/src/switch_manager/secure_channel_sender.c +0 -131
- data/src/switch_manager/secure_channel_sender.h +0 -41
- data/src/switch_manager/service_interface.c +0 -180
- data/src/switch_manager/service_interface.h +0 -44
- data/src/switch_manager/switch.c +0 -988
- data/src/switch_manager/switch.h +0 -50
- data/src/switch_manager/switch_manager.c +0 -643
- data/src/switch_manager/switch_manager.h +0 -65
- data/src/switch_manager/switch_option.c +0 -30
- data/src/switch_manager/switch_option.h +0 -41
- data/src/switch_manager/switchinfo.h +0 -81
- data/src/switch_manager/xid_table.c +0 -182
- data/src/switch_manager/xid_table.h +0 -53
- data/src/tremashark/README +0 -79
- data/src/tremashark/packet_capture.c +0 -358
- data/src/tremashark/pcap_private.h +0 -45
- data/src/tremashark/pcap_queue.c +0 -195
- data/src/tremashark/pcap_queue.h +0 -56
- data/src/tremashark/plugin/.gitignore +0 -6
- data/src/tremashark/plugin/packet-trema/.gitignore +0 -5
- data/src/tremashark/plugin/packet-trema/Makefile +0 -77
- data/src/tremashark/plugin/packet-trema/Makefile.am +0 -110
- data/src/tremashark/plugin/packet-trema/Makefile.common +0 -29
- data/src/tremashark/plugin/packet-trema/moduleinfo.h +0 -39
- data/src/tremashark/plugin/packet-trema/packet-trema.c +0 -1671
- data/src/tremashark/plugin/packet-trema/plugin.c +0 -31
- data/src/tremashark/plugin/user_dlts +0 -2
- data/src/tremashark/queue.c +0 -167
- data/src/tremashark/queue.h +0 -58
- data/src/tremashark/stdin_relay.c +0 -257
- data/src/tremashark/syslog_relay.c +0 -247
- data/src/tremashark/tremashark.c +0 -554
- data/trema +0 -11
- data/trema-config +0 -11
- data/unittests/buffer_stubs.c +0 -72
- data/unittests/cmockery_trema.c +0 -121
- data/unittests/cmockery_trema.h +0 -95
- data/unittests/lib/buffer_test.c +0 -368
- data/unittests/lib/byteorder_test.c +0 -1798
- data/unittests/lib/daemon_test.c +0 -804
- data/unittests/lib/doubly_linked_list_test.c +0 -348
- data/unittests/lib/ether_test.c +0 -125
- data/unittests/lib/event_forward_interface_test.c +0 -1676
- data/unittests/lib/external_callback_test.c +0 -282
- data/unittests/lib/hash_table_test.c +0 -278
- data/unittests/lib/linked_list_test.c +0 -434
- data/unittests/lib/log_test.c +0 -672
- data/unittests/lib/management_interface_test.c +0 -238
- data/unittests/lib/management_service_interface_test.c +0 -317
- data/unittests/lib/match_table_test.c +0 -1507
- data/unittests/lib/message_queue_test.c +0 -381
- data/unittests/lib/messenger_test.c +0 -623
- data/unittests/lib/openflow_application_interface_test.c +0 -3713
- data/unittests/lib/openflow_message_test.c +0 -8047
- data/unittests/lib/packet_info_test.c +0 -558
- data/unittests/lib/packet_parser_test.c +0 -784
- data/unittests/lib/packetin_filter_interface_test.c +0 -721
- data/unittests/lib/persistent_storage_test.c +0 -800
- data/unittests/lib/stat_test.c +0 -433
- data/unittests/lib/test_packets/arp_rep.cap +0 -0
- data/unittests/lib/test_packets/arp_req.cap +0 -0
- data/unittests/lib/test_packets/icmp6_echo_rep.cap +0 -0
- data/unittests/lib/test_packets/icmp6_echo_req.cap +0 -0
- data/unittests/lib/test_packets/icmp_echo_rep.cap +0 -0
- data/unittests/lib/test_packets/icmp_echo_req.cap +0 -0
- data/unittests/lib/test_packets/igmp_query_v2.cap +0 -0
- data/unittests/lib/test_packets/ipx.cap +0 -0
- data/unittests/lib/test_packets/lldp.cap +0 -0
- data/unittests/lib/test_packets/lldp_over_ip.cap +0 -0
- data/unittests/lib/test_packets/rarp_req.cap +0 -0
- data/unittests/lib/test_packets/tcp.cap +0 -0
- data/unittests/lib/test_packets/tcp_syn.cap +0 -0
- data/unittests/lib/test_packets/udp.cap +0 -0
- data/unittests/lib/test_packets/udp_frag_head.cap +0 -0
- data/unittests/lib/test_packets/udp_frag_next.cap +0 -0
- data/unittests/lib/test_packets/vtag_icmp_echo_rep.cap +0 -0
- data/unittests/lib/test_packets/vtag_icmp_echo_req.cap +0 -0
- data/unittests/lib/timer_test.c +0 -246
- data/unittests/lib/trema_private_test.c +0 -321
- data/unittests/lib/trema_test.c +0 -1030
- data/unittests/lib/utility_test.c +0 -711
- data/unittests/lib/wrapper_test.c +0 -228
- data/unittests/packetin_filter/packetin_filter_test.c +0 -476
- data/unittests/switch_manager/switch_manager_test.c +0 -1183
- data/unittests/wrapper_stubs.c +0 -37
- data/vendor/.gitignore +0 -6
- data/vendor/README.md +0 -29
- data/vendor/cmockery-20110428.tar.gz +0 -0
- data/vendor/oflops-0.03.trema1.tar.gz +0 -0
- data/vendor/oflops_no_snmp+1.0.0.diff +0 -340
- data/vendor/openflow-1.0.0.tar.gz +0 -0
- data/vendor/openflow.git.tar.gz +0 -0
- data/vendor/openvswitch-1.2.2.trema1.tar.gz +0 -0
- data/vendor/openvswitch-1.2.2_librt-check.diff +0 -21
- data/vendor/packet-openflow.diff +0 -13
- data/vendor/ruby-ifconfig-1.2/COPYING +0 -340
- data/vendor/ruby-ifconfig-1.2/Changelog +0 -16
- data/vendor/ruby-ifconfig-1.2/INSTALL +0 -239
- data/vendor/ruby-ifconfig-1.2/README +0 -38
- data/vendor/ruby-ifconfig-1.2/Rakefile +0 -14
- data/vendor/ruby-ifconfig-1.2/TODO +0 -8
- data/vendor/ruby-ifconfig-1.2/ifconfig_examples/darwin.txt +0 -17
- data/vendor/ruby-ifconfig-1.2/ifconfig_examples/dragonflybsd.txt +0 -10
- data/vendor/ruby-ifconfig-1.2/ifconfig_examples/dragonflybsd_netstat.txt +0 -14
- data/vendor/ruby-ifconfig-1.2/ifconfig_examples/freebsd.txt +0 -17
- data/vendor/ruby-ifconfig-1.2/ifconfig_examples/freebsd_netstat.txt +0 -24
- data/vendor/ruby-ifconfig-1.2/ifconfig_examples/linux.txt +0 -60
- data/vendor/ruby-ifconfig-1.2/ifconfig_examples/linux_ethernet.txt +0 -20
- data/vendor/ruby-ifconfig-1.2/ifconfig_examples/netbsd.txt +0 -10
- data/vendor/ruby-ifconfig-1.2/ifconfig_examples/openbsd.txt +0 -36
- data/vendor/ruby-ifconfig-1.2/ifconfig_examples/sunos.txt +0 -10
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig.rb +0 -71
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/bsd/ifconfig.rb +0 -72
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/bsd/interface_types.rb +0 -69
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/bsd/network_types.rb +0 -3
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/common/ifconfig.rb +0 -84
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/common/interface_types.rb +0 -130
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/common/network_types.rb +0 -49
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/linux/ifconfig.rb +0 -43
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/linux/interface_types.rb +0 -112
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/linux/network_types.rb +0 -55
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/sunos/ifconfig.rb +0 -38
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/sunos/interface_types.rb +0 -77
- data/vendor/ruby-ifconfig-1.2/lib/ifconfig/sunos/network_types.rb +0 -4
- data/vendor/ruby-ifconfig-1.2/setup.rb +0 -1306
- data/vendor/ruby-ifconfig-1.2/test/test_bsd.rb +0 -35
- data/vendor/ruby-ifconfig-1.2/test/test_darwin.rb +0 -33
- data/vendor/ruby-ifconfig-1.2/test/test_dragonflybsd.rb +0 -35
- data/vendor/ruby-ifconfig-1.2/test/test_helper.rb +0 -4
- data/vendor/ruby-ifconfig-1.2/test/test_linux.rb +0 -31
- data/vendor/ruby-ifconfig-1.2/test/test_netbsd.rb +0 -33
- data/vendor/ruby-ifconfig-1.2/test/test_openbsd.rb +0 -33
- data/vendor/ruby-ifconfig-1.2/test/test_sunos.rb +0 -35
- data/vendor/ruby-ifconfig-1.2/test/unit/tc_darwin.rb +0 -40
- data/vendor/ruby-ifconfig-1.2/test/unit/tc_dragonflybsd.rb +0 -39
- data/vendor/ruby-ifconfig-1.2/test/unit/tc_freebsd.rb +0 -40
- data/vendor/ruby-ifconfig-1.2/test/unit/tc_linux.rb +0 -49
- data/vendor/ruby-ifconfig-1.2/test/unit/tc_netbsd.rb +0 -39
- data/vendor/ruby-ifconfig-1.2/test/unit/tc_openbsd.rb +0 -39
- data/vendor/ruby-ifconfig-1.2/test/unit/tc_sunos.rb +0 -44
data/src/lib/messenger.h
DELETED
@@ -1,145 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Trema messenger library.
|
3
|
-
*
|
4
|
-
* Copyright (C) 2008-2013 NEC Corporation
|
5
|
-
*
|
6
|
-
* This program is free software; you can redistribute it and/or modify
|
7
|
-
* it under the terms of the GNU General Public License, version 2, as
|
8
|
-
* published by the Free Software Foundation.
|
9
|
-
*
|
10
|
-
* This program is distributed in the hope that it will be useful,
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
-
* GNU General Public License for more details.
|
14
|
-
*
|
15
|
-
* You should have received a copy of the GNU General Public License along
|
16
|
-
* with this program; if not, write to the Free Software Foundation, Inc.,
|
17
|
-
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
18
|
-
*/
|
19
|
-
|
20
|
-
|
21
|
-
#ifndef MESSENGER_H
|
22
|
-
#define MESSENGER_H
|
23
|
-
|
24
|
-
|
25
|
-
#include <net/if.h>
|
26
|
-
#include <stdint.h>
|
27
|
-
#include <stdlib.h>
|
28
|
-
#include <time.h>
|
29
|
-
#include "checks.h"
|
30
|
-
#include "bool.h"
|
31
|
-
|
32
|
-
|
33
|
-
#define MESSENGER_SERVICE_NAME_LENGTH 32
|
34
|
-
|
35
|
-
|
36
|
-
typedef struct message_header {
|
37
|
-
uint8_t version; // version = 0 (unused)
|
38
|
-
uint8_t message_type; // MESSAGE_TYPE_
|
39
|
-
uint16_t tag; // user defined
|
40
|
-
uint32_t message_length; // message length including header
|
41
|
-
uint8_t value[ 0 ];
|
42
|
-
} message_header;
|
43
|
-
|
44
|
-
typedef struct messenger_context_handle {
|
45
|
-
uint32_t transaction_id;
|
46
|
-
uint16_t service_name_len;
|
47
|
-
uint16_t pad;
|
48
|
-
char service_name[ 0 ];
|
49
|
-
} messenger_context_handle;
|
50
|
-
|
51
|
-
/* message dump format:
|
52
|
-
* +-------------------+--------+------------+----+
|
53
|
-
* |message_dump_header|app_name|service_name|data|
|
54
|
-
* +-------------------+--------+------------+----+
|
55
|
-
*/
|
56
|
-
typedef struct message_dump_header {
|
57
|
-
struct { // same as struct timespec but fixed length
|
58
|
-
uint32_t sec;
|
59
|
-
uint32_t nsec;
|
60
|
-
} sent_time;
|
61
|
-
uint16_t app_name_length;
|
62
|
-
uint16_t service_name_length;
|
63
|
-
uint32_t data_length;
|
64
|
-
} message_dump_header;
|
65
|
-
|
66
|
-
enum {
|
67
|
-
MESSENGER_DUMP_SENT,
|
68
|
-
MESSENGER_DUMP_RECEIVED,
|
69
|
-
MESSENGER_DUMP_RECV_CONNECTED,
|
70
|
-
MESSENGER_DUMP_RECV_OVERFLOW,
|
71
|
-
MESSENGER_DUMP_RECV_CLOSED,
|
72
|
-
MESSENGER_DUMP_SEND_CONNECTED,
|
73
|
-
MESSENGER_DUMP_SEND_REFUSED,
|
74
|
-
MESSENGER_DUMP_SEND_OVERFLOW,
|
75
|
-
MESSENGER_DUMP_SEND_CLOSED,
|
76
|
-
MESSENGER_DUMP_LOGGER,
|
77
|
-
MESSENGER_DUMP_PCAP,
|
78
|
-
MESSENGER_DUMP_SYSLOG,
|
79
|
-
MESSENGER_DUMP_TEXT,
|
80
|
-
};
|
81
|
-
|
82
|
-
typedef struct pcap_dump_header {
|
83
|
-
uint32_t datalink;
|
84
|
-
uint8_t interface[ IF_NAMESIZE ];
|
85
|
-
} pcap_dump_header;
|
86
|
-
|
87
|
-
typedef struct logger_dump_header {
|
88
|
-
struct {
|
89
|
-
uint32_t sec;
|
90
|
-
uint32_t nsec;
|
91
|
-
} sent_time;
|
92
|
-
} logger_dump_header;
|
93
|
-
|
94
|
-
typedef struct syslog_dump_header {
|
95
|
-
struct {
|
96
|
-
uint32_t sec;
|
97
|
-
uint32_t nsec;
|
98
|
-
} sent_time;
|
99
|
-
} syslog_dump_header;
|
100
|
-
|
101
|
-
typedef struct text_dump_header {
|
102
|
-
struct {
|
103
|
-
uint32_t sec;
|
104
|
-
uint32_t nsec;
|
105
|
-
} sent_time;
|
106
|
-
} text_dump_header;
|
107
|
-
|
108
|
-
|
109
|
-
typedef void ( *callback_message_received )( uint16_t tag, void *data, size_t len );
|
110
|
-
|
111
|
-
|
112
|
-
extern bool ( *add_message_received_callback )( const char *service_name, const callback_message_received function );
|
113
|
-
extern bool ( *rename_message_received_callback )( const char *old_service_name, const char *new_service_name );
|
114
|
-
extern bool ( *delete_message_received_callback )( const char *service_name, void ( *callback )( uint16_t tag, void *data, size_t len ) );
|
115
|
-
extern bool ( *add_message_requested_callback )( const char *service_name, void ( *callback )( const messenger_context_handle *handle, uint16_t tag, void *data, size_t len ) );
|
116
|
-
extern bool ( *rename_message_requested_callback )( const char *old_service_name, const char *new_service_name );
|
117
|
-
extern bool ( *delete_message_requested_callback )( const char *service_name, void ( *callback )( const messenger_context_handle *handle, uint16_t tag, void *data, size_t len ) );
|
118
|
-
extern bool ( *add_message_replied_callback )( const char *service_name, void ( *callback )( uint16_t tag, void *data, size_t len, void *user_data ) );
|
119
|
-
extern bool ( *delete_message_replied_callback )( const char *service_name, void ( *callback )( uint16_t tag, void *data, size_t len, void *user_data ) );
|
120
|
-
extern bool ( *send_message )( const char *service_name, const uint16_t tag, const void *data, size_t len );
|
121
|
-
extern bool ( *send_request_message )( const char *to_service_name, const char *from_service_name, const uint16_t tag, const void *data, size_t len, void *user_data );
|
122
|
-
extern bool ( *send_reply_message )( const messenger_context_handle *handle, const uint16_t tag, const void *data, size_t len );
|
123
|
-
extern bool ( *clear_send_queue )( const char *service_name );
|
124
|
-
|
125
|
-
bool init_messenger( const char *working_directory );
|
126
|
-
bool finalize_messenger( void );
|
127
|
-
|
128
|
-
bool start_messenger( void );
|
129
|
-
int flush_messenger( void );
|
130
|
-
bool stop_messenger( void );
|
131
|
-
|
132
|
-
void start_messenger_dump( const char *dump_app_name, const char *dump_service_name );
|
133
|
-
void stop_messenger_dump( void );
|
134
|
-
bool messenger_dump_enabled( void );
|
135
|
-
|
136
|
-
|
137
|
-
#endif // MESSENGER_H
|
138
|
-
|
139
|
-
|
140
|
-
/*
|
141
|
-
* Local variables:
|
142
|
-
* c-basic-offset: 2
|
143
|
-
* indent-tabs-mode: nil
|
144
|
-
* End:
|
145
|
-
*/
|
@@ -1,1800 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright (C) 2008-2013 NEC Corporation
|
3
|
-
*
|
4
|
-
* This program is free software; you can redistribute it and/or modify
|
5
|
-
* it under the terms of the GNU General Public License, version 2, as
|
6
|
-
* published by the Free Software Foundation.
|
7
|
-
*
|
8
|
-
* This program is distributed in the hope that it will be useful,
|
9
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
-
* GNU General Public License for more details.
|
12
|
-
*
|
13
|
-
* You should have received a copy of the GNU General Public License along
|
14
|
-
* with this program; if not, write to the Free Software Foundation, Inc.,
|
15
|
-
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
16
|
-
*/
|
17
|
-
|
18
|
-
|
19
|
-
#include <assert.h>
|
20
|
-
#include <inttypes.h>
|
21
|
-
#include <stdio.h>
|
22
|
-
#include <string.h>
|
23
|
-
#include <unistd.h>
|
24
|
-
#include "trema.h"
|
25
|
-
#include "log.h"
|
26
|
-
#include "messenger.h"
|
27
|
-
#include "openflow_application_interface.h"
|
28
|
-
#include "openflow_message.h"
|
29
|
-
#include "packet_info.h"
|
30
|
-
#include "wrapper.h"
|
31
|
-
|
32
|
-
|
33
|
-
#ifdef UNIT_TESTING
|
34
|
-
|
35
|
-
#define static
|
36
|
-
|
37
|
-
#ifdef get_trema_name
|
38
|
-
#undef get_trema_name
|
39
|
-
#endif
|
40
|
-
#define get_trema_name mock_get_trema_name
|
41
|
-
const char *mock_get_trema_name( void );
|
42
|
-
|
43
|
-
#ifdef send_message
|
44
|
-
#undef send_message
|
45
|
-
#endif
|
46
|
-
#define send_message mock_send_message
|
47
|
-
bool mock_send_message( char *service_name, uint16_t tag, void *data, size_t len );
|
48
|
-
|
49
|
-
#ifdef send_request_message
|
50
|
-
#undef send_request_message
|
51
|
-
#endif
|
52
|
-
#define send_request_message mock_send_request_message
|
53
|
-
bool mock_send_request_message( const char *to_service_name, char *from_service_name, uint16_t tag,
|
54
|
-
void *data, size_t len, void *user_data );
|
55
|
-
|
56
|
-
#ifdef init_openflow_message
|
57
|
-
#undef init_openflow_message
|
58
|
-
#endif
|
59
|
-
#define init_openflow_message mock_init_openflow_message
|
60
|
-
bool mock_init_openflow_message( void );
|
61
|
-
|
62
|
-
#ifdef add_message_received_callback
|
63
|
-
#undef add_message_received_callback
|
64
|
-
#endif
|
65
|
-
#define add_message_received_callback mock_add_message_received_callback
|
66
|
-
bool mock_add_message_received_callback( char *service_name,
|
67
|
-
void ( *callback )( uint16_t tag, void *data, size_t len ) );
|
68
|
-
|
69
|
-
#ifdef add_message_replied_callback
|
70
|
-
#undef add_message_replied_callback
|
71
|
-
#endif
|
72
|
-
#define add_message_replied_callback mock_add_message_replied_callback
|
73
|
-
bool mock_add_message_replied_callback( char *service_name,
|
74
|
-
void ( *callback )( uint16_t tag, void *data, size_t len, void *yser_data ) );
|
75
|
-
|
76
|
-
#ifdef delete_message_received_callback
|
77
|
-
#undef delete_message_received_callback
|
78
|
-
#endif
|
79
|
-
#define delete_message_received_callback mock_delete_message_received_callback
|
80
|
-
bool mock_delete_message_received_callback( char *service_name,
|
81
|
-
void ( *callback )( uint16_t tag, void *data, size_t len ) );
|
82
|
-
|
83
|
-
#ifdef delete_message_replied_callback
|
84
|
-
#undef delete_message_replied_callback
|
85
|
-
#endif
|
86
|
-
#define delete_message_replied_callback mock_delete_message_replied_callback
|
87
|
-
bool mock_delete_message_replied_callback( char *service_name,
|
88
|
-
void ( *callback )( uint16_t tag, void *data, size_t len, void *user_data ) );
|
89
|
-
|
90
|
-
#ifdef clear_send_queue
|
91
|
-
#undef clear_send_queue
|
92
|
-
#endif
|
93
|
-
#define clear_send_queue mock_clear_send_queue
|
94
|
-
bool mock_clear_send_queue( const char *service_name );
|
95
|
-
|
96
|
-
#ifdef getpid
|
97
|
-
#undef getpid
|
98
|
-
#endif
|
99
|
-
#define getpid mock_getpid
|
100
|
-
pid_t mock_getpid( void );
|
101
|
-
|
102
|
-
#ifdef parse_packet
|
103
|
-
#undef parse_packet
|
104
|
-
#endif
|
105
|
-
#define parse_packet mock_parse_packet
|
106
|
-
bool mock_parse_packet( buffer *buf );
|
107
|
-
|
108
|
-
#ifdef die
|
109
|
-
#undef die
|
110
|
-
#endif
|
111
|
-
#define die mock_die
|
112
|
-
void mock_die( const char *format, ... );
|
113
|
-
|
114
|
-
#ifdef debug
|
115
|
-
#undef debug
|
116
|
-
#endif
|
117
|
-
#define debug mock_debug
|
118
|
-
extern void mock_debug( const char *format, ... );
|
119
|
-
|
120
|
-
#ifdef info
|
121
|
-
#undef info
|
122
|
-
#endif
|
123
|
-
#define info mock_info
|
124
|
-
extern void mock_info( const char *format, ... );
|
125
|
-
|
126
|
-
#ifdef warn
|
127
|
-
#undef warn
|
128
|
-
#endif
|
129
|
-
#define warn mock_warn
|
130
|
-
extern void mock_warn( const char *format, ... );
|
131
|
-
|
132
|
-
#ifdef error
|
133
|
-
#undef error
|
134
|
-
#endif
|
135
|
-
#define error mock_error
|
136
|
-
extern void mock_error( const char *format, ... );
|
137
|
-
|
138
|
-
#ifdef critical
|
139
|
-
#undef critical
|
140
|
-
#endif
|
141
|
-
#define critical mock_critical
|
142
|
-
extern void mock_critical( const char *format, ... );
|
143
|
-
|
144
|
-
#endif // UNIT_TESTING
|
145
|
-
|
146
|
-
static bool openflow_application_interface_initialized = false;
|
147
|
-
static openflow_event_handlers_t event_handlers;
|
148
|
-
static char service_name[ MESSENGER_SERVICE_NAME_LENGTH ];
|
149
|
-
|
150
|
-
|
151
|
-
static void handle_message( uint16_t message_type, void *data, size_t length );
|
152
|
-
static void handle_list_switches_reply( uint16_t message_type, void *dpid, size_t length, void *user_data );
|
153
|
-
|
154
|
-
|
155
|
-
enum {
|
156
|
-
OPENFLOW_MESSAGE_SEND = 0,
|
157
|
-
OPENFLOW_MESSAGE_RECEIVE,
|
158
|
-
};
|
159
|
-
|
160
|
-
|
161
|
-
bool
|
162
|
-
openflow_application_interface_is_initialized() {
|
163
|
-
return openflow_application_interface_initialized;
|
164
|
-
}
|
165
|
-
|
166
|
-
|
167
|
-
static bool
|
168
|
-
maybe_init_openflow_application_interface() {
|
169
|
-
if ( !openflow_application_interface_is_initialized() ) {
|
170
|
-
debug( "OpenFlow Application Interface is not initialized yet. Initializing..." );
|
171
|
-
return init_openflow_application_interface( get_trema_name() );
|
172
|
-
}
|
173
|
-
return true;
|
174
|
-
}
|
175
|
-
|
176
|
-
|
177
|
-
bool
|
178
|
-
init_openflow_application_interface( const char *custom_service_name ) {
|
179
|
-
assert( custom_service_name != NULL );
|
180
|
-
|
181
|
-
debug( "Initializing OpenFlow Application Interface." );
|
182
|
-
|
183
|
-
if ( openflow_application_interface_is_initialized() ) {
|
184
|
-
error( "OpenFlow Application Interface is already initialized." );
|
185
|
-
return false;
|
186
|
-
}
|
187
|
-
|
188
|
-
memset( &event_handlers, 0, sizeof( openflow_event_handlers_t ) );
|
189
|
-
memset( service_name, '\0', sizeof( service_name ) );
|
190
|
-
|
191
|
-
size_t length = strlen( custom_service_name ) + 1;
|
192
|
-
if ( length > MESSENGER_SERVICE_NAME_LENGTH ) {
|
193
|
-
error( "Too long custom service name ( %s ).", custom_service_name );
|
194
|
-
return false;
|
195
|
-
}
|
196
|
-
assert( length <= sizeof( service_name ) );
|
197
|
-
memcpy( service_name, custom_service_name, length );
|
198
|
-
|
199
|
-
init_openflow_message();
|
200
|
-
|
201
|
-
add_message_received_callback( service_name, handle_message );
|
202
|
-
add_message_replied_callback( service_name, handle_list_switches_reply );
|
203
|
-
|
204
|
-
openflow_application_interface_initialized = true;
|
205
|
-
|
206
|
-
return true;
|
207
|
-
}
|
208
|
-
|
209
|
-
|
210
|
-
bool
|
211
|
-
finalize_openflow_application_interface() {
|
212
|
-
debug( "Finalizing OpenFlow Application Interface." );
|
213
|
-
|
214
|
-
assert( openflow_application_interface_initialized );
|
215
|
-
|
216
|
-
delete_message_received_callback( service_name, handle_message );
|
217
|
-
delete_message_replied_callback( service_name, handle_list_switches_reply );
|
218
|
-
|
219
|
-
memset( &event_handlers, 0, sizeof( openflow_event_handlers_t ) );
|
220
|
-
memset( service_name, '\0', sizeof( service_name ) );
|
221
|
-
|
222
|
-
openflow_application_interface_initialized = false;
|
223
|
-
|
224
|
-
return true;
|
225
|
-
}
|
226
|
-
|
227
|
-
|
228
|
-
bool
|
229
|
-
set_openflow_event_handlers( const openflow_event_handlers_t handlers ) {
|
230
|
-
maybe_init_openflow_application_interface();
|
231
|
-
assert( openflow_application_interface_initialized );
|
232
|
-
|
233
|
-
memcpy( &event_handlers, &handlers, sizeof( event_handlers ) );
|
234
|
-
|
235
|
-
return true;
|
236
|
-
}
|
237
|
-
|
238
|
-
|
239
|
-
bool
|
240
|
-
_set_switch_ready_handler( bool simple_callback, void *callback, void *user_data ) {
|
241
|
-
if ( callback == NULL ) {
|
242
|
-
die( "Invalid callback function for switch_ready event." );
|
243
|
-
}
|
244
|
-
assert( callback != NULL );
|
245
|
-
|
246
|
-
maybe_init_openflow_application_interface();
|
247
|
-
assert( openflow_application_interface_initialized );
|
248
|
-
|
249
|
-
debug( "Setting a switch ready handler ( callback = %p, user_data = %p ).",
|
250
|
-
callback, user_data );
|
251
|
-
|
252
|
-
event_handlers.simple_switch_ready_callback = simple_callback;
|
253
|
-
event_handlers.switch_ready_callback = callback;
|
254
|
-
event_handlers.switch_ready_user_data = user_data;
|
255
|
-
|
256
|
-
return true;
|
257
|
-
}
|
258
|
-
|
259
|
-
|
260
|
-
bool
|
261
|
-
set_switch_disconnected_handler( switch_disconnected_handler callback, void *user_data ) {
|
262
|
-
if ( callback == NULL ) {
|
263
|
-
die( "Callback function ( switch_disconnected_handler ) must not be NULL." );
|
264
|
-
}
|
265
|
-
assert( callback != NULL );
|
266
|
-
|
267
|
-
maybe_init_openflow_application_interface();
|
268
|
-
assert( openflow_application_interface_initialized );
|
269
|
-
|
270
|
-
debug( "Setting a switch disconnected handler ( callback = %p, user_data = %p ).",
|
271
|
-
callback, user_data );
|
272
|
-
|
273
|
-
event_handlers.switch_disconnected_callback = callback;
|
274
|
-
event_handlers.switch_disconnected_user_data = user_data;
|
275
|
-
|
276
|
-
return true;
|
277
|
-
}
|
278
|
-
|
279
|
-
|
280
|
-
bool
|
281
|
-
set_error_handler( error_handler callback, void *user_data ) {
|
282
|
-
if ( callback == NULL ) {
|
283
|
-
die( "Callback function ( error_handler ) must not be NULL." );
|
284
|
-
}
|
285
|
-
assert( callback != NULL );
|
286
|
-
|
287
|
-
maybe_init_openflow_application_interface();
|
288
|
-
assert( openflow_application_interface_initialized );
|
289
|
-
|
290
|
-
debug( "Setting an error handler ( callback = %p, user_data = %p ).",
|
291
|
-
callback, user_data );
|
292
|
-
|
293
|
-
event_handlers.error_callback = callback;
|
294
|
-
event_handlers.error_user_data = user_data;
|
295
|
-
|
296
|
-
return true;
|
297
|
-
}
|
298
|
-
|
299
|
-
|
300
|
-
bool
|
301
|
-
set_echo_reply_handler( echo_reply_handler callback, void *user_data ) {
|
302
|
-
if ( callback == NULL ) {
|
303
|
-
die( "Callback function ( echo_reply_handler ) must not be NULL." );
|
304
|
-
}
|
305
|
-
assert( callback != NULL );
|
306
|
-
|
307
|
-
maybe_init_openflow_application_interface();
|
308
|
-
assert( openflow_application_interface_initialized );
|
309
|
-
|
310
|
-
debug( "Setting a echo reply handler ( callback = %p, user_data = %p ).",
|
311
|
-
callback, user_data );
|
312
|
-
|
313
|
-
event_handlers.echo_reply_callback = callback;
|
314
|
-
event_handlers.echo_reply_user_data = user_data;
|
315
|
-
|
316
|
-
return true;
|
317
|
-
}
|
318
|
-
|
319
|
-
|
320
|
-
bool
|
321
|
-
set_vendor_handler( vendor_handler callback, void *user_data ) {
|
322
|
-
if ( callback == NULL ) {
|
323
|
-
die( "Callback function ( vendor_handler ) must not be NULL." );
|
324
|
-
}
|
325
|
-
assert( callback != NULL );
|
326
|
-
|
327
|
-
maybe_init_openflow_application_interface();
|
328
|
-
assert( openflow_application_interface_initialized );
|
329
|
-
|
330
|
-
debug( "Setting a vendor handler ( callback = %p, user_data = %p ).",
|
331
|
-
callback, user_data );
|
332
|
-
|
333
|
-
event_handlers.vendor_callback = callback;
|
334
|
-
event_handlers.vendor_user_data = user_data;
|
335
|
-
|
336
|
-
return true;
|
337
|
-
}
|
338
|
-
|
339
|
-
|
340
|
-
bool
|
341
|
-
set_features_reply_handler( features_reply_handler callback, void *user_data ) {
|
342
|
-
if ( callback == NULL ) {
|
343
|
-
die( "Callback function ( features_reply_handler ) must not be NULL." );
|
344
|
-
}
|
345
|
-
assert( callback != NULL );
|
346
|
-
|
347
|
-
maybe_init_openflow_application_interface();
|
348
|
-
assert( openflow_application_interface_initialized );
|
349
|
-
|
350
|
-
debug( "Setting a features reply handler ( callback = %p, user_data = %p ).",
|
351
|
-
callback, user_data );
|
352
|
-
|
353
|
-
event_handlers.features_reply_callback = callback;
|
354
|
-
event_handlers.features_reply_user_data = user_data;
|
355
|
-
|
356
|
-
return true;
|
357
|
-
}
|
358
|
-
|
359
|
-
|
360
|
-
bool
|
361
|
-
set_get_config_reply_handler( get_config_reply_handler callback, void *user_data ) {
|
362
|
-
if ( callback == NULL ) {
|
363
|
-
die( "Callback function ( get_config_reply_handler ) must not be NULL." );
|
364
|
-
}
|
365
|
-
assert( callback != NULL );
|
366
|
-
|
367
|
-
maybe_init_openflow_application_interface();
|
368
|
-
assert( openflow_application_interface_initialized );
|
369
|
-
|
370
|
-
debug( "Setting a get config reply handler ( callback = %p, user_data = %p ).",
|
371
|
-
callback, user_data );
|
372
|
-
|
373
|
-
event_handlers.get_config_reply_callback = callback;
|
374
|
-
event_handlers.get_config_reply_user_data = user_data;
|
375
|
-
|
376
|
-
return true;
|
377
|
-
}
|
378
|
-
|
379
|
-
|
380
|
-
bool
|
381
|
-
_set_packet_in_handler( bool simple_callback, void *callback, void *user_data ) {
|
382
|
-
if ( callback == NULL ) {
|
383
|
-
die( "Callback function (packet_in_handler) must not be NULL." );
|
384
|
-
}
|
385
|
-
assert( callback != NULL );
|
386
|
-
|
387
|
-
maybe_init_openflow_application_interface();
|
388
|
-
assert( openflow_application_interface_initialized );
|
389
|
-
|
390
|
-
debug( "Setting a packet-in handler (callback = %p, user_data = %p).", callback, user_data );
|
391
|
-
|
392
|
-
event_handlers.simple_packet_in_callback = simple_callback;
|
393
|
-
event_handlers.packet_in_callback = callback;
|
394
|
-
event_handlers.packet_in_user_data = user_data;
|
395
|
-
|
396
|
-
return true;
|
397
|
-
}
|
398
|
-
|
399
|
-
|
400
|
-
bool
|
401
|
-
_set_flow_removed_handler( bool simple_callback, void *callback, void *user_data ) {
|
402
|
-
if ( callback == NULL ) {
|
403
|
-
die( "Callback function (flow_removed_handler) must not be NULL." );
|
404
|
-
}
|
405
|
-
assert( callback != NULL );
|
406
|
-
|
407
|
-
maybe_init_openflow_application_interface();
|
408
|
-
assert( openflow_application_interface_initialized );
|
409
|
-
|
410
|
-
debug( "Setting a flow removed handler (callback = %p, user_data = %p).", callback, user_data );
|
411
|
-
|
412
|
-
event_handlers.simple_flow_removed_callback = simple_callback;
|
413
|
-
event_handlers.flow_removed_callback = callback;
|
414
|
-
event_handlers.flow_removed_user_data = user_data;
|
415
|
-
|
416
|
-
return true;
|
417
|
-
}
|
418
|
-
|
419
|
-
|
420
|
-
bool
|
421
|
-
set_port_status_handler( port_status_handler callback, void *user_data ) {
|
422
|
-
if ( callback == NULL ) {
|
423
|
-
die( "Callback function ( port_status_handler ) must not be NULL." );
|
424
|
-
}
|
425
|
-
assert( callback != NULL );
|
426
|
-
|
427
|
-
maybe_init_openflow_application_interface();
|
428
|
-
assert( openflow_application_interface_initialized );
|
429
|
-
|
430
|
-
debug( "Setting a port status handler ( callback = %p, user_data = %p ).",
|
431
|
-
callback, user_data );
|
432
|
-
|
433
|
-
event_handlers.port_status_callback = callback;
|
434
|
-
event_handlers.port_status_user_data = user_data;
|
435
|
-
|
436
|
-
return true;
|
437
|
-
}
|
438
|
-
|
439
|
-
|
440
|
-
bool
|
441
|
-
set_stats_reply_handler( stats_reply_handler callback, void *user_data ) {
|
442
|
-
if ( callback == NULL ) {
|
443
|
-
die( "Callback function ( stats_reply_handler ) must not be NULL." );
|
444
|
-
}
|
445
|
-
assert( callback != NULL );
|
446
|
-
|
447
|
-
maybe_init_openflow_application_interface();
|
448
|
-
assert( openflow_application_interface_initialized );
|
449
|
-
|
450
|
-
debug( "Setting a stats reply handler ( callback = %p, user_data = %p ).",
|
451
|
-
callback, user_data );
|
452
|
-
|
453
|
-
event_handlers.stats_reply_callback = callback;
|
454
|
-
event_handlers.stats_reply_user_data = user_data;
|
455
|
-
|
456
|
-
return true;
|
457
|
-
}
|
458
|
-
|
459
|
-
|
460
|
-
bool
|
461
|
-
set_barrier_reply_handler( barrier_reply_handler callback, void *user_data ) {
|
462
|
-
if ( callback == NULL ) {
|
463
|
-
die( "Callback function ( barrier_reply_handler ) must not be NULL." );
|
464
|
-
}
|
465
|
-
assert( callback != NULL );
|
466
|
-
|
467
|
-
maybe_init_openflow_application_interface();
|
468
|
-
assert( openflow_application_interface_initialized );
|
469
|
-
|
470
|
-
debug( "Setting a barrier reply handler ( callback = %p, user_data = %p ).",
|
471
|
-
callback, user_data );
|
472
|
-
|
473
|
-
event_handlers.barrier_reply_callback = callback;
|
474
|
-
event_handlers.barrier_reply_user_data = user_data;
|
475
|
-
|
476
|
-
return true;
|
477
|
-
}
|
478
|
-
|
479
|
-
|
480
|
-
bool
|
481
|
-
set_queue_get_config_reply_handler( queue_get_config_reply_handler callback, void *user_data ) {
|
482
|
-
if ( callback == NULL ) {
|
483
|
-
die( "Callback function ( queue_get_config_reply_handler ) must not be NULL." );
|
484
|
-
}
|
485
|
-
assert( callback != NULL );
|
486
|
-
|
487
|
-
maybe_init_openflow_application_interface();
|
488
|
-
assert( openflow_application_interface_initialized );
|
489
|
-
|
490
|
-
debug( "Setting a queue get config reply handler ( callback = %p, user_data = %p ).",
|
491
|
-
callback, user_data );
|
492
|
-
|
493
|
-
event_handlers.queue_get_config_reply_callback = callback;
|
494
|
-
event_handlers.queue_get_config_reply_user_data = user_data;
|
495
|
-
|
496
|
-
return true;
|
497
|
-
}
|
498
|
-
|
499
|
-
|
500
|
-
bool
|
501
|
-
set_list_switches_reply_handler( list_switches_reply_handler callback ) {
|
502
|
-
if ( callback == NULL ) {
|
503
|
-
die( "Callback function ( list_switches_reply_handler ) must not be NULL." );
|
504
|
-
}
|
505
|
-
assert( callback != NULL );
|
506
|
-
|
507
|
-
maybe_init_openflow_application_interface();
|
508
|
-
assert( openflow_application_interface_initialized );
|
509
|
-
|
510
|
-
debug( "Setting a list switches reply handler ( callback = %p ).", callback );
|
511
|
-
|
512
|
-
event_handlers.list_switches_reply_callback = callback;
|
513
|
-
|
514
|
-
return true;
|
515
|
-
}
|
516
|
-
|
517
|
-
|
518
|
-
static void
|
519
|
-
handle_error( const uint64_t datapath_id, buffer *data ) {
|
520
|
-
uint16_t type, code;
|
521
|
-
uint32_t transaction_id;
|
522
|
-
buffer *body;
|
523
|
-
struct ofp_error_msg *error_msg;
|
524
|
-
|
525
|
-
if ( ( data == NULL ) || ( ( data != NULL ) && ( data->length == 0 ) ) ) {
|
526
|
-
critical( "An OpenFlow message must be filled before calling handle_error()." );
|
527
|
-
assert( 0 );
|
528
|
-
}
|
529
|
-
|
530
|
-
error_msg = ( struct ofp_error_msg * ) data->data;
|
531
|
-
|
532
|
-
transaction_id = ntohl( error_msg->header.xid );
|
533
|
-
type = ntohs( error_msg->type );
|
534
|
-
code = ntohs( error_msg->code );
|
535
|
-
|
536
|
-
body = duplicate_buffer( data );
|
537
|
-
remove_front_buffer( body, offsetof( struct ofp_error_msg, data ) );
|
538
|
-
|
539
|
-
debug( "An error message is received from %#" PRIx64 " "
|
540
|
-
"( transaction_id = %#x, type = %#x, code = %#x, data length = %zu ).",
|
541
|
-
datapath_id, transaction_id, type, code, body->length );
|
542
|
-
|
543
|
-
if ( event_handlers.error_callback == NULL ) {
|
544
|
-
debug( "Callback function for error events is not set." );
|
545
|
-
free_buffer( body );
|
546
|
-
return;
|
547
|
-
}
|
548
|
-
|
549
|
-
debug( "Calling error handler ( callback = %p, user_data = %p ).",
|
550
|
-
event_handlers.error_callback, event_handlers.error_user_data );
|
551
|
-
|
552
|
-
event_handlers.error_callback( datapath_id,
|
553
|
-
transaction_id,
|
554
|
-
type,
|
555
|
-
code,
|
556
|
-
body,
|
557
|
-
event_handlers.error_user_data );
|
558
|
-
|
559
|
-
free_buffer( body );
|
560
|
-
}
|
561
|
-
|
562
|
-
|
563
|
-
static void
|
564
|
-
handle_echo_reply( const uint64_t datapath_id, buffer *data ) {
|
565
|
-
uint16_t body_length;
|
566
|
-
uint32_t transaction_id;
|
567
|
-
buffer *body;
|
568
|
-
struct ofp_header *header;
|
569
|
-
|
570
|
-
if ( ( data == NULL ) || ( ( data != NULL ) && ( data->length == 0 ) ) ) {
|
571
|
-
critical( "An OpenFlow message must be filled before calling handle_echo_reply()." );
|
572
|
-
assert( 0 );
|
573
|
-
}
|
574
|
-
|
575
|
-
header = ( struct ofp_header * ) data->data;
|
576
|
-
|
577
|
-
transaction_id = ntohl( header->xid );
|
578
|
-
|
579
|
-
body_length = ( uint16_t ) ( ntohs( header->length )
|
580
|
-
- sizeof( struct ofp_header ) );
|
581
|
-
|
582
|
-
debug( "A echo reply message is received from %#" PRIx64
|
583
|
-
" ( transaction_id = %#x, body length = %u ).",
|
584
|
-
datapath_id, transaction_id, body_length );
|
585
|
-
|
586
|
-
if ( event_handlers.echo_reply_callback == NULL ) {
|
587
|
-
debug( "Callback function for echo reply events is not set." );
|
588
|
-
return;
|
589
|
-
}
|
590
|
-
|
591
|
-
if ( body_length > 0 ) {
|
592
|
-
body = duplicate_buffer( data );
|
593
|
-
remove_front_buffer( body, sizeof( struct ofp_header ) );
|
594
|
-
}
|
595
|
-
else {
|
596
|
-
body = NULL;
|
597
|
-
}
|
598
|
-
|
599
|
-
debug( "Calling echo reply handler ( callback = %p, user_data = %p ).",
|
600
|
-
event_handlers.echo_reply_callback, event_handlers.echo_reply_user_data );
|
601
|
-
|
602
|
-
event_handlers.echo_reply_callback( datapath_id,
|
603
|
-
transaction_id,
|
604
|
-
body,
|
605
|
-
event_handlers.echo_reply_user_data );
|
606
|
-
|
607
|
-
if ( body != NULL ) {
|
608
|
-
free_buffer( body );
|
609
|
-
}
|
610
|
-
}
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
static void
|
615
|
-
handle_vendor( const uint64_t datapath_id, buffer *data ) {
|
616
|
-
uint16_t body_length;
|
617
|
-
uint32_t vendor, transaction_id;
|
618
|
-
buffer *body;
|
619
|
-
struct ofp_vendor_header *vendor_header;
|
620
|
-
|
621
|
-
if ( ( data == NULL ) || ( ( data != NULL ) && ( data->length == 0 ) ) ) {
|
622
|
-
critical( "An OpenFlow message must be filled before calling handle_vendor()." );
|
623
|
-
assert( 0 );
|
624
|
-
}
|
625
|
-
|
626
|
-
vendor_header = ( struct ofp_vendor_header * ) data->data;
|
627
|
-
|
628
|
-
transaction_id = ntohl( vendor_header->header.xid );
|
629
|
-
vendor = ntohl( vendor_header->vendor );
|
630
|
-
|
631
|
-
body_length = ( uint16_t ) ( ntohs( vendor_header->header.length )
|
632
|
-
- sizeof( struct ofp_vendor_header ) );
|
633
|
-
|
634
|
-
debug( "A vendor message is received from %#" PRIx64
|
635
|
-
" ( transaction_id = %#x, vendor = %#x, body length = %u ).",
|
636
|
-
datapath_id, transaction_id, vendor, body_length );
|
637
|
-
|
638
|
-
if ( event_handlers.vendor_callback == NULL ) {
|
639
|
-
debug( "Callback function for vendor events is not set." );
|
640
|
-
return;
|
641
|
-
}
|
642
|
-
|
643
|
-
if ( body_length > 0 ) {
|
644
|
-
body = duplicate_buffer( data );
|
645
|
-
remove_front_buffer( body, sizeof( struct ofp_vendor_header ) );
|
646
|
-
}
|
647
|
-
else {
|
648
|
-
body = NULL;
|
649
|
-
}
|
650
|
-
|
651
|
-
debug( "Calling vendor handler ( callback = %p, user_data = %p ).",
|
652
|
-
event_handlers.vendor_callback, event_handlers.vendor_user_data );
|
653
|
-
|
654
|
-
event_handlers.vendor_callback( datapath_id,
|
655
|
-
transaction_id,
|
656
|
-
vendor,
|
657
|
-
body,
|
658
|
-
event_handlers.vendor_user_data );
|
659
|
-
|
660
|
-
if ( body != NULL ) {
|
661
|
-
free_buffer( body );
|
662
|
-
}
|
663
|
-
}
|
664
|
-
|
665
|
-
|
666
|
-
static void
|
667
|
-
handle_features_reply( const uint64_t datapath_id, buffer *data ) {
|
668
|
-
char description[ 1024 ];
|
669
|
-
int i, n_phy_ports;
|
670
|
-
uint8_t n_tables;
|
671
|
-
uint16_t phy_ports_length;
|
672
|
-
uint32_t transaction_id, n_buffers, capabilities, actions;
|
673
|
-
list_element *element, *phy_ports_head;
|
674
|
-
struct ofp_phy_port *p, *phy_port;
|
675
|
-
struct ofp_switch_features *switch_features;
|
676
|
-
|
677
|
-
if ( ( data == NULL ) || ( ( data != NULL ) && ( data->length == 0 ) ) ) {
|
678
|
-
critical( "An OpenFlow message must be filled before calling handle_features_reply()." );
|
679
|
-
assert( 0 );
|
680
|
-
}
|
681
|
-
|
682
|
-
switch_features = ( struct ofp_switch_features * ) data->data;
|
683
|
-
|
684
|
-
transaction_id = ntohl( switch_features->header.xid );
|
685
|
-
n_buffers = ntohl( switch_features->n_buffers );
|
686
|
-
n_tables = switch_features->n_tables;
|
687
|
-
capabilities = ntohl( switch_features->capabilities );
|
688
|
-
actions = ntohl( switch_features->actions );
|
689
|
-
|
690
|
-
phy_ports_length = ( uint16_t ) ( ntohs( switch_features->header.length )
|
691
|
-
- offsetof( struct ofp_switch_features, ports ) );
|
692
|
-
|
693
|
-
n_phy_ports = phy_ports_length / sizeof( struct ofp_phy_port );
|
694
|
-
|
695
|
-
debug( "A features reply message is received from %#" PRIx64
|
696
|
-
" ( transaction_id = %#x, n_buffers = %u, n_tables = %u, "
|
697
|
-
"capabilities = %#x, actions = %#x, # of phy ports = %u ).",
|
698
|
-
datapath_id, transaction_id, n_buffers, n_tables,
|
699
|
-
capabilities, actions, n_phy_ports );
|
700
|
-
|
701
|
-
if ( n_phy_ports > 0 ) {
|
702
|
-
create_list( &phy_ports_head );
|
703
|
-
phy_port = ( struct ofp_phy_port * ) switch_features->ports;
|
704
|
-
for ( i = 0; i < n_phy_ports; i++ ) {
|
705
|
-
p = ( struct ofp_phy_port * ) xcalloc( 1, sizeof( struct ofp_phy_port ) );
|
706
|
-
ntoh_phy_port( p, phy_port );
|
707
|
-
append_to_tail( &phy_ports_head, ( void * ) p );
|
708
|
-
phy_port_to_string( p, description, sizeof( description ) );
|
709
|
-
debug( "[%p] %s", phy_port, description );
|
710
|
-
phy_port++;
|
711
|
-
}
|
712
|
-
}
|
713
|
-
else {
|
714
|
-
phy_ports_head = NULL;
|
715
|
-
}
|
716
|
-
|
717
|
-
if ( event_handlers.features_reply_callback == NULL ) {
|
718
|
-
debug( "Callback function for features reply events is not set." );
|
719
|
-
if ( phy_ports_head != NULL ) {
|
720
|
-
element = phy_ports_head;
|
721
|
-
while ( element != NULL ) {
|
722
|
-
xfree( element->data );
|
723
|
-
element = element->next;
|
724
|
-
}
|
725
|
-
delete_list( phy_ports_head );
|
726
|
-
}
|
727
|
-
return;
|
728
|
-
}
|
729
|
-
|
730
|
-
debug( "Calling features reply handler ( callback = %p, user_data = %p ).",
|
731
|
-
event_handlers.features_reply_callback, event_handlers.features_reply_user_data );
|
732
|
-
|
733
|
-
event_handlers.features_reply_callback( datapath_id,
|
734
|
-
transaction_id,
|
735
|
-
n_buffers,
|
736
|
-
n_tables,
|
737
|
-
capabilities,
|
738
|
-
actions,
|
739
|
-
phy_ports_head,
|
740
|
-
event_handlers.features_reply_user_data );
|
741
|
-
|
742
|
-
if ( phy_ports_head != NULL ) {
|
743
|
-
element = phy_ports_head;
|
744
|
-
while ( element != NULL ) {
|
745
|
-
xfree( element->data );
|
746
|
-
element = element->next;
|
747
|
-
}
|
748
|
-
delete_list( phy_ports_head );
|
749
|
-
}
|
750
|
-
}
|
751
|
-
|
752
|
-
|
753
|
-
static void
|
754
|
-
handle_get_config_reply( const uint64_t datapath_id, buffer *data ) {
|
755
|
-
uint16_t flags, miss_send_len;
|
756
|
-
uint32_t transaction_id;
|
757
|
-
struct ofp_switch_config *switch_config;
|
758
|
-
|
759
|
-
if ( ( data == NULL ) || ( ( data != NULL ) && ( data->length == 0 ) ) ) {
|
760
|
-
critical( "An OpenFlow message must be filled before calling handle_get_config_reply()." );
|
761
|
-
assert( 0 );
|
762
|
-
}
|
763
|
-
|
764
|
-
switch_config = ( struct ofp_switch_config * ) data->data;
|
765
|
-
|
766
|
-
transaction_id = ntohl( switch_config->header.xid );
|
767
|
-
flags = ntohs( switch_config->flags );
|
768
|
-
miss_send_len = ntohs( switch_config->miss_send_len );
|
769
|
-
|
770
|
-
debug( "A get config reply message is received from %#" PRIx64
|
771
|
-
" ( transaction_id = %#x, flags = %#x, miss_send_len = %u ).",
|
772
|
-
datapath_id, transaction_id, flags, miss_send_len );
|
773
|
-
|
774
|
-
if ( event_handlers.get_config_reply_callback == NULL ) {
|
775
|
-
debug( "Callback function for get config reply events is not set." );
|
776
|
-
return;
|
777
|
-
}
|
778
|
-
|
779
|
-
debug( "Calling get config reply handler ( callback = %p, user_data = %p ).",
|
780
|
-
event_handlers.get_config_reply_callback, event_handlers.get_config_reply_user_data );
|
781
|
-
|
782
|
-
event_handlers.get_config_reply_callback( datapath_id,
|
783
|
-
transaction_id,
|
784
|
-
flags,
|
785
|
-
miss_send_len,
|
786
|
-
event_handlers.get_config_reply_user_data );
|
787
|
-
}
|
788
|
-
|
789
|
-
|
790
|
-
static bool
|
791
|
-
empty( const buffer *data ) {
|
792
|
-
return ( data == NULL ) || ( ( data != NULL ) && ( data->length == 0 ) );
|
793
|
-
}
|
794
|
-
|
795
|
-
|
796
|
-
static void
|
797
|
-
handle_packet_in( const uint64_t datapath_id, buffer *data ) {
|
798
|
-
if ( empty( data ) ) {
|
799
|
-
die( "handle_packet_in(): packet_in message should not be empty." );
|
800
|
-
}
|
801
|
-
|
802
|
-
struct ofp_packet_in *_packet_in = ( struct ofp_packet_in * ) data->data;
|
803
|
-
uint32_t transaction_id = ntohl( _packet_in->header.xid );
|
804
|
-
uint32_t buffer_id = ntohl( _packet_in->buffer_id );
|
805
|
-
uint16_t total_len = ntohs( _packet_in->total_len );
|
806
|
-
uint16_t in_port = ntohs( _packet_in->in_port );
|
807
|
-
uint8_t reason = _packet_in->reason;
|
808
|
-
uint16_t body_length = ( uint16_t ) ( ntohs( _packet_in->header.length ) - offsetof( struct ofp_packet_in, data ) );
|
809
|
-
|
810
|
-
debug(
|
811
|
-
"A packet_in message is received from %#" PRIx64
|
812
|
-
" ( transaction_id = %#x, buffer_id = %#x, total_len = %u, in_port = %u, reason = %#x, body length = %u ).",
|
813
|
-
datapath_id,
|
814
|
-
transaction_id,
|
815
|
-
buffer_id,
|
816
|
-
total_len,
|
817
|
-
in_port,
|
818
|
-
reason,
|
819
|
-
body_length
|
820
|
-
);
|
821
|
-
|
822
|
-
if ( event_handlers.packet_in_callback == NULL ) {
|
823
|
-
debug( "Callback function for packet_in events is not set." );
|
824
|
-
return;
|
825
|
-
}
|
826
|
-
|
827
|
-
buffer *body = NULL;
|
828
|
-
if ( body_length > 0 ) {
|
829
|
-
body = duplicate_buffer( data );
|
830
|
-
remove_front_buffer( body, offsetof( struct ofp_packet_in, data ) );
|
831
|
-
bool parse_ok = parse_packet( body );
|
832
|
-
if ( !parse_ok ) {
|
833
|
-
error( "Failed to parse a packet." );
|
834
|
-
// ???: Is it OK to drop malformed packets?
|
835
|
-
free_buffer( body );
|
836
|
-
return;
|
837
|
-
}
|
838
|
-
}
|
839
|
-
else {
|
840
|
-
body = NULL;
|
841
|
-
}
|
842
|
-
|
843
|
-
assert( event_handlers.packet_in_callback != NULL );
|
844
|
-
debug( "Calling packet_in handler ( callback = %p, user_data = %p ).",
|
845
|
-
event_handlers.packet_in_callback,
|
846
|
-
event_handlers.packet_in_user_data
|
847
|
-
);
|
848
|
-
if ( event_handlers.simple_packet_in_callback ) {
|
849
|
-
packet_in message = {
|
850
|
-
datapath_id,
|
851
|
-
transaction_id,
|
852
|
-
buffer_id,
|
853
|
-
total_len,
|
854
|
-
in_port,
|
855
|
-
reason,
|
856
|
-
body,
|
857
|
-
event_handlers.packet_in_user_data
|
858
|
-
};
|
859
|
-
( ( simple_packet_in_handler * ) event_handlers.packet_in_callback )( datapath_id, message );
|
860
|
-
}
|
861
|
-
else {
|
862
|
-
( ( packet_in_handler * ) event_handlers.packet_in_callback )(
|
863
|
-
datapath_id,
|
864
|
-
transaction_id,
|
865
|
-
buffer_id,
|
866
|
-
total_len,
|
867
|
-
in_port,
|
868
|
-
reason,
|
869
|
-
body,
|
870
|
-
event_handlers.packet_in_user_data
|
871
|
-
);
|
872
|
-
}
|
873
|
-
|
874
|
-
if ( body != NULL ) {
|
875
|
-
free_buffer( body );
|
876
|
-
}
|
877
|
-
}
|
878
|
-
|
879
|
-
|
880
|
-
static void
|
881
|
-
handle_flow_removed( const uint64_t datapath_id, buffer *data ) {
|
882
|
-
if ( ( data == NULL ) || ( ( data != NULL ) && ( data->length == 0 ) ) ) {
|
883
|
-
critical( "An OpenFlow message must be filled before calling handle_flow_removed()." );
|
884
|
-
assert( 0 );
|
885
|
-
}
|
886
|
-
|
887
|
-
struct ofp_flow_removed *_flow_removed = ( struct ofp_flow_removed * ) data->data;
|
888
|
-
uint32_t transaction_id = ntohl( _flow_removed->header.xid );
|
889
|
-
struct ofp_match match;
|
890
|
-
ntoh_match( &match, &_flow_removed->match );
|
891
|
-
uint64_t cookie = ntohll( _flow_removed->cookie );
|
892
|
-
uint16_t priority = ntohs( _flow_removed->priority );
|
893
|
-
uint8_t reason = _flow_removed->reason;
|
894
|
-
uint32_t duration_sec = ntohl( _flow_removed->duration_sec );
|
895
|
-
uint32_t duration_nsec = ntohl( _flow_removed->duration_nsec );
|
896
|
-
uint16_t idle_timeout = ntohs( _flow_removed->idle_timeout );
|
897
|
-
uint64_t packet_count = ntohll( _flow_removed->packet_count );
|
898
|
-
uint64_t byte_count = ntohll( _flow_removed->byte_count );
|
899
|
-
|
900
|
-
char match_string[ 1024 ];
|
901
|
-
match_to_string( &match, match_string, sizeof( match_string ) );
|
902
|
-
|
903
|
-
debug(
|
904
|
-
"A flow removed message is received from %#" PRIx64
|
905
|
-
" ( transaction_id = %#x, match = [%s], cookie = %#" PRIx64 ", "
|
906
|
-
"priority = %u, reason = %#x, duration_sec = %u, duration_nsec = %u, "
|
907
|
-
"idle_timeout = %u, packet_count = %" PRIu64 ", byte_count = %" PRIu64 " ).",
|
908
|
-
datapath_id,
|
909
|
-
transaction_id,
|
910
|
-
match_string,
|
911
|
-
cookie,
|
912
|
-
priority,
|
913
|
-
reason,
|
914
|
-
duration_sec,
|
915
|
-
duration_nsec,
|
916
|
-
idle_timeout,
|
917
|
-
packet_count,
|
918
|
-
byte_count
|
919
|
-
);
|
920
|
-
|
921
|
-
if ( event_handlers.flow_removed_callback == NULL ) {
|
922
|
-
debug( "Callback function for flow removed events is not set." );
|
923
|
-
return;
|
924
|
-
}
|
925
|
-
|
926
|
-
debug(
|
927
|
-
"Calling flow removed handler ( callback = %p, user_data = %p ).",
|
928
|
-
event_handlers.flow_removed_callback,
|
929
|
-
event_handlers.flow_removed_user_data
|
930
|
-
);
|
931
|
-
if ( event_handlers.simple_flow_removed_callback ) {
|
932
|
-
flow_removed message = {
|
933
|
-
datapath_id,
|
934
|
-
transaction_id,
|
935
|
-
match,
|
936
|
-
cookie,
|
937
|
-
priority,
|
938
|
-
reason,
|
939
|
-
duration_sec,
|
940
|
-
duration_nsec,
|
941
|
-
idle_timeout,
|
942
|
-
packet_count,
|
943
|
-
byte_count,
|
944
|
-
event_handlers.flow_removed_user_data
|
945
|
-
};
|
946
|
-
( ( simple_flow_removed_handler * ) event_handlers.flow_removed_callback )( datapath_id, message );
|
947
|
-
}
|
948
|
-
else {
|
949
|
-
( ( flow_removed_handler * ) event_handlers.flow_removed_callback )(
|
950
|
-
datapath_id,
|
951
|
-
transaction_id,
|
952
|
-
match,
|
953
|
-
cookie,
|
954
|
-
priority,
|
955
|
-
reason,
|
956
|
-
duration_sec,
|
957
|
-
duration_nsec,
|
958
|
-
idle_timeout,
|
959
|
-
packet_count,
|
960
|
-
byte_count,
|
961
|
-
event_handlers.flow_removed_user_data
|
962
|
-
);
|
963
|
-
}
|
964
|
-
}
|
965
|
-
|
966
|
-
|
967
|
-
static void
|
968
|
-
handle_port_status( const uint64_t datapath_id, buffer *data ) {
|
969
|
-
char description[ 1024 ];
|
970
|
-
uint8_t reason;
|
971
|
-
uint32_t transaction_id;
|
972
|
-
struct ofp_phy_port phy_port;
|
973
|
-
struct ofp_port_status *port_status;
|
974
|
-
|
975
|
-
if ( ( data == NULL ) || ( ( data != NULL ) && ( data->length == 0 ) ) ) {
|
976
|
-
critical( "An OpenFlow message must be filled before calling handle_port_status()." );
|
977
|
-
assert( 0 );
|
978
|
-
}
|
979
|
-
|
980
|
-
port_status = ( struct ofp_port_status * ) data->data;
|
981
|
-
|
982
|
-
transaction_id = ntohl( port_status->header.xid );
|
983
|
-
reason = port_status->reason;
|
984
|
-
ntoh_phy_port( &phy_port, &port_status->desc );
|
985
|
-
|
986
|
-
phy_port_to_string( &phy_port, description, sizeof( description ) );
|
987
|
-
|
988
|
-
debug( "A port status message is received from %#" PRIx64
|
989
|
-
" ( transaction_id = %#x, reason = %#x, desc = [%s] ).",
|
990
|
-
datapath_id, transaction_id, reason, description );
|
991
|
-
|
992
|
-
if ( event_handlers.port_status_callback == NULL ) {
|
993
|
-
debug( "Callback function for port status events is not set." );
|
994
|
-
return;
|
995
|
-
}
|
996
|
-
|
997
|
-
debug( "Calling port status handler ( callback = %p, user_data = %p ).",
|
998
|
-
event_handlers.port_status_callback, event_handlers.port_status_user_data );
|
999
|
-
|
1000
|
-
event_handlers.port_status_callback( datapath_id,
|
1001
|
-
transaction_id,
|
1002
|
-
reason,
|
1003
|
-
phy_port,
|
1004
|
-
event_handlers.port_status_user_data );
|
1005
|
-
}
|
1006
|
-
|
1007
|
-
|
1008
|
-
static void
|
1009
|
-
handle_stats_reply( const uint64_t datapath_id, buffer *data ) {
|
1010
|
-
uint16_t type, flags, body_length;
|
1011
|
-
uint32_t transaction_id;
|
1012
|
-
buffer *body = NULL;
|
1013
|
-
buffer *body_h = NULL;
|
1014
|
-
struct ofp_stats_reply *stats_reply;
|
1015
|
-
|
1016
|
-
if ( ( data == NULL ) || ( ( data != NULL ) && ( data->length == 0 ) ) ) {
|
1017
|
-
critical( "An OpenFlow message must be filled before calling handle_stats_reply()." );
|
1018
|
-
assert( 0 );
|
1019
|
-
}
|
1020
|
-
|
1021
|
-
stats_reply = ( struct ofp_stats_reply * ) data->data;
|
1022
|
-
|
1023
|
-
transaction_id = ntohl( stats_reply->header.xid );
|
1024
|
-
type = ntohs( stats_reply->type );
|
1025
|
-
flags = ntohs( stats_reply->flags );
|
1026
|
-
|
1027
|
-
body_length = ( uint16_t ) ( ntohs( stats_reply->header.length )
|
1028
|
-
- offsetof( struct ofp_stats_reply, body ) );
|
1029
|
-
|
1030
|
-
debug( "A stats reply message is received from %#" PRIx64
|
1031
|
-
" ( transaction_id = %#x, type = %#x, flags = %#x, body length = %u ).",
|
1032
|
-
datapath_id, transaction_id, type, flags, body_length );
|
1033
|
-
|
1034
|
-
if ( event_handlers.stats_reply_callback == NULL ) {
|
1035
|
-
debug( "Callback function for stats reply events is not set." );
|
1036
|
-
return;
|
1037
|
-
}
|
1038
|
-
|
1039
|
-
if ( body_length > 0 ) {
|
1040
|
-
body = duplicate_buffer( data );
|
1041
|
-
remove_front_buffer( body, offsetof( struct ofp_stats_reply, body ) );
|
1042
|
-
}
|
1043
|
-
|
1044
|
-
if ( body != NULL ) {
|
1045
|
-
switch ( type ) {
|
1046
|
-
case OFPST_DESC:
|
1047
|
-
{
|
1048
|
-
body_h = body;
|
1049
|
-
body = NULL;
|
1050
|
-
}
|
1051
|
-
break;
|
1052
|
-
case OFPST_FLOW:
|
1053
|
-
{
|
1054
|
-
struct ofp_flow_stats *src, *dst;
|
1055
|
-
|
1056
|
-
body_h = alloc_buffer_with_length( body_length );
|
1057
|
-
append_back_buffer( body_h, body_length );
|
1058
|
-
|
1059
|
-
src = ( struct ofp_flow_stats * ) body->data;
|
1060
|
-
dst = ( struct ofp_flow_stats * ) body_h->data;
|
1061
|
-
|
1062
|
-
while ( body_length > 0 ) {
|
1063
|
-
ntoh_flow_stats( dst, src );
|
1064
|
-
|
1065
|
-
body_length = ( uint16_t ) ( body_length - dst->length );
|
1066
|
-
|
1067
|
-
src = ( struct ofp_flow_stats * ) ( ( char * ) src + dst->length );
|
1068
|
-
dst = ( struct ofp_flow_stats * ) ( ( char * ) dst + dst->length );
|
1069
|
-
}
|
1070
|
-
}
|
1071
|
-
break;
|
1072
|
-
case OFPST_AGGREGATE:
|
1073
|
-
{
|
1074
|
-
struct ofp_aggregate_stats_reply *src, *dst;
|
1075
|
-
|
1076
|
-
body_h = alloc_buffer_with_length( body_length );
|
1077
|
-
append_back_buffer( body_h, body_length );
|
1078
|
-
|
1079
|
-
src = ( struct ofp_aggregate_stats_reply * ) body->data;
|
1080
|
-
dst = ( struct ofp_aggregate_stats_reply * ) body_h->data;
|
1081
|
-
|
1082
|
-
ntoh_aggregate_stats( dst, src );
|
1083
|
-
}
|
1084
|
-
break;
|
1085
|
-
case OFPST_TABLE:
|
1086
|
-
{
|
1087
|
-
struct ofp_table_stats *src, *dst;
|
1088
|
-
|
1089
|
-
body_h = alloc_buffer_with_length( body_length );
|
1090
|
-
append_back_buffer( body_h, body_length );
|
1091
|
-
|
1092
|
-
src = ( struct ofp_table_stats * ) body->data;
|
1093
|
-
dst = ( struct ofp_table_stats * ) body_h->data;
|
1094
|
-
|
1095
|
-
while ( body_length > 0 ) {
|
1096
|
-
ntoh_table_stats( dst, src );
|
1097
|
-
|
1098
|
-
body_length = ( uint16_t ) ( body_length - sizeof( struct ofp_table_stats ) );
|
1099
|
-
|
1100
|
-
src++;
|
1101
|
-
dst++;
|
1102
|
-
}
|
1103
|
-
}
|
1104
|
-
break;
|
1105
|
-
case OFPST_PORT:
|
1106
|
-
{
|
1107
|
-
struct ofp_port_stats *src, *dst;
|
1108
|
-
|
1109
|
-
body_h = alloc_buffer_with_length( body_length );
|
1110
|
-
append_back_buffer( body_h, body_length );
|
1111
|
-
|
1112
|
-
src = ( struct ofp_port_stats * ) body->data;
|
1113
|
-
dst = ( struct ofp_port_stats * ) body_h->data;
|
1114
|
-
|
1115
|
-
while ( body_length > 0 ) {
|
1116
|
-
ntoh_port_stats( dst, src );
|
1117
|
-
|
1118
|
-
body_length = ( uint16_t ) ( body_length - sizeof( struct ofp_port_stats ) );
|
1119
|
-
|
1120
|
-
src++;
|
1121
|
-
dst++;
|
1122
|
-
}
|
1123
|
-
}
|
1124
|
-
break;
|
1125
|
-
case OFPST_QUEUE:
|
1126
|
-
{
|
1127
|
-
struct ofp_queue_stats *src, *dst;
|
1128
|
-
|
1129
|
-
body_h = alloc_buffer_with_length( body_length );
|
1130
|
-
append_back_buffer( body_h, body_length );
|
1131
|
-
|
1132
|
-
src = ( struct ofp_queue_stats * ) body->data;
|
1133
|
-
dst = ( struct ofp_queue_stats * ) body_h->data;
|
1134
|
-
|
1135
|
-
while ( body_length > 0 ) {
|
1136
|
-
ntoh_queue_stats( dst, src );
|
1137
|
-
|
1138
|
-
body_length = ( uint16_t ) ( body_length - sizeof( struct ofp_queue_stats ) );
|
1139
|
-
|
1140
|
-
src++;
|
1141
|
-
dst++;
|
1142
|
-
}
|
1143
|
-
}
|
1144
|
-
break;
|
1145
|
-
case OFPST_VENDOR:
|
1146
|
-
{
|
1147
|
-
uint32_t *src, *dst;
|
1148
|
-
body_h = alloc_buffer_with_length( body_length );
|
1149
|
-
append_back_buffer( body_h, body_length );
|
1150
|
-
|
1151
|
-
memcpy( body_h->data, body->data, body_length );
|
1152
|
-
|
1153
|
-
src = ( uint32_t * ) body->data;
|
1154
|
-
dst = ( uint32_t * ) body_h->data;
|
1155
|
-
|
1156
|
-
*dst = ntohl( *src ); // vendor id
|
1157
|
-
}
|
1158
|
-
break;
|
1159
|
-
default:
|
1160
|
-
if ( body != NULL ) {
|
1161
|
-
free_buffer( body );
|
1162
|
-
}
|
1163
|
-
critical( "Unhandled stats type ( type = %#x ).", type );
|
1164
|
-
assert( 0 );
|
1165
|
-
break;
|
1166
|
-
}
|
1167
|
-
}
|
1168
|
-
|
1169
|
-
debug( "Calling stats reply handler ( callback = %p, user_data = %p ).",
|
1170
|
-
event_handlers.stats_reply_callback, event_handlers.stats_reply_user_data );
|
1171
|
-
|
1172
|
-
event_handlers.stats_reply_callback( datapath_id,
|
1173
|
-
transaction_id,
|
1174
|
-
type,
|
1175
|
-
flags,
|
1176
|
-
body_h,
|
1177
|
-
event_handlers.stats_reply_user_data );
|
1178
|
-
|
1179
|
-
if ( body != NULL ) {
|
1180
|
-
free_buffer( body );
|
1181
|
-
}
|
1182
|
-
if ( body_h != NULL ) {
|
1183
|
-
free_buffer( body_h );
|
1184
|
-
}
|
1185
|
-
}
|
1186
|
-
|
1187
|
-
|
1188
|
-
static void
|
1189
|
-
handle_barrier_reply( const uint64_t datapath_id, buffer *data ) {
|
1190
|
-
uint32_t transaction_id;
|
1191
|
-
struct ofp_header *header;
|
1192
|
-
|
1193
|
-
if ( ( data == NULL ) || ( ( data != NULL ) && ( data->length == 0 ) ) ) {
|
1194
|
-
critical( "An OpenFlow message must be filled before calling handle_barrier_reply()." );
|
1195
|
-
assert( 0 );
|
1196
|
-
}
|
1197
|
-
|
1198
|
-
header = ( struct ofp_header * ) data->data;
|
1199
|
-
|
1200
|
-
transaction_id = ntohl( header->xid );
|
1201
|
-
|
1202
|
-
debug( "A barrier reply message is received from %#" PRIx64 " ( transaction_id = %#x ).",
|
1203
|
-
datapath_id, transaction_id );
|
1204
|
-
|
1205
|
-
if ( event_handlers.barrier_reply_callback == NULL ) {
|
1206
|
-
debug( "Callback function for barrier reply events is not set." );
|
1207
|
-
return;
|
1208
|
-
}
|
1209
|
-
|
1210
|
-
debug( "Calling barrier reply handler ( callback = %p, user_data = %p ).",
|
1211
|
-
event_handlers.barrier_reply_callback, event_handlers.barrier_reply_user_data );
|
1212
|
-
|
1213
|
-
event_handlers.barrier_reply_callback( datapath_id,
|
1214
|
-
transaction_id,
|
1215
|
-
event_handlers.barrier_reply_user_data );
|
1216
|
-
}
|
1217
|
-
|
1218
|
-
|
1219
|
-
static void
|
1220
|
-
handle_queue_get_config_reply( const uint64_t datapath_id, buffer *data ) {
|
1221
|
-
uint16_t port, queues_length;
|
1222
|
-
uint32_t transaction_id;
|
1223
|
-
list_element *queues_head = NULL;
|
1224
|
-
list_element *element = NULL;
|
1225
|
-
struct ofp_packet_queue *pq, *packet_queue;
|
1226
|
-
struct ofp_queue_get_config_reply *queue_get_config_reply;
|
1227
|
-
|
1228
|
-
if ( ( data == NULL ) || ( ( data != NULL ) && ( data->length == 0 ) ) ) {
|
1229
|
-
critical( "An OpenFlow message must be filled before calling handle_queue_get_config_reply()." );
|
1230
|
-
assert( 0 );
|
1231
|
-
}
|
1232
|
-
|
1233
|
-
queue_get_config_reply = ( struct ofp_queue_get_config_reply * ) data->data;
|
1234
|
-
|
1235
|
-
transaction_id = ntohl( queue_get_config_reply->header.xid );
|
1236
|
-
port = ntohs( queue_get_config_reply->port );
|
1237
|
-
|
1238
|
-
queues_length = ( uint16_t ) ( ntohs( queue_get_config_reply->header.length )
|
1239
|
-
- offsetof( struct ofp_queue_get_config_reply, queues ) );
|
1240
|
-
|
1241
|
-
debug( "A queue get config reply message is received from %#" PRIx64
|
1242
|
-
" ( transaction_id = %#x, port = %u, queues length = %u ).",
|
1243
|
-
datapath_id, transaction_id, port, queues_length );
|
1244
|
-
|
1245
|
-
if ( event_handlers.queue_get_config_reply_callback == NULL ) {
|
1246
|
-
debug( "Callback function for queue get config reply events is not set." );
|
1247
|
-
return;
|
1248
|
-
}
|
1249
|
-
|
1250
|
-
if ( queues_length > 0 ) {
|
1251
|
-
create_list( &queues_head );
|
1252
|
-
}
|
1253
|
-
else {
|
1254
|
-
critical( "No queues found." );
|
1255
|
-
assert( 0 );
|
1256
|
-
}
|
1257
|
-
|
1258
|
-
packet_queue = ( struct ofp_packet_queue * ) queue_get_config_reply->queues;
|
1259
|
-
|
1260
|
-
while ( queues_length > 0 ) {
|
1261
|
-
pq = ( struct ofp_packet_queue * ) xcalloc( 1, ntohs( packet_queue->len ) );
|
1262
|
-
|
1263
|
-
ntoh_packet_queue( pq, packet_queue );
|
1264
|
-
append_to_tail( &queues_head, pq );
|
1265
|
-
|
1266
|
-
packet_queue = ( struct ofp_packet_queue * ) ( ( char * ) packet_queue + pq->len );
|
1267
|
-
queues_length = ( uint16_t ) ( queues_length - pq->len );
|
1268
|
-
}
|
1269
|
-
|
1270
|
-
debug( "Calling queue get config reply handler ( callback = %p, user_data = %p ).",
|
1271
|
-
event_handlers.queue_get_config_reply_callback,
|
1272
|
-
event_handlers.queue_get_config_reply_user_data );
|
1273
|
-
|
1274
|
-
event_handlers.queue_get_config_reply_callback( datapath_id,
|
1275
|
-
transaction_id,
|
1276
|
-
port,
|
1277
|
-
queues_head,
|
1278
|
-
event_handlers.queue_get_config_reply_user_data );
|
1279
|
-
|
1280
|
-
if ( queues_head != NULL ) {
|
1281
|
-
element = queues_head;
|
1282
|
-
while ( element != NULL ) {
|
1283
|
-
xfree( element->data );
|
1284
|
-
element = element->next;
|
1285
|
-
}
|
1286
|
-
delete_list( queues_head );
|
1287
|
-
}
|
1288
|
-
}
|
1289
|
-
|
1290
|
-
|
1291
|
-
static void
|
1292
|
-
update_switch_event_stats( uint16_t type, int send_receive, bool result ) {
|
1293
|
-
char key[ STAT_KEY_LENGTH ];
|
1294
|
-
char suffix[ 16 ];
|
1295
|
-
char direction[ 16 ];
|
1296
|
-
const char *prefix = "openflow_application_interface.";
|
1297
|
-
|
1298
|
-
memset( suffix, '\0', sizeof( suffix ) );
|
1299
|
-
|
1300
|
-
if ( result ) {
|
1301
|
-
sprintf( suffix, "_succeeded" );
|
1302
|
-
}
|
1303
|
-
else {
|
1304
|
-
sprintf( suffix, "_failed" );
|
1305
|
-
}
|
1306
|
-
|
1307
|
-
memset( direction, '\0', sizeof( direction ) );
|
1308
|
-
|
1309
|
-
switch ( send_receive ) {
|
1310
|
-
case OPENFLOW_MESSAGE_SEND:
|
1311
|
-
sprintf( direction, "_send" );
|
1312
|
-
break;
|
1313
|
-
case OPENFLOW_MESSAGE_RECEIVE:
|
1314
|
-
sprintf( direction, "_receive" );
|
1315
|
-
break;
|
1316
|
-
default:
|
1317
|
-
return;
|
1318
|
-
}
|
1319
|
-
|
1320
|
-
switch ( type ) {
|
1321
|
-
case MESSENGER_OPENFLOW_CONNECTED:
|
1322
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "switch_connected", direction, suffix );
|
1323
|
-
break;
|
1324
|
-
case MESSENGER_OPENFLOW_READY:
|
1325
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "switch_ready", direction, suffix );
|
1326
|
-
break;
|
1327
|
-
case MESSENGER_OPENFLOW_DISCONNECTED:
|
1328
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "switch_disconnected", direction, suffix );
|
1329
|
-
break;
|
1330
|
-
case MESSENGER_OPENFLOW_FAILD_TO_CONNECT:
|
1331
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "switch_failed_to_connect", direction, suffix );
|
1332
|
-
break;
|
1333
|
-
default:
|
1334
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "undefined_switch_event", direction, suffix );
|
1335
|
-
break;
|
1336
|
-
}
|
1337
|
-
|
1338
|
-
increment_stat( key );
|
1339
|
-
}
|
1340
|
-
|
1341
|
-
|
1342
|
-
static void
|
1343
|
-
handle_switch_ready( uint64_t datapath_id ) {
|
1344
|
-
if ( event_handlers.switch_ready_callback == NULL ) {
|
1345
|
-
debug( "Callback function for switch_ready events is not set." );
|
1346
|
-
return;
|
1347
|
-
}
|
1348
|
-
|
1349
|
-
assert( event_handlers.switch_ready_callback != NULL );
|
1350
|
-
if ( event_handlers.simple_switch_ready_callback ) {
|
1351
|
-
switch_ready event = {
|
1352
|
-
datapath_id,
|
1353
|
-
event_handlers.switch_ready_user_data
|
1354
|
-
};
|
1355
|
-
( ( simple_switch_ready_handler * ) event_handlers.switch_ready_callback )( event );
|
1356
|
-
}
|
1357
|
-
else {
|
1358
|
-
( ( switch_ready_handler * ) event_handlers.switch_ready_callback )(
|
1359
|
-
datapath_id,
|
1360
|
-
event_handlers.switch_ready_user_data
|
1361
|
-
);
|
1362
|
-
}
|
1363
|
-
}
|
1364
|
-
|
1365
|
-
|
1366
|
-
static void
|
1367
|
-
handle_messenger_openflow_disconnected( uint64_t datapath_id ) {
|
1368
|
-
if ( event_handlers.switch_disconnected_callback != NULL ) {
|
1369
|
-
debug( "Calling switch disconnected handler ( callback = %p, user_data = %p ).",
|
1370
|
-
event_handlers.switch_disconnected_callback, event_handlers.switch_disconnected_user_data );
|
1371
|
-
event_handlers.switch_disconnected_callback( datapath_id, event_handlers.switch_disconnected_user_data );
|
1372
|
-
}
|
1373
|
-
else {
|
1374
|
-
debug( "Callback function for switch disconnected events is not set." );
|
1375
|
-
}
|
1376
|
-
delete_openflow_messages( datapath_id );
|
1377
|
-
}
|
1378
|
-
|
1379
|
-
|
1380
|
-
static void
|
1381
|
-
handle_switch_events( uint16_t type, void *data, size_t length ) {
|
1382
|
-
assert( data != NULL );
|
1383
|
-
assert( length == sizeof( openflow_service_header_t ) );
|
1384
|
-
|
1385
|
-
debug( "Received a switch event ( type = %#x ) from remote.", type );
|
1386
|
-
|
1387
|
-
openflow_service_header_t *message = data;
|
1388
|
-
uint64_t datapath_id = ntohll( message->datapath_id );
|
1389
|
-
|
1390
|
-
switch ( type ) {
|
1391
|
-
case MESSENGER_OPENFLOW_CONNECTED:
|
1392
|
-
case MESSENGER_OPENFLOW_FAILD_TO_CONNECT:
|
1393
|
-
// Do nothing.
|
1394
|
-
break;
|
1395
|
-
case MESSENGER_OPENFLOW_READY:
|
1396
|
-
handle_switch_ready( datapath_id );
|
1397
|
-
break;
|
1398
|
-
case MESSENGER_OPENFLOW_DISCONNECTED:
|
1399
|
-
handle_messenger_openflow_disconnected( datapath_id );
|
1400
|
-
break;
|
1401
|
-
default:
|
1402
|
-
error( "Unhandled switch event ( type = %#x ).", type );
|
1403
|
-
break;
|
1404
|
-
}
|
1405
|
-
|
1406
|
-
update_switch_event_stats( type, OPENFLOW_MESSAGE_RECEIVE, true );
|
1407
|
-
}
|
1408
|
-
|
1409
|
-
|
1410
|
-
static void
|
1411
|
-
update_openflow_stats( uint8_t type, int send_receive, bool result ) {
|
1412
|
-
char key[ STAT_KEY_LENGTH ];
|
1413
|
-
char suffix[ 16 ];
|
1414
|
-
char direction[ 16 ];
|
1415
|
-
const char *prefix = "openflow_application_interface.";
|
1416
|
-
|
1417
|
-
memset( suffix, '\0', sizeof( suffix ) );
|
1418
|
-
|
1419
|
-
if ( result ) {
|
1420
|
-
sprintf( suffix, "_succeeded" );
|
1421
|
-
}
|
1422
|
-
else {
|
1423
|
-
sprintf( suffix, "_failed" );
|
1424
|
-
}
|
1425
|
-
|
1426
|
-
memset( direction, '\0', sizeof( direction ) );
|
1427
|
-
|
1428
|
-
switch ( send_receive ) {
|
1429
|
-
case OPENFLOW_MESSAGE_SEND:
|
1430
|
-
sprintf( direction, "_send" );
|
1431
|
-
break;
|
1432
|
-
case OPENFLOW_MESSAGE_RECEIVE:
|
1433
|
-
sprintf( direction, "_receive" );
|
1434
|
-
break;
|
1435
|
-
default:
|
1436
|
-
return;
|
1437
|
-
}
|
1438
|
-
|
1439
|
-
switch ( type ) {
|
1440
|
-
case OFPT_HELLO:
|
1441
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "hello", direction, suffix );
|
1442
|
-
break;
|
1443
|
-
case OFPT_ERROR:
|
1444
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "error", direction, suffix );
|
1445
|
-
break;
|
1446
|
-
case OFPT_ECHO_REQUEST:
|
1447
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "echo_request", direction, suffix );
|
1448
|
-
break;
|
1449
|
-
case OFPT_ECHO_REPLY:
|
1450
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "echo_reply", direction, suffix );
|
1451
|
-
break;
|
1452
|
-
case OFPT_VENDOR:
|
1453
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "vendor", direction, suffix );
|
1454
|
-
break;
|
1455
|
-
case OFPT_FEATURES_REQUEST:
|
1456
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "features_request", direction, suffix );
|
1457
|
-
break;
|
1458
|
-
case OFPT_FEATURES_REPLY:
|
1459
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "features_reply", direction, suffix );
|
1460
|
-
break;
|
1461
|
-
case OFPT_GET_CONFIG_REQUEST:
|
1462
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "get_config_request", direction, suffix );
|
1463
|
-
break;
|
1464
|
-
case OFPT_GET_CONFIG_REPLY:
|
1465
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "get_config_reply", direction, suffix );
|
1466
|
-
break;
|
1467
|
-
case OFPT_SET_CONFIG:
|
1468
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "set_config", direction, suffix );
|
1469
|
-
break;
|
1470
|
-
case OFPT_PACKET_IN:
|
1471
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "packet_in", direction, suffix );
|
1472
|
-
break;
|
1473
|
-
case OFPT_FLOW_REMOVED:
|
1474
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "flow_removed", direction, suffix );
|
1475
|
-
break;
|
1476
|
-
case OFPT_PORT_STATUS:
|
1477
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "port_status", direction, suffix );
|
1478
|
-
break;
|
1479
|
-
case OFPT_PACKET_OUT:
|
1480
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "packet_out", direction, suffix );
|
1481
|
-
break;
|
1482
|
-
case OFPT_FLOW_MOD:
|
1483
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "flow_mod", direction, suffix );
|
1484
|
-
break;
|
1485
|
-
case OFPT_PORT_MOD:
|
1486
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "port_mod", direction, suffix );
|
1487
|
-
break;
|
1488
|
-
case OFPT_STATS_REQUEST:
|
1489
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "stats_request", direction, suffix );
|
1490
|
-
break;
|
1491
|
-
case OFPT_STATS_REPLY:
|
1492
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "stats_reply", direction, suffix );
|
1493
|
-
break;
|
1494
|
-
case OFPT_BARRIER_REQUEST:
|
1495
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "barrier_request", direction, suffix );
|
1496
|
-
break;
|
1497
|
-
case OFPT_BARRIER_REPLY:
|
1498
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "barrier_reply", direction, suffix );
|
1499
|
-
break;
|
1500
|
-
case OFPT_QUEUE_GET_CONFIG_REQUEST:
|
1501
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "queue_get_config_request", direction, suffix );
|
1502
|
-
break;
|
1503
|
-
case OFPT_QUEUE_GET_CONFIG_REPLY:
|
1504
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "queue_get_config_reply", direction, suffix );
|
1505
|
-
break;
|
1506
|
-
default:
|
1507
|
-
snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "undefined_message_type", direction, suffix );
|
1508
|
-
break;
|
1509
|
-
}
|
1510
|
-
|
1511
|
-
increment_stat( key );
|
1512
|
-
}
|
1513
|
-
|
1514
|
-
|
1515
|
-
static void
|
1516
|
-
handle_openflow_message( void *data, size_t length ) {
|
1517
|
-
void *p;
|
1518
|
-
int ret;
|
1519
|
-
uint64_t datapath_id;
|
1520
|
-
buffer *buffer;
|
1521
|
-
struct ofp_header *header;
|
1522
|
-
openflow_service_header_t *message;
|
1523
|
-
|
1524
|
-
assert( data != NULL );
|
1525
|
-
assert( length >= ( sizeof( openflow_service_header_t ) + sizeof( struct ofp_header ) ) );
|
1526
|
-
|
1527
|
-
debug( "An OpenFlow message is received from remote." );
|
1528
|
-
|
1529
|
-
message = ( openflow_service_header_t * ) data;
|
1530
|
-
|
1531
|
-
datapath_id = ntohll( message->datapath_id );
|
1532
|
-
|
1533
|
-
buffer = alloc_buffer_with_length( length );
|
1534
|
-
|
1535
|
-
assert( buffer != NULL );
|
1536
|
-
|
1537
|
-
p = append_back_buffer( buffer, length );
|
1538
|
-
memcpy( p, data, length );
|
1539
|
-
remove_front_buffer( buffer, sizeof( openflow_service_header_t ) );
|
1540
|
-
|
1541
|
-
ret = validate_openflow_message( buffer );
|
1542
|
-
|
1543
|
-
if ( ret < 0 ) {
|
1544
|
-
error( "Failed to validate an OpenFlow message ( code = %d, length = %zu ).", ret, length );
|
1545
|
-
free_buffer( buffer );
|
1546
|
-
|
1547
|
-
return;
|
1548
|
-
}
|
1549
|
-
|
1550
|
-
header = ( struct ofp_header * ) buffer->data;
|
1551
|
-
|
1552
|
-
switch ( header->type ) {
|
1553
|
-
case OFPT_ERROR:
|
1554
|
-
handle_error( datapath_id, buffer );
|
1555
|
-
break;
|
1556
|
-
case OFPT_ECHO_REPLY:
|
1557
|
-
handle_echo_reply( datapath_id, buffer );
|
1558
|
-
break;
|
1559
|
-
case OFPT_VENDOR:
|
1560
|
-
handle_vendor( datapath_id, buffer );
|
1561
|
-
break;
|
1562
|
-
case OFPT_FEATURES_REPLY:
|
1563
|
-
handle_features_reply( datapath_id, buffer );
|
1564
|
-
break;
|
1565
|
-
case OFPT_GET_CONFIG_REPLY:
|
1566
|
-
handle_get_config_reply( datapath_id, buffer );
|
1567
|
-
break;
|
1568
|
-
case OFPT_PACKET_IN:
|
1569
|
-
handle_packet_in( datapath_id, buffer );
|
1570
|
-
break;
|
1571
|
-
case OFPT_FLOW_REMOVED:
|
1572
|
-
handle_flow_removed( datapath_id, buffer );
|
1573
|
-
break;
|
1574
|
-
case OFPT_PORT_STATUS:
|
1575
|
-
handle_port_status( datapath_id, buffer );
|
1576
|
-
break;
|
1577
|
-
case OFPT_STATS_REPLY:
|
1578
|
-
handle_stats_reply( datapath_id, buffer );
|
1579
|
-
break;
|
1580
|
-
case OFPT_BARRIER_REPLY:
|
1581
|
-
handle_barrier_reply( datapath_id, buffer );
|
1582
|
-
break;
|
1583
|
-
case OFPT_QUEUE_GET_CONFIG_REPLY:
|
1584
|
-
handle_queue_get_config_reply( datapath_id, buffer );
|
1585
|
-
break;
|
1586
|
-
default:
|
1587
|
-
error( "Unhandled OpenFlow message ( type = %#x ).", header->type );
|
1588
|
-
break;
|
1589
|
-
}
|
1590
|
-
|
1591
|
-
update_openflow_stats( header->type, OPENFLOW_MESSAGE_RECEIVE, true );
|
1592
|
-
|
1593
|
-
free_buffer( buffer );
|
1594
|
-
}
|
1595
|
-
|
1596
|
-
|
1597
|
-
static void
|
1598
|
-
handle_message( uint16_t type, void *data, size_t length ) {
|
1599
|
-
assert( data != NULL );
|
1600
|
-
assert( length >= sizeof( openflow_service_header_t ) );
|
1601
|
-
|
1602
|
-
debug( "A message is received from remote ( type = %#x ).", type );
|
1603
|
-
|
1604
|
-
switch ( type ) {
|
1605
|
-
case MESSENGER_OPENFLOW_MESSAGE:
|
1606
|
-
return handle_openflow_message( data, length );
|
1607
|
-
case MESSENGER_OPENFLOW_CONNECTED:
|
1608
|
-
case MESSENGER_OPENFLOW_FAILD_TO_CONNECT:
|
1609
|
-
case MESSENGER_OPENFLOW_READY:
|
1610
|
-
case MESSENGER_OPENFLOW_DISCONNECTED:
|
1611
|
-
return handle_switch_events( type, data, length );
|
1612
|
-
default:
|
1613
|
-
error( "Unhandled message ( type = %#x ).", type );
|
1614
|
-
update_switch_event_stats( type, OPENFLOW_MESSAGE_RECEIVE, true );
|
1615
|
-
break;
|
1616
|
-
}
|
1617
|
-
}
|
1618
|
-
|
1619
|
-
|
1620
|
-
static void
|
1621
|
-
insert_dpid( list_element **head, uint64_t *dpid ) {
|
1622
|
-
assert( head != NULL );
|
1623
|
-
assert( dpid != NULL );
|
1624
|
-
|
1625
|
-
list_element *element;
|
1626
|
-
for ( element = *head; element != NULL; element = element->next ) {
|
1627
|
-
if ( *dpid <= *( uint64_t * ) element->data ) {
|
1628
|
-
break;
|
1629
|
-
}
|
1630
|
-
}
|
1631
|
-
if ( element == NULL ) {
|
1632
|
-
append_to_tail( head, dpid );
|
1633
|
-
}
|
1634
|
-
else if ( element == *head ) {
|
1635
|
-
insert_in_front( head, dpid );
|
1636
|
-
}
|
1637
|
-
else {
|
1638
|
-
insert_before( head, element->data, dpid );
|
1639
|
-
}
|
1640
|
-
}
|
1641
|
-
|
1642
|
-
|
1643
|
-
static void
|
1644
|
-
handle_list_switches_reply( uint16_t message_type, void *data, size_t length, void *user_data ) {
|
1645
|
-
UNUSED( message_type );
|
1646
|
-
assert( data != NULL );
|
1647
|
-
|
1648
|
-
uint64_t *dpid = ( uint64_t * ) data;
|
1649
|
-
size_t num_switch = length / sizeof( uint64_t );
|
1650
|
-
|
1651
|
-
debug( "A list switches reply message is received ( number of switches = %zu ).",
|
1652
|
-
num_switch );
|
1653
|
-
|
1654
|
-
if ( event_handlers.list_switches_reply_callback == NULL ) {
|
1655
|
-
debug( "Callback function for list switches reply events is not set." );
|
1656
|
-
return;
|
1657
|
-
}
|
1658
|
-
|
1659
|
-
list_element *switches;
|
1660
|
-
create_list( &switches );
|
1661
|
-
|
1662
|
-
unsigned int i;
|
1663
|
-
for ( i = 0; i < num_switch; ++i ) {
|
1664
|
-
uint64_t *datapath_id = ( uint64_t * ) xmalloc( sizeof( uint64_t ) );
|
1665
|
-
*datapath_id = ntohll( dpid[ i ] );
|
1666
|
-
insert_dpid( &switches, datapath_id );
|
1667
|
-
}
|
1668
|
-
|
1669
|
-
debug( "Calling list switches reply handler ( callback = %p ).",
|
1670
|
-
event_handlers.list_switches_reply_callback );
|
1671
|
-
|
1672
|
-
event_handlers.list_switches_reply_callback( switches, user_data );
|
1673
|
-
|
1674
|
-
list_element *element;
|
1675
|
-
for ( element = switches; element != NULL; element = element->next ) {
|
1676
|
-
xfree( element->data );
|
1677
|
-
}
|
1678
|
-
delete_list( switches );
|
1679
|
-
}
|
1680
|
-
|
1681
|
-
|
1682
|
-
bool
|
1683
|
-
send_openflow_message( const uint64_t datapath_id, buffer *message ) {
|
1684
|
-
bool ret;
|
1685
|
-
void *data;
|
1686
|
-
char remote_service_name[ MESSENGER_SERVICE_NAME_LENGTH ];
|
1687
|
-
uint16_t header_length;
|
1688
|
-
buffer *buffer;
|
1689
|
-
struct ofp_header *ofp;
|
1690
|
-
openflow_service_header_t header;
|
1691
|
-
|
1692
|
-
maybe_init_openflow_application_interface();
|
1693
|
-
assert( openflow_application_interface_initialized );
|
1694
|
-
|
1695
|
-
if ( ( message == NULL ) || ( ( message != NULL ) && ( message->length == 0 ) ) ) {
|
1696
|
-
critical( "An OpenFlow message must be passed to send_openflow_message()." );
|
1697
|
-
assert( 0 );
|
1698
|
-
}
|
1699
|
-
|
1700
|
-
ofp = ( struct ofp_header * ) message->data;
|
1701
|
-
buffer = duplicate_buffer( message );
|
1702
|
-
|
1703
|
-
assert( buffer != NULL );
|
1704
|
-
|
1705
|
-
header_length = ( uint16_t ) ( sizeof( openflow_service_header_t )
|
1706
|
-
+ strlen( service_name ) + 1 );
|
1707
|
-
|
1708
|
-
header.datapath_id = htonll( datapath_id );
|
1709
|
-
header.service_name_length = htons( ( uint16_t ) ( strlen( service_name ) + 1 ) );
|
1710
|
-
|
1711
|
-
data = append_front_buffer( buffer, header_length );
|
1712
|
-
memset( data, '\0', header_length );
|
1713
|
-
memcpy( data, &header, sizeof( openflow_service_header_t ) );
|
1714
|
-
memcpy( ( char * ) data + sizeof( openflow_service_header_t ),
|
1715
|
-
service_name, strlen( service_name ) );
|
1716
|
-
|
1717
|
-
memset( remote_service_name, '\0', sizeof( remote_service_name ) );
|
1718
|
-
snprintf( remote_service_name, sizeof( remote_service_name ),
|
1719
|
-
"switch.%#" PRIx64, datapath_id );
|
1720
|
-
|
1721
|
-
debug( "Sending an OpenFlow message to %#" PRIx64
|
1722
|
-
" ( service_name = %s, remote_service_name = %s, "
|
1723
|
-
"ofp_header = [version = %#x, type = %#x, length = %u, transaction_id = %#x] ).",
|
1724
|
-
datapath_id, service_name, remote_service_name,
|
1725
|
-
ofp->version, ofp->type, ntohs( ofp->length ), ntohl( ofp->xid ) );
|
1726
|
-
|
1727
|
-
ret = send_message( remote_service_name, MESSENGER_OPENFLOW_MESSAGE,
|
1728
|
-
buffer->data, buffer->length );
|
1729
|
-
|
1730
|
-
free_buffer( buffer );
|
1731
|
-
|
1732
|
-
update_openflow_stats( ofp->type, OPENFLOW_MESSAGE_SEND, ret );
|
1733
|
-
|
1734
|
-
return ret;
|
1735
|
-
}
|
1736
|
-
|
1737
|
-
|
1738
|
-
bool
|
1739
|
-
send_list_switches_request( void *user_data ) {
|
1740
|
-
uint16_t message_type = 0;
|
1741
|
-
void *data = NULL;
|
1742
|
-
size_t data_length = 0;
|
1743
|
-
|
1744
|
-
maybe_init_openflow_application_interface();
|
1745
|
-
assert( openflow_application_interface_initialized );
|
1746
|
-
|
1747
|
-
debug( "Sending a list switches request ( service_name = %s ).", service_name );
|
1748
|
-
|
1749
|
-
return send_request_message( "switch_manager", service_name, message_type,
|
1750
|
-
data, data_length, user_data );
|
1751
|
-
}
|
1752
|
-
|
1753
|
-
|
1754
|
-
bool
|
1755
|
-
delete_openflow_messages( uint64_t datapath_id ) {
|
1756
|
-
debug( "Deleting OpenFlow messages in a send queue ( datapath_id = %#" PRIx64 " ).", datapath_id );
|
1757
|
-
|
1758
|
-
char remote_service_name[ MESSENGER_SERVICE_NAME_LENGTH ];
|
1759
|
-
memset( remote_service_name, '\0', sizeof( remote_service_name ) );
|
1760
|
-
snprintf( remote_service_name, sizeof( remote_service_name ),
|
1761
|
-
"switch.%#" PRIx64, datapath_id );
|
1762
|
-
return clear_send_queue( remote_service_name );
|
1763
|
-
}
|
1764
|
-
|
1765
|
-
|
1766
|
-
bool
|
1767
|
-
disconnect_switch( uint64_t datapath_id ) {
|
1768
|
-
debug( "Disconnecting a switch ( datapath_id = %#" PRIx64 " ).", datapath_id );
|
1769
|
-
|
1770
|
-
maybe_init_openflow_application_interface();
|
1771
|
-
assert( openflow_application_interface_initialized );
|
1772
|
-
|
1773
|
-
size_t service_name_length = strlen( service_name ) + 1;
|
1774
|
-
size_t length = sizeof( openflow_service_header_t ) + service_name_length;
|
1775
|
-
buffer *buf = alloc_buffer_with_length( length );
|
1776
|
-
openflow_service_header_t *header = append_back_buffer( buf, sizeof( openflow_service_header_t ) );
|
1777
|
-
header->datapath_id = htonll( datapath_id );
|
1778
|
-
header->service_name_length = htons( ( uint16_t ) service_name_length );
|
1779
|
-
char *name = append_back_buffer( buf, service_name_length );
|
1780
|
-
memcpy( name, service_name, service_name_length );
|
1781
|
-
|
1782
|
-
char remote_service_name[ MESSENGER_SERVICE_NAME_LENGTH ];
|
1783
|
-
snprintf( remote_service_name, sizeof( remote_service_name ),
|
1784
|
-
"switch.%#" PRIx64, datapath_id );
|
1785
|
-
|
1786
|
-
bool ret = send_message( remote_service_name, MESSENGER_OPENFLOW_DISCONNECT_REQUEST,
|
1787
|
-
buf->data, buf->length );
|
1788
|
-
|
1789
|
-
free_buffer( buf );
|
1790
|
-
|
1791
|
-
return ret;
|
1792
|
-
}
|
1793
|
-
|
1794
|
-
|
1795
|
-
/*
|
1796
|
-
* Local variables:
|
1797
|
-
* c-basic-offset: 2
|
1798
|
-
* indent-tabs-mode: nil
|
1799
|
-
* End:
|
1800
|
-
*/
|