voidNetworkInterface::handle_ip_ethernet_update_and_send( uint32_t ip, EthernetAddress eth ) { // check whether there is a ARP request in air auto arp_rq_it = arp_request_timers_.find( ip ); if ( arp_rq_it != arp_request_timers_.end() ) { arp_request_timers_.erase( arp_rq_it ); }
// add this record to list and start the timer auto arp_rec_it = arp_table_.find( ip ); if ( arp_rec_it != arp_table_.end() ) { // 1. if the record is already in the list, renew the record and reset the timer arp_rec_it->second.first = eth; arp_rec_it->second.second.reset_time(); } else { // 2. if the this is a new record, add it to the list and start the timer arp_table_.emplace( ip, std::make_pair( eth, ArpRecordTimer() ) ); arp_table_[ip].second.start(); }
// Check if there is any datagram waiting for this ARP reply auto it = dgram_waiting_list_.find( ip ); if ( it != dgram_waiting_list_.end() ) { // There are datagrams waiting for this ARP reply while ( !it->second.empty() ) { InternetDatagram dgram = it->second.front(); it->second.pop(); EthernetFrame frame { .header = { .dst = eth, .src = ethernet_address_, .type = EthernetHeader::TYPE_IPv4 }, .payload = serialize( dgram ) }; this->transmit( frame ); } dgram_waiting_list_.erase( it ); } }