Skip to content

Commit 87a3c1d

Browse files
authored
Merge pull request #4021 from dihan0604/dev
add new property for bgp
2 parents 4ca9cbf + 3993e21 commit 87a3c1d

File tree

10 files changed

+160
-14
lines changed

10 files changed

+160
-14
lines changed

src/ServiceManagement/ExpressRoute/Commands.ExpressRoute/BgpPeerings/GetAzureBGPPeering.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ public class GetAzureBGPPeeringCommand : ExpressRouteBaseCmdlet
3333

3434
public override void ExecuteCmdlet()
3535
{
36-
var route = ExpressRouteClient.GetAzureBGPPeering(ServiceKey, AccessType);
37-
WriteObject(route);
36+
var peer = ExpressRouteClient.GetAzureBGPPeering(ServiceKey, AccessType);
37+
38+
if (AccessType != BgpPeeringAccessType.Microsoft)
39+
{
40+
peer.LegacyMode = 1;
41+
}
42+
43+
WriteObject(peer);
3844
}
3945
}
4046
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Microsoft.WindowsAzure.Commands.ExpressRoute.BgpPeerings
8+
{
9+
public enum LegacyMode
10+
{
11+
False = 0,
12+
True = 1
13+
}
14+
}

src/ServiceManagement/ExpressRoute/Commands.ExpressRoute/BgpPeerings/NewAzureBGPPeering.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ public class NewAzureBGPPeeringCommand : ExpressRouteBaseCmdlet
3232
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Customer AS number")]
3333
public UInt32 CustomerAsn { get; set; }
3434

35-
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true,
36-
HelpMessage = "Peer Asn")]
35+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Peer Asn")]
3736
public UInt32 PeerAsn { get; set; }
3837

38+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Legacy Mode")]
39+
[DefaultValue(LegacyMode.False)]
40+
public LegacyMode LegacyMode { get; set; }
41+
3942
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Primary Peer Subnet")]
4043
[ValidateNotNullOrEmpty]
4144
public string PrimaryPeerSubnet { get; set; }
@@ -61,8 +64,14 @@ public class NewAzureBGPPeeringCommand : ExpressRouteBaseCmdlet
6164
public override void ExecuteCmdlet()
6265
{
6366
var route = ExpressRouteClient.NewAzureBGPPeering(ServiceKey, AdvertisedPublicPrefixes, CustomerAsn, PeerAsn,
64-
PrimaryPeerSubnet, RoutingRegistryName, SecondaryPeerSubnet, VlanId, AccessType, SharedKey);
67+
PrimaryPeerSubnet, RoutingRegistryName, SecondaryPeerSubnet, VlanId, AccessType, SharedKey, Convert.ToUInt32(LegacyMode));
6568
WriteObject(route);
6669
}
6770
}
71+
72+
public enum LegacyMode
73+
{
74+
False = 0,
75+
True = 1
76+
}
6877
}

src/ServiceManagement/ExpressRoute/Commands.ExpressRoute/Commands.ExpressRoute.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.4.1.1\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
8989
</Reference>
9090
<Reference Include="Microsoft.WindowsAzure.Management.ExpressRoute">
91-
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.ExpressRoute.0.20.0-preview\lib\net40\Microsoft.WindowsAzure.Management.ExpressRoute.dll</HintPath>
91+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.ExpressRoute.0.21.0-preview\lib\net40\Microsoft.WindowsAzure.Management.ExpressRoute.dll</HintPath>
9292
<Private>True</Private>
9393
</Reference>
9494
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">

src/ServiceManagement/ExpressRoute/Commands.ExpressRoute/ExpressRouteClient.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,20 @@ public AzureBgpPeering GetAzureBGPPeering(Guid serviceKey, BgpPeeringAccessType
7979
return Client.BorderGatewayProtocolPeerings.Get(serviceKey.ToString(), accessType).BgpPeering;
8080
}
8181

