forked from berndonline/arista-lab-vagrant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
403 lines (373 loc) · 16.8 KB
/
Vagrantfile
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::DEFAULT_SERVER_URL.replace('https://vagrantcloud.com')
VAGRANTFILE_API_VERSION = "2"
default_box = 'vEOS-lab-4.20.1F'
server_box = 'ubuntu/xenial64'
def path_exists?(path)
File.directory?(path)
end
$dimage = ENV.fetch("DIMAGE", "netbricks")
$dtag = ENV.fetch("DTAG", "latest")
$dproject = ENV.fetch("DPROJECT", "williamofockham")
$nbpath = ENV.fetch("NBPATH", "../NetBricks")
$mgpath = ENV.fetch("MGPATH", "../MoonGen")
$dpdk_driver = ENV.fetch("DPDK_DRIVER", "uio_pci_generic")
$dpdk_devices = ENV.fetch("DPDK_DEVICES", "0000:00:08.0 0000:00:09.0")
# also defined in ansible/group_vars/bgp.yml -- ideally we'd only have one file with these
# need to find out how to share config across ansible and Vagrant
dc1_bgp_network = '10.0.153'
dc1_og_network = '10.0.154'
dc1_app_network = '10.0.155'
dc1_cli_network = '10.0.151'
dc1_asn = '65002'
dc2_bgp_network = '10.0.253'
dc2_og_network = '10.0.254'
dc2_app_network = '10.0.255'
dc2_cli_network = '10.0.251'
dc2_asn = '65003'
dc1_anycast_subnet = '192.168.1'
dc2_anycast_subnet = '192.168.2'
app_anycast = '192.168.0.2'
bgp_host = '11'
og_host = '12'
app_host = '13'
client_host = '14'
spine1_host = '2'
spine2_host = '3'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.provision "ansible" do |ansible|
ansible.playbook = "./helper_scripts/empty_playbook.yml"
ansible.groups = {
"spine" => ["spine-1","spine-2",],
"bgp" => ["bgp-1","bgp-2",],
"cli" => ["cli-1","cli-2"],
"og" => ["og-1", "og-2",],
"network:children" => ["spine",],
"dc1" => ["spine-1", "bgp-1", "og-1", "app-1"],
"dc2" => ["spine-2", "bgp-2", "og-2", "app-2"],
}
end
# for spine and leaf devices we only create the appropriate number of
# interfaces, they will be configured via ansible/site.yml
# each of the 2 spines has a direct port connecting to each of the 4 leaves,
# these connections use prefix 10.0.255.x (split into multiple /30 subnets)
#
# for spine-{1,2} device, the subnet we are setting to connect to the client is
# 10.0.25{1,2}.0/24 (see ansible/host_vars/spine-{1,2}.yml, under "interfaces",
# the interface with alias "uplink-cli-{1,2}).
#
# for leaf-{1,3} device, the subnet we are setting to connect to the og-{1,3}
# is the VLAN {101,102} with subnets 10.0.10{1,2}.0/24 (see ansible/host_vars/leaf-{1,3}.yml)
#
# we are using subnet 192.168.0.0/16 for anycasting. Each of the og-{1,3} binds
# to 192.168.0.{2,4} and they advertise route 192.168.0.0/16 via BGP to their peers
# (leaf-{1,3}).
#
# this setup means:
# - client devices must set as default gateway to route 192.168.0.0/16 the spine
# devices they're connected to (so for cli-1: "ip route add 192.168.0.0/16 via 10.0.251.2 dev enp0s8")
# - og servers must set the leaf devices they are connected to as default gateways for
# any subnets they want to reach, e.g., spine (10.0.255.0/24) and client networks
# (10.0.251.0/24).
# - og servers must have reverse path filtering disabled, ip forwarding enabled.
config.vm.define 'spine-1' do |spine01|
spine01.vm.box = default_box
spine01.vm.boot_timeout = 600
spine01.vm.network 'private_network',
virtualbox__intnet: 's01cli1',
ip: '169.254.1.11', auto_config: false
spine01.vm.network 'private_network',
virtualbox__intnet: 's01s02',
ip: '169.254.1.11', auto_config: false
spine01.vm.network 'private_network',
virtualbox__intnet: 's01bgp1',
ip: '169.254.1.11', auto_config: false
spine01.vm.network 'private_network',
virtualbox__intnet: 's01og1',
ip: '169.254.1.11', auto_config: false
spine01.vm.network 'private_network',
virtualbox__intnet: 's01app1',
ip: '169.254.1.11', auto_config: false
spine01.vm.provider 'virtualbox' do |vb|
vb.customize ['modifyvm', :id, '--nicpromisc2', 'allow-all']
vb.customize ['modifyvm', :id, '--nicpromisc3', 'allow-all']
vb.customize ['modifyvm', :id, '--nicpromisc4', 'allow-all']
vb.customize ['modifyvm', :id, '--nicpromisc5', 'allow-all']
vb.customize ['modifyvm', :id, '--nicpromisc6', 'allow-all']
end
config.vbguest.auto_update = false
end
config.vm.define 'spine-2' do |spine02|
spine02.vm.box = default_box
spine02.vm.boot_timeout = 600
spine02.vm.network 'private_network',
virtualbox__intnet: 's02cli2',
ip: '169.254.1.11', auto_config: false
spine02.vm.network 'private_network',
virtualbox__intnet: 's01s02',
ip: '169.254.1.11', auto_config: false
spine02.vm.network 'private_network',
virtualbox__intnet: 's02bgp2',
ip: '169.254.1.11', auto_config: false
spine02.vm.network 'private_network',
virtualbox__intnet: 's02og2',
ip: '169.254.1.11', auto_config: false
spine02.vm.network 'private_network',
virtualbox__intnet: 's02app2',
ip: '169.254.1.11', auto_config: false
spine02.vm.provider 'virtualbox' do |vb|
vb.customize ['modifyvm', :id, '--nicpromisc2', 'allow-all']
vb.customize ['modifyvm', :id, '--nicpromisc3', 'allow-all']
vb.customize ['modifyvm', :id, '--nicpromisc4', 'allow-all']
vb.customize ['modifyvm', :id, '--nicpromisc5', 'allow-all']
vb.customize ['modifyvm', :id, '--nicpromisc6', 'allow-all']
end
config.vbguest.auto_update = false
end
config.vm.define 'cli-1' do |cli1|
cli1.vm.box = server_box
cli1.vm.hostname = 'cli-1'
cli1.disksize.size = "30GB"
cli1.vm.synced_folder ".", "/vagrant", disabled: false
# interface 1 seems to map to enp0s3 (the one interface the guest uses to
# talk to the host), additional interfaces bind to enp0s(6 + interface number)
# so interface 2 would be bound to 10.0.251.3 below and mapped to enp0s8,
# currently cli-1 is connected to spine-1
cli1.vm.network 'private_network',
virtualbox__intnet: 's01cli1',
ip: dc1_cli_network + '.' + client_host
cli1.vm.provider 'virtualbox' do |vb|
vb.name = 'cli-1'
vb.customize ['modifyvm', :id, '--nicpromisc2', 'allow-all']
end
config.vbguest.auto_update = false
end
config.vm.define 'cli-2' do |cli2|
cli2.vm.box = server_box
cli2.vm.hostname = 'cli-2'
cli2.disksize.size = "30GB"
cli2.vm.synced_folder ".", "/vagrant", disabled: false
# interface 1 seems to map to enp0s3 (the one interface the guest uses to
# talk to the host), additional interfaces bind to enp0s(6 + interface number)
# so interface 2 would be bound to 10.0.252.3 below and mapped to enp0s8,
# currently cli-2 is connected to spine-2
cli2.vm.network 'private_network',
virtualbox__intnet: 's02cli2',
ip: dc2_cli_network + '.' + client_host
cli2.vm.provider 'virtualbox' do |vb|
vb.name = 'cli-2'
vb.customize ['modifyvm', :id, '--nicpromisc2', 'allow-all']
end
config.vbguest.auto_update = false
end
config.vm.define 'bgp-1' do |bgp1|
bgp1.vm.box = server_box
bgp1.vm.hostname = 'bgp-1'
bgp1.vm.synced_folder ".", "/vagrant", disabled: false
bgp1.vm.network 'private_network',
virtualbox__intnet: 's01bgp1',
ip: dc1_bgp_network + '.' + bgp_host
bgp1.vm.network 'private_network',
virtualbox__intnet: 'bgp1og1',
ip: dc1_anycast_subnet + '.' + bgp_host
bgp1.vm.provider 'virtualbox' do |vb|
vb.name = 'bgp-1'
vb.customize ['modifyvm', :id, '--nicpromisc2', 'allow-all']
vb.customize ['modifyvm', :id, '--nicpromisc3', 'allow-all']
end
bgp1.vm.provision 'shell', privileged: true, path: 'bgp-setup.sh', args: [dc1_bgp_network, bgp_host, dc1_asn]
config.vbguest.auto_update = false
end
config.vm.define 'bgp-2' do |bgp2|
bgp2.vm.box = server_box
bgp2.vm.hostname = 'bgp-2'
bgp2.vm.synced_folder ".", "/vagrant", disabled: false
bgp2.vm.network 'private_network',
virtualbox__intnet: 's02bgp2',
ip: dc2_bgp_network + '.' + bgp_host
bgp2.vm.network 'private_network',
virtualbox__intnet: 'bgp2og2',
ip: dc2_anycast_subnet + '.' + bgp_host
bgp2.vm.provider 'virtualbox' do |vb|
vb.name = 'bgp-2'
vb.customize ['modifyvm', :id, '--nicpromisc2', 'allow-all']
vb.customize ['modifyvm', :id, '--nicpromisc3', 'allow-all']
end
bgp2.vm.provision 'shell', privileged: true, path: 'bgp-setup.sh', args: [dc2_bgp_network, bgp_host, dc2_asn]
config.vbguest.auto_update = false
end
config.vm.define 'og-1' do |og1|
og1.vm.box = server_box
og1.vm.boot_timeout = 600
og1.vm.hostname = 'og-1'
og1.disksize.size = "30GB"
og1.vm.synced_folder ".", "/vagrant", disabled: false
if path_exists?($nbpath)
og1.vm.synced_folder $nbpath, "/NetBricks", disabled: false
end
if path_exists?($mgpath)
og1.vm.synced_folder $mgpath, "/MoonGen", disabled: false
end
og1_network = dc1_og_network
og1_host = og_host
og1_asn = dc1_asn
# Create a private network, which allows host-only access to the machine using a
# specific IP. This option is needed because DPDK takes over the NIC.
og1.vm.network "private_network", ip: "10.1.2.2", mac: "BADCAFEBEEF1", nic_type: "virtio"
og1.vm.network "private_network", ip: "10.1.2.3", mac: "BADCAFEBEEF2", nic_type: "virtio"
og1.vm.network 'private_network',
virtualbox__intnet: 's01og1',
ip: og1_network + '.' + og1_host
og1.vm.network 'private_network',
virtualbox__intnet: 'bgp1og1',
ip: dc1_anycast_subnet + '.' + og1_host
og1.vm.network 'private_network', virtualbox__intnet: 'appany1',
ip: app_anycast
og1.vm.provision 'shell', privileged: true, path: 'og-setup.sh'
# Pull and run (then remove) our image in order to do the devbind
og1 .vm.provision "docker" do |d|
d.pull_images "#{$dproject}/#{$dimage}:#{$dtag}"
d.run "#{$dproject}/#{$dimage}:#{$dtag}",
auto_assign_name: false,
args: %W(--name=#{$dimage}
--rm
--privileged
--pid=host
--network=host
-v /lib/modules:/lib/modules
-v /usr/src:/usr/src
-v /sys/bus/pci/drivers:/sys/bus/pci/drivers
-v /sys/kernel/mm/hugepages:/sys/kernel/mm/hugepages
-v /sys/devices/system/node:/sys/devices/system/node
-v /sbin/modinfo:/sbin/modinfo
-v /bin/kmod:/bin/kmod
-v /sbin/lsmod:/sbin/lsmod
-v /dev:/dev
-v /mnt/huge:/mnt/huge
-v /var/run:/var/run).join(" "),
restart: "no",
daemonize: true,
cmd: "/bin/bash -c '/dpdk/usertools/dpdk-devbind.py --force -b #{$dpdk_driver} #{$dpdk_devices}'"
end
og1.vm.provider 'virtualbox' do |vb|
vb.name = 'og-1'
vb.memory = 4096
vb.cpus = 4
vb.customize ['modifyvm', :id, '--nicpromisc2', 'allow-all']
vb.customize ['modifyvm', :id, '--nicpromisc3', 'allow-all']
vb.customize ['modifyvm', :id, '--nicpromisc4', 'allow-all']
vb.customize ['modifyvm', :id, '--nicpromisc5', 'allow-all']
vb.customize ['modifyvm', :id, '--nicpromisc6', 'allow-all']
# Configure VirtualBox to enable passthrough of SSE 4.1 and SSE 4.2 instructions,
# according to this: https://www.virtualbox.org/manual/ch09.html#sse412passthrough
# This step is fundamental otherwise DPDK won't build. It is possible to verify in
# the guest OS that these changes took effect by running `cat /proc/cpuinfo` and
# checking that `sse4_1` and `sse4_2` are listed among the CPU flags.
vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.1", "1"]
vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.2", "1"]
end
og1.vm.provision 'shell', privileged: true, path: 'og-setup.sh', args: [og1_network, og1_host, og1_asn]
config.vbguest.auto_update = false
end
config.vm.define 'og-2' do |og2|
og2.vm.box = server_box
og2.vm.boot_timeout = 600
og2.vm.hostname = 'og-2'
og2.disksize.size = "30GB"
og2.vm.synced_folder ".", "/vagrant", disabled: false
if path_exists?($nbpath)
og2.vm.synced_folder $nbpath, "/NetBricks", disabled: false
end
if path_exists?($mgpath)
og2.vm.synced_folder $mgpath, "/MoonGen", disabled: false
end
og2_network = dc2_og_network
og2_host = og_host
og2_asn = dc2_asn
# Create a private network, which allows host-only access to the machine using a
# specific IP. This option is needed because DPDK takes over the NIC.
og2.vm.network "private_network", ip: "10.1.2.4", mac: "BADCAFEBEEF3", nic_type: "virtio"
og2.vm.network "private_network", ip: "10.1.2.5", mac: "BADCAFEBEEF4", nic_type: "virtio"
og2.vm.network 'private_network',
virtualbox__intnet: 's02og2',
ip: og2_network + '.' + og2_host
og2.vm.network 'private_network',
virtualbox__intnet: 'bgp2og2',
ip: dc2_anycast_subnet + '.' + og2_host
og2.vm.network 'private_network', virtualbox__intnet: 'appany2',
ip: app_anycast
og2.vm.provision 'shell', privileged: true, path: 'og-setup.sh'
# Pull and run (then remove) our image in order to do the devbind
og2 .vm.provision "docker" do |d|
d.pull_images "#{$dproject}/#{$dimage}:#{$dtag}"
d.run "#{$dproject}/#{$dimage}:#{$dtag}",
auto_assign_name: false,
args: %W(--name=#{$dimage}
--rm
--privileged
--pid=host
--network=host
-v /lib/modules:/lib/modules
-v /usr/src:/usr/src
-v /sys/bus/pci/drivers:/sys/bus/pci/drivers
-v /sys/kernel/mm/hugepages:/sys/kernel/mm/hugepages
-v /sys/devices/system/node:/sys/devices/system/node
-v /sbin/modinfo:/sbin/modinfo
-v /bin/kmod:/bin/kmod
-v /sbin/lsmod:/sbin/lsmod
-v /dev:/dev
-v /mnt/huge:/mnt/huge
-v /var/run:/var/run).join(" "),
restart: "no",
daemonize: true,
cmd: "/bin/bash -c '/dpdk/usertools/dpdk-devbind.py --force -b #{$dpdk_driver} #{$dpdk_devices}'"
end
og2.vm.provider 'virtualbox' do |vb|
vb.name = 'og-2'
vb.memory = 4096
vb.cpus = 4
vb.customize ['modifyvm', :id, '--nicpromisc2', 'allow-all']
vb.customize ['modifyvm', :id, '--nicpromisc3', 'allow-all']
vb.customize ['modifyvm', :id, '--nicpromisc4', 'allow-all']
vb.customize ['modifyvm', :id, '--nicpromisc5', 'allow-all']
vb.customize ['modifyvm', :id, '--nicpromisc6', 'allow-all']
# Configure VirtualBox to enable passthrough of SSE 4.1 and SSE 4.2 instructions,
# according to this: https://www.virtualbox.org/manual/ch09.html#sse412passthrough
# This step is fundamental otherwise DPDK won't build. It is possible to verify in
# the guest OS that these changes took effect by running `cat /proc/cpuinfo` and
# checking that `sse4_1` and `sse4_2` are listed among the CPU flags.
vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.1", "1"]
vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.2", "1"]
end
config.vbguest.auto_update = false
end
config.vm.define 'app-1' do |app1|
app1.vm.box = server_box
app1.vm.hostname = 'app-1'
app1.vm.synced_folder ".", "/vagrant", disabled: false
app1.vm.network 'private_network',
virtualbox__intnet: 's01app1',
ip: dc1_app_network + '.' + app_host
app1.vm.provider 'virtualbox' do |vb|
vb.name = 'app-1'
vb.customize ['modifyvm', :id, '--nicpromisc2', 'allow-all']
end
# app1.vm.provision 'shell', privileged: true, path: 'app-setup.sh', args: []
config.vbguest.auto_update = false
end
config.vm.define 'app-2' do |app2|
app2.vm.box = server_box
app2.vm.hostname = 'app-2'
app2.vm.synced_folder ".", "/vagrant", disabled: false
app2.vm.network 'private_network',
virtualbox__intnet: 's02app2',
ip: dc2_app_network + '.' + app_host
app2.vm.provider 'virtualbox' do |vb|
vb.name = 'app-2'
vb.customize ['modifyvm', :id, '--nicpromisc2', 'allow-all']
end
# app1.vm.provision 'shell', privileged: true, path: 'app-setup.sh', args: []
config.vbguest.auto_update = false
end
end