O regex e essencialmente um parser, mas aplicado ao BGP torna-se um utilitário muito útil no parsing de rotas aprendidas pelo router. Existem alguns servidores públicos de rotas onde e possível testar o regex no BGP (consultar lista abaixo).
Exemplos:
!Rotas originadas no AS 21740
ns-route-server> sh ip bg reg _21740$
BGP table version is 934229088, local router ID is 24.137.100.8
Status codes: s suppressed, d damped, h history, * valid, > best, i – internal,
r RIB-failure, S Stale
Origin codes: i – IGP, e – EGP, ? – incomplete
Network Next Hop Metric LocPrf Weight Path
*>i8.5.0.0/24 77.67.70.141 622 100 0 3257 21740 i
*>i8.5.0.0/23 77.67.70.141 622 100 0 3257 21740 i
!Rotas com origem nos neighbors do AS 3257
ns-route-server>sh ip bg reg ^3257_([0-9]+)?$
BGP table version is 934227310, local router ID is 24.137.100.8
Status codes: s suppressed, d damped, h history, * valid, > best, i – internal,
r RIB-failure, S Stale
Origin codes: i – IGP, e – EGP, ? – incomplete
Network Next Hop Metric LocPrf Weight Path
* i1.9.0.0/16 77.67.70.77 90 100 0 3257 4788 i
*>i1.9.52.0/24 77.67.70.77 180 100 0 3257 4788 ?
*>i1.9.53.0/24 77.67.70.141 613 100 0 3257 4788 ?
Tabela Caracteres no Regex:
Caracter | Significado |
^ | Start of string |
$ | End of string |
[] | Range of characters |
– | Used to specify range ( i.e. [0-9] ) |
( ) | Logical grouping |
. | Any single character |
* | Zero or more instances |
+ | One or more instance |
? | Zero or one instance |
_(underscore) | Comma, open or close brace, open or close parentheses, start or end of string, or space |
\ | Matches the character following the backslash. Also matches (escapes) special characters. |
| | Concatenates constructs. Matches one of the characters or character patterns on either side of the vertical bar. |
Lista servidores públicos de rotas: