Exemple #1
0
function formatVLANPackDiff($old, $current)
{
    $ret = '';
    $new_pack = serializeVLANPack($current);
    $new_size = substr_count($new_pack, ',');
    if (!same8021QConfigs($old, $current)) {
        $old_pack = serializeVLANPack($old);
        $old_size = substr_count($old_pack, ',');
        $ret .= '<s>' . $old_pack . '</s><br>';
        // make diff
        $added = groupIntsToRanges(array_diff($current['allowed'], $old['allowed']));
        $removed = groupIntsToRanges(array_diff($old['allowed'], $current['allowed']));
        if ($old['mode'] == $current['mode'] && $current['mode'] == 'trunk') {
            if (!empty($added)) {
                $ret .= '<span class="vlan-diff diff-add">+ ' . implode(', ', $added) . '</span><br>';
            }
            if (!empty($removed)) {
                $ret .= '<span class="vlan-diff diff-rem">- ' . implode(', ', $removed) . '</span><br>';
            }
        }
    }
    $ret .= $new_pack;
    return $ret;
}
Exemple #2
0
function serializeVLANPack($vlanport)
{
    if (!array_key_exists('mode', $vlanport)) {
        return 'error';
    }
    switch ($vlanport['mode']) {
        case 'none':
            return 'none';
        case 'access':
            $ret = 'A';
            break;
        case 'trunk':
            $ret = 'T';
            break;
        case 'uplink':
            $ret = 'U';
            break;
        case 'downlink':
            $ret = 'D';
            break;
        default:
            return 'error';
    }
    if ($vlanport['native']) {
        $ret .= $vlanport['native'];
    }
    $tagged_bits = groupIntsToRanges($vlanport['allowed'], $vlanport['native']);
    if (count($tagged_bits)) {
        $ret .= '+' . implode(', ', $tagged_bits);
    }
    return strlen($ret) ? $ret : 'default';
}