def parse_interface(self, node, device_id, interface): '''\ Each interface can have multiple 'address' elements. ''' if_name = interface.getAttribute('name') network = self.find_interface_network_object(interface) if not network: msg = 'skipping node \'%s\' interface \'%s\': ' \ 'unknown network' % (node.name, if_name) self.warn(msg) assert False # XXX for testing return mac, ipv4, ipv6, hostname = self.parse_addresses(interface) if mac: hwaddr = MacAddr.fromstring(mac[0]) else: hwaddr = None ifindex = node.newnetif(network, addrlist=ipv4 + ipv6, hwaddr=hwaddr, ifindex=None, ifname=if_name) # TODO: 'hostname' addresses are unused if self.verbose: msg = 'node \'%s\' interface \'%s\' connected ' \ 'to network \'%s\'' % (node.name, if_name, network.name) self.info(msg) # set link parameters for wired links if isinstance(network, (nodes.HubNode, nodes.PtpNet, nodes.SwitchNode)): netif = node.netif(ifindex) self.set_wired_link_parameters(network, netif, device_id)
def parse_interface(self, node, device_id, interface): '''\ Each interface can have multiple 'address' elements. ''' if_name = interface.getAttribute('name') network = self.find_interface_network_object(interface) if not network: msg = 'skipping node \'%s\' interface \'%s\': ' \ 'unknown network' % (node.name, if_name) self.warn(msg) assert False # XXX for testing return mac, ipv4, ipv6, hostname = self.parse_addresses(interface) if mac: hwaddr = MacAddr.fromstring(mac[0]) else: hwaddr = None ifindex = node.newnetif(network, addrlist = ipv4 + ipv6, hwaddr = hwaddr, ifindex = None, ifname = if_name) # TODO: 'hostname' addresses are unused if self.verbose: msg = 'node \'%s\' interface \'%s\' connected ' \ 'to network \'%s\'' % (node.name, if_name, network.name) self.info(msg) # set link parameters for wired links if isinstance(network, (nodes.HubNode, nodes.PtpNet, nodes.SwitchNode)): netif = node.netif(ifindex) self.set_wired_link_parameters(network, netif, device_id)
def buildplatformxml(self): ''' Build a platform.xml file now that all nodes are configured. ''' values = self.getconfig(None, "emane", self.emane_config.getdefaultvalues())[1] doc = self.xmldoc("platform") plat = doc.getElementsByTagName("platform").pop() platformid = self.emane_config.valueof("platform_id_start", values) plat.setAttribute("name", "Platform %s" % platformid) plat.setAttribute("id", platformid) names = list(self.emane_config.getnames()) platform_names = names[:len(self.emane_config._confmatrix_platform)] platform_names.remove('platform_id_start') # append all platform options (except starting id) to doc list([plat.appendChild(self.xmlparam(doc, n, \ self.emane_config.valueof(n, values))) for n in platform_names]) nemid = int(self.emane_config.valueof("nem_id_start", values)) # assume self._objslock is already held here for n in sorted(self._objs.keys()): emanenode = self._objs[n] nems = emanenode.buildplatformxmlentry(doc) for netif in sorted(nems, key=lambda n: n.node.objid): # set ID, endpoints here nementry = nems[netif] nementry.setAttribute("id", "%d" % nemid) # insert nem options (except nem id) to doc trans_addr = self.emane_config.valueof("transportendpoint", \ values) nementry.insertBefore(self.xmlparam(doc, "transportendpoint", \ "%s:%d" % (trans_addr, self.transformport)), nementry.firstChild) platform_addr = self.emane_config.valueof("platformendpoint", \ values) nementry.insertBefore(self.xmlparam(doc, "platformendpoint", \ "%s:%d" % (platform_addr, self.platformport)), nementry.firstChild) plat.appendChild(nementry) emanenode.setnemid(netif, nemid) # NOTE: MAC address set before here is incorrect, including the one # sent from the GUI via link message # MAC address determined by NEM ID: 02:02:00:00:nn:nn" macstr = self._hwaddr_prefix + ":00:00:" macstr += "%02X:%02X" % ((nemid >> 8) & 0xFF, nemid & 0xFF) netif.sethwaddr(MacAddr.fromstring(macstr)) # increment counters used to manage IDs, endpoint port numbers nemid += 1 self.platformport += 1 self.transformport += 1 self.xmlwrite(doc, "platform.xml")
def ourmacaddress(n): return MacAddr.fromstring("02:02:00:00:00:%02x" % n)