Skip to content

Commit

Permalink
config: Create required interfaces in BNG
Browse files Browse the repository at this point in the history
Signed-off-by: Shashank D <[email protected]>
  • Loading branch information
shashank68 committed Nov 11, 2021
1 parent a9003fa commit ebefec5
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config_util/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
interfaces:
- ifname: enp2s0
customers:
- id: 100
outer_vlan: 1000
inner_vlan: 400
ip_addresses:
- 10.0.2.1/32
65 changes: 65 additions & 0 deletions config_util/config_utility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# SPDX-License-Identifier: GPL-2.0-or-later

import yaml
import ipaddress
import pr2modules
from pyroute2 import IPRoute


CONFIG_FILE = "./config.yaml"

with open(CONFIG_FILE) as f:
config = yaml.load(f, Loader=yaml.SafeLoader)


print(config)

# Create the base interface
ip = IPRoute()

for iface in config["interfaces"]:
if_name = iface["ifname"]
print(if_name)
for customer in iface["customers"]:
inner_vlan_tag = customer["inner_vlan"]
outer_vlan_tag = customer["outer_vlan"]
base_iface = ip.link_lookup(ifname=if_name)[0]
try:
ip.link(
"add",
ifname=f"{if_name}.{inner_vlan_tag}",
kind="vlan",
link=base_iface,
vlan_id=inner_vlan_tag,
)
except pr2modules.netlink.exceptions.NetlinkError:
pass

# TODO: Check for existing inner tagged iface
# TODO: Check if the base iface exists
outer_vlan_iface = f"{if_name}.{inner_vlan_tag}.{outer_vlan_tag}"
ip.link(
"add",
ifname=outer_vlan_iface,
kind="vlan",
link=ip.link_lookup(ifname=f"{if_name}.{inner_vlan_tag}")[0],
vlan_id=outer_vlan_tag,
)
# TODO: Check for existing outer tagged iface
for ip_addr_str in customer["ip_addresses"]:
ip_addr = ipaddress.ip_interface(ip_addr_str)
if ip_addr.version == 4:
mask = ip_addr.network.prefixlen
ip_str = ip_addr.ip.compressed

ip.addr(
"add",
index=ip.link_lookup(outer_vlan_iface)[0],
address=ip_str,
mask=mask,
)
# TODO: Handle ipv6
# TODO: Existing addresses


# TODO: Routing (with vlan interface), Attaching ebpf program

0 comments on commit ebefec5

Please sign in to comment.