BGP EVPN for MPLS networks: implementing EVPN IRB and VPWS services
Besides VXLAN BGP EVPN can also be used for MPLS networks as the control plane protocol, this is what we're going to take a look at in this post. Many people associate BGP EVPN with VXLAN, and they're not wrong, EVPN is mostly used in DC environments. But BGP EVPN doesn't actually specify any data plane protocol, it is only a way to learn MAC/IP addresses between routers. BGP EVPN is actually data plane agnostic, we can substitute the MPLS label to the VNI used in the VXLAN header. So let's take a look at the topology and let's see what are we're trying to accomplish in this lab:

We can be very flexible with EVPN: IRB (Integrated Routing and Switching) allows devices to perform both L2 switching and L3 routing on the same interface and provide seamless communication between L2 and L3 networks. This is what we're going to configure for Customer 1. Customer 1 (puple) has the same subnet configured at Site 1 and Site 2, so we're going to provide L2 services between Site 1 and Site 2. Besides that we're going to configure L3 services between Site 1 and Site 3, so Customer 1 will be able to ping between loopback 11.11.11.11 (located at Site 1) and loopback 12.12.12.12 (located at Site 3). But Site 2 and Site 3 should not be able to communicate with each other. For Customer 2 (green) we're going provide EVPN VPWS point-to-point Ethernet service, similarly to the E-Line (L2 pseudowire) service, but instead of LDP, this time we'll be using BGP as the control plane signalling mechanism. In our example R4 is going to be our Route Reflector in the MPLS core, we peer with R4 on all PE routers using the l2vpn evpn address family. This address family is different from the others in the way that, with BGP EVPN we have different route types to distinguish between different types of routing information (MAC address, IP prefix, multicast etc.). You can think of the route types as "sub-sub" address families, which not supported of course with MP-BGP, but because we need to transfer different types of routing information we use route types to differentiate.
EVPN VPWS (Customer 2)
Let's start with Customer 2. For Customer 2 we configure a point-to-point EVPN VPWS service which is very similar to the E-Line service. But this time we won't need to run targeted LDP between the PEs, we'll run BGP to transfer control plane information. Here is the configuration of R2:

Similarly to other L2VPN services, first we identify AC (attachment circuit) connected to the customer and create the service instance matching the relevant traffic coming in from the customer with the encapsulation statement. Here with the encapsulation default statement we basically match all traffic coming from the customer, so we'll send everything to the remote PE (tagged, untagged, all packets). We configure the EVPN VPWS service with an EVI (l2vpn evpn instance ID, which is 2121 in this example). These are locally significant, just like the VRFs used with the traditional L3VPN service, we use these EVIs to distinguish between the different VPWS services on the same PE. The EVPN VPWS service is configured with the local AC tag ID (11 in the example above), and with the remote AC tag ID (22 in the example above). The target ID has to match with the remote PE's (R7 in this example) source ID. Finally we associate the local AC (the service instance 1 on the interface e0/3) to the EVPN VPWS service. Only the source AC tag (11 on R2) is included in the BGP Update which we'll take a look at later in details, but first let's see the configuration of R7:

Which is exactly the same as the one before, except that the source and target IDs are reversed. Now let's take a look at the BGP Update originated by R7 and sent to R2 via the route reflector (R4):

As you can see we use the Route Type-1 here with the EVPN VPWS service, which is the Ethernet Auto-Discovery (AD) route. The PE (R7 in this example) uses this to discover his remote peer. The Ethernet Tag ID (22) is the source ID we configured on R7. The target ID is NOT included within the route Type-1 NLRI. This NLRI above also includes the ESI (Ethernet Segment ID) which is all 0s. The ESI is not relevant here, the ESI would be only different from 0s if we had a multi-home setup for our customer. That is a big advantage of EVPN VPWS over the traditional E-Line: EVPN supports all-active multi-homing. If we had a multi-home setup, our PEs would also originate Type-4 (Ethernet Segment Route) routes which are used to elect a Designated Forwarder. Notice that we didn't configure any Route Distinguisher (RD) or Route Target (RT), they are auto-configured by default. The RD will in the following format by default: <PE's loopback>:<instance ID>, for R7 10.7.7.7:2121. The RT is by default in the following format: <ASN>:<instance ID>, 65001:2121 in this example. Notice that if we don't configure the RTs manually, the EVIs (2121 in this case) have to match on both PEs. Lastly the NLRI contains the MPLS service label (7000 in this case), which R2 has to insert to the frame when he sends traffic to R7. Here is a ping from CE21 (10.0.0.1) to CE22 (10.0.0.2) captured in the MPLS core:

