public void CreateFailsIfDuplicateVlanIdUsedOrIfPeeringAlreadyExists() { using (var undoContext = UndoContext.Current) { undoContext.Start(); var expressRouteClient = GetCustomerExpressRouteManagementClient(); var provider = expressRouteClient.DedicatedCircuitServiceProviders.List().Single(p => p.Name.Equals(GetProviderName(), StringComparison.CurrentCultureIgnoreCase)); var location = provider.DedicatedCircuitLocations.Split(',').First(); var bandwidth = provider.DedicatedCircuitBandwidths.First().Bandwidth; var circuitName = TestUtilities.GenerateName("circuit"); var newCircuitParams = new DedicatedCircuitNewParameters() { Bandwidth = bandwidth, CircuitName = circuitName, Location = location, ServiceProviderName = provider.Name }; var newResponse = expressRouteClient.DedicatedCircuits.New(newCircuitParams); TestUtilities.ValidateOperationResponse(newResponse); Guid serviceKey; Assert.True(Guid.TryParse(newResponse.Data, out serviceKey)); var randomGen = new Random(); var newPrivatePeeringParams = new BorderGatewayProtocolPeeringNewParameters() { PeerAutonomousSystemNumber = PrivatePeerAsn, PrimaryPeerSubnet = PrivatePrimaryPeerSubnet, SecondaryPeerSubnet = PrivateSecondaryPeerSubnet, SharedKey = TestUtilities.GenerateName("SharedKey"), VirtualLanId = PrivateVlanId }; newResponse = expressRouteClient.BorderGatewayProtocolPeerings.New(serviceKey.ToString(), BgpPeeringAccessType.Private, newPrivatePeeringParams); TestUtilities.ValidateOperationResponse(newResponse); newPrivatePeeringParams.PeerAutonomousSystemNumber = PublicPeerAsn; newPrivatePeeringParams.PrimaryPeerSubnet = PublicPrimaryPeerSubnet; newPrivatePeeringParams.SecondaryPeerSubnet = PublicSecondaryPeerSubnet; newPrivatePeeringParams.SharedKey = TestUtilities.GenerateName("SharedKey"); var exception = Assert.Throws <CloudException>(() => newResponse = expressRouteClient.BorderGatewayProtocolPeerings.New(serviceKey.ToString(), BgpPeeringAccessType.Public, newPrivatePeeringParams)); Assert.Equal(exception.Error.Code, "ConflictError"); Assert.True(exception.Error.Message.Contains("The vlanId specified is already in use")); newPrivatePeeringParams.VirtualLanId = PublicVlanId; exception = Assert.Throws <CloudException>(() => newResponse = expressRouteClient.BorderGatewayProtocolPeerings.New( serviceKey.ToString(), BgpPeeringAccessType.Private, newPrivatePeeringParams)); Assert.Equal(exception.Error.Code, "ConflictError"); Assert.True(exception.Error.Message.Contains("BGP peering could not be created as it already exists")); } }
public void CreateFailsIfInvalidPrimaryOrSecondaryPeerSubnetUsed() { using (var undoContext = UndoContext.Current) { undoContext.Start(); var expressRouteClient = GetCustomerExpressRouteManagementClient(); var provider = expressRouteClient.DedicatedCircuitServiceProviders.List().Single(p => p.Name.Equals(GetProviderName(), StringComparison.CurrentCultureIgnoreCase)); var location = provider.DedicatedCircuitLocations.Split(',').First(); var bandwidth = provider.DedicatedCircuitBandwidths.First().Bandwidth; var circuitName = TestUtilities.GenerateName("circuit"); var newCircuitParams = new DedicatedCircuitNewParameters() { Bandwidth = bandwidth, CircuitName = circuitName, Location = location, ServiceProviderName = provider.Name }; var newResponse = expressRouteClient.DedicatedCircuits.New(newCircuitParams); TestUtilities.ValidateOperationResponse(newResponse); Guid serviceKey; Assert.True(Guid.TryParse(newResponse.Data, out serviceKey)); var randomGen = new Random(); var newPrivatePeeringParams = new BorderGatewayProtocolPeeringNewParameters() { PeerAutonomousSystemNumber = PrivatePeerAsn, PrimaryPeerSubnet = InvalidSubnet, SecondaryPeerSubnet = PrivateSecondaryPeerSubnet, SharedKey = TestUtilities.GenerateName("SharedKey"), VirtualLanId = PrivateVlanId }; var exception = Assert.Throws<CloudException>(() => newResponse = expressRouteClient.BorderGatewayProtocolPeerings.New(serviceKey.ToString(), BgpPeeringAccessType.Private, newPrivatePeeringParams)); Assert.Equal(exception.Error.Code, "BadRequest"); Assert.True(exception.Message.Contains(newPrivatePeeringParams.PrimaryPeerSubnet) && exception.Message.Contains("is not valid")); newPrivatePeeringParams.PrimaryPeerSubnet = PrivatePrimaryPeerSubnet; newPrivatePeeringParams.SecondaryPeerSubnet = InvalidSubnet; exception = Assert.Throws<CloudException>(() => newResponse = expressRouteClient.BorderGatewayProtocolPeerings.New(serviceKey.ToString(), BgpPeeringAccessType.Private, newPrivatePeeringParams)); Assert.Equal(exception.Error.Code, "BadRequest"); Assert.True(exception.Message.Contains(newPrivatePeeringParams.SecondaryPeerSubnet) && exception.Message.Contains("is not valid")); } }
public void CanCreateGetUpdateAndRemovePrivateAndPublicPeerings() { using (var undoContext = UndoContext.Current) { undoContext.Start(); var expressRouteClient = GetCustomerExpressRouteManagementClient(); var provider = expressRouteClient.DedicatedCircuitServiceProviders.List().Single(p => p.Name.Equals(GetProviderName(), StringComparison.CurrentCultureIgnoreCase)); var location = provider.DedicatedCircuitLocations.Split(',').First(); var bandwidth = provider.DedicatedCircuitBandwidths.First().Bandwidth; var circuitName = TestUtilities.GenerateName("circuit"); var newCircuitParams = new DedicatedCircuitNewParameters() { Bandwidth = bandwidth, CircuitName = circuitName, Location = location, ServiceProviderName = provider.Name }; var newResponse = expressRouteClient.DedicatedCircuits.New(newCircuitParams); TestUtilities.ValidateOperationResponse(newResponse); Guid serviceKey; Assert.True(Guid.TryParse(newResponse.Data, out serviceKey)); var newPrivatePeeringParams = new BorderGatewayProtocolPeeringNewParameters() { PeerAutonomousSystemNumber = PrivatePeerAsn, PrimaryPeerSubnet = PrivatePrimaryPeerSubnet, SecondaryPeerSubnet = PrivateSecondaryPeerSubnet, SharedKey = TestUtilities.GenerateName("SharedKey"), VirtualLanId = PrivateVlanId }; newResponse = expressRouteClient.BorderGatewayProtocolPeerings.New(serviceKey.ToString(), BgpPeeringAccessType.Private, newPrivatePeeringParams); TestUtilities.ValidateOperationResponse(newResponse); var getResponse = expressRouteClient.BorderGatewayProtocolPeerings.Get(serviceKey.ToString(), BgpPeeringAccessType.Private); TestUtilities.ValidateOperationResponse(getResponse); Assert.Equal(getResponse.BgpPeering.PeerAsn, newPrivatePeeringParams.PeerAutonomousSystemNumber); Assert.Equal(getResponse.BgpPeering.PrimaryPeerSubnet, newPrivatePeeringParams.PrimaryPeerSubnet); Assert.Equal(getResponse.BgpPeering.SecondaryPeerSubnet, newPrivatePeeringParams.SecondaryPeerSubnet); Assert.Equal(getResponse.BgpPeering.VlanId, newPrivatePeeringParams.VirtualLanId); Assert.Equal(getResponse.BgpPeering.State, BgpPeeringState.Enabled); var newPublicPeeringParams = new BorderGatewayProtocolPeeringNewParameters() { PeerAutonomousSystemNumber = PublicPeerAsn, PrimaryPeerSubnet = PublicPrimaryPeerSubnet, SecondaryPeerSubnet = PublicSecondaryPeerSubnet, SharedKey = TestUtilities.GenerateName("SharedKey"), VirtualLanId = PublicVlanId }; newResponse = expressRouteClient.BorderGatewayProtocolPeerings.New(serviceKey.ToString(), BgpPeeringAccessType.Public, newPublicPeeringParams); TestUtilities.ValidateOperationResponse(newResponse); getResponse = expressRouteClient.BorderGatewayProtocolPeerings.Get(serviceKey.ToString(), BgpPeeringAccessType.Public); TestUtilities.ValidateOperationResponse(getResponse); Assert.Equal(getResponse.BgpPeering.PeerAsn, newPublicPeeringParams.PeerAutonomousSystemNumber); Assert.Equal(getResponse.BgpPeering.PrimaryPeerSubnet, newPublicPeeringParams.PrimaryPeerSubnet); Assert.Equal(getResponse.BgpPeering.SecondaryPeerSubnet, newPublicPeeringParams.SecondaryPeerSubnet); Assert.Equal(getResponse.BgpPeering.VlanId, newPublicPeeringParams.VirtualLanId); Assert.Equal(getResponse.BgpPeering.State, BgpPeeringState.Enabled); BorderGatewayProtocolPeeringUpdateParameters updatePrivatePeeringParams = new BorderGatewayProtocolPeeringUpdateParameters () { PeerAutonomousSystemNumber = UpdatePrivatePeerAsn, PrimaryPeerSubnet = UpdatePrivatePrimaryPeerSubnet, SecondaryPeerSubnet = UpdatePrivateSecondaryPeerSubnet, SharedKey = TestUtilities.GenerateName("SharedKey"), VirtualLanId = UpdatePrivateVlanId }; var updateResponse = expressRouteClient.BorderGatewayProtocolPeerings.Update(serviceKey.ToString(), BgpPeeringAccessType .Private, updatePrivatePeeringParams); TestUtilities.ValidateOperationResponse(updateResponse); getResponse = expressRouteClient.BorderGatewayProtocolPeerings.Get(serviceKey.ToString(), BgpPeeringAccessType.Private); TestUtilities.ValidateOperationResponse(getResponse); Assert.Equal(getResponse.BgpPeering.PeerAsn, updatePrivatePeeringParams.PeerAutonomousSystemNumber); Assert.Equal(getResponse.BgpPeering.PrimaryPeerSubnet, updatePrivatePeeringParams.PrimaryPeerSubnet); Assert.Equal(getResponse.BgpPeering.SecondaryPeerSubnet, updatePrivatePeeringParams.SecondaryPeerSubnet); Assert.Equal(getResponse.BgpPeering.VlanId, updatePrivatePeeringParams.VirtualLanId); Assert.Equal(getResponse.BgpPeering.State, BgpPeeringState.Enabled); BorderGatewayProtocolPeeringUpdateParameters updatePublicPeeringParams = new BorderGatewayProtocolPeeringUpdateParameters () { PeerAutonomousSystemNumber = UpdatePublicPeerAsn, PrimaryPeerSubnet = UpdatePublicPrimaryPeerSubnet, SecondaryPeerSubnet = UpdatePublicSecondaryPeerSubnet, SharedKey = TestUtilities.GenerateName("SharedKey"), VirtualLanId = UpdatePublicVlanId }; updateResponse = expressRouteClient.BorderGatewayProtocolPeerings.Update(serviceKey.ToString(), BgpPeeringAccessType .Public, updatePublicPeeringParams); TestUtilities.ValidateOperationResponse(updateResponse); getResponse = expressRouteClient.BorderGatewayProtocolPeerings.Get(serviceKey.ToString(), BgpPeeringAccessType.Public); TestUtilities.ValidateOperationResponse(getResponse); Assert.Equal(getResponse.BgpPeering.PeerAsn, updatePublicPeeringParams.PeerAutonomousSystemNumber); Assert.Equal(getResponse.BgpPeering.PrimaryPeerSubnet, updatePublicPeeringParams.PrimaryPeerSubnet); Assert.Equal(getResponse.BgpPeering.SecondaryPeerSubnet, updatePublicPeeringParams.SecondaryPeerSubnet); Assert.Equal(getResponse.BgpPeering.VlanId, updatePublicPeeringParams.VirtualLanId); Assert.Equal(getResponse.BgpPeering.State, BgpPeeringState.Enabled); var removeResponse = expressRouteClient.BorderGatewayProtocolPeerings.Remove(serviceKey.ToString(), BgpPeeringAccessType .Private); TestUtilities.ValidateOperationResponse(removeResponse); removeResponse = expressRouteClient.BorderGatewayProtocolPeerings.Remove(serviceKey.ToString(), BgpPeeringAccessType.Public); TestUtilities.ValidateOperationResponse(removeResponse); } }
/// <summary> /// The New Border Gateway Protocol Peering operation creates a new /// Border Gateway Protocol Peering /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.ExpressRoute.IBorderGatewayProtocolPeeringOperations. /// </param> /// <param name='serviceKey'> /// Required. The service key representing the relationship between /// Azure and the customer. /// </param> /// <param name='accessType'> /// Required. Whether the peering is private or public. /// </param> /// <param name='parameters'> /// Required. Parameters supplied to the New Border Gateway Protocol /// Peering operation. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static Task <ExpressRouteOperationResponse> BeginNewAsync(this IBorderGatewayProtocolPeeringOperations operations, string serviceKey, BgpPeeringAccessType accessType, BorderGatewayProtocolPeeringNewParameters parameters) { return(operations.BeginNewAsync(serviceKey, accessType, parameters, CancellationToken.None)); }
/// <summary> /// The New Border Gateway Protocol Peering operation creates a new /// Border Gateway Protocol Peering /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.ExpressRoute.IBorderGatewayProtocolPeeringOperations. /// </param> /// <param name='serviceKey'> /// Required. The service key representing the relationship between /// Azure and the customer. /// </param> /// <param name='accessType'> /// Required. Whether the peering is private or public. /// </param> /// <param name='parameters'> /// Required. Parameters supplied to the New Border Gateway Protocol /// Peering operation. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static ExpressRouteOperationResponse BeginNew(this IBorderGatewayProtocolPeeringOperations operations, string serviceKey, BgpPeeringAccessType accessType, BorderGatewayProtocolPeeringNewParameters parameters) { return(Task.Factory.StartNew((object s) => { return ((IBorderGatewayProtocolPeeringOperations)s).BeginNewAsync(serviceKey, accessType, parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// The New Bgp Peering operation creates a new bgp peering associated /// with the dedicated circuit specified by the service key provided. /// </summary> /// <param name='serviceKey'> /// Required. The service key representing the relationship between /// Azure and the customer. /// </param> /// <param name='accessType'> /// Required. Whether the peering is private or public. /// </param> /// <param name='parameters'> /// Required. Parameters supplied to the New Bgp Peering operation. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The Get Bgp Peering Operation Response. /// </returns> public async System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.ExpressRoute.Models.BorderGatewayProtocolPeeringGetResponse> NewAsync(string serviceKey, BgpPeeringAccessType accessType, BorderGatewayProtocolPeeringNewParameters parameters, CancellationToken cancellationToken) { ExpressRouteManagementClient client = this.Client; bool shouldTrace = CloudContext.Configuration.Tracing.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = Tracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("serviceKey", serviceKey); tracingParameters.Add("accessType", accessType); tracingParameters.Add("parameters", parameters); Tracing.Enter(invocationId, this, "NewAsync", tracingParameters); } try { if (shouldTrace) { client = this.Client.WithHandler(new ClientRequestTrackingHandler(invocationId)); } cancellationToken.ThrowIfCancellationRequested(); ExpressRouteOperationResponse originalResponse = await client.BorderGatewayProtocolPeerings.BeginNewAsync(serviceKey, accessType, parameters, cancellationToken).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); ExpressRouteOperationStatusResponse result = await client.GetOperationStatusAsync(originalResponse.OperationId, cancellationToken).ConfigureAwait(false); int delayInSeconds = 30; while (result.Status == ExpressRouteOperationStatus.InProgress) { cancellationToken.ThrowIfCancellationRequested(); await TaskEx.Delay(delayInSeconds * 1000, cancellationToken).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); result = await client.GetOperationStatusAsync(originalResponse.OperationId, cancellationToken).ConfigureAwait(false); delayInSeconds = 10; } if (result.Status == ExpressRouteOperationStatus.Failed) { string exStr = "The BGP peering could not be created due to an internal server error."; throw new ArgumentException(exStr); } cancellationToken.ThrowIfCancellationRequested(); BorderGatewayProtocolPeeringGetResponse getResult = await client.BorderGatewayProtocolPeerings.GetAsync(serviceKey, accessType, cancellationToken).ConfigureAwait(false); if (shouldTrace) { Tracing.Exit(invocationId, result); } return(getResult); } finally { if (client != null && shouldTrace) { client.Dispose(); } } }
/// <summary> /// The New Dedicated Circuit operation creates a new dedicated circuit. /// </summary> /// <param name='serviceKey'> /// Required. The service key representing the relationship between /// Azure and the customer. /// </param> /// <param name='accessType'> /// Required. Whether the peering is private or public. /// </param> /// <param name='parameters'> /// Required. Parameters supplied to the New Bgp Peering operation. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public async System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.ExpressRoute.Models.ExpressRouteOperationResponse> BeginNewAsync(string serviceKey, BgpPeeringAccessType accessType, BorderGatewayProtocolPeeringNewParameters parameters, CancellationToken cancellationToken) { // Validate if (serviceKey == null) { throw new ArgumentNullException("serviceKey"); } if (serviceKey.Length > 36) { throw new ArgumentOutOfRangeException("serviceKey"); } if (parameters == null) { throw new ArgumentNullException("parameters"); } if (parameters.PrimaryPeerSubnet == null) { throw new ArgumentNullException("parameters.PrimaryPeerSubnet"); } if (parameters.PrimaryPeerSubnet.Length > 18) { throw new ArgumentOutOfRangeException("parameters.PrimaryPeerSubnet"); } if (parameters.SecondaryPeerSubnet == null) { throw new ArgumentNullException("parameters.SecondaryPeerSubnet"); } if (parameters.SecondaryPeerSubnet.Length > 18) { throw new ArgumentOutOfRangeException("parameters.SecondaryPeerSubnet"); } if (parameters.SharedKey != null && parameters.SharedKey.Length < 6) { throw new ArgumentOutOfRangeException("parameters.SharedKey"); } if (parameters.SharedKey != null && parameters.SharedKey.Length > 24) { throw new ArgumentOutOfRangeException("parameters.SharedKey"); } // Tracing bool shouldTrace = CloudContext.Configuration.Tracing.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = Tracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("serviceKey", serviceKey); tracingParameters.Add("accessType", accessType); tracingParameters.Add("parameters", parameters); Tracing.Enter(invocationId, this, "BeginNewAsync", tracingParameters); } // Construct URL string baseUrl = this.Client.BaseUri.AbsoluteUri; string url = "/" + (this.Client.Credentials.SubscriptionId != null ? this.Client.Credentials.SubscriptionId.Trim() : "") + "/services/networking/dedicatedcircuits/" + serviceKey.Trim() + "/bgppeerings/" + accessType + "?api-version=1.0"; // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl[baseUrl.Length - 1] == '/') { baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); } if (url[0] == '/') { url = url.Substring(1); } url = baseUrl + "/" + url; // Create HTTP transport objects HttpRequestMessage httpRequest = null; try { httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Post; httpRequest.RequestUri = new Uri(url); // Set Headers httpRequest.Headers.Add("x-ms-version", "2011-10-01"); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Serialize Request string requestContent = null; XDocument requestDoc = new XDocument(); XElement createBgpPeeringElement = new XElement(XName.Get("CreateBgpPeering", "http://schemas.microsoft.com/windowsazure")); requestDoc.Add(createBgpPeeringElement); XElement peerAsnElement = new XElement(XName.Get("PeerAsn", "http://schemas.microsoft.com/windowsazure")); peerAsnElement.Value = parameters.PeerAsn.ToString(); createBgpPeeringElement.Add(peerAsnElement); XElement primaryPeerSubnetElement = new XElement(XName.Get("PrimaryPeerSubnet", "http://schemas.microsoft.com/windowsazure")); primaryPeerSubnetElement.Value = parameters.PrimaryPeerSubnet; createBgpPeeringElement.Add(primaryPeerSubnetElement); XElement secondaryPeerSubnetElement = new XElement(XName.Get("SecondaryPeerSubnet", "http://schemas.microsoft.com/windowsazure")); secondaryPeerSubnetElement.Value = parameters.SecondaryPeerSubnet; createBgpPeeringElement.Add(secondaryPeerSubnetElement); if (parameters.SharedKey != null) { XElement sharedKeyElement = new XElement(XName.Get("SharedKey", "http://schemas.microsoft.com/windowsazure")); sharedKeyElement.Value = parameters.SharedKey; createBgpPeeringElement.Add(sharedKeyElement); } XElement vlanIdElement = new XElement(XName.Get("VlanId", "http://schemas.microsoft.com/windowsazure")); vlanIdElement.Value = parameters.VlanId.ToString(); createBgpPeeringElement.Add(vlanIdElement); requestContent = requestDoc.ToString(); httpRequest.Content = new StringContent(requestContent, Encoding.UTF8); httpRequest.Content.Headers.ContentType = new MediaTypeHeaderValue("application/xml"); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { Tracing.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { Tracing.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; if (statusCode != HttpStatusCode.Accepted) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { Tracing.Error(invocationId, ex); } throw ex; } // Create Result ExpressRouteOperationResponse result = null; // Deserialize Response cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new ExpressRouteOperationResponse(); XDocument responseDoc = XDocument.Parse(responseContent); XElement gatewayOperationAsyncResponseElement = responseDoc.Element(XName.Get("GatewayOperationAsyncResponse", "http://schemas.microsoft.com/windowsazure")); if (gatewayOperationAsyncResponseElement != null) { XElement idElement = gatewayOperationAsyncResponseElement.Element(XName.Get("ID", "http://schemas.microsoft.com/windowsazure")); if (idElement != null) { string idInstance = idElement.Value; result.OperationId = idInstance; } } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { Tracing.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }
public void CanCreateGetUpdateAndRemovePrivateAndPublicPeerings() { using (var undoContext = UndoContext.Current) { undoContext.Start(); var expressRouteClient = GetCustomerExpressRouteManagementClient(); var provider = expressRouteClient.DedicatedCircuitServiceProviders.List().Single(p => p.Name.Equals(GetProviderName(), StringComparison.CurrentCultureIgnoreCase)); var location = provider.DedicatedCircuitLocations.Split(',').First(); var bandwidth = provider.DedicatedCircuitBandwidths.First().Bandwidth; var circuitName = TestUtilities.GenerateName("circuit"); var newCircuitParams = new DedicatedCircuitNewParameters() { Bandwidth = bandwidth, CircuitName = circuitName, Location = location, ServiceProviderName = provider.Name }; var newResponse = expressRouteClient.DedicatedCircuits.New(newCircuitParams); TestUtilities.ValidateOperationResponse(newResponse); Guid serviceKey; Assert.True(Guid.TryParse(newResponse.Data, out serviceKey)); var newPrivatePeeringParams = new BorderGatewayProtocolPeeringNewParameters() { PeerAutonomousSystemNumber = PrivatePeerAsn, PrimaryPeerSubnet = PrivatePrimaryPeerSubnet, SecondaryPeerSubnet = PrivateSecondaryPeerSubnet, SharedKey = TestUtilities.GenerateName("SharedKey"), VirtualLanId = PrivateVlanId }; newResponse = expressRouteClient.BorderGatewayProtocolPeerings.New(serviceKey.ToString(), BgpPeeringAccessType.Private, newPrivatePeeringParams); TestUtilities.ValidateOperationResponse(newResponse); var getResponse = expressRouteClient.BorderGatewayProtocolPeerings.Get(serviceKey.ToString(), BgpPeeringAccessType.Private); TestUtilities.ValidateOperationResponse(getResponse); Assert.Equal(getResponse.BgpPeering.PeerAsn, newPrivatePeeringParams.PeerAutonomousSystemNumber); Assert.Equal(getResponse.BgpPeering.PrimaryPeerSubnet, newPrivatePeeringParams.PrimaryPeerSubnet); Assert.Equal(getResponse.BgpPeering.SecondaryPeerSubnet, newPrivatePeeringParams.SecondaryPeerSubnet); Assert.Equal(getResponse.BgpPeering.VlanId, newPrivatePeeringParams.VirtualLanId); Assert.Equal(getResponse.BgpPeering.State, BgpPeeringState.Enabled); var newPublicPeeringParams = new BorderGatewayProtocolPeeringNewParameters() { PeerAutonomousSystemNumber = PublicPeerAsn, PrimaryPeerSubnet = PublicPrimaryPeerSubnet, SecondaryPeerSubnet = PublicSecondaryPeerSubnet, SharedKey = TestUtilities.GenerateName("SharedKey"), VirtualLanId = PublicVlanId }; newResponse = expressRouteClient.BorderGatewayProtocolPeerings.New(serviceKey.ToString(), BgpPeeringAccessType.Public, newPublicPeeringParams); TestUtilities.ValidateOperationResponse(newResponse); getResponse = expressRouteClient.BorderGatewayProtocolPeerings.Get(serviceKey.ToString(), BgpPeeringAccessType.Public); TestUtilities.ValidateOperationResponse(getResponse); Assert.Equal(getResponse.BgpPeering.PeerAsn, newPublicPeeringParams.PeerAutonomousSystemNumber); Assert.Equal(getResponse.BgpPeering.PrimaryPeerSubnet, newPublicPeeringParams.PrimaryPeerSubnet); Assert.Equal(getResponse.BgpPeering.SecondaryPeerSubnet, newPublicPeeringParams.SecondaryPeerSubnet); Assert.Equal(getResponse.BgpPeering.VlanId, newPublicPeeringParams.VirtualLanId); Assert.Equal(getResponse.BgpPeering.State, BgpPeeringState.Enabled); BorderGatewayProtocolPeeringUpdateParameters updatePrivatePeeringParams = new BorderGatewayProtocolPeeringUpdateParameters () { PeerAutonomousSystemNumber = UpdatePrivatePeerAsn, PrimaryPeerSubnet = UpdatePrivatePrimaryPeerSubnet, SecondaryPeerSubnet = UpdatePrivateSecondaryPeerSubnet, SharedKey = TestUtilities.GenerateName("SharedKey"), VirtualLanId = UpdatePrivateVlanId }; var updateResponse = expressRouteClient.BorderGatewayProtocolPeerings.Update(serviceKey.ToString(), BgpPeeringAccessType .Private, updatePrivatePeeringParams); TestUtilities.ValidateOperationResponse(updateResponse); getResponse = expressRouteClient.BorderGatewayProtocolPeerings.Get(serviceKey.ToString(), BgpPeeringAccessType.Private); TestUtilities.ValidateOperationResponse(getResponse); Assert.Equal(getResponse.BgpPeering.PeerAsn, updatePrivatePeeringParams.PeerAutonomousSystemNumber); Assert.Equal(getResponse.BgpPeering.PrimaryPeerSubnet, updatePrivatePeeringParams.PrimaryPeerSubnet); Assert.Equal(getResponse.BgpPeering.SecondaryPeerSubnet, updatePrivatePeeringParams.SecondaryPeerSubnet); Assert.Equal(getResponse.BgpPeering.VlanId, updatePrivatePeeringParams.VirtualLanId); Assert.Equal(getResponse.BgpPeering.State, BgpPeeringState.Enabled); BorderGatewayProtocolPeeringUpdateParameters updatePublicPeeringParams = new BorderGatewayProtocolPeeringUpdateParameters () { PeerAutonomousSystemNumber = UpdatePublicPeerAsn, PrimaryPeerSubnet = UpdatePublicPrimaryPeerSubnet, SecondaryPeerSubnet = UpdatePublicSecondaryPeerSubnet, SharedKey = TestUtilities.GenerateName("SharedKey"), VirtualLanId = UpdatePublicVlanId }; updateResponse = expressRouteClient.BorderGatewayProtocolPeerings.Update(serviceKey.ToString(), BgpPeeringAccessType .Public, updatePublicPeeringParams); TestUtilities.ValidateOperationResponse(updateResponse); getResponse = expressRouteClient.BorderGatewayProtocolPeerings.Get(serviceKey.ToString(), BgpPeeringAccessType.Public); TestUtilities.ValidateOperationResponse(getResponse); Assert.Equal(getResponse.BgpPeering.PeerAsn, updatePublicPeeringParams.PeerAutonomousSystemNumber); Assert.Equal(getResponse.BgpPeering.PrimaryPeerSubnet, updatePublicPeeringParams.PrimaryPeerSubnet); Assert.Equal(getResponse.BgpPeering.SecondaryPeerSubnet, updatePublicPeeringParams.SecondaryPeerSubnet); Assert.Equal(getResponse.BgpPeering.VlanId, updatePublicPeeringParams.VirtualLanId); Assert.Equal(getResponse.BgpPeering.State, BgpPeeringState.Enabled); } }