Skip to content

Commit

Permalink
fix example scripts (bisdn#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
DFritzsche authored and toanju committed Nov 8, 2018
1 parent 40fcd7c commit b5fed76
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 47 deletions.
8 changes: 4 additions & 4 deletions examples/bridging/01-controller
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
# This script will create the following logical connections:

# port1 \
# > bridge0
# > swbridge
# port2 /

# Further, the VLAN ids in BR_VLAN_RANGE will be added to the ports

PORTA=${PORTA:-port1}
PORTB=${PORTB:-port2}
BRIDGE=${BRIDGE:-bridge0}
BRIDGE=${BRIDGE:-swbridge}

BR_VLAN_RANGE_DEF="{4..6}"
BR_VLAN_RANGE=${BR_VLAN_RANGE:-$BR_VLAN_RANGE_DEF}
Expand All @@ -37,6 +37,6 @@ ip link set ${PORTB} up

# vids
for vid in $(eval echo $BR_VLAN_RANGE) ; do
bridge vlan add vid $vid dev ${PORTA}
bridge vlan add vid $vid dev ${PORTB}
bridge vlan add vid ${vid} dev ${PORTA}
bridge vlan add vid ${vid} dev ${PORTB}
done
20 changes: 11 additions & 9 deletions examples/bridging/01-server
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ PORT=${PORT:-eth}
INTF=($PORT1 $PORT2)

CFG=${CFG:-"a"}
NS=${NS:-0}

function nsexec {
ip netns exec ns${NS} $@
Expand All @@ -30,22 +29,25 @@ function nswipe {

# setup
function setup {
# configure namespace
ip netns add ns0
for id in {0..1}; do

export NS=$id

# configure namespace
ip netns add ns$id

for id in {1..2}; do
# specific setup
ip link set $PORT$id netns ns0
ip link set ${PORT}$id netns ns$id

# bring interfaces in namespace up
nsexec ip link set lo up
nsexec ip link set $PORT$id up
nsexec ip link set ${PORT}$id up

#configure VLANs and add IP address
for vid in $(eval echo $BR_VLAN_RANGE) ; do
nsexec ip l a link port$id name port$id.$vid type vlan id $vid
nsexec ip a a ${TENANT_PREFIX}.${vid}.2${vid}/24 dev port$id.$vid
nsexec ip l s port$id.$vid up
nsexec ip l add link ${PORT}$id name ${PORT}$id.$vid type vlan id $vid
nsexec ip a add ${TENANT_PREFIX}.${vid}.2${id}/24 dev ${PORT}$id.$vid
nsexec ip l set ${PORT}$id.$vid up
done
done
}
Expand Down
10 changes: 5 additions & 5 deletions examples/routing/IPv4/01-controller
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
# eth1 eth2
# ns1 ns2

# On the L3 switch, both ports are configured as gateways
# for the networks on the switch ports. On the servers,
# a manual (or simply a default route) should be inserted,
# On the L3 switch, both ports are configured as gateways
# for the networks on the switch ports. On the servers,
# a manual (or simply a default route) should be inserted,
# to make sure that connectivity exists between the namespaces.

PORTA=${PORTA:-port1}
PORTB=${PORTB:-port2}
IFACES=($PORTA $PORTB)

PORTAADDR=10.20.40.1/24
PORTBADDR=10.20.30.1/24
PORTBADDR=10.20.50.1/24

function setup() {
ip address add $PORTAADDR dev ${PORTA}
ip address add $PORTBADDRB dev ${PORTB}
ip address add $PORTBADDR dev ${PORTB}
}

setup
27 changes: 11 additions & 16 deletions examples/routing/IPv4/01-server
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,33 @@
# eth1 eth2
# ns1 ns2

# On the L3 switch, both ports are configured as gateways
# for the networks on the switch ports. On the servers,
# a manual (or simply a default route) should be inserted,
# On the L3 switch, both ports are configured as gateways
# for the networks on the switch ports. On the servers,
# a manual (or simply a default route) should be inserted,
# to make sure that connectivity exists between the namespaces.

ADDR=("10.20.30.10/24" "10.20.40.10/24")
ADDR=("10.20.40.10/24" "10.20.50.10/24")
LOADDR=("10.33.10.10/32" "10.44.10.10/32")

aroutes="10.20.40.0/24"
broutes="10.20.30.0/24"
ROUTES=($aroutes $broutes)
ROUTES=("10.20.50.0/24" "10.20.40.0/24")

GW=("10.20.30.1" "10.20.40.1")
GW=("10.20.40.1" "10.20.50.1")

PORTA=${PORTA:-eth1}
PORTB=${PORTB:-eth2}
IFACES=($PORTA $PORTB)

function exec {
function nsexec {
ip netns exec ${NS} $@
}

# setup
function setup {

# generic setup
for id in {0..1}; do
for id in {0..1}; do
export NS=ns$id

# setting up variables for each namespace
iface=${IFACES[${id}]}
ipaddr=${ADDR[${id}]}
Expand All @@ -48,16 +46,13 @@ function setup {
gw=${GW[${id}]}

ip netns add ns$id
ip link $iface set netns ns$id
ip link set $iface netns ns$id

## set links up
nsexec ip link set $iface up
nsexec ip address add $ipaddr dev $iface

## loopback addresses
nsexec ip link set lo up
nsexec ip address add $ipaddr dev lo

## add route
nsexec ip route add $iproute via $gw dev $iface
done
}
Expand Down
10 changes: 5 additions & 5 deletions examples/routing/IPv6/01-controller
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
# eth1 eth2
# ns1 ns2

# On the L3 switch, both ports are configured as gateways
# On the L3 switch, both ports are configured as gateways
# for the networks on the switch ports. Since IPv6 requires
# radvd, an external daemon that sends the Router Advertisement
# messages down, in this folder you can also find an example
# messages down, in this folder you can also find an example
# configuration for this daemon. According to the defaults,
# this file should be placed in the /etc/radvd.conf.
# this file should be placed in the /etc/radvd.conf.
# Due to autoconfiguration, the addresses on the servers are
# automatically configured to a combination of the announced
# prefix from the router with the physical (MAC) address of the
# prefix from the router with the physical (MAC) address of the
# interface.

PORTA=${PORTA:-port1}
Expand All @@ -41,7 +41,7 @@ function setup {
ipaddr=${ADDR[${id}]}

# add IPv6 address
ip address add $ipaddr dev $ipaddr
ip address add $ipaddr dev $iface
done

systemctl restart radvd
Expand Down
16 changes: 8 additions & 8 deletions examples/routing/IPv6/01-server
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
# eth1 eth2
# ns1 ns2

# On the L3 switch, both ports are configured as gateways
# On the L3 switch, both ports are configured as gateways
# for the networks on the switch ports. Since IPv6 requires
# radvd, an external daemon that sends the Router Advertisement
# messages down, in this folder you can also find an example
# messages down, in this folder you can also find an example
# configuration for this daemon. According to the defaults,
# this file should be placed in the /etc/radvd.conf.
# this file should be placed in the /etc/radvd.conf.
# Due to autoconfiguration, the addresses on the servers are
# automatically configured to a combination of the announced
# prefix from the router with the physical (MAC) address of the
# prefix from the router with the physical (MAC) address of the
# interface.

PORTA=${PORTA:-eth1}
Expand All @@ -35,17 +35,17 @@ function setup {
for id in {0..1}; do
# setup namespaces
export NS=ns$id
port=${IFACES[${id}]}
port=${IFACES[${id}]}

ip netns add ns$id

ip link set $port netns $ns
ip link set $port netns ns$id

# setup interfaces up
nsexec ip link set lo up
nsexec ip link set $port up



done
}

setup

0 comments on commit b5fed76

Please sign in to comment.