r3760 xos12ReadLLDPStatus(): new function, initial implementation
authorDenis Ovsienko <infrastation@yandex.ru>
Sun, 6 Jun 2010 22:00:40 +0000 (22:00 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Sun, 6 Jun 2010 22:00:40 +0000 (22:00 +0000)
inc/gateways.php

index bbee5ee1eb5e018aa23a964dd19d57d581f17cdc..2881b853c0acca8b22bcd7450962e899326d574b 100644 (file)
@@ -16,6 +16,7 @@
 // translating functions maps
 $gwrxlator = array();
 $gwrxlator['getcdpstatus']['ios12'] = 'ios12ReadCDPStatus';
+$gwrxlator['getlldpstatus']['xos12'] = 'xos12ReadLLDPStatus';
 $gwrxlator['get8021q'] = array
 (
        'ios12' => 'ios12ReadVLANConfig',
@@ -391,6 +392,40 @@ function ios12ReadCDPStatus ($input)
        return $ret;
 }
 
+function xos12ReadLLDPStatus ($input)
+{
+       $ret = array();
+       foreach (explode ("\n", $input) as $line)
+       {
+               $matches = array();
+               switch (TRUE)
+               {
+               case preg_match ('/^LLDP Port ([[:digit:]]+) detected 1 neighbor$/', $line, $matches):
+                       $ret['current']['local_port'] = ios12ShortenIfName ($matches[1]);
+                       break;
+               case preg_match ('/^      Port ID     : "(.+)"$/', $line, $matches):
+                       $ret['current']['remote_port'] = ios12ShortenIfName ($matches[1]);
+                       break;
+               case preg_match ('/^    - System Name: "(.+)"$/', $line, $matches):
+                       if
+                       (
+                               array_key_exists ('current', $ret) and
+                               array_key_exists ('local_port', $ret['current']) and
+                               array_key_exists ('remote_port', $ret['current'])
+                       )
+                               $ret[$ret['current']['local_port']] = array
+                               (
+                                       'device' => $matches[1],
+                                       'port' => $ret['current']['remote_port'],
+                               );
+                       unset ($ret['current']);
+               default:
+               }
+       }
+       unset ($ret['current']);
+       return $ret;
+}
+
 function ios12ReadVLANConfig ($input)
 {
        $ret = array