Exemplo n.º 1
0
    def config(self, **kwargs):
        Host.config(self, **kwargs)

        debug("configuring route %s" % self.route)

        self.cmd('ip addr add %s dev %s-eth0' % (self.ip, self.name))
        self.cmd('ip route add default via %s' % self.route)
Exemplo n.º 2
0
 def __init__(self, name, *args, **kwargs):
     dirs = [PRIVDIR]
     Host.__init__(self, name, privateDirs=dirs, *args, **kwargs)
     self.dir = "/tmp/%s" % name
     self.nets = []
     if not os.path.exists(self.dir):
         os.makedirs(self.dir)
Exemplo n.º 3
0
 def __init__(self, name, *args, **kwargs ):
     """privateDirs: list of private directories
        remounts: dirs to remount
        unmount: unmount dirs in cleanup? (True)
        Note: if unmount is False, you must call unmountAll()
        manually."""
     self.privateDirs = kwargs.pop( 'privateDirs', [] )
     self.remounts = kwargs.pop( 'remounts', [] )
     self.unmount = kwargs.pop( 'unmount', True )
     Host.__init__( self, name, *args, **kwargs )
     self.rundir = '%s/%s' % ( self.mnRunDir, name )
     self.root, self.private = None, None  # set in createBindMounts
     if self.privateDirs:
         self.privateDirs = [ realpath( d ) for d in self.privateDirs ]
         self.createBindMounts()
     # These should run in the namespace before we chroot,
     # in order to put the right entries in /etc/mtab
     # Eventually this will allow a local pid space
     # Now we chroot and cd to wherever we were before.
     pwd = self.cmd( 'pwd' ).strip()
     self.sendCmd( 'exec chroot', self.root, 'bash -ms mininet:'
                    + self.name )
     self.waiting = False
     self.cmd( 'cd', pwd )
     # In order for many utilities to work,
     # we need to remount /proc and /sys
     self.cmd( 'mount /proc' )
     self.cmd( 'mount /sys' )
Exemplo n.º 4
0
    def config(self, **kwargs):
        Host.config(self, **kwargs)

        debug("configuring route %s" % self.route)

        self.cmd('ip addr add %s dev %s-eth0' % (self.ip, self.name))
        self.cmd('ip route add default via %s' % self.route)
Exemplo n.º 5
0
	def __init__(self, name, loopback, CR, cluster_id, *args, **kwargs ):
		dirs = ['/var/log/', '/var/log/quagga', '/var/run', '/var/run/quagga', '/var/run/openvswitch', '/var/run/sshd']
		Host.__init__(self, name, privateDirs=dirs, *args, **kwargs )
		self.loopback = loopback

		if cluster_id == "default":
			cluster_id = "0"
		cluster_id = int(cluster_id)
		if CR:
			cluster_id = cluster_id + 128	
	
		extrainfo = '%02x000000' % cluster_id

		self.dpid = self.loopbackDpid(self.loopback, extrainfo)
		self.mac = self.loopbackMac(self.loopback,"0200")
		self.path_ovs = "%s/%s/ovs" %(self.baseDIR, self.name)
		self.path_quagga =  "%s/%s/quagga" %(self.baseDIR, self.name)
		self.path_fpm = "%s/%s/fpm-of" %(self.baseDIR, self.name)
		if OSHI.checked == False:
			self.checkQuagga()
			if self.OF_V == "OpenFlow13":
				self.checkOVS()
			if OSHI.SR == True:
				self.checkSR()
			OSHI.checked = True
    def terminate(self):
        self.cmd("mv %s/exabgp%s.log %s/exabgp%s_`cat %s/exabgp%s.pid`.log" %(
            EXABGP_LOG_DIR, self.name, EXABGP_LOG_DIR, self.name, EXABGP_RUN_DIR, self.name))
        self.cmd("kill `cat %s/exabgp%s.pid`" % (EXABGP_RUN_DIR, self.name))


        Host.terminate(self)
    def terminate(self):
        #I don't think it works because it does not read pid number
        #self.cmd("ps ax | egrep 'bgpd%s.pid|zebra%s.pid' | awk '{print $1}' | xargs kill" % (self.name, self.name))
        self.cmd("kill `cat %s/bgpd%s.pid`" % (QUAGGA_RUN_DIR, self.name))
        self.cmd("kill `cat %s/zebra%s.pid`" % (QUAGGA_RUN_DIR, self.name))

        Host.terminate(self)
Exemplo n.º 8
0
 def __init__(self, name, ips, ce_mac_address=None, gw=None, *args, **kwargs ):
   dirs = ['/var/log/', '/var/log/quagga', '/var/run', '/var/run/quagga']
   Host.__init__(self, name, privateDirs=dirs, *args, **kwargs )
   self.ips = ips
   self.ce_mac_address = ce_mac_address
   self.gw = gw
   self.path_quagga = "%s/%s/quagga" %(self.baseDIR, self.name)
Exemplo n.º 9
0
    def __init__(self, name, quaggaConfFile, zebraConfFile, intfDict, *args,
                 **kwargs):
        Host.__init__(self, name, *args, **kwargs)

        self.quaggaConfFile = quaggaConfFile
        self.zebraConfFile = zebraConfFile
        self.intfDict = intfDict
Exemplo n.º 10
0
    def config(self, **kwargs):
        Host.config(self, **kwargs)

        debug("configuring arp for %s %s" % (self.remoteIP, self.remoteMAC))

        self.setARP(self.remoteIP, self.remoteMAC)
        self.cmd('iperf -s -D -u -p %s' % (self.iperfPort))
Exemplo n.º 11
0
    def __init__(self, name, ip, mac, remoteIP, remoteMAC, iperfPort, *args,
                 **kwargs):
        Host.__init__(self, name, ip=ip, mac=mac, *args, **kwargs)

        self.remoteIP = remoteIP
        self.remoteMAC = remoteMAC
        self.iperfPort = iperfPort
    def config(self, **kwargs):
        Host.config(self, **kwargs)
        self.cmd('sysctl net.ipv4.ip_forward=1')

        for intf, attrs in self.intfDict.items():
            self.cmd('ip addr flush dev %s' % intf)
            if 'mac' in attrs:
                self.cmd('ip link set %s down' % intf)
                self.cmd('ip link set %s address %s' % (intf, attrs['mac']))
                self.cmd('ip link set %s up ' % intf)
                self.nameToIntf[intf].mac=attrs['mac']
            # for addr in attrs['ipAddrs']:
            if 'vlan' in attrs:
                # self.cmd('ip addr flush dev %s')
                self.cmd('ip link add link %s name %s.%s type vlan id %s' % (intf, intf, attrs['vlan'], attrs['vlan']))
                self.cmd('ip addr add %s dev %s.%s' % (attrs['ipAddrs'], intf, attrs['vlan']))
                self.cmd('ip link set dev %s.%s up' % (intf, attrs['vlan']))
            if ('ipAddrs' in attrs) & ('vlan' not in attrs):
                self.cmd('ip addr add %s dev %s' % (attrs['ipAddrs'], intf))
                self.nameToIntf[intf].ip=attrs['ipAddrs'].split('/')[0]
                self.nameToIntf[intf].prefixLen=attrs['ipAddrs'].split('/')[1]


        self.cmd('%s/zebra -d -f %s -z %s/zebra%s.api -i %s/zebra%s.pid' % (
        QUAGGA_DIR, self.zebraConfFile, QUAGGA_RUN_DIR, self.name, QUAGGA_RUN_DIR, self.name))
        self.cmd('%s/bgpd -d -f %s -z %s/zebra%s.api -i %s/bgpd%s.pid' % (
        QUAGGA_DIR, self.quaggaConfFile, QUAGGA_RUN_DIR, self.name, QUAGGA_RUN_DIR, self.name))

        for attrs in self.ARPDict.itervalues():
            if 'localdev' in attrs:
                self.cmd('ip route add %s%s dev %s' % (attrs['remoteIP'], attrs['remoteMask'], attrs['localdev']))
                self.setARP(attrs['remoteIP'], attrs['remoteMAC'])
            elif 'nexthop' in attrs:
                self.cmd('ip route add %s%s via %s' % (attrs['remoteIP'], attrs['remoteMask'], attrs['nexthop']))
                self.setARP(attrs['nexthop'], attrs['remoteMAC'])
Exemplo n.º 13
0
    def __init__(self, name, exabgpIniFile, exabgpConfFile, intfDict, ARPDict,
                 *args, **kwargs):
        Host.__init__(self, name, *args, **kwargs)

        self.exabgpConfFile = exabgpConfFile
        self.exabgpIniFile = exabgpIniFile
        self.intfDict = intfDict
        self.ARPDict = ARPDict
Exemplo n.º 14
0
 def config(self, **kwargs):
     Host.config(self, **kwargs)
     self.cmd('ip -4 addr flush dev %s' % self.defaultIntf())
     for ip in self.ips:
         self.cmd('ip addr add %s dev %s' % (ip, self.defaultIntf()))
     self.cmd('ip route add default via %s' % self.gateway)
     self.cmd('ip neigh add %s dev %s lladdr %s' %
              (self.gateway, self.defaultIntf(), self.gateway_mac))
    def __init__(self, name, quaggaConfFile, zebraConfFile, intfDict, ARPDict, *args, **kwargs):
        Host.__init__(self, name, *args, **kwargs)

        self.quaggaConfFile = quaggaConfFile
        self.zebraConfFile = zebraConfFile
        self.intfDict = intfDict
        # TODO should be optional?
        self.ARPDict = ARPDict
    def __init__(self, name, exabgpIniFile, exabgpConfFile, intfDict, ARPDict, *args, **kwargs):
        Host.__init__(self, name, *args, **kwargs)

        self.exabgpConfFile = exabgpConfFile
        self.exabgpIniFile = exabgpIniFile
        self.intfDict = intfDict
        # TODO should be optional?
        self.ARPDict = ARPDict
Exemplo n.º 17
0
    def config(self, **kwargs):
        Host.config(self, **kwargs)

        self.cmd('ip -6 addr flush dev %s' % self.defaultIntf())
        for ip in self.ips:
            self.cmd('ip -6 addr add %s dev %s' % (ip, self.defaultIntf()))

        self.cmd('ip -6 route add default via %s' % self.gateway)
Exemplo n.º 18
0
 def __init__( self, name, image='hadoop:latest', dargs=None, startString=None, **kwargs ):
     self.image = image
     self.dargs = dargs
     if startString is None:
         self.startString = "/bin/bash"
         self.dargs = "-di"
     else:
         self.startString = startString
     Host.__init__( self, name, **kwargs )
Exemplo n.º 19
0
 def cleanup(self):
     """Clean up, then unmount bind mounts
        unmount: actually unmount bind mounts?"""
     # Wait for process to actually terminate
     self.shell.wait()
     Host.cleanup(self)
     if self.unmount:
         self.unmountBindMounts()
         errFail('rmdir ' + self.root)
