Beispiel #1
0
/* Load instruction addressed at IP */
void read_instruction(struct lilith* vm, struct Instruction *current)
{
	memset(current, 0, sizeof(struct Instruction));
	/* Store IP for debugging */
	current->ip = vm->ip;

	outside_of_world(vm, current->ip, "READ Instruction outside of World");

	/* Read the actual bytes and increment the IP */
	current->raw0 = (uint8_t)vm->memory[vm->ip];
	vm->ip = vm->ip + 1;
	current->raw1 = (uint8_t)vm->memory[vm->ip];
	vm->ip = vm->ip + 1;
	current->raw2 = (uint8_t)vm->memory[vm->ip];
	vm->ip = vm->ip + 1;
	current->raw3 = (uint8_t)vm->memory[vm->ip];
	vm->ip = vm->ip + 1;
	unpack_instruction(current);
}
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 );
  }
}