ruby/trema/echo-reply.c in trema-0.2.2.1 vs ruby/trema/echo-reply.c in trema-0.2.3
- old
+ new
@@ -1,8 +1,6 @@
/*
- * Author: Nick Karanatsios <nickkaranatsios@gmail.com>
- *
* Copyright (C) 2008-2012 NEC Corporation
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation.
@@ -16,87 +14,103 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include "trema.h"
+#include "echo.h"
#include "ruby.h"
+#include "trema.h"
+#include "trema-ruby-utils.h"
extern VALUE mTrema;
VALUE cEchoReply;
static VALUE
echo_reply_alloc( VALUE klass ) {
- buffer *echo_reply = create_echo_reply( get_transaction_id(), NULL );
+ buffer *body = alloc_buffer();
+ buffer *echo_reply = create_echo_reply( 0, body );
+ free_buffer( body );
return Data_Wrap_Struct( klass, NULL, free_buffer, echo_reply );
}
+#if 0
/*
- * Creates a {EchoReply} instance.
+ * Creates a EchoReply OpenFlow message. This message can be used to
+ * measure the bandwidth of a controller/switch connection as well as
+ * to verify its liveness.
*
- * @overload initialize(options={})
- *
+ * @overload initialize()
* @example
* EchoReply.new
- * EchoReply.new( :transaction_id => 123 )
*
+ * @overload initialize(transaction_id)
+ * @example
+ * EchoReply.new( 123 )
+ * @param [Integer] transaction_id
+ * An unsigned 32bit integer number associated with this message.
+ *
+ * @overload initialize(options)
+ * @example
+ * EchoReply.new(
+ * :transaction_id => transaction_id,
+ * :user_data => "Thu Aug 25 13:09:00 +0900 2011"
+ * )
* @param [Hash] options
* the options to create a message with.
- *
+ * @option options [Number] :xid
* @option options [Number] :transaction_id
- * An unsigned 32-bit integer auto-generated if not supplied.
+ * An unsigned 32bit integer number associated with this message.
+ * If not specified, an auto-generated value is set.
+ * @option options [String] :user_data
+ * the user data field specified as a String may be a message timestamp to check latency,
+ * various lengths to measure bandwidth or zero-size(nil) to verify liveness between
+ * the switch and controller.
*
- * @raise [ArgumentError] if transaction id is not an unsigned 32-bit integer.
- * @raise [TypeError] if options is not a hash.
- *
- * @return [EchoReply]
- * an object that encapsulates the +OFPT_ECHO_REPLY+ OpenFlow message.
+ * @raise [ArgumentError] if transaction ID is not an unsigned 32-bit integer.
+ * @raise [ArgumentError] if user data is not a string.
+ * @raise [TypeError] if argument is not a hash.
+ * @return [EchoReply]
*/
-static VALUE
-echo_reply_init( int argc, VALUE *argv, VALUE self ) {
- buffer *echo_reply;
- Data_Get_Struct( self, buffer, echo_reply );
- uint32_t xid = get_transaction_id();
- VALUE options;
+VALUE
+echo_init( int argc, VALUE *argv, VALUE self ) {}
+#endif
- if ( rb_scan_args( argc, argv, "01", &options ) == 1 ) {
- Check_Type( options, T_HASH );
- VALUE xid_ruby;
- if ( ( xid_ruby = rb_hash_aref( options, ID2SYM( rb_intern( "transaction_id" ) ) ) ) != Qnil ) {
- if ( rb_funcall( xid_ruby, rb_intern( "unsigned_32bit?" ), 0 ) == Qfalse ) {
- rb_raise( rb_eArgError, "Transaction ID must be an unsigned 32-bit integer" );
- }
- xid = ( uint32_t ) NUM2UINT( xid_ruby );
- }
- }
- ( ( struct ofp_header * ) ( echo_reply->data ) )->xid = htonl( xid );
- return self;
-}
-
+#if 0
/*
- * Transaction ids, message sequence numbers matching requests to replies.
+ * Transaction ids, message sequence numbers matching requests to
+ * replies.
*
* @return [Number] the value of transaction id.
*/
-static VALUE
-echo_reply_transaction_id( VALUE self ) {
- buffer *echo_reply;
- Data_Get_Struct( self, buffer, echo_reply );
- uint32_t xid = ntohl( ( ( struct ofp_header * ) ( echo_reply->data ) )->xid );
- return UINT2NUM( xid );
-}
+VALUE
+echo_transaction_id( VALUE self ) {}
+#endif
+#if 0
+/*
+ * An arbitrary length user data payload.
+ *
+ * @return [String] a user data payload is set.
+ * @return [nil] a user data payload is not set.
+ */
+VALUE
+echo_user_data( VALUE self ) {}
+#endif
+
+
void
Init_echo_reply() {
cEchoReply = rb_define_class_under( mTrema, "EchoReply", rb_cObject );
rb_define_alloc_func( cEchoReply, echo_reply_alloc );
- rb_define_method( cEchoReply, "initialize", echo_reply_init, -1 );
- rb_define_method( cEchoReply, "transaction_id", echo_reply_transaction_id, 0 );
+ rb_define_method( cEchoReply, "initialize", echo_init, -1 );
+ rb_define_method( cEchoReply, "transaction_id", echo_transaction_id, 0 );
+ rb_alias( cEchoReply, rb_intern( "xid" ), rb_intern( "transaction_id" ) );
+ rb_define_method( cEchoReply, "user_data", echo_user_data, 0 );
}
/*
* Local variables: