2023-01-24 15:29:31 +01:00
|
|
|
|
/* Copyright (c) Cloud Software Group, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
|
* that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using XenAdmin.Controls;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Wizards.NewNetworkWizard_Pages
|
|
|
|
|
{
|
|
|
|
|
public partial class NetWDetails : XenTabPage
|
|
|
|
|
{
|
2020-02-11 16:34:55 +01:00
|
|
|
|
private List<int> vlans;
|
|
|
|
|
private bool _vlanError;
|
|
|
|
|
private bool _mtuError;
|
|
|
|
|
private bool _populatingNics;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
public NetWDetails()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2020-02-11 16:34:55 +01:00
|
|
|
|
//non-browsable events
|
2013-06-24 13:41:48 +02:00
|
|
|
|
numericUpDownVLAN.TextChanged += numericUpDownVLAN_TextChanged;
|
2020-02-11 16:34:55 +01:00
|
|
|
|
numericUpDownMTU.TextChanged += numericUpDownMTU_TextChanged;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
numericUpDownMTU.Maximum = XenAPI.Network.MTU_MAX;
|
|
|
|
|
numericUpDownMTU.Minimum = XenAPI.Network.MTU_MIN;
|
|
|
|
|
numericUpDownMTU.Value = XenAPI.Network.MTU_DEFAULT;
|
2020-02-11 16:34:55 +01:00
|
|
|
|
numericUpDownVLAN.Maximum = 4094;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
public override string Text => Messages.NETW_DETAILS_TEXT;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
public override string PageTitle =>
|
|
|
|
|
SelectedNetworkType == NetworkTypes.External
|
|
|
|
|
? Messages.NETW_EXTERNAL_DETAILS_TITLE
|
|
|
|
|
: Messages.NETW_INTERNAL_DETAILS_TITLE;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
public override bool EnableNext()
|
|
|
|
|
{
|
2020-02-11 16:34:55 +01:00
|
|
|
|
if (_vlanError || _mtuError)
|
|
|
|
|
return false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
return SelectedHostNic != null || !comboBoxNICList.Visible;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void PopulatePage()
|
|
|
|
|
{
|
2020-02-11 16:34:55 +01:00
|
|
|
|
var external = SelectedNetworkType == NetworkTypes.External;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
labelExternal.Visible = external;
|
|
|
|
|
labelInternal.Visible = !external;
|
|
|
|
|
labelNIC.Visible = external;
|
|
|
|
|
comboBoxNICList.Visible = external;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
if (comboBoxNICList.Visible)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-02-11 16:34:55 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_populatingNics = true;
|
|
|
|
|
comboBoxNICList.Items.Clear();
|
|
|
|
|
|
|
|
|
|
foreach (PIF ThePIF in Connection.Cache.PIFs)
|
|
|
|
|
{
|
|
|
|
|
if (ThePIF.host.opaque_ref == Host.opaque_ref && ThePIF.IsPhysical() &&
|
|
|
|
|
(Properties.Settings.Default.ShowHiddenVMs || ThePIF.Show(Properties.Settings.Default.ShowHiddenVMs)) &&
|
2021-08-31 12:31:16 +02:00
|
|
|
|
!ThePIF.IsBondMember())
|
2020-02-11 16:34:55 +01:00
|
|
|
|
{
|
|
|
|
|
comboBoxNICList.Items.Add(ThePIF);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
_populatingNics = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (comboBoxNICList.Items.Count > 0)
|
|
|
|
|
comboBoxNICList.SelectedIndex = 0;
|
|
|
|
|
|
|
|
|
|
comboBoxNICList.Focus();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2020-02-11 16:34:55 +01:00
|
|
|
|
|
|
|
|
|
labelVLAN.Visible = external;
|
|
|
|
|
numericUpDownVLAN.Visible = external;
|
|
|
|
|
numericUpDownVLAN.Minimum = Helpers.VLAN0Allowed(Connection) ? 0 : 1;
|
|
|
|
|
numericUpDownMTU.Visible = labelMTU.Visible = infoMtuPanel.Visible = external;
|
|
|
|
|
|
|
|
|
|
checkBoxSriov.Visible = SelectedHostNic != null && SelectedHostNic.IsSriovPhysicalPIF();
|
|
|
|
|
|
|
|
|
|
OnPageUpdated();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Accessors
|
|
|
|
|
|
|
|
|
|
public NetworkTypes SelectedNetworkType { private get; set; }
|
|
|
|
|
|
|
|
|
|
public Host Host { private get; set; }
|
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
public PIF SelectedHostNic => comboBoxNICList.SelectedItem as PIF;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
public int VLAN => Convert.ToInt32(Math.Round(numericUpDownVLAN.Value, MidpointRounding.AwayFromZero));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
public bool AddNicToVmsAutomatically => checkBoxAutomatic.Checked;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
public bool CreateVlanOnSriovNetwork => checkBoxSriov.Visible && checkBoxSriov.Checked;
|
2018-03-15 20:42:01 +01:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// <summary>
|
2020-02-11 16:34:55 +01:00
|
|
|
|
/// Returns -1 if the custom MTU option is disabled
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// </summary>
|
2020-02-11 16:34:55 +01:00
|
|
|
|
public int MTU => numericUpDownMTU.Visible && numericUpDownMTU.Enabled
|
|
|
|
|
? Convert.ToInt32(Math.Round(numericUpDownMTU.Value, MidpointRounding.AwayFromZero))
|
|
|
|
|
: -1;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
private List<int> GetVLANList(PIF nic)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-02-11 16:34:55 +01:00
|
|
|
|
List<int> vlans = new List<int>();
|
|
|
|
|
foreach (PIF pif in nic.Connection.Cache.PIFs)
|
|
|
|
|
{
|
|
|
|
|
if (pif.device == nic.device)
|
|
|
|
|
{
|
|
|
|
|
var pifIsSriov = pif.NetworkSriov() != null;
|
|
|
|
|
if ((CreateVlanOnSriovNetwork && pifIsSriov) || (!CreateVlanOnSriovNetwork && !pifIsSriov))
|
|
|
|
|
vlans.Add((int)pif.VLAN);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
return vlans;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
private void ValidateVLANValue()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-02-11 16:34:55 +01:00
|
|
|
|
//CA-192746: do not call numericUpDown.Value or properties/methods that call it
|
|
|
|
|
//in the validation method, because it auto-corrects what the user has typed
|
|
|
|
|
|
|
|
|
|
_vlanError = false;
|
|
|
|
|
string msg = null;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
if (!int.TryParse(numericUpDownVLAN.Text.Trim(), out int currentValue))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-02-11 16:34:55 +01:00
|
|
|
|
_vlanError = true;
|
|
|
|
|
msg = Messages.INVALID_NUMBER;
|
|
|
|
|
}
|
|
|
|
|
else if (currentValue < numericUpDownVLAN.Minimum || numericUpDownVLAN.Maximum < currentValue)
|
|
|
|
|
{
|
|
|
|
|
_vlanError = true;
|
|
|
|
|
msg = string.Format(Messages.NETW_DETAILS_VLAN_RANGE, numericUpDownVLAN.Minimum, numericUpDownVLAN.Maximum);
|
|
|
|
|
}
|
|
|
|
|
else if (vlans != null && vlans.Contains(currentValue))
|
|
|
|
|
{
|
|
|
|
|
_vlanError = true;
|
|
|
|
|
msg = Messages.NETW_DETAILS_VLAN_NUMBER_IN_USE;
|
|
|
|
|
}
|
|
|
|
|
else if (currentValue == 0)
|
|
|
|
|
{
|
|
|
|
|
msg = Messages.NETW_VLAN_ZERO;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
if (_vlanError)
|
|
|
|
|
{
|
|
|
|
|
pictureBoxVlan.Image = Images.StaticImages._000_error_h32bit_16;
|
|
|
|
|
labelVlanMessage.Text = msg;
|
|
|
|
|
infoVlanPanel.Visible = true;
|
|
|
|
|
}
|
|
|
|
|
else if (!string.IsNullOrEmpty(msg))
|
|
|
|
|
{
|
|
|
|
|
pictureBoxVlan.Image = Images.StaticImages._000_Info3_h32bit_16;
|
|
|
|
|
labelVlanMessage.Text = msg;
|
|
|
|
|
infoVlanPanel.Visible = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
infoVlanPanel.Visible = false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
OnPageUpdated();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
private void ValidateMtuValue()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-02-11 16:34:55 +01:00
|
|
|
|
//CA-192746: do not call numericUpDown.Value or properties/methods that call it
|
|
|
|
|
//in the validation method, because it auto-corrects what the user has typed
|
|
|
|
|
|
|
|
|
|
_mtuError = false;
|
|
|
|
|
|
|
|
|
|
if (!int.TryParse(numericUpDownMTU.Text.Trim(), out int currentValue))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-02-11 16:34:55 +01:00
|
|
|
|
_mtuError = true;
|
|
|
|
|
pictureBoxMtu.Image = Images.StaticImages._000_error_h32bit_16;
|
|
|
|
|
labelMtuMessage.Text = Messages.INVALID_NUMBER;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (currentValue < numericUpDownMTU.Minimum || numericUpDownMTU.Maximum < currentValue)
|
|
|
|
|
_mtuError = true;
|
|
|
|
|
|
|
|
|
|
pictureBoxMtu.Image = Images.StaticImages._000_Info3_h32bit_16;
|
|
|
|
|
labelMtuMessage.Text = numericUpDownMTU.Minimum == numericUpDownMTU.Maximum
|
|
|
|
|
? string.Format(Messages.ALLOWED_MTU_VALUE, numericUpDownMTU.Minimum)
|
|
|
|
|
: string.Format(Messages.ALLOWED_MTU_RANGE, numericUpDownMTU.Minimum, numericUpDownMTU.Maximum);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
infoMtuPanel.Visible = true;
|
|
|
|
|
OnPageUpdated();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
#region Event Handlers
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private void cmbHostNicList_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-02-11 16:34:55 +01:00
|
|
|
|
if (_populatingNics || SelectedHostNic == null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return;
|
2018-03-15 20:42:01 +01:00
|
|
|
|
|
2018-03-16 17:48:16 +01:00
|
|
|
|
checkBoxSriov.Visible = SelectedHostNic.IsSriovPhysicalPIF();
|
2018-03-15 20:42:01 +01:00
|
|
|
|
|
2015-12-01 15:46:58 +01:00
|
|
|
|
numericUpDownMTU.Maximum = Math.Min(SelectedHostNic.MTU, XenAPI.Network.MTU_MAX);
|
2015-12-18 19:30:15 +01:00
|
|
|
|
numericUpDownMTU.Enabled = numericUpDownMTU.Minimum != numericUpDownMTU.Maximum;
|
2020-02-11 16:34:55 +01:00
|
|
|
|
ValidateMtuValue();
|
2015-12-04 12:22:06 +01:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
vlans = GetVLANList(SelectedHostNic);
|
|
|
|
|
|
|
|
|
|
//CA-72484: check whether the currently selected VLAN is available and keep it
|
2020-02-11 16:34:55 +01:00
|
|
|
|
if (!vlans.Contains(VLAN))
|
2014-05-20 13:38:03 +02:00
|
|
|
|
{
|
2020-02-11 16:34:55 +01:00
|
|
|
|
ValidateVLANValue();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return;
|
2014-05-20 13:38:03 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
//CA-19111: VLAN values should only go up to the numericUpDownVLAN.Maximum (4094)
|
|
|
|
|
for (int i = 1; i <= numericUpDownVLAN.Maximum; i++)
|
|
|
|
|
{
|
|
|
|
|
if (!vlans.Contains(i))
|
|
|
|
|
{
|
|
|
|
|
numericUpDownVLAN.Value = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
OnPageUpdated();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
private void numericUpDownVLAN_Leave(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-02-11 16:34:55 +01:00
|
|
|
|
if (numericUpDownVLAN.Text == "")
|
|
|
|
|
numericUpDownVLAN.Text = VLAN.ToString();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
private void numericUpDownVLAN_TextChanged(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
ValidateVLANValue();
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
private void numericUpDownVLAN_ValueChanged(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-02-11 16:34:55 +01:00
|
|
|
|
ValidateVLANValue();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
private void numericUpDownMTU_Leave(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-02-11 16:34:55 +01:00
|
|
|
|
if (numericUpDownMTU.Text == "")
|
|
|
|
|
numericUpDownMTU.Text = MTU.ToString();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
private void numericUpDownMTU_TextChanged(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-02-11 16:34:55 +01:00
|
|
|
|
ValidateMtuValue();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 16:34:55 +01:00
|
|
|
|
private void numericUpDownMTU_ValueChanged(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-02-11 16:34:55 +01:00
|
|
|
|
ValidateMtuValue();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2018-03-20 03:40:59 +01:00
|
|
|
|
|
|
|
|
|
private void checkBoxSriov_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-02-11 16:34:55 +01:00
|
|
|
|
vlans = GetVLANList(SelectedHostNic);
|
2018-03-20 03:40:59 +01:00
|
|
|
|
ValidateVLANValue();
|
|
|
|
|
}
|
2020-02-11 16:34:55 +01:00
|
|
|
|
|
|
|
|
|
#endregion
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|