Here's some example of using libbgp. You can compile examples with the following command:
$ c++ name_of_example.cc -lbgp -o name_of_example
Some examples require you to link pthread too. Add -lpthread after -lbgp to compile those examples. For example, to compile peer-and-print.cc, do the following:
$ c++ peer-and-print.cc -lbgp -lpthread -o peer-and-print
Then you can run the example with ./peer-and-print. (you may need root for this specific example since this example open a TCP socket listening on a well-known port)
The following examples are avaliable:
deserialize-and-serialize.cc: Deserializing and serializing BGP message withBgpPacket.peer-and-print.cc: listen on TCP0.0.0.0:179, wait for a peer, and print all BGP messages sent/received withBgpFsm. (pthreadneeded for thetickerthread)route-event-bus.cc: Example of adding new routes to RIB while BGP FSM is running. Notify BGP FSM to send updates to the peer withRouteEventBus. This example also shows how you can implement your ownBgpOutHandlerandBgpLogHandler.route-filter.cc: Example of using ingress/egress route filtering feature of BgpFsm. This example also shows how you can implement your ownBgpOutHandlerandBgpLogHandler.route-server.cc: Simple BGP route server implements with libbgp. Use ofRouteEventBusand sharedBgpRibis demoed in this example. This example also shows how you can implement your ownBgpLogHandler. (pthreadneeded)
All the example codes are distributed under the Unlicense license.