"./blocks/sim2/two_nodes_802.11G",
    "./blocks/sim2/wifi_linearDistanceUDP_deferredStart_udperf",
    "./blocks/sim2/two_nodes_802.11G_unidir"
]
nb1 = NetworkBlock(blockPaths[0])  # init nb1
emu.addNetworkBlocks([nb1])

udperf_app = UdperfApp(n1, n0, 0.0, 110, 10000, 6000, 6001)

n1.addUserResult("/home/nfd/cmdScheduler.log",
                 "cmdSched" + str(n1.getId()) + ".log_%RUN%")

emu.setDuration(112)

emu.addApplications([udperf_app])
emu.setSecondsBetweenRuns(5)
emu.setNumberOfRuns(1)

for bpath in blockPaths:
    # update nb1
    emu.removeNetworkBlocks([nb1])
    nb1 = NetworkBlock(bpath)
    nb1.setNodes([n0, n1])
    nb1.selectInterval(1000)
    nb1.addPreprocessingStep(SetConstantValueForColumn("", 3, 27000.0))
    emu.addNetworkBlocks([nb1])

    emu.setName('multisim_' + os.path.basename(bpath))
    emu.setOutputDirectory('./results/sim2/' + emu.getName())
    emu.start()
from emulation_lib.emulation import Emulation
from emulation_lib.network_blocks.network_block import NetworkBlock
from emulation_lib.apps.udperf_app import UdperfApp
from emulation_lib.preprocessing.set_constant_value_for_column import SetConstantValueForColumn
from emulation_lib.linkcmd_backends.bdl_ import BDL_

emu = Emulation("example.config.py", [0, 1])
emu.setLinkCmdBackend(BDL_())
n0 = emu.getNode(0)
n1 = emu.getNode(1)


nb1 = NetworkBlock("./blocks/simple_mobility_802.11G_AdHoc_constant")
nb1.setNodes([n0, n1])
nb1.addPreprocessingStep(SetConstantValueForColumn("", 3, 27000.0))  # empty prefix -> apply to all files

emu.addNetworkBlocks([nb1])

udperf_app = UdperfApp(n1, n0, 0.0, 110, 10000, 6000, 6001)

n1.addUserResult("/home/nfd/cmdScheduler.log", "cmdSched" + str(n1.getId()) + ".log_%RUN%")

emu.setDuration(112)

emu.addApplications([udperf_app])
emu.setSecondsBetweenRuns(5)
emu.setNumberOfRuns(40)

for interval in [1000, 500, 250, 100, 50, 25]:
    nb1.selectInterval(interval)
    emu.setName(str(interval))
wlan = NetworkBlock(WIFI_BLOCK)
wlan.setNodes(
    emu.getNodes()
    [0:NUMBER_OF_NODES])  # assign all two nodes to be part of the network

# select interval of network condition changes
# ./blocks/simple_mobility_802.11G_AdHoc_constant/0_1_1000.txt
# ./blocks/simple_mobility_802.11G_AdHoc_constant/1_0_1000.txt
wlan.selectInterval(1000)

# preprocessing steps are ways to modify intermediate files without changing the originals (experimentation)
# if the given intermediate files were too long, here we could use a preprocessing step to only take the first n seconds
wlan.addPreprocessingStep(RepeatIntermedFileUntil(EMULATION_DURATION, False))
# for this example, we only want to restrict the bandwidth (column #3 in the intermediate file)
# and therefore overwrite the columns for delay (#1) and loss (#2) with zeros using the following preprocessing steps
wlan.addPreprocessingStep(SetConstantValueForColumn("", 1, 0))
wlan.addPreprocessingStep(SetConstantValueForColumn("", 2, 0))

# before (part of 1_0_1000.txt)
# 10.000000	0.001542	0.44	5522.400
# 11.000000	0.001679	0.22	5632.848
# 12.000000	0.002284	1.71	3522.064

# after (part of 1_0_1000.txt)
# 10.000000	0	0	5522.400
# 11.000000	0	0	5632.848
# 12.000000	0	0	3522.064

# add the network block to the emulation
emu.addNetworkBlocks([wlan])