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)
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
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