This commit is contained in:
Rod A Santiago 2017-06-05 10:20:39 -07:00
commit a4f47a17e3
27 changed files with 228 additions and 206 deletions

View file

@ -239,7 +239,9 @@ class Emane(ConfigurableManager):
# Adamson change: first check for iface config keyed by "node:ifc.name"
# (so that nodes w/ multiple interfaces of same conftype can have
# different configs for each separate interface)
key = 1000*ifc.node.objid + ifc.netindex
key = 1000*ifc.node.objid
if ifc.netindex is not None:
key += ifc.netindex
values = self.getconfig(key, conftype, None)[1]
if not values:
values = self.getconfig(ifc.node.objid, conftype, None)[1]

View file

@ -911,12 +911,12 @@ class CoreDocumentParser1(object):
def parse_default_services(self):
# defaults from the CORE GUI
self.default_services = {
'router': ['zebra', 'OSPFv2', 'OSPFv3', 'vtysh', 'IPForward'],
'router': ['zebra', 'OSPFv2', 'OSPFv3', 'IPForward'],
'host': ['DefaultRoute', 'SSH'],
'PC': ['DefaultRoute',],
'mdr': ['zebra', 'OSPFv3MDR', 'vtysh', 'IPForward'],
# 'prouter': ['zebra', 'OSPFv2', 'OSPFv3', 'vtysh', 'IPForward'],
# 'xen': ['zebra', 'OSPFv2', 'OSPFv3', 'vtysh', 'IPForward'],
'mdr': ['zebra', 'OSPFv3MDR', 'IPForward'],
# 'prouter': ['zebra', 'OSPFv2', 'OSPFv3', 'IPForward'],
# 'xen': ['zebra', 'OSPFv2', 'OSPFv3', 'IPForward'],
}
default_services = \
getFirstChildByTagName(self.scenario, 'CORE:defaultservices')

View file

@ -225,8 +225,12 @@ class SimpleLxcNode(PyCoreNode):
"error setting MAC address %s" % str(addr))
def addaddr(self, ifindex, addr):
if self.up:
self.cmd([IP_BIN, "addr", "add", str(addr),
"dev", self.ifname(ifindex)])
if ":" in str(addr): # check if addr is ipv6
self.cmd([IP_BIN, "addr", "add", str(addr),
"dev", self.ifname(ifindex)])
else:
self.cmd([IP_BIN, "addr", "add", str(addr), "broadcast", "+",
"dev", self.ifname(ifindex)])
self._netif[ifindex].addaddr(addr)
def deladdr(self, ifindex, addr):

View file

