static void test_mac_to_uint64() { uint8_t mac1[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; uint8_t mac2[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; assert_true( mac_to_uint64( mac1 ) == 281474976710655ULL ); assert_true( mac_to_uint64( mac2 ) == 0 ); }
static VALUE match_dl( VALUE self, uint8_t which ) { struct ofp_match *match; uint8_t *dl_addr; match = get_match( self ); if ( which ) { dl_addr = match->dl_src; } else { dl_addr = match->dl_dst; } return rb_funcall( rb_eval_string( "Trema::Mac" ), rb_intern( "new" ), 1, ULL2NUM( mac_to_uint64( dl_addr ) ) ); }
VALUE port_from( const struct ofp_phy_port *phy_port ) { VALUE attributes = rb_hash_new(); rb_hash_aset( attributes, ID2SYM( rb_intern( "number" ) ), UINT2NUM( phy_port->port_no ) ); VALUE hw_addr = rb_funcall( rb_eval_string( "Trema::Mac" ), rb_intern( "new" ), 1, ULL2NUM( mac_to_uint64( phy_port->hw_addr ) ) ); rb_hash_aset( attributes, ID2SYM( rb_intern( "hw_addr" ) ), hw_addr ); rb_hash_aset( attributes, ID2SYM( rb_intern( "name" ) ), rb_str_new2( phy_port->name ) ); rb_hash_aset( attributes, ID2SYM( rb_intern( "config" ) ), UINT2NUM( phy_port->config ) ); rb_hash_aset( attributes, ID2SYM( rb_intern( "state" ) ), UINT2NUM( phy_port->state ) ); rb_hash_aset( attributes, ID2SYM( rb_intern( "curr" ) ), UINT2NUM( phy_port->curr ) ); rb_hash_aset( attributes, ID2SYM( rb_intern( "advertised" ) ), UINT2NUM( phy_port->advertised ) ); rb_hash_aset( attributes, ID2SYM( rb_intern( "supported" ) ), UINT2NUM( phy_port->supported ) ); rb_hash_aset( attributes, ID2SYM( rb_intern( "peer" ) ), UINT2NUM( phy_port->peer ) ); return rb_funcall( cPort, rb_intern( "new" ), 1, attributes ); }
/* * The MAC destination address. * * @return [Trema::Mac] macda MAC destination address. */ static VALUE packet_in_macda( VALUE self ) { packet_in *cpacket_in = get_packet_in( self ); VALUE macda = ULL2NUM( mac_to_uint64( packet_info( cpacket_in->data )->l2_data.eth->macda ) ); return rb_funcall( rb_eval_string( "Trema::Mac" ), rb_intern( "new" ), 1, macda ); }