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 sdn.py defines services to start Open vSwitch and the Ryu SDN Controller.
running the service.
""" """
import os import os
import re import re
@ -8,32 +7,35 @@ import re
from core.service import CoreService from core.service import CoreService
from core.service import ServiceManager from core.service import ServiceManager
class OvsService(CoreService): class SdnService(CoreService):
''' This is a sample user-defined service. """
''' Parent class for SDN services.
# a unique name is required, without spaces """
_name = "OvsService" _name = "SdnProcess"
# you can create your own group here
_group = "SDN" _group = "SDN"
# list of other services this service depends on
_depends = () _depends = ()
# per-node directories _dirs = ()
_dirs = ("/etc/openvswitch", "/var/run/openvswitch", "/var/log/openvswitch") _configs = ()
# generated files (without a full path this file goes in the node's dir, _startindex = 50
# e.g. /tmp/pycore.12345/n1.conf/) _startup = ()
_configs = ('OvsService.sh', ) _shutdown = ()
# this controls the starting order vs other enabled services
@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 _startindex = 50
# list of startup commands, also may be generated during startup
_startup = ('sh OvsService.sh',) _startup = ('sh OvsService.sh',)
# list of shutdown commands
_shutdown = ('killall ovs-vswitchd','killall ovsdb-server') _shutdown = ('killall ovs-vswitchd','killall ovsdb-server')
@classmethod @classmethod
def generateconfig(cls, node, filename, services): 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 # Check whether the node is running zebra
has_zebra = 0 has_zebra = 0
for s in services: 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 eth%s\n" % ifnum
cfg += "ovs-vsctl add-port ovsbr0 sw%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 # 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" cfg += "ovs-vsctl set-controller ovsbr0 tcp:127.0.0.1:6633\n"
#else:
# Delete flows otherwise
#cfg += "ovs-ofctl del-flows ovsbr0\n"
# Setup default flows # Setup default flows
portnum = 1 portnum = 1
@ -99,12 +98,29 @@ class OvsService(CoreService):
return cfg return cfg
@staticmethod class ryuService(SdnService):
def subnetentry(x): _name = "ryuService"
# Maybe move default flow rules to here? _group = "SDN"
return _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 import os
from core.service import CoreService, addservice from core.misc.ipaddress import Ipv4Prefix
from core.misc.ipaddr import IPv4Prefix, IPv6Prefix from core.misc.ipaddress import Ipv6Prefix
from core.service import CoreService
from core.service import ServiceManager
class MyService(CoreService): class MyService(CoreService):
''' This is a sample user-defined service. ''' This is a sample user-defined service.
@ -60,5 +62,5 @@ class MyService(CoreService):
return 'echo " network %s"' % (net) return 'echo " network %s"' % (net)
# this line is required to add the above class to the list of available services # this line is required to add the above class to the list of available services
addservice(MyService) ServiceManager.add(MyService)