static void
unpack_aggregate_multipart_reply( VALUE r_attributes, void *data ) {
  assert( data );
  const struct ofp_aggregate_stats_reply *aggregate_stats = data;

  HASH_SET( r_attributes, "packet_count", ULL2NUM( aggregate_stats->packet_count ) );
  HASH_SET( r_attributes, "byte_count", ULL2NUM( aggregate_stats->byte_count ) );
  HASH_SET( r_attributes, "flow_count", UINT2NUM( aggregate_stats->flow_count ) );
}
static void
unpack_table_multipart_reply( VALUE r_attributes, void *data ) {
  assert( data );
  const struct ofp_table_stats *table_stats = data;
  
  HASH_SET( r_attributes, "table_id", UINT2NUM( table_stats->table_id ) );
  HASH_SET( r_attributes, "active_count", UINT2NUM( table_stats->active_count ) );
  HASH_SET( r_attributes, "lookup_count", ULL2NUM( table_stats->lookup_count ) );
  HASH_SET( r_attributes, "matched_count", ULL2NUM( table_stats->matched_count ) );
}
static void
unpack_desc_multipart_reply( VALUE r_attributes, void *data ) {
  assert( data );
  const struct ofp_desc *desc_stats = data;

  if ( strlen( desc_stats->mfr_desc ) ) {
    HASH_SET( r_attributes, "mfr_desc", rb_str_new2( desc_stats->mfr_desc ) );
  }
  if ( strlen( desc_stats->hw_desc ) ) {
    HASH_SET( r_attributes, "hw_desc", rb_str_new2( desc_stats->hw_desc ) );
  }
  if ( strlen( desc_stats->sw_desc ) ) {
    HASH_SET( r_attributes, "sw_desc", rb_str_new2( desc_stats->sw_desc ) );
  }
  if ( strlen( desc_stats->serial_num ) ) {
    HASH_SET( r_attributes, "serial_num", rb_str_new2( desc_stats->serial_num ) );
  }
  if ( strlen( desc_stats->dp_desc ) ) {
    HASH_SET( r_attributes, "dp_desc", rb_str_new2( desc_stats->dp_desc ) );
  }
} 
Example #4
0
void
handle_error( uint64_t datapath_id,
              uint32_t transaction_id,
              uint16_t type,
              uint16_t code,
              const buffer *data,
              void *controller ) {
  if ( !rb_respond_to( ( VALUE ) controller, rb_intern( "error" ) ) ) {
    return;
  }
  
  VALUE r_attributes = rb_hash_new();
  HASH_SET( r_attributes, "datapath_id", ULL2NUM( datapath_id ) );
  HASH_SET( r_attributes, "transaction_id", UINT2NUM( transaction_id ) );
  HASH_SET( r_attributes, "type", UINT2NUM( type ) );
  HASH_SET( r_attributes, "code", UINT2NUM( code ) );
  HASH_SET( r_attributes, "data", buffer_to_r_array( data ) );

  VALUE r_error = rb_funcall( rb_eval_string( "Trema::Messages::Error" ), rb_intern( "new" ), 1, r_attributes );
  rb_funcall( ( VALUE ) controller, rb_intern( "error" ), 2, ULL2NUM( datapath_id ), r_error );
}
static void
unpack_flow_multipart_reply( VALUE r_attributes, void *data ) {
  assert( data );
  const struct ofp_flow_stats *flow_stats = data;

  HASH_SET( r_attributes, "length", UINT2NUM( flow_stats->length ) );
  HASH_SET( r_attributes, "table_id", UINT2NUM( flow_stats->table_id ) );
  HASH_SET( r_attributes, "duration_sec", UINT2NUM( flow_stats->duration_sec ) );
  HASH_SET( r_attributes, "duration_nsec", UINT2NUM( flow_stats->duration_nsec ) );
  HASH_SET( r_attributes, "priority", UINT2NUM( flow_stats->priority ) );
  HASH_SET( r_attributes, "idle_timeout", UINT2NUM( flow_stats->idle_timeout ) );
  HASH_SET( r_attributes, "hard_timeout", UINT2NUM( flow_stats->hard_timeout ) );
  HASH_SET( r_attributes, "flags", UINT2NUM( flow_stats->flags ) );
  HASH_SET( r_attributes, "cookie", ULL2NUM( flow_stats->cookie ) );
  HASH_SET( r_attributes, "packet_count", ULL2NUM( flow_stats->packet_count ) );
  HASH_SET( r_attributes, "byte_count", ULL2NUM( flow_stats->byte_count ) );
  VALUE r_match = ofp_match_to_r_match( &flow_stats->match );
  if ( !NIL_P( r_match ) ) {
    HASH_SET( r_attributes, "match", r_match );
  }
  uint16_t match_length = ( uint16_t ) ( flow_stats->match.length + PADLEN_TO_64( flow_stats->match.length ) );
  size_t offset = offsetof( struct ofp_flow_stats, match ) + match_length;
  size_t instructions_length = flow_stats->length - offset;

  VALUE r_instruction_ary = rb_ary_new();
  while ( instructions_length > sizeof( struct ofp_instruction ) ) {
    const struct ofp_instruction *inst_src = ( const struct ofp_instruction * ) ( ( const char * ) flow_stats + offset );

    uint16_t part_length = inst_src->len;
    if ( instructions_length < part_length ) {
      break;
    }
    unpack_instruction( inst_src, r_instruction_ary );

    instructions_length -= part_length;
    offset += part_length;
  }
  if ( RARRAY_LEN( r_instruction_ary ) ) {
    HASH_SET( r_attributes, "instructions", r_instruction_ary );
  }
}
static void
unpack_port_multipart_reply( VALUE r_attributes, void *data ) {
  assert( data );
  const struct ofp_port_stats *port_stats = data;

  HASH_SET( r_attributes, "port_no", UINT2NUM( port_stats->port_no ) );
  HASH_SET( r_attributes, "rx_packets", ULL2NUM( port_stats->rx_packets ) );
  HASH_SET( r_attributes, "tx_packets", ULL2NUM( port_stats->tx_packets ) );
  HASH_SET( r_attributes, "rx_bytes", ULL2NUM( port_stats->rx_bytes ) );
  HASH_SET( r_attributes, "tx_bytes", ULL2NUM( port_stats->tx_bytes ) );
  HASH_SET( r_attributes, "rx_dropped", ULL2NUM( port_stats->rx_dropped ) );
  HASH_SET( r_attributes, "tx_dropped", ULL2NUM( port_stats->tx_dropped ) );
  HASH_SET( r_attributes, "rx_errors", ULL2NUM( port_stats->rx_errors ) );
  HASH_SET( r_attributes, "tx_errors", ULL2NUM( port_stats->tx_errors ) );
  HASH_SET( r_attributes, "rx_frame_err", ULL2NUM( port_stats->rx_frame_err ) );
  HASH_SET( r_attributes, "rx_over_err", ULL2NUM( port_stats->rx_over_err ) );
  HASH_SET( r_attributes, "rx_crc_err", ULL2NUM( port_stats->rx_crc_err ) );
  HASH_SET( r_attributes, "collisions", ULL2NUM( port_stats->collisions ) );
  HASH_SET( r_attributes, "duration_sec", UINT2NUM( port_stats->duration_sec ) );
  HASH_SET( r_attributes, "duration_nsec", UINT2NUM( port_stats->duration_nsec ) );
}
Example #7
0
void
handle_flow_removed( uint64_t datapath_id,
                     uint32_t transaction_id,
                     uint64_t cookie,
                     uint16_t priority,
                     uint8_t reason,
                     uint8_t table_id,
                     uint32_t duration_sec,
                     uint32_t duration_nsec,
                     uint16_t idle_timeout,
                     uint16_t hard_timeout,
                     uint64_t packet_count,
                     uint64_t byte_count,
                     const oxm_matches *match,
                     void *controller ) {
  if ( !rb_respond_to( ( VALUE ) controller, rb_intern( "flow_removed" ) ) ) {
    return;
  }
  VALUE r_attributes = rb_hash_new();
  HASH_SET( r_attributes, "datapath_id", ULL2NUM( datapath_id ) );
  HASH_SET( r_attributes, "transaction_id", UINT2NUM( transaction_id ) );
  HASH_SET( r_attributes, "cookie", ULL2NUM( cookie ) );
  HASH_SET( r_attributes, "priority", UINT2NUM( priority ) );
  HASH_SET( r_attributes, "reason", UINT2NUM( reason ) );
  HASH_SET( r_attributes, "table_id", UINT2NUM( table_id ) );
  HASH_SET( r_attributes, "duration_sec", UINT2NUM( duration_sec ) );
  HASH_SET( r_attributes, "duration_nsec", UINT2NUM( duration_nsec ) );
  HASH_SET( r_attributes, "idle_timeout", UINT2NUM( idle_timeout ) );
  HASH_SET( r_attributes, "hard_timeout", UINT2NUM( hard_timeout ) );
  HASH_SET( r_attributes, "packet_count", ULL2NUM( packet_count ) );
  HASH_SET( r_attributes, "byte_count", ULL2NUM( byte_count ) );

  if ( match != NULL ) {
    VALUE r_match = oxm_match_to_r_match( match );
    HASH_SET( r_attributes, "match", r_match );
  }
  VALUE r_flow_removed = rb_funcall( rb_eval_string( "Messages::FlowRemoved" ), rb_intern( "new" ), 1, r_attributes );
  rb_funcall( ( VALUE ) controller, rb_intern( "flow_removed" ), 2, ULL2NUM( datapath_id ), r_flow_removed );
}