klasa Node + laczenie wezla jeden z drugim
This commit is contained in:
2
Main.cpp
2
Main.cpp
@@ -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;
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -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
|
||||||
|
|||||||
@@ -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
82
Node.cpp
Normal 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
46
Node.h
Normal 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_ */
|
||||||
3
Packet.h
3
Packet.h
@@ -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
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user