You can't see the Echo Replies in the pcap above, but the pings actually worked properly, we just do ECMP and the replies came back on a different path where I didn't capture the traffic. Let's take a look at the BGP table of R2 where we have the Type-1 EVPN routes:

Notice the Type-1 route of R2: R2 assigned a label 2000 for this EVPN VPWS service. For all traffic coming in from Customer 2 on the AC, R7 inserts the inner label of 2000 and sends it to R2. Also notice that we don't do MAC address learning with VPWS (PEs don't generate Type-2 EVPN routes), remember that we didn't configure a bridge domain! Basically we send everything to the remote peer coming in from the AC and matching the service instance. This will be different for Customer 1. So to summarize: EVPN VPWS is very similar to the traditional E-Line service but instead of tLDP, we use BGP for the control plane and EVPN also supports all-active multi-homing for the customer. Type-1 (Ethernet Auto Discovery) routes are used for autodiscovery. All PEs that are configured with the EVPN VPWS service originate the Type-1 route, and also, in case if we have a multi-homing setup for the customer, they also originate a Type-4 route, which is used to elect a DF in a multi-home environment. Now let's move to Customer 1 where we configure EVPN Native and EVPN IRB services.
EVPN Native and EVPN IRB
For Customer 1 we configure both L2 services (EVPN Native between Site 1 and Site 2), and L3 services (EVPN IRB between Site 1 and Site 3). EVPN Native is very similar to the traditional VPLS service, except that we don't use tLDP. With the traditional VPLS service MAC address learning is done in the data plane (flood & learn), with EVPN, MAC address learning is done in the control plane (the PEs advertise the MAC address of the CEs to all other remote PEs via BGP).
So let's start with R1:

We configure the service instance on the customer-facing interface the same way as with EVPN VPWS. Instead of point-to-point we configure the L2VPN EVPN instance with the vlan-based keyword here, which basically means that we associate one VLAN to the bridge domain (BD). The RT under the EVPN instance will be used for Type-2 and Type-3 EVPN routes, and the replicate-type ingress defines what we do with the BUM traffic. The PEs replicate the BUM traffic coming in from the customer and send it to every other PE (one copy per PE) using the MPLS label they learned from the Type-3 EVPN routes. Unfortunately only the ingress option is available on the IOS-XE platform I used in this lab, remember that in the VXLAN lab with NX-OS we used multicast in the underlay. Since we do L3 routing on R1 we also need to configure a VRF for Customer 1:

Routing information will be signalled via the EVPN Type-5 routes which are called IP Prefix routes. They are very similar to the VPNv4 routes which we use with the traditional L3VPN services. We configure the RT for the Type-5 routes with the stitching keyword, the RT without the stitching keyword is used for the VPNv4 routes (I guess I could omit that here, VPNv4 RTs are not required for the Type-5 EVPN routes). Because we do routing we also need to configure an IP address on the PE, of course we cannot do this on the physical interface where we specified the service instance, we have to create a new BDI (Bridge Domain Interface) interface, and associate it with the customer VRF. Basically this will be the default gateway for our customer. Finally to be able to generate the Type-5 routes we configure the advertise l2vpn evpn statement under the BGP AF associated with the VRF:

To create Type-5 EVPN routes I use the redistribute commands here (11.11.11.11/32 loopback of CE11 and also the customer-facing subnet of 192.168.0.0/24). That's all we need on R1, the configuration of R10 is very similar:

And here are the physical and BDI interfaces, very similar to what we did on R1:

I'm not going to insert the full configuration of R5. It's basically the same, except that on R5 I didn't configure the VRF and the BDI interface because we don't provide routing services for the customer CE13. R5 will only generate Type-2 and Type-3 EVPN routes, we don't even need the RT with the stitching keyword. CE13 will only be able to communicate with CE11 in this own subnet of 192.168.0.0/24. Now let's check the BGP table of R1, with this relatively simple topology we have a lot of entries, this is because we have different routes types:

Notice that we have Type-2, Type-3 and Type-5 routes. Let's also quickly verify that the data plane is also functional: CE11 can reach CE13 (L2 service, same subnet), and can also trace to 12.12.12.12 which he has learned from CE12:

First let's focus on the Type-5 routes (12.12.12.12/32 in the example above) which from a high level point of view are just VPNv4 routes. They carry a single IP prefix with a RT, we can import it into our PE's BGP table if we have a matching RT import statement under the VRF definition. Very much the same thing as how we do VPNv4. The difference is that RTs are configured with the stitching keyword. Here is the Type-5 route in details:

