2020-04-18 08:11:12 -07:00
|
|
|
"""
|
|
|
|
This is a script to run a small switch based scenario and depends on
|
|
|
|
the user running this script through the "Execute Python Script" option
|
|
|
|
in the GUI. The usage of globals() below allows this script to leverage the
|
|
|
|
same CoreEmu instance the GUI is using.
|
|
|
|
"""
|
|
|
|
|
2019-10-04 12:36:15 -07:00
|
|
|
import logging
|
2019-05-05 16:19:12 -07:00
|
|
|
|
2020-05-20 22:14:03 -07:00
|
|
|
from core.emulator.coreemu import CoreEmu
|
2018-05-01 10:40:25 -07:00
|
|
|
from core.emulator.emudata import IpPrefixes
|
2020-05-20 22:14:03 -07:00
|
|
|
from core.emulator.enumerations import EventTypes
|
|
|
|
from core.nodes.base import CoreNode
|
|
|
|
from core.nodes.network import SwitchNode
|
2019-02-16 09:50:19 -08:00
|
|
|
|
2020-04-18 08:11:12 -07:00
|
|
|
NODES = 2
|
|
|
|
|
2018-04-20 17:00:47 -07:00
|
|
|
|
2020-04-18 08:11:12 -07:00
|
|
|
def main():
|
2018-04-20 17:00:47 -07:00
|
|
|
# ip generator for example
|
2018-04-24 16:24:54 -07:00
|
|
|
prefixes = IpPrefixes("10.83.0.0/16")
|
2018-04-20 17:00:47 -07:00
|
|
|
|
|
|
|
# create emulator instance for creating sessions and utility methods
|
2020-05-20 22:14:03 -07:00
|
|
|
coreemu: CoreEmu = globals()["coreemu"]
|
2018-04-25 10:55:48 -07:00
|
|
|
session = coreemu.create_session()
|
2018-04-20 17:00:47 -07:00
|
|
|
|
|
|
|
# must be in configuration state for nodes to start, when using "node_add" below
|
2018-04-25 16:33:58 -07:00
|
|
|
session.set_state(EventTypes.CONFIGURATION_STATE)
|
2018-04-20 17:00:47 -07:00
|
|
|
|
|
|
|
# create switch network node
|
2020-05-20 22:14:03 -07:00
|
|
|
switch = session.add_node(SwitchNode)
|
2018-04-20 17:00:47 -07:00
|
|
|
|
|
|
|
# create nodes
|
2020-04-18 08:11:12 -07:00
|
|
|
for _ in range(NODES):
|
2020-05-20 22:14:03 -07:00
|
|
|
node = session.add_node(CoreNode)
|
2018-04-24 16:24:54 -07:00
|
|
|
interface = prefixes.create_interface(node)
|
2020-06-12 16:52:41 -07:00
|
|
|
session.add_link(node.id, switch.id, interface1_data=interface)
|
2018-04-20 17:00:47 -07:00
|
|
|
|
|
|
|
# instantiate session
|
|
|
|
session.instantiate()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ in {"__main__", "__builtin__"}:
|
2019-10-04 12:36:15 -07:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
2020-04-18 08:11:12 -07:00
|
|
|
main()
|