igor@34: #### igor@34: # igor@34: # External variables: igor@34: # * network igor@34: # * domain igor@34: igor@35: try: igor@35: domain igor@35: except NameError: igor@35: import sys igor@35: network=sys.modules['__main__'].network igor@35: domain=sys.modules['__main__'].domain igor@34: igor@61: import os igor@61: nata@36: sys.path.append(os.environ['HOME']+"/xentaur") igor@63: sys.path.append('.') nata@36: os.environ['xendomain']=domain nata@36: igor@58: igor@58: igor@47: igor@47: ############################ igor@47: # default values: igor@58: platform='' igor@47: npe_type='npe-400' igor@47: bridge_bridge_table = { igor@47: } igor@47: igor@61: #try: igor@61: # domains igor@61: #except: igor@61: # domains=[] igor@61: igor@61: igor@58: domains_brief=[] igor@58: domain_types=[] igor@58: domain_notes=[] igor@58: domain_subtypes=[] igor@47: hidden_bridges = [] igor@47: broken_links = [] igor@47: temporary_links = [] igor@60: cross_bridges=[] igor@47: real_bridges=[] igor@47: real_nodes=[] igor@61: connection_table={} igor@61: igor@61: exec 'from %s import *' % (network) igor@61: igor@58: # overriden by network config igor@47: ############################ igor@47: igor@58: def process_domains_brief(): igor@61: # import sre igor@61: #global domains_brief, domains, domain_types, real_nodes, domain_notes, domain_subtypes igor@61: if len(domains_brief) >0 : igor@61: node_brief_re=sre.compile('([a-zA-Z_0-9-]*)(?::([a-zA-Z_0-9-]*))?(?::([a-zA-Z_0-9-]*))?(\*?)(?:#(.*))?') igor@61: if len(domains)==0: igor@61: domains=map(lambda x:node_brief_re.search(x).groups()[0] or '', domains_brief) igor@61: if len(domain_types)==0: igor@61: domain_types=map(lambda x:node_brief_re.search(x).groups()[1] or '', domains_brief) igor@61: if len(domain_subtypes)==0: igor@61: domain_subtypes=map(lambda x:node_brief_re.search(x).groups()[2] or '', domains_brief) igor@61: if len(real_nodes)==0: igor@61: i=0 igor@61: for brief in domains_brief: igor@61: if node_brief_re.search(brief).groups()[3] == '*': igor@61: real_nodes.append(domains[i]) igor@61: i+=1 igor@61: if len(domain_notes)==0: igor@61: domain_notes=map(lambda x:node_brief_re.search(x).groups()[4] or '', domains_brief) igor@58: igor@58: ############################ igor@35: #try: igor@35: #except: igor@35: # print "Can't find or interpret module %s with topology description" %(network) igor@35: # sys.exit(1) igor@34: igor@61: #process_domains_brief() igor@34: igor@59: N = domains.index(domain) igor@35: name=domain igor@34: igor@34: pae=1 igor@34: if pae: igor@40: kernel = "/boot/vmlinuz-2.6.18-4-xen-686" igor@40: ramdisk = "/boot/initrd.img-2.6.18-4-xen-686" igor@34: else: igor@34: kernel = "/boot/vmlinuz-2.6.18-without-PAE-4-xen-686" igor@34: ramdisk = "/boot/initrd.img-2.6.18-without-PAE-4-xen-686-domU" igor@34: igor@34: #builder='linux' igor@34: cpu_cap = 10 igor@34: igor@62: hvm = 0 igor@62: if domain_types[N] in ['freebsd','windows']: igor@62: hvm = 1 igor@59: igor@62: if hvm: igor@62: kernel = "hvmloader" igor@62: builder='hvm' igor@62: shadow_memory = 8 igor@62: device_model = 'qemu-dm' igor@62: boot="c" igor@62: sdl=0 igor@62: vnc=1 igor@62: vncpasswd='' igor@62: stdvga=0 igor@62: serial='pty' igor@62: usb=1 igor@59: igor@59: igor@56: for br in bridges: igor@56: if not br in vbridges_table.keys(): igor@56: vbridges_table[br]=[] igor@56: igor@56: for domain in domains: igor@56: if not domain in connection_table.keys(): igor@56: connection_table[domain]='true' igor@34: igor@34: vbridges = vbridges_table[name] igor@34: igor@34: vif=[] igor@34: x=1 igor@34: for i in vbridges: igor@62: if hvm: igor@62: vif.append('bridge='+i+',type=ioemu,mac=00:16:3e:01:'+hex(N)[2:]+':'+hex(int('c0',16)+x)[2:]) igor@62: else: igor@62: vif.append('bridge='+i+',mac=00:16:3e:01:'+hex(N)[2:]+':'+hex(int('c0',16)+x)[2:]) igor@34: x+=1 igor@34: igor@62: if domain_types[N] in ['xenomips','quagga','dynamips','pixemu']: igor@62: disk = [ 'file:'+xenomips_dir+'xenomips1.img,hda1,r', 'file:'+xenomips_dir+'xenomips-ios1.img,hda2,r', 'file:'+xenomips_dir+'xenomips-config'+str(N)+'.img,hda3,w' ] igor@62: else: igor@62: if hvm: igor@62: if domain_types[N] == 'linux': igor@62: disk = [ 'file:/xen/xentaur-images/'+network+'/'+name+'.img,hda,w' ] igor@62: else: igor@62: disk = [ 'file:/xen/xentaur-images/'+network+'/'+name+'.img,hda,w', 'file:/xen/xentaur-images/'+network+'/'+name+'-disk2.img,hdb,w' ] igor@62: igor@62: else: igor@62: disk = [ 'file:/xen/xentaur-images/'+network+'/'+name+'.img,hda1,w' ] igor@62: igor@34: root = "/dev/hda1 ro" igor@34: igor@59: if domain_types[N] == 'quagga': igor@59: memory = 64 igor@62: elif domain_types[N] == 'linux': igor@63: memory = 128 igor@59: else: igor@62: memory = 300 igor@59: igor@61: if len(domain_subtypes) >0 and domain_subtypes[N] != '' and platform == '': igor@58: platform=domain_subtypes[N] igor@58: igor@59: if platform == '': igor@58: platform='7200' igor@42: igor@34: igor@59: if domain_types[N] == 'quagga': igor@34: extra = "quagga" igor@61: elif domain_types[N] == 'dynamips': igor@61: default_network_module={ igor@61: '7200' : 'PA-FE-TX', igor@61: '3600' : 'NM-1FE-TX', igor@61: '3725' : 'NM-1FE-TX', igor@61: '3745' : 'NM-1FE-TX', igor@61: '2691' : 'NM-1FE-TX', igor@61: } igor@61: igor@61: platform_option="" igor@61: if platform != '7200': igor@61: platform_option=' -P '+platform igor@61: npe_option="" igor@61: if platform == '7200': igor@61: npe_option=" -t "+npe_type igor@61: mac_option=' -m 00:16:3e:01:'+hex(N)[2:]+':01' igor@61: if platform != '7200': igor@61: mac_option ='' igor@61: igor@61: network_module=default_network_module[platform] igor@61: igor@61: xenomips='dynamips /xenomips/ios/'+ios_name+platform_option+npe_option+mac_option igor@61: if platform== '7200': igor@61: for i in range(len(vbridges)-1): igor@61: xenomips += ' -p '+str(i+1)+':'+network_module igor@61: else: igor@61: for i in range(len(vbridges)-1): igor@61: xenomips += ' -p '+str(i+1)+':'+network_module igor@61: for i in range(len(vbridges)): igor@61: xenomips += ' -s '+str(i)+':0:gen_eth:eth'+str(i) igor@61: extra = "xenomips=\""+xenomips+"\"" igor@61: elif domain_types[N] == 'pixemu': igor@61: xenomips="./pemu -net nic,vlan=1,macaddr=00:aa:00:00:02:01 -net pcap,vlan=1,ifname=eth0 -net nic,vlan=2,macaddr=00:aa:00:00:02:02 -net pcap,vlan=2,ifname=eth1 -serial stdio -m 128 FLASH"+' /xenomips/ios/'+ios_name igor@61: extra = "xenomips=\""+xenomips+"\"" igor@34: else: igor@62: if not domain_types[N] in ['freebsd','windows','linux'] : igor@62: raise "Unknown domain type %s of domain %s " % (domain_types[N], domains[N]) igor@34: igor@34: on_poweroff = 'destroy' igor@34: on_reboot = 'restart' igor@34: on_crash = 'restart' igor@34: