Пример #1
0
/* -------------------------------------------------------------------

   ------------------------------------------------------------------- */
int SendData2(int sourcefd, int targetfd, unsigned long int filesize)
{
  unsigned long int nread=0, nwrite, ns=0, readsize, i, offset=0;
  long int nt;
  char *buffptr, buff[MAXBUFFLEN];
  int retval;
  struct ibp_timer timeout;
 
  int fin;  char tmpbuf[3];
  
  timeout.ServerSync = 10;
  timeout.ClientTimeout = 10;
  fprintf(stderr,"IN SEND DATA 2     IBP_cap:<<%s>>\n",glb.IBP_cap);

  while(nread < filesize){ 
    readsize = ((filesize-nread)<(MAXBUFFLEN) ? (filesize-nread):(MAXBUFFLEN));
    bzero(buff,MAXBUFFLEN); 
    /**ns = sRead(sourcefd, buff, readsize);*/
    offset += ns;
    ns = IBP_load(glb.IBP_cap, &timeout, buff, readsize, offset);
    if(ns == 0){
      /**fprintf(stderr,"TCP client failed readsize= %d nread=%d\n",readsize,nread);*/
      perror("smclientTCP: error reading from FILE");
      return -1;
    }
    nwrite=0;
    buffptr = buff;
    fprintf(stderr,"#");
    while(nwrite < ns){
      nt = ns-nwrite;
      if((nt = sWrite(targetfd, buffptr, ns-nwrite)) < 0){
	perror("error writing to socket");
	return -1;                    /* one fails all fails*/ 
      }
      buffptr += nt;
      nwrite += nt;
    }    
    nread += ns;
  }
  
  fin = read(targetfd, tmpbuf, 3);
  if(fin > 0){
    if(!strcmp(tmpbuf,"FIN")){
      fprintf(stderr,"End of data transfer\n");
      retval = 1;
      goto FIN;
    }
    else{
      retval = -1;
      goto FIN;
    }
  }
  else{
    fprintf(stderr,"Cannot end transmission properly, SendData failed\n");
    retval = -1;
  }
 FIN:
  return retval;
}
Пример #2
0
int SendData2(int sourcefd, int *targetfd, unsigned long int filesize,int numtargets)
{
  unsigned long    int nread=0, nwrite, ns=0, readsize, i, offset=0;
  long             int nt;
  char             *buffptr, buff[MAXBUFFLEN];
  struct ibp_timer timeout;
  int              fin,retval;  
  char             tmpbuf[3];

  while(nread < filesize){ 
    readsize = ((filesize-nread)<(MAXBUFFLEN) ? (filesize-nread):(MAXBUFFLEN));
    bzero(buff,MAXBUFFLEN); 
    /***ns = sRead(sourcefd, buff, readsize);*/
    offset += ns;
    ns = IBP_load(glb.IBP_cap, &timeout, buff, readsize, offset);
    if(ns == 0){
      perror("error reading from FILE");
      return -1;
    }
    nwrite=0;
    buffptr = buff;
    fprintf(stderr,"#");
    while(nwrite < ns){
      for(i=0; i<numtargets; i++){
	if((nt = sWrite(targetfd[i], buffptr, ns-nwrite)) < 0){
	  fprintf(stderr,"(host %d) ",i);
	  perror("error writing to socket");
	  return -1;                    /* one fails, everything else fails*/
	}
      }
      buffptr += nt;
      nwrite += nt;
    }    
    nread += ns;
  }

  for(i=0; i<numtargets; i++){
    fin = read(targetfd[i], tmpbuf, 3);
    if(fin > 0){
      if(!strcmp(tmpbuf,"FIN")){
	fprintf(stderr,"End of data transfer [%d]\n",i);
	retval = 1;
      }
      else{
	retval = -1;
	goto FIN;
      }
    }
    else{
      fprintf(stderr,"Cannot end transmission properly, target %d failed\n",i);
      retval = -1;
      goto FIN;
    }
  }
 FIN:  
  return retval;
}
void ibp_test_nfu(struct ibp_depot *depot) 
{
    struct ibp_attributes ls_att;
    time_t ls_now;
    struct ibp_timer timeout;
    IBP_set_of_caps caps1,caps2,caps3;
    char  buf[]="123456789123456789123456789123456789";
    int ret,i;
    char retBuf[60];
    PARAMETER paras[3];
    int len = strlen(buf);
    
    time(&ls_now);
    ls_att.duration = (ls_now + 5);
    ls_att.reliability = IBP_STABLE;
    ls_att.type = IBP_BYTEARRAY;

    timeout.ServerSync = 10000;
    timeout.ClientTimeout = 10000;

    if ( NULL == ( caps1 = IBP_allocate(depot,&timeout, 500,&ls_att)) ){
        fprintf(stderr," Allocate failed %d\n",IBP_errno);
        exit(-1);
    }
    if ( NULL == ( caps2 = IBP_allocate(depot,&timeout, 500,&ls_att)) ){
        fprintf(stderr,"failed %d\n",IBP_errno);
        exit(-1);
    }
    if ( NULL == ( caps3 = IBP_allocate(depot,&timeout, 500,&ls_att)) ){
        fprintf(stderr,"failed %d\n",IBP_errno);
        exit(-1);
    }
    if ( len != ( ret = IBP_store(caps1->writeCap,&timeout,buf,len)) ){
        fprintf(stderr,"failed %d\n",IBP_errno);
        exit(-1);
    }
    if ( len != ( ret = IBP_store(caps2->writeCap,&timeout,buf,len)) ){
        fprintf(stderr,"failed %d\n",IBP_errno);
        exit(-1);
    }
/*
    fprintf(stderr,"cap = %s\n",caps3->writeCap );
    fprintf(stderr,"store\n");

    if ( len != ( ret = IBP_store(caps3->writeCap,&timeout,buf,len)) ){
        fprintf(stderr,"failed %d\n",IBP_errno);
        exit(-1);
    }
*/
    //exit(-1);
    paras[0].ioType = IBP_REF_RD;
    paras[0].data = caps1->readCap;
    paras[0].offset = 0;
    paras[0].len = len;

    
    paras[1].ioType = IBP_REF_RD;
    paras[1].data = caps2->readCap;
    paras[1].offset = 0;
    paras[1].len = len;

    paras[2].ioType = IBP_REF_RDWR;
    paras[2].data = caps3->writeCap;
    paras[2].offset = 0;
    paras[2].len = len;

    if ( (ret = IBP_nfu_op(depot,1,3,paras,&timeout)) != IBP_OK ){
        fprintf(stderr," failed %d\n", IBP_errno);
        exit(-1);
    }
/*
    retBuf[32]= '\0';
    fprintf(stderr,"MD5 = %s len = %d \n",retBuf,strlen(retBuf));

    return;
*/
    if ( len != ( ret = IBP_load(caps3->readCap,&timeout,buf,len,0)) ){
        fprintf(stderr,"failed %d\n",IBP_errno);
        exit(-1);
    }
    
    for ( i = 0 ; i < len ; i ++ ){
        if ( buf[i] != 0 ){
            fprintf(stderr,"failed \n");
            exit(-1);
        }
    }

    return;
}
Пример #4
0
int main(int argc, char **argv)
{
  ibp_depotinfo_t *depotinfo;
  ibp_depot_t depot1, depot2;
  ibp_attributes_t attr;
  ibp_timer_t timer;
  ibp_capset_t *caps, *caps2, *caps4;
  ibp_capset_t caps3, caps5;
  ibp_capstatus_t astat;
  ibp_alias_capstatus_t alias_stat;
  int err, i, len, offset;
  int bufsize = 1024*1024;
  char wbuf[bufsize];
  char rbuf[bufsize];
  char *host1, *host2;
  int port1, port2;
  rid_t rid1, rid2;

  failed_tests = 0;

  if (argc < 6) {
     printf("ibp_test [-d loglevel] [-config ibp.cfg] host1 port1 rid1 host2 port2 rid2\n");
     printf("\n");
     printf("     2 depots are requred to test depot-depot copies.\n");
     printf("     Can use the same depot if necessary\n");
     printf("\n");
     printf("\n");
     return(-1);
  }

  ibp_init();  //** Initialize IBP


  //*** Read in the arguments ***    
  i = 1;
  if (strcmp(argv[i], "-d") == 0) {
     i++;
     set_log_level(atoi(argv[i]));
     i++;
  }

  if (strcmp(argv[i], "-config") == 0) { //** Read the config file
     i++;
     ibp_load_config(argv[i]);
     i++;
  }

  host1 = argv[i];  i++;
  port1 = atoi(argv[i]); i++;
  rid1 = ibp_str2rid(argv[i]); i++;  

  host2 = argv[i];  i++;
  port2 = atoi(argv[i]); i++;
  rid2 = ibp_str2rid(argv[i]); i++;  

  //*** Print the ibp client version ***
  printf("\n");
  printf("================== IBP Client Version =================\n");
  printf("%s\n", ibp_client_version());

  //*** Init the structures ***
  ibp_timeout = 5;
  set_ibp_depot(&depot1, host1, port1, rid1);
  set_ibp_depot(&depot2, host2, port2, rid2);
  set_ibp_attributes(&attr, time(NULL) + 60, IBP_HARD, IBP_BYTEARRAY); 
  set_ibp_timer(&timer, ibp_timeout, ibp_timeout);

//printf("Before allocate\n"); fflush(stdout);

  //*** Perform single allocation
  caps = IBP_allocate(&depot1, &timer, bufsize, &attr);

  if (caps == NULL) {
     printf("Error!!!! ibp_errno = %d\n", IBP_errno);
     return(1);
  } else {
     printf("Read: %s\n", caps->readCap);
     printf("Write: %s\n", caps->writeCap);
     printf("Manage: %s\n", caps->manageCap);
  }  

  printf("ibp_manage(IBP_PROBE):-----------------------------------\n");
  memset(&astat, 0, sizeof(astat));
  err = IBP_manage(get_ibp_cap(caps, IBP_MANAGECAP), &timer, IBP_PROBE, 0, &astat);
  if (err == 0) {
     printf("read count = %d\n", astat.readRefCount);
     printf("write count = %d\n", astat.writeRefCount);
     printf("current size = %d\n", astat.currentSize);
     printf("max size = %lu\n", astat.maxSize);
     printf("duration = %ld\n", astat.attrib.duration - time(NULL));
     printf("reliability = %d\n", astat.attrib.reliability);
     printf("type = %d\n", astat.attrib.type);
  } else {
     failed_tests++;
     printf("ibp_manage error = %d * ibp_errno=%d\n", err, IBP_errno);
  }


  printf("ibp_manage(IBP_DECR for write cap):-----------------------------------\n");
  err = IBP_manage(get_ibp_cap(caps, IBP_MANAGECAP), &timer, IBP_DECR, IBP_WRITECAP, &astat);
  if (err != 0) { printf("ibp_manage error = %d * ibp_errno=%d\n", err, IBP_errno); }
  err = IBP_manage(get_ibp_cap(caps, IBP_MANAGECAP), &timer, IBP_PROBE, 0, &astat);
  if (err == 0) {
     printf("read count = %d\n", astat.readRefCount);
     printf("write count = %d\n", astat.writeRefCount);
     printf("current size = %d\n", astat.currentSize);
     printf("max size = %lu\n", astat.maxSize);
     printf("duration = %lu\n", astat.attrib.duration - time(NULL));
     printf("reliability = %d\n", astat.attrib.reliability);
     printf("type = %d\n", astat.attrib.type);
  } else {
     failed_tests++;
     printf("ibp_manage error = %d * ibp_errno=%d\n", err, IBP_errno);
  }


  printf("ibp_manage(IBP_CHNG - incresing size to 2MB and changing duration to 20 sec):-----------------------------------\n");
  set_ibp_attributes(&(astat.attrib), time(NULL) + 20, IBP_HARD, IBP_BYTEARRAY);
  astat.maxSize = 2*1024*1024;
  err = IBP_manage(get_ibp_cap(caps, IBP_MANAGECAP), &timer, IBP_CHNG, 0, &astat);
  if (err != 0) { printf("ibp_manage error = %d * ibp_errno=%d\n", err, IBP_errno); }
  err = IBP_manage(get_ibp_cap(caps, IBP_MANAGECAP), &timer, IBP_PROBE, 0, &astat);
  if (err == 0) {
     printf("read count = %d\n", astat.readRefCount);
     printf("write count = %d\n", astat.writeRefCount);
     printf("current size = %d\n", astat.currentSize);
     printf("max size = %lu\n", astat.maxSize);
     printf("duration = %lu\n", astat.attrib.duration - time(NULL));
     printf("reliability = %d\n", astat.attrib.reliability);
     printf("type = %d\n", astat.attrib.type);
  } else {
     failed_tests++;
     printf("ibp_manage error = %d * ibp_errno=%d\n", err, IBP_errno);
  }

  //**** Basic Write tests ****
  printf("write tests..................................\n");
  for (i=0; i<bufsize; i++) wbuf[i] = '0';
  len = 3*bufsize/4;
  err = IBP_store(get_ibp_cap(caps, IBP_WRITECAP), &timer, wbuf, len);
  if (err != len) {
     failed_tests++;
     printf("Error with IBP_store1! wrote=%d err=%d\n", err, IBP_errno);
  }    

  len = bufsize - len;
  err = IBP_store(get_ibp_cap(caps, IBP_WRITECAP), &timer, wbuf, len);
  if (err != len) {
     failed_tests++;
     printf("Error with IBP_store2! wrote=%d err=%d\n", err, IBP_errno);
  }    

  for (i=0; i<bufsize; i++) wbuf[i] = '1';
  len = bufsize/2;
  offset = 10;
  err = IBP_write(get_ibp_cap(caps, IBP_WRITECAP), &timer, wbuf, len, offset);
  if (err != len) {
     failed_tests++;
     printf("Error with IBP_Write! wrote=%d err=%d\n", err, IBP_errno);
  }    


  printf("ibp_load test...............................\n");
  len = bufsize;
  offset = 0;
  err = IBP_load(get_ibp_cap(caps, IBP_READCAP), &timer, rbuf, len, offset);
  if (err != len) {
     failed_tests++;
     printf("Error with IBP_load! wrote=%d err=%d\n", err, IBP_errno);
  } else {
    rbuf[50] = '\0';
    printf("rbuf=%s\n", rbuf);
  }

  printf("ibp_copy test................................\n");
  //*** Perform single allocation
  caps2 = IBP_allocate(&depot2, &timer, bufsize, &attr);
  if (caps2 == NULL) {
     failed_tests++;
     printf("Error with allocation of dest cap!!!! ibp_errno = %d\n", IBP_errno);
     return(1);
  } else {
     printf("dest Read: %s\n", caps2->readCap);
     printf("dest Write: %s\n", caps2->writeCap);
     printf("dest Manage: %s\n", caps2->manageCap);
  }  
  err = IBP_copy(get_ibp_cap(caps, IBP_READCAP), get_ibp_cap(caps2, IBP_WRITECAP), &timer, &timer, 1024, 0);
  if (err != 1024) { failed_tests++; printf("ibp_copy size = %d * ibp_errno=%d\n", err, IBP_errno); }

  printf("ibp_phoebus_copy test................................\n");
  //*** Perform single allocation
  caps4 = IBP_allocate(&depot2, &timer, bufsize, &attr);
  if (caps4 == NULL) {
     printf("Error with allocation of dest cap!!!! ibp_errno = %d\n", IBP_errno);
     failed_tests++;
     return(1);
  } else {
     printf("dest Read: %s\n", caps4->readCap);
     printf("dest Write: %s\n", caps4->writeCap);
     printf("dest Manage: %s\n", caps4->manageCap);
  }  
  err = IBP_phoebus_copy(NULL, get_ibp_cap(caps, IBP_READCAP), get_ibp_cap(caps4, IBP_WRITECAP), &timer, &timer, 1024, 0);
  if (err != 1024) { failed_tests++; printf("ibp_copy size = %d * ibp_errno=%d\n", err, IBP_errno); }

  //** Remove the cap
  err = IBP_manage(get_ibp_cap(caps4, IBP_MANAGECAP), &timer, IBP_DECR, IBP_READCAP, &astat);
  if (err != 0) { 
     failed_tests++;
     printf("Error deleting phoebus dest cap error = %d * ibp_errno=%d\n", err, IBP_errno); 
  }
  destroy_ibp_capset(caps4); caps4 = NULL;

  printf("ibp_manage(IBP_DECR):-Removing allocations----------------------------------\n");
  err = IBP_manage(get_ibp_cap(caps, IBP_MANAGECAP), &timer, IBP_DECR, IBP_READCAP, &astat);
  if (err != 0) { failed_tests++; printf("ibp_manage(decr) for caps1 error = %d * ibp_errno=%d\n", err, IBP_errno); }
  err = IBP_manage(get_ibp_cap(caps2, IBP_MANAGECAP), &timer, IBP_DECR, IBP_READCAP, &astat);
  if (err != 0) { failed_tests++; printf("ibp_manage(decr) for caps2 error = %d * ibp_errno=%d\n", err, IBP_errno); }

  printf("ibp_status: IBP_ST_INQ--------------------------------------------------------\n");
  depotinfo = IBP_status(&depot1, IBP_ST_INQ, &timer, "ibp", 10,11,12);
  if (depotinfo != NULL) {
     printf("rid=%d * duration=%ld\n", depotinfo->rid, depotinfo->Duration);
     printf("hc=" LL " hs=" LL " ha=" LL "\n",depotinfo->HardConfigured, depotinfo->HardServed, depotinfo->HardAllocable);
     printf("tc=" LL " ts=" LL " tu=" LL "\n", depotinfo->TotalConfigured, depotinfo->TotalServed, depotinfo->TotalUsed);
  } else {
     failed_tests++;
     printf("ibp_status error=%d\n", IBP_errno);
  }

  //** Perform some basic async R/W alloc/remove tests
  base_async_test(2, &depot1);

  //** Now do a few of the extra tests for async only
  ibp_op_t op;

  //*** Print the depot version ***
  set_ibp_version_op(&op, &depot1, rbuf, sizeof(rbuf), ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err == IBP_OK) {
     printf("Printing depot version information......................................\n");
     printf("%s\n", rbuf);
  } else {
     failed_tests++;
     printf("Error getting ibp_version. err=%d\n", err);
  }
  
  //*** Query the depot resources ***
  ibp_ridlist_t rlist;
  set_ibp_query_resources_op(&op, &depot1, &rlist, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err == IBP_OK) {
     printf("Number of resources: %d\n", ridlist_get_size(&rlist));
     for (i=0; i<ridlist_get_size(&rlist); i++) {
        printf("  %d: %s\n", i, ibp_rid2str(ridlist_get_element(&rlist, i), rbuf));
     }
  } else {
     failed_tests++;
     printf("Error querying depot resource list. err=%d\n", err);
  }  

  perform_user_rw_tests(&depot1);  //** Perform the "user" version of the R/W functions

  //-----------------------------------------------------------------------------------------------------
  //** check ibp_rename ****

  printf("Testing IBP_RENAME...............................................\n");
  caps = IBP_allocate(&depot1, &timer, bufsize, &attr);
  if (caps == NULL) {
     failed_tests++;
     printf("Error!!!! ibp_errno = %d\n", IBP_errno);
     return(1);
  } else {
     printf("Original Cap..............\n");
     printf("Read: %s\n", caps->readCap);
     printf("Write: %s\n", caps->writeCap);
     printf("Manage: %s\n", caps->manageCap);
  }  

  //** Upload the data
  char *data = "This is a test....";
  len = strlen(data)+1;
  err = IBP_store(get_ibp_cap(caps, IBP_WRITECAP), &timer, data, len);
  if (err != len) {
     failed_tests++;
     printf("Error with IBP_store1! wrote=%d err=%d\n", err, IBP_errno);
  }    

  //** Rename the allocation
  set_ibp_rename_op(&op, caps2, get_ibp_cap(caps, IBP_MANAGECAP), ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("Error with ibp_rename. err=%d\n", err);
  } else {
     printf("Renamed Cap..............\n");
     printf("Read: %s\n", caps2->readCap);
     printf("Write: %s\n", caps2->writeCap);
     printf("Manage: %s\n", caps2->manageCap);
  }  
  
  //** Try reading the original which should fail
  rbuf[0] = '\0';
  err = IBP_load(get_ibp_cap(caps, IBP_READCAP), &timer, rbuf, len, 0);
  if (err != len) {
     printf("Can't read the original cap after the rename which is good!  Got err err=%d\n", err);
  } else {
     failed_tests++;
    printf("Oops!  The read of the original cap succeeded! rbuf=%s\n", rbuf);
  }

  //** Try reading with the new cap
  rbuf[0] = '\0';
  err = IBP_load(get_ibp_cap(caps2, IBP_READCAP), &timer, rbuf, len, 0);
  if (err == len) {
     if (strcmp(rbuf, data) == 0) {
        printf("Read using the new cap the original data!\n");
     } else {
        failed_tests++;
        printf("Read some data with the new cap but it wasn't correct!\n");
        printf("Original=%s\n", data);
        printf("     Got=%s\n", wbuf);
     }
  } else {
     failed_tests++;
     printf("Oops! Failed reading with new cap! err=%d\n", err);
  }

  //** Remove the cap
  err = IBP_manage(get_ibp_cap(caps2, IBP_MANAGECAP), &timer, IBP_DECR, IBP_READCAP, &astat);
  if (err != 0) { 
     failed_tests++;
     printf("Error deleting new cap after rename caps2 error = %d * ibp_errno=%d\n", err, IBP_errno); 
  }
  printf("Completed ibp_rename test...........................\n");

  //-----------------------------------------------------------------------------------------------------
  //** check ibp_alias_allocate/manage ****

//**** GOOD
  printf("Testing IBP_alias_ALLOCATE/MANAGE...............................................\n");
  caps = IBP_allocate(&depot1, &timer, bufsize, &attr);
  if (caps == NULL) {
     failed_tests++;
     printf("Error!!!! ibp_errno = %d\n", IBP_errno);
     return(1);
  } else {
     printf("Original Cap..............\n");
     printf("Read: %s\n", caps->readCap);
     printf("Write: %s\n", caps->writeCap);
     printf("Manage: %s\n", caps->manageCap);
  }  

  set_ibp_alias_alloc_op(&op, caps2, get_ibp_cap(caps, IBP_MANAGECAP), 0, 0, 0, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("Error with ibp_alias_alloc. err=%d\n", err);
  } else {
     printf("Alias Cap..............\n");
     printf("Read: %s\n", caps2->readCap);
     printf("Write: %s\n", caps2->writeCap);
     printf("Manage: %s\n", caps2->manageCap);
  }  


  err = IBP_manage(get_ibp_cap(caps, IBP_MANAGECAP), &timer, IBP_PROBE, 0, &astat);
  if (err == 0) {
     printf("Actual cap info\n");
     printf(" read count = %d\n", astat.readRefCount);
     printf(" write count = %d\n", astat.writeRefCount);
     printf(" current size = %d\n", astat.currentSize);
     printf(" max size = %lu\n", astat.maxSize);
     printf(" duration = %lu\n", astat.attrib.duration - time(NULL));
     printf(" reliability = %d\n", astat.attrib.reliability);
     printf(" type = %d\n", astat.attrib.type);
  } else {
     failed_tests++;
     printf("ibp_manage error = %d * ibp_errno=%d\n", err, IBP_errno);
  }

  err = IBP_manage(get_ibp_cap(caps2, IBP_MANAGECAP), &timer, IBP_PROBE, 0, &astat);
  if (err == 0) {
     printf("Using alias to get actual cap info\n");
     printf(" read count = %d\n", astat.readRefCount);
     printf(" write count = %d\n", astat.writeRefCount);
     printf(" current size = %d\n", astat.currentSize);
     printf(" max size = %lu\n", astat.maxSize);
     printf(" duration = %lu\n", astat.attrib.duration - time(NULL));
     printf(" reliability = %d\n", astat.attrib.reliability);
     printf(" type = %d\n", astat.attrib.type);
  } else {
     failed_tests++;
     printf("ibp_manage error = %d * ibp_errno=%d\n", err, IBP_errno);
  }

  set_ibp_alias_probe_op(&op, get_ibp_cap(caps2, IBP_MANAGECAP), &alias_stat, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("Error with ibp_alias_probe. err=%d\n", err);
  } else {
     printf("Alias stat..............\n");
     printf(" read count = %d\n", alias_stat.read_refcount);
     printf(" write count = %d\n", alias_stat.write_refcount);
     printf(" offset = " ST "\n", alias_stat.offset);
     printf(" size = " ST "\n", alias_stat.size);
     printf(" duration = %lu\n", alias_stat.duration - time(NULL));
  }

  set_ibp_alias_alloc_op(&op, &caps3, get_ibp_cap(caps, IBP_MANAGECAP), 10, 40, 0, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("Error with ibp_alias_alloc_op. err=%d\n", err);
  } else {
     printf("Alias Cap with range 10-50.............\n");
     printf("Read: %s\n", caps3.readCap);
     printf("Write: %s\n", caps3.writeCap);
     printf("Manage: %s\n", caps3.manageCap);
  }  

  err = IBP_manage(get_ibp_cap(&caps3, IBP_MANAGECAP), &timer, IBP_PROBE, 0, &astat);
  if (err == 0) {
     printf("Using limited alias to get actual cap info\n");
     printf(" read count = %d\n", astat.readRefCount);
     printf(" write count = %d\n", astat.writeRefCount);
     printf(" current size = %d\n", astat.currentSize);
     printf(" max size = %lu *** This should be 40\n", astat.maxSize);
     printf(" duration = %lu\n", astat.attrib.duration - time(NULL));
     printf(" reliability = %d\n", astat.attrib.reliability);
     printf(" type = %d\n", astat.attrib.type);
  } else {
     failed_tests++;
     printf("ibp_manage error = %d * ibp_errno=%d\n", err, IBP_errno);
  }

  printf("*append* using the full alias..................................\n");
  for (i=0; i<bufsize; i++) wbuf[i] = '0';
  err = IBP_store(get_ibp_cap(caps2, IBP_WRITECAP), &timer, wbuf, bufsize);
  if (err != bufsize) {
     failed_tests++;
     printf("Error with IBP_store! wrote=%d err=%d\n", err, IBP_errno);
  }    

  printf("write using the limited alias..................................\n");  
  data = "This is a test.";
  len = strlen(data)+1;
  err = IBP_write(get_ibp_cap(&caps3, IBP_WRITECAP), &timer, data, len, 0);
  if (err != len) {
     failed_tests++;
     printf("Error with IBP_Write! wrote=%d err=%d\n", err, IBP_errno);
  }    

  memcpy(&(wbuf[10]), data, strlen(data)+1);
  len = 10 + strlen(data)+1;
  err = IBP_load(get_ibp_cap(caps2, IBP_READCAP), &timer, rbuf, len, 0);
  if (err == len) {
     if (strcmp(rbuf, wbuf) == 0) {
        printf("Read using the new full alias the original data!\n");
        printf("  read=%s\n", rbuf);       
     } else {
        failed_tests++;
        printf("Read some data with the new cap but it wasn't correct!\n");
        printf("Original=%s\n", wbuf);
        printf("     Got=%s\n", rbuf);
     }
  } else {
     failed_tests++;
     printf("Oops! Failed reading with new cap! err=%d\n", err);
  }


  //** Try to R/W beyond the end of the limited cap **
  printf("attempting to R/W beyond the end of the limited alias......\n");
  data = "This is a test.";
  len = strlen(data)+1;
  err = IBP_write(get_ibp_cap(&caps3, IBP_WRITECAP), &timer, data, len, 35);
  if (err != len) {
     printf("Correctly got an IBP_Write error! wrote=%d err=%d\n", err, IBP_errno);
  } else {
     failed_tests++;
     printf("Oops! Was able to write beyond the end of the limited cap with new cap!\n");
  }

  err = IBP_load(get_ibp_cap(&caps3, IBP_READCAP), &timer, rbuf, len, 35);
  if (err != len) {
     printf("Correctly got an IBP_read error! wrote=%d err=%d\n", err, IBP_errno);
  } else {
     failed_tests++;
     printf("Oops! Was able to read beyond the end of the limited cap with new cap!\n");
  }

  //** Perform a alias->alias copy.  The src alias is restricted
  printf("Testing restricted alias->full alias depot-depot copy\n");
  caps4 = IBP_allocate(&depot1, &timer, bufsize, &attr);
  if (caps == NULL) {
     failed_tests++;
     printf("alias-alias allocate Error!!!! ibp_errno = %d\n", IBP_errno);
     return(1);
  } else {
     printf("Depot-Depot copy OriginalDestiniation Cap..............\n");
     printf("Read: %s\n", caps4->readCap);
     printf("Write: %s\n", caps4->writeCap);
     printf("Manage: %s\n", caps4->manageCap);
  }  

  set_ibp_alias_alloc_op(&op, &caps5, get_ibp_cap(caps4, IBP_MANAGECAP), 0, 0, 0, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("Error with ibp_alias_alloc_op. err=%d\n", err);
  } else {
     printf("Destination Alias Cap with full range.............\n");
     printf("Read: %s\n", caps5.readCap);
     printf("Write: %s\n", caps5.writeCap);
     printf("Manage: %s\n", caps5.manageCap);
  }  

//BAD!!!!!!!!!!!
  //** Perform the copy
  data = "This is a test.";
  len = strlen(data)+1;
  err = IBP_copy(get_ibp_cap(&caps3, IBP_READCAP), get_ibp_cap(&caps5, IBP_WRITECAP), &timer, &timer, len, 0);
  if (err != len) { printf("ibp_copy size = %d * ibp_errno=%d\n", err, IBP_errno); }

  //** Load it back and verify **
  err = IBP_load(get_ibp_cap(&caps5, IBP_READCAP), &timer, rbuf, len, 0);
  if (err == len) {
     if (strcmp(rbuf, data) == 0) {
        printf("Read using the new full alias the original data!\n");
        printf("  read=%s\n", rbuf);       
     } else {
        failed_tests++;
        printf("Read some data with the new cap but it wasn't correct!\n");
        printf("Original=%s\n", data);
        printf("     Got=%s\n", rbuf);
     }
  } else {
     failed_tests++;
     printf("Oops! Failed reading with new cap! err=%d\n", err);
  }

  //** Remove the cap5 (full alias)
  set_ibp_alias_remove_op(&op, get_ibp_cap(&caps5, IBP_MANAGECAP), get_ibp_cap(caps4, IBP_MANAGECAP), ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("Error dest deleting alias cap error = %d\n", err); 
  }

  //** Remove the dest cap
  err = IBP_manage(get_ibp_cap(caps4, IBP_MANAGECAP), &timer, IBP_DECR, IBP_READCAP, &astat);
  if (err != 0) { 
     failed_tests++;
     printf("Error deleting dest caps error = %d * ibp_errno=%d\n", err, IBP_errno); 
  }

  printf("completed alias depot->depot copy test\n");

  //** Try to remove the cap2 (full alias) with a bad cap
  set_ibp_alias_remove_op(&op, get_ibp_cap(caps2, IBP_MANAGECAP), get_ibp_cap(&caps3, IBP_MANAGECAP), ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     printf("Correctly detected error deleting alias cap with an invalid master cap error = %d\n", err); 
  } else {
     failed_tests++;
     printf("Oops! Was able to delete the alias with an invalid master cap!!!!!!!!\n");
  }

  //** Remove the cap2 (full alias)
  set_ibp_alias_remove_op(&op, get_ibp_cap(caps2, IBP_MANAGECAP), get_ibp_cap(caps, IBP_MANAGECAP), ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("Error deleting alias cap error = %d\n", err); 
  }

  printf("Try to read the deleted full falias.  This should generate an error\n");
  err = IBP_load(get_ibp_cap(caps2, IBP_READCAP), &timer, rbuf, len, 35);
  if (err != len) {
     printf("Correctly got an IBP_read error! wrote=%d err=%d\n", err, IBP_errno);
  } else {
     failed_tests++;
     printf("Oops! Was able to write beyond the end of the limited cap with new cap!\n");
  }

  //** Remove the limited alias (cap3)
  set_ibp_alias_remove_op(&op, get_ibp_cap(&caps3, IBP_MANAGECAP), get_ibp_cap(caps, IBP_MANAGECAP), ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("Error deleting the limited alias cap  error = %d\n", err); 
  }

  //** Remove the original cap
  err = IBP_manage(get_ibp_cap(caps, IBP_MANAGECAP), &timer, IBP_DECR, IBP_READCAP, &astat);
  if (err != 0) { 
     failed_tests++;
     printf("Error deleting original caps error = %d * ibp_errno=%d\n", err, IBP_errno); 
  }

//GOOD!!!!!!!!!!!!!!!!!!!!

  printf("finished testing IBP_alias_ALLOCATE/MANAGE...............................................\n");

  perform_splitmerge_tests(&depot1);
  perform_pushpull_tests(&depot1, &depot2);

  printf("\n\n");
  printf("Final network connection counter: %d\n", network_counter(NULL));
  printf("Tests that failed: %d\n", failed_tests);

  ibp_finalize();

  return(0);
}
Пример #5
0
void perform_pushpull_tests(ibp_depot_t *depot1, ibp_depot_t *depot2)
{
  int bufsize = 2048;
  char wbuf[bufsize+1], rbuf[bufsize+1];
  ibp_op_t op;
  ibp_attributes_t attr;
  ibp_capset_t caps1, caps2;
  int nbytes, err;
  ibp_timer_t timer;
  int start_nfailed = failed_tests;

  printf("perform_pushpull_tests:  Starting tests!\n");

  set_ibp_timer(&timer, ibp_timeout, ibp_timeout);

  //** Initialize the buffers **
  memset(wbuf, '0', sizeof(wbuf));  wbuf[1023]='1'; wbuf[1024]='2'; wbuf[bufsize] = '\0';
  memset(rbuf, 0, sizeof(rbuf));
  nbytes = 1024;

  //*** Make the allocation used in the tests ***
  set_ibp_attributes(&attr, time(NULL) + A_DURATION, IBP_HARD, IBP_BYTEARRAY);
  set_ibp_alloc_op(&op, &caps1, bufsize, depot1, &attr, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_pushpull_tests: Oops! Error creating allocation 1 for tests!! error=%d\n", err);
     return;
  }

  set_ibp_alloc_op(&op, &caps2, bufsize, depot2, &attr, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_pushpull_tests: Oops! Error creating allocation 2 for tests!! error=%d\n", err);
     return;
  }

  //** Fill caps1="1" with data **
  err = IBP_store(get_ibp_cap(&caps1, IBP_WRITECAP), &timer, "1", 1);
  if (err != 1) {
     failed_tests++;
     printf("perform_pushpull_tests: Oops! Error with master IBP_store! wrote=%d err=%d\n", err, IBP_errno);
  }    

  //** Append it to cap2="1"
  set_ibp_copy_op(&op, IBP_PUSH, NS_TYPE_SOCK, NULL, get_ibp_cap(&caps1, IBP_READCAP), 
          get_ibp_cap(&caps2, IBP_WRITECAP), 0, -1, 1, ibp_timeout, ibp_timeout, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_pushpull_tests: Oops! Error with copy 1!! error=%d\n", err);
     return;
  }

  //** Append cap2 to cap1="11"
  set_ibp_copy_op(&op, IBP_PULL, NS_TYPE_SOCK, NULL, get_ibp_cap(&caps1, IBP_WRITECAP), 
          get_ibp_cap(&caps2, IBP_READCAP), -1, 0, 1, ibp_timeout, ibp_timeout, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_pushpull_tests: Oops! Error with copy 2!! error=%d\n", err);
     return;
  }

  //** Append it to cap2="111"
  set_ibp_copy_op(&op, IBP_PUSH, NS_TYPE_SOCK, NULL, get_ibp_cap(&caps1, IBP_READCAP), 
          get_ibp_cap(&caps2, IBP_WRITECAP), 0, -1, 2, ibp_timeout, ibp_timeout, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_pushpull_tests: Oops! Error with copy 3!! error=%d\n", err);
     return;
  }

  //** Change  caps1="123"
  err = IBP_write(get_ibp_cap(&caps1, IBP_WRITECAP), &timer, "23", 2, 1);
  if (err != 2) {
     failed_tests++;
     printf("perform_pushpull_tests: Oops! Error with IBP_store 2! wrote=%d err=%d\n", err, IBP_errno);
  }    

  //** offset it to also make cap2="123"
  set_ibp_copy_op(&op, IBP_PUSH, NS_TYPE_SOCK, NULL, get_ibp_cap(&caps1, IBP_READCAP), 
          get_ibp_cap(&caps2, IBP_WRITECAP), 1, 1, 2, ibp_timeout, ibp_timeout, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_pushpull_tests: Oops! Error with copy 4!! error=%d\n", err);
     return;
  }

  //** Now read them back and check them
  //** verify caps1
  memset(rbuf, 0, sizeof(rbuf));
  memcpy(wbuf, "123", 4);
  err = IBP_load(get_ibp_cap(&caps1, IBP_READCAP), &timer, rbuf, 3, 0);
  if (err == 3) {
     if (strcmp(rbuf, wbuf) != 0) {
        failed_tests++;
        printf("perform_pushpull_tests: Read some data with the cap1 but it wasn't correct!\n");
        printf("perform_pushpull_tests: Original=%s\n", wbuf);
        printf("perform_pushpull_tests:      Got=%s\n", rbuf);
     }
  } else {
     failed_tests++;
     printf("perform_pushpull_tests: Oops! Failed reading cap1! err=%d\n", err);
  }

  //** and also caps2
  memset(rbuf, 0, sizeof(rbuf));
  err = IBP_load(get_ibp_cap(&caps2, IBP_READCAP), &timer, rbuf, 3, 0);
  if (err == 3) {
     if (strcmp(rbuf, wbuf) != 0) {
        failed_tests++;
        printf("perform_pushpull_tests: Read some data with the cap2 but it wasn't correct!\n");
        printf("perform_pushpull_tests: Original=%s\n", wbuf);
        printf("perform_pushpull_tests:      Got=%s\n", rbuf);
     }
  } else {
     failed_tests++;
     printf("perform_pushpull_tests: Oops! Failed reading cap2! err=%d\n", err);
  }

  //** Lastly Remove the allocations **
  set_ibp_remove_op(&op, get_ibp_cap(&caps1, IBP_MANAGECAP), ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     printf("perform_pushpull_tests: Oops! Error removing allocation 1!  ibp_errno=%d\n", err);
  }
  set_ibp_remove_op(&op, get_ibp_cap(&caps2, IBP_MANAGECAP), ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     printf("perform_pushpull_tests: Oops! Error removing allocation 2!  ibp_errno=%d\n", err);
  }

  if (start_nfailed == failed_tests) {
     printf("perform_pushpull_tests: Passed!\n");
  } else {
     printf("perform_pushpull_tests: Oops! FAILED!\n");
  }
}
Пример #6
0
void perform_splitmerge_tests(ibp_depot_t *depot)
{
  int bufsize = 2048;
  char wbuf[bufsize+1], rbuf[bufsize+1];
  ibp_op_t op;
  ibp_attributes_t attr;
  ibp_capset_t mcaps, caps, caps2;
  ibp_capstatus_t probe;
  int nbytes, err, max_size, curr_size, dummy;
  ibp_timer_t timer;

  printf("perform_splitmerge_tests:  Starting tests!\n");

  set_ibp_timer(&timer, ibp_timeout, ibp_timeout);

  //** Initialize the buffers **
  memset(wbuf, '0', sizeof(wbuf));  wbuf[1023]='1'; wbuf[1024]='2'; wbuf[bufsize] = '\0';
  memset(rbuf, 0, sizeof(rbuf));
  nbytes = 1024;

  //*** Make the allocation used in the tests ***
  set_ibp_attributes(&attr, time(NULL) + A_DURATION, IBP_HARD, IBP_BYTEARRAY);
  set_ibp_alloc_op(&op, &mcaps, bufsize, depot, &attr, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error creating initial allocation for tests!! error=%d\n", err);
     return;
  }

  //** Fill the master with data **
  err = IBP_store(get_ibp_cap(&mcaps, IBP_WRITECAP), &timer, wbuf, bufsize);
  if (err != bufsize) {
     failed_tests++;
     printf("perform_splitmerge_tests: Error with master IBP_store! wrote=%d err=%d\n", err, IBP_errno);
  }    

  //** Split the allocation
  set_ibp_split_alloc_op(&op, get_ibp_cap(&mcaps, IBP_MANAGECAP), &caps, 1024, &attr, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error creating child allocation for tests!! error=%d\n", err);
     return;
  }
  
  //** Check the new size of the master
  set_ibp_probe_op(&op, get_ibp_cap(&mcaps, IBP_MANAGECAP), &probe, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error probing master allocation for tests!! error=%d\n", err);
     return;
  }

  get_ibp_capstatus(&probe, &dummy, &dummy, &curr_size, &max_size, &attr);
  if ((curr_size != 1024) && (max_size != 1024)) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error with master allocation size!! curr_size=%d * max_size=%d should both be 1024\n", curr_size, max_size);
     return;
  }   

  //** Check the size of the child allocation
  set_ibp_probe_op(&op, get_ibp_cap(&caps, IBP_MANAGECAP), &probe, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error probing child allocation for tests!! error=%d\n", err);
     return;
  }

  get_ibp_capstatus(&probe, &dummy, &dummy, &curr_size, &max_size, &attr); 
  if ((curr_size != 0) && (max_size != 1024)) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error with master allocation size!! curr_size=%d * max_size=%d should be 0 and 1024\n", curr_size, max_size);
     return;
  }   

  //** Verify the master data
  wbuf[1024] = '\0';
  err = IBP_load(get_ibp_cap(&mcaps, IBP_READCAP), &timer, rbuf, 1024, 0);
  if (err == 1024) {
     if (strcmp(rbuf, wbuf) != 0) {
        failed_tests++;
        printf("Read some data with the mastercap but it wasn't correct!\n");
        printf("Original=%s\n", wbuf);
        printf("     Got=%s\n", rbuf);
     }
  } else {
     failed_tests++;
     printf("Oops! Failed reading master cap! err=%d\n", err);
  }

  //** Load data into the child
  err = IBP_store(get_ibp_cap(&caps, IBP_WRITECAP), &timer, wbuf, 1024);
  if (err != 1024) {
     failed_tests++;
     printf("perform_splitmerge_tests: Error with child IBP_store! wrote=%d err=%d\n", err, IBP_errno);
  }    

  //** Read it back
  memset(rbuf, 0, sizeof(rbuf));
  err = IBP_load(get_ibp_cap(&caps, IBP_READCAP), &timer, rbuf, 1024, 0);
  if (err == 1024) {
     if (strcmp(rbuf, wbuf) != 0) {
        failed_tests++;
        printf("Read some data with the childcap but it wasn't correct!\n");
        printf("Original=%s\n", wbuf);
        printf("     Got=%s\n", rbuf);
     }
  } else {
     failed_tests++;
     printf("Oops! Failed reading child cap! err=%d\n", err);
  }

  //** Split the master again but htis time make it to big so it should fail
  set_ibp_split_alloc_op(&op, get_ibp_cap(&mcaps, IBP_MANAGECAP), &caps2, 2048, &attr, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err == IBP_OK) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error created child allocation when I shouldn't have! error=%d\n", err);
     return;
  }

  //** Check the size of the master to make sure it didn't change
  set_ibp_probe_op(&op, get_ibp_cap(&mcaps, IBP_MANAGECAP), &probe, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error probing master allocation2 for tests!! error=%d\n", err);
     return;
  }

  get_ibp_capstatus(&probe, &dummy, &dummy, &curr_size, &max_size, &attr);
  if ((curr_size != 1024) && (max_size != 1024)) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error with master allocation size2!! curr_size=%d * max_size=%d should both be 1024\n", curr_size, max_size);
     return;
  }   

