Class: Trema::PortMod
- Inherits:
-
Object
- Object
- Trema::PortMod
- Defined in:
- ruby/trema/port-mod.c
Instance Method Summary collapse
-
#advertise ⇒ Number
Set to zero to prevent any changes.
-
#config ⇒ Number
A port can be administratively brought down, disable flooding or packet forwarding or any other options as per
ofp_port_config. -
#hw_addr ⇒ Mac
Ethernet address converted and stored as a Mac object.
-
#initialize(options = {}) ⇒ PortMod
constructor
A PortMod instance a request object to perform operations on a physical port.
-
#mask ⇒ Number
Set the bitmap as per
configattribute. -
#port_no ⇒ Number
Port number and hardware address as a pair identify a port.
-
#transaction_id ⇒ Number
Transaction ids, message sequence numbers matching requests to replies.
Constructor Details
#initialize(options = {}) ⇒ PortMod
A Trema::PortMod instance a request object to perform operations on a physical port.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'ruby/trema/port-mod.c', line 78 static VALUE port_mod_init( int argc, VALUE *argv, VALUE self ) { VALUE ; if ( rb_scan_args( argc, argv, "01", & ) == 1 ) { Check_Type( , T_HASH ); buffer *port_mod; Data_Get_Struct( self, buffer, port_mod ); VALUE mac; VALUE hw_addr; uint8_t *ptr; uint8_t haddr[ OFP_ETH_ALEN ]; if ( ( hw_addr = rb_hash_aref( , ID2SYM( rb_intern( "hw_addr" ) ) ) ) != Qnil ) { mac = hw_addr; if ( rb_obj_is_kind_of( hw_addr, rb_cString ) == Qtrue || rb_obj_is_kind_of( hw_addr, rb_cInteger ) == Qtrue ) { mac = rb_funcall( rb_eval_string( "Trema::Mac" ), rb_intern( "new" ), 1, hw_addr ); } else if ( rb_obj_is_instance_of( hw_addr, rb_eval_string( "Trema::Mac" ) ) == Qfalse ) { rb_raise( rb_eArgError, "hw_addr must be a string or an integer or Mac object" ); } ptr = ( uint8_t * ) dl_addr_to_a( mac, haddr ); rb_iv_set( self, "@hw_addr", mac ); } VALUE port_no; if ( ( port_no = rb_hash_aref( , ID2SYM( rb_intern( "port_no" ) ) ) ) != Qnil ) { if ( rb_funcall( port_no, rb_intern( "unsigned_16bit?" ), 0 ) == Qfalse ) { rb_raise( rb_eArgError, "Port number must be an unsigned 16-bit integer" ); } rb_iv_set( self, "@port_no", port_no ); } VALUE config; if ( ( config = rb_hash_aref( , ID2SYM( rb_intern( "config" ) ) ) ) != Qnil ) { rb_iv_set( self, "@config", config ); } VALUE mask; if ( ( mask = rb_hash_aref( , ID2SYM( rb_intern( "mask" ) ) ) ) != Qnil ) { rb_iv_set( self, "@mask", mask ); } VALUE advertise; if ( ( advertise = rb_hash_aref( , ID2SYM( rb_intern( "advertise" ) ) ) ) != Qnil ) { rb_iv_set( self, "@advertise", advertise ); } uint32_t xid = get_transaction_id(); rb_iv_set( self, "@transaction_id", UINT2NUM( xid ) ); ( ( struct ofp_header * ) ( port_mod->data ) )->xid = htonl( xid ); ( ( struct ofp_port_mod * ) ( port_mod->data ) )->port_no = htons( ( uint16_t ) NUM2UINT( port_no ) ); memcpy( ( ( struct ofp_port_mod * ) ( port_mod->data ) )->hw_addr, ptr, OFP_ETH_ALEN ); ( ( struct ofp_port_mod * ) ( port_mod->data ) )->config = htonl( ( uint32_t ) NUM2UINT( config ) ); ( ( struct ofp_port_mod * ) ( port_mod->data ) )->mask = htonl( ( uint32_t ) NUM2UINT( mask ) ); ( ( struct ofp_port_mod * ) ( port_mod->data ) )->advertise = htonl( ( uint32_t ) NUM2UINT( advertise ) ); } else { rb_raise( rb_eArgError, "Port no, hw_addr, config, mask, advertise are mandatory options" ); } return self; } |
Instance Method Details
#advertise ⇒ Number
Set to zero to prevent any changes.
200 201 202 203 |
# File 'ruby/trema/port-mod.c', line 200 static VALUE port_mod_advertise( VALUE self ) { return rb_iv_get( self, "@advertise" ); } |
#config ⇒ Number
A port can be administratively brought down, disable flooding or packet forwarding or any other options as per ofp_port_config. flags.
178 179 180 181 |
# File 'ruby/trema/port-mod.c', line 178 static VALUE port_mod_config( VALUE self ) { return rb_iv_get( self, "@config" ); } |
#hw_addr ⇒ Mac
Ethernet address converted and stored as a Mac object.
166 167 168 169 |
# File 'ruby/trema/port-mod.c', line 166 static VALUE port_mod_hw_addr( VALUE self ) { return rb_iv_get( self, "@hw_addr" ); } |
#mask ⇒ Number
Set the bitmap as per config attribute.
189 190 191 192 |
# File 'ruby/trema/port-mod.c', line 189 static VALUE port_mod_mask( VALUE self ) { return rb_iv_get( self, "@mask" ); } |
#port_no ⇒ Number
Port number and hardware address as a pair identify a port.
155 156 157 158 |
# File 'ruby/trema/port-mod.c', line 155 static VALUE port_mod_port_no( VALUE self ) { return rb_iv_get( self, "@port_no" ); } |
#transaction_id ⇒ Number
Transaction ids, message sequence numbers matching requests to replies.
144 145 146 147 |
# File 'ruby/trema/port-mod.c', line 144 static VALUE port_mod_transaction_id( VALUE self ) { return rb_iv_get( self, "@transaction_id" ); } |