function ios15ShortenIfName_real added to handle port-channel interfaces names correc...
[racktables] / wwwroot / inc / breed-ios15.php
1 <?php
2
3 # This file is a part of RackTables, a datacenter and server room management
4 # framework. See accompanying file "COPYING" for the full copyright and
5 # licensing information.
6
7 function ios15ReadLLDPStatus ($input)
8 {
9 $ret = array();
10 foreach (explode ("\n", $input) as $line)
11 {
12 $matches = array();
13 switch (TRUE)
14 {
15 case preg_match ('/^Local Intf: (.+)$/', $line, $matches):
16 $ret['current']['local_port'] = shortenIfName ($matches[1]);
17 break;
18 case preg_match ('/^[Pp]ort [Ii][Dd]: (.+)$/', $line, $matches):
19 $ret['current']['remote_port'] = $matches[1];
20 break;
21 case preg_match ('/^[Pp]ort [Dd]escription: (.+)$/', $line, $matches):
22 $ret['current']['port_descr'] = $matches[1];
23 break;
24 case preg_match ('/^[Ss]ystem [Nn]ame: (.+)$/', $line, $matches):
25 $ret['current']['sys_name'] = $matches[1];
26 if
27 (
28 array_key_exists ('current', $ret) &&
29 array_key_exists ('local_port', $ret['current']) &&
30 array_key_exists ('port_descr', $ret['current']) &&
31 array_key_exists ('sys_name', $ret['current']) &&
32 array_key_exists ('remote_port', $ret['current'])
33 )
34 {
35 $port = NULL;
36 if (preg_match ('/^[a-f0-9]{4}.[a-f0-9]{4}.[a-f0-9]{4}$/',$ret['current']['remote_port'], $matches))
37 $port = $ret['current']['port_descr'];
38 else
39 $port = $ret['current']['remote_port'];
40 if (isset ($port))
41 $ret[$ret['current']['local_port']][] = array
42 (
43 'device' => $ret['current']['sys_name'],
44 'port' => $port,
45 );
46 }
47 unset ($ret['current']);
48 break;
49 default:
50 }
51 }
52 unset ($ret['current']);
53 return $ret;
54 }
55
56 // most of the commands are compatible with IOS12, so are generated by ios12TranslatePushQueue
57 // Only ios15-specific commands are generated here (eg., lldp)
58 function ios15TranslatePushQueue ($dummy_object_id, $queue, $dummy_vlan_names)
59 {
60 $ret = '';
61 foreach ($queue as $cmd)
62 switch ($cmd['opcode'])
63 {
64 case 'getlldpstatus':
65 $ret .= "show lldp neighbors detail | i Local Intf:|Chassis id:|Port id:|Port Description:|System Name:\n";
66 break;
67 default:
68 $ret .= ios12TranslatePushQueue ($dummy_object_id, array ($cmd), $dummy_vlan_names);
69 break;
70 }
71 return $ret;
72 }
73
74 function ios15ShortenIfName_real ($ifname)
75 {
76 $ifname = preg_replace ('@^FastEthernet(.+)$@', 'fa\\1', $ifname);
77 $ifname = preg_replace ('@^GigabitEthernet(.+)$@', 'gi\\1', $ifname);
78 $ifname = preg_replace ('@^TenGigabitEthernet(.+)$@', 'te\\1', $ifname);
79 $ifname = preg_replace ('@^po([0-9]+)$@i', 'port-channel\\1', $ifname);
80 $ifname = strtolower ($ifname);
81 $ifname = preg_replace ('/^(fa|gi|te|po)\s+(\d.*)/', '$1$2', $ifname);
82 return $ifname;
83 }