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

📄 nwip.pc

📁 simulator for ad hoc
💻 PC
📖 第 1 页 / 共 5 页
字号:
   InterfaceIdType interfaceId,    NODE_ADDR nextHop){    GlomoNetworkIp *ipLayer = (GlomoNetworkIp *)node->networkData.networkVar;   IpHeaderType* ipHeader = (IpHeaderType *) msg->packet;        ipLayer->stats.numPacketsSentToMac++;                           if (ipHeader->ip_len <= ipLayer->maxPacketLength) {      QueueUpIpFragmentForMacLayer(node, msg, interfaceId, nextHop);   } else {      int ipHeaderSize = IpHeaderSize(ipHeader);      int packetIndex = ipHeaderSize;            //      // Send the packet by splitting it into fragments of       // maximum IP fragment size.      //                            while (packetIndex < ipHeader->ip_len) {         //          // Figure out the packet fragment's size and create it.                  IpHeaderType* fragIpHeader = NULL;         Message* fragment = GLOMO_MsgAlloc(node, 0, 0, 0);         int lastIndex;         int fragmentSize;         int fragmentDataSize = ipLayer->maxPacketLength - ipHeaderSize;                  if ((packetIndex + fragmentDataSize) >= ipHeader->ip_len) {            //            // Its the last fragment.            //            lastIndex = ipHeader->ip_len - 1;            fragmentSize = ipHeaderSize + (lastIndex - packetIndex + 1);         } else {            //            // Shrink fragment data portion to be divisable by 8.            //            fragmentDataSize = ((fragmentDataSize/8) * 8);            fragmentSize = ipHeaderSize + fragmentDataSize;            lastIndex = packetIndex + fragmentDataSize - 1;         }//if//                  GLOMO_MsgPacketAlloc(node, fragment, fragmentSize);                   //         // Copy the header (same for all fragments) into the packet.         // Then the fragment's specific data.   The set the         // fragment's header to specify which part of the packet's         // data it contains.         //                  memcpy(fragment->packet, msg->packet, ipHeaderSize);                  memcpy(&(fragment->packet[ipHeaderSize]),                &(msg->packet[packetIndex]),                 (fragmentSize - ipHeaderSize));                         fragIpHeader = (IpHeaderType *) fragment->packet;         fragIpHeader->ip_len = fragmentSize;         SetFragmentOffset(fragIpHeader, (packetIndex - ipHeaderSize));         if (lastIndex == (ipHeader->ip_len - 1)) {            fragIpHeader->ip_more_fragments = FALSE;          } else {            fragIpHeader->ip_more_fragments = TRUE;          }//if//         QueueUpIpFragmentForMacLayer(node, fragment, interfaceId ,nextHop);                  packetIndex = lastIndex + 1;      }//while//   }//if//}//NetworkIpSendPacketToMacLayer//      //-----------------------------------------------------------------------------typedef struct {   InterfaceIdType interfaceId;   NODE_ADDR nextHop;} DelayedSendToMacLayerInfoType;//-----------------------------------------------------------------------------//// FUNCTION    NetworkIpSendPacketToMacLayerWithDelay()//// PURPOSE     Same as NetworkIpSendPacketToMacLayer but schedules it//             after a simulation delay.     void NetworkIpSendPacketToMacLayerWithDelay(        GlomoNode* node,    Message* msg,    InterfaceIdType interfaceId,    NODE_ADDR nextHop,   clocktype delay) {   DelayedSendToMacLayerInfoType* info;      GLOMO_MsgInfoAlloc(node, msg, sizeof(DelayedSendToMacLayerInfoType));      info = (DelayedSendToMacLayerInfoType*)GLOMO_MsgReturnInfo(msg);   info->interfaceId = interfaceId;   info->nextHop = nextHop;      GLOMO_MsgSetLayer(msg, GLOMO_NETWORK_LAYER, NETWORK_PROTOCOL_IP);   GLOMO_MsgSetEvent(msg, MSG_NETWORK_DelayedSendToMac);   GLOMO_MsgSend(node, msg, delay);}//-----------------------------------------------------------------------------void NetworkIpSendRawGlomoMessageToMacLayer(        GlomoNode* node,   Message* rawMessage,    NODE_ADDR destinationAddress,   NetworkQueueingPriorityType priority,   unsigned char protocol,   unsigned int ttl,   InterfaceIdType interfaceId,   NODE_ADDR nextHop) {   AddIpHeader(node, rawMessage, destinationAddress, priority, protocol, ttl);   NetworkIpSendPacketToMacLayer(node, rawMessage, interfaceId, nextHop);}   void NetworkIpSendRawGlomoMessageToMacLayerWithDelay(        GlomoNode* node,   Message* rawMessage,    NODE_ADDR destinationAddress,   NetworkQueueingPriorityType priority,   unsigned char protocol,   unsigned int ttl,   InterfaceIdType interfaceId,   NODE_ADDR nextHop,   clocktype delay) {   AddIpHeader(node, rawMessage, destinationAddress, priority, protocol, ttl);   NetworkIpSendPacketToMacLayerWithDelay(      node, rawMessage, interfaceId, nextHop, delay);}staticvoid ProcessDelayedSendToMac(GlomoNode* node, Message* msg) {   DelayedSendToMacLayerInfoType* info =       (DelayedSendToMacLayerInfoType*)GLOMO_MsgReturnInfo(msg);   NetworkIpSendPacketToMacLayer(node, msg, info->interfaceId, info->nextHop);}  //---------------------------------------------------------------------------//   SOURCE ROUTING ROUTINE      //// FUNCTION    NetworkIpSendPacketToMacLayerWithNewStrictSourceRoute()//// PURPOSE     Tacks on a new source route to an existing IP packet and//             then sends the packet to the MAC layer.//// PARAMETERS  msg - The message to add the new source route.//             nextHopAddress - The address of the next node on the route.//             newRouteAddresses[] - The source route, a list of addresses.//             numNewRouteAddress - The length of the new source route.//void NetworkIpSendPacketToMacLayerWithNewStrictSourceRoute(   GlomoNode *node,   Message *msg,    NODE_ADDR newRouteAddresses[],   int numNewRouteAddresses,   BOOL removeExistingRecordedRoute){   IpHeaderType* ipHeader = (IpHeaderType*)msg->packet;   char* NewRoutePositionPtr;   IpOptionsHeaderType* ipOption = IpHeaderSourceRouteOptionField(ipHeader);      if (ipOption == NULL) {      //       // Add a source route to a packet with no source route      // currently. The next equation uses the fact that this      // sum will always be divisable by 4.                                                 //        AddIpOptionField(node, msg, IPOPT_SSRR,          ((numNewRouteAddresses * sizeof(NODE_ADDR)) +         IP_SOURCE_ROUTE_OPTION_PADDING));            } else {      //      // Replace a source route to already existing source routing option      // header.      //      if (removeExistingRecordedRoute) {         ipOption->ptr = IPOPT_MINOFF;      }//if//            ExpandOrShrinkIpOptionField(node, msg, IPOPT_SSRR,          ((ipOption->ptr - 1) + (numNewRouteAddresses * sizeof(NODE_ADDR)) +         IP_SOURCE_ROUTE_OPTION_PADDING));   }//if//    // Copy the new route into the option header. Must be   // byte copy because of alignment issues.   ipHeader = (IpHeaderType*)msg->packet;   ipOption = IpHeaderSourceRouteOptionField(ipHeader);   NewRoutePositionPtr =       (char*)IpHeaderSourceRouteOptionField(ipHeader) + (ipOption->ptr - 1);       memcpy(NewRoutePositionPtr, newRouteAddresses,        (sizeof(NODE_ADDR)* numNewRouteAddresses));      // Special case for DSR. Allows for new replacement source route   // whose first addresses is current node. It just moves the route   // pointer to the correct next hop.   if ((removeExistingRecordedRoute) &&        (newRouteAddresses[0] == node->nodeAddr))   {      ipOption->ptr = ipOption->ptr + sizeof(NODE_ADDR);   }//if//   SourceRouteThePacket(node, msg);   }//NetworkIpSendPacketToMacLayerWithNewStrictSourceRoute////---------------------------------------------------------------------------//  CALLBACK FUNCTION SETUP ROUTINES FOR ROUTING PROTOCOLS//// FUNCTION   NetworkIpSetRouterFunction()//// PURPOSE    Allows a routing protocol to set the "routing function" //            (one of its functions) which is called when a packet//            needs to be routed.//void NetworkIpSetRouterFunction(   GlomoNode *node, RouterFunctionType RouterFunctionPtr) {   GlomoNetworkIp *ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;   assert(ipLayer->routerFunction == NULL);   ipLayer->routerFunction = RouterFunctionPtr;}//// FUNCTION   NetworkIpSetPromiscuousMessagePeekFunction()//// PURPOSE    Allows a routing protocol to set the "promiscuous mode//            MAC packet "Peek" function (one of its functions) //            which lets the routing protocol to look at these MAC//            layer packets.//void NetworkIpSetPromiscuousMessagePeekFunction(   GlomoNode* node,    PromiscuousMessagePeekFunctionType PeekFunctionPtr){   GlomoNetworkIp *ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;   assert(ipLayer->promiscuousMessagePeekFunction == NULL);   ipLayer->promiscuousMessagePeekFunction = PeekFunctionPtr;}//// FUNCTION   NetworkIpSetPacketDropNotificationFunction//// PURPOSE    Allows a routing protocol to set the "packet drop //            notification function" which allows the routing//            protocol process packets that are going to be dropped//            (for a broken link).//            //void NetworkIpSetPacketDropNotificationFunction(   GlomoNode* node,    PacketDropNotificationFunctionType packetDropHandlerPtr){   GlomoNetworkIp *ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;   assert(ipLayer->packetDropHandlerFunction == NULL);   ipLayer->packetDropHandlerFunction = packetDropHandlerPtr;}//---------------------------------------------------------------------------// INTERFACE ROUTINES FOR OTHER LAYERS AND SUBSYSTEMS//// FUNCTION    NetworkIpSneakPeekAtMacPacket()//// PURPOSE     Called Directly by the MAC layer, this allows a routing//             protocol to "sneak a peek" or "tap" messages it would not//             normally see from the MAC layer.  This function will//             possibly unfragment such packets and call the function//             registered by the routing protocol to do the "Peek".//// PARAMETERS  msg - The message being peeked at from the MAC layer.  Must//                   not be freed or modified!//void NetworkIpSneakPeekAtMacPacket(GlomoNode *node,  const Message *msg) {   GlomoNetworkIp* ipLayer = (GlomoNetworkIp *)node->networkData.networkVar;      if (ipLayer->promiscuousMessagePeekFunction != NULL) {      IpHeaderType *ipHeader = (IpHeaderType *) msg->packet;         if (!IpPacketIsFragmented(ipHeader)) {          (*ipLayer->promiscuousMessagePeekFunction)(node, msg);      } else {         BOOL packetIsComplete;         Message* completePacket;                  ProcessFragmentAndMaybeBuildCompletePacket(              node, msg, &packetIsComplete, &completePacket);          if (packetIsComplete) {            (*ipLayer->promiscuousMessagePeekFunction)(node, completePacket);            GLOMO_MsgFree(node, completePacket);         }//if//     }//if//   }//if//// TBD   GLOMO_MsgFree(msg);}//NetworkIpSneakPeekAtMacPacket////// FUNCTION    NetworkIpSendRawGlomoMessage()//// PURPOSE     Used by routing protocols in the network layer//             to send a new routing protocol packet to another node.//             The message sent is a raw GloMoSim WITHOUT an IP header.//             The packet follows the usual code path through the network//             layer where it is routed and possibly fragmented.//// PARAMETERS  destinationAddress - Where the packet is going.//             priority - priority of the packet.//             protocol - network protocol being used.//void NetworkIpSendRawGlomoMessage(   GlomoNode* node,   Message* rawMessage,    NODE_ADDR destinationAddress,   NetworkQueueingPriorityType priority,   unsigned char protocol,   unsigned int ttl){   AddIpHeader(node, rawMessage, destinationAddress, priority, protocol, ttl);   RoutePacketAndSendToMac(node, rawMessage);}//// FUNCTION    NetworkIpSendNewPacket()//// PURPOSE     Used by routing protocols in the network layer//             to send a new routing protocol packet to another node.//             If the routing protocol has a routing function, the//             it will quickly see it again to be routed.//// PARAMETERS  destinationAddress - Where the packet is going.//             payload, payloadSize - The payload to send.//             priority - priority of packet.//             protocol - IP protocol number.//void NetworkIpSendNewPacket(   GlomoNode* node,    NODE_ADDR destinationAddress,   NetworkQueueingPriorityType priority,   unsigned char protocol,   unsigned int ttl,   char* payload, int payloadSize){   Message* newMessage = GLOMO_MsgAlloc(node, 0, 0, 0);   GLOMO_MsgPacketAlloc(node, newMessage, payloadSize);   memcpy(newMessage->packet, payload, payloadSize);      AddIpHeader(node, newMessage, destinationAddress, priority, protocol, ttl);   RoutePacketAndSendToMac(node, newMessage);}//// FUNCTION    NetworkIpSendRawGlomoMessageWithDelay()//// PURPOSE     Used by routing protocols in the network layer//             to send a new routing protocol packet to another node.//             The message sent is a raw GloMoSim WITHOUT an IP header.//             The routine simply slaps on an IP header and schedules a//             self message to process the packet.//             The packet follows the usual code path through the network//             layer where it is routed and possibly fragmented.//// PARAMETERS  destinationAddress - Where the packet is going.//             priority - priority of the packet.//             protocol - IP protocol number.//             delay - The delay until the packet is delivered to this//                     layer.//void NetworkIpSendRawGlomoMessageWithDelay(   GlomoNode* node,    Message* msg,    NODE_ADDR destinationAddress,   NetworkQueueingPriorityType priority,   unsigned char protocol,   unsigned int ttl,   clocktype delay) {   AddIpHeader(node, msg, destinationAddress, priority, protocol, ttl);   GLOMO_MsgSetEvent(msg, MSG_NETWORK_FromTransportOrRoutingProtocol);   GLOMO_MsgSetLayer(msg, GLOMO_NETWORK_LAYER, NETWORK_PROTOCOL_IP);   GLOMO_MsgSend(node, msg, delay);}

⌨️ 快捷键说明

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