Class: Trema::Controller Abstract
- Inherits:
-
App
- Object
- App
- Trema::Controller
- Defined in:
- ruby/trema/controller.rb,
ruby/trema/controller.c
Overview
The base class of Trema controller. Subclass and override handlers to implement a custom OpenFlow controller.
Constant Summary collapse
- OFPP_MAX =
INT2NUM( OFPP_MAX )
- OFPP_IN_PORT =
INT2NUM( OFPP_IN_PORT )
- OFPP_TABLE =
INT2NUM( OFPP_TABLE )
- OFPP_NORMAL =
INT2NUM( OFPP_NORMAL )
- OFPP_FLOOD =
INT2NUM( OFPP_FLOOD )
- OFPP_ALL =
INT2NUM( OFPP_ALL )
- OFPP_CONTROLLER =
INT2NUM( OFPP_CONTROLLER )
- OFPP_LOCAL =
INT2NUM( OFPP_LOCAL )
- OFPP_NONE =
INT2NUM( OFPP_NONE )
Instance Method Summary collapse
- #barrier_reply(datapath_id, message) ⇒ Object abstract
-
#daemonize! ⇒ Object
Run as a daemon.
- #features_reply(datapath_id, message) ⇒ Object abstract
- #flow_removed(datapath_id, message) ⇒ Object abstract
- #get_config_reply(datapath_id, message) ⇒ Object abstract
- #list_switches_reply(datapath_ids) ⇒ Object abstract
-
#name ⇒ String
Name of the controller.
- #openflow_error(datapath_id, message) ⇒ Object abstract
- #packet_in(datapath_id, message) ⇒ Object abstract
- #port_status(datapath_id, message) ⇒ Object abstract
- #queue_get_config_reply(datapath_id, message) ⇒ Object abstract
-
#run! ⇒ Object
Starts this controller.
-
#send_flow_mod_add(datapath_id, options = {}) ⇒ Object
Sends a flow_mod message to add a flow into the datapath.
-
#send_flow_mod_delete(datapath_id, options = {}) ⇒ Object
Sends a flow_mod_delete message to delete all matching flows.
-
#send_flow_mod_modify(datapath, options = {}) ⇒ Object
Sends a flow_mod message to either modify or modify strict a flow from datapath.
- #send_list_switches_request ⇒ Object
-
#send_message(datapath_id, message) ⇒ Object
Sends an OpenFlow message to the datapath.
-
#send_packet_out(datapath_id, options = {}) ⇒ Object
Sends a packet_out message to have a packet processed by the datapath.
-
#shutdown! ⇒ Object
In the context of trema framework stops this controller and its applications.
- #stats_reply(datapath_id, message) ⇒ Object abstract
- #switch_disconnected(datapath_id) ⇒ Object abstract
- #switch_ready(datapath_id) ⇒ Object abstract
- #vendor(datapath_id, message) ⇒ Object abstract
Methods included from Logger
#critical, #debug, #error, #info, #notice, #warn
Instance Method Details
#barrier_reply(datapath_id, message) ⇒ Object
Barrier Reply message handler. Override this to implement a custom handler.
165 |
# File 'ruby/trema/controller.rb', line 165 handler :barrier_reply |
#daemonize! ⇒ Object
Run as a daemon.
226 227 228 229 230 231 232 233 234 235 236 |
# File 'ruby/trema/controller.rb', line 226 def daemonize! fork do ::Process.setsid fork do STDIN.close STDOUT.reopen "/dev/null", "a" STDERR.reopen "/dev/null", "a" self.run! end end end |
#features_reply(datapath_id, message) ⇒ Object
Features Reply message handler. Override this to implement a custom handler.
139 |
# File 'ruby/trema/controller.rb', line 139 handler :features_reply |
#flow_removed(datapath_id, message) ⇒ Object
Flow Removed message handler. Override this to implement a custom handler.
100 |
# File 'ruby/trema/controller.rb', line 100 handler :flow_removed |
#get_config_reply(datapath_id, message) ⇒ Object
Get Config Reply message handler. Override this to implement a custom handler.
178 |
# File 'ruby/trema/controller.rb', line 178 handler :get_config_reply |
#list_switches_reply(datapath_ids) ⇒ Object
List Switches Reply message handler. Override this to implement a custom handler.
74 |
# File 'ruby/trema/controller.rb', line 74 handler :list_switches_reply |
#name ⇒ String
Name of the controller.
244 245 246 |
# File 'ruby/trema/controller.rb', line 244 def name self.class.to_s.split( "::" ).last end |
#openflow_error(datapath_id, message) ⇒ Object
OpenFlow Error message handler. Override this to implement a custom handler.
126 |
# File 'ruby/trema/controller.rb', line 126 handler :openflow_error |
#packet_in(datapath_id, message) ⇒ Object
Packet In message handler. Override this to implement a custom handler.
87 |
# File 'ruby/trema/controller.rb', line 87 handler :packet_in |
#port_status(datapath_id, message) ⇒ Object
Port Status message handler. Override this to implement a custom handler.
113 |
# File 'ruby/trema/controller.rb', line 113 handler :port_status |
#queue_get_config_reply(datapath_id, message) ⇒ Object
Queue Get Config Reply message handler. Override this to implement a custom handler.
191 |
# File 'ruby/trema/controller.rb', line 191 handler :queue_get_config_reply |
#run! ⇒ Object
Starts this controller. Usually you do not need to invoke explicitly, because this is called implicitly by “trema run” command.
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 |
# File 'ruby/trema/controller.c', line 537 static VALUE controller_run( VALUE self ) { setenv( "TREMA_HOME", STR2CSTR( rb_funcall( mTrema, rb_intern( "home" ), 0 ) ), 1 ); VALUE name = rb_funcall( self, rb_intern( "name" ), 0 ); rb_gv_set( "$PROGRAM_NAME", name ); int argc = 3; char **argv = xmalloc( sizeof( char * ) * ( uint32_t ) ( argc + 1 ) ); argv[ 0 ] = STR2CSTR( name ); argv[ 1 ] = ( char * ) ( uintptr_t ) "--name"; argv[ 2 ] = STR2CSTR( name ); argv[ 3 ] = NULL; init_trema( &argc, &argv ); xfree( argv ); set_switch_ready_handler( handle_switch_ready, ( void * ) self ); set_features_reply_handler( handle_features_reply, ( void * ) self ); set_packet_in_handler( handle_packet_in, ( void * ) self ); set_flow_removed_handler( handle_flow_removed, ( void * ) self ); set_switch_disconnected_handler( handle_switch_disconnected, ( void * ) self ); set_port_status_handler( handle_port_status, ( void * ) self ); set_stats_reply_handler( handle_stats_reply, ( void * ) self ); set_error_handler( handle_openflow_error, ( void * ) self ); set_get_config_reply_handler( handle_get_config_reply, ( void * ) self ); ( , ( void * ) self ); set_vendor_handler( handle_vendor, ( void * ) self ); set_queue_get_config_reply_handler( handle_queue_get_config_reply, ( void * ) self ); set_list_switches_reply_handler( handle_list_switches_reply ); struct itimerspec interval; interval.it_interval.tv_sec = 1; interval.it_interval.tv_nsec = 0; interval.it_value.tv_sec = 0; interval.it_value.tv_nsec = 0; add_timer_event_callback( &interval, handle_timer_event, ( void * ) self ); if ( rb_respond_to( self, rb_intern( "start" ) ) == Qtrue ) { rb_funcall( self, rb_intern( "start" ), 0 ); } rb_funcall( self, rb_intern( "start_trema" ), 0 ); return self; } |
#send_flow_mod_add(datapath_id, options = {}) ⇒ Object
349 350 351 352 |
# File 'ruby/trema/controller.c', line 349 static VALUE controller_send_flow_mod_add( int argc, VALUE *argv, VALUE self ) { return controller_send_flow_mod( OFPFC_ADD, argc, argv, self ); } |
#send_flow_mod_delete(datapath_id, options = {}) ⇒ Object
390 391 392 393 394 395 396 397 398 |
# File 'ruby/trema/controller.c', line 390 static VALUE controller_send_flow_mod_delete( int argc, VALUE *argv, VALUE self ) { uint16_t command = OFPFC_DELETE; if ( get_strict( argc, argv ) == Qtrue ) { command = OFPFC_DELETE_STRICT; } return controller_send_flow_mod( command, argc, argv, self ); } |
#send_flow_mod_modify(datapath, options = {}) ⇒ Object
367 368 369 370 371 372 373 374 375 |
# File 'ruby/trema/controller.c', line 367 static VALUE controller_send_flow_mod_modify( int argc, VALUE *argv, VALUE self ) { uint16_t command = OFPFC_MODIFY; if ( get_strict( argc, argv ) == Qtrue ) { command = OFPFC_MODIFY_STRICT; } return controller_send_flow_mod( command, argc, argv, self ); } |
#send_list_switches_request ⇒ Object
74 75 76 77 78 |
# File 'ruby/trema/controller.c', line 74 static VALUE controller_send_list_switches_request( VALUE self ) { send_list_switches_request( ( void * ) self ); return self; } |
#send_message(datapath_id, message) ⇒ Object
65 66 67 68 69 70 71 |
# File 'ruby/trema/controller.c', line 65 static VALUE ( VALUE self, VALUE datapath_id, VALUE ) { buffer *buf; Data_Get_Struct( , buffer, buf ); ( NUM2ULL( datapath_id ), buf ); return self; } |
#send_packet_out(datapath_id, options = {}) ⇒ Object
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 |
# File 'ruby/trema/controller.c', line 446 static VALUE controller_send_packet_out( int argc, VALUE *argv, VALUE self ) { VALUE datapath_id = Qnil; VALUE = Qnil; rb_scan_args( argc, argv, "11", &datapath_id, & ); // Defaults. uint32_t buffer_id = UINT32_MAX; uint16_t in_port = OFPP_NONE; openflow_actions *actions = create_actions(); const buffer *data = NULL; buffer *allocated_data = NULL; VALUE opt_zero_padding = Qnil; if ( != Qnil ) { VALUE = rb_hash_aref( , ID2SYM( rb_intern( "packet_in" ) ) ); if ( != Qnil ) { packet_in *; Data_Get_Struct( , packet_in, ); if ( NUM2ULL( datapath_id ) == ->datapath_id ) { buffer_id = ->buffer_id; in_port = ->in_port; } data = ( buffer_id == UINT32_MAX ? ->data : NULL ); } VALUE opt_buffer_id = rb_hash_aref( , ID2SYM( rb_intern( "buffer_id" ) ) ); if ( opt_buffer_id != Qnil ) { buffer_id = ( uint32_t ) NUM2ULONG( opt_buffer_id ); } VALUE opt_in_port = rb_hash_aref( , ID2SYM( rb_intern( "in_port" ) ) ); if ( opt_in_port != Qnil ) { in_port = ( uint16_t ) NUM2UINT( opt_in_port ); } VALUE opt_action = rb_hash_aref( , ID2SYM( rb_intern( "actions" ) ) ); if ( opt_action != Qnil ) { form_actions( opt_action, actions ); } VALUE opt_data = rb_hash_aref( , ID2SYM( rb_intern( "data" ) ) ); if ( opt_data != Qnil ) { Check_Type( opt_data, T_STRING ); uint16_t length = ( uint16_t ) RSTRING_LEN( opt_data ); allocated_data = alloc_buffer_with_length( length ); memcpy( append_back_buffer( allocated_data, length ), RSTRING_PTR( opt_data ), length ); data = allocated_data; } opt_zero_padding = rb_hash_aref( , ID2SYM( rb_intern( "zero_padding" ) ) ); if ( opt_zero_padding != Qnil ) { if ( TYPE( opt_zero_padding ) != T_TRUE && TYPE( opt_zero_padding ) != T_FALSE ) { rb_raise( rb_eTypeError, ":zero_padding must be true or false" ); } } } if ( data != NULL && data->length + ETH_FCS_LENGTH < ETH_MINIMUM_LENGTH && opt_zero_padding != Qnil && TYPE( opt_zero_padding ) == T_TRUE ) { if ( allocated_data == NULL ) { allocated_data = duplicate_buffer( data ); data = allocated_data; } fill_ether_padding( allocated_data ); } buffer *packet_out = create_packet_out( get_transaction_id(), buffer_id, in_port, actions, data ); ( NUM2ULL( datapath_id ), packet_out ); if ( allocated_data != NULL ) { free_buffer( allocated_data ); } free_buffer( packet_out ); delete_actions( actions ); return self; } |
#shutdown! ⇒ Object
588 589 590 591 592 |
# File 'ruby/trema/controller.c', line 588 static VALUE controller_shutdown( VALUE self ) { stop_trema(); return self; } |
#stats_reply(datapath_id, message) ⇒ Object
Stats Reply message handler. Override this to implement a custom handler.
152 |
# File 'ruby/trema/controller.rb', line 152 handler :stats_reply |
#switch_disconnected(datapath_id) ⇒ Object
Switch Disconnected event handler. Override this to implement a custom handler.
62 |
# File 'ruby/trema/controller.rb', line 62 handler :switch_disconnected |
#switch_ready(datapath_id) ⇒ Object
Switch Ready event handler. Override this to implement a custom handler.
51 |
# File 'ruby/trema/controller.rb', line 51 handler :switch_ready |
#vendor(datapath_id, message) ⇒ Object
Vendor message handler. Override this to implement a custom handler.
204 |
# File 'ruby/trema/controller.rb', line 204 handler :vendor |