2019-10-05 01:33:44 +01:00
|
|
|
import logging
|
2019-10-07 19:58:27 +01:00
|
|
|
import pdb
|
2019-10-08 23:09:26 +01:00
|
|
|
import sys
|
2019-10-05 01:33:44 +01:00
|
|
|
|
|
|
|
from core.emulator.coreemu import CoreEmu
|
2019-10-08 23:09:26 +01:00
|
|
|
from core.emulator.emudata import IpPrefixes, NodeOptions
|
|
|
|
from core.emulator.enumerations import EventTypes, NodeTypes
|
2019-10-05 01:33:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
# ip generator for example
|
2019-10-08 23:09:26 +01:00
|
|
|
prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")
|
2019-10-05 01:33:44 +01:00
|
|
|
|
|
|
|
# create emulator instance for creating sessions and utility methods
|
|
|
|
coreemu = CoreEmu()
|
|
|
|
session = coreemu.create_session()
|
|
|
|
|
2019-10-09 05:06:22 +01:00
|
|
|
# set controlnet
|
|
|
|
session.options.set_config("controlnet", "172.16.0.0/24")
|
|
|
|
|
2019-10-05 01:33:44 +01:00
|
|
|
# initialize distributed
|
2019-10-08 23:09:26 +01:00
|
|
|
address = sys.argv[1]
|
|
|
|
remote = sys.argv[2]
|
|
|
|
session.address = address
|
|
|
|
session.add_distributed(remote)
|
2019-10-05 01:33:44 +01:00
|
|
|
|
|
|
|
# must be in configuration state for nodes to start, when using "node_add" below
|
|
|
|
session.set_state(EventTypes.CONFIGURATION_STATE)
|
|
|
|
|
2019-10-08 23:09:26 +01:00
|
|
|
# create local node, switch, and remote nodes
|
|
|
|
node_one = session.add_node()
|
|
|
|
switch = session.add_node(_type=NodeTypes.SWITCH)
|
2019-10-05 01:33:44 +01:00
|
|
|
options = NodeOptions()
|
2019-10-08 23:09:26 +01:00
|
|
|
options.emulation_server = remote
|
|
|
|
node_two = session.add_node(node_options=options)
|
2019-10-05 01:33:44 +01:00
|
|
|
|
2019-10-09 05:17:15 +01:00
|
|
|
# create node interfaces and link
|
2019-10-08 23:09:26 +01:00
|
|
|
interface_one = prefixes.create_interface(node_one)
|
|
|
|
interface_two = prefixes.create_interface(node_two)
|
|
|
|
session.add_link(node_one.id, switch.id, interface_one=interface_one)
|
|
|
|
session.add_link(node_two.id, switch.id, interface_one=interface_two)
|
2019-10-05 01:33:44 +01:00
|
|
|
|
|
|
|
# instantiate session
|
|
|
|
session.instantiate()
|
|
|
|
|
2019-10-08 23:09:26 +01:00
|
|
|
# pause script for verification
|
2019-10-07 19:58:27 +01:00
|
|
|
pdb.set_trace()
|
|
|
|
|
2019-10-05 01:33:44 +01:00
|
|
|
# shutdown session
|
|
|
|
coreemu.shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
main()
|