2020-09-12 19:22:58 +01:00
|
|
|
# required imports
|
2018-05-01 18:40:25 +01:00
|
|
|
from core.emulator.coreemu import CoreEmu
|
2022-05-25 18:51:42 +01:00
|
|
|
from core.emulator.data import IpPrefixes
|
2020-05-21 06:14:03 +01:00
|
|
|
from core.emulator.enumerations import EventTypes
|
2022-05-25 18:51:42 +01:00
|
|
|
from core.nodes.base import CoreNode, Position
|
2020-05-21 06:14:03 +01:00
|
|
|
from core.nodes.network import SwitchNode
|
2019-02-16 17:50:19 +00:00
|
|
|
|
2020-09-12 19:22:58 +01:00
|
|
|
# ip nerator for example
|
|
|
|
ip_prefixes = IpPrefixes(ip4_prefix="10.0.0.0/24")
|
2018-04-21 01:00:47 +01:00
|
|
|
|
2020-09-12 19:22:58 +01:00
|
|
|
# create emulator instance for creating sessions and utility methods
|
|
|
|
coreemu = CoreEmu()
|
|
|
|
session = coreemu.create_session()
|
2018-04-21 01:00:47 +01:00
|
|
|
|
2020-09-12 19:22:58 +01:00
|
|
|
# must be in configuration state for nodes to start, when using "node_add" below
|
|
|
|
session.set_state(EventTypes.CONFIGURATION_STATE)
|
2018-04-21 01:00:47 +01:00
|
|
|
|
2020-09-12 19:22:58 +01:00
|
|
|
# create switch
|
2022-05-25 18:51:42 +01:00
|
|
|
position = Position(x=200, y=200)
|
|
|
|
switch = session.add_node(SwitchNode, position=position)
|
2018-04-21 01:00:47 +01:00
|
|
|
|
2020-09-12 19:22:58 +01:00
|
|
|
# create nodes
|
2022-05-25 18:51:42 +01:00
|
|
|
position = Position(x=100, y=100)
|
|
|
|
n1 = session.add_node(CoreNode, position=position)
|
|
|
|
position = Position(x=300, y=100)
|
|
|
|
n2 = session.add_node(CoreNode, position=position)
|
2018-04-21 01:00:47 +01:00
|
|
|
|
2020-09-12 19:22:58 +01:00
|
|
|
# link nodes to switch
|
|
|
|
iface1 = ip_prefixes.create_iface(n1)
|
|
|
|
session.add_link(n1.id, switch.id, iface1)
|
|
|
|
iface1 = ip_prefixes.create_iface(n2)
|
|
|
|
session.add_link(n2.id, switch.id, iface1)
|
2018-04-21 01:00:47 +01:00
|
|
|
|
2020-09-12 19:22:58 +01:00
|
|
|
# start session
|
|
|
|
session.instantiate()
|
2018-04-21 01:00:47 +01:00
|
|
|
|
2020-09-12 19:22:58 +01:00
|
|
|
# do whatever you like here
|
|
|
|
input("press enter to shutdown")
|
2018-04-21 01:00:47 +01:00
|
|
|
|
2020-09-12 19:22:58 +01:00
|
|
|
# stop session
|
|
|
|
session.shutdown()
|