1. A non-transitory machine readable medium storing a program which when executed by at least one processing unit implements a first managed forwarding element for implementing a plurality of logical networks for a plurality of machines that connect to the first managed forwarding element, the program comprising sets of instructions for: receiving a packet from a particular machine that connects to the first managed forwarding element; performing logical L2 processing for a first logical L2 domain, to which the particular machine logically couples, to logically forward the packet to a logical router, said performing logical L2 processing for the first domain comprising identifying the logical router by identifying a logical egress port of the first logical L2 domain that is associated with a media access control (MAC) address of the logical router; performing logical L3 processing for the logical router to logically forward the packet to a second logical L2 domain to which a machine associated with a destination address of the packet belongs; performing logical L2 processing for the second logical L2 domain; and based on the logical L2 processing for the second logical L2 domain, forwarding the packet to a second managed forwarding element with context information stored in the packet indicating that the logical L2 processing for the second logical L2 domain was performed by the first managed forwarding element, said logical L2 and L3 processing performed by analyzing logical L2 and L3 attributes of the first and second logical L2 domains, said L2 logical attributes comprising said logical egress port.