r3637 Finalize the first implementation of CDP (#58):
authorDenis Ovsienko <infrastation@yandex.ru>
Thu, 20 May 2010 11:29:34 +0000 (11:29 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Thu, 20 May 2010 11:29:34 +0000 (11:29 +0000)
ios12ScanCDPEntry(): finish entry scan on port line, don't look for next entry start
getPortInfo(): also return, if the port is linked or not
renderLiveCDP(): fix select name
importCDPData(): new function

inc/database.php
inc/functions.php
inc/interface.php
inc/navigation.php
inc/ophandlers.php

index 3a74ba5..bbedbce 100644 (file)
@@ -3576,6 +3576,7 @@ function getPortInfo ($port_id)
 {
        $query = "SELECT object_id, name, iif_id, type AS oif_id, l2address, ".
                "(SELECT dict_value FROM Dictionary WHERE dict_key = type) AS oif_name, " .
+               "(SELECT COUNT(*) FROM Link WHERE id IN (porta, portb)) AS linked, " .
                "(SELECT iif_name FROM PortInnerInterface WHERE id = iif_id) AS iif_name " .
                "FROM Port WHERE id = ?";
        $result = usePreparedSelectBlade ($query, array ($port_id));
index f7cc555..1169539 100644 (file)
@@ -3098,7 +3098,6 @@ function ios12ReadCDPStatus ($input)
        $procfunc = 'ios12ScanCDPTopLevel';
        foreach (explode ("\n", $input) as $line)
                $procfunc = $procfunc ($ret, $line);
-       unset ($ret['current']);
        return $ret;
 }
 
@@ -3108,7 +3107,7 @@ function ios12ScanCDPTopLevel (&$work, $line)
        switch (TRUE)
        {
        case preg_match ('/^Device ID: (.+)$/', $line, $matches):
-               $work['current'] = array ('remote_device' => $matches[1]);
+               $work['current'] = array ('device' => $matches[1]);
                return 'ios12ScanCDPEntry';
        default:
                return __FUNCTION__; // continue scan
@@ -3117,28 +3116,17 @@ function ios12ScanCDPTopLevel (&$work, $line)
 
 function ios12ScanCDPEntry (&$work, $line)
 {
-       if (preg_match ('/^-+$/', $line))
-       {
-               if
-               (
-                       array_key_exists ('local_port', $work['current']) and
-                       array_key_exists ('remote_port', $work['current'])
-               )
-                       $work[$work['current']['local_port']] = array
-                       (
-                               'device' => $work['current']['remote_device'],
-                               'port' => $work['current']['remote_port'],
-                       );
-               unset ($work['current']);
-               return 'ios12ScanCDPTopLevel';
-       }
        $matches = array();
        switch (TRUE)
        {
        case preg_match ('/^Interface: (.+),  Port ID \(outgoing port\): (.+)$/', $line, $matches):
-               $work['current']['local_port'] = ios12ShortenIfName ($matches[1]);
-               $work['current']['remote_port'] = ios12ShortenIfName ($matches[2]);
-               break;
+               $work[ios12ShortenIfName ($matches[1])] = array
+               (
+                       'device' => $work['current']['device'],
+                       'port' => ios12ShortenIfName ($matches[2]),
+               );
+               unset ($work['current']);
+               return 'ios12ScanCDPTopLevel';
        default:
        }
        return __FUNCTION__;
index 000bcb1..b12cdf4 100644 (file)
@@ -7781,7 +7781,7 @@ function renderLiveCDP ($object_id)
                foreach ($remote_port_ids as $remote_port_id)
                        $remote_options[$remote_port_id] = formatPortIIFOIF (getPortInfo ($remote_port_id));
                echo "<tr class=trwarning><td>${local_port}</td><td>";
-               printSelect ($local_options, array ('name' => "pid2_${inputno}"));
+               printSelect ($local_options, array ('name' => "pid1_${inputno}"));
                echo "</td><td>${remote['device']}</td>";
                echo "<td>${remote['port']}</td><td>";
                printSelect ($remote_options, array ('name' => "pid2_${inputno}"));
index 7799b60..d1f45be 100644 (file)
@@ -84,7 +84,7 @@ $tab['object']['ports'] = 'Ports';
 $tab['object']['ipv4'] = 'IPv4';
 $tab['object']['nat4'] = 'NATv4';
 $tab['object']['livevlans'] = 'Live VLANs';
-$tab['object']['livecdp'] = '[Live CDP]';
+$tab['object']['livecdp'] = 'Live CDP';
 $tab['object']['snmpportfinder'] = 'SNMP sync';
 $tab['object']['editrspvs'] = 'RS pools';
 $tab['object']['lvsconfig'] = 'keepalived.conf';
index 60ee1d9..39ebdc4 100644 (file)
@@ -2575,4 +2575,33 @@ function updVSTRule()
        return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
 }
 
+$msgcode['importCDPData']['OK'] = 44;
+function importCDPData()
+{
+       global $sic;
+       assertUIntArg ('nports');
+       $nignored = $ndone = 0;
+       for ($i = 0; $i < $sic['nports']; $i++)
+               if (array_key_exists ("do_${i}", $sic))
+               {
+                       assertUIntArg ("pid1_${i}");
+                       assertUIntArg ("pid2_${i}");
+                       $porta = getPortInfo ($_REQUEST["pid1_${i}"]);
+                       $portb = getPortInfo ($_REQUEST["pid2_${i}"]);
+                       if
+                       (
+                               $porta['linked'] or
+                               $portb['linked'] or
+                               ($porta['object_id'] != $sic['object_id'] and $portb['object_id'] != $sic['object_id'])
+                       )
+                       {
+                               $nignored++;
+                               continue;
+                       }
+                       linkPorts ($_REQUEST["pid1_${i}"], $_REQUEST["pid2_${i}"]);
+                       $ndone++;
+               }
+       return buildRedirectURL (__FUNCTION__, 'OK', array ($nignored, $ndone));
+}
+
 ?>