NetSim 1.0.0
An educational network simulation software for students
|
Represents a network host that can communicate through routers. More...
#include <host.h>
Public Member Functions | |
Host ()=default | |
The default constructor. | |
Host (const NetworkCard &networkCard) | |
Constructor that initializes a host with a network card. | |
QMap< Port, Process > | processTable () const |
Retrieve the process table. | |
QMap< IPAddress, MACAddress > | hostTable () const |
Retrieve the host table. | |
QMap< QString, IPAddress > | domainTable () const |
Retrieve the domain table. | |
QMap< MACAddress, Router * > | cables () const |
Retrieve the cables table. | |
NetworkCard | networkCard () const |
Retrieve the network card. | |
Router * | getRouterByMACAddress (const MACAddress &destinationAddress) |
Retrieves the router by its MAC address. | |
void | sendPackage (Package &data, const MACAddress &destinationAddress) |
Send a package to a destination MAC address. | |
virtual void | receivePackage (Package data)=0 |
Pure virtual function to receive a package. Must be implemented in derived classes. | |
void | addProcess (const Process &process) |
Adds a process to the process table. | |
void | addIPAddress (const IPAddress &ipAddress, const MACAddress &macAddress) |
Adds an IP address to MAC address resolution to the ARP table. | |
void | addMACAddress (const MACAddress &macAddress, Router *router) |
Adds a MAC address to router pointer to the cables table. | |
void | addDomain (const QString &domain, const IPAddress &ipAddress) |
Adds a domain to IP address resolution to the DNS table. | |
PackageTableModel * | packages () const |
Get all the packages associated with this host. | |
void | setPackages (PackageTableModel *packages) |
Set the packages for this host. | |
Process & | getProcessByName (const QString &name) |
Retrieves a process by its name. | |
void | setHostOfProcesses (Host *host) |
Set the host for all processes. | |
Represents a network host that can communicate through routers.
A host maintains various tables to map processes to ports, IP addresses to MAC addresses, and domain names to IP addresses. It can also maintain cables connected to routers.
|
default |
The default constructor.
Host::Host | ( | const NetworkCard & | networkCard | ) |
Constructor that initializes a host with a network card.
networkCard | The network card associated with this host. |
void Host::addDomain | ( | const QString & | domain, |
const IPAddress & | ipAddress | ||
) |
Adds a domain to IP address resolution to the DNS table.
domain | The domain to add. |
ipAddress | The IP address to add. |
void Host::addIPAddress | ( | const IPAddress & | ipAddress, |
const MACAddress & | macAddress | ||
) |
void Host::addMACAddress | ( | const MACAddress & | macAddress, |
Router * | router | ||
) |
void Host::addProcess | ( | const Process & | process | ) |
Adds a process to the process table.
process | The process to add. |
QMap< MACAddress, Router * > Host::cables | ( | ) | const |
QMap< QString, IPAddress > Host::domainTable | ( | ) | const |
Retrieve the domain table.
QMap<QString,IPAddress> | The table mapping domain names to IP addresses. |
Process & Host::getProcessByName | ( | const QString & | name | ) |
Retrieves a process by its name.
name | The name of the process to retrieve. |
Process& | A reference to the retrieved process. |
std::runtime_error | If no process with the given name is found. |
Router * Host::getRouterByMACAddress | ( | const MACAddress & | destinationAddress | ) |
Retrieves the router by its MAC address.
destinationAddress | The MAC address of the router to retrieve. |
Router* | Pointer to the associated router. |
CableNotFoundException | If the MAC address does not map to any router. |
QMap< IPAddress, MACAddress > Host::hostTable | ( | ) | const |
Retrieve the host table.
QMap<IPAddress,MACAddress> | The table mapping IP addresses to MAC addresses. |
NetworkCard Host::networkCard | ( | ) | const |
Retrieve the network card.
NetworkCard | The associated network card. |
PackageTableModel * Host::packages | ( | ) | const |
Get all the packages associated with this host.
PackageTableModel* | Pointer to the package table model. |
Retrieve the process table.
QMap<Port,Process> | The table mapping ports to processes. |
|
pure virtual |
Pure virtual function to receive a package. Must be implemented in derived classes.
data | The received package. |
Implemented in NetSim::Client, and NetSim::Server.
void Host::sendPackage | ( | Package & | data, |
const MACAddress & | destinationAddress | ||
) |
void Host::setHostOfProcesses | ( | Host * | host | ) |
Set the host for all processes.
host | Pointer to the new host. |
void Host::setPackages | ( | PackageTableModel * | packages | ) |
Set the packages for this host.
packages | Pointer to the new package table model. |