Symulacja NAT na przedmiot Symulacje Komputerowe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

66 lines
1.5 KiB

/*
* Node.h
*
* Created on: 10.01.2017
* Author: piotrek
*/
#ifndef NODE_H_
#define NODE_H_
#include "common.h"
#include "Packet.h"
#include "Log.h"
typedef struct {
string ip;
string mask;
string network;
string gatewayIp;
} NetConf;
class Node : public Log
{
private:
queue<Packet>rcvBuffer; // kolejka z pakietami do przetworzenia
map<Node*, bool> connectedNodes; // referencje do węzłów, z którymi jest podłączony
NetConf netConf; // konfiguracja sieciowa
string hostname; // nazwa węzła
void setNetwork();
protected:
Node * findConnection(string ip);
Packet recv();
string ipToString(unsigned int ip);
unsigned int stringToIp(string ip);
string calculateNetwork(string ip, string mask);
void split(const string &s, char delim, vector<string> &elems);
vector<string> split(const string &s, char delim);
public:
Node();
Node(string hostname);
Node(string hostname, string ip, string mask);
Node(string hostname, string ip, string mask, string gatewayIp);
virtual ~Node();
bool connectNode(Node *node, bool isExternal = false, bool firstConnected = false);
int send(Packet packet, bool isRouter = false);
void putPacket(Packet packet);
// settery
void setHostname(string hostname);
void setIp(string ip);
void setMask(string mask);
void setGatewayIp(string gatewayIp);
// gettery
string getHostname();
string getIp();
string getMask();
string getNetwork();
string getGatewayIp();
virtual void onRecv(); // wirtualna metoda na odbiór i dalszą akcję
};
#endif /* NODE_H_ */