@ -15,6 +15,7 @@ services.
'''
import sys, os, shlex
import imp
from itertools import repeat
from core.api import coreapi
@ -47,9 +48,8 @@ class CoreServices(ConfigurableManager):
_name = "services"
_type = coreapi.CORE_TLV_REG_UTILITY
_invalid_custom_names = ('core', 'addons', 'api', 'bsd', 'emane', 'misc',
'netns', 'phys', 'services', 'xen')
service_path = set()
def __init__(self, session):
ConfigurableManager.__init__(self, session)
# dict of default services tuples, key is node type
@ -65,23 +65,34 @@ class CoreServices(ConfigurableManager):
self.importcustom(path)
self.isStartupService = startup.Startup.isStartupService
@classmethod
def add_service_path(cls, path):
cls.service_path.add(path)
def importcustom(self, path):
''' Import services from a myservices directory.
'''
if not path or len(path) == 0:
if not path or path in self.service_path:
return
if not os.path.isdir(path):
self.session.warn("invalid custom service directory specified" \
": %s" % path)
return
self.add_service_path(path)
try:
parentdir, childdir = os.path.split(path)
if childdir in self._invalid_custom_names:
raise ValueError, "use a unique custom services dir name, " \
"not '%s'" % childdir
if not parentdir in sys.path:
sys.path.append(parentdir)
exec("from %s import *" % childdir)
f, pathname, description = imp.find_module(childdir, [parentdir])
name = 'core.services.custom.' + childdir
if name in sys.modules:
i = 1
while name + str(i) in sys.modules:
i += 1
name += str(i)
m = imp.load_module(name, f, pathname, description)
if hasattr(m, '__all__'):
for x in m.__all__:
f, pathname, description = imp.find_module(x, [path])
imp.load_module(name + '.' + x, f, pathname, description)
except Exception, e:
self.session.warn("error importing custom services from " \
"%s:\n%s" % (path, e))
@ -820,7 +831,7 @@ class CoreService(object):
def setvalue(self, key, value):
if key not in self.keys:
raise ValueError
raise ValueError('key `%s` not in `%s`' % (key, self.keys))
# this handles data conversion to int, string, and tuples
if value:
if key == "startidx":

View file

@ -20,17 +20,11 @@ from core.misc.ipaddr import IPv4Prefix, isIPv4Address, isIPv6Address
from core.api import coreapi
from core.constants import *
QUAGGA_USER="root"
QUAGGA_GROUP="root"
if os.uname()[0] == "FreeBSD":
QUAGGA_GROUP="wheel"
class Zebra(CoreService):
'''
'''
_name = "zebra"
_group = "Quagga"
_depends = ("vtysh", )
_dirs = ("/usr/local/etc/quagga", "/var/run/quagga")
_configs = ("/usr/local/etc/quagga/Quagga.conf",
"quaggaboot.sh","/usr/local/etc/quagga/vtysh.conf")
@ -140,8 +134,6 @@ QUAGGA_CONF=%s
QUAGGA_SBIN_SEARCH=%s
QUAGGA_BIN_SEARCH=%s
QUAGGA_STATE_DIR=%s
QUAGGA_USER=%s
QUAGGA_GROUP=%s
searchforprog()
{
@ -170,21 +162,6 @@ confcheck()
fi
}
waitforvtyfiles()
{
for f in "$@"; do
count=1
until [ -e $QUAGGA_STATE_DIR/$f ]; do
if [ $count -eq 10 ]; then
echo "ERROR: vty file not found: $QUAGGA_STATE_DIR/$f" >&2
return 1
fi
sleep 0.1
count=$(($count + 1))
done
done
}
bootdaemon()
{
QUAGGA_SBIN_DIR=$(searchforprog $1 $QUAGGA_SBIN_SEARCH)
@ -196,55 +173,55 @@ bootdaemon()
flags=""
if [ "$1" != "zebra" ]; then
waitforvtyfiles zebra.vty
fi
if [ "$1" = "xpimd" ] && \\
grep -E -q '^[[:space:]]*router[[:space:]]+pim6[[:space:]]*$' $QUAGGA_CONF; then
flags="$flags -6"
fi
$QUAGGA_SBIN_DIR/$1 $flags -u $QUAGGA_USER -g $QUAGGA_GROUP -d
$QUAGGA_SBIN_DIR/$1 $flags -d
if [ "$?" != "0" ]; then
echo "ERROR: Quagga's '$1' daemon failed to start!:"
return 1
fi
}
bootvtysh()
bootquagga()
{
QUAGGA_BIN_DIR=$(searchforprog $1 $QUAGGA_BIN_SEARCH)
QUAGGA_BIN_DIR=$(searchforprog 'vtysh' $QUAGGA_BIN_SEARCH)
if [ "z$QUAGGA_BIN_DIR" = "z" ]; then
echo "ERROR: Quagga's '$1' daemon not found in search path:"
echo " $QUAGGA_SBIN_SEARCH"
echo "ERROR: Quagga's 'vtysh' program not found in search path:"
echo " $QUAGGA_BIN_SEARCH"
return 1
fi
vtyfiles="zebra.vty"
# fix /var/run/quagga permissions
id -u quagga 2>/dev/null >/dev/null
if [ "$?" = "0" ]; then
chown quagga $QUAGGA_STATE_DIR
fi
bootdaemon "zebra"
for r in rip ripng ospf6 ospf bgp babel; do
if grep -q "^router \<${r}\>" $QUAGGA_CONF; then
vtyfiles="$vtyfiles ${r}d.vty"
bootdaemon "${r}d"
fi
done
if grep -E -q '^[[:space:]]*router[[:space:]]+pim6?[[:space:]]*$' $QUAGGA_CONF; then
vtyfiles="$vtyfiles xpimd.vty"
bootdaemon "xpimd"
fi
# wait for Quagga daemon vty files to appear before invoking vtysh
waitforvtyfiles $vtyfiles
$QUAGGA_BIN_DIR/vtysh -b
}
confcheck
if [ "x$1" = "x" ]; then
echo "ERROR: missing the name of the Quagga daemon to boot"
if [ "$1" != "zebra" ]; then
echo "WARNING: '$1': all Quagga daemons are launched by the 'zebra' service!"
exit 1
elif [ "$1" = "vtysh" ]; then
bootvtysh $1
else
bootdaemon $1
fi
confcheck
bootquagga
""" % (cls._configs[0], quagga_sbin_search, quagga_bin_search, \
QUAGGA_STATE_DIR, QUAGGA_USER, QUAGGA_GROUP)
QUAGGA_STATE_DIR)
addservice(Zebra)
@ -311,7 +288,7 @@ class Ospfv2(QuaggaService):
unified Quagga.conf file.
'''
_name = "OSPFv2"
_startup = ("sh quaggaboot.sh ospfd",)
_startup = ()
_shutdown = ("killall ospfd", )
_validate = ("pidof ospfd", )
_ipv4_routing = True
@ -382,7 +359,7 @@ class Ospfv3(QuaggaService):
unified Quagga.conf file.
'''
_name = "OSPFv3"
_startup = ("sh quaggaboot.sh ospf6d",)
_startup = ()
_shutdown = ("killall ospf6d", )
_validate = ("pidof ospf6d", )
_ipv4_routing = True
@ -486,7 +463,7 @@ class Bgp(QuaggaService):
having the same AS number.
'''
_name = "BGP"
_startup = ("sh quaggaboot.sh bgpd",)
_startup = ()
_shutdown = ("killall bgpd", )
_validate = ("pidof bgpd", )
_custom_needed = True
@ -511,7 +488,7 @@ class Rip(QuaggaService):
''' The RIP service provides IPv4 routing for wired networks.
'''
_name = "RIP"
_startup = ("sh quaggaboot.sh ripd",)
_startup = ()
_shutdown = ("killall ripd", )
_validate = ("pidof ripd", )
_ipv4_routing = True
@ -534,7 +511,7 @@ class Ripng(QuaggaService):
''' The RIP NG service provides IPv6 routing for wired networks.
'''
_name = "RIPNG"
_startup = ("sh quaggaboot.sh ripngd",)
_startup = ()
_shutdown = ("killall ripngd", )
_validate = ("pidof ripngd", )
_ipv6_routing = True
@ -558,7 +535,7 @@ class Babel(QuaggaService):
protocol for IPv6 and IPv4 with fast convergence properties.
'''
_name = "Babel"
_startup = ("sh quaggaboot.sh babeld",)
_startup = ()
_shutdown = ("killall babeld", )
_validate = ("pidof babeld", )
_ipv6_routing = True
@ -588,7 +565,7 @@ class Xpimd(QuaggaService):
PIM multicast routing based on XORP.
'''
_name = 'Xpimd'
_startup = ('sh quaggaboot.sh xpimd',)
_startup = ()
_shutdown = ('killall xpimd', )
_validate = ('pidof xpimd', )
_ipv4_routing = True
@ -614,21 +591,3 @@ class Xpimd(QuaggaService):
return ' ip mfea\n ip igmp\n ip pim\n'
addservice(Xpimd)
class Vtysh(CoreService):
''' Simple service to run vtysh -b (boot) after all Quagga daemons have
started.
'''
_name = "vtysh"
_group = "Quagga"
_startindex = 45
_startup = ("sh quaggaboot.sh vtysh",)
_shutdown = ()
@classmethod
def generateconfig(cls, node, filename, services):
return ""
addservice(Vtysh)