//GOOD!!!!!!!!!!!!!!!!!

  //** Merge the 2 allocations
  set_ibp_merge_alloc_op(&op, get_ibp_cap(&mcaps, IBP_MANAGECAP), get_ibp_cap(&caps, IBP_MANAGECAP), ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error with merge! error=%d\n", err);
     return;
  }

  //** Verify the child is gone
  set_ibp_probe_op(&op, get_ibp_cap(&caps, IBP_MANAGECAP), &probe, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err == IBP_OK) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Oops!  Child allocation is available after merge! ccap=%s\n", get_ibp_cap(&caps, IBP_MANAGECAP));
     return;
  }


  //** Verify the max/curr size of the master
  set_ibp_probe_op(&op, get_ibp_cap(&mcaps, IBP_MANAGECAP), &probe, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error with probe of mcapafter mergs! ccap=%s err=%d\n", get_ibp_cap(&mcaps, IBP_MANAGECAP), err);
     return;
  }

//GOOD!!!!!!!!!!!!!!!!!

  get_ibp_capstatus(&probe, &dummy, &dummy, &curr_size, &max_size, &attr);
  if ((curr_size != 1024) && (max_size != 2048)) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error with master allocation size after merge!! curr_size=%d * max_size=%d should both 1024 and 2048\n", curr_size, max_size);
     return;
  }   

  //** Lastly Remove the master allocation **
  set_ibp_remove_op(&op, get_ibp_cap(&mcaps, IBP_MANAGECAP), ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     printf("perform_splitmerge_tests: Error removing master allocation!  ibp_errno=%d\n", err);
  }

  printf("perform_splitmerge_tests:  Passed!\n");
}
Пример #7
0
int SendDataUDP(int srcfd, int targfd, unsigned long int size, int count,float initwindow)
{
  int lastack;             /* last packet acked */
  int i, cnt;
  int resends = 0;
  int thisack;             /* temporarly here */
  int rflag = 0;
  int wintot = 0;
  int globalSeq=0;
  int retread;
  char data[MAXBUF], adata[MAXBUF];
  char action[5];
  float window;            /* packets in flight */
  int offset=0;
  struct ibp_timer timeout;

  int ooffset;
  start1 = time(NULL);

  lastack = -1;
  i = 0;
  globalSeq = 0;
  strcpy(action,"send\0");
  window = initwindow;
  ooffset = lseek(srcfd,0,SEEK_CUR);                      /* get position within file (header) */

  timeout.ServerSync = 0;
  timeout.ClientTimeout = 10;

  for (i=0; i < (count-1) || lastack < count; )           /* <------   main loop gets the file */
  {   
    int load;    
    load = (i != count-1) ? MAXLOAD : (size - MAXLOAD*(count-1));

    if (lastack < (count-1) && ((i-lastack) <= window))
    {
      sprintf(data, "%08d  %08d", i,globalSeq);           /* adding header seq# to data */

#ifndef NODISK                                            /* reads from local-server file to buff to send */
      lseek(srcfd, (i*MAXLOAD)+ooffset, SEEK_SET);        /* position in the local file */
      retread = read(srcfd, data+HDR+HDR2, load);         /* added HDR2 to include seq # */

      offset += retread;
      retread = IBP_load(glb.IBP_cap, &timeout, data+HDR+HDR2, load, offset);
#endif

      if (sendto(targfd, data, load+HDR+HDR2, 0, 
		 (struct sockaddr *)&name1, sizeof(name1)) < 0)
          perror("Sending datagram message");


      if (i < (count-1)) i++; 
    }

    if (((i-lastack) > window) || (i == (count-1) && lastack < count))  /*  <---- i think problem here */
    {
      do {
        signal(SIGALRM, wake);
        ualarm(100000, 0);

        if (cnt=recvfrom(targfd,adata,MAXBUF,0,(struct sockaddr *)&name1,&length1)<0 
	    && errno != EINTR){
          perror("Error receving ack data from client");     
          exit(1);
        }
        ualarm(0, 0);
      } while (cnt < 0);

      wintot += window;   
      if(atoi(adata+3)!=0)                      /* added this if to see if it works  */
	thisack = atoi(adata+3);                /*  <------ thisack depends on adata, if kicked is 0     */
      else
	thisack = lastack;

      if (adata[1] != 'A')
      {
        if (!rflag || adata[1] != 'N') { 
          if (adata[1] == 'N') fprintf(stderr, "(%.0f)", window);
	  else fprintf(stderr, "[%.0f]", window);

          resends += i - thisack + 1;
          i = thisack;                          /*  <-------- i modified          */
	  lastack = thisack;                    /* - window + 1; */

	  window *= WINDOW_DOWN;
	  if (window < MINWIN) window = MINWIN;
	  
	  if (adata[1] == 'N') rflag = 1; else rflag = 0;
        } 
      } 
      else {
        if (!(thisack%10)) fprintf(stderr, "#");

        if (lastack <= thisack) {
          window += WINDOW_UP;
	  lastack = thisack;
	}
        rflag = 0;
      }
    } /* end if */
    globalSeq++;
  }   /* end of for transfering file */

  fprintf(stderr, "\ninit window=%.0f, avg = %0.f, final=%.0f, resends=%.0f%%\n", 
	  initwindow, wintot/(float)count, window, resends*100/(float)count);

  return 1;
}