kytos-ng / of_core

Kytos Main OpenFlow Network Application (NApp)
MIT License
0 stars 5 forks source link

Handler `kytos/core.openflow.raw.in` crashed when trying to log an OFPT_ERROR #61

Closed viniarck closed 2 years ago

viniarck commented 2 years ago

When I was migrationg flow_manager to MongoDB, I was exploring some OPFT_ERROR messages, and this crash showed up, the impact is high since it wont publish the message to listeners to properly handle it:

kytos $> 2022-05-19 15:46:21,503 - ERROR [kytos.core.helpers] (thread_pool_sb_0) listen_to handler: <function Main.on_raw_in at 0x7f972ac48430>, args: (<Main(of_core, started 140287221921344)>, KytosEvent('kytos/core.openflow.raw.in', {'source': Connection('127.0.0.1', 37552, <asyncio.TransportSocket fd=115, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 6653), raddr=('127.0.0.1', 37552)>, Switch('00:00:00:00:00:00:00:01'), <ConnectionState.ESTABLISHED: 2>), 'new_data': b'\x04\x01\x00d\xd4\xf4\x02\x99\x00\
x04\x00\x07\x04\x0e\x00X\xd4\xf4\x02\x99\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff
\x00\x01\x00\x00\x00\x01\x00\n\x80\x00\x0c\x027\x10\x00\x00\x00\x00\x00\x00\x00\x04\x00\x18\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x02\xff\xff\x00\x00\x00\x00\x00\x00\x04\x15\x00\
x08$.\x88\x99'})), exception: <class 'TypeError'>: unsupported format string passed to UBInt32.__format__

The root cause is a format that was being used at when trying to convert the UBInt* field type https://github.com/kytos-ng/of_core/blob/master/main.py#L344-L348

viniarck commented 2 years ago

To reproduce, you can send this request and check out kytos console:

❯ echo '{ "flows": [ { "match": { "dl_vlan": 10000 }, "actions": [ { "action_type": "output", "port": 2 } ] } ] }' | http POST http://localhost:8181/api/kytos/flow_manager/v2/flows/00:00
:00:00:00:00:00:01
HTTP/1.0 202 ACCEPTED
Access-Control-Allow-Origin: *
Content-Length: 37
Content-Type: application/json
Date: Thu, 19 May 2022 18:46:21 GMT
Server: Werkzeug/1.0.1 Python/3.9.12

{
    "response": "FlowMod Messages Sent"
}
italovalcy commented 2 years ago

Hi Vinicius, the logging in hex format was actually a request from @jab1982 to be convenient for tshoot some physical devices (which show XID in hex format on their logs, so comparing the requests would be easier if Kytos also exports on hex format). From what I understood, we should actually modify pyof to allow __format__ calls. What do you thinkg? Another option would be use UBInt32.value on the log call.