Exemplo n.º 20
0
 def cleanup( self ):
     """Clean up, then unmount bind mounts
        unmount: actually unmount bind mounts?"""
     # Wait for process to actually terminate
     self.shell.wait()
     Host.cleanup( self )
     if self.unmount:
         self.unmountBindMounts()
         errFail( 'rmdir ' + self.root )
 def __init__( self, name, image='myace:v1', dargs=None, startString=None, **kwargs ):
     self.image = image
     self.dargs = dargs
     if startString is None:
         self.startString = "/bin/bash"
         self.dargs = "-ti"
     else:
         self.startString = startString
     Host.__init__( self, name, **kwargs )
Exemplo n.º 22
0
 def __init__( self, name, image='ubuntu', dargs=None, startString=None, **kwargs ):
     self.image = image
     self.dargs = dargs
     if startString is None:
         self.startString = "/bin/bash"
         self.dargs = "-it"
     else:
         self.startString = startString
     Host.__init__( self, name, **kwargs )
Exemplo n.º 23
0
	def configDefault(self, **kwargs):
		Host.configDefault(self, **kwargs)
				
		# Set IP to the default interface
		if 'ip' in self.params and self.params.get('ip'):
			ip_prefix = self.params.get( 'ip' )
			[ip, prefix] = ip_prefix.split('/')
			
			self.setIP(ip, prefix)
Exemplo n.º 24
0
 def config(self, **kwargs):
     Host.config(self, **kwargs)
     for intf, attrs in self.intfDict.items():
         self.cmd('ip addr flush dev %s' % intf)
         if 'mac' in attrs:
             self.cmd('ip link set %s down' % intf)
             self.cmd('ip link set %s address %s' % (intf, attrs['mac']))
             self.cmd('ip link set %s up ' % intf)
         for addr in attrs['ipAddrs']:
             self.cmd('ip addr add %s dev %s' % (addr, intf))
Exemplo n.º 25
0
    def config(self, **kwargs):
        Host.config(self, **kwargs)

        debug("configuring route %s" % self.gateway)

        self.cmd('ip addr flush dev %s' % self.defaultIntf())
        for ip in self.ips:
            self.cmd('ip addr add %s dev %s' % (ip, self.defaultIntf()))

        self.cmd('ip route add default via %s' % self.gateway)
Exemplo n.º 26
0
    def __init__(self, name, **kwargs):

        Host.__init__(self, name, **kwargs)
        if not NdnHost.inited:
            NdnHostCommon.init()

        self.nfd = Nfd(self)
        self.nfd.start()

        self.peerList = {}
Exemplo n.º 27
0
    def config(self, **kwargs):
        Host.config(self, **kwargs)

        debug("configuring route %s" % self.gateway)

        self.cmd('ip addr flush dev %s' % self.defaultIntf())
        for ip in self.ips:
            self.cmd('ip addr add %s dev %s' % (ip, self.defaultIntf()))

        self.cmd('ip route add default via %s' % self.gateway)
Exemplo n.º 28
0
 def config(self, **kwargs):
     Host.config(self, **kwargs)
     self.cmd('ip -4 addr flush dev %s' % self.defaultIntf())
     for ip in self.ips:
         self.cmd('ip addr add %s dev %s' % (ip, self.defaultIntf()))
     self.cmd('ip route add default via %s' % self.gateway)
     # Disable offload
     for attr in ["rx", "tx", "sg"]:
         cmd = "/sbin/ethtool --offload %s %s off" % (self.defaultIntf(), attr)
         self.cmd(cmd)
Exemplo n.º 29
0
    def __init__(self, name, **kwargs):

        kwargs.update(inNamespace=True)
        #self.alertAction = kwargs.pop( 'alertAction', 'exception' )
        Host.__init__(self, name, **kwargs)
        self.dir = '/tmp/%s' % self.name
        self.TENNISON_HOME = '/tmp'
        self.cmd('rm -rf', self.dir)
        self.TENNISON_INSTALL = self.unpackTENNISON(self.dir)

        setLogLevel('info')
Exemplo n.º 30
0
    def config(self, **kwargs):
        Host.config(self, **kwargs)
        self.vlanIntf = "%s.%s" % (self.defaultIntf(), self.vlan)
        self.cmd('ip -4 addr flush dev %s' % self.defaultIntf())
        self.cmd('ip link add link %s name %s type vlan id %s' % (self.defaultIntf(), self.vlanIntf, self.vlan))
        self.cmd('ip link set up %s' % self.vlanIntf)

        for ip in self.ips:
            self.cmd('ip addr add %s dev %s' % (ip, self.vlanIntf))

        self.cmd('ip route add default via %s' % self.gateway)
Exemplo n.º 31
0
 def __init__(self,
              name,
              ips,
              gw=None,
              ce_mac_address=None,
              *args,
              **kwargs):
     Host.__init__(self, name, *args, **kwargs)
     self.ips = ips
     self.gw = gw
     self.ce_mac_address = ce_mac_address
Exemplo n.º 32
0
    def __init__(self, name, **kwargs):
        privateDirs = [('/usr/local/etc/ndn', '/tmp/%(name)s/usr/local/etc/ndn'),  ]
        kwargs['privateDirs'] = privateDirs

        Host.__init__(self, name, **kwargs)
        if not NdnHost.inited:
            NdnHostCommon.init()

        self.nfd = Nfd(self)
        self.nfd.start()

        self.peerList = {}
Exemplo n.º 33
0
    def __init__(self, name, ip=None, inNamespace=True,
                 root_dir=None, ssh_template=None,
                 auth_keys=None, **kwargs):

        self.name = name
        self.ssh_template = ssh_template
        self.auth_keys = auth_keys
        self.root_dir = root_dir
        self.ssh_pid_file = None
        self.mounted_dirs = []

        Host.__init__(self, name, inNamespace, **kwargs)
Exemplo n.º 34
0
 def config(self, **kwargs):
     Host.config(self, **kwargs)
     for intf, attrs in self.intfDict.items():
         self.cmd('ip addr flush dev %s' % intf)
         if 'mac' in attrs:
             self.cmd('ip link set %s down' % intf)
             self.cmd('ip link set %s address %s' % (intf, attrs['mac']))
             self.cmd('ip link set %s up ' % intf)
         for addr in attrs['ipAddrs']:
             self.cmd('ip addr add %s dev %s' % (addr, intf))
     self.cmd('route del default ')
     #self.cmd('ip route add 10.103.0.0/16 via 10.103.238.1')
     self.cmd('ip route add default via %s' % self.route)
Exemplo n.º 35
0
 def config(self, **kwargs):
     Host.config(self, **kwargs)
     self.cmd('sysctl net.ipv4.ip_forward=1')
     for intf, attrs in self.intfDict.items():
         self.cmd('ip addr flush dev %s' % intf)
         if 'mac' in attrs:
             self.cmd('ip link set %s down' % intf)
             self.cmd('ip link set %s address %s' % (intf, attrs['mac']))
             self.cmd('ip link set %s up ' % intf)
         for addr in attrs['ipAddrs']:
             self.cmd('ip addr add %s dev %s' % (addr, intf))
     self.cmd('/usr/lib/quagga/zebra -d -f %s -z %s/zebra%s.api -i %s/zebra%s.pid' % (self.zebraConfFile, QUAGGA_RUN_DIR, self.name, QUAGGA_RUN_DIR, self.name))
     self.cmd('/usr/lib/quagga/bgpd -d -f %s -z %s/zebra%s.api -i %s/bgpd%s.pid' % (self.quaggaConfFile, QUAGGA_RUN_DIR, self.name, QUAGGA_RUN_DIR, self.name))
Exemplo n.º 36
0
 def __init__(self,
              name,
              ips,
              ce_mac_address=None,
              gw=None,
              *args,
              **kwargs):
     dirs = ['/var/log/', '/var/log/quagga', '/var/run', '/var/run/quagga']
     Host.__init__(self, name, privateDirs=dirs, *args, **kwargs)
     self.ips = ips
     self.ce_mac_address = ce_mac_address
     self.gw = gw
     self.path_quagga = "%s/%s/quagga" % (self.baseDIR, self.name)
Exemplo n.º 37
0
    def config(self, **kwargs):
        Host.config(self, **kwargs)
        self.cmd('sysctl net.ipv4.ip_forward=1')

        for intf, attrs in self.intfDict.items():
            self.cmd('ip addr flush dev %s' % intf)
            if 'mac' in attrs:
                self.cmd('ip link set %s down' % intf)
                self.cmd('ip link set %s address %s' % (intf, attrs['mac']))
                self.cmd('ip link set %s up ' % intf)
            for addr in attrs['ipAddrs']:
                self.cmd('ip addr add %s dev %s' % (addr, intf))

        self.cmd(
            '/quagga/zebra/zebra -d -f %s -z %s/zebra%s.api -i %s/zebra%s.pid'
            % (self.zebraConfFile, QUAGGA_RUN_DIR, self.name, QUAGGA_RUN_DIR,
               self.name))
        print(
            '\n%s /quagga/zebra/zebra -d -f %s -z %s/zebra%s.api -i %s/zebra%s.pid'
            % (self.name, self.zebraConfFile, QUAGGA_RUN_DIR, self.name,
               QUAGGA_RUN_DIR, self.name))

        if self.name == "r1" or self.name == "r2" or self.name == "ospfbgp":
            self.cmd(
                '/quagga/ospfd/ospfd -d -f %s -z %s/zebra%s.api -i %s/ospfd%s.pid'
                % (self.quaggaConfFile, QUAGGA_RUN_DIR, self.name,
                   QUAGGA_RUN_DIR, self.name))
            print(
                '%s /quagga/ospfd/ospfd -d -f %s -z %s/zebra%s.api -i %s/ospfd%s.pid'
                % (self.name, self.quaggaConfFile, QUAGGA_RUN_DIR, self.name,
                   QUAGGA_RUN_DIR, self.name))
        else:
            self.cmd(
                '/quagga/bgpd/bgpd -d -f %s -z %s/zebra%s.api -i %s/bgpd%s.pid'
                % (self.quaggaConfFile, QUAGGA_RUN_DIR, self.name,
                   QUAGGA_RUN_DIR, self.name))
            print(
                '%s /quagga/bgpd/bgpd -d -f %s -z %s/zebra%s.api -i %s/bgpd%s.pid'
                % (self.name, self.quaggaConfFile, QUAGGA_RUN_DIR, self.name,
                   QUAGGA_RUN_DIR, self.name))

        if self.name == "ospfbgp":
            quaggaBgp = "%s/quagga-sdn-bgp.conf" % CONFIG_DIR
            self.cmd(
                '/quagga/bgpd/bgpd -d -f %s -z %s/zebra%s.api -i %s/bgpd%s.pid'
                % (quaggaBgp, QUAGGA_RUN_DIR, self.name, QUAGGA_RUN_DIR,
                   self.name))
            print(
                '%s /quagga/bgpd/bgpd -d -f %s -z %s/zebra%s.api -i %s/bgpd%s.pid'
                % (self.name, quaggaBgp, QUAGGA_RUN_DIR, self.name,
                   QUAGGA_RUN_DIR, self.name))
