コード例 #1
0
ファイル: dlmo.c プロジェクト: ESE519/ISA100.11a
void configureSlot(uint8_t slotNumber, uint16_t neighborId, LinkType linkType, bool clockSource)
{
	DLMO_NEIGHBOR* neighborIndex; 		//store the neighbor index to pass to addLink()
	if (slotNumber >=  ISA_MAX_SLOTS) {
		printf ("Slot number not in range");
		return;
	}

	//Call the function to add a neighbor
	neighborIndex = addNeighbor(neighborId,0, 0, 0, clockSource,0,0, 0);
	if (neighborIndex == NULL)//
    {
		printIsaError();
		return;
	}

	if (addLink(slotNumber, neighborIndex, linkType) == -1)
	{
		printIsaError();
		return;
	}
//record that the slot is in use- used to calculate next wakeup
	isa_slot |= ((uint64_t) 1) << slotNumber;

}
コード例 #2
0
ファイル: main.c プロジェクト: atiselsts/osw
void appMain(void)
{
    macProtocol.recvCb = macRecv;

    MosAddr dst;
    uint8_t counter = 0,i;
    uint16_t neighbor;
    // XXX: hardcoded addresses
    if (localAddress == 0x0236) {
        intToAddr(dst, 0x5b5a);
    } else {
        intToAddr(dst, 0x0236);
    }
    neighbor = addNeighbor(dst.shortAddr);
    while (true) {
        for (i=0;i<10;i++) {
            sendBuffer[0] = '0' + counter++;
            if (counter >= 10) counter = 0;

            int8_t result = macSend(&dst, sendBuffer, sizeof(sendBuffer));
            if (result < 0) {
                PRINTF("mac send failed: %s\n", strerror(-result));
            } else if (result < sizeof(sendBuffer)) {
                PRINTF("mac send: not all sent! (%u vs %u)\n", result, sizeof(sendBuffer));
            }
           mdelay(1000);
        }
        PRINTF("sent:%d akcepted:%d => %d%%\t",
                linq[neighbor].sent, linq[neighbor].sentAck,
                (100*linq[neighbor].sentAck / linq[neighbor].sent));
        PRINTF("recv:%d akcepted:%d => %d%%\n",
                linq[neighbor].recv, linq[neighbor].recvAck,
                (100*linq[neighbor].recvAck / linq[neighbor].recv));
    }
}
コード例 #3
0
void addNeighbor(Node* node, const Node* neighbor) {
	addNeighborCapacityIfFull(node);
	node->neighbors[node->neighborCount++] = neighbor;
	//adding a neighbor is a mutual operation --> add node also to neighbor
	if (searchNeighbor(neighbor, node->name) == NOT_FOUND)
		addNeighbor(neighbor, node);
}
コード例 #4
0
ファイル: net_stats.c プロジェクト: KuanYuChen/mansos
inline uint16_t getIdFromAddress(MosShortAddr addr){
    uint8_t i;
    for (i = 0; i < linqNeighborCount; i++){
        if (linq[i].addr == addr){
            return i;
        }
    }
    return addNeighbor(addr);
}
コード例 #5
0
ファイル: list.c プロジェクト: AndrewBusch/minesweeper
/*
 * Add a neighbor to a given list
 */
neighbor* addNeighbor( neighbor* list, square value) {

	if( list == NULL) {
		list = (neighbor*) malloc( sizeof( neighbor));
		list->next = NULL;
		list->value = value;
		return list;
	} else {
		list->next = addNeighbor( list->next, value);
		return list;
	}
}
コード例 #6
0
	void RoadmapVertex::computeNeighbors(float radius)
	{
		neighbors_.clear();
		
		for (int i = 0; i < static_cast<int>(Sim_->roadmapVertices_.size()); ++i)
		{
			if (Sim_->roadmapVertices_[i] != this
				&& Sim_->kdTree_->queryVisibility(position_, 
												  Sim_->roadmapVertices_[i]->position_, radius))
			{
				addNeighbor(abs(Sim_->roadmapVertices_[i]->position_ - position_), i);
			}
		}
	}
コード例 #7
0
ファイル: NDP.cpp プロジェクト: erhodes/4203-Mesh
// Handle Message
void NDP::handleMessage(string src, string dst, string msg){
  // handle beacon
  if(msg == "<BEACON>"){
    // Lock
    barrier.lock();
    // Add to neighbor table
    addNeighbor(src);
    // Unlock
    barrier.unlock();
  }
  // handle other
  else{
    // delegate message
    if(messageHandler != 0){
      messageHandler->handleMessage(src, dst, msg);
    }
  }
}
コード例 #8
0
//process the input from system, e.g. X-AB
void buildGraphFromInput(char* input, Graph* graph) {
	char name = input[0];
	if (name == '\n') return; //catch empty case
	//check if node already exists
	if (searchNode(graph, name) == NOT_FOUND) {
		addNode(graph, name);
	}
	int nodeIndex = searchNode(graph, name);
	//add neighbors after '-'
	if (input[1] == '\n') return; //catch one letter case
	name = input[2];
	for (int i = 2; name != '\n'; i++) {
		if (searchNode(graph, name) == NOT_FOUND) {
			addNode(graph, name);
		}
		int neighborIndex = searchNode(graph, name);
		//check if neighbor already exists
		if (searchNeighbor(&graph->nodes[nodeIndex], name) == NOT_FOUND)
			addNeighbor(&graph->nodes[nodeIndex], &graph->nodes[neighborIndex]);
		name = input[i + 1];
	}
}
コード例 #9
0
ファイル: wpcapslip6.c プロジェクト: 1uk3/contiki
void
serial_to_wpcap(FILE *inslip)
{
	uint16_t buf_aligned[BUF_SIZE/2 + 42]; //extra for possible eth_hdr and ip_process expansion
	uint8_t *buf = (uint8_t *)buf_aligned;

    static int inbufptr = 0, issensiblestring=1;
    int ret;
	unsigned char c;

    unsigned char * inpktbuf;

    if(tun){
        inpktbuf = buf + sizeof(struct uip_eth_hdr);
    }
    else {
        inpktbuf = buf;
    }



read_more:
	if(inbufptr >= BUF_SIZE) {
		inbufptr = 0;
	}
	ret = fread(&c, 1, 1, inslip);

	if(ret == -1) {
		err(1, "serial_to_tun: read");
	}
	if(ret == 0) {
		clearerr(inslip);
		return;
		if (timestamp) stamptime();
		fprintf(stderr, "serial_to_tun: EOF\n");
		exit(1);
	}
	/*  fprintf(stderr, ".");*/
	switch(c) {
  case SLIP_END:
	  if(inbufptr > 0) {
		  if(inpktbuf[0] == '!') {
			  if (inpktbuf[1] == 'M' && inbufptr == 18) {
				  /* Read gateway MAC address and autoconfigure tap0 interface */
				  char macs64[24], macs48[18];
				  int addr_bytes[8];				  
				  int i, pos;				  
				  for(i = 0, pos = 0; i < 16; i++) {
					  macs64[pos++] = inpktbuf[2 + i];
					  if ((i & 1) == 1 && i < 14) {
						  macs64[pos++] = '-';
					  }
				  }
				  macs64[pos] = '\0';
				  if (timestamp) stamptime();
				  fprintf(stderr, "*** Gateway's MAC address: %s\n", macs64);
				  mac_received = true;
				  
				  sscanf(macs64, "%2X-%2X-%2X-%2X-%2X-%2X-%2X-%2X",
                        &addr_bytes[0],
                        &addr_bytes[1],
                        &addr_bytes[2],
                        &addr_bytes[3],
                        &addr_bytes[4],
                        &addr_bytes[5],
                        &addr_bytes[6],
                        &addr_bytes[7]);
                        
                  /* Form a fictitious MAC address for the attached device from its EUI-64 (2 middle bytes elided)  */
                  addr_bytes[0] |= 0x02;
                  for(i=0;i<3;i++){
                      dev_eth_addr.addr[i] = addr_bytes[i];
                  }
                  for(i=3;i<6;i++){
                      dev_eth_addr.addr[i] = addr_bytes[i+2];
                  }
                  sprintf(macs48,"%02X-%02X-%02X-%02X-%02X-%02X",
                            dev_eth_addr.addr[0],
                            dev_eth_addr.addr[1],
                            dev_eth_addr.addr[2],
                            dev_eth_addr.addr[3],
                            dev_eth_addr.addr[4],
                            dev_eth_addr.addr[5]);
				  if (timestamp) stamptime();
                  fprintf(stderr,"Fictitious MAC-48: %s\n", macs48);

				  if(autoconf){

                      if(IPAddrFromPrefix(autoconf_addr, ipprefix, macs64)!=0){
					      if (timestamp) stamptime();
                          fprintf(stderr, "Invalid IPv6 address.\n");
						  exit(1);
                      }
					  local_ipaddr = autoconf_addr;
					  addAddress(if_name,local_ipaddr);
					  
				  }
                  if(br_prefix != NULL){
                      /* RPL Border Router mode. Add route towards LoWPAN. */

                      if(IPAddrFromPrefix(rem_ipaddr, br_prefix, macs64)!=0){
					      if (timestamp) stamptime();
                          fprintf(stderr, "Invalid IPv6 address.\n");
						  exit(1);
                      }

                      addLoWPANRoute(if_name, br_prefix, rem_ipaddr);
                      addNeighbor(if_name, rem_ipaddr, macs48);
                  }

			  }
#define DEBUG_LINE_MARKER '\r'
		  }
		  else if(inpktbuf[0] == '?') {
			   if (inpktbuf[1] == 'M') {
				   /* Send our MAC address. */

				   send_mac = true;
				   set_sniffer_mode = true;
				   set_channel = true;
			   }
               else if (inpktbuf[1] == 'P') {
				   /* Send LoWPAN network prefix to the border router. */
				   send_prefix = true;
			   }
		  }
		  else if(inpktbuf[0] == DEBUG_LINE_MARKER) {
		    /* Dont insert timestamp on wireshark packet dumps starting with 0000 */
			  if (timestamp) {
			     if (inpktbuf[0]!='0' || inpktbuf[1]!=0 || inpktbuf[2]!=0 || inpktbuf[3]!=0) stamptime();
			  }
			  fwrite(inpktbuf + 1, inbufptr - 1, 1, stderr);
			  issensiblestring=1;
		  }
#if 0
		  else if(is_sensible_string(inpktbuf, inbufptr)) {
		    /* Dont insert timestamp on wireshark packet dumps starting with 0000 */
			  if (timestamp) {
			     if (inpktbuf[0]!='0' || inpktbuf[1]!=0 || inpktbuf[2]!=0 || inpktbuf[3]!=0) stamptime();
			  }
			  fwrite(inpktbuf, inbufptr, 1, stderr);
		  }
#else
		  else if(issensiblestring) {
		    /* Dont insert timestamp on wireshark packet dumps starting with 0000 */
			  if (timestamp) {
			     if (inpktbuf[0]!='0' || inpktbuf[1]!=0 || inpktbuf[2]!=0 || inpktbuf[3]!=0) stamptime();
			  }
			  fwrite(inpktbuf, inbufptr, 1, stderr);
			  
		  }
#endif
		  else {

              PRINTF("Sending to wpcap\n");

              if(tun){
                  
                  //Ethernet header to be inserted before IP packet
                  struct uip_eth_hdr * eth_hdr = (struct uip_eth_hdr *)buf;

                  memcpy(&eth_hdr->dest, &adapter_eth_addr, sizeof(struct uip_eth_addr));
                  memcpy(&eth_hdr->src, &dev_eth_addr, sizeof(struct uip_eth_addr));

                  eth_hdr->type = htons(UIP_ETHTYPE_IPV6);
                  inbufptr += sizeof(struct uip_eth_hdr);

                  // Process incoming packets to transform link layer addresses inside ICMP packets.
                  // Try to do processing if we did not succeed to add the neighbor.
                  if(clean_neighb == false){
                    inbufptr = ip_process(buf, inbufptr);
                  }
              }
              //print_packet(inpktbuf, inbufptr);

			  wpcap_send(buf, inbufptr);
			  /*      printf("After sending to wpcap\n");*/
		  }
		  inbufptr = 0;
		  issensiblestring=1;
	  }
	  break;

  case SLIP_ESC:
	  if(fread(&c, 1, 1, inslip) != 1) {
		  clearerr(inslip);
		  /* Put ESC back and give up! */
		  ungetc(SLIP_ESC, inslip);
		  return;
	  }

	  switch(c) {
  case SLIP_ESC_END:
	  c = SLIP_END;
	  break;
  case SLIP_ESC_ESC:
	  c = SLIP_ESC;
	  break;
	  }
	  /* FALLTHROUGH */
  default:
	  inpktbuf[inbufptr++] = c;
	  if (issensiblestring) {
	    if(c == '\n') {
		/* Dont insert timestamp on wireshark packet dumps starting with 0000 */
		  if (timestamp) {
			 if (inpktbuf[0]!='0' || inpktbuf[1]!=0 || inpktbuf[2]!=0 || inpktbuf[3]!=0) stamptime();
		  }
/* This could be a proper debug string starting with CR just a print to stdout */
/* Trap the CR which would cause overwriting of the timestamp */
//{int i;for (i=0;i<inbufptr;i++) fprintf(stderr,"%2x ",inpktbuf[i]);}
		  if(inpktbuf[0] == DEBUG_LINE_MARKER) {
		    fwrite(inpktbuf + 1, inbufptr - 1, 1, stderr);
		  } else {
	  	    fwrite(inpktbuf, inbufptr, 1, stderr);
		  }
		  inbufptr=0; 
		} else if (c == 0 || c == '\t' || c == '\r') {
	    } else if(c < ' ' || '~' < c) {
	      issensiblestring=0;
		}
	  }
	  break;
	}

	goto read_more;
}
コード例 #10
0
ファイル: bpclock.c プロジェクト: b/ION
static int	adjustThrottles()
{
	PsmPartition	ionwm = getIonwm();
	IonVdb		*ionvdb = getIonVdb();
	BpVdb		*bpvdb = getBpVdb();
	PsmAddress	elt;
	VOutduct	*outduct;
	unsigned long	nodeNbr;
	IonNeighbor	*neighbor;
	PsmAddress	nextElt;
	int		delta;
	VInduct		*induct;

	/*	Only the LTP induct and outduct throttles can be
	 *	dynamically adjusted in response to changes in data
	 *	rate between the local node and its neighbors, because
	 *	(currently) there is no mechanism for mapping neighbor
	 *	node number to duct name for any other CL protocol.
	 *	For LTP, duct name is LTP engine number which, by
	 *	convention, is identical to BP node number.  For all
	 *	other CL protocols, duct nominal data rate is initially
	 *	set to the protocol's configured nominal data rate and
	 *	is never subsequently modified.
	 *	
	 *	So, first we find the LTP induct if any.		*/

	for (elt = sm_list_first(ionwm, bpvdb->inducts); elt;
			elt = sm_list_next(ionwm, elt))
	{
		induct = (VInduct *) psp(ionwm, sm_list_data(ionwm, elt));
		if (strcmp(induct->protocolName, "ltp") == 0)
		{
			break;	/*	Found the LTP induct.		*/
		}
	}

	if (elt == 0)		/*	No LTP induct; nothing to do.	*/
	{
		return 0;
	}

	/*	Now update all LTP outducts, and the induct as well,
	 *	inferring the existence of Neighbors in the process.	*/

	for (elt = sm_list_first(ionwm, bpvdb->outducts); elt;
			elt = sm_list_next(ionwm, elt))
	{
		outduct = (VOutduct *) psp(ionwm, sm_list_data(ionwm, elt));
		if (strcmp(outduct->protocolName, "ltp") != 0)
		{
			continue;
		}

		nodeNbr = atol(outduct->ductName);
		neighbor = findNeighbor(ionvdb, nodeNbr, &nextElt);
		if (neighbor == NULL)
		{
			neighbor = addNeighbor(ionvdb, nodeNbr, nextElt);
			if (neighbor == NULL)
			{
				putErrmsg("Can't adjust outduct throttle.",
						NULL);
				return -1;
			}
		}

		if (neighbor->xmitRate != neighbor->prevXmitRate)
		{
#ifndef ION_NOSTATS
			if (neighbor->nodeNbr != getOwnNodeNbr())
			{
			/*	We report and clear transmission
			 *	statistics as necessary.  NOTE that
			 *	this procedure is based on the
			 *	assumption that the local node is
			 *	in LTP transmission contact with
			 *	AT MOST ONE neighbor at any time.
			 *	For more complex topologies it will
			 *	need to be redesigned.			*/

				if (neighbor->xmitRate == 0)
				{
					/*	End of xmit contact.	*/
					reportAllStateStats();
					clearAllStateStats();
				}
				else if (neighbor->prevXmitRate == 0)
				{
					/*	Start of xmit contact.	*/
					reportAllStateStats();
					clearAllStateStats();
				}
			}
#endif
			outduct->xmitThrottle.nominalRate = neighbor->xmitRate;
			neighbor->prevXmitRate = neighbor->xmitRate;
		}

		/*	Note that the LTP induct is aggregate; the
		 *	duct's nominal rate is the sum of the rates
		 *	at which all neighbors are expected to be
		 *	transmitting to the local node at any given
		 *	moment.  So we must add the change in rate
		 *	for each known neighbor to the aggregate
		 *	nominal reception rate for the induct.		*/

		if (neighbor->recvRate != neighbor->prevRecvRate)
		{
#ifndef ION_NOSTATS
			if (neighbor->nodeNbr != getOwnNodeNbr())
			{
			/*	We report and clear reception
			 *	statistics as necessary.  NOTE that
			 *	this procedure is based on the
			 *	assumption that the local node is
			 *	in LTP reception contact with
			 *	AT MOST ONE neighbor at any time.
			 *	For more complex topologies it will
			 *	need to be redesigned.			*/

				if (neighbor->recvRate == 0)
				{
					/*	End of recv contact.	*/
					reportAllStateStats();
					clearAllStateStats();
				}
				else if (neighbor->prevRecvRate == 0)
				{
					/*	Start of recv contact.	*/
					reportAllStateStats();
					clearAllStateStats();
				}
			}
#endif
			delta = neighbor->recvRate - neighbor->prevRecvRate;
			induct->acqThrottle.nominalRate += delta;
			neighbor->prevRecvRate = neighbor->recvRate;
		}
	}

	return 0;
}
コード例 #11
0
ファイル: ltpclock.c プロジェクト: b/ION
static int	manageLinks(Sdr sdr, time_t currentTime)
{
	PsmPartition	ionwm = getIonwm();
	LtpVdb		*ltpvdb = getLtpVdb();
	IonVdb		*ionvdb = getIonVdb();
	PsmAddress	elt;
	LtpVspan	*vspan;
	Object		obj;
	LtpSpan		span;
	IonNeighbor	*neighbor;
	PsmAddress	nextElt;
	unsigned long	priorXmitRate;

	sdr_begin_xn(sdr);
	for (elt = sm_list_first(ionwm, ltpvdb->spans); elt;
			elt = sm_list_next(ionwm, elt))
	{
		vspan = (LtpVspan *) psp(ionwm, sm_list_data(ionwm, elt));

		/*	Finish aggregation as necessary.		*/

		obj = sdr_list_data(sdr, vspan->spanElt);
		sdr_stage(sdr, (char *) &span, obj, sizeof(LtpSpan));
		if (span.lengthOfBufferedBlock > 0)
		{
			span.ageOfBufferedBlock++;
			sdr_write(sdr, obj, (char *) &span, sizeof(LtpSpan));
			if (span.ageOfBufferedBlock >= span.aggrTimeLimit)
			{
				sm_SemGive(vspan->bufFullSemaphore);
			}
		}

		/*	Find Neighbor object encapsulating the current
		 *	known state of this LTP engine.			*/

		neighbor = findNeighbor(ionvdb, vspan->engineId, &nextElt);
		if (neighbor == NULL)
		{
			neighbor = addNeighbor(ionvdb, vspan->engineId,
					nextElt);
			if (neighbor == NULL)
			{
				putErrmsg("Can't update span.", NULL);
				return -1;
			}
		}

		if (neighbor->xmitRate == 0)
		{
			if (vspan->localXmitRate > 0)
			{
				vspan->localXmitRate = 0;
				ltpStopXmit(vspan);
			}
		}
		else
		{
			if (vspan->localXmitRate == 0)
			{
				vspan->localXmitRate = neighbor->xmitRate;
				ltpStartXmit(vspan);
			}
		}

		if (neighbor->fireRate == 0)
		{
			if (vspan->remoteXmitRate > 0)
			{
				priorXmitRate = vspan->remoteXmitRate;
				vspan->remoteXmitRate = 0;
				if (ltpSuspendTimers(vspan, elt, currentTime,
						priorXmitRate))
				{
					putErrmsg("Can't manage links.", NULL);
					return -1;
				}
			}
		}
		else
		{
			if (vspan->remoteXmitRate == 0)
			{
				vspan->remoteXmitRate = neighbor->fireRate;
				if (ltpResumeTimers(vspan, elt, currentTime,
						vspan->remoteXmitRate))
				{
					putErrmsg("Can't manage links.", NULL);
					return -1;
				}
			}
		}

		if (neighbor->recvRate == 0)
		{
			vspan->receptionRate = 0;
		}
		else
		{
			vspan->receptionRate = neighbor->recvRate;
		}

		if (neighbor->owltInbound != vspan->owltInbound)
		{
			vspan->owltInbound = neighbor->owltInbound;
		}

		if (neighbor->owltOutbound != vspan->owltOutbound)
		{
			vspan->owltOutbound = neighbor->owltOutbound;
		}
	}

	if (sdr_end_xn(sdr) < 0)
	{
		putErrmsg("ltpclock failed managing links.", NULL);
		return -1;
	}

	return 0;
}
コード例 #12
0
BoxShape::BoxShape(const Box& box, int resolution):
    Shape(ceil(pow(resolution + 1, 3)), 3*(resolution * 2) * (resolution) * 6), res(resolution)
{
    
    Vector3 v1 = box.getV1();
    Vector3 v2 = box.getV2();
    
    Vector3 midpoint = box.getV1() + (box.getV2() - box.getV1()) * 0.5;
    double radius = (box.getV1().getX() - box.getV2().getX()) / 2;
    
    double xseg = (v2.getX() - v1.getX()) / (double)this->res;
    double yseg = (v2.getY() - v1.getY()) / (double)this->res;
    double zseg = (v2.getZ() - v1.getZ()) / (double)this->res;
  
    fprintf(stderr, "Creating box shape.\n");
    int pwind = 0;
    int iwind = 0;
    // Create vertices and springs
    
    int ycount = 0;
    double y = v1.getY();
    while (ycount <= this->res)
    {
        int xcount = 0;
        double x = v1.getX();
        while (xcount <= this->res)
        {
            int zcount = 0;
            double z = v1.getZ();
            while (zcount <= this->res)
            {
                Vector3 pos = Vector3(x, y, z);
                double plen = (pos - midpoint).length();
                Vector3 pnorm = (pos - midpoint); pnorm.normalize();
                //if (plen > radius)
                    //pos = midpoint + pnorm * radius;
                
                this->points[pwind] = Point(pos);
                
                
                for (int ix = -1; ix < 2; ix++)
                {
                    for (int iy = -1; iy < 2; iy++)
                    {
                        for (int iz = -1; iz < 2; iz++)
                        {
                            if (ix != 0 || iy != 0 || iz != 0)
                                addNeighbor(&this->points[pwind], xcount + ix, ycount + iy, zcount + iz);
                        }
                    }
                }
                
                // Surface triangles
                if (xcount < this->res && ycount < this->res && zcount == 0)
                {
                    // upper front triangle
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount, zcount);
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount + 1, zcount);
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount + 1, ycount, zcount);

                    // lower front triangle
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount + 1, zcount);
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount + 1, ycount + 1, zcount);                    
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount + 1, ycount, zcount);    
                }   
                if (xcount < this->res && ycount < this->res && zcount == this->res)
                {
                    // upper back triangle
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount, zcount);
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount + 1, ycount, zcount);
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount + 1, zcount);

                    // lower back triangle
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount + 1, zcount);
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount + 1, ycount, zcount);    
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount + 1, ycount + 1, zcount);                    
                }    
                if (xcount == this->res && ycount < this->res && zcount < this->res)
                {
                    // upper right triangle
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount, zcount);
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount + 1, zcount);
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount, zcount + 1);

                    // lower right triangle
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount + 1, zcount);
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount + 1, zcount + 1);                    
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount, zcount + 1);    
                } 
                if (xcount == 0 && ycount < this->res && zcount < this->res)
                {
                    // upper left triangle
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount, zcount);
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount, zcount + 1);
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount + 1, zcount);

                    // lower left triangle
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount + 1, zcount);
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount, zcount + 1);    
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount + 1, zcount + 1);                    
                } 
                if (xcount < this->res && ycount == this->res && zcount < this->res)
                {
                    // upper top triangle
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount, zcount);
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount, zcount + 1);
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount + 1, ycount, zcount);

                    // lower bottom triangle
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount, zcount + 1);
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount + 1, ycount, zcount + 1);                    
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount + 1, ycount, zcount);    
                } 
                if (xcount < this->res && ycount == 0 && zcount < this->res)
                {
                    // upper front triangle
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount, zcount);
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount + 1, ycount, zcount);
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount, zcount + 1);

                    // lower front triangle
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount, ycount, zcount + 1);
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount + 1, ycount, zcount);    
                    this->surfaceIndices[iwind++] = getPointWindIndex(xcount + 1, ycount, zcount + 1);                    
                }  
                
                //fprintf(stderr, "swind: %i\n", swind);
                pwind++;
                
                zcount++;
                z = v1.getZ() + (double)zcount * zseg;        
            }
            xcount++;
            x = v1.getX() + (double)xcount * xseg;
        }
        ycount++;
        y = v1.getY() + (double)ycount * yseg;
    }
   
    fprintf(stderr, "pwind: %i, pcount: %i\n", pwind, pointcount);
    fprintf(stderr, "iwind: %i, icount: %i\n", iwind, this->indexCount);
    
    setupSprings();
    
}
コード例 #13
0
ファイル: testRoutePool_.c プロジェクト: rkophs/pa3
int main(int argc, char** argv) {
    
    
    struct lspPool *pool;
    int buffSize = 2048;
    char buff[buffSize];
    bzero(buff, buffSize);
    
    struct LSP *n1; struct LSP *n2; struct LSP *n3; struct LSP *n4; struct LSP *n5;
    struct LSP *n6; struct LSP *n7; struct LSP *n8; struct LSP *n9; struct LSP *na;
    
    pool = createLSPPool();
    n1 = createLSP("A", 1, 10, 5);
    addNeighbor(n1, 4, "B", 1, 9701, 9704);
    addNeighbor(n1, 1, "C", 1, 9702, 9706);
    addNeighbor(n1, 4, "F", 1, 9703, 9717);
    n2 = createLSP("B", 1, 11, 5);
    addNeighbor(n2, 4, "A", 1, 9704, 9701);
    addNeighbor(n2, 1, "D", 1, 9705, 9709);
    n3 = createLSP("C", 1, 12, 5);
    addNeighbor(n3, 1, "A", 1, 9706, 9702);
    addNeighbor(n3, 1, "D", 1, 9707, 9710);
    addNeighbor(n3, 3, "E", 1, 9708, 9713);
    n4 = createLSP("D", 1, 13, 5);
    addNeighbor(n4, 1, "B", 1, 9709, 9705);
    addNeighbor(n4, 1, "C", 1, 9710, 9707);
    addNeighbor(n4, 1, "E", 1, 9711, 9714);
    addNeighbor(n4, 2, "F", 1, 9712, 9718);
    n5 = createLSP("E", 1, 14, 6);
    addNeighbor(n5, 3, "C", 1, 9713, 9708);
    addNeighbor(n5, 1, "D", 1, 9714, 9711);
    addNeighbor(n5, 1, "F", 1, 9715, 9716);
    n6 = createLSP("F", 1, 15, 4);
    addNeighbor(n6, 4, "A", 1, 9717, 9703);
    addNeighbor(n6, 2, "D", 1, 9718, 9712);
    addNeighbor(n6, 1, "E", 1, 9716, 9715);
    
    lspPoolCtrl(pool, n1);
    lspPoolCtrl(pool, n2);
    lspPoolCtrl(pool, n3);
    lspPoolCtrl(pool, n4);
    lspPoolCtrl(pool, n5);
    lspPoolCtrl(pool, n6);
    bzero(buff, buffSize);
    BuffAllLSPs(pool, buff, buffSize);
    printf("%s\n", buff);
        
    printf("Executing Dijkstra's...\n");
    
    struct RoutePool *rA = initRoutePool("A", 1);
    struct RoutePool *rB = initRoutePool("B", 1);
    struct RoutePool *rC = initRoutePool("C", 1);
    struct RoutePool *rD = initRoutePool("D", 1);
    struct RoutePool *rE = initRoutePool("E", 1);
    struct RoutePool *rF = initRoutePool("F", 1);
    
    printf("Pool A\n");
    dijkstrasEngine(rA, pool);
    bzero(buff, buffSize);
    BuffRouteTable(rA, buff, buffSize);
    printf("%s\n", buff);
    
    printf("Pool B\n");
    dijkstrasEngine(rB, pool);
    bzero(buff, buffSize);
    BuffRouteTable(rB, buff, buffSize);
    printf("%s\n", buff);
    
    printf("Pool C\n");
    dijkstrasEngine(rC, pool);
    bzero(buff, buffSize);
    BuffRouteTable(rC, buff, buffSize);
    printf("%s\n", buff);
    
    printf("Pool D\n");
    dijkstrasEngine(rD, pool);
    bzero(buff, buffSize);
    BuffRouteTable(rD, buff, buffSize);
    printf("%s\n", buff);
    
    printf("Pool E\n");
    dijkstrasEngine(rE, pool);
    bzero(buff, buffSize);
    BuffRouteTable(rE, buff, buffSize);
    printf("%s\n", buff);
    
    printf("Pool F\n");
    dijkstrasEngine(rF, pool);
    bzero(buff, buffSize);
    BuffRouteTable(rF, buff, buffSize);
    printf("%s\n", buff);
    
    releaseLSPPool(pool);
    
    //---------------------------------------------
    
    struct RoutePool *rG = initRoutePool("G", 1);
    struct RoutePool *rH = initRoutePool("H", 1);
    struct RoutePool *rI = initRoutePool("I", 1);
    struct RoutePool *rJ = initRoutePool("J", 1);
    
    pool = createLSPPool();
    n1 = createLSP("A", 1, 10, 5);
    addNeighbor(n1, 1, "B", 1, 1, 2);
    addNeighbor(n1, 3, "H", 1, 16, 15);
    addNeighbor(n1, 5, "I", 1, 17, 18);
    n2 = createLSP("B", 1, 11, 5);
    addNeighbor(n2, 1, "A", 1, 2, 1);
    addNeighbor(n2, 1, "C", 1, 3, 4);
    addNeighbor(n2, 3, "I", 1, 20, 19);
    n3 = createLSP("C", 1, 12, 5);
    addNeighbor(n3, 1, "B", 1, 4, 3);
    addNeighbor(n3, 1, "D", 1, 5, 6);
    n4 = createLSP("D", 1, 13, 5);
    addNeighbor(n4, 1, "C", 1, 6, 5);
    addNeighbor(n4, 1, "E", 1, 7, 8);
    n5 = createLSP("E", 1, 14, 6);
    addNeighbor(n5, 1, "D", 1, 8, 7);
    addNeighbor(n5, 1, "F", 1, 9, 10);
    n6 = createLSP("F", 1, 15, 4);
    addNeighbor(n6, 1, "E", 1, 10, 9);
    addNeighbor(n6, 1, "G", 1, 11, 12);
    addNeighbor(n6, 1, "J", 1, 23, 22);
    n7 = createLSP("G", 1, 15, 4);
    addNeighbor(n7, 1, "F", 1, 12, 11);
    addNeighbor(n7, 3, "H", 1, 13, 14);
    n8 = createLSP("H", 1, 15, 4);
    addNeighbor(n8, 3, "A", 1, 15, 16);
    addNeighbor(n8, 3, "G", 1, 14, 13);
    addNeighbor(n8, 1, "I", 1, 24, 25);
    n9 = createLSP("I", 1, 15, 4);
    addNeighbor(n9, 5, "A", 1, 18, 17);
    addNeighbor(n9, 3, "B", 1, 19, 20);
    addNeighbor(n9, 1, "H", 1, 25, 24);
    addNeighbor(n9, 10, "J", 1, 26, 21);
    na = createLSP("J", 1, 15, 4);
    addNeighbor(na, 1, "F", 1, 22, 23);
    addNeighbor(na, 10, "I", 1, 21, 26);
    
    lspPoolCtrl(pool, n1);
    lspPoolCtrl(pool, n2);
    lspPoolCtrl(pool, n3);
    lspPoolCtrl(pool, n4);
    lspPoolCtrl(pool, n5);
    lspPoolCtrl(pool, n6);
    lspPoolCtrl(pool, n7);
    lspPoolCtrl(pool, n8);
    lspPoolCtrl(pool, n9);
    lspPoolCtrl(pool, na);
    
    bzero(buff, buffSize);
    BuffAllLSPs(pool, buff, buffSize);
    printf("%s\n", buff);
        
    printf("Executing Dijkstra's...\n");
    
    printf("Pool A\n");
    dijkstrasEngine(rA, pool);
    bzero(buff, buffSize);
    BuffRouteTable(rA, buff, buffSize);
    printf("%s\n", buff);
    
    printf("Pool B\n");
    dijkstrasEngine(rB, pool);
    bzero(buff, buffSize);
    BuffRouteTable(rB, buff, buffSize);
    printf("%s\n", buff);
    
    printf("Pool C\n");
    dijkstrasEngine(rC, pool);
    bzero(buff, buffSize);
    BuffRouteTable(rC, buff, buffSize);
    printf("%s\n", buff);
    
    printf("Pool D\n");
    dijkstrasEngine(rD, pool);
    bzero(buff, buffSize);
    BuffRouteTable(rD, buff, buffSize);
    printf("%s\n", buff);
    
    printf("Pool E\n");
    dijkstrasEngine(rE, pool);
    bzero(buff, buffSize);
    BuffRouteTable(rE, buff, buffSize);
    printf("%s\n", buff);
    
    printf("Pool F\n");
    dijkstrasEngine(rF, pool);
    bzero(buff, buffSize);
    BuffRouteTable(rF, buff, buffSize);
    printf("%s\n", buff);
    
    printf("Pool G\n");
    dijkstrasEngine(rG, pool);
    bzero(buff, buffSize);
    BuffRouteTable(rG, buff, buffSize);
    printf("%s\n", buff);
    
    printf("Pool H\n");
    dijkstrasEngine(rH, pool);
    bzero(buff, buffSize);
    BuffRouteTable(rH, buff, buffSize);
    printf("%s\n", buff);
    
    printf("Pool I\n");
    dijkstrasEngine(rI, pool);
    bzero(buff, buffSize);
    BuffRouteTable(rI, buff, buffSize);
    printf("%s\n", buff);
    
    printf("Pool J\n");
    dijkstrasEngine(rJ, pool);
    bzero(buff, buffSize);
    BuffRouteTable(rJ, buff, buffSize);
    printf("%s\n", buff);
    
    releaseRoutePool(rA);
    releaseRoutePool(rB);
    releaseRoutePool(rC);
    releaseRoutePool(rD);
    releaseRoutePool(rE);
    releaseRoutePool(rF);
    releaseRoutePool(rG);
    releaseRoutePool(rH);
    releaseRoutePool(rI);
    releaseRoutePool(rJ);
    
    releaseLSPPool(pool);
    
    return (EXIT_SUCCESS);
}
コード例 #14
0
ファイル: romanian.c プロジェクト: chavli/C
int main(int argc, char *argv[]){
	if(argc != 4)
		printf("usage: ./program city_file edge_file h_file\n");
	else{
		FILE *cities = fopen(argv[1], "r");
		FILE *edges = fopen(argv[2], "r");
		FILE *hvals =	fopen(argv[3], "r");
		
		//this is our adjacency list
		CityNode *root = 0, *new_city;
		NeighborNode *new_neighbor;

		char line[128];
		char *temp, *temp2;

		//set up all the cities
		while(fgets(line, 128, cities)){
			temp = strtok(line, ":");
			char *city = malloc(16 * sizeof(char));
			strcpy(city, temp);
			new_city = initializeCityNode(city, 0);
			addCity(&root, new_city);
		}
		rewind(cities);
		
		//set up neighbors
		while(fgets(line, 128, cities)){
			temp = strtok(line, ":");
			char *neighbor = malloc(16 * sizeof(char));
			while(temp2 = strtok(NULL, ",")){
				strcpy(neighbor, temp2);
				if(strcmp(neighbor, "\n") != 0){
					CityNode *dest = getCityNode(root, neighbor);
					CityNode *src = getCityNode(root, temp);
					new_neighbor = initializeNeighborNode(dest, 0);
					addNeighbor(&src, new_neighbor);
				}
			}
		}
		
		fclose(cities);

		//set up edge costs
		int cost;
		char from[16], to[16], line2[128];
		while(fgets(line2, 128, edges)){
			sscanf(line2, "%s %s %d", from, to, &cost);
			CityNode *src = getCityNode(root, from);
			NeighborNode *dest = getNeighborNode(src, to);
			dest->cost = cost;
		}
		fclose(edges);
		
		//set up h(n)
		while(fgets(line, 128, hvals)){
			sscanf(line, "%s %d", from, &cost);
			CityNode *src = getCityNode(root, from);
			src->h_n = cost;
		}
		fclose(hvals);
		
		//the adjacency list
		printCityList(root);
		
		CityNode *start = getCityNode(root, "arad");
		CityNode *end = getCityNode(root, "buch");

		printf("\nRunning Depth First Search...\n");
		runDepthFirst(start, end, INT_MAX);

		printf("\nRunning Iterative Deepening Search...\n");
		runIterDeepening(start, end);

		printf("\nRunning Breadth First Search...\n");
		runBreadthFirst(start, end, 0);

		printf("\nRunning Uniform Cost Search...\n");
		runUniformCost(start, end, (int (*)(void *, void *))basicComp);

		printf("\nRunning Best First Search with straightLineDistance...\n");
		runBestFirst(start, end, 
										(int (*)(void *, void *))basicComp,
										(int (*)(void *))straightLineDistance);

		printf("\nRunning Best First Search with nonEuclideanDistance...\n");
		runBestFirst(start, end, 
										(int (*)(void *, void *))basicComp,
										(int (*)(void *))nonEuclideanDistance);

		printf("\nRunning A* Search with straightLineDistance...\n");
		runAStar(start, end, 
										(int (*)(void *, void *))basicComp,
										(int (*)(void *))straightLineDistance,
										INT_MAX);

		printf("\nRunning A* Search with nonEuclideanDistance...\n");
		runAStar(start, end, 
										(int (*)(void *, void *))basicComp,
										(int (*)(void *))nonEuclideanDistance,
										INT_MAX);
		
		printf("\nRunning IDA* Search  with straightLineDistance...\n");
		runIDAStar(start, end, 
										(int (*)(void *, void *))basicComp,
										(int (*)(void *))straightLineDistance,
										0);

		printf("\nRunning IDA* Search  with nonEuclideanDistance...\n");
		runIDAStar(start, end, 
										(int (*)(void *, void *))basicComp,
										(int (*)(void *))nonEuclideanDistance,
										0);
	}
	return 0;
}