diff --git a/EduNetworkBuilder/DeviceConfig.Designer.cs b/EduNetworkBuilder/DeviceConfig.Designer.cs
index 3912a9f..6f0c864 100644
--- a/EduNetworkBuilder/DeviceConfig.Designer.cs
+++ b/EduNetworkBuilder/DeviceConfig.Designer.cs
@@ -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;
}
}
\ No newline at end of file
diff --git a/EduNetworkBuilder/DeviceConfig.cs b/EduNetworkBuilder/DeviceConfig.cs
index 8b542f1..d02a547 100644
--- a/EduNetworkBuilder/DeviceConfig.cs
+++ b/EduNetworkBuilder/DeviceConfig.cs
@@ -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();
+ }
}
}
diff --git a/EduNetworkBuilder/EduNetworkBuilder.csproj b/EduNetworkBuilder/EduNetworkBuilder.csproj
index 710aee6..9bf2912 100644
--- a/EduNetworkBuilder/EduNetworkBuilder.csproj
+++ b/EduNetworkBuilder/EduNetworkBuilder.csproj
@@ -158,6 +158,13 @@
RTFWindow.cs
+
+ Form
+
+
+ VLANConfig.cs
+
+
DeviceConfig.cs
@@ -195,6 +202,9 @@
RTFWindow.cs
+
+ VLANConfig.cs
+
diff --git a/EduNetworkBuilder/NB.cs b/EduNetworkBuilder/NB.cs
index 3b0a19a..a8e722b 100644
--- a/EduNetworkBuilder/NB.cs
+++ b/EduNetworkBuilder/NB.cs
@@ -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 }
diff --git a/EduNetworkBuilder/Network.cs b/EduNetworkBuilder/Network.cs
index c8ae1d1..652db86 100644
--- a/EduNetworkBuilder/Network.cs
+++ b/EduNetworkBuilder/Network.cs
@@ -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 PacketRectangles = new List();
+ public List VlanNames = new List() { 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(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();
}
diff --git a/EduNetworkBuilder/NetworkCard.cs b/EduNetworkBuilder/NetworkCard.cs
index 8501a4b..206b3c9 100644
--- a/EduNetworkBuilder/NetworkCard.cs
+++ b/EduNetworkBuilder/NetworkCard.cs
@@ -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;
diff --git a/EduNetworkBuilder/NetworkDevice.cs b/EduNetworkBuilder/NetworkDevice.cs
index feb6671..969d434 100644
--- a/EduNetworkBuilder/NetworkDevice.cs
+++ b/EduNetworkBuilder/NetworkDevice.cs
@@ -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 arp(UInt32 IP)
{
List arps = new List();
diff --git a/EduNetworkBuilder/NetworkInterface.cs b/EduNetworkBuilder/NetworkInterface.cs
index 41932d6..250e263 100644
--- a/EduNetworkBuilder/NetworkInterface.cs
+++ b/EduNetworkBuilder/NetworkInterface.cs
@@ -14,6 +14,7 @@ namespace EduNetworkBuilder
public IPAddress myIP;
public string nic_name; //eth0, eth0:0, etc
public HostNicID AttachedToHostNic;
+ public List VLANs = new List() { 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(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();
}
diff --git a/EduNetworkBuilder/Packet.cs b/EduNetworkBuilder/Packet.cs
index 768f09c..c01961a 100644
--- a/EduNetworkBuilder/Packet.cs
+++ b/EduNetworkBuilder/Packet.cs
@@ -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;
diff --git a/EduNetworkBuilder/Resources/languages/edustrings.resx b/EduNetworkBuilder/Resources/languages/edustrings.resx
index 7d6d446..cec040a 100644
--- a/EduNetworkBuilder/Resources/languages/edustrings.resx
+++ b/EduNetworkBuilder/Resources/languages/edustrings.resx
@@ -1509,4 +1509,8 @@
Display the name and IPs of network devices
NetworkBuilder: NB_cbViewTitles = Display the name and IPs of network devices
+
+ VLANs
+ DeviceConfig bntVLAN = VLANs
+
\ No newline at end of file
diff --git a/EduNetworkBuilder/VLANConfig.Designer.cs b/EduNetworkBuilder/VLANConfig.Designer.cs
new file mode 100644
index 0000000..26164f9
--- /dev/null
+++ b/EduNetworkBuilder/VLANConfig.Designer.cs
@@ -0,0 +1,98 @@
+namespace EduNetworkBuilder
+{
+ partial class VLANConfig
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ 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;
+ }
+}
\ No newline at end of file
diff --git a/EduNetworkBuilder/VLANConfig.cs b/EduNetworkBuilder/VLANConfig.cs
new file mode 100644
index 0000000..e5754f6
--- /dev/null
+++ b/EduNetworkBuilder/VLANConfig.cs
@@ -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 VLANNames = new BindingList();
+ DataTable VlanBindings = new DataTable();
+ List interfaces = new List();
+
+ 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 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 enumvalues = new List();
+ 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 tempitem = new BindingList();
+ VLANName current = ((BindingList)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)dgv_VLANNames.DataSource)[e.RowIndex] = new VLANName { ID = id, Name = value };
+ }
+
+ }
+}
diff --git a/EduNetworkBuilder/VLANStuff.cs b/EduNetworkBuilder/VLANStuff.cs
new file mode 100644
index 0000000..9455e89
--- /dev/null
+++ b/EduNetworkBuilder/VLANStuff.cs
@@ -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;
+ }
+ }
+}