klasa Node + laczenie wezla jeden z drugim

This commit is contained in:
2017-01-10 20:13:42 +01:00
parent 8e5fc60dc6
commit 9492948e5a
7 changed files with 156 additions and 9 deletions

View File

@@ -5,6 +5,8 @@
* Author: Piotr Dergun * Author: Piotr Dergun
*/ */
#include "common.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
return 0; return 0;

View File

@@ -1,7 +1,7 @@
CXX = g++ CXX = g++
CXXFLAGS = -Wall CXXFLAGS = -Wall
LDFLAGS = -pthread LDFLAGS = -pthread
OBJ = Packet.o OBJ = Packet.o NATItem.o Node.o
all: all:
+@make simulation +@make simulation

View File

@@ -8,8 +8,7 @@
#ifndef NATITEM_H_ #ifndef NATITEM_H_
#define NATITEM_H_ #define NATITEM_H_
#include <iostream> #include "common.h"
using namespace std;
class NATItem class NATItem
{ {

82
Node.cpp Normal file
View File

@@ -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<Node*>::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()
{
}

46
Node.h Normal file
View File

@@ -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
{
queue<Packet>rcvPackets; // kolejka z pakietami do przetworzenia
vector<Node*> 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_ */

View File

@@ -8,8 +8,7 @@
#ifndef PACKET_H_ #ifndef PACKET_H_
#define PACKET_H_ #define PACKET_H_
#include <iostream> #include "common.h"
using namespace std;
class Packet class Packet
{ {

19
common.h Normal file
View File

@@ -0,0 +1,19 @@
/*
* common.h
*
* Created on: 10.01.2017
* Author: piotrek
*/
#ifndef COMMON_H_
#define COMMON_H_
#include <iostream>
#include <queue>
#include <map>
#include <functional>
using namespace std;
#endif /* COMMON_H_ */