Merge pull request #178 from andreas-ibm/ovs
add comments to the OVS service
This commit is contained in:
commit
98c9730967
1 changed files with 26 additions and 14 deletions
|
@ -40,10 +40,15 @@ class OvsService(SdnService):
|
||||||
|
|
||||||
cfg = "#!/bin/sh\n"
|
cfg = "#!/bin/sh\n"
|
||||||
cfg += "# auto-generated by OvsService (OvsService.py)\n"
|
cfg += "# auto-generated by OvsService (OvsService.py)\n"
|
||||||
cfg += "/etc/init.d/openvswitch-switch start < /dev/null\n"
|
cfg += "## First make sure that the ovs services are up and running\n"
|
||||||
|
cfg += "/etc/init.d/openvswitch-switch start < /dev/null\n\n"
|
||||||
|
cfg += "## create the switch itself, set the fail mode to secure, \n"
|
||||||
|
cfg += "## this stops it from routing traffic without defined flows.\n"
|
||||||
|
cfg += "## remove the -- and everything after if you want it to act as a regular switch\n"
|
||||||
cfg += "ovs-vsctl add-br ovsbr0 -- set Bridge ovsbr0 fail-mode=secure\n"
|
cfg += "ovs-vsctl add-br ovsbr0 -- set Bridge ovsbr0 fail-mode=secure\n"
|
||||||
cfg += "ip link set dev ovsbr0 up\n"
|
|
||||||
|
|
||||||
|
cfg += "\n## Now add all our interfaces as ports to the switch\n"
|
||||||
|
portnum = 1
|
||||||
for ifc in node.netifs():
|
for ifc in node.netifs():
|
||||||
if hasattr(ifc, "control") and ifc.control is True:
|
if hasattr(ifc, "control") and ifc.control is True:
|
||||||
continue
|
continue
|
||||||
|
@ -51,9 +56,8 @@ class OvsService(SdnService):
|
||||||
ifnum = ifnumstr[0]
|
ifnum = ifnumstr[0]
|
||||||
|
|
||||||
# create virtual interfaces
|
# create virtual interfaces
|
||||||
|
cfg += "## Create a veth pair to send the data to\n"
|
||||||
cfg += "ip link add rtr%s type veth peer name sw%s\n" % (ifnum, ifnum)
|
cfg += "ip link add rtr%s type veth peer name sw%s\n" % (ifnum, ifnum)
|
||||||
cfg += "ip link set dev rtr%s up\n" % ifnum
|
|
||||||
cfg += "ip link set dev sw%s up\n" % ifnum
|
|
||||||
|
|
||||||
# remove ip address of eths because quagga/zebra will assign same IPs to rtr interfaces
|
# remove ip address of eths because quagga/zebra will assign same IPs to rtr interfaces
|
||||||
# or assign them manually to rtr interfaces if zebra is not running
|
# or assign them manually to rtr interfaces if zebra is not running
|
||||||
|
@ -71,25 +75,33 @@ class OvsService(SdnService):
|
||||||
raise ValueError("invalid address: %s" % ifcaddr)
|
raise ValueError("invalid address: %s" % ifcaddr)
|
||||||
|
|
||||||
# add interfaces to bridge
|
# add interfaces to bridge
|
||||||
cfg += "ovs-vsctl add-port ovsbr0 eth%s\n" % ifnum
|
# Make port numbers explicit so they're easier to follow in reading the script
|
||||||
cfg += "ovs-vsctl add-port ovsbr0 sw%s\n" % ifnum
|
cfg += "## Add the CORE interface to the switch\n"
|
||||||
|
cfg += "ovs-vsctl add-port ovsbr0 eth%s -- set Interface eth%s ofport_request=%d\n" % (ifnum, ifnum, portnum)
|
||||||
|
cfg += "## And then add its sibling veth interface\n"
|
||||||
|
cfg += "ovs-vsctl add-port ovsbr0 sw%s -- set Interface sw%s ofport_request=%d\n" % (ifnum, ifnum, portnum+1)
|
||||||
|
cfg += "## start them up so we can send/receive data\n"
|
||||||
|
cfg += "ovs-ofctl mod-port ovsbr0 eth%s up\n" % ifnum
|
||||||
|
cfg += "ovs-ofctl mod-port ovsbr0 sw%s up\n" % ifnum
|
||||||
|
cfg += "## Bring up the lower part of the veth pair\n"
|
||||||
|
cfg += "ip link set dev rtr%s up\n" % ifnum
|
||||||
|
portnum += 2
|
||||||
|
|
||||||
# Add rule for default controller if there is one local (even if the controller is not local, it finds it)
|
# Add rule for default controller if there is one local (even if the controller is not local, it finds it)
|
||||||
|
cfg += "\n## We assume there will be an SDN controller on the other end of this, \n"
|
||||||
|
cfg += "## but it will still function if there's not\n"
|
||||||
cfg += "ovs-vsctl set-controller ovsbr0 tcp:127.0.0.1:6633\n"
|
cfg += "ovs-vsctl set-controller ovsbr0 tcp:127.0.0.1:6633\n"
|
||||||
|
|
||||||
|
cfg += "\n## Now to create some default flows, \n"
|
||||||
|
cfg += "## if the above controller will be present then you probably want to delete them\n"
|
||||||
# Setup default flows
|
# Setup default flows
|
||||||
portnum = 1
|
portnum = 1
|
||||||
for ifc in node.netifs():
|
for ifc in node.netifs():
|
||||||
if hasattr(ifc, "control") and ifc.control is True:
|
if hasattr(ifc, "control") and ifc.control is True:
|
||||||
continue
|
continue
|
||||||
cfg += (
|
cfg += "## Take the data from the CORE interface and put it on the veth and vice versa\n"
|
||||||
"ovs-ofctl add-flow ovsbr0 priority=1000,in_port=%d,action=output:%d\n"
|
cfg += "ovs-ofctl add-flow ovsbr0 priority=1000,in_port=%d,action=output:%d\n" % (portnum, portnum + 1)
|
||||||
% (portnum, portnum + 1)
|
cfg += "ovs-ofctl add-flow ovsbr0 priority=1000,in_port=%d,action=output:%d\n" % (portnum + 1, portnum)
|
||||||
)
|
|
||||||
cfg += (
|
|
||||||
"ovs-ofctl add-flow ovsbr0 priority=1000,in_port=%d,action=output:%d\n"
|
|
||||||
% (portnum + 1, portnum)
|
|
||||||
)
|
|
||||||
portnum += 2
|
portnum += 2
|
||||||
|
|
||||||
return cfg
|
return cfg
|
||||||
|
|
Loading…
Reference in a new issue