Exemplo n.º 38
0
    def config(self, **kwargs):
        Host.config(self, **kwargs)
        intf = self.defaultIntf()
        self.vlanIntf = "%s.%s" % (intf, self.vlan)
        self.cmd('ip -4 addr flush dev %s' % intf)
        self.cmd('ip link add link %s name %s type vlan id %s' % (intf, self.vlanIntf, self.vlan))
        self.cmd('ip link set up %s' % self.vlanIntf)

        for ip in self.ips:
            self.cmd('ip addr add %s dev %s' % (ip, self.vlanIntf))

        self.cmd('ip route add default via %s' % self.gateway)
        intf.name = self.vlanIntf
        self.nameToIntf[self.vlanIntf] = intf
Exemplo n.º 39
0
def emptyNet():

    net = Mininet(topo=None, build=False)
    c0 = Controller('c0', inNamespace=False)

    h1 = Host('h1')
    h2 = Host('h2')
    #intf1 = Intf("h1-eth1")
    #intf2 = Intf("h2-eth1")
    s1 = OVSSwitch('br0', inNamespace=False)

    Link(h1, s1)
    Link(h2, s1)

    c0.start()
    s1.start([c0])

    net.start()
    #s1.cmd('ovs-vsctl set bridge br0 protocols=OpenFlow13')
    CLI(net)

    net.stop()
    h1.stop()
    h2.stop()
    s1.stop()
    c0.stop()
Exemplo n.º 40
0
def emptyNet():

    net = Mininet(switch=OVSSwitch, build=False)

    #c0 = net.addController('c0', controller=RemoteController, port=6633)
    #c1 = net.addController('c1', controller=RemoteController, port=6634)
    c0 = net.addController('c0', controller=Controller, port=6634)
    c1 = net.addController('c1', controller=Controller, port=6635)

    h1 = net.addHost('host1', ip='192.168.0.2/24', mac='00:1e:65:15:fc:01')
    h2 = net.addHost('host2', ip='192.168.0.3/24', mac='00:1e:65:15:fc:02')
    s1 = net.addSwitch('br0')
    net.addLink(h1, s1)
    net.addLink(h2, s1)

    h3 = net.addHost('host3', ip='172.168.0.2/24', mac='00:1e:65:15:fc:03')
    h4 = net.addHost('host4', ip='172.168.0.3/24', mac='00:1e:65:15:fc:04')
    s2 = net.addSwitch('br1')
    net.addLink(h3, s2)
    net.addLink(h4, s2)

    # hide the gatway in net
    gateway = Host('gateway')
    net.addLink(s1, gateway)
    net.addLink(s2, gateway)
    gateway.intf("gateway-eth0").setIP('192.168.0.1/24')
    gateway.intf("gateway-eth1").setIP('172.168.0.1/24')

    # show gateway in net
    #gateway = net.addHost('gateway', ip='192.168.0.1/24')
    #net.addLink(s1, gateway)
    #net.addLink(s2, gateway)
    #gateway.intf("gateway-eth1").setIP('172.168.0.1/24')

    net.build()

    print h1.cmd('ip route add default via 192.168.0.1 dev host1-eth0')
    print h2.cmd('ip route add default via 192.168.0.1 dev host2-eth0')
    print h3.cmd('ip route add default via 172.168.0.1 dev host3-eth0')
    print h4.cmd('ip route add default via 172.168.0.1 dev host4-eth0')

    c0.start()
    c1.start()
    s1.start([c0])
    s2.start([c1])

    #s1.cmd('ovs-vsctl set bridge br0 protocols=OpenFlow13')
    #s2.cmd('ovs-vsctl set bridge br1 protocols=OpenFlow13')
    CLI( net )
    net.stop()
Exemplo n.º 41
0
    def __init__(self, name, **kwargs):

        Host.__init__(self, name, **kwargs)
        if not NdnHost.inited:
            NdnHostCommon.init()

        # Create home directory for a node
        self.homeFolder = "%s/%s" % (self.params['workdir'], self.name)
        self.cmd("mkdir -p %s" % self.homeFolder)
        self.cmd("cd %s" % self.homeFolder)

        self.nfd = None

        self.peerList = {}
