From c744b22785ff5c5ff756b6bccba0fc98a04afb5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Levente=20M=C3=A9sz=C3=A1ros?= Date: Wed, 1 Sep 2021 11:37:54 +0200 Subject: [PATCH 1/3] TemporarySharedPtr: Followed changes in omnet with class descriptor. --- src/inet/common/TemporarySharedPtr.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/inet/common/TemporarySharedPtr.h b/src/inet/common/TemporarySharedPtr.h index 0678ee813ce..97a5fa02dec 100644 --- a/src/inet/common/TemporarySharedPtr.h +++ b/src/inet/common/TemporarySharedPtr.h @@ -61,6 +61,8 @@ class TemporarySharedPtrClassDescriptor : public cClassDescriptor virtual const char *getFieldStructName(int field) const override { return classDescriptor->getFieldStructName(field); } virtual any_ptr getFieldStructValuePointer(any_ptr object, int field, int i) const override { return classDescriptor->getFieldStructValuePointer(getObjectPointer(object), field, i); } virtual void setFieldStructValuePointer(any_ptr object, int field, int i, any_ptr ptr) const override { classDescriptor->setFieldStructValuePointer(getObjectPointer(object), field, i, ptr); } + virtual cValue getFieldValue(any_ptr object, int field, int i) const override { return classDescriptor->getFieldValue(object, field, i); } + virtual void setFieldValue(any_ptr object, int field, int i, const cValue& value) const override { classDescriptor->setFieldValue(object, field, i, value); } }; /** From 656bdb56ddcc7ba8ffc1b6dd225221847e715e43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Levente=20M=C3=A9sz=C3=A1ros?= Date: Wed, 1 Sep 2021 11:17:51 +0200 Subject: [PATCH 2/3] IApskModulation: Fixed field types to be the same as in the existing C++ class. --- .../wireless/common/contract/packetlevel/IModulation.msg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/inet/physicallayer/wireless/common/contract/packetlevel/IModulation.msg b/src/inet/physicallayer/wireless/common/contract/packetlevel/IModulation.msg index 245878cc9bc..0d2c93f54e6 100644 --- a/src/inet/physicallayer/wireless/common/contract/packetlevel/IModulation.msg +++ b/src/inet/physicallayer/wireless/common/contract/packetlevel/IModulation.msg @@ -34,6 +34,6 @@ class IApskModulation { @existingClass; @descriptor(readonly); - int codeWordSize; - int constellationSize; + unsigned int codeWordSize; + unsigned int constellationSize; }; From b99e4651df3a38294a9d96228b5818e1224cd759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Levente=20M=C3=A9sz=C3=A1ros?= Date: Wed, 8 Sep 2021 18:25:25 +0200 Subject: [PATCH 3/3] TODO TCP: Implemented graceful stop operation which closes all open connections and waits for the close to be finished. TelnetApp is modified to test this with shutdownrestart example, this modification is not needed Open questions: - what happens with the callback to the application (which is already stopped) when the socket is closed? Currently it causes an error. - TCP starts a very long timeout (120s) after receiving the FIN bit, so the connection to be removed takes a lot of time --- examples/inet/shutdownrestart/omnetpp.ini | 4 +++ src/inet/applications/tcpapp/TelnetApp.cc | 12 ++++----- .../common/lifecycle/OperationalMixinImpl.h | 4 +-- src/inet/transportlayer/tcp/Tcp.cc | 27 ++++++++++++++++--- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/examples/inet/shutdownrestart/omnetpp.ini b/examples/inet/shutdownrestart/omnetpp.ini index 76155c635ba..b3d2a1206ab 100644 --- a/examples/inet/shutdownrestart/omnetpp.ini +++ b/examples/inet/shutdownrestart/omnetpp.ini @@ -8,6 +8,10 @@ sim-time-limit = 100s **.hasStatus = true +# this timer had to modified to reduce the amount of time to wait for segments after the FYN is received +# what else can we do? +**.msl = 0s + *.scenarioManager.script = xmldoc(${scenario = "scenario_node.xml", "scenario_app.xml", "scenario_iface.xml"}) [Config Ping] diff --git a/src/inet/applications/tcpapp/TelnetApp.cc b/src/inet/applications/tcpapp/TelnetApp.cc index 95c7a1d50b2..72db16178a5 100644 --- a/src/inet/applications/tcpapp/TelnetApp.cc +++ b/src/inet/applications/tcpapp/TelnetApp.cc @@ -74,8 +74,8 @@ void TelnetApp::handleStopOperation(LifecycleOperation *operation) { cancelEvent(timeoutMsg); if (socket.isOpen()) { - close(); - delayActiveOperationFinish(par("stopOperationTimeout")); +// close(); +// delayActiveOperationFinish(par("stopOperationTimeout")); } } @@ -190,10 +190,10 @@ void TelnetApp::socketClosed(TcpSocket *socket) timeoutMsg->setKind(MSGKIND_CONNECT); checkedScheduleAt(simTime() + par("idleInterval"), timeoutMsg); } - else if (operationalState == State::STOPPING_OPERATION) { - if (!this->socket.isOpen()) - startActiveOperationExtraTimeOrFinish(par("stopOperationExtraTime")); - } +// else if (operationalState == State::STOPPING_OPERATION) { +// if (!this->socket.isOpen()) +// startActiveOperationExtraTimeOrFinish(par("stopOperationExtraTime")); +// } } void TelnetApp::socketFailure(TcpSocket *socket, int code) diff --git a/src/inet/common/lifecycle/OperationalMixinImpl.h b/src/inet/common/lifecycle/OperationalMixinImpl.h index 94aef1e03a0..dec6e590eb7 100644 --- a/src/inet/common/lifecycle/OperationalMixinImpl.h +++ b/src/inet/common/lifecycle/OperationalMixinImpl.h @@ -84,8 +84,8 @@ void OperationalMixin::handleMessageWhenDown(cMessage *message) throw cRuntimeError("Self message '%s' received when %s is down", message->getName(), T::getComponentType()->getName()); else if (simTime() == lastChange) EV_WARN << T::getComponentType()->getName() << " is down, dropping '" << message->getName() << "' message\n"; - else - throw cRuntimeError("Message '%s' received when %s is down", message->getName(), T::getComponentType()->getName()); +// else +// throw cRuntimeError("Message '%s' received when %s is down", message->getName(), T::getComponentType()->getName()); delete message; } diff --git a/src/inet/transportlayer/tcp/Tcp.cc b/src/inet/transportlayer/tcp/Tcp.cc index a98649ee766..9e4180b0d76 100644 --- a/src/inet/transportlayer/tcp/Tcp.cc +++ b/src/inet/transportlayer/tcp/Tcp.cc @@ -227,6 +227,9 @@ void Tcp::removeConnection(TcpConnection *conn) emit(tcpConnectionRemovedSignal, conn); conn->deleteModule(); + + if (operationalState == State::STOPPING_OPERATION && tcpAppConnMap.empty()) + startActiveOperationExtraTimeOrFinish(par("stopOperationExtraTime")); } TcpConnection *Tcp::findConnForSegment(const Ptr& tcpHeader, L3Address srcAddr, L3Address destAddr) @@ -382,10 +385,26 @@ void Tcp::handleStartOperation(LifecycleOperation *operation) void Tcp::handleStopOperation(LifecycleOperation *operation) { - // FIXME close connections??? yes, because the applications may not close them!!! - reset(); - delayActiveOperationFinish(par("stopOperationTimeout")); - startActiveOperationExtraTimeOrFinish(par("stopOperationExtraTime")); + if (tcpAppConnMap.empty()) + startActiveOperationExtraTimeOrFinish(par("stopOperationExtraTime")); + else { + for (auto& elem : tcpAppConnMap) { + auto connection = elem.second; + auto state = connection->getFsmState(); + if (state != TCP_S_FIN_WAIT_1 && + state != TCP_S_FIN_WAIT_2 && + state != TCP_S_CLOSING && + state != TCP_S_LAST_ACK && + state != TCP_S_TIME_WAIT) + { + auto request = new Request("CLOSE", TCP_C_CLOSE); + TcpCommand *cmd = new TcpCommand(); + request->setControlInfo(cmd); + connection->processAppCommand(request); + } + } + delayActiveOperationFinish(par("stopOperationTimeout")); + } } void Tcp::handleCrashOperation(LifecycleOperation *operation)