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
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
return 0;
|
||||
|
||||
2
Makefile
2
Makefile
@@ -1,7 +1,7 @@
|
||||
CXX = g++
|
||||
CXXFLAGS = -Wall
|
||||
LDFLAGS = -pthread
|
||||
OBJ = Packet.o
|
||||
OBJ = Packet.o NATItem.o Node.o
|
||||
|
||||
all:
|
||||
+@make simulation
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
#ifndef NATITEM_H_
|
||||
#define NATITEM_H_
|
||||
|
||||
#include <iostream>
|
||||
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();
|
||||
|
||||
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_ */
|
||||
7
Packet.h
7
Packet.h
@@ -8,8 +8,7 @@
|
||||
#ifndef PACKET_H_
|
||||
#define PACKET_H_
|
||||
|
||||
#include <iostream>
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user