> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/fpp/2.2/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/components/fpp/2.2/source-based-forwarding.md).

# Source-based routing

>**FEATURE STATE:** beta

FPP allows source-based routing with the use of the VPP ACL-based forwarding (ABF) feature. The enablement requires creating a matching access-control list (ACL) for the incoming traffic and a dedicated policy to apply to it.

> **CAUTION:** The source-based routing is a beta feature exposed as VPP CLI command configuration. In future FPP releases, it will be managed through a Custom Resource configuration.

## ACL creation

VPP uses `acl-plugin` to manage ACLs. Each ACL consists of a pattern for traffic matching and a rule to perform on it. For the ABF feature, ACLs with the apply action `permit` are required. A dedicated command to create an ACL using VPP CLI should be placed in the `afterCommands` section of the VPPConfig CR. The VPP CLI command:

```bash
set acl-plugin acl permit src <PREFIX> dst <PREFIX> proto X sport X-Y dport X-Y [tag FOO]
```

As an example, an ACL that matches input traffic from network `10.0.0.0/24` looks as follows:

```bash
set acl-plugin acl permit src 10.0.0.0/24
```

CLI returns `ACL index:<X>` where `X` is a positive integer index of the ACL created. This index will be used to create the ABF policy.

## Policy-based routing activation

To use an existing ACL that matches certain traffic and to make a routing decision, run the following:

```bash
abf policy [add|del] id <index> acl <index> via <fib-path-format>
```

As an example, ABF Policy with index `0` uses ACL with index `0` and performs lookup in table  `100` for IPv4 traffic:

```bash
abf policy add id 0 acl 0 via ip4-lookup-in-table 100
```

The table ID must match the corresponding `RoutingTable` spec. Example:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: RoutingTable
metadata:
  labels:
    fpp-manager.cennso.com/plumbing-instance: upg
    name: upg-access-routes
  name: upg-access-routes
  namespace: fpp-sample
spec:
  addressFamily: IPv4
  id: 100
  routes:
(...)
```

Attach the policy to the input interface through the CLI command:

```bash
abf attach <ip4|ip6> [del] policy <value> <interface>
```

An example of an attachment policy with index `0` to interface named `net-1`:

```bash
abf attach ip4 policy 0 net-1
```

Several ABF policies can be attached to a single input interface.

## VPPConfig example

ABF policies creation and attachment must be added in the `afterCommands` section:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPConfig
metadata:
  name: vpp-example
  namespace: fpp-sample
  labels:
...
spec:
  afterCommands:
  - set acl-plugin acl permit src 10.0.0.0/24
  - ip table add 100
  - abf policy add id 0 acl 0 via ip4-lookup-in-table 100
  - abf attach ip4 policy 0 {{ .Ifs.srv.Name }}
  interfaces:
  - srv
...

```

`ip table add 100` is added for synchronization purposes because the VPPConfig and RoutingTable objects do not guarantee that routing table 100 will be created before VPPConfig `afterCommands` are executed.
