######################################################################################################
[Config Wireless01]
description = Two hosts communicating wirelessly
network = WirelessA

# At this point you should take a look at the NED files corresponding to this Ini file. 
# They are rather simple. The only interesting thing is that they are using parametrized types
# (i.e. like) so we will be able to change the type of the different modules from the Ini file.
# This allows us go through the tutorial only by changing parameter values in this file. 

# Limit the simulation to 25s
sim-time-limit = 25s

# Now we are ready to jump into the tutorial

# Let's configure ARP
# ARP in the real world is used to figure out the MAC address of a node from its IPv4 address.
# We do not want to use it in this wireless tutorial as it just adds some uninteresting 
# message exchanges before the real communication between the nodes can start. We will use 
# the GlobalARP module instead that can automatically provide all the MAC-IP assocoations 
# for the nodes out of band. 
**.arpType = "GlobalARP"

# Configure an aplication for hostA that sends a constant
# UDP traffic around 800Kbps (+ protocol overhead) 
*.hostA.numUdpApps = 1
*.hostA.udpApp[0].typename = "UDPBasicApp"
*.hostA.udpApp[0].destAddresses = "hostB"
*.hostA.udpApp[0].destPort = 5000
*.hostA.udpApp[0].messageLength = 1000B
*.hostA.udpApp[0].sendInterval = exponential(10ms)

# Configure an app that receives the USP traffic (and simply drops the data)
*.hostB.numUdpApps = 1
*.hostB.udpApp[0].typename = "UDPSink"
*.hostB.udpApp[0].localPort = 5000

# Configure the hosts to have a single "ideal" wireless NIC. An IdealWirelessNic
# can be configured with a maximum communication range. All packets withing range
# are always received successfully while out of range messages are never received.
# This is useful if we are not interested how the actual messages get to their destination,
# we just want to be sure that they get there once the nodes are in range.
*.host*.wlan[*].typename = "IdealWirelessNic"

# All radios and MACs should run on 1Mbps in our examples
**.bitrate = 1Mbps

# Mandatory physical layer parameters
*.host*.wlan[*].radio.transmitter.maxCommunicationRange = 500m

# Simplify the IdealWirelessNic even further. We do not care even if there are
# transmission collisions. Any number of nodes in range can transmit at the same time
# and the packets will be still successfully delivered.
*.host*.wlan[*].radio.receiver.ignoreInterference = true

# Result: HostA can send data to hostB using almost the whole 1Mbps bandwidth.

######################################################################################################
[Config Wireless02]
description = Setting up some animations
extends = Wireless01

# Allow the medium to animate the transmissions using the OMNeT++ Canvas API
# (We no longer need the default message animation so let's turn it off manually
# in the Tkenv's animation settings dialog.)
*.visualizer.mediumVisualizer.displaySignals = true

# To have a bit more smoother animation, turn on periodic self messages 
# from the medium. This will generate canvas updates to animate the 
# transmission animation. Instead of seeing only important events, we will see 
# how the transmission propagates through space. 
*.visualizer.mediumVisualizer.signalPropagationUpdateInterval = 100ns

# Allow the medium to draw a fading trail of successful transmissions (will show the communication paths).
*.visualizer.mediumVisualizer.displayCommunicationTrail = true

# Result: We can see nice expanding bubbles representing the transmissions.

######################################################################################################
[Config Wireless03]
description = Adding more nodes and decreasing the communication range
extends = Wireless02
network = WirelessB

# Decrease the communication range so hostA and hostB can no longer
# communicate directly.	
*.host*.wlan[*].radio.transmitter.maxCommunicationRange = 250m

# Result: With decreased communication range, hostA and hostB can no longer talk to each other directly.
# Unfortunately the extra nodes we have added to relay the information are not properly configured for
# routing. 

######################################################################################################
[Config Wireless04]
description = Setting up static routing
extends = Wireless03

# Enable static routing
*.host*.forwarding = true

# To have proper communication, we have to add static route entries in all hosts.
# It is too much work to do it manually so we instruct the network configurator 
# to use the estimated error rate between the nodes to set up static routes. 
# Nodes out of range will have an error rate of 1 while nodes within range 
# will have configurator.minLinkWeight error rate (by default it is 1e-3) 
# when using the IdealRadio. This will generate a properly configured IPv4 network 
# without any additional manual configuration.
*.configurator.config = xml("<config><interface hosts='**' address='10.0.0.x' netmask='255.255.255.0'/><autoroute metric='errorRate'/></config>")

