trema 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/Doxyfile +1 -1
- data/Gemfile +18 -6
- data/README.md +112 -5
- data/Rakefile +3 -1
- data/Rantfile +88 -1
- data/bin/trema +248 -0
- data/bin/trema-config +59 -0
- data/cruise.rb +1 -1
- data/features/example.dumper.feature +45 -65
- data/features/example.hello_trema.feature +21 -0
- data/features/example.learning_switch.feature +26 -28
- data/features/example.list_switches.feature +19 -33
- data/features/example.message.echo_reply.feature +10 -10
- data/features/example.message.echo_request.feature +2 -2
- data/features/example.message.features_request.feature +6 -5
- data/features/example.message.hello.feature +47 -13
- data/features/example.message.set_config.feature +4 -4
- data/features/example.message.vendor-action.feature +23 -0
- data/features/example.multi_learning_switch.feature +14 -42
- data/features/example.packet_in.feature +31 -0
- data/features/example.packetin_filter_config.feature +11 -7
- data/features/example.patch_panel.feature +29 -0
- data/features/example.repeater_hub.feature +43 -40
- data/features/example.switch_info.feature +51 -0
- data/features/example.switch_monitor.feature +24 -42
- data/features/packetin_filter.feature +28 -22
- data/features/step_definitions/misc_steps.rb +19 -8
- data/features/step_definitions/send_packets_steps.rb +1 -10
- data/features/step_definitions/stats_steps.rb +4 -4
- data/features/support/env.rb +2 -1
- data/features/support/hooks.rb +35 -2
- data/features/switch_manager.feature +18 -12
- data/features/trema-config.feature +26 -39
- data/features/trema.dump_flows.feature +26 -12
- data/features/trema.help.feature +26 -0
- data/features/trema.kill.feature +39 -41
- data/features/trema.killall.feature +23 -23
- data/features/trema.reset_stats.feature +50 -10
- data/features/trema.run.feature +28 -39
- data/features/trema.send_packets.feature +29 -40
- data/features/trema.show_stats.feature +30 -33
- data/features/trema.up.feature +33 -0
- data/features/trema.version.feature +9 -0
- data/ruby/extconf.rb +7 -0
- data/ruby/trema/aggregate-stats-reply.rb +3 -3
- data/ruby/trema/app.rb +5 -1
- data/ruby/trema/barrier-request.c +55 -30
- data/ruby/trema/cli.rb +8 -8
- data/ruby/trema/command.rb +1 -3
- data/ruby/trema/command/dump_flows.rb +5 -24
- data/ruby/trema/command/kill.rb +31 -36
- data/ruby/trema/command/killall.rb +1 -19
- data/{features/step_definitions/kill_steps.rb → ruby/trema/command/netns.rb} +13 -5
- data/ruby/trema/command/reset_stats.rb +3 -23
- data/ruby/trema/command/ruby.rb +2 -19
- data/ruby/trema/command/run.rb +6 -27
- data/ruby/trema/command/send_packets.rb +6 -90
- data/ruby/trema/command/show_stats.rb +21 -40
- data/ruby/trema/command/up.rb +5 -26
- data/ruby/trema/command/version.rb +1 -5
- data/ruby/trema/controller.c +14 -16
- data/ruby/trema/custom-switch.rb +56 -0
- data/ruby/trema/desc-stats-reply.rb +5 -5
- data/ruby/trema/dsl/configuration.rb +4 -0
- data/{features/step_definitions/up_steps.rb → ruby/trema/dsl/custom-switch.rb} +18 -4
- data/ruby/trema/dsl/netns.rb +78 -0
- data/ruby/trema/dsl/parser.rb +2 -0
- data/ruby/trema/dsl/runner.rb +8 -0
- data/ruby/trema/dsl/syntax.rb +18 -0
- data/ruby/trema/echo-reply.h +2 -2
- data/ruby/trema/echo-request.c +3 -5
- data/ruby/trema/enqueue.rb +2 -2
- data/ruby/trema/error.c +3 -3
- data/ruby/trema/executables.rb +26 -2
- data/ruby/trema/features-request.c +3 -5
- data/ruby/trema/flow-removed.c +6 -6
- data/ruby/trema/flow-stats-reply.rb +6 -8
- data/ruby/trema/flow.rb +12 -1
- data/ruby/trema/get-config-request.c +55 -28
- data/ruby/trema/hello.c +3 -5
- data/ruby/trema/host.rb +8 -0
- data/ruby/trema/list-switches-reply.c +1 -1
- data/ruby/trema/mac.rb +1 -1
- data/ruby/trema/match.c +15 -14
- data/ruby/trema/monkey-patch/module/deprecation.rb +0 -2
- data/ruby/trema/netns.rb +127 -0
- data/ruby/trema/ordered-hash.rb +5 -4
- data/ruby/trema/packet-in.c +136 -113
- data/ruby/trema/packet-queue.rb +9 -9
- data/ruby/trema/packetin-filter.rb +1 -1
- data/ruby/trema/phost.rb +16 -7
- data/ruby/trema/port-mod.c +6 -5
- data/ruby/trema/port-stats-reply.rb +2 -2
- data/ruby/trema/process.rb +29 -0
- data/ruby/trema/queue-stats-reply.rb +2 -4
- data/ruby/trema/send-out-port.rb +5 -3
- data/ruby/trema/set-eth-addr.rb +4 -0
- data/ruby/trema/set-ip-addr.rb +4 -2
- data/ruby/trema/set-ip-dst-addr.rb +2 -1
- data/ruby/trema/set-ip-src-addr.rb +2 -1
- data/ruby/trema/set-ip-tos.rb +3 -2
- data/ruby/trema/set-transport-port.rb +3 -2
- data/ruby/trema/set-vlan-priority.rb +3 -2
- data/ruby/trema/set-vlan-vid.rb +5 -4
- data/ruby/trema/shell/reset_stats.rb +2 -1
- data/ruby/trema/shell/run.rb +1 -1
- data/ruby/trema/shell/send_packets.rb +1 -1
- data/ruby/trema/shell/show_stats.rb +1 -1
- data/ruby/trema/stats-helper.rb +3 -3
- data/ruby/trema/stats-reply.c +26 -17
- data/ruby/trema/stats-request.c +39 -41
- data/ruby/trema/switch-daemon.rb +36 -31
- data/ruby/trema/switch.c +1 -1
- data/ruby/trema/table-stats-reply.rb +1 -1
- data/ruby/trema/timers.rb +13 -13
- data/ruby/trema/trema.c +3 -3
- data/ruby/trema/tremashark.rb +9 -2
- data/ruby/trema/util.rb +39 -15
- data/ruby/trema/vendor-action.rb +8 -3
- data/ruby/trema/vendor-stats-reply.rb +4 -6
- data/ruby/trema/vendor.c +1 -1
- data/ruby/trema/version.rb +1 -1
- data/spec/trema/barrier-request_spec.rb +47 -37
- data/spec/trema/controller_spec.rb +1 -0
- data/spec/trema/dsl/runner_spec.rb +8 -3
- data/spec/trema/dsl/vhost_spec.rb +8 -8
- data/spec/trema/echo-request_spec.rb +1 -0
- data/spec/trema/features-request_spec.rb +1 -0
- data/spec/trema/flow-removed_spec.rb +9 -9
- data/spec/trema/get-config-request_spec.rb +51 -39
- data/spec/trema/match_spec.rb +1 -1
- data/spec/trema/openflow-error_spec.rb +11 -11
- data/spec/trema/packet-out_spec.rb +5 -5
- data/spec/trema/queue-get-config-reply_spec.rb +1 -1
- data/spec/trema/queue-get-config-request_spec.rb +1 -1
- data/spec/trema/set-eth-dst-addr_spec.rb +1 -1
- data/spec/trema/set-eth-src-addr_spec.rb +1 -1
- data/spec/trema/set-ip-dst-addr_spec.rb +1 -0
- data/spec/trema/set-ip-src-addr_spec.rb +1 -0
- data/spec/trema/set-ip-tos_spec.rb +1 -0
- data/spec/trema/set-transport-dst-port_spec.rb +1 -0
- data/spec/trema/set-transport-src-port_spec.rb +1 -0
- data/spec/trema/set-vlan-priority_spec.rb +1 -0
- data/spec/trema/set-vlan-vid_spec.rb +2 -1
- data/spec/trema/stats-reply_spec.rb +38 -36
- data/spec/trema/stats-request_spec.rb +6 -6
- data/spec/trema/strip-vlan-header_spec.rb +1 -0
- data/spec/trema/util_spec.rb +3 -2
- data/spec/trema/vendor-action_spec.rb +9 -8
- data/src/examples/dumper/dumper.c +8 -6
- data/src/examples/dumper/dumper.rb +1 -1
- data/{features/step_definitions/killall_steps.rb → src/examples/hello_trema/hello-trema.rb} +6 -5
- data/src/examples/hello_trema/hello_trema.c +4 -4
- data/src/examples/learning_switch/learning_switch.c +1 -1
- data/src/examples/list_switches/list_switches.c +2 -2
- data/src/examples/match_compare/match-compare.rb +2 -2
- data/src/examples/multi_learning_switch/multi-learning-switch.rb +1 -1
- data/src/examples/multi_learning_switch/multi_learning_switch.c +3 -3
- data/src/examples/openflow_message/README +1 -1
- data/src/examples/openflow_message/echo-request.rb +1 -1
- data/src/examples/openflow_message/features_request.c +21 -21
- data/src/examples/openflow_message/hello.c +1 -3
- data/src/examples/openflow_message/hello.rb +9 -24
- data/src/examples/{hello_trema/hello_trema.rb → openflow_message/vendor-action.rb} +17 -7
- data/src/examples/openflow_message/vendor_action.c +105 -0
- data/src/examples/openflow_switch/hello_switch.c +81 -0
- data/src/examples/packet_in/packet-in.rb +9 -13
- data/src/examples/packetin_filter_config/packetin_filter_config.c +2 -2
- data/src/examples/patch_panel/network.conf +14 -0
- data/src/examples/patch_panel/patch-panel.conf +1 -0
- data/{features/step_definitions/show_stats_steps.rb → src/examples/patch_panel/patch-panel.rb} +29 -13
- data/src/examples/switch_info/{switch_info.rb → switch-info.rb} +2 -2
- data/src/examples/switch_info/switch_info.c +4 -4
- data/src/examples/switch_monitor/switch_monitor.c +3 -3
- data/src/examples/traffic_monitor/counter.c +9 -9
- data/src/examples/traffic_monitor/fdb.c +9 -9
- data/src/lib/arp.h +1 -1
- data/src/lib/buffer.c +4 -3
- data/src/lib/byteorder.c +31 -5
- data/src/lib/byteorder.h +2 -2
- data/src/lib/chibach.c +8 -6
- data/src/lib/daemon.c +29 -3
- data/src/lib/doubly_linked_list.c +6 -1
- data/src/lib/ether.c +1 -1
- data/src/lib/ether.h +1 -1
- data/src/lib/event_handler.c +3 -3
- data/src/lib/hash_table.c +1 -1
- data/src/lib/linked_list.c +50 -2
- data/src/lib/linked_list.h +2 -2
- data/src/lib/log.c +122 -22
- data/src/lib/log.h +13 -9
- data/src/lib/management_interface.c +361 -0
- data/src/lib/management_interface.h +42 -0
- data/src/lib/management_service_interface.c +104 -0
- data/src/lib/management_service_interface.h +136 -0
- data/src/lib/match_table.c +5 -5
- data/src/lib/message_queue.c +5 -3
- data/src/lib/message_queue.h +1 -1
- data/src/lib/messenger.c +73 -39
- data/src/lib/messenger.h +3 -2
- data/src/lib/openflow_application_interface.c +17 -17
- data/src/lib/openflow_message.c +175 -23
- data/src/lib/openflow_message.h +2 -1
- data/src/lib/openflow_switch_interface.c +12 -12
- data/src/lib/packet_parser.c +11 -32
- data/src/lib/packetin_filter_interface.c +5 -5
- data/src/lib/persistent_storage.c +7 -7
- data/src/lib/secure_channel.c +6 -6
- data/src/lib/secure_channel.h +1 -1
- data/src/lib/stat.c +54 -17
- data/src/lib/stat.h +9 -0
- data/src/lib/timer.c +11 -10
- data/src/lib/trema.c +38 -9
- data/src/lib/trema.h +1 -0
- data/src/lib/trema_private.h +6 -0
- data/src/lib/trema_wrapper.c +4 -4
- data/src/lib/trema_wrapper.h +10 -10
- data/src/lib/utility.c +6 -6
- data/src/management/application.c +224 -0
- data/src/management/echo.c +185 -0
- data/src/management/set_logging_level.c +153 -0
- data/src/management/show_stats.c +150 -0
- data/src/management/trema_manager +184 -0
- data/src/packetin_filter/packetin_filter.c +31 -29
- data/src/switch_manager/cookie_table.c +7 -7
- data/src/switch_manager/dpid_table.c +3 -3
- data/src/switch_manager/dpid_table.h +0 -1
- data/src/switch_manager/management_interface.h +0 -1
- data/src/switch_manager/ofpmsg_recv.c +3 -3
- data/src/switch_manager/ofpmsg_recv.h +0 -1
- data/src/switch_manager/ofpmsg_send.c +2 -2
- data/src/switch_manager/ofpmsg_send.h +0 -1
- data/src/switch_manager/secure_channel_listener.c +2 -2
- data/src/switch_manager/secure_channel_receiver.c +2 -2
- data/src/switch_manager/secure_channel_receiver.h +0 -1
- data/src/switch_manager/secure_channel_sender.c +8 -1
- data/src/switch_manager/service_interface.c +5 -4
- data/src/switch_manager/switch.c +79 -53
- data/src/switch_manager/switch_manager.c +24 -22
- data/src/switch_manager/xid_table.c +6 -6
- data/src/switch_manager/xid_table.h +0 -1
- data/src/tremashark/README +4 -3
- data/src/tremashark/packet_capture.c +11 -9
- data/src/tremashark/pcap_queue.c +2 -2
- data/src/tremashark/pcap_queue.h +2 -2
- data/src/tremashark/plugin/packet-trema/Makefile +1 -1
- data/src/tremashark/plugin/packet-trema/Makefile.common +1 -1
- data/src/tremashark/plugin/packet-trema/packet-trema.c +50 -37
- data/src/tremashark/queue.c +5 -4
- data/src/tremashark/queue.h +1 -1
- data/src/tremashark/stdin_relay.c +10 -8
- data/src/tremashark/syslog_relay.c +14 -12
- data/src/tremashark/tremashark.c +15 -18
- data/trema +2 -96
- data/trema-config +2 -52
- data/trema.gemspec +12 -1
- data/unittests/cmockery_trema.h +14 -13
- data/unittests/lib/buffer_test.c +1 -1
- data/unittests/lib/byteorder_test.c +108 -25
- data/unittests/lib/daemon_test.c +141 -5
- data/unittests/lib/doubly_linked_list_test.c +5 -1
- data/unittests/lib/ether_test.c +4 -4
- data/unittests/lib/hash_table_test.c +5 -3
- data/unittests/lib/linked_list_test.c +82 -4
- data/unittests/lib/log_test.c +96 -5
- data/unittests/lib/management_interface_test.c +240 -0
- data/unittests/lib/management_service_interface_test.c +319 -0
- data/unittests/lib/message_queue_test.c +6 -2
- data/unittests/lib/messenger_test.c +167 -2
- data/unittests/lib/openflow_application_interface_test.c +16 -22
- data/unittests/lib/openflow_message_test.c +721 -24
- data/unittests/lib/packet_info_test.c +2 -2
- data/unittests/lib/packet_parser_test.c +15 -16
- data/unittests/lib/packetin_filter_interface_test.c +6 -6
- data/unittests/lib/persistent_storage_test.c +11 -11
- data/unittests/lib/stat_test.c +151 -7
- data/unittests/lib/timer_test.c +1 -1
- data/unittests/lib/trema_private_test.c +2 -2
- data/unittests/lib/trema_test.c +40 -12
- data/unittests/lib/utility_test.c +3 -3
- data/unittests/lib/wrapper_test.c +3 -3
- data/unittests/packetin_filter/packetin_filter_test.c +12 -11
- data/unittests/switch_manager/switch_manager_test.c +29 -22
- metadata +99 -20
- data/features/step_definitions/log_steps.rb +0 -90
- data/features/step_definitions/run_steps.rb +0 -91
- data/features/trema.feature +0 -27
- data/features/tutorial.hello_trema.feature +0 -27
- data/features/tutorial.packet_in.feature +0 -47
- data/features/tutorial.switch_info.feature +0 -55
- data/ruby/trema/command/usage.rb +0 -63
data/src/lib/messenger.h
CHANGED
@@ -75,7 +75,7 @@ enum {
|
|
75
75
|
MESSENGER_DUMP_SEND_REFUSED,
|
76
76
|
MESSENGER_DUMP_SEND_OVERFLOW,
|
77
77
|
MESSENGER_DUMP_SEND_CLOSED,
|
78
|
-
MESSENGER_DUMP_LOGGER,
|
78
|
+
MESSENGER_DUMP_LOGGER,
|
79
79
|
MESSENGER_DUMP_PCAP,
|
80
80
|
MESSENGER_DUMP_SYSLOG,
|
81
81
|
MESSENGER_DUMP_TEXT,
|
@@ -115,13 +115,14 @@ extern bool ( *add_message_received_callback )( const char *service_name, const
|
|
115
115
|
extern bool ( *rename_message_received_callback )( const char *old_service_name, const char *new_service_name );
|
116
116
|
extern bool ( *delete_message_received_callback )( const char *service_name, void ( *callback )( uint16_t tag, void *data, size_t len ) );
|
117
117
|
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 ) );
|
118
|
+
extern bool ( *rename_message_requested_callback )( const char *old_service_name, const char *new_service_name );
|
118
119
|
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 ) );
|
119
120
|
extern bool ( *add_message_replied_callback )( const char *service_name, void ( *callback )( uint16_t tag, void *data, size_t len, void *user_data ) );
|
120
121
|
extern bool ( *delete_message_replied_callback )( const char *service_name, void ( *callback )( uint16_t tag, void *data, size_t len, void *user_data ) );
|
121
122
|
extern bool ( *send_message )( const char *service_name, const uint16_t tag, const void *data, size_t len );
|
122
123
|
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 );
|
123
124
|
extern bool ( *send_reply_message )( const messenger_context_handle *handle, const uint16_t tag, const void *data, size_t len );
|
124
|
-
extern bool ( *clear_send_queue )
|
125
|
+
extern bool ( *clear_send_queue )( const char *service_name );
|
125
126
|
|
126
127
|
bool init_messenger( const char *working_directory );
|
127
128
|
bool finalize_messenger( void );
|
@@ -538,8 +538,8 @@ handle_error( const uint64_t datapath_id, buffer *data ) {
|
|
538
538
|
body = duplicate_buffer( data );
|
539
539
|
remove_front_buffer( body, offsetof( struct ofp_error_msg, data ) );
|
540
540
|
|
541
|
-
debug( "An error message is received from %#
|
542
|
-
"( transaction_id = %#x, type =
|
541
|
+
debug( "An error message is received from %#" PRIx64 " "
|
542
|
+
"( transaction_id = %#x, type = %#x, code = %#x, data length = %zu ).",
|
543
543
|
datapath_id, transaction_id, type, code, body->length );
|
544
544
|
|
545
545
|
if ( event_handlers.error_callback == NULL ) {
|
@@ -718,7 +718,7 @@ handle_features_reply( const uint64_t datapath_id, buffer *data ) {
|
|
718
718
|
|
719
719
|
if ( event_handlers.features_reply_callback == NULL ) {
|
720
720
|
debug( "Callback function for features reply events is not set." );
|
721
|
-
if( phy_ports_head != NULL ) {
|
721
|
+
if ( phy_ports_head != NULL ) {
|
722
722
|
element = phy_ports_head;
|
723
723
|
while ( element != NULL ) {
|
724
724
|
xfree( element->data );
|
@@ -811,7 +811,7 @@ handle_packet_in( const uint64_t datapath_id, buffer *data ) {
|
|
811
811
|
|
812
812
|
debug(
|
813
813
|
"A packet_in message is received from %#" PRIx64
|
814
|
-
" (transaction_id = %#x, buffer_id = %#x, total_len = %u, in_port = %u, reason = %#x, body length = %u).",
|
814
|
+
" ( transaction_id = %#x, buffer_id = %#x, total_len = %u, in_port = %u, reason = %#x, body length = %u ).",
|
815
815
|
datapath_id,
|
816
816
|
transaction_id,
|
817
817
|
buffer_id,
|
@@ -843,7 +843,7 @@ handle_packet_in( const uint64_t datapath_id, buffer *data ) {
|
|
843
843
|
}
|
844
844
|
|
845
845
|
assert( event_handlers.packet_in_callback != NULL );
|
846
|
-
debug( "Calling packet_in handler (callback = %p, user_data = %p).",
|
846
|
+
debug( "Calling packet_in handler ( callback = %p, user_data = %p ).",
|
847
847
|
event_handlers.packet_in_callback,
|
848
848
|
event_handlers.packet_in_user_data
|
849
849
|
);
|
@@ -926,7 +926,7 @@ handle_flow_removed( const uint64_t datapath_id, buffer *data ) {
|
|
926
926
|
}
|
927
927
|
|
928
928
|
debug(
|
929
|
-
"Calling flow removed handler (callback = %p, user_data = %p).",
|
929
|
+
"Calling flow removed handler ( callback = %p, user_data = %p ).",
|
930
930
|
event_handlers.flow_removed_callback,
|
931
931
|
event_handlers.flow_removed_user_data
|
932
932
|
);
|
@@ -1162,7 +1162,7 @@ handle_stats_reply( const uint64_t datapath_id, buffer *data ) {
|
|
1162
1162
|
if ( body != NULL ) {
|
1163
1163
|
free_buffer( body );
|
1164
1164
|
}
|
1165
|
-
critical( "Unhandled stats type ( type =
|
1165
|
+
critical( "Unhandled stats type ( type = %#x ).", type );
|
1166
1166
|
assert( 0 );
|
1167
1167
|
break;
|
1168
1168
|
}
|
@@ -1368,7 +1368,7 @@ handle_switch_ready( uint64_t datapath_id ) {
|
|
1368
1368
|
static void
|
1369
1369
|
handle_messenger_openflow_disconnected( uint64_t datapath_id ) {
|
1370
1370
|
if ( event_handlers.switch_disconnected_callback != NULL ) {
|
1371
|
-
debug( "Calling switch disconnected handler (callback = %p, user_data = %p).",
|
1371
|
+
debug( "Calling switch disconnected handler ( callback = %p, user_data = %p ).",
|
1372
1372
|
event_handlers.switch_disconnected_callback, event_handlers.switch_disconnected_user_data );
|
1373
1373
|
event_handlers.switch_disconnected_callback( datapath_id, event_handlers.switch_disconnected_user_data );
|
1374
1374
|
}
|
@@ -1384,7 +1384,7 @@ handle_switch_events( uint16_t type, void *data, size_t length ) {
|
|
1384
1384
|
assert( data != NULL );
|
1385
1385
|
assert( length == sizeof( openflow_service_header_t ) );
|
1386
1386
|
|
1387
|
-
debug( "Received a switch event (type =
|
1387
|
+
debug( "Received a switch event ( type = %#x ) from remote.", type );
|
1388
1388
|
|
1389
1389
|
openflow_service_header_t *message = data;
|
1390
1390
|
uint64_t datapath_id = ntohll( message->datapath_id );
|
@@ -1401,7 +1401,7 @@ handle_switch_events( uint16_t type, void *data, size_t length ) {
|
|
1401
1401
|
handle_messenger_openflow_disconnected( datapath_id );
|
1402
1402
|
break;
|
1403
1403
|
default:
|
1404
|
-
error( "Unhandled switch event (type =
|
1404
|
+
error( "Unhandled switch event ( type = %#x ).", type );
|
1405
1405
|
break;
|
1406
1406
|
}
|
1407
1407
|
|
@@ -1543,7 +1543,7 @@ handle_openflow_message( void *data, size_t length ) {
|
|
1543
1543
|
ret = validate_openflow_message( buffer );
|
1544
1544
|
|
1545
1545
|
if ( ret < 0 ) {
|
1546
|
-
error( "Failed to validate an OpenFlow message ( code = %d, length = %
|
1546
|
+
error( "Failed to validate an OpenFlow message ( code = %d, length = %zu ).", ret, length );
|
1547
1547
|
free_buffer( buffer );
|
1548
1548
|
|
1549
1549
|
return;
|
@@ -1586,7 +1586,7 @@ handle_openflow_message( void *data, size_t length ) {
|
|
1586
1586
|
handle_queue_get_config_reply( datapath_id, buffer );
|
1587
1587
|
break;
|
1588
1588
|
default:
|
1589
|
-
error( "Unhandled OpenFlow message ( type =
|
1589
|
+
error( "Unhandled OpenFlow message ( type = %#x ).", header->type );
|
1590
1590
|
break;
|
1591
1591
|
}
|
1592
1592
|
|
@@ -1601,7 +1601,7 @@ handle_message( uint16_t type, void *data, size_t length ) {
|
|
1601
1601
|
assert( data != NULL );
|
1602
1602
|
assert( length >= sizeof( openflow_service_header_t ) );
|
1603
1603
|
|
1604
|
-
debug( "A message is received from remote ( type =
|
1604
|
+
debug( "A message is received from remote ( type = %#x ).", type );
|
1605
1605
|
|
1606
1606
|
switch ( type ) {
|
1607
1607
|
case MESSENGER_OPENFLOW_MESSAGE:
|
@@ -1612,7 +1612,7 @@ handle_message( uint16_t type, void *data, size_t length ) {
|
|
1612
1612
|
case MESSENGER_OPENFLOW_DISCONNECTED:
|
1613
1613
|
return handle_switch_events( type, data, length );
|
1614
1614
|
default:
|
1615
|
-
error( "Unhandled message ( type =
|
1615
|
+
error( "Unhandled message ( type = %#x ).", type );
|
1616
1616
|
update_switch_event_stats( type, OPENFLOW_MESSAGE_RECEIVE, true );
|
1617
1617
|
break;
|
1618
1618
|
}
|
@@ -1647,10 +1647,10 @@ handle_list_switches_reply( uint16_t message_type, void *data, size_t length, vo
|
|
1647
1647
|
UNUSED( message_type );
|
1648
1648
|
assert( data != NULL );
|
1649
1649
|
|
1650
|
-
uint64_t *dpid = ( uint64_t *) data;
|
1650
|
+
uint64_t *dpid = ( uint64_t * ) data;
|
1651
1651
|
size_t num_switch = length / sizeof( uint64_t );
|
1652
1652
|
|
1653
|
-
debug( "A list switches reply message is received ( number of switches = %
|
1653
|
+
debug( "A list switches reply message is received ( number of switches = %zu ).",
|
1654
1654
|
num_switch );
|
1655
1655
|
|
1656
1656
|
if ( event_handlers.list_switches_reply_callback == NULL ) {
|
@@ -1663,7 +1663,7 @@ handle_list_switches_reply( uint16_t message_type, void *data, size_t length, vo
|
|
1663
1663
|
|
1664
1664
|
unsigned int i;
|
1665
1665
|
for ( i = 0; i < num_switch; ++i ) {
|
1666
|
-
uint64_t *datapath_id = ( uint64_t *) xmalloc( sizeof( uint64_t ) );
|
1666
|
+
uint64_t *datapath_id = ( uint64_t * ) xmalloc( sizeof( uint64_t ) );
|
1667
1667
|
*datapath_id = ntohll( dpid[ i ] );
|
1668
1668
|
insert_dpid( &switches, datapath_id );
|
1669
1669
|
}
|
data/src/lib/openflow_message.c
CHANGED
@@ -57,10 +57,12 @@ extern void mock_debug( const char *format, ... );
|
|
57
57
|
#endif // UNIT_TESTING
|
58
58
|
|
59
59
|
|
60
|
-
#define VLAN_VID_MASK 0x0fff
|
61
|
-
#define VLAN_PCP_MASK 0x07
|
62
|
-
#define NW_TOS_MASK 0xfc
|
63
|
-
#define ARP_OP_MASK 0x00ff
|
60
|
+
#define VLAN_VID_MASK 0x0fff // 12 bits
|
61
|
+
#define VLAN_PCP_MASK 0x07 // 3 bits
|
62
|
+
#define NW_TOS_MASK 0xfc // upper 6 bits
|
63
|
+
#define ARP_OP_MASK 0x00ff // 8 bits
|
64
|
+
#define ICMP_TYPE_MASK 0x00ff // 8 bits
|
65
|
+
#define ICMP_CODE_MASK 0x00ff // 8 bits
|
64
66
|
|
65
67
|
#define PORT_CONFIG ( OFPPC_PORT_DOWN | OFPPC_NO_STP | OFPPC_NO_RECV \
|
66
68
|
| OFPPC_NO_RECV_STP | OFPPC_NO_FLOOD | OFPPC_NO_FWD \
|
@@ -104,7 +106,7 @@ init_openflow_message( void ) {
|
|
104
106
|
|
105
107
|
static buffer *
|
106
108
|
create_header( const uint32_t transaction_id, const uint8_t type, const uint16_t length ) {
|
107
|
-
debug( "Creating an OpenFlow header (version = %#x, type = %#x, length = %u, xid = %#x).",
|
109
|
+
debug( "Creating an OpenFlow header ( version = %#x, type = %#x, length = %u, xid = %#x ).",
|
108
110
|
OFP_VERSION, type, length, transaction_id );
|
109
111
|
|
110
112
|
assert( length >= sizeof( struct ofp_header ) );
|
@@ -291,7 +293,7 @@ create_features_reply( const uint32_t transaction_id, const uint64_t datapath_id
|
|
291
293
|
|
292
294
|
if ( n_ports ) {
|
293
295
|
phy_port = ( struct ofp_phy_port * ) ( ( char * ) buffer->data
|
294
|
-
+ offsetof( struct ofp_switch_features, ports) );
|
296
|
+
+ offsetof( struct ofp_switch_features, ports ) );
|
295
297
|
port = p;
|
296
298
|
while ( port != NULL ) {
|
297
299
|
phy_port_to_string( port->data, port_str, sizeof( port_str ) );
|
@@ -433,7 +435,7 @@ create_flow_removed( const uint32_t transaction_id, const struct ofp_match match
|
|
433
435
|
|
434
436
|
buffer *
|
435
437
|
create_port_status( const uint32_t transaction_id, const uint8_t reason,
|
436
|
-
const struct ofp_phy_port desc) {
|
438
|
+
const struct ofp_phy_port desc ) {
|
437
439
|
char desc_str[ 1024 ];
|
438
440
|
buffer *buffer;
|
439
441
|
struct ofp_phy_port d = desc;
|
@@ -480,10 +482,10 @@ get_actions_length( const openflow_actions *actions ) {
|
|
480
482
|
action = action->next;
|
481
483
|
}
|
482
484
|
|
483
|
-
debug( "Total length of actions = %
|
485
|
+
debug( "Total length of actions = %d.", actions_length );
|
484
486
|
|
485
487
|
if ( actions_length > UINT16_MAX ) {
|
486
|
-
critical( "Too many actions ( # of actions = %d, actions length = %
|
488
|
+
critical( "Too many actions ( # of actions = %d, actions length = %d ).",
|
487
489
|
actions->n_actions, actions_length );
|
488
490
|
assert( 0 );
|
489
491
|
}
|
@@ -585,7 +587,7 @@ create_flow_mod( const uint32_t transaction_id, const struct ofp_match match,
|
|
585
587
|
"buffer_id = %#x, out_port = %u, flags = %#x ).",
|
586
588
|
transaction_id, match_str, cookie, command,
|
587
589
|
idle_timeout, hard_timeout, priority,
|
588
|
-
buffer_id, out_port, flags
|
590
|
+
buffer_id, out_port, flags );
|
589
591
|
}
|
590
592
|
|
591
593
|
if ( actions != NULL ) {
|
@@ -922,7 +924,7 @@ create_flow_stats_reply( const uint32_t transaction_id, const uint16_t flags,
|
|
922
924
|
flow = flow->next;
|
923
925
|
}
|
924
926
|
|
925
|
-
debug( "# of flows = %
|
927
|
+
debug( "# of flows = %d.", n_flows );
|
926
928
|
|
927
929
|
length = ( uint16_t ) ( offsetof( struct ofp_stats_reply, body ) + length );
|
928
930
|
|
@@ -1635,7 +1637,7 @@ append_action_vendor( openflow_actions *actions, const uint32_t vendor, const bu
|
|
1635
1637
|
body_length = ( uint16_t ) body->length;
|
1636
1638
|
}
|
1637
1639
|
|
1638
|
-
debug( "Appending a vendor action ( vendor = %#"
|
1640
|
+
debug( "Appending a vendor action ( vendor = %#" PRIx32 ", body length = %u ).", vendor, body_length );
|
1639
1641
|
|
1640
1642
|
assert( actions != NULL );
|
1641
1643
|
|
@@ -1645,6 +1647,10 @@ append_action_vendor( openflow_actions *actions, const uint32_t vendor, const bu
|
|
1645
1647
|
action_vendor->len = ( uint16_t ) ( sizeof( struct ofp_action_vendor_header ) + body_length );
|
1646
1648
|
action_vendor->vendor = vendor;
|
1647
1649
|
|
1650
|
+
if ( body_length > 0 ) {
|
1651
|
+
memcpy( ( char * ) action_vendor + sizeof( struct ofp_action_vendor_header ), body->data, body_length );
|
1652
|
+
}
|
1653
|
+
|
1648
1654
|
ret = append_to_tail( &actions->list, ( void * ) action_vendor );
|
1649
1655
|
if ( ret ) {
|
1650
1656
|
actions->n_actions++;
|
@@ -3447,18 +3453,14 @@ validate_action_enqueue( const struct ofp_action_enqueue *action ) {
|
|
3447
3453
|
|
3448
3454
|
int
|
3449
3455
|
validate_action_vendor( const struct ofp_action_vendor_header *action ) {
|
3450
|
-
|
3451
|
-
|
3452
|
-
ntoh_action_vendor( &vendor, action );
|
3453
|
-
|
3454
|
-
if ( vendor.type != OFPAT_VENDOR ) {
|
3456
|
+
if ( ntohs( action->type ) != OFPAT_VENDOR ) {
|
3455
3457
|
return ERROR_INVALID_ACTION_TYPE;
|
3456
3458
|
}
|
3457
|
-
if (
|
3459
|
+
if ( ntohs( action->len ) < sizeof( struct ofp_action_vendor_header ) ) {
|
3458
3460
|
return ERROR_TOO_SHORT_ACTION_VENDOR;
|
3459
3461
|
}
|
3460
3462
|
|
3461
|
-
// vendor
|
3463
|
+
// action->vendor
|
3462
3464
|
|
3463
3465
|
return 0;
|
3464
3466
|
}
|
@@ -3929,6 +3931,7 @@ set_match_from_packet( struct ofp_match *match, const uint16_t in_port,
|
|
3929
3931
|
const uint32_t wildcards, const buffer *packet ) {
|
3930
3932
|
// Note that wildcards must be filled before calling this function.
|
3931
3933
|
|
3934
|
+
assert( match != NULL );
|
3932
3935
|
assert( packet != NULL );
|
3933
3936
|
assert( packet->user_data != NULL );
|
3934
3937
|
|
@@ -3948,8 +3951,8 @@ set_match_from_packet( struct ofp_match *match, const uint16_t in_port,
|
|
3948
3951
|
if ( packet_type_eth_vtag( packet ) ) {
|
3949
3952
|
match->dl_vlan = ( ( packet_info * ) packet->user_data )->vlan_vid;
|
3950
3953
|
if ( ( match->dl_vlan & ~VLAN_VID_MASK ) != 0 ) {
|
3951
|
-
warn( "Invalid vlan id ( change
|
3952
|
-
|
3954
|
+
warn( "Invalid vlan id ( change %#x to %#x )", match->dl_vlan, match->dl_vlan & VLAN_VID_MASK );
|
3955
|
+
match->dl_vlan = ( uint16_t ) ( match->dl_vlan & VLAN_VID_MASK );
|
3953
3956
|
}
|
3954
3957
|
}
|
3955
3958
|
else {
|
@@ -3961,7 +3964,7 @@ set_match_from_packet( struct ofp_match *match, const uint16_t in_port,
|
|
3961
3964
|
match->dl_vlan_pcp = ( ( packet_info * ) packet->user_data )->vlan_prio;
|
3962
3965
|
if ( ( match->dl_vlan_pcp & ~VLAN_PCP_MASK ) != 0 ) {
|
3963
3966
|
warn( "Invalid vlan pcp ( change %u to %u )", match->dl_vlan_pcp, match->dl_vlan_pcp & VLAN_PCP_MASK );
|
3964
|
-
|
3967
|
+
match->dl_vlan_pcp = ( uint8_t ) ( match->dl_vlan_pcp & VLAN_PCP_MASK );
|
3965
3968
|
}
|
3966
3969
|
}
|
3967
3970
|
}
|
@@ -3972,7 +3975,7 @@ set_match_from_packet( struct ofp_match *match, const uint16_t in_port,
|
|
3972
3975
|
if ( !( wildcards & OFPFW_NW_TOS ) ) {
|
3973
3976
|
match->nw_tos = ( ( packet_info * ) packet->user_data )->ipv4_tos;
|
3974
3977
|
if ( ( match->nw_tos & ~NW_TOS_MASK ) != 0 ) {
|
3975
|
-
warn( "Invalid ipv4 tos ( change
|
3978
|
+
warn( "Invalid ipv4 tos ( change %#x to %#x )", match->nw_tos, match->nw_tos & NW_TOS_MASK );
|
3976
3979
|
match->nw_tos = ( uint8_t ) ( match->nw_tos & NW_TOS_MASK );
|
3977
3980
|
}
|
3978
3981
|
}
|
@@ -4034,6 +4037,155 @@ set_match_from_packet( struct ofp_match *match, const uint16_t in_port,
|
|
4034
4037
|
}
|
4035
4038
|
|
4036
4039
|
|
4040
|
+
void
|
4041
|
+
normalize_match( struct ofp_match *match ) {
|
4042
|
+
|
4043
|
+
assert( match != NULL );
|
4044
|
+
|
4045
|
+
char match_string[ 1024 ];
|
4046
|
+
match_to_string( match, match_string, sizeof( match_string ) );
|
4047
|
+
debug( "Normalizing match structure ( original match = [%s] ).", match_string );
|
4048
|
+
|
4049
|
+
memset( match->pad1, 0, sizeof( match->pad1 ) );
|
4050
|
+
memset( match->pad2, 0, sizeof( match->pad2 ) );
|
4051
|
+
|
4052
|
+
match->wildcards &= OFPFW_ALL;
|
4053
|
+
|
4054
|
+
if ( match->wildcards & OFPFW_IN_PORT ) {
|
4055
|
+
match->in_port = 0;
|
4056
|
+
}
|
4057
|
+
if ( match->wildcards & OFPFW_DL_VLAN ) {
|
4058
|
+
match->dl_vlan = 0;
|
4059
|
+
}
|
4060
|
+
else {
|
4061
|
+
if ( match->dl_vlan == UINT16_MAX ) {
|
4062
|
+
match->wildcards |= ( uint32_t ) OFPFW_DL_VLAN_PCP;
|
4063
|
+
match->dl_vlan_pcp = 0;
|
4064
|
+
}
|
4065
|
+
else {
|
4066
|
+
match->dl_vlan &= VLAN_VID_MASK;
|
4067
|
+
}
|
4068
|
+
}
|
4069
|
+
if ( match->wildcards & OFPFW_DL_SRC ) {
|
4070
|
+
memset( match->dl_src, 0, sizeof( match->dl_src ) );
|
4071
|
+
}
|
4072
|
+
if ( match->wildcards & OFPFW_DL_DST ) {
|
4073
|
+
memset( match->dl_dst, 0, sizeof( match->dl_dst ) );
|
4074
|
+
}
|
4075
|
+
if ( match->wildcards & OFPFW_DL_TYPE ) {
|
4076
|
+
match->dl_type = 0;
|
4077
|
+
match->wildcards |= ( uint32_t ) OFPFW_NW_TOS;
|
4078
|
+
match->wildcards |= ( uint32_t ) OFPFW_NW_PROTO;
|
4079
|
+
match->wildcards |= ( uint32_t ) OFPFW_NW_SRC_MASK;
|
4080
|
+
match->wildcards |= ( uint32_t ) OFPFW_NW_DST_MASK;
|
4081
|
+
match->wildcards |= ( uint32_t ) OFPFW_TP_SRC;
|
4082
|
+
match->wildcards |= ( uint32_t ) OFPFW_TP_DST;
|
4083
|
+
match->nw_tos = 0;
|
4084
|
+
match->nw_proto = 0;
|
4085
|
+
match->nw_src = 0;
|
4086
|
+
match->nw_dst = 0;
|
4087
|
+
match->tp_src = 0;
|
4088
|
+
match->tp_dst = 0;
|
4089
|
+
}
|
4090
|
+
else {
|
4091
|
+
if ( match->dl_type == ETH_ETHTYPE_ARP ) {
|
4092
|
+
match->wildcards |= ( uint32_t ) OFPFW_NW_TOS;
|
4093
|
+
match->wildcards |= ( uint32_t ) OFPFW_TP_SRC;
|
4094
|
+
match->wildcards |= ( uint32_t ) OFPFW_TP_DST;
|
4095
|
+
match->nw_tos = 0;
|
4096
|
+
match->tp_src = 0;
|
4097
|
+
match->tp_dst = 0;
|
4098
|
+
}
|
4099
|
+
else if ( match->dl_type != ETH_ETHTYPE_IPV4 ) {
|
4100
|
+
match->wildcards |= ( uint32_t ) OFPFW_NW_TOS;
|
4101
|
+
match->wildcards |= ( uint32_t ) OFPFW_NW_PROTO;
|
4102
|
+
match->wildcards |= ( uint32_t ) OFPFW_NW_SRC_MASK;
|
4103
|
+
match->wildcards |= ( uint32_t ) OFPFW_NW_DST_MASK;
|
4104
|
+
match->wildcards |= ( uint32_t ) OFPFW_TP_SRC;
|
4105
|
+
match->wildcards |= ( uint32_t ) OFPFW_TP_DST;
|
4106
|
+
match->nw_tos = 0;
|
4107
|
+
match->nw_proto = 0;
|
4108
|
+
match->nw_src = 0;
|
4109
|
+
match->nw_dst = 0;
|
4110
|
+
match->tp_src = 0;
|
4111
|
+
match->tp_dst = 0;
|
4112
|
+
}
|
4113
|
+
}
|
4114
|
+
if ( match->wildcards & OFPFW_NW_PROTO ) {
|
4115
|
+
match->nw_proto = 0;
|
4116
|
+
if ( match->dl_type != ETH_ETHTYPE_IPV4 ) {
|
4117
|
+
match->wildcards |= ( uint32_t ) OFPFW_TP_SRC;
|
4118
|
+
match->wildcards |= ( uint32_t ) OFPFW_TP_DST;
|
4119
|
+
match->tp_src = 0;
|
4120
|
+
match->tp_dst = 0;
|
4121
|
+
}
|
4122
|
+
}
|
4123
|
+
else {
|
4124
|
+
if ( match->dl_type == ETH_ETHTYPE_ARP ) {
|
4125
|
+
match->nw_proto &= ARP_OP_MASK;
|
4126
|
+
}
|
4127
|
+
if ( match->dl_type == ETH_ETHTYPE_IPV4 &&
|
4128
|
+
match->nw_proto != IPPROTO_TCP && match->nw_proto != IPPROTO_UDP && match->nw_proto != IPPROTO_ICMP ) {
|
4129
|
+
match->wildcards |= ( uint32_t ) OFPFW_TP_SRC;
|
4130
|
+
match->wildcards |= ( uint32_t ) OFPFW_TP_DST;
|
4131
|
+
match->tp_src = 0;
|
4132
|
+
match->tp_dst = 0;
|
4133
|
+
}
|
4134
|
+
}
|
4135
|
+
|
4136
|
+
unsigned int nw_src_mask_len = ( match->wildcards & OFPFW_NW_SRC_MASK ) >> OFPFW_NW_SRC_SHIFT;
|
4137
|
+
if ( nw_src_mask_len >= 32 ) {
|
4138
|
+
match->wildcards &= ( uint32_t ) ~OFPFW_NW_SRC_MASK;
|
4139
|
+
match->wildcards |= OFPFW_NW_SRC_ALL;
|
4140
|
+
match->nw_src = 0;
|
4141
|
+
}
|
4142
|
+
else {
|
4143
|
+
match->nw_src &= ( 0xffffffff << nw_src_mask_len );
|
4144
|
+
}
|
4145
|
+
unsigned int nw_dst_mask_len = ( match->wildcards & OFPFW_NW_DST_MASK ) >> OFPFW_NW_DST_SHIFT;
|
4146
|
+
if ( nw_dst_mask_len >= 32 ) {
|
4147
|
+
match->wildcards &= ( uint32_t ) ~OFPFW_NW_DST_MASK;
|
4148
|
+
match->wildcards |= OFPFW_NW_DST_ALL;
|
4149
|
+
match->nw_dst = 0;
|
4150
|
+
}
|
4151
|
+
else {
|
4152
|
+
match->nw_dst &= ( 0xffffffff << nw_dst_mask_len );
|
4153
|
+
}
|
4154
|
+
if ( match->wildcards & OFPFW_TP_SRC ) {
|
4155
|
+
match->tp_src = 0;
|
4156
|
+
}
|
4157
|
+
else {
|
4158
|
+
if ( match->nw_proto == IPPROTO_ICMP ) {
|
4159
|
+
match->tp_src &= ICMP_TYPE_MASK;
|
4160
|
+
}
|
4161
|
+
}
|
4162
|
+
if ( match->wildcards & OFPFW_TP_DST ) {
|
4163
|
+
match->tp_dst = 0;
|
4164
|
+
}
|
4165
|
+
else {
|
4166
|
+
if ( match->nw_proto == IPPROTO_ICMP ) {
|
4167
|
+
match->tp_dst &= ICMP_CODE_MASK;
|
4168
|
+
}
|
4169
|
+
}
|
4170
|
+
|
4171
|
+
if ( match->wildcards & OFPFW_DL_VLAN_PCP ) {
|
4172
|
+
match->dl_vlan_pcp = 0;
|
4173
|
+
}
|
4174
|
+
else {
|
4175
|
+
match->dl_vlan_pcp &= VLAN_PCP_MASK;
|
4176
|
+
}
|
4177
|
+
if ( match->wildcards & OFPFW_NW_TOS ) {
|
4178
|
+
match->nw_tos = 0;
|
4179
|
+
}
|
4180
|
+
else {
|
4181
|
+
match->nw_tos &= NW_TOS_MASK;
|
4182
|
+
}
|
4183
|
+
|
4184
|
+
match_to_string( match, match_string, sizeof( match_string ) );
|
4185
|
+
debug( "Normalization completed ( updated match = [%s] ).", match_string );
|
4186
|
+
}
|
4187
|
+
|
4188
|
+
|
4037
4189
|
/*
|
4038
4190
|
* Local variables:
|
4039
4191
|
* c-basic-offset: 2
|