Merge branch 'develop' into ovs
This commit is contained in:
commit
06e145f508
487 changed files with 49691 additions and 30722 deletions
|
@ -4,51 +4,40 @@ sdn.py defines services to start Open vSwitch and the Ryu SDN Controller.
|
|||
|
||||
import re
|
||||
|
||||
from core.service import CoreService
|
||||
import netaddr
|
||||
|
||||
from core.services.coreservices import CoreService
|
||||
|
||||
|
||||
class SdnService(CoreService):
|
||||
"""
|
||||
Parent class for SDN services.
|
||||
"""
|
||||
_name = None
|
||||
_group = "SDN"
|
||||
_depends = ()
|
||||
_dirs = ()
|
||||
_configs = ()
|
||||
_startindex = 50
|
||||
_startup = ()
|
||||
_shutdown = ()
|
||||
|
||||
group = "SDN"
|
||||
|
||||
@classmethod
|
||||
def generateconfig(cls, node, filename, services):
|
||||
def generate_config(cls, node, filename):
|
||||
return ""
|
||||
|
||||
|
||||
class OvsService(SdnService):
|
||||
_name = "OvsService"
|
||||
_group = "SDN"
|
||||
_depends = ()
|
||||
_dirs = ("/etc/openvswitch", "/var/run/openvswitch", "/var/log/openvswitch")
|
||||
_configs = ('OvsService.sh',)
|
||||
_startindex = 50
|
||||
_startup = ('sh OvsService.sh',)
|
||||
_shutdown = ('killall ovs-vswitchd', 'killall ovsdb-server')
|
||||
name = "OvsService"
|
||||
executables = ("ovs-ofctl", "ovs-vsctl")
|
||||
group = "SDN"
|
||||
dirs = ("/etc/openvswitch", "/var/run/openvswitch", "/var/log/openvswitch")
|
||||
configs = ("OvsService.sh",)
|
||||
startup = ("sh OvsService.sh",)
|
||||
shutdown = ("killall ovs-vswitchd", "killall ovsdb-server")
|
||||
|
||||
@classmethod
|
||||
def generateconfig(cls, node, filename, services):
|
||||
def generate_config(cls, node, filename):
|
||||
# Check whether the node is running zebra
|
||||
has_zebra = 0
|
||||
for s in services:
|
||||
if s._name == "zebra":
|
||||
for s in node.services:
|
||||
if s.name == "zebra":
|
||||
has_zebra = 1
|
||||
|
||||
# Check whether the node is running an SDN controller
|
||||
has_sdn_ctrlr = 0
|
||||
for s in services:
|
||||
if s._name == "ryuService":
|
||||
has_sdn_ctrlr = 1
|
||||
|
||||
cfg = "#!/bin/sh\n"
|
||||
cfg += "# auto-generated by OvsService (OvsService.py)\n"
|
||||
cfg += "## First make sure that the ovs services are up and running\n"
|
||||
|
@ -61,7 +50,7 @@ class OvsService(SdnService):
|
|||
cfg += "\n## Now add all our interfaces as ports to the switch\n"
|
||||
portnum = 1
|
||||
for ifc in node.netifs():
|
||||
if hasattr(ifc, 'control') and ifc.control is True:
|
||||
if hasattr(ifc, "control") and ifc.control is True:
|
||||
continue
|
||||
ifnumstr = re.findall(r"\d+", ifc.name)
|
||||
ifnum = ifnumstr[0]
|
||||
|
@ -69,17 +58,16 @@ class OvsService(SdnService):
|
|||
# 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 += "ifconfig rtr%s up\n" % ifnum
|
||||
# cfg += "ifconfig sw%s up\n" % ifnum
|
||||
|
||||
# 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
|
||||
for ifcaddr in ifc.addrlist:
|
||||
if ifcaddr.find(".") >= 0:
|
||||
addr = ifcaddr.split("/")[0]
|
||||
if netaddr.valid_ipv4(addr):
|
||||
cfg += "ip addr del %s dev %s\n" % (ifcaddr, ifc.name)
|
||||
if has_zebra == 0:
|
||||
cfg += "ip addr add %s dev rtr%s\n" % (ifcaddr, ifnum)
|
||||
elif ifcaddr.find(":") >= 0:
|
||||
elif netaddr.valid_ipv6(addr):
|
||||
cfg += "ip -6 addr del %s dev %s\n" % (ifcaddr, ifc.name)
|
||||
if has_zebra == 0:
|
||||
cfg += "ip -6 addr add %s dev rtr%s\n" % (ifcaddr, ifnum)
|
||||
|
@ -109,7 +97,7 @@ class OvsService(SdnService):
|
|||
# Setup default flows
|
||||
portnum = 1
|
||||
for ifc in node.netifs():
|
||||
if hasattr(ifc, 'control') and ifc.control is True:
|
||||
if hasattr(ifc, "control") and ifc.control is True:
|
||||
continue
|
||||
cfg += "## Take the data from the CORE interface and put it on the veth and vice versa\n"
|
||||
cfg += "ovs-ofctl add-flow ovsbr0 priority=1000,in_port=%d,action=output:%d\n" % (portnum, portnum + 1)
|
||||
|
@ -120,23 +108,23 @@ class OvsService(SdnService):
|
|||
|
||||
|
||||
class RyuService(SdnService):
|
||||
_name = "ryuService"
|
||||
_group = "SDN"
|
||||
_depends = ()
|
||||
_dirs = ()
|
||||
_configs = ('ryuService.sh',)
|
||||
_startindex = 50
|
||||
_startup = ('sh ryuService.sh',)
|
||||
_shutdown = ('killall ryu-manager',)
|
||||
name = "ryuService"
|
||||
executables = ("ryu-manager",)
|
||||
group = "SDN"
|
||||
dirs = ()
|
||||
configs = ("ryuService.sh",)
|
||||
startup = ("sh ryuService.sh",)
|
||||
shutdown = ("killall ryu-manager",)
|
||||
|
||||
@classmethod
|
||||
def generateconfig(cls, node, filename, services):
|
||||
def generate_config(cls, node, filename):
|
||||
"""
|
||||
Return a string that will be written to filename, or sent to the
|
||||
GUI for user customization.
|
||||
"""
|
||||
app_path = "/usr/local/lib/python2.7/dist-packages/ryu/app"
|
||||
cfg = "#!/bin/sh\n"
|
||||
cfg += "# auto-generated by ryuService (ryuService.py)\n"
|
||||
cfg += '/usr/local/bin/ryu-manager --observe-links %s/ofctl_rest.py %s/rest_topology.py' % (app_path, app_path)
|
||||
cfg += (
|
||||
"ryu-manager --observe-links ryu.app.ofctl_rest ryu.app.rest_topology &\n"
|
||||
)
|
||||
return cfg
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue