/
E_Port.hpp
105 lines (89 loc) · 2.51 KB
/
E_Port.hpp
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
/**
* @file E_Port.hpp
* @Author leeopop (dlrmsghd@gmail.com)
* @date November, 2014
* @brief Header for E::Port
*/
#ifndef E_PORT_HPP_
#define E_PORT_HPP_
#include <E/E_Common.hpp>
#include <E/E_Module.hpp>
#include <E/Networking/E_NetworkLog.hpp>
#include <E/Networking/E_Networking.hpp>
#include <E/Networking/E_Link.hpp>
#include <E/Networking/E_Host.hpp>
namespace E
{
class Packet;
class Module;
class Host;
/**
* @brief Port does a role of 2-ended wire.
* However there is a speed limit and delayed packets are queued
* (currently, no limitation to the queue length).
*/
class Port : public Module, public NetworkModule, private NetworkLog
{
private:
Module* connected[2];
Time nextAvailable[2];
Time propagationDelay;
Size bps;
bool limit_speed;
public:
/**
* @brief Create a Port.
* @param name See NetworkModule
* @param system See NetworkModule
* @param propagationDelay Propagation delay in nanoseconds.
* @param bps Link speed in bit per sec.
* @param limit_speed Control speed limiting functionality.
*/
Port(std::string name, NetworkSystem* system, Time propagationDelay = 1000000, Size bps = 1000000000UL, bool limit_speed = true);
virtual ~Port();
/**
* @param do_limit Control speed limiting functionality.
* @note You cannot override this function.
*/
virtual void setSpeedLimit(bool do_limit) final;
/**
* @param bps Set data rate.
* @note You cannot override this function.
*/
virtual void setPortSpeed(Size bps) final;
/**
* @param delay Set propagation delay.
* @note You cannot override this function.
*/
virtual void setPropagationDelay(Time delay) final;
enum MessageType
{
PACKET_TO_PORT,
PACKET_FROM_PORT,
};
class Message : public Module::Message
{
public:
enum MessageType type;
Packet* packet;
};
/**
* @brief Connect a module to one of this Port's port.
* Maximum 2 modules can be connected at once.
* @param module Module to be connected.
* @note You cannot override this function.
*/
virtual void connect(Module* module) final;
/**
* @param module Module to be disconnected.
* @note You cannot override this function.
*/
virtual void disconnect(Module* module) final;
virtual Time nextSendAvailable(Module* me) final;
private:
virtual Module::Message* messageReceived(Module* from, Module::Message* message) final;
virtual void messageFinished(Module* to, Module::Message* message, Module::Message* response) final;
virtual void messageCancelled(Module* to, Module::Message* message) final;
};
}
#endif /* E_PORT_HPP_ */