Merge branch 'cleanup' of git-ssh.web.boeing.com:Boeing-CORE/CORE into cleanup

This commit is contained in:
Blake J. Harnden 2017-06-16 14:31:23 -07:00
commit 5920a09aae
17 changed files with 758 additions and 66 deletions

View file

@ -13,5 +13,7 @@ Pieces can be imported individually, for example
from core.netns import vnode
"""
__all__ = []
# Automatically import all add-ons listed in addons.__all__
from addons import *

View file

@ -301,6 +301,12 @@ class LxBrNet(PyCoreNet):
snoop = "/sys/devices/virtual/net/%s/bridge/multicast_snooping" % self.brname
if os.path.exists(snoop):
open(snoop, "w").write('0')
# turn on LLDP forwarding (disabled by default in linux)
lldpfile = "/sys/class/net/%s/bridge/group_fwd_mask" % self.brname
if os.path.exists(lldpfile):
open(lldpfile, "w").write('0x4000')
except subprocess.CalledProcessError:
logger.exception("Error setting bridge parameters")

View file

@ -4,3 +4,4 @@ Services
Services available to nodes can be put in this directory. Everything listed in
__all__ is automatically loaded by the main core module.
"""
__all__ = ["quagga", "nrl", "xorp", "bird", "utility", "security", "ucarp", "dockersvc", "OvsService" , "ryuService" , 'startup' ]

View file

