0% found this document useful (0 votes)
40 views

Source Code

This code sample defines a Windows form application with multiple classes, controls, labels, buttons, text boxes, and timers. It initializes the form components, handles events like button clicks, and contains code for tasks like topology discovery, distance calculation, and routing path preparation between nodes.

Uploaded by

ram
Copyright
© © All Rights Reserved
0% found this document useful (0 votes)
40 views

Source Code

This code sample defines a Windows form application with multiple classes, controls, labels, buttons, text boxes, and timers. It initializes the form components, handles events like button clicks, and contains code for tasks like topology discovery, distance calculation, and routing path preparation between nodes.

Uploaded by

ram
Copyright
© © All Rights Reserved
You are on page 1/ 19

SAMPLE CODE

Using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.Threading;
namespace simulator
{

public class Form1 : System.Windows.Forms.Form


{
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox txtMobileQty;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label label5;
private Button button14;
private TextBox textBox4;
private Label label7;
private ListBox listBox1;
private OpenFileDialog openFileDialog1;
private Label label4;
private TextBox textBox1;
private Label label1;
private TextBox textBox2;
private Label label2;
private Label label6;
private Button button6;
private Label label12;
private Button button1;
private Button button4;
private Button button5;
private Button button7;
private Button button8;
private GroupBox groupBox3;
private Label label9;
private RichTextBox richTextBox1;
private Label label14;
private Label label13;
private System.Windows.Forms.Timer timer1;
private Label label3;
private TextBox textBox5;
private System.Windows.Forms.Timer timer2;
private System.Windows.Forms.Timer timer3;
private System.Windows.Forms.Timer timer4;
private GroupBox groupBox4;
private Button button9;
private Button button11;
private Button button10;
private GroupBox groupBox5;
private Button button13;
private System.Windows.Forms.Timer timer5;

1
private System.Windows.Forms.Timer timer6;
private System.ComponentModel.IContainer components;

public Form1()
{

InitializeComponent();

protected override void Dispose( bool disposing )


{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code

private void InitializeComponent()


{
this.components = new System.ComponentModel.Container();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.button2 = new System.Windows.Forms.Button();
this.txtMobileQty = new System.Windows.Forms.TextBox();
this.button3 = new System.Windows.Forms.Button();
this.textBox3 = new System.Windows.Forms.TextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.button6 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.button14 = new System.Windows.Forms.Button();
this.textBox4 = new System.Windows.Forms.TextBox();
this.label7 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.listBox1 = new System.Windows.Forms.ListBox();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.label4 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label12 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.button7 = new System.Windows.Forms.Button();
this.button8 = new System.Windows.Forms.Button();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.label9 = new System.Windows.Forms.Label();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.label14 = new System.Windows.Forms.Label();
this.label13 = new System.Windows.Forms.Label();
this.timer1 = new System.Windows.Forms.Timer(this.components);
2
this.label3 = new System.Windows.Forms.Label();
this.textBox5 = new System.Windows.Forms.TextBox();
this.timer2 = new System.Windows.Forms.Timer(this.components);
this.timer3 = new System.Windows.Forms.Timer(this.components);
this.timer4 = new System.Windows.Forms.Timer(this.components);
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.button9 = new System.Windows.Forms.Button();
this.button11 = new System.Windows.Forms.Button();
this.button10 = new System.Windows.Forms.Button();
this.groupBox5 = new System.Windows.Forms.GroupBox();
this.button13 = new System.Windows.Forms.Button();
this.timer5 = new System.Windows.Forms.Timer(this.components);
this.timer6 = new System.Windows.Forms.Timer(this.components);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.groupBox4.SuspendLayout();
this.groupBox5.SuspendLayout();
this.SuspendLayout();
this.pictureBox1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))),
((int)(((byte)(224)))));
this.pictureBox1.Location = new System.Drawing.Point(532, 82);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(400, 400);
this.pictureBox1.TabIndex = 1;
this.pictureBox1.TabStop = false;
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
this.button2.Font = new System.Drawing.Font("Times New Roman", 9F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button2.Location = new System.Drawing.Point(215, 49);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(125, 28);
this.button2.TabIndex = 2;
this.button2.Text = "Topology Discovery";
this.button2.Click += new System.EventHandler(this.button2_Click);
this.txtMobileQty.Location = new System.Drawing.Point(216, 21);
this.txtMobileQty.Name = "txtMobileQty";
this.txtMobileQty.Size = new System.Drawing.Size(124, 22);
this.txtMobileQty.TabIndex = 3;
this.txtMobileQty.Text = "10";
this.txtMobileQty.TextChanged += new System.EventHandler(this.txtMobileQty_TextChanged);
this.button3.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button3.Location = new System.Drawing.Point(217, 156);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(125, 26);
this.button3.TabIndex = 4;
this.button3.Text = "Calculate Distance";
this.button3.Click += new System.EventHandler(this.button3_Click);
this.textBox3.Location = new System.Drawing.Point(232, 545);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(1, 22);
this.textBox3.TabIndex = 11;
this.textBox3.Text = "textBox3";
this.groupBox1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)
(((byte)(224)))));
this.groupBox1.Controls.Add(this.button6);
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Controls.Add(this.label1);
3
this.groupBox1.Controls.Add(this.textBox2);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Font = new System.Drawing.Font("Times New Roman", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.groupBox1.ForeColor = System.Drawing.Color.Blue;
this.groupBox1.Location = new System.Drawing.Point(2, 253);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(375, 132);
this.groupBox1.TabIndex = 18;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Routing Path Preperation";
this.button6.Location = new System.Drawing.Point(214, 94);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(125, 26);
this.button6.TabIndex = 57;
this.button6.Text = "Path Calculation";
this.button6.UseVisualStyleBackColor = true;
this.button6.Click += new System.EventHandler(this.button6_Click);
this.textBox1.Enabled = false;
this.textBox1.Location = new System.Drawing.Point(216, 24);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 22);
this.textBox1.TabIndex = 11;
this.textBox1.Text = "6";
this.label1.Location = new System.Drawing.Point(13, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(172, 23);
this.label1.TabIndex = 13;
this.label1.Text = "Enter Source Node";
this.textBox2.Enabled = false;
this.textBox2.Location = new System.Drawing.Point(215, 57);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(100, 22);
this.textBox2.TabIndex = 12;
this.textBox2.Text = "9";
this.label2.Location = new System.Drawing.Point(13, 60);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(170, 23);
this.label2.TabIndex = 14;
this.label2.Text = "Enter Destination Node";
this.groupBox2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)
(((byte)(224)))));
this.groupBox2.Controls.Add(this.button14);
this.groupBox2.Controls.Add(this.textBox4);
this.groupBox2.Controls.Add(this.label7);
this.groupBox2.Controls.Add(this.button3);
this.groupBox2.Controls.Add(this.label5);
this.groupBox2.Controls.Add(this.txtMobileQty);
this.groupBox2.Controls.Add(this.button2);
this.groupBox2.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.groupBox2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(64)))), ((int)
(((byte)(0)))));
this.groupBox2.Location = new System.Drawing.Point(1, 41);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(375, 204);
this.groupBox2.TabIndex = 19;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Node Preperation";

4
this.button14.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button14.Location = new System.Drawing.Point(216, 122);
this.button14.Name = "button14";
this.button14.Size = new System.Drawing.Size(125, 28);
this.button14.TabIndex = 7;
this.button14.Text = "Display Range";
this.button14.Click += new System.EventHandler(this.button14_Click);
this.textBox4.Location = new System.Drawing.Point(217, 93);
this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(124, 22);
this.textBox4.TabIndex = 6;
this.label7.Location = new System.Drawing.Point(9, 97);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(186, 23);
this.label7.TabIndex = 5;
this.label7.Text = "Enter Coverage Range";
this.label5.Location = new System.Drawing.Point(8, 24);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(175, 23);
this.label5.TabIndex = 0;
this.label5.Text = "Enter Number of Nodes";
this.listBox1.Font = new System.Drawing.Font("Times New Roman", 8.25F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.listBox1.FormattingEnabled = true;
this.listBox1.Location = new System.Drawing.Point(386, 82);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(130, 303);
this.listBox1.TabIndex = 24;
this.openFileDialog1.FileName = "openFileDialog1";
this.label4.BackColor = System.Drawing.Color.Blue;
this.label4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label4.Font = new System.Drawing.Font("Calibri", 15.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label4.ForeColor = System.Drawing.Color.White;
this.label4.Location = new System.Drawing.Point(0, -1);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(956, 40);
this.label4.TabIndex = 49;
this.label4.Text = "Detection of Selfish Misbehavior in Delay Tolerant Network Using Trust Authority";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label6.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label6.Location = new System.Drawing.Point(400, 56);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(97, 23);
this.label6.TabIndex = 50;
this.label6.Text = "Nodes Distance";
this.label12.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label12.Location = new System.Drawing.Point(611, 56);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(244, 23);
this.label12.TabIndex = 56;
this.label12.Text = "Delay Tolerant Network Nodes";
this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.button1.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button1.Location = new System.Drawing.Point(6, 21);
this.button1.Name = "button1";
5
this.button1.Size = new System.Drawing.Size(123, 26);
this.button1.TabIndex = 58;
this.button1.Text = "Node Registration";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click_1);
this.button4.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button4.Location = new System.Drawing.Point(135, 21);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(99, 26);
this.button4.TabIndex = 59;
this.button4.Text = "Create Packet";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.button4_Click);
this.button5.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button5.Location = new System.Drawing.Point(240, 21);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(121, 26);
this.button5.TabIndex = 60;
this.button5.Text = "Routing Evidence";
this.button5.UseVisualStyleBackColor = true;
this.button5.Click += new System.EventHandler(this.button5_Click_1);
this.button7.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button7.Location = new System.Drawing.Point(6, 56);
this.button7.Name = "button7";
this.button7.Size = new System.Drawing.Size(176, 26);
this.button7.TabIndex = 61;
this.button7.Text = "Forwarding History Evidence";
this.button7.UseVisualStyleBackColor = true;
this.button7.Click += new System.EventHandler(this.button7_Click_1);
this.button8.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button8.Location = new System.Drawing.Point(190, 56);
this.button8.Name = "button8";
this.button8.Size = new System.Drawing.Size(171, 26);
this.button8.TabIndex = 62;
this.button8.Text = "Contact History Evidence";
this.button8.UseVisualStyleBackColor = true;
this.button8.Click += new System.EventHandler(this.button8_Click_1);
this.groupBox3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)
(((byte)(224)))));
this.groupBox3.Controls.Add(this.button4);
this.groupBox3.Controls.Add(this.button8);
this.groupBox3.Controls.Add(this.button1);
this.groupBox3.Controls.Add(this.button7);
this.groupBox3.Controls.Add(this.button5);
this.groupBox3.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.groupBox3.ForeColor = System.Drawing.Color.Blue;
this.groupBox3.Location = new System.Drawing.Point(2, 391);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(375, 101);
this.groupBox3.TabIndex = 63;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Routing Model";
this.label9.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label9.Location = new System.Drawing.Point(386, 390);
6
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(130, 23);
this.label9.TabIndex = 65;
this.label9.Text = "Packet Information";
this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.label9.Click += new System.EventHandler(this.label9_Click);
this.richTextBox1.Font = new System.Drawing.Font("Times New Roman", 8.25F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.richTextBox1.Location = new System.Drawing.Point(386, 416);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(130, 76);
this.richTextBox1.TabIndex = 64;
this.richTextBox1.Text = "";
this.richTextBox1.TextChanged += new System.EventHandler(this.richTextBox1_TextChanged);
this.label14.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label14.Location = new System.Drawing.Point(744, 497);
this.label14.Name = "label14";
this.label14.Size = new System.Drawing.Size(123, 23);
this.label14.TabIndex = 117;
this.label14.Text = "Checking.....";
this.label13.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label13.Location = new System.Drawing.Point(605, 495);
this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(123, 23);
this.label13.TabIndex = 116;
this.label13.Text = "Transmission Status";
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
this.label3.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label3.Location = new System.Drawing.Point(544, 559);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(80, 19);
this.label3.TabIndex = 118;
this.label3.Text = "Start Time";
this.textBox5.Enabled = false;
this.textBox5.Location = new System.Drawing.Point(630, 555);
this.textBox5.Name = "textBox5";
this.textBox5.Size = new System.Drawing.Size(42, 22);
this.textBox5.TabIndex = 119;
this.textBox5.Text = "0";
this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
this.timer3.Tick += new System.EventHandler(this.timer3_Tick);
this.timer4.Tick += new System.EventHandler(this.timer4_Tick);
this.groupBox4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)
(((byte)(224)))));
this.groupBox4.Controls.Add(this.button10);
this.groupBox4.Controls.Add(this.button9);
this.groupBox4.Controls.Add(this.button11);
this.groupBox4.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.groupBox4.ForeColor = System.Drawing.Color.Blue;
this.groupBox4.Location = new System.Drawing.Point(2, 498);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(375, 56);
this.groupBox4.TabIndex = 120;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "Threat Model";

7
this.button9.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button9.Location = new System.Drawing.Point(6, 21);
this.button9.Name = "button9";
this.button9.Size = new System.Drawing.Size(99, 26);
this.button9.TabIndex = 59;
this.button9.Text = "Broadcast";
this.button9.UseVisualStyleBackColor = true;
this.button9.Click += new System.EventHandler(this.button9_Click_1);
this.button11.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button11.Location = new System.Drawing.Point(216, 21);
this.button11.Name = "button11";
this.button11.Size = new System.Drawing.Size(123, 26);
this.button11.TabIndex = 58;
this.button11.Text = "Trusted Authority";
this.button11.UseVisualStyleBackColor = true;
this.button11.Click += new System.EventHandler(this.button11_Click);
this.button10.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button10.Location = new System.Drawing.Point(111, 21);
this.button10.Name = "button10";
this.button10.Size = new System.Drawing.Size(99, 26);
this.button10.TabIndex = 60;
this.button10.Text = "Forwarded";
this.button10.UseVisualStyleBackColor = true;
this.button10.Click += new System.EventHandler(this.button10_Click_1);
this.groupBox5.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)
(((byte)(224)))));
this.groupBox5.Controls.Add(this.button13);
this.groupBox5.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.groupBox5.ForeColor = System.Drawing.Color.Blue;
this.groupBox5.Location = new System.Drawing.Point(2, 560);
this.groupBox5.Name = "groupBox5";
this.groupBox5.Size = new System.Drawing.Size(375, 56);
this.groupBox5.TabIndex = 121;
this.groupBox5.TabStop = false;
this.groupBox5.Text = "Performance";
this.button13.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button13.Location = new System.Drawing.Point(6, 21);
this.button13.Name = "button13";
this.button13.Size = new System.Drawing.Size(99, 26);
this.button13.TabIndex = 59;
this.button13.Text = "Detection Rate";
this.button13.UseVisualStyleBackColor = true;
this.button13.Click += new System.EventHandler(this.button13_Click_1);
this.timer5.Tick += new System.EventHandler(this.timer5_Tick);
this.timer6.Tick += new System.EventHandler(this.timer6_Tick);
this.AutoScrollMargin = new System.Drawing.Size(12, 15);
this.BackColor = System.Drawing.Color.Snow;
this.CausesValidation = false;
this.ClientSize = new System.Drawing.Size(952, 628);
this.Controls.Add(this.groupBox5);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.textBox5);
this.Controls.Add(this.label3);
this.Controls.Add(this.label14);
this.Controls.Add(this.label13);
8
this.Controls.Add(this.label9);
this.Controls.Add(this.richTextBox1);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.label12);
this.Controls.Add(this.label6);
this.Controls.Add(this.label4);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.pictureBox1);
this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.HelpButton = true;
this.KeyPreview = true;
this.Location = new System.Drawing.Point(20, 20);
this.Name = "Form1";
this.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Tag = "Glade";
this.Text = "Misbehaviour Detection";
this.TransparencyKey = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)
(192)))));
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.groupBox3.ResumeLayout(false);
this.groupBox4.ResumeLayout(false);
this.groupBox5.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();

}
#endregion

