MC Exp4
MC Exp4
Lab Outcome: -
Date of Performance: -
Date of Submission: -
Practical In charge
EXPERIMENT NO. 04
Title: Illustration of Hidden Terminal/Exposed terminal Problem. Consider two Wi-fi
base stations (STA) and an access point (AP) located along the x-axis. All the nodes
are fixed. The AP is situated at the middle of the two STA, the distance of separation
being 150 m. [variable]. Node #0 and node #1 are the hidden terminals. Both are
transmitting some data to the AP (almost at same rate) at the same time. The loss
across the wireless link between each STA and the AP is fixed at 50 dB irrespective
of the distance of separation.
Theory:
Hidden and exposed terminals:
Consider the scenario with three mobile phones as shown in Figure 1. The
transmission range of A reaches B, but not C (the detection range does not reach C
either). The transmission range of C reaches B, but not A. Finally, the transmission
range of B reaches A and C, i.e., A cannot detect C and vice versa. A starts sending to
B, C does not receive this transmission. C also wants to send something to B and
senses the medium. The medium appears to be free, the carrier sense fails. C also
starts sending causing a collision at B. But A cannot detect this collision at B and
continues with its transmission. A is hidden for C and vice versa.
Figure. 2:
With MACA, A does not start its transmission at once, but sends a request to send (RTS)
first. B receives the RTS that contains the name of sender and receiver, as well as the length of
the future transmission. This RTS is not heard by C, but triggers an acknowledgement from B,
called clear to send (CTS). The CTS again contains the names of sender (A) and receiver (B)
of the user data, and the length of the future transmission. This CTS is now heard by C and the
medium for future use by A is now reserved for the duration of the transmission. After
receiving a CTS, C is not allowed to send anything for the duration indicated in the CTS
toward B. A collision cannot occur at B during data transmission, and the hidden terminal
problem is solved – provided that the transmission conditions remain the same. (Another
station could move into the transmission range of B after the transmission of CTS.)
NS2 Implementation:
Here a simulator object has to be created. We have to start the simulation with the same
command, and if we want to run nam automatically, we will always have to open a trace
file, initialize it, and define a procedure which closes it and starts nam.
Now insert the following lines into the code to create four nodes. set n0
[$ns node]
set n1 [$ns node]
set n2 [$ns node] set n3
[$ns node]
The following piece of Tcl code creates three duplex links between the nodes.
Add the next three lines to your Tcl script and start it again.
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
The events:
Now we create two UDP agents with CBR traffic sources and attach them to the nodes
n0 and n1. Then we create a Null agent and attach it to node n3.
We want the first CBR agent to start sending at 0.5 seconds and to stop at 4.5 seconds while
the second CBR agent starts at 1.0 seconds and stops at 4.0 seconds.
$ns at 0.5 "$cbr0 start"
$ns at 1.0 "$cbr1 start"
$ns at 4.0 "$cbr1 stop"
$ns at 4.5 "$cbr0 stop"
Marking flows:
Add the following two lines to your CBR agent definitions.
$udp0 set class_ 1
$udp1 set class_ 2
This code allows you to set different colors for each flow id.
Wired
Program:
import simpy
import networkx as nx
import matplotlib.pyplot as plt
env = simpy.Environment()
n0 = {"label": "Client1", "color": "blue"}
n1 = {"label": "Server", "color": "red", "shape": "hexagon"}
n2 = {"label": "Client2", "color": "green", "shape": "square"}
links = [((0, "Client1"), (1, "Server")), ((1, "Server"), (2, "Client2"))]
G = nx.DiGraph()
for node in [n0, n1, n2]:
G.add_node(node["label"], color=node.get("color", "gray"), shape=node.get("shape", "ellipse"))
class Link:
def __init__(self, env, node1, node2, bandwidth, delay):
self.env = env
self.node1 = node1
self.node2 = node2
self.bandwidth = bandwidth
self.delay = delay
self.action = env.process(self.run())
def run(self):
yield self.env.timeout(0) # Initial delay
print(f"Link between {self.node1['label']} and {self.node2['label']} established.")
pos = nx.spring_layout(G)
ellipse_nodes = [node for node, data in G.nodes(data=True) if data["shape"] == "ellipse"]
hexagon_nodes = [node for node, data in G.nodes(data=True) if data["shape"] == "hexagon"]
square_nodes = [node for node, data in G.nodes(data=True) if data["shape"] == "square"]
WIRELESS
Program:
import simpy
import networkx as nx
import matplotlib.pyplot as plt
env = simpy.Environment()
node_positions = [(0, 0), (1, 0), (2, 0), (1, 1)] # Example positions, adjust as needed
nodes = [simpy.Container(env) for _ in range(len(node_positions))]
links = [
(0, 1, {"bandwidth": 2e6, "delay": 1e-3}),
(1, 2, {"bandwidth": 2.5e6, "delay": 1e-3}),
(2, 3, {"bandwidth": 2e6, "delay": 1.5e-3}),
(3, 1, {"bandwidth": 12e6, "delay": 1e-2}),
]
G = nx.DiGraph()
G.add_nodes_from(range(len(node_positions)))
G.add_edges_from(links)
for i in range(len(node_positions)):
env.process(ftp_traffic(env, nodes[i], nodes[(i + 2) % len(node_positions)]))
def visualize_graph(G):
pos = nx.spring_layout(G)
edge_styles = [(u, v, {"dashed": True}) for u, v in G.edges()]
nx.draw(G, pos, with_labels=True, node_color="skyblue", node_size=700, font_color="black",
font_weight="bold", edgelist=edge_styles, connectionstyle="arc3,rad=0.1")
plt.show()
env.run(until=3.0)
visualize_graph(G)
print("Simulation finished.")
Output:
CONCLUSION: