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_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)
obj = get_component_object(obj_cmp, obj_name) else: # support component-less configurations obj = SIM_create_object(classname, newname, attribs + [["queue", SIM_current_processor()]]) except Exception, msg: print "Failed creating %s '%s': %s" % (classname, newname, msg) raise CliError SIM_set_attribute(obj, "break-string", breakpoints) if dev.component: disconnect_cmd(dev.component, None, con.component, None) connectors = [x for x in dev.component.connectors if dev.component.connectors[x]["type"] == "serial"] free_cnt = sorted([x for x in connectors if x not in [y[0] for y in dev.component.connections]]) for cnt in free_cnt: connect_cmd(dev.component, cnt, obj.component, None, True) if "console" in dir(sim.objects[dev.name]) and dev.console: break # correct connector! if "link" in dir(sim.objects[dev.name]) and dev.link: break # correct connector! disconnect_cmd(dev.component, cnt, obj.component, None, True) else: dev.console = obj VT_hap_replace_object_references(con, obj) if con.component: try: SIM_delete_object(con.component) except: print ("Failed removing existing console component '%s'" % con.component.name)
attribs + [['queue', SIM_current_processor()]]) except Exception, msg: print "Failed creating %s '%s': %s" % (classname, newname, msg) raise CliError SIM_set_attribute(obj, "break-string", breakpoints) if dev.component: disconnect_cmd(dev.component, None, con.component, None) connectors = [x for x in dev.component.connectors if dev.component.connectors[x]['type'] == 'serial'] free_cnt = sorted([x for x in connectors if x not in [y[0] for y in dev.component.connections]]) for cnt in free_cnt: connect_cmd(dev.component, cnt, obj.component, None, True) if 'console' in dir(sim.objects[dev.name]) and dev.console: break # correct connector! if 'link' in dir(sim.objects[dev.name]) and dev.link: break # correct connector! disconnect_cmd(dev.component, cnt, obj.component, None, True) else: dev.console = obj VT_hap_replace_object_references(con, obj) if con.component: try: SIM_delete_object(con.component) except: print ("Failed removing existing console component '%s'"