82-
public AzureBgpPeering NewAzureBGPPeering(Guid serviceKey, string advertisedPublicPrefixes, UInt32 customerAsn, UInt32 peerAsn, string primaryPeerSubnet,
83-
string routingRegistryName, string secondaryPeerSubnet, UInt32 vlanId, BgpPeeringAccessType accessType, string sharedKey = null)
82+
public AzureBgpPeering NewAzureBGPPeering(Guid serviceKey, string advertisedPublicPrefixes, UInt32 customerAsn, UInt32 peerAsn,string primaryPeerSubnet,
83+
string routingRegistryName, string secondaryPeerSubnet, UInt32 vlanId, BgpPeeringAccessType accessType, string sharedKey = null, UInt32 legacyMode = 0)
8484
{
8585
var result = Client.BorderGatewayProtocolPeerings.New(serviceKey.ToString(), accessType, new BorderGatewayProtocolPeeringNewParameters()
8686
{
8787
AdvertisedPublicPrefixes = advertisedPublicPrefixes,
8888
CustomerAutonomousSystemNumber = customerAsn,
89+
LegacyMode = legacyMode,
8990
PeerAutonomousSystemNumber = peerAsn,
9091
PrimaryPeerSubnet = primaryPeerSubnet,
9192
RoutingRegistryName = routingRegistryName,
9293
SecondaryPeerSubnet = secondaryPeerSubnet,
9394
SharedKey = sharedKey,
94-
VirtualLanId = vlanId
95+
VirtualLanId = vlanId,
9596
});
9697

9798
if (result.HttpStatusCode.Equals(HttpStatusCode.OK))

src/ServiceManagement/ExpressRoute/Commands.ExpressRoute/Microsoft.WindowsAzure.Commands.ExpressRoute.dll-help.xml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,13 @@
10341034
</maml:description>
10351035
<command:parameterValue required="true" variableLength="false">BgpPeeringAccessType</command:parameterValue>
10361036
</command:parameter>
1037+
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="named">
1038+
<maml:name>LegacyMode</maml:name>
1039+
<maml:description>
1040+
<maml:para>Legacy mode can be either False or True. False (the default value) sets up a BGP session which advertised no routes. True sets up a BGP session which advertised all routes.</maml:para>
1041+
</maml:description>
1042+
<command:parameterValue required="true" variableLength="false">BgpPeeringAccessType</command:parameterValue>
1043+
</command:parameter>
10371044
</command:syntaxItem>
10381045
</command:syntax>
10391046
<command:parameters>
@@ -1128,6 +1135,19 @@
11281135
<dev:defaultValue>
11291136
</dev:defaultValue>
11301137
</command:parameter>
1138+
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="named">
1139+
<maml:name>LegacyMode</maml:name>
1140+
<maml:description>
1141+
<maml:para>Specifies the legacy mode of the bgp peering.</maml:para>
1142+
</maml:description>
1143+
<command:parameterValue required="true" variableLength="false">UInt32</command:parameterValue>
1144+
<dev:type>
1145+
<maml:name>UInt32</maml:name>
1146+
<maml:uri />
1147+
</dev:type>
1148+
<dev:defaultValue>
1149+
</dev:defaultValue>
1150+
</command:parameter>
11311151
</command:parameters>
11321152
<command:inputTypes>
11331153
<command:inputType>
@@ -1179,9 +1199,9 @@
11791199
<maml:para>
11801200
</maml:para>
11811201
</maml:introduction>
1182-
<dev:code>PS C:\&gt; C:\PS&gt;New-AzureBGPPeering -ServiceKey "12345678-1234-1234-abcd-1234567890ab" -VlanId 100 -PeerAsn 65014 -PrimaryPeerSubnet "10.0.0.0/30" -SecondaryPeerSubnet "10.0.0.4/30"</dev:code>
1202+
<dev:code>PS C:\&gt; C:\PS&gt;New-AzureBGPPeering -ServiceKey "12345678-1234-1234-abcd-1234567890ab" -VlanId 100 -PeerAsn 65014 -PrimaryPeerSubnet "10.0.0.0/30" -SecondaryPeerSubnet "10.0.0.4/30" -LegacyMode True</dev:code>
11831203
<dev:remarks>
1184-
<maml:para>Creates a new BGP session for an ExpressRoute circuit with service key "12345678-1234-1234-abcd-1234567890ab". The BGP session with AS number 65014 is established on VLAN ID 100.</maml:para>
1204+
<maml:para>Creates a new BGP session for an ExpressRoute circuit with service key "12345678-1234-1234-abcd-1234567890ab". The BGP session with AS number 65014 is established on VLAN ID 100 which advertised all routes for microsoft peering</maml:para>
11851205
</dev:remarks>
11861206
<command:commandLines>
11871207
<command:commandLine>

src/ServiceManagement/ExpressRoute/Commands.ExpressRoute/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
<package id="Microsoft.Rest.ClientRuntime" version="2.3.5" targetFramework="net45" />
1313
<package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="2.2.9-preview" targetFramework="net45" />
1414
<package id="Microsoft.WindowsAzure.Management" version="4.1.1" targetFramework="net45" />
15-
<package id="Microsoft.WindowsAzure.Management.ExpressRoute" version="0.20.0-preview" targetFramework="net45" />
15+
<package id="Microsoft.WindowsAzure.Management.ExpressRoute" version="0.21.0-preview" targetFramework="net45" />
1616
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
1717
</packages>

src/ServiceManagement/Services/Commands.Test/Commands.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Compute.14.0.0\lib\net40\Microsoft.WindowsAzure.Management.Compute.dll</HintPath>
137137
</Reference>
138138
<Reference Include="Microsoft.WindowsAzure.Management.ExpressRoute">
139-
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.ExpressRoute.0.20.0-preview\lib\net40\Microsoft.WindowsAzure.Management.ExpressRoute.dll</HintPath>
139+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.ExpressRoute.0.21.0-preview\lib\net40\Microsoft.WindowsAzure.Management.ExpressRoute.dll</HintPath>
140140
<Private>True</Private>
141141
</Reference>
142142
<Reference Include="Microsoft.WindowsAzure.Management.MediaServices">

src/ServiceManagement/Services/Commands.Test/ExpressRoute/AzureBgpPeeringTests.cs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,102 @@ public void NewAzureBgpPeeringSuccessful()
135135
Assert.Equal(expectedBgp.BgpPeering.PrimaryAzurePort, actual.PrimaryAzurePort);
136136
}
137137

