Skip to content

Commit

Permalink
Merge with inet framework
Browse files Browse the repository at this point in the history
  • Loading branch information
aarizaq committed May 31, 2017
1 parent fbd3663 commit 660acc2
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 46 deletions.
1 change: 1 addition & 0 deletions src/inet/mobility/base/MobilityBase.cc
Expand Up @@ -52,6 +52,7 @@ static bool isFiniteNumber(double value)

MobilityBase::MobilityBase() :
visualRepresentation(nullptr),
canvasProjection(nullptr),
constraintAreaMin(Coord::ZERO),
constraintAreaMax(Coord::ZERO),
lastPosition(Coord::ZERO),
Expand Down
5 changes: 2 additions & 3 deletions src/inet/mobility/single/TurtleMobility.cc
Expand Up @@ -346,15 +346,14 @@ void TurtleMobility::computeMaxSpeed(cXMLElement *nodes)
cXMLElementList childs = nodes->getChildren();
for (auto & child : childs)
{
const char *speedAttr = (child)->getAttribute("speed");
const char *speedAttr = child->getAttribute("speed");
if (speedAttr)
{
double speed = atof(speedAttr);
if (speed > maxSpeed)
maxSpeed = speed;
}
if (child)
computeMaxSpeed(child);
computeMaxSpeed(child);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/inet/networklayer/common/InterfaceEntry.cc
Expand Up @@ -398,7 +398,11 @@ void InterfaceEntry::changeMulticastGroupMembership(const L3Address& multicastAd
}

IPv4Address InterfaceEntry::getIPv4Address() const {
#ifdef WITH_IPv4
return ipv4data == nullptr ? IPv4Address::UNSPECIFIED_ADDRESS : ipv4data->getIPAddress();
#else
return IPv4Address::UNSPECIFIED_ADDRESS;
#endif // ifdef WITH_IPv4
}

} // namespace inet
Expand Down
Expand Up @@ -464,7 +464,7 @@ const char *NetworkConfiguratorBase::getWirelessId(InterfaceEntry *interfaceEntr
cModule *radioModule = interfaceModule->getSubmodule("radio");
const IRadio *radio = dynamic_cast<const IRadio *>(radioModule);
if (radio != nullptr) {
const cModule *mediumModule = dynamic_cast<const cModule *>(radio->getMedium());
const cModule *mediumModule = check_and_cast<const cModule *>(radio->getMedium());
return mediumModule->getFullName();
}
#endif
Expand Down
8 changes: 6 additions & 2 deletions src/inet/networklayer/ipv4/IPv4RoutingTable.cc
Expand Up @@ -351,8 +351,9 @@ bool IPv4RoutingTable::isLocalAddress(const IPv4Address& dest) const
if (localAddresses.empty()) {
// collect interface addresses if not yet done
for (int i = 0; i < ift->getNumInterfaces(); i++) {
IPv4Address interfaceAddr = ift->getInterface(i)->ipv4Data()->getIPAddress();
localAddresses.insert(interfaceAddr);
auto ipv4Data = ift->getInterface(i)->ipv4Data();
if (ipv4Data != nullptr)
localAddresses.insert(ipv4Data->getIPAddress());
}
}

Expand Down Expand Up @@ -590,6 +591,7 @@ void IPv4RoutingTable::internalAddRoute(IPv4Route *entry)
void IPv4RoutingTable::addRoute(IPv4Route *entry)
{
Enter_Method("addRoute(...)");
EV_INFO << "add route " << entry->info() << "\n";

internalAddRoute(entry);

Expand All @@ -615,6 +617,7 @@ IPv4Route *IPv4RoutingTable::removeRoute(IPv4Route *entry)
entry = internalRemoveRoute(entry);

if (entry != nullptr) {
EV_INFO << "remove route " << entry->info() << "\n";
invalidateCache();
ASSERT(entry->getRoutingTable() == this); // still filled in, for the listeners' benefit
emit(NF_ROUTE_DELETED, entry);
Expand All @@ -630,6 +633,7 @@ bool IPv4RoutingTable::deleteRoute(IPv4Route *entry) //TODO this is almost du
entry = internalRemoveRoute(entry);

if (entry != nullptr) {
EV_INFO << "delete route " << entry->info() << "\n";
invalidateCache();
ASSERT(entry->getRoutingTable() == this); // still filled in, for the listeners' benefit
emit(NF_ROUTE_DELETED, entry);
Expand Down
2 changes: 2 additions & 0 deletions src/inet/transportlayer/tcp/TCPConnectionBase.cc
Expand Up @@ -75,6 +75,8 @@ TCPStateVariables::TCPStateVariables()

ws_support = false; // will be set from configureStateVariables()
ws_enabled = false;
ws_manual_scale = -1;

snd_ws = false;
rcv_ws = false;
rcv_wnd_scale = 0; // will be set from configureStateVariables()
Expand Down
8 changes: 4 additions & 4 deletions src/inet/transportlayer/udp/UDP.cc
Expand Up @@ -465,12 +465,12 @@ void UDP::processICMPError(cPacket *pk)
throw cRuntimeError("Unrecognized packet (%s)%s: not an ICMP error message", pk->getClassName(), pk->getName());
}

EV_WARN << "ICMP error received: type=" << type << " code=" << code
<< " about packet " << localAddr << ":" << localPort << " > "
<< remoteAddr << ":" << remotePort << "\n";

// identify socket and report error to it
if (udpHeaderAvailable) {
EV_WARN << "ICMP error received: type=" << type << " code=" << code
<< " about packet " << localAddr << ":" << localPort << " > "
<< remoteAddr << ":" << remotePort << "\n";

SockDesc *sd = findSocketForUnicastPacket(localAddr, localPort, remoteAddr, remotePort);
if (sd) {
// send UDP_I_ERROR to socket
Expand Down
24 changes: 11 additions & 13 deletions src/inet/visualizer/base/LinkVisualizerBase.cc
Expand Up @@ -186,7 +186,9 @@ void LinkVisualizerBase::setLastModule(int treeId, cModule *module)

void LinkVisualizerBase::removeLastModule(int treeId)
{
lastModules.erase(lastModules.find(treeId));
auto it = lastModules.find(treeId);
if (it != lastModules.end())
lastModules.erase(it);
}

void LinkVisualizerBase::refreshLinkVisualization(const LinkVisualization *linkVisualization, cPacket *packet)
Expand Down Expand Up @@ -215,10 +217,11 @@ void LinkVisualizerBase::receiveSignal(cComponent *source, simsignal_t signal, c
auto networkNode = getContainingNode(module);
auto interfaceEntry = getInterfaceEntry(networkNode, module);
auto packet = check_and_cast<cPacket *>(object);
if (nodeFilter.matches(networkNode) && interfaceFilter.matches(interfaceEntry) && packetFilter.matches(packet)) {
auto treeId = packet->getTreeId();
auto treeId = packet->getTreeId();
if (nodeFilter.matches(networkNode) && interfaceFilter.matches(interfaceEntry) && packetFilter.matches(packet))
setLastModule(treeId, module);
}
else
removeLastModule(treeId);
}
}
else if (signal == LayeredProtocolBase::packetSentToUpperSignal) {
Expand All @@ -227,15 +230,10 @@ void LinkVisualizerBase::receiveSignal(cComponent *source, simsignal_t signal, c
auto networkNode = getContainingNode(module);
auto interfaceEntry = getInterfaceEntry(networkNode, module);
auto packet = check_and_cast<cPacket *>(object);
if (nodeFilter.matches(networkNode) && interfaceFilter.matches(interfaceEntry) && packetFilter.matches(packet)) {
auto treeId = packet->getTreeId();
auto lastModule = getLastModule(treeId);
if (lastModule != nullptr) {
updateLinkVisualization(getContainingNode(lastModule), getContainingNode(module), packet);
// TODO: breaks due to multiple recipient?
// removeLastModule(treeId);
}
}
auto treeId = packet->getTreeId();
auto lastModule = getLastModule(treeId);
if (lastModule != nullptr && nodeFilter.matches(networkNode) && interfaceFilter.matches(interfaceEntry) && packetFilter.matches(packet))
updateLinkVisualization(getContainingNode(lastModule), getContainingNode(module), packet);
}
}
else
Expand Down
40 changes: 37 additions & 3 deletions src/inet/visualizer/base/PathCanvasVisualizerBase.cc
Expand Up @@ -29,8 +29,12 @@ static inline double determinant(double a1, double a2, double b1, double b2)
return a1 * b2 - a2 * b1;
}

static Coord intersectLines(const Coord& begin1, const Coord& end1, const Coord& begin2, const Coord& end2)
static Coord intersectLines(const LineSegment& segment1, const LineSegment& segment2)
{
const Coord& begin1 = segment1.getPoint1();
const Coord& end1 = segment1.getPoint2();
const Coord& begin2 = segment2.getPoint1();
const Coord& end2 = segment2.getPoint2();
double x1 = begin1.x;
double y1 = begin1.y;
double x2 = end1.x;
Expand All @@ -47,6 +51,14 @@ static Coord intersectLines(const Coord& begin1, const Coord& end1, const Coord&
return Coord(x, y, 0);
}

bool isPointOnSegment(const LineSegment& segment, const Coord& point)
{
auto& p1 = segment.getPoint1();
auto& p2 = segment.getPoint2();
return (p2.x <= std::max(p1.x, point.x) && p2.x >= std::min(p1.x, point.x) &&
p2.y <= std::max(p1.y, point.y) && p2.y >= std::min(p1.y, point.y));
}

PathCanvasVisualizerBase::PathCanvasVisualization::PathCanvasVisualization(const std::vector<int>& path, LabeledPolylineFigure *figure) :
PathVisualization(path),
figure(figure)
Expand Down Expand Up @@ -96,8 +108,29 @@ void PathCanvasVisualizerBase::refreshDisplay() const
if (index == 0)
points.push_back(canvasProjection->computeCanvasPoint(segments[index].getPoint1()));
if (index > 0) {
Coord intersection = intersectLines(segments[index].getPoint1(), segments[index].getPoint2(), segments[index - 1].getPoint1(), segments[index - 1].getPoint2());
points.push_back(canvasProjection->computeCanvasPoint(intersection));
auto& segment1 = segments[index - 1];
auto& segment2 = segments[index];
Coord intersection = intersectLines(segment1, segment2);
if (std::isfinite(intersection.x) && std::isfinite(intersection.y)) {
if (isPointOnSegment(segment1, intersection) && isPointOnSegment(segment2, intersection)) {
points.push_back(canvasProjection->computeCanvasPoint(intersection));
}
else {
double distance = segment1.getPoint2().distance(segment2.getPoint1());
double distance1 = intersection.distance(segment1.getPoint2());
double distance2 = intersection.distance(segment2.getPoint1());
if (distance1 + distance2 < 2 * distance)
points.push_back(canvasProjection->computeCanvasPoint(intersection));
else {
points.push_back(canvasProjection->computeCanvasPoint(segment1.getPoint2()));
points.push_back(canvasProjection->computeCanvasPoint(segment2.getPoint1()));
}
}
}
else {
points.push_back(canvasProjection->computeCanvasPoint(segment1.getPoint2()));
points.push_back(canvasProjection->computeCanvasPoint(segment2.getPoint1()));
}
}
if (index == segments.size() - 1)
points.push_back(canvasProjection->computeCanvasPoint(segments[index].getPoint2()));
Expand All @@ -111,6 +144,7 @@ const PathVisualizerBase::PathVisualization *PathCanvasVisualizerBase::createPat
{
auto figure = new LabeledPolylineFigure("path");
auto polylineFigure = figure->getPolylineFigure();
polylineFigure->setSmooth(lineSmooth);
polylineFigure->setLineWidth(lineWidth);
polylineFigure->setLineStyle(lineStyle);
polylineFigure->setEndArrowhead(cFigure::ARROW_BARBED);
Expand Down
16 changes: 6 additions & 10 deletions src/inet/visualizer/base/PathVisualizerBase.cc
Expand Up @@ -61,6 +61,7 @@ void PathVisualizerBase::initialize(int stage)
lineColorSet.parseColors(par("lineColor"));
lineStyle = cFigure::parseLineStyle(par("lineStyle"));
lineWidth = par("lineWidth");
lineSmooth = par("lineSmooth");
lineShift = par("lineShift");
lineShiftMode = par("lineShiftMode");
lineContactSpacing = par("lineContactSpacing");
Expand Down Expand Up @@ -198,7 +199,10 @@ const std::vector<int> *PathVisualizerBase::getIncompletePath(int treeId)

void PathVisualizerBase::addToIncompletePath(int treeId, cModule *module)
{
incompletePaths[treeId].push_back(module->getId());
auto& moduleIds = incompletePaths[treeId];
auto moduleId = module->getId();
if (moduleIds.size() == 0 || moduleIds[moduleIds.size() - 1] != moduleId)
moduleIds.push_back(moduleId);
}

void PathVisualizerBase::removeIncompletePath(int treeId)
Expand Down Expand Up @@ -238,15 +242,7 @@ void PathVisualizerBase::receiveSignal(cComponent *source, simsignal_t signal, c
}
}
else if (signal == LayeredProtocolBase::packetReceivedFromLowerSignal) {
if (isPathEnd(static_cast<cModule *>(source))) {
auto packet = check_and_cast<cPacket *>(object);
if (packetFilter.matches(packet)) {
auto treeId = packet->getEncapsulationTreeId();
auto module = check_and_cast<cModule *>(source);
addToIncompletePath(treeId, getContainingNode(module));
}
}
else if (isPathElement(static_cast<cModule *>(source))) {
if (isPathElement(static_cast<cModule *>(source))) {
auto packet = check_and_cast<cPacket *>(object);
if (packetFilter.matches(packet)) {
auto treeId = packet->getEncapsulationTreeId();
Expand Down
1 change: 1 addition & 0 deletions src/inet/visualizer/base/PathVisualizerBase.h
Expand Up @@ -67,6 +67,7 @@ class INET_API PathVisualizerBase : public VisualizerBase, public cListener
ColorSet lineColorSet;
cFigure::LineStyle lineStyle;
double lineWidth = NaN;
bool lineSmooth = false;
double lineShift = NaN;
const char *lineShiftMode = nullptr;
double lineContactSpacing = NaN;
Expand Down
1 change: 1 addition & 0 deletions src/inet/visualizer/base/PathVisualizerBase.ned
Expand Up @@ -57,6 +57,7 @@ simple PathVisualizerBase extends VisualizerBase
string lineColor @enum("light", "dark") = default("dark"); // route color is a list of colors, a set of dark colors by default
string lineStyle = default("solid"); // route line style (solid, dashed, dotted)
double lineWidth = default(3); // route line width
bool lineSmooth = default(false); // when true polylines are displayed as curves

double lineShift = default(10); // route line shift to avoid overlapping routes
string lineShiftMode = default("normal"); // determines how overlapping lines are shifted, possible values are: normal, x, y, z; optional prefix + or -
Expand Down
2 changes: 1 addition & 1 deletion src/inet/visualizer/mobility/MobilityCanvasVisualizer.cc
Expand Up @@ -60,7 +60,7 @@ void MobilityCanvasVisualizer::refreshDisplay() const
auto position = canvasProjection->computeCanvasPoint(mobility->getCurrentPosition());
auto orientation = mobility->getCurrentAngularPosition();
auto velocity = canvasProjection->computeCanvasPoint(mobility->getCurrentSpeed());
mobilityVisualization->networkNodeVisualization->setPosition(cFigure::Point(position.x, position.y));
mobilityVisualization->networkNodeVisualization->setTransform(cFigure::Transform().translate(position.x, position.y));
if (mobilityVisualization->visualRepresentation != nullptr)
setPosition(mobilityVisualization->visualRepresentation, position);
if (displayOrientations) {
Expand Down
Expand Up @@ -57,6 +57,11 @@ bool NetworkRouteCanvasVisualizer::isPathElement(cModule *module) const
return true;
#endif

#ifdef WITH_IPv4
if (dynamic_cast<IPv4 *>(module) != nullptr)
return true;
#endif

return false;
}

Expand Down
8 changes: 5 additions & 3 deletions src/inet/visualizer/scene/NetworkNodeCanvasVisualization.cc
Expand Up @@ -39,10 +39,12 @@ static BoxedLabelFigure *createRectangle(const char *label) {
}

NetworkNodeCanvasVisualization::NetworkNodeCanvasVisualization(cModule *networkNode, double annotationSpacing) :
cPanelFigure(networkNode->getFullName()),
cGroupFigure(networkNode->getFullName()),
networkNode(networkNode),
annotationSpacing(annotationSpacing)
{
annotationFigure = new cPanelFigure("annotation");
addFigure(annotationFigure);
submoduleBounds = getEnvir()->getSubmoduleBounds(networkNode);
submoduleBounds.x = -submoduleBounds.width / 2;
submoduleBounds.y = -submoduleBounds.height / 2;
Expand All @@ -57,7 +59,7 @@ void NetworkNodeCanvasVisualization::refreshDisplay()
void NetworkNodeCanvasVisualization::addAnnotation(cFigure *figure, cFigure::Point size, Displacement displacement, double priority)
{
annotations.push_back(Annotation(figure, size, displacement, priority));
addFigure(figure);
annotationFigure->addFigure(figure);
isLayoutInvalid = true;
}

Expand All @@ -70,7 +72,7 @@ void NetworkNodeCanvasVisualization::removeAnnotation(cFigure *figure)
break;
}
}
removeFigure(figure);
annotationFigure->removeFigure(figure);
isLayoutInvalid = true;
}

Expand Down
3 changes: 2 additions & 1 deletion src/inet/visualizer/scene/NetworkNodeCanvasVisualization.h
Expand Up @@ -25,7 +25,7 @@ namespace inet {

namespace visualizer {

class INET_API NetworkNodeCanvasVisualization : public cPanelFigure
class INET_API NetworkNodeCanvasVisualization : public cGroupFigure
{
protected:
class INET_API Annotation {
Expand All @@ -48,6 +48,7 @@ class INET_API NetworkNodeCanvasVisualization : public cPanelFigure
bool isLayoutInvalid = false;
cFigure::Rectangle submoduleBounds;
std::vector<Annotation> annotations;
cPanelFigure *annotationFigure = nullptr;

protected:
virtual void layout();
Expand Down
4 changes: 2 additions & 2 deletions src/inet/visualizer/scene/NetworkNodeCanvasVisualizer.cc
Expand Up @@ -38,7 +38,7 @@ void NetworkNodeCanvasVisualizer::initialize(int stage)
auto position = canvasProjection->computeCanvasPoint(getPosition(networkNode));
auto visualization = createNetworkNodeVisualization(networkNode);
visualization->setZIndex(zIndex);
visualization->setPosition(cFigure::Point(position.x, position.y));
visualization->setTransform(cFigure::Transform().translate(position.x, position.y));
setNetworkNodeVisualization(networkNode, visualization);
visualizerTargetModule->getCanvas()->addFigure(visualization);
}
Expand All @@ -52,7 +52,7 @@ void NetworkNodeCanvasVisualizer::refreshDisplay() const
auto networkNode = it.first;
auto visualization = it.second;
auto position = canvasProjection->computeCanvasPoint(getPosition(networkNode));
visualization->setPosition(cFigure::Point(position.x, position.y));
visualization->setTransform(cFigure::Transform().translate(position.x, position.y));
visualization->refreshDisplay();
}
}
Expand Down

0 comments on commit 660acc2

Please sign in to comment.