cleaned up SDN services for release

This commit is contained in:
cspiker 2017-06-08 13:19:06 -07:00
parent a1007e2391
commit 192b362ae6
3 changed files with 54 additions and 87 deletions

View file

@ -1,51 +0,0 @@
"""
Ryu SDN controller service.
"""
import os
from core.service import CoreService
from core.service import ServiceManager
class ryuService(CoreService):
''' This is a ryu user-defined service.
'''
# a unique name is required, without spaces
_name = "ryuService"
# you can create your own group here
_group = "SDN"
# list of other services this service depends on
_depends = ()
# per-node directories
_dirs = ()
# generated files (without a full path this file goes in the node's dir,
# e.g. /tmp/pycore.12345/n1.conf/)
_configs = ('ryuService.sh', )
# this controls the starting order vs other enabled services
_startindex = 50
# list of startup commands, also may be generated during startup
_startup = ('sh ryuService.sh',)
# list of shutdown commands
_shutdown = ('killall ryu-manager')
@classmethod
def generateconfig(cls, node, filename, services):
''' 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)
return cfg
@staticmethod
def subnetentry(x):
''' Generate a subnet declaration block given an IPv4 prefix string
for inclusion in the config file.
'''
return
# this line is required to add the above class to the list of available services
ServiceManager.add(ryuService)

View file

@ -1,6 +1,5 @@
"""
This service starts Open vSwitch (if already installed) on nodes
running the service.
sdn.py defines services to start Open vSwitch and the Ryu SDN Controller.
"""
import os
import re
@ -8,32 +7,35 @@ import re
from core.service import CoreService
from core.service import ServiceManager
class OvsService(CoreService):
''' This is a sample user-defined service.
'''
# a unique name is required, without spaces
_name = "OvsService"
# you can create your own group here
class SdnService(CoreService):
"""
Parent class for SDN services.
"""
_name = "SdnProcess"
_group = "SDN"
# list of other services this service depends on
_depends = ()
# per-node directories
_dirs = ("/etc/openvswitch", "/var/run/openvswitch", "/var/log/openvswitch")
# generated files (without a full path this file goes in the node's dir,
# e.g. /tmp/pycore.12345/n1.conf/)
_configs = ('OvsService.sh', )
# this controls the starting order vs other enabled services
_dirs = ()
_configs = ()
_startindex = 50
_startup = ()
_shutdown = ()
@classmethod
def generateconfig(cls, node, filename, services):
return ""
class OvsService(SdnService):
_name = "OvsService"
_group = "SDN"
_depends = ()
_dirs = ("/etc/openvswitch", "/var/run/openvswitch", "/var/log/openvswitch")
_configs = ('OvsService.sh', )
_startindex = 50
# list of startup commands, also may be generated during startup
_startup = ('sh OvsService.sh',)
# list of shutdown commands
_shutdown = ('killall ovs-vswitchd','killall ovsdb-server')
@classmethod
def generateconfig(cls, node, filename, services):
''' Return a string that will be written to filename, or sent to the
GUI for user customization.
'''
# Check whether the node is running zebra
has_zebra = 0
for s in services:
@ -81,12 +83,9 @@ class OvsService(CoreService):
cfg += "ovs-vsctl add-port ovsbr0 eth%s\n" % ifnum
cfg += "ovs-vsctl add-port ovsbr0 sw%s\n" % ifnum
#if has_sdn_ctrlr == 1: #TODO- even if the controller is not local, it finds it
# Add rule for default controller if there is one local
cfg += "ovs-vsctl set-controller ovsbr0 tcp:127.0.0.1:6633\n"
#else:
# Delete flows otherwise
#cfg += "ovs-ofctl del-flows ovsbr0\n"
# Add rule for default controller if there is one local (even if the controller is not local, it finds it)
cfg += "ovs-vsctl set-controller ovsbr0 tcp:127.0.0.1:6633\n"
# Setup default flows
portnum = 1
@ -99,12 +98,29 @@ class OvsService(CoreService):
return cfg
@staticmethod
def subnetentry(x):
# Maybe move default flow rules to here?
return
class ryuService(SdnService):
_name = "ryuService"
_group = "SDN"
_depends = ()
_dirs = ()
_configs = ('ryuService.sh', )
_startindex = 50
_startup = ('sh ryuService.sh',)
_shutdown = ('killall ryu-manager')
@classmethod
def generateconfig(cls, node, filename, services):
''' 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)
return cfg
def load_services():
ServiceManager.add(OvsService)
ServiceManager.add(ryuService)
# this line is required to add the above class to the list of available services
ServiceManager.add(OvsService)

View file

@ -8,8 +8,10 @@
import os
from core.service import CoreService, addservice
from core.misc.ipaddr import IPv4Prefix, IPv6Prefix
from core.misc.ipaddress import Ipv4Prefix
from core.misc.ipaddress import Ipv6Prefix
from core.service import CoreService
from core.service import ServiceManager
class MyService(CoreService):
''' This is a sample user-defined service.
@ -60,5 +62,5 @@ class MyService(CoreService):
return 'echo " network %s"' % (net)
# this line is required to add the above class to the list of available services
addservice(MyService)
ServiceManager.add(MyService)