Sie sind auf Seite 1von 14

Appendix C

List of Algorithms

Appendix C
Algorithm-1: wait-for-event. Wait-for-event. This is a subroutine responsible for detecting the events and returning the value of the detected event. Theses events are: 1. Frame-arrival. It means that a ne buffer. !. TRT-expired. It means that the T"T counted up to its specified value. #. THT-expired. It means that the T$T counted up to its specified value. %. ACK-expired. It means that the AC& timer counted up to its specified value and no ac'no ledges frame as received. (. AMP-expired. It means that the A)* timer counted up to its specified value. +ub Wait-for-event Loop, if T"T.enabled - false then event - T"T-expired .lse: If mscomm. Com.vent - Com.v"eceive then event - frame-arrival .lse: If T$T.enabled -false and to'en -true then event - T$T-expired .lse: If A)*.enabled - false then event - A)*-expired .lse: frame is available at the receiver

Appendix C

List of Algorithms

If AC&.enabled - false and frame - true then event - AC&-expired .nd if .nd if .nd if .nd if .nd if Algorithm- : To-Ph!-"a!er This procedure receives a frame/ converts its b0tes into s0mbols of % bits/ encodes these s0mbols into ( bits s0mbols using the %1-(1 procedure/ finall0 it puts the encoded frame onto the ring for circulating it till it arrives the destination. to-ph0-la0er 2s as frame / inforleng as integer 3 4im 4ata5 4im a as b0te 4ata5 - cstr 2s.sd13 6 cstr 2s.sd!3 A - b%-b( 2s.fc and 173 4ata5 - data5 6 cstr 2A3 A - b%-b( 2s.fc and !%83 4ata5 - data5 6 cstr 2A3 A - b%-b( 2s.da1 and 173 4ata5 - data5 6 cstr 2A3 A - b%-b( 2s.da1 and !%83 4ata5 - data5 6 cstr 2A3 A - b%-b( 2s.da! and 173

Appendix C

List of Algorithms

