r3762 vrp53ReadLLDPStatus(): new function, initial implementation
authorDenis Ovsienko <infrastation@yandex.ru>
Sun, 6 Jun 2010 22:32:43 +0000 (22:32 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Sun, 6 Jun 2010 22:32:43 +0000 (22:32 +0000)
ios12ShortenIfName(): accept Quidway's naming input

inc/functions.php
inc/gateways.php

index 1cf5fc643ff764a4af9336d58cf8c3442784bb33..c506324cd9dd793f65dcffd722c4a1b0c0120167 100644 (file)
@@ -2366,6 +2366,7 @@ function ios12ShortenIfName ($ifname)
        $ifname = preg_replace ('@^GigabitEthernet(.+)$@', 'gi\\1', $ifname);
        $ifname = preg_replace ('@^TenGigabitEthernet(.+)$@', 'te\\1', $ifname);
        $ifname = preg_replace ('@^Port-channel(.+)$@', 'po\\1', $ifname);
+       $ifname = preg_replace ('@^XGigabitEthernet(.+)$@', 'xg\\1', $ifname);
        return $ifname;
 }
 
index 2881b853c0acca8b22bcd7450962e899326d574b..3cc8c834554adc696eaae60ac4e0b3b7de98fb5e 100644 (file)
 // translating functions maps
 $gwrxlator = array();
 $gwrxlator['getcdpstatus']['ios12'] = 'ios12ReadCDPStatus';
-$gwrxlator['getlldpstatus']['xos12'] = 'xos12ReadLLDPStatus';
+$gwrxlator['getlldpstatus'] = array
+(
+       'xos12' => 'xos12ReadLLDPStatus',
+       'vrp53' => 'vrp53ReadLLDPStatus',
+);
 $gwrxlator['get8021q'] = array
 (
        'ios12' => 'ios12ReadVLANConfig',
@@ -426,6 +430,43 @@ function xos12ReadLLDPStatus ($input)
        return $ret;
 }
 
+function vrp53ReadLLDPStatus ($input)
+{
+       $ret = array();
+       foreach (explode ("\n", $input) as $line)
+       {
+               $matches = array();
+               switch (TRUE)
+               {
+               case preg_match ('/^(.+) has 1 neighbors:$/', $line, $matches):
+                       $ret['current']['local_port'] = ios12ShortenIfName ($matches[1]);
+                       break;
+               case preg_match ('/^(PortIdSubtype|PortId): ([^ ]+)/', $line, $matches):
+                       $ret['current'][$matches[1]] = $matches[2];
+                       break;
+               case preg_match ('/^SysName: (.+)$/', $line, $matches):
+                       if
+                       (
+                               array_key_exists ('current', $ret) and
+                               array_key_exists ('PortIdSubtype', $ret['current']) and
+                               ($ret['current']['PortIdSubtype'] == 'interfaceAlias' or $ret['current']['PortIdSubtype'] == 'interfaceName') and
+                               array_key_exists ('PortId', $ret['current']) and
+                               array_key_exists ('local_port', $ret['current'])
+                       )
+                               $ret[$ret['current']['local_port']] = array
+                               (
+                                       'device' => $matches[1],
+                                       'port' => ios12ShortenIfName ($ret['current']['PortId']),
+                               );
+                       unset ($ret['current']);
+                       break;
+               default:
+               }
+       }
+       unset ($ret['current']);
+       return $ret;
+}
+
 function ios12ReadVLANConfig ($input)
 {
        $ret = array