@@ -643,3 +643,196 @@ func (vcd *TestVCD) Test_NsxtEdgeSlaacProfile(check *C) {
643
643
check .Assert (err , IsNil )
644
644
check .Assert (updatedSlaacProfile , NotNil )
645
645
}
646
+
647
+ // Test_NsxtEdgeCreateWithT0AndExternalNetworks checks that IP Allocation counts and External
648
+ // Network attachment works well with NSX-T T0 Gateway backed external network
649
+ func (vcd * TestVCD ) Test_NsxtEdgeCreateWithT0AndExternalNetworks (check * C ) {
650
+ test_NsxtEdgeCreateWithExternalNetworks (vcd , check , vcd .config .VCD .Nsxt .Tier0router , types .ExternalNetworkBackingTypeNsxtTier0Router )
651
+ }
652
+
653
+ // Test_NsxtEdgeCreateWithT0VrfAndExternalNetworks checks that IP Allocation counts and External
654
+ // Network attachment works well with NSX-T T0 VRF Gateway backed external network
655
+ func (vcd * TestVCD ) Test_NsxtEdgeCreateWithT0VrfAndExternalNetworks (check * C ) {
656
+ test_NsxtEdgeCreateWithExternalNetworks (vcd , check , vcd .config .VCD .Nsxt .Tier0routerVrf , types .ExternalNetworkBackingTypeNsxtVrfTier0Router )
657
+ }
658
+
659
+ func test_NsxtEdgeCreateWithExternalNetworks (vcd * TestVCD , check * C , backingRouter , backingRouterType string ) {
660
+ if vcd .client .Client .APIVCDMaxVersionIs ("< 37.1" ) {
661
+ check .Skip ("Segment Backed External Network uplinks are supported in VCD 10.4.1+" )
662
+ }
663
+ skipNoNsxtConfiguration (vcd , check )
664
+ skipOpenApiEndpointTest (vcd , check , types .OpenApiPathVersion1_0_0 + types .OpenApiEndpointEdgeGateways )
665
+ vcd .skipIfNotSysAdmin (check )
666
+
667
+ adminOrg , err := vcd .client .GetAdminOrgByName (vcd .config .VCD .Org )
668
+ check .Assert (err , IsNil )
669
+ check .Assert (adminOrg , NotNil )
670
+
671
+ nsxtVdc , err := adminOrg .GetVDCByName (vcd .config .VCD .Nsxt .Vdc , false )
672
+ if ContainsNotFound (err ) {
673
+ check .Skip (fmt .Sprintf ("No NSX-T VDC (%s) found - skipping test" , vcd .config .VCD .Nsxt .Vdc ))
674
+ }
675
+ check .Assert (err , IsNil )
676
+ check .Assert (nsxtVdc , NotNil )
677
+
678
+ // Setup 2 NSX-T Segment backed External Networks and 1 T0 or T0 VRF backed networks
679
+ nsxtManager , err := vcd .client .QueryNsxtManagerByName (vcd .config .VCD .Nsxt .Manager )
680
+ check .Assert (err , IsNil )
681
+ nsxtManagerId , err := BuildUrnWithUuid ("urn:vcloud:nsxtmanager:" , extractUuid (nsxtManager [0 ].HREF ))
682
+ check .Assert (err , IsNil )
683
+
684
+ // T0 backed external network
685
+ backingExtNet := getBackingIdByNameAndType (check , backingRouter , backingRouterType , vcd , nsxtManagerId )
686
+ nsxtExternalNetworkCfg := t0vrfBackedExternalNetworkConfig (vcd , check .TestName ()+ "-t0" , "89.1.1" , backingRouterType , backingExtNet , nsxtManagerId )
687
+ nsxtExternalNetwork , err := CreateExternalNetworkV2 (vcd .client , nsxtExternalNetworkCfg )
688
+ check .Assert (err , IsNil )
689
+ check .Assert (nsxtExternalNetwork , NotNil )
690
+ openApiEndpoint := types .OpenApiPathVersion1_0_0 + types .OpenApiEndpointExternalNetworks + nsxtExternalNetwork .ExternalNetwork .ID
691
+ AddToCleanupListOpenApi (nsxtExternalNetwork .ExternalNetwork .Name , check .TestName (), openApiEndpoint )
692
+
693
+ // First NSX-T Segment backed network
694
+ backingId1 := getBackingIdByNameAndType (check , vcd .config .VCD .Nsxt .NsxtImportSegment , types .ExternalNetworkBackingTypeNsxtSegment , vcd , nsxtManagerId )
695
+ segmentBackedNet1Cfg := t0vrfBackedExternalNetworkConfig (vcd , check .TestName ()+ "-1" , "1.1.1" , types .ExternalNetworkBackingTypeNsxtSegment , backingId1 , nsxtManagerId )
696
+ segmentBackedNet1 , err := CreateExternalNetworkV2 (vcd .client , segmentBackedNet1Cfg )
697
+ check .Assert (err , IsNil )
698
+ check .Assert (segmentBackedNet1 , NotNil )
699
+ openApiEndpoint = types .OpenApiPathVersion1_0_0 + types .OpenApiEndpointExternalNetworks + segmentBackedNet1 .ExternalNetwork .ID
700
+ AddToCleanupListOpenApi (segmentBackedNet1 .ExternalNetwork .Name , check .TestName (), openApiEndpoint )
701
+
702
+ // Second NSX-T Segment backed network
703
+ backingId2 := getBackingIdByNameAndType (check , vcd .config .VCD .Nsxt .NsxtImportSegment2 , types .ExternalNetworkBackingTypeNsxtSegment , vcd , nsxtManagerId )
704
+ segmentBackedNet2Cfg := t0vrfBackedExternalNetworkConfig (vcd , check .TestName ()+ "-2" , "4.4.4" , types .ExternalNetworkBackingTypeNsxtSegment , backingId2 , nsxtManagerId )
705
+ segmentBackedNet2 , err := CreateExternalNetworkV2 (vcd .client , segmentBackedNet2Cfg )
706
+ check .Assert (err , IsNil )
707
+ check .Assert (segmentBackedNet2 , NotNil )
708
+ openApiEndpoint = types .OpenApiPathVersion1_0_0 + types .OpenApiEndpointExternalNetworks + segmentBackedNet2 .ExternalNetwork .ID
709
+ AddToCleanupListOpenApi (segmentBackedNet1 .ExternalNetwork .Name , check .TestName (), openApiEndpoint )
710
+ // Setup 2 NSX-T Segment backed External Networks and 1 T0 or T0 VRF backed networks
711
+
712
+ egwDefinition := & types.OpenAPIEdgeGateway {
713
+ Name : "nsx-t-edge" ,
714
+ Description : "nsx-t-edge-description" ,
715
+ OrgVdc : & types.OpenApiReference {
716
+ ID : nsxtVdc .Vdc .ID ,
717
+ },
718
+ EdgeGatewayUplinks : []types.EdgeGatewayUplinks {
719
+ {
720
+ UplinkID : nsxtExternalNetwork .ExternalNetwork .ID ,
721
+ Subnets : types.OpenAPIEdgeGatewaySubnets {Values : []types.OpenAPIEdgeGatewaySubnetValue {{
722
+ Gateway : "5.1.1.1" ,
723
+ PrefixLength : 24 ,
724
+ Enabled : true ,
725
+ }}},
726
+ Connected : true ,
727
+ Dedicated : false ,
728
+ },
729
+ {
730
+ UplinkID : segmentBackedNet1 .ExternalNetwork .ID ,
731
+ Subnets : types.OpenAPIEdgeGatewaySubnets {Values : []types.OpenAPIEdgeGatewaySubnetValue {{
732
+ Gateway : "1.1.1.1" ,
733
+ PrefixLength : 24 ,
734
+ Enabled : true ,
735
+ AutoAllocateIPRanges : true ,
736
+ PrimaryIP : "1.1.1.5" ,
737
+ TotalIPCount : addrOf (4 ),
738
+ }}},
739
+ Connected : true ,
740
+ Dedicated : false ,
741
+ },
742
+ {
743
+ UplinkID : segmentBackedNet2 .ExternalNetwork .ID ,
744
+ Subnets : types.OpenAPIEdgeGatewaySubnets {Values : []types.OpenAPIEdgeGatewaySubnetValue {{
745
+ Gateway : "4.4.4.1" ,
746
+ PrefixLength : 24 ,
747
+ Enabled : true ,
748
+ AutoAllocateIPRanges : true ,
749
+ TotalIPCount : addrOf (7 ),
750
+ }}},
751
+ Connected : true ,
752
+ Dedicated : false ,
753
+ },
754
+ },
755
+ }
756
+
757
+ createdEdge , err := adminOrg .CreateNsxtEdgeGateway (egwDefinition )
758
+ check .Assert (err , IsNil )
759
+ check .Assert (createdEdge .EdgeGateway .Name , Equals , egwDefinition .Name )
760
+ openApiEndpoint = types .OpenApiPathVersion1_0_0 + types .OpenApiEndpointEdgeGateways + createdEdge .EdgeGateway .ID
761
+ PrependToCleanupListOpenApi (createdEdge .EdgeGateway .Name , check .TestName (), openApiEndpoint )
762
+ // check.Assert(*createdEdge.EdgeGateway.EdgeGatewayUplinks[0].BackingType, Equals, types.ExternalNetworkBackingTypeNsxtTier0Router)
763
+
764
+ // Retrieve edge gateway
765
+ retrievedEdge , err := adminOrg .GetNsxtEdgeGatewayById (createdEdge .EdgeGateway .ID )
766
+ check .Assert (err , IsNil )
767
+ check .Assert (retrievedEdge , NotNil )
768
+ // check.Assert(*retrievedEdge.EdgeGateway.EdgeGatewayUplinks[0].BackingType, Equals, types.ExternalNetworkBackingTypeNsxtTier0Router)
769
+
770
+ // Check IP allocation in NSX-T Segment backed networks
771
+ totalAllocatedIpCountSegmentBacked , err := retrievedEdge .GetAllocatedIpCountByUplinkType (false , types .ExternalNetworkBackingTypeNsxtSegment )
772
+ check .Assert (err , IsNil )
773
+ check .Assert (totalAllocatedIpCountSegmentBacked , Equals , (4 + 7 ))
774
+
775
+ // Check IP allocation in NSX-T T0 backed networks
776
+ totalAllocatedIpCountT0backed , err := retrievedEdge .GetAllocatedIpCountByUplinkType (false , backingRouterType )
777
+ check .Assert (err , IsNil )
778
+ check .Assert (totalAllocatedIpCountT0backed , Equals , 1 )
779
+
780
+ // Check IP allocation for all subnets
781
+ totalAllocatedIpCount , err := retrievedEdge .GetAllocatedIpCount (false )
782
+ check .Assert (err , IsNil )
783
+ check .Assert (totalAllocatedIpCount , Equals , (1 + 4 + 7 ))
784
+
785
+ createdEdge .EdgeGateway .Name = check .TestName () + "-renamed-edge"
786
+ updatedEdge , err := createdEdge .Update (createdEdge .EdgeGateway )
787
+ check .Assert (err , IsNil )
788
+ check .Assert (updatedEdge .EdgeGateway .Name , Equals , createdEdge .EdgeGateway .Name )
789
+
790
+ // Check IP allocation in NSX-T Segment backed networks
791
+ totalAllocatedIpCountSegmentBacked , err = updatedEdge .GetAllocatedIpCountByUplinkType (false , types .ExternalNetworkBackingTypeNsxtSegment )
792
+ check .Assert (err , IsNil )
793
+ check .Assert (totalAllocatedIpCountSegmentBacked , Equals , (4 + 7 ))
794
+
795
+ // Check IP allocation in NSX-T T0 backed networks
796
+ totalAllocatedIpCountT0backed , err = updatedEdge .GetAllocatedIpCountByUplinkType (false , backingRouterType )
797
+ check .Assert (err , IsNil )
798
+ check .Assert (totalAllocatedIpCountT0backed , Equals , 1 )
799
+
800
+ // Check IP allocation for all subnets
801
+ totalAllocatedIpCount , err = updatedEdge .GetAllocatedIpCount (false )
802
+ check .Assert (err , IsNil )
803
+ check .Assert (totalAllocatedIpCount , Equals , (1 + 4 + 7 ))
804
+
805
+ // Cleanup
806
+ err = updatedEdge .Delete ()
807
+ check .Assert (err , IsNil )
808
+ }
809
+
810
+ func t0vrfBackedExternalNetworkConfig (vcd * TestVCD , name , ipPrefix string , backingType , backingId , NetworkProviderId string ) * types.ExternalNetworkV2 {
811
+ net := & types.ExternalNetworkV2 {
812
+ Name : name ,
813
+ Subnets : types.ExternalNetworkV2Subnets {Values : []types.ExternalNetworkV2Subnet {
814
+ {
815
+ Gateway : ipPrefix + ".1" ,
816
+ PrefixLength : 24 ,
817
+ IPRanges : types.ExternalNetworkV2IPRanges {Values : []types.ExternalNetworkV2IPRange {
818
+ {
819
+ StartAddress : ipPrefix + ".3" ,
820
+ EndAddress : ipPrefix + ".50" ,
821
+ },
822
+ }},
823
+ Enabled : true ,
824
+ },
825
+ }},
826
+ NetworkBackings : types.ExternalNetworkV2Backings {Values : []types.ExternalNetworkV2Backing {
827
+ {
828
+ BackingID : backingId ,
829
+ NetworkProvider : types.NetworkProvider {
830
+ ID : NetworkProviderId ,
831
+ },
832
+ BackingTypeValue : backingType ,
833
+ },
834
+ }},
835
+ }
836
+
837
+ return net
838
+ }
0 commit comments