Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Get-ArubaCXNeighbors (ARP) information #74

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions PowerArubaCX/Private/ConvertTo.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#
# Copyright 2024, Alexis La Goutte <alexis dot lagoutte at gmail dot com>
#
# SPDX-License-Identifier: Apache-2.0
#

function ConvertTo-ArubaCXMacAddressTable {

<#
.SYNOPSIS
ConvertTo Aruba CX Mac Address Table

.DESCRIPTION
Convert ArubaCX Macs Address Table to more easy array (with mac, vlan and port)


.EXAMPLE
Get-ArubaCXMacs -depth 2 | ConvertTo-ArubaCXMacAddressTable

Convert ArubaCX Macs to MAC Address Table (mac, vlan and port)
#>

Param(
[Parameter(Mandatory = $true, position = 1, ValueFromPipeline = $true)]
[PSObject]$mac
)

Begin {
}

Process {
$table = @()
#Get list of vlan name
$list_mac_vlan_name = $mac.psobject.properties.name

foreach ($mac_vlan_name in $list_mac_vlan_name) {
$list_mac = $mac.$mac_vlan_name
$list_mac_name = $list_mac.psobject.properties.name

#get List of modemac (Dynamic + MAC @)
foreach ($mac_name in $list_mac_name) {
$table += [pscustomobject]@{
"mac" = $list_mac.$mac_name.mac_addr
"vlan" = $mac_vlan_name
"port" = $list_mac.$mac_name.port.psobject.properties.name
}
}
}

$table
}

End {
}

}

function ConvertTo-ArubaCXARPTable {

<#
.SYNOPSIS
ConvertTo Aruba CX ARP Table

.DESCRIPTION
Convert ArubaCX ARP Table to more easy array (with mac, IP, vlan and port)

.EXAMPLE
Get-ArubaCXNeighbors -depth 2 | ConvertTo-ArubaCXARPTable

Convert ArubaCX Neighbors to ARP Table (mac, IP? vlan and port)
#>

Param(
[Parameter(Mandatory = $true, position = 1, ValueFromPipeline = $true)]
[PSObject]$arp
)

Begin {
}

Process {
$table = @()

#Get list of vrf name
$list_arp_vrf_name = $arp.psobject.properties.name

foreach ($arp_vrf_name in $list_arp_vrf_name) {
$list_arp = $arp.$arp_vrf_name

#get List of arp name (IP + Vlan...)
$list_arp_name = $list_arp.psobject.properties.name

foreach ($arp_name in $list_arp_name) {
$ipvlan = $arp.$arp_vrf_name.$arp_name
$table += [pscustomobject]@{
"ip_address" = $ipvlan.ip_address
"mac" = $ipvlan.mac
"vlan" = $ipvlan.port.psobject.properties.name
"port" = $ipvlan.phy_port.psobject.properties.name
"vrf" = $arp_vrf_name
}
}
}
$table
}

End {
}

}
88 changes: 88 additions & 0 deletions PowerArubaCX/Public/Macs.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#
# Copyright 2021, Alexis La Goutte <alexis dot lagoutte at gmail dot com>
#
# SPDX-License-Identifier: Apache-2.0
#
function Get-ArubaCXMACs {


<#
.SYNOPSIS
Get list of MACs (MAC Address Table)

.DESCRIPTION
Get list of MACs (Mac Address, type, vlan...)

.EXAMPLE
Get-ArubaCXMACs

Get Neighbors (MAC Address Table) information on all Vlans

.EXAMPLE
Get-ArubaCXMACs -vlan MyVlan

Get Neighbors (MAC Address Table) information on vlan MyVlan

.EXAMPLE
Get-ArubaCXVlans MyVlan | Get-ArubaCXMACs

Get Neighbors (MAC Address Table) information on vlan MyVlan (using pipeline)

#>

[CmdletBinding(DefaultParametersetname = "Default")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "")]
Param(
[Parameter (Mandatory = $false, ValueFromPipeline = $true, ParameterSetName = "vlan")]
[ValidateScript( { Confirm-ArubaCXVlans $_ })]
[psobject]$vlan_pp,
[Parameter(Mandatory = $false, position = 1, ParameterSetName = "id")]
[String]$vlan = "*",
[Parameter(Mandatory = $false)]
[ValidateRange(1, 4)]
[Int]$depth,
[Parameter(Mandatory = $false)]
[ValidateSet("configuration", "status", "statistics", "writable")]
[String]$selector,
[Parameter(Mandatory = $false)]
[String[]]$attributes,
[Parameter(Mandatory = $false)]
[switch]$vsx_peer,
[Parameter (Mandatory = $False)]
[ValidateNotNullOrEmpty()]
[PSObject]$connection = $DefaultArubaCXConnection
)

Begin {
}