static void Main()


{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)


{

}
Graphics g;
Bitmap bmp;
int x1;
int x2;
int x3;
private void pictureBox1_Click(object sender, System.EventArgs e)
{
int xmouse = MousePosition.X;
int y = MousePosition.Y;

}
Mobile[] ob;
9
double[,] Distance;
int MaxMobile=0;
int MaxMobile1 = 0;
double[,] Distance1;
Mobile[] ob1;
int x;
private void distancedd()
{
for (int i = 0; i < MaxMobile1; i++)
{
for (int j = 0; j < MaxMobile1; j++)
{
if (i != j)
{
Distance1[i, j] = Dist.CalcDist(ob1[i].x, ob1[i].y, ob1[j].x, ob1[j].y);
}
else
{
Distance1[i, j] = 0;
}
}
}
}

private void pathdesgin()


{
MaxMobile1 = 3;
RouteDiscover.MAX = MaxMobile1;
Distance1 = new double[MaxMobile1, MaxMobile1];

int i = 0;
ob1 = new Mobile[MaxMobile1];
int[] rx = new int[] { 200, 225, 350 };
int[] ry = new int[] { 200, 300, 260 };
for (i = 0; i < ob1.Length; i++)
{
ob1[i] = new Mobile();
ob1[i].x = rx[i];
ob1[i].y = ry[i];
ob1[i].x = rx[i];
ob1[i].startx = ob[i].x;
ob1[i].starty = ob[i].y;

}
private void button2_Click(object sender, System.EventArgs e)
{

MaxMobile = int.Parse(txtMobileQty.Text);
RouteDiscover.MAX = MaxMobile;
Distance = new double[MaxMobile, MaxMobile];
int i = 0;
ob = new Mobile[MaxMobile];
int[] rx = new int[] { 200, 125, 275, 100, 200, 300, 30, 125, 225, 350 };
int[] ry = new int[] { 40, 100, 100, 200, 200, 200, 260, 300, 300, 260 };

10
for (i = 0; i < ob.Length; i++)
{
ob[i] = new Mobile();
ob[i].x = rx[i];
ob[i].y = ry[i];
ob[i].x = rx[i];
ob[i].startx = ob[i].x;
ob[i].starty = ob[i].y;

}
treetopolgy();

}
private void treetopolgy()
{
bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
g = Graphics.FromImage(bmp);
pictureBox1.Image = bmp;
g.DrawLine(new Pen(new SolidBrush(Color.YellowGreen), 2), 0, 0, pictureBox1.Width, 0);
g.DrawLine(new Pen(new SolidBrush(Color.YellowGreen), 2), 0, 0, 0, pictureBox1.Height);
g.DrawLine(new Pen(new SolidBrush(Color.YellowGreen), 2), 0, pictureBox1.Height, pictureBox1.Width,
pictureBox1.Height);
g.DrawLine(new Pen(new SolidBrush(Color.YellowGreen), 2), pictureBox1.Width, 0, pictureBox1.Width,
pictureBox1.Height);

int var = 20;


for (int i = 0; (i * var + 10) <= pictureBox1.Width - 10; i++)
{

}
for (int j = 0; (j * var + 10) <= pictureBox1.Height - 10; j++)
{

for (int i = 1; i < ob.Length; i++)


{
g.DrawRectangle(new Pen(new SolidBrush(Color.Black), 4), ob[i].x, ob[i].y, 2, 2);
g.DrawString("N" + i.ToString(), new Font("Times New Roman", 8), new SolidBrush(Color.Red), ob[i].x + 4,
ob[i].y + 4);

}
for (int i = 0; i < 1; i++)
{
g.DrawEllipse(new Pen(new SolidBrush(Color.Blue), 25), ob[i].x, ob[i].y, 25, 25);
g.DrawString("TA", new Font("Times New Roman", 10), new SolidBrush(Color.White), ob[i].x+5 ,
ob[i].y+5 );
}

private void button3_Click(object sender, System.EventArgs e)


{
for(int i=0;i<MaxMobile;i++)
{
for(int j=0;j<MaxMobile;j++)
{
if(i!=j)
11
{
Distance[i,j]=Dist.CalcDist(ob[i].x,ob[i].y,ob[j].x,ob[j].y);

listBox1.Items.Add("i=" + i.ToString() + " j=" + j.ToString() + " " + " Dist=" + Math.Floor(Distance[i, j]));
}
else
{
Distance[i,j]=0;
}

}
}

}
int []paths;
int Control=0;
void RePath()
{

private void txtMobileQty_TextChanged(object sender, System.EventArgs e)


{

private void button7_Click(object sender, System.EventArgs e)


{

private void button8_Click(object sender, System.EventArgs e)


{

private void button10_Click(object sender, System.EventArgs e)


{

private void button12_Click(object sender, EventArgs e)


{

private void button13_Click(object sender, EventArgs e)


{
12
}

private void button14_Click(object sender, EventArgs e)


{
if (textBox4.Text == "")
{
MessageBox.Show("Enter Coverage Range");
}
else
{
bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
g = Graphics.FromImage(bmp);
pictureBox1.Image = bmp;
g.DrawLine(new Pen(new SolidBrush(Color.YellowGreen), 2), 0, 0, pictureBox1.Width, 0);
g.DrawLine(new Pen(new SolidBrush(Color.YellowGreen), 2), 0, 0, 0, pictureBox1.Height);
g.DrawLine(new Pen(new SolidBrush(Color.YellowGreen), 2), 0, pictureBox1.Height, pictureBox1.Width,
pictureBox1.Height);
g.DrawLine(new Pen(new SolidBrush(Color.YellowGreen), 2), pictureBox1.Width, 0, pictureBox1.Width,
pictureBox1.Height);
int var = 20;
for (int i = 0; (i * var + 10) <= pictureBox1.Width - 10; i++)
{
for (int j = 0; (j * var + 10) <= pictureBox1.Height - 10; j++)

for (int i = 1; i < ob.Length; i++)


{
g.DrawRectangle(new Pen(new SolidBrush(Color.Black), 4), ob[i].x, ob[i].y, 2, 2);
g.DrawString("N" + i.ToString(), new Font("Times New Roman", 8), new SolidBrush(Color.Red), ob[i].x +
4, ob[i].y + 4);

}
for (int i = 0; i < 1; i++)
{
g.DrawEllipse(new Pen(new SolidBrush(Color.Blue), 25), ob[i].x, ob[i].y, 25, 25);
g.DrawString("TA", new Font("Times New Roman", 10), new SolidBrush(Color.White), ob[i].x + 5, ob[i].y
+ 5);
}
for (int i = 1; i < ob.Length; i++)
{

g.FillEllipse(Brushes.Blue, ob[i].x, ob[i].y, 4, 4);


g.DrawEllipse(Pens.Black, ob[i].x - 40, ob[i].y - 40, Convert.ToInt32(textBox4.Text),
Convert.ToInt32(textBox4.Text));

}
}
}

private void groupBox3_Enter(object sender, EventArgs e)


{

13
private void button1_Click(object sender, EventArgs e)
{

private void button6_Click(object sender, EventArgs e)


{
if (textBox1.Text == "")
{
MessageBox.Show("Enter Source Node");
}
else if (textBox2.Text == "")
{
MessageBox.Show("Enter Destination Node");
}
else
{
int src, dst;
src = int.Parse(textBox1.Text);
dst = int.Parse(textBox2.Text);
try
{
RREQ req = new RREQ(0, src, dst, 50, 0);
RouteDiscover rd = new RouteDiscover();
paths = rd.Discover(req, Distance);
for (int i = 0; i < paths.Length - 1; i++)
{
MessageBox.Show("Next Hop", "Shortest Path");
g.DrawLine(new Pen(new SolidBrush(Color.Red), 05), ob[paths[i]].x, ob[paths[i]].y, ob[paths[i + 1]].x,
ob[paths[i + 1]].y);
pictureBox1.Image = bmp;
}
}
catch (Exception ex)
{
}
}
}

private void button1_Click_1(object sender, EventArgs e)


{

node_reg frm = new node_reg();


frm.ShowDialog();

private void button4_Click(object sender, EventArgs e)


{
Create_Packet frm = new Create_Packet();
frm.ShowDialog();
System.IO.StreamReader file =
new System.IO.StreamReader(Application.StartupPath + "\\packet.txt");
string linetotext = file.ReadLine().ToString();
richTextBox1.Text = linetotext.ToString();
timer1.Start();
timer1.Interval = 2000;
}

private void button5_Click_1(object sender, EventArgs e)


14
{
frmnode1 frm = new frmnode1();
frm.ShowDialog();
timer2.Start();
timer2.Interval = 2000;

}
private void button7_Click_1(object sender, EventArgs e)
{

frmnode2 frm = new frmnode2();


frm.ShowDialog();
timer3.Start();
timer3.Interval = 2000;
}

private void button8_Click_1(object sender, EventArgs e)


{

frmnode3 frm = new frmnode3();


frm.ShowDialog();
timer4.Start();
timer4.Interval = 2000;
}

private void richTextBox1_TextChanged(object sender, EventArgs e)


{

private void label9_Click(object sender, EventArgs e)


{

private void button9_Click(object sender, EventArgs e)


{
label14.Text = "Checking....";
timer1.Start();
timer1.Interval = 2000;
}

private void timer1_Tick(object sender, EventArgs e)


{
x++;
textBox5.Text = x.ToString();
int src, dst;
src = int.Parse(textBox1.Text);
dst = int.Parse(textBox2.Text);
RREQ req = new RREQ(0, src, dst, 50, 0);
RouteDiscover rd = new RouteDiscover();
paths = rd.Discover(req, Distance);
pictureBox1.Image = bmp;
for (int i = 0; i < paths.Length - 1; i++)
{
if (x == 2)
{
MessageBox.Show("Source Node Starts Transmission");
}
else if (x == 6)
15
{
if (paths[i] == 6)
{
g.DrawLine(new Pen(new SolidBrush(Color.White), 05), ob[paths[i]].x, ob[paths[i]].y, ob[paths[i + 1]].x,
ob[paths[i + 1]].y);

MessageBox.Show("Packet Forwarded to Node3");


}
}
else if (x == 8)
{
if (paths[i] == 3)
{
g.DrawLine(new Pen(new SolidBrush(Color.White), 05), ob[paths[i]].x, ob[paths[i]].y, ob[paths[i + 1]].x,
ob[paths[i + 1]].y);

MessageBox.Show("A forwards packets to B");


}
}
else if (x == 10)
{
MessageBox.Show("Create Routing Evidence");
timer1.Stop();
}

}
}

private void timer2_Tick(object sender, EventArgs e)


{
x1++;
textBox5.Text = x1.ToString();
int src, dst;
src = int.Parse(textBox1.Text);
dst = int.Parse(textBox2.Text);
RREQ req = new RREQ(0, src, dst, 50, 0);
RouteDiscover rd = new RouteDiscover();
paths = rd.Discover(req, Distance);
pictureBox1.Image = bmp;
for (int i = 0; i < paths.Length - 1; i++)
{
if (x1 == 2)
{

g.DrawLine(new Pen(new SolidBrush(Color.Yellow), 05), ob[4].x, ob[4].y, ob[3].x, ob[3].y);

MessageBox.Show("A get delegation history from B");


}
else if (x1 == 4)
{

g.DrawLine(new Pen(new SolidBrush(Color.White), 05), ob[4].x, ob[4].y, ob[5].x, ob[5].y);

MessageBox.Show("B Forward packet to C");

else if (x1 == 6)
{
MessageBox.Show("Create Forward evidence");
16
timer2.Stop();
}
}
}

private void timer3_Tick(object sender, EventArgs e)


{
x2++;
textBox5.Text = x2.ToString();
int src, dst;
src = int.Parse(textBox1.Text);
dst = int.Parse(textBox2.Text);
RREQ req = new RREQ(0, src, dst, 50, 0);
RouteDiscover rd = new RouteDiscover();
paths = rd.Discover(req, Distance);
pictureBox1.Image = bmp;
for (int i = 0; i < paths.Length - 1; i++)
{
if (x2 == 2)
{

g.DrawLine(new Pen(new SolidBrush(Color.Yellow), 05), ob[5].x, ob[5].y, ob[4].x, ob[4].y);

MessageBox.Show("B get delegation history from C");

else if (x2 == 5)
{
MessageBox.Show("Create Contact evidence");
timer3.Stop();
}
}
}

private void timer4_Tick(object sender, EventArgs e)


{
x3++;
textBox5.Text = x3.ToString();
int src, dst;
src = int.Parse(textBox1.Text);
dst = int.Parse(textBox2.Text);
RREQ req = new RREQ(0, src, dst, 50, 0);
RouteDiscover rd = new RouteDiscover();
paths = rd.Discover(req, Distance);
for (int i = 0; i < paths.Length - 1; i++)
{
if (x3 == 2)
{
if (paths[i] == 5)
{
g.DrawLine(new Pen(new SolidBrush(Color.White), 05), ob[paths[i]].x, ob[paths[i]].y, ob[paths[i + 1]].x,
ob[paths[i + 1]].y);
pictureBox1.Image = bmp;
MessageBox.Show("Packet Forwarded to Destination");
}
}

else if (x3 == 5)
{
17
MessageBox.Show("Packet Received");
timer4.Stop();
}
}
}

private void button11_Click(object sender, EventArgs e)


{

frmTA frm = new frmTA();


frm.ShowDialog();
}

private void button9_Click_1(object sender, EventArgs e)


{
timer5.Start();
timer5.Interval = 2000;
}
int xt1;
private void timer5_Tick(object sender, EventArgs e)
{
xt1++;
g = Graphics.FromImage(bmp);
pictureBox1.Image = bmp;
g.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.HighQuality;
Pen greenPen = new Pen(Color.Blue);
Pen greenPen1 = new Pen(Color.Magenta);
greenPen.Width = 5.0F;
greenPen.DashCap = System.Drawing.Drawing2D.DashCap.Triangle;
greenPen1.Width = 5.0F;
greenPen1.DashCap = System.Drawing.Drawing2D.DashCap.Triangle;
g.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.None;
if (xt1 == 1)
{
MessageBox.Show("Source Node Request TA for Investigation");
}
else if (xt1 == 2)
{
g.DrawLine(greenPen1, ob[6].x, ob[6].y, ob[0].x, ob[0].y);
}
else if (xt1 == 4)
{
MessageBox.Show("TA broadcast a message to submit evidences about B");
}
else if (xt1 == 6)
{
g.DrawLine(greenPen, ob[0].x, ob[0].y, ob[3].x, ob[3].y);
}
else if (xt1 == 8)
{
g.DrawLine(greenPen, ob[0].x, ob[0].y, ob[4].x, ob[4].y);
}
else if (xt1 == 10)
{
g.DrawLine(greenPen, ob[0].x, ob[0].y, ob[5].x, ob[5].y);
}
else if (xt1 == 11)
{
18
timer5.Stop();
}
}

private void button10_Click_1(object sender, EventArgs e)


{
timer6.Start();
timer6.Interval = 2000;
}
int xt2;
private void timer6_Tick(object sender, EventArgs e)
{
xt2++;
if (xt2 == 2)
{
g.DrawLine(new Pen(new SolidBrush(Color.Yellow), 05), ob[3].x, ob[3].y, ob[0].x, ob[0].y);
pictureBox1.Image = bmp;
MessageBox.Show("Delegation History to TA");
}
else if (xt2 == 4)
{
g.DrawLine(new Pen(new SolidBrush(Color.Yellow), 05), ob[4].x, ob[4].y, ob[0].x, ob[0].y);
pictureBox1.Image = bmp;
MessageBox.Show("Forwarding History to TA");
}
else if (xt2 == 6)
{
g.DrawLine(new Pen(new SolidBrush(Color.Yellow), 05), ob[5].x, ob[5].y, ob[0].x, ob[0].y);
pictureBox1.Image = bmp;
MessageBox.Show("Contact History to TA");

}
else if (xt2 == 7)
{
timer6.Stop();
}

private void button13_Click_1(object sender, EventArgs e)


{

19

You might also like