Bug 1956

Summary: It is not possible to reuse a PacketSocket after a Close()
Product: ns-3 Reporter: Tommaso Pecorella <tommaso.pecorella>
Component: networkAssignee: ns-bugs <ns-bugs>
Status: CONFIRMED ---    
Severity: minor    
Priority: P5    
Version: ns-3-dev   
Hardware: All   
OS: All   

Description Tommaso Pecorella 2014-07-28 16:48:16 EDT
Reported here:

If you use Close on a PacketSocket, both m_shutdownSend and m_shutdownRecv are set.
However, they are not set back to false when the socket is re-opened with a new Connect.
Comment 1 Tommaso Pecorella 2014-07-29 17:41:02 EDT
The bug is more complex. The PacketSocket has an internal state machine. The states are:
   * \brief States of the socket
  enum State {
    STATE_BOUND,     // open and bound
    STATE_CONNECTED, // open, bound and connected

The real issue is that a socket starts in STATE_OPEN and it is left in STATE_CLOSED after a Close().
There is no way to return from STATE_CLOSED to STATE_OPEN, effectively making it impossible to "restart" the socket.

Funny enough, it is possible to "use" a PacketSocket also in STATE_OPEN: SendTo () can be used on non-bound and non-connected sockets.
The only trick is that non-bound sockets can not receive packets (missing m_node->RegisterProtocolHandler).