4ata5 - data5 6 cstr 2A3 A - b%-b( 2s.da! and !%83 4ata5 - data5 6 cstr 2A3 A - b%-b( 2s.sa1 and 173 4ata5 - data5 6 cstr 2A3 A - b%-b( 2s.sa1 and !%83 4ata5 - data5 6 cstr 2A3 A - b%-b( 2s.sa! and 173 4ata5 - data5 6 cstr 2A3 A - b%-b( 2s.sa! and !%83 4ata5 - data5 6 cstr 2A3 A - b%-b( 2s.LLC.dsap and 173 4ata5 - data5 6 cstr 2A3 A - b%-b( 2s. LLC.dsap and !%83 4ata5 - data5 6 cstr 2A3 A - b%-b( 2s. LLC.ssap and 173 4ata5 - data5 6 cstr 2A3 A - b%-b( 2s. LLC.ssap and !%83 4ata5 - data5 6 cstr 2A3 A - b%-b( 2s. LLC.contro and 173 4ata5 - data5 6 cstr 2A3 A - b%-b( 2s. LLC.control and !%83 4ata5 - data5 6 cstr 2A3 9or I-8 to inforleng A - b%-b( 2s. LLC.data2I3 and 173 4ata5 - data5 6 cstr 2A3 A - b%-b( 2s. LLC.data 2I3 and !%83 4ata5 - data5 6 cstr 2A3 :ext I

Appendix C

List of Algorithms

A - b%-b( 2s. fcs1and 173 4ata5 - data5 6 cstr 2A3 A - b%-b( 2s. fcs1and !%83 4ata5 - data5 6 cstr 2A3 A - b%-b( 2s. fcs! and 173 4ata5 - data5 6 cstr 2A3 A - b%-b( 2s. fcs! and !%83 4ata5 - data5 6 cstr 2A3 4ata5 - data5 6 cstr 2s.ed3 4ata5 - data5 6 cstr 2s.fsa3 4ata5 - data5 6 cstr 2s.fsc3 4ata5 - data5 6 cstr 2s.fse3 )scomm.output - 4ATA5 4ATA5-8 .nd sub Algorithm-#: From-Ph!-"a!er. This procedure fetches an arrived frame from the receiver buffer/ decode it 2i.e. each ( bit s0mbol is converted to its origin % bits replica3 using the (1-%1 procedure/ and reassemble the frame. +ub 9rom-ph0-la0er 23 &1 - mscomm.input arrivedframe.sd1 - '1 &1 - mscomm.input arrivedframe.sd! - '1 '1 - b(-b% 2 mscomm.input3 '! - b(-b% 2 mscomm.input3 arrivedframe.fc - '1 6 '!<17 ; enter a s0mbol of data.

Appendix C

List of Algorithms

'1 - b(-b% 2 mscomm.input3 '! - b(-b% 2 mscomm.input3 arrivedframe.da1 - '1 6 '!<17 '1 - b(-b% 2 mscomm.input3 '! - b(-b% 2 mscomm.input3 arrivedframe.da! - '1 6 '!<17 '1 - b(-b% 2 mscomm.input3 '! - b(-b% 2 mscomm.input3 arrivedframe.sa1 - '1 6 '!<17 '1 - b(-b% 2 mscomm.input3 '! - b(-b% 2 mscomm.input3 arrivedframe.sa! - '1 6 '!<17 '1 - b(-b% 2 mscomm.input3 '! - b(-b% 2 mscomm.input3 arrivedframe.LLC.dsap - '1 6 '!<17 '1 - b(-b% 2 mscomm.input3 '! - b(-b% 2 mscomm.input3 arrivedframe.LLC.ssap - '1 6 '!<17 '1 - b(-b% 2 mscomm.input3 '! - b(-b% 2 mscomm.input3 arrivedframe.LLC.control - '1 6 '!<17 n-8 Loop1 '1 - b(-b% 2mscomm.input3 If '1 - 1# then r.ed - '1: =oto Loop# .ndif '! - b(-b% 2 mscomm.input3 arrivedframe.LLC.data 2n3 - '1 6 '!<17 n-n61

Appendix C

List of Algorithms

=oto Loop1 Loop! r.ed - mscomm.input Loop# mscomm.inputlen -1 arrivedframe. fsa - mscomm.input arrivedframe. fsc - mscomm.input arrivedframe. fse - mscomm.input )scomm.inputlen - ! .nd sub Algorithm-$: Prepare-MAC-Frame This procedure assembles a )AC control frame of a t0pe specified b0 the t0pe variable as an argument. *repare-)AC-frame 2t0pe as string3 s.sd1 - sd1 s.sd!-sd! +elect case t0pe Case to'en s.fc -1!> Case claim s.fc -?( Case *"= s.fc -?> Case +)* s.fc -?, Case A)* s.fc - ?? Case 4AT s.fc - ?7 ; enter t o s0mbols each time. ; enter one s0mbol each time.

Appendix C

List of Algorithms

.nd select If t0pe - claim then s.da1- una1 s.da!- una! =oto Loop( end if s.da1- 1 s.da!- 1 Loop( s.sa1- sa1 s.sa!- sa! s.ed - ed s.fsa - , s.fsc - , s.fse - , .nd sub Algorithm %&:CRC-'enerator. This procedure calculates the value of the frame chec' sum of the frame s and put this value in s.fsc1 and s.fsc! fields. crc-gen 2 s23 as b0te/ length as integer 3 4im crcarr 2173 as integer 4im dat as integer 4im C as b0te 4im Crc1 as b0te/ Crc! as b0te 9or I-8 to 17 Crcarr 2I3 -8 :ext I 9or I-8 to length C - s 2I3

Appendix C

List of Algorithms

9or @-8 to , If c and 2Ah13 -1 then 4at -1 .lse: dat -8 .nd if Call shift-right 2dat/ crcarr3 C-C mode ! :ext @ :ext i Crc1-Crc!-8 9or I-8 to , Crc1-Crc16 crcarr 2I3 < !B I Crc!-Crc!6 crcarr 2I6,3 < !B I :ext I .nd sub Algorithm-(: )AT-Re*pon*e. This procedure is called hen a 4AT )AC control frame is received. It chec's eather this frame is sent b0 this station or b0 another one through monitoring the value of frame-status. 4AT/ and ta'es the suitable action. +ub 4AT-response 2frame-sataus. 4AT as 1oolean/ arrivedframe as dataframe3 +elect case frame-sataus. 4AT Case true Chec'-address-status 2arrivedframe3 If status -true then ;the station sent 4AT frame previosl0

Appendix C

List of Algorithms

*repare-)AC-frame 2+)*3 To-ph0-la0er 2ss3

;send a +)* )AC frame

.lse: print Cthe source address is used b0 another stationD: Call b0pass-satate .nd if Case false If arrivedframe.sa - sa then +et-frame-address-status 2arrivedframe3 .nd if To-ph0-la0er 2arrivedframe3 .nd select Algorithm-+: ,MP-Re*pon*e This procedure is activated in response to detection of arrival of an +)* frame. It chec's eather this frame is sent b0 this station or b0 another one through monitoring the value of frame-status. +)*/ and ta'es the suitable action. +)*-response 2framestatus. +)* as 1oolean/ arrivedframe as dataframe3 +elect case framestatus. +)* Case true If arrivedframe.fsa - , and arrivedframe.fsc - , then Epdate-E:A 2arrivedframe3 neighbor address .lse: .nd if Case false if arrivedframe.fsa - , then Epdate-E:A 2arrivedframe3 ;this frame is sent b0 another station ;update the upstream ;the 4AT frame is sent b0 another station

Appendix C

List of Algorithms

10

set-frame-status 2arrivedframe3 to-ph0-la0er 2arrivedframe3 prepare-)AC-frame 2+)*3 to-ph0-la0er 2s3 .lse To-ph0-la0er 2arrivedframe3 .nd if .nd select .nd sub Algorithm--: AMP-Re*pon*e. This procedure is called in response to arrival of an A)* frame. It chec's eather this frame is sent b0 this station or b0 another one through monitoring the value of frame-status. A)*/ and ta'es the suitable action. A)*-response 2framestatus. A)* as 1oolean/ r as dataframe3 +elect case framestatus. A)* Case true If arrivedframe .sa - sa then If arrivedframe.fsa -, and r.fsc - , then *repare-)AC-frame 2A)*3 To-ph0-la0er 2s3 .lse: *repare-)AC-frame 2to'en3 To-ph0-la0er2s3 .nd if .nd if Case false If r.fsa - , and r.fsc - , then

Appendix C

List of Algorithms

11

Epdate-E:A 2arrivedframe3 *repare-)AC-frame 2+)*3 To-ph0-la0er2s3 .lse: "estart-timer 2A)*3 To-ph0-la0er 2arrivedframe3 .nd if .nd select .nd sub Algorithm-.: PR'-Re*pon*e. This procedure is called in response to arrival of a *"= frame. It chec's eather this frame is sent b0 this station or b0 another one through monitoring the value of frame-status. *"=/ and ta'es the suitable action. *"=-response 2framestatus. *"= as 1oolean/ arrivedframe as dataframe3 +elect case framestatus. *"= Case true If r.sa - sa then *repare-)AC-frame 2A)*3 To-ph0-la0er 2s3 .nd if Case false To-ph0-la0er 2arrivedframe3 Call idle-state .nd select Algorithm-1/: CT-Re*pon*e.

Appendix C

List of Algorithms

12

This procedure is activated in response to arrival of a CT )AC frame. It chec's the framestatus. CT to ma'e a correct response to this frame. CT-response 2framestatus. CT as 1oolean/ arrivedframe as dataframe3 +elect case framestatus. CT Case true If arrivedframe.sa - sa and arrivedframe.da - E:A then :e -active-monitor .lse: +tandb0-state ; .nd if Case false +elect case activemonitor ; Case true arrivedframe.sa - sa arrivedframe.da - E:A to-ph0-la0er 2arrivedframe3 Case false to-ph0-la0er 2arrivedframe3 .nd select .nd select .nd sub ; the station is not an active monitor ; the station chec's eather it is the present active monitor ;the station is the present active monitor ;there is some error and the station onl0 monitor passing of periodic frame. ;this station is being the active monitor

Algorithm-11: ,tart-Timer. This procedure activated the timer name. hich is specified b0 the argument

Appendix C

List of Algorithms

13

+ub +tart-timer 2:ame as string3 :ame.enabled -true .nd sub Algorithm %1 : ,top-Timer. This procedure is called henever it is reFuired to turn a timer off. The timer is specified b0 the argument name. +top-timer 2name as string3 :ame.enabled - false .nd sub Algorithm %1#: re*tart-timer This procedure activated henever it is reFuired to restart the timer hich is specified b0 the argument name. +ub "estart-timer 2name as string3 If :ame.enabled - false then :ame.enabled -true .lse: :ame.enabled - false :ame.enabled -true .nd if .nd sub Algorithm-1$: 0!pa**-,tate. In this state the station or's onl0 as a repeater. It @ust retransmit the incoming data ithout an0 proceesing. +top-timer 2T"T3 +top-timer 2T$T3

Appendix C

List of Algorithms

14

+top-timer 2A)*3 +top-timer 2AC&3 mscomm.inputLen - 1 mscomm.inputThreshold - 1 Loop aite-for-event 2nevent3 If nevent - frame-arrival then mscomm.output - mscomm.input =oto loop .nd sub

Das könnte Ihnen auch gefallen