Skip to content

Commit

Permalink
FRR: Parse IPv6 BGP neighbors (#6587)
Browse files Browse the repository at this point in the history
  • Loading branch information
ratulm committed Jan 25, 2021
1 parent b7639c5 commit 612b9e1
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,16 @@ IP_PREFIX
F_IpPrefix
;

IPV6_ADDRESS
:
F_Ipv6Address
;

IPV6_PREFIX
:
F_Ipv6Prefix
;

L2VPN
:
'l2vpn'
Expand Down Expand Up @@ -846,6 +856,145 @@ F_Digit
[0-9]
;

fragment
F_HexDigit
:
[0-9A-Fa-f]
;

fragment
F_HexWord
:
F_HexDigit F_HexDigit? F_HexDigit? F_HexDigit?
;

fragment
F_HexWord2
:
F_HexWord ':' F_HexWord
;

fragment
F_HexWord3
:
F_HexWord2 ':' F_HexWord
;

fragment
F_HexWord4
:
F_HexWord3 ':' F_HexWord
;

fragment
F_HexWord5
:
F_HexWord4 ':' F_HexWord
;

fragment
F_HexWord6
:
F_HexWord5 ':' F_HexWord
;

fragment
F_HexWord7
:
F_HexWord6 ':' F_HexWord
;

fragment
F_HexWord8
:
F_HexWord6 ':' F_HexWordFinal2
;

fragment
F_HexWordFinal2
:
F_HexWord2
| F_IpAddress
;

fragment
F_HexWordFinal3
:
F_HexWord ':' F_HexWordFinal2
;

fragment
F_HexWordFinal4
:
F_HexWord ':' F_HexWordFinal3
;

fragment
F_HexWordFinal5
:
F_HexWord ':' F_HexWordFinal4
;

fragment
F_HexWordFinal6
:
F_HexWord ':' F_HexWordFinal5
;

fragment
F_HexWordFinal7
:
F_HexWord ':' F_HexWordFinal6
;

fragment
F_HexWordLE1
:
F_HexWord?
;

fragment
F_HexWordLE2
:
F_HexWordLE1
| F_HexWordFinal2
;

fragment
F_HexWordLE3
:
F_HexWordLE2
| F_HexWordFinal3
;

fragment
F_HexWordLE4
:
F_HexWordLE3
| F_HexWordFinal4
;

fragment
F_HexWordLE5
:
F_HexWordLE4
| F_HexWordFinal5
;

fragment
F_HexWordLE6
:
F_HexWordLE5
| F_HexWordFinal6
;

fragment
F_HexWordLE7
:
F_HexWordLE6
| F_HexWordFinal7
;

fragment
F_IpAddress
:
Expand All @@ -866,6 +1015,35 @@ F_IpPrefixLength
| [3] [012]
;

fragment
F_Ipv6Address
:
'::' F_HexWordLE7
| F_HexWord '::' F_HexWordLE6
| F_HexWord2 '::' F_HexWordLE5
| F_HexWord3 '::' F_HexWordLE4
| F_HexWord4 '::' F_HexWordLE3
| F_HexWord5 '::' F_HexWordLE2
| F_HexWord6 '::' F_HexWordLE1
| F_HexWord7 '::'
| F_HexWord8
;

fragment
F_Ipv6Prefix
:
F_Ipv6Address '/' F_Ipv6PrefixLength
;

fragment
F_Ipv6PrefixLength
:
F_Digit
| F_PositiveDigit F_Digit
| '1' [01] F_Digit
| '12' [0-8]
;

fragment
F_SubnetMask
:
Expand Down Expand Up @@ -1095,6 +1273,11 @@ M_Neighbor_IP_Address
F_IpAddress -> type(IP_ADDRESS) , popMode
;

M_Neighbor_IPV6_Address
:
F_Ipv6Address -> type(IPV6_ADDRESS) , popMode
;

M_Neighbor_Word
:
F_Word -> type(WORD) , popMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ statement
| s_frr
| s_hostname
| s_ip
| s_ipv6
| s_line
| s_log
| s_no
Expand Down Expand Up @@ -102,6 +103,11 @@ s_ip
)
;

s_ipv6
:
IPV6 null_rest_of_line
;

ip_route
:
ROUTE network = prefix (next_hop_ip = ip_address | next_hop_interface = word) (distance = uint8)?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ sbb_cluster_id

sb_neighbor
:
NEIGHBOR (sbn_ip | sbn_name) NEWLINE
NEIGHBOR (sbn_ip | sbn_ip6 | sbn_name) NEWLINE
;

sb_address_family
Expand All @@ -117,6 +117,7 @@ sb_address_family
sbaf
:
sbaf_ipv4_unicast
| sbaf_ipv6_unicast
| sbaf_l2vpn_evpn
;

Expand All @@ -134,6 +135,22 @@ sbaf_ipv4_unicast
)*
;

sbaf_ipv6_unicast
:
IPV6 UNICAST NEWLINE
sbafi6_null_tail*
;

sbafi6_null_tail
:
(
// there are likely others but haven't seen examples yet, so leaving for later
NEIGHBOR
| REDISTRIBUTE
) null_rest_of_line
;


sbaf_l2vpn_evpn
:
L2VPN EVPN NEWLINE
Expand Down Expand Up @@ -209,6 +226,11 @@ sbn_ip
ip = IP_ADDRESS sbn_property
;

sbn_ip6
:
ip6 = IPV6_ADDRESS sbn_property
;

sbn_name
:
name = word
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ rm_match
| rmm_community
| rmm_interface
| rmm_ip
| rmm_ipv6
| rmm_tag
)
;
Expand Down Expand Up @@ -101,6 +102,11 @@ rmm_ip
IP rmmip_address
;

rmm_ipv6
:
IPV6 null_rest_of_line
;

rmm_tag
:
TAG tag = uint32 NEWLINE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.batfish.common.Warnings.ParseWarning;
import org.batfish.datamodel.ConcreteInterfaceAddress;
import org.batfish.datamodel.Ip;
import org.batfish.datamodel.Ip6;
import org.batfish.datamodel.LineAction;
import org.batfish.datamodel.Prefix;
import org.batfish.datamodel.SubRange;
Expand Down Expand Up @@ -125,6 +126,7 @@
import org.batfish.grammar.cumulus_frr.CumulusFrrParser.Sbb_router_idContext;
import org.batfish.grammar.cumulus_frr.CumulusFrrParser.Sbbb_aspath_multipath_relaxContext;
import org.batfish.grammar.cumulus_frr.CumulusFrrParser.Sbn_interfaceContext;
import org.batfish.grammar.cumulus_frr.CumulusFrrParser.Sbn_ip6Context;
import org.batfish.grammar.cumulus_frr.CumulusFrrParser.Sbn_ipContext;
import org.batfish.grammar.cumulus_frr.CumulusFrrParser.Sbn_nameContext;
import org.batfish.grammar.cumulus_frr.CumulusFrrParser.Sbn_peer_group_declContext;
Expand All @@ -149,6 +151,7 @@
import org.batfish.representation.cumulus.BgpInterfaceNeighbor;
import org.batfish.representation.cumulus.BgpIpNeighbor;
import org.batfish.representation.cumulus.BgpIpv4UnicastAddressFamily;
import org.batfish.representation.cumulus.BgpIpv6Neighbor;
import org.batfish.representation.cumulus.BgpL2VpnEvpnIpv4Unicast;
import org.batfish.representation.cumulus.BgpL2vpnEvpnAddressFamily;
import org.batfish.representation.cumulus.BgpNeighbor;
Expand Down Expand Up @@ -871,11 +874,20 @@ public void exitSbb_max_med_administrative(Sbb_max_med_administrativeContext ctx

@Override
public void enterSbn_ip(Sbn_ipContext ctx) {
String name = ctx.ip.getText();
_currentBgpNeighbor =
_currentBgpVrf
.getNeighbors()
.computeIfAbsent(name, (ipStr) -> new BgpIpNeighbor(ipStr, Ip.parse(ipStr)));
.computeIfAbsent(
ctx.ip.getText(), (ipStr) -> new BgpIpNeighbor(ipStr, Ip.parse(ipStr)));
}

@Override
public void enterSbn_ip6(Sbn_ip6Context ctx) {
_currentBgpNeighbor =
_currentBgpVrf
.getNeighbors()
.computeIfAbsent(
ctx.ip6.getText(), (ipStr) -> new BgpIpv6Neighbor(ipStr, Ip6.parse(ipStr)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.batfish.representation.cumulus;

import javax.annotation.Nonnull;
import org.batfish.datamodel.Ip6;

/** BGP neighbor identified by an IPv4 peer address */
public class BgpIpv6Neighbor extends BgpNeighbor {
private final @Nonnull Ip6 _peerIp;

public BgpIpv6Neighbor(String name, Ip6 ip6) {
super(name);
_peerIp = ip6;
}

public @Nonnull Ip6 getPeerIp() {
return _peerIp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ static void addBgpNeighbor(
} else if (neighbor instanceof BgpIpNeighbor) {
BgpIpNeighbor ipNeighbor = (BgpIpNeighbor) neighbor;
addIpv4BgpNeighbor(c, vsConfig, ipNeighbor, localAs, bgpVrf, viBgpProcess, w);
} else if (!(neighbor instanceof BgpPeerGroupNeighbor)) {
} else if (!(neighbor instanceof BgpPeerGroupNeighbor || neighbor instanceof BgpIpv6Neighbor)) {
throw new IllegalArgumentException(
"Unsupported BGP neighbor type: " + neighbor.getClass().getSimpleName());
}
Expand Down
Loading

0 comments on commit 612b9e1

Please sign in to comment.