-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart-routers.sh
executable file
·118 lines (105 loc) · 2.82 KB
/
start-routers.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
[ -f Vagrantfile ] || ( echo "Vagrantfile not found, aborting" ; exit 1 )
trap "rm -f /tmp/sshconfig-r?.$$" EXIT
TESTBED=testbed.yaml
###############
# Bring up the VMs
function start_vms() {
for NUM in $* ; do
vagrant up r$NUM || exit 1
done
}
###############
# we need some initial config to make robot happy (minimum hostname)
# while at it, also setting up connectivity on the crosslinks between the
# devices
function config_routers() {
for NUM in $* ; do
echo "Setting up r$NUM"
cat << _EOF | vagrant ssh r$NUM
conf term
hostname r$NUM
ipv6 unicast-routing
no ip domain-lookup
default interface Loopback0
interface loopback0
ip address 10.0.0.$NUM 255.255.255.255
ipv6 address fd00:0:0:0::$NUM/128
ip ospf 1 area 0
ipv6 ospf 1 area 0
default interface GigabitEthernet2
interface GigabitEthernet2
no shut
ip address 172.16.0.$NUM 255.255.255.0
ipv6 address fd00:a:a:a:2::$NUM/64
ip ospf 1 area 0
ipv6 ospf 1 area 0
end
write
exit
_EOF
done
}
###############
# Creating testbed.yaml, extracting port and identifyfile
# created by vagrant
#
function create_testbed() {
# find out which routers are running
set -- $(vagrant status | sed -n 's/^r\([12]\).*running.*/\1/p')
if [ $# -eq 0 ]; then
echo "No routes are running, returning"
fi
echo "Setting up $TESTBED"
echo "# this file was auto-generated by $0, manual edits might get lost if the script is re-executed" > $TESTBED
echo "devices:" > $TESTBED
for NUM in $* ; do
r=r$NUM
tmpfile=/tmp/sshconfig-${r}.$$
vagrant ssh-config $r > $tmpfile
port=$(sed -n 's/^ *Port *\(.*\) *$/\1/p' $tmpfile)
identity=$(sed -n 's/ *IdentityFile *\(.*\) *$/\1/p' $tmpfile)
if [ $(uname) == Darwin ] ; then
# while developing on mac
address=host.docker.internal
else
address=127.0.0.1
fi
# in case we develop in a different directory
identity=$(echo $identity | sed "s#$HOME#/home/devnet#")
echo "$r, $address:$port, IdentityFile $identity"
cat << _EOF >> $TESTBED
$r:
type: router
os: ios
custom:
abstraction:
order: [os]
categories:
- ios
credentials:
default:
username: vagrant
password: using-key
connections:
defaults:
class: unicon.Unicon
cli:
protocol: ssh
ip: $address
port: $port
ssh_options: -o IdentityFile=$identity -o StrictHostKeyChecking=no
_EOF
done
}
##### MAIN
start_vms 1 2
config_routers 1 2
create_testbed
###########
# bring up the docker-compose cluster
echo "starting cxta container"
export WORKDIR=$(pwd)
docker-compose up -d
# run a robot test which connects to the VMs and checks connectivity
docker exec -it cxta_devnet robot -d /tmp test-vms.robot