You are on page 1of 2

class SingleSwitchTopo(Topo):

"Single switch connected to n (< 256) hosts."


def __init__(self, sw_path, json_path, thrift_port, pcap_dump, n, **opts):
# Initialize topology and default options
Topo.__init__(self, **opts)

switch = self.addSwitch('s1',
sw_path = sw_path,
json_path = json_path,
thrift_port = thrift_port,
pcap_dump = pcap_dump)
switch2 = self.addSwitch('s2',
sw_path = sw_path,
json_path = json_path,
thrift_port = thrift_port,
pcap_dump = pcap_dump)
switch3 = self.addSwitch('s3',
sw_path = sw_path,
json_path = json_path,
thrift_port = thrift_port,
pcap_dump = pcap_dump)

for h in xrange(n):
host = self.addHost('h%d' % (h + 1),
ip = "10.0.%d.10/24" % h,
mac = '00:04:00:00:00:%02x' %h)

host2 = self.addHost('h%d' % (h + 1),


ip = "10.0.%d.10/24" % h,
mac = '00:04:00:00:00:%02x' %h)
host3 = self.addHost('h%d' % (h + 1),
ip = "10.0.%d.10/24" % h,
mac = '00:04:00:00:00:%02x' %h)
host4 = self.addHost('h%d' % (h + 1),
ip = "10.0.%d.10/24" % h,
mac = '00:04:00:00:00:%02x' %h)
host5 = self.addHost('h%d' % (h + 1),
ip = "10.0.%d.10/24" % h,
mac = '00:04:00:00:00:%02x' %h)
host6 = self.addHost('h%d' % (h + 1),
ip = "10.0.%d.10/24" % h,
mac = '00:04:00:00:00:%02x' %h)

self.addLink(host, switch)
self.addLink(switch, switch2)
self.addLink(switch2, host2)
self.addLink(switch2, host3)
self.addLink(switch2, host4)
self.addLink(switch1, switch3)
self.addLink(switch3, host5)
self.addLink(switch3, host6)

def main():
num_hosts = args.num_hosts
mode = args.mode

topo = SingleSwitchTopo(args.behavioral_exe,
args.json,
args.thrift_port,
args.pcap_dump,
num_hosts)
net = Mininet(topo = topo,
host = P4Host,
switch = P4Switch,
controller = None)
net.start()

sw_mac = ["00:aa:bb:00:00:%02x" % n for n in xrange(num_hosts)]

sw_addr = ["10.0.%d.1" % n for n in xrange(num_hosts)]

for n in xrange(num_hosts):
h = net.get('h%d' % (n + 1))
if mode == "l2":
h.setDefaultRoute("dev eth0")
else:
h.setARP(sw_addr[n], sw_mac[n])
h.setDefaultRoute("dev eth0 via %s" % sw_addr[n])

for n in xrange(num_hosts):
h = net.get('h%d' % (n + 1))
h.describe()

sleep(1)

print "Ready !"

CLI( net )
net.stop()

if __name__ == '__main__':
setLogLevel( 'info' )
main()

You might also like