Remember if we omit the RT statement with the stitching keyword, the PE will still send the Type-5 route, but with an empty RT in the extended communities, so the route will be effectively useless. Also notice the service (inner) label (10011) which is also sent with the NLRI, this is what R1 inserted to the packets which CE11 sent to 12.12.12.12 in the previous example. Now let's move on to the Type-2 and Type-3 routes, they are not as straightforward as the Type-5s in my opinion. This time we'll take a closer look at the NLRIs in Wireshark. This is the NLRI R5 sends to the Route Reflector:

Type-2 EVPN routes are generated automatically when a PE router receives data packets from the CE (in this case from CE13). The remote PEs (in this case R1) learn via these Type-2 routes where the host is located in the same subnet as the local CE. Type-2 routes can also optionally include the host's /32 IP address as well (as it can be seen above). Hosts usually send Gratuitous ARP messages when they come up, the PE can learn from these (or from basically any kind of data packets) the MAC and IP address of the connected host, the PE then generates a Type-2 EVPN routes and sends it to the RR. The remote PEs can then import these routes based on the RTs. But we didn't configure any RTs on R5... We can configure Type-2/Type-3 RTs explicitly like I did on R1 (65001:1112), or we can just use the auto-generated value which is the <ASN>:<EVPN Instance ID>. Interestingly the manually configured RT doesn't overwrite the auto-configured one, so R1 can still import and use this Type-2 EVPN route. So if our EVPN Instance IDs match on both PEs (as in this case), we won't have any issues with the auto-generated RTs. But be aware that if the Instance IDs don't match, we have to manually configure the RTs. Similarly to the RT, notice that the RD is also auto-configured in the following format: <PE's loopback>:<EVPN Instance ID>. Finally let's take a look at the data plane: when CE11 sends data packets to CE13, R1 encapsulates them using the label 5001 which he learned from the Type-2 EVPN route above:

Wireshark couldn't decode the encapsulated data here for some reason, but believe me, these are the ICMP Echoes we sent from CE11 to CE13 above.
Remember that with EVPN VPWS, the PEs didn't do MAC address learning, this time the PEs learn the remote MAC addresses on the bridge domain:

Notice that the remote MAC addresses (learned via BGP) don't age out, they are added to the MAC address table statically (to prevent the periodic flood & learn), only the local MAC addresses are dynamic entries, which can age out after the usual 300 sec aging timer.
Following Type-2, now let's examine the Type-3 route R5 generated:

Basically in EVPN each bridge domain and each EVPN Instance has one label for unicast (Type-2) and one label for for BUM traffic. Route Type-3 is used to send the service label for the BUM traffic to the remote PEs. Using this NLRI above, R5 provides a label for BUM traffic. When R1 sends BUM traffic to R5 (an ARP Request for example), R1 uses label 5000 as the inner label. Ingress replication means that we send one frame, one copy of the BUM traffic for each remote PE using the label of the Type-3 EVPN route provided by the remote PE. RD and RTs for the Type-3 EVPN routes are also auto-generated in the same format as the Type-2 routes.
Remember, we didn't enable routing for Site 2 (we didn't create BDI interface on R5), but on R1 and R10 we enabled routing between Site 1 and Site 3. Let's take a look at the Type-2 EVPN generated by R1 and let's examine how it is different from the Type-2 route generated by R5:

First we have three RTs in the extended communities: the auto-generated one (65001:1), the one we configured manually under the EVPN instance (65001:1112), and also the Type-5 (65001:100, configured using the "stitching" keyword), because we also do routing on R1. What's more interesting is that we have two MPLS labels attached to the NLRI. Type-2 EVPN routes can also optionally include a second MPLS label. The first label (1001 in this example) is used for L2 bridging, the second label is used for L3 routing (1013). When CE13 from the same subnet sends traffic to CE11, R5 inserts the service label 1001 and sends the packet to R1. Label 2 is used with symmetric IRB to support routing: when a customer from a different subnet (CE12 in our example) sends traffic to 192.168.0.11, R10 inserts Label 2 (1013). Remember this label is for the host route only, for 192.168.0.11/32, when CE12 wants to send traffic to a different host in this subnet (192.168.0.0/24) which R1 advertises using the Type-5 EVPN route, R10 inserts the label provided by the Type-5 route. So as always, the more specific route (/32 host route in this case) takes precedence.
Besides multi-homing, there is one more big advantage of EVPN which is the distributed anycast gateway (DAG). DAG means that we can configure the same MAC and IP address on many PEs on the BDI interface to provide mobility services for our customers. Basically the same thing which we have done in VXLAN on the Leaf switches. We don't do DAG here in this lab, but basically this is how we would configure it:

Same concept as with VXLAN: we don't need to reconfigure our hosts if they move from one PE to another.
Finally feel free to download my lab file in YAML of this lab and import it into CML to practice and experiment with it.