03 March, 2015

Lect-15 (Socket Option)

Socket Option
Three ways to get and set the socket option that affect a socket
getsockopt , setsockopt function=>IPv4 and IPv6 multicasting options
fcntl function =>nonblocking I/O, signal driven I/O
ioctl function

getsockopt and setsockopt:
#include
int getsockopt(int sockfd, , int level, int optname, void *optval, socklent_t *optlen);
int setsockopt(int sockfd, int level , int optname, const void *optval, socklent_t  optlen);
sockfd => open socket descriptor
level => code in the system to interprete the option(generic, IPv4, IPv6, TCP)
optval => pointer to a variable from which the new value of option is fetched   by setsockopt, or into which the current value of the option is stored
                  by setsockopt.
optlen => the size of the option variable.

Generic socket option: level -> SO

SO_BROCAST =>enable or disable the ability of the process to send broadcast message

SO_DEBUG =>kernel keep track of detailed information about all packets sent or received by TCP(only supported by TCP)

SO_DONTROUTE=>outgoing packets are to bypass the normal routing mechanisms of the underlying protocol.

SO_ERROR=>when error occurs on a socket, the protocol module in a Berkeley-derived kernel sets a variable named so_error for that socket. Process can obtain the value of so_error by fetching the SO_ERROR socket option

SO_KEEPALIVE=>wait 2hours, and then TCP automatically sends a keepalive probe to the peer. Peer response: ACK(everything OK)
RST(peer crashed and rebooted):ECONNRESET
no response:ETIMEOUT =>socket closed

SO_LINGER =>specify how the close function operates for a connection-oriented protocol(default:close returns immediately)

SO_RCVBUF , SO_SNDBUF
let us change the default send-buffer, receive-buffer size. Default TCP send and receive buffer size :
4096bytes 8192-61440 bytes. Default UDP buffer size : 9000bytes, 40000 bytes

SO_RCVBUF option must be setting before connection established.

SO_TYPE: Return the socket type.
Returned value is such as SOCK_STREAM, SOCK_DGRAM...

IPV4 Socket Options: Level -> IPPROTO_IP

IP_HDRINCL => If this option is set for a raw IP socket, we must build our IP header for all the datagrams that we send on the raw socket.

IP_OPTIONS=>allows us to set IP option in IPv4 header.

IP_RECVDSTADDR=>This socket option causes the destination IP address of a received UDP datagram to be returned as ancillary data by recvmsg.

IP_RECVIF: Cause the index of the interface on which a UDP datagram is received to be returned as ancillary data by recvmsg.

IP_TOS: lets us set the type-of-service(TOS) field in IP header for a TCP or UDP socket.
If we call getsockopt for this option, the current value that would be placed into the TOS(type of service) field in the IP header is returned.

IP_TTL: We can set and fetch the default TTL.

IPV6 Socket Option:
This socket option is processed by IPv6 and have a level of IPPROTO_IPV6.

IPV6_ADDRFORM=>allow a socket to be converted from IPv4 to IPv6 or vice versa.(chapter 10)

IPV6_CHECKSUM=>specifies the byte offset into the user data of where the checksum field is located.

IPV6_DSTOPTS: Specifies that any received IPv6 destination options are to be returned as ancillary data by recvmsg.

IPV6_HOPLIMIT: Setting this option specifies that the received hop limit field be returned as ancillary data by recvmsg.

IPV6_HOPOPTS: Setting this option specifies that any received IPv6 hop-by-hop option are to be returned as ancillary data by recvmsg.

IPV6_NEXTHOP: This is not a socket option but the type of an ancillary data object that can be specified to sendmsg. This object specifies the next-hop address for a datagram as a socket address structure.


TCP Socket Options:
There are five socket option for TCP, but three are new with Posix.1g and not widely supported.
Specify the level as IPPROTO_TCP.

TCP_KEEPALIVE: It specifies the idle time in second for the connection before TCP starts sending keepalive probe. Default 2hours. this option is effective only when the SO_KEEPALIVE socket option enabled.

