Repository navigation
Expand file tree
/
Copy pathoutputSimulator_benchmark.cs
More file actions
59 lines (48 loc) · 1.69 KB
/
Copy pathoutputSimulator_benchmark.cs
File metadata and controls
59 lines (48 loc) · 1.69 KB
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
using System.IO;
using System;
using SME;
namespace simplePackageFilter
{
public class OutputSimulator : SimulationProcess
{
[InputBus]
public out_verdict_to_sim from_out = Scope.CreateOrLoadBus<out_verdict_to_sim>();
[OutputBus]
public IBus_Blacklist_out ipv4 = Scope.CreateBus<IBus_Blacklist_out>();
// Used to read input from a .txt file
byte[] sample;
public async override System.Threading.Tasks.Task Run()
{
sample = File.ReadAllBytes("../../input_data/ipv4_outgoing_bytes");
var stream = new MemoryStream(sample, 0, sample.Length);
var reader = new BinaryReader(stream);
// Reads a single byte each clockcykle, and
// updates the Toplevel Inputbus Bus_IPv4
// reads every byte up until the source and destination IP's
await ClockAsync();
ipv4.ReadyToWorkFlag = true;
int length = (int)reader.BaseStream.Length;
for (int j = 0; j < length / 10; j++)
{
// FROM IP
for (int i = 0; i < 4; i++)
{
ipv4.SourceIP[i] = reader.ReadByte();
}
// TO IP
for (int i = 0; i < 4; i++)
{
ipv4.DestIP[i] = reader.ReadByte();
}
// Port
ipv4.SourcePort = reader.ReadByte();
// Syn/Ack etc
ipv4.Flags = reader.ReadByte();
await ClockAsync();
}
ipv4.ReadyToWorkFlag = false;
await ClockAsync();
await ClockAsync();
}
}
}