Exemplo n.º 42
0
def emptyNet():

    net = Mininet(switch=OVSSwitch, build=False)

    #c0 = net.addController('c0', controller=RemoteController, port=6633)
    #c1 = net.addController('c1', controller=RemoteController, port=6634)
    c0 = net.addController('c0', controller=Controller, port=6634)
    c1 = net.addController('c1', controller=Controller, port=6635)

    h1 = net.addHost('host1', ip='192.168.0.2/24', mac='00:1e:65:15:fc:01')
    h2 = net.addHost('host2', ip='192.168.0.3/24', mac='00:1e:65:15:fc:02')
    s1 = net.addSwitch('br0')
    net.addLink(h1, s1)
    net.addLink(h2, s1)

    h3 = net.addHost('host3', ip='172.168.0.2/24', mac='00:1e:65:15:fc:03')
    h4 = net.addHost('host4', ip='172.168.0.3/24', mac='00:1e:65:15:fc:04')
    s2 = net.addSwitch('br1')
    net.addLink(h3, s2)
    net.addLink(h4, s2)

    # hide the gatway in net
    gateway = Host('gateway')
    net.addLink(s1, gateway)
    net.addLink(s2, gateway)
    gateway.intf("gateway-eth0").setIP('192.168.0.1/24')
    gateway.intf("gateway-eth1").setIP('172.168.0.1/24')

    # show gateway in net
    #gateway = net.addHost('gateway', ip='192.168.0.1/24')
    #net.addLink(s1, gateway)
    #net.addLink(s2, gateway)
    #gateway.intf("gateway-eth1").setIP('172.168.0.1/24')

    net.build()

    print h1.cmd('ip route add default via 192.168.0.1 dev host1-eth0')
    print h2.cmd('ip route add default via 192.168.0.1 dev host2-eth0')
    print h3.cmd('ip route add default via 172.168.0.1 dev host3-eth0')
    print h4.cmd('ip route add default via 172.168.0.1 dev host4-eth0')

    c0.start()
    c1.start()
    s1.start([c0])
    s2.start([c1])

    #s1.cmd('ovs-vsctl set bridge br0 protocols=OpenFlow13')
    #s2.cmd('ovs-vsctl set bridge br1 protocols=OpenFlow13')
    CLI(net)
    net.stop()
Exemplo n.º 43
0
    def terminate(self):
        self.cmd("mv %s/exabgp%s.log %s/exabgp%s_`cat %s/exabgp%s.pid`.log" %
                 (EXABGP_LOG_DIR, self.name, EXABGP_LOG_DIR, self.name,
                  EXABGP_RUN_DIR, self.name))
        self.cmd("kill `cat %s/exabgp%s.pid`" % (EXABGP_RUN_DIR, self.name))
        self.cmd("sleep 2")
        #In some cases pid is not removed
        if os.path.exists("%s/exabgp%s.pid" % (EXABGP_RUN_DIR, self.name)):
            self.cmd("rm -f %s/exabgp%s.pid`" % (EXABGP_RUN_DIR, self.name))

        #In case the pid is not removed - when the gentle methods failed
        self.cmd("killall -KILL exabgp")

        Host.terminate(self)
Exemplo n.º 44
0
    def __init__(self, name, **kwargs):

        Host.__init__(self, name, **kwargs)
        if not NdnHost.inited:
            NdnHostCommon.init()

        # Create home directory for a node
        self.homeFolder = "%s/%s" % (self.params['workdir'], self.name)
        self.cmd("mkdir -p %s" % self.homeFolder)
        self.cmd("cd %s" % self.homeFolder)

        self.nfd = Nfd(self)
        self.nfd.start()

        self.peerList = {}
Exemplo n.º 45
0
    def __init__(self, name, **kwargs ):

        self.portOffset = kwargs.pop('portOffset', 0)
        self.ipBase = kwargs.pop('ipBase', '192.168.123.0/24')
        self.ip = kwargs.pop('ip', '192.168.123.100')
        self.defaultGW = kwargs.pop('gw', '192.168.123.2')

        self.name = name
        kwargs.update( inNamespace=True )
        #self.alertAction = kwargs.pop( 'alertAction', 'exception' )
        Host.__init__( self, name, **kwargs )
        self.dir = '/tmp/%s' % self.name
        self.TENNISON_HOME = '/tmp'
        self.cmd( 'rm -rf', self.dir )
        self.TENNISON_INSTALL = self.unpackTENNISON( self.dir )
Exemplo n.º 46
0
    def config(self, **kwargs):
        Host.config(self, **kwargs)
        self.cmd('sysctl net.ipv4.ip_forward=1')

        for intf, attrs in self.intfDict.items():
            self.cmd('ip addr flush dev %s' % intf)
            if 'mac' in attrs:
                self.cmd('ip link set %s down' % intf)
                self.cmd('ip link set %s address %s' % (intf, attrs['mac']))
                self.cmd('ip link set %s up ' % intf)
            for addr in attrs['ipAddrs']:
                self.cmd('ip addr add %s dev %s' % (addr, intf))

        self.cmd('%s %s > /dev/null 2> exabgp.log &' %
                 (EXABGP_RUN_EXE, self.exaBGPconf))
Exemplo n.º 47
0
    def config(self, **kwargs):
        Host.config(self, **kwargs)
        self.cmd('sysctl net.ipv4.ip_forward=1')

        for intf, attrs in self.intfDict.items():
            self.cmd('ip addr flush dev %s' % intf)
            if 'mac' in attrs:
                self.cmd('ip link set %s down' % intf)
                self.cmd('ip link set %s address %s' % (intf, attrs['mac']))
                self.cmd('ip link set %s up' % intf)
            for addr in attrs['ipAddrs']:
                self.cmd('ip addr add %s dev %s' % (addr, intf))

        self.cmd('/usr/lib/quagga/zebra -d -f %s -z %s/zebra%s.api -i %s/zebra%s.pid' % (self.zebraConfFile, QUAGGA_RUN_DIR, self.name, QUAGGA_RUN_DIR, self.name))
        self.cmd('/usr/lib/quagga/ospfd -d -f %s -z %s/zebra%s.api -i %s/ospfd%s.pid' % (self.quaggaConfFile, QUAGGA_RUN_DIR, self.name, QUAGGA_RUN_DIR, self.name))
