def link_interface(interface_proto): """ Create interface data from interface proto. :param core_pb2.Interface interface_proto: interface proto :return: interface data :rtype: InterfaceData """ interface = None if interface_proto: name = interface_proto.name if name == "": name = None mac = interface_proto.mac if mac == "": mac = None else: mac = MacAddress.from_string(mac) interface = InterfaceData( _id=interface_proto.id, name=name, mac=mac, ip4=interface_proto.ip4, ip4_mask=interface_proto.ip4mask, ip6=interface_proto.ip6, ip6_mask=interface_proto.ip6mask, ) return interface
def create_interface_data(interface_element): interface_id = int(interface_element.get("id")) name = interface_element.get("name") mac = interface_element.get("mac") if mac: mac = MacAddress.from_string(mac) ip4 = interface_element.get("ip4") ip4_mask = get_int(interface_element, "ip4_mask") ip6 = interface_element.get("ip6") ip6_mask = get_int(interface_element, "ip6_mask") return InterfaceData(interface_id, name, mac, ip4, ip4_mask, ip6, ip6_mask)
def build_node_platform_xml(emane_manager, control_net, node, nem_id, platform_xmls): """ Create platform xml for a specific node. :param core.emane.emanemanager.EmaneManager emane_manager: emane manager with emane configurations :param core.nodes.network.CtrlNet control_net: control net node for this emane network :param core.emane.nodes.EmaneNode node: node to write platform xml for :param int nem_id: nem id to use for interfaces for this node :param dict platform_xmls: stores platform xml elements to append nem entries to :return: the next nem id that can be used for creating platform xml files :rtype: int """ logging.debug( "building emane platform xml for node(%s) nem_id(%s): %s", node, nem_id, node.name, ) nem_entries = {} if node.model is None: logging.warning("warning: EmaneNode %s has no associated model", node.name) return nem_entries for netif in node.netifs(): logging.debug("building platform xml for interface(%s) nem_id(%s)", netif.name, nem_id) # build nem xml nem_definition = nem_file_name(node.model, netif) nem_element = etree.Element("nem", id=str(nem_id), name=netif.localname, definition=nem_definition) # check if this is an external transport, get default config if an interface specific one does not exist config = emane_manager.getifcconfig(node.model.id, netif, node.model.name) if is_external(config): nem_element.set("transport", "external") platform_endpoint = "platformendpoint" add_param(nem_element, platform_endpoint, config[platform_endpoint]) transport_endpoint = "transportendpoint" add_param(nem_element, transport_endpoint, config[transport_endpoint]) else: # build transport xml transport_type = netif.transport_type if not transport_type: logging.info("warning: %s interface type unsupported!", netif.name) transport_type = "raw" transport_file = transport_file_name(node.id, transport_type) transport_element = etree.SubElement(nem_element, "transport", definition=transport_file) # add transport parameter add_param(transport_element, "device", netif.name) # add nem entry nem_entries[netif] = nem_element # merging code key = netif.node.id if netif.transport_type == "raw": key = "host" otadev = control_net.brname eventdev = control_net.brname else: otadev = None eventdev = None platform_element = platform_xmls.get(key) if platform_element is None: platform_element = etree.Element("platform") if otadev: emane_manager.set_config("otamanagerdevice", otadev) if eventdev: emane_manager.set_config("eventservicedevice", eventdev) # append all platform options (except starting id) to doc for configuration in emane_manager.emane_config.emulator_config: name = configuration.id if name == "platform_id_start": continue value = emane_manager.get_config(name) add_param(platform_element, name, value) # add platform xml platform_xmls[key] = platform_element platform_element.append(nem_element) node.setnemid(netif, nem_id) macstr = _hwaddr_prefix + ":00:00:" macstr += "%02X:%02X" % ((nem_id >> 8) & 0xFF, nem_id & 0xFF) netif.sethwaddr(MacAddress.from_string(macstr)) # increment nem id nem_id += 1 for key in sorted(platform_xmls.keys()): if key == "host": file_name = "platform.xml" else: file_name = "platform%d.xml" % key platform_element = platform_xmls[key] doc_name = "platform" file_path = os.path.join(emane_manager.session.session_dir, file_name) create_file(platform_element, doc_name, file_path) return nem_id
def AddLink(self, request, context): logging.debug("add link: %s", request) session = self.get_session(request.session_id, context) # validate node exist self.get_node(session, request.link.node_one_id, context) self.get_node(session, request.link.node_two_id, context) node_one_id = request.link.node_one_id node_two_id = request.link.node_two_id interface_one = None interface_one_data = request.link.interface_one if interface_one_data: name = interface_one_data.name if name == "": name = None mac = interface_one_data.mac if mac == "": mac = None else: mac = MacAddress.from_string(mac) interface_one = InterfaceData( _id=interface_one_data.id, name=name, mac=mac, ip4=interface_one_data.ip4, ip4_mask=interface_one_data.ip4mask, ip6=interface_one_data.ip6, ip6_mask=interface_one_data.ip6mask, ) interface_two = None interface_two_data = request.link.interface_two if interface_two_data: name = interface_two_data.name if name == "": name = None mac = interface_two_data.mac if mac == "": mac = None else: mac = MacAddress.from_string(mac) interface_two = InterfaceData( _id=interface_two_data.id, name=name, mac=mac, ip4=interface_two_data.ip4, ip4_mask=interface_two_data.ip4mask, ip6=interface_two_data.ip6, ip6_mask=interface_two_data.ip6mask, ) link_type = None link_type_value = request.link.type if link_type_value is not None: link_type = LinkTypes(link_type_value) options_data = request.link.options link_options = LinkOptions(_type=link_type) if options_data: link_options.delay = options_data.delay link_options.bandwidth = options_data.bandwidth link_options.per = options_data.per link_options.dup = options_data.dup link_options.jitter = options_data.jitter link_options.mer = options_data.mer link_options.burst = options_data.burst link_options.mburst = options_data.mburst link_options.unidirectional = options_data.unidirectional link_options.key = options_data.key link_options.opaque = options_data.opaque session.add_link(node_one_id, node_two_id, interface_one, interface_two, link_options=link_options) return core_pb2.AddLinkResponse(result=True)