# By disabling the routing table entry optimization we will have a separate entry for
# each destination host. The routing tables will be longer, but they are much easier to
# understand.
*.configurator.optimizeRoutes = false

# Disable routing table entries generated from the netmask (will disable default routes too.)
**.routingTable.netmaskRoutes = ""

# Enable route visualization
*.visualizer.routeVisualizer.packetNameFilter = "UDPBasicAppData-*"

# Result: Data is now correctly routed by the R1 node. In reality we would expect that 
# the throughput between the hosts drops becuase two nodes (hostA and hostR1) are using 
# the medium at the same time with a datarate that is around the capacity of the medium. 
# The simulation does not show this, because we have disabled the handling of the radio 
# interference in step 1 (ignoreInterference = true)

######################################################################################################
[Config Wireless05]
description = Taking interference into account
extends = Wireless04

# In this step we will try to more accurately model the communication by taking into account
# the interference betweeen transmissions at the radio receiver.
*.host*.wlan[*].radio.receiver.ignoreInterference = false

# Let's make the interference range the double of the communication range. 
*.host*.wlan[*].radio.transmitter.maxInterferenceRange = 500m

# Result: This change resulted in an almost constant collision at hostB becuase both hostA and hostR1 is 
# transmitting at almost the capacity of the medium. The only packets that get through are 
# the ones that are sent from hostR1 to hostB while the hostA happens not to transmit by chance.
# Because of this, we are seeing and extremely low throughput. HostA and hostR1 should use some
# form of media access so they could minimize the interference.

######################################################################################################
[Config Wireless06]
description = Using CSMA to better utilize the medium
extends = Wireless05

# We will use CSMA for the MAC so transmitters will sniff into the medium and will not
# transmit if there is an ongoing transmission in their interference range. 

# Let's switch the NIC to WirlessNic (from IdealWireless).
*.host*.wlan[*].typename = "WirelessNic"

# Still using IdealRadio. We have to set this, because the default radio for WirelessNic is Ieee80211.
*.host*.wlan[*].radioType = "IdealRadio"

# The MAC protocol is now CSMA
*.host*.wlan[*].macType = "CSMA"

# No ACKs for now
*.host*.wlan[*].mac.useMACAcks = false

# Result: After CSMA was configured, we should see an increased throughput (compared to the previous step
# where the medium was not checked before transmission)

######################################################################################################
[Config Wireless07]
description = Turning on ACKs in CSMA
extends = Wireless06

# We need MAC acknowledgements to detect if a link is broken between two nodes
*.host*.wlan[*].mac.useMACAcks = true

# Result: About the same number of packets go through, but the the link lsyer is now reliable
# (packets arriving at hostB are of consecutive sequence numbers)

######################################################################################################
[Config Wireless08]
description = Configuring node movements
extends = Wireless07

# Turn bubble off, we don't need them anymore
*.visualizer.mediumVisualizer.displaySignals = false

# Configure the relay nodes (R1-3) to move straight north during the simulation
# TIP: run the simulation in Fast mode to see some screen updates
*.hostR*.mobilityType = "LinearMobility"
*.hostR*.mobility.speed = 12mps
*.hostR*.mobility.angle = 270deg

# Result: we are seeig lower throughput than previously. This is because the
# static routing tables were configured based on the topology (node distances) at
# the beginning of the simulation. Data was routed from A to B through the R1 node.
# Unfortunately R1 node gets out of range around 13s and after that time the original 
# route is no longer usable. We could use A->R2->R3->B after this point, but that would 
# require an active protocol that reconfigures routing tables in response to the 
# lost connectivity.     

######################################################################################################
[Config Wireless09]
description = Configuring ad-hoc routing (AODV)
extends = Wireless08

# Turn off the static configuration added by the IPv4NetworkConfigurator so it will not interfere
# with the dynamic routing protocol. We are only assigning IP addresses now
*.configurator.addStaticRoutes = false
*.configurator.addDefaultRoutes = false
*.configurator.addSubnetRoutes = false

# Let's use AODV by using AODVRouters in the network. See Wireless07
# While running the simulation we see that the communication is broken areound 13s
# and AODV re-establishes the routes through A->R2->R3->B around 16s
*.hostType = "AODVRouter"

