trema 0.2.2.1 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitmodules +3 -0
- data/.travis.yml +13 -0
- data/.yardopts +4 -0
- data/Gemfile +2 -3
- data/README.md +43 -97
- data/Rakefile +60 -4
- data/Rantfile +11 -10
- data/cruise.rb +4 -6
- data/features/example.packetin_filter_config.feature +10 -10
- data/features/example.switch_monitor.feature +14 -2
- data/features/step_definitions/kill_steps.rb +2 -2
- data/features/step_definitions/{off_steps.rb → killall_steps.rb} +2 -2
- data/features/step_definitions/misc_steps.rb +1 -1
- data/features/step_definitions/up_steps.rb +30 -0
- data/features/trema.feature +1 -0
- data/features/trema.run.feature +1 -0
- data/locale/README.ja.md +19 -0
- data/locale/ja/yard.po +3762 -0
- data/locale/yard.pot +3740 -0
- data/ruby/extconf.rb +4 -1
- data/ruby/trema/action-common.c +3 -17
- data/ruby/trema/action-common.h +3 -7
- data/ruby/trema/action.rb +33 -0
- data/ruby/trema/app.rb +1 -1
- data/ruby/trema/barrier-request.c +1 -0
- data/ruby/trema/command/run.rb +13 -9
- data/ruby/trema/command/usage.rb +1 -0
- data/ruby/trema/command/version.rb +1 -1
- data/ruby/trema/controller.c +133 -50
- data/ruby/trema/controller.rb +2 -2
- data/ruby/trema/desc-stats-reply.rb +77 -0
- data/ruby/trema/dsl/configuration.rb +3 -14
- data/ruby/trema/dsl/rswitch.rb +47 -0
- data/ruby/trema/dsl/runner.rb +4 -1
- data/ruby/trema/dsl/syntax.rb +11 -8
- data/ruby/trema/echo-reply.c +59 -45
- data/ruby/trema/echo-reply.h +1 -3
- data/ruby/trema/echo-request.c +49 -71
- data/ruby/trema/echo-request.h +0 -2
- data/ruby/trema/echo.c +99 -0
- data/ruby/trema/{action-enqueue.h → echo.h} +6 -7
- data/ruby/trema/enqueue.rb +87 -0
- data/ruby/trema/error.c +109 -104
- data/ruby/trema/error.h +0 -2
- data/ruby/trema/features-reply.c +89 -35
- data/ruby/trema/features-reply.h +0 -6
- data/ruby/trema/features-request.c +63 -37
- data/ruby/trema/features-request.h +0 -2
- data/ruby/trema/flow-mod.c +149 -0
- data/ruby/trema/{action-output.h → flow-mod.h} +6 -6
- data/ruby/trema/get-config-request.c +1 -0
- data/ruby/trema/hardware-switch.rb +88 -0
- data/ruby/trema/hello.c +55 -31
- data/ruby/trema/hello.h +0 -2
- data/ruby/trema/ip.rb +12 -2
- data/ruby/trema/logger.rb +29 -0
- data/ruby/trema/mac.rb +57 -36
- data/ruby/trema/match.c +7 -9
- data/ruby/trema/monkey-patch/integer/ranges.rb +0 -2
- data/ruby/trema/network-component.rb +1 -1
- data/ruby/trema/open-vswitch.rb +2 -2
- data/ruby/trema/openflow-switch.rb +3 -54
- data/ruby/trema/{packet_in.c → packet-in.c} +262 -175
- data/ruby/trema/{packet_in.h → packet-in.h} +0 -2
- data/ruby/trema/packet-queue.rb +4 -3
- data/ruby/trema/port-mod.c +8 -9
- data/ruby/trema/port-status-add.rb +60 -0
- data/ruby/trema/port-status-delete.rb +60 -0
- data/ruby/trema/port-status-modify.rb +60 -0
- data/ruby/trema/port-status.c +48 -15
- data/ruby/trema/port-status.h +6 -8
- data/ruby/trema/port.c +63 -8
- data/ruby/trema/queue-get-config-request.c +1 -0
- data/ruby/trema/ruby-switch.rb +62 -0
- data/ruby/trema/send-out-port.rb +97 -0
- data/ruby/trema/set-config.c +1 -0
- data/ruby/trema/set-eth-addr.rb +45 -0
- data/ruby/trema/set-eth-dst-addr.rb +54 -0
- data/ruby/trema/set-eth-src-addr.rb +54 -0
- data/ruby/trema/set-ip-addr.rb +47 -0
- data/ruby/trema/set-ip-dst-addr.rb +53 -0
- data/ruby/trema/set-ip-src-addr.rb +52 -0
- data/ruby/trema/set-ip-tos.rb +63 -0
- data/ruby/trema/set-transport-dst-port.rb +53 -0
- data/ruby/trema/set-transport-port.rb +52 -0
- data/ruby/trema/set-transport-src-port.rb +54 -0
- data/ruby/trema/set-vlan-priority.rb +65 -0
- data/ruby/trema/set-vlan-vid.rb +64 -0
- data/ruby/trema/shell/down.rb +1 -1
- data/ruby/trema/shell/link.rb +4 -4
- data/ruby/trema/shell/run.rb +8 -6
- data/ruby/trema/shell/up.rb +3 -3
- data/ruby/trema/stats-reply.c +27 -2
- data/ruby/trema/stats-request.c +64 -23
- data/ruby/trema/strip-vlan-header.rb +41 -0
- data/ruby/trema/switch.c +196 -0
- data/ruby/trema/{action-vendor.h → switch.h} +5 -7
- data/ruby/trema/switch.rb +28 -9
- data/ruby/trema/trema-ruby-utils.c +66 -0
- data/ruby/trema/{action-set-dl-src.h → trema-ruby-utils.h} +9 -11
- data/ruby/trema/trema.c +61 -61
- data/ruby/trema/vendor-action.rb +73 -0
- data/ruby/trema/vendor.c +121 -52
- data/ruby/trema/vendor.h +6 -10
- data/ruby/trema/version.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/support/action.rb +52 -0
- data/spec/support/mandatory-option.rb +56 -0
- data/spec/support/openflow-message.rb +91 -7
- data/spec/support/port-status.rb +38 -0
- data/spec/trema/controller_spec.rb +0 -26
- data/spec/trema/dsl/configuration_spec.rb +3 -3
- data/spec/trema/dsl/runner_spec.rb +12 -32
- data/spec/trema/dsl/syntax_spec.rb +2 -11
- data/spec/trema/echo-reply_spec.rb +49 -14
- data/spec/trema/echo-request_spec.rb +86 -34
- data/spec/trema/enqueue_spec.rb +76 -0
- data/spec/trema/error_spec.rb +43 -58
- data/spec/trema/features-reply_spec.rb +58 -24
- data/spec/trema/features-request_spec.rb +54 -28
- data/spec/trema/flow-mod_spec.rb +99 -0
- data/spec/trema/{openflow-switch_spec.rb → hardware-switch_spec.rb} +3 -3
- data/spec/trema/hello_spec.rb +28 -14
- data/spec/trema/ip_spec.rb +54 -0
- data/spec/trema/mac_spec.rb +49 -64
- data/spec/trema/match_spec.rb +1 -1
- data/spec/trema/open-vswitch_spec.rb +7 -7
- data/spec/trema/packet-in_spec.rb +73 -16
- data/spec/trema/port-status-add_spec.rb +32 -0
- data/spec/trema/port-status-delete_spec.rb +32 -0
- data/spec/trema/port-status-modify_spec.rb +71 -0
- data/spec/trema/port-status_spec.rb +5 -76
- data/spec/trema/{action-output_spec.rb → send-out-port_spec.rb} +20 -47
- data/spec/trema/set-eth-dst-addr_spec.rb +75 -0
- data/spec/trema/set-eth-src-addr_spec.rb +72 -0
- data/spec/trema/set-ip-dst-addr_spec.rb +58 -0
- data/spec/trema/set-ip-src-addr_spec.rb +58 -0
- data/spec/trema/set-ip-tos_spec.rb +65 -0
- data/spec/trema/set-transport-dst-port_spec.rb +65 -0
- data/spec/trema/set-transport-src-port_spec.rb +65 -0
- data/spec/trema/set-vlan-priority_spec.rb +65 -0
- data/spec/trema/set-vlan-vid_spec.rb +65 -0
- data/spec/trema/shell/vhost_spec.rb +4 -1
- data/spec/trema/shell/vswitch_spec.rb +11 -11
- data/spec/trema/stats-reply_spec.rb +59 -13
- data/spec/trema/stats-request_spec.rb +6 -0
- data/spec/trema/{action-strip-vlan_spec.rb → strip-vlan-header_spec.rb} +3 -17
- data/spec/trema/switch-daemon_spec.rb +39 -0
- data/spec/trema/vendor-action_spec.rb +81 -0
- data/spec/trema/vendor_spec.rb +76 -0
- data/spec/trema_spec.rb +56 -0
- data/src/examples/dumper/dumper.c +0 -8
- data/src/examples/dumper/dumper.rb +52 -52
- data/src/examples/hello_trema/hello_trema.c +0 -2
- data/src/examples/learning_switch/learning-switch.rb +3 -3
- data/src/examples/multi_learning_switch/multi-learning-switch.rb +3 -3
- data/src/examples/openflow_message/features-request.rb +3 -3
- data/src/examples/packetin_filter_config/utils.c +4 -4
- data/src/examples/repeater_hub/repeater-hub.rb +3 -3
- data/src/examples/switch_info/switch_info.rb +2 -2
- data/src/examples/switch_monitor/switch_monitor.c +1 -1
- data/src/examples/traffic_monitor/traffic-monitor.rb +3 -3
- data/src/lib/arp.h +4 -1
- data/src/lib/chibach.c +391 -0
- data/src/lib/chibach.h +71 -0
- data/src/lib/chibach_private.c +170 -0
- data/src/lib/chibach_private.h +52 -0
- data/src/lib/ether.c +2 -1
- data/src/lib/ether.h +0 -1
- data/src/lib/ipv4.h +13 -14
- data/{ruby/trema/action-set-nw-src.h → src/lib/ipv6.h} +13 -9
- data/src/lib/log.c +161 -58
- data/src/lib/log.h +11 -16
- data/src/lib/messenger.c +36 -1
- data/src/lib/messenger.h +1 -0
- data/src/lib/openflow_application_interface.c +128 -28
- data/src/lib/openflow_application_interface.h +31 -6
- data/src/lib/openflow_message.c +2 -1
- data/src/lib/openflow_service_interface.h +1 -0
- data/src/lib/openflow_switch_interface.c +1380 -0
- data/src/lib/openflow_switch_interface.h +264 -0
- data/src/lib/packet_info.c +94 -11
- data/src/lib/packet_info.h +22 -3
- data/src/lib/packet_parser.c +38 -2
- data/src/lib/secure_channel.c +498 -0
- data/{ruby/trema/vendor-request.h → src/lib/secure_channel.h} +11 -10
- data/src/lib/tcp.h +0 -3
- data/src/lib/trema.c +38 -5
- data/{ruby/trema/action-set-nw-dst.h → src/lib/trema.hpp} +17 -8
- data/src/lib/trema_wrapper.c +5 -0
- data/src/lib/trema_wrapper.h +4 -0
- data/src/lib/utility.c +93 -4
- data/src/lib/utility.h +1 -0
- data/src/lib/wrapper.c +30 -7
- data/src/lib/wrapper.h +2 -0
- data/src/switch_manager/ofpmsg_recv.c +44 -30
- data/src/switch_manager/ofpmsg_send.c +40 -1
- data/src/switch_manager/ofpmsg_send.h +2 -0
- data/src/switch_manager/switch.c +153 -8
- data/src/switch_manager/switch.h +1 -0
- data/src/switch_manager/switchinfo.h +5 -0
- data/src/tremashark/README +2 -2
- data/src/tremashark/plugin/packet-trema/packet-trema.c +1 -0
- data/trema +1 -1
- data/unittests/lib/log_test.c +158 -34
- data/unittests/lib/openflow_application_interface_test.c +252 -69
- data/unittests/lib/openflow_message_test.c +3 -1
- data/unittests/lib/packet_parser_test.c +60 -15
- 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/trema_test.c +2 -0
- data/unittests/lib/utility_test.c +65 -2
- data/unittests/lib/wrapper_test.c +29 -0
- data/vendor/{README → README.md} +2 -12
- data/vendor/packet-openflow.diff +13 -0
- metadata +86 -53
- data/GPL2 +0 -339
- data/ruby/trema/action-enqueue.c +0 -161
- data/ruby/trema/action-output.c +0 -169
- data/ruby/trema/action-set-dl-dst.c +0 -131
- data/ruby/trema/action-set-dl-dst.h +0 -44
- data/ruby/trema/action-set-dl-src.c +0 -131
- data/ruby/trema/action-set-nw-dst.c +0 -135
- data/ruby/trema/action-set-nw-src.c +0 -140
- data/ruby/trema/action-set-nw-tos.c +0 -124
- data/ruby/trema/action-set-nw-tos.h +0 -42
- data/ruby/trema/action-set-tp-dst.c +0 -122
- data/ruby/trema/action-set-tp-dst.h +0 -42
- data/ruby/trema/action-set-tp-src.c +0 -124
- data/ruby/trema/action-set-tp-src.h +0 -42
- data/ruby/trema/action-set-vlan-pcp.c +0 -128
- data/ruby/trema/action-set-vlan-pcp.h +0 -42
- data/ruby/trema/action-set-vlan-vid.c +0 -125
- data/ruby/trema/action-set-vlan-vid.h +0 -42
- data/ruby/trema/action-strip-vlan.c +0 -81
- data/ruby/trema/action-strip-vlan.h +0 -42
- data/ruby/trema/action-vendor.c +0 -121
- data/ruby/trema/vendor-request.c +0 -193
- data/spec/trema/action-enqueue_spec.rb +0 -100
- data/spec/trema/action-set-dl-dst_spec.rb +0 -95
- data/spec/trema/action-set-dl-src_spec.rb +0 -92
- data/spec/trema/action-set-nw-dst_spec.rb +0 -96
- data/spec/trema/action-set-nw-src_spec.rb +0 -97
- data/spec/trema/action-set-nw-tos_spec.rb +0 -88
- data/spec/trema/action-set-tp-dst_spec.rb +0 -88
- data/spec/trema/action-set-tp-src_spec.rb +0 -88
- data/spec/trema/action-set-vlan-pcp_spec.rb +0 -91
- data/spec/trema/action-set-vlan-vid_spec.rb +0 -91
- data/spec/trema/action-vendor_spec.rb +0 -90
- data/spec/trema/vendor-request_spec.rb +0 -79
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
|
-
*
|
2
|
+
* OpenFlow Switch Listener
|
3
3
|
*
|
4
|
-
* Author:
|
4
|
+
* Author: Yasunobu Chiba
|
5
5
|
*
|
6
6
|
* Copyright (C) 2008-2012 NEC Corporation
|
7
7
|
*
|
@@ -20,20 +20,21 @@
|
|
20
20
|
*/
|
21
21
|
|
22
22
|
|
23
|
-
#ifndef
|
24
|
-
#define
|
23
|
+
#ifndef SECURE_CANNEL_H
|
24
|
+
#define SECURE_CANNEL_H
|
25
25
|
|
26
26
|
|
27
|
-
|
27
|
+
typedef void ( *connected_handler )( void );
|
28
|
+
typedef void ( *disconnected_handler ) ( void );
|
28
29
|
|
29
30
|
|
30
|
-
|
31
|
+
bool init_secure_channel( uint32_t ip, uint16_t port,
|
32
|
+
connected_handler connected_callback, disconnected_handler disconnected_callback );
|
33
|
+
bool finalize_secure_channel();
|
34
|
+
bool send_message_to_secure_channel( buffer *message );
|
31
35
|
|
32
36
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
#endif // VENDOR_REQUEST_H
|
37
|
+
#endif // SECURE_CANNEL_H
|
37
38
|
|
38
39
|
|
39
40
|
/*
|
data/src/lib/tcp.h
CHANGED
data/src/lib/trema.c
CHANGED
@@ -50,7 +50,7 @@
|
|
50
50
|
#undef init_log
|
51
51
|
#endif
|
52
52
|
#define init_log mock_init_log
|
53
|
-
bool mock_init_log( const char *ident, const char *log_directory,
|
53
|
+
bool mock_init_log( const char *ident, const char *log_directory, logging_type type );
|
54
54
|
|
55
55
|
#ifdef error
|
56
56
|
#undef error
|
@@ -275,6 +275,7 @@ static char *executable_name = NULL;
|
|
275
275
|
static char *trema_log = NULL;
|
276
276
|
static char *trema_pid = NULL;
|
277
277
|
static char *trema_sock = NULL;
|
278
|
+
static logging_type log_output_type = LOGGING_TYPE_FILE;
|
278
279
|
static pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
279
280
|
|
280
281
|
|
@@ -282,10 +283,11 @@ static struct option long_options[] = {
|
|
282
283
|
{ "name", 1, NULL, 'n' },
|
283
284
|
{ "daemonize", 0, NULL, 'd' },
|
284
285
|
{ "logging_level", 1, NULL, 'l' },
|
286
|
+
{ "syslog", 0, NULL, 'g' },
|
285
287
|
{ "help", 0, NULL, 'h' },
|
286
288
|
{ NULL, 0, NULL, 0 },
|
287
289
|
};
|
288
|
-
static char short_options[] = "n:dl:
|
290
|
+
static char short_options[] = "n:dl:gh";
|
289
291
|
|
290
292
|
|
291
293
|
/**
|
@@ -302,6 +304,7 @@ usage() {
|
|
302
304
|
" -n, --name=SERVICE_NAME service name\n"
|
303
305
|
" -d, --daemonize run in the background\n"
|
304
306
|
" -l, --logging_level=LEVEL set logging level\n"
|
307
|
+
" -g, --syslog output log messages to syslog\n"
|
305
308
|
" -h, --help display this help and exit\n",
|
306
309
|
executable_name
|
307
310
|
);
|
@@ -437,6 +440,9 @@ parse_argv( int *argc, char ***argv ) {
|
|
437
440
|
case 'l':
|
438
441
|
set_logging_level( optarg );
|
439
442
|
break;
|
443
|
+
case 'g':
|
444
|
+
log_output_type = LOGGING_TYPE_SYSLOG;
|
445
|
+
break;
|
440
446
|
case 'h':
|
441
447
|
usage();
|
442
448
|
xfree( trema_name );
|
@@ -494,6 +500,28 @@ set_exit_handler() {
|
|
494
500
|
}
|
495
501
|
|
496
502
|
|
503
|
+
static void
|
504
|
+
do_restart_log() {
|
505
|
+
restart_log( NULL );
|
506
|
+
}
|
507
|
+
|
508
|
+
|
509
|
+
static void
|
510
|
+
set_do_restart_log_as_external_callback() {
|
511
|
+
set_external_callback( do_restart_log );
|
512
|
+
}
|
513
|
+
|
514
|
+
|
515
|
+
static void
|
516
|
+
set_hup_handler() {
|
517
|
+
struct sigaction signal_hup;
|
518
|
+
|
519
|
+
memset( &signal_hup, 0, sizeof( struct sigaction ) );
|
520
|
+
signal_hup.sa_handler = ( void * ) set_do_restart_log_as_external_callback;
|
521
|
+
sigaction( SIGHUP, &signal_hup, NULL );
|
522
|
+
}
|
523
|
+
|
524
|
+
|
497
525
|
static void
|
498
526
|
set_dump_stats_as_external_callback() {
|
499
527
|
set_external_callback( dump_stats );
|
@@ -561,14 +589,19 @@ init_trema( int *argc, char ***argv ) {
|
|
561
589
|
initialized = false;
|
562
590
|
trema_started = false;
|
563
591
|
run_as_daemon = false;
|
592
|
+
log_output_type = LOGGING_TYPE_FILE;
|
564
593
|
|
565
594
|
parse_argv( argc, argv );
|
566
595
|
set_trema_home();
|
567
596
|
set_trema_tmp();
|
568
597
|
check_trema_tmp();
|
569
|
-
|
598
|
+
if ( !run_as_daemon ) {
|
599
|
+
log_output_type |= LOGGING_TYPE_STDOUT;
|
600
|
+
}
|
601
|
+
init_log( get_trema_name(), get_trema_log(), log_output_type );
|
570
602
|
ignore_sigpipe();
|
571
603
|
set_exit_handler();
|
604
|
+
set_hup_handler();
|
572
605
|
set_usr1_handler();
|
573
606
|
set_usr2_handler();
|
574
607
|
init_messenger( get_trema_sock() );
|
@@ -638,14 +671,14 @@ set_trema_name( const char *name ) {
|
|
638
671
|
if ( trema_name != NULL ) {
|
639
672
|
if ( trema_started ) {
|
640
673
|
rename_pid( get_trema_pid(), trema_name, name );
|
641
|
-
rename_log(
|
674
|
+
rename_log( name );
|
642
675
|
}
|
643
676
|
xfree( trema_name );
|
644
677
|
}
|
645
678
|
trema_name = xstrdup( name );
|
646
679
|
|
647
680
|
if ( initialized ) {
|
648
|
-
restart_log( trema_name
|
681
|
+
restart_log( trema_name );
|
649
682
|
}
|
650
683
|
}
|
651
684
|
|
@@ -1,7 +1,9 @@
|
|
1
1
|
/*
|
2
|
-
*
|
2
|
+
* Trema C++ wrapper.
|
3
3
|
*
|
4
|
-
*
|
4
|
+
* Author: Vladimir Olteanu <vladimir.olteanu@cs.pub.ro>
|
5
|
+
*
|
6
|
+
* Copyright (C) 2012 Vladimir Olteanu
|
5
7
|
*
|
6
8
|
* This program is free software; you can redistribute it and/or modify
|
7
9
|
* it under the terms of the GNU General Public License, version 2, as
|
@@ -18,20 +20,27 @@
|
|
18
20
|
*/
|
19
21
|
|
20
22
|
|
21
|
-
#ifndef
|
22
|
-
#define
|
23
|
+
#ifndef TREMA_HPP
|
24
|
+
#define TREMA_HPP
|
23
25
|
|
24
26
|
|
25
|
-
|
27
|
+
template <typename type1, typename type2> struct _types_compatible_p {
|
28
|
+
static const bool result = false;
|
29
|
+
};
|
26
30
|
|
31
|
+
template <typename type1> struct _types_compatible_p<type1, type1> {
|
32
|
+
static const bool result = true;
|
33
|
+
};
|
27
34
|
|
28
|
-
|
35
|
+
#define __builtin_types_compatible_p( type1, type2 ) _types_compatible_p< type1, type2 >::result
|
29
36
|
|
30
37
|
|
31
|
-
|
38
|
+
extern "C" {
|
39
|
+
#include "trema.h"
|
40
|
+
}
|
32
41
|
|
33
42
|
|
34
|
-
#endif //
|
43
|
+
#endif // TREMA_HPP
|
35
44
|
|
36
45
|
|
37
46
|
/*
|
data/src/lib/trema_wrapper.c
CHANGED
@@ -23,6 +23,7 @@
|
|
23
23
|
#include <stdio.h>
|
24
24
|
#include <stdlib.h>
|
25
25
|
#include <sys/types.h>
|
26
|
+
#include <syslog.h>
|
26
27
|
#include <unistd.h>
|
27
28
|
|
28
29
|
|
@@ -40,6 +41,10 @@ int ( *trema_unlink )( const char *pathname ) = unlink;
|
|
40
41
|
|
41
42
|
pid_t ( *trema_getpid )( void ) = getpid;
|
42
43
|
|
44
|
+
void ( *trema_openlog ) ( const char *ident, int option, int facility ) = openlog;
|
45
|
+
void ( *trema_closelog ) ( void ) = closelog;
|
46
|
+
void ( *trema_vsyslog ) ( int priority, const char *format, va_list ap ) = vsyslog;
|
47
|
+
|
43
48
|
int ( *trema_sqlite3_open )( const char *filename, sqlite3 **ppDb ) = sqlite3_open;
|
44
49
|
int ( *trema_sqlite3_close )( sqlite3 * ) = sqlite3_close;
|
45
50
|
int ( *trema_sqlite3_exec )( sqlite3 *, const char *sql, int ( *callback ) ( void *, int, char **, char ** ), void *, char **errmsg ) = sqlite3_exec;
|
data/src/lib/trema_wrapper.h
CHANGED
@@ -45,6 +45,10 @@ extern int ( *trema_unlink ) ( const char *pathname );
|
|
45
45
|
|
46
46
|
extern pid_t ( *trema_getpid )( void );
|
47
47
|
|
48
|
+
extern void ( *trema_openlog ) ( const char *ident, int option, int facility );
|
49
|
+
extern void ( *trema_closelog ) ( void );
|
50
|
+
extern void ( *trema_vsyslog ) ( int priority, const char *format, va_list ap );
|
51
|
+
|
48
52
|
extern int ( *trema_sqlite3_open) ( const char *filename, sqlite3 **ppDb );
|
49
53
|
extern int ( *trema_sqlite3_close ) ( sqlite3 * );
|
50
54
|
extern int ( *trema_sqlite3_exec ) ( sqlite3 *, const char *sql, int ( *callback ) ( void *, int, char **, char ** ), void *, char **errmsg );
|
data/src/lib/utility.c
CHANGED
@@ -143,11 +143,99 @@ string_to_datapath_id( const char *str, uint64_t *datapath_id ) {
|
|
143
143
|
}
|
144
144
|
|
145
145
|
|
146
|
+
static bool
|
147
|
+
append_string( char *buf, size_t length, const char *string ) {
|
148
|
+
assert( buf != NULL );
|
149
|
+
assert( length > 0 );
|
150
|
+
assert( string != NULL );
|
151
|
+
|
152
|
+
size_t current_length = strlen( buf );
|
153
|
+
size_t length_to_append = strlen( string );
|
154
|
+
if ( ( current_length + length_to_append + 1 ) > length ) {
|
155
|
+
return false;
|
156
|
+
}
|
157
|
+
strncpy( buf + current_length, string, length_to_append + 1 );
|
158
|
+
|
159
|
+
return true;
|
160
|
+
}
|
161
|
+
|
162
|
+
|
163
|
+
bool
|
164
|
+
wildcards_to_string( uint32_t wildcards, char *str, size_t size ) {
|
165
|
+
assert( str != NULL );
|
166
|
+
assert( size > 0 );
|
167
|
+
|
168
|
+
memset( str, '\0', size );
|
169
|
+
|
170
|
+
bool ret = true;
|
171
|
+
if ( ( wildcards & OFPFW_ALL ) == 0 ) {
|
172
|
+
ret &= append_string( str, size, "none" );
|
173
|
+
return ret;
|
174
|
+
}
|
175
|
+
|
176
|
+
uint32_t nw_src_mask = ( wildcards & OFPFW_NW_SRC_MASK ) >> OFPFW_NW_SRC_SHIFT;
|
177
|
+
uint32_t nw_dst_mask = ( wildcards & OFPFW_NW_DST_MASK ) >> OFPFW_NW_DST_SHIFT;
|
178
|
+
uint32_t mask = OFPFW_ALL & ~OFPFW_NW_SRC_MASK & ~OFPFW_NW_DST_MASK;
|
179
|
+
if ( ( wildcards & mask ) == mask && nw_src_mask >=32 && nw_dst_mask >= 32 ) {
|
180
|
+
ret &= append_string( str, size, "all" );
|
181
|
+
return ret;
|
182
|
+
}
|
183
|
+
|
184
|
+
if ( wildcards & OFPFW_IN_PORT ) {
|
185
|
+
ret &= append_string( str, size, "in_port|" );
|
186
|
+
}
|
187
|
+
if ( wildcards & OFPFW_DL_SRC ) {
|
188
|
+
ret &= append_string( str, size, "dl_src|" );
|
189
|
+
}
|
190
|
+
if ( wildcards & OFPFW_DL_DST ) {
|
191
|
+
ret &= append_string( str, size, "dl_dst|" );
|
192
|
+
}
|
193
|
+
if ( wildcards & OFPFW_DL_TYPE ) {
|
194
|
+
ret &= append_string( str, size, "dl_type|" );
|
195
|
+
}
|
196
|
+
if ( wildcards & OFPFW_DL_VLAN ) {
|
197
|
+
ret &= append_string( str, size, "dl_vlan|" );
|
198
|
+
}
|
199
|
+
if ( wildcards & OFPFW_DL_VLAN_PCP ) {
|
200
|
+
ret &= append_string( str, size, "dl_vlan_pcp|" );
|
201
|
+
}
|
202
|
+
if ( wildcards & OFPFW_NW_PROTO ) {
|
203
|
+
ret &= append_string( str, size, "nw_proto|" );
|
204
|
+
}
|
205
|
+
if ( wildcards & OFPFW_NW_TOS ) {
|
206
|
+
ret &= append_string( str, size, "nw_tos|" );
|
207
|
+
}
|
208
|
+
|
209
|
+
char mask_str[ 16 ];
|
210
|
+
if ( nw_src_mask > 0 ) {
|
211
|
+
snprintf( mask_str, sizeof( mask_str ), "nw_src(%u)|", nw_src_mask );
|
212
|
+
ret &= append_string( str, size, mask_str );
|
213
|
+
}
|
214
|
+
if ( nw_dst_mask > 0 ) {
|
215
|
+
snprintf( mask_str, sizeof( mask_str ), "nw_dst(%u)|", nw_dst_mask );
|
216
|
+
ret &= append_string( str, size, mask_str );
|
217
|
+
}
|
218
|
+
if ( wildcards & OFPFW_TP_SRC ) {
|
219
|
+
ret &= append_string( str, size, "tp_src|" );
|
220
|
+
}
|
221
|
+
if ( wildcards & OFPFW_TP_DST ) {
|
222
|
+
ret &= append_string( str, size, "tp_dst|" );
|
223
|
+
}
|
224
|
+
|
225
|
+
if ( strlen( str ) > 0 ) {
|
226
|
+
str[ strlen( str ) - 1 ] = '\0';
|
227
|
+
}
|
228
|
+
|
229
|
+
return ret;
|
230
|
+
}
|
231
|
+
|
232
|
+
|
146
233
|
bool
|
147
234
|
match_to_string( const struct ofp_match *match, char *str, size_t size ) {
|
148
235
|
assert( match != NULL );
|
149
236
|
assert( str != NULL );
|
150
237
|
|
238
|
+
char wildcards_str[ 256 ];
|
151
239
|
char nw_src[ 16 ];
|
152
240
|
char nw_dst[ 16 ];
|
153
241
|
struct in_addr addr;
|
@@ -155,6 +243,7 @@ match_to_string( const struct ofp_match *match, char *str, size_t size ) {
|
|
155
243
|
unsigned int nw_src_prefixlen;
|
156
244
|
unsigned int nw_dst_prefixlen;
|
157
245
|
|
246
|
+
wildcards_to_string( match->wildcards, wildcards_str, sizeof( wildcards_str ) );
|
158
247
|
addr.s_addr = htonl( match->nw_src );
|
159
248
|
memset( nw_src, '\0', sizeof( nw_src ) );
|
160
249
|
inet_ntop( AF_INET, &addr, nw_src, sizeof( nw_src ) );
|
@@ -171,20 +260,20 @@ match_to_string( const struct ofp_match *match, char *str, size_t size ) {
|
|
171
260
|
int ret = snprintf(
|
172
261
|
str,
|
173
262
|
size,
|
174
|
-
"wildcards = %#x, in_port = %u, "
|
263
|
+
"wildcards = %#x(%s), in_port = %u, "
|
175
264
|
"dl_src = %02x:%02x:%02x:%02x:%02x:%02x, "
|
176
265
|
"dl_dst = %02x:%02x:%02x:%02x:%02x:%02x, "
|
177
266
|
"dl_vlan = %u, dl_vlan_pcp = %u, dl_type = %#x, "
|
178
267
|
"nw_tos = %u, nw_proto = %u, nw_src = %s/%u, nw_dst = %s/%u, "
|
179
268
|
"tp_src = %u, tp_dst = %u",
|
180
|
-
match->wildcards, match->in_port,
|
269
|
+
match->wildcards, wildcards_str, match->in_port,
|
181
270
|
match->dl_src[ 0 ], match->dl_src[ 1 ], match->dl_src[ 2 ],
|
182
271
|
match->dl_src[ 3 ], match->dl_src[ 4 ], match->dl_src[ 5 ],
|
183
272
|
match->dl_dst[ 0 ], match->dl_dst[ 1 ], match->dl_dst[ 2 ],
|
184
273
|
match->dl_dst[ 3 ], match->dl_dst[ 4 ], match->dl_dst[ 5 ],
|
185
274
|
match->dl_vlan, match->dl_vlan_pcp, match->dl_type,
|
186
275
|
match->nw_tos, match->nw_proto, nw_src, nw_src_prefixlen,
|
187
|
-
|
276
|
+
nw_dst, nw_dst_prefixlen, match->tp_src, match->tp_dst
|
188
277
|
);
|
189
278
|
|
190
279
|
if ( ( ret >= ( int ) size ) || ( ret < 0 ) ) {
|
@@ -205,7 +294,7 @@ phy_port_to_string( const struct ofp_phy_port *phy_port, char *str, size_t size
|
|
205
294
|
int ret = snprintf(
|
206
295
|
str,
|
207
296
|
size,
|
208
|
-
"port_no = %u, hw_addr =
|
297
|
+
"port_no = %u, hw_addr = %02x:%02x:%02x:%02x:%02x:%02x, "
|
209
298
|
"name = %s, config = %#x, state = %#x, "
|
210
299
|
"curr = %#x, advertised = %#x, supported = %#x, peer = %#x",
|
211
300
|
phy_port->port_no,
|
data/src/lib/utility.h
CHANGED
@@ -50,6 +50,7 @@ unsigned int hash_datapath_id( const void *key );
|
|
50
50
|
bool string_to_datapath_id( const char *str, uint64_t *datapath_id );
|
51
51
|
|
52
52
|
bool match_to_string( const struct ofp_match *match, char *str, size_t size );
|
53
|
+
bool wildcards_to_string( uint32_t wildcards, char *str, size_t size );
|
53
54
|
bool phy_port_to_string( const struct ofp_phy_port *phy_port, char *str, size_t size );
|
54
55
|
bool actions_to_string( const struct ofp_action_header *actions, uint16_t actions_length, char *str, size_t str_length );
|
55
56
|
|
data/src/lib/wrapper.c
CHANGED
@@ -76,19 +76,42 @@ xstrdup( const char *s ) {
|
|
76
76
|
}
|
77
77
|
|
78
78
|
|
79
|
+
static char *
|
80
|
+
_xvasprintf( const char *format, va_list args, const char *error_message ) {
|
81
|
+
va_list args_copy;
|
82
|
+
va_copy( args_copy, args );
|
83
|
+
int n = vsnprintf( NULL, 0, format, args_copy );
|
84
|
+
va_end( args_copy );
|
85
|
+
if ( n <= 0 ) {
|
86
|
+
return NULL;
|
87
|
+
}
|
88
|
+
size_t size = ( size_t ) ( n + 1 );
|
89
|
+
char *str = _trema_malloc( size, error_message );
|
90
|
+
va_copy( args_copy, args );
|
91
|
+
n = vsnprintf( str, size, format, args_copy );
|
92
|
+
va_end( args_copy );
|
93
|
+
if ( n <= 0 || ( size_t ) n > size ) {
|
94
|
+
xfree( str );
|
95
|
+
return NULL;
|
96
|
+
}
|
97
|
+
return str;
|
98
|
+
}
|
99
|
+
|
100
|
+
|
101
|
+
char *
|
102
|
+
xvasprintf( const char *format, va_list args ) {
|
103
|
+
return _xvasprintf( format, args, "Out of memory, xvasprintf failed" );
|
104
|
+
}
|
105
|
+
|
106
|
+
|
79
107
|
char *
|
80
108
|
xasprintf( const char *format, ... ) {
|
81
109
|
const char error[] = "Out of memory, xasprintf failed";
|
82
110
|
va_list args;
|
83
111
|
va_start( args, format );
|
84
|
-
char *str;
|
85
|
-
if ( trema_vasprintf( &str, format, args ) < 0 ) {
|
86
|
-
die( error );
|
87
|
-
}
|
88
|
-
char *result = _xstrdup( str, error );
|
89
|
-
free( str );
|
112
|
+
char *str = _xvasprintf( format, args, error );
|
90
113
|
va_end( args );
|
91
|
-
return
|
114
|
+
return str;
|
92
115
|
}
|
93
116
|
|
94
117
|
|
data/src/lib/wrapper.h
CHANGED
@@ -24,6 +24,7 @@
|
|
24
24
|
#define WRAPPER_H
|
25
25
|
|
26
26
|
|
27
|
+
#include <stdarg.h>
|
27
28
|
#include <stddef.h>
|
28
29
|
#include <string.h>
|
29
30
|
#include "utility.h"
|
@@ -62,6 +63,7 @@ void *xcalloc( size_t nmemb, size_t size );
|
|
62
63
|
void xfree( void *ptr );
|
63
64
|
|
64
65
|
char *xstrdup( const char *s );
|
66
|
+
char *xvasprintf( const char *format, va_list args );
|
65
67
|
char *xasprintf( const char *format, ... );
|
66
68
|
|
67
69
|
|