analizar tramas
DESCRIPTION
Programa en c que analiza tramas enterasTRANSCRIPT
INSTITUTO POLITCNICO NACIONALESCUELA SUPERIOR DE CMPUTO
Redes de Computadoras
Analyzer frames
By:Romero Rubio Gerardo Daniel
Professor: M. en C. NIDIA ASUNCIN CORTEZ DUARTE
Octubre2015
2
IndexContenidoProblem:1Hypothesis:1Software (libraries, packages, tools):1Procedure:1Control Field2HDLC Command/Response Repertoire3Unnumbered Frames4Results (Data):8Conclusions:8References:9Code9
i
Problem:Make a C program that contains a function that receives an information frame and analyses the first 16 bits.Observations:The contents of an HDLC frame are shown in the following table:FlagAddressControlInformationFCSFlag
8 bits8 or more bits8 or 16 bitsVariable length, 0 or more bits16 or 32 bits8 bits
Note that the end flag of one frame may be (but does not have to be) the beginning (start) flag of the next frame.Data is usually sent in multiples of 8 bits, but only some variants require this; others theoretically permitdata alignmentson other than 8-bit boundaries.Hypothesis:Using gates and shift bits analyze each reveived frames, with this a case will be performed to analyze the information frames, not numbered, and sequence which has a special feature to identify that it is in the bit number 16, which discuss in detail with the use of gates and shift bits.Software (libraries, packages, tools):* Dev C*Windows 7Procedure:There are three fundamental types of HDLC frames. Information frames, orI-frames, transport user data from the network layer. In addition they can also include flow and error control information piggybacked on data. Supervisory Frames, orS-frames, are used for flow and error control whenever piggybacking is impossible or inappropriate, such as when a station does not have data to send. S-framesdo nothave information fields. Unnumbered frames, orU-frames, are used for various miscellaneous purposes, including link management. Some U-frames contain an information field, depending on the type.Control FieldThe general format of the control field is:HDLC control fields
76543210
N(R)Receive sequence no.P/FN(S)Send sequence no.0I-frame
N(R)Receive sequence no.P/Ftype01S-frame
typeP/Ftype11U-frame
There are also extended (2-byte) forms of I and S frames. Again, the least significant bit (rightmost in this table) is sent first.
Extended HDLC control fields
1514131211109876543210
N(R)Receive sequence no.P/FN(S)Send sequence no.0Extended I-frame
N(R)Receive sequence no.P/F0000type01Extended S-frame
HDLC Command/Response RepertoireType Of FrameNameCommand/ResponseDescriptionInfoC-Field Format
76543210
Information(I)C/RUser exchange dataN(R)P/FN(S)0
Supervisory (S)Receive Ready (RR)C/RPositive AcknowledgementReady to receive I-frame N(R)N(R)P/F0001
Receive Not Ready (RNR)C/RPositive AcknowledgementNot ready to receiveN(R)P/F0101
Reject (REJ)C/RNegative AcknowledgementRetransmit starting with N(R)N(R)P/F1001
Selective Reject (SREJ)C/RNegative AcknowledgementRetransmit only N(R)N(R)P/F1101
Unnumbered FramesUnnumbered frames are identified by the low two bits being 1. With the P/F flag, that leaves 5 bits as a frame type. Even though fewer than 32 values are in use, some types have different meanings depending on the direction they are sent: as a request or as a response. The relationship between theDISC(disconnect) command and theRD(request disconnect) response seems clear enough, but the reason for makingSARMcommand numerically equal to theDMresponse is obscure.NameCommand/ResponseDescriptionInfoC-Field Format
76543210
Set normal responseSNRMCSet modeUse 3 bit sequence number100P0011
Set normal response extended modeSNRMECSet mode; extendedUse 7 bit sequence number110P1111
Set asynchronous responseSARMCSet modeUse 3 bit sequence number000P1111
Set asynchronous response extended modeSARMECSet mode; extendedUse 7 bit sequence number010P1111
Set asynchronous balanced modeSABMCSet modeUse 3 bit sequence number001P1111
Set asynchronous balanced extended modeSABMECSet mode; extendedUse 7 bit sequence number011P1111
Set initialization modeSIMCInitialize link control function in the addressed station000P0111
DisconnectDISCCTerminate logical link connectionFuture I and S frames returnDM010P0011
Unnumbered AcknowledgmentUARAcknowledge acceptance of one of the set-mode commands.011F0011
Disconnect ModeDMRResponder in Disconnect Modemode set required000F1111
Request DisconnectRDRSolicitation forDISCCommand010F0011
Request Initialization ModeRIMRInitialization neededRequest forSIMcommand000F0111
Unnumbered InformationUIC/RUnacknowledged datahas a payload000P/F0011
Unnumbered PollUPCUsed to solicit control information001P0011
ResetRSETCUsed for recoveryResets N(R) but not N(S)100P1111
Exchange IdentificationXIDC/RUsed to Request/Report capabilities101P/F1111
TestTESTC/RExchange identical information fields for testing111P/F0011
Frame RejectFRMRRReport receipt of unacceptable frame100F0111
Nonreserved 0NR0C/RNot standardizedFor application use000P/F1011
Nonreserved 1NR1C/RNot standardizedFor application use100P/F1011
Nonreserved 2NR2C/RNot standardizedFor application use010P/F1011
Nonreserved 3NR3C/RNot standardizedFor application use110P/F1011
Configure for testCFGRC/RNot part of HDLCWas part of SDLC110P/F0111
BeaconBCNRNot part of HDLCWas part of SDLC111F1111
Results (Data):
Conclusions:* Accept or reject your hypothesis.* EXPLAIN why you accepted or rejected your hypothesis using data from the lab.* Include a summary of the data - averages, highest, lowest..etc to help the reader understand your results. Try not to copy your data here, you should summarize and reference KEY information.* List one thing you learned and describe how it applies to a real-life situation.*Discuss possible errors that could have occurred in the collection of the data (experimental errors)References:1. H.M Deitel/ P.J Deitel. Como programar en C/C++, 19942. Francisco Javier Cevallos. Como programar en C/C++, 1999.3. William Staling. Comunicaciones y Redes de Computadores , 2002.
Code#include #include #include
void analizatrama(unsigned char T[14]){ int t; unsigned char masc; unsigned char c,o,u,k; char UC[][6] ={"UI","SIM","-","SARM","UP","-","-","SABM","DISC","-","-","SARME","-","-","-","SABME","SNRM","-","-","RSET","-","-","-","XID","-","-","-","SNRME","-","-","-","-","-"}; char UR[][6] = {"UI","RIM","-","DM","-","-","-","-","RD","-","-","-","UA","-","-","-","-","FRMR","-","-","-","-","-","XID","-","-","-","-","-","-","-","-","-"}; char supervision[][5]={"RR","RNR","REJ","SREJ"}; //t=((T[12]>1); break; case 2: printf("\n Informacion"); break; case 1: printf("\n Supervision"); c=(T[16]>>2)&3; switch(c){case 0:printf("\n T-S: %s",supervision[0]);break;case 1: printf("\n T-S: %s",supervision[1]);break;case 2:printf("\n T-S: %s",supervision[2]);break;case 3:printf("\n T-S: %s",supervision[3]);break; } printf("\n N(R): %d \n",T[17]>>1); break; case 3: printf("\n No Numerada"); if(((T[16]>>4)&1)==1) if((T[15]&1)==1){ printf("\n %s - F \n",UR[((T[16]>>2)&3)|((T[16]>>3)&28)]); }else{ printf("\n %s - P \n",UC[((T[16]>>2)&3)|((T[16]>>3)&28)]); } break; } } else{ printf("\n-----------------------------"); printf("\n Es Trama Ethernet \n "); } return; }
main(){ unsigned char T1[]={0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x03,0xf0,0xf0, 0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; unsigned char T2[]={0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x03,0xf0,0xf1, 0x73,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; unsigned char Tx[]={0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x08,0x06,0x01,0x1b}; unsigned char T3[]={0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x04,0xf0,0xf0, 0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; unsigned char T4[]={0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x04,0xf0,0xf1, 0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; unsigned char T5[]={0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x12,0xf0,0xf0, 0x00,0x01,0x0e,0x00,0xff,0xef,0x19,0x8f,0xbc,0x05,0x7f,0x00,0x23,0x00,0x7f,0x23}; unsigned char T6[]={0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x12,0xf0,0xf0, 0x00,0x01,0x0e,0x00,0xff,0xef,0x19,0x8f,0xbc,0x05,0x7f,0x00,0x23,0x00,0x7f,0x23}; unsigned char T7[]={0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x04,0xf0,0xf1, 0x01,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; unsigned char T8[]={0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x04,0xf0,0xf1, 0x01,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; unsigned char T9[]={0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0xac,0xf0,0xf0, 0x02,0x02,0x0e,0x00,0xff,0xef,0x16,0x04,0x00,0x00,0x00,0x00,0x28,0x00,0x7f,0x23}; unsigned char T10[]={0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x04,0xf0,0xf1, 0x01,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; unsigned char T11[]={0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x5f,0xf0,0xf0, 0x02,0x04,0x0e,0x00,0xff,0xef,0x16,0x0c,0x00,0x00,0x28,0x00,0x28,0x00,0x7f,0x23}; unsigned char T12[]={0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x04,0xf0,0xf1, 0x01,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; unsigned char T13[]={0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x91,0xf0,0xf0, 0x04,0x04,0x0e,0x00,0xff,0xef,0x16,0x0c,0x00,0x00,0x28,0x00,0x28,0x00,0x7f,0x23}; unsigned char T14[]={0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x04,0xf0,0xf1, 0x01,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; unsigned char T15[]={0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x46,0xf0,0xf0, 0x04,0x06,0x0e,0x00,0xff,0xef,0x16,0x0c,0x00,0x00,0x28,0x00,0x28,0x00,0x7f,0x23}; unsigned char T16[]={0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x04,0xf0,0xf1, 0x01,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; unsigned char T17[]={0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x7e,0xf0,0xf0, 0x06,0x06,0x0e,0x00,0xff,0xef,0x16,0x0c,0x00,0x00,0x28,0x00,0x28,0x00,0x7f,0x23}; unsigned char T18[]={0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x04,0xf0,0xf1, 0x73,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; unsigned char T19[]={0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x04,0xf0,0xf1, 0x01,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; unsigned char T20[]={0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x7e,0xf0,0xf0, 0x08,0x08,0x0e,0x00,0xff,0xef,0x16,0x0c,0x00,0x00,0x28,0x00,0x28,0x00,0x7f,0x23}; unsigned char T21[]={0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x04,0xf0,0xf1, 0x01,0x0a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; unsigned char T22[]={0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x04,0xf0,0xf1, 0x01,0x0a,0x0e,0x00,0xff,0xef,0x19,0x8f,0xbc,0x05,0x7f,0x00,0x23,0x00,0x7f,0x23}; unsigned char T23[]={0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x12,0xf0,0xf0, 0x0a,0x0b,0x0e,0x00,0xff,0xef,0x14,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x7f,0x23}; unsigned char T24[]={0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x04,0xf0,0xf1, 0x01,0x0d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; unsigned char T25[]={0x03,0x00,0x00,0x00,0x00,0x01,0x00,0x04,0xac,0x44,0x4d,0x02,0x00,0x8b,0xf0,0xf0, 0x03,0x2c,0x00,0xff,0xef,0x08,0x00,0x00,0x00,0x00,0x00,0x28,0x00,0x42,0x34,0x20}; unsigned char T26[]={0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x35,0xf0,0xf0, 0x0c,0x0a,0x0e,0x00,0xff,0xef,0x16,0x04,0x00,0x00,0x00,0x00,0x28,0x00,0x7f,0x23}; unsigned char T27[]={0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x35,0xf0,0xf0, 0x0a,0x0e,0x0e,0x00,0xff,0xef,0x16,0x04,0x00,0x00,0x28,0x00,0x28,0x00,0x23,0x7f}; unsigned char T28[]={0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x12,0xf0,0xf0, 0x0e,0x0d,0x0e,0x00,0xff,0xef,0x14,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x7f,0x23}; unsigned char T29[]={0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x04,0xf0,0xf1, 0x01,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; unsigned char T30[]={0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x12,0xf0,0xf0, 0x10,0x0d,0x0e,0x00,0xff,0xef,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x23}; unsigned char T31[]={0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x04,0xf0,0xf1, 0x01,0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; unsigned char T32[]={0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x03,0xf0,0xf0, 0x53,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; unsigned char T33[]={0x00,0x02,0xb3,0x9c,0xdf,0x1b,0x00,0x02,0xb3,0x9c,0xae,0xba,0x00,0x03,0xf0,0xf1, 0x73,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; // analizatrama(Tx); analizatrama(T1); analizatrama(T2); analizatrama(T3); analizatrama(T4); analizatrama(T5); analizatrama(T6); analizatrama(T7); analizatrama(T8); analizatrama(T9); analizatrama(T10); analizatrama(T11); analizatrama(T12); analizatrama(T13); analizatrama(T14); analizatrama(T15); analizatrama(T16); analizatrama(T17); analizatrama(T18); analizatrama(T19); analizatrama(T20); analizatrama(T21); analizatrama(T22); analizatrama(T23); analizatrama(T24); analizatrama(T25); analizatrama(T26); analizatrama(T27); analizatrama(T28); analizatrama(T29); analizatrama(T30); analizatrama(T31); analizatrama(T32); analizatrama(T33); system("pause");}9