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 addremovectrlif(self, node, netidx=0, remove=False, conf_reqd=True): ''' Add a control interface to a node when a 'controlnet' prefix is listed in the config file or session options. Uses addremovectrlnet() to build or remove the control bridge. If conf_reqd is False, the control network may be built even when the user has not configured one (e.g. for EMANE.) ''' ctrlnet = self.addremovectrlnet(netidx, remove, conf_reqd) if ctrlnet is None: return if node is None: return if node.netif(ctrlnet.CTRLIF_IDX_BASE + netidx): return # ctrl# already exists ctrlip = node.objid try: addrlist = [ "%s/%s" % (ctrlnet.prefix.addr(ctrlip), ctrlnet.prefix.prefixlen) ] except ValueError: msg = "Control interface not added to node %s. " % node.objid msg += "Invalid control network prefix (%s). " % ctrlnet.prefix msg += "A longer prefix length may be required for this many nodes." node.exception(coreapi.CORE_EXCP_LEVEL_ERROR, "Session.addremovectrlif()", msg) return ifi = node.newnetif(net=ctrlnet, ifindex=ctrlnet.CTRLIF_IDX_BASE + netidx, ifname="ctrl%d" % netidx, hwaddr=MacAddr.random(), addrlist=addrlist) node.netif(ifi).control = True
def addremovectrlif(self, node, remove=False, conf_reqd=True): ''' Add a control interface to a node when a 'controlnet' prefix is listed in the config file or session options. Uses addremovectrlnet() to build or remove the control bridge. If conf_reqd is False, the control network may be built even when the user has not configured one (e.g. for EMANE.) ''' ctrlnet = self.addremovectrlnet(remove, conf_reqd) if ctrlnet is None: return if node is None: return if node.netif(ctrlnet.CTRLIF_IDX_BASE): return # ctrl0 already exists ctrlip = node.objid try: addrlist = ["%s/%s" % (ctrlnet.prefix.addr(ctrlip), ctrlnet.prefix.prefixlen)] except ValueError: msg = "Control interface not added to node %s. " % node.objid msg += "Invalid control network prefix (%s). " % ctrlnet.prefix msg += "A longer prefix length may be required for this many nodes." node.exception(coreapi.CORE_EXCP_LEVEL_ERROR, "Session.addremovectrlif()", msg) return ifi = node.newnetif(net = ctrlnet, ifindex = ctrlnet.CTRLIF_IDX_BASE, ifname = "ctrl0", hwaddr = MacAddr.random(), addrlist = addrlist) node.netif(ifi).control = True
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)