Progress on vlans

This commit is contained in:
Tim Young 2016-10-03 19:49:05 -05:00
parent 66a310f602
commit 49c771fff2
13 changed files with 378 additions and 12 deletions

View File

@ -46,7 +46,7 @@
this.btnRoutes = new System.Windows.Forms.Button();
this.cbDHCP = new System.Windows.Forms.CheckBox();
this.btnDHCP = new System.Windows.Forms.Button();
this.btn_vlan = new System.Windows.Forms.Button();
this.btnVLAN = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// tbHostname
@ -227,14 +227,15 @@
this.btnDHCP.UseVisualStyleBackColor = true;
this.btnDHCP.Click += new System.EventHandler(this.btnDHCP_Click);
//
// btn_vlan
// btnVLAN
//
this.btn_vlan.Location = new System.Drawing.Point(182, 80);
this.btn_vlan.Name = "btn_vlan";
this.btn_vlan.Size = new System.Drawing.Size(75, 23);
this.btn_vlan.TabIndex = 21;
this.btn_vlan.Text = "VLANs";
this.btn_vlan.UseVisualStyleBackColor = true;
this.btnVLAN.Location = new System.Drawing.Point(182, 80);
this.btnVLAN.Name = "btnVLAN";
this.btnVLAN.Size = new System.Drawing.Size(75, 23);
this.btnVLAN.TabIndex = 21;
this.btnVLAN.Text = "VLANs";
this.btnVLAN.UseVisualStyleBackColor = true;
this.btnVLAN.Click += new System.EventHandler(this.btnVLAN_Click);
//
// DeviceConfig
//
@ -243,7 +244,7 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size(471, 365);
this.Controls.Add(this.btn_vlan);
this.Controls.Add(this.btnVLAN);
this.Controls.Add(this.btnDHCP);
this.Controls.Add(this.cbDHCP);
this.Controls.Add(this.btnRoutes);
@ -290,6 +291,6 @@
private System.Windows.Forms.Button btnRoutes;
private System.Windows.Forms.CheckBox cbDHCP;
private System.Windows.Forms.Button btnDHCP;
private System.Windows.Forms.Button btn_vlan;
private System.Windows.Forms.Button btnVLAN;
}
}

View File

@ -56,6 +56,7 @@ namespace EduNetworkBuilder
btnRoutes.Text = NB.Translate("DC_btnRoutes");
cbDHCP.Text = NB.Translate("DC_cbDHCP");
btnDHCP.Text = NB.Translate("_DHCP");
btnVLAN.Text = NB.Translate("DC_btnVLAN");
Text = NB.Translate("DC_Form");
}
@ -70,7 +71,8 @@ namespace EduNetworkBuilder
}
if (processing) return;
processing = true;
if (ClonedItem.GetType().ToString() == "EduNetworkBuilder.NetworkDevice")
// if (ClonedItem.GetType().ToString() == "EduNetworkBuilder.NetworkDevice")
if(ClonedItem is NetworkDevice)
{
NetworkDevice ndCLonedItem = (NetworkDevice)ClonedItem;
@ -84,6 +86,10 @@ namespace EduNetworkBuilder
btnNicMinus.Visible = false;
}
if (ndCLonedItem.DoesVLANs())
btnVLAN.Visible = true;
else btnVLAN.Visible = false;
if(ndCLonedItem.CanServeDHCP)
{
if (ndCLonedItem.GetIsDHCPServer())
@ -435,6 +441,11 @@ namespace EduNetworkBuilder
}
UpdateForm();
}
private void btnVLAN_Click(object sender, EventArgs e)
{
VLANConfig VLC = new VLANConfig((NetworkDevice)ClonedItem);
VLC.ShowDialog();
}
}
}

View File

@ -158,6 +158,13 @@
<Compile Include="RTFWindow.Designer.cs">
<DependentUpon>RTFWindow.cs</DependentUpon>
</Compile>
<Compile Include="VLANConfig.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="VLANConfig.Designer.cs">
<DependentUpon>VLANConfig.cs</DependentUpon>
</Compile>
<Compile Include="VLANStuff.cs" />
<EmbeddedResource Include="DeviceConfig.resx">
<DependentUpon>DeviceConfig.cs</DependentUpon>
</EmbeddedResource>
@ -195,6 +202,9 @@
<EmbeddedResource Include="RTFWindow.resx">
<DependentUpon>RTFWindow.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="VLANConfig.resx">
<DependentUpon>VLANConfig.cs</DependentUpon>
</EmbeddedResource>
<None Include="EduNetworkBuilder_1_TemporaryKey.pfx" />
<None Include="EduNetworkBuilder_TemporaryKey.pfx" />
<None Include="Properties\Settings.settings">

