Example #1
0
static int
update(pkt_t *pkt, void *fh, int isnew)
{
    FLOWDESC *x = F(fh);

    if (isnew) {
        x->nts = 0;
        
        x->proto = IP(proto);
        x->src_ip = IP(src_ip);
        x->dst_ip = IP(dst_ip);

	    if (IP(proto) == IPPROTO_TCP) {
	        x->src_port = TCP(src_port); 
	        x->dst_port = TCP(dst_port); 
	    } else if (IP(proto) == IPPROTO_UDP) {
	        x->src_port = UDP(src_port); 
	        x->dst_port = UDP(dst_port); 
	    } else {
	        N16(x->src_port) = N16(x->dst_port) = 0; 
	    }
    }

    x->ts[x->nts] = pkt->ts;
    x->nts++;

    if (x->nts == 10) return 1;
    else return 0;
}
Example #2
0
static uint32_t
hash(void *self, pkt_t *pkt)
{
    if (pkt->l3type != ETHERTYPE_IP) 
        return 0; 

    /* must be the same source ip, dest ip, source port, dest port */
    return (H32(IP(src_ip)) ^ H32(IP(dst_ip)) ^ (H16(TCP(dst_port)) << 3) ^ 
           (H16(TCP(dst_port)) << 3));
}
Example #3
0
static int
check(void *self, pkt_t *pkt)
{
    CONFIGDESC *config = CONFIG(self);

    if (TCP(syn) == 0) {
        if (H16(IP(len)) == (IP(ihl)*4 + TCP(hlen)*4) || 
            pkt->caplen == pkt->l7ofs) {
            /* captured length is equal to the data offset, so no data. */
            return 0;
        }
    }
    
    return 1;
}
Example #4
0
int main(){

	short int numberOfEdges;
	float cost[MAXI][MAXI], cable[MAXI][MAXI];
	char marked[MAXI];
	short int auxValueP1, auxValueP2;
	float auxCost;
	short int auxFor, auxFor2;

	scanf("%f %f",&cableCost,&trenchCost);
	scanf("%hd %hd",&numberOfPoints,&numberOfEdges);

	//zerando variaveis cm valor "infinito"
	for(auxFor=0;auxFor<numberOfPoints;auxFor++){
		for(auxFor2=0;auxFor2<numberOfPoints;auxFor2++){
			values[auxFor][auxFor2]=0;
			cost[auxFor][auxFor2]=0;
			cable[auxFor][auxFor2]=0;
		}
		marked[auxFor]='o';
	}

	for(auxFor=0;auxFor<numberOfEdges;auxFor++){
		scanf("%hd %hd %f",&auxValueP1,&auxValueP2,&auxCost);
		values[auxValueP1][auxValueP2]=auxCost;
		values[auxValueP2][auxValueP1]=auxCost;
	}

    marked[0]='x';
	TCP(0, 0, 1, 0, cost, cable, marked);
	printf("\n%.3f \n\n",bestCostDBB);
	system("pause");
	return 0;

}
Example #5
0
static uint32_t
hash(pkt_t *pkt)
{
    uint sport, dport; 

    if (IP(proto) == IPPROTO_TCP) { 
	    sport = N16(TCP(src_port)); 
	    dport = N16(TCP(dst_port)); 
    } else if (IP(proto) == IPPROTO_UDP) { 
	    sport = N16(UDP(src_port)); 
	    dport = N16(UDP(dst_port)); 
    } else { 
	    sport = dport = 0;
    } 

    /* The hash is a bitwise XOR of IP addresses and ports */
    return (N32(IP(src_ip)) ^ N32(IP(dst_ip)) ^ (sport << 3) ^ (dport << 3));
}
Example #6
0
static int
ematch(void *self, void *efh, void *fh)
{
    pkt_t* pkt;
    int ret = 0;
    FLOWDESC *x = F(fh);
    EFLOWDESC *ex = EF(efh);

    pkt = (pkt_t *)x->buf;
    
    if (ex->full_flow == 0) { /* if its full, go to next export record */
        ret = ((ex->dst_port == H16(TCP(dst_port))) && 
               (ex->src_port == H16(TCP(src_port))) &&
               (ex->src_ip == H32(IP(src_ip))) && 
               (ex->dst_ip == H32(IP(dst_ip))));
    }

    return ret;
}
Example #7
0
static timestamp_t
init(void *self, char *args[])
{
    CONFIGDESC *config;
    metadesc_t *inmd, *outmd;
    pkt_t * pkt;
    int i;
    
    inmd = metadesc_define_in(self, 0);
    
    pkt = metadesc_tpl_add(inmd, "any:any:~ip:~tcp");
    N16(TCP(src_port)) = 0xffff;
    N16(TCP(dst_port)) = 0xffff;
    IP(proto) = 0xff;
    N16(IP(len)) = 0xff;
    N32(IP(src_ip)) = 0xffffffff;
    N32(IP(dst_ip)) = 0xffffffff;
    
    outmd = metadesc_define_out(self, 0);
    
    pkt = metadesc_tpl_add(outmd, "any:any:any:any");
    
    config = (CONFIGDESC *)mem_mdl_malloc(self, sizeof(CONFIGDESC));

    /* default values for config parameters */
    config->flow_timeout = TIME2TS(60, 0);
    config->wait_fin = 60;
    
    for (i = 0; args && args[i]; i++) {
        if (strstr(args[i], "flow_timeout=")) {
            char * f_t = index(args[i], '=') + 1; 
            config->flow_timeout = TIME2TS(atoi(f_t), 0);
        }
        if (strstr(args[i], "wait_fin=")) {
            char * w_f = index(args[i], '=') + 1; 
            config->wait_fin = atoi(w_f);
        }
    }

    CONFIG(self) = config;
    
    return TIME2TS(1,0);
}
Example #8
0
void
capture(mdl_t *self, pkt_t *pkt, tuple_t *st, double srate)
{
    config_t *config = mdl_get_config(self, config_t);
    int app, app1, app2;
    double b, p;

    if (! isTCP && ! isUDP) /* non-TCP, non-UDP traffic */
        app = 1;
    else {                  /* TCP and UDP traffic */
        if (isTCP) {
            app1 = config->tcp_port2app[H16(TCP(src_port))];
            app2 = config->tcp_port2app[H16(TCP(dst_port))];
        } else {
            app1 = config->udp_port2app[H16(UDP(src_port))];
            app2 = config->tcp_port2app[H16(UDP(dst_port))];
        }

        if (app1 == 0 || app2 == 0) /* at most 1 port matches a known app */
            app = app1 + app2;
        else if (app1 == app2)      /* both ports match the same app */
            app = app1;
        else                        /* ports match different apps, unknown */
            app = 0;
    }

    if (COMO(type) == COMOTYPE_NF) {
        b = H32(NF(pktcount)) * COMO(len) * H16(NF(sampling));
        p = H32(NF(pktcount)) * (uint32_t) H16(NF(sampling));
    } else if (COMO(type) == COMOTYPE_SFLOW) {
        b = (uint64_t) COMO(len) * (uint64_t) H32(SFLOW(sampling_rate));
        p = H32(SFLOW(sampling_rate));
    } else {
        b = COMO(len);
        p = 1;
    }

    /* scale with sampling rate */
    st->bytes[app] += b / srate;
    st->pkts[app] += p / srate;
}
Example #9
0
static int
match(pkt_t *pkt, void *fh)
{
    FLOWDESC *x = F(fh);
    uint sport, dport; 
    
    if (IP(proto) == IPPROTO_TCP) {
        sport = N16(TCP(src_port));
        dport = N16(TCP(dst_port));
    } else if (IP(proto) == IPPROTO_UDP) {
        sport = N16(UDP(src_port));
        dport = N16(UDP(dst_port));
    } else {
        sport = dport = 0;
    }

    return (
         N32(IP(src_ip)) == N32(x->src_ip) &&
         N32(IP(dst_ip)) == N32(x->dst_ip) &&
         sport == N16(x->src_port) && dport == N16(x->dst_port) &&
         IP(proto) == x->proto
    );
}
Example #10
0
void TCP(short int source, short int target, short int numberOfMarkeds, float actualCost, float cost[MAXI][MAXI], float cable[MAXI][MAXI], char marked[MAXI]){
	short int auxFor, auxFor2;
	float minValue=INFINITY;
	short int nextSource, nextTarget;
	float auxTempCost,auxTempValue;

	/*Cortes*/
	if (numberOfMarkeds>numberOfPoints && actualCost>bestCostDBB)
		return;
	/*Atualiza melhor custo*/
	if(numberOfMarkeds==numberOfPoints){
#if DEBUG
		if(bestCostDBB>actualCost)
			printf("Nova Melhor Resposta %f \n", actualCost);
#endif
		bestCostDBB=MIN(bestCostDBB,actualCost);
		return;
	}
	/*Atualizando linha da matriz de valores do TCP
      Tabela principal de custos atuais.
	*/
	for(auxFor=0;auxFor<numberOfPoints;auxFor++){
		if(values[target][auxFor]!=0 ){
			cost[target][auxFor]=(values[target][auxFor]*(trenchCost+cableCost))+cable[source][target];
			cable[target][auxFor]=(values[target][auxFor]*(cableCost))+cable[source][target];
		}
	}

	/*Procura proximo elemento a ser visitado*/
	for(auxFor=0;auxFor<numberOfPoints;auxFor++){
		if(marked[auxFor]=='x'){
			for(auxFor2=0;auxFor2<numberOfPoints;auxFor2++){
				if(cost[auxFor][auxFor2]<minValue && marked[auxFor2]=='o' && cost[auxFor][auxFor2]>0 && cost[auxFor][auxFor2]!=INFINITY ){
					minValue=cost[auxFor][auxFor2];
					nextSource=auxFor;
					nextTarget=auxFor2;
				}
			}
		}
	}
    /*Se o melhor caminho encontrado for um com custo infinito, portanto essa solução não é desejavel, logo valor descartado*/
	if(minValue==INFINITY)
		return;

	/*Seleciona novo elemento*/
	actualCost+=minValue;
	numberOfMarkeds++;
	marked[nextTarget]='x';

	TCP(nextSource,nextTarget, numberOfMarkeds, actualCost,cost, cable, marked);

   	/*Salva variaveis de custo e valores, para serem atualizados por pesos "infinitos"*/
	auxTempCost=cost[nextSource][nextTarget];
	auxTempValue=values[nextSource][nextTarget];

	/*Deseleciona aresta e custo infinito*/
	cost[nextSource][nextTarget]=INFINITY;
	cost[nextTarget][nextSource]=INFINITY;

	values[nextSource][nextTarget]=INFINITY;
	values[nextTarget][nextSource]=INFINITY;

	actualCost-=minValue;
	marked[nextTarget]='o';
	numberOfMarkeds--;

	/*Verifica se proxima solução é viavel*/
	/*Corte branch and bound*/
	TCP(source,target, numberOfMarkeds, actualCost, cost, cable, marked);

	/*Retorna arestas ao valor original*/
	cost[nextSource][nextTarget]=cost[nextTarget][nextSource]=auxTempCost;
	values[nextTarget][nextSource]=values[nextSource][nextTarget]=auxTempValue;
}
Example #11
0
int main(int argc, char** argv)
{

  char port[] = "27015";
  char ip[] = "10.0.0.67";

  int numbytes;
  char buf[MAXDATASIZE];

  // Get input parameters
  for(int a=0; a < argc; a++)
    {
      if( strcmp( argv[a], "--ip" ) == 0 )
	{
	  strcpy(ip, argv[a+1]);
	}

      if( strcmp( argv[a], "--port" ) == 0 )
	{
	  strcpy(port, argv[a+1]);
	}
    }

  TCP myClient = TCP(port, ip);

  ros::init(argc, argv, "joints");
  ros::NodeHandle n;

  std::string receivedString;
  std::string attribute;
  std::stringstream ss;
  std::istringstream iss;

  tf::TransformBroadcaster br;
  tf::Transform transform;

  ros::Rate loop_rate(30);


  if( myClient.Connect() == 0 )
    {
      // Receive data
      numbytes = recv(myClient.s,buf,MAXDATASIZE-1,0);

      while (numbytes != 0 && ros::ok())
	{
	  numbytes = recv(myClient.s,buf,MAXDATASIZE-1,0);

	  buf[numbytes]='\0';

	  receivedString.assign(buf);

	  // debug
	  // std::cout << "Ahoy! Received " << numbytes << " bytes. " << receivedString << std::endl;

	  std::istringstream iss(receivedString);


	  std::vector<double> x (25, 0.0);
	  std::vector<double> y (25, 0.0);
	  std::vector<double> z (25, 0.0);

    std::vector<std::vector<double> > X (6, x);
    std::vector<std::vector<double> > Y (6, y);
    std::vector<std::vector<double> > Z (6, z);

    std::vector<double> qx (25, 0.0);
	  std::vector<double> qy (25, 0.0);
	  std::vector<double> qz (25, 0.0);
	  std::vector<double> qw (25, 1.0);

    std::vector<std::vector<double> > QX (6, qx);
    std::vector<std::vector<double> > QY (6, qy);
    std::vector<std::vector<double> > QZ (6, qz);
    std::vector<std::vector<double> > QW (6, qw);

	  int j;
	  int count = 6;
	  int id;

	  std::vector<int> foundIdx;
    std::string frame;
    std::string joint;

      /* code */

	  while(!iss.eof())
	    {
      // joint = "joint_";
      iss >> attribute;
      frame = "person_";

	      if( strcmp(attribute.c_str(), "count:") == 0 )
		{
		  iss >> count;
		  // ROS_INFO("count %d",count);
		}
	      else if( strcmp(attribute.c_str(), "id:") == 0 )
		{
		  iss >> id;
		  foundIdx.push_back(id);
      frame.append(boost::lexical_cast<std::string>(id));
		  // ROS_INFO("id %s",frame);
      // std::cout << id << " " << frame << " ";
		}