next up previous contents index
Next: 13.8 Other Components Up: 13. Local Area Networks Previous: 13.6.2 Example: Link Layer

13.7 LanRouter class

By default, there is just one LanRouter object per LAN, which is created when a new LanNode is initialized. For every node on the LAN, the link layer object (LL) has a pointer to the LanRouter, so it is able to find the next hop for the packet that is sent on the LAN:
Packet* LL::sendto(Packet* p, Handler* h)
{        
        int nh = (lanrouter_) ? lanrouter_-\>next_hop(p) : -1;
        . . .
}
LanRouter is able to find the next hop by querying the current RouteLogic:
int LanRouter::next_hop(Packet *p) {
        int next_hopIP;
        if (enableHrouting_) {
                routelogic_-\>lookup_hier(lanaddr_, adst, next_hopIP);
        } else {
                routelogic_-\>lookup_flat(lanaddr_, adst, next_hopIP);
        }
One limitation of this is that RouteLogic may not be aware of dynamic changes to the routing. But it is always possible to derive a new class from LanRouter so that to re-define its next_hop method to handle dynamic changes appopriately.




2000-08-24