View File

@ -27,6 +27,7 @@ namespace EduNetworkBuilder
finished_failed, //The packet is finished (failed) and is ready to be removed from the network.
finished //There was an appropriate reason this packet finished. It stopped
}
public enum VLANTagType { Tagged, Untagged, Forbidden }
public enum LinkType { normal, wireless, broken }
public enum PacketType { none, ping_request, ping_answer, arp_request, arp_answer, dhcp_request, dhcp_answer, vpn_packet, tun_packet }
public enum ResponseToPacket { none, accept, masq, drop, reject }

View File

@ -8,6 +8,7 @@ using System.Windows.Forms;
using System.Xml;
using System.IO;
using System.Text.RegularExpressions;
using System.ComponentModel;
namespace EduNetworkBuilder
@ -49,6 +50,7 @@ namespace EduNetworkBuilder
private int DefaultTimeout = 10;
private int NumberOfSecondsForTimeout = 10;
private List<Rectangle> PacketRectangles = new List<Rectangle>();
public List<VLANName> VlanNames = new List<VLANName>() { new VLANName(1,"Default") };
private bool previously_had_packets = false; //used on "tick" to determine if we are starting from scratch
@ -169,6 +171,15 @@ namespace EduNetworkBuilder
StartingHelpLevel = NB.ParseEnum<NetTestVerbosity>(Individual.InnerText);
HintsToDisplay = StartingHelpLevel;
break;
case "vlanname":
if (Individual.Attributes != null && Individual.Attributes["ID"] != null)
{
int ID;
int.TryParse(Individual.Attributes["ID"].Value, out ID);
if(ID>1)
VlanNames.Add(new VLANName(ID, Individual.InnerText));
}
break;
default:
if(Regex.IsMatch(Individual.Name.ToLower(),"message"))
{
@ -269,6 +280,13 @@ namespace EduNetworkBuilder
{
writer.WriteElementString("tag",HT.ToString());
}
foreach(VLANName VLAN in VlanNames)
{
writer.WriteStartElement("VLANName");
writer.WriteAttributeString("ID", VLAN.ID.ToString());
writer.WriteString(VLAN.Name);
writer.WriteEndElement();
}
writer.WriteEndElement();
}

View File

@ -33,6 +33,8 @@ namespace EduNetworkBuilder
set { EncryptionKey = value; }
}
public int IFCount { get { return interfaces.Count; } }
public NetworkCard(int index, int HostID, string hostname, NicType theType = NicType.eth)
{
myNicType = theType;

View File

@ -1072,6 +1072,15 @@ namespace EduNetworkBuilder
return false;
}
public bool DoesVLANs()
{
if (myType == NetworkComponentType.net_switch)
return true;
if (myType == NetworkComponentType.wrouter)
return true;
return false;
}
public override List<string> arp(UInt32 IP)
{
List<string> arps = new List<string>();

View File

@ -14,6 +14,7 @@ namespace EduNetworkBuilder
public IPAddress myIP;
public string nic_name; //eth0, eth0:0, etc
public HostNicID AttachedToHostNic;
public List<VLANInfo> VLANs = new List<VLANInfo>() { new VLANInfo(1, VLANTagType.Untagged ) };
//We should have a feature: none, IP_in_IP_Tunnel, encrypted_vpn, vlan, etc
public NetworkInterface(string name, string IP, string Mask, HostNicID AttachedTo)
{
@ -38,16 +39,51 @@ namespace EduNetworkBuilder
case "nicname":
nic_name = Individual.InnerText;
break;
case "vlan":
if (Individual.Attributes != null && Individual.Attributes["ID"] != null)
{
int ID;
VLANTagType Tag = NB.TryParseEnum<VLANTagType>(Individual.InnerText, VLANTagType.Untagged);
int.TryParse(Individual.Attributes["ID"].Value, out ID);
VLANInfo current = GetVLANInfo(ID);
if (current != null) VLANs.Remove(current); //we are replacing it
VLANs.Add(new VLANInfo(ID, Tag));
}
break;
}
}
}
}
public VLANInfo GetVLANInfo(int id)
{
foreach(VLANInfo one in VLANs)
{
if (one.ID == id)
return one;
}
return null;
}
public VLANTagType GetVLANTag(int id)
{
VLANInfo vli = GetVLANInfo(id);
if (vli != null) return vli.Tag;
return VLANTagType.Forbidden; //if not defined, it is forbidden
}
public void Save(XmlWriter writer)
{
writer.WriteStartElement("interface");
writer.WriteElementString("nicname", nic_name);
myIP.Save(writer, "myip");
foreach (VLANInfo one in VLANs)
{
writer.WriteStartElement("VLAN");
writer.WriteAttributeString("ID", one.ID.ToString());
writer.WriteString(one.Tag.ToString());
writer.WriteEndElement();
}
writer.WriteEndElement();
}

