def set_mac(obj, mac): sc = get_component(obj).o.sc mac = mac_as_list(mac) idprom = sc.idprom for i in range(6): idprom[i] = mac[i] sc.idprom = idprom
def get_mac(obj): phys_mem = get_component(obj).master_cpu.physical_memory addr = 0x1FFF8909FD8 mac = [0] * 6 for i in range(6): mac[i] = read_memory(phys_mem, addr + 2 + i) return "%x:%x:%x:%x:%x:%x" % (mac[0], mac[1], mac[2], mac[3], mac[4], mac[5])
def cmos_floppy_cmd(obj, drive, drive_type): rtc = get_component(obj).rtc drive = string.upper(drive) if (drive != "A") and (drive != "B"): print "Only drive A and B supported" return try: type_num = disk_types.index(drive_type) except: print "Unknown disk type" print "Try one of:" print disk_types SIM_command_has_problem() return # high nibble drive 0, low drive 1 val = nvram_read(rtc, 0x10) if drive == "A": val = (type_num << 4) | (val & 0x0f) else: val = type_num | (val & 0xf0) nvram_write(rtc, 0x10, val) drives = 0 if val & 0xf0: drives = 1 if val & 0x0f: drives = drives + 1 # equipment byte: bit 6-7, number of disk drives val = (drives << 6) | (nvram_read(rtc, 0x14) & 0x3f) nvram_write(rtc, 0x14, val) cmos_checksum(rtc)
def get_prom_env(obj, env): system = get_component(obj) nvram = system.o.nvram_image key = env_list[env][0] diff_keys = get_diff_variables(nvram) if diff_keys.has_key(key): offset = diff_keys[key][2] + 7 # 4 + 1 + 2 int_len = diff_keys[key][1] - 7 elif key < variable_offset: offset = key int_len = env_list[env][1] else: # use default value return "%s" % env_list[env][3] if env_list[env][2] == "bool": return read_variable(nvram, env, offset) elif env_list[env][2] == "int": return "%d" % read_variable(nvram, env, offset, int_len) elif env_list[env][2] == "enum": return read_variable(nvram, env, offset) elif env_list[env][2] == "bytes": raise Exception, "Getting %s not supported" % env elif env_list[env][2] == "str": return read_variable(nvram, env, offset) elif env_list[env][2] == "rc": return read_variable(nvram, env, offset) else: raise Exception, "Error in 'get-prom-env' command"
def set_prom_env(obj, env, val_tuple): system = get_component(obj) try: set_env(system, env, val_tuple) except Exception, msg: print "Failed setting variable:", msg SIM_command_has_problem()
def cmos_hd_cmd(obj, drive, cylinders, heads, sectors_per_track): rtc = get_component(obj).rtc drive = string.upper(drive) if (drive != "C") and (drive != "D"): print "Only drive C and D supported" return drive_val = 0xf if (cylinders == 0) or (heads == 0) or (sectors_per_track == 0): if SIM_get_verbose(): print "[%s] No drive set on: %s" % (rtc.name, drive) drive_val = 0x0 cylinders = 0 heads = 0 sector_per_track = 0 # Type of hard drive. High nibble drive 0, low nibble drive 1 # Values: 0x0 - no drive, # 0x1 -> 0xe - different type numbers # 0xf - read in reg 0x19 instead (0x1a for drive 1). val = nvram_read(rtc, 0x12) if drive == "C": val = (drive_val << 4) | (val & 0x0f) drive_num = 0 else: val = (drive_val) | (val & 0xf0) drive_num = 1 nvram_write(rtc, 0x12, val) # HD <drive> type, use 47 if drive_val == 0: nvram_write(rtc, hd_regs[drive_num][0], 0x0) else: nvram_write(rtc, hd_regs[drive_num][0], 0x2f) # low and high cylinder word (number of cyls) nvram_write(rtc, hd_regs[drive_num][1], cylinders & 0xff) nvram_write(rtc, hd_regs[drive_num][2], (cylinders >> 8) & 0xff) # number of heads nvram_write(rtc, hd_regs[drive_num][3], heads) # low precomp cylinder, obsolete set to 0 nvram_write(rtc, hd_regs[drive_num][4], 0x00) nvram_write(rtc, hd_regs[drive_num][5], 0x00) # drive control, # bit 6, 7 == 0 # bit 5 - bad map at last cyl + 1, (not used) # bit 3 - more that 8 heads val = 0x00 if heads > 8: val = val | 0x08 nvram_write(rtc, hd_regs[drive_num][6], val) # low and high landing zone cyl, obsolete set to max cylinder + 1 nvram_write(rtc, hd_regs[drive_num][7], cylinders & 0xff) nvram_write(rtc, hd_regs[drive_num][8], (cylinders >> 8) & 0xff) # sectors per track nvram_write(rtc, hd_regs[drive_num][9], sectors_per_track) cmos_checksum(rtc)
def cmos_init_cmd(obj): rtc = get_component(obj).rtc # shutdown status, 0 normal startup nvram_write(rtc, 0x0f, 0x00) # equipment byte. # bit 6-7, number of disk drives, (set later) # bit 4-5, video: 0 - vga # bit 2, unused # bit 1, math coprocessor # bit 0, disk drive installed for boot nvram_write(rtc, 0x14, 0x07) # base memory in kB, always 640 nvram_write(rtc, 0x15, 640 & 0xff) nvram_write(rtc, 0x16, (640 >> 8) & 0xff) # system flags: # bit 5 - boot A: first, then C: - A is default nvram_write(rtc, 0x2d, 0x20) # default century cmos_century(rtc, 20) cmos_checksum(rtc)
def get_prom_env(obj, env): system = get_component(obj) base = 0x1FFF8908000 if env_list[env][2] == "bool": val = SIM_read_phys_memory(system.master_cpu, base + env_list[env][0], 1) if val == 0xFF: return "true" else: return "false" elif env_list[env][2] == "int": return "0x%x" % read_int_bytes(system.master_cpu, base + env_list[env][0], env_list[env][1]) elif env_list[env][2] == "enum": val = SIM_read_phys_memory(system.master_cpu, base + env_list[env][0], 1) try: lst = env_list[env][4] return lst.keys()[lst.values().index(val)] except KeyError: raise Exception, "Unkown enum value '%d'" % val elif env_list[env][2] == "bytes": raise Exception, "Getting %s not supported" % env elif env_list[env][2] == "str": return read_str_bytes(system.master_cpu, base + env_list[env][0]) elif env_list[env][2] == "rc": raise Exception, "Getting %s not supported" % env else: raise Exception, "Error in 'get-prom-env' command"
def get_mac(obj): nvram = get_component(obj).o.nvram_image base = 0x1fe0 return '%x:%x:%x:%x:%x:%x' % ( nvram.byte_access[base + 2], nvram.byte_access[base + 3], nvram.byte_access[base + 4], nvram.byte_access[base + 5], nvram.byte_access[base + 6], nvram.byte_access[base + 7])
def get_prom_env(obj, env): system = get_component(obj) base = 0x1fff8908000 if env_list[env][2] == "bool": val = SIM_read_phys_memory(system.master_cpu, base + env_list[env][0], 1) if val == 0xff: return "true" else: return "false" elif env_list[env][2] == "int": return "0x%x" % read_int_bytes( system.master_cpu, base + env_list[env][0], env_list[env][1]) elif env_list[env][2] == "enum": val = SIM_read_phys_memory(system.master_cpu, base + env_list[env][0], 1) try: lst = env_list[env][4] return lst.keys()[lst.values().index(val)] except KeyError: raise Exception, "Unkown enum value '%d'" % val elif env_list[env][2] == "bytes": raise Exception, "Getting %s not supported" % env elif env_list[env][2] == "str": return read_str_bytes(system.master_cpu, base + env_list[env][0]) elif env_list[env][2] == "rc": raise Exception, "Getting %s not supported" % env else: raise Exception, "Error in 'get-prom-env' command"
def get_hostid(obj): nvram = get_component(obj).o.nvram_image base = 0x1fe0 hostid = nvram.byte_access[base + 1] << 24 hostid |= nvram.byte_access[base + 12] << 16 hostid |= nvram.byte_access[base + 13] << 8 hostid |= nvram.byte_access[base + 14] return hostid
def get_hostid(obj): phys_mem = get_component(obj).master_cpu.physical_memory addr = 0x1FFF8909FD8 hostid = read_memory(phys_mem, addr + 1) << 24 hostid |= read_memory(phys_mem, addr + 12) << 16 hostid |= read_memory(phys_mem, addr + 13) << 8 hostid |= read_memory(phys_mem, addr + 14) return hostid
def get_hostid(obj): phys_mem = get_component(obj).master_cpu.physical_memory addr = 0x1fff8909fd8 hostid = read_memory(phys_mem, addr + 1) << 24 hostid |= read_memory(phys_mem, addr + 12) << 16 hostid |= read_memory(phys_mem, addr + 13) << 8 hostid |= read_memory(phys_mem, addr + 14) return hostid
def get_mac(obj): phys_mem = get_component(obj).master_cpu.physical_memory addr = 0x1fff8909fd8 mac = [0] * 6 for i in range(6): mac[i] = read_memory(phys_mem, addr + 2 + i) return '%x:%x:%x:%x:%x:%x' % (mac[0], mac[1], mac[2], mac[3], mac[4], mac[5])
def get_mac(obj): nvram = get_component(obj).o.nvram_image base = 0x1fe0 return '%x:%x:%x:%x:%x:%x' % (nvram.byte_access[base + 2], nvram.byte_access[base + 3], nvram.byte_access[base + 4], nvram.byte_access[base + 5], nvram.byte_access[base + 6], nvram.byte_access[base + 7])
def cmos_base_mem_cmd(obj, size): rtc = get_component(obj).rtc if size > 640: print "Larger than maximal value (640 kB), setting max." size = 640 # store size in kB nvram_write(rtc, 0x15, size & 0xff) nvram_write(rtc, 0x16, (size >> 8) & 0xff) cmos_checksum(rtc)
def cmos_extended_mem_cmd(obj, size): rtc = get_component(obj).rtc # store size in kB, saturate to 0xffff size_in_k = size * 1024 if size_in_k > 0xffff: size_in_k = 0xffff nvram_write(rtc, 0x17, size_in_k & 0xff) nvram_write(rtc, 0x18, (size_in_k >> 8) & 0xff) nvram_write(rtc, 0x30, size_in_k & 0xff) nvram_write(rtc, 0x31, (size_in_k >> 8) & 0xff) cmos_checksum(rtc)
def cmos_boot_dev_cmd(obj, drive): rtc = get_component(obj).rtc drive = string.upper(drive) if drive == "A": nvram_write(rtc, 0x2d, 0x20) elif drive == "C": nvram_write(rtc, 0x2d, 0x00) else: print "Only drive A and C supported as boot devices" return cmos_checksum(rtc)
def set_prom_env(obj, env, val_tuple): system = get_component(obj) check_variable_list(system) if not variable_list.has_key(env): print "Unknown OBP variable '%s'" % env SIM_command_has_problem() return try: val = str(val_tuple[1]) SIM_set_attribute(system.o.nvci, variable_list[env], val) except Exception, msg: print "Failed setting variable: %s" % msg SIM_command_has_problem()
def get_prom_env(obj, env): system = get_component(obj) check_variable_list(system) if env == "": lst = variable_list.keys() elif not variable_list.has_key(env): print "Unknown OBP variable '%s'" % env SIM_command_has_problem() return else: lst = [env] for i in lst: print "%-30s : %s" % ( i, SIM_get_attribute(system.o.nvci, variable_list[i]))
def cmos_info_cmd(obj): rtc = get_component(obj).rtc print print " Base memory : %5d kB" % ( (nvram_read(rtc, 0x16) << 8) | nvram_read(rtc, 0x15)) print "Extended memory (1): %5d kB" % ( (nvram_read(rtc, 0x18) << 8) | nvram_read(rtc, 0x17)) print "Extended memory (2): %5d kB" % ( (nvram_read(rtc, 0x31) << 8) | nvram_read(rtc, 0x30)) print print " Num floppy drives: %d" % ((nvram_read(rtc, 0x14) >> 6) & 0x3) try: atype = disk_types[nvram_read(rtc, 0x10) >> 4] except: atype = "Unknown" try: btype = disk_types[nvram_read(rtc, 0x10) & 0xf] except: btype = "Unknown" print " A: type: %s" % atype print " B: type: %s" % btype print drvtype = [] drvname = ["C", "D"] drvtype.append(nvram_read(rtc, 0x12) >> 4) drvtype.append(nvram_read(rtc, 0x12) & 0xf) for drv in range(0, 2): if drvtype[drv] == 0x0: print " %s: Drive type : No disk" % drvname[drv] elif drvtype[drv] != 0xf: print " %s: Drive type : 0x%02x (obsolete)" % (drvname[drv], drvtype[drv]) else: print " %s: Drive type : 0x%02x" % ( drvname[drv], nvram_read(rtc, hd_regs[drv][0])) print " Cylinders : %4d" % ( (nvram_read(rtc, hd_regs[drv][2]) << 8) | nvram_read(rtc, hd_regs[drv][1])) print " Heads : %4d" % nvram_read(rtc, hd_regs[drv][3]) print " Sectors per track : %4d" % nvram_read(rtc, hd_regs[drv][9]) print print if nvram_read(rtc, 0x2d) == 0x20: boot_dev = "A" elif nvram_read(rtc, 0x2d) == 0x00: boot_dev = "C" else: boot_dev = "Unknown" print " Boot device: %s" % boot_dev print
def get_prom_env(obj, env): system = get_component(obj) check_variable_list(system) if env == "": lst = variable_list.keys() elif not variable_list.has_key(env): print "Unknown OBP variable '%s'" % env SIM_command_has_problem() return else: lst = [env] for i in lst: print "%-30s : %s" % (i, SIM_get_attribute(system.o.nvci, variable_list[i]))
def set_env(obj, env, val_tuple, do_chk=1): system = get_component(obj) base = 0x1fff8908000 try: env_list[env] except: raise Exception, "Unknown OBP variable '%s'" % env if type(val_tuple) == type((0, )): if env_list[env][2] == "int" and val_tuple[2] != "int": raise Exception, "Variable needs integer argument" elif env_list[env][2] != "int" and val_tuple[2] == "int": raise Exception, "Variable needs string argument" val = val_tuple[1] else: val = val_tuple if env_list[env][2] == "bool": if val == "false": SIM_write_phys_memory(system.master_cpu, base + env_list[env][0], 0x00, 1) elif val == "true": SIM_write_phys_memory(system.master_cpu, base + env_list[env][0], 0xff, 1) else: raise Exception, "Illegal bool value '%s'" % val elif env_list[env][2] == "int": write_int_bytes(system.master_cpu, base + env_list[env][0], val, env_list[env][1]) elif env_list[env][2] == "enum": lst = env_list[env][4] try: SIM_write_phys_memory(system.master_cpu, base + env_list[env][0], lst[val], 1) except KeyError: raise Exception, "Could not set enum to '%s'" % val elif env_list[env][2] == "bytes": raise Exception, "Setting %s not supported" % env elif env_list[env][2] == "str": if (len(val) + 1) > env_list[env][1]: raise Exception, "String too long, max %d" % (env_list[env][1] - 1) return write_str_bytes(system.master_cpu, base + env_list[env][0], val) elif env_list[env][2] == "rc": raise Exception, "Setting %s not supported" % env else: raise Exception, "%s is UNKNOWN %s" % (env, env_list[env][2]) if do_chk != 0: update_eeprom_checksum(system)
def set_default_nvram(obj): system = get_component(obj) nvram = system.o.nvram_image if read_int_bytes(nvram, variable_offset, 4) == start_key: # already initialized? (e.g. from an image file) print "Skipping nvram init." return write_int_bytes(nvram, variable_offset + 0, start_key, 4) write_int_bytes(nvram, variable_offset + 4, reboot_key, 4) write_int_bytes(nvram, variable_offset + 8, stop_key, 4) for env in env_list.keys(): if env_list[env][0] >= variable_offset: # skip default values for 'non-fixed' variables continue if env_list[env][3] != "@n/a@": set_env(system, env, env_list[env][3]) update_eeprom_checksum(nvram)
def set_env(obj, env, val_tuple, do_chk=1): system = get_component(obj) base = 0x1FFF8908000 try: env_list[env] except: raise Exception, "Unknown OBP variable '%s'" % env if type(val_tuple) == type((0,)): if env_list[env][2] == "int" and val_tuple[2] != "int": raise Exception, "Variable needs integer argument" elif env_list[env][2] != "int" and val_tuple[2] == "int": raise Exception, "Variable needs string argument" val = val_tuple[1] else: val = val_tuple if env_list[env][2] == "bool": if val == "false": SIM_write_phys_memory(system.master_cpu, base + env_list[env][0], 0x00, 1) elif val == "true": SIM_write_phys_memory(system.master_cpu, base + env_list[env][0], 0xFF, 1) else: raise Exception, "Illegal bool value '%s'" % val elif env_list[env][2] == "int": write_int_bytes(system.master_cpu, base + env_list[env][0], val, env_list[env][1]) elif env_list[env][2] == "enum": lst = env_list[env][4] try: SIM_write_phys_memory(system.master_cpu, base + env_list[env][0], lst[val], 1) except KeyError: raise Exception, "Could not set enum to '%s'" % val elif env_list[env][2] == "bytes": raise Exception, "Setting %s not supported" % env elif env_list[env][2] == "str": if (len(val) + 1) > env_list[env][1]: raise Exception, "String too long, max %d" % (env_list[env][1] - 1) return write_str_bytes(system.master_cpu, base + env_list[env][0], val) elif env_list[env][2] == "rc": raise Exception, "Setting %s not supported" % env else: raise Exception, "%s is UNKNOWN %s" % (env, env_list[env][2]) if do_chk != 0: update_eeprom_checksum(system)
def cmos_info_cmd(obj): rtc = get_component(obj).rtc print print " Base memory : %5d kB" % ((nvram_read(rtc, 0x16) << 8) | nvram_read(rtc, 0x15)) print "Extended memory (1): %5d kB" % ((nvram_read(rtc, 0x18) << 8) | nvram_read(rtc, 0x17)) print "Extended memory (2): %5d kB" % ((nvram_read(rtc, 0x31) << 8) | nvram_read(rtc, 0x30)) print print " Num floppy drives: %d" % ((nvram_read(rtc, 0x14) >> 6) & 0x3) try: atype = disk_types[nvram_read(rtc, 0x10) >> 4] except: atype = "Unknown" try: btype = disk_types[nvram_read(rtc, 0x10) & 0xf] except: btype = "Unknown" print " A: type: %s" % atype print " B: type: %s" % btype print drvtype = [] drvname = ["C", "D"] drvtype.append(nvram_read(rtc, 0x12) >> 4) drvtype.append(nvram_read(rtc, 0x12) & 0xf) for drv in range(0, 2): if drvtype[drv] == 0x0: print " %s: Drive type : No disk" % drvname[drv] elif drvtype[drv] != 0xf: print " %s: Drive type : 0x%02x (obsolete)" % (drvname[drv], drvtype[drv]) else: print " %s: Drive type : 0x%02x" % (drvname[drv], nvram_read(rtc, hd_regs[drv][0])) print " Cylinders : %4d" % ((nvram_read(rtc, hd_regs[drv][2]) << 8) | nvram_read(rtc, hd_regs[drv][1])) print " Heads : %4d" % nvram_read(rtc, hd_regs[drv][3]) print " Sectors per track : %4d" % nvram_read(rtc, hd_regs[drv][9]) print print if nvram_read(rtc, 0x2d) == 0x20: boot_dev = "A" elif nvram_read(rtc, 0x2d) == 0x00: boot_dev = "C" else: boot_dev = "Unknown" print " Boot device: %s" % boot_dev print
def write_idprom_to_nvram(obj, hostid, mac): phys_mem = get_component(obj).master_cpu.physical_memory addr = 0x1FFF8909FD8 # offset 0 = format (1) write_memory(phys_mem, addr + 0, 1, 1) if hostid: # offset 1, 12-14 = hostid write_memory(phys_mem, addr + 1, hostid >> 24, 1) write_memory(phys_mem, addr + 12, hostid >> 16, 1) write_memory(phys_mem, addr + 13, hostid >> 8, 1) write_memory(phys_mem, addr + 14, hostid >> 0, 1) if mac: # offset 2 - 7 = ethernet mac = mac_as_list(mac) for i in range(len(mac)): write_memory(phys_mem, addr + 2 + i, mac[i], 1) # offset 8 - 11 = date (not used) # offset 15 = checksum chk = 0 for i in range(15): chk ^= read_memory(phys_mem, addr + i) write_memory(phys_mem, addr + 15, chk, 1)
def write_idprom_to_nvram(obj, hostid, mac): nvram = get_component(obj).o.nvram_image base = 0x1fe0 # offset 0 = format (1) nvram.byte_access[base + 0] = 1 if hostid: # offset 1, 12-14 = hostid nvram.byte_access[base + 1] = (hostid >> 24) & 0xff nvram.byte_access[base + 12] = (hostid >> 16) & 0xff nvram.byte_access[base + 13] = (hostid >> 8) & 0xff nvram.byte_access[base + 14] = (hostid >> 0) & 0xff if mac: # offset 2 - 7 = ethernet mac = mac_as_list(mac) for i in range(len(mac)): nvram.byte_access[base + 2 + i] = mac[i] # offset 8 - 11 = date (not used?) # offset 15 = checksum chk = 0 for i in range(15): chk ^= nvram.byte_access[base + i] nvram.byte_access[base + 15] = chk & 0xff
def load(cls, filename, min_width, min_height): f = open(filename, 'r') grid = [] for line in f: row = [] for char in line.strip("\n"): cls_symbol = get_component(char) row.append(cls_symbol.get_empty()) if row: if len(row) < min_width: row.extend([ Empty.get_empty() for i in range(min_width - len(row)) ]) grid.append(row) if len(grid) < min_height: for i in range(min_height - len(grid)): grid.append([Empty.get_empty() for o in range(min_width)]) g = Grid(len(grid[0]), len(grid)) g.grid = grid g.link() f.close() return g
def write_idprom_to_nvram(obj, hostid, mac): phys_mem = get_component(obj).master_cpu.physical_memory addr = 0x1fff8909fd8 # offset 0 = format (1) write_memory(phys_mem, addr + 0, 1, 1) if hostid: # offset 1, 12-14 = hostid write_memory(phys_mem, addr + 1, hostid >> 24, 1) write_memory(phys_mem, addr + 12, hostid >> 16, 1) write_memory(phys_mem, addr + 13, hostid >> 8, 1) write_memory(phys_mem, addr + 14, hostid >> 0, 1) if mac: # offset 2 - 7 = ethernet mac = mac_as_list(mac) for i in range(len(mac)): write_memory(phys_mem, addr + 2 + i, mac[i], 1) # offset 8 - 11 = date (not used) # offset 15 = checksum chk = 0 for i in range(15): chk ^= read_memory(phys_mem, addr + i) write_memory(phys_mem, addr + 15, chk, 1)
def get_service_node(link, tgt_ip, sn_ip, create_sn): queue = get_first_queue() # may raise exception link_created = 0 sn_cmp = None if not link: links = [ x for x in SIM_all_objects() if instance_of(x, "ethernet-link") ] if len(links) > 1: SIM_command_has_problem() print("There are more than one ethernet-link, please specify " + "which one the simulated machine is connected to.") raise Exception elif len(links) == 0: # create component SIM_get_class('std-ethernet-link') basename = component_basename('std-ethernet-link') link_cmp = SIM_create_object('std-ethernet-link', get_available_object_name(basename), []) instantiate_cmd(False, [link_cmp]) link = get_component_object(link_cmp, "link") link_created = 1 if SIM_is_interactive(): print "No ethernet-link found, creating '%s'." % link.name else: link = links[0] link_cmp = link.component # find service nodes on link sns = [ x.service_node for x in SIM_all_objects() if instance_of(x, "service-node-device") and x.link == link ] if len(sns) == 0: if not create_sn: return None if not sn_ip: if not tgt_ip: return None sn_ip = inet_ntoa(inet_aton(tgt_ip)[0:3] + '\x01') # create component SIM_get_class('std-service-node') basename = component_basename('std-service-node') sn_cmp = SIM_create_object('std-service-node', get_available_object_name(basename), []) instantiate_cmd(False, [sn_cmp]) get_component(sn_cmp).add_connector(sn_ip, "255.255.255.0") sn = get_component_object(sn_cmp, "sn") if SIM_is_interactive(): print("No service-node found, creating '%s' with IP '%s'." % (sn.name, sn_ip)) else: sn = sns[0] if sn_ip and sn_ip != get_sn_ip(sn, link): print("Using already existing service node with IP %s." % get_sn_ip(sn, link)) if len(sns) > 1: print "More than one service-node, using '%s'." % sn.name # connect devices to our newly created link if link_created: devs = [ x for x in SIM_all_objects() if instance_of(x, "ethernet_device") ] for dev in devs: if not dev.link: dev_cmp = dev.component if dev_cmp and link_cmp: if components_connected(dev_cmp, link_cmp): continue # connect using components connect_cmd(link_cmp, None, dev_cmp, None, True) print("Connecting component '%s' to '%s'" % (dev_cmp.name, link_cmp.name)) else: dev.link = link print("Connecting device '%s' to '%s'" % (dev.name, link.name)) elif sn_cmp: # a service-node component was created, but no link if link_cmp: # connect using components connect_cmd(link_cmp, None, sn_cmp, None, True) print("Connecting component '%s' to '%s'" % (sn_cmp.name, link_cmp.name)) else: snd = [ x for x in SIM_all_objects() if (instance_of(x, "service-node-device") and x.service_node == sn and x.ip_address == sn_ip and x.netmask == "255.255.255.0") ][0] snd.link = link print("Connecting device '%s' to '%s'" % (snd.name, link.name)) return (link, sn)
def var_expand(string, obj): system = get_component(obj) check_variable_list(system) return get_completions(string, variable_list.keys())
def get_service_node(link, tgt_ip, sn_ip, create_sn): queue = get_first_queue() # may raise exception link_created = 0 sn_cmp = None if not link: links = [x for x in SIM_all_objects() if instance_of(x, "ethernet-link")] if len(links) > 1: SIM_command_has_problem() print ("There are more than one ethernet-link, please specify " + "which one the simulated machine is connected to.") raise Exception elif len(links) == 0: # create component SIM_get_class('std-ethernet-link') basename = component_basename('std-ethernet-link') link_cmp = SIM_create_object( 'std-ethernet-link', get_available_object_name(basename), []) instantiate_cmd(False, [link_cmp]) link = get_component_object(link_cmp, "link") link_created = 1 if SIM_is_interactive(): print "No ethernet-link found, creating '%s'." % link.name else: link = links[0] link_cmp = link.component # find service nodes on link sns = [x.service_node for x in SIM_all_objects() if instance_of(x, "service-node-device") and x.link == link] if len(sns) == 0: if not create_sn: return None if not sn_ip: if not tgt_ip: return None sn_ip = inet_ntoa(inet_aton(tgt_ip)[0:3] + '\x01') # create component SIM_get_class('std-service-node') basename = component_basename('std-service-node') sn_cmp = SIM_create_object( 'std-service-node', get_available_object_name(basename), []) instantiate_cmd(False, [sn_cmp]) get_component(sn_cmp).add_connector(sn_ip, "255.255.255.0") sn = get_component_object(sn_cmp, "sn") if SIM_is_interactive(): print ("No service-node found, creating '%s' with IP '%s'." % (sn.name, sn_ip)) else: sn = sns[0] if sn_ip and sn_ip != get_sn_ip(sn, link): print ("Using already existing service node with IP %s." % get_sn_ip(sn, link)) if len(sns) > 1: print "More than one service-node, using '%s'." % sn.name # connect devices to our newly created link if link_created: devs = [x for x in SIM_all_objects() if instance_of(x, "ethernet_device")] for dev in devs: if not dev.link: dev_cmp = dev.component if dev_cmp and link_cmp: if components_connected(dev_cmp, link_cmp): continue # connect using components connect_cmd(link_cmp, None, dev_cmp, None, True) print ("Connecting component '%s' to '%s'" % (dev_cmp.name, link_cmp.name)) else: dev.link = link print ("Connecting device '%s' to '%s'" % (dev.name, link.name)) elif sn_cmp: # a service-node component was created, but no link if link_cmp: # connect using components connect_cmd(link_cmp, None, sn_cmp, None, True) print ("Connecting component '%s' to '%s'" % (sn_cmp.name, link_cmp.name)) else: snd = [x for x in SIM_all_objects() if (instance_of(x, "service-node-device") and x.service_node == sn and x.ip_address == sn_ip and x.netmask == "255.255.255.0")][0] snd.link = link print ("Connecting device '%s' to '%s'" % (snd.name, link.name)) return (link, sn)
def get_mac(obj): sc = get_component(obj).o.sc return '%x:%x:%x:%x:%x:%x' % (sc.idprom[0], sc.idprom[1], sc.idprom[2], sc.idprom[3], sc.idprom[4], sc.idprom[5])
def set_hostid(obj, hostid): sc = get_component(obj).o.sc idprom = sc.idprom for i in range(4): idprom[10 + i] = hostid >> (24 - i * 8) sc.idprom = idprom
def get_hostid(obj): sc = get_component(obj).o.sc hostid = 0 for i in range(4): hostid |= sc.idprom[10 + i] << (24 - i * 8) return hostid
def set_default_nvram(obj): for env in env_list.keys(): if env_list[env][3] != "@n/a@": set_env(obj, env, env_list[env][3], 0) update_eeprom_checksum(get_component(obj))