blob: 200c1aa92e42d4185f4a7b1c8e7bce5f5b330794 [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)
Rich Lanef57e3592012-10-25 13:42:05 -070027 veth = "veth%d" % (idx*2)
28 veth_peer = "veth%d" % (idx*2+1)
29 call(["/sbin/ip", "link", "add", "name", veth, "type", "veth",
30 "peer", "name", veth_peer])
Dan Talaycocc047ac2010-04-16 09:13:08 -070031
32for idx in range(0, 2 * options.port_count):
33 cmd = ["/sbin/ifconfig",
34 "veth" + str(idx),
35 "192.168.1" + str(idx) + ".1",
36 "netmask",
37 "255.255.255.0"]
38 print "Cmd: " + str(cmd)
39 call(cmd)
40
41veths = "veth0"
42for idx in range(1, options.port_count):
43 veths += ",veth" + str(2 * idx)
44
45ofd = options.of_dir + "/udatapath/ofdatapath"
46ofp = options.of_dir + "/secchan/ofprotocol"
47
48try:
49 check_call(["ls", ofd])
50except:
51 print "Could not find datapath daemon: " + ofd
52 os.exit(1)
53
54try:
55 check_call(["ls", ofp])
56except:
57 print "Could not find protocol daemon: " + ofp
58 os.exit(1)
59
Dan Talaycod344c902010-05-04 13:02:11 -070060if not options.no_wait:
61 print "Starting ofprotocol in 2 seconds; ^C to quit"
62 time.sleep(2)
63else:
64 print "Starting ofprotocol; ^C to quit"
65
Dan Talaycocc047ac2010-04-16 09:13:08 -070066ofd_op = Popen([ofd, "-i", veths, "punix:/tmp/ofd"])
67print "Started ofdatapath on IFs " + veths + " with pid " + str(ofd_op.pid)
68
Dan Talaycocc047ac2010-04-16 09:13:08 -070069call([ofp, "unix:/tmp/ofd", "tcp:127.0.0.1:" + str(options.port),
70 "--fail=closed", "--max-backoff=1"])
71
72ofd_op.kill()
73
74
75
76
77