-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
109 lines (87 loc) · 3.05 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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 aloha
{
public partial class ALOHA : Form
{
static UInt64 counter=0;
List<Node> node_list;
private double PROBABILITY;
private int NODE_AMOUNT;
private double packets_send;
private double throughput;
private double channelload;
private int packets_attempts;
public ALOHA()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
node_list = new List<Node>();
throughput = 0;
packets_send = 0;
packets_attempts = 0;
}
private void timer1_Tick(object sender, EventArgs e)
{
bool collision = false;
String console_text;
console_text = "Time: " + counter.ToString() + "\n";
Random rnd = new Random();
List<Node> wanting_to_send = new List<Node>();
foreach( Node nod in node_list)
{
if (rnd.Next(0, (int)(1.0 / PROBABILITY)) == 0)
nod.inc_Packets();
if(nod.packet_amount > 0)
{
wanting_to_send.Add(nod);
}
console_text += nod.node_number.ToString() + ": " + nod.packet_amount.ToString() + "\n";
}
if (wanting_to_send.Count > 0)
{
if (wanting_to_send.Count == 1) //No Collision
{
wanting_to_send[0].dec_Packets();
packets_send++;
}
else
{
collision = true; //Collision
}
packets_attempts += wanting_to_send.Count;
}
throughput = packets_send / (double)counter; //Calculate Throughput
channelload = (double)packets_attempts / (double)counter;
console_text += "Channel Load:" + channelload.ToString("0.###") + "\n";
console_text += "Throughput:" + throughput.ToString("0.###") + "\n";
console_text += "Global amount of packets: " + Node.global_packet_amount.ToString() + "\n";
if (collision)
{ console_text += "Collision occured!"; }
out_console.Text = console_text;
counter++;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button_start_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
PROBABILITY = Convert.ToDouble(textBox_prob.Text);
NODE_AMOUNT = Convert.ToInt32(textBox_nodeamount.Text);
for (int i = 0; i < NODE_AMOUNT; i++)
{
node_list.Add(new Node());
}
}
}
}