added new OVS service file
This commit is contained in:
parent
97f3c3a070
commit
b37d1d52fa
6 changed files with 660 additions and 0 deletions
113
daemon/core/services/OvsService.py
Executable file
113
daemon/core/services/OvsService.py
Executable file
|
@ -0,0 +1,113 @@
|
|||
#
|
||||
# CORE
|
||||
# Copyright (c)2010-2012 the Boeing Company.
|
||||
# See the LICENSE file included in this distribution.
|
||||
#
|
||||
''' Sample user-defined service.
|
||||
'''
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
from core.service import CoreService, addservice
|
||||
|
||||
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
|
||||
_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
|
||||
_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:
|
||||
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 += "/etc/init.d/openvswitch-switch start < /dev/null\n"
|
||||
cfg += "ovs-vsctl add-br ovsbr0\n"
|
||||
cfg += "ifconfig ovsbr0 up\n"
|
||||
|
||||
for ifc in node.netifs():
|
||||
if hasattr(ifc, 'control') and ifc.control == True:
|
||||
continue
|
||||
ifnumstr = re.findall(r"\d+", ifc.name)
|
||||
ifnum = ifnumstr[0]
|
||||
|
||||
# create virtual interfaces
|
||||
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:
|
||||
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:
|
||||
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)
|
||||
else:
|
||||
raise Value, "invalid address: %s", x
|
||||
|
||||
# add interfaces to bridge
|
||||
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"
|
||||
|
||||
# Setup default flows
|
||||
portnum = 1
|
||||
for ifc in node.netifs():
|
||||
if hasattr(ifc, 'control') and ifc.control == True:
|
||||
continue
|
||||
cfg += "ovs-ofctl add-flow ovsbr0 priority=1000,in_port=%d,action=output:%d\n" % (portnum, portnum+1)
|
||||
cfg += "ovs-ofctl add-flow ovsbr0 priority=1000,in_port=%d,action=output:%d\n" % (portnum+1, portnum)
|
||||
portnum += 2
|
||||
|
||||
return cfg
|
||||
|
||||
@staticmethod
|
||||
def subnetentry(x):
|
||||
# TODO - Maybe move default flow rules to here?
|
||||
return
|
||||
|
||||
|
||||
# this line is required to add the above class to the list of available services
|
||||
addservice(OvsService)
|
||||
|
66
daemon/core/services/ryuService.py
Executable file
66
daemon/core/services/ryuService.py
Executable file
|
@ -0,0 +1,66 @@
|
|||
#
|
||||
# CORE
|
||||
# Copyright (c)2010-2012 the Boeing Company.
|
||||
# See the LICENSE file included in this distribution.
|
||||
#
|
||||
''' Ryu SDN controller user-defined service.
|
||||
'''
|
||||
|
||||
import os
|
||||
|
||||
from core.service import CoreService, addservice
|
||||
from core.misc.ipaddr import IPv4Prefix, IPv6Prefix
|
||||
|
||||
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)
|
||||
|
||||
#for ifc in node.netifs():
|
||||
# cfg += 'echo "Node %s has interface %s"\n' % (node.name, ifc.name)
|
||||
# # here we do something interesting
|
||||
# cfg += "\n".join(map(cls.subnetentry, ifc.addrlist))
|
||||
# break
|
||||
return cfg
|
||||
|
||||
@staticmethod
|
||||
def subnetentry(x):
|
||||
''' Generate a subnet declaration block given an IPv4 prefix string
|
||||
for inclusion in the config file.
|
||||
'''
|
||||
if x.find(":") >= 0:
|
||||
# this is an IPv6 address
|
||||
return ""
|
||||
else:
|
||||
net = IPv4Prefix(x)
|
||||
return 'echo " network %s"' % (net)
|
||||
|
||||
# this line is required to add the above class to the list of available services
|
||||
addservice(ryuService)
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue