diff --git a/Main.cpp b/Main.cpp index 32f1147..b06f1cb 100644 --- a/Main.cpp +++ b/Main.cpp @@ -5,6 +5,8 @@ * Author: Piotr Dergun */ +#include "common.h" + int main(int argc, char *argv[]) { return 0; diff --git a/Makefile b/Makefile index d77016e..0f799b1 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CXX = g++ CXXFLAGS = -Wall LDFLAGS = -pthread -OBJ = Packet.o +OBJ = Packet.o NATItem.o Node.o all: +@make simulation diff --git a/NATItem.h b/NATItem.h index 2458fb5..03d26f1 100644 --- a/NATItem.h +++ b/NATItem.h @@ -8,8 +8,7 @@ #ifndef NATITEM_H_ #define NATITEM_H_ -#include -using namespace std; +#include "common.h" class NATItem { @@ -21,12 +20,12 @@ public: NATItem(); virtual ~NATItem(); - //settery + // settery void setIp(string ip); void setPort(int port); void setTimeout(int timeout); - //gettery + // gettery string getIp(); int getPort(); int getTimeout(); diff --git a/Node.cpp b/Node.cpp new file mode 100644 index 0000000..d2425a7 --- /dev/null +++ b/Node.cpp @@ -0,0 +1,82 @@ +/* + * Node.cpp + * + * Created on: 10.01.2017 + * Author: piotrek + */ + +#include "Node.h" + +Node::Node() +{ + // TODO Auto-generated constructor stub + +} + +Node::~Node() +{ + // TODO Auto-generated destructor stub +} + +/* + * funkcja symuluje typową sytuację: mamy kartę sieciową, a funkcja connectNode jest podłączeniem wtyczki + * z jednej strony + */ +bool Node::connectNode(Node *node) +{ + vector::iterator it = this->connectedNodes.begin(); + for (; it != this->connectedNodes.end(); ++it) //sprawdzamy, czy połączenia już przypadkiem nie ma + { + if (*it == node) + return false; + } + + this->connectedNodes.push_back(node); // podłączamy drugi węzeł + node->connectNode(this); // podłączamy drugą stronę + + return true; +} + +void Node::send(Packet packet) +{ + +} + +Packet Node::recv() +{ +} + +void Node::setHostname(string hostname) +{ + +} + +void Node::setIp(string ip) +{ + +} + +void Node::setMask(string mask) +{ + +} + +string Node::getHostname() +{ + +} + +string Node::getIp() +{ + +} + +string Node::getMask() +{ + +} + +void Node::onRecv() +{ + +} diff --git a/Node.h b/Node.h new file mode 100644 index 0000000..c73c1c4 --- /dev/null +++ b/Node.h @@ -0,0 +1,46 @@ +/* + * Node.h + * + * Created on: 10.01.2017 + * Author: piotrek + */ + +#ifndef NODE_H_ +#define NODE_H_ + +#include "common.h" +#include "Packet.h" + +typedef struct { + string ip; + string mask; +} NetConf; + +class Node +{ + queuercvPackets; // kolejka z pakietami do przetworzenia + vector connectedNodes; // referencje do węzłów, z którymi jest podłączony + NetConf netConf; // konfiguracja sieciowa + string hostname; // nazwa węzła +public: + Node(); + virtual ~Node(); + bool connectNode(Node *node); + + void send(Packet packet); + Packet recv(); + + // settery + void setHostname(string hostname); + void setIp(string ip); + void setMask(string mask); + + // gettery + string getHostname(); + string getIp(); + string getMask(); + + virtual void onRecv(); // wirtualna metoda na odbiór i dalszą akcję +}; + +#endif /* NODE_H_ */ diff --git a/Packet.h b/Packet.h index 2d8ca9d..bed6fa6 100644 --- a/Packet.h +++ b/Packet.h @@ -8,8 +8,7 @@ #ifndef PACKET_H_ #define PACKET_H_ -#include -using namespace std; +#include "common.h" class Packet { @@ -22,14 +21,14 @@ public: Packet(); virtual ~Packet(); - //settery + // settery void setSrcIp(string ip); void setDstIp(string ip); void setSrcPort(int port); void setDstPort(int port); void setMsg(string msg); - //gettery + // gettery string getSrcIp(); string getDstIp(); int getSrcPort(); diff --git a/common.h b/common.h new file mode 100644 index 0000000..c5ccefc --- /dev/null +++ b/common.h @@ -0,0 +1,19 @@ +/* + * common.h + * + * Created on: 10.01.2017 + * Author: piotrek + */ + +#ifndef COMMON_H_ +#define COMMON_H_ + +#include +#include +#include +#include + +using namespace std; + + +#endif /* COMMON_H_ */