Advertisement
Guest User

FFRL Backbone BIRD Configuration

a guest
Sep 21st, 2015
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 11.15 KB | None | 0 0
  1. define ROUTER_ID = 185.66.192.3;
  2. define AS_FFRL = 201701;
  3. define METRO_IDENTIFIER = 195;
  4. define ANNOUNCE_ALL = 300;
  5. define GLOBAL_ROUTE = (5093,200);
  6. define METRO_ROUTE = (5093,201);
  7. define BERLIN_ROUTE = (5093,195);
  8. define FRANKFURT_ROUTE = (5093,194);
  9. define DUESSELDORF_ROUTE = (5093,193);
  10. define AGGREGATE_ROUTE = (5093,191);
  11. define ROUTE_ORIGIN = (5093,195);
  12.  
  13. define DRAINED = 0;
  14. define METROIZED = 0;
  15.  
  16. router id 185.66.192.3;
  17. log syslog all;
  18. graceful restart wait 300;
  19.  
  20. function is_our_net () {
  21.         return net ~ [ 185.66.192.0/22+ ];
  22. }
  23.  
  24. protocol kernel {
  25.         scan time 10;
  26.         import all;
  27.         export all;
  28. }
  29.  
  30. protocol static {
  31.         #route 0.0.0.0/0 unreachable;
  32.         route 185.66.195.0/24 unreachable;
  33.         route 185.66.192.0/22 unreachable;
  34. }
  35.  
  36. protocol device {
  37.         scan time 10;
  38. }
  39.  
  40. protocol ospf IGP {
  41.         import all;
  42.         export none;
  43.  
  44.         area 0.0.0.0 {
  45.                 interface "lo" {
  46.                         stub yes;
  47.                 };
  48.  
  49.                 # X-Link bb-b.ber
  50.                 interface "eth4" {
  51.                         type broadcast;
  52.                         cost 1;
  53.                 };
  54.         };
  55. }
  56.  
  57. ################################################################################
  58. #                                Peering Policy                                #
  59. ################################################################################
  60.  
  61. function community_in() {
  62.         bgp_local_pref = 10000;
  63.         bgp_med = 0;
  64. }
  65.  
  66. filter drain {
  67.         reject;
  68. }
  69.  
  70. filter ibgp_in {
  71.         if (GLOBAL_ROUTE ~ bgp_community) then {
  72.                 accept;
  73.         }
  74.         if (METRO_ROUTE ~ bgp_community) then {
  75.                 if (ROUTE_ORIGIN ~ bgp_community) then {
  76.                         accept;
  77.                 }
  78.                 else {
  79.                         bgp_local_pref = 5;
  80.                         accept;
  81.                 }
  82.         }
  83.         accept;
  84. }
  85.  
  86. function peer_ip_filter_in() {
  87.         if DRAINED = 1 then
  88.                 return 0;
  89.         if net ~ [
  90.                 10.0.0.0/8{8,32},
  91.                 172.16.0.0/12{8,32},
  92.                 192.168.0.0/16{16,32},
  93.                 169.254.0.0/16{16,32},
  94.                 224.0.0.0/3{3,32},
  95.                 185.66.192.0/22{22,32},
  96.                 100.64.0.0/10{10,32},
  97.                 0.0.0.0/8{8,32},
  98.                 127.0.0.0/8{8,32},
  99.                 192.0.0.0/24{24,32},
  100.                 198.18.0.0/15{15,32},
  101.                 198.51.100.0/24{24,32},
  102.                 203.0.113.0/24{24,32},
  103.                 240.0.0.0/4{4,32},
  104.                 255.255.255.255/32,
  105.                 0.0.0.0/0
  106.                 ] then {
  107.                 return 0;
  108.         }
  109.         if net ~ [ 0.0.0.0/0{8,24} ] then {
  110.                 return 1;
  111.         }
  112.         return 0;
  113. }
  114.  
  115. function peer_ip_filter_out() {
  116.         if DRAINED = 1 then
  117.                 return 0;
  118.         if net ~ [
  119.                 185.66.192.0/22{22,24}
  120.         ] then {
  121.                 return 1;
  122.         }
  123.         return 0;
  124. }
  125.  
  126. function modify_originated_routes()
  127. {
  128.         bgp_path.empty;
  129.         if net = 185.66.192.0/22 then {
  130.                 bgp_community.add(AGGREGATE_ROUTE);
  131.                 bgp_community.add(BERLIN_ROUTE);
  132.                 return true;
  133.         }
  134.         if net = 185.66.195.0/24 then {
  135.                 bgp_community.add(METRO_ROUTE);
  136.                 bgp_community.add(BERLIN_ROUTE);
  137.                 return true;
  138.         }
  139.         return true;
  140. }
  141.  
  142. function ebgp_out(string rt_scope)
  143. int path_prepend;
  144. {
  145.         if peer_ip_filter_out() = 0 then {
  146.                 return 0;
  147.         }
  148.  
  149.         modify_originated_routes();
  150.  
  151.         path_prepend = 0;
  152.  
  153.         if "global-transit" = rt_scope then {
  154.                 path_prepend = 1;
  155.         }
  156.         if "metro-transit" = rt_scope then {
  157.                 path_prepend = 1;
  158.         }
  159.  
  160.         if path_prepend = 1 then {
  161.                 bgp_path.prepend(AS_FFRL);
  162.                 bgp_path.prepend(AS_FFRL);
  163.                 bgp_path.prepend(AS_FFRL);
  164.         }
  165.  
  166.         if ("metro-transit" = rt_scope) || ("metro-peering" = rt_scope) then {
  167.                 if METROIZED = 0 then {
  168.                         if (AGGREGATE_ROUTE ~ bgp_community) then {
  169.                                 return 1;
  170.                         }
  171.                 }
  172.                 else {
  173.                         if (AGGREGATE_ROUTE ~ bgp_community) then {
  174.                                 return 0;
  175.                         }
  176.                 }
  177.                 if (ROUTE_ORIGIN ~ bgp_community) then {
  178.                         return 1;
  179.                 }
  180.                 return 0;
  181.         }
  182.  
  183.         if "global-transit" = rt_scope || "global-peering" = rt_scope then {
  184.                 if METROIZED = 0 then {
  185.                         if (AGGREGATE_ROUTE ~ bgp_community) then {
  186.                                 return 1;
  187.                         }
  188.                         if (METRO_ROUTE ~ bgp_community) then {
  189.                                 return 1;
  190.                         }
  191.                 }
  192.                 else {
  193.                         if (AGGREGATE_ROUTE ~ bgp_community) then {
  194.                                 return 0;
  195.                         }
  196.                 }
  197.                 if (ROUTE_ORIGIN ~ bgp_community) then {
  198.                         return 1;
  199.                 }
  200.                 return 0;
  201.         }
  202.         return 0;
  203. }
  204.  
  205. function ebgp_in(string rt_scope)
  206. int lpref;
  207. int rt_med;
  208. int metroized;
  209. {
  210.         if peer_ip_filter_in() = 0 then {
  211.                 return 0;
  212.         }
  213.  
  214.         if "global-transit" = rt_scope then
  215.                 lpref = 500; rt_med = 0; metroized = 0;
  216.         if "metro-transit" = rt_scope then
  217.                 lpref = 500; rt_med = 0; metroized = 1;
  218.         if "global-peer" = rt_scope then
  219.                 lpref = 1000; rt_med = 0; metroized = 0;
  220.         if "metro-peer" = rt_scope then
  221.                 lpref = 1000; rt_med = 0; metroized = 1;
  222.         if "px-global-peer" = rt_scope then
  223.                 lpref = 1000; rt_med = 100; metroized = 0;
  224.         if "px-metro-peer" = rt_scope then
  225.                 lpref = 1000; rt_med = 100; metroized = 1;
  226.         if "px-global-backup-peer" = rt_scope then
  227.                 lpref = 1000; rt_med = 500; metroized = 0;
  228.         if "px-metro-backup-peer" = rt_scope then
  229.                 lpref = 1000; rt_med = 500; metroized = 1;
  230.         if "route-server" = rt_scope then
  231.                 lpref = 1000; rt_med = 1000; metroized = 0;
  232.  
  233.         bgp_local_pref = lpref;
  234.         bgp_med = rt_med;
  235.         if metroized = 1 then {
  236.                 bgp_community.add(METRO_ROUTE);
  237.         }
  238.         else {
  239.                 if METROIZED = 1 then {
  240.                         bgp_community.add(METRO_ROUTE);
  241.                 }
  242.                 else {
  243.                         bgp_community.add(GLOBAL_ROUTE);
  244.                 }
  245.         }
  246.  
  247.         bgp_community.add(BERLIN_ROUTE);
  248.         return 1;
  249. }
  250.  
  251. filter global_transit_in {
  252.         if ebgp_in("global-transit") = 1 then
  253.                 accept;
  254.         reject;
  255. }
  256.  
  257. filter metro_transit_in {
  258.         if ebgp_in("metro-transit") = 1 then
  259.                 accept;
  260.         reject;
  261. }
  262.  
  263. filter global_peer_in {
  264.         if ebgp_in("global-peer") = 1 then
  265.                 accept;
  266.         reject;
  267. }
  268.  
  269. filter metro_peer_in {
  270.         if ebgp_in("metro-peer") = 1 then
  271.                 accept;
  272.         reject;
  273. }
  274.  
  275. filter px_global_peer_in {
  276.         if ebgp_in("px-global-peer") = 1 then
  277.                 accept;
  278.         reject;
  279. }
  280.  
  281. filter px_metro_peer_in {
  282.         if ebgp_in("px-metro-peer") = 1 then
  283.                 accept;
  284.         reject;
  285. }
  286.  
  287. filter px_global_backup_peer_in {
  288.         if ebgp_in("px-global-backup-peer") = 1 then
  289.                 accept;
  290.         reject;
  291. }
  292.  
  293. filter px_metro_backup_peer_in {
  294.         if ebgp_in("px-metro-backup-peer") = 1 then
  295.                 accept;
  296.         reject;
  297. }
  298.  
  299. filter route_server_in {
  300.         if ebgp_in("route-server") = 1 then
  301.                 accept;
  302.         reject;
  303. }
  304.  
  305. filter global_transit_out {
  306.         if ebgp_out("global-transit") = 1 then
  307.                 accept;
  308.         reject;
  309. }
  310.  
  311. filter metro_transit_out {
  312.         if ebgp_out("metro-transit") = 1then
  313.                 accept;
  314.         reject;
  315. }
  316.  
  317. filter global_peer_out {
  318.         if ebgp_out("global-peering") = 1 then
  319.                 accept;
  320.         reject;
  321. }
  322.  
  323. filter metro_peer_out {
  324.         if ebgp_out("metro-peering") = 1 then
  325.                 accept;
  326.         reject;
  327. }
  328.  
  329. filter community_out {
  330.         if DRAINED = 1 then
  331.                 reject;
  332.         if net = 0.0.0.0/0 then
  333.                 accept;
  334.         reject;
  335. }
  336.  
  337. ################################################################################
  338. #                                BGP templates                                 #
  339. ################################################################################
  340.  
  341. template bgp general_bgp {
  342.         local as AS_FFRL;
  343.         enable route refresh on;
  344.         graceful restart time 300;
  345.         med metric on;
  346. }
  347.  
  348. template bgp ibgp from general_bgp {
  349.         password "%BEXL6y]";
  350.         source address 185.66.192.3;
  351.         import filter ibgp_in;
  352. }
  353.  
  354. ##########################################
  355. #       Upstream BGP templates           #
  356. ##########################################
  357.  
  358. template bgp global_transit from general_bgp {
  359.         import filter global_transit_in;
  360.         export filter global_transit_out;
  361. }
  362.  
  363. template bgp metro_transit from general_bgp {
  364.         import filter metro_transit_in;
  365.         export filter metro_transit_out;
  366. }
  367.  
  368. ##########################################
  369. #        Peering BGP templates           #
  370. ##########################################
  371.  
  372. template bgp global_peer from general_bgp {
  373.         import filter global_peer_in;
  374.         export filter global_peer_out;
  375. }
  376.  
  377. template bgp metro_peer from general_bgp {
  378.         import filter metro_peer_in;
  379.         export filter metro_peer_out;
  380. }
  381.  
  382. template bgp px_global_peer from general_bgp {
  383.         import filter px_global_peer_in;
  384.         export filter global_peer_out;
  385. }
  386.  
  387. template bgp px_metro_peer from general_bgp {
  388.         import filter px_metro_peer_in;
  389.         export filter metro_peer_out;
  390. }
  391.  
  392. template bgp px_global_backup_peer from general_bgp {
  393.         import filter px_global_backup_peer_in;
  394.         export filter global_peer_out;
  395. }
  396.  
  397. template bgp px_metro_backup_peer from general_bgp {
  398.         import filter px_metro_backup_peer_in;
  399.         export filter metro_peer_out;
  400. }
  401.  
  402. template bgp route_server from general_bgp {
  403.         import filter route_server_in;
  404.         export filter metro_peer_out;
  405. }
  406.  
  407. ##########################################
  408. #       Downstream BGP templates         #
  409. ##########################################
  410.  
  411. template bgp ebgp_community from general_bgp {
  412.         export filter {
  413.                 if net = 0.0.0.0/0 then accept;
  414.                 reject;
  415.         };
  416. }
  417.  
  418. # Load additiional configuration (iBGP, Peerings, Transits, 'n stuff)
  419. include "/etc/bird/bird.d/*.conf";
  420. include "/etc/bird/bird.d/communities/*.conf";
  421. include "/etc/bird/bird.d/upstreams/*.conf";
  422. include "/etc/bird/bird.d/peerings/*.conf";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement