Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 8 commits
  • 8 files changed
  • 0 commit comments
  • 4 contributors
View
2 src/lib/openflow_application_interface.c
@@ -708,7 +708,7 @@ handle_features_reply( const uint64_t datapath_id, buffer *data ) {
ntoh_phy_port( p, phy_port );
append_to_tail( &phy_ports_head, ( void * ) p );
phy_port_to_string( p, description, sizeof( description ) );
- debug( "[%u] %s", phy_port, description );
+ debug( "[%p] %s", phy_port, description );
phy_port++;
}
}
View
2 src/lib/utility.c
@@ -294,7 +294,7 @@ phy_port_to_string( const struct ofp_phy_port *phy_port, char *str, size_t size
int ret = snprintf(
str,
size,
- "port_no = %u, hw_addr = %02x:%02x:%02x:%02x:%02x:%02x, "
+ "port_no = %u, hw_addr = %02x:%02x:%02x:%02x:%02x:%02x, "
"name = %s, config = %#x, state = %#x, "
"curr = %#x, advertised = %#x, supported = %#x, peer = %#x",
phy_port->port_no,
View
37 src/lib/wrapper.c
@@ -76,19 +76,42 @@ xstrdup( const char *s ) {
}
+static char *
+_xvasprintf( const char *format, va_list args, const char *error_message ) {
+ va_list args_copy;
+ va_copy( args_copy, args );
+ int n = vsnprintf( NULL, 0, format, args_copy );
+ va_end( args_copy );
+ if ( n <= 0 ) {
+ return NULL;
+ }
+ size_t size = ( size_t ) ( n + 1 );
+ char *str = _trema_malloc( size, error_message );
+ va_copy( args_copy, args );
+ n = vsnprintf( str, size, format, args_copy );
+ va_end( args_copy );
+ if ( n <= 0 || ( size_t ) n > size ) {
+ xfree( str );
+ return NULL;
+ }
+ return str;
+}
+
+
+char *
+xvasprintf( const char *format, va_list args ) {
+ return _xvasprintf( format, args, "Out of memory, xvasprintf failed" );
+}
+
+
char *
xasprintf( const char *format, ... ) {
const char error[] = "Out of memory, xasprintf failed";
va_list args;
va_start( args, format );
- char *str;
- if ( trema_vasprintf( &str, format, args ) < 0 ) {
- die( error );
- }
- char *result = _xstrdup( str, error );
- free( str );
+ char *str = _xvasprintf( format, args, error );
va_end( args );
- return result;
+ return str;
}
View
2 src/lib/wrapper.h
@@ -24,6 +24,7 @@
#define WRAPPER_H
+#include <stdarg.h>
#include <stddef.h>
#include <string.h>
#include "utility.h"
@@ -62,6 +63,7 @@ void *xcalloc( size_t nmemb, size_t size );
void xfree( void *ptr );
char *xstrdup( const char *s );
+char *xvasprintf( const char *format, va_list args );
char *xasprintf( const char *format, ... );
View
25 src/switch_manager/switch.c
@@ -486,8 +486,7 @@ switch_event_disconnected( struct switch_info *sw_info ) {
}
flush_messenger();
- stop_event_handler();
- stop_messenger();
+ stop_trema();
return 0;
}
@@ -565,6 +564,22 @@ management_recv( uint16_t tag, void *data, size_t data_len ) {
}
+static void
+stop_switch_daemon( void ) {
+ switch_event_disconnected( &switch_info );
+}
+
+
+static void
+handle_sigterm( int signum ) {
+ UNUSED( signum );
+
+ if ( !set_external_callback( stop_switch_daemon ) ) {
+ stop_trema();
+ }
+}
+
+
int
main( int argc, char *argv[] ) {
int ret;
@@ -604,6 +619,12 @@ main( int argc, char *argv[] ) {
}
}
+ struct sigaction signal_exit;
+ memset( &signal_exit, 0, sizeof( struct sigaction ) );
+ signal_exit.sa_handler = handle_sigterm;
+ sigaction( SIGINT, &signal_exit, NULL );
+ sigaction( SIGTERM, &signal_exit, NULL );
+
fcntl( switch_info.secure_channel_fd, F_SETFL, O_NONBLOCK );
set_fd_handler( switch_info.secure_channel_fd, secure_channel_read, NULL, secure_channel_write, NULL );
View
3 unittests/lib/packet_parser_test.c
@@ -142,6 +142,7 @@ test_parse_packet_arp_request_succeeds() {
assert_memory_equal( packet_info->arp_tha, maczero, ETH_ADDRLEN );
assert_true( packet_type_arp_request( buffer ) );
+ assert_false( packet_type_arp_reply( buffer ) );
free_buffer( buffer );
}
@@ -169,7 +170,7 @@ test_parse_packet_ipv6_succeeds() {
0x8e, 0x89, 0xa5, 0xff, 0xfe, 0x15, 0x84, 0xcb };
assert_memory_equal( packet_info->ipv6_saddr, saddr, IPV6_ADDRLEN );
assert_memory_equal( packet_info->ipv6_daddr, daddr, IPV6_ADDRLEN );
-
+
free_buffer( buffer );
}
View
2 unittests/lib/utility_test.c
@@ -282,7 +282,7 @@ test_match_to_string_fails_with_insufficient_buffer() {
static void
test_phy_port_to_string() {
char phy_port_str[ 256 ];
- char expected_phy_port_str[] = "port_no = 1, hw_addr = 01:02:03:04:05:06, name = GbE 0/1, config = 0x1, state = 0x1, curr = 0x4a0, advertised = 0x6bf, supported = 0x6bf, peer = 0x6bf";
+ char expected_phy_port_str[] = "port_no = 1, hw_addr = 01:02:03:04:05:06, name = GbE 0/1, config = 0x1, state = 0x1, curr = 0x4a0, advertised = 0x6bf, supported = 0x6bf, peer = 0x6bf";
uint8_t hw_addr[ OFP_ETH_ALEN ] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
uint32_t port_features = ( OFPPF_10MB_HD | OFPPF_10MB_FD | OFPPF_100MB_HD |
OFPPF_100MB_FD | OFPPF_1GB_HD | OFPPF_1GB_FD |
View
29 unittests/lib/wrapper_test.c
@@ -154,6 +154,32 @@ test_xstrdup_fail() {
}
+static char *
+test_xvasprintf_helper( const char *fmt, ... ) {
+ va_list ap;
+ va_start(ap, fmt);
+ char *str = xvasprintf( fmt, ap );
+ va_end(ap);
+ return str;
+}
+
+
+static void
+test_xvasprintf() {
+ char hello[] = "Hello";
+ char *printed_hello = test_xvasprintf_helper( "%s", hello );
+ assert_string_equal( hello, printed_hello );
+ xfree( printed_hello );
+}
+
+
+static void
+test_xvasprintf_fail() {
+ expect_string( mock_die, output, "Out of memory, xvasprintf failed" );
+ expect_assert_failure( test_xvasprintf_helper( "FAIL" ) );
+}
+
+
static void
test_xasprintf() {
char hello[] = "Hello";
@@ -186,6 +212,9 @@ main() {
unit_test_setup_teardown( test_xstrdup, setup, teardown ),
unit_test_setup_teardown( test_xstrdup_fail, setup_fail_allocators, teardown ),
+ unit_test_setup_teardown( test_xvasprintf, setup, teardown ),
+ unit_test_setup_teardown( test_xvasprintf_fail, setup_fail_allocators, teardown ),
+
unit_test_setup_teardown( test_xasprintf, setup, teardown ),
unit_test_setup_teardown( test_xasprintf_fail, setup_fail_allocators, teardown ),
};

No commit comments for this range

Something went wrong with that request. Please try again.