Example of using ingress/egress route filtering feature of BgpFsm. This example also shows how you can implement your own BgpOutHandler and BgpLogHandler.
#include <libbgp/bgp-fsm.h>
#include <arpa/inet.h>
public:
PipedOutHandler() {
other = NULL;
}
this->other = other;
}
bool handleOut(
const uint8_t *buffer,
size_t length) {
return other->
run(buffer, length) >= 0;
};
private:
};
public:
MyLoghandler(const char *name) {
this->name = name;
}
protected:
void logImpl(const char* str) {
printf("[%s] %s", name, str);
}
private:
const char *name;
};
int main(void) {
MyLoghandler local_logger("local");
MyLoghandler remote_logger("remote");
local_logger.setLogLevel(libbgp::DEBUG);
remote_logger.setLogLevel(libbgp::DEBUG);
);
);
);
PipedOutHandler pipe_local;
local_bgp_config.
asn = 65000;
local_bgp_config.peer_asn = 65001;
local_bgp_config.use_4b_asn = true;
local_bgp_config.mp_bgp_ipv4 = false;
local_bgp_config.mp_bgp_ipv6 = false;
local_bgp_config.hold_timer = 120;
local_bgp_config.out_handler = &pipe_local;
local_bgp_config.no_collision_detection = true;
local_bgp_config.rib4 = NULL;
local_bgp_config.rev_bus = NULL;
local_bgp_config.clock = NULL;
local_bgp_config.log_handler = &local_logger;
local_bgp_config.in_filters4 = ingress_rules;
local_bgp_config.out_filters4 = egress_rules;
inet_pton(AF_INET, "10.0.0.1", &local_bgp_config.router_id);
inet_pton(AF_INET, "10.0.0.1", &local_bgp_config.default_nexthop4);
local_bgp_config.forced_default_nexthop4 = true;
local_bgp_config.no_nexthop_check4 = true;
PipedOutHandler pipe_remote;
remote_bgp_config.
asn = 65001;
remote_bgp_config.
rib4 = NULL;
remote_bgp_config.
clock = NULL;
inet_pton(AF_INET,
"10.0.0.2", &remote_bgp_config.
router_id);
pipe_local.setPeer(&remote);
pipe_remote.setPeer(&local);
return 0;
}