'Test that after loopback mode has been set, multicast packets are
delivered to their sender.'

def test_loopback(self):

    self.assertEqual(self.server.transport.getLoopbackMode(), 1)
    addr = self.server.transport.getHost()
    joined = self.server.transport.joinGroup('225.0.0.250')
    def cbJoined(ignored):
        d = self.server.packetReceived = Deferred()
        self.server.transport.write('hello', ('225.0.0.250', addr.port))
        return d
    joined.addCallback(cbJoined)
    def cbPacket(ignored):
        self.assertEqual(len(self.server.packets), 1)
        self.server.transport.setLoopbackMode(0)
        self.assertEqual(self.server.transport.getLoopbackMode(), 0)
        self.server.transport.write('hello', ('225.0.0.250', addr.port))
        d = Deferred()
        reactor.callLater(0, d.callback, None)
        return d
    joined.addCallback(cbPacket)
    def cbNoPacket(ignored):
        self.assertEqual(len(self.server.packets), 1)
    joined.addCallback(cbNoPacket)
    return joined
