/// <summary>
        /// The create exchange peering.
        /// </summary>
        /// <param name="asn">
        /// The asn.
        /// </param>
        /// <returns>
        /// The <see cref="PeeringModel"/>.
        /// </returns>
        private PeeringModel CreateExchangePeeringModel(int asn = 65000)
        {
            // create resource group
            var resourceGroup = this.CreateResourceGroup();

            // Create Asn
            var subId = this.CreatePeerAsn(asn, $"AS{asn}", isApproved: true);

            // Create Exchange Peering
            var ipAddress          = int.Parse(MockServer.GetVariable("ipAddress", this.random.Next(150, 190).ToString()));
            var exchangeConnection = new ExchangeConnection
            {
                ConnectionIdentifier = Guid.NewGuid().ToString(),
                PeeringDBFacilityId  = 99999,
                BgpSession           = new Microsoft.Azure.Management.Peering.Models.BgpSession()
                {
                    PeerSessionIPv4Address  = $"10.12.97.{ipAddress}",
                    MaxPrefixesAdvertisedV4 = 20000
                }
            };
            SubResource asnReference = new SubResource(subId);
            var         exchangePeeringProperties = new PeeringPropertiesExchange(
                new List <ExchangeConnection>(),
                asnReference);

            exchangePeeringProperties.Connections.Add(exchangeConnection);
            var peeringModel = new PeeringModel
            {
                PeeringLocation = "Seattle",
                Sku             = new PeeringSku("Basic_Exchange_Free"),
                Location        = "centralus",
                Exchange        = exchangePeeringProperties,
                Kind            = "Exchange",
                Tags            = new Dictionary <string, string>
                {
                    { TestUtilities.GenerateName("tfs_"), "Active" }
                }
            };
            var name = $"exchangepeering{asn}";

            try
            {
                var result  = this.Client.Peerings.CreateOrUpdate(resourceGroup.Name, name, peeringModel);
                var peering = this.Client.Peerings.Get(resourceGroup.Name, name);
                Assert.NotNull(peering);
                Assert.Equal(name, peering.Name);
                return(peering);
            }
            catch (Exception ex)
            {
                Assert.Contains("NotFound", ex.Message);
            }
            return(null);
        }
Esempio n. 2
0
        public void CreateExchangePeering()
        {
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                this.client = context.GetServiceClient <PeeringManagementClient>();

                //Create a Resource Group
                this.resourcesClient = context.GetServiceClient <ResourceManagementClient>();
                var rgname        = TestUtilities.GenerateName("res");
                var resourceGroup = resourcesClient.ResourceGroups.CreateOrUpdate(
                    rgname,
                    new ResourceGroup
                {
                    Location = "centralus"
                });


                int asn = 65000;

                //Create Exchange Peering
                var exchangeConnection = new ExchangeConnection
                {
                    PeeringDBFacilityId = 26,
                    BgpSession          = new Microsoft.Azure.Management.Peering.Models.BgpSession()
                    {
                        PeerSessionIPv4Address  = $"80.249.208.{this.random.Next(1, 254)}",
                        MaxPrefixesAdvertisedV4 = 20000
                    }
                };
                SubResource asnReference = new SubResource(this.client.PeerAsns.Get($"Contoso{asn}").Id);
                var         exchangePeeringProperties = new PeeringPropertiesExchange(new List <ExchangeConnection>(), asnReference);
                exchangePeeringProperties.Connections.Add(exchangeConnection);
                var peeringModel = new PeeringModel
                {
                    PeeringLocation = "Amsterdam",
                    Sku             = new PeeringSku("Basic_Exchange_Free"),
                    Location        = "centralus",
                    Exchange        = exchangePeeringProperties,
                    Kind            = "Exchange"
                };
                var name    = $"exchangepeering1022";
                var result  = this.client.Peerings.CreateOrUpdate(rgname, name, peeringModel);
                var peering = this.client.Peerings.Get(rgname, name);
                Assert.NotNull(peering);
                Assert.Equal(name, peering.Name);
            }
        }