TCP_MAXRT: It specifies the amount of time in seconds before a connection is broken once TCP starts retransmitting data. 0 : use default , -1:retransmit forever, positive value :rounded up to next transmission time

TCP_MAXSEG:  This allows us to fetch or set the maximum segment size(MSS) for TCP connection.

TCP_NODELAY: This option disables TCP’s Nagle algorithm. (default this algorithm enabled). Purpose of the Nagle algorithm: prevent a connection from having multiple small packets outstanding at any time.


Lect-14 (Protocols)

Xerox Network Services (XNS)
Xerox Network Services (XNS) is a computer networking protocol suite developed by Xerox within the Xerox Network Systems Architecture. It provided general purpose network communications, internetwork routing and packet delivery, and higher level functions such as a reliable stream, and remote procedure calls. XNS predated and influenced the development of the Open Systems Interconnection (OSI) networking model, and was very influential in local area networking designs.
Xerox used XNS for file transfers, sharing network resources, packet transfers, sharing routing information and remote procedure calls. Its basic working mechanism is almost the same as in the TCP/IP protocol suit, but XNS contains only two network layers. This differs from the seven-layer Open Systems Interconnection (OSI) model, although the functionality is basically the same.
XNS was a public domain technology and therefore became one of the most commonly used networking technologies through 1980s. It was replaced by the Internet Protocol suite.

XNS contains two major layers, a network layer and a transport layer. The network layer provides the packet-carrying service and logical addressing. XNS was developed for many purposes, such as office applications, transmissions, communication media and processors. There is an echo protocol inside the XNS suite, which works as a door knocker, checking the connectivity between the two systems. This is similar to ping in IP systems.

XNS Architectures


XNS Basic Protocol

Internet Datagram Protocol (IDP)

The Internet Datagram Protocol (IDP) delivers a single frame as an independent entity to an Internet address, irrespective of other packets or addressee responses. XNS generally limits the IDP packets to a maximum size of 576 bytes, excluding the data link header.
The following parameters are available for IDP:
Destination network: Four-byte address of the destination network.
Destination socket: Two-byte socket number of the destination port.
Source network: Four-byte address of the source network.
Source socket: Two-byte socket number of the source port.
Hop count: Indicates the number of routers encountered during transport of the packet. Each router handling a packet increments the hop count by one. When the hop count reaches 16, this protocol discards the packet.

Routing Information Protocol (RIP)
XNS uses the Routing Information Protocol (RIP) to maintain a database of network hosts and exchange information about the topology of the network. Each router maintains a list of all networks known to that router along with the routing cost in hops required to reach each network. XNS distributes routing information on the network by routers broadcasting their routing tables every 30 seconds. This protocol sends routing tables as a result of changes in service or topology or in response to a request for routing information.
XNS generally uses the Echo protocol to demonstrate the existence and accessibility of another host on the network, while using the Error protocol to signal routing errors.

Packet Exchange Protocol (PEP)
The Packet Exchange Protocol (PEP) provides a semi-reliable packet delivery service that orients toward single-packet exchanges.
The following parameters are available for PEP:
Packet ID: A unique number used to identify responses as belonging to a particular request. The sending host sets the packet ID field to a fixed value, then looks for PEP responses containing the same packet ID value.
Client type: A registered code used to identify the particular application in use.

Sequenced Packet Protocol (SPP)
The Sequenced Packet Protocol (SPP) provides reliable transport delivery with flow control.
The following parameters are available for SPP:
Source connection ID: Reference number used to identify the source end of a transport connection. This protocol establishes Connection IDs at connect time to distinguish between multiple transport connections.
Destination connection ID: Reference number used to identify the target end of a transport connection.
Sequence number: Sequence number of the packet. Each successive packet transmitted and acknowledged on the transport connection must have a sequence number one higher than the previous sequence number.
Acknowledge number: Sequence number of the last packet that the protocol received properly. Each side of the transport connection uses its own sequence of numbers for transmitted packets, resulting in sequence and acknowledge numbers in the same packet generally being out of phase with each other.