Exemplo n.º 48
0
    def config(self, **kwargs):
        Host.config(self, **kwargs)
        intf = self.defaultIntf()
        self.vlanIntf = "%s.%s" % (intf, self.vlan)
        self.cmd('ip -4 addr flush dev %s' % intf)
        self.cmd('sysctl -w net.ipv4.ip_forward=0')
        self.cmd('ip link add link %s name %s type vlan id %s' % (intf, self.vlanIntf, self.vlan))
        self.cmd('ip link set up %s' % self.vlanIntf)

        for ip in self.ips:
            self.cmd('ip addr add %s dev %s' % (ip, self.vlanIntf))

        self.cmd('ip route add default via %s' % self.gateway)
        intf.name = self.vlanIntf
        self.nameToIntf[self.vlanIntf] = intf
Exemplo n.º 49
0
    def config(self, **kwargs):
        Host.config(self, **kwargs)

        for intf, attrs in self.intfDict.items():
            self.cmd('ip addr flush dev %s' % intf)
            if 'mac' in attrs:
                self.cmd('ip link set %s down' % intf)
                self.cmd('ip link set %s address %s' % (intf, attrs['mac']))
                self.cmd('ip link set %s up ' % intf)
            for addr in attrs['ipAddrs']:
                self.cmd('ip addr add %s dev %s' % (addr, intf))

        self.cmd(
            'java -jar /home/dimitris/enodeb/target/sctpclient-1.0-SNAPSHOT-jar-with-dependencies.jar &> /dev/null &'
        )
Exemplo n.º 50
0
  def __init__(self, name, controller_ip, ips, dpid=None, border=0, ce_ip_address=None, ce_mac_address=None, *args, **kwargs ):
    dirs = ['/var/log/', '/var/log/quagga', '/var/run', '/var/run/quagga', '/var/run/openvswitch']
    Host.__init__(self, name, privateDirs=dirs, *args, **kwargs )
    self.path_ovs = "%s/%s/ovs" %(self.baseDIR, self.name)
    self.ips = ips

    if dpid is None:
      dpid = format((int(re.search(r'\d+', name).group())), '#018x')[2:]

    self.dpid = dpid
    self.controller_ip = controller_ip
    self.border = border
    self.ce_ip_address = ce_ip_address
    self.ce_mac_address = ce_mac_address
    self.path_quagga = "%s/%s/quagga" %(self.baseDIR, self.name)
Exemplo n.º 51
0
 def popen( self, *args, **kwargs ):
     """Return a Popen() object in node's namespace
        args: Popen() args, single list, or string
        kwargs: Popen() keyword args"""
     # Tell mnexec to execute command in our cgroup
     mncmd = [ 'docker', 'attach', "mininet-"+self.name ]
     return Host.popen( self, *args, mncmd=mncmd, **kwargs )
Exemplo n.º 52
0
    def config(self, **kwargs):
        Host.config(self, **kwargs)
        self.cmd('sysctl net.ipv4.ip_forward=1')

        for intf, attrs in self.intfDict.items():
            self.cmd('ip addr flush dev %s' % intf)
            if 'mac' in attrs:
                self.cmd('ip link set %s down' % intf)
                self.cmd('ip link set %s address %s' % (intf, attrs['mac']))
                self.cmd('ip link set %s up ' % intf)
            for addr in attrs['ipAddrs']:
                print str(attrs)
                mask = attrs['mask']
                gateway = attrs['gateway']
                # print str('ifconfig %s %s netmask %s' % (intf, addr, mask))
                self.cmd('ifconfig %s %s netmask %s' % (intf, addr, mask))
                self.cmd('route add default gw %s' % (gateway))
Exemplo n.º 53
0
 def popen( self, *args, **kwargs ):
     "Popen with chroot support"
     chroot = kwargs.pop( 'chroot', True )
     mncmd = kwargs.get( 'mncmd',
                        [ 'mnexec', '-a', str( self.pid ) ] )
     if chroot:
         mncmd = [ 'chroot', self.root ] + mncmd
         kwargs[ 'mncmd' ] = mncmd
     return Host.popen( self, *args, **kwargs )
Exemplo n.º 54
0
def emptyNet():

    net = Mininet(topo=None, build=False)
    c0 = Controller('c0', inNamespace=False)

    h1 = Host('h1')
    h2 = Host('h2')
    #intf1 = Intf("h1-eth1")
    #intf2 = Intf("h2-eth1")
    s1 = OVSSwitch('br0', inNamespace=False)    

    Link(h1, s1)
    Link(h2, s1)


    c0.start()
    s1.start([c0])

    net.start()    
    #s1.cmd('ovs-vsctl set bridge br0 protocols=OpenFlow13')
    CLI(net)

    net.stop()
    h1.stop()
    h2.stop()
    s1.stop()
    c0.stop()
    def config(self, **kwargs):
        Host.config(self, **kwargs)
        self.cmd('sysctl net.ipv4.ip_forward=1')

        for intf, attrs in self.intfDict.items():
            self.cmd('ip addr flush dev %s' % intf)
            if 'mac' in attrs:
                self.cmd('ip link set %s down' % intf)
                self.cmd('ip link set %s address %s' % (intf, attrs['mac']))
                self.cmd('ip link set %s up ' % intf)
                self.nameToIntf[intf].mac=attrs['mac']
            # for addr in attrs['ipAddrs']:
            if 'vlan' in attrs:
                # self.cmd('ip addr flush dev %s')
                self.cmd('ip link add link %s name %s.%s type vlan id %s' % (intf, intf, attrs['vlan'], attrs['vlan']))
                self.cmd('ip addr add %s dev %s.%s' % (attrs['ipAddrs'], intf, attrs['vlan']))
                self.cmd('ip link set dev %s.%s up' % (intf, attrs['vlan']))
            if ('ipAddrs' in attrs) & ('vlan' not in attrs):
                self.cmd('ip addr add %s dev %s' % (attrs['ipAddrs'], intf))
                self.nameToIntf[intf].ip=attrs['ipAddrs'].split('/')[0]
                self.nameToIntf[intf].prefixLen=attrs['ipAddrs'].split('/')[1]


        self.cmd('env exabgp.daemon.pid=%s/exabgp%s.pid exabgp.log.destination=%s/exabgp%s.log exabgp -e %s %s' %(
            EXABGP_RUN_DIR, self.name, EXABGP_LOG_DIR, self.name, self.exabgpIniFile, self.exabgpConfFile
        ))