View File

@ -36,6 +36,7 @@ namespace EduNetworkBuilder
}
}
public int packetID;
public int VLANID = 1; //starts on the management vlan
public int TTL = 20;
public int TickTTL = 50;
public int health = 100;

View File

@ -1509,4 +1509,8 @@
<value>Display the name and IPs of network devices</value>
<comment>NetworkBuilder: NB_cbViewTitles = Display the name and IPs of network devices</comment>
</data>
<data name="DC_btnVLAN" xml:space="preserve">
<value>VLANs</value>
<comment>DeviceConfig bntVLAN = VLANs</comment>
</data>
</root>

98
EduNetworkBuilder/VLANConfig.Designer.cs generated Normal file
View File

@ -0,0 +1,98 @@
namespace EduNetworkBuilder
{
partial class VLANConfig
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dgv_VLANAssignments = new System.Windows.Forms.DataGridView();
this.dgv_VLANNames = new System.Windows.Forms.DataGridView();
this.btnDone = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dgv_VLANAssignments)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dgv_VLANNames)).BeginInit();
this.SuspendLayout();
//
// dgv_VLANAssignments
//
this.dgv_VLANAssignments.AllowUserToAddRows = false;
this.dgv_VLANAssignments.AllowUserToDeleteRows = false;
this.dgv_VLANAssignments.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dgv_VLANAssignments.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgv_VLANAssignments.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter;
this.dgv_VLANAssignments.Location = new System.Drawing.Point(12, 169);
this.dgv_VLANAssignments.Name = "dgv_VLANAssignments";
this.dgv_VLANAssignments.RowTemplate.Height = 24;
this.dgv_VLANAssignments.Size = new System.Drawing.Size(313, 195);
this.dgv_VLANAssignments.TabIndex = 0;
//
// dgv_VLANNames
//
this.dgv_VLANNames.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dgv_VLANNames.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgv_VLANNames.Location = new System.Drawing.Point(12, 12);
this.dgv_VLANNames.Name = "dgv_VLANNames";
this.dgv_VLANNames.RowTemplate.Height = 24;
this.dgv_VLANNames.Size = new System.Drawing.Size(313, 151);
this.dgv_VLANNames.TabIndex = 1;
this.dgv_VLANNames.CellParsing += new System.Windows.Forms.DataGridViewCellParsingEventHandler(this.dgv_VLANNames_CellParsing);
//
// btnDone
//
this.btnDone.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnDone.Location = new System.Drawing.Point(249, 370);
this.btnDone.Name = "btnDone";
this.btnDone.Size = new System.Drawing.Size(75, 23);
this.btnDone.TabIndex = 2;
this.btnDone.Text = "Done";
this.btnDone.UseVisualStyleBackColor = true;
this.btnDone.Click += new System.EventHandler(this.btnDone_Click);
//
// VLANConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(334, 398);
this.Controls.Add(this.btnDone);
this.Controls.Add(this.dgv_VLANNames);
this.Controls.Add(this.dgv_VLANAssignments);
this.Name = "VLANConfig";
this.Text = "VLANConfig";
((System.ComponentModel.ISupportInitialize)(this.dgv_VLANAssignments)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dgv_VLANNames)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataGridView dgv_VLANAssignments;
private System.Windows.Forms.DataGridView dgv_VLANNames;
private System.Windows.Forms.Button btnDone;
}
}

View File

