Ejemplo n.º 1
0
    def new_obj(value):
        """
        Retrieve Ipv6 address from a string representation.

        :param str value: value to get Ipv4 address from
        :return: Ipv4 address
        :rtype: core.nodes.ipaddress.IpAddress
        """
        return IpAddress(af=socket.AF_INET6, address=value)
Ejemplo n.º 2
0
    def test_tunnel(self, cored, distributed_address):
        """
        Test session broker creation.

        :param core.coreserver.CoreServer conftest.Core cored: core daemon server to test with
        :param str distributed_address: distributed server to test against
        """
        # initialize server for testing
        cored.setup(distributed_address)

        # create local node
        message = conftest.node_message(
            _id=1,
            name="n1",
            model="host"
        )
        cored.request_handler.handle_message(message)

        # create distributed node and assign to distributed server
        message = conftest.node_message(
            _id=2,
            name=distributed_address,
            emulation_server=cored.distributed_server,
            node_type=NodeTypes.TUNNEL
        )
        cored.request_handler.handle_message(message)

        # link message one
        ip4_address = cored.prefix.addr(1)
        address_two = IpAddress.from_string(distributed_address)
        message = conftest.link_message(
            n1=1,
            n2=2,
            intf_one=0,
            address_one=ip4_address,
            intf_two=0,
            address_two=address_two,
            key=1
        )
        cored.request_handler.handle_message(message)

        # change session to instantiation state
        message = conftest.state_message(EventTypes.INSTANTIATION_STATE)
        cored.request_handler.handle_message(message)
Ejemplo n.º 3
0
    def installphysnodes(self, net):
        """
        After installing a mobility model on a net, include any physical
        nodes that we have recorded. Use the GreTap tunnel to the physical node
        as the node's interface.

        :param net: network to install
        :return: nothing
        """
        node_ids = self.physnets.get(net.id, [])
        for node_id in node_ids:
            node = self.phys[node_id]
            # TODO: fix this bad logic, relating to depending on a break to get a valid server
            for server in self.session.broker.getserversbynode(node_id):
                break
            netif = self.session.broker.gettunnel(
                net.id, IpAddress.to_int(server.host))
            node.addnetif(netif, 0)
            netif.node = node
            x, y, z = netif.node.position.get()
            netif.poshook(netif, x, y, z)
Ejemplo n.º 4
0
    def create_gre_tunnel(self, node, server):
        """
        Create gre tunnel using a pair of gre taps between the local and remote server.


        :param core.nodes.network.CoreNetwork node: node to create gre tunnel for
        :param core.emulator.distributed.DistributedServer server: server to create
            tunnel for
        :return: local and remote gre taps created for tunnel
        :rtype: tuple
        """
        host = server.host
        key = self.tunnel_key(node.id, IpAddress.to_int(host))
        tunnel = self.tunnels.get(key)
        if tunnel is not None:
            return tunnel

        # local to server
        logging.info("local tunnel node(%s) to remote(%s) key(%s)", node.name,
                     host, key)
        local_tap = GreTap(session=self.session, remoteip=host, key=key)
        local_tap.net_client.create_interface(node.brname, local_tap.localname)

        # server to local
        logging.info("remote tunnel node(%s) to local(%s) key(%s)", node.name,
                     self.address, key)
        remote_tap = GreTap(session=self.session,
                            remoteip=self.address,
                            key=key,
                            server=server)
        remote_tap.net_client.create_interface(node.brname,
                                               remote_tap.localname)

        # save tunnels for shutdown
        tunnel = (local_tap, remote_tap)
        self.tunnels[key] = tunnel
        return tunnel
Ejemplo n.º 5
0
    def addnettunnel(self, node_id):
        """
        Add network tunnel between node and broker.

        :param int node_id: node id of network to add tunnel to
        :return: list of gre taps
        :rtype: list
        """
        try:
            net = self.session.get_node(node_id)
            logging.info("adding net tunnel for: id(%s) %s", node_id, net)
        except KeyError:
            raise KeyError("network node %s not found" % node_id)

        # add other nets here that do not require tunnels
        if nodeutils.is_node(net, NodeTypes.EMANE_NET):
            logging.warning("emane network does not require a tunnel")
            return None

        server_interface = getattr(net, "serverintf", None)
        if nodeutils.is_node(
                net, NodeTypes.CONTROL_NET) and server_interface is not None:
            logging.warning(
                "control networks with server interfaces do not need a tunnel")
            return None

        servers = self.getserversbynode(node_id)
        if len(servers) < 2:
            logging.warning("not enough servers to create a tunnel: %s",
                            servers)
            return None

        hosts = []
        for server in servers:
            if server.host is None:
                continue
            logging.info("adding server host for net tunnel: %s", server.host)
            hosts.append(server.host)

        if len(hosts) == 0:
            for session_client in self.session_clients:
                # get IP address from API message sender (master)
                if session_client.client_address != "":
                    address = session_client.client_address[0]
                    logging.info("adding session_client host: %s", address)
                    hosts.append(address)

        r = []
        for host in hosts:
            if self.myip:
                # we are the remote emulation server
                myip = self.myip
            else:
                # we are the session master
                myip = host
            key = self.tunnelkey(node_id, IpAddress.to_int(myip))
            if key in self.tunnels.keys():
                logging.info(
                    "tunnel already exists, returning existing tunnel: %s",
                    key)
                gt = self.tunnels[key]
                r.append(gt)
                continue
            logging.info("adding tunnel for net %s to %s with key %s", node_id,
                         host, key)
            gt = GreTap(node=None,
                        name=None,
                        session=self.session,
                        remoteip=host,
                        key=key)
            self.tunnels[key] = gt
            r.append(gt)
            # attaching to net will later allow gt to be destroyed
            # during net.shutdown()
            net.attach(gt)

        return r