Network protocol and network software frame design
Network protocol
TCP / IP (Network Control Protocol and Internet Protocol)
The correspondence diagram of the protocol in the OSI and UNIX system, and the location of different networks in OSI
OSI Open System Interconnection Reference Model UNIX System
Application ------> ------> ------> ------> ------> NetWork Network File System (NFS) Representation ( Conference layer (session) SNMPFTPSMTPTELNET .. Transport TCP UDP Network Layer (Network)
ICMP, IGMP, RIP IP
ARP Data Link LAN Drive LLC ---------------------- Media Access Control Mac CSMA / CD (Carrier Listening / Multi-Road Access ) Switching Winnt (NDIS) IEEE802.3 Ethernet MacFDDi DMAC Network Interface Card Drive Physical Physical Layer in Multiple NIC Drivers
Link TCP / IP foundation
MAC layer interface of ordinary network card
NIC internal bus
<========>
802.3 Mac Engine (ENGINE)
<====>
Codon / Decoder (Encoder / Decoder) & PLL
<========>
10/100 Base-T Network & Aui
||
LED logic display
Receipt process
The MAC receives the packet from the decoder / decoder, first check the SFD, after the check is completed, the MAC believes that all bits behind the SFD are frame data bits. Read destination address DA, compare it and the address is compared If DA passes the address filter layer, this frame will be placed in the storage space of the NIC. After the entire receipt is completed, the MAC checks the validity of the FCS.
Ethernet Frame Format
101010 ... SFD destination address DA source address SALENGTH FIELDLLC DataPadFCS can up to 7 bytes 1 byte 6 byte 6 byte 2 byte 4-byte frame guide header length about 64 bytes --- --1500 bytes <======== Transport direction
SFD = START OF FRAME DELIMITEDA = DESTINATION Addresssa = Source Addressllc = Logical Link ControlFCS = Frame Check Sequence Or Cyclic Redundancy Check (CRC)
SNMP (Simple Network Management Protocol SIMPLE NetWork Management Protocol)
SNMP
Used to manage network devices and get peripheral information, part of TCP / IP, with protocol independence. Using SNMP, a management station can remotely manage all network devices that support this protocol, including monitoring network status, modify network device configuration , Receive network event warnings, etc.
Management Information Library (MIB):
Two types of MIB-1, MIB-2.MIB are a tree structure, and the SNMP protocol message accesses devices in the network by traversing node (OID) in the MIB tree directory.
Each node of the MIB tree is designated as a number (non-negative), the node of the same layer is distinguished by different numbers. These node numbers are specified by the standard organization. Any of the nodes in the MIB tree are named. Because the nodes of the same layer are different, the route reaching a node can be represented by a numeric string from the node passed from the tree root to this node. This digital string is called the object identifier (OID) of the corresponding MIB object.
For example, ODI, 1.3.6.1.2.1.1 The object represented by the root node named "1", the subsequent subsequent subsequent node "3", then the next level is "6", and this type is pushed. Management information structure Identification (SMI): Defines Technical Specifications for MiB Middle Bank.
SNMP currently has two versions of SNMP V1 and SNMP V2.
The SNMP Protocol unit (PDU) implements communication between the agent and management station, and the communication of Server and Targets.
Communication type
Type PDU Type Transfer Direction Description 0getRequestServer ---> Target Used to get one or more SNMPs (OID) values from Target 1GetNextRequestServer ---> Target to get the next SNMP object (OID) in the MIB on the target Value 2GetResponseTarget ----> ServerTarget Response ServerSNMP Object Request 3SetRequestServer ---> TargetServer on the OID assignment 4traptarget in TargetMib ----> ServerTarget with it to notify Server has a specific time occurred
The current SNMP network management software is HP's OpenView.
BSD socket (BSD sockets)
BSD sockets use the most widely used network program programming method, mainly for application writing, used for mutual communication between hosts and hosts on the network.
Allix, Linux, VxWorks support BSD Sockets, WINSOCK for Windows is basically from BSD Sockets
Socket is divided into Stream Sockets and Data Sockets.
Stream sockets is a two-way data transmission of reliability TCP, such as HTTP, FTP, etc.
Data Sockets is unreliable to connect with UDP, such as multipart, DHCP, SNMP, RIP, etc.
Process of the TCP server and a TCP client communication
Server client
Create a socket sfd = socket (AF_INET, SOCK_STREAM, 0) Bind the socket and the IP, TCP port of this machine (SFD, STRUCKADDR *) & ServerAddr, SockAddrSize to create a waiting queue LISTEN (SFD, Server_MAX_CONNACTIONS) The cycle is waiting, if a client connection request is received, accept the client connection requires Accept (SFD, STRUCKADDR *) & ClientDr, & SockAddrSize) Accept the information sent by the client FioEad (SFD, (Char *) & ClientRequest, Sizeof (ClientRequest ))) Write (SFD, Replymsg, SIZEOF (Replymsg)) Close Socket, terminating close (sfd) two light blue functions is two Sockets handshake functions, that is, establish a connection here.
Create a socket sfd = socket (AF_INET, SOCK_STREAM, 0) Note: The client does not need to be bound because the TCP port is dynamic. Send a connection request to the server side, and wait for the response here, if you receive the response, execute down After Connect (SFD, SockAddr *) & ServerAddr, SockAddrSize, after accepting connection request, read (SFD, Buffer, 20) sent to the server Write (SFD, Buffer, 20); Close Sockets Close (SFD, Buffer, 20); SFD)
UDP server and a program process of UDP client communication
Server client
Create a socket sfd = socket (AF_INET, SOCK_DGRAM, 0) Bind the socket and the IP, TCP port of this machine (SFD, (Struct SockAddr *) & ServerAddr, SockAddrsize, does not need to create a wait queue here loop waiting, if available Connection accepts and read the information sent by the customer Recvfrom (SFD, (CLIENTREQUEST), 0, (Struct Sockaddr *) & Clientaddr, & SockAddr *) Close Socket, and communication termination close (SFD) is not built Connection, just data delivery <---------- Create a socket sfd = socket (AF_INET, SOCK_DGRAM, 0) Note: The client does not need to be bound because the UCP port is dynamic. Send a connection to the server side Requests and information, not waiting for the server's response Sendto (SFD, (Caddr_t) & MyRequest, SizeOf (MyRequest), 0, (Struct Sockaddr *) & ServerAddr, SockAddrSize Close Sockets Close (SFD)
UDP broadcast package program
Send a UDP broadcast package to find IP information for all running SNMP service devices in the local network. Winsock, Win32 console procedure.
#define SNMP_PORT 161void SearchIP_In_LAN () {WSADATA wsaData; SOCKET sockListener; SOCKADDR_IN saUdpCli, saUdpServ; BOOL fBroadcast = TRUE; char sendBuff [40] = // SNMP query packet content { '/ x30', '/ x26', '/ x02 ',' / x01 ',' / x00 ',' / x04 ',' / x06 ',' / x70 ',' / x75 ',' / x62 ',' / x6c ',' / x69 ',' / x63 ',' / xa0 ',' / x19, '/ x02', '/ x02', '/ x01', '/ x00', '/ x02', '/ x01 ',' / x00 ',' / x30 ',' / x0e ',' / x06, '/ x08', '/ x2b', '/ x06', '/ x01 ',' / x02 ',' / x01 ',' / x00 ',' / x05 ',' / x00 '}; char recvBuff [600]; int nsize, err, timeoutnum = 1 ;; ulong hostddr; int RV; int ncount = 0; IF (WSAStartup (MakeWord (2, 2), & WSADATA)! = 0) {Printf ("Winsocket Start Error! / N"); return;} socklistener = socket (AF_INET, SOCK_DGRAM, 0); err = setsockopt (sockListener, SOL_SOCKET, SO_BROADCAST, (CHAR *) & fBroadcast, sizeof (BOOL)); if (SOCKET_ERROR == err) return; int TimeOut = 10000; err = setsockopt (sockListener , SOL_Socket, SO_RCVTIMEO, (CHAR *) & Timeout, SizeOf (Timeout)); if (socket_error == Err) Return; SaudpCli.sin_Family = AF_INET; SaudpCli.sin_p Ort = htons (0); SaudpCli.sin_addr.s_addr = htonl (INADDR_Any); if (Bind (SockListener, (SockAddr *) & SaudpCli, Sizeof (SockAddr_in))! = 0) {Printf ("can't Bind Socket To LOCAL Port! program stop./n" "return;} err = gethostname (Recvbuff, sizeof (recvbuff)); if (socket_error == err) return; struct hostent * hp =
gethostbyname (recvBuff); if (! hp) return; saUdpServ.sin_family = AF_INET; memcpy (& (saUdpServ.sin_addr), hp-> h_addr, hp-> h_length); HostIpAddr = ntohl (saUdpServ.sin_addr.s_addr); saUdpServ .sin_addr.s_addr = htonl (INADDR_BROADCAST); saUdpServ.sin_port = htons (SNMP_PORT); nSize = sizeof (SOCKADDR_IN); if ((rv = sendto (sockListener, sendBuff, sizeof (sendBuff), 0, (SOCKADDR *) & saUdpServ, SIZEOF (SOCKADDR_IN)) == SOCKET_ERROR) {Printf ("Send Error! / N"); CloseSocket (* ((socket *) socklistener); return;} Printf ("Send Successful! / N"); do / / waiting to receive {if ((rv = recvfrom (sockListener, recvBuff, sizeof (recvBuff), 0, (SOCKADDR *) & saUdpCli, & nSize)) == SOCKET_ERROR) {if (WSAGetLastError () == WSAETIMEDOUT) {if (timeoutnum > 6) // Wait for 1 minute.break; elsetimeoutnum ;}} else {cstract IP (inet_ntoa (saudpcli.sin_addr)); Printf ("/ T IP adject->% s", IP);}} while (TRUE ); CloseSocket (* (socket *) socklistener); returnographic;} Network software design block diagram (personal understanding, for reference only)
Equipment management service software architecture
PC (Windows NT, UNIX, NOVELL ... Platform) Management Server (HTTP, FTP ... Server) server program program receives user requests, send down the reception processing result, sent to users
||| V ^ |||
Communication method: Socket, NamedPipe, etc.
||||||
Backstage core program processing request, receive send data SNMP customers
<==============> Internet (http, .. protocol), such as the user's PC missing the corresponding drive, the server dynamically loads the User PC to install the Internet (SNMP protocol) <====== =======>
Terminal PC users (IE browser ...)
Network Equipment (Embedded Operating System) SNMP Server
Information Home Appliance (IA) architecture
Network Equipment (Embedded Operating System Platform) Embedded Server (Embedded Web Server, HTTP, FTP ...) server program receiving user request, sending downward reception processing results, sending it to user
||| V ^ |||
Communication method: Socket, NamedPipe, etc.
||||||
Backstage core program processing request, receive transmission data || Embedded system SNMP interface || Equipment SNMP (MIB)
<===========> Internet (http, .. protocol) terminal PC users (IE browser ...)
Wireless mobile communication architecture
Base station wireless transmission receiving device (wireless communication protocol) Receive End Processing software program receives processing data packet header, substantially complies with an INTERNET transmission, such as X.25), put it on the Internet to receive data packets, plus itself wireless The header of the communication protocol, wirelessly sent to the user terminal
||||
Communication method: Internet (two-way) X.25, ATM ... and other protocols
||||
Gateway handles the content of the packet, the relevant content reads the storage database
||||
database
||||
HTTP protocol to operate, add, delete, print ... Terminal PC (IE browser)
<============> Wireless communication protocol (Mobitex or Datatac, .. protocol)
Mobile communication device (embedded operating system)