'check that packing and unpacking an ofp object works, and that lengths etc. are correct'

def _test_pack_unpack(self, o, xid, ofp_type=None):

    show = (lambda o: (o.show() if hasattr(o, 'show') else str(show)))
    if (not ofp_type):
        ofp_type = self.ofp_type[type(o)]
    self.assertTrue(o._assert(), ('pack_unpack    for    %s    --    original    object    should    _assert    to    true' % show(o)))
    o.show()
    pack = o.pack()
    self.assertEqual(len(o), len(pack), ('pack_unpack    for    %s    --    len(object)=%d    !=    len(packed)=%d' % (type(o), len(o), len(pack))))
    self.assert_packed_header(pack, ofp_type, len(o), xid)
    unpacked = type(o)()
    unpacked.unpack(pack)
    self.assertEqual(o, unpacked, ('pack_unpacked    --    original    !=    unpacked\n===Original:\n%s\n===Repacked:%s\n' % (show(o), show(unpacked))))
    return unpacked