#        self.cmd('env exabgp.daemon.pid=%s/exabgp%s.pid exabgp -e %s %s' %(
#            EXABGP_RUN_DIR, self.name, self.exabgpIniFile, self.exabgpConfFile
#        ))

        for attrs in self.ARPDict.itervalues():
            if 'localdev' in attrs:
                self.cmd('ip route add %s%s dev %s' % (attrs['remoteIP'], attrs['remoteMask'], attrs['localdev']))
                self.setARP(attrs['remoteIP'], attrs['remoteMAC'])
            elif 'nexthop' in attrs:
                self.cmd('ip route add %s%s via %s' % (attrs['remoteIP'], attrs['remoteMask'], attrs['nexthop']))
                self.setARP(attrs['nexthop'], attrs['remoteMAC'])
Exemplo n.º 56
0
	def config(self, *_parm, **_params):
		rv = Host.config(self, *_parm, **_params)
		qcall(self,self.cmd,'iptables -P INPUT ACCEPT')
		qcall(self,self.cmd,'iptables -P OUTPUT ACCEPT')
		qcall(self,self.cmd,'iptables -P FORWARD DROP')
		qcall(self,self.cmd,'iptables -A FORWARD -p icmp -j ACCEPT')
		qcall(self,self.cmd,'iptables -A FORWARD -i s1-lan -o s1-wan -p tcp --sport 1024:65535 --dport 80 -j ACCEPT')
		qcall(self,self.cmd,'iptables -A FORWARD -i s1-wan -o s1-lan -p tcp --sport 80 --dport 1024:65535 -j ACCEPT')
		#qcall(self,self.cmd,'iptables -A FORWARD -i s1-lan -o s1-wan -p tcp --sport 49152:65535 --dport 80 -j ACCEPT')
		#qcall(self,self.cmd,'iptables -A FORWARD -i s1-wan -o s1-lan -p tcp --sport 80 --dport 49152:65535 -j ACCEPT')
		self.ifc()
		qcall(self,self.cmd,'ip route add default via 10.0.2.1 dev s1-wan')
		self.cmd('sysctl -w net.ipv4.ip_forward=1')
		return rv
Exemplo n.º 57
0
    def __init__(self, *opts, **params):
        """Construct NDN host.
           fw: forwarder constructor
           rout: routing constructor
           env: base environ for popen"""
        OVERRIDE_DIRS = ['/etc/ndn', '/var/log/ndn', '/var/run', '/root']
        privateDirs = params.get('privateDirs', [])
        privateDirs = [ pd for pd in privateDirs if pd[0] not in OVERRIDE_DIRS ]
        for d in OVERRIDE_DIRS:
            privateDirs.append((d, '/tmp/mnndn/%(name)s' + d))
        params['privateDirs'] = privateDirs

        Host.__init__(self, *opts, **params)
        self.cmd('export HOME=/root')

        from NfdForwarder import NfdForwarder
        from NlsrRouting import NlsrRouting
        self.fwCtor = params.pop('fw', NfdForwarder)
        self.routCtor = params.pop('rout', NlsrRouting)
        self.env = params.pop('env', {})

        self.fw = None
        self.rout = None
Exemplo n.º 58
0
    def popen(self, *args, **params):
        if len(args) == 1:
            if isinstance(args[0], list):
                # popen([cmd, arg1, arg2...])
                cmd = args[0]
            elif isinstance(args[0], basestring):
                # popen("cmd arg1 arg2...")
                cmd = args[0].split()
            else:
                raise TypeError('popen() requires a string or list')
        elif len(args) > 0:
            # popen( cmd, arg1, arg2... )
            cmd = list(args)

        if cmd[0][0] != '/' and cmd[0] != 'which':
            cmdPath, _, whichExit = self.pexec('which', cmd[0])
            if whichExit == 0:
                cmd[0] = cmdPath.rstrip()

        env = self.env
        env.update(params.get('env', {}))
        env['HOME'] = '/root'
        params['env'] = env
        return Host.popen(self, cmd, **params)
Exemplo n.º 59
0
 def config(self, **kwargs):
     Host.config(self, **kwargs)
     mtu = "ifconfig "+self.name+"-eth0 mtu 1490"
     self.cmd(mtu)
     self.cmd('ip route add default via %s' % self.gateway)
 def popen( self, *args, **kwargs ):
     mncmd = [ 'docker', 'attach', ""+self.name ]
     return Host.popen( self, *args, mncmd=mncmd, **kwargs )