@ -0,0 +1,119 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace EduNetworkBuilder
{
public partial class VLANConfig : Form
{
NetworkDevice TheDevice = null;
BindingList<VLANName> VLANNames = new BindingList<VLANName>();
DataTable VlanBindings = new DataTable();
List<NetworkInterface> interfaces = new List<NetworkInterface>();
public VLANConfig(NetworkDevice ToEdit)
{
InitializeComponent();
TheDevice = ToEdit;
LocalSetup();
}
private void LocalSetup()
{
//Bind the vlan names
Network theNet = NB.GetNetwork();
//var _VLANNames = from row in theNet.VlanNames select new { VLAN_ID = row.Key, VLAN_Name = row.Value };
//dgv_VLANNames.DataSource = _VLANNames.ToArray();
theNet.VlanNames.Sort((x, y) => x.ID.CompareTo(y.ID));
dgv_VLANNames.DataSource = theNet.VlanNames;
//dgv_VLANNames.Columns.Add("ID", "ID");
//dgv_VLANNames.Columns.Add("Name", "Name");
dgv_VLANNames.AllowUserToAddRows = true;
VlanBindings.Clear();
VlanBindings.Columns.Add("IF", typeof(string));
foreach(VLANName vn in theNet.VlanNames)
{
VlanBindings.Columns.Add(vn.Name, typeof(string));
}
List<string> theNics = TheDevice.NICNames();
foreach(string oneNic in theNics)
{
NetworkCard NIC = TheDevice.NicFromName(oneNic);
if (NIC.NicName() == NicType.lo.ToString()) continue;
if (NIC.NicName() == NicType.management_interface.ToString()) continue;
for (int i=0; i< NIC.IFCount; i++)
{
NetworkInterface nif = NIC.GetInterface(i);
DataRow DR = VlanBindings.NewRow();
DR["IF"] = nif.nic_name;
foreach (VLANName vn in theNet.VlanNames)
{
DR[vn.Name] = nif.GetVLANTag(vn.ID).ToString();
}
VlanBindings.Rows.Add(DR);
}
}
dgv_VLANAssignments.AutoGenerateColumns = false;
//dgv_VLANAssignments.Columns.Add("IF","IF");
DataGridViewTextBoxColumn scol = new DataGridViewTextBoxColumn();
scol.ValueType = typeof(string);
scol.DataPropertyName = "IF";
scol.Name = "IF";
scol.HeaderText = "Interface";
scol.ReadOnly = true;
scol.Frozen = true;
dgv_VLANAssignments.Columns.Add(scol);
List<string> enumvalues = new List<string>();
foreach (VLANTagType vtt in Enum.GetValues(typeof(VLANTagType)))
enumvalues.Add(vtt.ToString());
foreach (VLANName vn in theNet.VlanNames)
{
DataGridViewComboBoxColumn col = new DataGridViewComboBoxColumn();
col.Name = vn.Name;
col.DataPropertyName = vn.Name;
col.DataSource = enumvalues;
col.Width = 75;
dgv_VLANAssignments.Columns.Add(col);
}
dgv_VLANAssignments.DataSource = VlanBindings;
}
private void btnDone_Click(object sender, EventArgs e)
{
//We will probably do a lot more than this later.
Close();
}
private void dgv_VLANNames_CellParsing(object sender, DataGridViewCellParsingEventArgs e)
{
// BindingList<VLANName> tempitem = new BindingList<VLANName>();
VLANName current = ((BindingList<VLANName>)dgv_VLANNames.DataSource)[e.RowIndex];
string key = current.ID.ToString();
int id = current.ID;
string value = current.Name;
string cellValue = e.Value.ToString();
if (e.ColumnIndex == 0) key = cellValue;
else value = cellValue;
((BindingList<VLANName>)dgv_VLANNames.DataSource)[e.RowIndex] = new VLANName { ID = id, Name = value };
}
}
}

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
namespace EduNetworkBuilder
{
[Serializable]
public class VLANName
{
public int _ID;
[DisplayName("ID")]
public int ID { get { return _ID; } set { _ID = value; } }
public string _Name;
[DisplayName("Name")]
public string Name { get { return _Name; } set { _Name = value; } }
public VLANName()
{
}
public VLANName(int id, string name)
{
ID = id;
Name = name;
}
}
[Serializable]
public class VLANInfo
{
public int _ID;
[DisplayName("ID")]
public int ID { get { return _ID; } set { _ID = value; } }
public VLANTagType _Tag;
[DisplayName("Tag")]
public VLANTagType Tag { get { return _Tag; } set { _Tag = value; } }
public VLANInfo()
{
}
public VLANInfo(int id, VLANTagType tag)
{
ID = id;
Tag = tag;
}
}
}