2020-01-17 21:47:55 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from core.emulator.coreemu import CoreEmu
|
|
|
|
from core.emulator.emudata import IpPrefixes, NodeOptions
|
2020-05-21 06:14:03 +01:00
|
|
|
from core.emulator.enumerations import EventTypes
|
|
|
|
from core.nodes.base import CoreNode
|
|
|
|
from core.nodes.network import SwitchNode
|
2020-01-17 21:47:55 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
|
|
|
|
# setup basic network
|
|
|
|
prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")
|
2020-06-13 00:52:41 +01:00
|
|
|
options = NodeOptions(model=None)
|
2020-01-17 21:47:55 +00:00
|
|
|
coreemu = CoreEmu()
|
|
|
|
session = coreemu.create_session()
|
|
|
|
session.set_state(EventTypes.CONFIGURATION_STATE)
|
2020-05-21 06:14:03 +01:00
|
|
|
switch = session.add_node(SwitchNode)
|
2020-01-17 21:47:55 +00:00
|
|
|
|
|
|
|
# node one
|
2020-01-18 05:09:51 +00:00
|
|
|
options.config_services = ["DefaultRoute", "IPForward"]
|
2020-06-13 00:52:41 +01:00
|
|
|
node1 = session.add_node(CoreNode, options=options)
|
|
|
|
interface = prefixes.create_interface(node1)
|
|
|
|
session.add_link(node1.id, switch.id, interface1_data=interface)
|
2020-01-17 21:47:55 +00:00
|
|
|
|
|
|
|
# node two
|
2020-06-13 00:52:41 +01:00
|
|
|
node2 = session.add_node(CoreNode, options=options)
|
|
|
|
interface = prefixes.create_interface(node2)
|
|
|
|
session.add_link(node2.id, switch.id, interface1_data=interface)
|
2020-01-17 21:47:55 +00:00
|
|
|
|
2020-01-18 00:57:49 +00:00
|
|
|
# start session and run services
|
|
|
|
session.instantiate()
|
2020-01-17 21:47:55 +00:00
|
|
|
|
|
|
|
input("press enter to exit")
|
|
|
|
session.shutdown()
|