def buildBGPconfig(net): configBGP = {} for r,asn in LinuxRouter._routers: configBGP[r]={} configBGP[r]['asn']=asn configBGP[r]['peers']=[] for intf in net.get(r).intfList(): remote = intf.link.intf2 if intf == intf.link.intf1 else intf.link.intf1 if 'asn' in intf.params: configBGP[r]['peers'].append({ 'ip' : addrOnly(remote.params['ip']), 'asn' : remote.params['asn']}) return configBGP
def build( self, **_opts ): subnetFactory = SubnetFactory('10.0.0.0/8') for n in range(RN): ip1,ip2 = subnetFactory.getLink() print "host network: ",(ip1,ip2) asn = 100+n c = str(n) r = self.addNode( 'r'+c, cls=LinuxRouter, ip=ip1, asn=asn ) h = self.addHost( 'h'+c, ip=ip2, defaultRoute='via '+addrOnly(ip1)) self.addLink( h, r, intfName2='r%s-eth1'%c, params2={ 'ip' : ip1 } ) for n in range(RN): # can only add links when ALL of the routers are defined, hence a second loop is needed for m in range(n+1,RN): asn = 100+n remoteAsn = 100+m cm = str(m) cn = str(n) ra = 'r'+cn ; rb = 'r'+cm ; intfca = ra+'-'+rb ; intfcb = rb+'-'+ra ip1,ip2 = subnetFactory.getLink() print "adding peer", ra, rb, intfca,intfcb, ip1 , ip2 , asn, remoteAsn self.addLink( ra, rb, intfName1=intfca, intfName2=intfcb, params1={ 'ip' : ip1, 'asn' : asn } , params2={ 'ip' : ip2, 'asn' : remoteAsn } )