summaryrefslogtreecommitdiffhomepage
path: root/tools/config
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-12-23 23:56:37 -0800
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-12-23 23:56:37 -0800
commit0376901ae2cfed0f0e6e0f5f0475f3ee24510c04 (patch)
treef251b7a9d85111165e4f1f8f4d745c0565df22ea /tools/config
parentc66c6b3b0469346c4ce05354552be2dec1e46ffa (diff)
tools: for route server testings on Docker
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'tools/config')
-rw-r--r--tools/config/quagga-rsconfig.go103
-rwxr-xr-xtools/config/root-server-docker.sh67
2 files changed, 170 insertions, 0 deletions
diff --git a/tools/config/quagga-rsconfig.go b/tools/config/quagga-rsconfig.go
new file mode 100644
index 00000000..cf3d211c
--- /dev/null
+++ b/tools/config/quagga-rsconfig.go
@@ -0,0 +1,103 @@
+package main
+
+import (
+ "bytes"
+ "fmt"
+ "github.com/BurntSushi/toml"
+ "github.com/jessevdk/go-flags"
+ "github.com/osrg/gobgp/config"
+ "io/ioutil"
+ "log"
+ "net"
+ "os"
+ "path/filepath"
+)
+
+type QuaggaConfig struct {
+ id int
+ config *config.NeighborType
+ gobgpConfig *config.GlobalType
+ serverIP net.IP
+}
+
+func NewQuaggaConfig(id int, gConfig *config.GlobalType, myConfig *config.NeighborType, server net.IP) *QuaggaConfig {
+ return &QuaggaConfig{
+ id: id,
+ config: myConfig,
+ gobgpConfig: gConfig,
+ serverIP: server,
+ }
+}
+
+func (qt *QuaggaConfig) Config() *bytes.Buffer {
+ buf := bytes.NewBuffer(nil)
+
+ buf.WriteString("hostname bgpd\n")
+ buf.WriteString("password zebra\n")
+ buf.WriteString(fmt.Sprintf("router bgp %d\n", qt.config.PeerAs))
+ buf.WriteString(fmt.Sprintf("bgp router-id 192.168.0.%d\n", qt.id))
+ buf.WriteString(fmt.Sprintf("network 192.168.%d.0/24\n", qt.id))
+ buf.WriteString(fmt.Sprintf("neighbor %s remote-as %d\n", qt.serverIP, qt.gobgpConfig.As))
+ buf.WriteString(fmt.Sprintf("neighbor %s password %s\n", qt.serverIP, qt.config.AuthPassword))
+ buf.WriteString("log file /var/log/quagga/bgpd.log")
+ return buf
+}
+
+func create_config_files(nr int, outputDir string) {
+ quaggaConfigList := make([]*QuaggaConfig, 0)
+
+ gobgpConf := config.BgpType{
+ Global: config.GlobalType{
+ As: 64512,
+ RouterId: net.ParseIP("192.168.255.1"),
+ },
+ }
+
+ for i := 1; i < nr+1; i++ {
+ c := config.NeighborType{
+ PeerAs: 64513 + uint32(i),
+ NeighborAddress: net.ParseIP(fmt.Sprintf("10.0.0.%d", i)),
+ AuthPassword: fmt.Sprintf("hoge%d", i),
+ }
+ gobgpConf.NeighborList = append(gobgpConf.NeighborList, c)
+ q := NewQuaggaConfig(i, &gobgpConf.Global, &c, net.ParseIP("10.0.255.1"))
+ quaggaConfigList = append(quaggaConfigList, q)
+ os.Mkdir(fmt.Sprintf("%s/q%d", outputDir, i), 0755)
+ err := ioutil.WriteFile(fmt.Sprintf("%s/q%d/bgpd.conf", outputDir, i), q.Config().Bytes(), 0644)
+ if err != nil {
+ log.Fatal(err)
+ }
+ }
+
+ var buffer bytes.Buffer
+ encoder := toml.NewEncoder(&buffer)
+ encoder.Encode(gobgpConf)
+
+ err := ioutil.WriteFile(fmt.Sprintf("%s/gobgpd.conf", outputDir), buffer.Bytes(), 0644)
+ if err != nil {
+ log.Fatal(err)
+ }
+}
+
+func main() {
+ var opts struct {
+ ClientNumber int `short:"n" long:"client-number" description:"specfying the number of clients" default:"8"`
+ OutputDir string `short:"c" long:"output" description:"specifing the output directory"`
+ }
+ parser := flags.NewParser(&opts, flags.Default)
+
+ _, err := parser.Parse()
+ if err != nil {
+ os.Exit(1)
+ }
+
+ if opts.OutputDir == "" {
+ opts.OutputDir, _ = filepath.Abs(".")
+ } else {
+ if _, err := os.Stat(opts.OutputDir); os.IsNotExist(err) {
+ os.Mkdir(opts.OutputDir, 0755)
+ }
+ }
+
+ create_config_files(opts.ClientNumber, opts.OutputDir)
+}
diff --git a/tools/config/root-server-docker.sh b/tools/config/root-server-docker.sh
new file mode 100755
index 00000000..f2af3d7d
--- /dev/null
+++ b/tools/config/root-server-docker.sh
@@ -0,0 +1,67 @@
+#!/bin/sh
+
+NR_PEERS=8
+BRIDGE_NAME=br0
+CONFIG_DIR=`pwd`
+
+run_quagga() {
+ local docker_name=q$1
+ docker run --privileged=true -v $CONFIG_DIR/$docker_name:/etc/quagga --name $docker_name -id osrg/quagga
+ sudo pipework $BRIDGE_NAME $docker_name 10.0.0.$1/16
+}
+
+stop_quagga() {
+ local docker_name=q$1
+ docker rm -f $docker_name
+}
+
+delete_bridge() {
+ local name=$1
+ local sysfs_name=/sys/class/net/$name
+ if [ -e $sysfs_name ]; then
+ sudo ifconfig $name down
+ sudo brctl delbr $name
+ fi
+}
+
+while getopts c: OPT
+do
+ case $OPT in
+ c) CONFIG_DIR="$OPTARG"
+ ;;
+ *) echo "Unknown option"
+ exit 1
+ ;;
+ esac
+done
+
+shift $((OPTIND - 1))
+
+case "$1" in
+ start)
+ i=1
+ while [ $i -le $NR_PEERS ]
+ do
+ run_quagga $i
+ i=$(( i+1 ))
+ done
+ sudo ip addr add 10.0.255.1/16 dev $BRIDGE_NAME
+ ;;
+
+ stop)
+ i=1
+ while [ $i -le $NR_PEERS ]
+ do
+ stop_quagga $i
+ i=$(( i+1 ))
+ done
+ delete_bridge $BRIDGE_NAME
+ ;;
+ *)
+ echo $1
+ echo "Usage: root-server-docker {start|stop}"
+ exit 2
+ ;;
+esac
+
+