{"action":"created","issue":{"url":"https://api.github.com/repos/FRRouting/frr/issues/1145","repository_url":"https://api.github.com/repos/FRRouting/frr","labels_url":"https://api.github.com/repos/FRRouting/frr/issues/1145/labels{/name}","comments_url":"https://api.github.com/repos/FRRouting/frr/issues/1145/comments","events_url":"https://api.github.com/repos/FRRouting/frr/issues/1145/events","html_url":"https://github.com/FRRouting/frr/pull/1145","id":256316254,"number":1145,"title":"Multithreaded BGPD","user":{"login":"qlyoung","id":6827003,"avatar_url":"https://avatars3.githubusercontent.com/u/6827003?v=4","gravatar_id":"","url":"https://api.github.com/users/qlyoung","html_url":"https://github.com/qlyoung","followers_url":"https://api.github.com/users/qlyoung/followers","following_url":"https://api.github.com/users/qlyoung/following{/other_user}","gists_url":"https://api.github.com/users/qlyoung/gists{/gist_id}","starred_url":"https://api.github.com/users/qlyoung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qlyoung/subscriptions","organizations_url":"https://api.github.com/users/qlyoung/orgs","repos_url":"https://api.github.com/users/qlyoung/repos","events_url":"https://api.github.com/users/qlyoung/events{/privacy}","received_events_url":"https://api.github.com/users/qlyoung/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":17,"created_at":"2017-09-08T17:07:18Z","updated_at":"2017-09-20T15:58:21Z","closed_at":null,"author_association":"OWNER","pull_request":{"url":"https://api.github.com/repos/FRRouting/frr/pulls/1145","html_url":"https://github.com/FRRouting/frr/pull/1145","diff_url":"https://github.com/FRRouting/frr/pull/1145.diff","patch_url":"https://github.com/FRRouting/frr/pull/1145.patch"},"body":"This patch implements multithreading for BGP keepalive generation and network I/O. \r\n\r\nKeepalives \r\n------------ \r\nImplementation is in `bgp_keepalives.[ch]`. This is essentially a hash table with a mutex that holds peers who need keepalives and the time until they need one. To turn on keepalives for a peer call `bgp_keepalives_on(peer)`, which wakes the thread up, inserts the peer into the table, recalculates the smallest time until any one peer needs a KA and sleeps for that long. When the time has elapsed it wakes up, generates keepalives for as many peers as it can, calculates the new sleep time in the same pass, and goes back to sleep. Generating a keepalive is just making the packet and pushing it onto `peer->obuf`, after that the I/O thread handles the rest. \r\n\r\nI/O\r\n---\r\nImplementation is in `bgp_io.[ch]`. Thread runs its own event loop and communicates with the main thread by scheduling and receiving events. When a packet is pushed onto a peer's output buffer, `bgp_writes_on(peer)` is called from the owning  which pushes an event onto the I/O pthread's event queue, causing the peer socket to be added to the list of `poll()`'d file descriptors. At some point in the future the socket will become ready for writing (or the connection will die) at which point the output buffer is serviced. As many packets as possible are written either until the write quanta is reached or until a socket write becomes blocking. In either case the peer socket is rescheduled for writing until all packets on the output buffer have been written. Upon error a `BGP_Stop` event is generated on the main thread, write events are cancelled and session teardown proceeds as per usual. If the peer exhausts all the packets on its output buffer a new write event is not scheduled, `bgp_writes_on(peer)` must be called again to reschedule it. \r\n\r\nReads operate differently, when a caller wants to receive packets from a peer's socket, they register the peer with `bgp_reads_on(peer)`. When the peer's socket becomes ready for reading, as much data as possible is read off the socket into a raw input buffer. It is then broken up into individual BGP messages, whose headers are validated before being pushed onto the packet input queue. When new data is available on this queue an event is generated on the main pthread that schedules `bgp_process_packets()`, which handles processing the actual content of the messages, updating any internal state, generating FSM events etc. Reads automatically reschedule forever until `bgp_reads_off()` is called, or an error is encountered. If an error is encountered rescheduling stops and a `BGP_Stop` event is generated on the main pthread. \r\n\r\nSome changes to the structure of packet processing routines have been made to clean up their return codes, improve documentation and improve organization."},"comment":{"url":"https://api.github.com/repos/FRRouting/frr/issues/comments/330898296","html_url":"https://github.com/FRRouting/frr/pull/1145#issuecomment-330898296","issue_url":"https://api.github.com/repos/FRRouting/frr/issues/1145","id":330898296,"user":{"login":"NetDEF-CI","id":19297776,"avatar_url":"https://avatars3.githubusercontent.com/u/19297776?v=4","gravatar_id":"","url":"https://api.github.com/users/NetDEF-CI","html_url":"https://github.com/NetDEF-CI","followers_url":"https://api.github.com/users/NetDEF-CI/followers","following_url":"https://api.github.com/users/NetDEF-CI/following{/other_user}","gists_url":"https://api.github.com/users/NetDEF-CI/gists{/gist_id}","starred_url":"https://api.github.com/users/NetDEF-CI/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NetDEF-CI/subscriptions","organizations_url":"https://api.github.com/users/NetDEF-CI/orgs","repos_url":"https://api.github.com/users/NetDEF-CI/repos","events_url":"https://api.github.com/users/NetDEF-CI/events{/privacy}","received_events_url":"https://api.github.com/users/NetDEF-CI/received_events","type":"User","site_admin":false},"created_at":"2017-09-20T15:58:21Z","updated_at":"2017-09-20T15:58:21Z","author_association":"COLLABORATOR","body":"# Continuous Integration Result: SUCCESSFUL\n\nCongratulations, this patch passed basic tests\n\nTested-by: NetDEF / OpenSourceRouting.org CI System\n\nCI System Testrun URL: https://ci1.netdef.org/browse/FRR-FRRPULLREQ-1715/\n\nThis is a comment from an EXPERIMENTAL automated CI system.\nFor questions and feedback in regards to this CI system, please feel free to email\nMartin Winter - mwinter (at) opensourcerouting.org.\n\n\n-----------------------------\n### CLANG Static Analyzer Summary\n- Github Pull Request 1145, comparing to Git base SHA 9650716\n#### Fixed warnings:\n- Logic error: Dereference of null pointer in bgpd/bgp_packet.c, function bgp_read, line 2341\n#### Static Analysis warning summary compared to base:\n- Fixed warnings: 1\n- New warnings:   0\n#### 78 Static Analyzer issues remaining.\nSee details at\nhttps://ci1.netdef.org/browse/FRR-FRRPULLREQ-1715/artifact/shared/static_analysis/index.html\n"}}
{"actor":{"display_login":"NetDEF-CI"}}