@ -89,7 +89,7 @@ class NrlNhdp(NrlService):
servicenames = map(lambda x: x._name, services)
if "SMF" in servicenames:
cmd += " -flooding ecds-etx sticky"
cmd += " -flooding ecds"
cmd += " -smfClient %s_smf" % node.name
netifs = filter(lambda x: not getattr(x, 'control', False), \
@ -603,7 +603,7 @@ class MgenActor(NrlService):
cfg = "#!/bin/sh\n"
cfg += "# auto-generated by nrl.py:MgenActor.generateconfig()\n"
comments = ""
cmd = "mgenBasicActor.py -n %s -a 0.0.0.0" % node.name
cmd = "python /usr/local/bin/mgenBasicActor.py -n %s -a 0.0.0.0 -p 5555" % (node.name)
servicenames = map(lambda x: x._name, services)
netifs = filter(lambda x: not getattr(x, 'control', False), node.netifs())

View file

@ -3,6 +3,7 @@ quagga.py: defines routing services provided by Quagga.
"""
import os
import re
from core import constants
from core.enumerations import LinkTypes, NodeTypes
@ -52,15 +53,28 @@ class Zebra(CoreService):
@classmethod
def generateQuaggaConf(cls, node, services):
""" Returns configuration file text. Other services that depend on zebra
will have generatequaggaifcconfig() and generatequaggaconfig()
hooks that are invoked here.
"""
Returns configuration file text. Other services that depend on zebra
will have generatequaggaifcconfig() and generatequaggaconfig()
hooks that are invoked here.
"""
# Check whether the node is running OVS
has_ovs = 0
for s in services:
if s._name == "OvsService":
has_ovs =1
# we could verify here that filename == Quagga.conf
cfg = ""
for ifc in node.netifs():
cfg += "interface %s\n" % ifc.name
if has_ovs == 0:
ifname = ifc.name
else:
ifnumstr = re.findall(r"\d+", ifc.name)
ifnum = ifnumstr[0]
ifname = "rtr%s" % ifnum
cfg += "interface %s\n" % ifname
#cfg += "interface %s\n" % ifc.name
# include control interfaces in addressing but not routing daemons
if hasattr(ifc, 'control') and ifc.control == True:
cfg += " "
@ -100,7 +114,7 @@ class Zebra(CoreService):
for s in services:
if cls._name not in s._depends:
continue
cfg += s.generatequaggaconfig(node)
cfg += s.generatequaggaconfig(node, services)
return cfg
@staticmethod
@ -294,7 +308,7 @@ class QuaggaService(CoreService):
return ""
@classmethod
def generatequaggaconfig(cls, node):
def generatequaggaconfig(cls, node, services):
return ""
@ -339,7 +353,7 @@ class Ospfv2(QuaggaService):
return ""
@classmethod
def generatequaggaconfig(cls, node):
def generatequaggaconfig(cls, node, services):
cfg = "router ospf\n"
rtrid = cls.routerid(node)
cfg += " router-id %s\n" % rtrid
@ -424,13 +438,26 @@ class Ospfv3(QuaggaService):
return ""
@classmethod
def generatequaggaconfig(cls, node):
def generatequaggaconfig(cls, node, services):
# Check whether the node is running OVS
has_ovs = 0
for s in services:
if s._name == "OvsService":
has_ovs =1
cfg = "router ospf6\n"
rtrid = cls.routerid(node)
cfg += " router-id %s\n" % rtrid
for ifc in node.netifs():
if hasattr(ifc, 'control') and ifc.control is True:
continue
if has_ovs == 0:
ifname = ifc.name
else:
ifnumstr = re.findall(r"\d+", ifc.name)
ifnum = ifnumstr[0]
ifname = "rtr%s" % ifnum
cfg += " interface %s area 0.0.0.0\n" % ifc.name
cfg += "!\n"
return cfg
@ -466,6 +493,7 @@ class Ospfv3mdr(Ospfv3):
@classmethod
def generatequaggaifcconfig(cls, node, ifc):
cfg = cls.mtucheck(ifc)
# Uncomment the following line to use Address Family Translation for IPv4
cfg += " ipv6 ospf6 instance-id 65\n"
if ifc.net is not None and nodeutils.is_node(ifc.net, (NodeTypes.WIRELESS_LAN, NodeTypes.EMANE)):
return cfg + """\
@ -480,7 +508,6 @@ class Ospfv3mdr(Ospfv3):
else:
return cfg
class Bgp(QuaggaService):
"""
The BGP service provides interdomain routing.
@ -496,7 +523,7 @@ class Bgp(QuaggaService):
_ipv6_routing = True
@classmethod
def generatequaggaconfig(cls, node):
def generatequaggaconfig(cls, node, services):
cfg = "!\n! BGP configuration\n!\n"
cfg += "! You should configure the AS number below,\n"
cfg += "! along with this router's peers.\n!\n"
@ -507,7 +534,6 @@ class Bgp(QuaggaService):
cfg += "! neighbor 1.2.3.4 remote-as 555\n!\n"
return cfg
class Rip(QuaggaService):
"""
The RIP service provides IPv4 routing for wired networks.
@ -519,7 +545,7 @@ class Rip(QuaggaService):
_ipv4_routing = True
@classmethod
def generatequaggaconfig(cls, node):
def generatequaggaconfig(cls, node, services):
cfg = """\
router rip
redistribute static
@ -530,7 +556,6 @@ router rip
"""
return cfg
class Ripng(QuaggaService):
"""
The RIP NG service provides IPv6 routing for wired networks.
@ -542,7 +567,7 @@ class Ripng(QuaggaService):
_ipv6_routing = True
@classmethod
def generatequaggaconfig(cls, node):
def generatequaggaconfig(cls, node, services):
cfg = """\
router ripng
redistribute static
@ -553,7 +578,6 @@ router ripng
"""
return cfg
class Babel(QuaggaService):
"""
The Babel service provides a loop-avoiding distance-vector routing
@ -566,11 +590,24 @@ class Babel(QuaggaService):
_ipv6_routing = True
@classmethod
def generatequaggaconfig(cls, node):
def generatequaggaconfig(cls, node, services):
# Check whether the node is running OVS
has_ovs = 0
for s in services:
if s._name == "OvsService":
has_ovs =1
cfg = "router babel\n"
for ifc in node.netifs():
if hasattr(ifc, 'control') and ifc.control is True:
continue
if has_ovs == 0:
ifname = ifc.name
else:
ifnumstr = re.findall(r"\d+", ifc.name)
ifnum = ifnumstr[0]
ifname = "rtr%s" % ifnum
cfg += " network %s\n" % ifc.name
cfg += " redistribute static\n redistribute connected\n"
return cfg
@ -583,7 +620,6 @@ class Babel(QuaggaService):
else:
return " babel wired\n babel split-horizon\n"
class Xpimd(QuaggaService):
"""
PIM multicast routing based on XORP.
@ -595,11 +631,26 @@ class Xpimd(QuaggaService):
_ipv4_routing = True
@classmethod
def generatequaggaconfig(cls, node):
ifname = 'eth0'
def generatequaggaconfig(cls, node, services):
# Check whether the node is running OVS
has_ovs = 0
for s in services:
if s._name == "OvsService":
has_ovs =1
if has_ovs == 0:
ifname = 'eth0'
else:
ifname = 'rtr0'
for ifc in node.netifs():
if ifc.name != 'lo':
ifname = ifc.name
if has_ovs == 0:
ifname = ifc.name
else:
ifnumstr = re.findall(r"\d+", ifc.name)
ifnum = ifnumstr[0]
ifname = "rtr%s" % ifnum
break
cfg = 'router mfea\n!\n'
cfg += 'router igmp\n!\n'
@ -614,7 +665,6 @@ class Xpimd(QuaggaService):
def generatequaggaifcconfig(cls, node, ifc):
return ' ip mfea\n ip igmp\n ip pim\n'
class Vtysh(CoreService):
"""
Simple service to run vtysh -b (boot) after all Quagga daemons have
@ -630,7 +680,6 @@ class Vtysh(CoreService):
def generateconfig(cls, node, filename, services):
return ""
def load_services():
ServiceManager.add(Zebra)
ServiceManager.add(Ospfv2)

126
daemon/core/services/sdn.py Normal file
View file

@ -0,0 +1,126 @@
"""
sdn.py defines services to start Open vSwitch and the Ryu SDN Controller.
"""
import os
import re
from core.service import CoreService
from core.service import ServiceManager
class SdnService(CoreService):
"""
Parent class for SDN services.
"""
_name = "SdnProcess"
_group = "SDN"
_depends = ()
_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
_startup = ('sh OvsService.sh',)
_shutdown = ('killall ovs-vswitchd','killall ovsdb-server')
@classmethod
def generateconfig(cls, node, filename, services):
# 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
# 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
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
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)