/* * I would like to thank this particular integration test * for showing me that the setUp is called for every test, * not once per testsuite as I had originally thought. */ void setUp() { mp1 = new MetaServerPacket(); mp1->setPacketType(NMT_SERVERKEEPALIVE); mp1->setSequence(1); mp1->setTimeOffset(1); mp2 = new MetaServerPacket(); mp2->setPacketType(NMT_SERVERSHAKE); mp2->addPacketData(22); mp2->setSequence(2); mp2->setTimeOffset(2); p = new PacketReader(); file_name = "/tmp/packet_test.bin"; pl = new PacketLogger(file_name); }
/** * Convenience method that evaluates what type of packet and call appropriate handle method * @param msp incoming metaserver packet * @param rsp outgoing metaserver packet to be filled */ void MetaServer::processMetaserverPacket(MetaServerPacket& msp, MetaServerPacket& rsp) { /* * Packet Sequence: store this so that we can replay the packets in the * same order after the fact * Time Offset: time in milliseconds relative to the "start time". The start time * is defined as the first packet to be processed. I chose this because * it will be possible to replay the packets in the correct order, at * exactly the same rate, relative to the start of the first packet */ if ( m_PacketSequence == 0 ) m_startTime = boost::posix_time::microsec_clock::local_time(); ++m_PacketSequence; msp.setSequence(m_PacketSequence); msp.setTimeOffset( getDeltaMillis() ); switch(msp.getPacketType()) { case NMT_SERVERKEEPALIVE: processSERVERKEEPALIVE(msp,rsp); break; case NMT_SERVERSHAKE: processSERVERSHAKE(msp,rsp); break; case NMT_TERMINATE: processTERMINATE(msp,rsp); break; case NMT_CLIENTKEEPALIVE: processCLIENTKEEPALIVE(msp,rsp); break; case NMT_CLIENTSHAKE: processCLIENTSHAKE(msp,rsp); break; case NMT_LISTREQ: processLISTREQ(msp,rsp); break; case NMT_SERVERATTR: processSERVERATTR(msp,rsp); break; case NMT_CLIENTATTR: processCLIENTATTR(msp,rsp); break; case NMT_CLIENTFILTER: processCLIENTFILTER(msp,rsp); break; default: --m_PacketSequence; m_Logger.debug("Packet Type [%u] not supported.", msp.getPacketType()); break; } /* * Flag response packets sequence and offset tagging */ ++m_PacketSequence; rsp.setSequence(m_PacketSequence); rsp.setTimeOffset( getDeltaMillis() ); /* * Packet Logging */ if ( m_logPackets ) { // always log the incoming packets, even if they are bad ( as a bad incoming packet could be the cause // of an issue ) m_PacketLogger->LogPacket(msp); // we don't want to log if: // 1) sequence is 0 : this means the sequence is not set ... this means something has gone astray elsewhere // 2) packet type is NULL : these responses are never sent to the client if ( rsp.getSequence() != 0 && rsp.getPacketType() != NMT_NULL ) m_PacketLogger->LogPacket(rsp); } }