Ejemplo n.º 1
0
RoutingTableEntryList RoutingTable::getPossibleNextHops(const Packet* packet) {
    if (isDeliverable(packet->getDestination())) {
        AddressPtr source = packet->getSource();
        AddressPtr sender = packet->getSender();

        RoutingTableEntryList* availableHops = table[packet->getDestination()];
        RoutingTableEntryList returnedList = RoutingTableEntryList(*availableHops);

        // remove all entries that would route the packet back over the source or sender of the packet (would create a loop)
        RoutingTableEntryList::iterator iterator = returnedList.begin();
        while (iterator != returnedList.end()) {
            RoutingTableEntry* entry = *iterator;
            AddressPtr possibleNextHop = entry->getAddress();
            if (possibleNextHop->equals(source) || possibleNextHop->equals(sender) ) {
                iterator = returnedList.erase(iterator);
            }
            else {
                iterator++;
            }
        }

        return returnedList;
    }
    else {
        // return empty list
        return RoutingTableEntryList();
    }
}
Ejemplo n.º 2
0
void RoutingTable::removeEntry(AddressPtr destination, AddressPtr nextHop, NetworkInterface* interface) {
    if (table.find(destination) != table.end()) {
        RoutingTableEntryList* entryList = table[destination];
        RoutingTableEntryList::iterator iterator = entryList->begin();

        if (iterator != entryList->end()) {
            while (iterator != entryList->end()) {
                RoutingTableEntry* entry = *iterator;
                if (entry->getAddress()->equals(nextHop) && entry->getNetworkInterface()->equals(interface)) {
                    entryList->erase(iterator);
                    delete entry;
                    break;
                }
                iterator++;
            }

            if (entryList->empty()) {
                // this was the last entry so we can delete the whole list
                table.erase(destination);
                delete entryList;
            }
        }
    }
}