blob: 382d109cf78826c1694cf2c87c1ef6551dc84cf4 [file] [log] [blame]
Dan Talaycocc047ac2010-04-16 09:13:08 -07001#!/usr/bin/env python
2#
3# Create veth pairs and start up switch daemons
4#
5
6import os
Dan Talaycod344c902010-05-04 13:02:11 -07007import time
Dan Talaycocc047ac2010-04-16 09:13:08 -07008from subprocess import Popen,PIPE,call,check_call
9from optparse import OptionParser
10
11parser = OptionParser(version="%prog 0.1")
12parser.set_defaults(port_count=4)
Rich Laneb7611cd2012-10-25 13:37:31 -070013parser.set_defaults(of_dir="../openflow")
Dan Talaycocc047ac2010-04-16 09:13:08 -070014parser.set_defaults(port=6633)
15parser.add_option("-n", "--port_count", type="int",
16 help="Number of veth pairs to create")
17parser.add_option("-o", "--of_dir", help="OpenFlow root directory for host")
18parser.add_option("-p", "--port", type="int",
19 help="Port for OFP to listen on")
Dan Talaycod344c902010-05-04 13:02:11 -070020parser.add_option("-N", "--no_wait", action="store_true",
21 help="Do not wait 2 seconds to start daemons")
Dan Talaycocc047ac2010-04-16 09:13:08 -070022(options, args) = parser.parse_args()
23
24call(["/sbin/modprobe", "veth"])
25for idx in range(0, options.port_count):
26 print "Creating veth pair " + str(idx)
27 call(["/sbin/ip", "link", "add", "type", "veth"])
28
29for idx in range(0, 2 * options.port_count):
30 cmd = ["/sbin/ifconfig",
31 "veth" + str(idx),
32 "192.168.1" + str(idx) + ".1",
33 "netmask",
34 "255.255.255.0"]
35 print "Cmd: " + str(cmd)
36 call(cmd)
37
38veths = "veth0"
39for idx in range(1, options.port_count):
40 veths += ",veth" + str(2 * idx)
41
42ofd = options.of_dir + "/udatapath/ofdatapath"
43ofp = options.of_dir + "/secchan/ofprotocol"
44
45try:
46 check_call(["ls", ofd])
47except:
48 print "Could not find datapath daemon: " + ofd
49 os.exit(1)
50
51try:
52 check_call(["ls", ofp])
53except:
54 print "Could not find protocol daemon: " + ofp
55 os.exit(1)
56
Dan Talaycod344c902010-05-04 13:02:11 -070057if not options.no_wait:
58 print "Starting ofprotocol in 2 seconds; ^C to quit"
59 time.sleep(2)
60else:
61 print "Starting ofprotocol; ^C to quit"
62
Dan Talaycocc047ac2010-04-16 09:13:08 -070063ofd_op = Popen([ofd, "-i", veths, "punix:/tmp/ofd"])
64print "Started ofdatapath on IFs " + veths + " with pid " + str(ofd_op.pid)
65
Dan Talaycocc047ac2010-04-16 09:13:08 -070066call([ofp, "unix:/tmp/ofd", "tcp:127.0.0.1:" + str(options.port),
67 "--fail=closed", "--max-backoff=1"])
68
69ofd_op.kill()
70
71
72
73
74