Process {

#get vlan id from vlan_pp ps object (passed by pipeline)
if ($vlan_pp) {
$vlan = $vlan_pp.id
}

$invokeParams = @{ }
if ( $PsBoundParameters.ContainsKey('depth') ) {
$invokeParams.add( 'depth', $depth )
}
if ( $PsBoundParameters.ContainsKey('selector') ) {
$invokeParams.add( 'selector', $selector )
}
if ( $PsBoundParameters.ContainsKey('attributes') ) {
$invokeParams.add( 'attributes', $attributes )
}
if ( $PsBoundParameters.ContainsKey('vsx_peer') ) {
$invokeParams.add( 'vsx_peer', $true )
}

$uri = "system/vlans/$vlan/macs"

$response = Invoke-ArubaCXRestMethod -uri $uri -method 'GET' -connection $connection @invokeParams
$response
}

End {
}
}
88 changes: 88 additions & 0 deletions PowerArubaCX/Public/Neighbors.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#
# Copyright 2021, Alexis La Goutte <alexis dot lagoutte at gmail dot com>
#
# SPDX-License-Identifier: Apache-2.0
#
function Get-ArubaCXNeighbors {


<#
.SYNOPSIS
Get list of Neighbors (ARP Table)

.DESCRIPTION
Get list of Neighbors (Mac Address, IP Address, type, vlan...)

.EXAMPLE
Get-ArubaCXNeighbors

Get Neighbors (ARP Table) information on all VRF

.EXAMPLE
Get-ArubaCXNeighbors -vrf MyVRF

Get Neighbors (ARP Table) information on vrf MyVRF

.EXAMPLE
Get-ArubaCXVrfs MyVRF | Get-ArubaCXNeighbors

Get Neighbors (ARP Table) information on vrf MyVRF (using pipeline)

#>

[CmdletBinding(DefaultParametersetname = "Default")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "")]
Param(
[Parameter (Mandatory = $false, ValueFromPipeline = $true, ParameterSetName = "vrf_pp")]
[ValidateScript( { Confirm-ArubaCXVrfs $_ })]
[psobject]$vrf_pp,
[Parameter(Mandatory = $false, position = 1, ParameterSetName = "vrf")]
[String]$vrf = "*",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mutual exclusive... ?

[Parameter(Mandatory = $false)]
[ValidateRange(1, 4)]
[Int]$depth,
[Parameter(Mandatory = $false)]
[ValidateSet("configuration", "status", "statistics", "writable")]
[String]$selector,
[Parameter(Mandatory = $false)]
[String[]]$attributes,
[Parameter(Mandatory = $false)]
[switch]$vsx_peer,
[Parameter (Mandatory = $False)]
[ValidateNotNullOrEmpty()]
[PSObject]$connection = $DefaultArubaCXConnection
)

Begin {
}

Process {

#get vrf name from vrf_pp ps object (passed by pipeline)
if ($vrf_pp) {
$vrf = $vrf_pp.name
}

$invokeParams = @{ }
if ( $PsBoundParameters.ContainsKey('depth') ) {
$invokeParams.add( 'depth', $depth )
}
if ( $PsBoundParameters.ContainsKey('selector') ) {
$invokeParams.add( 'selector', $selector )
}
if ( $PsBoundParameters.ContainsKey('attributes') ) {
$invokeParams.add( 'attributes', $attributes )
}
if ( $PsBoundParameters.ContainsKey('vsx_peer') ) {
$invokeParams.add( 'vsx_peer', $true )
}

$uri = "system/vrfs/$vrf/neighbors"

$response = Invoke-ArubaCXRestMethod -uri $uri -method 'GET' -connection $connection @invokeParams
$response
}

End {
}
}
73 changes: 73 additions & 0 deletions Tests/integration/Macs.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#
# Copyright 2020, Alexis La Goutte <alexis dot lagoutte at gmail dot com>
#
# SPDX-License-Identifier: Apache-2.0
#
. ../common.ps1

BeforeAll {
Connect-ArubaCX @invokeParams
}

#Only Basic check because no neighbor... (need to add some peer switch)
Describe "Get (Vlan) Macs (Mac Address Table)" {

BeforeAll {
Add-ArubaCXVlans -id $pester_vlan -name pester_vlan
}

It "Get MACs not throw an error" {
{
Get-ArubaCXMACs
} | Should -Not -Throw
}

It "Get MACs with a vlan ($pester_vlan) Does not throw an error" {
{
Get-ArubaCXMACs -vlan $pester_vlan
} | Should -Not -Throw
}

It "Get MACs with a pipeline vlan ($pester_vlan) Does not throw an error" {
{
Get-ArubaCXVlans -id $pester_vlan | Get-ArubaCXMACs
} | Should -Not -Throw
}

Context "Depth" {

It "Get Neighbor with depth equal 1" {
{
Get-ArubaCXMACs -depth 1
} | Should -Not -Throw
}

It "Get MACs with depth equal 2" {
{
Get-ArubaCXMACs -depth 2
} | Should -Not -Throw
}

It "Get MACs with depth equal 3" {
{
Get-ArubaCXMACs -depth 3
} | Should -Not -Throw
}

It "Get MACs with depth equal 4" {
{
Get-ArubaCXMACs -depth 4
} | Should -Not -Throw
}

}

AfterAll {
Get-ArubaCXVlans -id $pester_vlan | Remove-ArubaCXVlans -confirm:$false
#Reverse CheckPoint ?
}
}

AfterAll {
Disconnect-ArubaCX -confirm:$false
}
Loading