Exemplo n.º 1
0
Arquivo: main.c Projeto: ebichu/dd-wrt
// This is called randomly, atleast once every 100mS
int BackgroundProcessing(void){

	long PacketAge;
	int Queue, i;
	
	// Get current time
	struct timeval NowTime;
	gettimeofday(&NowTime, NULL);

	// Wait for access to the packet queue
	pthread_mutex_lock(&PacketQueueMutex);

	for(Queue = 0; Queue < PacketQueues; Queue++){

		// Loop
		while(PacketQueueHead[Queue] != PacketQueueTail[Queue]){

			// Work out age in mS
			PacketAge = (NowTime.tv_sec - ((ipq_packet_msg_t *)&PacketQueue[Queue][PacketQueueTail[Queue] * sizeof(struct ipq_packet_msg)])->timestamp_sec) * 1000;
			if(NowTime.tv_usec < ((ipq_packet_msg_t *)&PacketQueue[Queue][PacketQueueTail[Queue] * sizeof(struct ipq_packet_msg)])->timestamp_usec)
				 PacketAge += (1000000 - ((ipq_packet_msg_t *)&PacketQueue[Queue][PacketQueueTail[Queue] * sizeof(struct ipq_packet_msg)])->timestamp_usec + NowTime.tv_usec) / 1000;
			else
				 PacketAge += (NowTime.tv_usec - ((ipq_packet_msg_t *)&PacketQueue[Queue][PacketQueueTail[Queue] * sizeof(struct ipq_packet_msg)])->timestamp_usec) / 1000;

			// If the packet is old
			if(PacketAge > STALETIME){

				// Drop the packet
				ipq_set_verdict(hIpq, ((ipq_packet_msg_t *)&PacketQueue[Queue][PacketQueueTail[Queue] * sizeof(struct ipq_packet_msg)])->packet_id, NF_DROP, 0, NULL);

				// Move the Tail offset
				PacketQueueTail[Queue]++;
				if(PacketQueueTail[Queue] >= Config.Queue)
					PacketQueueTail[Queue] = 0;
			}
			else{
				// As the queue should be chronological, we can assume if this
				// packet is not too old, later ones won't be either
				break;
			}
		}
	}

	// Release access to the packet queue
	pthread_mutex_unlock(&PacketQueueMutex);

	// Delete old connections from contrack
	for(i = 0; i < MaxConTrack; i++){

		// If more than 30s since last packet
		if(Age(ConTrack[i].LastTime) > 30000 && ConTrack[i].Flags & CT_FlagValid){
			// Clear the valid flag
			ConTrack[i].Flags &= ~CT_FlagValid;
		}
	}

	return 1;
}
bool AgeSizeParticleAffector::affect(ParticleSystemRefPtr System, Int32 ParticleIndex, const Time& elps)
{
    if(getMFAges()->size()!=getMFSizes()->size())
    {
        return false;
    }
    else
    {
        Real32 time;
        UInt32 i(0);
        Real32 Age(System->getAge(ParticleIndex)),Lifespan(System->getLifespan(ParticleIndex));
        if(Lifespan < 0.0)
        {
            return false;
        }

        time = (Age)/(Lifespan);
        for( ;i<getMFAges()->size() && time>getAges(i);++i)
        {
            
        }

        if(i == getMFSizes()->size())
        {
            System->setSize(getMFSizes()->back(),ParticleIndex);
        }
        else if(i == 0.0)
        {
            System->setSize(getMFSizes()->front(),ParticleIndex);
        }
        else
        {
            Vec3f size;
            time = (time - getAges(i-1))/(getAges(i)-getAges(i-1));

            lerp(getSizes(i-1),getSizes(i),time,size);
            System->setSize(size,ParticleIndex);
        }


    }
    return false;
}
Exemplo n.º 3
0
Arquivo: ex1.cpp Projeto: yijay/TMB
Type objective_function<Type>::operator()()
{
 DATA_FACTOR(Sex);
 DATA_VECTOR(Age);
 DATA_VECTOR(Length);
 int n = Length.size();

 // These are the parameters (three are vectors; one is a scalar)
 PARAMETER_VECTOR(Linf);
 PARAMETER_VECTOR(Kappa);
 PARAMETER_VECTOR(t0);
 PARAMETER(LogSigma);
 Type Sigma = exp(LogSigma);
 vector<Type> LengthPred(n);

 // Provide the standard error of Sigma
 ADREPORT(Sigma);

 // Predictions and likelihoods
 for(int i=0;i<n;i++){
  Type Temp = Kappa(Sex(i))*(Age(i)-t0(Sex(i)));
  LengthPred(i) = Linf(Sex(i))*(1.0-exp(-Temp));
  }
 Type nll = -sum(dnorm(Length,LengthPred,Sigma,true));

 // Prediction for sex 1 and age 10
 Type Temp = Kappa(0)*(Type(10)-t0(0));
 Type PredLen10 = Linf(0)*(1.0-exp(-Temp));
 ADREPORT(PredLen10);

 // Predicted growth curve
 matrix<Type>LenPred(2,50);
 for (int Isex=0;Isex<2;Isex++)
  for (int Iage=1;Iage<=50;Iage++)
   {
   Temp = Kappa(Isex)*(Iage*1.0-t0(Isex));
   LenPred(Isex,Iage-1) = Linf(Isex)*(1.0-exp(-Temp));
   }
 REPORT(LenPred);

 return nll;
}
Exemplo n.º 4
0
Arquivo: main.c Projeto: ebichu/dd-wrt
// This is called to work out a packets priority
int PacketPriority(ipq_packet_msg_t *pPacketMsg){

#define PriHigh	0
#define PriDef	1
#define PriLow	2

	int i;
	unsigned char Protocol;
	char SourceIp[20], DestIp[20];
	unsigned short SourcePort, DestPort;

	// Store the protocol
	Protocol = ((struct iphdr *)(pPacketMsg->payload))->protocol;
	
	// If it is ICMP it is high priority automatically
	if(Protocol == IPPROTO_ICMP){

		return PriHigh;
	}

	// If TCP/UDP protocol
	else if(Protocol == IPPROTO_TCP || Protocol == IPPROTO_UDP){

		// If TCP protocol
		if(Protocol == IPPROTO_TCP){

			// Get pointer to TCP header
			struct tcphdr *pTcpHdr;
			pTcpHdr = (struct tcphdr *) (pPacketMsg->payload + sizeof(struct iphdr));

			// Store the source/dest ports
			SourcePort = ntohs(pTcpHdr->source);
			DestPort = ntohs(pTcpHdr->dest);
		}

		// else UDP protocol
		else{

			// Get pointer to UDP header
			struct udphdr *pUdpHdr;
			pUdpHdr = (struct udphdr *) (pPacketMsg->payload + sizeof(struct iphdr));

			// Store the source/dest ports
			SourcePort = ntohs(pUdpHdr->source);
			DestPort = ntohs(pUdpHdr->dest);
		}

		// Look for source or dest port being high priority
		for(i = 0; i < Config.HiPortsCnt; i++){

			if(SourcePort == Config.HiPorts[i] || DestPort == Config.HiPorts[i]){

				return PriHigh;
			}
		}

		// Store the source/dest IP
		strcpy(SourceIp, inet_ntoa(*(struct in_addr *) &((struct iphdr *)(pPacketMsg->payload))->saddr));
		strcpy(DestIp, inet_ntoa(*(struct in_addr *) &((struct iphdr *)(pPacketMsg->payload))->daddr));

		// Look for source or dest port being high priority
		for(i = 0; i < MaxConTrack; i++){

			// If this slot has valid data
			if(ConTrack[i].Flags & CT_FlagValid){

				// If this connection matches
				if(ConTrack[i].SourcePort == SourcePort &&
					strcmp(ConTrack[i].SourceIp, SourceIp) == 0){

					// Update info
					gettimeofday(&ConTrack[i].LastTime, NULL);
					ConTrack[i].Data += (float)pPacketMsg->data_len;

					// If done less than ~2 MB
					if(ConTrack[i].Data < 2000000){

						return PriDef;
					}

					// else has done significant data
					else{

						// If doing more than 5 kB/s
						if((ConTrack[i].Data / max((Age(ConTrack[i].StartTime) / 1000), 1)) > 5120){

							return PriLow;
						}
					}

					return PriDef;
				}
			}
		}

		// Look for an empty slot to use to track this connection
		for(i = 0; i < MaxConTrack; i++){

			if(!(ConTrack[i].Flags & CT_FlagValid)){

				// Set initial info
				gettimeofday(&ConTrack[i].StartTime, NULL);
				gettimeofday(&ConTrack[i].LastTime, NULL);
				ConTrack[i].SourcePort = SourcePort;
				strcpy(ConTrack[i].SourceIp, SourceIp);
				ConTrack[i].Data = (float)pPacketMsg->data_len;
				ConTrack[i].Flags = CT_FlagValid;

				break;
			}
		}
	}
	/* Non-ICMP/TCP/UDP protocol
	else{

	}
	*/

	// Retun the default
	return PriDef;
}