Exemple #1
0
void queueStatusChangeNotif(unsigned int assocID, int queueType, int queueID, int queueLength, void* ulpDataPtr)
{
   unsigned char chunk[MAXIMUM_PAYLOAD_LENGTH];
   unsigned short streamID = 0;
   struct timeval now, diffTime;
   double seconds, throughput;

   if (vverbose) {
       fprintf(stdout, "%-8x: Queue status change notification: Type %d, ID %d, Length %d\n",
                       assocID, queueType, queueID, queueLength);
       fflush(stdout);
   }

   if (queueType == SCTP_SEND_QUEUE && queueLength <= SEND_QUEUE_SIZE) {
      memset(chunk, 0, sizeof(chunk));

      while(stopSending!=1 && (!(((struct ulp_data *)ulpDataPtr)->ShutdownReceived)) &&
            (SCTP_send(assocID, streamID, chunk, chunkLength, SCTP_GENERIC_PAYLOAD_PROTOCOL_ID,
                      SCTP_USE_PRIMARY, SCTP_NO_CONTEXT, timeToLive,
                      SCTP_ORDERED_DELIVERY, SCTP_BUNDLING_DISABLED) == SCTP_SUCCESS)) {
         if (vverbose) {
            fprintf(stdout, "%-8x: %u bytes sent.\n", assocID, chunkLength);
            fflush(stdout);
         }
         if (rotateStreams) {
            streamID = (streamID + 1) % (((struct ulp_data *)ulpDataPtr)->maximumStreamID+1);
         }
         ((struct ulp_data *)ulpDataPtr)->nrOfSentChunks += 1;
         ((struct ulp_data *)ulpDataPtr)->nrOfSentBytes  += chunkLength;
      }
   }
   if ((stopSending == 1) && (queueLength == 0)) {
      SCTP_shutdown(assocID);
      gettimeofday(&now, NULL);
      timersub(&now, &startTime, &diffTime);
      seconds = diffTime.tv_sec + (double)diffTime.tv_usec/1000000;
      fprintf(stdout, "%s of %ld messages of length %u took %f seconds.\n",
         "Sending", ((struct ulp_data *)ulpDataPtr)->nrOfSentChunks, chunkLength, seconds);
      throughput = (double)((struct ulp_data *)ulpDataPtr)->nrOfSentChunks * (double)chunkLength / seconds / 1024.0;
      fprintf(stdout, "Throughput was %f KB/sec.\n", throughput);
   }
}
Exemple #2
0
void clientDataArriveNotif(unsigned int assocID, unsigned short streamID, unsigned int len,
                           unsigned short streamSN,unsigned int TSN, unsigned int protoID,
                           unsigned int unordered, void* ulpDataPtr)
{
    unsigned char chunk[MAXIMUM_PAYLOAD_LENGTH];
    unsigned int length;
    unsigned short ssn;
    unsigned int the_tsn;

    chunkCount++;
    length = sizeof(chunk);
    SCTP_receive(assocID, streamID, chunk, &length, &ssn, &the_tsn, SCTP_MSG_DEFAULT);
    SCTP_send(assocID,
              streamID,
              chunk, length,
              protoID,
              SCTP_USE_PRIMARY, SCTP_NO_CONTEXT, SCTP_INFINITE_LIFETIME, unordered, SCTP_BUNDLING_DISABLED);

    if (chunkCount > ende)     SCTP_shutdown(assocID);
}
Exemple #3
0
void
stdinCallback(char *readBuffer, int length)
{
    if (length == 0) {
        SCTP_unregisterStdinCallback();
        if (useAbort) {
            SCTP_abort(associationID);
        } else {
            SCTP_shutdown(associationID);
        }
    }
    if (length > 0) {
        SCTP_send(associationID,
                  currentStream,
                  (unsigned char*)readBuffer, length,
                  SCTP_GENERIC_PAYLOAD_PROTOCOL_ID,
                  SCTP_USE_PRIMARY, SCTP_NO_CONTEXT,
                  timeToLive, SCTP_ORDERED_DELIVERY, SCTP_BUNDLING_DISABLED);
    }
    if (rotateStreams) currentStream = (currentStream + 1)%numberOutStreams;
}
Exemple #4
0
void* communicationUpNotif(unsigned int assocID, int status,
                           unsigned int noOfPaths,
                           unsigned short noOfInStreams, unsigned short noOfOutStreams,
                           int associationSupportsPRSCTP, void* dummy)
{
   unsigned int index;
   unsigned char chunk[MAXIMUM_PAYLOAD_LENGTH];
   SCTP_PathStatus pathStatus;
   unsigned short pathID;
   unsigned short streamID = 0;
   unsigned long packetNumber;
   struct timeval now, diffTime;
   double seconds, throughput;


   if (verbose) {
      fprintf(stdout, "%-8x: Communication up (%u paths:", assocID, noOfPaths);
      for (pathID=0; pathID < noOfPaths; pathID++){
          SCTP_getPathStatus(assocID, pathID, &pathStatus);
          fprintf(stdout, " %s", pathStatus.destinationAddress);
      }
      fprintf(stdout, ")\n");
      fprintf(stdout, "%-8x:                  %u incoming, %u outgoing streams.\n",
              assocID, noOfInStreams, noOfOutStreams);
      fflush(stdout);
   }

   /* look for a free ULP data */
   for (index=0; index < MAXIMUM_NUMBER_OF_ASSOCIATIONS; index++) {
      if (ulpData[index].maximumStreamID == -1)
         break;
   }

   /* if found */
   if (index < MAXIMUM_NUMBER_OF_ASSOCIATIONS) {
      /* use it */
      ulpData[index].maximumStreamID    = noOfOutStreams - 1;
      ulpData[index].assocID            = assocID;
      ulpData[index].nrOfReceivedChunks = 0;
      ulpData[index].nrOfReceivedBytes  = 0;
      ulpData[index].ShutdownReceived   = 0;
      ulpData[index].nrOfSentChunks = 0;
      ulpData[index].nrOfSentBytes  = 0;

      if (numberOfInitialPackets > 0 && startAssociation) {
         /* send the initial packets */
         memset(chunk, 0, sizeof(chunk));
         gettimeofday(&startTime, NULL);
         for(packetNumber=1; packetNumber <= numberOfInitialPackets; packetNumber++) {
         SCTP_send(assocID,
            streamID,
            chunk, chunkLength,
            SCTP_GENERIC_PAYLOAD_PROTOCOL_ID,
            SCTP_USE_PRIMARY, SCTP_NO_CONTEXT, timeToLive,
            SCTP_ORDERED_DELIVERY,
            SCTP_BUNDLING_DISABLED);
         if (rotateStreams) {
            streamID = (streamID + 1) % noOfOutStreams;
         }
         ulpData[index].nrOfSentChunks += 1;
              ulpData[index].nrOfSentBytes  += chunkLength;
         }
         SCTP_shutdown(assocID);
         if (verbose) {
            fprintf(stdout, "%ld messages of size %d sent.\n",
               packetNumber-1, chunkLength);
         }
      }
      else if (measurementTime > 0) {
         memset(chunk, 0, sizeof(chunk));
         ulpData[index].stopTimerID = SCTP_startTimer(measurementTime, &stopSendingFunction, (void *) &ulpData[index], NULL);
         gettimeofday(&startTime, NULL);
         while((SCTP_send(assocID, streamID, chunk, chunkLength, SCTP_GENERIC_PAYLOAD_PROTOCOL_ID,
                          SCTP_USE_PRIMARY, SCTP_NO_CONTEXT, timeToLive,
                          SCTP_ORDERED_DELIVERY, SCTP_BUNDLING_DISABLED) == SCTP_SUCCESS) && stopSending!=1) {
            if (vverbose) {
             fprintf(stdout, "%-8x: %u bytes sent.\n", assocID, chunkLength);
             fflush(stdout);
            }
            if (rotateStreams) {
               streamID = (streamID + 1) % noOfOutStreams;
            }

            ulpData[index].nrOfSentChunks += 1;
            ulpData[index].nrOfSentBytes  += chunkLength;
         }
         if (stopSending == 1) {
            SCTP_shutdown(assocID);
            gettimeofday(&now, NULL);
            timersub(&now, &startTime, &diffTime);
            seconds = diffTime.tv_sec + (double)diffTime.tv_usec/1000000;
            fprintf(stdout, "%s of %ld messages of length %u took %f seconds.\n",
               "Sending", ulpData[index].nrOfSentChunks, chunkLength, seconds);
            throughput = (double)ulpData[index].nrOfSentChunks * (double)chunkLength / seconds / 1024.0;
            fprintf(stdout, "Throughput was %f KB/sec.\n", throughput);
         }
      }
      return &ulpData[index];
   } else {
      /* abort assoc due to lack of resources */
      SCTP_abort(assocID);
      return NULL;
   }
}