NetSim 1.0.0
An educational network simulation software for students
Loading...
Searching...
No Matches
router.h
Go to the documentation of this file.
1#ifndef ROUTER_H
2#define ROUTER_H
3
4#include "host.h"
5#include "natentry.h"
8#include <QHash>
9#include <QStack>
10#include <QString>
11
15
16namespace NetSim {
17
18class Host;
19
22
32class Router {
33public:
37 Router() = default;
38
44 void receivePackage(Package data);
45
48
51
53 QMap<IPAddress, MACAddress> macTable() const;
54
56 QMap<MACAddress, Router *> routerCable() const;
57
59 QMap<MACAddress, Host *> hostCable() const;
60
62 QMap<Port, NATEntry> NAT() const;
63
71 void addIPAddress(const IPAddress &ipAddress, const MACAddress &macaddress);
72
79 void addMACAddress(const MACAddress &macAddress, Router *router);
80
87 void addMACAddress(const MACAddress &macAddress, Host *host);
88
95 void addNATEntry(const NATEntry &entry, const Port &port);
96
97private:
99 QMap<IPAddress, MACAddress> m_macTable{};
100
102 QMap<MACAddress, Router *> m_routerCable{};
103
105 QMap<MACAddress, Host *> m_hostCable{};
106
108 QMap<Port, NATEntry> m_portToNAT{};
109
111 QMap<NATEntry, Port> m_natToPort{};
112
114 NetworkCard m_networkCard{NetworkCard(IPAddress::getRandomAddress(true),
116
118 IPAddress m_globalIpAddress{IPAddress::getRandomAddress(false)};
119};
120} // namespace NetSim
121
122#endif // ROUTER_H
Represents a network host that can communicate through routers.
Definition host.h:32
Represents an IPv4 address.
Definition ipaddress.h:27
static IPAddress getRandomAddress(bool isLocal=false)
Generates a random IP address.
Definition ipaddress.cpp:28
Represents a Media Access Control (MAC) address.
Definition macaddress.h:26
static MACAddress getRandomAddress()
Generates a random MAC address.
Definition macaddress.cpp:33
Represents an entry in the NAT table with an IP address and associated port.
Definition natentry.h:27
Represents a virtual network card with network and physical address capabilities.
Definition networkcard.h:27
Represents a network package.
Definition package.h:28
Represents a network port.
Definition port.h:24
Represents a virtual router with capability to forward packages.
Definition router.h:32
void addIPAddress(const IPAddress &ipAddress, const MACAddress &macaddress)
Adds an IP address and its associated MAC address to the router's table.
Definition router.cpp:19
Router()=default
Default constructor.
void addNATEntry(const NATEntry &entry, const Port &port)
Adds a NAT entry and its associated port to the router's NAT table.
Definition router.cpp:32
QMap< MACAddress, Router * > routerCable() const
Returns the mapping between MAC addresses and connected routers.
Definition router.cpp:13
NetworkCard networkCard() const
Returns the network card associated with the router.
Definition router.cpp:9
QMap< IPAddress, MACAddress > macTable() const
Returns the MAC address table mapping IP addresses to MAC addresses.
Definition router.cpp:11
QMap< Port, NATEntry > NAT() const
Returns the mapping of NAT entries and associated ports.
Definition router.cpp:17
QMap< MACAddress, Host * > hostCable() const
Returns the mapping between MAC addresses and connected hosts.
Definition router.cpp:15
void addMACAddress(const MACAddress &macAddress, Router *router)
Adds a MAC address and its associated router to the router's table.
Definition router.cpp:24
void receivePackage(Package data)
Receives a package and forwards it accordingly.
Definition router.cpp:37
IPAddress globalIpAddress() const
Returns the global IP address of the router.
Definition router.cpp:7
The Host class implements a host in the network.
Contains the IPAddress class definition.
Definition logger.h:12
Contains the NAT Entry class definition.
Contains the Network Card class definition.