2020-04-18 16:11:12 +01:00
|
|
|
"""
|
|
|
|
This is a standalone script to run a small EMANE scenario and will not interact
|
|
|
|
with the GUI. You also must have installed OSPF MDR as noted in the documentation
|
|
|
|
installation page.
|
|
|
|
"""
|
|
|
|
|
2019-10-04 20:36:15 +01:00
|
|
|
import logging
|
2018-04-17 22:30:34 +01:00
|
|
|
|
|
|
|
from core.emane.ieee80211abg import EmaneIeee80211abgModel
|
2018-05-01 18:40:25 +01:00
|
|
|
from core.emulator.coreemu import CoreEmu
|
2019-10-22 23:13:28 +01:00
|
|
|
from core.emulator.emudata import IpPrefixes, NodeOptions
|
2019-10-23 05:27:31 +01:00
|
|
|
from core.emulator.enumerations import EventTypes, NodeTypes
|
2019-02-16 17:50:19 +00:00
|
|
|
|
2020-04-18 16:11:12 +01:00
|
|
|
NODES = 2
|
|
|
|
|
2018-04-17 22:30:34 +01:00
|
|
|
|
2020-04-18 16:11:12 +01:00
|
|
|
def main():
|
2018-04-17 22:30:34 +01:00
|
|
|
# ip generator for example
|
2018-04-25 00:24:54 +01:00
|
|
|
prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")
|
2018-04-17 22:30:34 +01:00
|
|
|
|
|
|
|
# create emulator instance for creating sessions and utility methods
|
|
|
|
coreemu = CoreEmu()
|
|
|
|
session = coreemu.create_session()
|
|
|
|
|
2018-04-25 18:55:48 +01:00
|
|
|
# must be in configuration state for nodes to start, when using "node_add" below
|
2018-04-26 00:33:58 +01:00
|
|
|
session.set_state(EventTypes.CONFIGURATION_STATE)
|
2018-04-25 18:55:48 +01:00
|
|
|
|
2020-04-18 16:11:12 +01:00
|
|
|
# create emane network node, emane determines connectivity based on
|
|
|
|
# location, so the session and nodes must be configured to provide one
|
2019-10-23 05:27:31 +01:00
|
|
|
session.set_location(47.57917, -122.13232, 2.00000, 1.0)
|
|
|
|
options = NodeOptions()
|
|
|
|
options.set_position(80, 50)
|
|
|
|
emane_network = session.add_node(_type=NodeTypes.EMANE, options=options)
|
|
|
|
session.emane.set_model(emane_network, EmaneIeee80211abgModel)
|
2018-04-17 22:30:34 +01:00
|
|
|
|
|
|
|
# create nodes
|
2019-10-22 23:13:28 +01:00
|
|
|
options = NodeOptions(model="mdr")
|
2020-04-18 16:11:12 +01:00
|
|
|
for i in range(NODES):
|
2019-10-22 23:31:50 +01:00
|
|
|
node = session.add_node(options=options)
|
2018-04-17 22:30:34 +01:00
|
|
|
node.setposition(x=150 * (i + 1), y=150)
|
2018-04-25 18:55:48 +01:00
|
|
|
interface = prefixes.create_interface(node)
|
2019-04-27 06:07:51 +01:00
|
|
|
session.add_link(node.id, emane_network.id, interface_one=interface)
|
2018-04-17 22:30:34 +01:00
|
|
|
|
|
|
|
# instantiate session
|
|
|
|
session.instantiate()
|
|
|
|
|
|
|
|
# shutdown session
|
2019-09-11 05:01:51 +01:00
|
|
|
input("press enter to exit...")
|
2018-04-25 00:24:54 +01:00
|
|
|
coreemu.shutdown()
|
2018-04-17 22:30:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__" or __name__ == "__builtin__":
|
2020-04-18 16:11:12 +01:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
2018-04-17 22:30:34 +01:00
|
|
|
main()
|