138+
[Fact]
139+
[Trait(Category.AcceptanceType, Category.CheckIn)]
140+
public void NewAzureMicrosoftBgpPeeringSuccessful()
141+
{
142+
// Setup
143+
string serviceKey = "aa28cd19-b10a-41ff-981b-53c6bbf15ead";
144+
UInt32 peerAsn = 64496;
145+
string primaryPeerSubnet = "aaa";
146+
string secondayPeerSubnet = "bbb";
147+
UInt32 azureAsn = 64494;
148+
string primaryAzurePort = "8081";
149+
string secondaryAzurePort = "8082";
150+
var state = BgpPeeringState.Enabled;
151+
uint vlanId = 2;
152+
var accessType = BgpPeeringAccessType.Microsoft;
153+
uint legacyMode = 0;
154+
string prefix = "12.2.3.4/30";
155+
156+
MockCommandRuntime mockCommandRuntime = new MockCommandRuntime();
157+
Mock<ExpressRouteManagementClient> client = InitExpressRouteManagementClient();
158+
var bgpMock = new Mock<IBorderGatewayProtocolPeeringOperations>();
159+
160+
BorderGatewayProtocolPeeringGetResponse expectedBgp =
161+
new BorderGatewayProtocolPeeringGetResponse
162+
{
163+
BgpPeering = new AzureBgpPeering()
164+
{
165+
AzureAsn = azureAsn,
166+
PeerAsn = peerAsn,
167+
PrimaryAzurePort = primaryAzurePort,
168+
PrimaryPeerSubnet = primaryPeerSubnet,
169+
SecondaryAzurePort = secondaryAzurePort,
170+
SecondaryPeerSubnet = secondayPeerSubnet,
171+
State = state,
172+
VlanId = vlanId,
173+
LegacyMode = legacyMode,
174+
AdvertisedPublicPrefixes = prefix
175+
},
176+
RequestId = "",
177+
StatusCode = new HttpStatusCode()
178+
};
179+
180+
ExpressRouteOperationStatusResponse expectedStatus = new ExpressRouteOperationStatusResponse()
181+
{
182+
HttpStatusCode = HttpStatusCode.OK
183+
};
184+
185+
var tGet = new Task<BorderGatewayProtocolPeeringGetResponse>(() => expectedBgp);
186+
tGet.Start();
187+
188+
var tNew = new Task<ExpressRouteOperationStatusResponse>(() => expectedStatus);
189+
tNew.Start();
190+
191+
bgpMock.Setup(
192+
f =>
193+
f.NewAsync(It.Is<string>(x => x == serviceKey),
194+
It.Is<BgpPeeringAccessType>(
195+
y => y == accessType),
196+
It.Is<BorderGatewayProtocolPeeringNewParameters>(
197+
z =>
198+
z.PeerAutonomousSystemNumber == peerAsn && z.PrimaryPeerSubnet == primaryPeerSubnet &&
199+
z.SecondaryPeerSubnet == secondayPeerSubnet && z.VirtualLanId == vlanId),
200+
It.IsAny<CancellationToken>()))
201+
.Returns((string sKey, BgpPeeringAccessType atype, BorderGatewayProtocolPeeringNewParameters param, CancellationToken cancellation) => tNew);
202+
client.SetupGet(f => f.BorderGatewayProtocolPeerings).Returns(bgpMock.Object);
203+
204+
bgpMock.Setup(
205+
f =>
206+
f.GetAsync(It.Is<string>(x => x == serviceKey),
207+
It.Is<BgpPeeringAccessType>(
208+
y => y == accessType),
209+
It.IsAny<CancellationToken>()))
210+
.Returns((string sKey, BgpPeeringAccessType atype, CancellationToken cancellation) => tGet);
211+
client.SetupGet(f => f.BorderGatewayProtocolPeerings).Returns(bgpMock.Object);
212+
213+
NewAzureBGPPeeringCommand cmdlet = new NewAzureBGPPeeringCommand()
214+
{
215+
ServiceKey = Guid.Parse(serviceKey),
216+
AccessType = accessType,
217+
PeerAsn = peerAsn,
218+
PrimaryPeerSubnet = primaryPeerSubnet,
219+
SecondaryPeerSubnet = secondayPeerSubnet,
220+
SharedKey = null,
221+
VlanId = vlanId,
222+
CommandRuntime = mockCommandRuntime,
223+
ExpressRouteClient = new ExpressRouteClient(client.Object)
224+
};
225+
226+
cmdlet.ExecuteCmdlet();
227+
228+
// Assert
229+
AzureBgpPeering actual = mockCommandRuntime.OutputPipeline[0] as AzureBgpPeering;
230+
Assert.Equal(expectedBgp.BgpPeering.State, actual.State);
231+
Assert.Equal(expectedBgp.BgpPeering.PrimaryAzurePort, actual.PrimaryAzurePort);
232+
}
233+
138234
[Fact]
139235
[Trait(Category.AcceptanceType, Category.CheckIn)]
140236
public void GetAzureBgpPeeringSuccessful()

src/ServiceManagement/Services/Commands.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.2.0" targetFramework="net45" />
2121
<package id="Microsoft.WindowsAzure.Management" version="4.1.1" targetFramework="net45" />
2222
<package id="Microsoft.WindowsAzure.Management.Compute" version="14.0.0" targetFramework="net45" />
23-
<package id="Microsoft.WindowsAzure.Management.ExpressRoute" version="0.20.0-preview" targetFramework="net45" />
23+
<package id="Microsoft.WindowsAzure.Management.ExpressRoute" version="0.21.0-preview" targetFramework="net45" />
2424
<package id="Microsoft.WindowsAzure.Management.MediaServices" version="4.0.0" targetFramework="net45" />
2525
<package id="Microsoft.WindowsAzure.Management.ServiceBus" version="0.18.0-preview" targetFramework="net45" />
2626
<package id="Microsoft.WindowsAzure.Management.Storage" version="6.0.1" targetFramework="net45" />

0 commit comments

Comments
 (0)