-
Notifications
You must be signed in to change notification settings - Fork 34
/
routeserver_2hubs.azcli
1996 lines (1904 loc) · 113 KB
/
routeserver_2hubs.azcli
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
##########################################
#
# AzCLI commands to play around with ARS
#
##########################################
# Control
ars_hub_b2b=yes # Whether enabling b2b in the hub ARS
hub_no=2 # 1 or 2 regions
nva_no=1 # 1 or 2 NVAs per region
nva_type=linux1nic # Only linux supported (linux1nic | linux2nic), CSR To Do
create_azfw=yes # Whether an AzFW is created in the hub
flowlogs2logws=yes # Whether Flow Logs are sent to an LA workspace too
stress_test_routes=no # Whether running a stress test on the number of routes by creating many VNets peered to the hub
next_hop=nva # Either 'azfw', 'lb' or 'nva'. If 'lb', it sets the advertised next hop to ARS as the internal LB private IP
use_vxlan=no # Whether using VXLAN encap between the NVAs in different hubs
create_onprem=yes # Whether onprem will be simulated with an additional network
onprem_vpn=yes # Whether onprem will be connected via S2S VPN + BGP
onprem_er=yes # Whether onprem will be connected via ExpressRoute (not implemented yet)
spoke_rts=yes # Override ARS information and create RTs for the spokes with gw prop disabled
# Variables
rg=routeserver
hub1_vnet_name=hub1
hub1_location=northeurope
hub1_vnet_prefix=10.1.0.0/20
hub1_rs_subnet_name=RouteServerSubnet
hub1_rs_subnet_prefix=10.1.0.0/24
hub1_rs_name=hub1rs
hub1_nva_subnet_name=nva1ary
hub1_nva_subnet_prefix=10.1.1.0/24
hub1_nva_subnet2_name=nva2ary
hub1_nva_subnet2_prefix=10.1.11.0/24
hub1_nva_overlay_ip=10.251.0.1
hub1_nva_asn=65001
hub1_vm_subnet_name=vm
hub1_vm_subnet_prefix=10.1.2.0/24
hub1_gw_subnet_prefix=10.1.3.0/24
hub1_azfw_subnet_prefix=10.1.15.0/24
hub1_spoke_summary=10.1.0.0/16
spoke11_vnet_name=spoke11
spoke11_vnet_prefix=10.1.16.0/24
spoke11_vm_subnet_name=vm
spoke11_vm_subnet_prefix=10.1.16.0/26
spoke12_vnet_name=spoke12
spoke12_vnet_prefix=10.1.17.0/24
spoke12_vm_subnet_name=vm
spoke12_vm_subnet_prefix=10.1.17.0/26
hub2_vnet_name=hub2
hub2_location=eastus
hub2_vnet_prefix=10.2.0.0/20
hub2_rs_subnet_name=RouteServerSubnet
hub2_rs_subnet_prefix=10.2.0.0/24
hub2_rs_name=hub2rs
hub2_nva_subnet_name=nva1ary
hub2_nva_subnet_prefix=10.2.1.0/24
hub2_nva_subnet2_name=nva2ary
hub2_nva_subnet2_prefix=10.2.11.0/24
hub2_nva_asn=65002
hub2_vm_subnet_name=vm
hub2_vm_subnet_prefix=10.2.2.0/24
hub2_gw_subnet_prefix=10.2.3.0/24
hub2_azfw_subnet_prefix=10.2.15.0/24
hub2_spoke_summary=10.2.0.0/16
hub2_nva_overlay_ip=10.251.0.2
spoke21_vnet_name=spoke21
spoke21_vnet_prefix=10.2.16.0/24
spoke21_vm_subnet_name=vm
spoke21_vm_subnet_prefix=10.2.16.0/26
spoke22_vnet_name=spoke22
spoke22_vnet_prefix=10.2.17.0/24
spoke22_vm_subnet_name=vm
spoke22_vm_subnet_prefix=10.2.17.0/26
azfw_policy_name=azfwpolicy
# ER variables (optional)
er_provider=Megaport
er_circuit_sku=Premium
megaport_script_path="/home/jose/repos/azcli/megaport.sh"
# hub1_er_pop=Sydney
hub1_er_pop=Frankfurt
mcr1_asn=65001
gr_ip_range=172.16.31.0/29
hub1_er_circuit_name="er1-$hub1_er_pop"
hub1_ergw_name=hub1ergw
hub1_ergw_pip=hub1ergw-pip
# hub2_er_pop=Dallas
hub2_er_pop=Amsterdam
hub2_er_circuit_name="er2-$hub2_er_pop"
hub2_ergw_name=hub2ergw
hub2_ergw_pip=hub2ergw-pip
mcr2_asn=65002
# gcloud variables to simulate onprem via ER
project_name=onprem
project_id="${project_name}${RANDOM}"
machine_type=e2-micro
gcp_asn=16550
# https://cloud.google.com/compute/docs/regions-zones/
# region1=australia-southeast1
# zone1=australia-southeast1-b
region1=europe-west1 # Belgium
zone1=europe-west1-b
gcp_vm1_name=vm1
gcp_vpc1_name=vpc1
gcp_subnet1_name=vm1
gcp_subnet1_prefix='10.4.2.0/24'
attachment1_name=attachment1
router1_name=router1
# region2=us-west2 # London
# zone2=us-west2-b
region2=europe-west3
zone2=europe-west3-b
gcp_vm2_name=vm2
gcp_vpc2_name=vpc2
gcp_subnet2_name=vm2
gcp_subnet2_prefix='10.5.2.0/24'
attachment2_name=attachment2
router2_name=router2
# Auxiliary function to manipulate CIDR
function first_ip(){
subnet=$1
IP=$(echo $subnet | cut -d/ -f 1)
IP_HEX=$(printf '%.2X%.2X%.2X%.2X\n' `echo $IP | sed -e 's/\./ /g'`)
NEXT_IP_HEX=$(printf %.8X `echo $(( 0x$IP_HEX + 1 ))`)
NEXT_IP=$(printf '%d.%d.%d.%d\n' `echo $NEXT_IP_HEX | sed -r 's/(..)/0x\1 /g'`)
echo "$NEXT_IP"
}
# Auxiliary function to get the first private IP of a VM (whose name is supplied as argument)
function get_1st_private_ip(){
vm_name=$1
nic_id=$(az vm show -n "$vm_name" -g "$rg" --query 'networkProfile.networkInterfaces[0].id' -o tsv)
private_ip=$(az network nic show --ids $nic_id --query 'ipConfigurations[0].privateIpAddress' -o tsv) && echo $private_ip
}
# Auxiliary function to get the public IP of a VM (whose name is supplied as argument)
function get_pip(){
vm_name=$1
nic_id=$(az vm show -n "$vm_name" -g "$rg" --query 'networkProfile.networkInterfaces[0].id' -o tsv)
pip_id=$(az network nic show --ids $nic_id --query 'ipConfigurations[0].publicIpAddress.id' -o tsv)
pip=$(az network public-ip show --ids $pip_id --query 'ipAddress' -o tsv) && echo $pip
}
###########
# Start #
###########
# Create Vnets
echo "Creating VNets..."
az group create -n $rg -l $hub1_location -o none
az network vnet create -g $rg -n $hub1_vnet_name --address-prefix $hub1_vnet_prefix --subnet-name $hub1_vm_subnet_name --subnet-prefixes $hub1_vm_subnet_prefix -l $hub1_location -o none
az network vnet subnet create -n $hub1_nva_subnet_name --address-prefix $hub1_nva_subnet_prefix --vnet-name $hub1_vnet_name -g $rg -o none
az network vnet subnet create -n $hub1_nva_subnet2_name --address-prefix $hub1_nva_subnet2_prefix --vnet-name $hub1_vnet_name -g $rg -o none
az network vnet subnet create -n GatewaySubnet --address-prefix $hub1_gw_subnet_prefix --vnet-name $hub1_vnet_name -g $rg -o none
az network vnet subnet create -n RouteServerSubnet --address-prefix $hub1_rs_subnet_prefix --vnet-name $hub1_vnet_name -g $rg -o none
az network vnet create -g $rg -n $spoke11_vnet_name --address-prefix $spoke11_vnet_prefix --subnet-name $spoke11_vm_subnet_name --subnet-prefixes $spoke11_vm_subnet_prefix -l $hub1_location -o none
az network vnet create -g $rg -n $spoke12_vnet_name --address-prefix $spoke12_vnet_prefix --subnet-name $spoke12_vm_subnet_name --subnet-prefixes $spoke12_vm_subnet_prefix -l $hub1_location -o none
if [[ "$hub_no" == "2" ]]
then
az network vnet create -g $rg -n $hub2_vnet_name --address-prefix $hub2_vnet_prefix --subnet-name $hub2_vm_subnet_name --subnet-prefixes $hub2_vm_subnet_prefix -l $hub2_location -o none
az network vnet subnet create -n $hub2_nva_subnet_name --address-prefix $hub2_nva_subnet_prefix --vnet-name $hub2_vnet_name -g $rg -o none
az network vnet subnet create -n $hub2_nva_subnet2_name --address-prefix $hub2_nva_subnet2_prefix --vnet-name $hub2_vnet_name -g $rg -o none
az network vnet subnet create -n GatewaySubnet --address-prefix $hub2_gw_subnet_prefix --vnet-name $hub2_vnet_name -g $rg -o none
az network vnet subnet create -n RouteServerSubnet --address-prefix $hub2_rs_subnet_prefix --vnet-name $hub2_vnet_name -g $rg -o none
az network vnet create -g $rg -n $spoke21_vnet_name --address-prefix $spoke21_vnet_prefix --subnet-name $spoke21_vm_subnet_name --subnet-prefixes $spoke21_vm_subnet_prefix -l $hub2_location -o none
az network vnet create -g $rg -n $spoke22_vnet_name --address-prefix $spoke22_vnet_prefix --subnet-name $spoke22_vm_subnet_name --subnet-prefixes $spoke22_vm_subnet_prefix -l $hub2_location -o none
fi
# Create Route Servers
echo "Creating Route Servers..."
hub1_rs_subnet_id=$(az network vnet subnet show -n RouteServerSubnet --vnet-name $hub1_vnet_name -g $rg --query id -o tsv)
hub1_rs_pip_name="${hub1_rs_name}-pip"
az network public-ip create -g $rg -n "$hub1_rs_pip_name" --allocation-method Static --sku Standard -l $hub1_location -o none
az network routeserver create -n $hub1_rs_name -g $rg --hosted-subnet $hub1_rs_subnet_id -l $hub1_location --public-ip-address $hub1_rs_pip_name -o none
if [[ "$hub_no" == "2" ]]
then
hub2_rs_pip_name="${hub2_rs_name}-pip"
az network public-ip create -g $rg -n "$hub2_rs_pip_name" --allocation-method Static --sku Standard -l $hub2_location -o none
hub2_rs_subnet_id=$(az network vnet subnet show -n RouteServerSubnet --vnet-name $hub2_vnet_name -g $rg --query id -o tsv)
az network routeserver create -n $hub2_rs_name -g $rg --hosted-subnet $hub2_rs_subnet_id -l $hub2_location --public-ip-address $hub2_rs_pip_name -o none
fi
# Optionally, enable for peering with VNGs
if [[ "$ars_hub_b2b" == "yes" ]]
then
echo "Enabling b2b in ARS..."
az network routeserver update -n $hub1_rs_name -g $rg --allow-b2b-traffic true -o none
if [[ "$hub_no" == "2" ]]
then
az network routeserver update -n $hub2_rs_name -g $rg --allow-b2b-traffic true -o none
fi
fi
# Delete Vnet peerings
# az network vnet peering delete -n hub1tospoke11 -g $rg --vnet-name $hub1_vnet_name -o none
# az network vnet peering delete -n spoke11tohub1 -g $rg --vnet-name $spoke11_vnet_name -o none
# az network vnet peering delete -n hub1tospoke12 -g $rg --vnet-name $hub1_vnet_name -o none
# az network vnet peering delete -n spoke12tohub1 -g $rg --vnet-name $spoke12_vnet_name -o none
# if [[ "$hub_no" == "2" ]]
# then
# az network vnet peering delete -n hub2tospoke21 -g $rg --vnet-name $hub2_vnet_name -o none
# az network vnet peering delete -n spoke21tohub2 -g $rg --vnet-name $spoke21_vnet_name -o none
# az network vnet peering delete -n hub2tospoke22 -g $rg --vnet-name $hub2_vnet_name -o none
# az network vnet peering delete -n spoke22tohub2 -g $rg --vnet-name $spoke22_vnet_name -o none
# fi
# Create Vnet peerings
echo "Creating VNet peerings..."
az network vnet peering create -n hub1tospoke11 -g $rg --vnet-name $hub1_vnet_name --remote-vnet $spoke11_vnet_name --allow-vnet-access --allow-forwarded-traffic --allow-gateway-transit -o none
az network vnet peering create -n spoke11tohub1 -g $rg --vnet-name $spoke11_vnet_name --remote-vnet $hub1_vnet_name --allow-vnet-access --allow-forwarded-traffic --use-remote-gateways -o none
az network vnet peering create -n hub1tospoke12 -g $rg --vnet-name $hub1_vnet_name --remote-vnet $spoke12_vnet_name --allow-vnet-access --allow-forwarded-traffic --allow-gateway-transit -o none
az network vnet peering create -n spoke12tohub1 -g $rg --vnet-name $spoke12_vnet_name --remote-vnet $hub1_vnet_name --allow-vnet-access --allow-forwarded-traffic --use-remote-gateways -o none
if [[ "$hub_no" == "2" ]]
then
az network vnet peering create -n hub2tospoke21 -g $rg --vnet-name $hub2_vnet_name --remote-vnet $spoke21_vnet_name --allow-vnet-access --allow-forwarded-traffic --allow-gateway-transit -o none
az network vnet peering create -n spoke21tohub2 -g $rg --vnet-name $spoke21_vnet_name --remote-vnet $hub2_vnet_name --allow-vnet-access --allow-forwarded-traffic --use-remote-gateways -o none
az network vnet peering create -n hub2tospoke22 -g $rg --vnet-name $hub2_vnet_name --remote-vnet $spoke22_vnet_name --allow-vnet-access --allow-forwarded-traffic --allow-gateway-transit -o none
az network vnet peering create -n spoke22tohub2 -g $rg --vnet-name $spoke22_vnet_name --remote-vnet $hub2_vnet_name --allow-vnet-access --allow-forwarded-traffic --use-remote-gateways -o none
az network vnet peering create -n hub1tohub2 -g $rg --vnet-name $hub1_vnet_name --remote-vnet $hub2_vnet_name --allow-vnet-access --allow-forwarded-traffic -o none
az network vnet peering create -n hub2tohub1 -g $rg --vnet-name $hub2_vnet_name --remote-vnet $hub1_vnet_name --allow-vnet-access --allow-forwarded-traffic -o none
fi
# Get RS info
echo "ARS in hub1 info:"
hub1_rs_ip1=$(az network routeserver show -n $hub1_rs_name -g $rg --query 'virtualRouterIps[0]' -o tsv) && echo $hub1_rs_ip1
hub1_rs_ip2=$(az network routeserver show -n $hub1_rs_name -g $rg --query 'virtualRouterIps[1]' -o tsv) && echo $hub1_rs_ip2
hub1_rs_asn=$(az network routeserver show -n $hub1_rs_name -g $rg --query 'virtualRouterAsn' -o tsv) && echo $hub1_rs_asn
if [[ "$hub_no" == "2" ]]
then
echo "ARS in hub2 info:"
hub2_rs_ip1=$(az network routeserver show -n $hub2_rs_name -g $rg --query 'virtualRouterIps[0]' -o tsv) && echo $hub2_rs_ip1
hub2_rs_ip2=$(az network routeserver show -n $hub2_rs_name -g $rg --query 'virtualRouterIps[1]' -o tsv) && echo $hub2_rs_ip2
hub2_rs_asn=$(az network routeserver show -n $hub2_rs_name -g $rg --query 'virtualRouterAsn' -o tsv) && echo $hub2_rs_asn
fi
# Create NSGs for VMs and NVAs (using the same for simplicity)
echo "Creating NSGs..."
hub1_nsg_name="hub1-nsg"
az network nsg create -n "$hub1_nsg_name" -g $rg -l $hub1_location -o none
az network nsg rule create -n SSHin --nsg-name "$hub1_nsg_name" -g $rg --priority 1000 --destination-port-ranges 22 --access Allow --protocol Tcp --direction Inbound -o none
az network nsg rule create -n ICMPin --nsg-name "$hub1_nsg_name" -g $rg --priority 1010 --destination-port-ranges '*' --access Allow --protocol Icmp --direction Inbound -o none
az network nsg rule create -n IKEin --nsg-name "$hub1_nsg_name" -g $rg --priority 1020 --destination-port-ranges 4500 --access Allow --protocol Udp --direction Inbound -o none
az network nsg rule create -n IPsecin --nsg-name "$hub1_nsg_name" -g $rg --priority 1030 --destination-port-ranges 500 --access Allow --protocol Udp --direction Inbound -o none
az network nsg rule create -n RFC1918in --nsg-name "$hub1_nsg_name" -g $rg --priority 1040 --source-address-prefixes '10.0.0.0/8' '10.251.0.0/16' '172.16.0.0/12' --destination-address-prefixes '10.0.0.0/8' '10.251.0.0/16' '172.16.0.0/12' --destination-port-ranges '*' --access Allow --protocol '*' --direction Inbound -o none
az network nsg rule create -n ICMPout --nsg-name "$hub1_nsg_name" -g $rg --priority 1000 --destination-port-ranges '*' --access Allow --protocol Icmp --direction Outbound -o none
az network nsg rule create -n RFC1918out --nsg-name "$hub1_nsg_name" -g $rg --priority 1010 --source-address-prefixes '10.0.0.0/8' '10.251.0.0/16' '172.16.0.0/12' --destination-address-prefixes '10.0.0.0/8' '10.251.0.0/16' '172.16.0.0/12' --destination-port-ranges '*' --access Allow --protocol '*' --direction Outbound -o none
if [[ "$hub_no" == "2" ]]
then
hub2_nsg_name="hub2-nsg"
az network nsg create -n "$hub2_nsg_name" -g $rg -l $hub2_location -o none
az network nsg rule create -n SSHin --nsg-name "$hub2_nsg_name" -g $rg --priority 1000 --destination-port-ranges 22 --access Allow --protocol Tcp --direction Inbound -o none
az network nsg rule create -n ICMPin --nsg-name "$hub2_nsg_name" -g $rg --priority 1010 --destination-port-ranges '*' --access Allow --protocol Icmp --direction Inbound -o none
az network nsg rule create -n IKEin --nsg-name "$hub2_nsg_name" -g $rg --priority 1020 --destination-port-ranges 4500 --access Allow --protocol Udp --direction Inbound -o none
az network nsg rule create -n IPsecin --nsg-name "$hub2_nsg_name" -g $rg --priority 1030 --destination-port-ranges 500 --access Allow --protocol Udp --direction Inbound -o none
az network nsg rule create -n RFC1918in --nsg-name "$hub2_nsg_name" -g $rg --priority 1040 --source-address-prefixes '10.0.0.0/8' '10.251.0.0/16' '172.16.0.0/12' --destination-address-prefixes '10.0.0.0/8' '10.251.0.0/16' '172.16.0.0/12' --destination-port-ranges '*' --access Allow --protocol '*' --direction Inbound -o none
az network nsg rule create -n ICMPout --nsg-name "$hub2_nsg_name" -g $rg --priority 1000 --destination-port-ranges '*' --access Allow --protocol Icmp --direction Outbound -o none
az network nsg rule create -n RFC1918out --nsg-name "$hub2_nsg_name" -g $rg --priority 1010 --source-address-prefixes '10.0.0.0/8' '10.251.0.0/16' '172.16.0.0/12' --destination-address-prefixes '10.0.0.0/8' '10.251.0.0/16' '172.16.0.0/12' --destination-port-ranges '*' --access Allow --protocol '*' --direction Outbound -o none
fi
# Create Log Analytics workspaces in each region (or find an existing one in RG)
hub1_logws_name=$(az monitor log-analytics workspace list -g $rg --query "[?location=='${hub1_location}'].name" -o tsv)
if [[ -z "$hub1_logws_name" ]]
then
hub1_logws_name=log$RANDOM
echo "INFO: Creating log analytics workspace ${hub1_logws_name} in ${hub1_location}..."
az monitor log-analytics workspace create -n $hub1_logws_name -g $rg -l $hub1_location -o none
else
echo "INFO: Log Analytics workspace $hub1_logws_name in $hub1_location found in resource group $rg"
fi
hub1_logws_id=$(az resource list -g $rg -n $hub1_logws_name --query '[].id' -o tsv)
hub1_logws_customerid=$(az monitor log-analytics workspace show -n $hub1_logws_name -g $rg --query customerId -o tsv)
if [[ "$hub_no" == "2" ]]
then
hub2_logws_name=$(az monitor log-analytics workspace list -g $rg --query "[?location=='${hub2_location}'].name" -o tsv)
if [[ -z "$hub2_logws_name" ]]
then
hub2_logws_name=log$RANDOM
echo "INFO: Creating log analytics workspace ${hub2_logws_name} in ${hub2_location}..."
az monitor log-analytics workspace create -n $hub2_logws_name -g $rg -l $hub2_location -o none
else
echo "INFO: Log Analytics workspace $hub2_logws_name in $hub2_location found in resource group $rg"
fi
hub2_logws_id=$(az resource list -g $rg -n $hub2_logws_name --query '[].id' -o tsv)
hub2_logws_customerid=$(az monitor log-analytics workspace show -n $hub2_logws_name -g $rg --query customerId -o tsv)
fi
# Configure flow logs for NSGs in location 1
storage_account1_name=$(az storage account list -g $rg -o tsv --query "[?location=='$hub1_location'].name" | head -1)
if [[ -z "$storage_account1_name" ]]; then
echo "No storage account found in $hub1_location, creating one..."
storage_account1_name=rslogs$RANDOM${hub1_location}
az storage account create -n $storage_account1_name -g $rg --sku Standard_LRS --kind StorageV2 -l $hub1_location -o none
else
echo "Storage account $storage_account1_name found in $hub1_location, using it for NSG flow flogs"
fi
if [[ "$flowlogs2logws" == yes ]]
then
echo "Configuring Flow Logs for NSG $hub1_nsg_name into storage account $storage_account1_name and LA workspace ${hub1_logws_name}..."
az network watcher flow-log create -l $hub1_location -n flowlog$RANDOM -g $rg --nsg $hub1_nsg_name --storage-account $storage_account1_name --log-version 2 --retention 7 \
--traffic-analytics true --workspace $hub1_logws_id --interval 10 -o none
else
echo "Configuring Flow Logs for NSG $hub1_nsg_name into storage account $storage_account1_name..."
az network watcher flow-log create -l $hub1_location -n flowlog$RANDOM -g $rg --nsg $hub1_nsg_name --storage-account $storage_account1_name --log-version 2 --retention 7 -o none
fi
# Configure flow logs for NSGs in location 2
if [[ "$hub_no" == "2" ]]
then
storage_account2_name=$(az storage account list -g $rg -o tsv --query "[?location=='$hub2_location'].name" | head -1)
if [[ -z "$storage_account2_name" ]]; then
echo "No storage account found in $hub2_location, creating one..."
storage_account2_name=rslogs$RANDOM${hub2_location}
az storage account create -n $storage_account2_name -g $rg --sku Standard_LRS --kind StorageV2 -l $hub2_location -o none
else
echo "Storage account $storage_account2_name found in $hub2_location, using it for NSG flow flogs"
fi
if [[ "$flowlogs2logws" == yes ]]
then
echo "Configuring Flow Logs for NSG $hub2_nsg_name into storage account $storage_account2_name and LA workspace ${hub2_logws_name}..."
az network watcher flow-log create -l $hub2_location -n flowlog$RANDOM -g $rg --nsg $hub2_nsg_name --storage-account $storage_account2_name --log-version 2 --retention 7 \
--traffic-analytics true --workspace $hub2_logws_id --interval 10 -o none
else
echo "Configuring Flow Logs for NSG $hub2_nsg_name into storage account $storage_account2_name..."
az network watcher flow-log create -l $hub2_location -n flowlog$RANDOM -g $rg --nsg $hub2_nsg_name --storage-account $storage_account2_name --log-version 2 --retention 7 -o none
fi
fi
# Create test VMs in each subnet
vm_size=Standard_B1s
hub1_vm_name="${hub1_vnet_name}-vm"
hub1_vm_pip_name="${hub1_vm_name}-pip"
echo "Creating VMs..."
az vm create -n $hub1_vm_name -g $rg -l $hub1_location --image ubuntuLTS --generate-ssh-keys --public-ip-address ${hub1_vm_pip_name} --public-ip-sku Standard --vnet-name $hub1_vnet_name --size $vm_size --subnet $hub1_vm_subnet_name --nsg $hub1_nsg_name -o none
hub1_vm_pip=$(az network public-ip show -n $hub1_vm_pip_name --query ipAddress -o tsv -g $rg)
hub1_vm_nic_id=$(az vm show -n "$hub1_vm_name" -g "$rg" --query 'networkProfile.networkInterfaces[0].id' -o tsv)
hub1_vm_private_ip=$(az network nic show --ids $hub1_vm_nic_id --query 'ipConfigurations[0].privateIpAddress' -o tsv)
spoke11_vm_name="${spoke11_vnet_name}-vm"
spoke11_vm_pip_name="${spoke11_vm_name}-pip"
az vm create -n $spoke11_vm_name -g $rg -l $hub1_location --image ubuntuLTS --generate-ssh-keys --public-ip-address ${spoke11_vm_pip_name} --public-ip-sku Standard --vnet-name $spoke11_vnet_name --size $vm_size --subnet $spoke11_vm_subnet_name --nsg $hub1_nsg_name -o none
spoke11_vm_pip=$(az network public-ip show -n $spoke11_vm_pip_name --query ipAddress -o tsv -g $rg)
spoke11_vm_nic_id=$(az vm show -n "$spoke11_vm_name" -g "$rg" --query 'networkProfile.networkInterfaces[0].id' -o tsv)
spoke11_vm_private_ip=$(az network nic show --ids $spoke11_vm_nic_id --query 'ipConfigurations[0].privateIpAddress' -o tsv)
spoke12_vm_name="${spoke12_vnet_name}-vm"
spoke12_vm_pip_name="${spoke12_vm_name}-pip"
az vm create -n $spoke12_vm_name -g $rg -l $hub1_location --image ubuntuLTS --generate-ssh-keys --public-ip-address ${spoke12_vm_pip_name} --public-ip-sku Standard --vnet-name $spoke12_vnet_name --size $vm_size --subnet $spoke12_vm_subnet_name --nsg $hub1_nsg_name -o none
spoke12_vm_pip=$(az network public-ip show -n $spoke12_vm_pip_name --query ipAddress -o tsv -g $rg)
spoke12_vm_nic_id=$(az vm show -n "$spoke12_vm_name" -g "$rg" --query 'networkProfile.networkInterfaces[0].id' -o tsv)
spoke12_vm_private_ip=$(az network nic show --ids $spoke12_vm_nic_id --query 'ipConfigurations[0].privateIpAddress' -o tsv)
if [[ "$hub_no" == "2" ]]
then
hub2_vm_name="${hub2_vnet_name}-vm"
hub2_vm_pip_name="${hub2_vm_name}-pip"
az vm create -n $hub2_vm_name -g $rg -l $hub2_location --image ubuntuLTS --generate-ssh-keys --public-ip-address ${hub2_vm_pip_name} --public-ip-sku Standard --vnet-name $hub2_vnet_name --size $vm_size --subnet $hub2_vm_subnet_name --nsg $hub2_nsg_name -o none
hub2_vm_pip=$(az network public-ip show -n $hub2_vm_pip_name --query ipAddress -o tsv -g $rg)
hub2_vm_nic_id=$(az vm show -n "$hub2_vm_name" -g "$rg" --query 'networkProfile.networkInterfaces[0].id' -o tsv)
hub2_vm_private_ip=$(az network nic show --ids $hub2_vm_nic_id --query 'ipConfigurations[0].privateIpAddress' -o tsv)
spoke21_vm_name="${spoke21_vnet_name}-vm"
spoke21_vm_pip_name="${spoke21_vm_name}-pip"
az vm create -n $spoke21_vm_name -g $rg -l $hub2_location --image ubuntuLTS --generate-ssh-keys --public-ip-address ${spoke21_vm_pip_name} --public-ip-sku Standard --vnet-name $spoke21_vnet_name --size $vm_size --subnet $spoke21_vm_subnet_name --nsg $hub2_nsg_name -o none
spoke21_vm_pip=$(az network public-ip show -n $spoke21_vm_pip_name --query ipAddress -o tsv -g $rg)
spoke21_vm_nic_id=$(az vm show -n "$spoke21_vm_name" -g "$rg" --query 'networkProfile.networkInterfaces[0].id' -o tsv)
spoke21_vm_private_ip=$(az network nic show --ids $spoke21_vm_nic_id --query 'ipConfigurations[0].privateIpAddress' -o tsv)
spoke22_vm_name="${spoke22_vnet_name}-vm"
spoke22_vm_pip_name="${spoke22_vm_name}-pip"
az vm create -n $spoke22_vm_name -g $rg -l $hub2_location --image ubuntuLTS --generate-ssh-keys --public-ip-address ${spoke22_vm_pip_name} --public-ip-sku Standard --vnet-name $spoke22_vnet_name --size $vm_size --subnet $spoke22_vm_subnet_name --nsg $hub2_nsg_name -o none
spoke22_vm_pip=$(az network public-ip show -n $spoke22_vm_pip_name --query ipAddress -o tsv -g $rg)
spoke22_vm_nic_id=$(az vm show -n "$spoke22_vm_name" -g "$rg" --query 'networkProfile.networkInterfaces[0].id' -o tsv)
spoke22_vm_private_ip=$(az network nic show --ids $spoke22_vm_nic_id --query 'ipConfigurations[0].privateIpAddress' -o tsv)
fi
# Optional: create AzFW
if [[ "$create_azfw" == "yes" ]]
then
# AzFW Policy (for both hubs)
echo "Creating Azure Firewall Policy..."
az network firewall policy create -n "$azfw_policy_name" -g $rg --sku Standard -o none
azfw_policy_id=$(az network firewall policy show -n $azfw_policy_name -g $rg --query id -o tsv)
# Net rule for ICMP
az network firewall policy rule-collection-group create -n ruleset01 --policy-name $azfw_policy_name -g $rg --priority 2000 -o none
az network firewall policy rule-collection-group collection add-filter-collection --policy-name $azfw_policy_name --rule-collection-group-name ruleset01 -g $rg \
--name NetworkTraffic --collection-priority 2500 --action Allow --rule-name permitAll --rule-type NetworkRule --description "Permit all traffic" \
--destination-addresses '*' --destination-ports '*' --source-addresses '*' --ip-protocols 'Any' -o none
azfw_policy_id=$(az network firewall policy show -n $azfw_policy_name -g $rg --query id -o tsv)
# Hub1 AzFW
az network vnet subnet create -n AzureFirewallSubnet --address-prefix $hub1_azfw_subnet_prefix --vnet-name $hub1_vnet_name -g $rg -o none
hub1_azfw_name=azfw1
hub1_azfw_pip_name="${hub1_azfw_name}-pip"
echo "Creating Azure Firewall ${hub1_azfw_name}..."
az network public-ip create -g $rg -n $hub1_azfw_pip_name --sku Standard --allocation-method static -l $hub1_location -o none
hub1_azfw_ip=$(az network public-ip show -g $rg -n $hub1_azfw_pip_name --query ipAddress -o tsv)
az network firewall create -n $hub1_azfw_name -g $rg -l $hub1_location --policy $azfw_policy_id -o none
hub1_azfw_id=$(az network firewall show -n $hub1_azfw_name -g $rg -o tsv --query id)
az network firewall ip-config create -f $hub1_azfw_name -n "${hub1_azfw_name}-ipconfig" -g $rg --public-ip-address $hub1_azfw_pip_name --vnet-name $hub1_vnet_name -o none
az network firewall update -n $hub1_azfw_name -g $rg -o none
hub1_azfw_private_ip=$(az network firewall show -n $hub1_azfw_name -g $rg --query 'ipConfigurations[0].privateIpAddress' -o tsv)
# Logs
az monitor diagnostic-settings create -n mydiag --resource $hub1_azfw_id --workspace $hub1_logws_id \
--metrics '[{"category": "AllMetrics", "enabled": true, "retentionPolicy": {"days": 0, "enabled": false }, "timeGrain": null}]' \
--logs '[{"category": "AzureFirewallApplicationRule", "enabled": true, "retentionPolicy": {"days": 0, "enabled": false}},
{"category": "AzureFirewallNetworkRule", "enabled": true, "retentionPolicy": {"days": 0, "enabled": false}}]' >/dev/null
# Hub2 AzFW
if [[ "$hub_no" == "2" ]]
then
az network vnet subnet create -n AzureFirewallSubnet --address-prefix $hub2_azfw_subnet_prefix --vnet-name $hub2_vnet_name -g $rg -o none
hub2_azfw_name=azfw2
hub2_azfw_pip_name="${hub2_azfw_name}-pip"
echo "Creating Azure Firewall ${hub2_azfw_name}..."
az network public-ip create -g $rg -n $hub2_azfw_pip_name --sku Standard --allocation-method static -l $hub2_location -o none
hub2_azfw_ip=$(az network public-ip show -g $rg -n $hub2_azfw_pip_name --query ipAddress -o tsv)
az network firewall create -n $hub2_azfw_name -g $rg -l $hub2_location --policy $azfw_policy_id -o none
hub2_azfw_id=$(az network firewall show -n $hub2_azfw_name -g $rg -o tsv --query id)
az network firewall ip-config create -f $hub2_azfw_name -n "${hub2_azfw_name}-ipconfig" -g $rg --public-ip-address $hub2_azfw_pip_name --vnet-name $hub2_vnet_name -o none
az network firewall update -n $hub2_azfw_name -g $rg -o none
hub2_azfw_private_ip=$(az network firewall show -n $hub2_azfw_name -g $rg --query 'ipConfigurations[0].privateIpAddress' -o tsv)
# Logs
az monitor diagnostic-settings create -n mydiag --resource $hub2_azfw_id --workspace $hub2_logws_id \
--metrics '[{"category": "AllMetrics", "enabled": true, "retentionPolicy": {"days": 0, "enabled": false }, "timeGrain": null}]' \
--logs '[{"category": "AzureFirewallApplicationRule", "enabled": true, "retentionPolicy": {"days": 0, "enabled": false}},
{"category": "AzureFirewallNetworkRule", "enabled": true, "retentionPolicy": {"days": 0, "enabled": false}}]' >/dev/null
fi
fi
# Create NVA: Ubuntu VM with Bird and StrongSwan
if [[ "$nva_type" == "linux1nic" ]] || [[ "$nva_type" == "linux2nic" ]]
then
nva_size=Standard_B1s
publisher=Canonical
offer=UbuntuServer
sku=18.04-LTS
version=$(az vm image list -p $publisher -f $offer -s $sku --all --query '[0].version' -o tsv 2>/dev/null)
nva_cloudinit_file=/tmp/nva_cloudinit.txt
cat <<EOF > $nva_cloudinit_file
#cloud-config
runcmd:
- apt update
- UCF_FORCE_CONFOLD=1 DEBIAN_FRONTEND=noninteractive apt install -y bird strongswan
- sysctl -w net.ipv4.ip_forward=1
- sysctl -w net.ipv4.conf.all.accept_redirects=0
- sysctl -w net.ipv4.conf.all.send_redirects=0
EOF
# Hub1 NVA creation
hub1_nva_asn=65001
for nva_id in $(seq 1 $nva_no)
do
hub1_nva_name="hub1nva${nva_id}"
hub1_nva_pip="${hub1_nva_name}-pip"
# Option 1: 1-NIC NVA
echo "Creating NVA ${hub1_nva_name}..."
if [[ "$nva_type" == "linux1nic" ]]
then
az vm create -n $hub1_nva_name -g $rg -l $hub1_location --image ubuntuLTS --generate-ssh-keys \
--public-ip-address $hub1_nva_pip --public-ip-sku Standard --vnet-name $hub1_vnet_name --size $nva_size --subnet $hub1_nva_subnet_name \
--custom-data $nva_cloudinit_file --nsg $hub1_nsg_name -o none
hub1_nva_nic_id=$(az vm show -n $hub1_nva_name -g "$rg" --query 'networkProfile.networkInterfaces[0].id' -o tsv)
az network nic update --ids $hub1_nva_nic_id --ip-forwarding -o none
# Option 2: 2-NIC NVA
else
az network public-ip create -g $rg -n "$hub1_nva_pip" --allocation-method Static --sku Standard -l $hub1_location -o none
az network nic create -n "${hub1_nva_name}-nic0" -g $rg --vnet-name $hub1_vnet_name --subnet $hub1_nva_subnet_name \
--network-security-group "$hub1_nsg_name" --public-ip-address $hub1_nva_pip --ip-forwarding -l $hub1_location -o none
az network nic create -n "${hub1_nva_name}-nic1" -g $rg --vnet-name $hub1_vnet_name --subnet $hub1_nva_subnet2_name \
--network-security-group "$hub1_nsg_name" --ip-forwarding -l $hub1_location -o none
az vm create -n $hub1_nva_name -g $rg -l $hub1_location --image ubuntuLTS --generate-ssh-keys \
--size ${nva_size} --custom-data "$nva_cloudinit_file" --nics "${hub1_nva_name}-nic0" "${hub1_nva_name}-nic1" -o none
fi
# Get NVA data
echo "$hub1_nva_name info:"
hub1_nva_pip_ip=$(az network public-ip show -n $hub1_nva_pip -g $rg --query ipAddress -o tsv) && echo $hub1_nva_pip_ip
hub1_nva_private_ip=$(get_1st_private_ip $hub1_nva_name) && echo $hub1_nva_private_ip
hub1_nva_default_gw=$(first_ip "$hub1_nva_subnet_prefix") && echo $hub1_nva_default_gw
if [[ "$nva_type" == "linux2nic" ]]
then
hub1_nva_private_ip2=$(az network nic show -n "${hub1_nva_name}-nic1" -g $rg --query 'ipConfigurations[0].privateIpAddress' -o tsv) && echo $hub1_nva_private_ip2
hub1_nva_default_gw2=$(first_ip "$hub1_nva_subnet2_prefix") && echo $hub1_nva_default_gw2
fi
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub1_nva_pip_ip "ip a"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub1_nva_pip_ip "systemctl status bird"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub1_nva_pip_ip "sudo birdc show route"
done
# Internal LB in front of redundant NVAs
if [[ "$nva_no" == "2" ]]
then
nva_lb_name=hub1_nva
echo "Creating LB ${nva_lb_name}..."
az network lb create -n $nva_lb_name -g $rg -l $hub1_location --sku Standard --vnet-name $hub1_vnet_name --subnet $hub1_nva_subnet_name --frontend-ip-name nvafrontend --backend-pool-name nvas -o none
az network lb probe create -n nvaprobe --lb-name $nva_lb_name -g $rg --protocol tcp --port 22 -o none
az network lb rule create -n nvahaports --lb-name $nva_lb_name -g $rg --protocol All --frontend-port 0 --backend-port 0 --frontend-ip-name nvafrontend --backend-pool-name nvas --probe-name nvaprobe -o none
hub1_lb_ip=$(az network lb frontend-ip show -n nvafrontend --lb-name $nva_lb_name -g $rg --query privateIpAddress -o tsv)
for nva_id in $(seq 1 $nva_no)
do
hub1_nva_name="hub1nva${nva_id}"
hub1_nva_nic_id=$(az vm show -n $hub1_nva_name -g "$rg" --query 'networkProfile.networkInterfaces[0].id' -o tsv)
hub1_nva_nic_name=$(az network nic show --ids $hub1_nva_nic_id --query name -o tsv)
hub1_nva_ipconfig_name=$(az network nic show --ids $hub1_nva_nic_id --query 'ipConfigurations[0].name' -o tsv)
az network nic ip-config address-pool add --address-pool nvas --lb-name $nva_lb_name -g $rg --ip-config-name $hub1_nva_ipconfig_name --nic-name $hub1_nva_nic_name -o none
done
fi
# Hub2 NVA creation
if [[ "$hub_no" == "2" ]]
then
hub2_nva_asn=65002
for nva_id in $(seq 1 $nva_no)
do
hub2_nva_name="hub2nva${nva_id}"
hub2_nva_pip="${hub2_nva_name}-pip"
# Option 1: 1-NIC NVA
echo "Creating NVA ${hub2_nva_name}..."
if [[ "$nva_type" == "linux1nic" ]]
then
az vm create -n $hub2_nva_name -g $rg -l $hub2_location --image ubuntuLTS --generate-ssh-keys \
--public-ip-address $hub2_nva_pip --public-ip-sku Standard --vnet-name $hub2_vnet_name --size $nva_size --subnet $hub2_nva_subnet_name \
--custom-data $nva_cloudinit_file --nsg $hub2_nsg_name -o none
hub2_nva_nic_id=$(az vm show -n $hub2_nva_name -g "$rg" --query 'networkProfile.networkInterfaces[0].id' -o tsv)
az network nic update --ids $hub2_nva_nic_id --ip-forwarding -o none
# Option 2: 2-NIC NVA
else
az network public-ip create -g $rg -n "$hub2_nva_pip" --allocation-method Static --sku Standard -l $hub2_location -o none
az network nic create -n "${hub2_nva_name}-nic0" -g $rg --vnet-name $hub2_vnet_name --subnet $hub2_nva_subnet_name \
--network-security-group "$hub2_nsg_name" --public-ip-address $hub2_nva_pip --ip-forwarding -l $hub2_location -o none
az network nic create -n "${hub2_nva_name}-nic1" -g $rg --vnet-name $hub2_vnet_name --subnet $hub2_nva_subnet2_name \
--network-security-group "$hub2_nsg_name" --ip-forwarding -l $hub2_location -o none
az vm create -n $hub2_nva_name -g $rg -l $hub2_location --image ubuntuLTS --generate-ssh-keys \
--size ${nva_size} --custom-data "$nva_cloudinit_file" --nics "${hub2_nva_name}-nic0" "${hub2_nva_name}-nic1" -o none
fi
# Get NVA Data
echo "$hub2_nva_name info:"
hub2_nva_pip_ip=$(az network public-ip show -n $hub2_nva_pip -g $rg --query ipAddress -o tsv) && echo $hub2_nva_pip_ip
hub2_nva_private_ip=$(get_1st_private_ip $hub2_nva_name) && echo $hub2_nva_private_ip
hub2_nva_default_gw=$(first_ip "$hub2_nva_subnet_prefix") && echo $hub2_nva_default_gw
if [[ "$nva_type" == "linux2nic" ]]
then
hub2_nva_private_ip2=$(az network nic show -n "${hub2_nva_name}-nic1" -g $rg --query 'ipConfigurations[0].privateIpAddress' -o tsv) && echo $hub2_nva_private_ip2
hub2_nva_default_gw2=$(first_ip "$hub2_nva_subnet2_prefix") && echo $hub2_nva_default_gw2
fi
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub2_nva_pip_ip "ip a"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub2_nva_pip_ip "systemctl status bird"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub2_nva_pip_ip "sudo birdc show route"
done
# Internal LB in front of redundant NVAs
if [[ "$nva_no" == "2" ]]
then
nva_lb_name=hub2_nva
echo "Creating LB ${nva_lb_name}..."
az network lb create -n $nva_lb_name -g $rg -l $hub2_location --sku Standard --vnet-name $hub2_vnet_name --subnet $hub2_nva_subnet_name --frontend-ip-name nvafrontend --backend-pool-name nvas -o none
az network lb probe create -n nvaprobe --lb-name $nva_lb_name -g $rg --protocol tcp --port 22 -o none
az network lb rule create -n nvahaports --lb-name $nva_lb_name -g $rg --protocol All --frontend-port 0 --backend-port 0 --frontend-ip-name nvafrontend --backend-pool-name nvas --probe-name nvaprobe -o none
hub2_lb_ip=$(az network lb frontend-ip show -n nvafrontend --lb-name $nva_lb_name -g $rg --query privateIpAddress -o tsv)
for nva_id in $(seq 1 $nva_no)
do
hub2_nva_name="hub2nva${nva_id}"
hub2_nva_nic_id=$(az vm show -n $hub2_nva_name -g "$rg" --query 'networkProfile.networkInterfaces[0].id' -o tsv)
hub2_nva_nic_name=$(az network nic show --ids $hub2_nva_nic_id --query name -o tsv)
hub2_nva_ipconfig_name=$(az network nic show --ids $hub2_nva_nic_id --query 'ipConfigurations[0].name' -o tsv)
az network nic ip-config address-pool add --address-pool nvas --lb-name $nva_lb_name -g $rg --ip-config-name $hub2_nva_ipconfig_name --nic-name $hub2_nva_nic_name -o none
done
fi
fi
fi
# Create RTs and attach to NVA subnets, to potentially overwrite some of the routes
echo "Creating Route Tables for NVA subnets..."
# Hub1
hub1_nva_rt_name=hub1nva
az network route-table create -n $hub1_nva_rt_name -g $rg -l $hub1_location -o none
az network vnet subnet update -g $rg --vnet-name $hub1_vnet_name -n $hub1_nva_subnet_name --route-table $hub1_nva_rt_name -o none
# If multiple hubs and not using VXLAN, we need to overwrite the route for the remote hub on the local NVA subnet with next hop the remote ALB
if [[ "$hub_no" == "2" ]] && [[ "use_vxlan" == "no" ]]
then
echo "Adding route in hub1 NVA subnet for $hub2_spoke_summary and next hop $hub2_lb_ip..."
az network route-table route create --route-table-name $hub1_nva_rt_name -g $rg --address-prefix $hub2_spoke_summary -n hub2 --next-hop-type VirtualAppliance --next-hop-ip-address $hub2_lb_ip -o none
fi
# If using 2-NIC NVAs, we need to create RTs for the second NIC
if [[ "$nva_type" == "linux2nic" ]]
then
hub1_nva_rt2_name=hub1nva2
az network route-table create -n $hub1_nva_rt2_name -g $rg -l $hub1_location -o none
az network vnet subnet update -g $rg --vnet-name $hub1_vnet_name -n $hub1_nva_subnet2_name --route-table $hub1_nva_rt2_name -o none
# If using the 2nd NIC for the hub-to-hub traffic, we can disable BGP propagation
az network route-table update -n $hub1_nva_rt2_name -g $rg --disable-bgp-route-propagation true -o none
if [[ "$hub_no" == "2" ]] && [[ "use_vxlan" == "no" ]]
then
az network route-table route create --route-table-name $hub1_nva_rt2_name -g $rg --address-prefix $hub2_spoke_summary -n hub2 --next-hop-type VirtualAppliance --next-hop-ip-address $hub2_lb_ip -o none
fi
fi
# Hub2
if [[ "$hub_no" == "2" ]]
then
hub2_nva_rt_name=hub2nva
az network route-table create -n $hub2_nva_rt_name -g $rg -l $hub2_location -o none
az network vnet subnet update -g $rg --vnet-name $hub2_vnet_name -n $hub2_nva_subnet_name --route-table $hub2_nva_rt_name -o none
# If multiple hubs and not using VXLAN, we need to overwrite the route for the remote hub on the local NVA subnet with next hop the remote ALB
if [[ "use_vxlan" == "no" ]]
then
echo "Adding route in hub1 NVA subnet for $hub2_spoke_summary and next hop $hub2_lb_ip..."
az network route-table route create --route-table-name $hub2_nva_rt_name -g $rg --address-prefix $hub1_spoke_summary -n hub1 --next-hop-type VirtualAppliance --next-hop-ip-address $hub1_lb_ip -o none
fi
if [[ "$nva_type" == "linux2nic" ]]
then
hub2_nva_rt2_name=hub2nva2
az network route-table create -n $hub2_nva_rt2_name -g $rg -l $hub2_location -o none
az network vnet subnet update -g $rg --vnet-name $hub2_vnet_name -n $hub2_nva_subnet2_name --route-table $hub2_nva_rt2_name -o none
az network route-table update -n $hub2_nva_rt2_name -g $rg --disable-bgp-route-propagation true -o none
# If using the 2nd NIC for the hub-to-hub traffic, we can disable BGP propagation
az network route-table update -n $hub1_nva_rt2_name -g $rg --disable-bgp-route-propagation true -o none
if [[ "$hub_no" == "2" ]] && [[ "use_vxlan" == "no" ]]
then
az network route-table route create --route-table-name $hub2_nva_rt2_name -g $rg --address-prefix $hub1_spoke_summary -n hub1 --next-hop-type VirtualAppliance --next-hop-ip-address $hub1_nva_private_ip2 -o none
fi
fi
fi
# Optionally create route tables for the spokes
if [[ "$spoke_rts" == "yes" ]]; then
hub1_spokes_rt_name=spokes-hub1
hub2_spokes_rt_name=spokes-hub2
# Hub1
if [[ "$next_hop" == "lb" ]]
then
local_hub_prefix_next_hop=$hub1_lb_ip
elif [[ "$next_hop" == "azfw" ]]
then
local_hub_prefix_next_hop=$hub1_azfw_private_ip
else
hub1_nva_name=hub1nva1
hub1_nva_private_ip=$(get_1st_private_ip $hub1_nva_name)
local_hub_prefix_next_hop=$hub1_nva_private_ip
fi
az network route-table create -n $hub1_spokes_rt_name -g $rg -l $hub1_location --disable-bgp-route-propagation true -o none
az network vnet subnet update -n vm --vnet-name $spoke11_vnet_name -g $rg --route-table $hub1_spokes_rt_name -o none
az network vnet subnet update -n vm --vnet-name $spoke12_vnet_name -g $rg --route-table $hub1_spokes_rt_name -o none
az network route-table route create --route-table-name $hub1_spokes_rt_name -g $rg -n default --address-prefix "0.0.0.0/0" --next-hop-type VirtualAppliance --next-hop-ip-address $local_hub_prefix_next_hop -o none
# Hub2
if [[ "$hub_no" == "2" ]]; then
if [[ "$next_hop" == "lb" ]]
then
local_hub_prefix_next_hop=$hub2_lb_ip
elif [[ "$next_hop" == "azfw" ]]
then
local_hub_prefix_next_hop=$hub2_azfw_private_ip
else
hub2_nva_name=hub2nva1
hub2_nva_private_ip=$(get_1st_private_ip $hub2_nva_name)
local_hub_prefix_next_hop=$hub2_nva_private_ip
fi
az network route-table create -n $hub2_spokes_rt_name -g $rg -l $hub2_location --disable-bgp-route-propagation true -o none
az network vnet subnet update -n vm --vnet-name $spoke21_vnet_name -g $rg --route-table $hub2_spokes_rt_name -o none
az network vnet subnet update -n vm --vnet-name $spoke22_vnet_name -g $rg --route-table $hub2_spokes_rt_name -o none
az network route-table route create --route-table-name $hub2_spokes_rt_name -g $rg -n default --address-prefix "0.0.0.0/0" --next-hop-type VirtualAppliance --next-hop-ip-address $local_hub_prefix_next_hop -o none
fi
fi
# Create VXLAN tunnels between Linux NVAs in both hubs and configure static routing
if [[ "$hub_no" == "2" ]] && [[ "$nva_type" == "linux1nic" || "$nva_type" == "linux2nic" ]]
then
if [[ "$use_vxlan" == "yes" ]]
then
if [[ "$nva_type" == "linux1nic" ]]
then
# IF using VXLAN and single-NIC Linux
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub1_nva_pip_ip "sudo ip link add vxlan0 type vxlan id 1 remote $hub2_nva_private_ip dstport 4789 dev eth0"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub1_nva_pip_ip "sudo ip link set vxlan0 up"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub1_nva_pip_ip "sudo ip addr add ${hub1_nva_overlay_ip}/30 dev vxlan0"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub1_nva_pip_ip "sudo ip route add $hub2_nva_private_ip/32 via $hub1_nva_default_gw"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub1_nva_pip_ip "sudo ifconfig eth0 mtu 1600"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub2_nva_pip_ip "sudo ip link add vxlan0 type vxlan id 1 remote $hub1_nva_private_ip dstport 4789 dev eth0"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub2_nva_pip_ip "sudo ip link set vxlan0 up"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub2_nva_pip_ip "sudo ip addr add ${hub2_nva_overlay_ip}/30 dev vxlan0"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub2_nva_pip_ip "sudo ip route add $hub1_nva_private_ip/32 via $hub2_nva_default_gw"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub2_nva_pip_ip "sudo ifconfig eth0 mtu 1600"
else
# If not usig VXLAN tunnels but 2ary NICs, create routes to the 2ary NIC
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub1_nva_pip_ip "sudo ip route add $hub2_nva_private_ip2/32 via $hub1_nva_default_gw2"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub2_nva_pip_ip "sudo ip route add $hub1_nva_private_ip2/32 via $hub2_nva_default_gw2"
fi
else
# If not using VXLAN
# Static routes so that the learnt BGP routes for the remote hub do not create routing loops
echo "Setting static routes in the Linux NVAs..."
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $(get_pip hub1nva1) "sudo ip route add $(get_1st_private_ip hub2nva1)/32 via $hub1_nva_default_gw"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $(get_pip hub1nva1) "sudo ip route add ${hub2_lb_ip}/32 via $hub1_nva_default_gw"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $(get_pip hub2nva1) "sudo ip route add $(get_1st_private_ip hub1nva1)/32 via $hub2_nva_default_gw"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $(get_pip hub2nva1) "sudo ip route add ${hub1_lb_ip}/32 via $hub2_nva_default_gw"
if [[ "$nva_no" == "2" ]]
then
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $(get_pip hub1nva1) "sudo ip route add $(get_1st_private_ip hub2nva2)/32 via $hub1_nva_default_gw"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $(get_pip hub1nva2) "sudo ip route add $(get_1st_private_ip hub2nva1)/32 via $hub1_nva_default_gw"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $(get_pip hub1nva2) "sudo ip route add $(get_1st_private_ip hub2nva2)/32 via $hub1_nva_default_gw"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $(get_pip hub1nva2) "sudo ip route add ${hub2_lb_ip}/32 via $hub1_nva_default_gw"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $(get_pip hub2nva1) "sudo ip route add $(get_1st_private_ip hub1nva2)/32 via $hub2_nva_default_gw"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $(get_pip hub2nva2) "sudo ip route add $(get_1st_private_ip hub1nva1)/32 via $hub2_nva_default_gw"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $(get_pip hub2nva2) "sudo ip route add $(get_1st_private_ip hub1nva2)/32 via $hub2_nva_default_gw"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $(get_pip hub2nva2) "sudo ip route add ${hub1_lb_ip}/32 via $hub2_nva_default_gw"
fi
fi
fi
# RS adjacencies
for nva_id in $(seq 1 $nva_no)
do
hub1_nva_name="hub1nva${nva_id}"
hub1_nva_private_ip=$(get_1st_private_ip $hub1_nva_name)
echo "Creating ARS peering between ${hub1_rs_name} and ${hub1_nva_name}..."
az network routeserver peering create --routeserver $hub1_rs_name -g $rg --peer-ip $hub1_nva_private_ip --peer-asn $hub1_nva_asn -n $hub1_nva_name -o none
if [[ "$hub_no" == "2" ]]
then
hub2_nva_name="hub2nva${nva_id}"
hub2_nva_private_ip=$(get_1st_private_ip $hub2_nva_name)
echo "Creating ARS peering between ${hub2_rs_name} and ${hub2_nva_name}..."
az network routeserver peering create --routeserver $hub2_rs_name -g $rg --peer-ip $hub2_nva_private_ip --peer-asn $hub2_nva_asn -n $hub2_nva_name -o none
fi
done
# Configure NVAs iptables firewall
for hub_id in $(seq 1 $hub_no)
do
for nva_id in $(seq 1 $nva_no)
do
nva_name="hub${hub_id}nva${nva_id}"
nva_pip=$(get_pip $nva_name)
if [[ -z "$nva_pip" ]]
then
echo "Not able to get public IP address for VM ${nva_name}"
else
echo "Configuring iptables in NVA ${nva_name} (${nva_pip})..."
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $nva_pip "sudo iptables -P FORWARD DROP"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $nva_pip "sudo iptables -A FORWARD -m conntrack --ctstate INVALID -j DROP"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $nva_pip "sudo iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $nva_pip "sudo iptables -A FORWARD -p tcp --syn --dport 22 -m conntrack --ctstate NEW -j ACCEPT"
fi
done
done
# BGP config with 1 hub
if [[ "$hub_no" == "1" ]]
then
for nva_id in $(seq 1 $nva_no)
do
# Get NVA Data
hub1_nva_name="hub1nva${nva_id}"
hub1_nva_pip="${hub1_nva_name}-pip"
echo "Getting $hub1_nva_name info..."
hub1_nva_pip_ip=$(az network public-ip show -n $hub1_nva_pip -g $rg --query ipAddress -o tsv)
hub1_nva_private_ip=$(get_1st_private_ip $hub1_nva_name)
hub1_nva_default_gw=$(first_ip "$hub1_nva_subnet_prefix")
if [[ "$nva_type" == "linux2nic" ]]
then
hub1_nva_private_ip2=$(az network nic show -n "${hub1_nva_name}-nic1" -g $rg --query 'ipConfigurations[0].privateIpAddress' -o tsv)
hub1_nva_default_gw2=$(first_ip "$hub1_nva_subnet2_prefix")
fi
# BGP next hop for the local hub prefix
if [[ "$next_hop" == "lb" ]]
then
local_hub_prefix_next_hop=$hub1_lb_ip
elif [[ "$next_hop" == "azfw" ]]
then
local_hub_prefix_next_hop=$hub1_azfw_private_ip
else
local_hub_prefix_next_hop=$hub1_nva_private_ip
fi
# bird.conf for hub1
bird_config_file=/tmp/bird.conf
cat <<EOF > $bird_config_file
log syslog all;
router id $hub1_nva_private_ip;
protocol device {
scan time 10;
}
protocol direct {
disabled;
}
protocol kernel {
export where source != RTS_STATIC;
}
protocol static {
route $hub1_rs_ip1/32 via $hub1_nva_default_gw;
route $hub1_rs_ip2/32 via $hub1_nva_default_gw;
route 1${nva_id}.1${nva_id}.1${nva_id}.1${nva_id}/32 via $hub1_nva_default_gw; # Test route
# route $hub2_nva_overlay_ip/32 via "vxlan0";
$([[ "$nva_type" == "linux2nic" && "$hub_no" == "2" ]] && echo "route $hub2_nva_private_ip2/32 via $hub1_nva_default_gw2;" || echo "")
route $hub1_spoke_summary via $hub1_nva_default_gw;
}
template bgp PEERS {
local as $hub1_nva_asn;
multihop;
}
filter TO_RS {
# Accept test route
if (net = 1${nva_id}.1${nva_id}.1${nva_id}.1${nva_id}/32) then { accept; }
# Drop other long prefixes (see /32 in static routes)
if ( net ~ [ 0.0.0.0/0{30,32} ] ) then { reject; }
# Optionally set next hop for hub prefix as the LB
if (net = $hub1_spoke_summary) then
{
bgp_next_hop = $local_hub_prefix_next_hop;
accept;
}
# Accept everything else
else {
bgp_path.delete(65515); # In case routes from a VNG arrive here
accept;
}
}
protocol bgp rs0 from PEERS {
description "RouteServer instance 0";
neighbor $hub1_rs_ip1 as $hub1_rs_asn;
import all;
export filter TO_RS;
}
protocol bgp rs1 from PEERS {
description "RouteServer instance 1";
neighbor $hub1_rs_ip2 as $hub1_rs_asn;
import all;
export filter TO_RS;
}
EOF
hub1_nva_user=$(ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub1_nva_pip_ip "whoami")
echo "Uploading BIRD config file to ${hub1_nva_name}..."
scp $bird_config_file "${hub1_nva_pip_ip}:/home/${hub1_nva_user}/bird.conf"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub1_nva_pip_ip "sudo mv /home/${hub1_nva_user}/bird.conf /etc/bird/bird.conf"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub1_nva_pip_ip "sudo systemctl restart bird"
done
# BGP config with 2 hubs
else
# With 2 hubs each NVA needs to talk to each other
# This 2-hub use case still needs to be modified for 2 NVAs/hub
# Hub1 NVA bird config file
for nva_id in $(seq 1 $nva_no)
do
# Get NVA Data
hub1_nva_name="hub1nva${nva_id}"
hub1_nva_pip="${hub1_nva_name}-pip"
echo "Getting $hub1_nva_name info..."
hub1_nva_pip_ip=$(az network public-ip show -n $hub1_nva_pip -g $rg --query ipAddress -o tsv)
hub1_nva_private_ip=$(get_1st_private_ip $hub1_nva_name)
hub1_nva_default_gw=$(first_ip "$hub1_nva_subnet_prefix")
if [[ "$nva_type" == "linux2nic" ]]
then
hub1_nva_private_ip2=$(az network nic show -n "${hub1_nva_name}-nic1" -g $rg --query 'ipConfigurations[0].privateIpAddress' -o tsv)
hub1_nva_default_gw2=$(first_ip "$hub1_nva_subnet2_prefix")
fi
# BGP next hop for the local hub prefix
if [[ "$next_hop" == "lb" ]]
then
local_hub_prefix_next_hop=$hub1_lb_ip
elif [[ "$next_hop" == "azfw" ]]
then
local_hub_prefix_next_hop=$hub1_azfw_private_ip
else
local_hub_prefix_next_hop=$hub1_nva_private_ip
fi
# bird.conf for hub1
bird_config_file=/tmp/bird.conf
cat <<EOF > $bird_config_file
log syslog all;
router id $hub1_nva_private_ip;
protocol device {
scan time 10;
}
protocol direct {
disabled;
}
protocol kernel {
export where source != RTS_STATIC;
}
protocol static {
route $hub1_rs_ip1/32 via $hub1_nva_default_gw;
route $hub1_rs_ip2/32 via $hub1_nva_default_gw;
$([[ "$nva_no" == "2" ]] && echo "route $hub2_lb_ip/32 via $hub1_nva_default_gw;" || echo "")
route $(get_1st_private_ip hub2nva1)/32 via $hub1_nva_default_gw;
$([[ "$nva_no" == "2" ]] && echo "route $(get_1st_private_ip hub2nva2)/32 via $hub1_nva_default_gw;" || echo "")
route 1${nva_id}.1${nva_id}.1${nva_id}.1${nva_id}/32 via $hub1_nva_default_gw; # Test route
$([[ "$use_vxlan" == "yes" && "$hub_no" == "2" ]] && echo "route $hub2_nva_overlay_ip/32 via \"vxlan0\";" || echo "")
$([[ "$nva_type" == "linux2nic" && "$hub_no" == "2" ]] && echo "route $hub2_nva_private_ip2/32 via $hub1_nva_default_gw2;" || echo "")
route $hub1_spoke_summary via $hub1_nva_default_gw;
}
template bgp PEERS {
local as $hub1_nva_asn;
multihop;
}
filter TO_RS {
# Accept test routes
if (net = 11.11.11.11/32) then { accept; }
if (net = 12.12.12.12/32) then { accept; }
if (net = 21.21.21.21/32) then { accept; }
if (net = 22.22.22.22/32) then { accept; }
# Drop other long prefixes (see /32 in static routes)
if ( net ~ [ 0.0.0.0/0{30,32} ] ) then { reject; }
# Optionally set next hop for local/remote hub prefixes as the LB
if (net = $hub1_spoke_summary) then
{
bgp_next_hop = $local_hub_prefix_next_hop;
accept;
}
if (net = $hub2_spoke_summary) then
{
bgp_next_hop = $local_hub_prefix_next_hop;
accept;
}
# Accept everything else
else {
bgp_path.delete(65515); # In case routes from a VNG arrive here
bgp_next_hop = $local_hub_prefix_next_hop;
accept;
}
}
filter TO_NVA {
# Accept test routes
if (net = 11.11.11.11/32) then { accept; }
if (net = 12.12.12.12/32) then { accept; }
if (net = 21.21.21.21/32) then { accept; }
if (net = 22.22.22.22/32) then { accept; }
# Drop other long prefixes (see /32 in static routes)
if ( net ~ [ 0.0.0.0/0{30,32} ] ) then { reject; }
# Drop prefixes originated by the local ARS (advertise only the self-generated summary)
if ( bgp_path ~ [= $hub1_nva_asn 65515 =] ) then { reject; }
# Accept everything else
else {
bgp_next_hop = $local_hub_prefix_next_hop;
accept;
}
}
protocol bgp rs0 from PEERS {
description "RouteServer instance 0";
neighbor $hub1_rs_ip1 as $hub1_rs_asn;
import all;
export filter TO_RS;
}
protocol bgp rs1 from PEERS {
description "RouteServer instance 1";
neighbor $hub1_rs_ip2 as $hub1_rs_asn;
import all;
export filter TO_RS;
}
protocol bgp hub2nva1 from PEERS {
description "Hub 2 NVA1";
$([[ "$use_vxlan" == "yes" && "$hub_no" == "2" ]] && echo "neighbor $hub2_nva_overlay_ip as $hub2_nva_asn;" || echo "")
$([[ "$use_vxlan" == "no" && "$hub_no" == "2" && "$nva_type" == "linux2nic" ]] && echo "neighbor $hub2_nva_private_ip2 as $hub2_nva_asn;" || echo "")
$([[ "$use_vxlan" == "no" && "$hub_no" == "2" && "$nva_type" == "linux1nic" ]] && echo "neighbor $(get_1st_private_ip hub2nva1) as $hub2_nva_asn;" || echo "")
import all;
export filter TO_NVA;
}
protocol bgp hub2nva2 from PEERS {
description "Hub 2 NVA2";
$([[ "$nva_no" == "1" ]] && echo "disabled;" || echo "# disabled")
$([[ "$use_vxlan" == "yes" && "$hub_no" == "2" ]] && echo "neighbor $hub2_nva_overlay_ip as $hub2_nva_asn;" || echo "")
$([[ "$use_vxlan" == "no" && "$hub_no" == "2" && "$nva_type" == "linux1nic" && "$nva_no" == "2" ]] && echo "neighbor $(get_1st_private_ip hub2nva2) as $hub2_nva_asn;" || echo "")
$([[ "$use_vxlan" == "no" && "$hub_no" == "2" && "$nva_type" == "linux1nic" && "$nva_no" == "1" ]] && echo "neighbor 1.2.3.4 as $hub2_nva_asn;" || echo "")
import all;
export filter TO_NVA;
}
EOF
hub1_nva_user=$(ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub1_nva_pip_ip "whoami")
echo "Uploading BIRD config file to ${hub1_nva_name}..."
scp $bird_config_file "${hub1_nva_pip_ip}:/home/${hub1_nva_user}/bird.conf"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub1_nva_pip_ip "sudo mv /home/${hub1_nva_user}/bird.conf /etc/bird/bird.conf"
ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $hub1_nva_pip_ip "sudo systemctl restart bird"
done
# hub2
for nva_id in $(seq 1 $nva_no)
do
# Get NVA Data
hub2_nva_name="hub2nva${nva_id}"
hub2_nva_pip="${hub2_nva_name}-pip"
echo "Getting $hub2_nva_name info..."
hub2_nva_pip_ip=$(az network public-ip show -n $hub2_nva_pip -g $rg --query ipAddress -o tsv)
hub2_nva_private_ip=$(get_1st_private_ip $hub2_nva_name)
hub2_nva_default_gw=$(first_ip "$hub2_nva_subnet_prefix")
if [[ "$nva_type" == "linux2nic" ]]
then
hub2_nva_private_ip2=$(az network nic show -n "${hub2_nva_name}-nic1" -g $rg --query 'ipConfigurations[0].privateIpAddress' -o tsv)
hub2_nva_default_gw2=$(first_ip "$hub2_nva_subnet2_prefix")
fi
# BGP next hop for the local hub prefix
if [[ "$next_hop" == "lb" ]]
then
local_hub_prefix_next_hop=$hub2_lb_ip
elif [[ "$next_hop" == "azfw" ]]
then
local_hub_prefix_next_hop=$hub2_azfw_private_ip
else
local_hub_prefix_next_hop=$hub2_nva_private_ip
fi
# bird.conf for hub2
bird_config_file=/tmp/bird.conf
cat <<EOF > $bird_config_file
log syslog all;
router id $hub2_nva_private_ip;
protocol device {