Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
emulab
emulab-devel
Commits
8286c6df
Commit
8286c6df
authored
Nov 15, 2001
by
Robert Ricci
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cure bitrot following snmpit changes. Now understand's snmpit's new
output format.
parent
8e15134b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
29 deletions
+41
-29
utils/vlandiff.in
utils/vlandiff.in
+41
-29
No files found.
utils/vlandiff.in
View file @
8286c6df
...
...
@@ -31,20 +31,23 @@ my %id = ();
my
$result
=
DBQueryFatal
("
select id,members from vlans
");
while
(
@row
=
$result
->
fetchrow_array
())
{
my
@list
=
split
("
",
$row
[
1
]);
my
(
$vlan_id
,
$members
)
=
@row
;
my
@list
=
split
("
",
$members
);
foreach
$port
(
@list
)
{
my
(
$node
,
$card
)
=
split
("
:
",
$port
);
if
(
$card
=~
/[a-zA-Z]/
)
{
# specified ala ethX
my
$result2
=
DBQueryFatal
("
select card from interfaces
"
.
"
where node_id='
$node
' and iface='
$card
'
");
$card
=
(
$result2
->
fetchrow_array
()
)[
0
]
;
if
(
$debug
)
{
print
"
Had '
$port
', changed to '
$node
:
$card
'
\n
";
}
(
$card
)
=
$result2
->
fetchrow_array
();
debug
(
"
Had '
$port
', changed to '
$node
:
$card
'
\n
"
)
;
$port
=
"
$node
:
$card
";
}
}
$table
{
$row
[
0
]}
=
join
("
",
sort
@list
);
if
(
$debug
)
{
print
"
In table: vlan
$row
[0]:
$table
{
$row
[0]}
\n
";
}
$table
{
$vlan_id
}
=
\
@list
;
debug
("
In table: vlan
$vlan_id
:
$table
{
$vlan_id
}
\n
");
}
# Get all the vlans from the switch
...
...
@@ -54,20 +57,23 @@ my $vlan=0;
open
(
LIST
,"
snmpit -l |
")
||
die
("
vlandiff: couldn't run snmpit: $!
\n
");
while
(
<
LIST
>
)
{
chop
;
if
(
/(^ID)|(^--)|(^1 )/
)
{
next
;
}
s/[\t ]+/ /g
;
if
(
/^(\d+)\s+(\S+)(?:\s+(.*))?$/
)
{
if
(
!
defined
$
3
)
{
$list
=
"";
}
else
{
$list
=
$
3
;
}
if
(
$
2
ne
"
default
")
{
$switch
{
$
2
}
=
join
("
",
sort
split
("
",
$list
));
$id
{
$
2
}
=
$
1
;
$vlan
=
$
2
;
if
(
$debug
)
{
print
"
On switch: vlan #$1 $2:
$switch
{$2}
\n
";
}
}
# Skip heaer lines
if
(
/(^VLAN)|(^--)/
)
{
next
;
}
# Ignore the pid/eid and vlan_name
if
(
/^(\S+)\s+\S*\s+\S*\s+(.*)$/
)
{
my
$vlan_id
=
$
1
;
my
$members
=
$
2
;
debug
("
VLAN id
$vlan_id
has members
$members
\n
");
$switch
{
$vlan_id
}
=
[
split
("
",
$members
)
];
$vlan
=
$vlan_id
;
}
elsif
(
/^\s+(.*)?$/
)
{
if
(
!
defined
$
1
)
{
$list
=
"";
}
else
{
$list
=
$
1
;
}
$switch
{
$vlan
}
.=
"
"
.
join
("
",
sort
split
("
",
$list
));
if
(
$debug
)
{
print
"
On switch: vlan #
$id
{
$vlan
}
$vlan
:
$switch
{
$vlan
}
\n
";
}
# These lines are continuations of multi-line meber lists
my
$members
=
$
1
;
if
(
!
defined
$members
)
{
$list
=
"";
}
else
{
$list
=
$members
;
}
push
@
{
$switch
{
$vlan
}},
split
("
",
$list
);
debug
("
On switch: vlan
$vlan
:
$switch
{
$vlan
}
\n
");
}
}
close
(
LIST
);
...
...
@@ -75,13 +81,15 @@ close(LIST);
# Compare all of them...
foreach
$key
(
sort
keys
%table
)
{
if
(
defined
$switch
{
$key
}
&&
(
$switch
{
$key
}
eq
$table
{
$key
})
)
{
# If its in both lists, delete it from both
if
(
$debug
)
{
print
"
vlan table:
$key
(
$table
{
$key
}) matches switch:
$key
(
$switch
{
$key
})
\n
"
if
(
defined
$switch
{
$key
}
)
{
# Hacky 'one liner' list comparison
if
(
join
("
\
0
",
sort
(
@
{
$switch
{
$key
}}))
eq
join
("
\
0
",
sort
(
@
{
$table
{
$key
}})))
{
# If its in both lists, delete it from both
debug
("
vlan table:
$key
(
$table
{
$key
}) matches switch:
$key
(
$switch
{
$key
})
\n
");
delete
$switch
{
$key
};
delete
$table
{
$key
};
}
delete
$switch
{
$key
};
delete
$table
{
$key
};
}
}
...
...
@@ -92,7 +100,7 @@ my $rv = 0;
if
(
keys
%table
)
{
print
"
In vlans table only:
\n
";
foreach
$key
(
sort
keys
%table
)
{
print
"
$key
\t
$table
{
$key
}
\n
";
print
"
$key
\t
",
join
("
",
@
{
$table
{
$key
}
}),
"
\n
";
}
$rv
++
;
}
...
...
@@ -100,16 +108,20 @@ if (keys %table) {
if
(
keys
%switch
)
{
print
"
On switch only:
\n
";
foreach
$key
(
sort
keys
%switch
)
{
print
"
#
",
$id
{"
$key
"},"
:
$key
\t
$switch
{
$key
}
\n
";
print
"
$key
\t
",
join
("
",
@
{
$switch
{
$key
}
}),
"
\n
";
}
$rv
++
;
}
if
(
$debug
)
{
print
"
Exiting with value
$rv
\n
";
}
debug
("
Exiting with value
$rv
\n
");
# Return 0 if same, 1 for a one-sided diff, 2 for a two-sided diff
# (Could be changed to return total # of different vlans)
exit
(
$rv
);
sub
debug
(@)
{
if
(
$debug
)
{
warn
@_
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment