router id 10.x.x.x; define my_as = xxxxx; function net_martian() { return net ~ [ 169.254.0.0/16+, 172.16.0.0/12+, 192.168.0.0/16+, 10.0.0.0/8+, 224.0.0.0/4+, 240.0.0.0/4+, 0.0.0.0/32-, 0.0.0.0/0{25,32}, 0.0.0.0/0{0,7} ]; } function net_internal() { return net ~ [ 172.16.0.0/12+, 192.168.0.0/16+, 10.0.0.0/8+, x.x.x.0/22+, y.y.y.0/24+ ]; } function net_local() { return net ~ [ x.x.x.0/22+, y.y.y.0/24+ ]; } function net_peers_world() { return net ~ [ a.a.a.a/31+, b.b.b.b/31+ ]; } function rt_client(int asn_t; prefix set nets) { return (net ~ nets && (bgp_path.first = asn_t || bgp_path ~ [= my_as asn_t * =]) && bgp_path.last = asn_t); } function net_clients() { return rt_client(yyyyy, [c.c.c.0/24]); } function rt_export() { return ((proto = "static_bgp_ua" || proto = "static_bgp_w" || source = RTS_BGP) && !net_martian() && bgp_path.len < 64); } function rt_export_OSPF() { #connected & static if ( source = RTS_DEVICE || proto = "ospf_static" ) then { return true; } return false; } filter import_BGP { # Add prepend for datagroup AS if ( net_martian() || bgp_path.len > 45 ) then { reject; } accept; } filter import_BGP_local { if ( (net_martian() && !net_peers_world()) || bgp_path.len > 45 ) then { reject; } accept; } filter export_BGP_local_w { # only BGP routes if ( rt_export() || (net_peers_world() ) ) then { accept; } reject; } filter export_BGP_uplink_prepend { if ( rt_export() && (net_local() || net_clients()) ) then { bgp_path.prepend(my_as); bgp_path.prepend(my_as); accept; } reject; } filter export_OSPF_world { #connected & static if ( rt_export_OSPF() || net = 0.0.0.0/0 ) then { accept; } reject; } ipv4 table world; protocol direct { ipv4 { }; } protocol kernel kernel_main { persist; # Don't remove routes on bird shutdown scan time 20; # Scan kernel routing table every 20 seconds ipv4 { export all; # Default is export none import none; }; } protocol device { scan time 2; # Scan interfaces every 10 seconds } protocol static static_bgp_w { ipv4 { }; route x.x.x.0/22 unreachable; route y.y.y.0/24 unreachable; } protocol static static_ospf { ipv4 { preference 10; # Default preference of routes }; route 0.0.0.0/0 unreachable; } protocol pipe main_pipe_world { peer table world; import filter {krt_metric = 100; accept;}; export filter {if (source = RTS_DEVICE ) then {accept;} reject;}; table master4; } protocol ospf ospf_world { ipv4 { import all; export filter export_OSPF_world; table world; }; router id z.z.z.201; ecmp yes; area 100 { networks { z.z.z.0/24; }; interface "vlan3" { cost 5; type broadcast; hello 10; retransmit 5; wait 40; dead count 4; authentication none; stub no; }; }; } template bgp bgp_local_w { local as my_as; ipv4 { table world; import filter import_BGP_local; export filter export_BGP_local_w; }; multihop; rr client; rr cluster id 1.0.0.1; } protocol bgp bgp_peer_nas1_w from bgp_local_w { description "NAS 1"; neighbor z.z.z.1 as xxxxx; } protocol bgp bgp_peer_nas2_w from bgp_local_w { description "NAS 2"; neighbor z.z.z.2 as xxxxx; } protocol bgp bgp_peer_nas3_w from bgp_local_w { description "NAS 3"; neighbor z.z.z.3 as xxxxx; } protocol bgp bgp_peer_nas4_w from bgp_local_w { description "NAS 4"; neighbor z.z.z.4 as xxxxx; } protocol bgp bgp_peer_i1_w from bgp_local_w { description "IPoE 1"; neighbor z.z.z.11 as xxxxx; } protocol bgp bgp_peer_r2_w from bgp_local_w { description "Router 2"; neighbor z.z.z.102 as xxxxx; } protocol bgp bgp_peer_g2_w from bgp_local_w { description "Border 2"; neighbor z.z.z.202 as xxxxx; } template bgp bgp_uplink { local as my_as; ipv4 { import filter import_BGP; export filter export_BGP_uplink_prepend; }; default bgp_local_pref 1; } protocol bgp bgp_peer_uplink_w from bgp_uplink { description "world uplink"; ipv4 { table world; }; neighbor 194.146.196.16 as 3326; default bgp_local_pref 1; }