Class: Trema::PortMod

Inherits:
Object
  • Object
show all
Defined in:
ruby/trema/port-mod.c

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PortMod

A Trema::PortMod instance a request object to perform operations on a physical port.

Returns an object that encapsulates the OFPT_PORT_MOD OpenFlow message.

Examples:

PortMod.new(
  :port_no => 1,
  :hw_addr => "11:22:33:44:55:66",
  :config => 1,
  :mask => 1,
  :advertise => 0
)

Parameters:

  • (defaults to: {})

    the options to create a message with.

  • an index into datapath’s ports list.

  • the hardware address of a port. Unique for each port. Obtained from OFPT_FEATURES_REPLY message. Can be supplied as a string, number or as a Mac object.

  • a bitmap that can be set to configure a port.

  • set the bits of the config flag to change.

  • bitmap of ofp_port_features set to zero to prevent any changes. Or can be copied from OFPT_FEATURES_REPLY message.



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 options;

  if ( rb_scan_args( argc, argv, "01", &options ) == 1 ) {
    Check_Type( options, 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( options, 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( options, 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( options, ID2SYM( rb_intern( "config" ) ) ) ) != Qnil ) {
      rb_iv_set( self, "@config", config );
    }
    VALUE  mask;
    if ( ( mask = rb_hash_aref( options, ID2SYM( rb_intern( "mask" ) ) ) ) != Qnil ) {
      rb_iv_set( self, "@mask", mask );
    }
    VALUE advertise;
    if ( ( advertise = rb_hash_aref( options, 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

Set to zero to prevent any changes.

Returns:

  • the value of advertise.



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" );
}

#configNumber

A port can be administratively brought down, disable flooding or packet forwarding or any other options as per ofp_port_config. flags.

Returns:

  • the value of config.



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_addrMac

Ethernet address converted and stored as a Mac object.

Returns:

  • the value of hw_addr.



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" );
}

#maskNumber

Set the bitmap as per config attribute.

Returns:

  • the value of mask.



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_noNumber

Port number and hardware address as a pair identify a port.

Returns:

  • the value of port_no.



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_idNumber

Transaction ids, message sequence numbers matching requests to replies.

Returns:

  • the value of transaction_id.



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" );
}