Esempio n. 3
0
        public void CreateDirectPeering()
        {
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                this.client = context.GetServiceClient <PeeringManagementClient>();

                //Create a Resource Group
                this.resourcesClient = context.GetServiceClient <ResourceManagementClient>();
                var rgname        = TestUtilities.GenerateName("res");
                var resourceGroup = resourcesClient.ResourceGroups.CreateOrUpdate(
                    rgname,
                    new ResourceGroup
                {
                    Location = "centralus"
                });

                //Create Direct Peering
                var directConnection = new DirectConnection
                {
                    BandwidthInMbps     = 10000,
                    PeeringDBFacilityId = 63,
                    BgpSession          = new Microsoft.Azure.Management.Peering.Models.BgpSession()
                    {
                        SessionPrefixV4         = this.CreateIpv4Address(true),
                        MaxPrefixesAdvertisedV4 = 20000
                    }
                };

                SubResource asnReference            = new SubResource(this.client.PeerAsns.Get($"Contoso{65000}").Id);
                var         directPeeringProperties = new PeeringPropertiesDirect(new List <DirectConnection>(), false, asnReference);
                directPeeringProperties.Connections.Add(directConnection);
                var peeringModel = new PeeringModel
                {
                    PeeringLocation = "Amsterdam",
                    Sku             = new PeeringSku("Basic_Direct_Free"),
                    Direct          = directPeeringProperties,
                    Location        = "centralus",
                    Kind            = "Direct"
                };
                var name    = $"directpeering3103";
                var result  = this.client.Peerings.CreateOrUpdate(rgname, name, peeringModel);
                var peering = this.client.Peerings.Get(rgname, name);
                Assert.NotNull(peering);
                Assert.Equal(name, peering.Name);
            }
        }
        public void CreateExchangePeering()
        {
            using (var context = MockContext.Start(this.GetType()))
            {
                this.client = context.GetServiceClient <PeeringManagementClient>();

                //Create a Resource Group
                this.resourcesClient = context.GetServiceClient <ResourceManagementClient>();
                var rgname        = TestUtilities.GenerateName("res");
                var resourceGroup = resourcesClient.ResourceGroups.CreateOrUpdate(
                    rgname,
                    new ResourceGroup
                {
                    Location = "centralus"
                });

                //Create Asn
                int asn   = 65000;
                var subId = this.CreatePeerAsn(context, asn, $"AS{asn}", isApproved: true);


                //Create Exchange Peering
                var exchangeConnection = new ExchangeConnection
                {
                    ConnectionIdentifier = Guid.NewGuid().ToString(),
                    PeeringDBFacilityId  = 99999,
                    BgpSession           = new Microsoft.Azure.Management.Peering.Models.BgpSession()
                    {
                        PeerSessionIPv4Address  = $"10.12.97.{this.random.Next(150, 190)}",
                        MaxPrefixesAdvertisedV4 = 20000
                    }
                };
                SubResource asnReference = new SubResource(subId);
                var         exchangePeeringProperties = new PeeringPropertiesExchange(new List <ExchangeConnection>(), asnReference);
                exchangePeeringProperties.Connections.Add(exchangeConnection);
                var peeringModel = new PeeringModel
                {
                    PeeringLocation = "Seattle",
                    Sku             = new PeeringSku("Basic_Exchange_Free"),
                    Location        = "centralus",
                    Exchange        = exchangePeeringProperties,
                    Kind            = "Exchange",
                    Tags            = new Dictionary <string, string> {
                        { TestUtilities.GenerateName("tfs_"), "Active" }
                    }
                };
                var name = $"exchangepeering1022";
                try
                {
                    var result  = this.client.Peerings.CreateOrUpdate(rgname, name, peeringModel);
                    var peering = this.client.Peerings.Get(rgname, name);
                    Assert.NotNull(peering);
                    Assert.Equal(name, peering.Name);
                }
                catch (Exception ex)
                {
                    Assert.Contains("NotFound", ex.Message);
                }
                finally
                {
                    Assert.True(this.DeletePeering(context, name, rgname));
                    Assert.True(this.DeletePeerAsn(context, $"AS{asn}"));
                    Assert.True(this.DeleteResourceGroup(context, rgname));
                }
            }
        }
        public void CreateDirectPeering()
        {
            using (var context = MockContext.Start(this.GetType()))
            {
                this.client = context.GetServiceClient <PeeringManagementClient>();

                //Create a Resource Group
                this.resourcesClient = context.GetServiceClient <ResourceManagementClient>();
                var rgname        = TestUtilities.GenerateName("res");
                var resourceGroup = resourcesClient.ResourceGroups.CreateOrUpdate(
                    rgname,
                    new ResourceGroup
                {
                    Location = "centralus"
                });

                //Create Direct Peering
                var directConnection = new DirectConnection
                {
                    ConnectionIdentifier   = Guid.NewGuid().ToString(),
                    BandwidthInMbps        = 10000,
                    PeeringDBFacilityId    = 99999,
                    SessionAddressProvider = SessionAddressProvider.Peer,
                    UseForPeeringService   = false,
                    BgpSession             = new Microsoft.Azure.Management.Peering.Models.BgpSession()
                    {
                        SessionPrefixV4         = this.CreateIpv4Address(true),
                        MaxPrefixesAdvertisedV4 = 20000
                    }
                };

                //Create Asn
                int asn   = 65003;
                var subId = this.CreatePeerAsn(context, asn, $"AS{asn}", isApproved: true);

                SubResource asnReference            = new SubResource(subId);
                var         directPeeringProperties = new PeeringPropertiesDirect(new List <DirectConnection>(), false, asnReference, DirectPeeringType.Edge);
                directPeeringProperties.Connections.Add(directConnection);
                var peeringModel = new PeeringModel
                {
                    PeeringLocation = "Seattle",
                    Sku             = new PeeringSku("Basic_Direct_Free"),
                    Direct          = directPeeringProperties,
                    Location        = "centralus",
                    Kind            = "Direct"
                };
                var name = $"directpeering3103";
                try
                {
                    var result  = this.client.Peerings.CreateOrUpdate(rgname, name, peeringModel);
                    var peering = this.client.Peerings.Get(rgname, name);
                    Assert.NotNull(peering);
                }
                catch (Exception ex)
                {
                    Assert.Contains("NotFound", ex.Message);
                }
                finally
                {
                    Assert.True(this.DeletePeering(context, name, rgname));
                    Assert.True(this.DeletePeerAsn(context, $"AS{asn}"));
                    //Assert.True(this.DeleteResourceGroup(context, rgname));
                }
            }
        }
        public void CreateGetListAndDeleteRegisteredPrefix()
        {
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                this.MockClients(context);
                PeeringModel peering    = null;
                var          asn        = int.Parse(TestUtilities.GenerateName("0"));
                var          prefixName = TestUtilities.GenerateName("prefix_");
                try
                {
                    // Create a Resource Group
                    var rgname = this.CreateResourceGroup().Name;

                    // Create Asn
                    var subId = this.CreatePeerAsn(asn, $"AS{asn}", isApproved: true, peerName: "FooBar");

                    // Set prefix
                    var prefix = new PeeringRegisteredPrefix {
                        Prefix = CreateIpv4Address(true)
                    };

                    SubResource asnReference            = new SubResource(subId);
                    var         directPeeringProperties = new PeeringPropertiesDirect(
                        new List <DirectConnection>(),
                        true,
                        asnReference,
                        DirectPeeringType.Edge);
                    var locations = this.Client.PeeringLocations.List("Direct", DirectPeeringType.Edge);
                    var loc       = locations.FirstOrDefault(x => x.Name == "Seattle");

                    // Create Direct Peering
                    var directConnection = new DirectConnection
                    {
                        ConnectionIdentifier = Guid.NewGuid().ToString(),
                        BandwidthInMbps      = 10000,
                        PeeringDBFacilityId  =
                            loc.Direct.PeeringFacilities.FirstOrDefault(x => x.PeeringDBFacilityId == 99999)
                            ?.PeeringDBFacilityId,
                        SessionAddressProvider = SessionAddressProvider.Peer,
                        BgpSession             = new BgpSession
                        {
                            SessionPrefixV4 = prefix.Prefix, MaxPrefixesAdvertisedV4 = 20000
                        },
                        UseForPeeringService = true
                    };

                    directPeeringProperties.Connections.Add(directConnection);
                    var peeringModel = new PeeringModel
                    {
                        PeeringLocation = loc.Name,
                        Sku             = new PeeringSku("Premium_Direct_Free"),
                        Direct          = directPeeringProperties,
                        Location        = loc.AzureRegion,
                        Kind            = "Direct"
                    };
                    var name = TestUtilities.GenerateName("direct_");
                    try
                    {
                        var result = this.Client.Peerings.CreateOrUpdate(rgname, name, peeringModel);
                        peering = this.Client.Peerings.Get(rgname, name);
                        Assert.NotNull(peering);
                    }
                    catch (Exception ex)
                    {
                        Assert.Contains("NotFound", ex.Message);
                    }

                    var resourceGroupName    = this.GetResourceGroup(peering?.Id);
                    var peeringName          = this.GetPeeringName(peering?.Id);
                    var registeredPrefixName = $"{peering?.Name}{prefixName}";

                    var resource = this.Client.RegisteredPrefixes.CreateOrUpdate(
                        resourceGroupName,
                        peeringName,
                        registeredPrefixName,
                        this.CreateIpv4Address(true));
                    Assert.NotNull(resource.PeeringServicePrefixKey);
                    resource = this.Client.RegisteredPrefixes.Get(
                        resourceGroupName,
                        peeringName,
                        registeredPrefixName);
                    Assert.NotNull(resource.PeeringServicePrefixKey);
                    var list = this.Client.RegisteredPrefixes.ListByPeering(resourceGroupName, peeringName);
                    Assert.NotNull(list.FirstOrDefault()?.PeeringServicePrefixKey);
                    this.Client.RegisteredPrefixes.Delete(
                        resourceGroupName,
                        peeringName,
                        registeredPrefixName);
                    try
                    {
                        resource = this.Client.RegisteredPrefixes.Get(
                            resourceGroupName,
                            peeringName,
                            registeredPrefixName);
                    }
                    catch (Exception ex)
                    {
                        Assert.NotNull(ex.Message);
                    }
                }
                finally
                {
                    Assert.True(this.DeletePeering(peering.Name, this.GetResourceGroup(peering.Id)));
                    Assert.True(this.DeletePeerAsn($"AS{asn}"));
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the PeeringPropertiesExchange class.
 /// </summary>
 /// <param name="connections">The set of connections that constitute an
 /// exchange peering.</param>
 /// <param name="peerAsn">The reference of the peer ASN.</param>
 public PeeringPropertiesExchange(IList <ExchangeConnection> connections = default(IList <ExchangeConnection>), SubResource peerAsn = default(SubResource))
 {
     Connections = connections;
     PeerAsn     = peerAsn;
     CustomInit();
 }
 /// <summary>
 /// Initializes a new instance of the PeeringPropertiesDirect class.
 /// </summary>
 /// <param name="connections">The set of connections that constitute a
 /// direct peering.</param>
 /// <param name="useForPeeringService">The flag that indicates whether
 /// or not the peering is used for peering service.</param>
 /// <param name="peerAsn">The reference of the peer ASN.</param>
 /// <param name="directPeeringType">The type of direct peering.
 /// Possible values include: 'Edge', 'Transit', 'Cdn', 'Internal',
 /// 'Ix', 'IxRs'</param>
 public PeeringPropertiesDirect(IList <DirectConnection> connections = default(IList <DirectConnection>), bool?useForPeeringService = default(bool?), SubResource peerAsn = default(SubResource), string directPeeringType = default(string))
 {
     Connections          = connections;
     UseForPeeringService = useForPeeringService;
     PeerAsn           = peerAsn;
     DirectPeeringType = directPeeringType;
     CustomInit();
 }