int simquit(void * pio) { PACKET pkt; ip_addr hop; struct ip * pip; if(simtimer) { in_timerkill(simtimer); simtimer = 0; } /* send all queued packets */ while(simq.q_head) { pkt = (PACKET)getq(&simq); /* get pkt to send */ hop = pkt->fhost; /* get hop from host field */ pip = ip_head(pkt); /* get real host address */ pkt->fhost = pip->ip_dest; /* restore host field */ ip2mac(pkt, hop); /* send pkt to hardware */ } rfsim_routing = FALSE; ns_printf(pio, "rfsim stopped\n"); return 0; }
void rfsim_timer() { ip_addr hop; struct ip * pip; PACKET pkt; /* send al packets which have timed out */ while(((PACKET)(simq.q_head))->nb_tstamp < cticks) { pkt = (PACKET)getq(&simq); /* get pkt to send */ hop = pkt->fhost; /* get hop from host field */ pip = ip_head(pkt); /* get real host address */ pkt->fhost = pip->ip_dest; /* restore host field */ simpkts++; /* see if it's time to drop a packet */ if((lossrate) && ((simpkts - simlastloss) > lossrate) && ((cticks & deviation) == 1)) { LOCK_NET_RESOURCE(FREEQ_RESID); pk_free(pkt); /* drop instead of send */ UNLOCK_NET_RESOURCE(FREEQ_RESID); simlastloss = simpkts; /* reset drop timer */ simdrops++; /* count drops */ } else ip2mac(pkt, hop); /* send pkt to hardware */ } return; }
/* * Query the neighbor cache for IPv4/IPv6 to mac address mapping. */ static int ibcm_nce_lookup(ibcm_arp_prwqn_t *wqnp, ill_t *ill, zoneid_t zoneid) { ip2mac_t ip2m; sin_t *sin; sin6_t *sin6; ip2mac_id_t ip2mid; int err; if (wqnp->src_addr.family != wqnp->dst_addr.family) { IBTF_DPRINTF_L2(cmlog, "ibcm_nce_lookup: Mis-match SRC_ADDR " "Family: %d, DST_ADDR Family %d", wqnp->src_addr.family, wqnp->dst_addr.family); return (1); } bzero(&ip2m, sizeof (ip2m)); if (wqnp->dst_addr.family == AF_INET) { sin = (sin_t *)&ip2m.ip2mac_pa; sin->sin_family = AF_INET; sin->sin_addr.s_addr = wqnp->dst_addr.un.ip4addr; } else if (wqnp->dst_addr.family == AF_INET6) { sin6 = (sin6_t *)&ip2m.ip2mac_pa; sin6->sin6_family = AF_INET6; sin6->sin6_addr = wqnp->dst_addr.un.ip6addr; } else { IBTF_DPRINTF_L2(cmlog, "ibcm_nce_lookup: Invalid DST_ADDR " "Family: %d", wqnp->dst_addr.family); return (1); } ip2m.ip2mac_ifindex = ill->ill_phyint->phyint_ifindex; wqnp->flags |= IBCM_ARP_PR_RESOLVE_PENDING; /* * issue the request to IP for Neighbor Discovery */ ip2mid = ip2mac(IP2MAC_RESOLVE, &ip2m, ibcm_resolver_ack, wqnp, zoneid); err = ip2m.ip2mac_err; if (err == EINPROGRESS) { wqnp->ip2mac_id = ip2mid; wqnp->flags |= IBCM_ARP_PR_RESOLVE_PENDING; err = 0; } else if (err == 0) { ibcm_resolver_ack(&ip2m, wqnp); } return (err); }