blob: d7d5f6b477f4b54b113d7c71f135ca26f5c45724 [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
7from subprocess import Popen,PIPE,call,check_call
8from optparse import OptionParser
9
10parser = OptionParser(version="%prog 0.1")
11parser.set_defaults(port_count=4)
12parser.set_defaults(of_dir="../../openflow")
13parser.set_defaults(port=6633)
14parser.add_option("-n", "--port_count", type="int",
15 help="Number of veth pairs to create")
16parser.add_option("-o", "--of_dir", help="OpenFlow root directory for host")
17parser.add_option("-p", "--port", type="int",
18 help="Port for OFP to listen on")
19(options, args) = parser.parse_args()
20
21call(["/sbin/modprobe", "veth"])
22for idx in range(0, options.port_count):
23 print "Creating veth pair " + str(idx)
24 call(["/sbin/ip", "link", "add", "type", "veth"])
25
26for idx in range(0, 2 * options.port_count):
27 cmd = ["/sbin/ifconfig",
28 "veth" + str(idx),
29 "192.168.1" + str(idx) + ".1",
30 "netmask",
31 "255.255.255.0"]
32 print "Cmd: " + str(cmd)
33 call(cmd)
34
35veths = "veth0"
36for idx in range(1, options.port_count):
37 veths += ",veth" + str(2 * idx)
38
39ofd = options.of_dir + "/udatapath/ofdatapath"
40ofp = options.of_dir + "/secchan/ofprotocol"
41
42try:
43 check_call(["ls", ofd])
44except:
45 print "Could not find datapath daemon: " + ofd
46 os.exit(1)
47
48try:
49 check_call(["ls", ofp])
50except:
51 print "Could not find protocol daemon: " + ofp
52 os.exit(1)
53
54ofd_op = Popen([ofd, "-i", veths, "punix:/tmp/ofd"])
55print "Started ofdatapath on IFs " + veths + " with pid " + str(ofd_op.pid)
56
57print "Starting ofprotocol; ^C to quit"
58call([ofp, "unix:/tmp/ofd", "tcp:127.0.0.1:" + str(options.port),
59 "--fail=closed", "--max-backoff=1"])
60
61ofd_op.kill()
62
63
64
65
66