r3335 computeSwitchPushRequest(): added draft code
authorDenis Ovsienko <infrastation@yandex.ru>
Tue, 9 Mar 2010 19:59:39 +0000 (19:59 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Tue, 9 Mar 2010 19:59:39 +0000 (19:59 +0000)
inc/functions.php

index cf945ae..491a4ae 100644 (file)
@@ -2612,28 +2612,84 @@ function computeSwitchPushRequest ($object_id, $which_ports)
        amplifyCell ($object);
        $db_config = getDesired8021QConfig ($object_id);
        $ports_to_do = array();
-       foreach ($which_ports as $req_port_name)
+       foreach ($which_ports as $port_name)
        {
-               if (!array_key_exists ($req_port_name, $db_config))
+               if (!array_key_exists ($port_name, $db_config))
                        continue;
                if
                (
-                       count ($db_config[$req_port_name]['allowed']) == 0 and
-                       $db_config[$req_port_name]['native'] == 0
+                       count ($db_config[$port_name]['allowed']) == 0 and
+                       $db_config[$port_name]['native'] == 0
                )
                        continue;
-               $ports_to_do[] = $req_port_name;
+               $ports_to_do[] = $port_name;
        }
        $new_managed_vlans = array();
        foreach ($vdomain['vlanlist'] as $vlan_id => $vlan)
-               if ($vlan['type'] == 'mandatory')
+               if ($vlan['vlan_type'] == 'compulsory')
                        $new_managed_vlans[] = $vlan_id;
-       foreach ($db_config as $vlanlist)
-               foreach ($vlanlist as $vlan_id)
+       foreach ($db_config as $portdata)
+               foreach ($portdata['allowed'] as $vlan_id)
                        if (!in_array ($vlan_id, $new_managed_vlans))
                                $new_managed_vlans[] = $vlan_id;
-       dump ($old_managed_vlans);
-       dump ($new_managed_vlans);
+       $ret = array();
+/*
+ * FIXME: this is a draft unfinished code
+ *
+       // Before removing old VLANs as such it is necessary to unassign
+       // ports from them (to remove VLANs from ports' list of "allowed"
+       // VLANs. This change in turn requires, that "native" VLAN isn't
+       // set to the one being removed.
+       foreach ($ports_to_do as $port_name)
+       {
+               if ($db_config[$port_name]['native'] and $db_config[$port_name]['native'] != $device_config[$port_name]['native'])
+                       $ret[] = array
+                       (
+                               'opcode' => 'unset native',
+                               'args' => array ($port_name, $device_config[$port_name]['native']),
+                       );
+               foreach (array_diff ($db_config[$port_name]['old_allowed'], $db_config[$port_name]['new_allowed']) as $vlan_id)
+                       $ret[] = array
+                       (
+                               'opcode' => 'rem allowed',
+                               'args' => array ($port_name, $vlan_id),
+                       );
+       }
+       foreach (array_diff ($old_managed_vlans, $new_managed_vlans) as $vlan_id)
+               $ret[] = array
+               (
+                       'opcode' => 'unset VLAN',
+                       'args' => array ($vlan_id),
+               );
+       foreach (array_diff ($new_managed_vlans, $old_managed_vlans) as $vlan_id)
+               $ret[] = array
+               (
+                       'opcode' => 'set VLAN',
+                       'args' => array ($vlan_id),
+               );
+       // Now, when all new VLANs are created (queued), it is safe to assign (queue)
+       // ports to the new VLANs.
+       foreach ($ports_to_do as $port_name)
+       {
+               // For each allowed VLAN, which is present on the "new" list and missing from
+               // the "old" one, queue a command to assign current port to that VLAN.
+               foreach (array_diff ($db_config[$port_name]['allowed'], $device_config[$port_name]['allowed']) as $vlan_id)
+                       $ret[] = array
+                       (
+                               'opcode' => 'add allowed',
+                               'args' => array ($port_name, $vlan_id),
+                       );
+               // One of the "allowed" VLANs for this port may probably be "native".
+               if (0) // "new native" is set and differs from "old native"
+                       $ret[] = array
+                       (
+                               'opcode' => 'set native',
+                               'args' => array ($port_name, $vlan_id),
+                       );
+
+       }
+*/
+       return $ret;
 }
 
 ?>