2020-01-17 21:47:55 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from core.emulator.coreemu import CoreEmu
|
2020-06-16 20:50:24 +01:00
|
|
|
from core.emulator.data 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)
|
2020-06-16 17:30:16 +01:00
|
|
|
interface = prefixes.create_iface(node1)
|
|
|
|
session.add_link(node1.id, switch.id, iface1_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)
|
2020-06-16 17:30:16 +01:00
|
|
|
interface = prefixes.create_iface(node2)
|
|
|
|
session.add_link(node2.id, switch.id, iface1_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()
|