⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nwip.pc

📁 simulator for ad hoc
💻 PC
📖 第 1 页 / 共 5 页
字号:
void NetworkIpOutputQueueTopPacket(   GlomoNode* node,   InterfaceIdType interfaceId,    Message** msg,   NODE_ADDR* nextHopAddress,   NetworkQueueingPriorityType* priority){   GlomoNetworkIp* ipLayer = (GlomoNetworkIp*)node->networkData.networkVar;   IpOutputQueueType* queue;   NetworkQueueingPriorityType NotUsed = 0;      assert(interfaceId >= 0);   assert(interfaceId < node->numberInterfaces);   queue = ipLayer->interfaceQueues[interfaceId];      (*queue->retrieveAndMaybeDequeueFunction)(      queue->queueUnion,       FALSE, NotUsed, 0,       msg, priority,       FALSE);         *nextHopAddress =       ((TackedOnInfoWhileInNetworkQueueType*)((*msg)->info))->nextHopAddress;}   void NetworkIpOutputQueueTopPacketForAPriority(   GlomoNode* node,   InterfaceIdType interfaceId,    NetworkQueueingPriorityType priority,   Message** msg,   NODE_ADDR* nextHopAddress){   GlomoNetworkIp* ipLayer = (GlomoNetworkIp*)node->networkData.networkVar;   IpOutputQueueType* queue;   NetworkQueueingPriorityType NotUsed = 0;      assert(interfaceId >= 0);   assert(interfaceId < node->numberInterfaces);   queue = ipLayer->interfaceQueues[interfaceId];      (*queue->retrieveAndMaybeDequeueFunction)(      queue->queueUnion,       TRUE, priority, 0,      msg, &NotUsed,       FALSE);         *nextHopAddress =       ((TackedOnInfoWhileInNetworkQueueType*)((*msg)->info))->nextHopAddress;}staticvoid NetworkIpOutputQueueInsert(   GlomoNode* node,   InterfaceIdType interfaceId,   Message* msg,   NODE_ADDR nextHopAddress,    BOOL* QueueIsFull){   GlomoNetworkIp* ipLayer = (GlomoNetworkIp*)node->networkData.networkVar;   IpHeaderType* ipHeader = (IpHeaderType*)msg->packet;   IpOutputQueueType* queue;      assert(interfaceId >= 0);   assert(interfaceId < node->numberInterfaces);   queue = ipLayer->interfaceQueues[interfaceId];      GLOMO_MsgInfoAlloc(node, msg, sizeof(TackedOnInfoWhileInNetworkQueueType));      // Tack on the nextHopAddress to the message using the insiduous "info"   // field.                                             ((TackedOnInfoWhileInNetworkQueueType*)(msg->info))->nextHopAddress =       nextHopAddress;      // Call the "insertFunction" via a ugly function pointer.      (*ipLayer->interfaceQueues[interfaceId]->insertFunction)(      ipLayer->interfaceQueues[interfaceId]->queueUnion,      msg,       ipHeader->ip_tos,      QueueIsFull);}            //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------//    SIMPLE GLOMOSIM MESSAGE SENDING ROUTINES           //// FUNCTION   QueueUpIpFragmentForMacLayer()// PURPOSE    Sends a IP packet to the Mac layer specifying the//            next node address "nextHop" for it to go.//staticvoid QueueUpIpFragmentForMacLayer(   GlomoNode* node,    Message* msg,    InterfaceIdType initInterfaceId,   NODE_ADDR nextHop){   GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;   IpHeaderType* ipHeader = (IpHeaderType*)msg->packet;   BOOL QueueIsFull;   BOOL QueueWasEmpty;      InterfaceIdType interfaceId = initInterfaceId;      if (interfaceId == GET_INTERFACE_FROM_TABLE) {      NODE_ADDR nextHopCheck;      NetworkGetInterfaceAndNextHopFromForwardingTable(node, nextHop,         &interfaceId, &nextHopCheck);      if (nextHopCheck == NETWORK_UNREACHABLE) {         fprintf(stderr, "IP Routing Error: Interface for next hop is ",                  "not in the forwarding table.");         assert(FALSE); abort();      }   }     QueueWasEmpty = NetworkIpOutputQueueIsEmpty(node, interfaceId);      NetworkIpOutputQueueInsert(node, interfaceId, msg, nextHop, &QueueIsFull);      if (QueueIsFull) {      ipLayer->interfaceQueues[interfaceId]->packetsLostToOverflow++;      GLOMO_MsgFree(node, msg);   } else {       if (QueueWasEmpty) {         GLOMO_MacNetworkLayerHasPacketToSend(node, interfaceId);      }   }}//// FUNCTION   SendToUdp()// PURPOSE    Simply sends a message already stripped of its IP//            header up to UDP in the transport layer.  The //            source address of the packet is also sent. //void SendToUdp(   GlomoNode *node,     Message *msg,    NetworkQueueingPriorityType priority,   NODE_ADDR sourceAddress,   NODE_ADDR destinationAddress) {   GLOMO_MsgSetEvent(msg, MSG_TRANSPORT_FromNetwork);   GLOMO_MsgSetLayer(msg, GLOMO_TRANSPORT_LAYER, TRANSPORT_PROTOCOL_UDP);   GLOMO_MsgInfoAlloc(node, msg, sizeof(NetworkToTransportInfo));   ((NetworkToTransportInfo *)msg->info)->sourceAddr = sourceAddress;   ((NetworkToTransportInfo *)msg->info)->destinationAddr = destinationAddress;   ((NetworkToTransportInfo *)msg->info)->priority = priority;   GLOMO_MsgSend(node, msg, PROCESS_IMMEDIATELY);}//// FUNCTION   SendToTcp()// PURPOSE    Simply sends a message already stripped of its IP//            header up to TCP in the transport layer.  The //            source address of the packet is also sent. //staticvoid SendToTcp(   GlomoNode *node,     Message *msg,    NetworkQueueingPriorityType priority,   NODE_ADDR sourceAddress,   NODE_ADDR destinationAddress) {   GLOMO_MsgSetEvent(msg, MSG_TRANSPORT_FromNetwork);   GLOMO_MsgSetLayer(msg, GLOMO_TRANSPORT_LAYER, TRANSPORT_PROTOCOL_TCP);   GLOMO_MsgInfoAlloc(node, msg, sizeof(NetworkToTransportInfo));   ((NetworkToTransportInfo *)msg->info)->sourceAddr = sourceAddress;   ((NetworkToTransportInfo *)msg->info)->destinationAddr = destinationAddress;   ((NetworkToTransportInfo *)msg->info)->priority = priority;   GLOMO_MsgSend(node, msg, PROCESS_IMMEDIATELY);}//-----------------------------------------------------------------------------//-----------------------------------------------------------------------------//    REASSEMBLY BUFFER LIST ROUTINES  // Functions for a Simple list abstract data type // for storing reassembly buffers.//// FUNCTION    IpReassemblyBufferList_Init()// PURPOSE     Initalize the list.//static void IpReassemblyBufferList_Init(   IpReassemblyBufferListType* reassemblyBufferList) {   reassemblyBufferList->firstPtr = NULL;   reassemblyBufferList->freeListPtr = NULL;}//// FUNCTION  IpReassemblyBufferList_Delete()// PURPOSE   Searches the list and deletes the list element//           identified by the "reassemblyBufferPtr" parameter.//           The deleted list cell is put on a free list.//   static                                              void IpReassemblyBufferList_Delete(   IpReassemblyBufferListType* reassemblyBufferList,   IpReassemblyBufferType** reassemblyBufferPtr) {   //   // Find the reassembly buffer in the list.   //   IpReassemblyBufferListCellType* previousCellPtr = NULL;       IpReassemblyBufferListCellType*       currentCellPtr = reassemblyBufferList->firstPtr;            while ((currentCellPtr != NULL) &&           (currentCellPtr->reassemblyBuffer.packetUnderConstruction !=           (*reassemblyBufferPtr)->packetUnderConstruction))   {      previousCellPtr = currentCellPtr;      currentCellPtr = currentCellPtr->nextPtr;   }//while//      assert(currentCellPtr != NULL);   //   // Unlink the cell.   //   if (previousCellPtr == NULL) {      reassemblyBufferList->firstPtr = currentCellPtr->nextPtr;   } else {      previousCellPtr->nextPtr = currentCellPtr->nextPtr;   }//if//   //   // Put the cell on Free List.   //   currentCellPtr->nextPtr =  reassemblyBufferList->freeListPtr;   reassemblyBufferList->freeListPtr = currentCellPtr;   (*reassemblyBufferPtr) = NULL;}//Delete////// FUNCTION  IpReassemblyBufferList_AddNewBuffer()// PURPOSE   Adds a new element to the list, getting //           the list cell from the free list if there//           is one.// RETURN    reassemblyBufferPtr - The new reassembly buffer.//   staticvoid IpReassemblyBufferList_AddNewBuffer(   IpReassemblyBufferListType* reassemblyBufferList,   IpReassemblyBufferType** reassemblyBufferPtr) {   IpReassemblyBufferListCellType* newCell = NULL;      if (reassemblyBufferList->freeListPtr == NULL) {      newCell = (IpReassemblyBufferListCellType*)checked_pc_malloc(         sizeof(IpReassemblyBufferListCellType));   } else {      newCell = reassemblyBufferList->freeListPtr;      reassemblyBufferList->freeListPtr =          reassemblyBufferList->freeListPtr->nextPtr;   }//if//      newCell->nextPtr = reassemblyBufferList->firstPtr;   reassemblyBufferList->firstPtr = newCell;      *reassemblyBufferPtr = &newCell->reassemblyBuffer;}//// FUNCTION  IpReassemblyBufferList_AddNewBuffer()// PURPOSE   Searches for a reassembly buffer that matches//           the packet fragment in "packetFragment".//           If one is not found, then make a new one//           and return that.// RETURN    reassemblyBufferPtr - A reassembly buffer for the fragment.//staticvoid IpReassemblyBufferList_FindOrCreateNew(   IpReassemblyBufferListType* reassemblyBufferList,   const Message* packetFragment,   IpReassemblyBufferType** FragBufferPtr,   BOOL* FoundExistingBuffer) {   IpReassemblyBufferListCellType*       currentCellPtr = reassemblyBufferList->firstPtr;            while ((currentCellPtr != NULL) &&          (!IsIpFragmentOf(              currentCellPtr->reassemblyBuffer.packetUnderConstruction,               packetFragment)))   {      currentCellPtr = currentCellPtr->nextPtr;   }//while//   if (currentCellPtr == NULL) {      *FoundExistingBuffer = FALSE;      IpReassemblyBufferList_AddNewBuffer(reassemblyBufferList, FragBufferPtr);   } else {      *FoundExistingBuffer = TRUE;      (*FragBufferPtr) = &(currentCellPtr->reassemblyBuffer);   }//if//}//FindOrCreateNew//   //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------//-----------------------------------------------------------------------------//  REASSEMBLY BUFFER MANAGEMENT//// FUNCTION  ClearReassemblyBuffer() // PURPOSE   Frees resources held by a reassembly buffer.//staticvoid ClearReassemblyBuffer(   GlomoNode* node,    IpReassemblyBufferType* FragBuffer) {   GLOMO_MsgFree(node, FragBuffer->packetUnderConstruction);}//// FUNCTION  ReassemblyBufferHasExpired() // PURPOSE   Is true if the reassembly buffer has expired.//staticBOOL ReassemblyBufferHasExpired(   IpReassemblyBufferType* reassemblyBuffer,   clocktype currentTime) {   return (reassemblyBuffer->expirationDate < currentTime);   }//// FUNCTION  RemoveExpiredIpReassemblyBuffers() // PURPOSE   Deletes expired reassembly buffers by iterating through the//           reassembly buffer list.//staticvoid RemoveExpiredIpReassemblyBuffers(   GlomoNode* node,   IpReassemblyBufferListType* reassemblyBufferList,   clocktype currentTime) {   GlomoNetworkIp* ipLayer = (GlomoNetworkIp *)node->networkData.networkVar;   IpReassemblyBufferListCellType* previousCellPtr = NULL;       IpReassemblyBufferListCellType*       currentCellPtr = reassemblyBufferList->firstPtr;            while (currentCellPtr != NULL) {      if (ReassemblyBufferHasExpired(         &(currentCellPtr->reassemblyBuffer), currentTime))       {         IpReassemblyBufferListCellType*             nextCellPtr = currentCellPtr->nextPtr;                  //         // Unlink the cell.         //                  if (previousCellPtr == NULL) {            reassemblyBufferList->firstPtr = currentCellPtr->nextPtr;         } else {            previousCellPtr->nextPtr = currentCellPtr->nextPtr;         }//if//         //         // Put the cell on Free List.         //         currentCellPtr->nextPtr =  reassemblyBufferList->freeListPtr;         reassemblyBufferList->freeListPtr = currentCellPtr;                  ClearReassemblyBuffer(node, &currentCellPtr->reassemblyBuffer);                  currentCellPtr = nextCellPtr;                         } else {         previousCellPtr = currentCellPtr;         currentCellPtr = currentCellPtr->nextPtr;      }//if//   }//while//}//RemoveExpiredIpFragmentBuffers////-----------------------------------------------------------------------------//   FRAGMENT REASSEMBLY ROUTINES//// FUNCTION ExpandReassemblyBuffer() //// PURPOSE  Expands a reassembly buffer for when large packets are//          defragmented.  The "minSize" specifies the minimal//          size that the buffer should be expanded to.//

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -