240 likes | 447 Views
CS 498 Lecture 8 Data Link Layer. Jennifer Hou Department of Computer Science University of Illinois at Urbana-Champaign Reading: Chapters 6, The Linux Networking Architecture: Design and Implementation of Network Protocols in the Linux Kernel. Data Link Layer.
E N D
CS 498 Lecture 8Data Link Layer Jennifer Hou Department of Computer Science University of Illinois at Urbana-Champaign Reading: Chapters 6, The Linux Networking Architecture: Design and Implementation of Network Protocols in the Linux Kernel
Data Link Layer • The data link layer is divided into a logical-link control (LLC) and a media-access control (MAC) layer. • LLC hides all media-specific differences and provides a uniform interface for high-layer protocols.
Layers 1 and 2 in IEEE 802 Network layer Network-layer Protocol instances 2b Network devices 802.1 Overview Architecture Management 802.1 Locigal Link Control 802.3 CSMA/CD 802.5 Token Ring 802.11 WLAN 2a Drivers Network-adapter ... ... 1 IEEE 802 standard Linux network architectue
Overview of LLC Activities Layer 5 Application processes NET_RX_SOFTIRQ- Software-Interrupt System calls *Kernel activities(Interrupts, Tasklets, Timer-Handler etc.) * Layer 1-4 CPU1 CPU2 eth0 eth1 Hardware-Interrupt System-calls NET_RX- Soft-IRQ NET_TX- Soft-IRQ
1. Hardware Interrupt • Hardware interrupts accept incoming data packets from the network adapters and put them immediately into the incoming queue of the processing CPU. • The software interrupt NET_RX_SOFTIRQ is marked for execution to handle the packets further.
2. Software Interrupt • Software interrupt NET_RX_SOFTIRQ • Is responsible for handling protocol instances on layers 2-4 (for packets to be delivered locally) or on layers 2-3 (for packets to be forwarded) • Incoming packets are handled by NET_RX_SOFTIRQ upto the kernel boundary and forwarded to a waiting process. • Packets to be forwarded are put into the outgoing queue of a network device.
3. System Calls • Data packets sent by application processes are handled by system calls. • In the context of a system call, a packet is handled by the corresponding protocol instances until it is put into one of the output queues of the network device. • When a packet cannot be sent immediately after it was put into the output queue, the software interrupt NET_TX_SOFTIRQ is marked for later execution.
Packet Path in LLC .. ... p8022_rcv arp_rcv ip_rcv arp_send ip_queue_xmit ETH_P_802_2 dev.c br_input.c dev.c ... handle_bridge dev_queue_xmit net_rx_action CONFIG_BRIDGE dev->qdisc->enqueue do_softirq Scheduler eth1 eth0 CPU1 CPU2 dev.c net_tx_action softnet_data[cpun].input_pkt_queue qdisc_run dev.c netif_rx Scheduler qdisc_restart eth_type_trans() driver.c dev->qdisc->dequeue dev_alloc_skb() driver.c net_interrupt dev->hard_start_xmit
Receiving a Packet • The network adapter receives a packet and informs the kernel about its arrival by triggering an interrupt. • The interrupt-handling routine of the network driver (e.g., net_interrupt()) handles the interrupt by identifying which event causes the interrupt. • In the case of an incoming packet, net_rx() is invoked. In the case of acknowledging packet transmission, net_tx() is invoked.
Receiving a Packet • net_rx() • Uses dev_alloc_skb(pkt_len) to obtain a socket buffer and copies the incoming packet to the packet data area of the skb. • Sets skb dev to the receiving network device. • Invokes eth_type_trans() to retrieve the protocol type in the Ethernet frame. • Invokes netif_rx() to complete the interrupt handling.
eth_type_trans() • Invoke skb_pull(skb, devhard_header_length) to take the layer-2 packet header. • Identify the packet type and store it in skbskb_type. • PACKET_BROADCAST • PACKET_MULTICAST • PACKET_HOST • PACKET_OTHERHOST • Identify the protocol identifier of the incoming packet and stores it in skb protocol.
Receiving a Packet • netif_rx() • Sets the current time in skbtime • Places the socket buffer in the input queue softnet_data[cpu].input_pkt_queue. • Marks NET_RX_SOFTIRQ for execution by __cpu_raise_softirq(cpu, NET_RX_SOFTIRQ) • When the process scheduler (schedule() in kernel/sched.c) is invoked, it first checks for whether a software interrupt is marked for execution, and uses do_softirq() to start soft-IRQ.
Receiving a Packet • net_rx_action() • Is the handling routine of NET_RX_SOFTIRQ. • Consists of essentially a continuous loop (for (;;){…}) and passes, one by one, the packets from the input queue to the protocol-handling routine. • Invokes __skb_dequeue(). • Passes the skb to all the protocols registered in the list ptype_all. • Passes the skb to all protocols registered with the protocol identifier (devprotocol). All the protocols are managed in the hash table ptype_base. • Example: devprotocol=0x0800 is mapped by the hash function to the IP instance, and the handling function ip_rcv() pointed to by func() is invoked.
Managing Protocols in LLC packet_type 0 ptype_base[16] type: ETH_P_ARP dev: NULL arp_rcv() func data: 1 packet_type A protocol that receives only packets with the correct packet identifier next packet_type 1 type: ETH_P_IP A protocol that receives all packets arriving at the interface dev: NULL ip_rcv() func data: 1 next . . . 16 packet_type packet_type packet_type type: ETH_P_ALL ptype_all type: ETH_P_ALL dev dev func func data data next next
Receiving a Packet • net_rx_action() • The continuous loop is exited when the packet-handling duration exceeds one tick (10ms) or when net_dev_max_backlog packets have been removed.
dev.c, net/sched/* dev_queue_xmit softirq.c, netdevice.h dev->qdisc->enqueue timer_handler netif_schedule Timer cpu_raise_softirq Scheduler NET_TX_SOFTIRQ qdisc_run do_softirq net_tx_action qdisc_restart dev->qdisc->dequeue driver.c dev->hard_start_xmit Sending a Packet
Transmitting a Packet • dev_queue_xmit(skb) • Is used by higher-layer protocol instances to send packets. • Places the skb in the output queue of the network devices by devqdiscenqueue(). • Invokes qdisc_run() to further handle the packet. • qdisc_run(dev) calls qdisc_restart() until there exist no more packets, or until netif_queue_stopped(dev).
Transmitting a Packet • qdisc_restart(dev) attempts to set the lock devxmit_lock. • If successful • Invokes devqdiscdequeue() to request the next packet. • Checks if netif_queue_stopped(dev) is true. • Sends the packet via devhard_start_xmit().
Transmitting a Packet • qdisc_restart(dev) attempts to set the lock devxmit_lock. • If not successful, get the locking CPU in devxmit_lock_owner • If the locking CPU is not the attempting CPU another CPU sends a packet concurrently over the network device. • Placing the skb back to the output queue (devqdiscrequeue()). • Activate NET_TX_SOFTIRQ in netif_schedule() to trigger the transmission process later. • If the locking CPU= the attempting CPU Transmission of an earlier packet was interrupted and the CPU is attempting to transmit another packet. • Drops the packet and returns from qdisc_restart()
Transmitting a Packet • NET_TX_SOFTIRQ can be marked for execution by netif_schedule(). • netif_schedule() is invoked when • A problem occur when a packet was forwarded to the network adapter (e.g., no free buffer space). • The skb has to be delayed to honor certain traffic shaping rule. A timer is set up in this case.
Transmitting a Packet • net_tx_action() • Is the handling routine of NET_TX_SOFTIRQ • Invokes qdisc_restart() to start the transmission.