update20140630
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* File: Distance.cc
|
||||
* Author: jgaebler
|
||||
*
|
||||
* Created on December 13, 2012, 4:10 PM
|
||||
*/
|
||||
|
||||
#include "Distance.h"
|
||||
|
||||
namespace ubeeme {
|
||||
namespace moversight {
|
||||
|
||||
Distance::Distance() : nodeName(""), distance(0.0) {
|
||||
}
|
||||
|
||||
Distance::Distance(std::string name):nodeName(name), distance(0.0){
|
||||
}
|
||||
|
||||
Distance::Distance(std::string name, double d):nodeName(name), distance(d){
|
||||
}
|
||||
|
||||
Distance::Distance(const Distance& orig):nodeName(orig.nodeName), distance(orig.distance) {
|
||||
}
|
||||
|
||||
Distance::~Distance() {
|
||||
}
|
||||
|
||||
void
|
||||
Distance::setDistance(double distance) {
|
||||
this->distance = distance;
|
||||
}
|
||||
|
||||
double
|
||||
Distance::getDistance() const {
|
||||
return distance;
|
||||
}
|
||||
|
||||
void
|
||||
Distance::setNodeName(std::string & name) {
|
||||
nodeName = name;
|
||||
}
|
||||
|
||||
std::string
|
||||
Distance::getNodeName() const {
|
||||
return nodeName;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* File: Distance.h
|
||||
* Author: jgaebler
|
||||
*
|
||||
* Created on December 13, 2012, 4:10 PM
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#ifndef DISTANCE_H
|
||||
#define DISTANCE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ubeeme {
|
||||
namespace moversight {
|
||||
|
||||
class Distance {
|
||||
public:
|
||||
|
||||
Distance();
|
||||
Distance(std::string name);
|
||||
Distance(std::string name, double d);
|
||||
Distance(const Distance& orig);
|
||||
virtual ~Distance();
|
||||
|
||||
void setDistance(double distance);
|
||||
double getDistance() const;
|
||||
void setNodeName(std::string & nodeName);
|
||||
std::string getNodeName() const;
|
||||
|
||||
private:
|
||||
|
||||
std::string nodeName;
|
||||
double distance;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* DISTANCE_H */
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* File: Node.cc
|
||||
* Author: jgaebler
|
||||
*
|
||||
* Created on December 13, 2012, 3:43 PM
|
||||
*/
|
||||
|
||||
#include "Node.h"
|
||||
|
||||
namespace ubeeme {
|
||||
namespace moversight {
|
||||
|
||||
Node::Node(std::string & nName) : nodeName(nName), transmissionRange(0), isMobil(false), isAP(false), connectedWith(""), timeLeft(0), connectedTime(0){
|
||||
}
|
||||
|
||||
Node::~Node() {
|
||||
}
|
||||
|
||||
void
|
||||
Node::setMacAdress(MACAddress macAdress) {
|
||||
this->macAdress = macAdress;
|
||||
}
|
||||
|
||||
MACAddress
|
||||
Node::getMacAdress() const {
|
||||
return macAdress;
|
||||
}
|
||||
|
||||
void
|
||||
Node::setIsAccessPoint(bool flag) {
|
||||
this->isAP = flag;
|
||||
}
|
||||
|
||||
bool
|
||||
Node::isAccessPoint() const {
|
||||
return isAP;
|
||||
}
|
||||
|
||||
void
|
||||
Node::setHasMobility(bool hasMobility) {
|
||||
this->isMobil = hasMobility;
|
||||
}
|
||||
|
||||
bool
|
||||
Node::hasMobility() const {
|
||||
return isMobil;
|
||||
}
|
||||
|
||||
void
|
||||
Node::setConnectedTime(SimTime connectedTime) {
|
||||
this->connectedTime = connectedTime;
|
||||
}
|
||||
|
||||
SimTime
|
||||
Node::getConnectedTime() const {
|
||||
return connectedTime;
|
||||
}
|
||||
|
||||
void
|
||||
Node::setTimeLeft(SimTime timeLeft) {
|
||||
this->timeLeft = timeLeft;
|
||||
}
|
||||
|
||||
SimTime
|
||||
Node::getTimeLeft() const {
|
||||
return timeLeft;
|
||||
}
|
||||
|
||||
void
|
||||
Node::setNodeDistanceList(Node::DistanceList & distanceList) {
|
||||
nodeDistanceList = distanceList;
|
||||
}
|
||||
|
||||
Node::DistanceList &
|
||||
Node::getNodeDistanceList() {
|
||||
return nodeDistanceList;
|
||||
}
|
||||
|
||||
void
|
||||
Node::setConnectedWith(std::string connectedWith) {
|
||||
this->connectedWith = connectedWith;
|
||||
}
|
||||
|
||||
std::string
|
||||
Node::getConnectedWith() const {
|
||||
return connectedWith;
|
||||
}
|
||||
|
||||
int
|
||||
Node::getNumEqualModules() const {
|
||||
return nodeDistanceList.size();
|
||||
}
|
||||
|
||||
void
|
||||
Node::setCurrentSpeed(Coord currSpeed) {
|
||||
this->currSpeed = currSpeed;
|
||||
}
|
||||
|
||||
Coord
|
||||
Node::getCurrentSpeed() const {
|
||||
return currSpeed;
|
||||
}
|
||||
|
||||
void
|
||||
Node::setCurrentPosition(Coord currPosition) {
|
||||
this->currPosition = currPosition;
|
||||
}
|
||||
|
||||
Coord
|
||||
Node::getCurrentPosition() const {
|
||||
return currPosition;
|
||||
}
|
||||
|
||||
void
|
||||
Node::setTransmissionRange(double transmissRange) {
|
||||
this->transmissionRange = transmissRange;
|
||||
}
|
||||
|
||||
double
|
||||
Node::getTransmissionRange() const {
|
||||
return transmissionRange;
|
||||
}
|
||||
|
||||
void
|
||||
Node::setRadioModule(cModule * radioModule) {
|
||||
this->radioModule = radioModule;
|
||||
}
|
||||
|
||||
cModule *
|
||||
Node::getRadioModule() const {
|
||||
return radioModule;
|
||||
}
|
||||
|
||||
void
|
||||
Node::setNodeName(std::string nodeName) {
|
||||
this->nodeName = nodeName;
|
||||
}
|
||||
|
||||
std::string
|
||||
Node::getNodeName() const {
|
||||
return nodeName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* File: Node.h
|
||||
* Author: jgaebler
|
||||
*
|
||||
* Created on December 13, 2012, 3:43 PM
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#ifndef NODE_H
|
||||
#define NODE_H
|
||||
|
||||
#include "Distance.h"
|
||||
|
||||
#include "simtime.h"
|
||||
|
||||
#include "base/Coord.h"
|
||||
#include "linklayer/contract/MACAddress.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace ubeeme {
|
||||
namespace moversight {
|
||||
|
||||
class Node {
|
||||
public:
|
||||
|
||||
typedef std::vector<Distance> DistanceList;
|
||||
|
||||
Node(std::string & nodeName);
|
||||
virtual ~Node();
|
||||
|
||||
void setMacAdress(MACAddress macAdress);
|
||||
MACAddress getMacAdress() const;
|
||||
|
||||
void setIsAccessPoint(bool flag);
|
||||
bool isAccessPoint() const;
|
||||
|
||||
void setHasMobility(bool hasMobility);
|
||||
bool hasMobility() const;
|
||||
|
||||
void setConnectedTime(SimTime connectedTime);
|
||||
SimTime getConnectedTime() const;
|
||||
|
||||
void setTimeLeft(SimTime timeLeft);
|
||||
SimTime getTimeLeft() const;
|
||||
|
||||
void setNodeDistanceList(DistanceList & nodeDistanceList);
|
||||
DistanceList & getNodeDistanceList();
|
||||
|
||||
void setConnectedWith(std::string connectedWith);
|
||||
std::string getConnectedWith() const;
|
||||
|
||||
void setNumEqualModules(int numEqualModules);
|
||||
int getNumEqualModules() const;
|
||||
|
||||
void setCurrentSpeed(Coord currSpeed);
|
||||
Coord getCurrentSpeed() const;
|
||||
|
||||
void setCurrentPosition(Coord currPosition);
|
||||
Coord getCurrentPosition() const;
|
||||
|
||||
void setTransmissionRange(double transmissRange);
|
||||
double getTransmissionRange() const;
|
||||
|
||||
void setRadioModule(cModule* radioModule);
|
||||
cModule * getRadioModule() const;
|
||||
|
||||
void setNodeName(std::string name);
|
||||
std::string getNodeName() const;
|
||||
|
||||
private:
|
||||
|
||||
std::string nodeName; // Name of wireless Node
|
||||
cModule *radioModule; // Pointer to radioModule
|
||||
double transmissionRange; // Transmission range of Node
|
||||
|
||||
bool isMobil; // false means no mobility available ( stationaryMobility)
|
||||
bool isAP; // true = Wireless Node ; false = AccessPoint
|
||||
Coord currPosition; // current Position
|
||||
Coord currSpeed; // current Speed ( if hasMobility == false -> currSpeed = COORD::ZERO)
|
||||
|
||||
std::string connectedWith; // connected Node
|
||||
DistanceList nodeDistanceList; // list of equal Module
|
||||
|
||||
SimTime timeLeft; // time left in Range to connected Module
|
||||
SimTime connectedTime; // time already connected with
|
||||
|
||||
MACAddress macAdress;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif /* NODE_H */
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* File: NotificationInfo.cc
|
||||
* Author: jgaebler
|
||||
*
|
||||
* Created on December 13, 2012, 2:28 PM
|
||||
*/
|
||||
|
||||
#include "NotificationInfo.h"
|
||||
|
||||
namespace ubeeme {
|
||||
namespace moversight {
|
||||
|
||||
const MACAddress &
|
||||
NotificationInfo::getApAddress() const{
|
||||
return apAddress;
|
||||
}
|
||||
|
||||
void
|
||||
NotificationInfo::setApAddress(const MACAddress & a){
|
||||
apAddress = a;
|
||||
}
|
||||
|
||||
const MACAddress &
|
||||
NotificationInfo::getStaAddress() const {
|
||||
return staAddress;
|
||||
}
|
||||
|
||||
void
|
||||
NotificationInfo::setStaAddress(const MACAddress & a){
|
||||
staAddress = a;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* File: NotificationInfo.h
|
||||
* Author: jgaebler
|
||||
*
|
||||
* Created on December 13, 2012, 2:28 PM
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#ifndef NOTIFICATIONINFO_H
|
||||
#define NOTIFICATIONINFO_H
|
||||
|
||||
#include <cobject.h>
|
||||
#include "linklayer/contract/MACAddress.h"
|
||||
|
||||
namespace ubeeme {
|
||||
namespace moversight {
|
||||
|
||||
class NotificationInfo : public cObject {
|
||||
public:
|
||||
|
||||
const MACAddress & getApAddress() const;
|
||||
void setApAddress(const MACAddress & a);
|
||||
|
||||
const MACAddress & getStaAddress() const;
|
||||
void setStaAddress(const MACAddress & a);
|
||||
|
||||
private:
|
||||
|
||||
MACAddress apAddress;
|
||||
MACAddress staAddress;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* NOTIFICATIONINFO_H */
|
||||
|
||||
@@ -0,0 +1,484 @@
|
||||
/*
|
||||
* File: WirelessConnectivityObserver.cc
|
||||
* Author: thandreg
|
||||
* Author: jgaebler
|
||||
*
|
||||
* Created on October 16, 2012, 1:30 PM
|
||||
*/
|
||||
#include "WirelessConnectivityObserver.h"
|
||||
|
||||
#include "NotificationInfo.h"
|
||||
|
||||
#include <FWMath.h>
|
||||
|
||||
#include "base/NotificationBoard.h"
|
||||
#include "mobility/models/MovingMobilityBase.h"
|
||||
#include "mobility/models/StationaryMobility.h"
|
||||
|
||||
#include <IRoutingTable.h>
|
||||
#include <IInterfaceTable.h>
|
||||
#include <IPvXAddressResolver.h>
|
||||
#include <IPv4InterfaceData.h>
|
||||
|
||||
|
||||
namespace ubeeme {
|
||||
namespace moversight {
|
||||
|
||||
Define_Module(WirelessConnectivityObserver);
|
||||
|
||||
void
|
||||
WirelessConnectivityObserver::initialize(int stage) {
|
||||
|
||||
if (stage == 2) {
|
||||
|
||||
nodeInfo.clear();
|
||||
|
||||
// extract topology into the cTopology object, then fill in
|
||||
// isIPNode, rt and ift members of nodeInfo[]
|
||||
extractTopology(topo, nodeInfo);
|
||||
|
||||
// assign addresses to IPv4 nodes, and also store result in nodeInfo[].address
|
||||
assignAddresses(topo, nodeInfo);
|
||||
|
||||
// add default routes to hosts (nodes with a single attachment);
|
||||
// also remember result in nodeInfo[].usesDefaultRoute
|
||||
addDefaultRoutes(topo, nodeInfo);
|
||||
|
||||
// calculate shortest paths, and add corresponding static routes
|
||||
fillRoutingTables(topo, nodeInfo);
|
||||
|
||||
// update display string
|
||||
setDisplayString(topo, nodeInfo);
|
||||
|
||||
cc = dynamic_cast<IChannelControl *> (simulation.getModuleByPath("channelControl"));
|
||||
if (!cc) {
|
||||
throw cRuntimeError("Could not find ChannelControl module with name 'channelControl' in the toplevel network.");
|
||||
}//End if
|
||||
|
||||
EV << "Initialising WirelessConnectivityObserver" << endl;
|
||||
|
||||
//initialize nodeList
|
||||
topo.extractByProperty("node");
|
||||
|
||||
for (int i = 0; i < (topo.getNumNodes()); i++) {
|
||||
|
||||
//we are only interested in wireless nodes
|
||||
if (topo.getNode(i)->getModule()->getSubmodule("wlan", 0)) {
|
||||
|
||||
std::string nodeName(topo.getNode(i)->getModule()->getFullName());
|
||||
Node node(nodeName);
|
||||
node.setRadioModule(topo.getNode(i)->getModule()->getSubmodule("wlan", 0)->getSubmodule("radio", 0));
|
||||
|
||||
MACAddress mac;
|
||||
mac.setAddress(topo.getNode(i)->getModule()->getSubmodule("wlan", 0)->getSubmodule("mac", 0)->par("address").stringValue());
|
||||
node.setMacAdress(mac);
|
||||
|
||||
int isMobil = topo.getNode(i)->getModule()->getSubmodule("mobility")->findPar("updateInterval");
|
||||
if (isMobil != -1) {
|
||||
node.setHasMobility(true);
|
||||
}//end if
|
||||
|
||||
//setting event-listener to AccessPoints
|
||||
if (topo.getNode(i)->getModule()->getSubmodule("relayUnit", 0) &&
|
||||
topo.getNode(i)->getModule()->getSubmodule("notificationBoard", 0)) {
|
||||
|
||||
NotificationBoard * blackBoard = dynamic_cast<NotificationBoard *> (topo.getNode(i)->getModule()->getSubmodule("notificationBoard"));
|
||||
if (!blackBoard) {
|
||||
std::cerr << "Could not find NotificationBoard module with name 'notificationBoard' in AP-Node." << endl;
|
||||
}//end if
|
||||
else {
|
||||
|
||||
//categories for notifications
|
||||
blackBoard->subscribe(this, NF_L2_AP_ASSOCIATED);
|
||||
blackBoard->subscribe(this, NF_L2_AP_DISASSOCIATED);
|
||||
}//end else
|
||||
|
||||
node.setIsAccessPoint(true);
|
||||
|
||||
}//end if
|
||||
|
||||
// Eventlistener to Notificationboard only for WirelessNodes
|
||||
if (topo.getNode(i)->getModule()->getSubmodule("networkLayer", 0) &&
|
||||
topo.getNode(i)->getModule()->getSubmodule("notificationBoard", 0)) {
|
||||
|
||||
NotificationBoard * blackBoard = dynamic_cast<NotificationBoard *> (topo.getNode(i)->getModule()->getSubmodule("notificationBoard"));
|
||||
if (!blackBoard) {
|
||||
std::cerr << "Could not find NotificationBoard module with name 'notificationBoard' in wlan-Node." << endl;
|
||||
}
|
||||
else {
|
||||
//categories für notifications
|
||||
blackBoard->subscribe(this, NF_L2_ASSOCIATED_NEWAP);
|
||||
blackBoard->subscribe(this, NF_L2_BEACON_LOST);
|
||||
blackBoard->subscribe(this, NF_L2_AP_ASSOCIATED);
|
||||
|
||||
}//End else
|
||||
}
|
||||
|
||||
nodeList.push_back(node);
|
||||
}
|
||||
}
|
||||
|
||||
//init params
|
||||
updateFrequency = par("updateFreq").doubleValue();
|
||||
|
||||
//starting Initialization2
|
||||
selfTrigger = new cMessage("selfTrigger");
|
||||
scheduleAt(simTime() + updateFrequency, selfTrigger);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
WirelessConnectivityObserver::handleMessage(cMessage *msg) {
|
||||
|
||||
//we only handly selfTrigger messages
|
||||
if (msg == selfTrigger) {
|
||||
|
||||
if (simTime() <= updateFrequency)
|
||||
initalizeNodes();
|
||||
|
||||
else {
|
||||
for (size_t i = 0; i < nodeList.size(); i++) {
|
||||
updatePositons(i);
|
||||
updateDistance(i);
|
||||
timeLeft(i);
|
||||
std::cerr << "Name: " << nodeList.at(i).getNodeName() << endl;
|
||||
std::cerr << "verbundene Zeit: " << nodeList.at(i).getConnectedTime() << endl;
|
||||
std::cerr << "verbleibene Zeit: " << nodeList.at(i).getTimeLeft() << endl;
|
||||
std::cerr << "verbunden mit: " << nodeList.at(i).getConnectedWith() << endl;
|
||||
std::cerr << "Speed: " << nodeList.at(i).getCurrentSpeed() << endl;
|
||||
std::cerr << "num equal: " << nodeList.at(i).getNumEqualModules() << endl << endl;
|
||||
}//End for
|
||||
}//End else
|
||||
|
||||
scheduleAt(simTime() + updateFrequency, selfTrigger);
|
||||
|
||||
}//end if
|
||||
}
|
||||
|
||||
void
|
||||
WirelessConnectivityObserver::initalizeNodes() {
|
||||
|
||||
//initial the position of the nodes
|
||||
for (size_t i = 0; i < nodeList.size(); i++) {
|
||||
updatePositons(i);
|
||||
}//end for
|
||||
|
||||
//initial the distance of the nodes
|
||||
for (size_t i = 0; i < nodeList.size(); i++) {
|
||||
|
||||
Node & node = nodeList[i];
|
||||
|
||||
cModule * radioModule = node.getRadioModule();
|
||||
if (radioModule != NULL) {
|
||||
|
||||
double transmissionPower = radioModule->par("transmitterPower");
|
||||
double transmissionRange = calcDistFreeSpace(i, transmissionPower);
|
||||
node.setTransmissionRange(transmissionRange);
|
||||
|
||||
for (size_t z = 0; z < nodeList.size(); z++) {
|
||||
if (i != z && node.isAccessPoint() != nodeList[z].isAccessPoint()) {
|
||||
|
||||
double distance = node.getCurrentPosition().distance(nodeList[z].getCurrentPosition());
|
||||
|
||||
Distance temp(nodeList[z].getNodeName(), distance);
|
||||
node.getNodeDistanceList().push_back(temp);
|
||||
|
||||
}//End if
|
||||
}//end for
|
||||
}//end if
|
||||
}//end for
|
||||
}
|
||||
|
||||
double
|
||||
WirelessConnectivityObserver::calcDistFreeSpace(size_t nodesIndex, double transmissionPower) {
|
||||
|
||||
//the carrier frequency used
|
||||
double carrierFrequency = getChannelControlPar("carrierFrequency");
|
||||
|
||||
//path loss coefficient
|
||||
double alpha = getChannelControlPar("alpha");
|
||||
|
||||
double waveLength = (SPEED_OF_LIGHT / carrierFrequency);
|
||||
|
||||
//minimum power level to be able to physically receive a signal
|
||||
double minReceivePower = FWMath::dBm2mW(double(nodeList.at(nodesIndex).getRadioModule()->par("sensitivity")));
|
||||
|
||||
double interfDistance = pow(waveLength * waveLength * transmissionPower /
|
||||
(16.0 * M_PI * M_PI * minReceivePower), 1.0 / alpha);
|
||||
|
||||
return interfDistance;
|
||||
}
|
||||
|
||||
void
|
||||
WirelessConnectivityObserver::updatePositons(size_t i) {
|
||||
|
||||
Node & node = nodeList[i];
|
||||
|
||||
cModule * radio = node.getRadioModule();
|
||||
|
||||
if (radio != NULL) {
|
||||
|
||||
cModule* help = radio->getParentModule()->getParentModule()->getSubmodule("mobility", 0);
|
||||
|
||||
if (node.hasMobility()) {
|
||||
|
||||
//All mobilities inherit from same modules
|
||||
MovingMobilityBase* mod = (MovingMobilityBase*) help;
|
||||
node.setCurrentPosition(mod->getCurrentPosition());
|
||||
node.setCurrentSpeed(mod->getCurrentSpeed() / 10);
|
||||
|
||||
}//end if
|
||||
else {
|
||||
|
||||
// when there is no mobility
|
||||
StationaryMobility* mod = (StationaryMobility*) help;
|
||||
node.setCurrentPosition(mod->getCurrentPosition());
|
||||
node.setCurrentSpeed(Coord::ZERO);
|
||||
|
||||
}//end else
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
WirelessConnectivityObserver::updateDistance(size_t nodeNum) {
|
||||
|
||||
Node & node = nodeList[nodeNum];
|
||||
Node::DistanceList & distanceList = node.getNodeDistanceList();
|
||||
|
||||
for (size_t i = 0; i < distanceList.size(); i++) {
|
||||
|
||||
std::string neighbourNodeName = distanceList.at(i).getNodeName();
|
||||
|
||||
//found myself
|
||||
if (node.getNodeName().compare(neighbourNodeName) == 0) continue;
|
||||
|
||||
//found position of neighbour
|
||||
Coord neighbourPos;
|
||||
for (size_t z = 0; z < nodeList.size(); z++) {
|
||||
//node found?
|
||||
|
||||
if (nodeList[z].getNodeName().compare(neighbourNodeName) == 0) {
|
||||
neighbourPos = nodeList[z].getCurrentPosition();
|
||||
}//End if
|
||||
}//End for
|
||||
|
||||
Coord selfPos = node.getCurrentPosition();
|
||||
double distance = selfPos.distance(neighbourPos);
|
||||
distanceList[i].setDistance(distance);
|
||||
|
||||
}//end for
|
||||
}
|
||||
|
||||
void
|
||||
WirelessConnectivityObserver::timeLeft(size_t nodeNum) {
|
||||
|
||||
bool connected = false;
|
||||
Node & node = nodeList[nodeNum];
|
||||
|
||||
size_t neighbourNodeNum = 0;
|
||||
|
||||
node.setTimeLeft(0);
|
||||
|
||||
//test, to avoid errors
|
||||
if (node.getNumEqualModules() == 0) {
|
||||
return;
|
||||
}//End if
|
||||
|
||||
if (node.getConnectedWith().compare("") != 0) {
|
||||
connected = true;
|
||||
}//End if
|
||||
|
||||
if (!connected) {
|
||||
node.setConnectedTime(0);
|
||||
}//End if
|
||||
else {
|
||||
//searching for connected Node
|
||||
while (node.getConnectedWith().compare(nodeList.at(neighbourNodeNum).getNodeName()) != 0) {
|
||||
neighbourNodeNum++;
|
||||
}//End while
|
||||
|
||||
node.setConnectedTime(node.getConnectedTime() + updateFrequency);
|
||||
|
||||
Node connectedNode = nodeList.at(neighbourNodeNum);
|
||||
|
||||
double distance = node.getCurrentPosition().distance(connectedNode.getCurrentPosition());
|
||||
|
||||
Coord speed1 = connectedNode.getCurrentSpeed();
|
||||
Coord speed2 = node.getCurrentSpeed();
|
||||
|
||||
Coord Pos = node.getCurrentPosition();
|
||||
|
||||
while (node.getTransmissionRange() >= distance) {
|
||||
|
||||
speed1 += connectedNode.getCurrentSpeed();
|
||||
speed2 += node.getCurrentSpeed();
|
||||
|
||||
if (speed1 == speed2 && speed1 == Coord::ZERO) {
|
||||
//std::cerr<<node.getNodeName()<<" ist undefiniert lange noch verbunden"<<endl;
|
||||
return;
|
||||
}
|
||||
else {
|
||||
Pos = Pos + speed1 + speed2;
|
||||
distance = connectedNode.getCurrentPosition().distance(Pos);
|
||||
}
|
||||
|
||||
node.setTimeLeft(node.getTimeLeft() + updateFrequency);
|
||||
|
||||
}//End while
|
||||
|
||||
//std::cerr<<node.getNodeName()<<" ist vorraussichtlich noch "<<node.getTimeLeft()<<" sec verbunden"<<endl;
|
||||
}//End else
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
WirelessConnectivityObserver::receiveChangeNotification(int category, const cObject * details) {
|
||||
|
||||
size_t i = 0;
|
||||
bool findObject = false;
|
||||
std::string nodeName = nodeList.at(i).getNodeName();
|
||||
|
||||
// finds the the notification giving Object to assign wlan modul
|
||||
// only for wireless Nodes
|
||||
if (details) {
|
||||
while (i < nodeList.size()) {
|
||||
|
||||
if (details->getFullPath().find(nodeName.c_str()) != details->getFullPath().npos) {
|
||||
|
||||
findObject = true;
|
||||
// set Associated AccessPoint for Wireless Host
|
||||
nodeList[i].setConnectedWith(nodeList[modulNumber].getNodeName());
|
||||
// set Associatetd Wireless Host for AP
|
||||
nodeList[modulNumber].setConnectedWith(nodeList[i].getNodeName());
|
||||
break;
|
||||
|
||||
}//end if
|
||||
|
||||
i++;
|
||||
|
||||
}//End while
|
||||
}//end if
|
||||
|
||||
if (!findObject) {
|
||||
|
||||
//only for wireless AccessPoints
|
||||
|
||||
const NotificationInfo * notiInfo = (NotificationInfo * const) details;
|
||||
if (notiInfo) {
|
||||
i = 0;
|
||||
//compares MacAdresses of Nodes and finds the notification giving object
|
||||
while (notiInfo->getApAddress() != nodeList.at(i).getMacAdress() && i < nodeList.size())
|
||||
i++;
|
||||
}
|
||||
|
||||
// APs changes notification first, so save the name of AP to associated AP with new associated WirelessNode
|
||||
//number of the ap within the nodeList
|
||||
modulNumber = i;
|
||||
}//end else
|
||||
|
||||
switch (category) {
|
||||
//emitted by Whost
|
||||
case NF_L2_ASSOCIATED_NEWAP:
|
||||
std::cerr << nodeList.at(i).getNodeName() << " associated with " << nodeList.at(modulNumber).getNodeName() << endl;
|
||||
addRoute(i);
|
||||
break;
|
||||
// emitted by WHOST
|
||||
case NF_L2_BEACON_LOST:
|
||||
std::cerr << "wirelessNode " << nodeList.at(i).getNodeName() << " dissociated" << endl;
|
||||
nodeList.at(i).setConnectedWith("");
|
||||
break;
|
||||
//emitted by AP
|
||||
case NF_L2_AP_ASSOCIATED:
|
||||
std::cerr << nodeList.at(i).getNodeName() << " associated" << endl;
|
||||
break;
|
||||
//probably did not work with this inet?!
|
||||
case NF_L2_AP_DISASSOCIATED:
|
||||
std::cerr << nodeList.at(i).getNodeName() << " dissociated" << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
WirelessConnectivityObserver::addRoute(size_t numNode) {
|
||||
|
||||
Node & node = nodeList[numNode]; //a wHost
|
||||
std::string accessPointName = node.getConnectedWith();
|
||||
|
||||
//findet den node in der topologie
|
||||
int findNode = 0;
|
||||
while (findNode < topo.getNumNodes() &&
|
||||
node.getNodeName().compare(topo.getNode(findNode)->getModule()->getFullName()) != 0) {
|
||||
findNode++;
|
||||
}//end while
|
||||
|
||||
cTopology::Node *destNode = topo.getNode(findNode);
|
||||
|
||||
IPv4Address destAddr = nodeInfo[findNode].address;
|
||||
std::string destModName = destNode->getModule()->getFullName();
|
||||
|
||||
//findet den passenden AccessPoint in topo
|
||||
int findAP = 0;
|
||||
while (findAP < topo.getNumNodes()) {
|
||||
if (accessPointName.compare(topo.getNode(findAP)->getModule()->getFullPath()) == 0) {
|
||||
destNode = topo.getNode(findAP);
|
||||
}//End if
|
||||
findAP++;
|
||||
}
|
||||
|
||||
// calculate shortest paths from everywhere towards destNode
|
||||
topo.calculateUnweightedSingleShortestPathsTo(destNode);
|
||||
|
||||
// add route (with host=destNode) to every routing table in the network
|
||||
// (excepting nodes with only one interface -- there we'll set up a default route)
|
||||
for (int j = 0; j < topo.getNumNodes(); j++) {
|
||||
if (findNode == j) continue;
|
||||
if (!nodeInfo[j].isIPNode)
|
||||
continue;
|
||||
|
||||
cTopology::Node *atNode = topo.getNode(j);
|
||||
|
||||
if (atNode->getNumPaths() == 0)
|
||||
continue; // not connected
|
||||
|
||||
if (nodeInfo[j].usesDefaultRoute)
|
||||
continue; // already added default route here
|
||||
|
||||
IPv4Address atAddr = nodeInfo[j].address;
|
||||
|
||||
IInterfaceTable *ift = nodeInfo[j].ift;
|
||||
|
||||
int outputGateId = atNode->getPath(0)->getLocalGate()->getId();
|
||||
InterfaceEntry *ie = ift->getInterfaceByNodeOutputGateId(outputGateId);
|
||||
if (!ie)
|
||||
error("%s has no interface for output gate id %d", ift->getFullPath().c_str(), outputGateId);
|
||||
|
||||
EV << " from " << atNode->getModule()->getFullName() << "=" << IPv4Address(atAddr);
|
||||
EV << " towards " << destModName << "=" << IPv4Address(destAddr) << " interface " << ie->getName() << endl;
|
||||
|
||||
// delete old route
|
||||
IRoutingTable *rt = nodeInfo[j].rt;
|
||||
int i = rt->getNumRoutes();
|
||||
for (; i > 0; i--) {
|
||||
IPv4Route* x = rt->getRoute(i - 1);
|
||||
if (x->getDestination() == destAddr)
|
||||
rt->deleteRoute(x);
|
||||
}
|
||||
|
||||
// add new route
|
||||
IPv4Route *e = new IPv4Route();
|
||||
e->setDestination(destAddr);
|
||||
e->setNetmask(IPv4Address(255, 255, 255, 255)); // full match needed
|
||||
e->setInterface(ie);
|
||||
e->setSource(IPv4Route::MANUAL);
|
||||
rt->addRoute(e);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
cPar &
|
||||
WirelessConnectivityObserver::getChannelControlPar(const char *parName) {
|
||||
return dynamic_cast<cModule *> (cc)->par(parName);
|
||||
}
|
||||
|
||||
} // end namespace moversight
|
||||
} // end namespace ubeeme
|
||||
@@ -0,0 +1,123 @@
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with this program. If not, see http://www.gnu.org/licenses/.
|
||||
//
|
||||
|
||||
/*
|
||||
* File: WirelessConnectivityObserver.cc
|
||||
* Author: thandreg
|
||||
* Author: jgaebler
|
||||
*
|
||||
* Created on October 16, 2012, 1:30 PM
|
||||
*/
|
||||
|
||||
#ifndef WIRELESSCONNECTIVITYOBSERVER_H_
|
||||
#define WIRELESSCONNECTIVITYOBSERVER_H_
|
||||
|
||||
#include "Node.h"
|
||||
|
||||
//omnet and inet includes
|
||||
#include <omnetpp.h>
|
||||
#include "INETDefs.h"
|
||||
#include "base/INotifiable.h"
|
||||
#include "linklayer/contract/MACAddress.h"
|
||||
#include "networklayer/autorouting/ipv4/FlatNetworkConfigurator.h"
|
||||
#include "world/radio/IChannelControl.h"
|
||||
|
||||
namespace ubeeme {
|
||||
namespace moversight {
|
||||
|
||||
class WirelessConnectivityObserver : public INotifiable, public FlatNetworkConfigurator {
|
||||
protected:
|
||||
|
||||
/*
|
||||
* @brief Configures IPv4 addresses and routing tables for a "flat" network
|
||||
* and initialize wirelessConnectivityObserver, means register for Notificationboard, initialize Nodelist of wireless hosts,
|
||||
* @param stage stage of Initialization
|
||||
*/
|
||||
virtual void initialize(int stage);
|
||||
|
||||
/*
|
||||
* @brief gets only self messages to update in an interval sets in ini-file
|
||||
* updates positions, distances to other nodes and time calculation of nodes in node-list
|
||||
* @param msg self message
|
||||
*/
|
||||
void handleMessage(cMessage *msg);
|
||||
|
||||
/*
|
||||
* @brief reads transmission Power from ini, starts after initialization to avoid error
|
||||
*/
|
||||
void initalizeNodes();
|
||||
|
||||
/*
|
||||
* @brief calculates the range of a Node for a faultless communication
|
||||
* @param NodesIndex the number of the editing Node in NodeList to simplify access
|
||||
* @param transmissionPower Power for transmisson, set in ini
|
||||
*/
|
||||
double calcDistFreeSpace(size_t nodesIndex, double transmissionPower);
|
||||
|
||||
/*
|
||||
* @brief updates the current Position and Speed of wireless Node
|
||||
* @param i number of editing Node in nodeList to simplify access
|
||||
*/
|
||||
void updatePositons(size_t i);
|
||||
|
||||
/*
|
||||
* @brief updates Distance to relative nodes
|
||||
* @param i number of editing node in nodeList to simplify access
|
||||
*/
|
||||
void updateDistance(size_t i);
|
||||
|
||||
/*
|
||||
* @brief notes which Node has a established connection to another, also
|
||||
* calculate the time it will probably be even more connected, based on the coordinates and speed
|
||||
* @param nodeNum number of editing Node in nodeList to simplify access
|
||||
*/
|
||||
void timeLeft(size_t nodeNum);
|
||||
|
||||
/**
|
||||
* @brief receive Notification from notificationBoard
|
||||
* @param category to identifiy the matter of changed Notification
|
||||
* @param details obtains information about the owner of notification
|
||||
*/
|
||||
void receiveChangeNotification(int category, const cPolymorphic *details);
|
||||
|
||||
/**
|
||||
* @brief adds/delete Routes to routing tables
|
||||
* @param i number of editing Node in nodeList to simplify access
|
||||
*/
|
||||
void addRoute(size_t nodeNum);
|
||||
|
||||
private:
|
||||
|
||||
IChannelControl* cc; // Pointer to the ChannelControl module
|
||||
|
||||
cPar& getChannelControlPar(const char *parName);
|
||||
|
||||
static IChannelControl *getChannelControl();
|
||||
|
||||
std::vector<Node> nodeList;
|
||||
NodeInfoVector nodeInfo;
|
||||
|
||||
cMessage * selfTrigger;
|
||||
double updateFrequency;
|
||||
|
||||
int modulNumber;
|
||||
|
||||
cTopology topo;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user