Commit fbcffb33 authored by Jan Moskyto Matejka's avatar Jan Moskyto Matejka

MPLS: scripts for creating a simple MPLS network in network namespaces

parent 26addca6
#!/bin/bash
set -x
# This script creates a testing MPLS network at Linux.
# Requirements:
# - iproute2 >=4.4
# - linux kernel >=4.4 with loaded modules mpls_router and mpls_iptunnel
#
# CE1 -- PE1 [ MPLS -- P -- MPLS ] PE2 -- CE2
# During development, the iproute2 compiled source code was located in /home/moskyto/iproute2.
IPROUTE=/home/moskyto/iproute2
alias ip=$IPROUTE/ip/ip
nsip() {
NS=$1
shift
$IPROUTE/ip/ip netns exec $NS $IPROUTE/ip/ip "$@"
}
# Create namespaces
ip netns add ce1
ip netns add ce2
ip netns add pe1
ip netns add pe2
ip netns add p
# Dummy ifaces
nsip ce1 link add ce1 type dummy
nsip ce1 link set ce1 up
nsip ce1 addr add 10.99.0.1/32 dev ce1
nsip ce2 link add ce2 type dummy
nsip ce2 link set ce2 up
nsip ce2 addr add 10.99.0.2/32 dev ce2
nsip pe1 link add pe1 type dummy
nsip pe1 link set pe1 up
nsip pe1 addr add 10.199.0.1/32 dev pe1
nsip p link add p type dummy
nsip p link set p up
nsip p addr add 10.199.1.1/32 dev p
nsip pe2 link add pe2 type dummy
nsip pe2 link set pe2 up
nsip pe2 addr add 10.199.0.3/32 dev pe2
# PE-P links
nsip p link add pe1 type veth peer name p netns pe1
nsip p link add pe2 type veth peer name p netns pe2
nsip p link set pe1 up
nsip p link set pe2 up
nsip p addr add 10.1.1.1/32 peer 10.1.1.2/32 dev pe1
nsip p addr add 10.1.2.1/32 peer 10.1.2.2/32 dev pe2
nsip pe1 link set p up
nsip pe2 link set p up
nsip pe1 addr add 10.1.1.2/32 peer 10.1.1.1/32 dev p
nsip pe2 addr add 10.1.2.2/32 peer 10.1.2.1/32 dev p
# PE-CE links
nsip pe1 link add ce1 type veth peer name pe1 netns ce1
nsip pe2 link add ce2 type veth peer name pe2 netns ce2
nsip pe1 link set ce1 up
nsip pe2 link set ce2 up
nsip pe1 addr add 10.10.1.1/32 peer 10.10.1.2/32 dev ce1
nsip pe2 addr add 10.10.2.1/32 peer 10.10.2.2/32 dev ce2
nsip ce1 link set pe1 up
nsip ce2 link set pe2 up
nsip ce1 addr add 10.10.1.2/32 peer 10.10.1.1/32 dev pe1
nsip ce2 addr add 10.10.2.2/32 peer 10.10.2.1/32 dev pe2
# Allow MPLS processing
echo 1 | $IPROUTE/ip/ip netns exec p tee /proc/sys/net/mpls/conf/pe1/input
echo 1 | $IPROUTE/ip/ip netns exec p tee /proc/sys/net/mpls/conf/pe2/input
echo 1 | $IPROUTE/ip/ip netns exec pe1 tee /proc/sys/net/mpls/conf/p/input
echo 1 | $IPROUTE/ip/ip netns exec pe2 tee /proc/sys/net/mpls/conf/p/input
# Raise MPLS label limit
echo 20 | $IPROUTE/ip/ip netns exec pe1 tee /proc/sys/net/mpls/platform_labels
echo 20 | $IPROUTE/ip/ip netns exec pe2 tee /proc/sys/net/mpls/platform_labels
echo 20 | $IPROUTE/ip/ip netns exec p tee /proc/sys/net/mpls/platform_labels
# Allow IPv4 forwarding
echo 1 | $IPROUTE/ip/ip netns exec pe1 tee /proc/sys/net/ipv4/ip_forward
echo 1 | $IPROUTE/ip/ip netns exec pe2 tee /proc/sys/net/ipv4/ip_forward
echo 1 | $IPROUTE/ip/ip netns exec p tee /proc/sys/net/ipv4/ip_forward
# Client routes
nsip ce1 route add 10.99.0.2/32 via 10.10.1.1
nsip ce2 route add 10.99.0.1/32 via 10.10.2.1
# Per-client routing table
nsip pe1 rule add iif ce1 table 16
nsip pe2 rule add iif ce2 table 16
# Encap rules
nsip pe1 route add 10.99.0.2/32 encap mpls 17/16 via 10.1.1.1 table 16
nsip pe2 route add 10.99.0.1/32 encap mpls 18/16 via 10.1.2.1 table 16
# MPLS rules at P
nsip p -f mpls route add 17 via inet 10.1.2.2
nsip p -f mpls route add 18 via inet 10.1.1.2
# Decap rules
nsip pe1 -f mpls route add 16 via inet 10.10.1.2
nsip pe2 -f mpls route add 16 via inet 10.10.2.2
#!/bin/bash
set -x
# During development, the iproute2 compiled source code was located in /home/moskyto/iproute2.
IPROUTE=/home/moskyto/iproute2
alias ip=$IPROUTE/ip/ip
nsip() {
NS=$1
shift
$IPROUTE/ip/ip netns exec $NS $IPROUTE/ip/ip "$@"
}
nsip ce1 link del ce1
nsip ce2 link del ce2
nsip pe1 link del pe1
nsip pe2 link del pe2
nsip p link del p
nsip p link del pe1
nsip p link del pe2
nsip pe1 link del ce1
nsip pe2 link del ce2
ip netns del ce1
ip netns del ce2
ip netns del pe1
ip netns del pe2
ip netns del p
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment