コード例 #1
0
ファイル: distributed_ptp.py プロジェクト: lsh23/core
def main(args):
    # ip generator for example
    prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")

    # create emulator instance for creating sessions and utility methods
    coreemu = CoreEmu({"distributed_address": args.address})
    session = coreemu.create_session()

    # initialize distributed
    server_name = "core2"
    session.distributed.add_server(server_name, args.server)

    # must be in configuration state for nodes to start, when using "node_add" below
    session.set_state(EventTypes.CONFIGURATION_STATE)

    # create local node, switch, and remote nodes
    options = NodeOptions()
    node_one = session.add_node(options=options)
    options.server = server_name
    node_two = session.add_node(options=options)

    # create node interfaces and link
    interface_one = prefixes.create_interface(node_one)
    interface_two = prefixes.create_interface(node_two)
    session.add_link(node_one.id, node_two.id, interface_one, interface_two)

    # instantiate session
    session.instantiate()

    # pause script for verification
    input("press enter for shutdown")

    # shutdown session
    coreemu.shutdown()
コード例 #2
0
def add_node_data(
        node_proto: core_pb2.Node) -> Tuple[NodeTypes, int, NodeOptions]:
    """
    Convert node protobuf message to data for creating a node.

    :param node_proto: node proto message
    :return: node type, id, and options
    """
    _id = node_proto.id
    _type = node_proto.type
    if _type is None:
        _type = NodeTypes.DEFAULT.value
    _type = NodeTypes(_type)

    options = NodeOptions(name=node_proto.name, model=node_proto.model)
    options.icon = node_proto.icon
    options.opaque = node_proto.opaque
    options.image = node_proto.image
    options.services = node_proto.services
    options.config_services = node_proto.config_services
    if node_proto.emane:
        options.emane = node_proto.emane
    if node_proto.server:
        options.server = node_proto.server

    position = node_proto.position
    options.set_position(position.x, position.y)
    if node_proto.HasField("geo"):
        geo = node_proto.geo
        options.set_location(geo.lat, geo.lon, geo.alt)
    return _type, _id, options
コード例 #3
0
ファイル: grpcutils.py プロジェクト: devdkerr/core-1
def add_node_data(node_proto):
    """
    Convert node protobuf message to data for creating a node.

    :param core_pb2.Node node_proto: node proto message
    :return: node type, id, and options
    :rtype: tuple
    """
    _id = node_proto.id
    _type = node_proto.type
    if _type is None:
        _type = NodeTypes.DEFAULT.value
    _type = NodeTypes(_type)

    options = NodeOptions(name=node_proto.name, model=node_proto.model)
    options.icon = node_proto.icon
    options.opaque = node_proto.opaque
    options.image = node_proto.image
    options.services = node_proto.services
    if node_proto.emane:
        options.emane = node_proto.emane
    if node_proto.server:
        options.server = node_proto.server

    position = node_proto.position
    options.set_position(position.x, position.y)
    options.set_location(position.lat, position.lon, position.alt)
    return _type, _id, options
コード例 #4
0
    def test_remote_node(self, session):
        # given
        server_name = "core2"
        host = "127.0.0.1"

        # when
        session.distributed.add_server(server_name, host)
        options = NodeOptions()
        options.server = server_name
        node = session.add_node(options=options)

        # then
        assert node.server is not None
        assert node.server.name == server_name
        assert node.server.host == host
コード例 #5
0
    def test_remote_bridge(self, session):
        # given
        server_name = "core2"
        host = "127.0.0.1"
        session.distributed.address = host

        # when
        session.distributed.add_server(server_name, host)
        options = NodeOptions()
        options.server = server_name
        node = session.add_node(_type=NodeTypes.HUB, options=options)
        session.instantiate()

        # then
        assert node.server is not None
        assert node.server.name == server_name
        assert node.server.host == host
        assert len(session.distributed.tunnels) > 0
コード例 #6
0
def main(args):
    # ip generator for example
    prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")

    # create emulator instance for creating sessions and utility methods
    coreemu = CoreEmu(
        {
            "controlnet": "core1:172.16.1.0/24 core2:172.16.2.0/24 core3:172.16.3.0/24 "
            "core4:172.16.4.0/24 core5:172.16.5.0/24",
            "distributed_address": args.address,
        }
    )
    session = coreemu.create_session()

    # initialize distributed
    server_name = "core2"
    session.distributed.add_server(server_name, args.server)

    # must be in configuration state for nodes to start, when using "node_add" below
    session.set_state(EventTypes.CONFIGURATION_STATE)

    # create local node, switch, and remote nodes
    options = NodeOptions(model="mdr")
    options.set_position(0, 0)
    node_one = session.add_node(options=options)
    emane_net = session.add_node(_type=NodeTypes.EMANE)
    session.emane.set_model(emane_net, EmaneIeee80211abgModel)
    options.server = server_name
    node_two = session.add_node(options=options)

    # create node interfaces and link
    interface_one = prefixes.create_interface(node_one)
    interface_two = prefixes.create_interface(node_two)
    session.add_link(node_one.id, emane_net.id, interface_one=interface_one)
    session.add_link(node_two.id, emane_net.id, interface_one=interface_two)

    # instantiate session
    session.instantiate()

    # pause script for verification
    input("press enter for shutdown")

    # shutdown session
    coreemu.shutdown()