XNS Addresses
An XNS address occupies 12 bytes and is comprised of three parts:
A 32-bit network ID
A 48-bit host ID
A 16-bit port number
The host ID is an absolute number that must be unique to all XNS Internets. The AIX implementation uses the 48-bit Ethernet address as host ID. With unique host IDs, the network ID is redundant but is required for routing purposes.
XNS addresses can be represented by several means, as can be seen in the following examples:
123#9.89.3c.90.45.56
5-124#123-456-900-455-749
0x45:0x9893c9045569:90
0456:9893c9045569H
The first example is in decimal format, and the second example, using - (minus signs), is separated into groups of three digits each. The 0x and H examples are in hex format. Finally, the 0 in front of the last example indicates that the number preceding the colon is in octal format.

System Network Architecture
SNA was developed in the 1970s with an overall structure that parallels the OSI reference model. With SNA, a mainframe running Advanced Communication Facility/Virtual Telecommunication Access Method (ACF/VTAM) serves as the hub of an SNA network. ACF/VTAM is responsible for establishing all sessions and for activating and deactivating resources. In this environment, resources are explicitly predefined, thereby eliminating the requirement for broadcast traffic and minimizing header overhead. The underlying architecture and key components of traditional.
It is a complete protocol stack for interconnecting computers and their resources. SNA describes formats and protocols and is, in itself, not a piece of software. The implementation of SNA takes the form of various communications packages, most notably Virtual Telecommunications Access Method (VTAM), the mainframe software package for SNA communications.
Systems Network Architecture (SNA) is IBM's proprietary networking architecture, created in 1974. It is a complete protocol stack for interconnecting computers and their resources. SNA describes formats and protocols and is, in itself, not a piece of software. The implementation of SNA takes the form of various communications packages, mostly Virtual Telecommunications Access Method (VTAM), the mainframe software package for SNA communications.

IBM SNA Architecture


IBM SNA-model components map closely to the OSI reference model. The descriptions that follow outline the role of each SNA component in providing connectivity among SNA entities.

Data-link control (DLC)---Defines several protocols, including the Synchronous Data Link Control (SDLC) protocol for hierarchical communication, and the Token Ring Network communication protocol for LAN communication between peers

Path control---Performs many OSI network-layer functions, including routing and datagram segmentation and reassembly (SAR)

Transmission control---Provides a reliable end-to-end connection service, as well as encrypting and decrypting services

Data flow control---Manages request and response processing, determines whose turn it is to communicate, groups messages together, and interrupts data flow on request

Presentation services---Specifies data-transformation algorithms that translate data from one format to another, coordinate resource sharing, and synchronize transaction operations

Transaction services---Provides application services in the form of programs that implement distributed processing or management services


Elements of SNA

Network Control Program (NCP):  It is a packet forwarding protocol, acting like modern switch - forwarding data packages to the next node, which might be a mainframe, a terminal or another 3705.  It is a multiplexer that connected multiple terminals into one communication line to the CPU, thus relieved the constraints on the maximum number of communication lines per CPU.

Synchronous Data Link Control (SDLC): It is a protocol which greatly improved the efficiency of data transfer over a single link
SDLC included much more powerful error detection and correction codes. These codes often enabled the communications cards to correct minor transmission errors without requesting re-transmission, and therefore made it possible to pump data down a line much faster.

Virtual Telecommunication Access Method (VTAM): VTAM, a software package to provide log-in, session keeping and routing services within the mainframe. A terminal user would log-in via VTAM to a specific application or application environment (e.g. CICS or TSO). A VTAM device would then route data from that terminal to the appropriate application or application environment until the user logged out and possibly logged into another application. The original versions of IBM hardware could only keep one session per terminal. In the 1980s further software (mainly from third-party vendors) made it possible for a terminal to have simultaneous sessions with different applications or application environments.