Skip to content

Commit 2f0716d

Browse files
committed
RSTP port roles
1 parent ff0053c commit 2f0716d

10 files changed

+342
-6
lines changed

application/controllers/CdpController.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ public function neighboursAction()
7373

7474
public function imgNeighboursGraphAction()
7575
{
76-
$this->view->cdp_root = $host = $this->_getParam( 'cdp_root', '' );
76+
$this->view->cdp_root = $cdp_root = $this->_getParam( 'cdp_root', '' );
7777

78-
if( !strlen( $host ) )
78+
if( !strlen( $cdp_root ) )
7979
{
8080
header( 'content-type: text/plain' );
8181
echo 'You must provide a hostname or IP address for CDP neighbour discovery';
@@ -84,8 +84,9 @@ public function imgNeighboursGraphAction()
8484

8585
try
8686
{
87-
$host = new \OSS\SNMP( $host, $this->_options['community'] );
87+
$host = new \OSS\SNMP( $cdp_root, $this->_options['community'] );
8888
$this->view->host = $host;
89+
$this->view->deviceId = $host->useCisco_CDP()->id();
8990
$this->view->neighbours = $host->useCisco_CDP()->neighbours();
9091
}
9192
catch( \OSS\Exception $e )
@@ -94,7 +95,6 @@ public function imgNeighboursGraphAction()
9495
$this->_forward( 'index' );
9596
}
9697

97-
$this->view->deviceId = $host->useCisco_CDP()->id();
9898
header( 'content-type: image/png' );
9999

100100
$file = 'img-neighbour-graph-' . OSS_String::random( 16, true, true, true );
+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2012, Open Source Solutions Limited, Dublin, Ireland
5+
All rights reserved.
6+
7+
This file is part of the NOCtools package.
8+
9+
Contact: Barry O'Donovan - barry (at) opensolutions (dot) ie
10+
http://www.opensolutions.ie/
11+
12+
Redistribution and use in source and binary forms, with or without
13+
modification, are permitted provided that the following conditions are met:
14+
15+
* Redistributions of source code must retain the above copyright
16+
notice, this list of conditions and the following disclaimer.
17+
* Redistributions in binary form must reproduce the above copyright
18+
notice, this list of conditions and the following disclaimer in the
19+
documentation and/or other materials provided with the distribution.
20+
* Neither the name of Open Source Solutions Limited nor the
21+
names of its contributors may be used to endorse or promote products
22+
derived from this software without specific prior written permission.
23+
24+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
28+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34+
*/
35+
36+
/**
37+
* StpController
38+
*
39+
* @author Barry O'Donovan <[email protected]>
40+
*/
41+
42+
class StpController extends OSS_Controller_Action
43+
{
44+
45+
/**
46+
* The default action - show the home page
47+
*/
48+
public function indexAction()
49+
{
50+
}
51+
52+
public function rstpPortRolesAction()
53+
{
54+
if( $this->getRequest()->isPost() )
55+
{
56+
$this->view->rstpPortRolesDevice = $device = $this->_getParam( 'rstpPortRolesDevice' );
57+
$this->view->limitToVlan = $limitToVlan = $this->_getParam( 'limitToVlan', false );
58+
59+
try
60+
{
61+
$host = new \OSS\SNMP( $device, $this->_options['community'] );
62+
$vlans = $host->useCisco_VTP()->vlanNames();
63+
}
64+
catch( \OSS\Exception $e )
65+
{
66+
$this->addMessage( "Could not query VLAN and port role information via SNMP from " . $device, OSS_Message::ERROR );
67+
return;
68+
}
69+
70+
$roles = array();
71+
$unknowns = array();
72+
$portsInRSTP = array();
73+
74+
if( $limitToVlan && isset( $vlans[ $limitToVlan ] ) )
75+
{
76+
$name = $vlans[ $limitToVlan ];
77+
unset( $vlans );
78+
$vlans = [ $limitToVlan => $name ];
79+
}
80+
81+
foreach( $vlans as $vid => $vname )
82+
{
83+
try
84+
{
85+
$roles[ $vid ] = $host->useCisco_RSTP()->rstpPortRole( $vid, true );
86+
87+
foreach( $roles[ $vid ] as $portId => $role )
88+
if( !isset( $portsInRSTP[ $portId ] ) )
89+
$portsInRSTP[ $portId ] = $portId;
90+
}
91+
catch( \OSS\Exception $e )
92+
{
93+
$unknowns[ $vid ] = $vname;
94+
}
95+
}
96+
97+
ksort( $portsInRSTP, SORT_NUMERIC );
98+
$this->view->portsInRSTP = $portsInRSTP;
99+
$this->view->ports = $host->useIface()->names();
100+
$this->view->vlans = $vlans;
101+
$this->view->roles = $roles;
102+
$this->view->unknowns = unknowns;
103+
104+
unset( $host );
105+
}
106+
107+
}
108+
109+
}

application/views/cdp/img-neighbours-graph.dot

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ digraph G {
99
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
1010
{assign var="ports" value=0}
1111
{include assign="portGraph" file="./img-neighbours-graph-ports.dot" scope=parent}
12-
<TR><TD COLSPAN="{$ports}">{$name}</TD></TR>
12+
<TR><TD COLSPAN="{$ports}">{$deviceId}</TD></TR>
1313
{$portGraph}
1414
</TABLE>
1515
>];

application/views/menu.phtml

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
<li {if $controller eq 'cdp'}class="active"{/if}>
1212
<a href="{genUrl controller="cdp"}">CDP</a>
1313
</li>
14+
<li {if $controller eq 'stp'}class="active"{/if}>
15+
<a href="{genUrl controller="stp"}">STP</a>
16+
</li>
1417
<li {if $controller eq 'vlan'}class="active"{/if}>
1518
<a href="{genUrl controller="vlan"}">VLAN</a>
1619
</li>

application/views/stp/index.phtml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{include file="header.phtml"}
2+
3+
<div class="container">
4+
5+
{include file="./stp-header.phtml"}
6+
7+
</div>
8+
9+
{include file="footer.phtml"}
+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
{include file="header.phtml"}
2+
3+
<div class="container">
4+
5+
<h1>NOCtools - Spanning Tree Utilities - RSTP VLAN Port Roles</h1>
6+
7+
<br />
8+
9+
{OSS_Message}
10+
11+
<div class="row">
12+
13+
<form action="{genUrl controller="stp" action="rstp-port-roles"}" method="post">
14+
15+
<div class="span3">
16+
<p>
17+
This tool will allow you to see the port RSTP roles per VLAN
18+
for a given switch.
19+
</p>
20+
<p>
21+
{if isset( $_devices ) and count( $_devices )}
22+
<select name="rstpPortRolesDevice" data-placeholder="Choose a device..." class="chzn-select span3">
23+
<option></option>
24+
{foreach $_devices as $d}
25+
<option value="{$d}" {if isset( $rstpPortRolesDevice ) and $rstpPortRolesDevice eq $d}selected="selected"{/if}>{$d}</option>
26+
{/foreach}
27+
</select>
28+
<br /><br />
29+
<input type="submit" value="Submit &raquo;" class="btn" />
30+
{else}
31+
<span class="label label-important">ERROR</span> No devices defined in:<br /><br />
32+
<code>application/configs/devices.ini</code>
33+
{/if}
34+
</p>
35+
</div>
36+
37+
<div class="span3">
38+
{if isset( $vlans )}
39+
<p>
40+
Select a VLAN below if you wish to limit the results to a single VLAN.
41+
</p>
42+
<p>
43+
<select name="limitToVlan" data-placeholder="Optionally choose a VLAN..." class="chzn-select-deselect span3">
44+
<option></option>
45+
{foreach $vlans as $vid => $vname}
46+
<option value="{$vid}" {if isset( $limitToVlan ) and $limitToVlan neq false and $vid eq $limitToVlan}selected="selected"{/if}>{$vid} - {$vname}</option>
47+
{/foreach}
48+
</select>
49+
</p>
50+
{/if}
51+
</div>
52+
53+
<div class="span3">
54+
</div>
55+
56+
<div class="span3">
57+
</div>
58+
59+
</form>
60+
61+
62+
</div>
63+
64+
{if isset( $vlans )}
65+
66+
<br />
67+
68+
{if isset( $limitToVlan ) and $limitToVlan}
69+
<h4>Port RSTP Roles for VLAN {$vlans.$limitToVlan} ({$limitToVlan}) on {$rstpPortRolesDevice}</h4>
70+
71+
<div class="row">
72+
<div class="span3">&nbsp;</div>
73+
<div class="span6">
74+
<br />
75+
<table class="table span6">
76+
<thead>
77+
<tr>
78+
<th>Port</th>
79+
<th>Role</th>
80+
</tr>
81+
</thead>
82+
<tbody>
83+
{foreach $portsInRSTP as $portId}
84+
<tr>
85+
<td>
86+
{$ports.$portId}
87+
</td>
88+
<td>
89+
{if isset( $roles.$vid.$portId )}
90+
<label class="label
91+
{if $roles.$vid.$portId eq 'root'}
92+
label-success
93+
{elseif $roles.$vid.$portId eq 'designated'}
94+
label-success
95+
{elseif $roles.$vid.$portId eq 'alternate'}
96+
label-important
97+
{elseif $roles.$vid.$portId eq 'backup'}
98+
label-error
99+
{else}
100+
label-info
101+
{/if}" style="text-align: center">{$roles.$vid.$portId|capitalize}</label>
102+
{/if}
103+
</td>
104+
</tr>
105+
{/foreach}
106+
</tbody>
107+
</table>
108+
</div>
109+
<div class="span3">&nbsp;</div>
110+
</div>
111+
112+
{else}
113+
<h4>Port RSTP Roles for All VLANs on {$rstpPortRolesDevice}</h4>
114+
115+
<p>
116+
Note that blank cells mean that that port is not participating in RSTP for the given VLAN / is not a member of the given VLAN.
117+
</p>
118+
119+
<table class="table">
120+
<thead>
121+
<tr>
122+
<th>ID</th>
123+
<th>Name</th>
124+
{foreach $portsInRSTP as $portId}
125+
<th style="text-align: center">{$ports.$portId}</th>
126+
{/foreach}
127+
</tr>
128+
</thead>
129+
<tbody>
130+
{foreach $vlans as $vid => $vname}
131+
<tr>
132+
<td>{$vid}</td>
133+
<td>{$vname}</td>
134+
{foreach $portsInRSTP as $portId}
135+
<td>
136+
{if isset( $roles.$vid.$portId )}
137+
<label class="label
138+
{if $roles.$vid.$portId eq 'root'}
139+
label-success
140+
{elseif $roles.$vid.$portId eq 'designated'}
141+
label-success
142+
{elseif $roles.$vid.$portId eq 'alternate'}
143+
label-important
144+
{elseif $roles.$vid.$portId eq 'backup'}
145+
label-error
146+
{else}
147+
label-info
148+
{/if}" style="text-align: center">{$roles.$vid.$portId|capitalize}</label>
149+
{/if}
150+
</td>
151+
{/foreach}
152+
</tr>
153+
{/foreach}
154+
</tbody>
155+
</table>
156+
{/if}
157+
158+
159+
<br /><br /><br />
160+
161+
162+
{/if} {* if isset( $vlans ) *}
163+
164+
</div>
165+
166+
{include file="footer.phtml"}
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
<h1>NOCtools - Spanning Tree Utilities</h1>
3+
4+
<br />
5+
6+
{OSS_Message}
7+
8+
<div class="row">
9+
10+
<div class="span3">
11+
<h3>RSTP VLAN Port Roles</h3>
12+
13+
<p>
14+
This tool will allow you to see the port RSTP roles per VLAN
15+
for a given switch.
16+
</p>
17+
<p>
18+
{if isset( $_devices ) and count( $_devices )}
19+
<form action="{genUrl controller="stp" action="rstp-port-roles"}" method="post">
20+
<select name="rstpPortRolesDevice" data-placeholder="Choose a device..." class="chzn-select span3">
21+
<option></option>
22+
{foreach $_devices as $d}
23+
<option value="{$d}" {if isset( $rstpPortRolesDevice ) and $rstpPortRolesDevice eq $d}selected="selected"{/if}>{$d}</option>
24+
{/foreach}
25+
</select>
26+
<br /><br />
27+
<input type="submit" value="Submit &raquo;" class="btn" />
28+
</form>
29+
{else}
30+
<span class="label label-important">ERROR</span> No devices defined in:<br /><br />
31+
<code>application/configs/devices.ini</code>
32+
{/if}
33+
</p>
34+
</div>
35+
36+
<div class="span3">
37+
</div>
38+
39+
<div class="span3">
40+
</div>
41+
42+
<div class="span3">
43+
</div>
44+
45+
46+
</div>
47+

application/views/vlan/compare.phtml

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
{/if}
102102
</td>
103103
{/foreach}
104+
</tr>
104105
{/foreach}
105106
</tbody>
106107
</table>

0 commit comments

Comments
 (0)