Example #1
0
def main(args):
    core = client.CoreGrpcClient()

    with core.context_connect():
        # create session
        response = core.create_session()
        session_id = response.session_id
        logging.info("created session: %s", response)

        # add distributed server
        server_name = "core2"
        response = core.add_session_server(session_id, server_name,
                                           args.server)
        logging.info("added session server: %s", response)

        # handle events session may broadcast
        core.events(session_id, log_event)

        # change session state
        response = core.set_session_state(session_id,
                                          SessionState.CONFIGURATION)
        logging.info("set session state: %s", response)

        # create switch node
        switch = Node(type=NodeType.SWITCH)
        response = core.add_node(session_id, switch)
        logging.info("created switch: %s", response)
        switch_id = response.node_id

        # helper to create interfaces
        interface_helper = client.InterfaceHelper(ip4_prefix="10.83.0.0/16")

        # create node one
        position = Position(x=100, y=50)
        node = Node(position=position)
        response = core.add_node(session_id, node)
        logging.info("created node one: %s", response)
        node1_id = response.node_id

        # create link
        interface1 = interface_helper.create_iface(node1_id, 0)
        response = core.add_link(session_id, node1_id, switch_id, interface1)
        logging.info("created link from node one to switch: %s", response)

        # create node two
        position = Position(x=200, y=50)
        node = Node(position=position, server=server_name)
        response = core.add_node(session_id, node)
        logging.info("created node two: %s", response)
        node2_id = response.node_id

        # create link
        interface1 = interface_helper.create_iface(node2_id, 0)
        response = core.add_link(session_id, node2_id, switch_id, interface1)
        logging.info("created link from node two to switch: %s", response)

        # change session state
        response = core.set_session_state(session_id,
                                          SessionState.INSTANTIATION)
        logging.info("set session state: %s", response)
Example #2
0
def main():
    # helper to create interface addresses
    interface_helper = client.InterfaceHelper(ip4_prefix="10.83.0.0/24")

    # create grpc client and start connection context, which auto closes connection
    core = client.CoreGrpcClient()
    with core.context_connect():
        # create session
        response = core.create_session()
        logging.info("created session: %s", response)

        # handle events session may broadcast
        session_id = response.session_id
        core.events(session_id, log_event)

        # change session state to configuration so that nodes get started when added
        response = core.set_session_state(session_id,
                                          SessionState.CONFIGURATION)
        logging.info("set session state: %s", response)

        # create emane node
        position = Position(x=200, y=200)
        emane = Node(type=NodeType.EMANE, position=position)
        response = core.add_node(session_id, emane)
        logging.info("created emane: %s", response)
        emane_id = response.node_id

        # an emane model must be configured for use, by the emane node
        core.set_emane_model_config(session_id, emane_id,
                                    EmaneIeee80211abgModel.name)

        # create node one
        position = Position(x=100, y=100)
        node1 = Node(type=NodeType.DEFAULT, position=position)
        response = core.add_node(session_id, node1)
        logging.info("created node: %s", response)
        node1_id = response.node_id

        # create node two
        position = Position(x=300, y=100)
        node2 = Node(type=NodeType.DEFAULT, position=position)
        response = core.add_node(session_id, node2)
        logging.info("created node: %s", response)
        node2_id = response.node_id

        # links nodes to switch
        interface1 = interface_helper.create_iface(node1_id, 0)
        response = core.add_link(session_id, node1_id, emane_id, interface1)
        logging.info("created link: %s", response)
        interface1 = interface_helper.create_iface(node2_id, 0)
        response = core.add_link(session_id, node2_id, emane_id, interface1)
        logging.info("created link: %s", response)

        # change session state
        response = core.set_session_state(session_id,
                                          SessionState.INSTANTIATION)
        logging.info("set session state: %s", response)
Example #3
0
 def create_node(
     self, x: float, y: float, node_type: NodeType, model: str
 ) -> Optional[Node]:
     """
     Add node, with information filled in, to grpc manager
     """
     node_id = self.next_node_id()
     position = Position(x=x, y=y)
     image = None
     if NodeUtils.is_image_node(node_type):
         image = "ubuntu:latest"
     emane = None
     if node_type == NodeType.EMANE:
         if not self.emane_models:
             dialog = EmaneInstallDialog(self.app)
             dialog.show()
             return
         emane = self.emane_models[0]
         name = f"EMANE{node_id}"
     elif node_type == NodeType.WIRELESS_LAN:
         name = f"WLAN{node_id}"
     elif node_type in [NodeType.RJ45, NodeType.TUNNEL]:
         name = "UNASSIGNED"
     else:
         name = f"n{node_id}"
     node = Node(
         id=node_id,
         type=node_type,
         name=name,
         model=model,
         position=position,
         image=image,
         emane=emane,
     )
     if NodeUtils.is_custom(node_type, model):
         services = NodeUtils.get_custom_node_services(self.app.guiconfig, model)
         node.services[:] = services
     # assign default services to CORE node
     else:
         services = self.default_services.get(model)
         if services:
             node.services[:] = services
     logging.info(
         "add node(%s) to session(%s), coordinates(%s, %s)",
         node.name,
         self.session_id,
         x,
         y,
     )
     return node
Example #4
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
Example #5
0
                                      ip6_prefix="2001::/64")

# create grpc client and connect
core = client.CoreGrpcClient()
core.connect()

# create session and get id
response = core.create_session()
session_id = response.session_id

# change session state to configuration so that nodes get started when added
core.set_session_state(session_id, SessionState.CONFIGURATION)

# create switch node
position = Position(x=200, y=200)
switch = Node(type=NodeType.SWITCH, position=position)
response = core.add_node(session_id, switch)
switch_id = response.node_id

# create node one
position = Position(x=100, y=100)
n1 = Node(type=NodeType.DEFAULT, position=position, model="PC")
response = core.add_node(session_id, n1)
n1_id = response.node_id

# create node two
position = Position(x=300, y=100)
n2 = Node(type=NodeType.DEFAULT, position=position, model="PC")
response = core.add_node(session_id, n2)
n2_id = response.node_id
Example #6
0
File: wlan.py Project: umr-ds/core
def main():
    # helper to create interface addresses
    interface_helper = client.InterfaceHelper(ip4_prefix="10.83.0.0/24")

    # create grpc client and start connection context, which auto closes connection
    core = client.CoreGrpcClient()
    with core.context_connect():
        # create session
        response = core.create_session()
        logging.info("created session: %s", response)

        # handle events session may broadcast
        session_id = response.session_id
        core.events(session_id, log_event)

        # change session state to configuration so that nodes get started when added
        response = core.set_session_state(session_id,
                                          SessionState.CONFIGURATION)
        logging.info("set session state: %s", response)

        # create wlan node
        position = Position(x=200, y=200)
        wlan = Node(type=NodeType.WIRELESS_LAN, position=position)
        response = core.add_node(session_id, wlan)
        logging.info("created wlan: %s", response)
        wlan_id = response.node_id

        # change/configure wlan if desired
        # NOTE: error = loss, and named this way for legacy purposes for now
        config = {
            "bandwidth": "54000000",
            "range": "500",
            "jitter": "0",
            "delay": "5000",
            "error": "0",
        }
        response = core.set_wlan_config(session_id, wlan_id, config)
        logging.info("set wlan config: %s", response)

        # create node one
        position = Position(x=100, y=100)
        node1 = Node(type=NodeType.DEFAULT, position=position)
        response = core.add_node(session_id, node1)
        logging.info("created node: %s", response)
        node1_id = response.node_id

        # create node two
        position = Position(x=300, y=100)
        node2 = Node(type=NodeType.DEFAULT, position=position)
        response = core.add_node(session_id, node2)
        logging.info("created node: %s", response)
        node2_id = response.node_id

        # links nodes to switch
        interface1 = interface_helper.create_iface(node1_id, 0)
        response = core.add_link(session_id, node1_id, wlan_id, interface1)
        logging.info("created link: %s", response)
        interface1 = interface_helper.create_iface(node2_id, 0)
        response = core.add_link(session_id, node2_id, wlan_id, interface1)
        logging.info("created link: %s", response)

        # change session state
        response = core.set_session_state(session_id,
                                          SessionState.INSTANTIATION)
        logging.info("set session state: %s", response)
Example #7
0
                                      ip6_prefix="2001::/64")

# create grpc client and connect
core = client.CoreGrpcClient()
core.connect()

# create session and get id
response = core.create_session()
session_id = response.session_id

# change session state to configuration so that nodes get started when added
core.set_session_state(session_id, SessionState.CONFIGURATION)

# create node one
position = Position(x=100, y=100)
n1 = Node(type=NodeType.DEFAULT, position=position, model="PC")
response = core.add_node(session_id, n1)
n1_id = response.node_id

# create node two
position = Position(x=300, y=100)
n2 = Node(type=NodeType.DEFAULT, position=position, model="PC")
response = core.add_node(session_id, n2)
n2_id = response.node_id

# links nodes together
iface1 = iface_helper.create_iface(n1_id, 0)
iface2 = iface_helper.create_iface(n2_id, 0)
core.add_link(session_id, n1_id, n2_id, iface1, iface2)

# change session state
Example #8
0
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")

# create grpc client and connect
core = client.CoreGrpcClient()
core.connect()

# create session and get id
response = core.create_session()
session_id = response.session_id

# change session state to configuration so that nodes get started when added
core.set_session_state(session_id, SessionState.CONFIGURATION)

# create wlan node
position = Position(x=200, y=200)
wlan = Node(type=NodeType.WIRELESS_LAN, position=position)
response = core.add_node(session_id, wlan)
wlan_id = response.node_id

# create node one
position = Position(x=100, y=100)
n1 = Node(type=NodeType.DEFAULT, position=position, model="mdr")
response = core.add_node(session_id, n1)
n1_id = response.node_id

# create node two
position = Position(x=300, y=100)
n2 = Node(type=NodeType.DEFAULT, position=position, model="mdr")
response = core.add_node(session_id, n2)
n2_id = response.node_id
Example #9
0
# create grpc client and connect
core = client.CoreGrpcClient()
core.connect()

# create session and get id
response = core.create_session()
session_id = response.session_id

# change session state to configuration so that nodes get started when added
core.set_session_state(session_id, SessionState.CONFIGURATION)

# create emane node
position = Position(x=200, y=200)
emane = Node(type=NodeType.EMANE,
             position=position,
             emane=EmaneIeee80211abgModel.name)
response = core.add_node(session_id, emane)
emane_id = response.node_id

# create node one
position = Position(x=100, y=100)
n1 = Node(type=NodeType.DEFAULT, position=position, model="mdr")
response = core.add_node(session_id, n1)
n1_id = response.node_id

# create node two
position = Position(x=300, y=100)
n2 = Node(type=NodeType.DEFAULT, position=position, model="mdr")
response = core.add_node(session_id, n2)
n2_id = response.node_id