question has been provided. you are making a C++ program that is stated in the addition information and using the two psudocode examples provided.
B. Simulation Part (80%) 1) Carefully read the background and the additional details sections provided below. 2) Set the system by hard-coding the time limit, and the relevant inputs (marked with yellow highlights), e.g., via trial and error, so that each station is performing numerous message transmission attempts. 3) Include only three stations, S₁, S₂, and S3, simulation. 4) Implement only the part that generates messages. In other words, you only have to implement the CSMA part, you do not have to implement the CD part (marked with a line-through text). 5) Produce the C++ code for the pseudo code Included in the background section. 6) Deliverables: i) program code and collaterals (e.g., .h files), ii) a CSV file that records the time (tick), source, and destination of each message generated, iii) execution screenshot.
Additional Details. Initial system definitions: • The length of the cable is M distance units (M is an odd parameter of your choice). • There are N stations for now N = 3. So, three stations S₁ to S3. •S, and S, are on the two ends of the cable, S, is in the middle. A message propagates at a rate of one distance unit per tick. . At each time-tick, with a probability of p=0.1, an idle station S, might initiate a message of length K ticks (K is a random number between 1 and 3) to another station S; (j is selected randomly). • At any time-tick, each station is sensing the carrier, it can only sense the distance unit of its location. Prior to sending a message to station "B,' Station 'A' senses the carrier. . If the carrier is free, then 'A' starts transmitting the message. . If the carrier is busy, then 'A' stops sensing and randomly selects one of the next T ticks (T is a random number between 1 and 4) for CS. .On collision, the message gets distorted. .On collision the initiating stations stop the transmission and delays the attempt for retransmission (CS) by a random amount of tieks: . For this assignment, we will assume that the 'A' delays the next transmission of the collided message (i.e., the next CS) by P ticks, where 'l' is a random number in the range [1,..., R] .The simulation program checks for termination condition (a relatively large number of ticks) • The program evaluates and records (in a CVS file) statistics including The number of messages initiated and the number of successful transmissions.
Background The CSMA/CD Protocol Carrier Sense, Multiple Access with Collision Detection For example, the ethernet IEEE 802.3 (a Medium Access Layer protocol) is a special case of CSMACD (802.13 is a CSMA/CD based protocol for mobile connection) •The Carrier is a cable, and each station is connected to the cable. • Each station can get all the data that goes through the carrier. • Propagation time (latency) - Echo - when a message reaches a cable end the message echo starts to propagate back on the cable → a message got distorted (e.g., due to collision) - Ignore for now .CS - Carrier sense a station can "sense" the carrier and notice that there is a communication session between other station at the time of sense. • MA - Multiple Access - many (all) stations can access the cable at any given time. .CD-collision detection - Several stations and in specific the source of a message can identify collision (echo is different from the original message). Hence, methods for reducing collisions, avoiding collision, and resolving collisions are needed. Issues: In CS, if A wants to send a message to B but notices that C is currently sending a message to D. A "sleep" for an arbitrary amount of time and then senses the carrier again. How often? How many times? In CD, If A sends a message to B and C is currently sending a message to D. The two messages might collide, and collision might be detected. What should A and C do? Retry later (random amount of time) How to avoid repeated collision? Solution, each station waits for an arbitrary amount of time, then, go back to CS and then retransmit.
The P-Persistent Carrier Sense, Multiple Access with Collision Detection Protocol (CSMA/CD) It is assumed that several stations are connected to, and can communicate with each other, via a single carrier (this is a part of the MA). In this protocol, time is discretized and an atomic time unit is referred to as a tick. Each of the stations might attempt to initiate a communication session with another station connected to the carrier. Every station can get any message that is going through the carrier at any given time. Prior to sending a message, the station "senses" the carrier to determine if it is busy. If the carrier is busy, the station refrains from sending the message according to the CS part of the protocol. Nevertheless, due to propagation delays, despite the sensing, collisions might still occur. Pseudo Code for the Time-Based Simulation Initiate system definitions and status "Infinite" loop on ticks { Check system status For every Station For the carrier Update system status // Most likely using some probability distribution function Gather and record Data Produce output into a CSV file Check for termination condition Analyze / visualize system status data } Evaluate visualize statistics
Pseudo Random Number Generator Using C++ rand(), srand() - Generates a seed Consecutive calls to rand() generates pseudo random integers Often the Integers are between [0-224] [0- RAND_MAX] (float) rand()/RAND_MAX random numbers in [0.. 1] rand() / modulus 5 (rand() %5) → Pseudo random integers between 0 and 4. To get a probability of 0.1 R = (float) rand() / RAND_MAX ->> [0.0 -1.0] If R is in [0.0, 0.1] then the events occur This means "if greater than 0.1 - not taken" This means "if less than or equal 0.1 - taken" A Comma Separated Values (CSV) file Text file with the .csv extension. d11,d12, d13 d21,d22,d23 **** 1,2,30,S 2,3,45,F
Illustration S1 S2 S3 7 distance units Propagation 1 unit tick At T1 S1 initiate a message of length 2 to S3 $1 $2 83 81-83 At T1+1 $1 82 83 $1-83 81-83 At T1+2 SI initiate a message of length 2 to S3 SI 52 53 $1-83 81-83 At T1+3 S1 initiate a message of length 2 to S3 SI $2 S3 S1-5381-83 At T2 S1 S2 At T2+1 S1 S2 S3 At T2+2 81 82 83 Record (in a CSV) 1 attempt 1 success (time) At T3 S2 initiate a message of length 1 to S1 S1 S2 $3 S2-S1 At T3+1 S2initiate a message of length 1 to SI $1 53 $2 $2-81 $2-81 Later on SI 82-81 82-81 Attempt, Success (record the time) $3 $1-$351-53 $1-83 $2 83
Attempt, Success (record the time) At T4 S1 initiate a message of length 2 to S3, S3 initiates a message of 2 to S2 SI S2 S3 S1-S3 S3-S2 Next, SI S2 S1-S3 S1-S3 Next, SI S3 S3-S2 S3-S2 S2 S1-S3 S1-S3 S3-S2 S3-S2 S2 SI-S3 S1-S3 & S3-S2 S3-S2 2 attempts, 2 collisions Another scenario, S1 S2 S3 $1-83 S2 cannot initiate a message Next, SI S3 S3
the B. Simulation Part (80%) 1) Carefully read the background and the additional details sections provided below. 2) Set the
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am