View file

@ -109,7 +109,6 @@ class XenNode(PyCoreNode):
#'sh quaggaboot.sh zebra',
#'sh quaggaboot.sh ospfd',
#'sh quaggaboot.sh ospf6d',
'sh quaggaboot.sh vtysh',
'killall zebra',
'killall ospfd',
'killall ospf6d',

View file

@ -57,9 +57,9 @@ emane_platform_port = 8101
emane_transform_port = 8201
emane_event_generate = True
emane_event_monitor = False
emane_models = RfPipe, Ieee80211abg, CommEffect, Bypass
emane_models = RfPipe, Ieee80211abg, CommEffect, Bypass, Tdma
# EMANE log level range [0,4] default: 2
#emane_log_level = 2
emane_realtime = True
aux_request_handler = core.addons.api2handler.CoreApi2RequestHandler:12222
aux_request_handler = core.addons.api2handler.CoreApi2RequestHandler:12222

View file

@ -70,7 +70,7 @@ def main():
values[ names.index('propagationmodel') ] = '2ray'
session.emane.setconfig(wlan.objid, EmaneIeee80211abgModel._name, values)
services_str = "zebra|OSPFv3MDR|vtysh|IPForward"
services_str = "zebra|OSPFv3MDR|IPForward"
print "creating %d nodes with addresses from %s" % \
(options.numnodes, prefix)

View file

@ -97,7 +97,7 @@ def main():
parser.add_option("-s", "--services", dest = "services", type = str,
help = "pipe-delimited list of services added to each " \
"node (default = %s)\n(Example: 'zebra|OSPFv2|OSPFv3|" \
"vtysh|IPForward')" % parser.defaults["services"])
"IPForward')" % parser.defaults["services"])
def usage(msg = None, err = 0):
sys.stdout.write("\n")

View file

@ -66,7 +66,7 @@ def wifisession(opt):
wifi.phy.Set("RxGain", ns.core.DoubleValue(18.0))
prefix = ipaddr.IPv4Prefix("10.0.0.0/16")
services_str = "zebra|OSPFv3MDR|vtysh|IPForward"
services_str = "zebra|OSPFv3MDR|IPForward"
nodes = []
for i in xrange(1, opt.numnodes + 1):
node = session.addnode(name = "n%d" % i)

View file

@ -156,7 +156,6 @@ def sighandler(signum, stackframe):
signal.signal(signal.SIGHUP, sighandler)
signal.signal(signal.SIGINT, sighandler)
signal.signal(signal.SIGPIPE, sighandler)
signal.signal(signal.SIGTERM, sighandler)
signal.signal(signal.SIGUSR1, sighandler)
signal.signal(signal.SIGUSR2, sighandler)