Skip to content

Commit

Permalink
Add a script to configure the DS and create an external frr container
Browse files Browse the repository at this point in the history
Add a dev-env like script that configures both the external container
and the frr-k8s configuration.

Signed-off-by: Federico Paolinelli <[email protected]>
  • Loading branch information
fedepaol committed Jun 15, 2023
1 parent 6e4434f commit 784dd1a
Show file tree
Hide file tree
Showing 5 changed files with 260 additions and 0 deletions.
40 changes: 40 additions & 0 deletions hack/external_frr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
set -x

NODES=$(kubectl get nodes -l node-role.kubernetes.io/worker=worker -o jsonpath={.items[*].status.addresses[?\(@.type==\"InternalIP\"\)].address})
echo $NODES
pushd ./hack/frr/
go run . -nodes "$NODES"
popd

FRR_CONFIG=$(mktemp -d -t frr-XXXXXXXXXX)
cp hack/frr/*.conf $FRR_CONFIG
cp hack/frr/daemons $FRR_CONFIG
chmod a+rw $FRR_CONFIG/*

docker rm -f frr
docker run -d --privileged --network kind --rm --ulimit core=-1 --name frr --volume "$FRR_CONFIG":/etc/frr quay.io/frrouting/frr:8.4.2

FRR_IP=$(docker inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" frr)


cat <<EOF | kubectl apply -f -
apiVersion: frrk8s.metallb.io/v1beta1
kind: FRRConfiguration
metadata:
name: frrconfiguration-sample
namespace: default
spec:
bgp:
routers:
- asn: 64512
prefixes:
- 192.168.5.0/24
neighbors:
- asn: 64512
address: $FRR_IP
toAdvertise:
allowed:
prefixes:
- 192.168.5.0/24
EOF
80 changes: 80 additions & 0 deletions hack/frr/daemons
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# This file tells the frr package which daemons to start.
#
# Sample configurations for these daemons can be found in
# /usr/share/doc/frr/examples/.
#
# ATTENTION:
#
# When activating a daemon for the first time, a config file, even if it is
# empty, has to be present *and* be owned by the user and group "frr", else
# the daemon will not be started by /etc/init.d/frr. The permissions should
# be u=rw,g=r,o=.
# When using "vtysh" such a config file is also needed. It should be owned by
# group "frrvty" and set to ug=rw,o= though. Check /etc/pam.d/frr, too.
#
# The watchfrr and zebra daemons are always started.
#
bgpd=yes
ospfd=no
ospf6d=no
ripd=no
ripngd=no
isisd=no
pimd=no
ldpd=no
nhrpd=no
eigrpd=no
babeld=no
sharpd=no
pbrd=no
bfdd=yes
fabricd=no
vrrpd=no

#
# If this option is set the /etc/init.d/frr script automatically loads
# the config via "vtysh -b" when the servers are started.
# Check /etc/pam.d/frr if you intend to use "vtysh"!
#
vtysh_enable=yes
zebra_options=" -A 127.0.0.1 -s 90000000"
bgpd_options=" -A 127.0.0.1"
ospfd_options=" -A 127.0.0.1"
ospf6d_options=" -A ::1"
ripd_options=" -A 127.0.0.1"
ripngd_options=" -A ::1"
isisd_options=" -A 127.0.0.1"
pimd_options=" -A 127.0.0.1"
ldpd_options=" -A 127.0.0.1"
nhrpd_options=" -A 127.0.0.1"
eigrpd_options=" -A 127.0.0.1"
babeld_options=" -A 127.0.0.1"
sharpd_options=" -A 127.0.0.1"
pbrd_options=" -A 127.0.0.1"
staticd_options="-A 127.0.0.1"
bfdd_options=" -A 127.0.0.1"
fabricd_options="-A 127.0.0.1"
vrrpd_options=" -A 127.0.0.1"

# configuration profile
#
#frr_profile="traditional"
#frr_profile="datacenter"

#
# This is the maximum number of FD's that will be available.
# Upon startup this is read by the control files and ulimit
# is called. Uncomment and use a reasonable value for your
# setup if you are expecting a large number of peers in
# say BGP.
#MAX_FDS=1024

# The list of daemons to watch is automatically generated by the init script.
#watchfrr_options=""

# for debugging purposes, you can specify a "wrap" command to start instead
# of starting the daemon directly, e.g. to use valgrind on ospfd:
# ospfd_wrap="/usr/bin/valgrind"
# or you can use "all_wrap" for all daemons, e.g. to use perf record:
# all_wrap="/usr/bin/perf record --call-graph -"
# the normal daemon command is added to this at the end.
49 changes: 49 additions & 0 deletions hack/frr/frr.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
! -*- bgp -*-
!
! BGPd sample configuration file
!
! $Id: bgpd.conf.sample,v 1.1 2002/12/13 20:15:29 paul Exp $
!

hostname bgpd
password zebra
!enable password please-set-at-here
!
!
! NOTE: These NODE_IPs will be substituted with the IP addresses
! assigned to the kind cluster NodesIP if they are different.
! PROTOCOL will be substituted with either ipv4 or ipv6.
!
router bgp 64512
no bgp default ipv4-unicast
no bgp network import-check
neighbor 172.18.0.2 remote-as 64512
neighbor 172.18.0.4 remote-as 64512
address-family ipv4 unicast
neighbor 172.18.0.2 activate
neighbor 172.18.0.2 next-hop-self
neighbor 172.18.0.4 activate
neighbor 172.18.0.4 next-hop-self
exit-address-family

!
!router bgp 7675
! bgp router-id 10.0.0.1
! network 10.0.0.0/8
! neighbor 10.0.0.2 remote-as 7675
! neighbor 10.0.0.2 ebgp-multihop
!
! address-family ipv4 unicast
! neighbor 10.0.0.2 route-map set-nexthop out
! neighbor 10.0.0.2 next-hop-self
! exit-address-family
!
! access-list all permit any
!
!route-map set-nexthop permit 10
! match ip address all
! set ip next-hop 10.0.0.1
!
!log file /var/log/bgpd.log
!
log stdout debugging
51 changes: 51 additions & 0 deletions hack/frr/frr.conf.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
! -*- bgp -*-
!
! BGPd sample configuration file
!
! $Id: bgpd.conf.sample,v 1.1 2002/12/13 20:15:29 paul Exp $
!

hostname bgpd
password zebra
!enable password please-set-at-here
!
!
! NOTE: These NODE_IPs will be substituted with the IP addresses
! assigned to the kind cluster NodesIP if they are different.
! PROTOCOL will be substituted with either ipv4 or ipv6.
!
router bgp 64512
no bgp default ipv4-unicast
no bgp network import-check

{{- range $r := .NodesIP }}
neighbor {{ . }} remote-as 64512
{{- end }}
address-family {{ .Protocol }} unicast
{{- range $r := .NodesIP }}
neighbor {{ . }} activate
neighbor {{ . }} next-hop-self
{{- end }}
exit-address-family

!
!router bgp 7675
! bgp router-id 10.0.0.1
! network 10.0.0.0/8
! neighbor 10.0.0.2 remote-as 7675
! neighbor 10.0.0.2 ebgp-multihop
!
! address-family ipv4 unicast
! neighbor 10.0.0.2 route-map set-nexthop out
! neighbor 10.0.0.2 next-hop-self
! exit-address-family
!
! access-list all permit any
!
!route-map set-nexthop permit 10
! match ip address all
! set ip next-hop 10.0.0.1
!
!log file /var/log/bgpd.log
!
log stdout debugging
40 changes: 40 additions & 0 deletions hack/frr/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier:Apache-2.0

package main

import (
"flag"
"fmt"
"html/template"
"os"
"strings"
)

type BGPD struct {
NodesIP []string
Protocol string
}

func main() {
nodeList := flag.String("nodes", "", "nodes ip")
flag.Parse()
fmt.Println(*nodeList)
data := BGPD{
NodesIP: strings.Split(*nodeList, " "),
Protocol: "ipv4",
}

t, err := template.New("frr.conf.tmpl").ParseFiles("frr.conf.tmpl")
if err != nil {
panic(err)
}
f, err := os.Create("frr.conf")
if err != nil {
panic(err)
}
defer f.Close()
err = t.Execute(f, data)
if err != nil {
panic(err)
}
}

0 comments on commit 784dd1a

Please sign in to comment.