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
|
2020-04-18 16:18:29 +01:00
|
|
|
import time
|
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
|
2020-04-18 16:18:29 +01:00
|
|
|
EMANE_DELAY = 10
|
2020-04-18 16:11:12 +01:00
|
|
|
|
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)
|
2020-04-18 16:18:29 +01:00
|
|
|
emane_network = session.add_node(_type=NodeTypes.EMANE, options=options, _id=100)
|
2019-10-23 05:27:31 +01:00
|
|
|
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()
|
|
|
|
|
2020-04-18 16:18:29 +01:00
|
|
|
# OSPF MDR requires some time for routes to be created
|
|
|
|
logging.info("waiting %s seconds for OSPF MDR to create routes", EMANE_DELAY)
|
|
|
|
time.sleep(EMANE_DELAY)
|
|
|
|
|
|
|
|
# get nodes to run example
|
|
|
|
first_node = session.get_node(1)
|
|
|
|
last_node = session.get_node(NODES)
|
|
|
|
address = prefixes.ip4_address(first_node)
|
|
|
|
logging.info("node %s pinging %s", last_node.name, address)
|
|
|
|
output = last_node.cmd(f"ping -c 3 {address}")
|
|
|
|
logging.info(output)
|
|
|
|
|
2018-04-17 22:30:34 +01:00
|
|
|
# shutdown session
|
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()
|