Source Code
Source 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
{
1
private System.Windows.Forms.Timer timer6;
private System.ComponentModel.IContainer components;
public Form1()
{
InitializeComponent();
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
}
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;
}
}
}
}
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);
}
for (int j = 0; (j * var + 10) <= pictureBox1.Height - 10; j++)
{
}
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 );
}
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()
{
}
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++)
{
}
}
}
13
private void button1_Click(object sender, EventArgs e)
{
}
private void button7_Click_1(object sender, EventArgs e)
{
}
}
else if (x1 == 6)
{
MessageBox.Show("Create Forward evidence");
16
timer2.Stop();
}
}
}
else if (x2 == 5)
{
MessageBox.Show("Create Contact evidence");
timer3.Stop();
}
}
}
else if (x3 == 5)
{
17
MessageBox.Show("Packet Received");
timer4.Stop();
}
}
}
}
else if (xt2 == 7)
{
timer6.Stop();
}
19