Exemple #1
0
/*
 * Receive a control message
 */
static int
ng_vjc_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
	const priv_p priv = NG_NODE_PRIVATE(node);
	struct ng_mesg *resp = NULL;
	int error = 0;
	struct ng_mesg *msg;

	NGI_GET_MSG(item, msg);
	/* Check type cookie */
	switch (msg->header.typecookie) {
	case NGM_VJC_COOKIE:
		switch (msg->header.cmd) {
		case NGM_VJC_SET_CONFIG:
		    {
			struct ngm_vjc_config *const c =
				(struct ngm_vjc_config *) msg->data;

			if (msg->header.arglen != sizeof(*c))
				ERROUT(EINVAL);
			if ((priv->conf.enableComp || priv->conf.enableDecomp)
			    && (c->enableComp || c->enableDecomp))
				ERROUT(EALREADY);
			if (c->enableComp) {
				if (c->maxChannel > NG_VJC_MAX_CHANNELS - 1
				    || c->maxChannel < NG_VJC_MIN_CHANNELS - 1)
					ERROUT(EINVAL);
			} else
				c->maxChannel = NG_VJC_MAX_CHANNELS - 1;
			if (c->enableComp != 0 || c->enableDecomp != 0) {
				bzero(&priv->slc, sizeof(priv->slc));
				sl_compress_init(&priv->slc, c->maxChannel);
			}
			priv->conf = *c;
			break;
		    }
		case NGM_VJC_GET_CONFIG:
		    {
			struct ngm_vjc_config *conf;

			NG_MKRESPONSE(resp, msg, sizeof(*conf), M_NOWAIT);
			if (resp == NULL)
				ERROUT(ENOMEM);
			conf = (struct ngm_vjc_config *)resp->data;
			*conf = priv->conf;
			break;
		    }
		case NGM_VJC_GET_STATE:
		    {
			const struct slcompress *const sl0 = &priv->slc;
			struct slcompress *sl;
			u_int16_t index;
			int i;

			/* Get response structure */
			NG_MKRESPONSE(resp, msg, sizeof(*sl), M_NOWAIT);
			if (resp == NULL)
				ERROUT(ENOMEM);
			sl = (struct slcompress *)resp->data;
			*sl = *sl0;

			/* Replace pointers with integer indicies */
			if (sl->last_cs != NULL) {
				index = sl0->last_cs - sl0->tstate;
				bzero(&sl->last_cs, sizeof(sl->last_cs));
				*((u_int16_t *)&sl->last_cs) = index;
			}
			for (i = 0; i < MAX_STATES; i++) {
				struct cstate *const cs = &sl->tstate[i];

				index = sl0->tstate[i].cs_next - sl0->tstate;
				bzero(&cs->cs_next, sizeof(cs->cs_next));
				*((u_int16_t *)&cs->cs_next) = index;
			}
			break;
		    }
		case NGM_VJC_CLR_STATS:
			priv->slc.sls_packets = 0;
			priv->slc.sls_compressed = 0;
			priv->slc.sls_searches = 0;
			priv->slc.sls_misses = 0;
			priv->slc.sls_uncompressedin = 0;
			priv->slc.sls_compressedin = 0;
			priv->slc.sls_errorin = 0;
			priv->slc.sls_tossed = 0;
			break;
		case NGM_VJC_RECV_ERROR:
			sl_uncompress_tcp(NULL, 0, TYPE_ERROR, &priv->slc);
			break;
		default:
			error = EINVAL;
			break;
		}
		break;
	default:
		error = EINVAL;
		break;
	}
done:
	NG_RESPOND_MSG(error, node, item, resp);
	NG_FREE_MSG(msg);
	return (error);
}
void CVJDecompressTypeErrorTest::ProcessPacketL()
/**
This is a virtual function. 
This function feeds precompressed IP/TCP packets into both 
the VJDeCompressor (unit under test) and the Referece Decompressor 
(provided in RFC 1144).
The output of the VJDeCompressor is compared against the output of 
the Reference Decompressor to verify its corectness 
*/