# Result: The MANET routing protocol now dynamically reconfigures the routes so data keeps flowing
# even after some nodes get out of range.

######################################################################################################
[Config Wireless10]
description = Modeling energy consumption
extends = Wireless09

# Set up a model for the energy consumption of the nodes
**.energyConsumerType = "StateBasedEnergyConsumer"

# Configure an energy storage device (inifite energy). We are not interested
# in the actual storage behavior.
*.host*.energyStorageType = "IdealEnergyStorage"

# Result: We can check the energy use of a module by looking at the energyBalance value in the module
# (hostA.energyStorage.energyBalance) or it is possible to see the energy use
# over time by displaying the residualCapacity signal.

######################################################################################################
[Config Wireless11]
description = Adding obstacles to the environment
extends = Wireless10
network = WirelessC

### XXX because of an incorrect default we should configure an empty object cache for an infinite space environment
# We would not need this if we would limit the size of the play ground.
# (once this is fixed in INET the below line can be removed)
*.physicalEnvironment.objectCacheType = ""

# Configure the physical environment to contain a single brick wall
*.physicalEnvironment.config = xmldoc("walls.xml")
# Set up how the loss is calculated (using line of sight tracing)
*.radioMedium.obstacleLossType = "TracingObstacleLoss"

# Result: Unfortunately we don't see any difference. :( Our radio model is too simple to take into account 
# the objects in the environment so we have to set up a more accurate model.

######################################################################################################
[Config Wireless12]
description = Changing to a more realistic radio model
extends = Wireless11

# We switch to a more detailed radio model so we have to replace the global radioMedium module, too
*.mediumType = "APSKScalarRadioMedium"

# Configure the background noise for the medium
*.radioMedium.backgroundNoise.power = -110dBm

### FIXME: In best case this should not be provided by the user, but the medium should calculate this automatically from the radio frequency.
# In INET 3.0 this must be manually configured.
*.radioMedium.mediumLimitCache.carrierFrequency = 2GHz

# Configure each radio (transmitter/receiver) in the model. 
# We need a lot more parameters to set up the radio.
*.host*.wlan[*].radioType = "APSKScalarRadio"
*.host*.wlan[*].radio.carrierFrequency = 2GHz
*.host*.wlan[*].radio.bandwidth = 2MHz
*.host*.wlan[*].radio.transmitter.power = 1.2mW
*.host*.wlan[*].radio.transmitter.preambleDuration = 0s
*.host*.wlan[*].radio.transmitter.headerBitLength = 100b
*.host*.wlan[*].radio.receiver.sensitivity = -85dBm
*.host*.wlan[*].radio.receiver.energyDetection = -85dBm
*.host*.wlan[*].radio.receiver.snirThreshold = 4dB

# Result: The simulation is now able to calculate with the attenutation of the 
# different physical objects in the environment. We see that the wall is actually blocking the
# transmission sometimes.

######################################################################################################
[Config Wireless13]
description = Configuring a more accurate pathloss model
extends = Wireless12

# To make our model even more accurate, let's configure the pathloss model, too.
# By default the medium uses the free space model. We will use the TwoRayGroundReflection 
# model here (assuming the we are walking on the ground).
# At this point we could also configure the computation model for the medium (scalar, 
# multidimensional) the propagation mode (constant speed, constant time) etc. 
# (see the radioMedium's parameters for further detail.)
*.radioMedium.pathLossType = "TwoRayGroundReflection"
*.radioMedium.pathLoss.transmitterAntennaHeight = 1.5m
*.radioMedium.pathLoss.receiverAntennaHeight = 1.5m

# Result: We see that with a better propagation model the communication pattern changes considerably
# as the reception power is much smaller than with the free space model. (Experiment with different 
# height values between 1m and 2m. and see the differences!)
 
######################################################################################################
[Config Wireless14]
description = Introducing antenna gain
extends = Wireless13

# Let's install a better antenna to extend the range of the nodes and increase the connectivity.
*.host*.wlan[*].radio.antennaType = "ConstantGainAntenna"
*.host*.wlan[*].radio.antenna.gain = 12dB

# Results: We have much better connectivity this time because of the antenna gain. Some transmissions
# even geth through the wall. The connectivity grap is almost a full graph at the end of the simulation.
