100 likes | 474 Views
Chap 3. Network Interface Layer. Objects Passed Between Layers. Conceptual Layer. Application. Messages or Streams. Transport. Transport Protocol Packets. Internet. IP Datagrams. Network Interface. Network-Specific Frames. Hardware.
E N D
Chap 3. Network Interface Layer Objects Passed Between Layers Conceptual Layer Application Messages or Streams Transport Transport Protocol Packets Internet IP Datagrams Network Interface Network-Specific Frames Hardware Figure 3.1 The conceptual organization of TCP/IP protocol software into layers.
Network interface Layer – controls network hardware. – performs mapping from IP addresses to hardware addresses. – encapsulates and transmits outgoing packets. – accepts and demultiplexes incoming packets. S/W in the network interface layer provides a network interface abstraction, which defines the interface between protocol software in the O.S. and the underlying H/W. It hides hardware details and allows protocol software to interface with a variety of network H/W using the some data structures.
Interface structure – Hardware - independent – Consists of an array, nif[ ], with one element for each hardware interface attached to the machine. – Each elements in the interface array are known by their index in the array. – netif.h header file. /* netif.h - NIGET */ #define NI_MAXHWA 14 /* max size of any hardware */ /* (physical) net address */ struct hwa { /* a hardware address */ int ha_len; /* length of this address */ unsigned char ha_addr[NI_MAXHWA]; /* the address */ }; struct netif { /* info about one net interface */ char ni_name[NETNLEN]; /* domain name of interface */ char ni_state; /* interface states: NIS_ above */ IPaddr ni_ip; /* IP address for this interface*/ IPaddr ni_net; /* network IP address */ IPaddr ni_subnet; /* subnetwork IP address */ IPaddr ni_mask; /* IP subnet mask for interface */ IPaddr ni_brc; /* IP broadcast address */ IPaddr ni_nbrc; /* IP net broadcast address */ unsigned int ni_mtu; /* max transfer unit (bytes) */ unsigned int ni_hwtype; /* hardware type (for ARP) */ struct hwa ni_hwa; /* hardware address of interface*/ struct hwa ni_hwb; /* hardware broadcast address */
/* ether.h */ #define EPT_LOOP 0x0060 /* type: Loopback */ #define EPT_ECHO 0x0200 /* type: Echo */ #define EPT_PUP 0x0400 /* type: Xerox PUP */ #define EPT_IP 0x0800 /* type: Internet Protocol */ #define EPT_ARP 0x0806 /* type: ARP */ #define EPT_RARP 0x8035 /* type: Reverse ARP */ struct eh { /* ethernet header */ Eaddr eh_dst; /* destination host address */ Eaddr eh_src; /* source host address */ unsigned short eh_type;/* Ethernet packet type (see below) */ }; struct ep { /* complete structure of Ethernet packet*/ u_long ep_nexthop; /* niput() uses this */ short ep_ifn; /* originating interface number */ short ep_len; /* length of the packet */ short ep_order; /* byte order mask (for debugging) */ struct eh ep_eh; /* the ethernet header */ char ep_data[EP_DLEN]; /* data in the packet */ }; #define ep_dst ep_eh.eh_dst #define ep_src ep_eh.eh_src #define ep_type ep_eh.eh_type 3.3 Ethernet Definitions
Logical state of An Interface (for debug) – Field ni_state provides a mechanism to control the logical state of an interface, indep. of the H/W. network manager can assign ni_state to NS-Down to stop input and output completely., Later, manager can assign ni_state to NS_Up to restart I/O working Internet Network Interface H/W working
Local Host Interface This design uses a pseudo-network interface for higher-level protocol S/W on local machine. – no device driver – no real H/W Datagrams to and from local host Interface between IP and networks Interface for Net 1 Interface for Net n Pseudo-Interface for Local Host Device Driver for Net 1 Device Driver for Net n Operating System Hardware Network 1 hardware Network n hardware Figure 3.2 The pseudo-network interface used for communication with the local host.
Advantages – eliminate special cases (in IP layer), simplying IP code. – allow local machine to be represented in the routing table exactly like other destination. – allow net manger to interrogate local interface as easily as other interfaces.
3.6 Buffer Management • How to reduce the data copy during communication is import for the system performance • Large buffer solution (max IP datagram is 64Kbyte) • in general, we choose each buffer size between 4K and 8K bytes • Linked-list solution • each link (buffer) between 128 and 1 K bytes) • Our example solution • compromise between large buffers and linked list • allocate many network buffers large enough to hold a MTU packet • allocate few buffers large enough to hold large datagrams • use self-identifying buffer scheme provided by OS • getbuf: specify large or small buffer, return buffer point • freebuf: only passing buffer pointer, OS auto to deduce the buffer size • Other buffer issues (DMA) • gather-write • scatter-read
Demultiplexing Incoming Packets /* ni_in.c - ni_in */ int ni_in(struct netif *pni, struct ep *pep, unsigned len) { int rv; pep->ep_ifn = pni - &nif[0]; /* record originating intf # */ pni->ni_ioctets += len; if (!memcmp(pni->ni_hwa.ha_addr, pep->ep_dst, EP_ALEN)) pni->ni_iucast++; else pni->ni_inucast++; switch (pep->ep_type) { case EPT_ARP: rv = arp_in(pni, pep); break; case EPT_RARP: rv = rarp_in(pni, pep); break; case EPT_IP: rv = ip_in(pni, pep); break; default: pni->ni_iunkproto++; freebuf(pep); rv = OK; } return rv; }