{	
		TUint packetType = TrimPacketBeforeDecompression();
		
		if (packetType == 911)
		{
		    // Packet type is unsupported. Abort test.
		    SetTestStepResult(EFail);
		    return;
		}
			
		// Create packet buffer to be sent to reference decompressor
		// This is to prevent compromising the test results if the compressor/decompressor alters the original data
	    HBufC8* refPacketBuffer = HBufC8::NewMaxLC(TPcapRecord::KMaxPacketSize+KRefPacketHeaderSpace);
	    // Reserve some space at the head of the HBufC8 for the uncompressed header
	    // The reference decompressor expects the packet has enough space to prepend 120 byes of resconstructed header 
	    TPtr8 refInputPtr(const_cast<TUint8*>(refPacketBuffer->Ptr())+KRefPacketHeaderSpace, refPacketBuffer->Length()-KRefPacketHeaderSpace);
	    refInputPtr = iRec->Data();
	    
	    TUint8 *refdecompOutput = NULL;
	    TInt refPacketLen = refInputPtr.Length();
	  
	    // Create packet buffer to be sent to VJDecompressor
	    // This is to prevent compromising the test results if the compressor/decompressor alters the original data
	    // The size of the HBuf object must have a maximum length that is big enough to hold the decompressed data
	    HBufC8* vjPacketBuffer = HBufC8::NewLC(TPcapRecord::KMaxPacketSize);
	    TPtr8 vjOutputPtr (vjPacketBuffer->Des());
	    vjOutputPtr = iRec->Data();
	    		  
	    iPacket.CopyIn(*vjPacketBuffer, 0); 
	    iPacket.TrimEnd(vjPacketBuffer->Length());
		 
	   
	    // Create info packet
 	    RMBufPacket pkt;
	    RMBufPktInfo* info = 0;
        info = pkt.NewInfoL();  
       	info->iLength = vjPacketBuffer->Length();
        pkt.Pack();
        iPacket.Prepend(pkt);
	    		
	    // Put info packet in front of this packet 
	    TUint vjdecompRet;
	    
	     //-------------- substep 7 -------------------- 
	    // decompress the packet using VJDeCompressor and Reference decompressor 
	    INFO_PRINTF1(_L("  07, 08 Decompress the packet using VJDeCompressor and Reference Decompressor:"));
	    
	    switch (packetType)
	    {
	        case KPppIdIp:
	        // the packet is TYPE_IP
	             // decompress TYPE_IP packet using our reference decompressor
	            INFO_PRINTF1(_L("  07 Decompress TYPE_IP packet using reference decompressor:"));
      			refdecompOutput = sl_uncompress_tcp(const_cast<TUint8*>(refInputPtr.Ptr()), &refPacketLen, (TUint)TYPE_IP, iComp);
	    
	            // VJ Decompressor function is not called because the packet is TYPE_IP
	            INFO_PRINTF1(_L("  08 TYPE_IP packet is not modified by VJDecompressor."));
	            vjdecompRet = ETrue;
	    		break;
  		    case KPppIdVjCompTcp:
	        // the packet is COMPRESSED_TCP
	            // decompress using our reference decompressor
	            INFO_PRINTF1(_L("  07 Decompress COMPRESSED_TCP packet using reference decompressor:"));
      			refdecompOutput = sl_uncompress_tcp(const_cast<TUint8*>(refInputPtr.Ptr()), &refPacketLen, (TUint)TYPE_COMPRESSED_TCP, iComp);
	        
                //decompress using our VJ Decompressor
	            INFO_PRINTF1(_L("  08 Decompress COMPRESSED_TCP packet using VJDeCompressor:"));
	            vjdecompRet = iVJDeCompressor->DecompVJComp(iPacket);
	            INFO_PRINTF2(_L(" 08 COMPRESSED_TCP packet is decompressed: %d"), vjdecompRet);
	   	  		break;
	        case KPppIdVjUncompTcp:
	        // the packet is UNCOMPRESSED_TCP
	            // decompress using our reference Compressor
	            INFO_PRINTF1(_L("  07 Decompress UNCOMPRESSED_TCP packet using reference decompressor:"));
      			refdecompOutput = sl_uncompress_tcp(const_cast<TUint8*>(refInputPtr.Ptr()), &refPacketLen, (TUint)TYPE_UNCOMPRESSED_TCP, iComp);
	        	
	        //decompress using our VJ Decompressor
	            INFO_PRINTF1(_L("  08 Decompress UNCOMPRESSED_TCP packet using VJDeCompressor:"));
	            vjdecompRet = iVJDeCompressor->DecompVJUncomp(iPacket);
	            INFO_PRINTF2(_L(" 08 UNCOMPRESSED_TCP packet is decompressed: %d"), vjdecompRet);
	        	break;
	        default: 
	        //the packet is TYPE_ERROR
	            // set 'toss' flag and discard COMPRESSED_TCP packet until one with C bit set
	            // or an UNCOMPRESSED_TCP packet arrives
	             // decompress using our reference decompressor
	            INFO_PRINTF1(_L("  07 Decompress TYPE_ERROR packet using reference decompressor:"));
      			refdecompOutput = sl_uncompress_tcp(const_cast<TUint8*>(refInputPtr.Ptr()), &refPacketLen, (TUint)TYPE_ERROR, iComp);
	     		//decompress using our VJ Decompressor
	            INFO_PRINTF1(_L("  08 Handle TYPE_ERROR packet using VJDeCompressor:"));
	            iVJDeCompressor->CRCError(); 
	            vjdecompRet = EFalse;
	    		break;
	    }    
	    
	     if ((vjdecompRet) && refdecompOutput != 0)
	     {
	         //--------------substep 09----------------------
 	         // Display VJ decompressed packet
	         INFO_PRINTF1(_L("  09 The VJ decompressed packet:"));
	     
	         // The decompressed data should be larger than the compressed data
	         // So we need to expand the size of the pointer in order to hold the decompressed data
	         vjOutputPtr.SetMax();
	         
	         // Remove info packet 
	         iPacket.Remove();
	         iPacket.CopyOut(vjOutputPtr);	
 			 
	         INFO_PRINTF2(_L("VJ decompressed packet len: %d"), vjPacketBuffer->Length()); 
	         // TPtrC8 object is created because DumpIp() takes a TPtrC8 object as a parameter
	         TPtrC8 vjOutputPtrC (vjOutputPtr);
	         DumpIp(vjOutputPtrC);
	     
	         //--------------substep 10----------------------
 	         // Display REF decompressed packet
	         INFO_PRINTF1(_L("10 The REF decompressed packet is:")); 
	         TPtrC8 refOutputPtrC(refdecompOutput, refPacketLen);
	         DumpIp(refOutputPtrC);
	         
 	         //--------------substep 11----------------------
 	         //Compare the results of the reference compressor output and our VJ compressor output
 	     
 	         INFO_PRINTF1(_L("  11 Compare the result of the compression by VJCompressor to Reference compressor:"));
 	         INFO_PRINTF2(_L(" Size of VJ comp output: %d"), vjOutputPtrC.Length()); 
 		     INFO_PRINTF2(_L(" Size of Reference comp output: %d"), refOutputPtrC.Length()); 
 	     
 	    	 if (!CompareOutput(vjOutputPtrC, refOutputPtrC))
 		     {
 	              INFO_PRINTF1(_L("The results are not equal"));
 	              
 	              SetTestStepResult(EFail);   
 	         }
 	     }
 	     else
 	     {
 	           IsItATossPacket(vjdecompRet, refdecompOutput);
 	     }
 	     
 	     
 	     CleanupStack::PopAndDestroy(vjPacketBuffer);
 	        
		 CleanupStack::PopAndDestroy(refPacketBuffer);
 	   
		 vjPacketBuffer = NULL;
		 refPacketBuffer = NULL;
	
} // VJDecompressTypeErrorTest